]> git.mxchange.org Git - friendica.git/blob - object/Item.php
e680e293629122771d52593b6fb8808779c61173
[friendica.git] / object / Item.php
1 <?php
2 if(class_exists('Item'))
3         return;
4
5 require_once('object/BaseObject.php');
6 require_once('include/text.php');
7 require_once('include/diaspora.php');
8 require_once('boot.php');
9
10 /**
11  * An item
12  */
13 class Item extends BaseObject {
14         private $data = array();
15         private $template = null;
16         private $available_templates = array(
17                 'wall' => 'wall_thread.tpl',
18                 'wall2wall' => 'wallwall_thread.tpl'
19         );
20         private $comment_box_template = 'comment_item.tpl';
21         private $toplevel = false;
22         private $writable = false;
23         private $children = array();
24         private $parent = null;
25         private $conversation = null;
26         private $redirect_url = null;
27         private $owner_url = '';
28         private $owner_photo = '';
29         private $owner_name = '';
30         private $wall_to_wall = false;
31         private $threaded = false;
32         private $visiting = false;
33
34         public function __construct($data) {
35                 $a = $this->get_app();
36
37                 $this->data = $data;
38                 $this->set_template('wall');
39                 $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
40
41                 if(is_array($_SESSION['remote'])) {
42                         foreach($_SESSION['remote'] as $visitor) {
43                                 if($visitor['cid'] == $this->get_data_value('contact-id')) {
44                                         $this->visiting = true;
45                                         break;
46                                 }
47                         }
48                 }
49
50                 $this->writable = ($this->get_data_value('writable') || $this->get_data_value('self'));
51
52                 $ssl_state = ((local_user()) ? true : false);
53                 $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ;
54
55                 if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel())
56                         $this->threaded = true;
57
58                 // Prepare the children
59                 if(count($data['children'])) {
60                         foreach($data['children'] as $item) {
61                                 /*
62                                  * Only add will be displayed
63                                  */
64                                 if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
65                                         continue;
66                                 }
67                                 if(! visible_activity($item)) {
68                                         continue;
69                                 }
70                                 $item['pagedrop'] = $data['pagedrop'];
71                                 $child = new Item($item);
72                                 $this->add_child($child);
73                         }
74                 }
75         }
76
77         /**
78          * Get data in a form usable by a conversation template
79          *
80          * Returns:
81          *      _ The data requested on success
82          *      _ false on failure
83          */
84         public function get_template_data($conv_responses, $thread_level=1) {
85                 require_once("mod/proxy.php");
86
87                 $result = array();
88
89                 $a = $this->get_app();
90
91                 $item = $this->get_data();
92                 $edited = false;
93                 if (strcmp($item['created'], $item['edited'])<>0) {
94                       $edited = array(
95                           'label' => t('This entry was edited'),
96                           'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
97                           'relative' => relative_date($item['edited'])
98                       );
99                 }
100                 $commentww = '';
101                 $sparkle = '';
102                 $buttons = '';
103                 $dropping = false;
104                 $star = false;
105                 $ignore = false;
106                 $isstarred = "unstarred";
107                 $indent = '';
108                 $shiny = '';
109                 $osparkle = '';
110                 $total_children = $this->count_descendants();
111
112                 $conv = $this->get_conversation();
113
114
115                 $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
116                         || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
117                         ? t('Private Message')
118                         : false);
119                 $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false);
120                 if(local_user() && link_compare($a->contact['url'],$item['author-link']))
121                         $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
122                 else
123                         $edpost = false;
124                 if(($this->get_data_value('uid') == local_user()) || $this->is_visiting())
125                         $dropping = true;
126
127                 $drop = array(
128                         'dropping' => $dropping,
129                         'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''),
130                         'select' => t('Select'),
131                         'delete' => t('Delete'),
132                 );
133
134                 $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false);
135
136                 $diff_author    = ((link_compare($item['url'],$item['author-link'])) ? false : true);
137                 $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
138                 if($item['author-link'] && (! $item['author-name']))
139                         $profile_name = $item['author-link'];
140
141                 $sp = false;
142                 $profile_link = best_link_url($item,$sp);
143                 if($profile_link === 'mailbox')
144                         $profile_link = '';
145                 if($sp)
146                         $sparkle = ' sparkle';
147                 else
148                         $profile_link = zrl($profile_link);
149
150                 $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
151                 if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
152                         $profile_avatar = $a->contacts[$normalised]['thumb'];
153                 else
154                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_data_value('thumb')));
155
156                 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
157                 call_hooks('render_location',$locate);
158                 $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
159
160                 $searchpath = $a->get_baseurl()."/search?tag=";
161                 $tags=array();
162                 $hashtags = array();
163                 $mentions = array();
164
165
166                 /*foreach(explode(',',$item['tag']) as $tag){
167                         $tag = trim($tag);
168                         if ($tag!="") {
169                                 $t = bbcode($tag);
170                                 $tags[] = $t;
171                                 if($t[0] == '#')
172                                         $hashtags[] = $t;
173                                 elseif($t[0] == '@')
174                                         $mentions[] = $t;
175                         }
176                 }*/
177
178
179                 // process action responses - e.g. like/dislike/attend/agree/whatever
180                 $response_verbs = array('like');
181                         $response_verbs[] = 'dislike';
182                 if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
183                         $response_verbs[] = 'attendyes';
184                         $response_verbs[] = 'attendno';
185                         $response_verbs[] = 'attendmaybe';
186                         $isevent = true;
187                         $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
188                 }
189                 $consensus = (($item['item_flags'] & ITEM_CONSENSUS)? true : false);
190                 if($consensus) {
191                         $response_verbs[] = 'agree';
192                         $response_verbs[] = 'disagree';
193                         $response_verbs[] = 'abstain';
194                 }
195                 $responses = get_responses($conv_responses,$response_verbs,$this,$item);
196
197                 // like_button_label from red -> needs to be removed
198                 //$like_button_label = tt('Like','Likes',$like_count,'noun');
199
200                 // another part from red - it is here for compatility - maybe removed later
201                 $like_count = ((x($conv_responses['like'],$item['uri'])) ? $conv_responses['like'][$item['uri']] : '');
202                 $like_list = ((x($conv_responses['like'],$item['uri'])) ? $conv_responses['like'][$item['uri'] . '-l'] : '');
203                 if (count($like_list) > MAX_LIKERS) {
204                         $like_list_part = array_slice($like_list, 0, MAX_LIKERS);
205                         array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
206                 } else {
207                         $like_list_part = '';
208                 }
209                 $like_button_label = tt('Like','Likes',$like_count,'noun');
210                 $dislike_count = ((x($conv_responses['dislike'],$item['uri'])) ? $conv_responses['dislike'][$item['uri']] : '');
211                 $dislike_list = ((x($conv_responses['dislike'],$item['uri'])) ? $conv_responses['dislike'][$item['uri'] . '-l'] : '');
212                 $dislike_button_label = tt('Dislike','Dislikes',$dislike_count,'noun');
213                 if (count($dislike_list) > MAX_LIKERS) {
214                         $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
215                         array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
216                 } else {
217                         $dislike_list_part = '';
218                 }
219
220                 $like    = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
221                 $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : '');
222                 $like    = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : '');
223
224                 /*
225                  * We should avoid doing this all the time, but it depends on the conversation mode
226                  * And the conv mode may change when we change the conv, or it changes its mode
227                  * Maybe we should establish a way to be notified about conversation changes
228                  */
229                 $this->check_wall_to_wall();
230
231                 if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url()))
232                         $osparkle = ' sparkle';
233
234                 if($this->is_toplevel()) {
235                         if($conv->get_profile_owner() == local_user()) {
236                                 $isstarred = (($item['starred']) ? "starred" : "unstarred");
237
238                                 $star = array(
239                                         'do' => t("add star"),
240                                         'undo' => t("remove star"),
241                                         'toggle' => t("toggle star status"),
242                                         'classdo' => (($item['starred']) ? "hidden" : ""),
243                                         'classundo' => (($item['starred']) ? "" : "hidden"),
244                                         'starred' =>  t('starred'),
245                                 );
246                                 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
247                                         intval($item['uid']),
248                                         intval($item['id'])
249                                 );
250                                 if (count($r)) {
251                                         $ignore = array(
252                                                 'do' => t("ignore thread"),
253                                                 'undo' => t("unignore thread"),
254                                                 'toggle' => t("toggle ignore status"),
255                                                 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
256                                                 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
257                                                 'ignored' =>  t('ignored'),
258                                         );
259                                 }
260
261                                 $tagger = '';
262                                 if(feature_enabled($conv->get_profile_owner(),'commtag')) {
263                                         $tagger = array(
264                                                 'add' => t("add tag"),
265                                                 'class' => "",
266                                         );
267                                 }
268                         }
269                 } else {
270                         $indent = 'comment';
271                 }
272
273                 if($conv->is_writable()) {
274                         $buttons = array(
275                                 'like' => array( t("I like this \x28toggle\x29"), t("like")),
276                                 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''),
277                         );
278                         if ($shareable) $buttons['share'] = array( t('Share this'), t('share'));
279                 }
280
281                 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){
282                         $shiny = 'shiny';
283                 }
284
285                 localize_item($item);
286
287                 if ($item["postopts"] and !get_config("system", "suppress_language")) {
288                         //$langdata = explode(";", $item["postopts"]);
289                         //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
290                         $langstr = "";
291                         if (substr($item["postopts"], 0, 5) == "lang=") {
292                                 $postopts = substr($item["postopts"], 5);
293
294                                 $languages = explode(":", $postopts);
295
296                                 if (sizeof($languages) == 1) {
297                                         $languages = array();
298                                         $languages[] = $postopts;
299                                 }
300
301                                 foreach ($languages as $language) {
302                                         $langdata = explode(";", $language);
303                                         if ($langstr != "")
304                                                 $langstr .= ", ";
305
306                                         //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
307                                         $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0];
308                                 }
309                         }
310                 }
311
312                 $body = prepare_body($item,true);
313
314                 list($categories, $folders) = get_cats_and_terms($item);
315
316                 if($a->theme['template_engine'] === 'internal') {
317                         $body_e = template_escape($body);
318                         $text_e = strip_tags(template_escape($body));
319                         $name_e = template_escape($profile_name);
320                         $title_e = template_escape($item['title']);
321                         $location_e = template_escape($location);
322                         $owner_name_e = template_escape($this->get_owner_name());
323                 }
324                 else {
325                         $body_e = $body;
326                         $text_e = strip_tags($body);
327                         $name_e = $profile_name;
328                         $title_e = $item['title'];
329                         $location_e = $location;
330                         $owner_name_e = $this->get_owner_name();
331                 }
332
333                 // Disable features that aren't available in several networks
334                 if (($item["item_network"] != NETWORK_DFRN) AND isset($buttons["dislike"])) {
335                         unset($buttons["dislike"]);
336                         $tagger = '';
337                 }
338
339                 if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"]))
340                         unset($buttons["like"]);
341
342                 if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"]))
343                         unset($buttons["like"]);
344
345                 // Diaspora isn't able to do likes on comments - but red does
346                 if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
347                         !diaspora_is_redmatrix($item["owner-link"]) AND isset($buttons["like"]))
348                         unset($buttons["like"]);
349
350                 // Facebook can like comments - but it isn't programmed in the connector yet.
351                 if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"]))
352                         unset($buttons["like"]);
353
354                 $tmp_item = array(
355                         'template' => $this->get_template(),
356
357                         'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
358                         'tags' => $item['tags'],
359                         'hashtags' => $item['hashtags'],
360                         'mentions' => $item['mentions'],
361                         'txt_cats' => t('Categories:'),
362                         'txt_folders' => t('Filed under:'),
363                         'has_cats' => ((count($categories)) ? 'true' : ''),
364                         'has_folders' => ((count($folders)) ? 'true' : ''),
365                         'categories' => $categories,
366                         'folders' => $folders,
367                         'body' => $body_e,
368                         'text' => $text_e,
369                         'id' => $this->get_id(),
370                         'guid' => $item['guid'],
371                         'isevent' => $isevent,
372                         'attend' => $attend,
373                         'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
374                         'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $this->get_owner_name(), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
375                         'to' => t('to'),
376                         'via' => t('via'),
377                         'wall' => t('Wall-to-Wall'),
378                         'vwall' => t('via Wall-To-Wall:'),
379                         'profile_url' => $profile_link,
380                         'item_photo_menu' => item_photo_menu($item),
381                         'name' => $name_e,
382                         'thumb' => proxy_url($profile_avatar),
383                         'osparkle' => $osparkle,
384                         'sparkle' => $sparkle,
385                         'title' => $title_e,
386                         'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
387                         'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
388                         'app' => $item['app'],
389                         'created' => relative_date($item['created']),
390                         'lock' => $lock,
391                         'location' => $location_e,
392                         'indent' => $indent,
393                         'shiny' => $shiny,
394                         'owner_url' => $this->get_owner_url(),
395                         'owner_photo' => proxy_url($this->get_owner_photo()),
396                         'owner_name' => $owner_name_e,
397                         'plink' => get_plink($item),
398                         'edpost'    => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
399                         'isstarred' => $isstarred,
400                         'star'      => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
401                         'ignore'      => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''),
402                         'tagger'        => $tagger,
403                         'filer'     => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
404                         'drop' => $drop,
405                         'vote' => $buttons,
406                         'like' => $like,
407                         'dislike'   => $dislike,
408                         'responses' => $responses,
409                         'switchcomment' => t('Comment'),
410                         'comment' => $this->get_comment_box($indent),
411                         'previewing' => ($conv->is_preview() ? ' preview ' : ''),
412                         'wait' => t('Please wait'),
413                         'thread_level' => $thread_level,
414                         'postopts' => $langstr,
415                         'edited' => $edited,
416                         'network' => $item["item_network"],
417                         'network_name' => network_to_name($item['item_network'], $profile_link),
418                 );
419
420                 $arr = array('item' => $item, 'output' => $tmp_item);
421                 call_hooks('display_item', $arr);
422
423                 $result = $arr['output'];
424
425                 $result['children'] = array();
426                 $children = $this->get_children();
427                 $nb_children = count($children);
428                 if($nb_children > 0) {
429                         foreach($children as $child) {
430                                 $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1);
431                         }
432                         // Collapse
433                         if(($nb_children > 2) || ($thread_level > 1)) {
434                                 $result['children'][0]['comment_firstcollapsed'] = true;
435                                 $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
436                                 $result['children'][0]['hidden_comments_num'] = $total_children;
437                                 $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
438                                 $result['children'][0]['hide_text'] = t('show more');
439                                 if($thread_level > 1) {
440                                         $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
441                                 }
442                                 else {
443                                         $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
444                                 }
445                         }
446                 }
447
448         if ($this->is_toplevel()) {
449             $result['total_comments_num'] = "$total_children";
450             $result['total_comments_text'] = tt('comment', 'comments', $total_children);
451         }
452
453                 $result['private'] = $item['private'];
454                 $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
455
456                 if($this->is_threaded()) {
457                         $result['flatten'] = false;
458                         $result['threaded'] = true;
459                 }
460                 else {
461                         $result['flatten'] = true;
462                         $result['threaded'] = false;
463                 }
464
465                 return $result;
466         }
467
468         public function get_id() {
469                 return $this->get_data_value('id');
470         }
471
472         public function is_threaded() {
473                 return $this->threaded;
474         }
475
476         /**
477          * Add a child item
478          */
479         public function add_child($item) {
480                 $item_id = $item->get_id();
481                 if(!$item_id) {
482                         logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
483                         return false;
484                 }
485                 if($this->get_child($item->get_id())) {
486                         logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
487                         return false;
488                 }
489                 /*
490                  * Only add what will be displayed
491                  */
492                 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
493                         return false;
494                 }
495                 if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
496                         return false;
497                 }
498
499                 $item->set_parent($this);
500                 $this->children[] = $item;
501                 return end($this->children);
502         }
503
504         /**
505          * Get a child by its ID
506          */
507         public function get_child($id) {
508                 foreach($this->get_children() as $child) {
509                         if($child->get_id() == $id)
510                                 return $child;
511                 }
512                 return null;
513         }
514
515         /**
516          * Get all ou children
517          */
518         public function get_children() {
519                 return $this->children;
520         }
521
522         /**
523          * Set our parent
524          */
525         protected function set_parent($item) {
526                 $parent = $this->get_parent();
527                 if($parent) {
528                         $parent->remove_child($this);
529                 }
530                 $this->parent = $item;
531                 $this->set_conversation($item->get_conversation());
532         }
533
534         /**
535          * Remove our parent
536          */
537         protected function remove_parent() {
538                 $this->parent = null;
539                 $this->conversation = null;
540         }
541
542         /**
543          * Remove a child
544          */
545         public function remove_child($item) {
546                 $id = $item->get_id();
547                 foreach($this->get_children() as $key => $child) {
548                         if($child->get_id() == $id) {
549                                 $child->remove_parent();
550                                 unset($this->children[$key]);
551                                 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
552                                 $this->children = array_values($this->children);
553                                 return true;
554                         }
555                 }
556                 logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG);
557                 return false;
558         }
559
560         /**
561          * Get parent item
562          */
563         protected function get_parent() {
564                 return $this->parent;
565         }
566
567         /**
568          * set conversation
569          */
570         public function set_conversation($conv) {
571                 $previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
572                 
573                 $this->conversation = $conv;
574
575                 // Set it on our children too
576                 foreach($this->get_children() as $child)
577                         $child->set_conversation($conv);
578         }
579
580         /**
581          * get conversation
582          */
583         public function get_conversation() {
584                 return $this->conversation;
585         }
586
587         /**
588          * Get raw data
589          *
590          * We shouldn't need this
591          */
592         public function get_data() {
593                 return $this->data;
594         }
595
596         /**
597          * Get a data value
598          *
599          * Returns:
600          *      _ value on success
601          *      _ false on failure
602          */
603         public function get_data_value($name) {
604                 if(!isset($this->data[$name])) {
605 //                      logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
606                         return false;
607                 }
608
609                 return $this->data[$name];
610         }
611
612         /**
613          * Set template
614          */
615         private function set_template($name) {
616                 $a = get_app();
617
618                 if(!x($this->available_templates, $name)) {
619                         logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG);
620                         return false;
621                 }
622
623                 $this->template = $this->available_templates[$name];
624         }
625
626         /**
627          * Get template
628          */
629         private function get_template() {
630                 return $this->template;
631         }
632
633         /**
634          * Check if this is a toplevel post
635          */
636         private function is_toplevel() {
637                 return $this->toplevel;
638         }
639
640         /**
641          * Check if this is writable
642          */
643         private function is_writable() {
644                 $conv = $this->get_conversation();
645
646                 if($conv) {
647                         // This will allow us to comment on wall-to-wall items owned by our friends
648                         // and community forums even if somebody else wrote the post.
649
650                         // bug #517 - this fixes for conversation owner
651                         if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user())
652                                 return true; 
653
654                         // this fixes for visitors
655                         return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
656                 }
657                 return $this->writable;
658         }
659
660         /**
661          * Count the total of our descendants
662          */
663         private function count_descendants() {
664                 $children = $this->get_children();
665                 $total = count($children);
666                 if($total > 0) {
667                         foreach($children as $child) {
668                                 $total += $child->count_descendants();
669                         }
670                 }
671                 return $total;
672         }
673
674         /**
675          * Get the template for the comment box
676          */
677         private function get_comment_box_template() {
678                 return $this->comment_box_template;
679         }
680
681         /**
682          * Get the comment box
683          *
684          * Returns:
685          *      _ The comment box string (empty if no comment box)
686          *      _ false on failure
687          */
688         private function get_comment_box($indent) {
689                 $a = $this->get_app();
690                 if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) {
691                         return '';
692                 }
693                 
694                 $comment_box = '';
695                 $conv = $this->get_conversation();
696                 $template = get_markup_template($this->get_comment_box_template());
697                 $ww = '';
698                 if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
699                         $ww = 'ww';
700
701                 if($conv->is_writable() && $this->is_writable()) {
702                         $qc = $qcomment =  null;
703
704                         /*
705                          * Hmmm, code depending on the presence of a particular plugin?
706                          * This should be better if done by a hook
707                          */
708                         if(in_array('qcomment',$a->plugins)) {
709                                 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
710                                 $qcomment = (($qc) ? explode("\n",$qc) : null);
711                         }
712                         $comment_box = replace_macros($template,array(
713                                 '$return_path' => $a->query_string,
714                                 '$threaded' => $this->is_threaded(),
715 //                              '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
716                                 '$jsreload' => '',
717                                 '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
718                                 '$id' => $this->get_id(),
719                                 '$parent' => $this->get_id(),
720                                 '$qcomment' => $qcomment,
721                                 '$profile_uid' =>  $conv->get_profile_owner(),
722                                 '$mylink' => $a->contact['url'],
723                                 '$mytitle' => t('This is you'),
724                                 '$myphoto' => $a->contact['thumb'],
725                                 '$comment' => t('Comment'),
726                                 '$submit' => t('Submit'),
727                                 '$edbold' => t('Bold'),
728                                 '$editalic' => t('Italic'),
729                                 '$eduline' => t('Underline'),
730                                 '$edquote' => t('Quote'),
731                                 '$edcode' => t('Code'),
732                                 '$edimg' => t('Image'),
733                                 '$edurl' => t('Link'),
734                                 '$edvideo' => t('Video'),
735                                 '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''),
736                                 '$indent' => $indent,
737                                 '$sourceapp' => t($a->sourcename),
738                                 '$ww' => (($conv->get_mode() === 'network') ? $ww : ''),
739                                 '$rand_num' => random_digits(12)
740                         ));
741                 }
742
743                 return $comment_box;
744         }
745
746         private function get_redirect_url() {
747                 return $this->redirect_url;
748         }
749
750         /**
751          * Check if we are a wall to wall item and set the relevant properties
752          */
753         protected function check_wall_to_wall() {
754                 $a = $this->get_app();
755                 $conv = $this->get_conversation();
756                 $this->wall_to_wall = false;
757
758                 if($this->is_toplevel()) {
759                         if($conv->get_mode() !== 'profile') {
760                                 if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
761                                         // On the network page, I am the owner. On the display page it will be the profile owner.
762                                         // This will have been stored in $a->page_contact by our calling page.
763                                         // Put this person as the wall owner of the wall-to-wall notice.
764
765                                         $this->owner_url = zrl($a->page_contact['url']);
766                                         $this->owner_photo = $a->page_contact['thumb'];
767                                         $this->owner_name = $a->page_contact['name'];
768                                         $this->wall_to_wall = true;
769                                 }
770                                 else if($this->get_data_value('owner-link')) {
771
772                                         $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
773                                         $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
774                                         $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name'));
775
776                                         if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
777
778                                                 // The author url doesn't match the owner (typically the contact)
779                                                 // and also doesn't match the contact alias. 
780                                                 // The name match is a hack to catch several weird cases where URLs are 
781                                                 // all over the park. It can be tricked, but this prevents you from
782                                                 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
783                                                 // well that it's the same Bob Smith. 
784
785                                                 // But it could be somebody else with the same name. It just isn't highly likely. 
786
787
788                                                 $this->owner_photo = $this->get_data_value('owner-avatar');
789                                                 $this->owner_name = $this->get_data_value('owner-name');
790                                                 $this->wall_to_wall = true;
791                                                 // If it is our contact, use a friendly redirect link
792                                                 if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) 
793                                                         && ($this->get_data_value('network') === NETWORK_DFRN)) {
794                                                         $this->owner_url = $this->get_redirect_url();
795                                                 }
796                                                 else
797                                                         $this->owner_url = zrl($this->get_data_value('owner-link'));
798                                         }
799                                 }
800                         }
801                 }
802
803                 if(!$this->wall_to_wall) {
804                         $this->set_template('wall');
805                         $this->owner_url = '';
806                         $this->owner_photo = '';
807                         $this->owner_name = '';
808                 }
809         }
810
811         private function is_wall_to_wall() {
812                 return $this->wall_to_wall;
813         }
814
815         private function get_owner_url() {
816                 return $this->owner_url;
817         }
818
819         private function get_owner_photo() {
820                 return $this->owner_photo;
821         }
822
823         private function get_owner_name() {
824                 return $this->owner_name;
825         }
826
827         private function is_visiting() {
828                 return $this->visiting;
829         }
830
831
832
833
834 }
835 ?>