Beispiel #1
0
 public function action_post()
 {
     $article_id = $this->request->param('id');
     $article = new Model_Article($article_id);
     $article->values($_POST);
     // populate $article object from $_POST array
     $article->save();
     // saves article to database
     $this->redirect('article');
     // redirects to article page after saving
 }
Beispiel #2
0
 /**
  * 显示文章信息
  */
 public function detail()
 {
     if (!empty($_GET['url'])) {
         $start = strrpos($_GET['url'], '/');
         if (false === $start) {
             $start = -1;
         }
         if (false === strpos($_GET['url'], '.html')) {
             $str = substr($_GET['url'], $start + 1);
         } else {
             $str = substr($_GET['url'], $start + 1, -5);
         }
         $_GET['id'] = $id = UMath::idDecrypt($str);
     }
     if (empty($_GET['id']) || !ctype_digit($_GET['id'])) {
         $this->header404();
         exit;
     } else {
         $id = $_GET['id'];
     }
     $mo = new Model_Article();
     if (!$detail) {
         $this->header404();
         exit;
     }
     // 有跳转链接,直接跳转到目标网址
     if ($detail['redirect']) {
         header('Location:' . $detail['redirect']);
         exit;
     }
     if ($detail['html_file']) {
         if (!empty($_GET['make_html']) && is_file($htmlFile = $mo->getHtmlFile($id, $detail['html_file']))) {
             $htmlUrl = str_replace(WEB_PATH, '/', $htmlFile);
             header('Location:' . $htmlUrl);
             exit;
         } else {
             $_GET['make_html'] = true;
         }
     } else {
         $_GET['make_html'] = true;
         $detail['html_file'] = UMath::idCrypt($id);
         $data = array('id' => $id, 'html_file' => $detail['html_file']);
         $mo->save($data);
     }
     $this->detail = $detail;
     $_GET['make_html'] = true;
     $_GET['html_display'] = false;
     $_GET['html_file'] = $mo->getHtmlFile($id, $detail['html_file']);
     $htmlUrl = str_replace(WEB_PATH, '/', $_GET['html_file']);
     $this->display();
     header('Location:' . $htmlUrl);
     return false;
 }
Beispiel #3
0
 /**
  * 添加/修改文章
  */
 public function save()
 {
     if (!empty($_POST['id']) && !ctype_digit($_POST['id'])) {
         $this->failure(Core::getLang('invalid_request'));
     }
     // 如果有文件上传
     if ($_FILES['title_image']['error'] != UPLOAD_ERR_NO_FILE) {
         $options = array('type' => 'image', 'max_size' => 1024000, 'save_path' => IMG_PATH . 'article/', 'save_rule' => '##Ymd/');
         $upload = new UploadFile($options);
         // 上传错误提示错误信息
         if (!$upload->upload()) {
             $this->failure($upload->error());
         } else {
             // 上传成功 获取上传文件信息
             $_POST['title_image'] = $upload->fileList['title_image']['savename'];
         }
     } else {
         $_POST['title_image'] = '';
     }
     $_POST['editor_uid'] = $_SESSION['uid'];
     $_POST['editor'] = $_SESSION['username'];
     $_POST['post_time'] = strtotime($_POST['post_time']);
     // 		if (!isset($_POST['brief'])) {
     // 			$_POST['brief'] = '';
     // 		}
     // 		$_POST['content'] = '';
     $mo = new Model_Article();
     if ($mo->save($_POST)) {
         $this->success(Core::getLang('handle_success'), 'admin.php?a=article');
     } else {
         if ($mo->msg) {
             $msg = $mo->msg;
         } else {
             $msg = Core::getLang('save_article_data_fail');
         }
         $this->failure($msg);
     }
 }
Beispiel #4
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;
 }