Exemple #1
0
 /**
  *
  * If moderator then close it,
  * if Not moderator then if owner - request closing
  * of question
  *
  * @throws \Lampcms\AccessException
  * @return object $this
  */
 protected function setClosed()
 {
     try {
         $this->checkAccessPermission('close_question');
     } catch (\Lampcms\AccessException $e) {
         if (!\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw $e;
         }
         return $this->requestClose();
     }
     $reason = $this->Request['reason'] . '. ' . $this->Request['note'];
     d('reason: ' . $reason);
     $this->Question->setClosed($this->Registry->Viewer, $reason);
     $this->Registry->Dispatcher->post($this->Question, 'onQuestionClosed');
     return $this;
 }
 /**
  * Get array for this one question,
  * set $this->Question
  * and also set $this->aTplVars['body']
  * with parsed tplQuestion block
  *
  *
  * @throws Lampcms404Exception if question not found
  *
  * @return object $this
  */
 protected function getQuestion()
 {
     $isModerator = $this->Registry->Viewer->isModerator();
     $this->noComments = false === (bool) $this->Registry->Ini->MAX_COMMENTS;
     d('no comments: ' . $this->noComments);
     $aFields = $this->noComments || false === (bool) $this->Registry->Ini->SHOW_COMMENTS ? array('comments' => 0) : array();
     $this->aQuestion = $this->Registry->Mongo->QUESTIONS->findOne(array('_id' => (int) $this->Request['qid']), $aFields);
     /**
      * @todo Translate string
      */
     if (empty($this->aQuestion)) {
         throw new \Lampcms\Lampcms404Exception('Topic not found');
     }
     d('$this->aQuestion: ' . print_r($this->aQuestion, 1));
     /**
      * Only moderators can see ip address
      */
     if (!$isModerator && !empty($this->aQuestion['ip'])) {
         unset($this->aQuestion['ip']);
     }
     $deleted = !empty($this->aQuestion['i_del_ts']) ? ' deleted' : false;
     /**
      * Guests will have to see filtered
      * content
      */
     if (!$this->isLoggedIn()) {
         $this->aQuestion['b'] = Badwords::filter($this->aQuestion['b'], true);
     }
     $this->Question = new Question($this->Registry, $this->aQuestion);
     /**
      * @todo Translate string
      */
     if ($deleted) {
         if (!$isModerator && !\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw new \Lampcms\Lampcms404Exception('Topic was deleted on ' . date('F j Y', $this->aQuestion['i_del_ts']));
         }
         /**
          * If Viewer is moderator, then viewer
          * will be able to view deleted item
          * This will add 'deleted' class to question table
          */
         $this->aQuestion['deleted'] = $deleted;
         if (!empty($this->aQuestion['a_deleted'])) {
             $this->aQuestion['deletedby'] = \tplDeletedby::parse($this->aQuestion['a_deleted'], false);
             d('deletedby: ' . $this->aQuestion['deletedby']);
         }
     }
     if ($this->noComments) {
         $this->aQuestion['nocomments'] = ' nocomments';
     }
     $this->aQuestion['add_comment'] = $this->_('add comment');
     $this->aQuestion['reply'] = $this->_('Reply');
     $this->aQuestion['reply_t'] = $this->_('Reply to this comment');
     $this->aQuestion['edited'] = $this->_('Edited');
     $breadcrumb = empty($this->aQuestion['i_cat']) ? '' : $this->getBreadcrumb($this->aQuestion['i_cat']);
     $this->aPageVars['body'] = $breadcrumb . \tplQuestion::parse($this->aQuestion);
     return $this;
 }
Exemple #3
0
 /**
  * Delete is allowed by Resource Owner OR
  * by user authorized to delete_question
  * or delete_answer in the acl
  *
  * Also if question has answer(s) then
  * even the owner is not allowed to delete
  * and instead the moderators are notified
  *
  * @return object $this
  */
 protected function checkPermission()
 {
     if (!\Lampcms\isOwner($this->Registry->Viewer, $this->Resource)) {
         $this->checkAccessPermission($this->permission);
     }
     return $this;
 }
 /**
  * Check if viewer is owner of resource
  * users not allowed to vote for their own
  * question
  *
  * @return object $this
  */
 protected function checkIsOwner()
 {
     if (\Lampcms\isOwner($this->Registry->Viewer, $this->Resource)) {
         throw new \Lampcms\Exception('Cannot rate own questions or answers');
     }
     return $this;
 }
 /**
  * Edits can be done by owner of resource
  * OR by someone who has necessary permission
  *
  * @return object $this
  * @throws checkAccessPermission() will throw exception
  * if Viewer does not have required permission
  */
 protected function checkPermission()
 {
     if (!\Lampcms\isOwner($this->Registry->Viewer, $this->Resource)) {
         if (\Lampcms\Points::EDIT > $this->Registry->Viewer->getProfitPoint()) {
             $this->checkAccessPermission();
         }
     }
     return $this;
 }
 /**
  * Check to make sure Viewer has permission
  * to retag.
  * Permitted to retag are: owner of question,
  * moderator/admin or user with enough amounts of profit points
  *
  * @return object $this
  *
  */
 protected function checkPermission()
 {
     if (!\Lampcms\isOwner($this->Registry->Viewer, $this->Question) && $this->Registry->Viewer->getProfitPoint() < \Lampcms\Points::RETAG) {
         $this->checkAccessPermission('retag');
     }
     return $this;
 }
Exemple #7
0
 /**
  * Get array for this one question,
  * set $this->Question
  * and also set $this->aTplVars['body']
  * with parsed tplQuestion block
  *
  * @throws \Lampcms\Lampcms404Exception is question not found
  * @return object $this
  */
 protected function getQuestion()
 {
     $isModerator = $this->Registry->Viewer->isModerator();
     $this->noComments = false === (bool) $this->Registry->Ini->MAX_COMMENTS;
     d('no comments: ' . $this->noComments);
     $aFields = $this->noComments || false === (bool) $this->Registry->Ini->SHOW_COMMENTS ? array('comments' => 0) : array();
     $this->aQuestion = $this->Registry->Mongo->QUESTIONS->findOne(array('_id' => (int) $this->qid), $aFields);
     if (empty($this->aQuestion)) {
         throw new \Lampcms\Lampcms404Exception('@@Question not found@@');
     }
     /**
      * Only moderators can see ip address
      */
     if (!$isModerator && !empty($this->aQuestion['ip'])) {
         unset($this->aQuestion['ip']);
     }
     $deleted = isset($this->aQuestion[Schema::RESOURCE_STATUS_ID]) && $this->aQuestion[Schema::RESOURCE_STATUS_ID] === Schema::DELETED || !empty($this->aQuestion[Schema::DELETED_TIMESTAMP]) ? ' deleted' : false;
     $this->aQuestion['pending'] = isset($this->aQuestion[Schema::RESOURCE_STATUS_ID]) && $this->aQuestion[Schema::RESOURCE_STATUS_ID] === Schema::PENDING;
     $this->Question = new Question($this->Registry, $this->aQuestion);
     if ($deleted) {
         if (!$isModerator && !\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw new \Lampcms\Lampcms404Exception('@@Question was deleted on@@ ' . date('F j Y', $this->aQuestion['i_del_ts']));
         }
         /**
          * If Viewer is moderator, then viewer
          * will be able to view deleted item
          * This will add 'deleted' class to question table
          */
         $this->aQuestion['deleted'] = $deleted;
         if (!empty($this->aQuestion['a_deleted'])) {
             $this->aQuestion['deletedby'] = \tplDeletedby::parse($this->aQuestion['a_deleted'], false);
             d('deletedby: ' . $this->aQuestion['deletedby']);
         }
     }
     /**
      * Only Moderator or Owner can see pending questions
      * A notice is added to the question indicating it's pending approval
      * Moderators will be able to approve it.
      * Author will be able to edit it.
      * Others will get 404 error
      */
     if ($this->aQuestion['pending']) {
         if (!$isModerator && !\Lampcms\isOwner($this->Registry->Viewer, $this->Question)) {
             throw new \Lampcms\Lampcms404Exception('@@Question not found@@');
         }
     }
     /**
      * Guests will have to see filtered
      * content
      */
     if (!$this->isLoggedIn()) {
         $this->aQuestion['b'] = Badwords::filter($this->aQuestion['b'], true);
     }
     if ($this->noComments) {
         $this->aQuestion['nocomments'] = ' nocomments';
     }
     $breadcrumb = empty($this->aQuestion[Schema::CATEGORY_ID]) ? '' : $this->getBreadcrumb($this->aQuestion[Schema::CATEGORY_ID]);
     $this->aPageVars['body'] = $breadcrumb . \tplQuestion::parse($this->aQuestion);
     return $this;
 }
Exemple #8
0
 /**
  * Check to make sure Viewer has permission
  * to retag.
  * Permitted to retag are: owner of question,
  * moderator/admin or user with reputation
  *
  * @return object $this
  *
  */
 protected function checkPermission()
 {
     if (!\Lampcms\isOwner($this->Registry->Viewer, $this->Question) && $this->Registry->Viewer->getReputation() < $this->Registry->Ini->POINTS->RETAG) {
         $this->checkAccessPermission('retag');
     }
     return $this;
 }
Exemple #9
0
 /**
  * Edits can be done by owner of resource
  * OR by someone who has necessary permission
  *
  * @return object $this
  * @throws checkAccessPermission() will throw exception
  * if Viewer does not have required permission
  */
 protected function checkPermission()
 {
     if (!\Lampcms\isOwner($this->Registry->Viewer, $this->Resource)) {
         if ($this->Registry->Ini->POINTS->EDIT > $this->Registry->Viewer->getReputation()) {
             $this->checkAccessPermission();
         }
     }
     return $this;
 }