/** * Carries out the specified action */ function perform() { //print_r($_REQUEST); // fetch all the information that we need for the dummy Article object $this->_fetchCommonData(); // and now, create a harmless Article object with it $postText = Textfilter::xhtmlize($this->_postText) . POST_EXTENDED_TEXT_MODIFIER . Textfilter::xhtmlize($this->_postExtendedText); // create the main object $article = new Article($this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), $this->_blogInfo->getId(), $status, 0, array(), $this->_postSlug); // and a few more properties that we need to know about $this->_fetchPostDateInformation(); $article->setDateObject($this->_postTimestamp); // we will not allow comments because it wouldn't work! $article->setCommentsEnabled(false); $article->setFields($this->_getArticleCustomFields()); // the next two fields are also required in order to show an article $article->setUserInfo($this->_userInfo); $article->setBlogInfo($this->_blogInfo); $article->setCategories($this->_loadArticleCategories($this->_postCategories)); // and now trick the ViewArticleView class into thinking that we're showing // a real article just fetched from the database (even though it makes no difference // to the class itself whence the article came from :) // the 'random' parameter in the array is to provide the view with a random view id // every time that we run the preview, otherwise when caching is enabled we would always be // getting the same page!! $this->_view = new ViewArticleView($this->_blogInfo, array('random' => md5(time()))); $this->_view->setArticle($article); //$this->setCommonData(); return true; }
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() { $status = POST_STATUS_DRAFT; $articles = new Articles(); $postText = Textfilter::xhtmlize($this->_postText) . POST_EXTENDED_TEXT_MODIFIER . Textfilter::xhtmlize($this->_postExtendedText); $article = new Article($this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), $this->_blogInfo->getId(), $status, 0, array(), $this->_postSlug); // set also the date before it's too late $article->setDateObject($this->_postTimestamp); $article->setCommentsEnabled($this->_commentsEnabled); // prepare the custom fields $fields = array(); if (is_array($this->_customFields)) { foreach ($this->_customFields as $fieldId => $fieldValue) { // 3 of those parameters are not really need when creating a new object... it's enough that // we know the field definition id. $customField = new CustomFieldValue($fieldId, $fieldValue, "", -1, "", $artId, $this->_blogInfo->getId(), -1); array_push($fields, $customField); } $article->setFields($fields); } // in case the post is already in the db if ($this->_postId != "") { $article->setId($this->_postId); $postSavedOk = $articles->updateArticle($article); if ($postSavedOk) { $artId = $this->_postId; } else { $artId = false; } } else { $artId = $articles->addArticle($article); } // once we have built the object, we can add it to the database $this->_view = new AdminXmlView($this->_blogInfo, "response"); $this->_view->setValue("method", "saveXmlDraft"); if ($artId) { $this->_view->setValue("result", $artId); } else { $this->_view->setValue("result", "0"); } return true; }
function perform() { // retrieve the values from the view $this->_blogName = $this->_request->getValue("blogName"); $this->_ownerId = $this->_request->getValue("ownerid"); $this->_blogProperties = $this->_request->getValue("properties"); $this->_blogTemplate = $this->_request->getValue("blogTemplate"); $this->_blogLocale = $this->_request->getValue("blogLocale"); // configure the blog $blogs = new Blogs(); $blog = new BlogInfo($this->_blogName, $this->_ownerId, "", ""); $blog->setProperties($this->_blogProperties); $blog->setStatus(BLOG_STATUS_ACTIVE); $blogSettings = $blog->getSettings(); $blogSettings->setValue("locale", $this->_blogLocale); $blogSettings->setValue("template", $this->_blogTemplate); $blog->setSettings($blogSettings); // and now save it to the database $newblogId = $blogs->addBlog($blog); if (!$newblogId) { $this->_view = new WizardView("step4"); $this->_view->setValue("siteLocales", Locales::getLocales()); $ts = new TemplateSets(); $this->_view->setValue("siteTemplates", $ts->getGlobalTemplateSets()); $this->_view->setErrorMessage("There was an error creating the new blog"); $this->setCommonData(true); return false; } // if the blog was created, we can add some basic information // add a category $articleCategories = new ArticleCategories(); $articleCategory = new ArticleCategory("General", "", $newblogId, true); $catId = $articleCategories->addArticleCategory($articleCategory); // load the right locale $locale =& Locales::getLocale($this->_blogLocale); // and load the right text $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); // save a few things in the default configuration $config =& Config::getConfig(); // default blog id $config->saveValue("default_blog_id", (int) $newblogId); // default locale $config->saveValue("default_locale", $this->_blogLocale); // and finally, the default template $config->saveValue("default_template", $this->_blogTemplate); // // detect wether we have GD available and set the blog to use it // if (GdDetector::detectGd()) { $config->saveValue("thumbnail_method", "gd"); $message = "GD has been detected and set as the backend for dealing with images."; } else { $pathToConvert = $config->getValue("path_to_convert"); if ($pathToConvert) { $config->saveValue("thumbnail_method", "imagemagick"); $message = "ImageMagick has been detected and set as the backend for dealing with images."; } else { // nothing was found, so we'll have to do away with the 'null' resizer... $config->saveValue("thumbnail_method", "null"); $message = "Neither GD nor ImageMagick have been detected in this host so it will not be possible to generate thumbnails from images."; } } $this->_view = new WizardView("step5"); $this->_view->setValue("message", $message); return true; }
$markup .= $resource->getDescription(); } $markup .= "</a>"; $curItem++; if ($curItem < $numItems) { $markup .= "<br/><br/>"; } MoblogLogger::log("Adding markup {$markup}"); $postBody .= $markup; $postBody = TextFilter::autoP(trim($postBody)); $resNames .= $resource->getDescription(); } // add the article $articles = new Articles(); $article = new Article($request->getTopic(), $postBody, array($category->getId()), $userInfo->getId(), $blogInfo->getId(), POST_STATUS_PUBLISHED, 0); $article->setDateObject(new Timestamp()); // enable or disable comments by default depending on the current config $commentsEnabled = $blogSettings->getValue("comments_enabled"); $article->setCommentsEnabled($commentsEnabled); $result = $articles->addArticle($article); // add an article notification $notifications = new ArticleNotifications(); $notifications->addNotification($result, $blogInfo->getId(), $userInfo->getId()); // reset the cache in case it is enabled CacheControl::resetBlogCache($blogInfo->getId()); if (!$result) { $response = new MoblogResponse($request->getReplyTo(), "pLog Moblog: Error", "There was an error adding the post to the database."); MoblogLogger::log("There was an error adding the post to the database."); } else { $responseBody = "Post was successfully added to the database with topic '" . $request->getTopic() . "\n\n"; if (count($request->getAttachments()) > 0) {
/** * Carries out the specified action */ function perform() { $this->_fetchCommonData(); $this->_postId = $this->_request->getValue("postId"); $this->_previewPost = $this->_request->getValue("previewPost"); $this->_addPost = $this->_request->getValue("addPost"); $this->_saveDraft = $this->_request->getValue("isDraft"); // we know for sure that the information is correct so we can now add // the post to the database $postText = Textfilter::xhtmlize($this->_postText) . POST_EXTENDED_TEXT_MODIFIER . Textfilter::xhtmlize($this->_postExtendedText); $article = new Article($this->_postTopic, $postText, $this->_postCategories, $this->_userInfo->getId(), $this->_blogInfo->getId(), $this->_postStatus, 0, array(), $this->_postSlug); // set also the date before it's too late $article->setDateObject($this->_postTimestamp); $article->setCommentsEnabled($this->_commentsEnabled); // save the article to the db $artId = $this->_savePostData($article); // once we have built the object, we can add it to the database if ($artId) { $this->_view = new AdminPostsListView($this->_blogInfo); //$article->setId( $artId ); $message = $this->_locale->tr("post_added_ok"); // train the filter BayesianFilterCore::trainWithArticle($article); // add the article notification if requested to do so if ($this->_sendNotification) { $artNotifications = new ArticleNotifications(); $artNotifications->addNotification($artId, $this->_blogInfo->getId(), $this->_userInfo->getId()); $message .= " " . $this->_locale->tr("send_notifications_ok"); } // we only have to send trackback pings if the article was published // otherwise there is no need to... $article->setId($artId); if ($article->getStatus() == POST_STATUS_PUBLISHED) { // get the output from the xmlrpc pings but only if the user decided to do so! if ($this->_sendPings) { $pingsOutput = $this->sendXmlRpcPings(); $message .= "<br/><br/>" . $pingsOutput; } // and now check what to do with the trackbacks if ($this->_sendTrackbacks) { // get the links from the text of the post $postLinks = StringUtils::getLinks(stripslashes($article->getText())); // get the real trackback links from trackbackUrls $trackbackLinks = array(); foreach (explode("\r\n", $this->_trackbackUrls) as $host) { trim($host); if ($host != "" && $host != "\r\n" && $host != "\r" && $host != "\n") { array_push($trackbackLinks, $host); } } // if no links, there is nothing to do if (count($postLinks) == 0 && count($trackbackLinks) == 0) { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_no_trackback_links_sent")); } else { $this->_view = new AdminTemplatedView($this->_blogInfo, "sendtrackbacks"); $this->_view->setValue("post", $article); $this->_view->setValue("postLinks", $postLinks); $this->_view->setValue("trackbackLinks", $trackbackLinks); } } $this->_view->setSuccessMessage($message); $this->notifyEvent(EVENT_POST_POST_ADD, array("article" => &$article)); // empty the cache used by this blog CacheControl::resetBlogCache($this->_blogInfo->getId()); } else { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setSuccessMessage($this->_locale->tr("post_added_not_published")); $this->notifyEvent(EVENT_POST_POST_ADD, array("article" => &$article)); } } else { $this->_view = new AdminPostsListView($this->_blogInfo); $this->_view->setErrorMessage($this->_locale->tr("error_adding_post")); } $this->setCommonData(); // better to return true if everything fine return true; }
/** * create the blog */ function createBlog($userId) { $this->blogName = stripslashes($this->_request->getValue("blogName")); $this->blogLocale = $this->_request->getValue("blogLocale"); $this->templateId = $this->_request->getValue("templateId"); // get the default locale configured for the site $blogs = new Blogs(); $blogInfo = new BlogInfo($this->blogName, $userId, "", ""); if ($this->need_confirm == 1) { $blogInfo->setStatus(BLOG_STATUS_UNCONFIRMED); } else { $blogInfo->setStatus(BLOG_STATUS_ACTIVE); } $locale = Locales::getLocale($this->blogLocale); $blogInfo->setLocale($locale); $blogInfo->setTemplate($this->templateId); $newblogId = $blogs->addBlog($blogInfo); if (!$newblogId) { $this->_view = new SummaryView("registererror"); $this->_view->setErrorMessage($this->_locale->tr("error_creating_blog")); return false; } // get info about the blog $blogInfo = $blogs->getBlogInfo($newblogId); $this->_blogInfo = $blogInfo; // if the blog was created, we can add some basic information // add a category $articleCategories = new ArticleCategories(); $articleCategory = new ArticleCategory($locale->tr("register_default_category"), "", $newblogId, true); $catId = $articleCategories->addArticleCategory($articleCategory); // add an article based on that category $articleTopic = $locale->tr("register_default_article_topic"); $articleText = $locale->tr("register_default_article_text"); $article = new Article($articleTopic, $articleText, array($catId), $userId, $newblogId, POST_STATUS_PUBLISHED, 0, array(), "welcome"); $article->setDateObject(new Timestamp()); // set it to the current date $article->setCommentsEnabled(true); // enable comments $articles = new Articles(); $articles->addArticle($article); return true; }