public function contents($model_id = 0, $slug = '')
 {
     $network = $this->network;
     $theme = $network->theme;
     $theme = check_for_tour_theme($theme);
     Theme::setActive($theme);
     $data = $this->data;
     $model = Model::find($model_id);
     if ($model) {
         $contents = $model->contents()->published()->ofNetwork($this->network->id)->orderBy('id', 'desc')->get();
         $data['page_title'] = $model->name . ' Contents';
         $data['model'] = $model;
         $data['contents'] = $contents;
         $content_views = 0;
         foreach ($contents as $content) {
             $content_views = $content_views + $content->fake_views;
         }
         $data['content_views'] = $content_views;
         $username = \Request::server('PHP_AUTH_USER', 'sampleuser');
         $data['is_favorite'] = $username && Favorite::ofUsername($username)->hasFavorite('Model', $model->id)->count() ? 1 : 0;
         $this->breadcrumbs->addCrumb('Popular Models', url('models'));
         $this->breadcrumbs->addCrumb($model->name . ' Contents');
         return Theme::view('model.contents', $data);
     }
 }
 public function view($id, $slug = '')
 {
     $network = $this->network;
     $data = $this->data;
     $content = Content::find($id);
     if (!$content) {
         return redirect('/');
     }
     $job = new UpdateViewCount($id);
     $this->dispatch($job);
     $site = $content->sites()->ofNetwork($network->id)->first();
     $theme = $site->theme != '' ? $site->theme : $network->theme;
     $theme = check_for_tour_theme($theme);
     Theme::setActive($theme);
     $data['page_title'] = $content->title;
     $data['content'] = $content;
     $data['photos'] = $content->files()->photos()->get();
     $data['videos'] = $content->files()->videos()->get();
     $data['similar'] = Content::ofNetwork($this->network->id)->similar($content)->published()->take(12)->get();
     $data['type'] = 'stream';
     $data['site'] = $site;
     $data['content_sites'] = $content->sites()->ofNetwork($network->id)->orderBy('name', 'asc')->get();
     $data['content_tags'] = $content->tags()->ofNetwork($network->id)->orderBy('name', 'asc')->get();
     $data['content_models'] = $content->models()->ofNetwork($network->id)->orderBy('name', 'asc')->get();
     $data['content_dvds'] = $content->dvds()->ofNetwork($network->id)->orderBy('title', 'asc')->get();
     $this->breadcrumbs->addCrumb('Updates', url('updates'));
     $this->breadcrumbs->addCrumb($content->title);
     $username = \Request::server('PHP_AUTH_USER', 'sampleuser');
     $data['has_rated'] = $content->ratings()->where('username', $username)->first();
     $data['is_favorite'] = $username && Favorite::ofUsername($username)->hasFavorite('Content', $content->id)->count() ? 1 : 0;
     if (\Request::input('pl')) {
         $param = explode(':', \Request::input('pl'));
         if (isset($param[0]) && $param[0] == 'dvd') {
             $data['on_dvd'] = true;
             $dvd = $content->dvds()->find(isset($param[1]) ? $param[1] : 0);
             $data['dvd'] = $dvd;
             $data['dvd_contents'] = $dvd->contents()->get();
         }
         if (isset($param[0]) && $param[0] == 'member') {
             $data['on_playlist'] = true;
             $playlist = Playlist::find(isset($param[1]) ? $param[1] : 0);
             $data['playlist'] = $playlist;
             $data['playlist_contents'] = $playlist->contents()->get();
         }
     }
     $data['playlists'] = Playlist::ofUsername($username)->get();
     $data['piwik_tracker_ids'] = config('yppmembers.use_piwik') && $site->piwik_id != 0 ? array_merge($data['piwik_tracker_ids'], [$site->piwik_id]) : $data['piwik_tracker_ids'];
     return Theme::view('content.view', $data);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request)
 {
     $username = \Request::server('PHP_AUTH_USER', 'sampleuser');
     $response = [];
     $type = $request->input('type', '');
     $id = $request->input('id', '');
     $fav = Favorite::ofUsername($username)->hasFavorite($type, $id)->first();
     if ($username && $id && $fav) {
         $fav->delete();
         $response['success'] = true;
         $response['message'] = 'Item successfully removed.';
     }
     return \Response::json($response);
 }
 public function dvdSeries($id)
 {
     if (Input::has('o')) {
         $order = Input::get('o');
         switch ($order) {
             case 'v':
                 $orderBy = "views";
                 $sortName = "Most Viewed";
                 break;
             case 'r':
                 $orderBy = "rating";
                 $sortName = "Top Rated";
                 break;
             case 'f':
                 $orderBy = "favorites";
                 $sortName = "Most Popular";
                 break;
             default:
                 $orderBy = "publish_date";
                 $sortName = "Newest";
                 break;
         }
     } else {
         $order = "";
         $orderBy = "publish_date";
         $sortName = "Newest";
     }
     $network = $this->network;
     $theme = $network->theme;
     Theme::setActive($theme);
     $data = $this->data;
     $series = Dvdseries::find($id);
     $data['series'] = $series;
     $data['dvds'] = $series->dvds()->get();
     $data['page_title'] = $series->title;
     $username = \Request::server('PHP_AUTH_USER', 'sampleuser');
     $data['is_favorite'] = $username && Favorite::ofUsername($username)->hasFavorite('Dvdseries', $series->id)->count() ? 1 : 0;
     $data['tags'] = Tag::ofNetwork($this->network->id)->ofDvds()->get();
     $data['sortname'] = $sortName;
     $this->breadcrumbs->addCrumb('DVD');
     return Theme::view('dvd.series', $data);
 }