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