Пример #1
0
 public static function getTotal()
 {
     $tablename = Record::tableFromClass('Article');
     $sql = "SELECT COUNT(id) AS total FROM {$tablename} WHERE type='post'";
     self::$__CONN__->query($sql);
     return self::$__CONN__->last_result[0]->total;
 }
Пример #2
0
 public function createAction()
 {
     global $tpl;
     set_time_limit(100);
     //删除data/chache目录
     $path = DATA_DIR . 'cache/';
     //缓存目录
     if ($handle = opendir($path)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 //$files[] = $file;
                 @unlink($path . $file);
             }
         }
         closedir($handle);
     }
     //删除首页
     del_cache();
     //文章
     $total = Cache::getTotal();
     $start = 0;
     $limit = 20;
     $start_id = 0;
     $i = 0;
     $tablename_content = Record::tableFromClass('Article');
     $tablename_contentpart = Record::tableFromClass('ContentPart');
     $previous = null;
     while ($i < $total) {
         $sql = "select * from {$tablename_content} where type='post' and id > {$start_id} order by id asc limit {$limit}";
         Record::$__CONN__->query($sql);
         $articles = array();
         $articles = Record::$__CONN__->last_result;
         if (is_array($articles) && count($articles) > 0) {
             foreach ($articles as $k => $data) {
                 $article = new Article(get_object_vars($data));
                 //上一页
                 $previous = isset($previous) ? $previous : '';
                 $tpl->assign('previous', $previous);
                 $previous = $article;
                 //下一页
                 if (isset($articles[$k + 1])) {
                     //$next = new Article(get_object_vars($articles[$k+1]));
                     $next = $articles[$k + 1];
                 } else {
                     $next = $article->next();
                 }
                 $tpl->assign('next', $next);
                 $content_part = ContentPart::findById($article->id);
                 $article->content = processContent($content_part->content);
                 $article->tags = isset($this->cahce_tags[$article->id]) ? $this->cahce_tags[$article->id] : array();
                 $article->category = isset($this->cahce_categories[$article->cid]) ? $this->cahce_categories[$article->cid]['name'] : '无分类';
                 $article->category_slug = isset($this->cahce_categories[$article->cid]) ? $this->cahce_categories[$article->cid]['slug'] : 'uncategory';
                 $this->createHtml($article);
                 if ($k == $limit - 1) {
                     $start_id = $article->id;
                 }
             }
         }
         $i += $limit;
     }
     //while
     flush();
     echo 'create cache over!';
     echo '<a href="index.php">Index</a>';
 }
Пример #3
0
 /**
  * 批量移动文章
  * @param <type> $args
  */
 public function batch_moveAction($args = null)
 {
     //move update cid
     $post_checked = isset($_POST['checked']) ? $_POST['checked'] : null;
     $newcid = isset($_POST['newcid']) ? $_POST['newcid'] : null;
     if (is_array($post_checked) && count($post_checked) > 0) {
         $id_arr = array();
         foreach ($post_checked as $val) {
             $data = unserialize(base64_decode($val));
             if ($data->cid != $newcid) {
                 $id_arr[] = $data->id;
                 //更新分类统计
                 //                    $c2 = new Category('id', $data->cid);
                 //                    $c2->count--;
                 //                    $c2->save();
                 $tablename = Record::tableFromClass('Category');
                 $sql = "UPDATE {$tablename} SET count=count-1 WHERE id = '{$data->cid}'";
                 Record::$__CONN__->query($sql);
             }
         }
         //sql
         Article::moveIds($id_arr, $newcid);
     }
     //更新文章分类统计
     $c1 = new Category('id', $newcid);
     $c1->count = $c1->count + count($id_arr);
     $c1->save();
     del_cache();
     go_redirect('index.php?job=admin_article');
 }