Ejemplo n.º 1
0
 protected static function func(&$a)
 {
     $a['hts'] = \Lampcms\TimeFormatter::formatTime($_SESSION['locale'], $a['i_ts']);
     if (array_key_exists('a_edited', $a)) {
         $aEdited = end($a['a_edited']);
         $aEdited['edited'] = $a['edited'];
         $a['edits'] = \tplEditedby::parse($aEdited);
     }
     if (!empty($a['i_del_ts'])) {
         $a['deleted'] = ' deleted';
     }
     if (!empty($a['a_deleted'])) {
         $a['deletedby'] = \tplDeletedby::parse($a['a_deleted']);
     }
     if (!empty($a['a_comments'])) {
         /**
          * Closure function
          * to pass resource_id
          * and author id of this
          * Answer to the tplComments
          * This way we don't have to store
          * duplicate data in each comment
          * element and still be able to
          * have access to these 2 important
          * fields in the tplComments template
          * We going to need id or resource owner
          * in order to add it to the "reply" link
          * in the form of class uid-$uid
          *
          */
         $rid = $a['_id'];
         $uid = $a['i_uid'];
         $f = function (&$data) use($rid, $uid) {
             $data['resource_id'] = $rid;
             $data['owner_id'] = $uid;
         };
         $a['comments_html'] = tplComment::loop($a['a_comments'], true, $f);
     }
     if ($a['i_status'] === 2) {
         $a['moderate'] = '<span class="cb fl pending">@@This answer is pending moderator approval@@</span>';
         $a['approve'] = '<span class="ico ttt approve ajax" title="@@Approve this answer@@"> </span>';
     }
 }
Ejemplo n.º 2
0
 protected static function func(&$a)
 {
     if (array_key_exists('a_edited', $a)) {
         $aEdited = end($a['a_edited']);
         $aEdited['edited'] = $a['edited'];
         $a['edits'] = \tplEditedby::parse($aEdited, false);
     }
     if (!empty($a['i_del_ts'])) {
         $a['deleted'] = ' deleted';
     }
     if (!empty($a['a_deleted'])) {
         $a['deletedby'] = \tplDeletedby::parse($a['a_deleted'], false);
     }
     if (!empty($a['a_comments'])) {
         /**
          * Closure function
          * to pass resource_id 
          * and author id of this
          * Answer to the tplComments
          * This way we don't have to store
          * duplicate data in each comment
          * element and still be able to
          * have access to these 2 important
          * fields in the tplComments template
          * We going to need id or resource owner
          * in order to add it to the "reply" link
          * in the form of class uid-$uid
          * 
          */
         $rid = $a['_id'];
         $uid = $a['i_uid'];
         $reply = $a['reply'];
         $reply_t = $a['reply_t'];
         $f = function (&$data) use($rid, $uid, $reply, $reply_t) {
             $data['resource_id'] = $rid;
             $data['owner_id'] = $uid;
             $data['reply'] = $reply;
             $data['reply_t'] = $reply_t;
         };
         $a['comments_html'] = tplComment::loop($a['a_comments'], true, $f);
     }
 }
 /**
  * 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;
 }
Ejemplo n.º 4
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;
 }