/** * Carries out the specified action */ function perform() { // fetch the category $this->_categoryId = $this->_request->getValue("categoryId"); $categories = new ArticleCategories(); $category = $categories->getCategory($this->_categoryId, $this->_blogInfo->getId()); // show an error if we couldn't fetch the category if (!$category) { $this->_view = new AdminArticleCategoriesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_fetching_category")); $this->_view->setError(true); $this->setCommonData(); return false; } $this->notifyEvent(EVENT_CATEGORY_LOADED, array("category" => &$category)); // otherwise show the form to edit its fields $this->_view = new AdminTemplatedView($this->_blogInfo, "editarticlecategory"); $this->_view->setValue("category", $category); $this->_view->setValue("categoryName", $category->getName()); $this->_view->setValue("categoryDescription", $category->getDescription()); $this->_view->setValue("categoryInMainPage", $category->isInMainPage()); $this->_view->setValue("categoryId", $category->getId()); $this->setCommonData(); // better to return true if everything fine return true; }
function perform() { $this->_view = new BlogView($this->_blogInfo, VIEW_TRACKBACKS_TEMPLATE, SMARTY_VIEW_CACHE_CHECK, array("articleId" => $this->_articleId, "articleName" => $this->_articleName, "categoryName" => $this->_categoryName, "categoryId" => $this->_categoryId, "userId" => $this->_userId, "userName" => $this->_userName, "date" => $this->_date)); if ($this->_view->isCached()) { return true; } // --- // if we got a category name or a user name instead of a category // id and a user id, then we have to look up first those // and then proceed // --- // users... if ($this->_userName) { $users = new Users(); $user = $users->getUserInfoFromUsername($this->_userName); if (!$user) { $this->_setErrorView(); return false; } // if there was a user, use his/her id $this->_userId = $user->getId(); } // ...and categories... if ($this->_categoryName) { $categories = new ArticleCategories(); $category = $categories->getCategoryByName($this->_categoryName); if (!$category) { $this->_setErrorView(); return false; } // if there was a user, use his/her id $this->_categoryId = $category->getId(); } // fetch the article $articles = new Articles(); if ($this->_articleId) { $article = $articles->getBlogArticle($this->_articleId, $this->_blogInfo->getId(), false, $this->_date, $this->_categoryId, $this->_userId); } else { $article = $articles->getBlogArticleByTitle($this->_articleName, $this->_blogInfo->getId(), false, $this->_date, $this->_categoryId, $this->_userId); } // if the article id doesn't exist, cancel the whole thing... if ($article == false) { $this->_view = new ErrorView($this->_blogInfo); $this->_view->setValue("message", "error_fetching_article"); $this->setCommonData(); return false; } $this->notifyEvent(EVENT_POST_LOADED, array("article" => &$article)); $this->notifyEvent(EVENT_TRACKBACKS_LOADED, array("article" => &$article)); // if everything's fine, we set up the article object for the view $this->_view->setValue("post", $article); $this->_view->setValue("trackbacks", $article->getTrackbacks()); $this->setCommonData(); // and return everything normal return true; }
/** * loads a bunch of categories given their ids * * @param categoryIds */ function _loadArticleCategories($categoryIds) { $articleCategories = new ArticleCategories(); $categories = array(); foreach ($categoryIds as $categoryId) { $category = $articleCategories->getCategory($categoryId, $this->_blogInfo->getId()); if ($category) { array_push($categories, $category); } } return $categories; }
/** * @private * removes categories from the database */ function _deleteArticleCategories() { $categories = new ArticleCategories(); $errorMessage = ""; $successMessage = ""; $totalOk = 0; foreach ($this->_categoryIds as $categoryId) { // get the category $category = $categories->getCategory($categoryId, $this->_blogInfo->getId()); if ($category) { // get how many articles it has //$numArticles = $categories->getNumArticlesCategory( $categoryId ); $numArticles = $category->getNumArticles(POST_STATUS_ALL); // fire the pre-event $this->notifyEvent(EVENT_PRE_CATEGORY_DELETE, array("category" => &$category)); // if it has at least one we can't delete it because then it would break the // integrity of our data in the database... if ($numArticles > 0) { $errorMessage .= $this->_locale->pr("error_category_has_articles", $category->getName()) . "<br/>"; } else { // if everything correct, we can proceed and delete it if (!$categories->deleteCategory($categoryId, $this->_blogInfo->getId())) { $errorMessage .= $this->_locale->pr("error_deleting_category") . "<br/>"; } else { if ($totalOk < 2) { $successMessage .= $this->_locale->pr("category_deleted_ok", $category->getName()) . "<br/>"; } else { $successMessage = $this->_locale->pr("categories_deleted_ok", $totalOk); } // fire the pre-event $this->notifyEvent(EVENT_POST_CATEGORY_DELETE, array("category" => &$category)); } } } else { $errorMessage .= $this->_locale->pr("error_deleting_category2", $categoryId) . "<br/>"; } } // prepare the view and all the information it needs to know $this->_view = new AdminArticleCategoriesListView($this->_blogInfo); if ($errorMessage != "") { $this->_view->setErrorMessage($errorMessage); } if ($successMessage != "") { // and clear the cache to avoid outdated information CacheControl::resetBlogCache($this->_blogInfo->getId(), false); $this->_view->setSuccessMessage($successMessage); } $this->setCommonData(); return true; }
function perform() { // fetch the validated data $this->_blogName = Textfilter::filterAllHTML($this->_request->getValue("blogName")); $this->_ownerId = $this->_request->getValue("blogOwner"); $this->_blogProperties = $this->_request->getValue("properties"); // check that the user really exists $users = new Users(); $userInfo = $users->getUserInfoFromId($this->_ownerId); if (!$userInfo) { $this->_view = new AdminCreateBlogView($this->_blogInfo); $this->_form->setFieldValidationStatus("blogOwner", false); $this->setCommonData(true); return false; } // now that we have validated the data, we can proceed to create the user, making // sure that it doesn't already exists $blogs = new Blogs(); $blog = new BlogInfo($this->_blogName, $this->_ownerId, "", ""); $blog->setProperties($this->_blogProperties); $this->notifyEvent(EVENT_PRE_BLOG_ADD, array("blog" => &$blog)); $newBlogId = $blogs->addBlog($blog); if (!$newBlogId) { $this->_view = new AdminCreateBlogView($this->_blogInfo); $this->_form->setFieldValidationStatus("blogName", false); $this->setCommonData(); return false; } // add a default category and a default post $articleCategories = new ArticleCategories(); $articleCategory = new ArticleCategory("General", "", $newBlogId, true); $catId = $articleCategories->addArticleCategory($articleCategory); $config =& Config::getConfig(); $locale =& Locales::getLocale($config->getValue("default_locale")); $articleTopic = $locale->tr("register_default_article_topic"); $articleText = $locale->tr("register_default_article_text"); $article = new Article($articleTopic, $articleText, array($catId), $this->_ownerId, $newBlogId, POST_STATUS_PUBLISHED, 0, array(), "welcome"); $t = new Timestamp(); $article->setDateObject($t); $articles = new Articles(); $articles->addArticle($article); // and inform everyone that everything went ok $this->notifyEvent(EVENT_POST_BLOG_ADD, array("blog" => &$blog)); $this->_view = new AdminSiteBlogsListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->pr("blog_added_ok", $blog->getBlog())); $this->setCommonData(); return true; }
/** * Carries out the specified action */ function perform() { // initialize the view $this->_view = new AdminTemplatedView($this->_blogInfo, "newpostcategory"); $this->setCommonData(); // fetch the categories $categories = new ArticleCategories(); $blogSettings = $this->_blogInfo->getSettings(); $categoriesOrder = $blogSettings->getValue("categories_order"); $blogCategories = $categories->getBlogCategoriesAdmin($this->_blogInfo->getId(), false, $categoriesOrder); $this->_view->setValue("categories", $blogCategories); // this field should be true by default $this->_view->setValue("categoryInMainPage", true); // better to return true if everything fine return true; }
/** * Carries out the specified action */ function perform() { $categories = new ArticleCategories(); $blogCategories = $categories->getBlogCategories($this->_blogInfo->getId()); // but make sure that we have at least one! if (count($blogCategories) == 0) { $this->_view = new AdminTemplatedView($this->_blogInfo, "newpostcategory"); $this->_view->setSuccessMessage($this->_locale->tr("error_must_have_one_category")); $this->setCommonData(); return false; } // initialize the view $this->_view = new AdminNewPostView($this->_blogInfo); $this->setCommonData(); // better to return true if everything fine return true; }
function render() { // fetch the categories $categories = new ArticleCategories(); $blogSettings = $this->_blogInfo->getSettings(); $categoriesOrder = $blogSettings->getValue("categories_order"); $blogCategories = $categories->getBlogCategories($this->_blogInfo->getId(), false, $categoriesOrder); // get some stuff for the time stamp of the post, which is changeable now //$t = new Timestamp(); $t = Timestamp::getBlogDate($this->_blogInfo); //$t->toUTC(); // // changes to make plog store its dates with the time difference already // applied, instead of applying it dynamically // $config =& Config::getConfig(); /*if( $config->getValue( "time_difference_calculation" == TIME_DIFFERENCE_CALCULATION_STATIC ) { $blogSettings = $this->_blogInfo->getSettings(); $difference = $blogSettings->getValue( "time_offset" ); $t->setDate( Timestamp::getDateWithOffset( $t->getDate(), $difference ), DATE_FORMAT_TIMESTAMP ); }*/ // fetch the custom fields, if any, but not including the ones that have been set to "hidden"... $customFields = new CustomFields(); $blogFields = $customFields->getBlogCustomFields($this->_blogInfo->getId(), false); // and put everything in the template $locale = $this->_blogInfo->getLocale(); $this->setValue("commentsEnabled", $blogSettings->getValue("comments_enabled")); $this->setValue("categories", $blogCategories); $this->setValue("today", $t); $this->setValue("months", $locale->getMonthNames()); $this->setValue("days", $locale->getDayNamesShort()); $this->setValue("years", Timestamp::getYears()); $this->setValue("hours", Timestamp::getAllHours()); $this->setValue("minutes", Timestamp::getAllMinutes()); $this->setValue("customfields", $blogFields); $this->setValue("poststatus", ArticleStatus::getStatusList()); $this->setValue("sendPings", $config->getValue("send_xmlrpc_pings_enabled_by_default", true)); $this->setValue("xmlRpcPingEnabled", $config->getValue("xmlrpc_ping_enabled", false)); $this->setValue("autoSaveNewDraftsTimeMillis", $config->getValue("autosave_new_drafts_time_millis")); $this->setValue("xmlHttpRequestSupportEnabled", $config->getValue("save_drafts_via_xmlhttprequest_enabled")); $this->setValue("postDateTime", $t->getDay() . "/" . $t->getMonth() . "/" . $t->getYear() . " " . $t->getHour() . ":" . $t->getMinutes()); parent::render(); }
/** * Carries out the specified action */ function perform() { // get the data from the form $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue("categoryName")); $this->_categoryId = $this->_request->getValue("categoryId"); $this->_categoryDescription = Textfilter::filterAllHTML($this->_request->getValue("categoryDescription")); $this->_categoryInMainPage = $this->_request->getValue("categoryInMainPage"); $this->_properties = array(); // fetch the category we're trying to update $categories = new ArticleCategories(); $category = $categories->getCategory($this->_categoryId, $this->_blogInfo->getId()); if (!$category) { $this->_view = new AdminArticleCategoriesListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_fetching_category")); $this->setCommonData(); return false; } // fire the pre-event $this->notifyEvent(EVENT_PRE_CATEGORY_UPDATE, array("category" => &$category)); // update the fields $category->setName($this->_categoryName); $category->setUrl(""); $category->setInMainPage($this->_categoryInMainPage); $category->setProperties($this->_properties); $category->setDescription($this->_categoryDescription); // this is view we're going to use to show our messages $this->_view = new AdminArticleCategoriesListView($this->_blogInfo); if (!$categories->updateCategory($category)) { $this->_view->setErrorMessage($this->_locale->tr("error_updating_article_category")); } else { // if everything fine, load the list of categories $this->_view->setSuccessMessage($this->_locale->pr("article_category_updated_ok", $category->getName())); // fire the post-event $this->notifyEvent(EVENT_POST_CATEGORY_UPDATE, array("category" => &$category)); // clear the cache CacheControl::resetBlogCache($this->_blogInfo->getId()); } $this->setCommonData(); // better to return true if everything fine return true; }
/** * Carries out the specified action */ function render() { // prepare a few parameters $categories = new ArticleCategories(); $blogSettings = $this->_blogInfo->getSettings(); $categoriesOrder = $blogSettings->getValue("categories_order"); // get the page too $this->_page = $this->getCurrentPageFromRequest(); // retrieve the categories in an paged fashion $totalCategories = $categories->getBlogNumCategories($this->_blogInfo->getId(), true); $blogCategories = $categories->getBlogCategoriesAdmin($this->_blogInfo->getId(), false, $categoriesOrder, $this->_page, DEFAULT_ITEMS_PER_PAGE); if (!$blogCategories) { $blogCategories = array(); } // throw the even in case somebody's waiting for it! $this->notifyEvent(EVENT_CATEGORIES_LOADED, array("categories" => &$blogCategories)); $this->setValue("categories", $blogCategories); // the pager that will be used $pager = new Pager("?op=editArticleCategories&page=", $this->_page, $totalCategories, DEFAULT_ITEMS_PER_PAGE); $this->setValue("pager", $pager); parent::render(); }
function render() { // fetch the current settings $blogSettings = $this->_blogInfo->getSettings(); $pluginEnabled = $blogSettings->getValue("plugin_moblog_enabled"); $categoryId = $blogSettings->getValue("plugin_moblog_article_category_id"); $albumId = $blogSettings->getValue("plugin_moblog_gallery_resource_album_id"); $resourcePreviewType = $blogSettings->getValue("plugin_moblog_resource_preview_type"); // fetch all the current article categories $categories = new ArticleCategories(); $blogCategories = $categories->getBlogCategories($this->_blogInfo->getId()); // fetch all the current gallery albums $albums = new GalleryAlbums(); $blogAlbums = $albums->getUserAlbums($this->_blogInfo->getId()); // finally pass all these things to the templates $this->setValue("pluginEnabled", $pluginEnabled); $this->setValue("categoryId", $categoryId); $this->setValue("albumId", $albumId); $this->setValue("albums", $blogAlbums); $this->setValue("categories", $blogCategories); $this->setValue("resourcePreviewType", $resourcePreviewType); parent::render(); }
/** * Carries out the specified action */ function perform() { // fetch the data, we already know it's valid and that we can trust it! $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue("categoryName")); $this->_categoryUrl = $this->_request->getValue("categoryUrl"); $this->_categoryInMainPage = Textfilter::checkboxToBoolean($this->_request->getValue("categoryInMainPage")); $this->_categoryDescription = Textfilter::filterAllHTML($this->_request->getValue("categoryDescription")); $this->_properties = $this->_request->getValue("properties"); // create the object... $categories = new ArticleCategories(); $category = new ArticleCategory($this->_categoryName, $this->_categoryUrl, $this->_blogInfo->getId(), $this->_categoryInMainPage, $this->_categoryDescription, 0, $this->_properties); // fire the pre event... $this->notifyEvent(EVENT_PRE_CATEGORY_ADD, array("category" => &$category)); // once we have built the object, we can add it to the database! if ($categories->addArticleCategory($category)) { // if everything went fine, transfer the execution flow to the action that // lists all the article categories... without forgetting that we should let the // next class know that we actually added a category alongside a message // and the category that we just added! $this->_view = new AdminArticleCategoriesListView($this->_blogInfo); $this->_view->setSuccess(true); $this->_view->setSuccessMessage($this->_locale->pr("category_added_ok", $category->getName())); // fire the post event $this->notifyEvent(EVENT_POST_CATEGORY_ADD, array("category" => &$category)); // clear the cache if everything went fine CacheControl::resetBlogCache($this->_blogInfo->getId(), false); $this->setCommonData(); } else { // if there was an error, we should say so... as well as not changing the view since // we're going back to the original view where we can add the category $this->_view->setError(true); $this->_view->setErrorMessage($this->_locale->tr("error_adding_article_category")); $this->setCommonData(true); } // better to return true if everything fine return true; }
/** * Removes a blog from the database. It also removes all its posts, its posts categories * its links, its links categories, its trackbacks and its comments * * @param blogId the id of the blog we'd like to delete */ function deleteBlog($blogId) { // first of all, delete the posts $articles = new Articles(); $articles->deleteBlogPosts($blogId); // next is to remove the article categories $articleCategories = new ArticleCategories(); $articleCategories->deleteBlogCategories($blogId); // next, all the links and links categories $myLinks = new MyLinks(); $myLinks->deleteBlogMyLinks($blogId); $myLinksCategories = new MyLinksCategories(); $myLinksCategories->deleteBlogMyLinksCategories($blogId); // the permissions for the blog $perms = new UserPermissions(); $perms->revokeBlogPermissions($blogId); // and finally, delete the blog $query = "DELETE FROM " . $this->getPrefix() . "blogs WHERE id = {$blogId}"; $result = $this->Execute($query); return $result; }
function perform() { // retrieve the values from the view $this->_blogName = $this->_request->getValue("blogName"); $this->_ownerId = $this->_request->getValue("ownerid"); $this->_blogProperties = $this->_request->getValue("properties"); $this->_blogTemplate = $this->_request->getValue("blogTemplate"); $this->_blogLocale = $this->_request->getValue("blogLocale"); // configure the blog $blogs = new Blogs(); $blog = new BlogInfo($this->_blogName, $this->_ownerId, "", ""); $blog->setProperties($this->_blogProperties); $blog->setStatus(BLOG_STATUS_ACTIVE); $blogSettings = $blog->getSettings(); $blogSettings->setValue("locale", $this->_blogLocale); $blogSettings->setValue("template", $this->_blogTemplate); $blog->setSettings($blogSettings); // and now save it to the database $newblogId = $blogs->addBlog($blog); if (!$newblogId) { $this->_view = new WizardView("step4"); $this->_view->setValue("siteLocales", Locales::getLocales()); $ts = new TemplateSets(); $this->_view->setValue("siteTemplates", $ts->getGlobalTemplateSets()); $this->_view->setErrorMessage("There was an error creating the new blog"); $this->setCommonData(true); return false; } // if the blog was created, we can add some basic information // add a category $articleCategories = new ArticleCategories(); $articleCategory = new ArticleCategory("General", "", $newblogId, true); $catId = $articleCategories->addArticleCategory($articleCategory); // load the right locale $locale =& Locales::getLocale($this->_blogLocale); // and load the right text $articleTopic = $locale->tr("register_default_article_topic"); $articleText = $locale->tr("register_default_article_text"); $article = new Article($articleTopic, $articleText, array($catId), $this->_ownerId, $newblogId, POST_STATUS_PUBLISHED, 0, array(), "welcome"); $t = new Timestamp(); $article->setDateObject($t); $articles = new Articles(); $articles->addArticle($article); // save a few things in the default configuration $config =& Config::getConfig(); // default blog id $config->saveValue("default_blog_id", (int) $newblogId); // default locale $config->saveValue("default_locale", $this->_blogLocale); // and finally, the default template $config->saveValue("default_template", $this->_blogTemplate); // // detect wether we have GD available and set the blog to use it // if (GdDetector::detectGd()) { $config->saveValue("thumbnail_method", "gd"); $message = "GD has been detected and set as the backend for dealing with images."; } else { $pathToConvert = $config->getValue("path_to_convert"); if ($pathToConvert) { $config->saveValue("thumbnail_method", "imagemagick"); $message = "ImageMagick has been detected and set as the backend for dealing with images."; } else { // nothing was found, so we'll have to do away with the 'null' resizer... $config->saveValue("thumbnail_method", "null"); $message = "Neither GD nor ImageMagick have been detected in this host so it will not be possible to generate thumbnails from images."; } } $this->_view = new WizardView("step5"); $this->_view->setValue("message", $message); return true; }
public function getDropdown() { global $dataDropdown; $dataDropdown = array(); $parents = ArticleCategories::model()->with('levelTop')->findALl(); foreach ($parents as $parent) { $dataDropdown[$parent->id] = $parent->name; $this->_subDropDown($parent->childCategories); } return $dataDropdown; }
function perform() { $this->_view = new ViewArticleView($this->_blogInfo, array("articleId" => $this->_articleId, "articleName" => $this->_articleName, "categoryId" => $this->_categoryId, "categoryName" => $this->_categoryName, "userId" => $this->_userId, "userName" => $this->_userName, "date" => $this->_date)); if ($this->_view->isCached()) { if ($this->_config->getValue('update_cached_article_reads', false)) { if ($this->_articleId) { $this->articles->updateArticleNumReads($this->_articleId); $this->_updateArticleReferrersById($this->_articleId); } else { $this->articles->updateArticleNumReadsByName($this->_articleName); $this->_updateArticleReferrersByTitle($this->_articleName); } } return true; } // --- // if we got a category name or a user name instead of a category // id and a user id, then we have to look up first those // and then proceed // --- // users... if ($this->_userName) { $users = new Users(); $user = $users->getUserInfoFromUsername($this->_userName); if (!$user) { $this->_setErrorView(); return false; } // if there was a user, use his/her id $this->_userId = $user->getId(); } // ...and categories... if ($this->_categoryName) { $categories = new ArticleCategories(); $category = $categories->getCategoryByName($this->_categoryName, $this->_blogInfo->getId()); if (!$category) { $this->_setErrorView(); return false; } // if there was a user, use his/her id $this->_categoryId = $category->getId(); } // fetch the article // the article identifier can be either its internal id number or its mangled topic if ($this->_articleId) { $article = $this->articles->getBlogArticle($this->_articleId, $this->_blogInfo->getId(), false, $this->_date, $this->_categoryId, $this->_userId, POST_STATUS_PUBLISHED, $this->_maxDate); } else { $article = $this->articles->getBlogArticleByTitle($this->_articleName, $this->_blogInfo->getId(), false, $this->_date, $this->_categoryId, $this->_userId, POST_STATUS_PUBLISHED, $this->_maxDate); } // if the article id doesn't exist, cancel the whole thing... if (!$article) { $this->_setErrorView(); return false; } // throw the correct event $this->notifyEvent(EVENT_POST_LOADED, array("article" => &$article)); // check if we have to update how many times an article has been read if ($this->_config->getValue("update_article_reads")) { $this->updateNumArticleReads($article->getId()); } // update the referrers, if needed $this->_updateArticleReferrers($article); // if everything's fine, we set up the article object for the view $this->_view->setArticle($article); $this->setCommonData(); // and return everything normal return true; }
// now check if the user has permissions over the blog // $userPermissions = new UserPermissions(); $userPerm = $userPermissions->getUserPermissions($userInfo->getId(), $blogInfo->getId()); if (!$userPerm) { $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "You have no permissions in the given blog."); MoblogLogger::log("User '" . $request->getUser() . "' has no permissions in blog " . $request->getBlogId()); $response->send(); return false; } // // if everything's correct, then we can proceed to find if the category // chosen by the user exists. Since there is no way to fetch a category by its name, // we'll have to fetch them all and loop through them // $articleCategories = new ArticleCategories(); // load the category as defined in the plugin settings page $categoryId = $blogSettings->getValue("plugin_moblog_article_category_id"); $category = $articleCategories->getCategory($categoryId, $blogInfo->getId()); // if there was no such category, we should send an error and to make it more useful, send // as part of the error message the list of available categories if (!$category) { $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "The category does not exist."); MoblogLogger::log("User '" . $request->getUser() . "' tried to use category '" . $categoryId . "' which does not exist."); $response->send(); return false; } // // finally, add the resources to the database // // first, create a new album to hold these attachments
/** * create the blog */ function createBlog($userId) { $this->blogName = stripslashes($this->_request->getValue("blogName")); $this->blogLocale = $this->_request->getValue("blogLocale"); $this->templateId = $this->_request->getValue("templateId"); // get the default locale configured for the site $blogs = new Blogs(); $blogInfo = new BlogInfo($this->blogName, $userId, "", ""); if ($this->need_confirm == 1) { $blogInfo->setStatus(BLOG_STATUS_UNCONFIRMED); } else { $blogInfo->setStatus(BLOG_STATUS_ACTIVE); } $locale = Locales::getLocale($this->blogLocale); $blogInfo->setLocale($locale); $blogInfo->setTemplate($this->templateId); $newblogId = $blogs->addBlog($blogInfo); if (!$newblogId) { $this->_view = new SummaryView("registererror"); $this->_view->setErrorMessage($this->_locale->tr("error_creating_blog")); return false; } // get info about the blog $blogInfo = $blogs->getBlogInfo($newblogId); $this->_blogInfo = $blogInfo; // if the blog was created, we can add some basic information // add a category $articleCategories = new ArticleCategories(); $articleCategory = new ArticleCategory($locale->tr("register_default_category"), "", $newblogId, true); $catId = $articleCategories->addArticleCategory($articleCategory); // add an article based on that category $articleTopic = $locale->tr("register_default_article_topic"); $articleText = $locale->tr("register_default_article_text"); $article = new Article($articleTopic, $articleText, array($catId), $userId, $newblogId, POST_STATUS_PUBLISHED, 0, array(), "welcome"); $article->setDateObject(new Timestamp()); // set it to the current date $article->setCommentsEnabled(true); // enable comments $articles = new Articles(); $articles->addArticle($article); return true; }
/** * Returns how many articles have been categorized under this category. * * @param status A valid post status * @return An integer value */ function getNumArticles($status = POST_STATUS_PUBLISHED) { $origStatus = $status; if ($status == POST_STATUS_ALL) { $status = 0; } if (!is_array($this->_numArticles[$status]) || $this->_numArticles[$status] == null) { $categories = new ArticleCategories(); $this->_numArticles[$status] = $categories->getNumArticlesCategory($this->getId(), $origStatus); } return $this->_numArticles[$status]; }
/** * 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(); }
/** * Executes the action */ function perform() { // first of all, we have to determine which blog we would like to see $blogId = $this->_blogInfo->getId(); // fetch the settings for that blog $blogSettings = $this->_blogInfo->getSettings(); // prepare the view $this->_view = new DefaultView($this->_blogInfo, array("categoryId" => $this->_categoryId, "blogId" => $this->_blogInfo->getId(), "categoryName" => $this->_categoryName, "date" => $this->_date, "userName" => $this->_userName, "userId" => $this->_userId)); // check if everything's cached because if it is, then we don't have to // do any work... it's already been done before and we should "safely" assume // that there hasn't been any change so far if ($this->_view->isCached()) { return true; } // if we got a category name instead of a category id, then we // should first look up this category in the database and see if // it exists $categories = new ArticleCategories(); if ($this->_categoryName) { $category = $categories->getCategoryByName($this->_categoryName, $this->_blogInfo->getId()); if (!$category) { $this->_view = new ErrorView($this->_blogInfo); $this->_view->setValue('message', "error_incorrect_category_id"); $this->setCommonData(); return false; } // if everything went fine... $this->_categoryId = $category->getId(); } else { // we don't do anything if the cateogry id is '0' or '-1' if ($this->_categoryId > 0) { $category = $categories->getCategory($this->_categoryId, $this->_blogInfo->getId()); if (!$category) { $this->_view = new ErrorView($this->_blogInfo); $this->_view->setValue('message', "error_incorrect_category_id"); $this->setCommonData(); return false; } } } // export the category object in case it is needed if (isset($category)) { $this->_view->setValue("category", $category); } $users = new Users(); // if we got a user user id, then we should first look up this id // user in the database and see if it exists if ($this->_userId > 0) { $user = $users->getUserInfoFromId($this->_userId); if (!$user) { $this->_view = new ErrorView($this->_blogInfo); $this->_view->setValue('message', 'error_incorrect_user_id'); $this->setCommonData(); return false; } } else { if ($this->_userName) { // if we got a user name instead of a user id, then we // should first look up this user in the database and see if // it exists $user = $users->getUserInfoFromUsername($this->_userName); if (!$user) { $this->_view = new ErrorView($this->_blogInfo); $this->_view->setValue('message', 'error_incorrect_user_username'); $this->setCommonData(); return false; } // if everything went fine... $this->_userId = $user->getId(); } } // export the owner. The owner information should get from blogInfo directly $this->_view->setValue("owner", $this->_blogInfo->getOwnerInfo()); $t = new Timestamp(); $todayTimestamp = $t->getTimestamp(); // amount of posts that we have to show, but keeping in mind that when browsing a // category or specific date, we should show *all* of them if ($this->_date > 0 || $this->_categoryId > 0) { $this->_postAmount = -1; // also, inform the template that we're showing them all! $this->_view->setValue('showAll', true); } else { $this->_postAmount = $blogSettings->getValue('show_posts_max'); $this->_view->setValue('showAll', false); } // // :KLUDGE: // the more things we add here to filter, the more complicated this function // gets... look at this call and look at how many parameters it needs!! :( // if ($blogSettings->getValue('show_future_posts_in_calendar') && $this->_date > -1) { // if posts in the future are to be shown, we shouldn't set a maximum date $blogArticles = $this->articles->getBlogArticles($blogId, $this->_date, $this->_postAmount, $this->_categoryId, POST_STATUS_PUBLISHED, $this->_userId); } else { $blogArticles = $this->articles->getBlogArticles($blogId, $this->_date, $this->_postAmount, $this->_categoryId, POST_STATUS_PUBLISHED, $this->_userId, $todayTimestamp); } // if we couldn't fetch the articles, send an error and quit if (count($blogArticles) == 0) { $this->_view = new ErrorView($this->_blogInfo); $this->_view->setValue('message', 'error_fetching_articles'); } else { // otherwise, continue // the view will take care of cutting the post if we have the "show more" // feature enabled or not... we could do it here but I think that belongs // to the view since it is presentation stuff... It could also be handled // by the template but then it'd make the template a little bit more // complicated... // --- // before finishing, let's see if there's any plugin that would like to do // anything with the post that we just loaded // --- $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('posts', $articles); } $this->setCommonData(); // save the information about the session for later $this->saveSession(); return true; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ArticleCategories the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ArticleCategories::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
function _addCategory($data, $_debug) { if ($data["name"] == NULL) { $data["name"] = "Category"; } if ($data["url"] == NULL) { $data["url"] = ""; } if ($data["blog_id"] == NULL) { $data["blog_id"] = 1; } if ($data["mainpage"] == NULL) { $data["mainpage"] = 1; } $cat = new ArticleCategory($data["name"], $data["url"], $data["blog_id"], $data["mainpage"]); $cats = new ArticleCategories(); if (!($cat_id = $cats->getCategoryByName(TextFilter::urlize($data["name"]), $data["blog_id"]))) { $cat_id = $cats->addArticleCategory($cat); if ($_debug) { print "--- --- category " . $data["name"] . " added with id: " . $cat_id . "<br />\n\r"; } $this->_stats["categories"]["write"]++; } else { if ($_debug) { print "--- --- category " . $data["name"] . " already exists with id: " . $cat_id->getId() . "<br />\n\r"; } $cat_id = $cat_id->getId(); } // remap posts' category attribute to the correct ids. foreach ($this->_t_container["posts"] as $post => $val) { if ($val["category"] == $data["id"] || $val["category"] == NULL && $this->_container["posts"][$post]["blog_id"] == $data["blog_id"]) { if ($_debug) { print "--- --- --- remapping post entry #" . $post . " to proper category id<br />\n\r"; } $this->_container["posts"][$post]["category"] = $cat_id; } } return $cat_id; }
public function getCat() { return $this->hasOne(ArticleCategories::className(), ['id' => 'catid']); }
<!-- hinh anh --> <?php require_once dirname(__FILE__) . './../jfileupload/_upload.php'; ?> <?php $selected_categories = array(); foreach ($model->categories as $categories) { array_push($selected_categories, $categories->id); } ?> <div class="control-group"> <div class="control-label"> <label>Loại bài viết</label> </div> <div class="controls"> <?php echo CHtml::checkBoxList('categories', $selected_categories, CHtml::listData(ArticleCategories::model()->findAll('t.active=1 AND t.delete=0'), 'id', 'name'), array('template' => '<label class="checkbox">{input} {label}</label>', 'labelOptions' => array('style' => 'display:inline;'), 'separator' => '')); ?> </div> </div> <div class="control-group"> <div class="control-label"><?php echo $form->labelEx($model, 'summary'); ?> </div> <div class="controls"><?php echo $form->textArea($model, 'summary', array('class' => 'input-xxlarge', 'size' => 60, 'maxlength' => 500)); ?> </div> <div class="controls"><?php echo $form->error($model, 'summary');
public function actionArticleOfAreaDetail($id) { $model = ArticleOfArea::model()->findByAttributes(array('non_utf8_name' => $id)); if ($model === null || $model->active == 0 || $model->delete == 1) { throw new CHttpException(404, 'The requested page does not exist.'); } $this->pageTitle = $model->name . ' - ' . Config::model()->getValueByKey('sitetitle'); $this->metaDescription = $model->metadescription; $this->metaKeywords = $model->metakeywords; // danh sach cac bai viet khac cung the loai $otherArticle = array(); // danh sach cac category $criteria = new CDbCriteria(); $criteria->addCondition("t.active=1"); $criteria->addCondition("t.delete=0"); $criteria->addCondition("t.id!=1"); $criteria->order = "t.order, t.id DESC"; $categories = ArticleCategories::model()->findAll($criteria); $this->render('article', array('model' => $model, 'otherArticle' => $otherArticle, 'categories' => $categories)); }