/**
  * Performs the action.
  */
 function perform()
 {
     // fetch the articles for the given blog
     $articles = new Articles();
     $blogSettings = $this->_blogInfo->getSettings();
     $localeCode = $blogSettings->getValue("locale");
     // fetch the default profile as chosen by the administrator
     $defaultProfile = $this->_config->getValue("default_rss_profile");
     if ($defaultProfile == "" || $defaultProfile == null) {
         $defaultProfile = DEFAULT_PROFILE;
     }
     // fetch the profile
     // if the profile specified by the user is not valid, then we will
     // use the default profile as configured
     $profile = $this->_request->getValue("profile");
     if ($profile == "") {
         $profile = $defaultProfile;
     }
     // fetch the category, or set it to '0' otherwise, which will mean
     // fetch all the most recent posts from any category
     $categoryId = $this->_request->getValue("categoryId");
     if (!is_numeric($categoryId)) {
         $categoryId = 0;
     }
     // check if the template is available
     $this->_view = new RssView($this->_blogInfo, $profile, array("profile" => $profile, "categoryId" => $categoryId));
     // do nothing if the view was already cached
     if ($this->_view->isCached()) {
         return true;
     }
     // create an instance of a locale object
     $locale = Locales::getLocale($localeCode);
     // fetch the posts, though we are going to fetch the same amount in both branches
     $amount = $blogSettings->getValue("recent_posts_max", 15);
     $t = new Timestamp();
     if ($blogSettings->getValue('show_future_posts_in_calendar')) {
         $blogArticles = $articles->getBlogArticles($this->_blogInfo->getId(), -1, $amount, $categoryId, POST_STATUS_PUBLISHED, 0);
     } else {
         $today = $t->getTimestamp();
         $blogArticles = $articles->getBlogArticles($this->_blogInfo->getId(), -1, $amount, $categoryId, POST_STATUS_PUBLISHED, 0, $today);
     }
     $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("locale", $locale);
     $this->_view->setValue("posts", $articles);
     $this->setCommonData();
     return true;
 }
 /**
  * Constructor.
  *
  * @param actionInfo An ActionInfo object as provided by the constroller
  * @param request A valid HTTP request
  */
 function AdminAction($actionInfo, $request)
 {
     $this->Action($actionInfo, $request);
     // get information about the session
     $session = HttpVars::getSession();
     $this->_session = $session["SessionInfo"];
     $this->_config =& Config::getConfig();
     // get the information about the user and quit if we don't have it...
     $this->_getUserInfo();
     if ($this->_userInfo == "") {
         header("HTTP/1.0 403 Forbidden");
         print $this->mustAuthenticatePage();
         die;
     }
     // do the same with the information about the blog
     $this->_getBlogInfo();
     if ($this->_blogInfo == "") {
         if ($this->_actionInfo->getActionParamValue() != "blogSelect") {
             header("HTTP/1.0 403 Forbidden");
             print $this->mustAuthenticatePage();
             die;
         }
     }
     // prepare the plugin manager in case we'd like to throw events
     $this->_pm =& PluginManager::getPluginManager();
     // fetch the site locale
     $this->_locale =& $this->getLocale();
     $users =& new Users();
     $this->_userBlogs = $users->getUsersBlogs($this->_userInfo->getId(), BLOG_STATUS_ACTIVE);
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // get the parameters, which have already been validated
     $this->_userName = Textfilter::filterAllHTML($this->_request->getValue("userName"));
     $this->_userPassword = $this->_request->getValue("userPassword");
     $this->_op = Textfilter::filterAllHTML($this->_request->getValue("op"));
     // create a plugin manager
     $pm =& PluginManager::getPluginManager();
     // try to authenticate the user
     $users = new Users();
     if (!$users->authenticateUser($this->_userName, $this->_userPassword)) {
         $this->_view = new AdminDefaultView();
         $this->_view->setErrorMessage($this->_locale->tr("error_incorrect_username_or_password"));
         $this->setCommonData();
         $pm->notifyEvent(EVENT_LOGIN_FAILURE, array("user" => $this->_userName));
         return false;
     }
     // if the user is correct, get and put his or her information in the session
     $userInfo = $users->getUserInfo($this->_userName, $this->_userPassword);
     if (!$userInfo) {
         $this->_view = new AdminDefaultView();
         $this->_view->setErrorMessage($this->_locale->tr("error_incorrect_username_or_password"));
         $this->setCommonData();
         $pm->notifyEvent(EVENT_LOGIN_FAILURE, array("user" => $this->_userName));
         return false;
     }
     $pm->notifyEvent(EVENT_USER_LOADED, array("user" => &$userInfo, "from" => "Login"));
     //$sessionInfo = $_SESSION["SessionInfo"];
     $session = HttpVars::getSession();
     $sessionInfo = $session["SessionInfo"];
     $sessionInfo->setValue("userInfo", $userInfo);
     $session["SessionInfo"] = $sessionInfo;
     HttpVars::setSession($session);
     // get the list of blogs to which the user belongs
     $userBlogs = $users->getUsersBlogs($userInfo->getId(), BLOG_STATUS_ACTIVE);
     // but if he or she does not belong to any yet, we quit
     if (empty($userBlogs)) {
         $this->_view = new AdminDefaultView();
         $this->_view->setErrorMessage($this->_locale->tr("error_dont_belong_to_any_blog"));
         $this->setCommonData();
         return false;
     }
     $pm->notifyEvent(EVENT_BLOGS_LOADED, array("blogs" => &$userBlogs, "from" => "Login"));
     // check if we are skipping the dashboard
     if ($this->_config->getValue("skip_dashboard")) {
         // get the first blog that came
         $this->_blogInfo = end($userBlogs);
         // set it in the session
         $session = HttpVars::getSession();
         $session["SessionInfo"]->setValue("blogInfo", $this->_blogInfo);
         HttpVars::setSession($session);
         // and then continue...
         AdminController::setForwardAction("newPost");
     } else {
         $this->_view = new AdminDashboardView($userInfo, $userBlogs);
     }
     // better to return true if everything's fine
     return true;
 }
 /**
  * @see SmartyView
  */
 function BlogView($blogInfo, $template, $cachingEnabled = SMARTY_VIEW_CACHE_CHECK, $data = array())
 {
     // the SmartyView will generate the right Template object for us
     $this->SmartyView($blogInfo, $template, $cachingEnabled, $data);
     $this->articles = new Articles();
     $this->_pm =& PluginManager::getPluginManager();
     $this->_pm->setBlogInfo($this->_blogInfo);
     // set the character set in the request based on the blog locale
     $locale = $this->_blogInfo->getLocale();
     $this->setCharset($locale->getCharset());
 }
 /**
  * Calls the parent constructor and initializes the template service used
  * to fetch the templates
  *
  * @param blogInfo A valid BlogInfo object
  */
 function AdminView($blogInfo)
 {
     $this->View();
     $this->_templateService = new TemplateService();
     $this->_blogInfo = $blogInfo;
     $this->setValue('url', RequestGenerator::getRequestGenerator($blogInfo));
     $blogSettings = $this->_blogInfo->getSettings();
     // initialize the plugin manager, so that we can throw events from views too!
     $this->_pm =& PluginManager::getPluginManager();
     $this->_pm->setBlogInfo($this->_blogInfo);
     // set the character set in the request based on the blog locale
     $locale = $this->_blogInfo->getLocale();
     $this->setCharset($locale->getCharset());
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // initialize the view, but we first check if there is session information avaible
     // since in that case we will not make the user choose enter user and pass again, but
     // show the main menu page straight away
     if ($this->sessionInfoAvailable()) {
         AdminController::setForwardAction("emptyAction");
         // launch the event since we have all the info we need
         $pm =& PluginManager::getPluginManager();
         $pm->setBlogInfo($this->_blogInfo);
         $pm->setUserInfo($this->_userInfo);
         $pm->notifyEvent(EVENT_LOGIN_SUCCESS);
     } else {
         $this->_view = new AdminDefaultView();
     }
     // better to return true if everything fine
     return true;
 }
 /**
  * Constructor. Additionally, it fetches the SessionInfo object from
  * the session information
  *
  *
  */
 function BlogAction($actionInfo, $request)
 {
     $this->Action($actionInfo, $request);
     // we use the HttpVars package since then we can access the session object
     // independently wether we're using php ver. < 4.1.0 or not
     $session = HttpVars::getSession();
     $this->_session = $session['SessionInfo'];
     $this->_config =& Config::getConfig();
     $this->_getBlogInfo();
     // save the blogid in the session
     $this->_session->setValue('blogId', $this->_blogInfo->getId());
     $this->checkDateParameter();
     // initialize the plugin manager
     $this->_pm =& PluginManager::getPluginManager();
     $this->_pm->setBlogInfo($this->_blogInfo);
     $this->_pm->setUserInfo($this->_userInfo);
     // locale
     $this->_locale = $this->_blogInfo->getLocale();
     //
     // security stuff
     //
     $pipeline = new Pipeline($request, $this->_blogInfo);
     $result = $pipeline->process();
     //
     // if the pipeline blocked the request, then we have
     // to let the user know
     if (!$result->isValid()) {
         $message = $this->_locale->tr('error_you_have_been_blocked') . '<br/><br/>';
         $message .= $result->getErrorMessage();
         $this->_view = new ErrorView($this->_blogInfo, $message);
         $this->setCommonData();
         $this->_view->render();
         die;
     }
     // update the referrers, if needed
     $this->_updateReferrer();
     $this->articles = new Articles();
 }
 /**
  * @static
  * Static method that offers some kind of locale factory. Since the Locale object
  * better not use a Singleton (otherwise we couldn't use more than one locale file
  * at a time) this function has been included here to provide a system similar to
  * a singleton: we keep an static array inside the function, that contains all the
  * locale files that have been loaded so far. Whenever somebody requests a locale
  * to be fetched from disk, we will first check that we have not loaded it before. If
  * we have, then we only have to return the same object we were keeping.
  * If the locale wasn't there, we will then load it from disk and store/cache the
  * resulting object for future use.
  * It is recommended to use this method over creating new Locale objects every time
  * we need one.
  *
  * @param localeCode The code (eg. en_UK, es_ES) of the locale we want to get.
  * @return Returns a Locale object corresponding to the requested locale.
  * @see Locale
  */
 function &getLocale($localeCode = null)
 {
     // array to keep track of the locales that we have already loaded, so that
     // we don't have to fetch them from disk
     static $loadedLocales;
     // if there is no locale parameter, we use the default one
     if ($localeCode == null) {
         $config =& Config::getConfig();
         $localeCode = $config->getValue("default_locale");
     }
     // check if we have already loaded that locale or else, load it from
     // disk and keep it for later, just in case anybody asks again
     if (isset($loadedLocales[$localeCode])) {
         $locale = $loadedLocales[$localeCode];
     } else {
         $locale = new Locale($localeCode);
         $pm =& PluginManager::getPluginManager();
         foreach ($pm->_pluginList as $pluginId) {
             if ($pm->pluginHasLocale($pluginId, $localeCode)) {
                 // if the plugin provides the locale that we need, continue
                 $pluginLocale = Locales::getPluginLocale($pluginId, $localeCode);
             } else {
                 // if not, try to load en_UK by default
                 if ($pm->pluginHasLocale($pluginId, "en_UK")) {
                     $pluginLocale = Locales::getPluginLocale($pluginId, "en_UK");
                 }
                 // if not en_UK locale available, forget about it...
             }
             // merge the plugin locale with the big locale
             if (isset($pluginLocale)) {
                 $locale->mergeLocale($pluginLocale);
             }
         }
         $loadedLocales[$localeCode] = $locale;
     }
     return $locale;
 }
 /**
  * Carries out the specified action
  */
 function perform()
 {
     // initialize the plugin manager and load the plugins
     $pluginManager =& PluginManager::getPluginManager();
     // check if the plugin manager is enabled or not, since if it's not
     // there is no point in this feature...
     if (!$pluginManager->isEnabled()) {
         $this->_view = new AdminErrorView($this->_blogInfo);
         $this->_view->setMessage($this->_locale->tr("error_plugins_disabled"));
         $this->setCommonData();
         return false;
     }
     // we need to get an array with the plugins
     $pluginManager->refreshPluginList();
     $pluginManager->setBlogInfo($this->_blogInfo);
     $pluginManager->setUserInfo($this->_userInfo);
     $plugins = $pluginManager->getPlugins();
     // create a view and put the plugin objects in the template
     $this->_view = new AdminTemplatedView($this->_blogInfo, "plugincenter");
     $this->_view->setValue("plugins", $plugins);
     $this->setCommonData();
     // better to return true if everything fine
     return true;
 }
 function perform()
 {
     // initialize the plugin manager, needed to inform plugins of the EVENT_RESOURCE_LOADED
     // event, in case any of them is waiting for it! This obviously slows things down but
     // hey, what can I do? Users ask and I deliver...
     $this->_pm =& PluginManager::getPluginManager();
     $this->_pm->setBlogInfo($this->_blogInfo);
     $this->_userInfo = $this->_blogInfo->getOwnerInfo();
     $this->_pm->setUserInfo($this->_userInfo);
     // and fetch the resource
     $resources = new GalleryResources();
     if ($this->_resName) {
         $resource = $resources->getResourceFile($this->_blogInfo->getId(), $this->_resName);
     } else {
         $resource = $resources->getResource($this->_resId, $this->_blogInfo->getId());
     }
     if (!$resource) {
         // return 404 not found because the resource wasn't found
         $this->_view = new ResourceServerView();
         $this->_view->addHeaderResponse("HTTP/1.1 404 Not Found");
         $this->_view->addHeaderResponse("Status: 404 Not Found");
         $this->_view->addHeaderResponse("X-pLog-Error: Resource {$this->_resId} not found");
         return false;
     }
     // we need to let plugins know that we have successfully loaded a resource
     $this->notifyEvent(EVENT_RESOURCE_LOADED, array("resource" => &$resource));
     // generate the correct view with the resource data...
     $this->_view = new ResourceServerView($resource, $this->_mode);
     return true;
 }
Example #11
0
//ini_set('memory_limit', "16M");
if (!defined("PLOG_CLASS_PATH")) {
    define("PLOG_CLASS_PATH", dirname(__FILE__) . "/");
}
include_once PLOG_CLASS_PATH . "class/controller/blogcontroller.class.php";
include_once PLOG_CLASS_PATH . "class/net/http/session/sessionmanager.class.php";
include_once PLOG_CLASS_PATH . "class/dao/userinfo.class.php";
include_once PLOG_CLASS_PATH . "class/dao/bloginfo.class.php";
include_once PLOG_CLASS_PATH . "class/plugin/pluginmanager.class.php";
// just to make php use &amp; as the separator when adding the PHPSESSID
// variable to our requests
ini_set("arg_seperator.output", "&amp;");
ini_set("magic_quotes_runtime", 0);
//
// a security check, or else people might forget to remove the wizard.php script
//
if (File::isReadable("wizard.php")) {
    print "<span style=\"color:red\">The wizard.php script has to be removed after the installation process.</span><br/><br/>\n               Please remove it first to continue.";
    die;
}
// initialize the session
SessionManager::init();
$controller = new BlogController();
// load the plugins, this needs to be done *before* we call the
// Controller::process() method, as some of the plugins _might_
// add new actions to the controller
$pluginManager =& PluginManager::getPluginManager();
$pluginManager->loadPlugins();
// give control to the, ehem, controller :)
$controller->process(HttpVars::getRequest(), "op");
//xdebug_dump_function_profile(4);
Example #12
0
$blogs = new Blogs();
$blogInfo = $blogs->getBlogInfo($article->getBlog());
// a bit of protection...
if (!$blogInfo) {
    trackbackLog("ERROR: Article id " . $article->getId() . " points to blog " . $article->getBlog() . " that doesn't exist!");
    $result = errorResponse("The blog does not exist");
    die($result);
}
// if the blog is disabled, then we shoulnd't take trackbacks...
if ($blogInfo->getStatus() != BLOG_STATUS_ACTIVE) {
    trackbackLog("ERROR: The blog " . $blogInfo->getBlog() . " is set as disabled and cannot receive trackbacks!");
    $result = errorResponse("The blog is not active");
    die($result);
}
// if everything went fine, load the plugins so that we can throw some events...
$pm =& PluginManager::getPluginManager();
$pm->loadPlugins();
// and also configure the BlogInfo and UserInfo objects so that they know
// who threw the events...
$pm->setBlogInfo($blogInfo);
$userInfo = $blogInfo->getOwnerInfo();
$pm->setUserInfo($userInfo);
// receives the request and adds it to the database
$trackbacks = new TrackBacks();
// create teh trackback object
$now = new Timestamp();
$trackback = new Trackback($url, $title, $articleId, $excerpt, $blogName, $now->getTimestamp());
// throw the event in case somebody is listening to it!
$pm->notifyEvent(EVENT_PRE_TRACKBACK_ADD, array("trackback" => &$trackback));
$result = $trackbacks->addTrackBack($trackback);
if (!$result) {
Example #13
0
function deletePost($args)
{
    global $users, $articles, $blogsG;
    $appkey = $args[0];
    $postid = $args[1];
    $username = $args[2];
    $password = $args[3];
    $publish = $args[4];
    // -mhe todo
    $erg = $users->getUserInfo($username, $password);
    if ($erg != false) {
        $article = $articles->getUserArticle($postid, $erg->_id);
        // Get the plugin manager
        $plugMgr =& PluginManager::getPluginManager();
        $plugMgr->setBlogInfo($blogsG->getBlogInfo($article->getBlog()));
        $plugMgr->setUserInfo($erg);
        $plugMgr->loadPlugins();
        // Send the EVENT_PRE_POST_DELETE message
        $plugMgr->notifyEvent(EVENT_PRE_POST_DELETE, array("article" => &$article));
        $articles->deleteArticle($postid, $erg->_id, $article->getBlog(), $forever = true);
        // Send the EVENT_POST_POST_DELETE messages to the plugins
        $plugMgr->notifyEvent(EVENT_POST_POST_DELETE, array("article" => &$article));
        CacheControl::resetBlogCache($blogid);
        return true;
    } else {
        return new IXR_Error(-1, 'You did not provide the correct password');
    }
}
 /**
  * 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;
 }