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.
 
 
 
 
 
 

821 lines
24 KiB

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