Example #1
0
 private function saveArticle(Model_Article $article, View_Html $view)
 {
     if (isset($_REQUEST['save'])) {
         foreach (array("published", "archived") as $name) {
             $_POST[$name] = Filter_Date::fromString($_POST[$name]);
         }
         if (!isset($_POST['flags'])) {
             $_POST['flags'] = array();
         }
         $article->setData($_POST);
         if (!($errors = $article->validate())) {
             $article->save();
             $article->getRights()->setRights($_POST['rights'], $_POST['owner'], $_POST['group'])->save();
             $article->dropTags();
             $tags = isset($_POST['tag']) ? $_POST['tag'] : (isset($_POST['tags']) ? explode(", ", $_POST['tags']) : null);
             Model_Tag::setAutoCreate();
             if ($tags) {
                 $article->addTags($tags);
             }
             if ($_FILES && $_FILES["attach"]) {
                 $store = $this->getStorage();
                 foreach ($_FILES["attach"]["name"] as $index => $name) {
                     $attachment = new Model_Attachment($store);
                     $file = array('name' => $name, 'tmp_name' => $_FILES['attach']['tmp_name'][$index], 'error' => $_FILES['attach']['error'][$index], 'size' => $_FILES['attach']['size'][$index], 'type' => $_FILES['attach']['type'][$index]);
                     if ($attachment->uploadFile($file)) {
                         $attachment->attachTo($article);
                         $attachment->save();
                     }
                 }
             }
             $view->redir('Admin_Topic', 'default', array('id' => $article->topic));
             return true;
         }
         $view->errors = $errors;
     }
     return false;
 }