function perform()
 {
     // get the search terms that have already been validated...
     $this->_searchTerms = $this->_request->getValue("searchTerms");
     // check if the search feature is disabled in this site...
     $config =& Config::getConfig();
     if (!$config->getValue("search_engine_enabled")) {
         $this->_view = new ErrorView($this->_blogInfo, "error_search_engine_disabled");
         $this->setCommonData();
         return false;
     }
     // create the view and make sure that it hasn't been cached
     $this->_view = new BlogTemplatedView($this->_blogInfo, VIEW_SEARCH_TEMPLATE, array("searchTerms" => $this->_searchTerms));
     if ($this->_view->isCached()) {
         return true;
     }
     $searchEngine = new SearchEngine();
     $searchResults = $searchEngine->search($this->_blogInfo->getId(), $this->_searchTerms);
     // MARKWU: I add the searchterms variable for smarty/plog template
     $searchTerms = $searchEngine->getAdaptSearchTerms($this->_searchTerms);
     // if no search results, return an error message
     if (count($searchResults) == 0) {
         $this->_view = new ErrorView($this->_blogInfo, "error_no_search_results");
         $this->setCommonData();
         return true;
     }
     // if only one search result, we can see it straight away
     if (count($searchResults) == 1) {
         // we have to refill the $_REQUEST array, since the next action
         // is going to need some of the parameters
         $request =& HttpVars::getRequest();
         $searchResult = array_pop($searchResults);
         $article = $searchResult->getArticle();
         $request["articleId"] = $article->getId();
         $request["blogId"] = $this->_blogInfo->getId();
         HttpVars::setRequest($request);
         // since there is only one article, we can use the ViewArticleAction action
         // to display that article, instead of copy-pasting the code and doing it here.
         // You just have to love MVC and OOP :)
         return Controller::setForwardAction("ViewArticle");
     }
     // or else, show a list with all the posts that match the requested
     // search terms
     $this->_view->setValue("searchresults", $searchResults);
     // MARKWU: Now, I can use the searchterms to get the keyword
     $this->_view->setValue("searchterms", $searchTerms);
     // MARKWU:
     $config =& Config::getConfig();
     $urlmode = $config->getValue("request_format_mode");
     $this->_view->setValue("urlmode", $urlmode);
     $this->setCommonData();
     return true;
 }
예제 #2
0
 /**
  * Constructor. Initializes the view with a default content type, character set, etc.
  */
 function View()
 {
     $this->Object();
     $this->_params = new Properties();
     // set a default content type and character set for responses
     $this->_contentType = TEXT_HTML_CONTENT_TYPE;
     $this->_charset = DEFAULT_VIEW_CHARSET;
     $this->_headers = array();
     // no form has caused any error when we initialize the view!
     $this->setValue("formIsError", false);
     // and no form has caused any success yet either!
     $this->setValue("formIsSuccess", false);
     // let's send an HTTP 200 header response... If somebody wants to overwrite it later
     // on, php should keep in mind that the valid one will be the last one so it is
     // fine to do this more than once and twice
     $this->addHeaderResponse("HTTP/1.0 200 OK");
     // initialize a request object, in case it is needed somewhere
     $this->_request = new Request(HttpVars::getRequest());
 }
예제 #3
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 & as the separator when adding the PHPSESSID
// variable to our requests
ini_set("arg_seperator.output", "&");
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);
예제 #4
0
    }
    return true;
}
/**
 *
 * whoa believe it or not, in pLog you can also find php code that is not within a class! :-)
 *
 * perhaps the code below should be cleaned up and put into a TrackbackServer class or something
 * like that but since it works the way it is, we'll leave it like it is!
 *
 */
// prepare everything...
$config =& Config::getConfig();
// get the post and get parameters
trackbackLog("** Request received");
$params = new Properties(HttpVars::getRequest());
dumpRequest($params);
// check that they are correct and quit if they're not
if ($params->getValue("id") == "" || $params->getValue("id") <= 0) {
    $result = errorResponse("Incorrect or missing id parameter.");
    print $result;
    trackbackLog("Sending error response: {$result}");
    trackbackLog("** End");
    die;
}
if ($params->getValue("url") == "") {
    $result = errorResponse("The url parameter must be present.");
    print $result;
    trackbackLog("Sending error response: {$result}");
    trackbackLog("** End");
    die;
예제 #5
0
 *
 * To get this to work, we need a provider which allows to use
 * .htaccess files in their accounts and at the same time, allows
 * to have ErrorDocument directives in the .htaccess file.
 *
 * This should be the content of the file:
 *
 * ErrorDocument 401 /plog/error.php
 * ErrorDocument 403 /plog/error.php
 * ErrorDocument 404 /plog/error.php
 *
 * If pLog is running somewhere else other than /plog/, then that
 * should be changed since an absolute URL is required.
 */
$config =& Config::getConfig();
if ($config->getValue("request_format_mode") == SEARCH_ENGINE_FRIENDLY_MODE) {
    $server = HttpVars::getServer();
    $request = HttpVars::getRequest();
    $parts = split("/", $server["REQUEST_URI"]);
    $userParam = $parts[count($parts) - 1];
    if (is_numeric($userParam)) {
        $request["blogId"] = $userParam;
    } else {
        $request["blogUserName"] = $userParam;
    }
    HttpVars::setRequest($request);
    $scriptName = $config->getValue("script_name", DEFAULT_SCRIPT_NAME);
    include_once PLOG_CLASS_PATH . $scriptName;
} else {
    include_once PLOG_CLASS_PATH . "blog.php";
}
 /**
  * Carries out the action
  */
 function perform()
 {
     // need to check the ip of the client
     $clientIp = Client::getIp();
     // fetch the same article again so that we can have all the comments from
     // the database, plus this last one
     $articles = new Articles();
     $article = $articles->getBlogArticle($this->_articleId, $this->_blogInfo->getId());
     // check if the user wanted to receive comments for this article
     // or not...
     if ($article->getCommentsEnabled() == false) {
         $this->_view = new ErrorView($this->_blogInfo);
         $this->_view->setValue("message", "Comments have been disabled for this article.");
         $this->setCommonData();
         return false;
     }
     $this->notifyEvent(EVENT_POST_LOADED, array("article" => &$article));
     // we have already checked all the data, so we are sure that everything's in place
     $comments = new ArticleComments();
     $comment = new UserComment($this->_articleId, $this->_parentId, $this->_commentTopic, $this->_commentText, null, $this->_userName, $this->_userEmail, $this->_userUrl, $clientIp);
     // check if there is already a comment with the same text, topic and made from the same
     // IP already in the database because if so, then we will not add the comment that
     // the user is trying to add (a reload button mistake, perhaps?)
     if (!$comments->getIdenticalComment($this->_commentTopic, $this->_commentText, $this->_articleId, $this->_parentId, $this->_userName, $this->_userEmail, $this->_userUrl, $clientIp)) {
         // fire an event
         $this->notifyEvent(EVENT_PRE_COMMENT_ADD, array("comment" => &$comment));
         if (!$comments->addComment($comment)) {
             // show an error message if problems
             $this->_view = new ErrorView($this->_blogInfo);
             $this->_view->setValue("message", "error_adding_comment");
             $this->setCommonData();
             return false;
         }
     }
     // finally, check if there was any user who wanted to be notified of new comments
     // to this post...
     $notifier = new ArticleNotifications();
     $notifier->notifyUsers($article->getId(), $this->_blogInfo);
     // fire the post event...
     $this->notifyEvent(EVENT_POST_COMMENT_ADD, array("comment" => &$comment));
     //
     // clear caches. This should be done in a more granular way, because right now
     // we're either removing *all* of them or none. I guess we should only remove the
     // cache whose identifier corresponds with the blog and article that we just removed,
     // but let's leave it as it is for the time being...
     //
     CacheControl::resetBlogCache($this->_blogInfo->getId());
     // clean up the request, there's a parameter called 'userName' also used by
     // ViewArticleAction but that doesn't have the same meaning so we better remove it
     // before it's too late! We also need to add a new request commentUserName to replace
     // original userName, in case developer need it in filter or event plugin.
     $request = HttpVars::getRequest();
     $request["commentUserName"] = $request["userName"];
     $request["userName"] = "";
     HttpVars::setRequest($request);
     // forward the action to ViewArticleAction
     return BlogController::setForwardAction("ViewArticle");
 }
 /**
  * sets a value in the request
  *
  * @param key
  * @param value
  * @return true
  */
 function setRequestValue($key, $value)
 {
     $request = HttpVars::getRequest();
     $request["{$key}"] = $value;
     HttpVars::setRequest($request);
     return true;
 }
 /**
  * Processess the HTTP request sent by the client
  *
  * @param httpRequest HTTP request sent by the client
  */
 function process($httpRequest)
 {
     // get the name of the action
     $request = new Request($httpRequest);
     $i = 0;
     $performed = false;
     while (!$performed) {
         // get the value of this varilable, every loop
         global $_plogController_forwardAction;
         global $_plogController_previousAction;
         // jondaley: 08/29/2005, what are these here for??
         // perhaps the global statements should be moved
         // inside the elseif loop below?
         $_plogController_forwardAction;
         $_plogController_previousAction;
         if ($i == 0) {
             // if this is the first iteration, then we have to take this path...
             // since we will use the http request to determine which action to
             // use next
             $actionName = $request->getValue($this->_actionParam);
             $actionClass = $this->_getActionClassName($request->getValue($this->_actionParam));
         } elseif (!empty($_plogController_forwardAction)) {
             // if we're forwarding the current execution flow to another action, then
             // we'll go this way
             $actionName = $_plogController_forwardAction;
             $actionClass = $this->_getActionClassName($_plogController_forwardAction);
             $httpRequest = HttpVars::getRequest();
             $_plogController_forwardAction = null;
         } else {
             // if there's nothing else to do, finish
             $performed = true;
         }
         if (!$performed) {
             // load the class if it hasn't been loaded yet
             $this->loadActionClass($actionClass);
             $actionInfo = new ActionInfo($this->_actionParam, $actionName);
             $actionObject = new $actionClass($actionInfo, $httpRequest);
             $actionObject->setPreviousAction($_plogController_previousAction);
             // we can use the validate method to check the values of the form variables. If validate()
             // returns 'true', then we call the 'perform' method. If not, then we won't :)
             if ($actionObject->validate()) {
                 if ($actionObject->perform()) {
                     $actionObject->setSuccess(true);
                 } else {
                     $actionObject->setSuccess(false);
                 }
             }
         }
         $i++;
     }
     // once the operation has been carried out, fetch and send the view
     // to the client
     $view = $actionObject->getView();
     // this is not good...
     if (empty($view)) {
         $e = new Exception('The view is empty after calling the perform method.');
         throw $e;
     } else {
         $view->render();
     }
 }