Exemplo n.º 1
0
 public function save()
 {
     $option = JRequest::getCmd('option');
     $userData = JFactory::getUser();
     $userAccessLevel = comQuipForumHelper::getUserAccessLevel(JRequest::getVar('board_id'));
     if ($userAccessLevel < 2) {
         return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
     }
     JRequest::checkToken() or jexit('Invalid Token');
     $rowPost =& JTable::getInstance('posts', 'Table');
     if (!$rowPost->bind(JRequest::get('post'))) {
         JError::raiseError(500, $rowPost->getError());
     }
     if ($userAccessLevel == 2 && !$rowPost->thread_id) {
         return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
     }
     $rowPost->ip_address = $_SERVER['REMOTE_ADDR'];
     $rowPost->post_date = comQuipForumHelper::sqlDateTime();
     if (!trim(strip_tags($rowPost->body))) {
         $rowPost->no_text = 1;
     }
     if (!$rowPost->id) {
         $status = "created";
     } else {
         $status = "edited";
     }
     if (!$rowPost->store()) {
         JError::raiseError(500, $rowPost->getError());
     }
     $urls = array();
     if ($urls = comQuipForumHelper::parseUrlsFromText($rowPost->body)) {
         $noTextTester = $rowPost->body;
         foreach ((array) $urls as $key => $value) {
             $noTextTester = str_replace($value, "", $noTextTester);
             $rowLinks =& JTable::getInstance('links', 'Table');
             $rowLinks->url = $value;
             $rowLinks->post_id = $rowPost->id;
             $rowLinks->user_id = $rowPost->user_id;
             if (!$rowLinks->store()) {
                 JError::raiseError(500, $rowLinks->getError());
             }
             $rowPost->links++;
         }
         if (!trim(strip_tags($noTextTester))) {
             $rowPost->no_text = 1;
         }
         # update with # of links
         if (!$rowPost->store()) {
             JError::raiseError(500, $rowPost->getError());
         }
     }
     if (!($parent_id = JRequest::getVar('parent_id'))) {
         $rowPost->thread_id = $rowPost->id;
         $rowPostRefs =& JTable::getInstance('postreferences', 'Table');
         $rowPostRefs->load($rowPost->reference_key_id);
         $rowPostRefs->board_id = JRequest::getVar('board_id');
         $rowPostRefs->id = $rowPost->id;
         if (!$rowPostRefs->store()) {
             JError::raiseError(500, $rowPostRefs->getError());
         }
         $rowPost->reference_key_id = $rowPostRefs->key_id;
         if (!$rowPost->store()) {
             JError::raiseError(500, $rowPost->getError());
         }
     }
     $threadWeaver = new QuipForumThreadWeaver();
     $threadWeaver->weaveThread($rowPost->thread_id);
     if ($userData->id) {
         comQuipForumHelper::logIt(" <span class='qforum-log-post-" . $status . "'>Post " . $status . " by " . $userData->name . "(" . $userData->id . ") at " . $rowPost->post_date . ".</span>", $rowPost->id);
     } else {
         comQuipForumHelper::logIt(" <span class='qforum-log-post-" . $status . "'>Post " . $status . " by " . $rowPost->user_alt_name . "(guest from IP: " . $rowPost->ip_address . ") at " . $rowPost->post_date . ".</span>", $rowPost->id);
     }
     $this->setRedirect(JRoute::_('index.php?option=' . $option . '&view=post&id=' . $rowPost->id), 'Post saved, here it is!');
 }
Exemplo n.º 2
0
 protected function buildThreads()
 {
     $threadWeaver = new QuipForumThreadWeaver();
     if (!@$this->threadData[0]->thread_cache) {
         $threadWeaver->weaveThread($this->postData->thread_id);
         $this->threadData[0]->jsonThreadCache = $threadWeaver->encoded;
         echo " <span>(Thread #" . $this->postData->thread_id . " was rebuilt.)</span> ";
         $threadWeaver->clearVars();
     } else {
         $this->threadData[0]->jsonThreadCache = gzinflate($this->threadData[0]->thread_cache);
     }
     $this->jsonLog .= $this->threadData[0]->jsonThreadCache;
     $threadPostData = json_decode($this->threadData[0]->jsonThreadCache);
     foreach ((array) $threadPostData as $kkk => $vvv) {
         $linksMarkup = null;
         if (!$vvv->no_text) {
             $a_link = "<a href='" . JRoute::_('index.php?option=com_quipforum&view=post&id=' . $vvv->id) . "' class='qforum-board-subject'>";
             $a_close = "</a>";
         } else {
             $a_link = "<span class='qforum-board-subject-no-text'>";
             $a_close = "</span><span class='qforum-no-text'>NT</span><a href='" . JRoute::_('index.php?option=com_quipforum&view=post&id=' . $vvv->id . '#reply') . "' class='qforum-board-subject-reply'>reply</a>";
         }
         foreach ((array) @$vvv->link_urls as $kl => $vl) {
             $linksMarkup .= "<a href='" . $vl->url . "' target='_blank' class='qforum-post-external-link'>Link...</a>";
         }
         $this->threadMarkup .= " <li id='qforum-thread-" . $vvv->id . "' class='qforum-author-" . $vvv->user_id . " qforum-thread-parent'>\n\t    \t\t\t<div class='qforum-collapse-img'>" . JHTML::_('image', 'components/com_quipforum/icons/16x16/bullet_arrow_down.png', null) . "</div> " . $a_link . $vvv->subject . $a_close . $linksMarkup . "\n\t    \t\t\t\t<span class='qforum-posted-by'>posted by </span><span class='qforum-post-author'>" . $vvv->user_alt_name . "</span><span class='qforum-post-date'> on " . $vvv->post_date . "</span>";
         # recursive function -- weaves children
         foreach ((array) @$vvv->childReplies as $key => $values) {
             $this->threadMarkup .= " <ul class='qf-subthread' id='qf-thread-parent-" . $vvv->id . "'>";
             $this->weaveChildren($values);
             $this->threadMarkup .= " </ul>";
         }
         $this->threadMarkup .= "</li>";
     }
 }