/** * Artikel parsen * @return string */ protected function assignArticleData() { $categoryTexts = array(); $categoryIcons = array(); $categories = $this->categoryList->getCategoriesAll(); foreach ($this->article->getCategories() as $categoryId) { $category = isset($categories[$categoryId]) ? $categories[$categoryId] : false; if (!$category) { continue; } $categoryTexts[] = '<span class="fpcm-pub-category-text">' . $category->getName() . '</span>'; if (!$category->getIconPath()) { continue; } $categoryIcons[] = '<img src="' . $category->getIconPath() . '" alt="' . $category->getName() . '" title="' . $category->getName() . '" class="fpcm-pub-category-icon">'; } $shareButtonParser = new \fpcm\model\pubtemplates\sharebuttons($this->article->getArticleLink(), $this->article->getTitle()); $users = $this->userList->getUsersByIds(array($this->article->getCreateuser(), $this->article->getChangeuser())); $commentCounts = $this->commentList->countComments(array($this->article->getId()), 0, 1, 0); $commentCount = $this->config->system_comments_enabled && $this->article->getComments() ? isset($commentCounts[$this->article->getId()]) ? (int) $commentCounts[$this->article->getId()] : 0 : ''; $this->articleTemplate->setCommentsEnabled($this->config->system_comments_enabled && $this->article->getComments()); if (isset($users[$this->article->getCreateuser()])) { $emailAddress = '<a href="mailto:' . $users[$this->article->getCreateuser()]->getEmail() . '">' . $users[$this->article->getCreateuser()]->getDisplayname() . '</a>'; } else { $emailAddress = ''; } $replacements = array('{{headline}}' => $this->article->getTitle(), '{{text}}' => $this->article->getContent(), '{{author}}' => isset($users[$this->article->getCreateuser()]) ? $users[$this->article->getCreateuser()]->getDisplayname() : $this->lang->translate('GLOBAL_NOTFOUND'), '{{authorEmail}}' => $emailAddress, '{{date}}' => date($this->config->system_dtmask, $this->article->getCreatetime()), '{{changeDate}}' => date($this->config->system_dtmask, $this->article->getChangetime()), '{{changeUser}}' => isset($users[$this->article->getChangeuser()]) ? $users[$this->article->getChangeuser()]->getDisplayname() : $this->lang->translate('GLOBAL_NOTFOUND'), '{{statusPinned}}' => $this->article->getPinned() ? $this->lang->translate('PUBLIC_ARTICLE_PINNED') : '', '{{shareButtons}}' => $shareButtonParser->parse(), '{{categoryIcons}}' => implode(PHP_EOL, $categoryIcons), '{{categoryTexts}}' => implode(PHP_EOL, $categoryTexts), '{{commentCount}}' => $commentCount, '{{permaLink}}:{{/permaLink}}' => $this->article->getArticleLink(), '{{commentLink}}:{{/commentLink}}' => $this->article->getArticleLink() . '#comments', '<readmore>:</readmore>' => $this->article->getMd5path(), '{{articleImage}}' => $this->article->getArticleImage(), '{{sources}}' => $this->article->getSources()); $this->articleTemplate->setReplacementTags($replacements); $parsed = $this->articleTemplate->parse(); if ($this->session->exists()) { $html = array(); $html[] = '<div class="fpcm-pub-articletoolbar-article fpcm-pub-articletoolbar-article' . $this->articleId . '">'; $html[] = '<a href="' . $this->article->getEditLink() . '">' . $this->lang->translate('HL_ARTICLE_EDIT') . '</a>'; $html[] = '</div>'; $parsed = implode(PHP_EOL, $html) . $parsed; } return $parsed; }
/** * @see \fpcm\controller\abstracts\controller::request() * @return boolean */ public function request() { if (is_null($this->getRequestVar('articleid'))) { $this->redirect('articles/list'); } $this->article = new \fpcm\model\articles\article($this->getRequestVar('articleid')); if (!$this->article->exists()) { $this->view->setNotFound('LOAD_FAILED_ARTICLE', 'articles/list'); return true; } if (!$this->article->getEditPermission()) { $this->view = new \fpcm\model\view\error(); $this->view->addErrorMessage('PERMISSIONS_REQUIRED'); $this->view->render(); return false; } if ($this->getRequestVar('revrestore')) { $this->view->addNoticeMessage('SAVE_SUCCESS_ARTICLEREVRESTORE'); } $this->checkPageToken = $this->checkPageToken(); if ($this->buttonClicked('doAction') && !$this->checkPageToken) { $this->view->addErrorMessage('CSRF_INVALID'); } $revisionIdsArray = !is_null($this->getRequestVar('revisionIds')) ? array_map('intval', $this->getRequestVar('revisionIds')) : false; if ($this->buttonClicked('revisionDelete') && $revisionIdsArray && !$this->showRevision && $this->checkPageToken) { if ($this->article->deleteRevisions($revisionIdsArray)) { $this->view->addNoticeMessage('DELETE_SUCCESS_REVISIONS'); } else { $this->view->addErrorMessage('DELETE_FAILED_REVISIONS'); } } $this->revisionId = !is_null($this->getRequestVar('rev')) ? (int) $this->getRequestVar('rev') : (is_array($revisionIdsArray) ? array_shift($revisionIdsArray) : false); if ($this->buttonClicked('articleRevisionRestore') && ($this->getRequestVar('rev') || $this->getRequestVar('revisionIds')) && $this->checkPageToken) { if ($this->revisionId && $this->article->restoreRevision($this->revisionId)) { $this->redirect('articles/edit&articleid=' . $this->article->getId() . '&revrestore=1'); } else { $this->view->addErrorMessage('SAVE_FAILED_ARTICLEREVRESTORE'); } } if ($this->revisionId) { include_once \fpcm\classes\loader::libGetFilePath('PHP-FineDiff', 'finediff.php'); $this->currentArticle = clone $this->article; if (!$this->revisionId) { $this->revisionId = (int) $this->getRequestVar('rev'); } $this->showRevision = $this->article->getRevision($this->revisionId) ? true : false; $from = $this->currentArticle->getContent(); $to = $this->article->getContent(); $opcode = \FineDiff::getDiffOpcodes($from, $to, \FineDiff::$sentenceGranularity); $this->view->assign('textFrom', \FineDiff::renderDiffToHTMLFromOpcodes($from, $opcode)); $this->view->assign('textTo', \FineDiff::renderDiffToHTMLFromOpcodes($to, $opcode)); } if ($this->buttonClicked('articleDelete') && !$this->showRevision && $this->checkPageToken) { if ($this->article->delete()) { $this->redirect('articles/listall'); } else { $this->view->addErrorMessage('DELETE_FAILED_ARTICLE'); } } $res = false; $allTimer = time(); if ($this->buttonClicked('articleSave') && !$this->showRevision && $this->checkPageToken) { $this->article->prepareRevision(); $data = $this->getRequestVar('article', array(4, 7)); $this->article->setTitle($data['title']); $this->article->setContent($data['content']); $cats = $this->categoryList->getCategoriesCurrentUser(); $categories = isset($data['categories']) ? array_map('intval', $data['categories']) : array(array_shift($cats)->getId()); $this->article->setCategories($categories); if (isset($data['postponed']) && !isset($data['archived'])) { $timer = strtotime($data['postponedate'] . ' ' . (int) $data['postponehour'] . ':' . (int) $data['postponeminute'] . ':00'); $postpone = 1; if ($timer === false) { $timer = $allTimer; $postpone = 0; } $this->article->setPostponed($postpone); $this->article->setCreatetime($timer); } else { if ($this->article->getPostponed() || $this->article->getDraft() && !isset($data['draft'])) { $this->article->setCreatetime($allTimer); } $this->article->setPostponed(0); } $this->article->setPinned(isset($data['pinned']) ? 1 : 0); $this->article->setDraft(isset($data['draft']) ? 1 : 0); $this->article->setComments(isset($data['comments']) ? 1 : 0); $this->article->setApproval($this->permissions->check(array('article' => 'approve')) ? 1 : 0); $this->article->setImagepath(isset($data['imagepath']) ? $data['imagepath'] : ''); $this->article->setSources(isset($data['sources']) ? $data['sources'] : ''); if (isset($data['archived'])) { $this->article->setArchived(1); $this->article->setPinned(0); $this->article->setDraft(0); } else { $this->article->setArchived(0); } if (!$this->article->getTitle() || !$this->article->getContent()) { $this->view->addErrorMessage('SAVE_FAILED_ARTICLE_EMPTY'); return true; } if (isset($data['author']) && trim($data['author'])) { $this->article->setCreateuser($data['author']); } if (isset($data['tweettxt']) && $data['tweettxt']) { $this->article->setTweetOverride($data['tweettxt']); } $this->article->setChangetime($allTimer); $this->article->setChangeuser($this->session->getUserId()); $this->article->setMd5path($this->article->getArticleNicePath()); $this->article->prepareDataSave(); $saved = true; $res = $this->article->update(); if ($res) { $this->article->createRevision(); } } $this->handleCommentActions(); if ($res || $this->getRequestVar('added') == 1) { $this->view->addNoticeMessage('SAVE_SUCCESS_ARTICLE'); } elseif ($this->getRequestVar('added') == 2) { $this->view->addNoticeMessage('SAVE_SUCCESS_ARTICLE_APPROVAL'); } elseif (isset($saved) && !$res) { $this->view->addErrorMessage('SAVE_FAILED_ARTICLE'); } if (!$this->revisionId) { $this->article->prepareDataLoad(); } return true; }