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