Ejemplo n.º 1
0
 /**
  * Show a specific news article
  *
  * @return void
  */
 public function articleAction()
 {
     $articleID = $this->getRequest()->getParam('articleID');
     $news = new Datasource_Cms_News();
     $article = $news->getArticle($articleID);
     $content = $article['content'];
     // Replace code snippets in the content
     $snippets = new Application_Cms_PageSnippets();
     $content = $snippets->replace($content);
     $this->view->pageTitle = htmlentities(html_entity_decode($article['title'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
     $this->view->content = $content;
     $this->view->title = $article['title'];
     $this->view->summary = $article['summary'];
     $this->view->date = $article['niceDate'];
     $this->view->category = 'corporate';
     $this->view->articleId = intval($articleID);
 }
Ejemplo n.º 2
0
 /**
  * Save changes to an existing news article, or save a new article in the database. If a new article the function will return the ID.
  *
  * @return int
  */
 private function _saveNewsArticle()
 {
     // First of all we need to validate and sanitise the input from the form
     $requiredText = new Zend_Validate();
     $requiredText->addValidator(new Zend_Validate_NotEmpty());
     // $requiredText->addValidator(new Zend_Validate_Alnum(array('allowWhiteSpace' => true)));
     $filters = array('id' => 'Digits', 'newsTitle' => 'StringTrim', 'newsDate' => 'StringTrim', 'categoryList' => 'StringTrim');
     $validators = array('id' => array('allowEmpty' => true), 'newsTitle' => $requiredText, 'newsContent' => array('allowEmpty' => true), 'newsDate' => 'NotEmpty', 'categoryList' => array('allowEmpty' => true));
     $input = new Zend_Filter_Input($filters, $validators, $_POST);
     if ($input->isValid()) {
         // Data is all valid, formatted and sanitized so we can save it in the database
         $newsArticle = new Datasource_Cms_News();
         if (!$input->id) {
             // This is a new article so we need to create a new ID
             $newsID = $newsArticle->addNew($input->newsTitle, $input->newsDate, $input->getUnescaped('newsContent'));
         } else {
             // This is an existing article so we can just update the data
             $newsArticle->saveChanges($input->id, $input->newsTitle, $input->newsDate, $input->getUnescaped('newsContent'));
             $newsID = $input->id;
         }
         // Now we need to link the page to the categories selected
         $categoryList = $input->categoryList;
         $newsArticle->saveCategories($newsID, $categoryList);
         // Changes saved - so send them back with a nice success message
         $this->_helper->getHelper('FlashMessenger')->addMessage(array('saved' => true));
         $this->_helper->getHelper('Redirector')->goToUrl('/cms-admin/news/edit?id=' . $newsID);
     } else {
         // Invalid data in form
         print_r($_POST);
         print_r($input->getErrors());
         print_r($input->getInvalid());
     }
 }