public function addAction()
 {
     global $tpl;
     //如果是分表则通过$_POST['content'], $_POST['content_part']区分
     //$data = isset($_POST['article']) ? $_POST['article'] : array();
     $data = array();
     if (isset($_POST['add']) || isset($_POST['save'])) {
         $data = $_POST['content'];
         //判断ID是否存在
         if (!$data['id']) {
             //add
             $data['slug'] = !empty($data['slug']) ? dealWords($data['slug']) : null;
             $data['created_uid'] = AuthUser::getId();
             $data['created_date'] = time();
             $article = new Article($data);
             if ($article->save()) {
                 $data_part = array();
                 $data_part = $_POST['content_part'];
                 $data_part['id'] = $article->id;
                 $content_part = new ContentPart($data_part);
                 $content_part->insert();
                 $article->content = $content_part->content;
                 //save tags
                 $article->saveTags(trim($_POST['tags']));
                 //update category
                 $category = new Category('id', $article->cid);
                 $category->count++;
                 $category->save();
                 $article->category = $category->name;
                 $article->category_slug = $category->slug;
                 //删除上一篇缓存
                 $prev = $article->previous();
                 $this->delPostHtml($prev->id);
             }
         } else {
             //update
             $data['updated_uid'] = AuthUser::getId();
             $data['updated_date'] = time();
             $old_article = new Article('id', $data['id']);
             $article = new Article($data);
             if ($article->save()) {
                 $data_part = array();
                 $data_part = $_POST['content_part'];
                 $data_part['id'] = $article->id;
                 $content_part = new ContentPart($data_part);
                 $content_part->save();
                 $article->content = $content_part->content;
                 $article->saveTags($_POST['tags']);
                 //更新文章分类统计
                 if ($old_article->cid != $article->cid) {
                     $c1 = new Category('id', $article->cid);
                     $c1->count++;
                     $c1->save();
                     $c2 = new Category('id', $old_article->cid);
                     $c2->count--;
                     $c2->save();
                 }
             }
         }
         //$_POST = array();
         $tpl->assign('article', $article);
         //生成静态页面
         $status = isset($data['status']) ? $data['status'] : 'draft';
         if ($status == 'publish') {
             $this->createPostHtml($article);
         } else {
             if ($status == 'draft') {
                 $this->delPostHtml($article->id);
             }
         }
         del_cache();
         if (isset($_POST['add'])) {
             header('location:index.php?job=admin_article');
         }
     }
     $categories = Category::findAll();
     $tpl->assign('cats', $categories);
     $tpl->display('admin/article_add.html');
 }