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;
 }
 function perform()
 {
     // get the data
     $this->_userId = $this->_request->getValue("userId");
     $this->_userPassword = trim(Textfilter::filterAllHTML($this->_request->getValue("userProfilePassword")));
     $this->_userEmail = Textfilter::filterAllHTML($this->_request->getValue("userEmail"));
     $this->_userAbout = Textfilter::filterAllHTML($this->_request->getValue("userAbout"));
     $this->_userFullName = Textfilter::filterAllHTML($this->_request->getValue("userFullName"));
     $this->_adminPrivs = $this->_request->getValue("userIsSiteAdmin");
     $this->_userProperties = $this->_request->getValue("properties");
     $this->_userStatus = $this->_request->getValue("userStatus");
     // load the user settings
     $users = new Users();
     $user = $users->getUserInfoFromId($this->_userId);
     // if no info could be fetched, shown an error and quit
     if (!$user) {
         $this->_view = new AdminSiteUsersListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_invalid_user"));
         $this->setCommonData();
         return false;
     }
     // update the user settings
     $user->setEmail($this->_userEmail);
     $user->setAboutMyself($this->_userAbout);
     $user->setSiteAdmin($this->_adminPrivs);
     $user->setFullName($this->_userFullName);
     $user->setProperties($this->_userProperties);
     $user->setStatus($this->_userStatus);
     if ($this->_userPassword != "") {
         $user->setPassword($this->_userPassword);
     }
     $this->notifyEvent(EVENT_PRE_USER_UPDATE, array("user" => &$user));
     // and now update them
     if (!$users->updateUser($user)) {
         $this->_view = new AdminSiteUsersListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_user"));
         $this->setCommonData();
         return false;
     }
     // the post-update event... if needed
     $this->notifyEvent(EVENT_POST_USER_UPDATE, array("user" => &$user));
     $this->_view = new AdminSiteUsersListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("user_updated_ok", $user->getUsername()));
     $this->setCommonData();
     return true;
 }
 function perform()
 {
     // load the user settings
     $this->_userId = $this->_request->getValue("userId");
     $users = new Users();
     $user = $users->getUserInfoFromId($this->_userId);
     // if no info could be fetched, shown an error and quit
     if (!$user) {
         $this->_view = new AdminSiteUsersListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_invalid_user"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_USER_LOADED, array("user" => &$user));
     // start the view and render it
     $this->_view = new AdminEditSiteUserView($this->_blogInfo, $user);
     $this->setCommonData();
     return true;
 }
 /**
  * Loads the user info and show it
  */
 function perform()
 {
     $this->_userId = $this->_request->getValue("userId");
     $this->_view = new SummaryCachedView("userprofile", array("summary" => "userProfile", "userId" => $this->_userId, "locale" => $this->_locale->getLocaleCode()));
     if ($this->_view->isCached()) {
         // nothing to do, the view is cached
         return true;
     }
     // load some information about the user
     $users = new Users();
     $userInfo = $users->getUserInfoFromId($this->_userId, true);
     if (!$userInfo) {
         $this->_view = new SummaryCachedView("userlist", array("summary" => "UserList", "page" => 1, "locale" => $this->_locale->getLocaleCode()));
         $this->setCommonData();
         return false;
     }
     $this->_view->setValue("user", $userInfo);
     $this->setCommonData();
     return true;
 }
 /**
  * @private
  */
 function _disableUsers()
 {
     $errorMessage = "";
     $successMessage = "";
     $totalOk = 0;
     $users = new Users();
     // go user by user to remove them
     foreach ($this->_userIds as $userId) {
         // get some info about the user
         $userInfo = $users->getUserInfoFromId($userId);
         if (!$userInfo) {
             $errorMessage .= $this->_locale->pr("error_invalid_user2", $userId) . "<br/>";
         } else {
             $this->notifyEvent(EVENT_PRE_USER_DELETE, array("user" => &$userInfo));
             if (!$users->disableUser($userId)) {
                 $errorMessage .= $this->_locale->pr("error_deleting_user", $userInfo->getUsername()) . "<br/>";
             } else {
                 $totalOk++;
                 if ($totalOk < 2) {
                     $successMessage = $this->_locale->pr("user_deleted_ok", $userInfo->getUsername());
                 } else {
                     $successMessage = $this->_locale->pr("users_deleted_ok", $totalOk);
                 }
                 // notify of the post delete event
                 $this->notifyEvent(EVENT_POST_USER_DELETE, array("user" => &$userInfo));
             }
         }
     }
     // prepare the view
     $this->_view = new AdminSiteUsersListView($this->_blogInfo);
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     $this->setCommonData();
     return false;
 }
 function _revokePermissions()
 {
     // now that we have the list of users we'd like to remove
     // let's go through it and remove those that have been selected
     $users = new Users();
     $userPermissions = new UserPermissions();
     $successMessage = "";
     $errorMessage = "";
     $totalOk = 0;
     foreach ($this->_userIds as $userId) {
         $res = $userPermissions->revokePermission($userId, $this->_blogInfo->getId(), PERMISSION_BLOG_USER);
         $userInfo = $users->getUserInfoFromId($userId);
         if ($res) {
             $totalOk++;
             if ($totalOk < 2) {
                 $successMessage = $this->_locale->pr("user_removed_from_blog_ok", $userInfo->getUsername());
             } else {
                 $successMessage = $this->_locale->pr("users_removed_from_blog_ok", $totalOk);
             }
         } else {
             if ($userInfo) {
                 $errorMessage .= $this->_locale->pr("error_removing_user_from_blog", $userInfo->getUsername()) . "<br/>";
             } else {
                 $errorMessage .= $this->_locale->pr("error_removing_user_from_blog2", $userId) . "<br/>";
             }
         }
     }
     $this->_view = new AdminBlogUsersListView($this->_blogInfo);
     if ($successMessage != "") {
         $this->_view->setSuccessMessage($successMessage);
     }
     if ($errorMessage != "") {
         $this->_view->setErrorMessage($errorMessage);
     }
     $this->setCommonData();
     return true;
 }
 function _addUser($data, $_debug)
 {
     if ($data["username"] == NULL) {
         $data["username"] = "******";
     }
     if ($data["password"] == NULL) {
         $data["password"] = "******";
     }
     if ($data["email"] == NULL) {
         $data["email"] = "email address";
     }
     if ($data["about"] == NULL) {
         $data["about"] = "NA";
     }
     if ($data["fullname"] == NULL) {
         $data["fullname"] = "Full Name";
     }
     $users = new Users();
     if ($data["id"]) {
         $user = $users->getUserInfoFromId($data["id"]);
         if ($user) {
             if ($user->getUsername() == $data["username"]) {
                 if ($_debug) {
                     print "--- user " . $data["username"] . " already exists, at the proper id (" . $data["id"] . ").  next entry.<br />\n\r";
                 }
                 return $data["id"];
             }
         }
     }
     $user = $users->getUserInfoFromUsername($data["username"]);
     if ($user) {
         if ($user->getUsername() == $data["username"]) {
             $user_id = $user->getId();
         }
     } else {
         $user = new UserInfo($data["username"], $data["password"], $data["email"], $data["about"], $data["fullname"], "");
         $user_id = $users->addUser($user);
         $this->_stats["users"]["write"]++;
     }
     if ($_debug) {
         print "--- user " . $data["username"] . " has id number: " . $user_id . "<br />\n\r";
     }
     if (!($user_id == $data["id"])) {
         // remap blogs
         foreach ($this->_t_container["blogs"] as $blog => $val) {
             if ($val["owner"] == $data["id"] || $val["owner"] == NULL) {
                 $this->_container["blogs"][$blog]["owner"] = $user_id;
                 if ($_debug) {
                     print "--- --- remapping blog entry #" . $blog . " to proper user id<br />\n\r";
                 }
             }
         }
         // remap posts
         foreach ($this->_t_container["posts"] as $post => $val) {
             if ($val["user_id"] == $data["id"] || $val["user_id"] == NULL) {
                 $this->_container["posts"][$post]["user_id"] = $user_id;
                 if ($_debug) {
                     print "--- --- remapping post entry #" . $post . " to proper user id<br />\n\r";
                 }
             }
         }
     }
     return $user_id;
 }
 /**
  * Notifies all the users of new comments in a post
  *
  * @param postId The post we want to check if there are notifications
  * @param blogId Just in case, the blog to which that post belongs.
  */
 function notifyUsers($postId, $blogInfo, $message = null)
 {
     $blogId = $blogInfo->getId();
     $artNotifs = $this->getArticleNotifications($postId, $blogId);
     // default message.
     // NOTE: Should this be translatable???
     if ($message == null) {
         $message = "There has been actitivity in the article with id " . $postId;
     }
     if (empty($artNotifs)) {
         return;
     }
     $articles = new Articles();
     $article = $articles->getBlogArticle($postId, $blogId);
     // get the correct character set
     $blogLocale =& $blogInfo->getLocale();
     $charset = $blogLocale->getCharset();
     $users = new Users();
     foreach ($artNotifs as $notif) {
         $userInfo = $users->getUserInfoFromId($notif->getUserId());
         $message = $this->renderMessageTemplate($article, $blogInfo);
         $this->notifyUser($notif, $userInfo, "pLog Notification", $message, $charset);
     }
 }
 /**
  * Gets information about the owner of this blog
  * @return return a UserInfo object which contains much more info about the owner of the blog
  */
 function getOwnerInfo()
 {
     if ($this->_ownerInfo == null) {
         $users = new Users();
         $ownerInfo = $users->getUserInfoFromId($this->_owner);
         $this->setOwnerInfo($ownerInfo);
     }
     return $this->_ownerInfo;
 }
 /**
  * Returns the UserInfo object containing information about the owner of this post.
  *
  * @return A UserInfo object.
  * @see UserInfo
  */
 function getUserInfo()
 {
     // load the user if it hasn't been loaded yet
     if ($this->_userInfo == null) {
         $users = new Users();
         $this->setUserInfo($users->getUserInfoFromId($this->getUser()));
     }
     return $this->_userInfo;
 }
 /**
  * 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;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the values from the form which have already been validated
     $this->_blogName = Textfilter::filterAllHTML($this->_request->getValue("blogName"));
     $this->_blogLocale = $this->_request->getValue("blogLocale");
     $this->_blogTemplate = $this->_request->getValue("blogTemplate");
     $this->_blogOwner = $this->_request->getValue("blogOwner");
     $this->_editBlogId = $this->_request->getValue("blogId");
     $this->_blogTimeOffset = $this->_request->getValue("blogTimeOffset");
     $this->_blogProperties = $this->_request->getValue("properties");
     $this->_blogQuota = $this->_request->getValue("blogResourcesQuota");
     $this->_blogUsers = $this->_request->getValue("blogUsers");
     $this->_blogStatus = $this->_request->getValue("blogStatus");
     //print_r($_REQUEST);
     // get the blog we're trying to update
     $blogs = new Blogs();
     $blogInfo = $blogs->getBlogInfo($this->_editBlogId);
     if (!$blogInfo) {
         $this->_view = new AdminSiteBlogsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_fetching_blog"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_BLOG_LOADED, array("blog" => &$blogInfo));
     // make sure that the user we'd like to set as owner exists
     $users = new Users();
     $userInfo = $users->getUserInfoFromId($this->_blogOwner);
     if (!$userInfo) {
         $this->_view = new AdminSiteBlogsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_incorrect_blog_owner"));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_USER_LOADED, array("user" => &$userInfo));
     // set the different settings
     $blogSettings = $blogInfo->getSettings();
     $blogSettings->setValue("locale", $this->_blogLocale);
     $blogSettings->setValue("template", $this->_blogTemplate);
     $blogSettings->setValue("time_offset", $this->_blogTimeOffset);
     $blogInfo->setSettings($blogSettings);
     $blogInfo->setResourcesQuota($this->_blogQuota);
     $blogInfo->setBlog($this->_blogName);
     $blogInfo->setProperties($this->_blogProperties);
     $blogInfo->setOwner($this->_blogOwner);
     $blogInfo->setStatus($this->_blogStatus);
     $blogInfo->setMangledBlog(Textfilter::urlize($blogInfo->getBlog()));
     $this->notifyEvent(EVENT_PRE_BLOG_UPDATE, array("blog" => &$blogInfo));
     if (!$blogs->updateBlog($blogInfo->getId(), $blogInfo)) {
         $this->_view = new AdminSiteBlogsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->pr("error_updating_blog_settings", $blogInfo->getBlog()));
         $this->setCommonData();
         return false;
     }
     // update the user permissions, even if they didn't change (but we have no way to
     // check that anyway!)
     $permissions = new UserPermissions();
     if (!$permissions->updateBlogUserPermissions($this->_editBlogId, $this->_blogUsers)) {
         $this->_view = new AdminSiteBlogsListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->pr("error_updating_blog_settings", $blogInfo->getBlog()));
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_BLOG_UPDATE, array("blog" => &$blogInfo));
     // do it again, baby :)))
     if ($this->_blogInfo->getId() == $blogInfo->getId()) {
         $this->_blogInfo->setSettings($blogSettings);
         $blogInfo->setProperties($this->_blogProperties);
         $this->_session->setValue("blogInfo", $this->_blogInfo);
         $this->saveSession();
     }
     // if everything went fine, we can show a nice message
     $this->_view = new AdminSiteBlogsListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr("edit_blog_settings_updated_ok", $blogInfo->getBlog()));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($blogInfo->getId());
     // better to return true if everything fine
     return true;
 }
 /**
  * returns the usernames of the users who have permissions in a blog
  *
  * @param blogId
  * @retur An array of UserInfo objects
  */
 function getBlogUsers($blogId)
 {
     $query = "SELECT * FROM " . $this->getPrefix() . "users_permissions WHERE blog_id = '" . Db::qstr($blogId) . "'";
     $result = $this->Execute($query);
     if (!$result) {
         return false;
     }
     $blogUsers = array();
     $users = new Users();
     while ($row = $result->FetchRow()) {
         $blogUsers[] = $users->getUserInfoFromId($row["user_id"]);
     }
     return $blogUsers;
 }