Example #1
0
 /**
  * 创建一篇文章
  * 
  * @param int    $category_id 分类ID
  * @param string $title       标题
  * @param string $content     内容
  * 
  * @throws \Exception\Nologin
  * @throws \Exception\Msg
  * 
  * @return int
  */
 public static function create($category_id, $title, $content)
 {
     $uid = \Yaf_Registry::get('current_uid');
     $title = trim($title);
     $content = trim($content);
     //获取分类信息
     $category = Category::show($category_id);
     if (!$uid) {
         throw new \Exception\Nologin();
     }
     if (!$category || $category['uid'] && $category['uid'] != $uid) {
         throw new \Exception\Msg('指定分类不存在');
     }
     if (!$title || !$content) {
         throw new \Exception\Msg('标题和内容不能为空');
     }
     $data = array('category_id' => $category_id, 'title' => $title, 'content' => $content, 'state' => 0, 'uid' => $uid, 'create_time' => date('Y-m-d H:i:s'));
     $db = self::db();
     $db->insert($data);
     $id = $db->lastId();
     if (!$id) {
         throw new \Exception\Msg(_('文章发表失败'));
     }
     //计数器+1
     Counter\Article::incr($category_id);
     Counter\Article::incr(0);
     //发布至Github中
     $data['id'] = $id;
     Publish::article($data);
     return $id;
 }
Example #2
0
 /**
  * 发布一篇文章
  * 
  * @param array $article 文件内容
  * @param int   $publish 是否真正发布(如果为否,则仅为预览,输出至Buffer中)
  * 
  * @return array
  */
 public static function article(array $article, $publish = true)
 {
     \Model\User::validateAuth($article['uid']);
     $path = sprintf('article/%u.html', $article['id']);
     $message = sprintf('update article %u [%s]', $article['id'], date('Y-m-d H:i:s'));
     $blog = Blog::show();
     $category = Category::show($article['category_id']);
     $now = time();
     $publish_time = date('Y-m-d H:i:s', $now);
     $tpl_vars = array('blog' => $blog, 'category' => $category, 'article' => $article, 'publish' => $publish, 'publish_date' => date('Y-m-d', $now));
     $smarty = \Comm\Smarty::init();
     if ($publish) {
         $content = $smarty->render('tpl:article', $tpl_vars);
         $result = self::publishUserRespos($path, $content, $message);
         //发布成功,更新发布时间与发布状态
         try {
             Article::update($article, ['state' => 1, 'publish_time' => $publish_time]);
         } catch (\Exception $e) {
         }
     } else {
         $result = $smarty->display('tpl:article', $tpl_vars);
     }
     return $result;
 }
Example #3
0
 public function __construct()
 {
     parent::__construct();
     $this->data['kategori'] = Category::show()->fetch(false);
 }
 public function categories($do = '', $id = '')
 {
     $this->data['heading'] = 'Administrasi: Kategori';
     switch ($do) {
         case 'form':
             if (post('submit')) {
                 $data = ['nama' => post('nama'), 'alias' => post('alias'), 'keterangan' => post('keterangan')];
                 if (Category::save($data, $id)) {
                     if ($id) {
                         setAlert('success', 'Berhasil memperbarui data kategori <b>' . $data['nama'] . '</b>');
                     } else {
                         setAlert('success', 'Berhasil menambahkan kategori <b>' . $data['nama'] . '</b>');
                     }
                     return redirect('admin-shop/categories');
                 }
                 setAlert('error', 'Terjadi kesalahan dalam penyimpanan kategori <b>' . $data['nama'] . '</b>');
                 return redirect($this->uri->path());
             } else {
                 if ($id) {
                     $this->data['data'] = Category::show([Category::primary() => $id])->fetchOne();
                 }
                 return $this->render('category-form', $this->data);
             }
             break;
         case 'delete':
             if (Category::del([Category::primary() => $id])) {
                 setAlert('success', 'Kategori berhasil terhapus');
             } else {
                 setAlert('error', 'Terjadi kesalahan dalam penghapusan kategori');
             }
             return redirect('admin-shop/categories');
             break;
         default:
             $this->data['data'] = Category::show();
             return $this->render('category-table', $this->data);
             break;
     }
 }
Example #5
0
        <div class="control-group">
            <label class="label" for="nama">Nama</label>
            <div class="control-input">
                <input type="text" required name="nama" id="nama" <?php 
echo $data ? 'value="' . $data->nama . '"' : '';
?>
>
            </div>
        </div>

        <div class="control-group">
            <label class="label" for="kategori">Kategori</label>
            <div class="control-input">
                <?php 
$kategori = Category::show()->fetch(false);
?>
                <select name="kategori" required>
                    <option value="">Pilih Kategori</option>
                <?php 
if (count($kategori) > 0) {
    $katId = Category::primary();
    foreach ($kategori as $row) {
        ?>
                    <option <?php 
        echo ($data and $data->{$katId} == $row->{$katId}) ? 'selected' : '';
        ?>
 value="<?php 
        echo $row->{$katId};
        ?>
"><?php 
Example #6
0
 public function link()
 {
     $CategoryController = new Category();
     $HttpReturn = $CategoryController->show();
     $contentResult = $HttpReturn->getHttpContentResult();
     $contentResult->vo = $this->ContentSiteVO->toStdClass();
     //Debug::print_r($contentResult->vo);
     //Debug::print_r($this->ContentSiteVO->getCategoriesDad());
     return $HttpReturn;
 }