]> git.mxchange.org Git - friendica.git/blob - object/Item.php
Contact names with ">" and "<" are a problem ...
[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($alike, $dlike, $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   = htmlentities(((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                 $like    = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
179                 $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
180
181                 /*
182                  * We should avoid doing this all the time, but it depends on the conversation mode
183                  * And the conv mode may change when we change the conv, or it changes its mode
184                  * Maybe we should establish a way to be notified about conversation changes
185                  */
186                 $this->check_wall_to_wall();
187
188                 if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url()))
189                         $osparkle = ' sparkle';
190
191                 if($this->is_toplevel()) {
192                         if($conv->get_profile_owner() == local_user()) {
193                                 $isstarred = (($item['starred']) ? "starred" : "unstarred");
194
195                                 $star = array(
196                                         'do' => t("add star"),
197                                         'undo' => t("remove star"),
198                                         'toggle' => t("toggle star status"),
199                                         'classdo' => (($item['starred']) ? "hidden" : ""),
200                                         'classundo' => (($item['starred']) ? "" : "hidden"),
201                                         'starred' =>  t('starred'),
202                                 );
203                                 $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
204                                         intval($item['uid']),
205                                         intval($item['id'])
206                                 );
207                                 if (count($r)) {
208                                         $ignore = array(
209                                                 'do' => t("ignore thread"),
210                                                 'undo' => t("unignore thread"),
211                                                 'toggle' => t("toggle ignore status"),
212                                                 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
213                                                 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
214                                                 'ignored' =>  t('ignored'),
215                                         );
216                                 }
217
218                                 $tagger = '';
219                                 if(feature_enabled($conv->get_profile_owner(),'commtag')) {
220                                         $tagger = array(
221                                                 'add' => t("add tag"),
222                                                 'class' => "",
223                                         );
224                                 }
225                         }
226                 } else {
227                         $indent = 'comment';
228                 }
229
230                 if($conv->is_writable()) {
231                         $buttons = array(
232                                 'like' => array( t("I like this \x28toggle\x29"), t("like")),
233                                 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''),
234                         );
235                         if ($shareable) $buttons['share'] = array( t('Share this'), t('share'));
236                 }
237
238                 $comment = $this->get_comment_box($indent);
239
240                 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){
241                         $shiny = 'shiny';
242                 }
243
244                 localize_item($item);
245
246                 if ($item["postopts"] and !get_config("system", "suppress_language")) {
247                         //$langdata = explode(";", $item["postopts"]);
248                         //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
249                         $langstr = "";
250                         if (substr($item["postopts"], 0, 5) == "lang=") {
251                                 $postopts = substr($item["postopts"], 5);
252
253                                 $languages = explode(":", $postopts);
254
255                                 if (sizeof($languages) == 1) {
256                                         $languages = array();
257                                         $languages[] = $postopts;
258                                 }
259
260                                 foreach ($languages as $language) {
261                                         $langdata = explode(";", $language);
262                                         if ($langstr != "")
263                                                 $langstr .= ", ";
264
265                                         //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
266                                         $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0];
267                                 }
268                         }
269                 }
270
271                 $body = prepare_body($item,true);
272
273                 list($categories, $folders) = get_cats_and_terms($item);
274
275                 if($a->theme['template_engine'] === 'internal') {
276                         $body_e = template_escape($body);
277                         $text_e = strip_tags(template_escape($body));
278                         $name_e = template_escape($profile_name);
279                         $title_e = template_escape($item['title']);
280                         $location_e = template_escape($location);
281                         $owner_name_e = template_escape($this->get_owner_name());
282                 }
283                 else {
284                         $body_e = $body;
285                         $text_e = strip_tags($body);
286                         $name_e = $profile_name;
287                         $title_e = $item['title'];
288                         $location_e = $location;
289                         $owner_name_e = $this->get_owner_name();
290                 }
291
292                 // Disable features that aren't available in several networks
293                 if (($item["item_network"] != NETWORK_DFRN) AND isset($buttons["dislike"])) {
294                         unset($buttons["dislike"]);
295                         $tagger = '';
296                 }
297
298                 if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"]))
299                         unset($buttons["like"]);
300
301                 if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"]))
302                         unset($buttons["like"]);
303
304                 // Diaspora isn't able to do likes on comments - but red does
305                 if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
306                         !diaspora_is_redmatrix($item["owner-link"]) AND isset($buttons["like"]))
307                         unset($buttons["like"]);
308
309                 // Diaspora doesn't has multithreaded comments
310                 if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment'))
311                         unset($comment);
312
313                 // Facebook can like comments - but it isn't programmed in the connector yet.
314                 if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"]))
315                         unset($buttons["like"]);
316
317                 $tmp_item = array(
318                         'template' => $this->get_template(),
319
320                         'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
321                         'tags' => $item['tags'],
322                         'hashtags' => $item['hashtags'],
323                         'mentions' => $item['mentions'],
324                         'txt_cats' => t('Categories:'),
325                         'txt_folders' => t('Filed under:'),
326                         'has_cats' => ((count($categories)) ? 'true' : ''),
327                         'has_folders' => ((count($folders)) ? 'true' : ''),
328                         'categories' => $categories,
329                         'folders' => $folders,
330                         'body' => $body_e,
331                         'text' => $text_e,
332                         'id' => $this->get_id(),
333                         'guid' => urlencode($item['guid']),
334                         'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
335                         'olinktitle' => sprintf( t('View %s\'s profile @ %s'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
336                         'to' => t('to'),
337                         'via' => t('via'),
338                         'wall' => t('Wall-to-Wall'),
339                         'vwall' => t('via Wall-To-Wall:'),
340                         'profile_url' => $profile_link,
341                         'item_photo_menu' => item_photo_menu($item),
342                         'name' => $name_e,
343                         'thumb' => proxy_url($profile_avatar, false, PROXY_SIZE_THUMB),
344                         'osparkle' => $osparkle,
345                         'sparkle' => $sparkle,
346                         'title' => $title_e,
347                         'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
348                         'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
349                         'app' => $item['app'],
350                         'created' => relative_date($item['created']),
351                         'lock' => $lock,
352                         'location' => $location_e,
353                         'indent' => $indent,
354                         'shiny' => $shiny,
355                         'owner_url' => $this->get_owner_url(),
356                         'owner_photo' => proxy_url($this->get_owner_photo(), false, PROXY_SIZE_THUMB),
357                         'owner_name' => htmlentities($owner_name_e),
358                         'plink' => get_plink($item),
359                         'edpost'    => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
360                         'isstarred' => $isstarred,
361                         'star'      => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
362                         'ignore'      => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''),
363                         'tagger'        => $tagger,
364                         'filer'     => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
365                         'drop' => $drop,
366                         'vote' => $buttons,
367                         'like' => $like,
368                         'dislike'   => $dislike,
369                         'switchcomment' => t('Comment'),
370                         'comment' => $comment,
371                         'previewing' => ($conv->is_preview() ? ' preview ' : ''),
372                         'wait' => t('Please wait'),
373                         'thread_level' => $thread_level,
374                         'postopts' => $langstr,
375                         'edited' => $edited,
376                         'network' => $item["item_network"],
377                         'network_name' => network_to_name($item['item_network'], $profile_link),
378                 );
379
380                 $arr = array('item' => $item, 'output' => $tmp_item);
381                 call_hooks('display_item', $arr);
382
383                 $result = $arr['output'];
384
385                 $result['children'] = array();
386                 $children = $this->get_children();
387                 $nb_children = count($children);
388                 if($nb_children > 0) {
389                         foreach($children as $child) {
390                                 $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1);
391                         }
392                         // Collapse
393                         if(($nb_children > 2) || ($thread_level > 1)) {
394                                 $result['children'][0]['comment_firstcollapsed'] = true;
395                                 $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
396                                 $result['children'][0]['hidden_comments_num'] = $total_children;
397                                 $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
398                                 $result['children'][0]['hide_text'] = t('show more');
399                                 if($thread_level > 1) {
400                                         $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
401                                 }
402                                 else {
403                                         $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
404                                 }
405                         }
406                 }
407
408         if ($this->is_toplevel()) {
409             $result['total_comments_num'] = "$total_children";
410             $result['total_comments_text'] = tt('comment', 'comments', $total_children);
411         }
412
413                 $result['private'] = $item['private'];
414                 $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
415
416                 if($this->is_threaded()) {
417                         $result['flatten'] = false;
418                         $result['threaded'] = true;
419                 }
420                 else {
421                         $result['flatten'] = true;
422                         $result['threaded'] = false;
423                 }
424
425                 return $result;
426         }
427
428         public function get_id() {
429                 return $this->get_data_value('id');
430         }
431
432         public function is_threaded() {
433                 return $this->threaded;
434         }
435
436         /**
437          * Add a child item
438          */
439         public function add_child($item) {
440                 $item_id = $item->get_id();
441                 if(!$item_id) {
442                         logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
443                         return false;
444                 }
445                 if($this->get_child($item->get_id())) {
446                         logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
447                         return false;
448                 }
449                 /*
450                  * Only add what will be displayed
451                  */
452                 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
453                         return false;
454                 }
455                 if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
456                         return false;
457                 }
458
459                 $item->set_parent($this);
460                 $this->children[] = $item;
461                 return end($this->children);
462         }
463
464         /**
465          * Get a child by its ID
466          */
467         public function get_child($id) {
468                 foreach($this->get_children() as $child) {
469                         if($child->get_id() == $id)
470                                 return $child;
471                 }
472                 return null;
473         }
474
475         /**
476          * Get all ou children
477          */
478         public function get_children() {
479                 return $this->children;
480         }
481
482         /**
483          * Set our parent
484          */
485         protected function set_parent($item) {
486                 $parent = $this->get_parent();
487                 if($parent) {
488                         $parent->remove_child($this);
489                 }
490                 $this->parent = $item;
491                 $this->set_conversation($item->get_conversation());
492         }
493
494         /**
495          * Remove our parent
496          */
497         protected function remove_parent() {
498                 $this->parent = null;
499                 $this->conversation = null;
500         }
501
502         /**
503          * Remove a child
504          */
505         public function remove_child($item) {
506                 $id = $item->get_id();
507                 foreach($this->get_children() as $key => $child) {
508                         if($child->get_id() == $id) {
509                                 $child->remove_parent();
510                                 unset($this->children[$key]);
511                                 // Reindex the array, in order to make sure there won't be any trouble on loops using count()
512                                 $this->children = array_values($this->children);
513                                 return true;
514                         }
515                 }
516                 logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG);
517                 return false;
518         }
519
520         /**
521          * Get parent item
522          */
523         protected function get_parent() {
524                 return $this->parent;
525         }
526
527         /**
528          * set conversation
529          */
530         public function set_conversation($conv) {
531                 $previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
532
533                 $this->conversation = $conv;
534
535                 // Set it on our children too
536                 foreach($this->get_children() as $child)
537                         $child->set_conversation($conv);
538         }
539
540         /**
541          * get conversation
542          */
543         public function get_conversation() {
544                 return $this->conversation;
545         }
546
547         /**
548          * Get raw data
549          *
550          * We shouldn't need this
551          */
552         public function get_data() {
553                 return $this->data;
554         }
555
556         /**
557          * Get a data value
558          *
559          * Returns:
560          *      _ value on success
561          *      _ false on failure
562          */
563         public function get_data_value($name) {
564                 if(!isset($this->data[$name])) {
565 //                      logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
566                         return false;
567                 }
568
569                 return $this->data[$name];
570         }
571
572         /**
573          * Set template
574          */
575         private function set_template($name) {
576                 $a = get_app();
577
578                 if(!x($this->available_templates, $name)) {
579                         logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG);
580                         return false;
581                 }
582
583                 $this->template = $this->available_templates[$name];
584         }
585
586         /**
587          * Get template
588          */
589         private function get_template() {
590                 return $this->template;
591         }
592
593         /**
594          * Check if this is a toplevel post
595          */
596         private function is_toplevel() {
597                 return $this->toplevel;
598         }
599
600         /**
601          * Check if this is writable
602          */
603         private function is_writable() {
604                 $conv = $this->get_conversation();
605
606                 if($conv) {
607                         // This will allow us to comment on wall-to-wall items owned by our friends
608                         // and community forums even if somebody else wrote the post.
609
610                         // bug #517 - this fixes for conversation owner
611                         if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user())
612                                 return true; 
613
614                         // this fixes for visitors
615                         return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
616                 }
617                 return $this->writable;
618         }
619
620         /**
621          * Count the total of our descendants
622          */
623         private function count_descendants() {
624                 $children = $this->get_children();
625                 $total = count($children);
626                 if($total > 0) {
627                         foreach($children as $child) {
628                                 $total += $child->count_descendants();
629                         }
630                 }
631                 return $total;
632         }
633
634         /**
635          * Get the template for the comment box
636          */
637         private function get_comment_box_template() {
638                 return $this->comment_box_template;
639         }
640
641         /**
642          * Get the comment box
643          *
644          * Returns:
645          *      _ The comment box string (empty if no comment box)
646          *      _ false on failure
647          */
648         private function get_comment_box($indent) {
649                 $a = $this->get_app();
650                 if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) {
651                         return '';
652                 }
653
654                 $comment_box = '';
655                 $conv = $this->get_conversation();
656                 $template = get_markup_template($this->get_comment_box_template());
657                 $ww = '';
658                 if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
659                         $ww = 'ww';
660
661                 if($conv->is_writable() && $this->is_writable()) {
662                         $qc = $qcomment =  null;
663
664                         /*
665                          * Hmmm, code depending on the presence of a particular plugin?
666                          * This should be better if done by a hook
667                          */
668                         if(in_array('qcomment',$a->plugins)) {
669                                 $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
670                                 $qcomment = (($qc) ? explode("\n",$qc) : null);
671                         }
672                         $comment_box = replace_macros($template,array(
673                                 '$return_path' => $a->query_string,
674                                 '$threaded' => $this->is_threaded(),
675 //                              '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
676                                 '$jsreload' => '',
677                                 '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
678                                 '$id' => $this->get_id(),
679                                 '$parent' => $this->get_id(),
680                                 '$qcomment' => $qcomment,
681                                 '$profile_uid' =>  $conv->get_profile_owner(),
682                                 '$mylink' => $a->contact['url'],
683                                 '$mytitle' => t('This is you'),
684                                 '$myphoto' => $a->contact['thumb'],
685                                 '$comment' => t('Comment'),
686                                 '$submit' => t('Submit'),
687                                 '$edbold' => t('Bold'),
688                                 '$editalic' => t('Italic'),
689                                 '$eduline' => t('Underline'),
690                                 '$edquote' => t('Quote'),
691                                 '$edcode' => t('Code'),
692                                 '$edimg' => t('Image'),
693                                 '$edurl' => t('Link'),
694                                 '$edvideo' => t('Video'),
695                                 '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''),
696                                 '$indent' => $indent,
697                                 '$sourceapp' => t($a->sourcename),
698                                 '$ww' => (($conv->get_mode() === 'network') ? $ww : ''),
699                                 '$rand_num' => random_digits(12)
700                         ));
701                 }
702
703                 return $comment_box;
704         }
705
706         private function get_redirect_url() {
707                 return $this->redirect_url;
708         }
709
710         /**
711          * Check if we are a wall to wall item and set the relevant properties
712          */
713         protected function check_wall_to_wall() {
714                 $a = $this->get_app();
715                 $conv = $this->get_conversation();
716                 $this->wall_to_wall = false;
717
718                 if($this->is_toplevel()) {
719                         if($conv->get_mode() !== 'profile') {
720                                 if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
721                                         // On the network page, I am the owner. On the display page it will be the profile owner.
722                                         // This will have been stored in $a->page_contact by our calling page.
723                                         // Put this person as the wall owner of the wall-to-wall notice.
724
725                                         $this->owner_url = zrl($a->page_contact['url']);
726                                         $this->owner_photo = $a->page_contact['thumb'];
727                                         $this->owner_name = $a->page_contact['name'];
728                                         $this->wall_to_wall = true;
729                                 }
730                                 else if($this->get_data_value('owner-link')) {
731
732                                         $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
733                                         $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
734                                         $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name'));
735
736                                         if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
737
738                                                 // The author url doesn't match the owner (typically the contact)
739                                                 // and also doesn't match the contact alias. 
740                                                 // The name match is a hack to catch several weird cases where URLs are 
741                                                 // all over the park. It can be tricked, but this prevents you from
742                                                 // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
743                                                 // well that it's the same Bob Smith. 
744
745                                                 // But it could be somebody else with the same name. It just isn't highly likely. 
746
747
748                                                 $this->owner_photo = $this->get_data_value('owner-avatar');
749                                                 $this->owner_name = $this->get_data_value('owner-name');
750                                                 $this->wall_to_wall = true;
751                                                 // If it is our contact, use a friendly redirect link
752                                                 if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) 
753                                                         && ($this->get_data_value('network') === NETWORK_DFRN)) {
754                                                         $this->owner_url = $this->get_redirect_url();
755                                                 }
756                                                 else
757                                                         $this->owner_url = zrl($this->get_data_value('owner-link'));
758                                         }
759                                 }
760                         }
761                 }
762
763                 if(!$this->wall_to_wall) {
764                         $this->set_template('wall');
765                         $this->owner_url = '';
766                         $this->owner_photo = '';
767                         $this->owner_name = '';
768                 }
769         }
770
771         private function is_wall_to_wall() {
772                 return $this->wall_to_wall;
773         }
774
775         private function get_owner_url() {
776                 return $this->owner_url;
777         }
778
779         private function get_owner_photo() {
780                 return $this->owner_photo;
781         }
782
783         private function get_owner_name() {
784                 return $this->owner_name;
785         }
786
787         private function is_visiting() {
788                 return $this->visiting;
789         }
790
791
792
793
794 }
795 ?>