Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

787 lines
23 KiB

9 years ago
9 years ago
  1. <?php
  2. if(class_exists('Item'))
  3. return;
  4. require_once('object/BaseObject.php');
  5. require_once('include/text.php');
  6. require_once('boot.php');
  7. /**
  8. * An item
  9. */
  10. class Item extends BaseObject {
  11. private $data = array();
  12. private $template = null;
  13. private $available_templates = array(
  14. 'wall' => 'wall_thread.tpl',
  15. 'wall2wall' => 'wallwall_thread.tpl'
  16. );
  17. private $comment_box_template = 'comment_item.tpl';
  18. private $toplevel = false;
  19. private $writable = false;
  20. private $children = array();
  21. private $parent = null;
  22. private $conversation = null;
  23. private $redirect_url = null;
  24. private $owner_url = '';
  25. private $owner_photo = '';
  26. private $owner_name = '';
  27. private $wall_to_wall = false;
  28. private $threaded = false;
  29. private $visiting = false;
  30. public function __construct($data) {
  31. $a = $this->get_app();
  32. $this->data = $data;
  33. $this->set_template('wall');
  34. $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
  35. if(is_array($_SESSION['remote'])) {
  36. foreach($_SESSION['remote'] as $visitor) {
  37. if($visitor['cid'] == $this->get_data_value('contact-id')) {
  38. $this->visiting = true;
  39. break;
  40. }
  41. }
  42. }
  43. $this->writable = ($this->get_data_value('writable') || $this->get_data_value('self'));
  44. $ssl_state = ((local_user()) ? true : false);
  45. $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ;
  46. if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel())
  47. $this->threaded = true;
  48. // Prepare the children
  49. if(count($data['children'])) {
  50. foreach($data['children'] as $item) {
  51. /*
  52. * Only add will be displayed
  53. */
  54. if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
  55. continue;
  56. }
  57. if(! visible_activity($item)) {
  58. continue;
  59. }
  60. $item['pagedrop'] = $data['pagedrop'];
  61. $child = new Item($item);
  62. $this->add_child($child);
  63. }
  64. }
  65. }
  66. /**
  67. * Get data in a form usable by a conversation template
  68. *
  69. * Returns:
  70. * _ The data requested on success
  71. * _ false on failure
  72. */
  73. public function get_template_data($alike, $dlike, $thread_level=1) {
  74. require_once("mod/proxy.php");
  75. $result = array();
  76. $a = $this->get_app();
  77. $item = $this->get_data();
  78. $edited = false;
  79. if (strcmp($item['created'], $item['edited'])<>0) {
  80. $edited = array(
  81. 'label' => t('This entry was edited'),
  82. 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
  83. 'relative' => relative_date($item['edited'])
  84. );
  85. }
  86. $commentww = '';
  87. $sparkle = '';
  88. $buttons = '';
  89. $dropping = false;
  90. $star = false;
  91. $ignore = false;
  92. $isstarred = "unstarred";
  93. $indent = '';
  94. $shiny = '';
  95. $osparkle = '';
  96. $total_children = $this->count_descendants();
  97. $conv = $this->get_conversation();
  98. $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
  99. || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
  100. ? t('Private Message')
  101. : false);
  102. $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false);
  103. if(local_user() && link_compare($a->contact['url'],$item['author-link']))
  104. $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
  105. else
  106. $edpost = false;
  107. if(($this->get_data_value('uid') == local_user()) || $this->is_visiting())
  108. $dropping = true;
  109. $drop = array(
  110. 'dropping' => $dropping,
  111. 'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''),
  112. 'select' => t('Select'),
  113. 'delete' => t('Delete'),
  114. );
  115. $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false);
  116. $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
  117. $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
  118. if($item['author-link'] && (! $item['author-name']))
  119. $profile_name = $item['author-link'];
  120. $sp = false;
  121. $profile_link = best_link_url($item,$sp);
  122. if($profile_link === 'mailbox')
  123. $profile_link = '';
  124. if($sp)
  125. $sparkle = ' sparkle';
  126. else
  127. $profile_link = zrl($profile_link);
  128. $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
  129. if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
  130. $profile_avatar = $a->contacts[$normalised]['thumb'];
  131. else
  132. $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_data_value('thumb')));
  133. $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
  134. call_hooks('render_location',$locate);
  135. $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate));
  136. $searchpath = $a->get_baseurl()."/search?tag=";
  137. $tags=array();
  138. $hashtags = array();
  139. $mentions = array();
  140. /*foreach(explode(',',$item['tag']) as $tag){
  141. $tag = trim($tag);
  142. if ($tag!="") {
  143. $t = bbcode($tag);
  144. $tags[] = $t;
  145. if($t[0] == '#')
  146. $hashtags[] = $t;
  147. elseif($t[0] == '@')
  148. $mentions[] = $t;
  149. }
  150. }*/
  151. $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
  152. $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
  153. /*
  154. * We should avoid doing this all the time, but it depends on the conversation mode
  155. * And the conv mode may change when we change the conv, or it changes its mode
  156. * Maybe we should establish a way to be notified about conversation changes
  157. */
  158. $this->check_wall_to_wall();
  159. if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url()))
  160. $osparkle = ' sparkle';
  161. if($this->is_toplevel()) {
  162. if($conv->get_profile_owner() == local_user()) {
  163. $isstarred = (($item['starred']) ? "starred" : "unstarred");
  164. $star = array(
  165. 'do' => t("add star"),
  166. 'undo' => t("remove star"),
  167. 'toggle' => t("toggle star status"),
  168. 'classdo' => (($item['starred']) ? "hidden" : ""),
  169. 'classundo' => (($item['starred']) ? "" : "hidden"),
  170. 'starred' => t('starred'),
  171. );
  172. $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
  173. intval($item['uid']),
  174. intval($item['id'])
  175. );
  176. if (count($r)) {
  177. $ignore = array(
  178. 'do' => t("ignore thread"),
  179. 'undo' => t("unignore thread"),
  180. 'toggle' => t("toggle ignore status"),
  181. 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
  182. 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
  183. 'ignored' => t('ignored'),
  184. );
  185. }
  186. $tagger = '';
  187. if(feature_enabled($conv->get_profile_owner(),'commtag')) {
  188. $tagger = array(
  189. 'add' => t("add tag"),
  190. 'class' => "",
  191. );
  192. }
  193. }
  194. } else {
  195. $indent = 'comment';
  196. }
  197. if($conv->is_writable()) {
  198. $buttons = array(
  199. 'like' => array( t("I like this \x28toggle\x29"), t("like")),
  200. 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''),
  201. );
  202. if ($shareable) $buttons['share'] = array( t('Share this'), t('share'));
  203. }
  204. if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){
  205. $shiny = 'shiny';
  206. }
  207. localize_item($item);
  208. if ($item["postopts"] and !get_config("system", "suppress_language")) {
  209. //$langdata = explode(";", $item["postopts"]);
  210. //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
  211. $langstr = "";
  212. if (substr($item["postopts"], 0, 5) == "lang=") {
  213. $postopts = substr($item["postopts"], 5);
  214. $languages = explode(":", $postopts);
  215. if (sizeof($languages) == 1) {
  216. $languages = array();
  217. $languages[] = $postopts;
  218. }
  219. foreach ($languages as $language) {
  220. $langdata = explode(";", $language);
  221. if ($langstr != "")
  222. $langstr .= ", ";
  223. //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
  224. $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0];
  225. }
  226. }
  227. }
  228. $body = prepare_body($item,true);
  229. list($categories, $folders) = get_cats_and_terms($item);
  230. if($a->theme['template_engine'] === 'internal') {
  231. $body_e = template_escape($body);
  232. $text_e = strip_tags(template_escape($body));
  233. $name_e = template_escape($profile_name);
  234. $title_e = template_escape($item['title']);
  235. $location_e = template_escape($location);
  236. $owner_name_e = template_escape($this->get_owner_name());
  237. }
  238. else {
  239. $body_e = $body;
  240. $text_e = strip_tags($body);
  241. $name_e = $profile_name;
  242. $title_e = $item['title'];
  243. $location_e = $location;
  244. $owner_name_e = $this->get_owner_name();
  245. }
  246. // Disable features that aren't available in several networks
  247. if (($item["item_network"] != "dfrn") AND isset($buttons["dislike"])) {
  248. unset($buttons["dislike"]);
  249. $tagger = '';
  250. }
  251. if (($item["item_network"] == "feed") AND isset($buttons["like"]))
  252. unset($buttons["like"]);
  253. if (($item["item_network"] == "mail") AND isset($buttons["like"]))
  254. unset($buttons["like"]);
  255. if (($item["item_network"] == "dspr") AND ($indent == 'comment') AND isset($buttons["like"]))
  256. unset($buttons["like"]);
  257. // Facebook can like comments - but it isn't programmed in the connector yet.
  258. if (($item["item_network"] == "face") AND ($indent == 'comment') AND isset($buttons["like"]))
  259. unset($buttons["like"]);
  260. $tmp_item = array(
  261. 'template' => $this->get_template(),
  262. 'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
  263. 'tags' => $item['tags'],
  264. 'hashtags' => $item['hashtags'],
  265. 'mentions' => $item['mentions'],
  266. 'txt_cats' => t('Categories:'),
  267. 'txt_folders' => t('Filed under:'),
  268. 'has_cats' => ((count($categories)) ? 'true' : ''),
  269. 'has_folders' => ((count($folders)) ? 'true' : ''),
  270. 'categories' => $categories,
  271. 'folders' => $folders,
  272. 'body' => $body_e,
  273. 'text' => $text_e,
  274. 'id' => $this->get_id(),
  275. 'guid' => $item['guid'],
  276. 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
  277. 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $this->get_owner_name(), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
  278. 'to' => t('to'),
  279. 'via' => t('via'),
  280. 'wall' => t('Wall-to-Wall'),
  281. 'vwall' => t('via Wall-To-Wall:'),
  282. 'profile_url' => $profile_link,
  283. 'item_photo_menu' => item_photo_menu($item),
  284. 'name' => $name_e,
  285. 'thumb' => proxy_url($profile_avatar),
  286. 'osparkle' => $osparkle,
  287. 'sparkle' => $sparkle,
  288. 'title' => $title_e,
  289. 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
  290. 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
  291. 'app' => $item['app'],
  292. 'created' => relative_date($item['created']),
  293. 'lock' => $lock,
  294. 'location' => $location_e,
  295. 'indent' => $indent,
  296. 'shiny' => $shiny,
  297. 'owner_url' => $this->get_owner_url(),
  298. 'owner_photo' => proxy_url($this->get_owner_photo()),
  299. 'owner_name' => $owner_name_e,
  300. 'plink' => get_plink($item),
  301. 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
  302. 'isstarred' => $isstarred,
  303. 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
  304. 'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''),
  305. 'tagger' => $tagger,
  306. 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
  307. 'drop' => $drop,
  308. 'vote' => $buttons,
  309. 'like' => $like,
  310. 'dislike' => $dislike,
  311. 'switchcomment' => t('Comment'),
  312. 'comment' => $this->get_comment_box($indent),
  313. 'previewing' => ($conv->is_preview() ? ' preview ' : ''),
  314. 'wait' => t('Please wait'),
  315. 'thread_level' => $thread_level,
  316. 'postopts' => $langstr,
  317. 'edited' => $edited,
  318. 'network' => $item["item_network"],
  319. 'network_name' => network_to_name($item['item_network']),
  320. );
  321. $arr = array('item' => $item, 'output' => $tmp_item);
  322. call_hooks('display_item', $arr);
  323. $result = $arr['output'];
  324. $result['children'] = array();
  325. $children = $this->get_children();
  326. $nb_children = count($children);
  327. if($nb_children > 0) {
  328. foreach($children as $child) {
  329. $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1);
  330. }
  331. // Collapse
  332. if(($nb_children > 2) || ($thread_level > 1)) {
  333. $result['children'][0]['comment_firstcollapsed'] = true;
  334. $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
  335. $result['children'][0]['hidden_comments_num'] = $total_children;
  336. $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
  337. $result['children'][0]['hide_text'] = t('show more');
  338. if($thread_level > 1) {
  339. $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
  340. }
  341. else {
  342. $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
  343. }
  344. }
  345. }
  346. if ($this->is_toplevel()) {
  347. $result['total_comments_num'] = "$total_children";
  348. $result['total_comments_text'] = tt('comment', 'comments', $total_children);
  349. }
  350. $result['private'] = $item['private'];
  351. $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
  352. if($this->is_threaded()) {
  353. $result['flatten'] = false;
  354. $result['threaded'] = true;
  355. }
  356. else {
  357. $result['flatten'] = true;
  358. $result['threaded'] = false;
  359. }
  360. return $result;
  361. }
  362. public function get_id() {
  363. return $this->get_data_value('id');
  364. }
  365. public function is_threaded() {
  366. return $this->threaded;
  367. }
  368. /**
  369. * Add a child item
  370. */
  371. public function add_child($item) {
  372. $item_id = $item->get_id();
  373. if(!$item_id) {
  374. logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
  375. return false;
  376. }
  377. if($this->get_child($item->get_id())) {
  378. logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
  379. return false;
  380. }
  381. /*
  382. * Only add what will be displayed
  383. */
  384. if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
  385. return false;
  386. }
  387. if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
  388. return false;
  389. }
  390. $item->set_parent($this);
  391. $this->children[] = $item;
  392. return end($this->children);
  393. }
  394. /**
  395. * Get a child by its ID
  396. */
  397. public function get_child($id) {
  398. foreach($this->get_children() as $child) {
  399. if($child->get_id() == $id)
  400. return $child;
  401. }
  402. return null;
  403. }
  404. /**
  405. * Get all ou children
  406. */
  407. public function get_children() {
  408. return $this->children;
  409. }
  410. /**
  411. * Set our parent
  412. */
  413. protected function set_parent($item) {
  414. $parent = $this->get_parent();
  415. if($parent) {
  416. $parent->remove_child($this);
  417. }
  418. $this->parent = $item;
  419. $this->set_conversation($item->get_conversation());
  420. }
  421. /**
  422. * Remove our parent
  423. */
  424. protected function remove_parent() {
  425. $this->parent = null;
  426. $this->conversation = null;
  427. }
  428. /**
  429. * Remove a child
  430. */
  431. public function remove_child($item) {
  432. $id = $item->get_id();
  433. foreach($this->get_children() as $key => $child) {
  434. if($child->get_id() == $id) {
  435. $child->remove_parent();
  436. unset($this->children[$key]);
  437. // Reindex the array, in order to make sure there won't be any trouble on loops using count()
  438. $this->children = array_values($this->children);
  439. return true;
  440. }
  441. }
  442. logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG);
  443. return false;
  444. }
  445. /**
  446. * Get parent item
  447. */
  448. protected function get_parent() {
  449. return $this->parent;
  450. }
  451. /**
  452. * set conversation
  453. */
  454. public function set_conversation($conv) {
  455. $previous_mode = ($this->conversation ? $this->conversation->get_mode() : '');
  456. $this->conversation = $conv;
  457. // Set it on our children too
  458. foreach($this->get_children() as $child)
  459. $child->set_conversation($conv);
  460. }
  461. /**
  462. * get conversation
  463. */
  464. public function get_conversation() {
  465. return $this->conversation;
  466. }
  467. /**
  468. * Get raw data
  469. *
  470. * We shouldn't need this
  471. */
  472. public function get_data() {
  473. return $this->data;
  474. }
  475. /**
  476. * Get a data value
  477. *
  478. * Returns:
  479. * _ value on success
  480. * _ false on failure
  481. */
  482. public function get_data_value($name) {
  483. if(!isset($this->data[$name])) {
  484. // logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
  485. return false;
  486. }
  487. return $this->data[$name];
  488. }
  489. /**
  490. * Set template
  491. */
  492. private function set_template($name) {
  493. $a = get_app();
  494. if(!x($this->available_templates, $name)) {
  495. logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG);
  496. return false;
  497. }
  498. $this->template = $this->available_templates[$name];
  499. }
  500. /**
  501. * Get template
  502. */
  503. private function get_template() {
  504. return $this->template;
  505. }
  506. /**
  507. * Check if this is a toplevel post
  508. */
  509. private function is_toplevel() {
  510. return $this->toplevel;
  511. }
  512. /**
  513. * Check if this is writable
  514. */
  515. private function is_writable() {
  516. $conv = $this->get_conversation();
  517. if($conv) {
  518. // This will allow us to comment on wall-to-wall items owned by our friends
  519. // and community forums even if somebody else wrote the post.
  520. // bug #517 - this fixes for conversation owner
  521. if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user())
  522. return true;
  523. // this fixes for visitors
  524. return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
  525. }
  526. return $this->writable;
  527. }
  528. /**
  529. * Count the total of our descendants
  530. */
  531. private function count_descendants() {
  532. $children = $this->get_children();
  533. $total = count($children);
  534. if($total > 0) {
  535. foreach($children as $child) {
  536. $total += $child->count_descendants();
  537. }
  538. }
  539. return $total;
  540. }
  541. /**
  542. * Get the template for the comment box
  543. */
  544. private function get_comment_box_template() {
  545. return $this->comment_box_template;
  546. }
  547. /**
  548. * Get the comment box
  549. *
  550. * Returns:
  551. * _ The comment box string (empty if no comment box)
  552. * _ false on failure
  553. */
  554. private function get_comment_box($indent) {
  555. $a = $this->get_app();
  556. if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) {
  557. return '';
  558. }
  559. $comment_box = '';
  560. $conv = $this->get_conversation();
  561. $template = get_markup_template($this->get_comment_box_template());
  562. $ww = '';
  563. if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
  564. $ww = 'ww';
  565. if($conv->is_writable() && $this->is_writable()) {
  566. $qc = $qcomment = null;
  567. /*
  568. * Hmmm, code depending on the presence of a particular plugin?
  569. * This should be better if done by a hook
  570. */
  571. if(in_array('qcomment',$a->plugins)) {
  572. $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
  573. $qcomment = (($qc) ? explode("\n",$qc) : null);
  574. }
  575. $comment_box = replace_macros($template,array(
  576. '$return_path' => $a->query_string,
  577. '$threaded' => $this->is_threaded(),
  578. // '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
  579. '$jsreload' => '',
  580. '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
  581. '$id' => $this->get_id(),
  582. '$parent' => $this->get_id(),
  583. '$qcomment' => $qcomment,
  584. '$profile_uid' => $conv->get_profile_owner(),
  585. '$mylink' => $a->contact['url'],
  586. '$mytitle' => t('This is you'),
  587. '$myphoto' => $a->contact['thumb'],
  588. '$comment' => t('Comment'),
  589. '$submit' => t('Submit'),
  590. '$edbold' => t('Bold'),
  591. '$editalic' => t('Italic'),
  592. '$eduline' => t('Underline'),
  593. '$edquote' => t('Quote'),
  594. '$edcode' => t('Code'),
  595. '$edimg' => t('Image'),
  596. '$edurl' => t('Link'),
  597. '$edvideo' => t('Video'),
  598. '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''),
  599. '$indent' => $indent,
  600. '$sourceapp' => t($a->sourcename),
  601. '$ww' => (($conv->get_mode() === 'network') ? $ww : ''),
  602. '$rand_num' => random_digits(12)
  603. ));
  604. }
  605. return $comment_box;
  606. }
  607. private function get_redirect_url() {
  608. return $this->redirect_url;
  609. }
  610. /**
  611. * Check if we are a wall to wall item and set the relevant properties
  612. */
  613. protected function check_wall_to_wall() {
  614. $a = $this->get_app();
  615. $conv = $this->get_conversation();
  616. $this->wall_to_wall = false;
  617. if($this->is_toplevel()) {
  618. if($conv->get_mode() !== 'profile') {
  619. if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
  620. // On the network page, I am the owner. On the display page it will be the profile owner.
  621. // This will have been stored in $a->page_contact by our calling page.
  622. // Put this person as the wall owner of the wall-to-wall notice.
  623. $this->owner_url = zrl($a->page_contact['url']);
  624. $this->owner_photo = $a->page_contact['thumb'];
  625. $this->owner_name = $a->page_contact['name'];
  626. $this->wall_to_wall = true;
  627. }
  628. else if($this->get_data_value('owner-link')) {
  629. $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
  630. $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
  631. $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name'));
  632. if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
  633. // The author url doesn't match the owner (typically the contact)
  634. // and also doesn't match the contact alias.
  635. // The name match is a hack to catch several weird cases where URLs are
  636. // all over the park. It can be tricked, but this prevents you from
  637. // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
  638. // well that it's the same Bob Smith.
  639. // But it could be somebody else with the same name. It just isn't highly likely.
  640. $this->owner_photo = $this->get_data_value('owner-avatar');
  641. $this->owner_name = $this->get_data_value('owner-name');
  642. $this->wall_to_wall = true;
  643. // If it is our contact, use a friendly redirect link
  644. if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url')))
  645. && ($this->get_data_value('network') === NETWORK_DFRN)) {
  646. $this->owner_url = $this->get_redirect_url();
  647. }
  648. else
  649. $this->owner_url = zrl($this->get_data_value('owner-link'));
  650. }
  651. }
  652. }
  653. }
  654. if(!$this->wall_to_wall) {
  655. $this->set_template('wall');
  656. $this->owner_url = '';
  657. $this->owner_photo = '';
  658. $this->owner_name = '';
  659. }
  660. }
  661. private function is_wall_to_wall() {
  662. return $this->wall_to_wall;
  663. }
  664. private function get_owner_url() {
  665. return $this->owner_url;
  666. }
  667. private function get_owner_photo() {
  668. return $this->owner_photo;
  669. }
  670. private function get_owner_name() {
  671. return $this->owner_name;
  672. }
  673. private function is_visiting() {
  674. return $this->visiting;
  675. }
  676. }
  677. ?>