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