/** * Carries out the specified action */ function perform() { //print_r($_REQUEST); // fetch all the information that we need for the dummy Article object $this->_fetchCommonData(); // and now, create a harmless Article object with it $postText = Textfilter::xhtmlize($this->_postText) . POST_EXTENDED_TEXT_MODIFIER . Textfilter::xhtmlize($this->_postExtendedText); // create the main object $article = new Article($this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), $this->_blogInfo->getId(), $status, 0, array(), $this->_postSlug); // and a few more properties that we need to know about $this->_fetchPostDateInformation(); $article->setDateObject($this->_postTimestamp); // we will not allow comments because it wouldn't work! $article->setCommentsEnabled(false); $article->setFields($this->_getArticleCustomFields()); // the next two fields are also required in order to show an article $article->setUserInfo($this->_userInfo); $article->setBlogInfo($this->_blogInfo); $article->setCategories($this->_loadArticleCategories($this->_postCategories)); // and now trick the ViewArticleView class into thinking that we're showing // a real article just fetched from the database (even though it makes no difference // to the class itself whence the article came from :) // the 'random' parameter in the array is to provide the view with a random view id // every time that we run the preview, otherwise when caching is enabled we would always be // getting the same page!! $this->_view = new ViewArticleView($this->_blogInfo, array('random' => md5(time()))); $this->_view->setArticle($article); //$this->setCommonData(); return true; }
/** * Does exactly the same as _fillUserInformation, so that it can be reused * by the different functions that work on articles from the database. This method is * private and shouldn't be used outside this class. * * @private */ function _fillArticleInformation($query_result, $includeHiddenFields = true) { $id = $query_result['id']; if (isset($this->cache[$id])) { return $this->cache[$id]; } // this is a little dirty trick or otherwise the old // that don't have the 'properties' field will not work // as they will appear to have comments disabled if ($query_result['properties'] == "") { $tmpArray = array('comments_enabled' => true); $query_result['properties'] = serialize($tmpArray); } // --- // this, i do not like... but I couldn't find a more // "elegant" way to arrange it! This makes this method // totally dependant on the blog configuration so it basically // means an additional query every time we fetch an article // (just in case we didn't have enough!) // --- // // if there's a time difference applied to all dates, then we'd better // calculate it here!! // $blogId = $query_result['blog_id']; $blogInfo = $this->blogs->getBlogInfo($blogId); $blogSettings = $blogInfo->getSettings(); $timeDiff = $blogSettings->getValue('time_offset'); // we can use this auxiliary function to help us... $date = Timestamp::getDateWithOffset($query_result['date'], $timeDiff); $articleCategories = $this->getArticleCategories($query_result['id'], $query_result['blog_id']); $categoryIds = array(); foreach ($articleCategories as $category) { array_push($categoryIds, $category->getId()); } // get the article text $postText = $this->getArticleText($query_result['id']); $article = new Article($postText['topic'], $postText['text'], $categoryIds, $query_result['user_id'], $query_result['blog_id'], $query_result['status'], $query_result['num_reads'], unserialize($query_result['properties']), $query_result['slug'], $query_result['id']); // and fill in all the fields with the information we just got from the db $article->setDate($date); $article->setTimeOffset($timeDiff); // get information about the categories of the article $article->setCategories($articleCategories); $article->setBlogInfo($blogInfo); $article->setUserInfo($this->users->getUserInfoFromId($query_result['user_id'])); // fill in the cache with the result we just loaded $this->cache[$query_result['id']] = $article; return $article; }