X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObject%2FPost.php;h=847135d3621bf10945d71a652e694c4b9faa4a8f;hb=f40c57fc204ff47a3cf9f7eab75e8a635566275c;hp=8aae024ffbc7863b786383388102d50e22a730c6;hpb=6538a8eaca3224ce563b4f242dab6cda971e72d3;p=friendica.git diff --git a/src/Object/Post.php b/src/Object/Post.php index 8aae024ffb..847135d362 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -8,6 +8,7 @@ use Friendica\BaseObject; use Friendica\Content\ContactSelector; use Friendica\Core\Addon; use Friendica\Core\Config; +use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\PConfig; @@ -15,7 +16,6 @@ use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\Model\Contact; -use Friendica\Model\Conversation; use Friendica\Model\Item; use Friendica\Model\Term; use Friendica\Util\Crypto; @@ -60,6 +60,7 @@ class Post extends BaseObject * Constructor * * @param array $data data array + * @throws \Exception */ public function __construct(array $data) { @@ -115,6 +116,8 @@ class Post extends BaseObject * * @return mixed The data requested on success * false on failure + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException */ public function getTemplateData(array $conv_responses, $thread_level = 1) { @@ -229,7 +232,7 @@ class Post extends BaseObject } $locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => '']; - Addon::callHooks('render_location', $locate); + Hook::callAll('render_location', $locate); $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); // process action responses - e.g. like/dislike/attend/agree/whatever @@ -247,7 +250,7 @@ class Post extends BaseObject } } - $responses = get_responses($conv_responses, $response_verbs, $this, $item); + $responses = get_responses($conv_responses, $response_verbs, $item, $this); foreach ($response_verbs as $value => $verbs) { $responses[$verbs]['output'] = !empty($conv_responses[$verbs][$item['uri']]) ? format_like($conv_responses[$verbs][$item['uri']], $conv_responses[$verbs][$item['uri'] . '-l'], $verbs, $item['uri']) : ''; @@ -433,7 +436,7 @@ class Post extends BaseObject ]; $arr = ['item' => $item, 'output' => $tmp_item]; - Addon::callHooks('display_item', $arr); + Hook::callAll('display_item', $arr); $result = $arr['output']; @@ -500,6 +503,7 @@ class Post extends BaseObject * @param Post $item The child item to add * * @return mixed + * @throws \Exception */ public function addChild(Post $item) { @@ -589,6 +593,7 @@ class Post extends BaseObject * @param Post $item The child to be removed * * @return boolean Success or failure + * @throws \Exception */ public function removeChild(Post $item) { @@ -678,6 +683,7 @@ class Post extends BaseObject * * @param string $name template name * @return bool + * @throws \Exception */ private function setTemplate($name) { @@ -762,6 +768,44 @@ class Post extends BaseObject return $this->comment_box_template; } + /** + * Get default text for the comment box + * + * @return string + */ + private function getDefaultText() + { + if (!local_user()) { + return; + } + + $a = self::getApp(); + + $item = Item::selectFirst(['author-addr'], ['id' => $this->getId()]); + if (!DBA::isResult($item) || empty($item['author-addr'])) { + // Should not happen + return ''; + } + + if ($item['author-addr'] != $a->profile['addr']) { + $text = '@' . $item['author-addr'] . ' '; + } else { + $text = ''; + } + + $terms = Term::tagArrayFromItemId($this->getId(), TERM_MENTION); + + foreach ($terms as $term) { + $profile = Contact::getDetailsByURL($term['url']); + if (!empty($profile['addr']) && ($profile['contact-type'] != Contact::TYPE_COMMUNITY) && + ($profile['addr'] != $a->profile['addr']) && !strstr($text, $profile['addr'])) { + $text .= '@' . $profile['addr'] . ' '; + } + } + + return $text; + } + /** * Get the comment box * @@ -769,6 +813,7 @@ class Post extends BaseObject * * @return mixed The comment box string (empty if no comment box) * false on failure + * @throws \Exception */ private function getCommentBox($indent) { @@ -782,7 +827,7 @@ class Post extends BaseObject } if ($conv->isWritable() && $this->isWritable()) { - $qc = $qcomment = null; + $qcomment = null; /* * Hmmm, code depending on the presence of a particular addon? @@ -797,6 +842,8 @@ class Post extends BaseObject $uid = $conv->getProfileOwner(); $parent_uid = $this->getDataValue('uid'); + $default_text = $this->getDefaultText(); + if (!is_null($parent_uid) && ($uid != $parent_uid)) { $uid = $parent_uid; } @@ -810,6 +857,7 @@ class Post extends BaseObject '$id' => $this->getId(), '$parent' => $this->getId(), '$qcomment' => $qcomment, + '$default' => $default_text, '$profile_uid' => $uid, '$mylink' => $a->removeBaseURL($a->contact['url']), '$mytitle' => L10n::t('This is you'), @@ -848,6 +896,7 @@ class Post extends BaseObject * Check if we are a wall to wall item and set the relevant properties * * @return void + * @throws \Exception */ protected function checkWallToWall() {