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.

810 lines
25KB

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