/** * Performs the action. */ function perform() { // fetch the articles for the given blog $articles = new Articles(); $blogSettings = $this->_blogInfo->getSettings(); $localeCode = $blogSettings->getValue("locale"); // fetch the default profile as chosen by the administrator $defaultProfile = $this->_config->getValue("default_rss_profile"); if ($defaultProfile == "" || $defaultProfile == null) { $defaultProfile = DEFAULT_PROFILE; } // fetch the profile // if the profile specified by the user is not valid, then we will // use the default profile as configured $profile = $this->_request->getValue("profile"); if ($profile == "") { $profile = $defaultProfile; } // fetch the category, or set it to '0' otherwise, which will mean // fetch all the most recent posts from any category $categoryId = $this->_request->getValue("categoryId"); if (!is_numeric($categoryId)) { $categoryId = 0; } // check if the template is available $this->_view = new RssView($this->_blogInfo, $profile, array("profile" => $profile, "categoryId" => $categoryId)); // do nothing if the view was already cached if ($this->_view->isCached()) { return true; } // create an instance of a locale object $locale = Locales::getLocale($localeCode); // fetch the posts, though we are going to fetch the same amount in both branches $amount = $blogSettings->getValue("recent_posts_max", 15); $t = new Timestamp(); if ($blogSettings->getValue('show_future_posts_in_calendar')) { $blogArticles = $articles->getBlogArticles($this->_blogInfo->getId(), -1, $amount, $categoryId, POST_STATUS_PUBLISHED, 0); } else { $today = $t->getTimestamp(); $blogArticles = $articles->getBlogArticles($this->_blogInfo->getId(), -1, $amount, $categoryId, POST_STATUS_PUBLISHED, 0, $today); } $pm =& PluginManager::getPluginManager(); $pm->setBlogInfo($this->_blogInfo); $pm->setUserInfo($this->_userInfo); $result = $pm->notifyEvent(EVENT_POSTS_LOADED, array('articles' => &$blogArticles)); $articles = array(); foreach ($blogArticles as $article) { $postText = $article->getIntroText(); $postExtendedText = $article->getExtendedText(); $pm->notifyEvent(EVENT_TEXT_FILTER, array("text" => &$postText)); $pm->notifyEvent(EVENT_TEXT_FILTER, array("text" => &$postExtendedText)); $article->setIntroText($postText); $article->setExtendedText($postExtendedText); array_push($articles, $article); } $this->_view->setValue("locale", $locale); $this->_view->setValue("posts", $articles); $this->setCommonData(); return true; }
/** * Loads the blog info and show it */ function perform() { $this->_blogId = $this->_request->getValue("blogId"); $this->_view = new SummaryCachedView("blogprofile", array("summary" => "BlogProfile", "blogId" => $this->_blogId, "locale" => $this->_locale->getLocaleCode())); if ($this->_view->isCached()) { // nothing to do, the view is cached return true; } // load some information about the user $blogs = new Blogs(); $blogInfo = $blogs->getBlogInfo($this->_blogId, true); // if there was no blog or the status was incorrect, let's not show it! if (!$blogInfo || $blogInfo->getStatus() != BLOG_STATUS_ACTIVE) { $this->_view = new SummaryView("error"); $this->_view->setValue("message", $this->_locale->tr("error_incorrect_blog_id")); return false; } // fetch the blog latest posts $posts = array(); $articles = new Articles(); $t = new Timestamp(); $posts = $articles->getBlogArticles($blogInfo->getId(), -1, SUMMARY_DEFAULT_RECENT_BLOG_POSTS, 0, POST_STATUS_PUBLISHED, 0, $t->getTimestamp()); $this->_view->setValue("blog", $blogInfo); $this->_view->setValue("blogposts", $posts); $this->setCommonData(); return true; }
/** * marks all the articles from the given blog (or all of them * if blogId==0) as non-spam. This is good food for the * filter since then it knows which things should be allowed. * * @static * @param blogId The blog * @return Always true */ function markArticlesAsNonSpam($blogId = 0) { // first, gather all posts that should be used to gather "good" // for for the filter $articles = new Articles(); if ($blogId == 0) { $blogArticles = $articles->getAllArticles(); } else { $blogArticles = $articles->getBlogArticles($blogId); } // now, loop through each one of them marking the contents as // non-spam $bayesian = new BayesianFilterCore(); foreach ($blogArticles as $article) { $owner = $article->getUserInfo(); $bayesian->train($article->getBlog(), $article->getTopic(), $article->getText(), $owner->getUsername(), $owner->getEmail(), "", false); } return true; }
/** * normally views do not meddle with data but in this case moving all * this data fetching here is benefitial from a coding point of view, because it * allows this code to be reused by several action classes... In the worst case * we would have to copy+paste the code or put in a separate class only for this bit * of code. By moving it here, the view itself can handle everything */ function _loadViewData() { // for each blog, load some statistics $articles = new Articles(); $comments = new ArticleComments(); $trackbacks = new Trackbacks(); $resources = new GalleryResources(); $recentPosts = array(); $recentComments = array(); $recentResources = array(); // load some statistics for each one of the blogs foreach ($this->_userBlogs as $userBlog) { $recentPosts[$userBlog->getId()] = $articles->getBlogArticles($userBlog->getId(), -1, DASHBOARD_MAX_RECENT_ITEMS, 0, POST_STATUS_PUBLISHED); $recentComments[$userBlog->getId()] = $comments->getBlogComments($userBlog->getId(), DASHBOARD_MAX_RECENT_ITEMS); $recentTrackbacks[$userBlog->getId()] = $trackbacks->getBlogTrackbacks($userBlog->getId(), DASHBOARD_MAX_RECENT_ITEMS); } $this->_params->setValue("userblogs", $this->_userBlogs); $this->_params->setValue("recentposts", $recentPosts); $this->_params->setValue("recentcomments", $recentComments); $this->_params->setValue("recenttrackbacks", $recentTrackbacks); }
/** * renders the view */ function render() { // fetch all the articles for edition, but we need to know whether we are trying to // search for some of them or simply filter them based on certain criteria $articles = new Articles(); $posts = $articles->getBlogArticles($this->_blogInfo->getId(), $this->_showMonth, $this->_itemsPerPage, $this->_showCategory, $this->_showStatus, $this->_showUser, 0, $this->_searchTerms, $this->_page); // get the total number of posts $numPosts = $articles->getNumBlogArticles($this->_blogInfo->getId(), $this->_showMonth, $this->_itemsPerPage, $this->_showCategory, $this->_showStatus, $this->_showUser, 0, $this->_searchTerms, $this->_page); //print("number = $numPosts<br/>"); $pager = new Pager("?op=editPosts&showStatus={$this->_showStatus}&showCategory={$this->_showCategory}&showUser={$this->_showUser}&searchTerms={$this->_searchTerms}&page=", $this->_page, $numPosts, $this->_itemsPerPage); $this->setValue("posts", $posts); // throw the even in case somebody is listening to it $this->notifyEvent(EVENT_POSTS_LOADED, array("posts" => &$posts)); // and the categories $categories = new ArticleCategories(); $blogSettings = $this->_blogInfo->getSettings(); $categoriesOrder = $blogSettings->getValue("categories_order"); $blogCategories = $categories->getBlogCategories($this->_blogInfo->getId(), false, $categoriesOrder); $this->notifyEvent(EVENT_CATEGORIES_LOADED, array("categories" => &$blogCategories)); // and all the users that belong to this blog $users = new Users(); $blogUsers = $users->getBlogUsers($this->_blogInfo->getId()); // and all the post status available $postStatusList = ArticleStatus::getStatusList(true); $this->setValue("categories", $blogCategories); // values for the session, so that we can recover the status // of the filters later on in subsequent requests $this->setSessionValue("showCategory", $this->_showCategory); $this->setSessionValue("showStatus", $this->_showStatus); $this->setSessionValue("showUser", $this->_showUser); $this->setSessionValue("showMonth", $this->_showMonth); // values for the view $this->setValue("currentcategory", $this->_showCategory); $this->setValue("currentstatus", $this->_showStatus); $this->setValue("currentuser", $this->_showUser); $this->setValue("currentmonth", $this->_showMonth); $this->setValue("users", $blogUsers); $this->setValue("months", $this->_getMonths()); $this->setValue("poststatus", $postStatusList); $this->setValue("searchTerms", $this->_searchTerms); $this->setValue("pager", $pager); parent::render(); }
function _addPost($data, $_debug) { if ($data["title"] == NULL) { $data["title"] = "No Title Entered."; } if ($data["text"] == NULL) { $data["text"] = "No Body Entered."; } if ($data["category"] == NULL) { $data["category"] = 1; } if ($data["user_id"] == NULL) { $data["user_id"] = 1; } if ($data["blog_id"] == NULL) { $data["blog_id"] = 1; } if ($data["status"] == NULL) { $data["status"] = POST_STATUS_PUBLISHED; } if ($data["comments"] == NULL) { $data["comments"] = true; } $articles = new Articles(); // verify that article does not exist in database $artss = $articles->getBlogArticles($data["blog_id"]); $exists = 0; foreach ($artss as $art) { if ($art->getTopic() == $data["title"]) { $exists = $art->getId(); break; } } /* $exists = $articles->getBlogArticleByTitle( TextFilter::urlize($data["title"]) , $data["blog_id"], true, -1 -1 -1, POST_STATUS_PUBLISHED ); if (!$exists) { $exists = $articles->getBlogArticleByTitle( TextFilter::urlize($data["title"]) , $data["blog_id"], true, -1 -1 -1, POST_STATUS_DRAFT ); } */ if (!$exists) { // verify that desired post id does not exist. Otherwise, create new id. if (!$articles->getUserArticle($data["id"])) { $post_id = $data["id"]; } if ($_debug) { print "--- --- adding post " . $data["title"] . " to db.<br />\n\r"; } $cat[0] = $data["category"]; $article = new Article($data["title"], $data["text"], $cat, $data["user_id"], $data["blog_id"], $data["status"], 0); if ($data["date"]) { $article->setDate($data["date"]); } if ($post_id) { $article->setId($post_id); } $article->setCommentsEnabled($data["comments"]); $artId = $articles->addArticle($article); $this->_stats["posts"]["write"]++; // remap comments to $artId if ($this->_container["comments"]) { foreach ($this->_t_container["comments"] as $comment => $val) { if ($this->container["comments"][$comment]["article_id"] == $data["id"] || $val["article_id"] == NULL) { $this->_container["comments"][$comment]["article_id"] = $artId; if ($_debug) { print "--- --- remapping comment entry #" . $comment . " to proper article id<br />\n\r"; } } } } } else { $artId = $exists; if ($_debug) { print "--- --- post already exists, aborting operation.<br />\n\r"; } } return $artId; }
/** * returns the articles categorized here * * @param an array of Article obejcts */ function getArticles($status = POST_STATUS_PUBLISHED) { if (!is_array($this->_articles[$status]) || $this->_articles[$status] == null) { $articles = new Articles(); // you've got to love these huge method calls... $this->_articles[$status] = $articles->getBlogArticles($this->getBlogId(), -1, -1, $this->getId(), $status); } return $this->_articles[$status]; }
/** * Turns on notification for the specified article * */ function GenerateSiteMap() { // articles object $articles = new Articles(); $list = $articles->getBlogArticles($this->blogInfo->getId(), -1, -1, 0, POST_STATUS_PUBLISHED); $url = $this->blogInfo->getBlogRequestGenerator(); // Data from the xml file that needs to be there. $xmlData = "<?xml version='1.0' encoding='UTF-8'?>\n" . "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\"\n" . "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" . "xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84\n" . "http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">\n"; // Iterate over the posts and create an entry for each. foreach ($list as $item) { $xmlData = $xmlData . "<url>\n"; $xmlData = $xmlData . "<loc>\n"; $xmlData = $xmlData . htmlspecialchars($url->postPermalink($item)) . "\n"; $xmlData = $xmlData . "</loc>\n"; $xmlData = $xmlData . "</url>\n"; } $xmlData = $xmlData . "</urlset>\n"; $compressedFile = $this->cacheFolder . "/sitemap.gz"; // Save this to a compressed file. $gz = gzopen($compressedFile, 'w9'); if ($gz) { gzwrite($gz, $xmlData); gzclose($gz); } $blogSettings = $this->blogInfo->getSettings(); if ($blogSettings->getValue("plugin_sitemap_notify_google_enabled")) { // Send the request to google $rg =& RequestGenerator::getRequestGenerator($this->blogInfo); $rewriteFile = "/sitemap" . $this->blogInfo->getId() . ".gz"; $rewriteFileUrl = $rg->getUrl($rewriteFile); $pingUrl = "http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($rewriteFileUrl); $handle = fopen($pingUrl, "r"); fclose($handle); } }