/** * 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; }
/** * 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; }
/** * 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; }
$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 $albums = new GalleryAlbums(); $userAlbums = $albums->getUserAlbums($blogInfo->getId()); $t = new Timestamp();
/** * 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; }