private function getArticle($number, $language, $user)
 {
     $em = $this->container->get('em');
     $languageObject = $em->getRepository('Newscoop\\Entity\\Language')->findOneByCode($language);
     // Fetch article
     $articleObj = new \Article($languageObject->getId(), $number);
     if (!$articleObj->exists()) {
         throw new NewscoopException('Article does not exist');
     }
     if (!$articleObj->userCanModify($user)) {
         throw new AccessDeniedException('User cannot modify article.');
     }
     // Only users with a lock on the article can change it.
     if ($articleObj->isLocked() && $user->getUserId() != $articleObj->getLockedByUser()) {
         $lockTime = new \DateTime($articleObj->getLockTime());
         $now = new \DateTime('now');
         $difference = $now->diff($lockTime);
         $ago = $difference->format('%R%H:%I:%S');
         $lockUser = new \User($articleObj->getLockedByUser());
         throw new NewscoopException(sprintf('Article locked by %s (%s ago)', $lockUser->getRealName(), $ago));
     }
     return $articleObj;
 }
Example #2
0
if ($showComments) {
    //    $comments = array();
    /**
     * @todoget comments
     */
}
// Automatically switch to "view" mode if user doesnt have permissions
if (!$articleObj->userCanModify($g_user)) {
    $f_edit_mode = 'view';
}
//
// Automatic unlocking
//
$locked = TRUE;
// If the article has not been touched in 24 hours
$timeDiff = camp_time_diff_str($articleObj->getLockTime());
if ($timeDiff['days'] > 0) {
    $articleObj->setIsLocked(FALSE);
    $locked = FALSE;
} elseif ($articleObj->getLockedByUser() != 0 && !$lockUserObj->exists()) {
    // If the user who locked the article doesnt exist anymore, unlock the article
    $articleObj->setIsLocked(FALSE);
    $locked = FALSE;
}
//
// Automatic locking
//
// If the article has not been unlocked and is not locked by a user.
if ($f_unlock === FALSE) {
    if (!$articleObj->isLocked()) {
        // Lock the article
Example #3
0
    } else {
        unset($articleFields[$dbColumn->getName()]);
        // ignore if not set
    }
}
if (!empty($f_message)) {
    camp_html_add_msg($f_message, "ok");
}
if (!$articleObj->userCanModify($g_user)) {
    camp_html_add_msg($translator->trans("You do not have the right to change this article.  You may only edit your own articles and once submitted an article can only be changed by authorized users.", array(), 'articles'));
    camp_html_goto_page($BackLink);
    exit;
}
// Only users with a lock on the article can change it.
if ($articleObj->isLocked() && $g_user->getUserId() != $articleObj->getLockedByUser()) {
    $diffSeconds = time() - strtotime($articleObj->getLockTime());
    $hours = floor($diffSeconds / 3600);
    $diffSeconds -= $hours * 3600;
    $minutes = floor($diffSeconds / 60);
    $lockUser = new User($articleObj->getLockedByUser());
    camp_html_add_msg($translator->trans('Could not save the article. It has been locked by $1 $2 hours and $3 minutes ago.', array('$1' => $lockUser->getRealName(), '$2' => $hours, '$3' => $minutes), 'articles'));
    camp_html_goto_page($BackLink);
    exit;
}
// Update the article author
$blogService = Zend_Registry::get('container')->getService('blog');
$blogInfo = $blogService->getBlogInfo($g_user);
if (!empty($f_article_author)) {
    $em = Zend_Registry::get('container')->getService('em');
    $dispatcher = Zend_Registry::get('container')->getService('dispatcher');
    $language = $em->getRepository('Newscoop\\Entity\\Language')->findOneById($articleObj->getLanguageId());
Example #4
0
 /**
  * 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);
 }