Beispiel #1
0
 /**
  * 获取特定cat_id分类下文章
  *
  * @param  string $cat_id 分类id
  * @param  string|null $flag 推荐位
  * @param  string $lang 内容语言版本
  * @param  int $number 数量
  * @return Illuminate\Support\Collection
  */
 public function getArticleList($cat_id = '0', $flag = null, $number = 5)
 {
     $map = [];
     if (ctype_digit($cat_id)) {
         $map['cat_id'] = $cat_id;
     } else {
         $map['cat_id'] = '0';
     }
     if ($flag !== null && is_string($flag)) {
         $map['flag'] = $flag;
     }
     if (is_numeric($number)) {
         if ($number > 10) {
             $map['number'] = 5;
         } else {
             $map['number'] = $number;
         }
     } else {
         $map['number'] = 5;
     }
     $articles = Content::article()->where('category_id', '=', $map['cat_id'])->where(function ($query) use($map) {
         if (array_key_exists('flag', $map)) {
             $query->where('flag', 'like', '%' . $map['flag'] . '%');
         }
     })->orderBy('created_at', 'desc')->take($number)->get();
     return $articles;
 }
Beispiel #2
0
 /**
  * 侦测当前元(分类|标签)是否有内容(文章|单页)在所使用
  *
  * @param  string $type 元模型类型 分类category,标签tag
  * @param  int $id
  * @return boolean 如果元被内容所使用,则返回true,否则返回false
  */
 public function hasContent($type = 'category', $id)
 {
     if ($type === 'tag') {
         return true;
     } else {
         $content = $this->content->article()->where('category_id', '=', $id)->get();
         if ($content->isEmpty()) {
             return false;
         } else {
             return true;
         }
     }
 }
Beispiel #3
0
 /**
  * 创建或更新内容
  *
  * @param  YCMS\Models\Content $content
  * @param  array $inputs
  * @param  string $type
  * @param  string|int $user_id
  * @return YCMS\Models\Content
  */
 private function saveContent($content, $inputs, $type = 'article', $user_id = '0')
 {
     $content->title = e($inputs['title']);
     $content->content = e($inputs['content']);
     $content->thumb = e($inputs['thumb']);
     if ($type === 'article') {
         $content->category_id = e($inputs['category_id']);
         $content->type = 'article';
         $tmp_flag = '';
         /*这里需要对推荐位flag进行处理*/
         if (!empty($inputs['flag']) && is_array($inputs['flag'])) {
             foreach ($inputs['flag'] as $flag) {
                 if (!empty($flag)) {
                     $tmp_flag .= $flag . ',';
                 }
             }
             $content->flag = $tmp_flag;
         }
     } elseif ($type === 'page') {
         $content->category_id = 0;
         $content->type = 'page';
     } elseif ($type === 'fragment') {
         $content->category_id = 0;
         $content->type = 'fragment';
     }
     if (array_key_exists('is_top', $inputs)) {
         $content->is_top = e($inputs['is_top']);
     }
     if (array_key_exists('outer_link', $inputs)) {
         $content->outer_link = trim(e($inputs['outer_link']));
     }
     if (array_key_exists('slug', $inputs)) {
         $content->slug = e($inputs['slug']);
     }
     if ($user_id) {
         $content->user_id = $user_id;
     }
     $content->save();
     return $content;
 }
Beispiel #4
0
 /**
  * 博客文章
  */
 public function getArticleShow($cslug, $slug)
 {
     //尝试根据分类slug来匹配
     $category = Meta::category()->where('slug', '=', $cslug)->first();
     if ($category) {
         $article = Content::article()->where('category_id', '=', $category->id)->where('slug', '=', $slug)->first();
         if ($article) {
             $title = $article->title;
             $description = Cache::get('website_title', '芽丝博客') . ' - ' . $title . ',本博客由 芽丝内容管理框架(YASCMF) 所驱动的博客,基于Laravel实现的内容管理框架,Github地址: https://github.com/douyasi/yascmf 。';
             return view('front.show', compact('article', 'category', 'title', 'description'));
         } else {
             if (ctype_digit($slug)) {
                 $article = Content::article()->where('category_id', '=', $category->id)->find($slug);
                 is_null($article) && abort(404);
                 $title = $article->title;
                 $description = Cache::get('website_title', '芽丝博客') . ' - ' . $title . ',本博客由 芽丝内容管理框架(YASCMF) 所驱动的博客,基于Laravel实现的内容管理框架,Github地址: https://github.com/douyasi/yascmf 。';
                 return view('front.show', compact('article', 'category', 'title', 'description'));
             } else {
                 abort(404);
             }
         }
     } else {
         //再次尝试移除'cat_'前缀之后来匹配
         $new_cslug = ltrim($cslug, 'cat_');
         if (ctype_digit($new_cslug)) {
             $category = Meta::category()->find($new_cslug);
             is_null($category) && abort(404);
             $article = Content::article()->where('category_id', '=', $new_cslug)->where('slug', '=', $slug)->first();
             if ($article) {
                 $title = $article->title;
                 $description = Cache::get('website_title', '芽丝博客') . ' - ' . $title . ',本博客由 芽丝内容管理框架(YASCMF) 所驱动的博客,基于Laravel实现的内容管理框架,Github地址: https://github.com/douyasi/yascmf 。';
                 return view('front.show', compact('article', 'category', 'title', 'description'));
             } else {
                 if (ctype_digit($slug)) {
                     $article = Content::article()->where('category_id', '=', $category->id)->find($slug);
                     is_null($article) && abort(404);
                     $title = $article->title;
                     $description = Cache::get('website_title', '芽丝博客') . ' - ' . $title . ',本博客由 芽丝内容管理框架(YASCMF) 所驱动的博客,基于Laravel实现的内容管理框架,Github地址: https://github.com/douyasi/yascmf 。';
                     return view('front.show', compact('article', 'category', 'title', 'description'));
                 } else {
                     abort(404);
                 }
             }
         } else {
             abort(404);
         }
     }
 }