Ejemplo n.º 1
0
 /**
  * @before _secured, _admin
  */
 public function add()
 {
     $view = $this->getActionView();
     $view->set('submstoken', $this->mutliSubmissionProtectionToken());
     if (RequestMethods::post('submitAddNews')) {
         if ($this->checkCSRFToken() !== true && $this->checkMutliSubmissionProtectionToken(RequestMethods::post('submstoken')) !== true) {
             self::redirect('/admin/news/');
         }
         $errors = array();
         $urlKey = $this->_createUrlKey(RequestMethods::post('title'));
         if (!$this->_checkUrlKey($urlKey)) {
             $errors['title'] = array('This title is already used');
         }
         $shortText = str_replace(array('(!read_more_link!)', '(!read_more_title!)'), array('/aktuality/r/' . $urlKey, '[Celý článek]'), RequestMethods::post('shorttext'));
         $news = new App_Model_News(array('title' => RequestMethods::post('title'), 'author' => RequestMethods::post('author', $this->getUser()->getWholeName()), 'urlKey' => $urlKey, 'shortBody' => $shortText, 'body' => RequestMethods::post('text'), 'expirationDate' => RequestMethods::post('expiration'), 'rank' => RequestMethods::post('rank', 1), 'metaTitle' => RequestMethods::post('metatitle', RequestMethods::post('title')), 'metaDescription' => RequestMethods::post('metadescription'), 'metaImage' => ''));
         if (empty($errors) && $news->validate()) {
             $id = $news->save();
             Event::fire('admin.log', array('success', 'News id: ' . $id));
             $view->successMessage('News' . self::SUCCESS_MESSAGE_1);
             self::redirect('/admin/news/');
         } else {
             Event::fire('admin.log', array('fail'));
             $view->set('errors', $errors + $news->getErrors())->set('submstoken', $this->revalidateMutliSubmissionProtectionToken())->set('news', $news);
         }
     }
 }