Example #1
0
/**
 * Campsite Map function plugin
 *
 * Type:     function
 * Name:     count
 * Purpose:  Triggers a statistics counting request
 *
 * @param array
 *     $p_params List of parameters from template
 * @param object
 *     $p_smarty Smarty template object
 *
 * @return
 *     string The html content
 */
function smarty_function_count($p_params, &$p_smarty)
{
    global $Campsite;
    $campsite = $p_smarty->getTemplateVars('gimme');
    $content = '';
    $art_number = 0;
    $art_language_num = 0;
    $art_language_code = '';
    if (isset($p_params['article']) && is_numeric($p_params['article'])) {
        $art_number = $p_params['article'];
    }
    if (isset($p_params['language'])) {
        $langs = array();
        if (is_numeric($p_params['language'])) {
            $langs = \Language::GetLanguages($p_params['language']);
        } else {
            $langs = \Language::GetLanguages(null, $p_params['language']);
        }
        if (!isset($langs[0])) {
            return '';
            // 'no lang'
        }
        $art_language_obj = $langs[0];
        $art_language_num = $art_language_obj->getLanguageId();
        $art_language_code = $art_language_obj->getCode();
    }
    $count_automatically = true;
    if (isset($p_params['dont_count_automatically'])) {
        $count_automatically = false;
    }
    if (!$art_number || !$art_language_num) {
        $meta_article = $campsite->article;
        if ($meta_article->defined) {
            if (!$art_number) {
                $art_number = $meta_article->number;
            }
            if (!$art_language_num) {
                $art_language_meta = $meta_article->language;
                $art_language_num = $art_language_meta->number;
                $art_language_code = $art_language_meta->code;
            }
        }
    }
    if (!$art_language_num) {
        $art_language_meta = $campsite->language;
        $art_language_num = $art_language_meta->number;
        $art_language_code = $art_language_meta->code;
    }
    if (!$art_number || !$art_language_num) {
        return '';
        // 'no art_num or lang'
    }
    $article = new \Article($art_language_num, $art_number);
    if (!$article->exists()) {
        return '';
        // 'no art'
    }
    try {
        $requestObjectId = $article->getProperty('object_id');
        $updateArticle = empty($requestObjectId);
        $objectType = new \ObjectType('article');
        $object_type_id = $objectType->getObjectTypeId();
        if ($updateArticle) {
            $requestObject = new \RequestObject($requestObjectId);
            if (!$requestObject->exists()) {
                $requestObject->create(array('object_type_id' => $objectType->getObjectTypeId()));
                $requestObjectId = $requestObject->getObjectId();
            }
            $article->setProperty('object_id', $requestObjectId);
        }
        // statistics shall be only gathered if the site admin set it on (and not for editor previews)
        if (!$campsite->preview) {
            $stat_web_url = $Campsite['WEBSITE_URL'];
            if ('/' != $stat_web_url[strlen($stat_web_url) - 1]) {
                $stat_web_url .= '/';
            }
            $article_number = $article->getProperty('Number');
            $name_spec = '_' . $article_number . '_' . $art_language_code;
            $content .= \Statistics::JavaScriptTrigger(array('count_automatically' => $count_automatically, 'name_spec' => $name_spec, 'object_type_id' => $object_type_id, 'request_object_id' => $requestObjectId));
        }
    } catch (\Exception $ex) {
        return '';
    }
    return $content;
}
Example #2
0
    /**
     * Create a copy of the article, but make it a translation
     * of the current one.
     *
     * @param int $p_languageId
     * @param int $p_userId
     * @param string $p_name
     * @return Article
     */
    public function createTranslation($p_languageId, $p_userId, $p_name)
    {
        // Construct the duplicate article object.
        $articleCopy = new Article();
        $articleCopy->m_data['IdPublication'] = $this->m_data['IdPublication'];
        $articleCopy->m_data['NrIssue'] = $this->m_data['NrIssue'];
        $articleCopy->m_data['NrSection'] = $this->m_data['NrSection'];
        $articleCopy->m_data['IdLanguage'] = $p_languageId;
        $articleCopy->m_data['Number'] = $this->m_data['Number'];
        $values = array();
        // Copy some attributes
        $values['ShortName'] = $this->m_data['ShortName'];
        $values['Type'] = $this->m_data['Type'];
        $values['OnFrontPage'] = $this->m_data['OnFrontPage'];
        $values['OnSection'] = $this->m_data['OnFrontPage'];
        $values['Public'] = $this->m_data['Public'];
        $values['ArticleOrder'] = $this->m_data['ArticleOrder'];
        $values['comments_enabled'] = $this->m_data['comments_enabled'];
        $values['comments_locked'] = $this->m_data['comments_locked'];
        // Change some attributes
        $values['Name'] = $p_name;
        $values['Published'] = 'N';
        $values['IsIndexed'] = 'N';
        $values['LockUser'] = 0;
        $values['LockTime'] = 0;
        $values['IdUser'] = $p_userId;

        // Create the record
        $success = $articleCopy->__create($values);
        if (!$success) {
            return false;
        }

        $articleCopy->setProperty('UploadDate', 'NOW()', true, true);

        // Insert an entry into the article type table.
        $articleCopyData = new ArticleData($articleCopy->m_data['Type'],
            $articleCopy->m_data['Number'], $articleCopy->m_data['IdLanguage']);
        $articleCopyData->create();

        $origArticleData = $this->getArticleData();
        $origArticleData->copyToExistingRecord($articleCopy->getArticleNumber(), $p_languageId);

        if (function_exists("camp_load_translation_strings")) {
            camp_load_translation_strings("api");
        }
        $logtext = getGS('Article translated to "$4" ($5)',
            $articleCopy->getTitle(), $articleCopy->getLanguageName());
        Log::ArticleMessage($this, $logtext, null, 31);

        // geo-map processing
        Geo_Map::OnCreateTranslation($this->m_data['Number'], $this->m_data['IdLanguage'], $p_languageId);

        return $articleCopy;
    } // fn createTranslation
Example #3
0
    } 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.
// If not, dont change it.
if (preg_match("/\\d{4}-\\d{2}-\\d{2}/", $f_publish_date)) {
    $articleObj->setPublishDate($f_publish_date);
}
foreach ($articleFields as $dbColumnName => $text) {
    $articleTypeObj->setProperty($dbColumnName, $text);
}
Log::ArticleMessage($articleObj, $translator->trans('Content edited', array(), 'articles'), $g_user->getUserId(), 37);
ArticleIndex::RunIndexer(3, 10, true);
Example #4
0
 /**
  * Create a copy of the article, but make it a translation
  * of the current one.
  *
  * @param  int     $p_languageId
  * @param  int     $p_userId
  * @param  string  $p_name
  * @return Article
  */
 public function createTranslation($p_languageId, $p_userId, $p_name)
 {
     $translator = \Zend_Registry::get('container')->getService('translator');
     // Construct the duplicate article object.
     $articleCopy = new Article();
     $articleCopy->m_data['IdPublication'] = $this->m_data['IdPublication'];
     $articleCopy->m_data['NrIssue'] = $this->m_data['NrIssue'];
     $articleCopy->m_data['NrSection'] = $this->m_data['NrSection'];
     $articleCopy->m_data['IdLanguage'] = $p_languageId;
     $articleCopy->m_data['Number'] = $this->m_data['Number'];
     $values = array();
     // Copy some attributes
     $values['ShortName'] = $this->m_data['ShortName'];
     $values['Type'] = $this->m_data['Type'];
     $values['OnFrontPage'] = $this->m_data['OnFrontPage'];
     $values['OnSection'] = $this->m_data['OnFrontPage'];
     $values['Public'] = $this->m_data['Public'];
     $values['ArticleOrder'] = $this->m_data['ArticleOrder'];
     $values['comments_enabled'] = $this->m_data['comments_enabled'];
     $values['comments_locked'] = $this->m_data['comments_locked'];
     $values['rating_enabled'] = $this->m_data['rating_enabled'];
     // Change some attributes
     $values['Name'] = $p_name;
     $values['Published'] = 'N';
     $values['IsIndexed'] = 'N';
     $values['IdUser'] = $p_userId;
     // Create the record
     $success = $articleCopy->__create($values);
     if (!$success) {
         return false;
     }
     $articleCopy->setProperty('UploadDate', 'NOW()', true, true);
     $articleCopy->setProperty('LockUser', 'NULL', true, true);
     $articleCopy->setProperty('LockTime', 'NULL', true, true);
     // Insert an entry into the article type table.
     $articleCopyData = new ArticleData($articleCopy->m_data['Type'], $articleCopy->m_data['Number'], $articleCopy->m_data['IdLanguage']);
     $articleCopyData->create();
     $origArticleData = $this->getArticleData();
     $origArticleData->copyToExistingRecord($articleCopy->getArticleNumber(), $p_languageId);
     $logtext = $translator->trans('Article translated to $4 ($5)', array('$4' => $articleCopy->getTitle(), '$5' => $articleCopy->getLanguageName()), 'api');
     Log::ArticleMessage($this, $logtext, null, 31);
     // geo-map processing
     Geo_Map::OnCreateTranslation($this->m_data['Number'], $this->m_data['IdLanguage'], $p_languageId);
     return $articleCopy;
 }
Example #5
0
 /**
  * Publish text item
  *
  * @param Newscoop\News\NewsItem $item
  * @return Article
  */
 private function publishText(NewsItem $item)
 {
     $issueNumber = $this->settings->getPublicationId() ? \Issue::GetCurrentIssue($this->settings->getPublicationId())->getIssueNumber() : null;
     $type = $this->getArticleType($this->settings->getArticleTypeName());
     $article = new \Article($this->findLanguageId($item->getContentMeta()->getLanguage()));
     $article->create($type->getTypeName(), $item->getContentMeta()->getHeadline(), $this->settings->getPublicationId(), $issueNumber, $this->settings->getSectionNumber());
     $article->setKeywords($item->getContentMeta()->getSlugline());
     $article->setCreationDate($item->getItemMeta()->getFirstCreated()->format(self::DATE_FORMAT));
     $article->setPublishDate(null);
     $article->setProperty('time_updated', date_create('now')->format(self::DATE_FORMAT));
     $this->setArticleData($article, $item);
     $article->commit();
     return $article;
 }
Example #6
0
<?php

/**
 * @package Campsite
 *
 * @author Petr Jasek <*****@*****.**>
 * @copyright 2010 Sourcefabric o.p.s.
 * @license http://www.gnu.org/licenses/gpl.txt
 * @link http://www.sourcefabric.org
 */
require_once $GLOBALS['g_campsiteDir'] . "/{$ADMIN_DIR}/articles/article_common.php";
$article = new Article();
foreach ($f_order as $order => $item) {
    list($prefix, $articleId) = explode('_', $item);
    $article->Article($f_language, $articleId);
    $article->setProperty('ArticleOrder', $order + 1);
}
return TRUE;
Example #7
0
 /**
  * Set article dates
  *
  * @param Article $article
  * @param Newscoop\Entity\Ingest\Feed\Entry $entry
  * @return void
  */
 private function setArticleDates(\Article $article, Entry $entry)
 {
     $entry->setPublished(new \DateTime());
     $article->setCreationDate($entry->getCreated()->format(self::DATETIME_FORMAT));
     $article->setPublishDate($entry->getPublished()->format(self::DATETIME_FORMAT));
     $article->setProperty('time_updated', $entry->getUpdated()->format(self::DATETIME_FORMAT));
 }