App::LoadClass('Rating'); App::LoadClass('Favorite'); // Establish page variables, objects, arrays, etc View::InitView('myfavorites'); Plugin::Trigger('myfavorites.start'); Functions::RedirectIf(View::$vars->logged_in = User::LoginCheck(), HOST . '/login/'); View::$vars->user = new User(View::$vars->logged_in); $records_per_page = 9; $url = HOST . '/myaccount/myfavorites'; View::$vars->message = null; /*********************** Handle Form if submitted ***********************/ if (isset($_GET['vid']) && is_numeric($_GET['vid']) && $_GET['vid'] != 0) { $data = array('user_id' => View::$vars->user->user_id, 'video_id' => $_GET['vid']); $id = Favorite::Exist($data); if ($id) { Favorite::Delete($id); View::$vars->message = Language::GetText('success_favorite_removed'); View::$vars->message_type = 'success'; Plugin::Trigger('myfavorites.remove_favorite'); } } // Retrieve total count $query = "SELECT " . DB_PREFIX . "favorites.video_id FROM " . DB_PREFIX . "favorites INNER JOIN " . DB_PREFIX . "videos ON " . DB_PREFIX . "favorites.video_id = " . DB_PREFIX . "videos.video_id WHERE status = 'approved' AND private = '0' AND " . DB_PREFIX . "favorites.user_id = " . View::$vars->user->user_id; $result_count = $db->Query($query); $total = $db->Count($result_count); // Initialize pagination View::$vars->pagination = new Pagination($url, $total, $records_per_page); $start_record = View::$vars->pagination->GetStartRecord(); // Retrieve limited results
} Plugin::Trigger('favorite.ajax.login_check'); // Verify a valid video was provided if (empty($_POST['video_id']) || !is_numeric($_POST['video_id'])) { App::Throw404(); } if (!Video::Exist(array('video_id' => $_POST['video_id'], 'status' => 'approved'))) { App::Throw404(); } $video = new Video($_POST['video_id']); // Verify user is logged in if (!$logged_in) { echo json_encode(array('result' => 0, 'msg' => (string) Language::GetText('error_favorite_login'))); exit; } // Check user doesn't fav. his own video if ($user->user_id == $video->user_id) { echo json_encode(array('result' => 0, 'msg' => (string) Language::GetText('error_favorite_own'))); exit; } // Create Favorite record if none exists $data = array('user_id' => $user->user_id, 'video_id' => $video->video_id); if (!Favorite::Exist($data)) { Favorite::Create($data); Plugin::Trigger('favorite.ajax.favorite_video'); echo json_encode(array('result' => 1, 'msg' => (string) Language::GetText('success_favorite_added'))); exit; } else { echo json_encode(array('result' => 0, 'msg' => (string) Language::GetText('error_favorite_duplicate'))); exit; }