Ejemplo n.º 1
0
 /**
  * Prepares the row for output
  *
  * @param string $mode	The mode for preparing data. 'site' for fron-end data, 'admin' for administrator operations.
  *
  * @return void
  */
 public function prepare($mode = null)
 {
     // Prepare generic properties like dates and authors
     parent::prepare($mode);
     // Prepare specific properties
     $this->editLink = JURI::base(true) . '/index.php?option=com_k2#comments/edit/' . $this->id;
     // Created date
     $this->createdOn = JHtml::_('date', $this->date, JText::_('K2_DATE_FORMAT'));
     // Get application
     $application = JFactory::getApplication();
     // Front-end only
     if ($application->isSite()) {
         // Get user
         $this->user = $this->getUser();
         // Edit permission
         $this->canEdit = K2Comments::getPermissions()->canEdit;
         // Report permission
         $user = JFactory::getUser();
         $this->canReport = K2Comments::getPermissions()->canReport && $user->id != $this->userId;
         // Report user permission
         $this->canReportUser = K2Comments::getPermissions()->canReportUser && $this->userId > 0 && $user->id != $this->userId;
         // Apply no-follow to all links
         $document = new DOMDocument();
         $document->loadHTML('<?xml encoding="UTF-8"><html><body>' . $this->text . '</body></html>');
         $links = $document->getElementsByTagName('a');
         foreach ($links as $link) {
             $link->setAttribute('rel', 'nofollow');
         }
         $this->text = $document->saveHTML($document->getElementsByTagName('body')->item(0));
         $this->text = str_replace(array('<body>', '</body>'), '', $this->text);
         // Item link
         $this->itemLink = $this->getItemLink();
         // Category link
         $this->categoryLink = $this->getCategoryLink();
         // Is Author response?
         $this->isAuthorResponse = $this->getIsAuthorResponse();
         // Unset sensitive data if user is not authorised to edit the comment
         if (!$this->canEdit) {
             unset($this->email);
             unset($this->ip);
             unset($this->hostname);
         }
     }
 }
Ejemplo n.º 2
0
 public function report()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // Get application
     $application = JFactory::getApplication();
     // Get configuration
     $configuration = JFactory::getConfig();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     $reportName = $application->input->get('reportName', '', 'string');
     $reportReason = $application->input->get('reportReason', '', 'string');
     // Get params
     $params = JComponentHelper::getParams('com_k2');
     // Get user
     $user = JFactory::getUser();
     // Check if user can report
     if (!$params->get('comments') || !$params->get('commentsReporting') || $params->get('commentsReporting') == '2' && $user->guest) {
         K2Response::throwError(JText::_('K2_ALERTNOTAUTH'), 403);
     }
     // Get comment
     $comment = K2Comments::getInstance($id);
     // Check comment is published
     if (!$comment->state) {
         K2Response::throwError(JText::_('K2_COMMENT_NOT_FOUND'));
     }
     // Get item
     $item = K2Items::getInstance($comment->itemId);
     // Check access to the item
     $item->checkSiteAccess();
     // Check input
     if (trim($reportName) == '') {
         K2Response::throwError(JText::_('K2_PLEASE_TYPE_YOUR_NAME'));
     }
     if (trim($reportReason) == '') {
         K2Response::throwError(JText::_('K2_PLEASE_TYPE_THE_REPORT_REASON'));
     }
     // Check captcha depending on settings
     require_once JPATH_SITE . '/components/com_k2/helpers/captcha.php';
     $data = $this->getInputData();
     if (!($result = K2HelperCaptcha::check($data, $this))) {
         K2Response::throwError($this->getError());
     }
     $mailer = JFactory::getMailer();
     $senderEmail = $configuration->get('mailfrom');
     $senderName = $configuration->get('fromname');
     $mailer->setSender(array($senderEmail, $senderName));
     $mailer->setSubject(JText::_('K2_COMMENT_REPORT'));
     $mailer->IsHTML(true);
     $body = "\n        <strong>" . JText::_('K2_NAME') . "</strong>: " . $reportName . " <br/>\n        <strong>" . JText::_('K2_REPORT_REASON') . "</strong>: " . $reportReason . " <br/>\n        <strong>" . JText::_('K2_COMMENT') . "</strong>: " . nl2br($comment->text) . " <br/>\n        ";
     $mailer->setBody($body);
     $mailer->ClearAddresses();
     $mailer->AddAddress($params->get('commentsReportRecipient', $configuration->get('mailfrom')));
     $mailer->Send();
     $application->enqueueMessage(JText::_('K2_REPORT_SUBMITTED'));
     echo json_encode(K2Response::render());
     return $this;
 }