/**
  * 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());
 }
 /**
  * Manually adds the "show more" link in a post.
  *
  * @param post The post we are going to cut.
  * @param maxWords Amount of words we'd like to allow.
  * @param linkText Text we are going to show.
  * @return The modified link.
  */
 function addShowMoreLink($post, $maxWords, $linkText)
 {
     $textFilter = new TextFilter();
     $result = $textFilter->cutText($post->getText(), $maxWords);
     $config =& Config::getConfig();
     if ($result != $post->getText()) {
         $rg =& RequestGenerator::getRequestGenerator();
         $rg->addParameter("op", "ViewArticle");
         $rg->addParameter("articleId", $post->getId());
         $rg->addParameter("blogId", $this->_blogInfo->getId());
         $indexPage = $config->getValue("script_name", "index.php");
         $showMoreLink = " <a href=\"{$indexPage}" . $rg->getRequest() . "\">" . $linkText . "</a>";
         $result .= $showMoreLink;
     }
     return $result;
 }
 /**
  * Takes all the posts and determines if we have to add the "show more" after
  * show_more_threshold words have been counted. If so, clicking on the link
  * will show the whole post using the ViewArticle action.
  *
  * @param maxWords The amount of words we tollerate before showing the link.
  * @return nothing.
  */
 function _addShowMoreLink()
 {
     $posts = $this->_params->getValue('posts');
     $locale = $this->_blogInfo->getLocale();
     //$textFilter = new TextFilter();
     $modifPosts = array();
     $rg = RequestGenerator::getRequestGenerator($this->_blogInfo);
     foreach ($posts as $post) {
         if ($post->hasExtendedText()) {
             $result = $post->getIntroText();
             $showMoreText = $locale->tr('read_more');
             $showMoreLink = "&nbsp;<a href=\"" . $rg->postPermalink($post) . "\">" . $showMoreText . "</a>";
             $post->setText($result . $showMoreLink);
         }
         array_push($modifPosts, $post);
     }
     $this->_params->setValue('posts', $modifPosts);
 }
 /**
  * Constructor.
  *
  * @param dayPosts An array indexed from 1 to as many days as the month where
  * every position tells how many posts were made that day.
  * @param localeCode A code specifying the locale we want to use. If empty, the default
  * one specified in the configuration file will be used.
  */
 function PlogCalendar($dayPosts = null, $blogInfo = null, $localeCode = null)
 {
     $this->Calendar();
     if ($localeCode == null) {
         $config = Config::getConfig();
         //$locale = new Locale( $config->getValue( "default_locale" ));
         $locale = Locales::getLocale($config->getValue("default_locale"));
     } else {
         //$locale = new Locale( $localeCode );
         $locale = Locales::getLocale($localeCode);
     }
     $this->_dayPosts = $dayPosts;
     $this->_blogInfo = $blogInfo;
     // set the first day of the week according to our locale
     $this->startDay = $locale->firstDayOfWeek();
     //array_push( $this->monthsNames, $locale->tr("January"));
     $this->monthNames = $locale->getMonthNames();
     // abbreviations of the days of the week
     $this->dayNamesShort = $locale->getDayNamesShort();
     // full names of the days of the week
     $this->dayNames = $locale->getDayNames();
     $this->rg = RequestGenerator::getRequestGenerator($blogInfo);
 }
 /**
  * Sends a trackback ping to the given url.
  *
  * @param trackbackUrl the url where to send the trackback ping.
  * @param article The article object that is pinging the remote host.
  * @param blogName The name of the blog sending the trackback ping
  * @return Returns true if successful or false otherwise.
  */
 function sendTrackback($trackbackUrl, $article, $blogInfo)
 {
     $s = new HttpClient();
     $t =& RequestGenerator::getRequestGenerator($blogInfo);
     $formvars["title"] = $article->getTopic();
     // according to MT's implementation, the excerpt should not be longer than 255 characters.
     $formvars["excerpt"] = substr($article->getText(), 0, 255);
     $formvars["url"] = $t->postPermalink($article);
     $formvars["blog_name"] = $blogInfo->getBlog();
     // submit the form
     if (!$s->submit($trackbackUrl, $formvars)) {
         return false;
     }
     preg_match("/.*<error>(.*)<\\/error>.*/", $s->results, $res);
     if ($res[1] == 1) {
         return false;
     } else {
         return true;
     }
     return true;
 }
 /**
  * Renders the template at templates/misc/email_notifier.template
  */
 function renderMessageTemplate($article, $blogInfo)
 {
     // create a new template service
     $ts = new TemplateService();
     $messageTemplate = $ts->Template(EMAILNOTIFIER_TEMPLATE, "misc");
     // add these two useful objects
     $rg =& RequestGenerator::getRequestGenerator($blogInfo);
     // disable the xhtml mode, as some email clients cannot deal with it
     $rg->setXHTML(false);
     $messageTemplate->assign("url", $rg);
     $messageTemplate->assign("post", $article);
     // render and return the contents
     return $messageTemplate->fetch();
 }
 /**
  * Turns on notification for the specified article
  *
  */
 function GenerateSiteMap()
 {
     // articles object
     $articles = new Articles();
     $list = $articles->getBlogArticles($this->blogInfo->getId(), -1, -1, 0, POST_STATUS_PUBLISHED);
     $url = $this->blogInfo->getBlogRequestGenerator();
     // Data from the xml file that needs to be there.
     $xmlData = "<?xml version='1.0' encoding='UTF-8'?>\n" . "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\"\n" . "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" . "xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84\n" . "http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">\n";
     // Iterate over the posts and create an entry for each.
     foreach ($list as $item) {
         $xmlData = $xmlData . "<url>\n";
         $xmlData = $xmlData . "<loc>\n";
         $xmlData = $xmlData . htmlspecialchars($url->postPermalink($item)) . "\n";
         $xmlData = $xmlData . "</loc>\n";
         $xmlData = $xmlData . "</url>\n";
     }
     $xmlData = $xmlData . "</urlset>\n";
     $compressedFile = $this->cacheFolder . "/sitemap.gz";
     // Save this to a compressed file.
     $gz = gzopen($compressedFile, 'w9');
     if ($gz) {
         gzwrite($gz, $xmlData);
         gzclose($gz);
     }
     $blogSettings = $this->blogInfo->getSettings();
     if ($blogSettings->getValue("plugin_sitemap_notify_google_enabled")) {
         // Send the request to google
         $rg =& RequestGenerator::getRequestGenerator($this->blogInfo);
         $rewriteFile = "/sitemap" . $this->blogInfo->getId() . ".gz";
         $rewriteFileUrl = $rg->getUrl($rewriteFile);
         $pingUrl = "http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($rewriteFileUrl);
         $handle = fopen($pingUrl, "r");
         fclose($handle);
     }
 }
 /**
  * this method is some kind of a shortcut for a very common operation: obtaining the
  * correct RequestGenerator object so that we can generate urls based on the information
  * from this blog. This is very handy for example in the summary page where we have to
  * generate lots of different urls for lots of different blogs.
  *
  * @return A RequestGenerator object
  */
 function getBlogRequestGenerator()
 {
     return RequestGenerator::getRequestGenerator($this);
 }
 /**
  * generates the correct url for the print view of a post
  *
  * @param article
  * @return the right url
  */
 function printView($article)
 {
     $rg =& RequestGenerator::getRequestGenerator($this->_blogInfo);
     return $rg->getBaseUrl() . "/index.php?op=printView&amp;articleId=" . $article->getId() . "&amp;blogId=" . $this->blogInfo->getId();
 }
 function filter()
 {
     // get some info
     $blogInfo = $this->_pipelineRequest->getBlogInfo();
     $request = $this->_pipelineRequest->getHttpRequest();
     $session = HttpVars::getSession();
     // get the article id from the request, since if it is available, then we know
     // that we have to ask for the password before we can let users watch it
     $articleId = $request->getValue("articleId");
     // If we use custom url mode, the article id is not available, we need to use
     // - articleName
     // - userId
     // - categoryId
     // - date
     // and $articles->getBlogArticleByTitle() to find the value
     if ($articleId == "") {
         $articleName = $request->getValue("articleName");
         $categoryId = $request->getValue("postCategoryId", -1);
         $categoryName = $request->getValue("postCategoryName");
         $userId = $request->getValue("userId", -1);
         $userName = $request->getValue("userName");
         $date = $request->getValue("Date", -1);
         // If userName available, use it to find userId
         if ($userName) {
             $users =& new Users();
             $user = $users->getUserInfoFromUsername($userName);
             if (!$user) {
                 $result = new PipelineResult(true);
                 return $result;
             }
             // if there was a user, use his/her id
             $userId = $user->getId();
         }
         // If categoryName available, use it to find categoryId
         if ($categoryName) {
             $categories =& new ArticleCategories();
             $category = $categories->getCategoryByName($categoryName, $blogInfo->getId());
             if (!$category) {
                 $result = new PipelineResult(true);
                 return $result;
             }
             // if there was a user, use his/her id
             $categoryId = $category->getId();
         }
         // fetch the article
         // the article identifier can be either its internal id number or its mangled topic
         $articles =& new Articles();
         $article = $articles->getBlogArticleByTitle($articleName, $blogInfo->getId(), false, $date, $categoryId, $userId, POST_STATUS_PUBLISHED);
         if ($article) {
             $articleId = $article->getId();
         } else {
             $result = new PipelineResult(true);
             return $result;
         }
     }
     // check if the article should be protected or not
     $secretItems = new SecretItems();
     if ($secretItems->articleIsSecret($articleId)) {
         // if so, first check if the password does not already exist in the session
         $itemPassword = $request->getValue("itemPassword");
         // do we already have this information in the session?
         $sessionKey = "article_" . $articleId . "_auth";
         if ($session["{$sessionKey}"] != "") {
             // check if the information is correct
             if ($secretItems->authenticateItemHash($articleId, $session["{$sessionKey}"])) {
                 // if all correct, go ahead!
                 $result = new PipelineResult(true);
                 return $result;
             }
         }
         // if not, check if we are authenticating now...
         if ($itemPassword != "") {
             // authenticate using the given password
             if (!$secretItems->authenticateItem($articleId, $itemPassword)) {
                 $result = new PipelineResult(false, 500, "Better luck next time!");
             } else {
                 // if the user authenticated correctly, then put the information in the session
                 _debug("authenticated correctly!");
                 $session = HttpVars::getSession();
                 $session["{$sessionKey}"] = md5($itemPassword);
                 $result = new PipelineResult(true);
                 HttpVars::setSession($session);
             }
         } else {
             $ts = new TemplateService();
             $t = $ts->PluginTemplate("secret", "passwordform");
             $t->assign("locale", $blogInfo->getLocale());
             $t->assign("params", $request->getAsArray());
             $t->assign("articleId", $articleId);
             $t->assign("url", RequestGenerator::getRequestGenerator($blogInfo));
             $message = $t->fetch();
             $result = new PipelineResult(false, 500, $message);
         }
         return $result;
     }
     // if everything went fine, we can say so by returning
     // a positive PipelineResult object
     $result = new PipelineResult(true);
     return $result;
 }
示例#11
0
 /**
  * Sends a weblogsUpdate.ping xmlrpc call to notifiy of changes in this blog
  *
  * @param blogInfo The BlogInfo object containing information about the blog
  * @return Returns true if successful or false otherwise.
  */
 function updateNotify($blogInfo)
 {
     // if this feature is not enabled, we quit
     $config =& Config::getConfig();
     if (!$config->getValue("xmlrpc_ping_enabled")) {
         return;
     }
     // get the array which contains the hosts
     $hosts = $config->getValue("xmlrpc_ping_hosts");
     // if it is not an array, quit
     if (!is_array($hosts)) {
         return;
     }
     // if no hosts, we can quit too
     if (empty($hosts)) {
         return;
     }
     // otherwise, we continue
     $xmlrpcPingResult = array();
     $rg =& RequestGenerator::getRequestGenerator($blogInfo);
     $blogLink = $rg->blogLink();
     foreach ($hosts as $host) {
         $client = new XmlRpcClient($host);
         $result = $client->ping($blogInfo->getBlog(), $blogLink);
         //print("result = ".$result. "is Error = ".$client->isError()." message: ".$client->getErrorMessage()."<br/>");
         //$xmlrpcPingResult[$result["host"]
         $xmlrpcPingResult = array_merge($xmlrpcPingResult, $result);
     }
     return $xmlrpcPingResult;
 }