<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Users extends CI_Controller {
public $loggedIn;
/*
* Check if logged in or not and assign it to all methods
*/
function __construct() {
parent::__construct();
$this->loggedIn = $this->session->userdata('loggedIn');
}
/*
* User moderate links
*/
public function moderator() {
if(!$this->loggedIn OR !is_moderator())
{
redirect('/users/login');
exit;
}
$this->db->select("film_links.*, movies.film_title, movies.filmID, users.username, users.ip as ip_address,
(SELECT COUNT(*) as tLinks FROM film_links) as tLinks", false);
$this->db->join("users", "users.userID = film_links.linkBy", "LEFT");
$this->db->join("movies", "movies.filmID = film_links.mID", "LEFT");
$this->db->from("film_links");
$this->db->where('status', 'pending');
$this->db->order_by("linkID", "DESC");
$links = $this->db->get();
$data['links_to_moderate'] = $links->result();
$this->load->view('user-moderate', $data);
}
/*
* User moderate comments
*/
public function moderator_comments() {
if(!$this->loggedIn OR !is_moderator())
{
redirect('/users/login');
exit;
}
$removeID = $this->uri->segment(4);
if($removeID) {
$id = abs(intval($removeID));
$this->db->delete("comments", array("commID" => $id));
redirect('/users/moderator_comments');
}
$this->db->select("comments.*, movies.film_title, movies.filmID, users.username, users.ip as ip_address,
(SELECT COUNT(*) as tComments FROM comments) as tComments", false);
$this->db->join("users", "users.userID = comments.commUser", "LEFT");
$this->db->join("movies", "movies.filmID = comments.movID", "LEFT");
$this->db->from("comments");
$this->db->order_by("commID", "DESC");
$comments = $this->db->get();
$data['comments_to_moderate'] = $comments->result();
$this->load->view('user-moderate-comments', $data);
}
/*
* User home
*/
public function index()
{
if(!$this->loggedIn)
{
redirect('/users/login');
exit;
}
if($this->input->post('sb_signup')) {
if(!$this->input->post('email') OR !$this->input->post('password')) {
$data['form_message'] = div_class("Email and password are required", 'alert alert-error');
}else{
$this->db->where(array("email" => $this->input->post('email', TRUE)));
$this->db->where("userID != " . is_user_logged_in());
$user = $this->db->get("users");
if(count($user->result())) {
$data['form_message'] = '<div class="alert alert-warning">';
$data['form_message'] .= 'Username/Email taken, please chose another one.';
$data['form_message'] .= '</div>';
}else{
$this->db->where("userID", is_user_logged_in());
$this->db->update("users", array('email' => $this->input->post('email'),
'password' => md5($this->input->post('password')),
'about' => trim(strip_tags($this->input->post('about')))));
$data['form_message'] = div_class("Account updated", 'alert alert-success');
}
}
}
$user = $this->db->get_where("users", array("userID" => is_user_logged_in()));
$user = $user->row();
$data['user'] = $user;
$this->load->view('user-account', $data);
}
/*
* User Login
*/
public function login() {
if($this->loggedIn)
{
redirect('/users');
exit;
}
$data = array();
if($this->input->post('sbLogin')) {
$user = $this->input->post('uname', TRUE);
$pass = $this->input->post('upwd', TRUE);
if(!empty($user) AND !empty($pass)) {
$this->db->where(array("username" => $user));
$this->db->where(array("password" => md5($pass)));
$user = $this->db->get("users");
if(count($user->result())) {
$data['login_message'] = '<div class="alert alert-success">Ok, redirecting..</div>';
foreach($user->result() as $u) {
$this->session->set_userdata('loggedIn', $u->userID);
}
redirect('/users');
}else{
$data['login_message'] = '<div class="alert alert-error">Invalid user/pass</div>';
}
}else{
$data['login_message'] = '<div class="alert alert-error">Please enter user/pass</div>';
}
}
$this->load->view('login', $data);
}
/*
* Logout function
*/
public function logout() {
$this->session->unset_userdata('loggedIn');
redirect('/users/login');
}
/*
* Register Form/Page
*/
public function join() {
if($this->loggedIn)
{
redirect('/users');
exit;
}
$this->load->view('join-now');
}
/*
* Register via AJAX
*/
public function ajax_join() {
if($this->input->post('sb_signup')) {
unset($_POST['sb_signup']);
$insert = array();
foreach($this->input->post() as $k=>$v) {
if($this->input->post($k, TRUE) != "") {
$insert[$k] = $this->input->post($k, TRUE);
}else{
print '<div class="alert alert-warning">';
print 'All fields are mandatory';
print '</div>';
exit;
}
}
$this->db->where(array("username" => $this->input->post('username', TRUE)));
$this->db->or_where(array("email" => $this->input->post('email', TRUE)));
$user = $this->db->get("users");
if(count($user->result())) {
print '<div class="alert alert-warning">';
print 'Username/Email taken, please chose another one.';
print '</div>';
exit;
}
$insert['ip'] = ip2long($_SERVER['REMOTE_ADDR']);
$insert['password'] = md5($insert['password']);
if($this->db->insert("users", $insert)) {
$this->session->set_userdata('loggedIn', $this->db->insert_id());
print '<div class="alert alert-success">';
print 'You are now logged in. <a href="/users">My Account</a>';
print '</div>';
}else{
print '<div class="alert alert-warning">';
print 'DB Error';
print '</div>';
}
}else{
print '<div class="alert alert-warning">';
print '-No post-';
print '</div>';
}
}
/*
* User Profiles
*/
public function profile() {
$username = trim(strip_tags($this->uri->segment(3)));
if(!$username) {
$data['error'] = 'User not found';
$this->load->view('user-profiles', $data);
}else{
$user = $this->db->get_where("users", array("username" => $username));
$user = $user->row();
$data['user'] = $user;
if(count($user)) {
$this->db->select("playlists.*, movies.filmID, movies.film_title,
movies.thumbnail, movies.release_date, movies.rating");
$this->db->from("playlists");
$this->db->where("uID = $user->userID");
$this->db->join("movies","movies.filmID = playlists.fID");
$playlist= $this->db->get();
$data['playlist'] = $playlist->result();
}else{
$data['playlist'] = new stdClass;
}
$this->load->view('user-profiles', $data);
}
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class WatchMovies extends CI_Controller {
public function __construct() {
parent::__construct();
}
//redirect to external page
public function go() {
ob_start();
$id = $this->uri->segment(3);
$id = abs(intval($id));
if($id < 1) {
die("Negative ID");
}
//get external link details
$this->db->select("link_destination");
$link = $this->db->get_where('film_links', array('linkID' => $id));
$link = $link->row();
header("Location: ".$link->link_destination);
ob_end_flush();
}
//show embed link
public function embed() {
ob_start();
$id = $this->uri->segment(3);
$id = abs(intval($id));
if($id < 1) {
die("Negative ID");
}
//get external link details
$this->db->select("link_destination");
$link = $this->db->get_where('film_links', array('linkID' => $id));
$link = $link->row();
echo $link->link_destination;
ob_end_flush();
}
//single movie page
public function index($param = null)
{
$this->load->helper("form");
$uri_string = $this->uri->segment(2);
$movie = explode("-", $uri_string);
$movieID = $this->db->escape(abs(intval(end($movie))));
//get movie data
$moviesRs = $this->db->get_where("movies", array("filmID" => $movieID));
$movieData = $moviesRs->result();
//get genres
$genresRs = $this->db->where_in("genreID", @explode(",", $movieData[0]->genres));
$genresRs = $genresRs->get("genres");
$genresAll = $genresRs->result();
//get comments
$this->db->select("commID, comment, comm_date, userID, username");
$this->db->from("comments");
$this->db->where("movID = $movieID");
$this->db->join('users', 'comments.commUser = users.userID');
$comments = $this->db->get();
//get movie links
$this->db->select("film_links.*, film_title");
$this->db->from("film_links");
$this->db->where("status = 'approved'");
$this->db->where("mID = $movieID");
$this->db->join('movies', 'movies.filmID = film_links.mID');
$movie_links = $this->db->get();
//get ad code
$tos = $this->db->get("ads");
$tos = $tos->row();
$data['ads'] = $tos->ads;
//build seo title
$data['seo_title'] = 'Watch ' . $movieData[0]->film_title .' ('.date("Y", $movieData[0]->release_date).') Online';
//get related movies : same genre
$this->load->helper('related_sidebar');
$data['related_movies'] = related_sidebar($movieData[0]->genres, $movieID);
$data['movie_info'] = $movieData;
$data['genres'] = $genresAll;
$data['movie_comments'] = $comments->result();
$data['movie_links'] = $movie_links->result();
$this->load->view('watch-movies', $data);
}
//movies page
public function movies($param = null) {
$this->load->library('pagination');
//pagination
$config['base_url'] = '/watch/movies/page/';
$this->db->where(array("film_type" => 'movie'));
$this->db->from("movies");
$config['total_rows'] = $this->db->count_all_results();
$config['per_page'] = 16;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$page = abs(intval($this->uri->segment(4)));
$start = $page*$config['per_page'];
//estabilish vid type = movies
$data['vid_type'] = 'Watch Movies Online';
$this->db->order_by('is_featured', 'desc');
$this->db->order_by('filmID', 'desc');
$movies = $this->db->get_where("movies", array("film_type" => 'movie'), $config['per_page'], $page);
$data['movies'] = $movies->result();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('all-movies', $data);
}
//tv shows page
public function tvshows() {
//estabilish vid type = movies
$data['vid_type'] = 'Watch TV Shows Online';
$this->load->library('pagination');
//pagination
$config['base_url'] = '/watch/tv-shows/page/';
$this->db->where(array("film_type" => 'tv-show'));
$this->db->from("movies");
$config['total_rows'] = $this->db->count_all_results();
$config['per_page'] = 16;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$page = abs(intval($this->uri->segment(4)));
$start = $page*$config['per_page'];
$this->db->order_by('is_featured', 'desc');
$this->db->order_by('filmID', 'desc');
$movies = $this->db->get_where("movies", array("film_type" => 'tv-show'), $config['per_page'], $page);
$data['movies'] = $movies->result();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('all-movies', $data);
}
//watch by genre
public function by_genre() {
$genre_name = trim(strip_tags($this->uri->segment(2)));
if(empty($genre_name)) die("Empty genre");
//estabilish vid type = movies
$data['vid_type'] = 'Watch '.$genre_name.' Movies & TV Shows';
$data['seo_title'] = 'Watch '.$genre_name.' Movies & TV Shows';
$this->load->library('pagination');
//get genre id
$genreQuery = $this->db->get_where("genres", array("genre" => $genre_name));
$genre_name = $genreQuery->row();
if(!count($genre_name))
{
$data['error'] = 'Error fetching genre <strong>'.trim(strip_tags($this->uri->segment(2))).'</strong><br/>';
$this->load->view('all-movies', $data);
}else{
$genreID = $genre_name->genreID;
//pagination
$config['base_url'] = '/watch-genres/'.url_title($genre_name->genre).'/page/';
$qt = $this->db->query("SELECT * FROM movies WHERE FIND_IN_SET($genreID, genres)");
#var_dump($qt);
$config['total_rows'] = $qt->num_rows;
$config['per_page'] = 16;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$page = abs(intval($this->uri->segment(4)));
$start = abs(intval($page*$config['per_page']));
#print_r($config);
$movies = $this->db->query("SELECT * FROM movies WHERE FIND_IN_SET($genreID, genres) LIMIT $page, ".$config['per_page']."");
$data['movies'] = $movies->result();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('all-movies', $data);
}
}
//watch by actors
public function by_actor() {
$genre_name = trim(strip_tags($this->uri->segment(2)));
$genre_name = str_replace("-", " ", $genre_name);
if(empty($genre_name)) die("Empty actor");
//estabilish vid type = movies
$data['vid_type'] = 'Watch '.$genre_name.' Movies & TV Shows';
$data['seo_title'] = 'Watch '.$genre_name.' Movies & TV Shows';
$this->load->library('pagination');
//pagination
$config['base_url'] = '/watch-movies-by-actor/page/';
$this->db->query("SELECT * FROM movies WHERE FIND_IN_SET('$genre_name', actors) OR FIND_IN_SET(' $genre_name', actors)");
$config['total_rows'] = $this->db->count_all_results();
$config['per_page'] = 16;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$page = abs(intval($this->uri->segment(3)));
$start = abs(intval($page*$config['per_page']));
$movies = $this->db->query("SELECT * FROM movies WHERE FIND_IN_SET('$genre_name', actors) OR FIND_IN_SET(' $genre_name', actors) LIMIT $start, ".$config['per_page']."");
$data['movies'] = $movies->result();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('all-movies', $data);
}
//watch by keywords
public function by_keywords() {
$genre_name = trim(strip_tags($this->uri->segment(2)));
$genre_name = str_replace("-", " ", $genre_name);
if(empty($genre_name)) die("Empty keyword");
//estabilish vid type = movies
$data['vid_type'] = 'Watch "'.$genre_name.'" Movies & TV Shows';
$this->load->library('pagination');
//pagination
$config['base_url'] = '/watch-movies-by-keywords/page/';
$this->db->query("SELECT * FROM movies WHERE FIND_IN_SET('$genre_name', tags) OR FIND_IN_SET(' $genre_name', tags)");
$config['total_rows'] = $this->db->count_all_results();
$config['per_page'] = 16;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$page = abs(intval($this->uri->segment(3)));
$start = abs(intval($page*$config['per_page']));
$movies = $this->db->query("SELECT * FROM movies WHERE FIND_IN_SET('$genre_name', tags) OR FIND_IN_SET(' $genre_name', tags) LIMIT $start, ".$config['per_page']."");
$data['movies'] = $movies->result();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('all-movies', $data);
}
/*
* Leave comments to movies
*/
public function ajax_comment() {
$userID = is_user_logged_in();
if($userID) {
foreach($this->input->post() as $k=>$v) {
if($this->input->post($k, TRUE) == "") {
print '<div class="alert alert-warning">';
print 'All fields are mandatory';
print '</div>';
exit;
}
}
$comment = array();
$comment['comm_date'] = time();
$comment['commUser'] = $userID;
$comment['movID'] = abs(intval($this->input->post('movID', TRUE)));
$comment['comment'] = trim(strip_tags($this->input->post('comment', TRUE)));
if(strlen($comment['comment']) < 10 ) {
echo div_class('Please enter at least 10 characters for your comment', 'alert alert-error');
exit;
}
if($this->db->insert("comments", $comment)) {
echo div_class('Thank you for your comment', 'alert alert-warning');
echo '<script type="text/javascript">';
echo '$(function() {';
echo '$("#comment-form").hide("slow");';
echo '})';
echo '</script>';
}else{
echo div_class('DB Error!', "alert alert-error");
}
}else{
echo '<div class="alert alert-error">Please login</div>';
}
}
/*
* Load latest comment via ajax
*/
function ajax_last_comment() {
$lastID = abs(intval($this->input->post("last", TRUE)));
$movID = abs(intval($this->input->post("movie", TRUE)));
if($lastID AND $movID) {
//get comments
$this->db->select("commID, comment, comm_date, userID, username");
$this->db->from("comments");
$this->db->where("commID > $lastID");
$this->db->where("movID = $movID");
$this->db->join('users', 'comments.commUser = users.userID');
$comments = $this->db->get();
$comments = $comments->result();
if(count($comments)) {
foreach($comments as $c) {
echo '<li data-lastID="'.$c->commID.'">';
?>
<span class="comment_author"><b class="icon-user"></b> <?php echo anchor('users/profile/'.url_title($c->username), $c->username); ?> on <b class="icon-calendar"></b><em><?php echo date("jS F Y H:ia", $c->comm_date); ?></em></span>
<div class="comment_content"><?php echo wordwrap($c->comment, 80, '<br/>', TRUE); ?></div>
<?php
echo '</li>';
}
}
}else{
}
}
/*
* AJAX Star Rating system
*/
function rating($uri) {
ob_start();
$do = $this->uri->segment(4);
$movID = abs(intval($this->uri->segment(6)));
if($do AND $movID) {
if($do == 'getrate') {
$this->db->select("rating");
$this->db->from("movies");
$this->db->where("filmID = $movID");
$rating = $this->db->get();
$rating = $rating->row();
if($rating) {
echo $rating->rating*20;
}else{
echo 100;
}
}elseif($do == 'rate') {
$ip = ip2long($_SERVER['REMOTE_ADDR']);
$rating = abs(intval($this->uri->segment(8)));
$this->db->select("rating");
$this->db->from("movies");
$this->db->where("filmID = $movID");
$ratingDB = $this->db->get();
$ratingDB = $ratingDB->row();
if($rating >= 1 AND $rating <= 5) {
if(!isset($_COOKIE[$ip.'movie'.$movID])) {
if($ratingDB->rating > 0) {
$this->db->set('rating', '(rating+'.$rating.')/2', FALSE);
$this->db->where('filmID', $movID);
$this->db->update('movies');
echo 'Rated '.$rating.'/5';
setcookie($ip.'movie'.$movID, 'voted', time()+24*3600);
}else{
$this->db->set('rating', $rating);
$this->db->where('filmID', $movID);
$this->db->update('movies');
echo 'Rated '.$rating.'/5';
setcookie($ip.'.movie'.$movID, 'voted', time()+24*3600);
}
}else{
print "Already Rated";
}
}
}
}else{
echo 100;
}
ob_end_flush();
}
/*
* Function to rate broken/working link
*/
public function rate_external_ajax() {
ob_start();
$linkID = abs(intval($this->input->post('linkID')));
$feedback = (string) ($this->input->post('action'));
if($linkID AND ($feedback == 'works' OR $feedback == 'broken')) {
$ip = ip2long($_SERVER['REMOTE_ADDR']);
if(isset($_COOKIE[$ip.$linkID])) {
echo div_class('Not again. You can vote once', 'alert alert-warning');
}else{
setcookie($ip.$linkID, $feedback, time()+24*3600);
if($feedback == 'works') {
$this->db->set('link_ok', '(link_ok+1)', FALSE);
}else{
$this->db->set('link_broken', '(link_broken+1)', FALSE);
}
$this->db->where('linkID', $linkID);
$this->db->update('film_links');
echo div_class('Thank you', 'alert alert-warning');
}
}else{
print 'Nothing to do';
}
ob_end_flush();
}
/*
* ajax submit link
*/
public function ajax_link_submit() {
ob_start();
if(!is_user_logged_in() AND !is_admin()) die("Please login");
$title = (string) trim(strip_tags($this->input->post('link_title')));
$link = is_admin() ? $this->input->post('movie_link') : (string) trim(strip_tags($this->input->post('movie_link')));
$tab = (string) trim(strip_tags($this->input->post('link_tab')));
$userID = is_user_logged_in();
$movieID = (int) abs(intval($this->input->post('movieID')));
if($movieID < 1) die(div_class('MovieID negative', 'alert alert-error'));
if(!empty($title) AND !empty($link) AND stristr($link, 'http')) {
$insert['linkBy'] = $userID;
$insert['link_tab'] = $tab;
$insert['link_title'] = $title;
$insert['link_destination'] = $link;
$insert['link_ok'] = 0;
$insert['link_broken'] = 0;
if(!is_admin()) {
$insert['status'] = 'pending';
$insert['link_type'] = 'External';
}else{
$insert['status'] = 'approved';
$insert['link_type'] = (string) trim(strip_tags($this->input->post('link_type')));
}
$insert['mID'] = $movieID;
$this->db->insert("film_links", $insert);
if(!is_admin()) {
echo div_class('Thank you, we will review it soon and approve/reject.', 'alert alert-success');
echo '<script type="text/javascript">';
echo '$(function() {
$("#submit-link-form").hide("slow");
});';
echo '</script>';
}else{
echo div_class('Link Added. <a href="/admin/movielinks/'.$movieID.'">Refresh this page.</a>', 'alert alert-success');
}
}else{
echo div_class('Enter link details please. Link must start with http:// or https://', 'alert alert-error');
echo htmlspecialchars($link);
}
ob_end_flush();
}
/*
* Add to playlist
*/
public function ajax_add_playlist() {
ob_start();
if(!is_user_logged_in()) die(div_class("Please login to add to your playlist", "alert alert-warning"));
$movID = (int) abs(intval($this->uri->segment(3)));
$userID = is_user_logged_in();
if($movID < 1) die(div_class("Negative movie #ID", "alert alert-warning"));
//check if already on user playlist
$check = $this->db->query("SELECT listID FROM playlists WHERE fID = ? AND uID = ?", array($movID, $userID));
if(count($check->result())) {
echo div_class("Movie already in your Playlist", "alert alert-warning");
}else{
$insert = array("fID" => $movID, "uID" => $userID, "date" => time());
$this->db->insert("playlists", $insert);
echo div_class("Added to your playlist", "alert alert-success");
}
ob_end_flush();
}
}
Большая просьба помочь. Очень нужно.
Администрация если я не по теме прошу перенести.