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.
 
 
 
 
 
 

926 lines
26 KiB

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