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
2010-03-16 18:56:41 +00:00
Terms of use at http :// www . opensource . org / licenses / attribution . php
2009-08-25 12:16:42 +00:00
**************************************************************************************************
Copyright ( c ) 2007 - 2008 Clip - Bucket . com . All rights reserved .
**************************************************************************************************
2010-01-06 11:59:41 +00:00
2009-10-10 14:25:07 +00:00
check_user
check_email
DeleteFlv
DeleteOriginal
DeleteThumbs
DeleteVideoFiles
UpdateVideo
GetCategory
RateVideo
AddComment
AddToFavourite
FlagAsInappropriate
DeleteFlag
2009-08-25 12:16:42 +00:00
**/
2010-02-06 14:10:53 +00:00
/**
* Function used to return db table name with prefix
* @ param : table name
* @ return : prefix_table_name ;
*/
2010-03-01 14:33:21 +00:00
2010-02-06 14:10:53 +00:00
function tbl ( $tbl )
{
2010-02-21 20:40:26 +00:00
global $DBNAME ;
2010-02-06 14:10:53 +00:00
$prefix = TABLE_PREFIX ;
$tbls = explode ( " , " , $tbl );
$new_tbls = " " ;
foreach ( $tbls as $ntbl )
{
if ( ! empty ( $new_tbls ))
$new_tbls .= " , " ;
2010-02-21 20:40:26 +00:00
$new_tbls .= $DBNAME . " . " . $prefix . $ntbl ;
2010-02-06 14:10:53 +00:00
}
return $new_tbls ;
}
2009-08-25 12:16:42 +00:00
class myquery {
2011-04-21 14:41:57 +00:00
function Set_Website_Details ( $name , $value )
{
2009-08-25 12:16:42 +00:00
//mysql_query("UPDATE config SET value = '".$value."' WHERE name ='".$name."'");
2009-09-28 05:23:50 +00:00
global $db , $Cbucket ;
2011-04-21 14:41:57 +00:00
$this -> config_exists ( $name , true );
2010-02-06 09:56:30 +00:00
$db -> update ( tbl ( " config " ), array ( 'value' ), array ( $value ), " name = ' " . $name . " ' " );
2010-12-15 06:53:09 +00:00
//echo $db->db_query."<br/><br/>";
2009-09-28 05:23:50 +00:00
$Cbucket -> configs = $Cbucket -> get_configs ();
2009-08-25 12:16:42 +00:00
}
2010-02-06 13:38:16 +00:00
function Get_Website_Details ()
{
2010-02-06 14:10:53 +00:00
$query = mysql_query ( " SELECT * FROM " . tbl ( " config " ));
2009-10-10 14:25:07 +00:00
while ( $row = mysql_fetch_array ( $query ))
{
$name = $row [ 'name' ];
$data [ $name ] = $row [ 'value' ];
}
return $data ;
2009-08-25 12:16:42 +00:00
}
2011-04-21 14:41:57 +00:00
/**
* Function used to check weather config exists or not
* it also used to create a config if it does not exist
*/
function config_exists ( $name )
{
global $db ;
$count = $db -> count ( tbl ( " config " ), " configid " , " name=' $name ' " );
if ( ! $count )
$db -> insert ( tbl ( " config " ), array ( 'name' ), array ( $name ));
return true ;
}
2010-02-06 13:38:16 +00:00
2009-08-25 12:16:42 +00:00
//Function Used to Check Weather Video Exists or not
2009-10-10 14:25:07 +00:00
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
2009-10-10 14:25:07 +00:00
//Function used to Delete Video
2009-08-25 12:16:42 +00:00
function DeleteVideo ( $videoid ){
2009-08-31 12:01:33 +00:00
global $cbvid ;
2009-10-10 14:25:07 +00:00
return $cbvid -> delete_video ( $videoid );
2009-08-25 12:16:42 +00:00
}
2009-10-10 14:25:07 +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
*/
2009-10-10 14:25:07 +00:00
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
2009-10-10 14:25:07 +00:00
function UpdateVideoViews ( $vkey ){ increment_views ( $vkey , 'video' );}
2009-08-25 12:16:42 +00:00
2009-11-04 10:27:40 +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
*/
2009-12-21 21:11:54 +00:00
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
2009-12-21 21:11:54 +00:00
$cdetails = $this -> get_comment ( $cid );
2009-08-25 12:16:42 +00:00
$uid = user_id ();
2009-12-21 21:11:54 +00:00
if (( $uid == $cdetails [ 'userid' ] && $cdetails [ 'userid' ] != '' )
2010-02-02 16:19:41 +00:00
|| $cdetails [ 'type_owner_id' ] == userid ()
2010-01-25 13:18:18 +00:00
|| has_access ( " admin_del_access " , false )
2009-12-21 21:11:54 +00:00
|| $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 )
{
2009-12-21 21:11:54 +00:00
$this -> delete_comment ( $reply [ 'comment_id' ], $type , TRUE , $forceDelete );
2009-08-25 12:16:42 +00:00
}
}
2010-02-06 09:56:30 +00:00
$db -> Execute ( " DELETE FROM " . tbl ( " comments " ) . " WHERE comment_id=' $cid ' " );
2009-12-04 21:03:27 +00:00
2010-01-17 13:53:14 +00:00
/* if ( $uid )
$myquery -> update_comments_by_user ( $uid ); */
2009-12-21 21:11:54 +00:00
2010-01-13 09:53:21 +00:00
e ( lang ( 'usr_cmt_del_msg' ), " m " );
2010-01-25 13:18:18 +00:00
return $cdetails [ 'type_id' ];
2009-08-25 12:16:42 +00:00
} else {
2010-01-13 09:53:21 +00:00
e ( lang ( 'no_comment_del_perm' ));
2009-12-04 21:03:27 +00:00
return false ;
2009-08-25 12:16:42 +00:00
}
2009-12-04 21:03:27 +00:00
return false ;
2009-08-25 12:16:42 +00:00
}
2009-10-10 14:25:07 +00:00
function DeleteComment ( $id , $videoid ){ return $this -> delete_comment ( $videoid );}
2010-01-25 13:18:18 +00:00
/**
* 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' ));
2010-03-24 14:32:31 +00:00
elseif ( userid () == $comment [ 'userid' ] || ( ! userid () && $_SERVER [ 'REMOTE_ADDR' ] == $comment [ 'comment_ip' ]))
2010-01-25 13:18:18 +00:00
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 ;
2010-02-06 09:56:30 +00:00
$db -> update ( tbl ( 'comments' ), array ( 'spam_votes' , 'spam_voters' ), array ( $newscore , $voters ), " comment_id=' $cid ' " );
2010-01-25 13:18:18 +00:00
e ( lang ( 'spam_comment_ok' ), " m " );
return $newscore ;
}
}
e ( lang ( 'no_comment_exists' ));
return false ;
}
2009-12-21 21:11:54 +00:00
2010-03-19 11:39:18 +00:00
/**
* Function used to set comment as spam
*/
function remove_spam ( $cid ) {
global $db ;
$comment = $this -> get_comment ( $cid );
$vote = '0' ;
$none = '' ;
if ( $comment ) {
$votes = $comment [ 'spam_votes' ];
if ( ! $votes ) {
e ( lang ( 'Comment is not a spam' ));
} elseif ( ! userid ()) {
e ( lang ( 'login_to_mark_as_spam' ));
} else {
$db -> update ( tbl ( 'comments' ), array ( 'spam_votes' , 'spam_voters' ), array ( $vote , $none ), " comment_id=' $cid ' " );
e ( lang ( 'Spam removed from comment.' ), " m " );
}
} else {
e ( lang ( 'no_comment_exists' ));
}
}
2009-12-21 21:11:54 +00:00
/**
* Function used to delete all comments of particlar object
*/
function delete_comments ( $objid , $type = 'v' , $forceDelete = false )
{
global $db , $userquery , $LANG ;
$uid = user_id ();
2010-01-17 13:53:14 +00:00
if ( $userquery -> permission [ 'admin_del_access' ] == 'yes' || $forceDelete )
2009-12-21 21:11:54 +00:00
{
2010-02-06 09:56:30 +00:00
$db -> Execute ( " DELETE FROM " . tbl ( " comments " ) . " WHERE type_id=' $objid ' AND type=' $type ' " );
2009-12-21 21:11:54 +00:00
2010-03-30 07:46:02 +00:00
e ( lang ( 'usr_cmt_del_msg' ), 'm' );
2009-12-21 21:11:54 +00:00
return true ;
} else {
2010-01-13 09:53:21 +00:00
e ( lang ( 'no_comment_del_perm' ));
2009-12-21 21:11:54 +00:00
return false ;
}
return false ;
}
2009-11-30 19:46:45 +00:00
/***
* 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 ;
2010-02-06 09:56:30 +00:00
$db -> update ( tbl ( 'comments' ), array ( 'vote' , 'voters' ), array ( $newscore , $voters ), " comment_id=' $cid ' " );
2011-02-12 07:52:37 +00:00
2009-11-30 19:46:45 +00:00
e ( lang ( 'thanks_rating_comment' ), " m " );
return $newscore ;
2009-08-25 12:16:42 +00:00
}
2009-11-30 19:46:45 +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 ;
}
2010-02-06 13:38:16 +00:00
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 ;
2010-01-13 09:53:21 +00:00
$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
*/
2010-03-17 08:45:57 +00:00
function add_comment ( $comment , $obj_id , $reply_to = NULL , $type = 'v' , $obj_owner = NULL , $obj_link = NULL , $force_name_email = false )
2009-08-25 12:16:42 +00:00
{
2009-09-28 05:23:50 +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 ));
}
2010-04-26 15:17:37 +00:00
if ( ! verify_captcha ())
e ( lang ( 'usr_ccode_err' ));
2009-08-25 12:16:42 +00:00
if ( empty ( $comment ))
2010-02-09 13:00:29 +00:00
e ( lang ( " pelase_enter_something_for_comment " ));
2009-08-25 12:16:42 +00:00
2009-12-29 18:15:35 +00:00
$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 ))
2010-02-09 11:47:08 +00:00
e ( lang ( " class_vdo_del_err " ));
2009-08-25 12:16:42 +00:00
//Checking owner of video
if ( ! USER_COMMENT_OWN )
{
if ( userid () == $this -> get_vid_owner ( $obj_id ));
2010-02-09 13:00:29 +00:00
e ( lang ( " usr_cmt_err2 " ));
2009-08-25 12:16:42 +00:00
}
}
2010-03-23 18:17:53 +00:00
*/
2009-09-28 05:23:50 +00:00
if ( ! userid () && $Cbucket -> configs [ 'anonym_comments' ] != 'yes' )
2010-02-09 11:47:08 +00:00
e ( lang ( " you_not_logged_in " ));
2009-08-25 12:16:42 +00:00
2010-03-17 08:45:57 +00:00
if (( ! userid () && $Cbucket -> configs [ 'anonym_comments' ] == 'yes' ) || $force_name_email )
2009-09-28 05:23:50 +00:00
{
//Checking for input name and email
if ( empty ( $_POST [ 'name' ]))
2010-02-09 13:00:29 +00:00
e ( lang ( " please_enter_your_name " ));
2009-09-28 05:23:50 +00:00
if ( empty ( $_POST [ 'email' ]))
2010-02-09 13:00:29 +00:00
e ( lang ( " please_enter_your_email " ));
2009-09-28 05:23:50 +00:00
$name = mysql_clean ( $_POST [ 'name' ]);
$email = mysql_clean ( $_POST [ 'email' ]);
}
2009-08-25 12:16:42 +00:00
if ( empty ( $eh -> error_list ))
{
2010-02-06 09:56:30 +00:00
$db -> insert ( tbl ( " comments " ), array
2010-02-02 16:19:41 +00:00
( '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
2010-02-02 16:19:41 +00:00
( $type , $comment , $obj_id , userid (), NOW (), $reply_to , $name , $email , $_SERVER [ 'REMOTE_ADDR' ], $obj_owner ));
2010-02-06 09:56:30 +00:00
$db -> update ( tbl ( " users " ), array ( " total_comments " ), array ( " |f|total_comments+1 " ), " userid=' " . userid () . " ' " );
2009-12-04 21:03:27 +00:00
2010-02-09 13:00:29 +00:00
e ( lang ( " grp_comment_msg " ), " m " );
2010-01-21 13:49:49 +00:00
2010-03-01 14:33:21 +00:00
$cid = $db -> insert_id ();
$own_details = $userquery -> get_user_field_only ( $obj_owner , 'email' );
$username = username ();
$username = $username ? $username : post ( 'name' );
$useremail = $email ;
//Adding Comment Log
$log_array = array
(
'success' => 'yes' ,
'action_obj_id' => $cid ,
'action_done_id' => $obj_id ,
'details' => " made a comment " ,
'username' => $username ,
'useremail' => $useremail ,
);
insert_log ( $type . '_comment' , $log_array );
//sending email
2011-02-07 13:09:51 +00:00
if ( SEND_COMMENT_NOTIFICATION == 'yes' && $own_details )
2010-03-01 14:33:21 +00:00
{
global $cbemail ;
$tpl = $cbemail -> get_template ( 'user_comment_email' );
$more_var = array
( '{username}' => $username ,
'{obj_link}' => $obj_link . '#comment_' . $cid ,
'{comment}' => $comment ,
'{obj}' => get_obj_type ( $type )
);
if ( ! is_array ( $var ))
$var = array ();
$var = array_merge ( $more_var , $var );
$subj = $cbemail -> replace ( $tpl [ 'email_template_subject' ], $var );
$msg = nl2br ( $cbemail -> replace ( $tpl [ 'email_template' ], $var ));
//Now Finally Sending Email
cbmail ( array ( 'to' => $own_details , 'from' => WEBSITE_EMAIL , 'subject' => $subj , 'content' => $msg ));
}
2010-01-21 13:49:49 +00:00
return $cid ;
2009-08-25 12:16:42 +00:00
}
2009-11-30 19:46:45 +00:00
return false ;
2009-08-25 12:16:42 +00:00
}
2009-11-30 19:46:45 +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 ;
2009-12-09 13:43:19 +00:00
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-12-09 13:43:19 +00:00
} */
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 )
{
2009-11-04 10:27:40 +00:00
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 ()
{
2009-08-31 12:01:33 +00:00
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 ;
2010-02-06 09:56:30 +00:00
$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 )
{
2010-01-25 13:18:18 +00:00
global $db , $userquery ;
2010-02-06 09:56:30 +00:00
$result = $db -> select ( tbl ( " comments " ), " * " , " comment_id=' $id ' " );
2009-08-25 12:16:42 +00:00
if ( $db -> num_rows > 0 )
{
2010-01-25 13:18:18 +00:00
$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
*/
2011-02-21 11:17:54 +00:00
function get_comments ( $type_id = '*' , $type = 'v' , $count_only = FALSE , $get_type = 'all' , $parent_id = NULL , $useCache = 'yes' )
2011-02-07 13:09:51 +00:00
{
$params = array (
'type_id' => $type_id ,
'type' => $type ,
'count_only' => $count_only ,
'get_type' => $get_type ,
'parent_id' => $parent_id ,
2011-02-21 11:17:54 +00:00
'cache' => $useCache
2011-02-07 13:09:51 +00:00
);
return $this -> getComments ( $params );
}
/**
* Function used to get using ARRAY as paramter
*/
function getComments ( $params )
2009-08-25 12:16:42 +00:00
{
2011-02-12 07:52:37 +00:00
global $db , $userquery ;
2009-08-25 12:16:42 +00:00
$cond = '' ;
2011-02-21 11:17:54 +00:00
if ( ! $params [ 'cache' ])
$params [ 'cache' ] = 'yes' ;
2011-02-07 13:09:51 +00:00
$p = $params ;
extract ( $p , EXTR_SKIP );
2011-02-21 11:17:54 +00:00
2011-02-07 13:09:51 +00:00
switch ( $type )
{
case " video " :
case " videos " :
case " v " :
case " vdo " :
{
$type = 'v' ;
}
break ;
case " photo " :
case " p " :
case " photos " :
{
$type = 'p' ;
}
break ;
case " topic " :
case " t " :
case " topics " :
{
$type = 't' ;
}
break ;
case " channel " :
case " c " :
case " channels " :
{
2011-02-17 17:17:52 +00:00
$type = 'c' ;
2011-02-07 13:09:51 +00:00
}
break ;
case " cl " :
case " collect " :
case " collection " :
case " collections " :
{
$type = 'cl' ;
}
break ;
}
2009-08-25 12:16:42 +00:00
2011-02-21 11:17:54 +00:00
if ( ! $count_only && $params [ 'cache' ] == 'yes' )
2011-02-07 13:09:51 +00:00
{
$file = $type . $type_id . str_replace ( ',' , '_' , $limit ) . '-' . strtotime ( $last_update ) . '.tmp' ;
$files = glob ( COMM_CACHE_DIR . '/' . $type . $type_id . str_replace ( ',' , '_' , $limit ) . '*' );
$theFile = getName ( $files [ 0 ]);
$theFileDetails = explode ( '-' , $theFile );
$timeDiff = time () - $theFileDetails [ 1 ];
if ( file_exists ( COMM_CACHE_DIR . '/' . $file ) && $timeDiff < COMM_CACHE_TIME )
return json_decode ( file_get_contents ( COMM_CACHE_DIR . '/' . $file ), true );
}
if ( ! $order )
$order = ' date_added DESC ' ;
2009-08-25 12:16:42 +00:00
#Checking if user wants to get replies of comment
if ( $parent_id != NULL && $get_reply_only )
{
$cond .= " AND parent_id=' $parent_id ' " ;
}
2011-02-07 13:09:51 +00:00
if ( $type_id != '*' )
2010-01-23 13:50:53 +00:00
$typeid_query = " AND type_id=' $type_id ' " ;
2009-08-25 12:16:42 +00:00
2010-01-23 13:16:19 +00:00
if ( ! $count_only )
2009-08-25 12:16:42 +00:00
{
2011-02-07 13:09:51 +00:00
/**
* we have to get comments in such way that
* comment replies comes along with their parents
* in order to achieve this , we have to create a complex logic
* lets see if we can get some tips from WP commenting system ;)
* HAIL Open Source
*/
2011-02-12 07:52:37 +00:00
$results = $db -> select ( tbl ( " comments " ), '*'
, " type=' $type ' $typeid_query $cond " , $limit , $order );
2011-02-07 13:09:51 +00:00
if ( ! $results )
return false ;
$parent_cond = '' ;
$parents_array = array ();
if ( $results )
foreach ( $results as $result )
{
if ( $result [ 'parent_id' ] && ! in_array ( $result [ 'parent_id' ], $parents_array ))
{
if ( $parent_cond )
$parent_cond .= " OR " ;
$parent_cond .= " comment_id=' " . $result [ 'parent_id' ] . " ' " ;
$parents_array [] = $result [ 'parent_id' ];
}
}
//Getting Parents
2011-02-12 07:52:37 +00:00
$parents = $db -> select ( tbl ( " comments " ), '*'
, " type=' $type ' AND ( $parent_cond ) " , NULL , $order );
2011-02-07 13:09:51 +00:00
if ( $parents )
foreach ( $parents as $parent )
$new_parents [ $parent [ 'comment_id' ]] = $parent ;
2011-02-12 07:52:37 +00:00
//Inserting user data
$new_results = array ();
foreach ( $results as $com )
{
$userid = $com [ 'userid' ];
$uservar = 'user_' . $userid ;
if ( $userid && ! $$uservar )
$$uservar = $userquery -> get_user_details ( $userid );
if ( $$uservar )
$com = array_merge ( $com , $$uservar );
$new_results [] = $com ;
}
$comment [ 'comments' ] = $new_results ;
2011-02-07 13:09:51 +00:00
$comment [ 'parents' ] = $new_parents ;
//Deleting any other previuos comment file
$files = glob ( COMM_CACHE_DIR . '/' . $type . $type_id . str_replace ( ',' , '_' , $limit ) . '*' );
foreach ( $files as $delFile )
if ( file_exists ( $delFile ))
unlink ( $delFile );
//Caching comment file
if ( $file )
file_put_contents ( COMM_CACHE_DIR . '/' . $file , json_encode ( $comment ));
return $comment ;
2010-01-23 13:16:19 +00:00
} else
{
2010-02-06 09:56:30 +00:00
return $db -> count ( tbl ( " comments " ), " * " , " type=' $type ' $typeid_query $cond " );
2009-08-25 12:16:42 +00:00
}
}
2011-02-07 13:09:51 +00:00
2010-09-22 06:53:24 +00:00
/**
* Function used to get from database
* with nested replies
*/
/* function get_comments ( $obj_id , $type = 'v' , $parent_only = TRUE , $count_only = FALSE )
{
global $db ;
$cond = '' ;
$user_flds = tbl ( " users.userid " ) . " , " . tbl ( " users.username " ) . " , " . tbl ( " users.email " ) . " , " . tbl ( " users.avatar " ) . " , " . tbl ( " users.avatar_url " );
if ( $obj_id != " all " )
$cond = " type_id = ' $obj_id ' " ;
else
$cond = " " ;
if ( ! empty ( $cond ))
$cond .= " AND " ;
if ( $parent_only && is_numeric ( $parent_only ))
{
$parent_id = $parent_only ;
$cond .= " parent_id=' $parent_id ' " ;
} else {
$cond .= " parent_id = '0' " ;
}
if ( ! $count_only )
{
$result = $db -> select ( tbl ( " comments,users " ), tbl ( " comments " ) . " .*, $user_flds " , " $cond AND type=' $type ' AND " . tbl ( " comments.userid " ) . " = " . tbl ( " users.userid " ) . " " );
//echo $db->db_query;
$ayn_result = $db -> select ( tbl ( " comments,users " ), tbl ( " comments " ) . " .*, $user_flds " , " $cond AND type=' $type ' AND " . tbl ( " comments.userid " ) . " = '0' " );
if ( $result && $ayn_result )
$result = array_merge ( $result , $ayn_result );
elseif ( ! $result && $ayn_result )
$result = $ayn_result ;
$arr = array ();
foreach ( $result as $comment )
{
$arr [ $comment [ 'comment_id' ]] = $comment ;
$replies = $this -> get_replies ( $comment [ 'comment_id' ], $type );
if ( $replies )
{
$arr [ $comment [ 'comment_id' ]][] = $replies ;
}
}
return $arr ;
}
} */
function get_replies ( $p_id , $type = 'v' )
{
global $db ;
$result = $db -> select ( tbl ( " comments,users " ), " * " , " type=' $type ' AND parent_id = ' $p_id ' AND " . tbl ( " comments.userid " ) . " = " . tbl ( " users.userid " ) . " " );
$ayn_result = $db -> select ( tbl ( " comments,users " ), " * " , " type=' $type ' AND parent_id = ' $p_id ' AND " . tbl ( " comments.userid " ) . " = '0' " );
if ( $result && $ayn_result )
$result = array_merge ( $result , $ayn_result );
elseif ( ! $result && $ayn_result )
$result = $ayn_result ;
return $result ;
}
2009-08-25 12:16:42 +00:00
/**
* Function used to get video owner
*/
function get_vid_owner ( $vid )
{
global $db ;
2010-02-06 09:56:30 +00:00
$results = $db -> select ( tbl ( " video " ), " userid " , " videoid=' $vid ' " );
2009-08-25 12:16:42 +00:00
return $results [ 0 ];
}
2009-09-28 05:23:50 +00:00
/**
* 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 );
2010-03-30 07:46:02 +00:00
e ( lang ( " template_activated " ), 'm' );
2009-09-28 05:23:50 +00:00
} else
2010-02-09 13:00:29 +00:00
e ( lang ( " error_occured_changing_template " ));
2009-09-28 05:23:50 +00:00
}
/**
* Function used to update comment
*/
function update_comment ( $cid , $text )
{
global $db ;
2010-02-06 09:56:30 +00:00
$db -> Execute ( " UPDATE " . tbl ( " comments " ) . " SET comment=' $text ' WHERE comment_id=' $cid ' " );
2010-03-20 08:39:04 +00:00
//$db->update(tbl("comments"),array("comment"),array($text)," comment_id = $cid");
2009-09-28 05:23:50 +00:00
}
2009-12-29 18:15:35 +00:00
/**
* 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 ))
2010-02-09 11:47:08 +00:00
e ( lang ( " class_vdo_del_err " ));
2009-12-29 18:15:35 +00:00
//Checking owner of video
2010-03-01 14:33:21 +00:00
//if(!USER_COMMENT_OWN)
//{
// if(userid()==$this->get_vid_owner($obj_id));
/// e(lang("usr_cmt_err2"));
//}
2009-12-29 18:15:35 +00:00
}
$func_array = get_functions ( 'validate_comment_functions' );
if ( is_array ( $func_array ))
{
foreach ( $func_array as $func )
{
if ( function_exists ( $func ))
{
return $func ( $params );
}
}
}
}
2010-01-05 09:47:10 +00:00
/**
* Function used to insert note in data base for admin referance
*/
function insert_note ( $note )
{
global $db ;
2010-02-06 14:10:53 +00:00
$db -> insert ( tbl ( 'admin_notes' ), array ( 'note,date_added,userid' ), array ( $note , now (), userid ()));
2010-01-05 09:47:10 +00:00
}
/**
* Function used to get notes
*/
function get_notes ()
{
global $db ;
2010-02-06 14:10:53 +00:00
return $db -> select ( tbl ( 'admin_notes' ), '*' , " userid=' " . userid () . " ' " , NULL , " date_added DESC " );
2010-01-05 09:47:10 +00:00
}
/**
* Function usde to delete note
*/
function delete_note ( $id )
{
global $db ;
2010-02-06 14:10:53 +00:00
$db -> delete ( tbl ( " admin_notes " ), array ( " note_id " ), array ( $id ));
2010-01-05 09:47:10 +00:00
}
2010-02-28 13:26:17 +00:00
/**
* Function used to check weather object is commentable or not
*/
function is_commentable ( $obj , $type )
{
switch ( $type )
{
case " video " :
case " v " :
case " vdo " :
case " videos " :
case " vid " :
{
if ( $obj [ 'allow_comments' ] == 'yes' && config ( 'video_comments' ) == 1 )
return true ;
}
break ;
2010-11-01 11:01:15 +00:00
2010-02-28 13:26:17 +00:00
case " channel " :
case " user " :
case " users " :
case " u " :
case " c " :
{
2010-03-19 11:39:18 +00:00
if ( $obj [ 'allow_comments' ] == 'Yes' && config ( 'channel_comments' ) == 1 )
2010-02-28 13:26:17 +00:00
return true ;
}
2010-11-01 11:01:15 +00:00
break ;
case " collection " :
case " collect " :
case " cl " :
{
if ( $obj [ 'allow_comments' ] == 'yes' )
return true ;
}
break ;
2010-12-23 16:56:33 +00:00
case " photo " :
case " p " :
case " photos " :
{
if ( $obj [ 'allow_comments' ] == 'yes' && config ( 'photo_comments' ) == 1 )
return true ;
}
2010-02-28 13:26:17 +00:00
}
return false ;
}
2010-03-23 08:33:20 +00:00
/**
* Function used to get list of items in conversion queue
* @ params $Cond , $limit , $order
*/
function get_conversion_queue ( $cond = NULL , $limit = NULL , $order = 'date_added DESC' )
{
global $db ;
2010-03-23 15:21:27 +00:00
$result = $db -> select ( tbl ( " conversion_queue " ), " * " , $cond , $limit , $oder );
if ( $db -> num_rows > 0 )
return $result ;
else
return false ;
2010-03-23 08:33:20 +00:00
}
2010-03-23 15:21:27 +00:00
/**
* function used to remove queue
*/
function queue_action ( $action , $id )
{
global $db ;
switch ( $action )
{
case " delete " :
$db -> execute ( " DELETE from " . tbl ( 'conversion_queue' ) . " WHERE cqueue_id =' $id ' " );
break ;
case " processed " :
$db -> update ( tbl ( 'conversion_queue' ), array ( 'cqueue_conversion' ), array ( 'yes' ), " cqueue_id =' $id ' " );
break ;
case " pending " :
$db -> update ( tbl ( 'conversion_queue' ), array ( 'cqueue_conversion' ), array ( 'no' ), " cqueue_id =' $id ' " );
break ;
}
}
2010-02-28 13:26:17 +00:00
2009-08-25 12:16:42 +00:00
}
?>