Example #1
0
 public function actionIndex()
 {
     $type = intval($this->get("type", 1));
     $type = in_array($type, [1, 2, 3]) ? $type : 1;
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $data = [];
     $pagesize = 10;
     $offset = ($p - 1) * $pagesize;
     $query = Posts::find()->where(['status' => 1]);
     switch ($type) {
         case 2:
             $query->orderBy(['view_count' => SORT_DESC]);
             break;
         case 3:
             $query->andWhere(['original' => 1]);
             $query->orderBy(['id' => SORT_DESC]);
             break;
         default:
             $query->orderBy(['id' => SORT_DESC]);
             break;
     }
     $total_count = $query->count();
     $posts_info = $query->offset($offset)->limit($pagesize)->all();
     if ($posts_info) {
         $idx = 1;
         $author = Yii::$app->params['author'];
         foreach ($posts_info as $_post) {
             $tmp_content = UtilHelper::blog_summary($_post['content'], 105);
             $tags = explode(",", $_post['tags']);
             $data[] = ['idx' => $idx, 'id' => $_post['id'], 'title' => DataHelper::encode($_post['title']), 'content' => nl2br($tmp_content), 'original' => $_post['original'], 'view_count' => $_post['view_count'], 'author' => $author, 'tags' => $tags, 'date' => date("Y.m.d", strtotime($_post['updated_time'])), 'view_url' => UrlService::buildUrl("/default/info", ["id" => $_post['id']])];
         }
     }
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $pagesize, "page" => $p, "display" => 5]);
     $tags = CacheHelperService::getFrontCache("tag");
     return $this->render("index", ["data" => $data, "page_info" => $page_info, "type" => $type, "hot_kws" => array_slice($tags, 0, 5)]);
 }
Example #2
0
<?php

use common\service\CacheHelperService;
use common\service\GlobalUrlService;
use blog\components\UrlService;
$wx_urls = ["my" => GlobalUrlService::buildStaticUrl("/images/weixin/my.jpg"), "imguowei" => GlobalUrlService::buildStaticUrl("/images/weixin/imguowei_888.jpg"), "starzone" => GlobalUrlService::buildStaticUrl("/images/weixin/mystarzone.jpg")];
$tags = CacheHelperService::getFrontCache("tag");
?>
<aside class="col-md-4 sidebar">
    <div class="widget hide">
        <h4 class="title">搜索</h4>
        <div class="content search">
            <div class="input-group">
                <input type="text" class="form-control" id="kw"/>
                <span class="input-group-btn">
                    <button class="btn btn-default do-search" type="button" style="padding: 6px 12px;">搜索</button>
                </span>
            </div>
        </div>
    </div>
    <div class="widget hidden content_index_wrap">
        <h4 class="title">目录</h4>
        <div class="content">

        </div>
    </div>
    <div class="widget">
        <h4 class="title">智能推荐</h4>
        <div class="content recommend_posts">
                <?php 
foreach ($recommend_blogs as $_recommend_blog_info) {
Example #3
0
 public function actionSet()
 {
     $request = Yii::$app->request;
     if ($request->isGet) {
         $id = trim($this->get("id", 0));
         $info = [];
         if ($id) {
             $post_info = Posts::findOne(['id' => $id]);
             if ($post_info) {
                 $domains = Yii::$app->params['domains'];
                 $info = ["id" => $post_info['id'], "title" => DataHelper::encode($post_info['title']), "content" => DataHelper::encode($post_info['content']), "type" => $post_info['type'], "status" => $post_info['status'], "original" => $post_info['original'], "tags" => DataHelper::encode($post_info['tags']), 'view_url' => $domains['blog'] . Url::toRoute("/default/{$post_info['id']}")];
             }
         }
         //set or add
         return $this->render("set", ["info" => $info, "posts_type" => Constant::$posts_type, "status_desc" => Constant::$status_desc, "original_desc" => Constant::$original_desc]);
     }
     $uid = $this->current_user->uid;
     $id = trim($this->post("id", 0));
     $title = trim($this->post("title"));
     $content = trim($this->post("content"));
     $tags = trim($this->post("tags"));
     $type = trim($this->post("type"));
     $status = trim($this->post("status", 0));
     $original = trim($this->post("original", 0));
     if (mb_strlen($title, "utf-8") <= 0 || mb_strlen($title, "utf-8") > 100) {
         return $this->renderJSON([], "请输入博文标题并且少于100个字符", -1);
     }
     if (mb_strlen($content, "utf-8") <= 0) {
         return $this->renderJSON([], "请输入更多点博文内容", -1);
     }
     if (mb_strlen($tags, "utf-8") <= 0) {
         return $this->renderJSON([], "请输入博文tags", -1);
     }
     if (intval($type) <= 0) {
         return $this->renderJSON([], "请选择类型", -1);
     }
     $date_now = date("Y-m-d H:i:s");
     if ($id) {
         $model_posts = Posts::findOne(['id' => $id]);
     } else {
         $model_posts = new Posts();
         $model_posts->uid = $uid;
         $model_posts->created_time = $date_now;
     }
     $tags_arr = [];
     $tags = explode(",", $tags);
     if ($tags) {
         foreach ($tags as $_tag) {
             if (!in_array($_tag, $tags_arr)) {
                 $tags_arr[] = $_tag;
             }
         }
     }
     preg_match('/<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\\")(.*?)\\1[^>]*?\\/?\\s*>/i', $content, $match_img);
     if ($match_img && count($match_img) == 3) {
         $model_posts->image_url = $match_img[2];
     } else {
         $model_posts->image_url = "";
     }
     $model_posts->title = $title;
     $model_posts->content = $content;
     $model_posts->type = $type;
     $model_posts->original = $original;
     $model_posts->status = $status;
     $model_posts->tags = $tags_arr ? implode(",", $tags_arr) : "";
     $model_posts->updated_time = $date_now;
     $model_posts->save(0);
     $post_id = $model_posts->id;
     BlogService::buildTags($post_id);
     CacheHelperService::buildFront(true);
     if ($status == 1) {
         //只有在线的才进入同步队列
         SyncBlogService::addQueue($post_id);
         RecommendService::addQueue($post_id);
     }
     return $this->renderJSON(['post_id' => $post_id], "博文发布成功");
 }
Example #4
0
<?php

use common\service\CacheHelperService;
use common\service\GlobalUrlService;
$data = CacheHelperService::getFrontCache();
$tags = $data['tag'];
$post_hot = array_slice($data['post_hot'], 0, 5);
$post_latest = array_slice($data['post_latest'], 0, 5);
?>
<footer class="main-footer">
    <div class="container">
        <div class="row">
            <div class="col-sm-4">
                <div class="widget">
                    <h4 class="title">热门文章</h4>
                    <div class="content recent-post hots-post">
                        <?php 
if ($post_hot) {
    ?>
                            <?php 
    foreach ($post_hot as $_post_info) {
        ?>
                                <div class="recent-single-post">
                                    <a href="<?php 
        echo $_post_info['detail_url'];
        ?>
" class="post-title">
                                        <?php 
        echo $_post_info['title'];
        ?>
                                    </a>