Exemplo n.º 1
0
 public function deleteOrphans()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // Check permissions
     $user = JFactory::getUser();
     if (!$user->authorise('k2.tags.manage', 'com_k2')) {
         K2Response::throwError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'));
     }
     // Get model
     $model = K2Model::getInstance('Tags');
     $model->deleteOrphans();
     $application = JFactory::getApplication();
     $application->enqueueMessage(JText::_('K2_DELETE_COMPLETED'));
     echo json_encode(K2Response::render());
     return $this;
 }
Exemplo n.º 2
0
 public function resetHits()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // User
     $user = JFactory::getUser();
     // Item
     $application = JFactory::getApplication();
     $id = $application->input->get('id');
     $item = K2Items::getInstance($id);
     if (!$item->canEdit) {
         K2Response::throwError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'), 403);
     }
     $statistics = K2Model::getInstance('Statistics');
     $statistics->resetItemHitsCounter($item->id);
     echo json_encode(K2Response::render());
     return $this;
 }
Exemplo n.º 3
0
 public function report()
 {
     // Check for token
     JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $id = $application->input->get('id', 0, 'int');
     // Get model
     $model = K2Model::getInstance('Users');
     $model->setState('id', $id);
     $model->report();
     if (!$model->report()) {
         K2Response::throwError($model->getError());
     }
     // Response
     echo json_encode(K2Response::render());
     // Return
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Renders the response object into JSON.
  * Usually there will be no need to override this function.
  *
  * @return void
  */
 protected function render()
 {
     // Unset not used states
     unset($this->userStates['page']);
     unset($this->userStates['limit']);
     unset($this->userStates['limitstart']);
     unset($this->userStates['persist']);
     // Pass the states to the response
     K2Response::setStates($this->userStates);
     // Render
     K2Response::render();
 }
Exemplo n.º 5
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;
 }