/**
  * @param $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $article = Article::find($id);
     $article->delete();
     ArticleRecommend::whereArticleId($id)->delete();
     return $this->redirect->to('admin/article');
 }
Example #2
0
 /**
  * @param $key
  * @param array $opinions
  * @return mixed
  */
 public function position($key, $opinions = [])
 {
     $config = $this->config->get('page.recommends');
     $config = array_merge($config[$key], $opinions);
     $articles = ArticleRecommend::wherePosition($key);
     if (isset($opinions['limit']) && $opinions['limit'] > 0) {
         $articles->take($config['limit']);
     }
     $articles = $articles->orderBy('created_at', 'desc')->get();
     if (isset($config['thumbnail']) && is_array($config['thumbnail'])) {
         foreach ($articles as $k => $article) {
             $article = Article::find($article->article_id);
             if ($article) {
                 preg_match_all("/<img([^>]*)\\s*src=('|\")([^'\"]+)('|\")/", $article->content, $matches);
                 $hash = '';
                 $thumbnail = '';
                 if ($matches && $matches[3]) {
                     $matches = array_unique($matches[3]);
                     if ($matches[0] && $this->file->exists(public_path($matches[0]))) {
                         $thumbnail = $matches[0];
                         $hash = hash_file('md5', public_path($matches[0]), false);
                     }
                 }
                 if ($thumbnail && $hash) {
                     $path = '/uploads/thumbnails/' . $config['thumbnail']['width'] . 'X' . $config['thumbnail']['height'] . '/' . $hash . '.' . $this->file->extension(public_path($thumbnail));
                     $directory = public_path('/uploads/thumbnails/' . $config['thumbnail']['width'] . 'X' . $config['thumbnail']['height'] . '/');
                     if (!$this->file->isDirectory($directory)) {
                         $this->file->makeDirectory($directory, 0777, true, true);
                     }
                     if (!$this->file->exists(public_path($path))) {
                         $image = Image::make($thumbnail, $config['thumbnail']);
                         $image->save(public_path($path));
                     }
                     $article->thumbnail = $path;
                 }
                 $articles->put($k, $article);
             } else {
                 $articles->forget($k);
             }
         }
     }
     return $this->view->make($config['template'])->withArticles($articles);
 }
Example #3
0
 /**
  * @return bool
  */
 public function isCurrentRoute()
 {
     if (strpos($this->attributes['link'], 'http://') === false && strpos($this->attributes['link'], 'https://') === false) {
         if (strpos($this->attributes['link'], 'category') !== false) {
             $tmp = trim($this->attributes['link'], '/');
             $tmp = explode('/', $tmp);
             if (is_numeric($tmp[1])) {
                 $id = $tmp[1];
                 $collection = Collection::make();
                 $ids = [];
                 if (Container::getInstance()->make('request')->route("article")) {
                     $article = Article::find(Container::getInstance()->make('request')->route("article"));
                     if ($article instanceof Article) {
                         Category::getAllParentCategories($article->category->id, $collection);
                     }
                     foreach ($collection as $category) {
                         $ids[] = $category->id;
                     }
                     $ids = array_unique($ids);
                     if (in_array($id, $ids)) {
                         return true;
                     }
                 } else {
                     Category::getAllSubCategories($id, $collection);
                     $ids[] = $id;
                     foreach ($collection as $category) {
                         $ids[] = $category->id;
                     }
                     $ids = array_unique($ids);
                     $current = Container::getInstance()->make('request')->route("category");
                     if (in_array($current, $ids)) {
                         return true;
                     }
                 }
             }
         } else {
             return Container::getInstance()->make('request')->is($this->attributes['link'] . '*') ? true : false;
         }
     }
 }