/**
  * Constructor. It initializes certain things such as the base url, checks whether subdomains are
  * enabled, etc. This method will fetch the values of the following configuration settings:
  *
  * - base_url: this is the base URL that will be used to generate all other URLs in the system
  * - subdomains_base_url: if subdomains are enabled, we should also set this URL to something valid. We can
  *   either use {blogname} or {username} to specify whether the URLs should be generated including the
  *   name of the user who owns the blog or the name of the blog.
  * - include_blog_id_in_url
  * - script_name: use this setting to rename index.php to something else and still have pLog generate
  *   URLs pointing to the right script.
  *
  * @param blogInfo A valid BlogInfo object
  */
 function BaseRequestGenerator($blogInfo = null)
 {
     $this->Object();
     $this->_params = array();
     $this->_blogInfo = $blogInfo;
     $config =& Config::getConfig();
     $this->_baseUrl = $config->getValue("base_url");
     $this->_subdomainsBaseUrl = $config->getValue("subdomains_base_url");
     // get some information about the configuration of subdomains
     $this->_subdomainsEnabled = $config->getValue("subdomains_enabled");
     if ($this->_subdomainsEnabled) {
         $this->_includeBlogId = $config->getValue("include_blog_id_in_url");
     } else {
         $this->_includeBlogId = true;
     }
     // prepare the correct url if subdomains are enabled...
     if ($this->_subdomainsEnabled && $blogInfo != null) {
         $this->_subdomainsBaseUrl = str_replace("{blogname}", Textfilter::urlize($blogInfo->getBlog()), $this->_subdomainsBaseUrl);
         $ownerInfo = $blogInfo->getOwnerInfo();
         $this->_subdomainsBaseUrl = str_replace("{username}", Textfilter::urlize($ownerInfo->getUsername()), $this->_subdomainsBaseUrl);
     }
     $this->_scriptName = $config->getValue("script_name", DEFAULT_SCRIPT_NAME);
     // enable the xhtml mode by default, but it can be turned off
     // via the setXHTML() method
     $this->_xhtmlEnabled = true;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // fetch the settings from the db and update them accordingly
     $blogs = new Blogs();
     $blogSettings = $blogs->getBlogSettings($this->_blogInfo->getId());
     $blogSettings->setValue("locale", $this->_request->getValue("blogLocale"));
     $blogSettings->setValue("show_posts_max", $this->_request->getValue("blogMaxMainPageItems"));
     $blogSettings->setValue("recent_posts_max", $this->_request->getValue("blogMaxRecentItems"));
     $blogSettings->setValue("template", $this->_request->getValue("blogTemplate"));
     $blogSettings->setValue("time_offset", $this->_request->getValue("blogTimeOffset"));
     $blogSettings->setValue("categories_order", $this->_request->getValue("blogCategoriesOrder"));
     $blogSettings->setValue("link_categories_order", $this->_request->getValue("blogLinkCategoriesOrder"));
     $blogSettings->setValue("show_more_enabled", Textfilter::checkboxToBoolean($this->_request->getValue("blogShowMoreEnabled")));
     $blogSettings->setValue("htmlarea_enabled", Textfilter::checkboxToBoolean($this->_request->getValue("blogEnableHtmlarea")));
     $blogSettings->setValue("comments_enabled", Textfilter::checkboxToBoolean($this->_request->getValue("blogCommentsEnabled")));
     $blogSettings->setValue("show_future_posts_in_calendar", Textfilter::checkboxToBoolean($this->_request->getValue("blogShowFuturePosts")));
     $blogSettings->setValue("new_drafts_autosave_enabled", Textfilter::checkboxToBoolean($this->_request->getValue("blogEnableAutosaveDrafts")));
     $blogSettings->setValue("comments_order", $this->_request->getValue("blogCommentsOrder"));
     $this->_blogInfo->setAbout(Textfilter::filterAllHTML($this->_request->getValue("blogAbout")));
     $this->_blogInfo->setBlog(Textfilter::filterAllHTML($this->_request->getValue("blogName")));
     $this->_blogInfo->setSettings($blogSettings);
     $this->_blogInfo->setProperties($this->_request->getValue("properties"));
     $this->_blogInfo->setMangledBlog(Textfilter::urlize($this->_blogInfo->getBlog()));
     // and now update the settings in the database
     $blogs = new Blogs();
     // and now we can proceed...
     $this->notifyEvent(EVENT_PRE_BLOG_UPDATE, array("blog" => &$this->_blogInfo));
     if (!$blogs->updateBlog($this->_blogInfo->getId(), $this->_blogInfo)) {
         $this->_view = new AdminBlogSettingsView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_locale->tr("error_updating_settings"));
         $this->setCommonData();
         return false;
     }
     // do it again, baby :)))
     $this->_blogInfo->setAbout(Textfilter::filterAllHTML(stripslashes($this->_request->getValue("blogAbout"))));
     $this->_blogInfo->setBlog(Textfilter::filterAllHTML(stripslashes($this->_request->getValue("blogName"))));
     $this->_blogInfo->setSettings($blogSettings);
     $this->_blogInfo->setProperties($this->_blogProperties);
     $this->_session->setValue("blogInfo", $this->_blogInfo);
     $this->saveSession();
     $this->notifyEvent(EVENT_POST_BLOG_UPDATE, array("blog" => &$this->_blogInfo));
     $this->_view = new AdminBlogSettingsView($this->_blogInfo);
     $this->_locale =& Locales::getLocale($blogSettings->getValue("locale"));
     $this->_view->setSuccessMessage($this->_locale->pr("blog_settings_updated_ok", $this->_blogInfo->getBlog()));
     $this->setCommonData();
     // clear the cache
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     // better to return true if everything fine
     return true;
 }
 /**
  * @private
  */
 function _fillResourceParameters($resource)
 {
     $album = $resource->getAlbum();
     $blogId = $this->_blogInfo->getId();
     $ownerId = $resource->getOwnerId();
     if ($blogId != $ownerId) {
         $blogId = $ownerId;
         $blogs =& new Blogs();
         $blogInfo = $blogs->getBlogInfo($blogId);
         $blogShortName = $blogInfo->getMangledBlog();
         $ownerInfo = $blogInfo->getOwnerInfo();
     } else {
         $blogShortName = $this->_blogInfo->getMangledBlog();
         $ownerInfo = $this->_blogInfo->getOwnerInfo();
     }
     $params = array("{blogid}" => $blogId, "{blogname}" => $blogShortName, "{blogowner}" => $ownerInfo->getUsername(), "{resourceid}" => $resource->getId(), "{resourcename}" => rawurlencode($resource->getFileName()), "{albumid}" => $album->getId(), "{albumname}" => Textfilter::urlize($album->getName()));
     return $params;
 }
 function getMangledBlog()
 {
     // fill in the field if it hasn't been filled yet
     if ($this->_mangledBlog === null) {
         $this->_mangledBlog = Textfilter::urlize($this->getBlog());
     }
     return $this->_mangledBlog;
 }
 /**
  * sets a new post slug
  *
  * @param slug the new post slug
  */
 function setPostSlug($slug)
 {
     $this->_slug = Textfilter::urlize($slug);
 }
 /**
  * Adds an album to the database
  *
  * @param album A GalleryAlbum object, with all its data filled in
  * @return Returns true if successful or false otherwise.
  * @see GAlleryAlbum
  */
 function addAlbum($album)
 {
     $tf = new Textfilter();
     $query = "INSERT INTO " . $this->getPrefix() . "gallery_albums (\n                      owner_id, description, name, flags, parent_id, properties, \n                      show_album, normalized_name, normalized_description, mangled_name )\n                      VALUES (" . $album->getOwnerId() . ", '" . Db::qstr($album->getDescription()) . "', '" . Db::qstr($album->getName()) . "', 0, " . $album->getParentId() . ", '" . serialize($album->getProperties()) . "', " . $album->getShowAlbum() . " ,'" . Db::qstr($tf->normalizeText($album->getName())) . "','" . Db::qstr($tf->normalizeText($album->getDescription())) . "', '" . $tf->urlize($album->getName()) . "');";
     $result = $this->Execute($query);
     if (!$result) {
         return false;
     }
     // return the id of the last row we inserted, which will be the id of the album
     $result = $this->_db->Insert_ID();
     return $result;
 }
 /**
  * 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;
 }