abdlali8

|
Posted:
Mon Aug 31, 2009 5:45 am |
|
hey
this codes for ( index.php )
Code:<?php
if ( !defined('MODULE_FILE') )
{
die("You can't access this file directly...");
}
define('NO_EDITOR', 1);
require_once("mainfile.php");
$pagetitle = "- Videos";
include_once(dirname(__FILE__).'/module.php');
new video_module;
?>
|
and this for ( module.php )
Code:<?php
class video_module {
function video_module(){
global $db, $prefix, $user_prefix, $bgcolor2, $user, $admin;
//PHPNuke functions / vars
$this->db = &$db;
$this->prefix = &$prefix;
$this->user_prefix = &$user_prefix;
$this->user = &$user;
$this->admin = &$admin;
$this->userinfo = getusrinfo($this->user);
$this->base_path = dirname(__FILE__);
$this->template_path = $this->base_path.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR;
$this->module_name = basename($this->base_path);
//Settings Object
require_once($this->base_path.'/settings.php');
$this->settings = new vidmod_settings;
$this->config = $this->settings->get_settings();
//Video Object
include_once($this->base_path.'/videos.php');
$this->videos = new vidmod_videos;
//Category Object
include_once($this->base_path.'/categories.php');
$this->categories = new vidmod_categories;
//Language Object
include_once($this->base_path.'/languages.php');
$this->languages = new vidmod_languages;
//vTemplates
include($this->base_path.'/libraries/vtemplates/vtemplates.php');
$this->vt = new vtemplates;
$this->vt->assign('BGCOLOR2', $bgcolor2);
$this->vt->assign('SELF', basename($_SERVER['SCRIPT_NAME']));
$this->vt->assign('MODULE', $this->module_name);
$this->vt->assign('MEDIAPATH', 'modules/'.$this->module_name.'/media/');
$this->vt->assign('THUMBNAILPATH', 'modules/'.$this->module_name.'/files/thumbnails/');
$this->vt->assign('SETTINGS', $this->config);
$this->vt->assign('TEMPLATEPATH', $this->template_path);
$this->vt->assign('LANGUAGES', $this->languages->defines);
switch($_REQUEST['op']){
case 'search':
$this->search();
break;
case 'submit_video':
$this->submit_video();
break;
case 'submit_video_':
$this->submit_video_();
break;
case 'download_submitted_video':
$this->download_video();
break;
case 'view':
$this->view();
break;
case 'download_video':
$this->download_video();
break;
case 'download_converted':
$this->download_converted();
break;
case 'download_stream':
$this->download_stream();
break;
case 'download_remote':
$this->download_remote();
break;
case 'rate_video':
$this->rate_video();
break;
case 'post_comment':
$this->post_comment();
break;
case 'delete_comment':
$this->delete_comment();
break;
case 'category':
$this->category();
break;
case 'terms':
$this->terms();
break;
case 'view_user':
$this->view_user();
break;
case 'send_to_a_friend':
$this->send_to_a_friend();
break;
case 'report_broken':
$this->report_broken();
break;
default:
$this->view_videos();
break;
}
}
function header(){
include('header.php');
$is_user = is_user($this->user) ? true : false;
if($is_user){
$this->vt->assign('userinfo', $this->userinfo);
}
$this->vt->assign('is_user', $is_user);
$this->vt->display($this->base_path.'/templates/module_nav.tpl');
$this->vt->display($this->base_path.'/templates/nav_search.tpl');
}
function footer(){
include('footer.php');
}
function search(){
$query = isset($_POST['search_query']) ? $_POST['search_query'] : null;
$videos = $this->videos->get_search_videos($query);
$this->vt->assign('videos', $videos);
$this->vt->assign('query', htmlspecialchars($query));
$this->header();
$this->vt->display($this->base_path.'/templates/search.tpl');
$this->footer();
}
function category(){
$this->header();
$category_id = (isset($_REQUEST['vidmod_cat']) && is_numeric($_REQUEST['vidmod_cat']) ? $_REQUEST['vidmod_cat'] : false);
if($category_id !== false && $this->categories->category_exists($category_id)){
$this->vt->assign('main_categories', $this->categories->get_child_categories(0));
if(isset($category_id) && $category_id != 0 && is_numeric($category_id)){
$this->vt->assign('sub_categories', $this->categories->get_child_categories($category_id));
}
$perpage = $this->config['listing_perpage'];
if($perpage <= 0){
$perpage = 1;
}
$page = (isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 1);
$end = $page * $perpage;
$start = $end - ($perpage - 1);
$videos = $this->videos->get_category_videos($category_id, $start, $end);
$total_pages = intval($this->videos->temp_count / $perpage);
if(($this->videos->temp_count % $perpage) > 0) $total_pages++;
$pages = array();
for($i = 1; $i <= $total_pages; $i++)
$pages[] = $i;
$this->vt->assign('category', $this->categories->get_category($category_id));
$this->vt->assign('ancestry', $this->categories->ancestry($category_id));
$this->vt->assign('pages', $pages);
$this->vt->assign('current_page', $page);
$this->vt->assign('list', 'category_view');
$this->vt->assign('videos', $videos);
$this->vt->display($this->base_path.'/templates/videos.tpl');
$this->footer();
}
}
function view_videos(){
$this->header();
$perpage = $this->config['listing_perpage'];
if($perpage <= 0){
$perpage = 1;
}
$page = (isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ? $_REQUEST['page'] : 1);
$end = $page * $perpage;
$start = $end - ($perpage - 1);
$this->vt->assign('main_categories', $this->categories->get_child_categories(0));
switch(isset($_REQUEST['list']) ? $_REQUEST['list'] : null){
case 'most_recent':
$list = 'most_recent';
$videos = $this->videos->get_recent($start, $end);
break;
case 'most_viewed':
$list = 'most_viewed';
$videos = $this->videos->get_most_viewed($start, $end);
break;
default:
$list = 'most_hottest';
$videos = $this->videos->get_hottest($start, $end);
break;
}
$total_pages = intval($this->videos->temp_count / $perpage);
if(($this->videos->temp_count % $perpage) > 0) $total_pages++;
$pages = array();
for($i = 1; $i <= $total_pages; $i++)
$pages[] = $i;
$this->vt->assign('pages', $pages);
$this->vt->assign('current_page', $page);
$this->vt->assign('list', $list);
$this->vt->assign('videos', $videos);
$this->vt->display($this->base_path.'/templates/videos.tpl');
$this->footer();
}
function submit_video(){
$this->header();
$is_user = is_user($this->user) ? true : false;
if($is_user){
$this->vt->assign('userinfo', $this->userinfo);
}
$this->vt->assign('is_user', $is_user);
$this->vt->display($this->base_path.'/templates/submit_video.tpl');
$this->footer();
}
function submit_video_(){
$file_validity_check = $this->videos->check_valid_file($_FILES['video_file']['name']);
if($_FILES['video_file'] != null && ($file_validity_check === true || $_POST['remote_link'] != '')){
if(is_user($this->user)){
$id = $this->videos->create_submitted_video($_POST['video_name'], $_POST['video_description'], $_FILES['video_file'], $_POST['remote_link'], $this->userinfo['user_id'], $this->userinfo['user_email']);
} else {
$id = $this->videos->create_submitted_video($_POST['video_name'], $_POST['video_description'], $_FILES['video_file'], $_POST['remote_link'], '0', $_POST['submitter_email']);
}
if($_FILES['thumb_file'] != null && $this->videos->check_valid_thumb($_FILES['thumb_file']['name'])){
$this->videos->update_video($id, array('file_thumbnail' => $_FILES['thumb_file']));
}
$this->header();
$this->vt->display($this->base_path.'/templates/submitted_video.tpl');
$this->footer();
} else {
$this->header();
$this->vt->assign('error', $file_validity_check);
$this->vt->display($this->base_path.'/templates/error_submit.tpl');
$this->footer();
}
}
function download_submitted_video(){
$this->videos->download_video($_GET['video_id']);
}
function view(){
$this->header();
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
//Update views
if($this->videos->check_repstop($video_id, 'view') == false){
$this->videos->update_views($video_id, true);
}
$video = $this->videos->get_video($video_id);
$full_page_link = 'http://'.$_SERVER['HTTP_HOST'].(dirname($_SERVER['SCRIPT_NAME']) != '' ? dirname($_SERVER['SCRIPT_NAME']) : '').basename($_SERVER['SCRIPT_NAME']).'?name='.$this->module_name.'&op=view&video_id='.$video_id;
$full_stream_link = 'http://'.$_SERVER['HTTP_HOST'].(dirname($_SERVER['SCRIPT_NAME']) != '' ? dirname($_SERVER['SCRIPT_NAME']) : '').basename($_SERVER['SCRIPT_NAME']).'?name='.$this->module_name.'&op=download_stream&video_id='.$video_id;
$full_thumb_link = 'http://'.$_SERVER['HTTP_HOST'].(dirname($_SERVER['SCRIPT_NAME']) != '' ? dirname($_SERVER['SCRIPT_NAME']) : '').'modules/'.$this->module_name.'/files/thumbnails/'.$video_id.'_'.$video['file_thumbnail'];
$video['full_stream_link'] = urlencode($full_stream_link);
$video['html_link'] = htmlspecialchars('<a href="'.$full_page_link.'" target="_blank"></a><img src="'.$full_thumb_link.'" width=115></a><br><a href="'.$full_page_link.'" target="_blank">'.$this->languages->defines['click_to_view'].'</a>');
$video['bb_link'] = htmlspecialchars('[url='.$full_page_link.'][img]'.$full_thumb_link.'[/img][/url][url='.$full_page_link.']'.$this->languages->defines['click_to_view'].'[/url]');
$valid_ratings = array(5, 4, 3, 2, 1);
$is_user = is_user($this->user) ? true : false;
$this->vt->assign('comments', $this->videos->get_comments($video_id));
$this->vt->assign('is_user', $is_user);
$this->vt->assign('is_admin', is_admin($this->admin));
$this->vt->assign('submitted_by', $this->get_user_info($video['submitted_by']));
$this->vt->assign('valid_ratings', $valid_ratings);
$this->vt->assign('video', $video);
$this->vt->assign('video_player_template', $this->videos->determine_player($video['extension_converted'] != '' ? $video['extension_converted'] : $video['extension_video']).'.tpl');
$this->vt->display($this->base_path.'/templates/display_video.tpl');
$this->vt->display($this->base_path.'/templates/display_comments.tpl');
} else {
$this->vt->display($this->base_path.'/templates/video_noexist.tpl');
}
$this->footer();
}
function download_video(){
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$this->videos->download_video($video_id);
}
}
function download_converted(){
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$this->videos->download_converted($video_id);
}
}
function download_stream(){
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$this->videos->stream_converted($video_id);
}
}
function download_remote(){
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$this->videos->download_remote($video_id);
}
}
function rate_video(){
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$valid_ratings = array(1, 2, 3, 4, 5);
if(isset($_REQUEST['rating']) && in_array($_REQUEST['rating'], $valid_ratings)){
if($this->videos->check_repstop($video_id, 'rating') == false){
$this->videos->update_rating($video_id, $_REQUEST['rating'], true);
}
header('Location: '.basename($_SERVER['SCRIPT_NAME']).'?name='.$this->module_name.'&op=view&video_id='.$video_id);
}
}
}
function post_comment(){
$video_id = is_numeric($_POST['video_id']) ? $_POST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$this->videos->create_comment($video_id, $this->userinfo['user_id'], $_POST['subject'], $_POST['comment']);
header('Location: '.basename($_SERVER['SCRIPT_NAME']).'?name='.$this->module_name.'&op=view&video_id='.$video_id);
}
}
function delete_comment(){
$video_id = is_numeric($_GET['video_id']) ? $_GET['video_id'] : false;
$comment_id = is_numeric($_GET['comment_id']) ? $_GET['comment_id'] : false;
if($video_id !== false && $comment_id !== false && is_admin($this->admin)){
$this->videos->delete_comment($comment_id);
}
header('Location: '.basename($_SERVER['SCRIPT_NAME']).'?name='.$this->module_name.'&op=view&video_id='.$video_id);
}
function get_user_info($user_id){
if($user_id > 0){
$result_id = $this->db->sql_query("select * from ".$this->user_prefix."_users where user_id='".$user_id."'");
if($this->db->sql_numrows($result_id) > 0){
return $this->db->sql_fetchrow($result_id);
} else {
return false;
}
} else {
return false;
}
}
function view_user(){
if(is_numeric($_REQUEST['user_id'])){
$user_info = $this->get_user_info($_REQUEST['user_id']);
if($user_info !== false){
$this->vt->assign('user_info', $user_info);
$this->vt->assign('videos', $this->videos->get_user_videos($user_info['user_id']));
$this->header();
$this->vt->display($this->base_path.'/templates/view_user.tpl');
$this->footer();
}
}
}
function send_to_a_friend(){
switch($_REQUEST['action']){
case 'send':
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$sender_email = $_POST['sender_email'];
$receiver_email = $_POST['receiver_email'];
$this->vt->assign('sender_email', $sender_email);
$video = $this->videos->get_video($video_id);
$this->vt->assign('video', $video);
$url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'modules.php?name=Video&op=view&video_id='.$video_id;
$this->vt->assign('url', $url);
$message = $this->vt->generate($this->base_path.'/templates/mail_send_to_friend.tpl');
mail($receiver_email, $this->languages->defines['View_this_Video'], $message, 'From: '.$sender_email.'');
$this->header();
$this->vt->display($this->base_path.'/templates/sent_to_friend.tpl');
$this->footer();
}
break;
default:
$this->header();
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$video = $this->videos->get_video($video_id);
$this->vt->assign('video', $video);
$this->vt->display($this->base_path.'/templates/send_to_friend.tpl');
}
$this->footer();
break;
}
}
function report_broken(){
switch($_REQUEST['action']){
case 'submit':
$video_id = is_numeric($_POST['video_id']) ? $_POST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$ip = $_SERVER['REMOTE_ADDR'];
$description = htmlspecialchars($_POST['description']);
$video = $this->videos->get_video($video_id);
$this->vt->assign('video', $video);
$url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/modules.php?name=Video&op=view&video_id='.$video_id;
$this->vt->assign('url', $url);
$this->vt->assign('ip', $ip);
$this->vt->assign('description', $description);
$message = $this->vt->generate($this->base_path.'/templates/mail_report_broken.tpl');
mail($this->config['conf_email'], $this->languages->defines['Broken_Video'], $message, 'From: '.$this->config['conf_email'].'');
$this->header();
$this->vt->display($this->base_path.'/templates/report_thanks.tpl');
$this->footer();
}
break;
default:
$this->header();
$video_id = is_numeric($_REQUEST['video_id']) ? $_REQUEST['video_id'] : false;
if($video_id != false && $this->videos->video_exists_approve($video_id)){
$video = $this->videos->get_video($video_id);
$this->vt->assign('video', $video);
$this->vt->display($this->base_path.'/templates/report_broken.tpl');
}
$this->footer();
break;
}
}
function terms(){
$this->header();
$this->vt->display($this->base_path.'/templates/terms.tpl');
$this->footer();
}
}
?>
|
videos.php
Code:<?php
class vidmod_videos {
//Video player formats and valid extensions
var $video_formats = array('flv_player' => array('flv'),
'wmv_player' => array('wmv', 'avi', 'mpeg', 'mpg'),
'qt_player' => array('qt', 'mov'),
'real_player' => array('ra', 'rv', 'rm', 'rpm', 'ram')
);
var $thumb_formats = array('jpg', 'jpeg', 'gif', 'png');
function vidmod_videos(){
global $user, $db, $prefix, $user_prefix;
//PHPNuke functions / vars
$this->db = &$db;
$this->prefix = &$prefix;
$this->user_prefix = &$user_prefix;
$this->user = &$user;
$this->userinfo = is_user($user) ? getusrinfo($user) : array();
//Module specific
$this->file_path = dirname(__FILE__);
require_once(dirname(__FILE__).'/settings.php');
$this->settings = new vidmod_settings();
$this->config = $this->settings->get_settings();
$this->domain_video_path = 'modules/Video/files/videos/';
$this->domain_thumbnail_path = 'modules/Video/files/thumbnails/';
$this->domain_converted_path = 'modules/Video/files/converted/';
$this->video_path = $this->file_path.'/files/videos/';
$this->thumbnail_path = $this->file_path.'/files/thumbnails/';
$this->converted_path = $this->file_path.'/files/converted/';
$this->ftp_video_path = $this->file_path.'/files/ftp/videos/';
$this->ftp_thumbnail_path = $this->file_path.'/files/ftp/thumbnails/';
$this->ftp_converted_path = $this->file_path.'/files/ftp/converted/';
}
function create_submitted_video($name, $description, $video_file, $remote_link, $user_id, $submitter_email){
$this->db->sql_query("insert into ".$this->prefix."_vidmod_videos values (null, 0, '".htmlspecialchars($name, ENT_QUOTES)."', '".htmlspecialchars($description, ENT_QUOTES)."', '', '', '', '".htmlspecialchars($remote_link, ENT_QUOTES)."', '0', '0', '0', '0', '".$this->config['defaultchk_dl_original']."', '".$this->config['defaultchk_stream_converted']."', '".$user_id."', '".htmlspecialchars($submitter_email, ENT_QUOTES)."', ".time().", '0')");
$video_id = $this->db->sql_nextid();
$filename = $this->upload_video($video_id, $video_file);
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_video='".mysql_escape_string($filename)."' where id=".$video_id."");
return $video_id;
}
function create_ftp_video($category_id, $video_file, $upload_video_file, $remote_link, $converted_file, $upload_converted_file, $thumb_file, $upload_thumb_file, $name, $description, $allow_dl_original, $stream_converted){
$this->db->sql_query("insert into ".$this->prefix."_vidmod_videos values (null, '".$category_id."', '".htmlspecialchars($name, ENT_QUOTES)."', '".htmlspecialchars($description, ENT_QUOTES)."', '', '', '', '".htmlspecialchars($remote_link, ENT_QUOTES)."', '0', '0', '0', '0', '".$allow_dl_original."', '".$stream_converted."', '0', '', ".time().", '1')");
$video_id = $this->db->sql_nextid();
if($video_file != ''){
$new_video_file = $video_id.'_'.$video_file;
rename($this->ftp_video_path.$video_file, $this->video_path.$new_video_file);
}
if($converted_file != ''){
$new_converted_file = $video_id.'_'.$converted_file;
rename($this->ftp_converted_path.$converted_file, $this->converted_path.$new_converted_file);
}
if($thumb_file != ''){
$new_thumb_file = $video_id.'_'.$thumb_file;
rename($this->ftp_thumbnail_path.$thumb_file, $this->thumbnail_path.$new_thumb_file);
}
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_video='".mysql_real_escape_string($video_file)."', file_converted='".mysql_real_escape_string($converted_file)."', file_thumbnail='".mysql_real_escape_string($thumb_file)."' where id='".$video_id."'");
$name_video_file = $this->upload_video($video_id, $upload_video_file);
if($name_video_file != '')
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_video='".mysql_escape_string($name_video_file)."' where id=".$video_id."");
$name_converted_file = $this->upload_converted($video_id, $upload_converted_file);
if($name_converted_file != '')
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_converted='".mysql_escape_string($name_converted_file)."' where id=".$video_id."");
$name_thumb_file = $this->upload_thumbnail($video_id, $upload_thumb_file);
if($name_thumb_file != '')
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_thumbnail='".mysql_escape_string($name_thumb_file)."' where id=".$video_id."");
}
function upload_video($video_id, $file){
$temp_file = $file['tmp_name'];
$file_name = '';
if(is_uploaded_file($temp_file)){
$file_name = $file['name'];
$video_file = $video_id.'_'.$file_name;
@unlink($this->video_path.$video_id.$video_file);
move_uploaded_file($temp_file, $this->video_path.$video_file);
@chmod($this->video_path.$video_file, 0777);
}
return $file_name;
}
function upload_converted($video_id, $file){
//Stop upload from timing out
set_time_limit(0);
$temp_file = $file['tmp_name'];
$file_name = '';
if(is_uploaded_file($temp_file)){
$file_name = $file['name'];
$video_info = $this->get_video($video_id);
$converted_file = $video_id.'_'.$file_name;
@unlink($this->converted_path.$video_id.'_'.$video_info['file_converted']);
move_uploaded_file($temp_file, $this->converted_path.$converted_file);
@chmod($this->converted_path.$video_id.$converted_file, 0777);
}
return $file_name;
}
function upload_thumbnail($video_id, $file){
//Stop upload from timing out
set_time_limit(0);
$temp_file = $file['tmp_name'];
$file_name = '';
if(is_uploaded_file($temp_file)){
$file_name = $file['name'];
$video_info = $this->get_video($video_id);
@unlink($this->thumbnail_path.$video_id.'_'.$video_info['file_thumbnail']);
@unlink($this->thumbnail_path.$video_id.'_'.$file['name']);
move_uploaded_file($temp_file, $this->thumbnail_path.$video_id.'_'.$file['name']);
@chmod($this->thumbnail_path.$video_id.'_'.$file['name'], 0777);
}
return $file_name;
}
function update_video($video_id, $update_array){
//Lazy video updater
if($this->video_exists($video_id)){
foreach($update_array as $key => $value){
if($key == 'file_thumbnail'){
if($value != null || $value != ''){
$value = $this->upload_thumbnail($video_id, $value);
} else {
$value = null;
}
} else if($key == 'file_converted'){
if($value != null || $value != ''){
$value = $this->upload_converted($video_id, $value);
} else {
$value = null;
}
}
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set ".$key."='".$value."' where id=".$video_id."");
}
}
}
function update_ftp_thumbnail($video_id, $file){
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_thumbnail='".$file."' where id=".$video_id."");
}
function update_ftp_converted($video_id, $file){
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set file_converted='".$file."' where id=".$video_id."");
}
function video_exists($video_id){
//check if video exists
if(is_numeric($video_id)){
$result_id = $this->db->sql_query("select id from ".$this->prefix."_vidmod_videos where id=".$video_id."");
if($this->db->sql_numrows($result_id) == 1){
return true;
}
}
return false;
}
function video_exists_approve($video_id){
if(is_numeric($video_id)){
$result_id = $this->db->sql_query("select id from ".$this->prefix."_vidmod_videos where id=".$video_id." and approved=1");
if($this->db->sql_numrows($result_id) == 1){
return true;
}
}
return false;
}
function approve_video($video_id){
//Email user here.
$this->update_video($video_id, array('approved' => 1));
}
function reject_video($video_id, $reason){
//Email here
$this->delete_video($video_id);
}
function delete_video($video_id){
//delete video
if(is_numeric($video_id)){
$video_info = $this->get_video($video);
$this->db->sql_query("delete from ".$this->prefix."_vidmod_videos where id=".$video_id."");
@unlink($this->video_path.$video_id.'_'.$video_info['file_video']);
@unlink($this->converted_path.$video_id.'_'.$video_info['file_converted']);
@unlink($this->thumbnail_path.$video_id.'_'.$video_info['file_thumbnail']);
}
}
function get_all_submitted_videos(){
//get video information
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=0 order by date_created");
while($video = $this->db->sql_fetchrow($result_id)){
$video['file_size'] = @filesize($this->video_path.$video['id'].'_'.$video['file_video']);
$videos[] = $video;
}
return $videos;
}
function rate_round($rating){
return round($rating);
}
function get_video($video_id){
//get video information
$video_info = array();
if(is_numeric($video_id)){
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where id=".$video_id."");
$video_info = $this->db->sql_fetchrow($result_id);
if($video_info['remote_link'] != ''){
$video_info['extension_video'] = strtolower(array_pop(explode(".", $video_info['remote_link'])));
$video_info['extension_converted'] = strtolower(array_pop(explode(".", $video_info['remote_link'])));
} else {
$video_info['extension_video'] = strtolower(array_pop(explode(".", $video_info['file_video'])));
$video_info['extension_converted'] = strtolower(array_pop(explode(".", $video_info['file_converted'])));
}
$video_info['comment_count'] = $this->count_comments($video['id']);
$video_info['rate_round'] = $this->rate_round($video_info['rating_avg']);
}
return $video_info;
}
function get_hottest($start, $end){
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=1 order by rating_avg desc limit ".$this->config['most_videomax']."");
$count = 0;
while($video = $this->db->sql_fetchrow($result_id)){
$count++;
if($count >= $start && $count <= $end){
$video['comment_count'] = $this->count_comments($video['id']);
$video['rate_round'] = $this->rate_round($video['rating_avg']);
$videos[] = $video;
}
}
$this->temp_count = $this->db->sql_numrows($result_id);
return $videos;
}
function get_recent($start, $end){
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=1 order by date_created desc limit ".$this->config['most_videomax']."");
$count = 0;
while($video = $this->db->sql_fetchrow($result_id)){
$count++;
if($count >= $start && $count <= $end){
$video['comment_count'] = $this->count_comments($video['id']);
$video['rate_round'] = $this->rate_round($video['rating_avg']);
$videos[] = $video;
}
}
$this->temp_count = $this->db->sql_numrows($result_id);
return $videos;
}
function get_most_viewed($start, $end){
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=1 order by views desc limit ".$this->config['most_videomax']."");
$count = 0;
while($video = $this->db->sql_fetchrow($result_id)){
$count++;
if($count >= $start && $count <= $end){
$video['comment_count'] = $this->count_comments($video['id']);
$video['rate_round'] = $this->rate_round($video['rating_avg']);
$videos[] = $video;
}
}
$this->temp_count = $this->db->sql_numrows($result_id);
return $videos;
}
function get_category_videos($category_id, $start, $end){
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=1 and category_id=".$category_id." order by id desc");
$count = 0;
while($video = $this->db->sql_fetchrow($result_id)){
$count++;
if($count >= $start && $count <= $end){
$video['comment_count'] = $this->count_comments($video['id']);
$video['rate_round'] = $this->rate_round($video['rating_avg']);
$videos[] = $video;
}
}
$this->temp_count = $this->db->sql_numrows($result_id);
return $videos;
}
function get_user_videos($user_id){
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=1 and submitted_by='".$user_id."' order by id desc");
$count = 0;
$count = 0;
while($video = $this->db->sql_fetchrow($result_id)){
$video['comment_count'] = $this->count_comments($video['id']);
$video['rate_round'] = $this->rate_round($video['rating_avg']);
$videos[] = $video;
}
$this->temp_count = $this->db->sql_numrows($result_id);
return $videos;
}
function get_search_videos($query){
$videos = array();
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_videos where approved=1 and name like '%".mysql_real_escape_string($query)."%' or description like '%".mysql_real_escape_string($query)."%' order by id desc");
$count = 0;
while($video = $this->db->sql_fetchrow($result_id)){
$video['comment_count'] = $this->count_comments($video['id']);
$video['rate_round'] = $this->rate_round($video['rating_avg']);
$videos[] = $video;
}
$this->temp_count = $this->db->sql_numrows($result_id);
return $videos;
}
function create_comment($video_id, $user_id, $subject, $content){
//create a comment for a specific video
if($this->video_exists($video_id)){
$this->db->sql_query("insert into ".$this->prefix."_vidmod_comments values (null, ".$video_id.", ".$user_id.", '".htmlspecialchars($subject)."', '".htmlspecialchars($content)."', ".time().")");
}
}
function delete_comment($comment_id){
//simply delete a comment
if(is_numeric($comment_id)){
$this->db->sql_query("delete from ".$this->prefix."_vidmod_comments where id=".$comment_id."");
}
}
function get_comments($video_id){
$comments = array();
if(is_numeric($video_id)){
$result_id = $this->db->sql_query("select c.id, c.video_id, c.user_id, u.username, c.subject, c.content, c.date_posted from ".$this->prefix."_vidmod_comments c, ".$this->user_prefix."_users u where c.video_id=".$video_id." and c.user_id=u.user_id order by c.date_posted");
while($comment = $this->db->sql_fetchrow($result_id)){
$comments[] = $comment;
}
}
return $comments;
}
function count_comments($video_id){
if(is_numeric($video_id)){
$result_id = $this->db->sql_query("select id from ".$this->prefix."_vidmod_comments where video_id=".$video_id."");
return $this->db->sql_numrows($result_id);
}
return 0;
}
function update_views($video_id, $add_repstop = false){
//if valid video, update view count
if($this->video_exists($video_id)){
$video_info = $this->get_video($video_id);
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set views=".($video_info['views'] + 1)." where id=".$video_id."");
}
//if add_repstop is true, add ip of viewer to repstop list
if($add_repstop){
$this->add_repstop($video_id, 'view');
}
}
function update_rating($video_id, $score, $add_repstop = false){
//if valid rating and video, update score and rating count
if($this->valid_rating($score) && $this->video_exists($video_id)){
$video_info = $this->get_video($video_id);
$rating_score = $video_info['rating_score'] + $score;
$rating_count = $video_info['rating_count'] + 1;
if($rating_count != 0){
$rating_avg = $rating_score / $rating_count;
} else {
$rating_avg = 0;
}
$this->db->sql_query("update ".$this->prefix."_vidmod_videos set rating_score=".$rating_score.", rating_count=".$rating_count.", rating_avg=".$rating_avg." where id='".$video_id."'");
}
//if add_repstop is true, add ip of rater to repstop list
if($add_repstop){
$this->add_repstop($video_id, 'rating');
}
}
function check_repstop($video_id, $action = null){
//if video exists, get repstop count, and return true if user has committed action to video
$result_id = $this->db->sql_query("select * from ".$this->prefix."_vidmod_repstop where video_id=".$video_id." and action='".mysql_escape_string($action)."' and ip_address='".$_SERVER['REMOTE_ADDR']."'");
if($this->db->sql_numrows($result_id) == 0){
return false;
}
return true;
}
function valid_rating($score){
//checks for a valid score
if(is_numeric($score) && $score >= 1 && $score <= 5){
return true;
}
return false;
}
function add_repstop($video_id, $action){
//add ip address and action to video
if(is_numeric($video_id)){
$this->db->sql_query("insert into ".$this->prefix."_vidmod_repstop values (".$video_id.", '".mysql_escape_string($action)."', '".$_SERVER['REMOTE_ADDR']."', ".time().")");
}
}
function download_video($video_id){
if($this->video_exists($video_id)){
$video_info = $this->get_video($video_id);
$file = $this->domain_video_path.$video_id.'_'.$video_info['file_video'];
header('Location: '.$file);
} else {
die();
}
}
function stream_converted($video_id){
if($this->video_exists($video_id)){
$video_info = $this->get_video($video_id);
if($video_info['remote_link'] != ''){
$file = $video_info['remote_link'];
} else {
if($video_info['file_converted'] != ''){
$file = $this->domain_converted_path.$video_id.'_'.$video_info['file_converted'];
} else if($this->config['global_stream_original'] == 1){
$file = $this->domain_video_path.$video_id.'_'.$video_info['file_video'];
}
}
header('Location: '.$file);
} else {
die();
}
}
function download_converted($video_id){
if($this->video_exists($video_id)){
$video_info = $this->get_video($video_id);
$file = $this->domain_converted_path.$video_id.'_'.$video_info['file_converted'];
header('Location: '.$file);
} else {
die();
}
}
function download_remote($video_id){
if($this->video_exists($video_id)){
$video_info = $this->get_video($video_id);
$file = $video_info['remote_link'];
header('Location: '.$file);
} else {
die();
}
}
function get_random_videos($number){
$videos = array();
if($number > 0){
$result_id = $this->db->sql_query("select id from ".$this->prefix."_vidmod_videos where approved=1");
$all_videos = array();
while($temp_video = $this->db->sql_fetchrow($result_id)){
$all_videos[] = $temp_video['id'];
}
if(count($all_videos) > 0){
if(count($all_videos) < $number)
$number = count($all_videos);
$vid_ids = array_rand($all_videos, $number);
if(!is_array($vid_ids)){
$vid_ids = array($vid_ids);
}
foreach($vid_ids as $key => $id){
$video = $this->get_video($all_videos[$id]);
$video['comment_count'] = $this->count_comments($all_videos[$id]);
$videos[] = $video;
}
}
}
return $videos;
}
function get_recent_videos($number){
$videos = array();
if($number > 0){
$result_id = $this->db->sql_query("select id from ".$this->prefix."_vidmod_videos where approved=1 order by id desc limit ".$number." ");
while($temp_video = $this->db->sql_fetchrow($result_id)){
$video = $this->get_video($temp_video['id']);
$video['comment_count'] = $this->count_comments($temp_video['id']);
$videos[] = $video;
}
}
return $videos;
}
function check_valid_file($filename){
//This checks whether or not the file name is valid and if the extension
//is that off a file we want uploaded.
if(!preg_match('/^[a-zA-Z0-9_.\-()]*$/', $filename))
return 'bad_file_name';
//Get file extension
$file_extension = strtolower(array_pop(explode(".", $filename)));
foreach($this->video_formats as $video_player){
foreach($video_player as $video_extension){
if($video_extension == $file_extension){
return true;
}
}
}
return 'invalid_extension';
}
function check_valid_thumb($filename){
//This checks whether or not the file name is valid and if the extension
//is that off a file we want uploaded.
if(!preg_match('/^[a-zA-Z0-9_.\-()]*$/', $filename))
return 'bad_file_name';
//Get file extension
$file_extension = strtolower(array_pop(explode(".", $filename)));
foreach($this->thumb_formats as $format){
if($format == $file_extension){
return true;
}
}
return 'invalid_extension';
}
function determine_player($ext){
foreach($this->video_formats as $key => $video_format){
if(in_array($ext, $video_format)){
return $key;
}
}
return false;
}
}
?>
|
|
|
|