function test_article() { $article = new Article(9000001,9000002,9000003,9000004); // Test create $article->create("Unit Test Long Name", "Unit Test Short Name", "fastnews"); $this->assertTrue($article->exists()); // Test SET functions $article->setTitle("Unit Test New Title"); $article->setCreatorId(9000005); $article->setOnFrontPage(true); $article->setOnSection(true); $article->setWorkflowStatus('Y'); $article->setKeywords("Unit, Test"); $article->setIsIndexed(true); // Test GET functions $articleCopy = new Article(9000001, 9000002, 9000003, 9000004, $article->getArticleId()); $this->assertEquals(9000001, $articleCopy->getPublicationId()); $this->assertEquals(9000002, $articleCopy->getIssueNumber()); $this->assertEquals(9000003, $articleCopy->getSectionNumber()); $this->assertEquals(9000004, $articleCopy->getLanguageId()); $this->assertEquals(9000005, $articleCopy->getCreatorId()); $this->assertEquals("Unit Test New Title", $articleCopy->getTitle()); $this->assertEquals(true, $articleCopy->onFrontPage()); $this->assertEquals(true, $articleCopy->onSection()); $this->assertEquals('Y', $articleCopy->getWorkflowStatus()); $this->assertEquals("Unit, Test", $articleCopy->getKeywords()); $this->assertEquals(true, $articleCopy->isIndexed()); // Test DELETE functions $article->delete(); $this->assertFalse($article->exists()); }
// calculate the first language of an article number // and also the number of translations associated with an article number global $g_ado_db; $sql = "SELECT * FROM X$f_src WHERE NrArticle=$f_cur_preview"; $rows = $g_ado_db->GetAll($sql); if (!count($rows)) { $errMsgs[] = getGS('There is no article associated with the preview.'); $ok = false; } } if ($ok) { $numberOfTranslations = count($rows); $firstLanguage = $rows[0]['IdLanguage']; $curPreview = new Article($firstLanguage, $f_cur_preview); $articleCreator = new User($curPreview->getCreatorId()); $articleData = $dest->getPreviewArticleData(); $dbColumns = $articleData->getUserDefinedColumns(1, true); $srcArticleData = $curPreview->getArticleData(); $srcDbColumns = $srcArticleData->getUserDefinedColumns(1, true); $getString = ''; foreach ($_GET as $k => $v) { if ( ($k != 'f_action') && ($k != 'f_preview_action') ) { $getString .= "&$k=$v"; } } foreach ($_POST as $k => $v) { if ( ($k != 'f_action') && ($k != 'f_prev_action') ) { $getString .= "&$k=$v"; } }
/** * Create the first message for an article, which is a blank message * with the title of the article as the subject. * * @param Article $p_article * @param int $p_forumId * @return mixed * The comment created (or the one that already exists) on success, * or false on error. */ private function CreateFirstComment($p_article, $p_forumId) { // Check if the first post already exists. $articleNumber = $p_article->getArticleNumber(); $languageId = $p_article->getLanguageId(); $firstPost = ArticleComment::GetCommentThreadId($articleNumber, $languageId); if ($firstPost) { return new Phorum_message($firstPost); } // Get article creator $user = new User($p_article->getCreatorId()); if ($user->exists()) { $userId = $user->getUserId(); $userEmail = $user->getEmail(); $userPasswd = $user->getPassword(); $userName = $user->getUserName(); $userRealName = $user->getRealName(); // Create phorum user if necessary $phorumUser = Phorum_user::GetByUserName($userName); if (!is_object($phorumUser)) { $phorumUser = new Phorum_user(); } if (!$phorumUser->CampUserExists($userId) && !$phorumUser->create($userName, $userPasswd, $userEmail, $userId)) { return null; } } else { $userId = null; $userEmail = ''; $userRealName = ''; } // Create the comment. $title = $p_article->getTitle(); $commentObj = new Phorum_message(); if ($commentObj->create($p_forumId, $title, '', 0, 0, $userRealName, $userEmail, is_null($userId) ? 0 : $userId)) { // Link the message to the current article. ArticleComment::Link($articleNumber, $languageId, $commentObj->getMessageId(), true); return $commentObj; } else { return null; } } // method CreateFirstComment
$returnJson['messages'][] = buildMessage('affected', $affectedNo, $message); $returnJson['messages'][] = buildMessage('notAffected', $notAffectedNo, $errorMessage); return json_encode($returnJson); } switch ($f_action) { case 'delete': if (!$g_user->hasPermission('DeleteArticle')) { $success = false; $data->error = $translator->trans('You do not have the right to delete articles.', array(), 'library'); break; } $affectedArticles = 0; $notAffectedArticles = 0; foreach ($articleCodes as $articleCode) { $article = new Article($articleCode['language_id'], $articleCode['article_id']); $creatorId = $article->getCreatorId(); if ($article->delete()) { \Zend_Registry::get('container')->getService('dispatcher')->dispatch('user.set_points', new \Newscoop\EventDispatcher\Events\GenericEvent(null, array('user' => $creatorId))); $success = true; $affectedArticles += 1; } else { $notAffectedArticles += 1; } } $message = $translator->trans("\$1 articles have been removed", array('$1' => $affectedArticles), 'library'); $errorMessage = $translator->trans("\$1 articles have not been removed", array('$1' => $notAffectedArticles), 'library'); break; case "workflow_publish": if (!$g_user->hasPermission('Publish')) { $success = false; $data->error = $translator->trans('You do not have the right to change this article status. Once submitted an article can only be changed by authorized users.', array(), 'library');
$blogService = \Zend_Registry::get('container')->getService('blog'); if ($blogService->isBlogger($g_user)) { $userIsBlogger = true; $userSection = $blogService->getSection($g_user); if (empty($userSection) || $userSection->getSectionId() != $articleObj->getSection()->getSectionId()) { camp_html_display_error(getGS("You're not allowed to edit article.")); exit; } } $articleData = $articleObj->getArticleData(); // Get article type fields. $dbColumns = $articleData->getUserDefinedColumns(FALSE, TRUE); $articleType = new ArticleType($articleObj->getType()); $articleImages = ArticleImage::GetImagesByArticleNumber($f_article_number); $lockUserObj = new User($articleObj->getLockedByUser()); $articleCreator = new User($articleObj->getCreatorId()); $articleEvents = ArticlePublish::GetArticleEvents($f_article_number, $f_language_selected, TRUE); $articleTopics = ArticleTopic::GetArticleTopics($f_article_number); $articleFiles = ArticleAttachment::GetAttachmentsByArticleNumber($f_article_number, $f_language_selected); $articleLanguages = $articleObj->getLanguages(); // Create displayable "last modified" time. $lastModified = strtotime($articleObj->getLastModified()); $today = getdate(); $savedOn = getdate($lastModified); $savedToday = true; if ($today['year'] != $savedOn['year'] || $today['mon'] != $savedOn['mon'] || $today['mday'] != $savedOn['mday']) { $savedToday = FALSE; } $sectionObj = null; $showComments = FALSE; $showCommentControls = FALSE;
/** * Process item * @param Article $article * @return array */ public function processItem(Article $article) { global $g_user, $Campsite; $articleLinkParams = '?f_publication_id=' . $article->getPublicationId() . '&f_issue_number=' . $article->getIssueNumber() . '&f_section_number=' . $article->getSectionNumber() . '&f_article_number=' . $article->getArticleNumber() . '&f_language_id=' . $article->getLanguageId() . '&f_language_selected=' . $article->getLanguageId(); $articleLinkParamsTranslate = $articleLinkParams . '&f_action=translate&f_action_workflow=' . $article->getWorkflowStatus() . '&f_article_code=' . $article->getArticleNumber() . '_' . $article->getLanguageId(); $articleLink = $Campsite['WEBSITE_URL'] . '/admin/articles/edit.php' . $articleLinkParams; $previewLink = $Campsite['WEBSITE_URL'] . '/admin/articles/preview.php' . $articleLinkParams; $htmlPreviewLink = '<a href="' . $previewLink . '" target="_blank" title="' . getGS('Preview') . '">' . getGS('Preview') . '</a>'; $translateLink = $Campsite['WEBSITE_URL'] . '/admin/articles/translate.php' . $articleLinkParamsTranslate; $htmlTranslateLink = '<a href="' . $translateLink . '" target="_blank" title="' . getGS('Translate') . '">' . getGS('Translate') . '</a>'; $lockInfo = ''; $lockHighlight = false; $timeDiff = camp_time_diff_str($article->getLockTime()); if ($article->isLocked() && $timeDiff['days'] <= 0) { $lockUser = new User($article->getLockedByUser()); if ($timeDiff['hours'] > 0) { $lockInfo = getGS('The article has been locked by $1 ($2) $3 hour(s) and $4 minute(s) ago.', htmlspecialchars($lockUser->getRealName()), htmlspecialchars($lockUser->getUserName()), $timeDiff['hours'], $timeDiff['minutes']); } else { $lockInfo = getGS('The article has been locked by $1 ($2) $3 minute(s) ago.', htmlspecialchars($lockUser->getRealName()), htmlspecialchars($lockUser->getUserName()), $timeDiff['minutes']); } if ($article->getLockedByUser() != $g_user->getUserId()) { $lockHighlight = true; } } $tmpUser = new User($article->getCreatorId()); $tmpArticleType = new ArticleType($article->getType()); $tmpAuthor = new Author(); $articleAuthors = ArticleAuthor::GetAuthorsByArticle($article->getArticleNumber(), $article->getLanguageId()); foreach ((array) $articleAuthors as $author) { if (strtolower($author->getAuthorType()->getName()) == 'author') { $tmpAuthor = $author; break; } } if (!$tmpAuthor->exists() && isset($articleAuthors[0])) { $tmpAuthor = $articleAuthors[0]; } $onFrontPage = $article->onFrontPage() ? getGS('Yes') : getGS('No'); $onSectionPage = $article->onSectionPage() ? getGS('Yes') : getGS('No'); $imagesNo = (int) ArticleImage::GetImagesByArticleNumber($article->getArticleNumber(), true); $topicsNo = (int) ArticleTopic::GetArticleTopics($article->getArticleNumber(), true); $commentsNo = ''; if ($article->commentsEnabled()) { global $controller; $repositoryComments = $controller->getHelper('entity')->getRepository('Newscoop\\Entity\\Comment'); $filter = array('thread' => $article->getArticleNumber(), 'language' => $article->getLanguageId()); $params = array('sFilter' => $filter); $commentsNo = $repositoryComments->getCount($params); } else { $commentsNo = 'No'; } // get language code $language = new Language($article->getLanguageId()); return array($article->getArticleNumber(), $article->getLanguageId(), $article->getOrder(), sprintf('%s <a href="%s" title="%s %s">%s</a>', $article->isLocked() ? '<span class="ui-icon ui-icon-locked' . (!$lockHighlight ? ' current-user' : '') . '" title="' . $lockInfo . '"></span>' : '', $articleLink, getGS('Edit'), htmlspecialchars($article->getName() . " ({$article->getLanguageName()})"), htmlspecialchars($article->getName() . (empty($_REQUEST['language']) ? " ({$language->getCode()})" : ''))), htmlspecialchars($article->getSection()->getName()), $article->getWebcode(), htmlspecialchars($tmpArticleType->getDisplayName()), htmlspecialchars($tmpUser->getRealName()), htmlspecialchars($tmpAuthor->getName()), $article->getWorkflowStatus(), $onFrontPage, $onSectionPage, $imagesNo, $topicsNo, $commentsNo, (int) $article->getReads(), Geo_Map::GetArticleMapId($article) != NULL ? getGS('Yes') : getGS('No'), (int) sizeof(Geo_Map::GetLocationsByArticle($article)), $article->getCreationDate(), $article->getPublishDate(), $article->getLastModified(), $htmlPreviewLink, $htmlTranslateLink); }