/** * Log article related event. * * @param Article $p_article * @param string $p_text * @param int $p_userId * @param int $p_eventId * @param bool $p_short * * @return void */ public static function ArticleMessage(Article $p_article, $p_text, $p_userId = NULL, $p_eventId = 0, $p_short = FALSE) { ob_start(); echo getGS('Article'), ': ', $p_article->getTitle(); if (!$p_short) { // add publication, issue, section echo ' ('; echo getGS('Publication'), ': ', $p_article->getPublicationId(); echo ', '; echo getGS('Issue'), ': ', $p_article->getIssueNumber(); echo ', '; echo getGS('Section'), ': ', $p_article->getSectionNumber(); echo ")\n"; } // generate url $url = ShortURL::GetURL($p_article->getPublicationId(), $p_article->getLanguageId(), $p_article->getIssueNumber(), $p_article->getSectionNumber(), $p_article->getArticleNumber()); if (strpos($url, 'http') !== FALSE) { // no url for deleted echo getGS('Article URL'), ': ', $url, "\n"; } echo getGS('Article Number'), ': ', $p_article->getArticleNumber(), "\n"; echo getGS('Language'), ': ', $p_article->getLanguageName(), "\n"; echo "\n"; echo getGS('Action') . ': ', $p_text; $message = ob_get_clean(); self::Message($message, $p_userId, $p_eventId); }
/** * Log article related event. * * @param Article $p_article * @param string $p_text * @param int $p_userId * @param int $p_eventId * @param bool $p_short * * @return void */ public static function ArticleMessage(Article $p_article, $p_text, $p_userId = NULL, $p_eventId = 0, $p_short = FALSE) { ob_start(); $translator = \Zend_Registry::get('container')->getService('translator'); echo $translator->trans('Article'), ': ', $p_article->getTitle(); if (!$p_short) { // add publication, issue, section echo ' ('; echo $translator->trans('Publication'), ': ', $p_article->getPublicationId(); echo ', '; echo $translator->trans('Issue'), ': ', $p_article->getIssueNumber(); echo ', '; echo $translator->trans('Section'), ': ', $p_article->getSectionNumber(); echo ")\n"; } // generate url $url = ShortURL::GetURL($p_article->getPublicationId(), $p_article->getLanguageId(), $p_article->getIssueNumber(), $p_article->getSectionNumber(), $p_article->getArticleNumber()); if (strpos($url, 'http') !== FALSE) { // no url for deleted echo $translator->trans('Article URL', array(), 'api'), ': ', $url, "\n"; } echo $translator->trans('Article Number', array(), 'api'), ': ', $p_article->getArticleNumber(), "\n"; echo $translator->trans('Language'), ': ', $p_article->getLanguageName(), "\n"; echo "\n"; echo $translator->trans('Action') . ': ', $p_text; $message = ob_get_clean(); self::Message(substr($message, 0, 254), $p_userId, $p_eventId); }
public static function GetURI($p_publicationId, $p_languageId, $p_issueNo = null, $p_sectionNo = null, $p_articleNo = null) { $translator = \Zend_Registry::get('container')->getService('translator'); $languageObj = new Language($p_languageId); if (!$languageObj->exists()) { return new PEAR_Error($translator->trans('Language does not exist.')); } $uri = '/' . $languageObj->getCode() . '/'; if (!is_null($p_issueNo) && is_null($p_articleNo)) { $issueObj = new Issue($p_publicationId, $p_languageId, $p_issueNo); if (!$issueObj->exists()) { return new PEAR_Error($translator->trans('Issue does not exist.')); } $uri .= $issueObj->getUrlName() . '/'; } if (!is_null($p_sectionNo) && is_null($p_articleNo)) { $sectionObj = new Section($p_publicationId, $p_issueNo, $p_languageId, $p_sectionNo); if (!$sectionObj->exists()) { return new PEAR_Error($translator->trans('Section does not exist.')); } $uri .= $sectionObj->getUrlName() . '/'; } if (!is_null($p_articleNo)) { $articleObj = new Article($p_languageId, $p_articleNo); if (!$articleObj->exists()) { return new PEAR_Error($translator->trans('Article does not exist.')); } $issueObj = new Issue($p_publicationId, $p_languageId, $articleObj->getIssueNumber()); $sectionObj = new Section($p_publicationId, $articleObj->getIssueNumber(), $p_languageId, $articleObj->getSectionNumber()); $uri .= $issueObj->getUrlName() . '/'; $uri .= $sectionObj->getUrlName() . '/'; $uri .= $articleObj->getUrlName() . '/'; } return $uri; }
public static function GetURI($p_publicationId, $p_languageId, $p_issueNo = null, $p_sectionNo = null, $p_articleNo = null) { $languageObj = new Language($p_languageId); if (!$languageObj->exists()) { return new PEAR_Error(getGS('Language does not exist.')); } $uri = $GLOBALS['Campsite']['SUBDIR'] . '/' . $languageObj->getCode() . '/'; if (!is_null($p_issueNo) && is_null($p_articleNo)) { $issueObj = new Issue($p_publicationId, $p_languageId, $p_issueNo); if (!$issueObj->exists()) { return new PEAR_Error(getGS('Issue does not exist.')); } $uri .= $issueObj->getUrlName() . '/'; } if (!is_null($p_sectionNo) && is_null($p_articleNo)) { $sectionObj = new Section($p_publicationId, $p_issueNo, $p_languageId, $p_sectionNo); if (!$sectionObj->exists()) { return new PEAR_Error(getGS('Section does not exist.')); } $uri .= $sectionObj->getUrlName() . '/'; } if (!is_null($p_articleNo)) { $articleObj = new Article($p_languageId, $p_articleNo); if (!$articleObj->exists()) { return new PEAR_Error(getGS('Article does not exist.')); } $issueObj = new Issue($p_publicationId, $p_languageId, $articleObj->getIssueNumber()); $sectionObj = new Section($p_publicationId, $articleObj->getIssueNumber(), $p_languageId, $articleObj->getSectionNumber()); $uri .= $issueObj->getUrlName() . '/'; $uri .= $sectionObj->getUrlName() . '/'; $uri .= $articleObj->getUrlName() . '/'; } return $uri; }
private function getArticleLink(Article $article) { $params = array('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()); $queryString = implode('&', array_map(function ($property) use($params) { return $property . '=' . $params[$property]; }, array_keys($params))); return $this->view->baseUrl("/admin/articles/edit.php?{$queryString}"); }
/** * Get article edit link * * @param Article $article * @return string */ public function getEditLink($article) { $params = array('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()); $paramsStrings = array(); foreach ($params as $key => $val) { $paramsStrings[] = "{$key}={$val}"; } return '/admin/articles/edit.php?' . implode('&', $paramsStrings); }
/** * Send request to refresh article cache on Facebook * * @param int $number * @param int $languageId * * @return mixed response from Facebook about url, or array with error message */ private function clearpageCache($number, $languageId) { $article = new \Article($languageId, $number); if (!$article->isPublished()) { return array('message' => $this->get('translator')->trans('fb.label.errornot')); } $url = \ShortURL::GetURL($article->getPublicationId(), $article->getLanguageId(), $article->getIssueNumber(), $article->getSectionNumber(), $article->getArticleNumber()); try { $curlClient = new \Buzz\Client\Curl(); $curlClient->setTimeout(10000); $browser = new \Buzz\Browser($curlClient); $result = $browser->post('https://graph.facebook.com/?id=' . $url . '&scrape=true'); $urlInfo = json_decode($result->getContent(), true); } catch (\Buzz\Exception\ClientException $e) { return array('message' => $this->get('translator')->trans('fb.label.error')); } return $urlInfo; }
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()); }
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; unset($args[SecurityToken::SECURITY_TOKEN]); unset($args["f_article_code"]); $argsStr = camp_implode_keys_and_values($args, "=", "&"); $argsStr .= "&f_mode=multi&f_action=duplicate"; foreach ($_REQUEST["f_article_code"] as $code) { $argsStr .= "&f_article_code[]={$code}"; } camp_session_set($offsetVarName, 0); camp_html_goto_page("/{$ADMIN}/articles/duplicate.php?" . $argsStr);
/** * Create a link to an article. * * @param Article $p_articleObj * The article we want to display. * * @param int $p_sectionLanguageId * The language ID for the publication/issue/section. * * @param string $p_targetFileName * Which file in the "articles" directory to call. * * @param string $p_backLink * A URL to get back to the previous page the user was on. * * @param string $p_extraParams */ function camp_html_article_url($p_articleObj, $p_sectionLanguageId, $p_targetFileName = "", $p_backLink = "", $p_extraParams = null, $p_securityParameter = false) { global $ADMIN; $str = "/{$ADMIN}/articles/" . $p_targetFileName . "?f_publication_id=" . $p_articleObj->getPublicationId() . "&f_issue_number=" . $p_articleObj->getIssueNumber() . "&f_section_number=" . $p_articleObj->getSectionNumber() . "&f_article_number=" . $p_articleObj->getArticleNumber() . "&f_language_id=" . $p_sectionLanguageId . "&f_language_selected=" . $p_articleObj->getLanguageId(); if ($p_securityParameter) { $str .= '&' . SecurityToken::URLParameter(); } if ($p_backLink != "") { $str .= "&Back=" . urlencode($p_backLink); } if (!is_null($p_extraParams)) { $str .= $p_extraParams; } return $str; }
} else { $notAffectedArticles += 1; } } $message = getGS("$1 Article(s) unlocked", $affectedArticles); $errorMessage = getGS("$1 Article(s) not unlocked", $notAffectedArticles); break; case 'duplicate': 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); $success = true; $affectedArticles += 1; } $message = getGS("$1 Article(s) duplicated", $affectedArticles); break; case 'duplicate_interactive': case 'move': $args = array_merge($_REQUEST, $f_params); unset($args["f_article_code"]); $argsStr = camp_implode_keys_and_values($args, "=", "&");
break; case 'Published': $f_value = 'Y'; break; case 'Submitted': $f_value = 'S'; break; } $access = false; // A publisher can change the status in any way he sees fit. // Someone who can change an article can submit/unsubmit articles. // A user who owns the article may submit it. if ($g_user->hasPermission('Publish') || $g_user->hasPermission('ChangeArticle') && $f_value != 'Y' || $articleObj->userCanModify($g_user) && $f_value == 'S') { $access = true; } // If the article is not yet categorized, force it to be before publication. if ($f_action_workflow == "Y" && ($articleObj->getPublicationId() == 0 || $articleObj->getIssueNumber() == 0 || $articleObj->getSectionNumber() == 0)) { //$args = $_REQUEST; //$argsStr = camp_implode_keys_and_values($_REQUEST, "=", "&"); //$argsStr .= "&f_article_code[]=".$f_article_number."_".$f_language_selected; //$argsStr .= "&f_mode=single&f_action=publish"; //camp_html_goto_page("/$ADMIN/articles/duplicate.php?".$argsStr); } $success = $articleObj->setWorkflowStatus($f_value); $message = $translator->trans("Article status set to \$1", array('$1' => $articleObj->getWorkflowDisplayString($f_value)), 'library'); } } if ($affectedArticles == 0 && $success) { $affectedArticles = 1; } return returnJson($affectedArticles, $message, $notAffectedArticles, $errorMessage, $hiperlink);
if (!$issueObj->exists()) { camp_html_display_error($translator->trans('Issue does not exist.')); exit; } $sectionObj = new Section($f_publication_id, $f_issue_number, $f_language_id, $f_section_number); if (!$sectionObj->exists()) { camp_html_display_error($translator->trans('Section does not exist.')); exit; } $articleObj = new Article($f_article_language, $f_article_number); if (!$articleObj->exists()) { camp_html_display_error($translator->trans('Article does not exist.')); exit; } switch ($f_move) { case 'up_rel': $articleObj->positionRelative('up', 1); break; case 'down_rel': $articleObj->positionRelative('down', 1); break; case 'abs': $articleObj->positionAbsolute($f_position); break; default: } $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); $cacheService->clearNamespace('article'); $url = "/{$ADMIN}/articles/index.php" . "?f_publication_id=" . $articleObj->getPublicationId() . "&f_issue_number=" . $articleObj->getIssueNumber() . "&f_section_number=" . $articleObj->getSectionNumber() . "&f_article_number=" . $articleObj->getArticleNumber() . "&f_language_selected={$f_language_selected}" . "&f_language_id=" . $f_language_id; camp_html_add_msg($translator->trans("Article order changed.", array(), 'articles'), "ok"); camp_html_goto_page($url);
list($articleNumber, $languageId) = explode("_", $f_article_code); if (!Input::IsValid()) { camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), $BackLink); exit; } $articleObj = new Article($languageId, $articleNumber); if (!$articleObj->exists()) { camp_html_display_error(getGS('Article does not exist.'), $BackLink); exit; } $f_publication_id = ($f_publication_id > 0) ? $f_publication_id : $articleObj->getPublicationId(); $f_issue_number = ($f_issue_number > 0) ? $f_issue_number : $articleObj->getIssueNumber(); $f_section_number = ($f_section_number > 0) ? $f_section_number : $articleObj->getSectionNumber(); if ($f_publication_id > 0) { $publicationObj = new Publication($f_publication_id); if (!$publicationObj->exists()) { camp_html_display_error(getGS('Publication does not exist.'), $BackLink); exit; } $issueObj = new Issue($f_publication_id, $f_language_id, $f_issue_number); if (!$issueObj->exists()) { camp_html_display_error(getGS('No such issue.'), $BackLink); exit; } $sectionObj = new Section($f_publication_id, $f_issue_number, $f_language_id, $f_section_number);
} $articleObj = new Article($f_article_language, $f_article_number); if (!$articleObj->exists()) { camp_html_display_error(getGS('Article does not exist.')); exit; } switch ($f_move) { case 'up_rel': $articleObj->positionRelative('up', 1); break; case 'down_rel': $articleObj->positionRelative('down', 1); break; case 'abs': $articleObj->positionAbsolute($f_position); break; default: ; } $url = "/$ADMIN/articles/index.php" ."?f_publication_id=".$articleObj->getPublicationId() ."&f_issue_number=".$articleObj->getIssueNumber() ."&f_section_number=".$articleObj->getSectionNumber() ."&f_article_number=".$articleObj->getArticleNumber() ."&f_language_selected=$f_language_selected" ."&f_language_id=".$f_language_id; camp_html_add_msg(getGS("Article order changed."), "ok"); camp_html_goto_page($url); ?>
/** * Create a copy of this article. * * @param int $p_destPublicationId - * The destination publication ID. * @param int $p_destIssueNumber - * The destination issue number. * @param int $p_destSectionNumber - * The destination section number. * @param int $p_userId - * The user creating the copy. If null, keep the same user ID as the original. * @param mixed $p_copyTranslations - * If false (default), only this article will be copied. * If true, all translations will be copied. * If an array is passed, the translations given will be copied. * Any translations that do not exist will be ignored. * * @return Article * If $p_copyTranslations is TRUE or an array, return an array of newly created articles. * If $p_copyTranslations is FALSE, return the new Article. */ public function copy($p_destPublicationId = 0, $p_destIssueNumber = 0, $p_destSectionNumber = 0, $p_userId = null, $p_copyTranslations = false) { global $g_ado_db; // It is an optimization to put these here because in most cases // you dont need these files. require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleImage.php'); require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleTopic.php'); require_once($GLOBALS['g_campsiteDir'].'/classes/ArticleAttachment.php'); $copyArticles = array(); if ($p_copyTranslations) { // Get all translations for this article $copyArticles = $this->getTranslations(); // Remove any translations that are not requested to be translated. if (is_array($p_copyTranslations)) { $tmpArray = array(); foreach ($copyArticles as $tmpArticle) { if (in_array($tmpArticle->m_data['IdLanguage'], $p_copyTranslations)) { $tmpArray[] = $tmpArticle; } } $copyArticles = $tmpArray; } } else { $copyArticles[] = $this; } $newArticleNumber = $this->__generateArticleNumber(); // geo-map copying if (0 < count($copyArticles)) { $map_user_id = $p_userId; if (is_null($map_user_id)) { $map_user_id = $this->m_data['IdUser']; } $map_artilce_src = (int)$this->m_data['Number']; $map_artilce_dest = (int)$newArticleNumber; $map_translations = array(); foreach ($copyArticles as $copyMe) { $map_translations[] = (int)$copyMe->m_data['IdLanguage']; } Geo_Map::OnArticleCopy($map_artilce_src, $map_artilce_dest, $map_translations, $map_user_id); } // Load translation file for log message. if (function_exists("camp_load_translation_strings")) { camp_load_translation_strings("api"); } $articleOrder = null; $logtext = ''; $newArticles = array(); foreach ($copyArticles as $copyMe) { // Construct the duplicate article object. $articleCopy = new Article(); $articleCopy->m_data['IdPublication'] = (int)$p_destPublicationId; $articleCopy->m_data['NrIssue'] = (int)$p_destIssueNumber; $articleCopy->m_data['NrSection'] = (int)$p_destSectionNumber; $articleCopy->m_data['IdLanguage'] = (int)$copyMe->m_data['IdLanguage']; $articleCopy->m_data['Number'] = (int)$newArticleNumber; $values = array(); // Copy some attributes $values['ShortName'] = $newArticleNumber; $values['Type'] = $copyMe->m_data['Type']; $values['OnFrontPage'] = $copyMe->m_data['OnFrontPage']; $values['OnSection'] = $copyMe->m_data['OnSection']; $values['Public'] = $copyMe->m_data['Public']; $values['ArticleOrder'] = $articleOrder; $values['Keywords'] = $copyMe->m_data['Keywords']; // Change some attributes $values['Published'] = 'N'; $values['IsIndexed'] = 'N'; $values['LockUser'] = 0; $values['LockTime'] = 0; if (!is_null($p_userId)) { $values['IdUser'] = $p_userId; } else { $values['IdUser'] = $copyMe->m_data['IdUser']; } $values['Name'] = $articleCopy->getUniqueName($copyMe->m_data['Name']); $articleCopy->__create($values); $articleCopy->setProperty('UploadDate', 'NOW()', true, true); if (is_null($articleOrder)) { $g_ado_db->Execute('LOCK TABLES Articles WRITE'); $articleOrder = $g_ado_db->GetOne('SELECT MAX(ArticleOrder) + 1 FROM Articles'); $articleCopy->setProperty('ArticleOrder', $articleOrder); $g_ado_db->Execute('UNLOCK TABLES'); } // Insert an entry into the article type table. $newArticleData = new ArticleData($articleCopy->m_data['Type'], $articleCopy->m_data['Number'], $articleCopy->m_data['IdLanguage']); $newArticleData->create(); $origArticleData = $copyMe->getArticleData(); $origArticleData->copyToExistingRecord($articleCopy->m_data['Number']); // Copy image pointers ArticleImage::OnArticleCopy($copyMe->m_data['Number'], $articleCopy->m_data['Number']); // Copy topic pointers ArticleTopic::OnArticleCopy($copyMe->m_data['Number'], $articleCopy->m_data['Number']); // Copy file pointers ArticleAttachment::OnArticleCopy($copyMe->m_data['Number'], $articleCopy->m_data['Number']); // Position the new article at the beginning of the section $articleCopy->positionAbsolute(1); $newArticles[] = $articleCopy; $languageObj = new Language($copyMe->getLanguageId()); $logtext .= getGS('Article copied to Article #$4 (publication $5, issue $6, section $7).', $articleCopy->getArticleNumber(), $articleCopy->getPublicationId(), $articleCopy->getIssueNumber(), $articleCopy->getSectionNumber()); } Log::ArticleMessage($copyMe, $logtext, null, 155); if ($p_copyTranslations) { return $newArticles; } else { return array_pop($newArticles); } } // fn copy
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; unset($args[SecurityToken::SECURITY_TOKEN]); unset($args["f_article_code"]); $argsStr = camp_implode_keys_and_values($args, "=", "&"); $argsStr .= "&f_mode=multi&f_action=duplicate"; foreach ($_REQUEST["f_article_code"] as $code) { $argsStr .= "&f_article_code[]=$code"; }
/** * 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); }
/** * */ public static function GetTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr, $p_artNr, $p_isPublished = true) { global $g_ado_db; if ($p_lngId <= 0) { $publication = new Publication($p_pubId); if (!$publication->exists()) { return null; } $p_lngId = $publication->getLanguageId(); } if ($p_artNr > 0) { if ($p_issNr <= 0 || $p_sctNr <= 0) { $article = new Article($p_lngId, $p_artNr); if (!$article->exists() || $p_isPublished && !$article->isPublished()) { return self::GetInvalidURLTemplate($p_pubId, $p_issNr, $p_lngId, $p_isPublished); } $p_issNr = $article->getIssueNumber(); $p_sctNr = $article->getSectionNumber(); } return self::GetArticleTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr); } if ($p_sctNr > 0) { if ($p_issNr <= 0) { $sql = 'SELECT MAX(i.Number) AS Number ' . 'FROM Sections as s, Issues as i ' . 'WHERE s.IdPublication = i.IdPublication' . ' AND s.IdLanguage = i.IdLanguage' . ' AND s.IdPublication = ' . (int) $p_pubId . ' AND s.IdLanguage = ' . (int) $p_lngId; if ($p_isPublished == true) { $sql .= " AND i.Published = 'Y'"; } $data = $g_ado_db->GetOne($sql); if (empty($data)) { return null; } $p_issNr = $data; } return self::GetSectionTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr); } if ($p_issNr <= 0) { $sql = 'SELECT MAX(Number) AS Number FROM Issues ' . 'WHERE IdPublication = ' . $p_pubId . ' AND IdLanguage = ' . $p_lngId; if ($p_isPublished == true) { $sql .= " AND Published = 'Y'"; } $data = $g_ado_db->GetOne($sql); if (empty($data)) { return null; } $p_issNr = $data; } return self::GetIssueTemplate($p_lngId, $p_pubId, $p_issNr); }
} if (!camp_is_valid_url_name($f_issue_urlname)) { camp_html_add_msg(getGS('The $1 field may only contain letters, digits and underscore (_) character.', '"' . getGS('New issue URL name') . '"')); camp_html_goto_page($backLink); } $translationIssueObj->create($f_issue_urlname); if (!$translationIssueObj->exists()) { camp_html_add_msg(getGS('Unable to create the issue for translation $1.', $translationLanguageObj->getName())); camp_html_goto_page($backLink); } } else { $f_issue_name = Input::Get('f_issue_name', 'string', $issueObj->getName()); $f_issue_urlname = Input::Get('f_issue_urlname', 'string', $issueObj->getUrlName()); $translationIssueObj->update(array('Name' => $f_issue_name, 'ShortName' => $f_issue_urlname)); } $f_section_number = $articleObj->getSectionNumber(); $sectionObj = new Section($f_publication_id, $f_issue_number, $f_language_id, $f_section_number); if (!$sectionObj->exists()) { camp_html_display_error(getGS('No such section.'), $backLink); exit; } $translationSectionObj = new Section($f_publication_id, $f_issue_number, $f_translation_language, $f_section_number); if (!$translationSectionObj->exists()) { if (!$g_user->hasPermission("ManageSection")) { camp_html_add_msg(getGS('A section must be created for the selected language but you do not have the right to create a section.')); camp_html_goto_page($backLink); } foreach ($sectionObj->getData() as $field => $fieldValue) { if ($field != 'IdLanguage') { $translationSectionObj->setProperty($field, $fieldValue, false); }
/** * Test if given article is from users blog * * @param Article $article * @param Newscoop\Entity\User $user * @return bool */ public function isUsersArticle(\Article $article, User $user) { $section = $this->getSection($user); return $section->getSectionNumber() == $article->getSectionNumber() && $section->getPublicationId() == $article->getPublicationId() && $section->getIssueNumber() == $article->getIssueNumber() && $section->getLanguageId() == $article->getLanguageId(); }
if ($articleObj->userCanModify($g_user)) { $articleObj->setIsLocked(false); $success = true; $affectedArticles += 1; } else { $notAffectedArticles += 1; } } $message = getGS("\$1 Article(s) unlocked", $affectedArticles); $errorMessage = getGS("\$1 Article(s) not unlocked", $notAffectedArticles); break; case 'duplicate': 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); $success = true; $affectedArticles += 1; } $message = getGS("\$1 Article(s) duplicated", $affectedArticles); break; case 'duplicate_interactive': case 'move': $args = array_merge($_REQUEST, $f_params); unset($args["f_article_code"]); $argsStr = camp_implode_keys_and_values($args, "=", "&"); $argsStr .= '&f_mode=multi&f_action='; $argsStr .= $f_action == 'move' ? 'move' : 'duplicate'; $argsStr .= '&f_language_selected=' . (int) camp_session_get('f_language_selected', 0); foreach ($flatArticleCodes as $articleCode) { $argsStr .= '&f_article_code[]=' . $articleCode;
/** * */ public static function GetTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr, $p_artNr, $p_isPublished = true) { $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache'); global $g_ado_db; if ($p_lngId <= 0) { $cacheKey = $cacheService->getCacheKey('legacy_publication' . $p_pubId, 'publication'); if ($cacheService->contains($cacheKey)) { $publication = $cacheService->fetch($cacheKey); } else { $publication = new Publication($p_pubId); $cacheService->save($cacheKey, $publication); } if (!$publication->exists()) { return null; } $p_lngId = $publication->getLanguageId(); } if ($p_artNr > 0) { if ($p_issNr <= 0 || $p_sctNr <= 0) { $article = new Article($p_lngId, $p_artNr); if (!$article->exists() || $p_isPublished && !$article->isPublished()) { return self::GetInvalidURLTemplate($p_pubId, $p_issNr, $p_lngId, $p_isPublished); } $p_issNr = $article->getIssueNumber(); $p_sctNr = $article->getSectionNumber(); } return self::GetArticleTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr); } if ($p_sctNr > 0) { if ($p_issNr <= 0) { $sql = 'SELECT MAX(i.Number) AS Number ' . 'FROM Sections as s, Issues as i ' . 'WHERE s.IdPublication = i.IdPublication' . ' AND s.IdLanguage = i.IdLanguage' . ' AND s.IdPublication = ' . (int) $p_pubId . ' AND s.IdLanguage = ' . (int) $p_lngId; if ($p_isPublished == true) { $sql .= " AND i.Published = 'Y'"; } $data = $g_ado_db->GetOne($sql); if (empty($data)) { return null; } $p_issNr = $data; } return self::GetSectionTemplate($p_lngId, $p_pubId, $p_issNr, $p_sctNr); } if ($p_issNr <= 0) { $sql = 'SELECT MAX(Number) AS Number FROM Issues ' . 'WHERE IdPublication = ' . $p_pubId . ' AND IdLanguage = ' . $p_lngId; if ($p_isPublished == true) { $sql .= " AND Published = 'Y'"; } $data = $g_ado_db->GetOne($sql); if (empty($data)) { return null; } $p_issNr = $data; } return self::GetIssueTemplate($p_lngId, $p_pubId, $p_issNr); }
/** * @Route("/redirect/{languageId}/{articleNumber}/") */ public function redirectToArticleAction($languageId, $articleNumber, Request $request) { $legacyArticleLink = ''; // find article $article = new \Article($languageId, $articleNumber); if (!$article->exists()) { throw new Exception($this->container->get('translator')->trans('plugin.ingest.entries.articlenotfound', array('%language%' => $languageId, '%article%' => $articleNumber)), 1); } $legacyArticleLink = '/admin/articles/edit.php?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(); return $this->redirect($legacyArticleLink); }