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