Exemple #1
0
 /**
  * Categories list
  */
 public static function listing()
 {
     $categories = PostCategory::all();
     $id_tree = [];
     foreach ($categories as $cat) {
         $id_tree[$cat->id] = $cat;
     }
     return $id_tree;
 }
 public function index()
 {
     if (\Input::get('theme')) {
         \Cookie::queue('theme', \Input::get('theme'), 100);
         return Redirect::to('/')->withCookie(cookie('theme', \Input::get('theme'), 100));
     }
     $data = array('videos' => Video::where('active', '=', '1')->orderBy('created_at', 'DESC')->simplePaginate($this->videos_per_page), 'current_page' => 1, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'pagination_url' => '/videos', 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
     //dd($data['videos']);
     return View::make('Theme::home', $data);
 }
 public function index()
 {
     $search_value = Input::get('value');
     if (empty($search_value)) {
         return Redirect::to('/');
     }
     $videos = Video::where('active', '=', 1)->where('title', 'LIKE', '%' . $search_value . '%')->orderBy('created_at', 'desc')->get();
     $posts = Post::where('active', '=', 1)->where('title', 'LIKE', '%' . $search_value . '%')->orderBy('created_at', 'desc')->get();
     $data = array('videos' => $videos, 'posts' => $posts, 'search_value' => $search_value, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
     return View::make('Theme::search-list', $data);
 }
 public function category($category)
 {
     $page = Input::get('page');
     if (!empty($page)) {
         $page = Input::get('page');
     } else {
         $page = 1;
     }
     $cat = PostCategory::where('slug', '=', $category)->first();
     $data = array('posts' => Post::where('active', '=', '1')->where('post_category_id', '=', $cat->id)->orderBy('created_at', 'DESC')->simplePaginate($this->posts_per_page), 'current_page' => $page, 'category' => $cat, 'page_title' => 'Posts - ' . $cat->name, 'page_description' => 'Page ' . $page, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'pagination_url' => '/posts/category/' . $category, 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
     return View::make('Theme::post-list', $data);
 }
 public function show_favorites()
 {
     if (!Auth::guest()) {
         $page = Input::get('page');
         if (empty($page)) {
             $page = 1;
         }
         $favorites = Favorite::where('user_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->get();
         $favorite_array = array();
         foreach ($favorites as $key => $fave) {
             array_push($favorite_array, $fave->video_id);
         }
         $videos = Video::where('active', '=', '1')->whereIn('id', $favorite_array)->paginate(12);
         $data = array('videos' => $videos, 'page_title' => ucfirst(Auth::user()->username) . '\'s Favorite Videos', 'current_page' => $page, 'page_description' => 'Page ' . $page, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'pagination_url' => '/favorites', 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
         return View::make('Theme::video-list', $data);
     } else {
         return Redirect::to('videos');
     }
 }
 public function order()
 {
     $category_order = json_decode(Input::get('order'));
     $post_categories = PostCategory::all();
     $order = 1;
     foreach ($category_order as $category_level_1) {
         $level1 = PostCategory::find($category_level_1->id);
         if ($level1->id) {
             $level1->order = $order;
             $level1->parent_id = NULL;
             $level1->save();
             $order += 1;
         }
         if (isset($category_level_1->children)) {
             $children_level_1 = $category_level_1->children;
             foreach ($children_level_1 as $category_level_2) {
                 $level2 = PostCategory::find($category_level_2->id);
                 if ($level2->id) {
                     $level2->order = $order;
                     $level2->parent_id = $level1->id;
                     $level2->save();
                     $order += 1;
                 }
                 if (isset($category_level_2->children)) {
                     $children_level_2 = $category_level_2->children;
                     foreach ($children_level_2 as $category_level_3) {
                         $level3 = PostCategory::find($category_level_3->id);
                         if ($level3->id) {
                             $level3->order = $order;
                             $level3->parent_id = $level2->id;
                             $level3->save();
                             $order += 1;
                         }
                     }
                 }
             }
         }
     }
     return 1;
 }
Exemple #7
0
 /**
  * Import videos from youtube
  *
  * @param Request $request
  * @param $match
  * @return string
  */
 public function import(Request $request, $match)
 {
     if ($request->isMethod('post')) {
         $items = [];
         $query = ['part' => 'snippet,id', 'channelId' => $request->get('channel')];
         // Fetch videos
         /** @var Google $sm */
         $sm = NCService::load('SocialMedia.Google');
         while ($response = $sm->request('https://www.googleapis.com/youtube/v3/search', $query)) {
             $response = json_decode($response, true);
             $items = array_merge($items, $response['items']);
             // Move to next page or break
             if (isset($response['nextPageToken']) && $response['nextPageToken']) {
                 $query['pageToken'] = $response['nextPageToken'];
             } else {
                 break;
             }
         }
         // Save videos
         foreach ($items as $video) {
             $id = $video['id']['videoId'];
             $url = 'https://www.youtube.com/watch?v=' . $id;
             $title = $video['snippet']['title'];
             $description = $video['snippet']['description'];
             $iframe = '<iframe class="youtube" width="560" height="315" src="https://www.youtube.com/embed/' . $id . '" frameborder="0" allowfullscreen></iframe>';
             $created_at = strtotime($video['snippet']['publishedAt']);
             // Get image url
             $preview_img = end(array_values($video['snippet']['thumbnails']))['url'];
             // Render import template
             $body = $this->view->render('@assets/templates/youtube.import.twig', ['title' => $title, 'description' => $description, 'player' => $iframe, 'url' => $url, 'short' => '#split#', 'preview' => $preview_img]);
             $entity = new \Post(['author_id' => $this->user->id, 'title' => $title, 'content' => str_replace('#split#', '<!-- split -->', $body), 'moderate' => 1, 'category_id' => $request->get('category'), 'created_at' => $created_at, 'updated_at' => $created_at]);
             $entity->save();
         }
         $this->view->assign('message', $this->lang->translate('post.youtube.done', count($items)));
     }
     return $this->view->render('posts/import.twig', ['title' => $this->lang->translate('post.import'), 'categories' => \PostCategory::as_array(\PostCategory::all())]);
 }
Exemple #8
0
 /**
  * @param Request $request
  * @param null $matches
  * @return mixed|string
  */
 public function create(Request $request, $matches = null)
 {
     $this->authenticated_only();
     if (!$this->user->can('publicate')) {
         return $this->error403($request);
     }
     $title = $this->lang->translate('post.create');
     // Get post for updating
     $id = intval($matches->get('id', $request->get('id')));
     if ($id > 0) {
         $post = \Post::find(['conditions' => ['id = ? AND author_id = ?', $id, $this->user->id]]);
         $title = $this->lang->translate('post.editing', $post->title);
     } else {
         $last_category = \PostCategory::last();
         if ($last_category) {
             $last_category = $last_category->to_array();
         } else {
             $last_category = null;
         }
         $post = ['title' => $this->lang->translate('post.name'), 'content' => '', 'category' => $last_category];
     }
     // Create or update page
     if ($request->isMethod('post')) {
         if ($post instanceof \Post) {
             $post->title = $request->get('title');
             $post->content = $request->get('content');
             $post->category_id = $request->get('category');
             $post->keywords = $request->get('keywords');
             $post->slug = $request->get('slug');
             $post->moderate = $this->user->can('premoderate_publ');
         } else {
             $post = new \Post(['title' => $request->get('title'), 'content' => $request->get('content'), 'category_id' => $request->get('category'), 'keywords' => $request->get('keywords'), 'slug' => $request->get('slug'), 'author_id' => $this->user->id, 'moderate' => $this->user->can('premoderate_publ')]);
         }
         // Updating instance
         $post->save();
         if (!$post->moderate) {
             // Exporting to social
             static::export($post, $this->view);
             // Ping sitemap
             NCService::load('SocialMedia.Ping');
         }
         return static::json_response(['success' => true, 'message' => $this->lang->translate('form.saved')]);
     }
     if ($post instanceof \Post) {
         $post = $post->to_array();
     }
     return $this->view->render('posts/create.twig', ['post' => $post, 'title' => $title, 'categories' => \PostCategory::as_array(\PostCategory::all())]);
 }
 public function password_reset_token($token)
 {
     $data = array('type' => 'reset_password', 'token' => $token, 'menu' => Menu::orderBy('order', 'ASC')->get(), 'payment_settings' => PaymentSetting::first(), 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
     return View::make('Theme::auth', $data);
 }
 public function pages()
 {
     $data = array('pages' => Page::orderBy('created_at', 'DESC')->get(), 'page_title' => 'Pages', 'page_description' => 'All Pages', 'menu' => Menu::orderBy('order', 'ASC')->get(), 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
     return View::make('Theme::page-list', $data);
 }
 /**
  * Show the form for editing the specified video.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $post = Post::find($id);
     $data = array('headline' => '<i class="fa fa-edit"></i> Edit Post', 'post' => $post, 'post_route' => URL::to('admin/posts/update'), 'button_text' => 'Update Post', 'admin_user' => Auth::user(), 'post_categories' => PostCategory::all());
     return View::make('admin.posts.create_edit', $data);
 }
 public function renew($username)
 {
     $user = User::where('username', '=', $username)->first();
     $payment_settings = PaymentSetting::first();
     if ($payment_settings->live_mode) {
         User::setStripeKey($payment_settings->live_secret_key);
     } else {
         User::setStripeKey($payment_settings->test_secret_key);
     }
     if (Auth::user()->username == $username) {
         $data = array('user' => $user, 'post_route' => URL::to('user') . '/' . $user->username . '/update', 'type' => 'renew_subscription', 'menu' => Menu::orderBy('order', 'ASC')->get(), 'payment_settings' => $payment_settings, 'video_categories' => VideoCategory::all(), 'post_categories' => PostCategory::all(), 'theme_settings' => ThemeHelper::getThemeSettings(), 'pages' => Page::all());
         return View::make('Theme::user', $data);
     } else {
         return Redirect::to('/');
     }
 }