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.
 
 
 
 
 
 

815 lines
25 KiB

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