if ($comment->isNew()) { $comment->set('parent', Request::getInt('commentreply', 0)); $comment->set('created_by', !User::isGuest() ? User::get('id') : 0); $comment->set('anonymous', !User::isGuest() ? 0 : 1); } ?> <img src="<?php echo $comment->creator->picture($comment->get('anonymous')); ?> " alt="" /> </p> <fieldset> <?php if (!User::isGuest()) { if ($replyto = Request::getInt('commentreply', 0)) { $reply = \Plugins\Hubzero\Comments\Models\Comment::oneOrNew($replyto); $name = Lang::txt('COM_KB_ANONYMOUS'); if (!$reply->get('anonymous')) { $name = $this->escape(stripslashes($repy->creator->get('name'))); if (in_array($reply->creator->get('access'), User::getAuthorisedViewLevels())) { $name = '<a href="' . Route::url($reply->creator->link()) . '">' . $name . '</a>'; } } ?> <blockquote cite="c<?php echo $reply->get('id'); ?> "> <p> <strong><?php echo $name;
/** * Display a feed of comments * * @return void */ protected function _feed() { if (!$this->params->get('comments_feeds')) { $this->action = 'view'; $this->_view(); return; } // Set the mime encoding for the document Document::setType('feed'); $title = $this->obj->get('title'); // Start a new feed object $doc = Document::instance(); $doc->link = Route::url($this->url); $doc->title = Config::get('sitename') . ' - ' . Lang::txt(strtoupper($this->_option)); $doc->title .= $title ? ': ' . stripslashes($title) : ''; $doc->title .= ': ' . Lang::txt('PLG_HUBZERO_COMMENTS'); $doc->description = Lang::txt('PLG_HUBZERO_COMMENTS_RSS_DESCRIPTION', Config::get('sitename'), stripslashes($title)); $doc->copyright = Lang::txt('PLG_HUBZERO_COMMENTS_RSS_COPYRIGHT', date("Y"), Config::get('sitename')); $comments = \Plugins\Hubzero\Comments\Models\Comment::all()->whereEquals('item_type', $this->obj_type)->whereEquals('item_id', $this->obj_id)->whereEquals('parent', 0)->limit($this->params->get('display_limit', 25))->ordered()->paginated()->rows(); // Start outputing results if any found foreach ($comments as $row) { // URL link to article $link = Route::url('index.php?option=' . $this->_option . '§ion=' . $section->alias . '&category=' . $category->alias . '&alias=' . $entry->alias . '#c' . $row->id); $author = Lang::txt('PLG_HUBZERO_COMMENTS_ANONYMOUS'); if (!$row->get('anonymous')) { $author = $row->creator->get('name'); } // Prepare the title $title = Lang::txt('PLG_HUBZERO_COMMENTS_COMMENT_BY', $author) . ' @ ' . $row->created('time') . ' on ' . $row->created('date'); // Strip html from feed item description text if ($row->isReported()) { $description = Lang::txt('PLG_HUBZERO_COMMENTS_REPORTED_AS_ABUSIVE'); } else { $description = strip_tags($row->content); } @($date = $row->created() ? date('r', strtotime($row->created())) : ''); // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; $item->category = ''; $item->author = $author; // Loads item info into rss array $doc->addItem($item); // Check for any replies foreach ($row->replies()->rows() as $reply) { // URL link to article $link = Route::url('index.php?option=' . $this->_option . '§ion=' . $section->alias . '&category=' . $category->alias . '&alias=' . $entry->alias . '#c' . $reply->id); $author = Lang::txt('PLG_HUBZERO_COMMENTS_ANONYMOUS'); if (!$reply->anonymous) { $author = $reply->creator->get('name'); } // Prepare the title $title = Lang::txt('PLG_HUBZERO_COMMENTS_REPLY_TO_COMMENT', $row->id, $author) . ' @ ' . Date::of($reply->created)->toLocal(Lang::txt('TIME_FORMAT_HZ1')) . ' ' . Lang::txt('PLG_HUBZERO_COMMENTS_ON') . ' ' . Date::of($reply->created)->toLocal(Lang::txt('DATE_FORMAT_HZ1')); // Strip html from feed item description text if ($reply->reports) { $description = Lang::txt('PLG_HUBZERO_COMMENTS_REPORTED_AS_ABUSIVE'); } else { $description = is_object($p) ? $p->parse(stripslashes($reply->content)) : nl2br(stripslashes($reply->content)); } $description = html_entity_decode(\Hubzero\Utility\Sanitize::clean($description)); @($date = $reply->created ? gmdate('r', strtotime($reply->created)) : ''); // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; $item->category = ''; $item->author = $author; // Loads item info into rss array $doc->addItem($item); foreach ($reply->replies()->rows() as $response) { // URL link to article $link = Route::url('index.php?option=' . $this->_option . '§ion=' . $section->alias . '&category=' . $category->alias . '&alias=' . $entry->alias . '#c' . $response->id); $author = Lang::txt('PLG_HUBZERO_COMMENTS_ANONYMOUS'); if (!$response->anonymous) { $author = $response->creator->get('name'); } // Prepare the title $title = Lang::txt('PLG_HUBZERO_COMMENTS_REPLY_TO_COMMENT', $reply->id, $author) . ' @ ' . Date::of($response->created)->toLocal(Lang::txt('TIME_FORMAT_HZ1')) . ' ' . Lang::txt('PLG_HUBZERO_COMMENTS_ON') . ' ' . Date::of($response->created)->toLocal(Lang::txt('DATE_FORMAT_HZ1')); // Strip html from feed item description text if ($response->reports) { $description = Lang::txt('PLG_HUBZERO_COMMENTS_REPORTED_AS_ABUSIVE'); } else { $description = nl2br(stripslashes($response->content)); } $description = html_entity_decode(\Hubzero\Utility\Sanitize::clean($description)); @($date = $response->created ? gmdate('r', strtotime($response->created)) : ''); // Load individual item creator class $item = new \Hubzero\Document\Type\Feed\Item(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; $item->category = ''; $item->author = $author; // Loads item info into rss array $doc->addItem($item); } } } // Output the feed echo $doc->render(); }
/** * Get a list or count of comments * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function replies($rtrn = 'list', $filters = array(), $clear = false) { if (!isset($filters['parent']) && $this->exists()) { $filters['parent'] = $this->get('id'); } if (!isset($filters['item_type'])) { $filters['item_type'] = $this->get('item_type'); } if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('item_id'); } if (!isset($filters['state'])) { $filters['state'] = array(1, 3); } switch (strtolower($rtrn)) { case 'count': if (!is_numeric($this->get('replies.count')) || $clear) { $total = 0; foreach ($this->replies() as $com) { // Increment for this comment $total++; // Add the comment's replies to the total $total = $total + $com->replies('count'); } $this->set('replies.count', $total); } return $this->get('replies.count'); break; case 'list': case 'results': default: if (!$this->get('replies') instanceof ItemList || $clear) { $results = $this->get('replies'); if (!$results) { $results = $this->_tbl->find($filters); if ($results) { $children = array(0 => array()); $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit']; foreach ($results as $v) { $v = new Comment($v); $pt = $v->get('parent'); $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } $results = $this->_treeRecurse($children[0], $children); } else { $results = array(); } } $this->set('replies', new ItemList($results)); } return $this->get('replies'); break; } }