/** * 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; }
/** * Publish entry * * @param Newscoop\Entity\Ingest\Feed\Entry $entry * @param string $status * @return Article */ public function publish(Entry $entry, $status = 'Y') { $article = new \Article($this->getLanguage($entry->getLanguage())); $article->create($this->config['article_type'], $entry->getTitle(), $this->getPublication(), $this->getIssue(), $this->getSection($entry)); $article->setWorkflowStatus(strpos($entry->getTitle(), self::PROGRAM_TITLE) === 0 ? 'N' : $status); $article->setKeywords($entry->getCatchWord()); $article->setCommentsEnabled(TRUE); $this->setArticleData($article, $entry); $this->setArticleDates($article, $entry); $this->setArticleAuthors($article, $entry); $this->setArticleImages($article, $entry->getImages()); $entry->setArticleNumber($article->getArticleNumber()); $article->commit(); return $article; }
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 _addPost($data, $_debug) { if ($data["title"] == NULL) { $data["title"] = "No Title Entered."; } if ($data["text"] == NULL) { $data["text"] = "No Body Entered."; } if ($data["category"] == NULL) { $data["category"] = 1; } if ($data["user_id"] == NULL) { $data["user_id"] = 1; } if ($data["blog_id"] == NULL) { $data["blog_id"] = 1; } if ($data["status"] == NULL) { $data["status"] = POST_STATUS_PUBLISHED; } if ($data["comments"] == NULL) { $data["comments"] = true; } $articles = new Articles(); // verify that article does not exist in database $artss = $articles->getBlogArticles($data["blog_id"]); $exists = 0; foreach ($artss as $art) { if ($art->getTopic() == $data["title"]) { $exists = $art->getId(); break; } } /* $exists = $articles->getBlogArticleByTitle( TextFilter::urlize($data["title"]) , $data["blog_id"], true, -1 -1 -1, POST_STATUS_PUBLISHED ); if (!$exists) { $exists = $articles->getBlogArticleByTitle( TextFilter::urlize($data["title"]) , $data["blog_id"], true, -1 -1 -1, POST_STATUS_DRAFT ); } */ if (!$exists) { // verify that desired post id does not exist. Otherwise, create new id. if (!$articles->getUserArticle($data["id"])) { $post_id = $data["id"]; } if ($_debug) { print "--- --- adding post " . $data["title"] . " to db.<br />\n\r"; } $cat[0] = $data["category"]; $article = new Article($data["title"], $data["text"], $cat, $data["user_id"], $data["blog_id"], $data["status"], 0); if ($data["date"]) { $article->setDate($data["date"]); } if ($post_id) { $article->setId($post_id); } $article->setCommentsEnabled($data["comments"]); $artId = $articles->addArticle($article); $this->_stats["posts"]["write"]++; // remap comments to $artId if ($this->_container["comments"]) { foreach ($this->_t_container["comments"] as $comment => $val) { if ($this->container["comments"][$comment]["article_id"] == $data["id"] || $val["article_id"] == NULL) { $this->_container["comments"][$comment]["article_id"] = $artId; if ($_debug) { print "--- --- remapping comment entry #" . $comment . " to proper article id<br />\n\r"; } } } } } else { $artId = $exists; if ($_debug) { print "--- --- post already exists, aborting operation.<br />\n\r"; } } return $artId; }
camp_html_add_msg(getGS("\$1 toggled.", """ . getGS("On Front Page") . """), "ok"); break; case "toggle_section_page": foreach ($articleCodes as $articleCode) { $articleObj = new Article($articleCode['language_id'], $articleCode['article_id']); if ($articleObj->userCanModify($g_user)) { $articleObj->setOnSectionPage(!$articleObj->onSectionPage()); } } camp_html_add_msg(getGS("\$1 toggled.", """ . getGS("On Section Page") . """), "ok"); break; case "toggle_comments": foreach ($articleCodes as $articleCode) { $articleObj = new Article($articleCode['language_id'], $articleCode['article_id']); if ($articleObj->userCanModify($g_user)) { $articleObj->setCommentsEnabled(!$articleObj->commentsEnabled()); } } camp_html_add_msg(getGS("\$1 toggled.", """ . getGS("Comments") . """), "ok"); break; case "copy": foreach ($groupedArticleCodes as $articleNumber => $languageArray) { $languageId = camp_array_peek($languageArray); $articleObj = new Article($languageId, $articleNumber); $articleObj->copy($articleObj->getPublicationId(), $articleObj->getIssueNumber(), $articleObj->getSectionNumber(), $g_user->getUserId(), $languageArray); camp_html_add_msg(getGS("Article(s) duplicated."), "ok"); } camp_session_set($offsetVarName, 0); break; case "copy_interactive": $args = $_REQUEST;
/** * Creates an legacy Article based on a feed entry * * @param \NewscoopIngestPluginBundle\Entity\Feed\Entry $entry * * @return \Article Returns legacy article opbject */ protected function createLegacy(\Newscoop\IngestPluginBundle\Entity\Feed\Entry $entry) { $feed = $entry->getFeed(); $publication = $feed->getPublication(); // Determine issue if ($feed->getIssue() === null) { $issue = $this->em->getRepository('\\Newscoop\\Entity\\Issue')->findOneBy(array('publication' => $publication, 'language' => $entry->getLanguage(), 'workflowStatus' => 'Y'), array('number' => 'DESC')); } else { $issue = $feed->getIssue(); } $articleType = $this->em->getRepository('\\Newscoop\\Entity\\ArticleType')->findOneByName('Newswire'); $article = new \Article($entry->getLanguage()->getId()); $createSuccess = $article->create($articleType->getName(), $entry->getTitle(), $publication->getId(), $issue->getNumber(), $entry->getSection()->getNumber()); $article->setWorkflowStatus('N'); $article->setKeywords(implode(',', $entry->getKeywords())); $article->setCommentsEnabled(1); // ArticleType data $this->setArticleDataLegacy($article, $entry); // Dates $article->setCreationDate($entry->getCreated()->format('Y-m-d H:i:s')); $article->setProperty('time_updated', $entry->getUpdated()->format('Y-m-d H:i:s')); // Author $this->setArticleAuthorsLegacy($article, $entry); $this->setArticleImagesLegacy($article, $entry); try { $entry->setArticleId($article->getArticleNumber()); $articleAdded = $article->commit(); $this->em->persist($entry); $this->em->flush(); } catch (\Exception $e) { throw new Exception('Could not publish article.'); } // Topics $this->setArticleTopics($article->getArticleNumber(), $entry->getFeed()->getTopics()); return $article; }
/** * Create blog article * * @param string $title * @param Section $section * @return Article */ public function createBlog($title, \Section $section) { $article = new \Article($section->getLanguageId()); $article->create($this->config['article_type'], $title, $section->getPublicationId(), $section->getIssueNumber(), $section->getSectionNumber()); $qb = $this->em->createQueryBuilder(); $qb->select('atf')->from('\\Newscoop\\Entity\\ArticleTypeField', 'atf')->where("atf.typeHack = ?1 AND atf.name IS NOT NULL AND atf.name = 'NULL'")->setParameter(1, $this->config['article_type']); $articleTypeField = $qb->getQuery()->getOneOrNullResult(); $article->setCommentsEnabled($articleTypeField->getCommentsEnabled()); return $article; }
$i++; } } // Update the article. $articleObj->setTitle($f_article_title); $articleObj->setIsIndexed(false); if (!empty($f_comment_status)) { if ($f_comment_status == "enabled" || $f_comment_status == "locked") { $commentsEnabled = true; } else { $commentsEnabled = false; } // If status has changed, then you need to show/hide all the comments // as appropriate. if ($articleObj->commentsEnabled() != $commentsEnabled) { $articleObj->setCommentsEnabled($commentsEnabled); global $controller; $repository = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment'); $repository->setArticleStatus($f_article_number, $f_language_selected, $commentsEnabled ? STATUS_APPROVED : STATUS_HIDDEN); $repository->flush(); } $articleObj->setCommentsLocked($f_comment_status == "locked"); } // Make sure that the time stamp is updated. $articleObj->setProperty('time_updated', 'NOW()', true, true); // Verify creation date is in the correct format. // If not, dont change it. if (preg_match("/\\d{4}-\\d{2}-\\d{2}/", $f_creation_date)) { $articleObj->setCreationDate($f_creation_date); } // Verify publish date is in the correct format.
/** * 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; }
} else { $articleObj->create($f_article_type, $f_article_name, $publication_id, $issue_number, $section_number); } if ($articleObj->exists()) { $author = $this->_helper->service('user')->getCurrentUser()->getAuthorId(); if (empty($author)) { $articleObj->setCreatorId($g_user->getUserId()); $authorObj = new Author($g_user->getRealName()); if (!$authorObj->exists()) { $authorData = Author::ReadName($g_user->getRealName()); $authorData['email'] = $g_user->getEmail(); $authorObj->create($authorData); } } else { $authorObj = new Author($author); } if ($authorObj->exists()) { $articleObj->setAuthor($authorObj); } $articleObj->setIsPublic(true); if ($publication_id > 0) { $commentDefault = $publicationObj->commentsArticleDefaultEnabled(); $articleObj->setCommentsEnabled($commentDefault); } camp_html_add_msg(getGS("Article created."), "ok"); camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, "edit.php"), false); ArticleIndex::RunIndexer(3, 10, true); exit; } else { camp_html_display_error("Could not create article."); }
/** * 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; }