clipbucket/upload/includes/classes/my_queries.class.php

683 lines
17 KiB
PHP
Raw Normal View History

2009-08-25 12:16:42 +00:00
<?php
/**
***************************************************************************************************
* @Software ClipBucket
* @Authoer ArslanHassan
* @copyright Copyright (c) 2007-2009 {@link http://www.clip-bucket.com}
* @license http://www.clip-bucket.com
* @version Lite
* @since 2007-10-15
* @License CBLA
**************************************************************************************************
This Source File Is Written For ClipBucket, Please Read its End User License First and Agree its
Terms of use at http://clip-bucket.com/cbla
**************************************************************************************************
Copyright (c) 2007-2008 Clip-Bucket.com. All rights reserved.
**************************************************************************************************
check_user
check_email
DeleteFlv
DeleteOriginal
DeleteThumbs
DeleteVideoFiles
UpdateVideo
GetCategory
RateVideo
AddComment
AddToFavourite
FlagAsInappropriate
DeleteFlag
2009-08-25 12:16:42 +00:00
**/
/**
* Function used to return db table name with prefix
* @param : table name
* @return : prefix_table_name;
*/
function tbl($tbl)
{
$prefix = TABLE_PREFIX;
$tbls = explode(",",$tbl);
$new_tbls = "";
foreach($tbls as $ntbl)
{
if(!empty($new_tbls))
$new_tbls .= ",";
$new_tbls .= $prefix.$ntbl;
}
return $new_tbls;
}
2009-08-25 12:16:42 +00:00
class myquery {
function Set_Website_Details($name,$value){
//mysql_query("UPDATE config SET value = '".$value."' WHERE name ='".$name."'");
global $db,$Cbucket;
$db->update(tbl("config"),array('value'),array($value)," name = '".$name."'");
$Cbucket->configs = $Cbucket->get_configs();
2009-08-25 12:16:42 +00:00
}
function Get_Website_Details()
{
$query = mysql_query("SELECT * FROM ".tbl("config"));
while($row = mysql_fetch_array($query))
{
$name = $row['name'];
$data[$name] = $row['value'];
}
return $data;
2009-08-25 12:16:42 +00:00
}
2009-08-25 12:16:42 +00:00
//Function Used to Check Weather Video Exists or not
function VideoExists($videoid){global $cbvid;return $cbvid->exists($videoid);}
function video_exists($videoid){return $this->VideoExists($videoid);}
function CheckVideoExists($videokey){return $this->VideoExists($videokey);}
2009-08-25 12:16:42 +00:00
//Function used to Delete Video
2009-08-25 12:16:42 +00:00
function DeleteVideo($videoid){
global $cbvid;
return $cbvid->delete_video($videoid);
2009-08-25 12:16:42 +00:00
}
//Video Actions - All Moved to video.class.php
function MakeFeaturedVideo($videoid){global $cbvid;return $cbvid->action('feature',$videoid);}
function MakeUnFeaturedVideo($videoid){global $cbvid;return $cbvid->action('unfeature',$videoid);}
function ActivateVideo($videoid){global $cbvid;return $cbvid->action('activate',$videoid);}
function DeActivateVideo($videoid){global $cbvid;return $cbvid->action('deactivate',$videoid);}
2009-08-25 12:16:42 +00:00
/**
* Function used to get video details
* from video table
* @param INPUT vid or videokey
*/
function get_video_details($vid){global $cbvid;return $cbvid->get_video($vid);}
function GetVideoDetails($video){return $this->get_video_details($video);}
function GetVideDetails($video){return $this->get_video_details($video);}
2009-08-25 12:16:42 +00:00
//Function Used To Update Videos Views
function UpdateVideoViews($vkey){increment_views($vkey,'video');}
2009-08-25 12:16:42 +00:00
/**
* Function used to check weather username exists not
*/
function check_user($username){
global $userquery;
return $userquery->username_exists($username);
}
/**
* Function used to check weather email exists not
*/
function check_email($email){
global $userquery;
return $userquery->email_exists($email);
}
2009-08-25 12:16:42 +00:00
/**
* Function used to delete comments
* @param CID
*/
function delete_comment($cid,$type='v',$is_reply=FALSE,$forceDelete=false)
2009-08-25 12:16:42 +00:00
{
global $db,$userquery,$LANG;
//first get comment details
$cdetails = $this->get_comment($cid);
2009-08-25 12:16:42 +00:00
$uid = user_id();
if(($uid == $cdetails['userid'] && $cdetails['userid']!='')
|| $cdetails['type_owner_id'] == userid()
|| has_access("admin_del_access",false)
|| $is_reply==TRUE || $forceDelete)
2009-08-25 12:16:42 +00:00
{
$replies = $this->get_comments($cdetails['type_id'],$type,FALSE,$cid,TRUE);
if(count($replies)>0 && is_array($replies))
{
foreach($replies as $reply)
{
$this->delete_comment($reply['comment_id'],$type,TRUE,$forceDelete);
2009-08-25 12:16:42 +00:00
}
}
$db->Execute("DELETE FROM ".tbl("comments")." WHERE comment_id='$cid'");
/*if($uid)
$myquery->update_comments_by_user($uid);*/
e(lang('usr_cmt_del_msg'),"m");
return $cdetails['type_id'];
2009-08-25 12:16:42 +00:00
}else{
e(lang('no_comment_del_perm'));
return false;
2009-08-25 12:16:42 +00:00
}
return false;
2009-08-25 12:16:42 +00:00
}
function DeleteComment($id,$videoid){return $this->delete_comment($videoid);}
/**
* Function used to set comment as spam
*/
function spam_comment($cid)
{
global $db;
$comment = $this->get_comment($cid);
$uid = user_id();
if($comment)
{
$voters = $comment['spam_voters'];
$niddle = "|";
$niddle .= userid();
$niddle .= "|";
$flag = strstr($voters, $niddle);
if(!$comment)
e(lang('no_comment_exists'));
elseif(!userid())
e(lang('login_to_mark_as_spam'));
elseif(userid()==$comment['userid'] || (!userid() && $_SERVER['REMOTE_ADDR'] == $comment['comment_ip']))
e(lang('no_own_commen_spam'));
elseif(!empty($flag))
e(lang('already_spammed_comment'));
else
{
if(empty($voters))
$voters .= "|";
$voters .= userid();
$voters.= "|";
$newscore = $comment['spam_votes']+1;
$db->update(tbl('comments'),array('spam_votes','spam_voters'),array($newscore,$voters)," comment_id='$cid'");
e(lang('spam_comment_ok'),"m");
return $newscore;
}
}
e(lang('no_comment_exists'));
return false;
}
/**
* Function used to delete all comments of particlar object
*/
function delete_comments($objid,$type='v',$forceDelete=false)
{
global $db,$userquery,$LANG;
$uid = user_id();
if($userquery->permission['admin_del_access'] == 'yes' || $forceDelete)
{
$db->Execute("DELETE FROM ".tbl("comments")." WHERE type_id='$objid' AND type='$type' ");
e(lang('usr_cmt_del_msg'),m);
return true;
}else{
e(lang('no_comment_del_perm'));
return false;
}
return false;
}
/***
* Function used to rate comment
***/
function rate_comment($rate,$cid)
{
global $db;
$comment = $this->get_comment($cid);
$voters = $comment['voters'];
$niddle = "|";
$niddle .= userid();
$niddle .= "|";
$flag = strstr($voters, $niddle);
if(!$comment)
e(lang('no_comment_exists'));
elseif(!userid())
e(lang('class_comment_err6'));
elseif(userid()==$comment['userid'] || (!userid() && $_SERVER['REMOTE_ADDR'] == $comment['comment_ip']))
e(lang('no_own_commen_rate'));
elseif(!empty($flag))
e(lang('class_comment_err7'));
else
{
if(empty($voters))
$voters .= "|";
$voters .= userid();
$voters.= "|";
$newscore = $comment['vote']+$rate;
$db->update(tbl('comments'),array('vote','voters'),array($newscore,$voters)," comment_id='$cid'");
e(lang('thanks_rating_comment'),"m");
return $newscore;
2009-08-25 12:16:42 +00:00
}
return false;
}
2009-08-25 12:16:42 +00:00
//Function Used To Varify Syntax
function isValidSyntax($syntax){
global $LANG;
$pattern = "^^[_a-z0-9-]+$";
if (eregi($pattern, $syntax)){
return true;
}else {
return false;
}
}
/**
* FUNCTION USED TO GET VIDEOS FROM DATABASE
* @param: array of query parameters array()
* featured => '' (yes,no)
* username => '' (TEXT)
* title => '' (TEXT)
* tags => '' (TEXT)
* category => '' (INT)
* limit => '' (OFFSET,LIMIT)
* order=>'' (BY SORT) -- (date_added DESC)
* extra_param=>'' ANYTHING FOR MYSQL QUERY
* @param: boolean
* @param: results type (results,query)
*/
function getVideoList($param=array(),$global_cond=true,$result='results')
{
global $db;
$sql = "SELECT * FROM video";
//Global Condition For Videos
if($global_cond==true)
$cond = "broadcast='public' AND active='yes' AND status='Successful'";
//Checking Condition
if(!empty($param['featured']))
{
$param['featured'] = 'yes' ? 'yes' : 'no';
$cond .=" AND featured= '".$param['featured']."' ";
}
if(!empty($param['username']))
{
$username = mysql_clean($param['username']);
$cond .=" AND featured= '".$username."' ";
}
if(!empty($param['category']))
{
$category = intval($param['category']);
$cond .=" AND (category01= '".$category."' OR category02= '".$category."' OR category03= '".$category."') ";
}
if(!empty($param['tags']))
{
$tags = mysql_clean($param['tags']);
$cond .=" AND tags LIKE '%".$tags."%' ";
}
if(!empty($param['title']))
{
$tags = mysql_clean($param['tags']);
$cond .=" AND title LIKE '%".$param['title']."%' ";
}
//Adding Condition in Query
if(!empty($cond))
$sql .= " WHERE $cond ";
//SORTING VIDEOS
if(!empty($param['order']))
$sort = 'ORDER BY '.$param['order'];
//Adding Sorting In Query
$sql .= $sort;
//LIMITING VIDEO LIST
if(empty($param['limit']))
$limit = " LIMIT ". VLISTPP;
elseif($param['limit']=='nolimit')
$limit = '';
else
$limit = " LIMIT ".$param['limit'];
$sql .= $limit;
//Final Executing of Query and Returning Results
if($result=='results')
return $db->Execute($sql);
else
return $sql;
}
2009-08-25 12:16:42 +00:00
/**
* Function used to send subsribtion message
*/
function send_subscription($subscriber,$from,$video)
{
global $LANG;
//First checking weather $subscriber exists or not
$array = array('%subscriber%','%user%','%website_title%');
$replace = array($subscriber,$from,TITLE);
$to = $subscriber;
$subj = str_replace($array,$replace,lang('user_subscribe_subject'));
2009-08-25 12:16:42 +00:00
//Get Subscription Message Template
$msg = get_subscription_template();
$msg = str_replace($array,$replace,$msg);
$this->SendMessage($to,$from,$subj,$msg,$video,0,0);
}
/**
* Function used to add comment
* This is more advance function ,
* in this function functions can be applied on comments
*/
function add_comment($comment,$obj_id,$reply_to=NULL,$type='v',$obj_owner=NULL)
2009-08-25 12:16:42 +00:00
{
global $userquery,$eh,$db,$Cbucket;
2009-08-25 12:16:42 +00:00
//Checking maximum comments characters allowed
if(defined("MAX_COMMENT_CHR"))
{
if(strlen($comment) > MAX_COMMENT_CHR)
e(sprintf("'%d' characters allowed for comment",MAX_COMMENT_CHR));
}
if(empty($comment))
e("Please enter something for comment");
$params = array('comment'=>$comment,'obj_id'=>$obj_id,'reply_to'=>$reply_to,'type'=>$type);
$this->validate_comment_functions($params);
/*
2009-08-25 12:16:42 +00:00
if($type=='video' || $type=='v')
{
if(!$this->video_exists($obj_id))
e("Video does not exist");
//Checking owner of video
if(!USER_COMMENT_OWN)
{
if(userid()==$this->get_vid_owner($obj_id));
e("You cannot comment on your video");
}
}
*/
if(!userid() && $Cbucket->configs['anonym_comments']!='yes')
2009-08-25 12:16:42 +00:00
e("You are not logged in");
if(!userid() && $Cbucket->configs['anonym_comments']=='yes')
{
//Checking for input name and email
if(empty($_POST['name']))
e("Please enter your name");
if(empty($_POST['email']))
e("Please enter your email");
$name = mysql_clean($_POST['name']);
$email = mysql_clean($_POST['email']);
}
2009-08-25 12:16:42 +00:00
if(empty($eh->error_list))
{
$db->insert(tbl("comments"),array
('type,comment,type_id,userid,date_added,parent_id,anonym_name,anonym_email','comment_ip','type_owner_id'),
2009-08-25 12:16:42 +00:00
array
($type,$comment,$obj_id,userid(),NOW(),$reply_to,$name,$email,$_SERVER['REMOTE_ADDR'],$obj_owner));
$db->update(tbl("users"),array("total_comments"),array("|f|total_comments+1")," userid='".userid()."'");
2009-08-25 12:16:42 +00:00
e("Comment has been added",m);
$cid = $db->insert_id();
return $cid;
2009-08-25 12:16:42 +00:00
}
return false;
2009-08-25 12:16:42 +00:00
}
2009-08-25 12:16:42 +00:00
/**
* Function used to get file details from database
*/
function file_details($file_name)
{
global $db;
return get_file_details($file_name);
/*$results = $db->select("video_files","*"," src_name='$file_name'");
2009-08-25 12:16:42 +00:00
if($db->num_rows==0)
return false;
else
{
return $results[0];
}*/
2009-08-25 12:16:42 +00:00
}
/**
* Function used to update video and set a thumb as default
* @param VID
* @param THUMB NUM
*/
function set_default_thumb($vid,$thumb)
{
global $cbvid;
return $cbvid->set_default_thumb($vid,$thumb);
2009-08-25 12:16:42 +00:00
}
/**
* Function used to update video
*/
function update_video()
{
global $cbvid;
return $cbvid->update_video();
2009-08-25 12:16:42 +00:00
}
/**
* Function used to get categorie details
*/
function get_category($id)
{
global $db;
$results = $db->select(tbl("category"),"*"," categoryid='$id'");
2009-08-25 12:16:42 +00:00
return $results[0];
}
/**
* Function used to get comment from its ID
* @param ID
*/
function get_comment($id)
{
global $db,$userquery;
$result = $db->select(tbl("comments"),"*"," comment_id='$id'");
2009-08-25 12:16:42 +00:00
if($db->num_rows>0)
{
$result = $result[0];
if($result['userid'])
$udetails = $userquery->get_user_details($result['userid']);
if($udetails)
$result = array_merge($result,$udetails);
return $result ;
2009-08-25 12:16:42 +00:00
}else{
return false;
}
}
/**
* Function used to get from database
* @param TYPE_ID
* @param TYPE
* @param COUNT_ONLY Boolean
* @param PARENT_ID
* @param GET_REPLYIES_ONLY Boolean
*/
function get_comments($type_id,$type='v',$count_only=FALSE,$parent_id=NULL,$get_reply_only=FALSE)
{
global $db;
$cond = '';
#Checking if user wants to get replies of comment
if($parent_id!=NULL && $get_reply_only)
{
$cond .= " AND parent_id='$parent_id'";
}
if($type_id!='wildcard')
2010-01-23 13:50:53 +00:00
$typeid_query = "AND type_id='$type_id' ";
2009-08-25 12:16:42 +00:00
if(!$count_only)
2009-08-25 12:16:42 +00:00
{
//Fetching comments by registered users
$result = $db->select(tbl("comments,users"),"*"," type='$type' $typeid_query AND ".tbl("comments.userid")." = ".tbl("users.userid")." $cond");
//Fetchign comments by anonymous users
$result_anonym = $db->select(tbl("comments"),"*"," type='$type' $typeid_query AND ".tbl("comments.userid")." = '0' $cond");
//Mergin both arrays
if(is_array($result) && is_array($result_anonym))
$result = array_merge($result,$result_anonym);
elseif(is_array($result_anonym))
$result = $result_anonym;
//Sorting
$new_results = array();
if(is_array($result))
foreach($result as $r)
{
$new_results[$r['comment_id']] = $r;
}
//Sorting wrt keys..
ksort($new_results);
//pr($result);pr($new_results);
//pr($new_results);
if(count($new_results) > 0)
{
return $new_results;
}else{
return '';
}
}else
{
return $db->count(tbl("comments"),"*"," type='$type' $typeid_query $cond");
2009-08-25 12:16:42 +00:00
}
}
/**
* Function used to get video owner
*/
function get_vid_owner($vid)
{
global $db;
$results = $db->select(tbl("video"),"userid"," videoid='$vid'");
2009-08-25 12:16:42 +00:00
return $results[0];
}
/**
* Function used to set website template
*/
function set_template($template)
{
global $myquery;
if(is_dir(STYLES_DIR.'/'.$template) &&template)
{
$myquery->Set_Website_Details('template_dir',$template);
e("Template has been activated",m);
}else
e("An error occured while changing the template");
}
/**
* Function used to update comment
*/
function update_comment($cid,$text)
{
global $db;
$db->Execute("UPDATE ".tbl("comments")." SET comment='$text' WHERE comment_id='$cid'");
}
/**
* Function used to validate comments
*/
function validate_comment_functions($params)
{
$type = $params['type'];
$obj_id = $params['obj_id'];
$comment = $params['comment'];
$reply_to = $params['reply_to'];
if($type=='video' || $type=='v')
{
if(!$this->video_exists($obj_id))
e("Video does not exist");
//Checking owner of video
if(!USER_COMMENT_OWN)
{
if(userid()==$this->get_vid_owner($obj_id));
e("You cannot comment on your video");
}
}
$func_array = get_functions('validate_comment_functions');
if(is_array($func_array))
{
foreach($func_array as $func)
{
if(function_exists($func))
{
return $func($params);
}
}
}
}
/**
* Function used to insert note in data base for admin referance
*/
function insert_note($note)
{
global $db;
$db->insert(tbl('admin_notes'),array('note,date_added,userid'),array($note,now(),userid()));
}
/**
* Function used to get notes
*/
function get_notes()
{
global $db;
return $db->select(tbl('admin_notes'),'*'," userid='".userid()."'",NULL," date_added DESC ");
}
/**
* Function usde to delete note
*/
function delete_note($id)
{
global $db;
$db->delete(tbl("admin_notes"),array("note_id"),array($id));
}
2009-08-25 12:16:42 +00:00
}
?>