/**
  * Validate if everything is correct
  */
 function validate()
 {
     // first of all, check if we have a valid blog id
     $this->_blogId = $this->_request->getValue("blogId");
     if ($this->_blogId == "" || $this->_blogId < 0) {
         // check if the user really belongs to one or more blogs and if not, quit
         $users = new Users();
         $userBlogs = $users->getUsersBlogs($this->_userInfo->getId(), BLOG_STATUS_ACTIVE);
         if (count($userBlogs) == 0) {
             $this->_view = new AdminSimpleErrorView();
             $this->_view->setValue("message", $this->_locale->tr("error_dont_belong_to_any_blog"));
             return false;
         }
         // if everything went fine, then we can continue...
         $this->_view = new AdminDashboardView($this->_userInfo, $userBlogs);
         return false;
     }
     // load the blog
     $blogs = new Blogs();
     $this->_blogInfo = $blogs->getBlogInfo($this->_blogId);
     // check if the blog really exists
     if (!$this->_blogInfo) {
         $this->_view = new AdminSimpleErrorView();
         $this->_view->setValue("message", $this->_locale->tr("error_incorrect_blog_id"));
         return false;
     }
     // if so, check that it is active
     if ($this->_blogInfo->getStatus() != BLOG_STATUS_ACTIVE) {
         $this->_view = new AdminSimpleErrorView();
         $this->_view->setValue("message", $this->_locale->tr("error_incorrect_blog_id"));
         return false;
     }
     // if the blog identifier is valid, now we should now check if the user belongs
     // to that blog so that we know for sure that nobody has tried to forge the
     // parameter in the meantime
     $userPermissions = new UserPermissions();
     $blogUserPermissions = $userPermissions->getUserPermissions($this->_userInfo->getId(), $this->_blogInfo->getId());
     if (!$blogUserPermissions) {
         $this->_view = new AdminSimpleErrorView();
         $this->_view->setValue("message", $this->_locale->tr("error_no_permissions"));
         return false;
     }
     // if all correct, we can now set the blogInfo object in the session for later
     // use
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $session = HttpVars::getSession();
     $session["SessionInfo"] = $this->_session;
     HttpVars::setSession($session);
     return true;
 }
Пример #2
0
//
// check if the plugin has been enabled for this blog
//
$blogSettings = $blogInfo->getSettings();
$pluginEnabled = $blogSettings->getValue("plugin_moblog_enabled");
if (!$pluginEnabled) {
    $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "The plugin has not been enabled for this blog.");
    MoblogLogger::log("Plugin not enabled for blog " . $request->getBlogId());
    $response->send();
    return false;
}
//
// 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());