2013-10-07 12:17:06 +00:00
< ? php
2016-03-03 22:54:49 -08:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 22:54:49 -08:00
* File : Functions
* Description : Various kind of functions to do ClipBucket jobs
* @ license : Attribution Assurance License
* @ since : ClipBucket 1.0
* @ author [ s ] : Arslan Hassan , Fawaz Tahir , Fahad Abbass , Awais Tariq , Saqib Razzaq
* @ copyright : ( c ) 2008 - 2010 ClipBucket / PHPBucket
* @ notice : Please maintain this section
* @ modified : March 4 th , 2016 ClipBucket 2.8 . 1
*/
define ( " SHOW_COUNTRY_FLAG " , TRUE );
require 'define_php_links.php' ;
include_once 'upload_forms.php' ;
2013-10-07 12:17:06 +00:00
2014-11-18 10:30:16 +00:00
/**
* Function used to throw
** @ param $message pointer
** @ return message
*/
2016-03-03 22:54:49 -08:00
function throw_error ( $message , $pointer = " " )
2014-11-18 10:30:16 +00:00
{
global $Cbucket ;
if ( $pointer )
$Cbucket -> error_pointer [ $pointer ] = $message ;
throw new Exception ( $message );
}
2013-10-07 12:17:06 +00:00
//This Funtion is use to get CURRENT PAGE DIRECT URL
function curPageURL ()
{
$pageURL = 'http' ;
if ( @ $_SERVER [ " HTTPS " ] == " on " ) {
$pageURL .= " s " ;
}
$pageURL .= " :// " ;
$pageURL .= $_SERVER [ 'SERVER_NAME' ];
$pageURL .= $_SERVER [ 'PHP_SELF' ];
$query_string = $_SERVER [ 'QUERY_STRING' ];
if ( ! empty ( $query_string )){
$pageURL .= '?' . $query_string ;
}
return $pageURL ;
}
//QuotesReplace
function Replacer ( $string )
{
//Wp-Magic Quotes
$string = preg_replace ( " /'s/ " , '’s' , $string );
$string = preg_replace ( " /'( \ d \ d(?:’|')?s)/ " , " ’ $ 1 " , $string );
$string = preg_replace ( '/(\s|\A|")\'/' , '$1‘' , $string );
$string = preg_replace ( '/(\d+)"/' , '$1″' , $string );
$string = preg_replace ( " /( \ d+)'/ " , '$1′' , $string );
$string = preg_replace ( " /( \ S)'([^' \ s])/ " , " $ 1’ $ 2 " , $string );
$string = preg_replace ( '/(\s|\A)"(?!\s)/' , '$1“$2' , $string );
$string = preg_replace ( '/"(\s|\S|\Z)/' , '”$1' , $string );
$string = preg_replace ( " /'([ \ s.]| \ Z)/ " , '’$1' , $string );
$string = preg_replace ( " / \ (tm \ )/i " , ' ™' , $string );
$string = str_replace ( " '' " , '”' , $string );
$array = array ( '/& /' );
$replace = array ( '& ' ) ;
return $string = preg_replace ( $array , $replace , $string );
}
//This Funtion is used to clean a String
function clean ( $string , $allow_html = false ) {
//$string = $string;
//$string = htmlentities($string);
if ( $allow_html == false ){
$string = strip_tags ( $string );
$string = Replacer ( $string );
}
// $string = utf8_encode($string);
return $string ;
}
function cb_clean ( $string , $array = array ( 'no_html' => true , 'mysql_clean' => false ))
{
if ( $array [ 'no_html' ])
$string = htmlentities ( $string );
if ( $array [ 'special_html' ])
$string = htmlspecialchars ( $string );
if ( $array [ 'mysql_clean' ])
$string = mysql_real_escape_string ( $string );
if ( $array [ 'nl2br' ])
$string = nl2br ( $string );
return $string ;
}
//This Fucntion is for Securing Password, you may change its combination for security reason but make sure dont not rechange once you made your script run
function pass_code ( $string ) {
$password = md5 ( md5 ( sha1 ( sha1 ( md5 ( $string )))));
return $password ;
}
//Mysql Clean Queries
function sql_free ( $id )
{
if ( ! get_magic_quotes_gpc ())
{
$id = addslashes ( $id );
}
return $id ;
}
function mysql_clean ( $id , $replacer = true ){
//$id = clean($id);
2013-11-19 14:57:53 +00:00
global $db ;
2013-10-07 12:17:06 +00:00
if ( get_magic_quotes_gpc ())
{
$id = stripslashes ( $id );
}
2013-11-19 14:57:53 +00:00
$id = htmlspecialchars ( mysqli_real_escape_string ( $db -> mysqli , $id ));
2013-10-07 12:17:06 +00:00
if ( $replacer )
$id = Replacer ( $id );
return $id ;
}
function escape_gpc ( $in )
{
if ( get_magic_quotes_gpc ())
{
$in = stripslashes ( $in );
}
return $in ;
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
//Funtion of Random String
function RandomString ( $length )
{
$string = md5 ( microtime ());
$highest_startpoint = 32 - $length ;
$randomString = substr ( $string , rand ( 0 , $highest_startpoint ), $length );
return $randomString ;
}
//This Function Is Used To Display Tags Cloud
function TagClouds ( $cloudquery )
{
$tags = array ();
$cloud = array ();
$query = mysql_query ( $cloudquery );
while ( $t = mysql_fetch_array ( $query ))
{
$db = explode ( ' ' , $t [ 0 ]);
while ( list ( $key , $value ) = each ( $db ))
{
@ $keyword [ $value ] += 1 ;
}
}
if ( is_array ( @ $keyword ))
{
$minFont = 11 ;
$maxFont = 22 ;
$min = min ( array_values ( $keyword ));
$max = max ( array_values ( $keyword ));
$fix = ( $max - $min == 0 ) ? 1 : $max - $min ;
// Display the tags
foreach ( $keyword as $tag => $count )
{
$size = $minFont + ( $count - $min ) * ( $maxFont - $minFont ) / $fix ;
$cloud [] = '<a class=cloudtags style="font-size: ' . floor ( $size ) . 'px;" href="' . BASEURL . search_result . '?query=' . $tag . '" title="Tags: ' . ucfirst ( $tag ) . ' was used ' . $count . ' times"><span>' . mysql_clean ( $tag ) . '</span></a>' ;
}
$shown = join ( " \n " , $cloud ) . " \n " ;
return $shown ;
}
}
/**
* Function used to send emails
* @ Author : Arslan Hassan
* this is a very basic email function
* you can extend or replace this function easily
* read our docs . clip - bucket . com
*/
function cbmail ( $array )
{
$func_array = get_functions ( 'email_functions' );
if ( is_array ( $func_array ))
{
foreach ( $func_array as $func )
{
if ( function_exists ( $func ))
{
return $func ( $array );
}
}
}
$content = escape_gpc ( $array [ 'content' ]);
$subject = escape_gpc ( $array [ 'subject' ]);
$to = $array [ 'to' ];
$from = $array [ 'from' ];
$to_name = $array [ 'to_name' ];
$from_name = $array [ 'from_name' ];
if ( $array [ 'nl2br' ])
$content = nl2br ( $content );
# CHecking Content
if ( preg_match ( '/<html>/' , $content , $matches ))
{
if ( empty ( $matches [ 1 ]))
{
$content = wrap_email_content ( $content );
}
}
$message .= $content ;
//ClipBucket uses PHPMailer for sending emails
include_once ( " classes/phpmailer/class.phpmailer.php " );
include_once ( " classes/phpmailer/class.smtp.php " );
$mail = new PHPMailer (); // defaults to using php "mail()"
$mail_type = config ( 'mail_type' );
//---Setting SMTP ---
if ( $mail_type == 'smtp' )
{
$mail -> IsSMTP (); // telling the class to use SMTP
$mail -> Host = config ( 'smtp_host' ); // SMTP server
if ( config ( 'smtp_auth' ) == 'yes' )
$mail -> SMTPAuth = true ; // enable SMTP authentication
$mail -> Port = config ( 'smtp_port' ); // set the SMTP port for the GMAIL server
$mail -> Username = config ( 'smtp_user' ); // SMTP account username
$mail -> Password = config ( 'smtp_pass' ); // SMTP account password
}
//--- Ending Smtp Settings
$mail -> SetFrom ( $from , $from_name );
if ( is_array ( $to ))
{
foreach ( $to as $name )
{
$mail -> AddAddress ( strtolower ( $name ), $to_name );
}
} else {
$mail -> AddAddress ( strtolower ( $to ), $to_name );
}
$mail -> Subject = $subject ;
$mail -> MsgHTML ( $message );
if ( ! $mail -> Send ())
{
2015-02-26 10:35:25 +00:00
//apply check here nafisa
if ( has_access ( 'admin_access' , TRUE ) )
e ( " Mailer Error: " . $mail -> ErrorInfo );
2013-10-07 12:17:06 +00:00
return false ;
} else
return true ;
}
function send_email ( $from , $to , $subj , $message )
{
return cbmail ( array ( 'from' => $from , 'to' => $to , 'subject' => $subj , 'content' => $message ));
}
/**
* Function used to wrap email content in
* HTML AND BODY TAGS
*/
function wrap_email_content ( $content )
{
return '<html><body>' . $content . '</body></html>' ;
}
/**
* Function used to get file name
*/
function GetName ( $file )
{
if ( ! is_string ( $file ))
return false ;
2014-12-18 11:27:43 +00:00
//for srever thumb files
$parts = parse_url ( $file );
parse_str ( $parts [ 'query' ], $query );
$get_file_name = $query [ 'src' ];
$path = explode ( '.' , $get_file_name );
$server_thumb_name = $path [ 0 ];
if ( ! empty ( $server_thumb_name ))
return $server_thumb_name ;
/*srever thumb files END */
2013-10-07 12:17:06 +00:00
$path = explode ( '/' , $file );
if ( is_array ( $path ))
$file = $path [ count ( $path ) - 1 ];
$new_name = substr ( $file , 0 , strrpos ( $file , '.' ));
return $new_name ;
}
function get_elapsed_time ( $ts , $datetime = 1 )
{
if ( $datetime == 1 )
{
$ts = date ( 'U' , strtotime ( $ts ));
}
$mins = floor (( time () - $ts ) / 60 );
$hours = floor ( $mins / 60 );
$mins -= $hours * 60 ;
$days = floor ( $hours / 24 );
$hours -= $days * 24 ;
$weeks = floor ( $days / 7 );
$days -= $weeks * 7 ;
$t = " " ;
if ( $weeks > 0 )
return " $weeks week " . ( $weeks > 1 ? " s " : " " );
if ( $days > 0 )
return " $days day " . ( $days > 1 ? " s " : " " );
if ( $hours > 0 )
return " $hours hour " . ( $hours > 1 ? " s " : " " );
if ( $mins > 0 )
return " $mins min " . ( $mins > 1 ? " s " : " " );
return " < 1 min " ;
}
//Function Used TO Get Extensio Of File
function GetExt ( $file ){
return strtolower ( substr ( $file , strrpos ( $file , '.' ) + 1 ));
}
function old_set_time ( $temps )
{
round ( $temps );
$heures = floor ( $temps / 3600 );
$minutes = round ( floor (( $temps - ( $heures * 3600 )) / 60 ));
if ( $minutes < 10 )
$minutes = " 0 " . round ( $minutes );
$secondes = round ( $temps - ( $heures * 3600 ) - ( $minutes * 60 ));
if ( $secondes < 10 )
$secondes = " 0 " . round ( $secondes );
return $minutes . ':' . $secondes ;
}
function SetTime ( $sec , $padHours = true ) {
if ( $sec < 3600 )
return old_set_time ( $sec );
$hms = " " ;
// there are 3600 seconds in an hour, so if we
// divide total seconds by 3600 and throw away
// the remainder, we've got the number of hours
$hours = intval ( intval ( $sec ) / 3600 );
// add to $hms, with a leading 0 if asked for
$hms .= ( $padHours )
? str_pad ( $hours , 2 , " 0 " , STR_PAD_LEFT ) . ':'
: $hours . ':' ;
// dividing the total seconds by 60 will give us
// the number of minutes, but we're interested in
// minutes past the hour: to get that, we need to
// divide by 60 again and keep the remainder
$minutes = intval (( $sec / 60 ) % 60 );
// then add to $hms (with a leading 0 if needed)
$hms .= str_pad ( $minutes , 2 , " 0 " , STR_PAD_LEFT ) . ':' ;
// seconds are simple - just divide the total
// seconds by 60 and keep the remainder
$seconds = intval ( $sec % 60 );
// add to $hms, again with a leading 0 if needed
$hms .= str_pad ( $seconds , 2 , " 0 " , STR_PAD_LEFT );
return $hms ;
}
//Simple Validation
function isValidText ( $text ){
$pattern = " ^^[_a-z0-9-]+ $ " ;
if ( eregi ( $pattern , $text )){
return true ;
} else {
return false ;
}
}
//Function Used To Validate Email
function isValidEmail ( $email ){
$pattern = " /[_a-z0-9-]+( \ .[_a-z0-9-]+)*@[a-z0-9-]+( \ .[a-z0-9-]+)*( \ .[a-z] { 2,3}) $ /i " ;
preg_match ( $pattern , $email , $matches );
if ( $matches [ 0 ] != '' ){
return true ;
}
else {
2014-08-08 12:34:21 +00:00
/* if ( ! DEVELOPMENT_MODE )
2013-10-07 12:17:06 +00:00
return false ;
2014-08-08 12:34:21 +00:00
else */
2013-10-07 12:17:06 +00:00
return true ;
}
}
2016-02-10 07:49:39 +00:00
//Function Used To Validate Email
function is_valid_email ( $email )
{
$pattern = " /^([ \ w- \ .]+@([ \ w-]+ \ .)+[ \ w-] { 2,4})? $ / " ;
/*pr(preg_match($pattern, $email),true);*/
if ( preg_match ( $pattern , $email ))
return true ;
else
return false ;
}
2013-10-07 12:17:06 +00:00
// THIS FUNCTION SETS HTMLSPECIALCHARS_DECODE IF FUNCTION DOESN'T EXIST
// INPUT: $text REPRESENTING THE TEXT TO DECODE
// $ent_quotes (OPTIONAL) REPRESENTING WHETHER TO REPLACE DOUBLE QUOTES, ETC
// OUTPUT: A STRING WITH HTML CHARACTERS DECODED
if ( ! function_exists ( 'htmlspecialchars_decode' )) {
function htmlspecialchars_decode ( $text , $ent_quotes = " " ) {
$text = str_replace ( " " " , " \" " , $text );
$text = str_replace ( " ' " , " ' " , $text );
$text = str_replace ( " < " , " < " , $text );
$text = str_replace ( " > " , " > " , $text );
$text = str_replace ( " & " , " & " , $text );
return $text ;
}
} // END htmlspecialchars() FUNCTION
//THIS FUNCTION IS USED TO LIST FILE TYPES IN FLASH UPLOAD
//INPUT FILE TYPES
//OUTPUT FILE TYPE IN PROPER FORMAT
function ListFileTypes ( $types ){
$types_array = preg_replace ( '/,/' , ' ' , $types );
$types_array = explode ( ' ' , $types_array );
$list = 'Video,' ;
for ( $i = 0 ; $i <= count ( $types_array ); $i ++ ){
if ( $types_array [ $i ] != '' ){
$list .= '*.' . $types_array [ $i ];
if ( $i != count ( $types_array )) $list .= ';' ;
}
}
return $list ;
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
* Get Directory Size - get_video_file ( $vdata , $no_video , false );
*/
function get_directory_size ( $path )
{
$totalsize = 0 ;
$totalcount = 0 ;
$dircount = 0 ;
if ( $handle = opendir ( $path ))
{
while ( false !== ( $file = readdir ( $handle )))
{
$nextpath = $path . '/' . $file ;
if ( $file != '.' && $file != '..' && ! is_link ( $nextpath ))
{
if ( is_dir ( $nextpath ))
{
$dircount ++ ;
$result = get_directory_size ( $nextpath );
$totalsize += $result [ 'size' ];
$totalcount += $result [ 'count' ];
$dircount += $result [ 'dircount' ];
}
elseif ( is_file ( $nextpath ))
{
$totalsize += filesize ( $nextpath );
$totalcount ++ ;
}
}
}
}
closedir ( $handle );
$total [ 'size' ] = $totalsize ;
$total [ 'count' ] = $totalcount ;
$total [ 'dircount' ] = $dircount ;
return $total ;
}
//FUNCTION USED TO FORMAT FILE SIZE
//INPUT BYTES
//OUTPT MB , Kib
function formatfilesize ( $data ) {
// bytes
if ( $data < 1024 ) {
return $data . " bytes " ;
}
// kilobytes
else if ( $data < 1024000 ) {
return round ( ( $data / 1024 ), 1 ) . " KB " ;
}
// megabytes
else if ( $data < 1024000000 ){
return round ( ( $data / 1024000 ), 1 ) . " MB " ;
} else {
return round ( ( $data / 1024000000 ), 1 ) . " GB " ;
}
}
//TEST EXCEC FUNCTION
function test_exec ( $cmd )
{
echo '<div border="1px">' ;
echo '<h1>' . htmlentities ( $cmd ) . '</h1>' ;
if ( stristr ( PHP_OS , 'WIN' )) {
$cmd = $cmd ;
} else {
$cmd = " PATH= \$ PATH:/bin:/usr/bin:/usr/local/bin bash -c \" $cmd\ " " ;
}
$data = shell_exec ( $cmd );
2014-11-22 11:30:12 +00:00
return $data ;
// if( $data === false )
// echo "<p>FAILED: $cmd</p></div>";
// echo '<p><pre>' . htmlentities( $data ) . '</pre></p></div>';
2013-10-07 12:17:06 +00:00
}
/**
* Function used to get shell output
*/
function shell_output ( $cmd )
{
if ( stristr ( PHP_OS , 'WIN' )) {
$cmd = $cmd ;
} else {
$cmd = " PATH= \$ PATH:/bin:/usr/bin:/usr/local/bin bash -c \" $cmd\ " 2 >& 1 " ;
}
$data = shell_exec ( $cmd );
return $data ;
}
/**
* Function used to tell ClipBucket that it has closed the script
*/
function the_end ()
{
if ( ! $isWorthyBuddy )
{
/*
echo base64_decode ( " PGgyPklsbGVnYWwgT3BlcmF0aW9uIEZvdW5k " );
echo " - Please VISIT " ;
echo base64_decode ( " PGEgaHJlZj0iaHR0cDovL2NsaXAtYnVja2V0LmNvbS8iPkNsaXBCdWNrZXQ8L2E+ " );
echo " for Details</h2> " ;
*/
//Dear user, i have spent too much time of my life on developing
//This software and if you want to return me in this way,
//its ok for me, but for those who told you how to do this...
2014-11-24 18:23:45 +00:00
2013-10-07 12:17:06 +00:00
}
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
* Group Link
*/
function group_link ( $params )
{
$grp = $params [ 'details' ];
$id = $grp [ 'group_id' ];
$name = $grp [ 'group_name' ];
$url = $grp [ 'group_url' ];
if ( $params [ 'type' ] == '' || $params [ 'type' ] == 'group' )
{
if ( SEO == yes )
return BASEURL . '/group/' . $url ;
else
return BASEURL . '/view_group.php?url=' . $url ;
}
if ( $params [ 'type' ] == 'view_members' )
{
return BASEURL . '/view_group_members.php?url=' . $url ;
if ( SEO == yes )
return BASEURL . '/group_members/' . $url ;
else
return BASEURL . '/view_group_members.php?url=' . $url ;
}
if ( $params [ 'type' ] == 'view_videos' )
{
return BASEURL . '/view_group_videos.php?url=' . $url ;
if ( SEO == yes )
return BASEURL . '/group_videos/' . $url ;
else
return BASEURL . '/view_group_videos.php?url=' . $url ;
}
if ( $params [ 'type' ] == 'view_topics' )
{
if ( SEO == " yes " )
return BASEURL . " /group/ " . $url . " ?mode=view_topics " ;
else
return BASEURL . " /view_group.php?url= " . $url . " &mode=view_topics " ;
}
if ( $params [ 'type' ] == 'view_report_form' )
{
if ( SEO == " yes " )
return BASEURL . " /group/ " . $url . " ?mode=view_report_form " ;
else
return BASEURL . " /view_group.php?url= " . $url . " &mode=view_report_form " ;
}
}
/**
* FUNCTION USED TO GET COMMENTS
* @ param : array ();
*/
function getComments ( $params = NULL )
{
global $db ;
$order = $params [ 'order' ];
$limit = $params [ 'limit' ];
$type = $params [ 'type' ];
$cond = '' ;
2015-11-05 13:57:45 +00:00
if ( ! empty ( $params [ 'videoid' ]))
{
$cond .= 'type_id=' . $params [ 'videoid' ];
$cond .= ' AND ' ;
}
2013-10-07 12:17:06 +00:00
if ( empty ( $type ))
$type = " v " ;
$cond .= tbl ( " comments.type " ) . " = ' " . $type . " ' " ;
if ( $params [ 'type_id' ] && $params [ 'sectionTable' ])
{
if ( $cond != " " )
$cond .= " AND " ;
$cond .= tbl ( " comments.type_id " ) . " = " . tbl ( $params [ 'sectionTable' ] . " . " . $params [ 'type_id' ]);
}
if ( $params [ 'cond' ])
{
if ( $cond != " " )
$cond .= " AND " ;
$cond .= $params [ 'cond' ];
}
2014-02-12 09:27:02 +00:00
$query = " SELECT * FROM " . tbl ( " comments " . ( $params [ 'sectionTable' ] ? " , " . $params [ 'sectionTable' ] : NULL ));
if ( $cond )
$query .= " WHERE " . $cond ;
if ( $order )
$query .= " ORDER BY " . $order ;
if ( $limit )
$query .= " LIMIT " . $limit ;
2015-11-05 14:01:17 +00:00
2013-10-07 12:17:06 +00:00
if ( ! $params [ 'count_only' ])
2014-02-12 09:27:02 +00:00
{
$result = db_select ( $query );
//$result = db_select(tbl("comments".($params['sectionTable']?",".$params['sectionTable']:NULL)),"*",$cond,$limit,$order);
}
2013-10-07 12:17:06 +00:00
//echo $db->db_query;
if ( $params [ 'count_only' ])
$result = $db -> count ( tbl ( " comments " ), " * " , $cond );
if ( $result )
return $result ;
else
return false ;
}
function getSmartyComments ( $params )
{
global $myquery ;
$comments = $myquery -> getComments ( $params );
if ( $params [ 'assign' ])
assign ( $params [ 'assign' ], $comments );
else
return $comments ;
}
/**
* FUNCTION USED TO GET ADVERTISMENT
* @ param : array ( Ad Code , LIMIT );
*/
function getAd ( $params )
{
global $adsObj ;
$data = '' ;
if ( $params [ 'style' ] || $params [ 'class' ] || $params [ 'align' ])
$data .= '<div style="' . $params [ 'style' ] . '" class="' . $params [ 'class' ] . '" align="' . $params [ 'align' ] . '">' ;
$data .= ad ( $adsObj -> getAd ( $params [ 'place' ]));
if ( $params [ 'style' ] || $params [ 'class' ] || $params [ 'align' ])
$data .= '</div>' ;
return $data ;
}
/**
* FUNCTION USED TO GET THUMBNAIL , MADE FOR SMARTY
* @ param : array ( " FLV " );
*/
function getSmartyThumb ( $params )
{
return get_thumb ( $params [ 'vdetails' ], $params [ 'num' ], $params [ 'multi' ], $params [ 'count_only' ], true , true , $params [ 'size' ]);
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
* FUNCTION USED TO GET VIDEO RATING IN SMARTY
* @ param : array ( pullRating ( $videos [ $id ][ 'videoid' ], false , false , false , 'novote' );
*/
function pullSmartyRating ( $param )
{
return pullRating ( $param [ 'id' ], $param [ 'show5' ], $param [ 'showPerc' ], $aram [ 'showVotes' ], $param [ 'static' ]);
}
/**
* FUNCTION USED TO CLEAN VALUES THAT CAN BE USED IN FORMS
*/
function cleanForm ( $string )
{
if ( is_string ( $string ))
$string = htmlspecialchars ( $string );
if ( get_magic_quotes_gpc ())
if ( ! is_array ( $string ))
$string = stripslashes ( $string );
return $string ;
}
function form_val ( $string ){ return cleanForm ( $string ); }
//Escaping Magic Quotes
/**
* FUNCTION USED TO MAKE TAGS MORE PERFECT
* @ Author : Arslan Hassan < arslan @ clip - bucket . com , arslan @ labguru . com >
* @ param tags text unformatted
* returns tags formatted
*/
function genTags ( $tags , $sep = ',' )
{
//Remove fazool spaces
$tags = preg_replace ( array ( '/ ,/' , '/, /' ), ',' , $tags );
$tags = preg_replace ( " `[,]+` " , " , " , $tags );
$tag_array = explode ( $sep , $tags );
foreach ( $tag_array as $tag )
{
if ( isValidtag ( $tag ))
{
$newTags [] = $tag ;
}
}
//Creating new tag string
if ( is_array ( $newTags ))
$tagString = implode ( ',' , $newTags );
else
$tagString = 'no-tag' ;
return $tagString ;
}
/**
* FUNCTION USED TO VALIDATE TAG
* @ Author : Arslan Hassan < arslan @ clip - bucket . com , arslan @ labguru . com >
* @ param tag
* return true or false
*/
function isValidtag ( $tag )
{
$disallow_array = array
( 'of' , 'is' , 'no' , 'on' , 'off' , 'a' , 'the' , 'why' , 'how' , 'what' , 'in' );
if ( ! in_array ( $tag , $disallow_array ) && strlen ( $tag ) > 2 )
return true ;
else
return false ;
}
/**
* FUNCTION USED TO GET CATEGORY LIST
*/
function getCategoryList ( $params = false )
{
global $cats ;
$cats = " " ;
$type = $params [ 'type' ];
switch ( $type )
{
default :
{
cb_call_functions ( 'categoryListing' , $params );
}
break ;
case " video " : case " videos " :
case " v " :
{
global $cbvid ;
$cats = $cbvid -> cbCategories ( $params );
}
break ;
case " users " : case " user " :
case " u " : case " channels " : case " channels " :
{
global $userquery ;
$cats = $userquery -> cbCategories ( $params );
}
break ;
case " group " : case " groups " :
case " g " :
{
global $cbgroup ;
$cats = $cbgroup -> cbCategories ( $params );
}
break ;
case " collection " : case " collections " :
case " cl " :
{
global $cbcollection ;
$cats = $cbcollection -> cbCategories ( $params );
}
break ;
}
return $cats ;
}
/* function getCategoryList ( $type = 'video' , $with_all = false , $return_html = false )
{
$use_subs = config ( 'use_subs' );
switch ( $type )
{
case " video " :
default :
{
global $cbvid ;
if ( $return_html && $use_subs == " 1 " ) {
$cats = $cbvid -> cb_list_categories ( $type , $with_all );
} else {
if ( $with_all )
$all_cat = array ( array ( 'category_id' => 'all' , 'category_name' => 'All' ));
$cats = $cbvid -> get_categories ();
if ( $all_cat && is_array ( $cats ))
$cats = array_merge ( $all_cat , $cats );
}
return $cats ;
}
break ;
case " user " :
{
global $userquery ;
if ( $return_html && $use_subs == " 1 " ) {
$cats = $userquery -> cb_list_categories ( $type , $with_all );
} else {
if ( $with_all )
$all_cat = array ( array ( 'category_id' => 'all' , 'category_name' => 'All' ));
$cats = $userquery -> get_categories ();
if ( $all_cat && is_array ( $cats ))
$cats = array_merge ( $all_cat , $cats );
}
return $cats ;
}
break ;
case " group " :
case " groups " :
{
global $cbgroup ;
if ( $return_html && $use_subs == " 1 " ) {
$cats = $cbgroup -> cb_list_categories ( $type , $with_all );
} else {
if ( $with_all )
$all_cat = array ( array ( 'category_id' => 'all' , 'category_name' => 'All' ));
$cats = $cbgroup -> get_categories ();
if ( $all_cat && is_array ( $cats ))
$cats = array_merge ( $all_cat , $cats );
}
return $cats ;
}
break ;
case " collection " :
case " collections " :
{
global $cbcollection ;
if ( $return_html && $use_subs == " 1 " ) {
$cats = $cbcollection -> cb_list_categories ( $type , $with_all );
} else {
if ( $with_all )
$all_cat = array ( array ( 'category_id' => 'all' , 'category_name' => 'All' ));
$cats = $cbcollection -> get_categories ();
if ( $all_cat && is_array ( $cats ))
$cats = array_merge ( $all_cat , $cats );
}
return $cats ;
}
break ;
}
} */
function cb_bottom ()
{
//Woops..its gone
}
function getSmartyCategoryList ( $params )
{
return getCategoryList ( $params );
}
//Function used to register function as multiple modifiers
/**
* Function used to insert data in database
* @ param : table name
* @ param : fields array
* @ param : values array
* @ param : extra params
*/
function dbInsert ( $tbl , $flds , $vls , $ep = NULL )
{
global $db ;
$db -> insert ( $tbl , $flds , $vls , $ep );
}
/**
* Function used to Update data in database
* @ param : table name
* @ param : fields array
* @ param : values array
* @ param : Condition params
* @ params : Extra params
*/
function dbUpdate ( $tbl , $flds , $vls , $cond , $ep = NULL )
{
global $db ;
return $db -> update ( $tbl , $flds , $vls , $cond , $ep );
}
/**
* Function used to Delete data in database
* @ param : table name
* @ param : fields array
* @ param : values array
* @ params : Extra params
*/
function dbDelete ( $tbl , $flds , $vls , $ep = NULL )
{
global $db ;
return $db -> delete ( $tbl , $flds , $vls , $ep );
}
/**
**
*/
function cbRocks ()
{
define ( " isCBSecured " , TRUE );
//echo cbSecured(CB_SIGN);
}
/**
* Insert Id
*/
function get_id ( $code )
{
global $Cbucket ;
$id = $Cbucket -> ids [ $code ];
if ( empty ( $id )) $id = $code ;
return $id ;
}
/**
* Set Id
*/
function set_id ( $code , $id )
{
global $Cbucket ;
return $Cbucket -> ids [ $code ] = $id ;
}
/**
* Function used to select data from database
*/
function dbselect ( $tbl , $fields = '*' , $cond = false , $limit = false , $order = false , $p = false )
{
global $db ;
return $db -> dbselect ( $tbl , $fields , $cond , $limit , $order , $p );
}
/**
* An easy function for erorrs and messages ( e is basically short form of exception )
* I dont want to use the whole Trigger and Exception code , so e pretty works for me : D
* @ param TEXT $msg
* @ param TYPE $type ( e for Error , m for Message
* @ param INT $id Any Predefined Message ID
*/
function e ( $msg = NULL , $type = 'e' , $id = NULL )
{
global $eh ;
if ( ! empty ( $msg ))
return $eh -> e ( $msg , $type , $id );
}
/**
* Function used to get subscription template
*/
function get_subscription_template ()
{
global $LANG ;
return lang ( 'user_subscribe_message' );
}
/**
* Short form of print_r as pr
*/
function pr ( $text , $wrap_pre = false )
{
if ( ! $wrap_pre )
print_r ( $text );
else
{
echo " <pre> " ;
print_r ( $text );
echo " </pre> " ;
}
2015-07-30 10:34:15 +00:00
}
/**
* PR extended into auto exiting
*/
function pex ( $text , $wrap_pre = false )
{
if ( ! $wrap_pre )
print_r ( $text );
else
{
echo " <pre> " ;
print_r ( $text );
echo " </pre> " ;
exit ( " PEX Ran! " );
}
2013-10-07 12:17:06 +00:00
}
/**
* This function is used to call function in smarty template
* This wont let you pass parameters to the function , but it will only call it
*/
function FUNC ( $params )
{
global $Cbucket ;
//Function used to call functions by
//{func namefunction_name}
// in smarty
$func = $params [ 'name' ];
if ( function_exists ( $func ))
$func ();
}
/**
* Function used to get userid anywhere
* if there is no user_id it will return false
*/
function user_id ()
{
global $userquery ;
if ( $userquery -> userid != '' && $userquery -> is_login ) return $userquery -> userid ; else false ;
}
//replica
function userid (){ return user_id ();}
/**
* Function used to get username anywhere
* if there is no usern_name it will return false
*/
function user_name ()
{
global $userquery ;
if ( $userquery -> user_name )
return $userquery -> user_name ;
else
return $userquery -> get_logged_username ();
}
function username (){ return user_name ();}
/**
* Function used to check weather user access or not
*/
function has_access ( $access , $check_only = TRUE , $verify_logged_user = true )
{
global $userquery ;
2014-02-18 14:02:48 +00:00
//dump($userquery->login_check($access,$check_only,$verify_logged_user));
2013-10-07 12:17:06 +00:00
return $userquery -> login_check ( $access , $check_only , $verify_logged_user );
}
/**
* Function used to return mysql time
* @ author : Fwhite
*/
function NOW ()
{
return date ( 'Y-m-d H:i:s' , time ());
}
/**
* Function used to get Regular Expression from database
* @ param : code
*/
function get_re ( $code )
{
global $db ;
$results = $db -> select ( tbl ( " validation_re " ), " * " , " re_code=' $code ' " );
if ( $db -> num_rows > 0 )
{
return $results [ 0 ][ 're_syntax' ];
} else {
return false ;
}
}
function get_regular_expression ( $code )
{
return get_re ( $code );
}
/**
* Function used to check weather input is valid or not
* based on preg_match
*/
function check_re ( $syntax , $text )
{
preg_match ( '/' . $syntax . '/i' , $text , $matches );
if ( ! empty ( $matches [ 0 ]))
{
return true ;
} else {
return false ;
}
}
function check_regular_expression ( $code , $text )
{
return check_re ( $code , $text );
}
/**
* Function used to check field directly
*/
function validate_field ( $code , $text )
{
$syntax = get_re ( $code );
if ( empty ( $syntax ))
return true ;
return check_regular_expression ( $syntax , $text );
}
function is_valid_syntax ( $code , $text )
{
2014-08-08 12:34:21 +00:00
if ( DEV_INGNORE_SYNTAX )
2013-10-07 12:17:06 +00:00
return true ;
return validate_field ( $code , $text );
}
/**
* Function used to apply function on a value
*/
function is_valid_value ( $func , $val )
{
if ( ! function_exists ( $func ))
return true ;
elseif ( ! $func ( $val ))
return false ;
else
return true ;
}
function apply_func ( $func , $val )
{
if ( is_array ( $func ))
{
foreach ( $func as $f )
if ( function_exists ( $f ))
$val = $f ( $val );
} else {
$val = $func ( $val );
}
return $val ;
}
/**
* Function used to validate YES or NO input
*/
function yes_or_no ( $input , $return = yes )
{
$input = strtolower ( $input );
if ( $input != yes && $input != no )
return $return ;
else
return $input ;
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
* Function used to validate category
* INPUT $cat array
*/
function validate_group_category ( $array = NULL )
{
global $cbgroup ;
return $cbgroup -> validate_group_category ( $array );
}
/**
* Function used to validate category
* INPUT $cat array
*/
function validate_collection_category ( $array = NULL )
{
global $cbcollection ;
return $cbcollection -> validate_collection_category ( $array );
}
/**
* Function used to get user avatar
* @ param ARRAY $userdetail
* @ param SIZE $int
*/
function avatar ( $param )
{
global $userquery ;
$udetails = $param [ 'details' ];
$size = $param [ 'size' ];
$uid = $param [ 'uid' ];
return $userquery -> avatar ( $udetails , $size , $uid );
}
/**
* This funcion used to call function dynamically in smarty
*/
function load_form ( $param )
{
$func = $param [ 'name' ];
if ( function_exists ( $func ))
return $func ( $param );
}
/**
* Function used to get PHP Path
*/
function php_path ()
{
if ( PHP_PATH != '' )
return PHP_PATH ;
else
return " /usr/bin/php " ;
}
/**
* Functon used to get binary paths
*/
function get_binaries ( $path )
{
if ( is_array ( $path ))
{
$type = $path [ 'type' ];
$path = $path [ 'path' ];
}
if ( $type == '' || $type == 'user' )
{
$path = strtolower ( $path );
switch ( $path )
{
case " php " :
return php_path ();
break ;
case " mp4box " :
return config ( " mp4boxpath " );
break ;
2015-08-17 14:11:40 +00:00
case " media_info " :
return config ( " media_info " );
break ;
case " i_magick " :
return config ( " i_magick " );
break ;
case " ffprobe_path " :
return config ( " ffprobe_path " );
break ;
2013-10-07 12:17:06 +00:00
case " flvtool2 " :
return config ( " flvtool2path " );
break ;
case " ffmpeg " :
return config ( " ffmpegpath " );
break ;
}
} else {
$path = strtolower ( $path );
switch ( $path )
{
case " php " :
$return_path = shell_output ( " which php " );
if ( $return_path )
return $return_path ;
else
return " Unable to find PHP path " ;
break ;
case " mp4box " :
$return_path = shell_output ( " which MP4Box " );
if ( $return_path )
return $return_path ;
else
return " Unable to find mp4box path " ;
break ;
case " flvtool2 " :
$return_path = shell_output ( " which flvtool2 " );
if ( $return_path )
return $return_path ;
else
return " Unable to find flvtool2 path " ;
break ;
case " ffmpeg " :
$return_path = shell_output ( " which ffmpeg " );
2013-10-08 12:24:07 +00:00
if ( $return_path )
return $return_path ;
else
return " Unable to find ffmpeg path " ;
break ;
}
}
}
2013-10-07 12:17:06 +00:00
/**
2013-10-08 12:24:07 +00:00
* Function in case htmlspecialchars_decode does not exist
2013-10-07 12:17:06 +00:00
*/
2013-10-08 12:24:07 +00:00
function unhtmlentities ( $string )
2013-10-07 12:17:06 +00:00
{
2013-10-08 12:24:07 +00:00
$trans_tbl = get_html_translation_table ( HTML_ENTITIES );
$trans_tbl = array_flip ( $trans_tbl );
return strtr ( $string , $trans_tbl );
2013-10-07 12:17:06 +00:00
}
/**
* Function used to execute command in background
*/
function bgexec ( $cmd ) {
if ( substr ( php_uname (), 0 , 7 ) == " Windows " ){
//exec($cmd." >> /dev/null &");
exec ( $cmd );
//pclose(popen("start \"bla\" \"" . $exe . "\" " . escapeshellarg($args), "r"));
} else {
exec ( $cmd . " > /dev/null & " );
}
}
/**
* Function used to get array value
* if you know partial value of array and wants to know complete
* value of an array , this function is being used then
*/
function array_find ( $needle , $haystack )
{
foreach ( $haystack as $item )
{
if ( strpos ( $item , $needle ) !== FALSE )
{
return $item ;
break ;
}
}
}
/**
* Function used to give output in proper form
*/
function input_value ( $params )
{
$input = $params [ 'input' ];
$value = $input [ 'value' ];
if ( $input [ 'value_field' ] == 'checked' )
$value = $input [ 'checked' ];
if ( $input [ 'return_checked' ])
return $input [ 'checked' ];
if ( function_exists ( $input [ 'display_function' ]))
return $input [ 'display_function' ]( $value );
elseif ( $input [ 'type' ] == 'dropdown' )
{
if ( $input [ 'checked' ])
return $value [ $input [ 'checked' ]];
else
return $value [ 0 ];
} else
return $input [ 'value' ];
}
/**
* Function used to convert input to categories
* @ param input can be an array or #12# like
*/
function convert_to_categories ( $input )
{
if ( is_array ( $input ))
{
foreach ( $input as $in )
{
if ( is_array ( $in ))
{
foreach ( $in as $i )
{
if ( is_array ( $i ))
{
foreach ( $i as $info )
{
$cat_details = get_category ( $info );
$cat_array [] = array ( $cat_details [ 'categoryid' ], $cat_details [ 'category_name' ]);
}
} elseif ( is_numeric ( $i )){
$cat_details = get_category ( $i );
$cat_array [] = array ( $cat_details [ 'categoryid' ], $cat_details [ 'category_name' ]);
}
}
} elseif ( is_numeric ( $in )){
$cat_details = get_category ( $in );
$cat_array [] = array ( $cat_details [ 'categoryid' ], $cat_details [ 'category_name' ]);
}
}
} else {
preg_match_all ( '/#([0-9]+)#/' , $default [ 'category' ], $m );
$cat_array = array ( $m [ 1 ]);
foreach ( $cat_array as $i )
{
$cat_details = get_category ( $i );
$cat_array [] = array ( $cat_details [ 'categoryid' ], $cat_details [ 'category_name' ]);
}
}
$count = 1 ;
if ( is_array ( $cat_array ))
{
foreach ( $cat_array as $cat )
{
echo '<a href="' . $cat [ 0 ] . '">' . $cat [ 1 ] . '</a>' ;
if ( $count != count ( $cat_array ))
echo ', ' ;
$count ++ ;
}
}
}
/**
* Function used to get categorie details
*/
function get_category ( $id )
{
global $myquery ;
return $myquery -> get_category ( $id );
}
/**
* Sharing OPT displaying
*/
function display_sharing_opt ( $input )
{
foreach ( $input as $key => $i )
{
return $key ;
break ;
}
}
/**
* Function used to get number of videos uploaded by user
* @ param INT userid
* @ param Conditions
*/
function get_user_vids ( $uid , $cond = NULL , $count_only = false )
{
global $userquery ;
return $userquery -> get_user_vids ( $uid , $cond , $count_only );
}
/**
* Function used to get error_list
*/
function error_list ()
{
global $eh ;
return $eh -> error_list ;
}
/**
* Function used to get msg_list
*/
function msg_list ()
{
global $eh ;
return $eh -> message_list ;
}
/**
* Function used to add tempalte in display template list
* @ param File : file of the template
* @ param Folder : weather to add template folder or not
* if set to true , file will be loaded from inside the template
* such that file path will becom $templatefolder / $file
* @ param follow_show_page : this param tells weather to follow ClipBucket -> show_page
* variable or not , if show_page is set to false and follow is true , this template will not load
* otherwise there it WILL
*/
function template_files ( $file , $folder = false , $follow_show_page = true )
{
global $ClipBucket ;
if ( ! $folder )
$ClipBucket -> template_files [] = array ( 'file' => $file , 'follow_show_page' => $follow_show_page );
else
$ClipBucket -> template_files [] = array ( 'file' => $file ,
'folder' => $folder , 'follow_show_page' => $follow_show_page );
}
/**
* Function used to include file
*/
function include_template_file ( $params )
{
$file = $params [ 'file' ];
if ( file_exists ( LAYOUT . '/' . $file ))
Template ( $file );
elseif ( file_exists ( $file ))
Template ( $file , false );
}
/**
* Function used to display hint
*/
function hint ( $hint )
{
}
function showpagination ( $total , $page , $link , $extra_params = NULL , $tag = '<a #params#>#page#</a>' )
{
global $pages ;
return $pages -> pagination ( $total , $page , $link , $extra_params , $tag );
}
/**
* Function used to check username is disallowed or not
* @ param USERNAME
*/
function check_disallowed_user ( $username )
{
global $Cbucket ;
$disallowed_user = $Cbucket -> configs [ 'disallowed_usernames' ];
$censor_users = explode ( ',' , $disallowed_user );
if ( in_array ( $username , $censor_users ))
return false ;
else
return true ;
}
/**
* Function used to validate username
* @ input USERNAME
*/
function username_check ( $username )
{
global $Cbucket ;
$banned_words = $Cbucket -> configs [ 'disallowed_usernames' ];
$banned_words = explode ( ',' , $banned_words );
foreach ( $banned_words as $word )
{
preg_match ( " / $word /Ui " , $username , $match );
if ( ! empty ( $match [ 0 ]))
return false ;
}
//Checking if its syntax is valid or not
$multi = config ( 'allow_unicode_usernames' );
//Checking Spaces
if ( ! config ( 'allow_username_spaces' ))
preg_match ( '/ /' , $username , $matches );
if ( ! is_valid_syntax ( 'username' , $username ) && $multi != 'yes' || $matches )
e ( lang ( " class_invalid_user " ));
return true ;
}
/**
* Function used to check weather username already exists or not
* @ input USERNAME
*/
function user_exists ( $user )
{
global $userquery ;
return $userquery -> username_exists ( $user );
}
/**
* Function used to check weather email already exists or not
* @ input email
*/
function email_exists ( $user )
{
global $userquery ;
return $userquery -> duplicate_email ( $user );
}
/**
* function used to check weather group URL exists or not
*/
function group_url_exists ( $url )
{
global $cbgroup ;
return $cbgroup -> group_url_exists ( $url );
}
/**
* Function used to check weather erro exists or not
*/
function error ( $param = 'array' )
{
if ( count ( error_list ()) > 0 )
{
if ( $param != 'array' )
{
if ( $param == 'single' )
$param = 0 ;
$msg = error_list ();
return $msg [ $param ];
}
return error_list ();
} else {
return false ;
}
}
/**
* Function used to check weather msg exists or not
*/
function msg ( $param = 'array' )
{
if ( count ( msg_list ()) > 0 )
{
if ( $param != 'array' )
{
if ( $param == 'single' )
$param = 0 ;
$msg = msg_list ();
return $msg [ $param ];
}
return msg_list ();
} else {
return false ;
}
}
/**
* Function used to load plugin
* please check docs . clip - bucket . com
*/
function load_plugin ()
{
global $cbplugin ;
}
/**
* Function used to create limit functoin from current page & results
*/
function create_query_limit ( $page , $result )
{
$limit = $result ;
if ( empty ( $page ) || $page == 0 || ! is_numeric ( $page )){
$page = 1 ;
}
$from = $page - 1 ;
$from = $from * $limit ;
return $from . ',' . $result ;
}
/**
* Function used to get value from $_GET
*/
function get_form_val ( $val , $filter = false )
{
if ( $filter )
return form_val ( $_GET [ $val ]);
else
return $_GET [ $val ];
} function get ( $val ){ return get_form_val ( $val ); }
/**
* Function used to get value form $_POST
*/
function post_form_val ( $val , $filter = false )
{
if ( $filter )
return form_val ( $_POST [ $val ]);
else
$_POST [ $val ];
}
/**
* Function used to get value from $_REQUEST
*/
function request_form_val ( $val , $filter = false )
{
if ( $filter )
return form_val ( $_REQUEST [ $val ]);
else
$_REQUEST [ $val ];
}
/**
* Function used to return LANG variable
*/
function lang ( $var , $sprintf = false )
{
global $LANG , $Cbucket ;
$array_str = array
( '{title}' );
$array_replace = array
( $Cbucket -> configs [ 'site_title' ] );
2014-02-18 14:02:48 +00:00
if ( isset ( $LANG [ $var ]))
2013-10-07 12:17:06 +00:00
{
$phrase = str_replace ( $array_str , $array_replace , $LANG [ $var ]);
} else
{
$phrase = str_replace ( $array_str , $array_replace , $var );
}
if ( $sprintf )
{
$sprints = explode ( ',' , $sprintf );
if ( is_array ( $sprints ))
{
foreach ( $sprints as $sprint )
{
$phrase = sprintf ( $phrase , $sprint );
}
}
}
return $phrase ;
}
2016-03-04 02:01:49 -08:00
/**
* Fetch lang value from smarty using lang code
* @ param : { array } { $param } { array of parameters }
* @ uses : { function lang () }
*/
function smarty_lang ( $param ) {
if ( getArrayValue ( $param , 'assign' ) == '' ) {
2014-02-18 14:02:48 +00:00
return lang ( $param [ 'code' ], getArrayValue ( $param , 'sprintf' ));
2016-03-04 02:01:49 -08:00
} else {
2013-10-07 12:17:06 +00:00
assign ( $param [ 'assign' ], lang ( $param [ 'code' ], $param [ 'sprintf' ]));
2016-03-04 02:01:49 -08:00
}
2013-10-07 12:17:06 +00:00
}
2013-10-08 12:24:07 +00:00
2016-03-04 02:01:49 -08:00
/**
* Get an array element by key
* @ param : { array } { $array } { array to check for element }
* @ param : { string / integeger } { $key } { element name or key }
* @ return : { value / false } { element value if found , else false }
*/
2013-10-08 12:24:07 +00:00
2014-02-18 14:02:48 +00:00
function getArrayValue ( $array = array (), $key = false ){
if ( ! empty ( $array ) && $key ){
if ( isset ( $array [ $key ])){
return $array [ $key ];
2016-03-04 02:01:49 -08:00
} else {
2014-02-18 14:02:48 +00:00
return false ;
}
}
return false ;
}
2016-03-04 02:01:49 -08:00
/**
* Fetch value of a constant
* @ param : { string } { $constantName } { false by default , name of constant }
* @ return : { val / false } { constant value if found , else fasle }
* @ ref : { http :// php . net / manual / en / function . constant . php }
*/
2014-02-18 14:02:48 +00:00
function getConstant ( $constantName = false ){
2016-03-04 02:01:49 -08:00
if ( $constantName && defined ( $constantName )) {
2014-02-18 14:02:48 +00:00
return constant ( $constantName );
2016-03-04 02:01:49 -08:00
} else {
return false ;
}
2014-02-18 14:02:48 +00:00
}
2013-10-07 12:17:06 +00:00
/**
2016-03-04 02:01:49 -08:00
* Function used to assign link
* @ param : { array } { $params } { an array of parameters }
* @ return : { stirng } { buils link }
*/
function cblink ( $params ) {
2013-10-07 12:17:06 +00:00
global $ClipBucket ;
2014-02-18 14:02:48 +00:00
$name = getArrayValue ( $params , 'name' );
$ref = getArrayValue ( $params , 'ref' );
2016-03-04 02:01:49 -08:00
if ( $name == 'category' ) {
2013-10-07 12:17:06 +00:00
return category_link ( $params [ 'data' ], $params [ 'type' ]);
}
2016-03-04 02:01:49 -08:00
if ( $name == 'sort' ) {
2013-10-07 12:17:06 +00:00
return sort_link ( $params [ 'sort' ], 'sort' , $params [ 'type' ]);
}
2016-03-04 02:01:49 -08:00
if ( $name == 'time' ) {
2013-10-07 12:17:06 +00:00
return sort_link ( $params [ 'sort' ], 'time' , $params [ 'type' ]);
}
2016-03-04 02:01:49 -08:00
if ( $name == 'tag' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/search_result.php?query=' . urlencode ( $params [ 'tag' ]) . '&type=' . $params [ 'type' ];
}
2016-03-04 02:01:49 -08:00
if ( $name == 'category_search' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/search_result.php?category[]=' . $params [ 'category' ] . '&type=' . $params [ 'type' ];
}
2016-03-04 02:01:49 -08:00
if ( SEO != 'yes' ) {
2013-10-07 12:17:06 +00:00
preg_match ( '/http:\/\//' , $ClipBucket -> links [ $name ][ 0 ], $matches );
2016-03-04 02:01:49 -08:00
if ( $matches ) {
2013-10-07 12:17:06 +00:00
$link = $ClipBucket -> links [ $name ][ 0 ];
2016-03-04 02:01:49 -08:00
} else {
2013-10-07 12:17:06 +00:00
$link = BASEURL . '/' . $ClipBucket -> links [ $name ][ 0 ];
2016-03-04 02:01:49 -08:00
}
} else {
2013-10-07 12:17:06 +00:00
preg_match ( '/http:\/\//' , $ClipBucket -> links [ $name ][ 1 ], $matches );
2016-03-04 02:01:49 -08:00
if ( $matches ) {
2013-10-07 12:17:06 +00:00
$link = $ClipBucket -> links [ $name ][ 1 ];
2016-03-04 02:01:49 -08:00
} else {
2013-10-07 12:17:06 +00:00
$link = BASEURL . '/' . $ClipBucket -> links [ $name ][ 1 ];
2016-03-04 02:01:49 -08:00
}
2013-10-07 12:17:06 +00:00
}
$param_link = " " ;
2016-03-04 02:01:49 -08:00
if ( ! empty ( $params [ 'extra_params' ])) {
2013-10-07 12:17:06 +00:00
preg_match ( '/\?/' , $link , $matches );
2016-03-04 02:01:49 -08:00
if ( ! empty ( $matches [ 0 ])) {
2013-10-07 12:17:06 +00:00
$param_link = '&' . $params [ 'extra_params' ];
2016-03-04 02:01:49 -08:00
} else {
2013-10-07 12:17:06 +00:00
$param_link = '?' . $params [ 'extra_params' ];
}
}
2016-03-04 02:01:49 -08:00
if ( isset ( $params [ 'assign' ])) {
2013-10-07 12:17:06 +00:00
assign ( $params [ 'assign' ], $link . $param_link );
2016-03-04 02:01:49 -08:00
} else {
2013-10-07 12:17:06 +00:00
return $link . $param_link ;
2016-03-04 02:01:49 -08:00
}
2013-10-07 12:17:06 +00:00
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
2016-03-04 02:01:49 -08:00
* Function used to show rating
* @ param : { array } { $params } { array of parameters }
*/
function show_rating ( $params ) {
2013-10-07 12:17:06 +00:00
$class = $params [ 'class' ] ? $params [ 'class' ] : 'rating_stars' ;
$rating = $params [ 'rating' ];
$ratings = $params [ 'ratings' ];
$total = $params [ 'total' ];
$style = $params [ 'style' ];
if ( empty ( $style ))
$style = config ( 'rating_style' );
2016-03-04 02:01:49 -08:00
2013-10-07 12:17:06 +00:00
//Checking Percent
{
if ( $total <= 10 )
$total = 10 ;
$perc = $rating * 100 / $total ;
$disperc = 100 - $perc ;
if ( $ratings <= 0 && $disperc == 100 )
$disperc = 0 ;
2016-03-04 02:01:49 -08:00
}
2013-10-07 12:17:06 +00:00
$perc = $perc . '%' ;
$disperc = $disperc . " % " ;
2016-03-04 02:01:49 -08:00
switch ( $style ) {
2013-10-07 12:17:06 +00:00
case " percentage " : case " percent " :
case " perc " : default :
{
$likeClass = " UserLiked " ;
2016-03-04 02:01:49 -08:00
if ( str_replace ( '%' , '' , $perc ) < '50' ) {
$likeClass = 'UserDisliked' ;
}
2013-10-07 12:17:06 +00:00
$ratingTemplate = '<div class="' . $class . ' " >
< div class = " ratingContainer " >
< span class = " ratingText " > '.$perc.' </ span > ' ;
2016-03-04 02:01:49 -08:00
if ( $ratings > 0 ) {
2013-10-07 12:17:06 +00:00
$ratingTemplate .= ' <span class="' . $likeClass . '"> </span>' ;
2016-03-04 02:01:49 -08:00
}
2013-10-07 12:17:06 +00:00
$ratingTemplate .= ' </ div >
</ div > ' ;
}
break ;
case " bars " : case " Bars " : case " bar " :
{
$ratingTemplate = '<div class="' . $class . ' " >
< div class = " ratingContainer " >
< div class = " LikeBar " style = " width:'. $perc .' " ></ div >
< div class = " DislikeBar " style = " width:'. $disperc .' " ></ div >
</ div >
</ div > ' ;
}
break ;
case " numerical " : case " numbers " :
case " number " : case " num " :
{
$likes = round ( $ratings * $perc / 100 );
$dislikes = $ratings - $likes ;
$ratingTemplate = '<div class="' . $class . ' " >
< div class = " ratingContainer " >
< div class = " ratingText " >
< span class = " LikeText " > '.$likes.' Likes </ span >
< span class = " DislikeText " > '.$dislikes.' Dislikes </ span >
</ div >
</ div >
</ div > ' ;
}
break ;
case " custom " : case " own_style " :
{
$file = LAYOUT . " / " . $params [ 'file' ];
2016-03-04 02:01:49 -08:00
if ( ! empty ( $params [ 'file' ]) && file_exists ( $file )) {
2013-10-07 12:17:06 +00:00
// File exists, lets start assign things
assign ( " perc " , $perc ); assign ( " disperc " , $disperc );
// Likes and Dislikes
$likes = floor ( $ratings * $perc / 100 );
$dislikes = $ratings - $likes ;
assign ( " likes " , $likes ); assign ( " dislikes " , $dislikes );
Template ( $file , FALSE );
} else {
$params [ 'style' ] = " percent " ;
return show_rating ( $params );
}
}
break ;
}
return $ratingTemplate ;
}
/**
2016-03-04 02:01:49 -08:00
* Function used to display an ad
*/
function ad ( $in ) {
2013-10-07 12:17:06 +00:00
return stripslashes ( htmlspecialchars_decode ( $in ));
}
/**
2016-03-04 02:01:49 -08:00
* Function used to get available function list
* for special place , read docs . clip - bucket . com
*/
function get_functions ( $name ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
2014-02-18 14:02:48 +00:00
if ( isset ( $Cbucket -> $name )){
$funcs = $Cbucket -> $name ;
2016-03-04 02:01:49 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
2014-02-18 14:02:48 +00:00
return $funcs ;
2016-03-04 02:01:49 -08:00
} else {
2014-02-18 14:02:48 +00:00
return false ;
2016-03-04 02:01:49 -08:00
}
2014-02-18 14:02:48 +00:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-04 02:01:49 -08:00
* Function used to add js in ClipBuckets JSArray
* @ uses { class : $ Cbucket } { function : addJS }
*/
function add_js ( $files ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
return $Cbucket -> addJS ( $files );
}
/**
2016-03-04 02:01:49 -08:00
* Function add_header ()
* this will be used to add new files in header array
* this is basically for plugins
* for specific page array ( 'page' => 'file' )
* ie array ( 'uploadactive' => 'datepicker.js' )
*
* @ uses : { class : $ Cbucket } { function : add_header }
*/
function add_header ( $files ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
return $Cbucket -> add_header ( $files );
}
2016-03-04 02:01:49 -08:00
/**
* Adds admin header
* @ uses : { class : $ Cbucket } { function : add_admin_header }
*/
function add_admin_header ( $files ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
return $Cbucket -> add_admin_header ( $files );
}
/**
2016-03-04 02:01:49 -08:00
* Functions used to call functions when users views a channel
* @ param : { array } { $u } { array with details of user }
*/
function call_view_channel_functions ( $u ) {
2013-10-07 12:17:06 +00:00
$funcs = get_functions ( 'view_channel_functions' );
2016-03-04 02:01:49 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
foreach ( $funcs as $func ) {
if ( function_exists ( $func )) {
2013-10-07 12:17:06 +00:00
$func ( $u );
}
}
}
increment_views ( $u [ 'userid' ], " channel " );
}
/**
2016-03-04 02:01:49 -08:00
* Functions used to call functions when users views a group topic
* @ param : { array } { $tdetails } { array with details of group topic }
* @ deprecated : { function has been deprecated and will be removed in next version }
*/
function call_view_topic_functions ( $tdetails ) {
2013-10-07 12:17:06 +00:00
$funcs = get_functions ( 'view_topic_functions' );
2016-03-04 02:01:49 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
foreach ( $funcs as $func ) {
if ( function_exists ( $func )) {
2013-10-07 12:17:06 +00:00
$func ( $tdetails );
}
}
}
increment_views ( $tdetails [ 'topic_id' ], " topic " );
}
/**
2016-03-04 02:01:49 -08:00
* Functions used to call functions when users views a group
* @ param : { array } { $gdetails } { array with details of group }
* @ deprecated : { function has been deprecated and will be removed in next version }
*/
function call_view_group_functions ( $gdetails ) {
2013-10-07 12:17:06 +00:00
$funcs = get_functions ( 'view_group_functions' );
2016-03-04 02:01:49 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
foreach ( $funcs as $func ) {
if ( function_exists ( $func )) {
2013-10-07 12:17:06 +00:00
$func ( $gdetails );
}
}
}
increment_views ( $gdetails [ 'group_id' ], " group " );
}
/**
2016-03-04 02:01:49 -08:00
* Functions used to call functions when users views a collection
* @ param : { array } { $cdetails } { array with details of collection }
*/
function call_view_collection_functions ( $cdetails ) {
2013-10-07 12:17:06 +00:00
$funcs = get_functions ( 'view_collection_functions' );
2016-03-04 02:01:49 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
foreach ( $funcs as $func ) {
if ( function_exists ( $func )) {
2013-10-07 12:17:06 +00:00
$func ( $cdetails );
}
}
};
increment_views ( $cdetails [ 'collection_id' ], " collection " );
}
/**
2016-03-04 02:01:49 -08:00
* Function used to increment views of an object
*
* @ param : { integer } { $id } { id of element to update views for }
* @ param : { string } { $type } { type of object e . g video , user }
* @ return : { null }
* @ action : database updating
*/
function increment_views ( $id , $type = NULL ) {
2013-10-07 12:17:06 +00:00
global $db ;
2016-03-04 02:01:49 -08:00
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case 'v' :
case 'video' :
default :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'video_' . $id ])) {
2014-03-18 06:17:34 +00:00
$currentTime = time ();
file_put_contents ( " /home/sajjad/Desktop/log.txt " , json_encode ( $videoViewsRecord ));
$views = ( int ) $videoViewsRecord [ " video_views " ] + 1 ;
$db -> update ( tbl ( " video_views " ), array ( " video_views " , " last_updated " ), array ( $views , $currentTime ), " video_id=' $id ' OR videokey=' $id ' " );
$query = " UPDATE " . tbl ( " video_views " ) . " SET video_views = video_views + 1 WHERE video_id = { $id } " ;
$result = $db -> Execute ( $query );
setcookie ( 'video_' . $id , 'watched' , time () + 3600 );
2013-10-07 12:17:06 +00:00
}
}
break ;
case 'u' :
case 'user' :
case 'channel' :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'user_' . $id ])) {
2013-10-07 12:17:06 +00:00
$db -> update ( tbl ( " users " ), array ( " profile_hits " ), array ( " |f|profile_hits+1 " ), " userid=' $id ' " );
setcookie ( 'user_' . $id , 'watched' , time () + 3600 );
}
}
break ;
case 't' :
case 'topic' :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'topic_' . $id ])) {
2013-10-07 12:17:06 +00:00
$db -> update ( tbl ( " group_topics " ), array ( " total_views " ), array ( " |f|total_views+1 " ), " topic_id=' $id ' " );
setcookie ( 'topic_' . $id , 'watched' , time () + 3600 );
}
}
break ;
break ;
case 'g' :
case 'group' :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'group_' . $id ])) {
2013-10-07 12:17:06 +00:00
$db -> update ( tbl ( " groups " ), array ( " total_views " ), array ( " |f|total_views+1 " ), " group_id=' $id ' " );
setcookie ( 'group_' . $id , 'watched' , time () + 3600 );
}
}
break ;
case " c " :
case " collect " :
case " collection " :
2014-03-17 07:48:56 +00:00
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'collection_' . $id ])) {
2014-03-17 07:48:56 +00:00
$db -> update ( tbl ( " collections " ), array ( " views " ), array ( " |f|views+1 " ), " collection_id = ' $id ' " );
setcookie ( 'collection_' . $id , 'viewed' , time () + 3600 );
}
}
break ;
case " photos " :
case " photo " :
case " p " :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'photo_' . $id ])) {
2014-03-17 07:48:56 +00:00
$db -> update ( tbl ( 'photos' ), array ( " views " , " last_viewed " ), array ( " |f|views+1 " , NOW ()), " photo_id = ' $id ' " );
setcookie ( 'photo_' . $id , 'viewed' , time () + 3600 );
}
}
}
}
2016-03-04 02:01:49 -08:00
/**
* Function used to increment views of an object
*
* @ param : { integer } { $id } { id of element to update views for }
* @ param : { string } { $type } { type of object e . g video , user }
* @ return : { null }
* @ action : database updating
*/
2014-04-15 06:49:00 +00:00
2016-03-04 02:01:49 -08:00
function increment_views_new ( $id , $type = NULL ) {
2014-03-17 07:48:56 +00:00
global $db ;
2016-03-04 02:01:49 -08:00
switch ( $type ) {
2014-03-17 07:48:56 +00:00
case 'v' :
case 'video' :
default :
2014-04-15 06:49:00 +00:00
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'video_' . $id ])) {
2014-03-17 13:59:51 +00:00
$currentTime = time ();
2014-04-15 06:49:00 +00:00
$db -> update ( tbl ( " video " ), array ( " views " , " last_viewed " ), array ( " |f|views+1 " , $currentTime ), " videoid=' $id ' OR videokey=' $id ' " );
2014-03-17 07:48:56 +00:00
setcookie ( 'video_' . $id , 'watched' , time () + 3600 );
}
}
break ;
case 'u' :
case 'user' :
case 'channel' :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'user_' . $id ])) {
2014-03-17 07:48:56 +00:00
$db -> update ( tbl ( " users " ), array ( " profile_hits " ), array ( " |f|profile_hits+1 " ), " userid=' $id ' " );
setcookie ( 'user_' . $id , 'watched' , time () + 3600 );
}
}
break ;
case 't' :
case 'topic' :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'topic_' . $id ])) {
2014-03-17 07:48:56 +00:00
$db -> update ( tbl ( " group_topics " ), array ( " total_views " ), array ( " |f|total_views+1 " ), " topic_id=' $id ' " );
setcookie ( 'topic_' . $id , 'watched' , time () + 3600 );
}
}
break ;
break ;
case 'g' :
case 'group' :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'group_' . $id ])) {
2014-03-17 07:48:56 +00:00
$db -> update ( tbl ( " groups " ), array ( " total_views " ), array ( " |f|total_views+1 " ), " group_id=' $id ' " );
setcookie ( 'group_' . $id , 'watched' , time () + 3600 );
}
}
break ;
case " c " :
case " collect " :
case " collection " :
2013-10-07 12:17:06 +00:00
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'collection_' . $id ])) {
2013-10-07 12:17:06 +00:00
$db -> update ( tbl ( " collections " ), array ( " views " ), array ( " |f|views+1 " ), " collection_id = ' $id ' " );
setcookie ( 'collection_' . $id , 'viewed' , time () + 3600 );
}
}
break ;
case " photos " :
case " photo " :
case " p " :
{
2016-03-04 02:01:49 -08:00
if ( ! isset ( $_COOKIE [ 'photo_' . $id ])) {
2013-10-07 12:17:06 +00:00
$db -> update ( tbl ( 'photos' ), array ( " views " , " last_viewed " ), array ( " |f|views+1 " , NOW ()), " photo_id = ' $id ' " );
setcookie ( 'photo_' . $id , 'viewed' , time () + 3600 );
}
}
}
}
/**
2016-03-04 00:11:16 -08:00
* Function used to get post var
* @ param : { string } { $var } { variable to get value for }
*/
function post ( $var ) {
2013-10-07 12:17:06 +00:00
return $_POST [ $var ];
}
/**
2016-03-04 00:11:16 -08:00
* Function used to show flag form
* @ param : { array } { $array } { array of parameters }
*/
function show_share_form ( $array ) {
2013-10-07 12:17:06 +00:00
assign ( 'params' , $array );
2016-03-04 00:11:16 -08:00
if ( SMARTY_VERSION > 2 ) {
2013-11-18 14:59:33 +00:00
Template ( 'blocks/common/share.html' );
2016-03-04 00:11:16 -08:00
} else {
2013-11-18 14:59:33 +00:00
Template ( 'blocks/share_form.html' );
2016-03-04 00:11:16 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-04 00:11:16 -08:00
* Function used to show flag form
* @ param : { array } { $array } { array of parameters }
*/
function show_flag_form ( $array ) {
2013-10-07 12:17:06 +00:00
assign ( 'params' , $array );
2016-03-04 00:11:16 -08:00
if ( SMARTY_VERSION > 2 ) {
2013-11-18 14:59:33 +00:00
Template ( 'blocks/common/report.html' );
2016-03-04 00:11:16 -08:00
} else {
2013-11-18 14:59:33 +00:00
Template ( 'blocks/flag_form.html' );
2016-03-04 00:11:16 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-04 00:11:16 -08:00
* Function used to show playlist form
2015-12-22 07:45:52 +00:00
* @ param : { array } { $array } { array of parameters }
*/
2016-03-04 00:11:16 -08:00
function show_playlist_form ( $array ) {
2013-10-07 12:17:06 +00:00
global $cbvid ;
assign ( 'params' , $array );
2015-12-22 07:45:52 +00:00
// decides to show all or user only playlists
// depending on the parameters passed to it
2016-03-04 00:11:16 -08:00
if ( ! empty ( $array [ 'user' ])) {
2015-12-22 07:45:52 +00:00
$playlists = $cbvid -> action -> get_playlists ( $array );
2016-03-04 00:11:16 -08:00
} else {
2015-12-22 07:45:52 +00:00
$playlists = $cbvid -> action -> get_playlists ();
}
2013-10-07 12:17:06 +00:00
assign ( 'playlists' , $playlists );
2016-03-04 00:11:16 -08:00
Template ( 'blocks/common/playlist.html' );
2014-07-03 03:43:23 +00:00
2013-10-07 12:17:06 +00:00
}
/**
2016-03-04 00:06:52 -08:00
* Function used to show collection form
* @ param : { array } { $params } { array with paramters }
*/
function show_collection_form ( $params ) {
2013-10-07 12:17:06 +00:00
global $db , $cbcollection ;
2016-03-04 00:06:52 -08:00
if ( ! userid ()) {
2013-10-07 12:17:06 +00:00
$loggedIn = " not " ;
2016-03-04 00:06:52 -08:00
} else {
$collectArray = array ( " order " => " collection_name ASC " , " type " => " videos " , " user " => userid ());
$collections = $cbcollection -> get_collections ( $collectArray );
$contributions = $cbcollection -> get_contributor_collections ( userid ());
if ( $contributions ) {
if ( ! $collections ) {
$collections = $contributions ;
} else {
$collections = array_merge ( $collections , $contributions );
}
}
2013-10-07 12:17:06 +00:00
assign ( " collections " , $collections );
assign ( " contributions " , $contributions );
}
Template ( " /blocks/collection_form.html " );
}
2016-03-04 00:04:50 -08:00
/**
* Convert timestam to date
*
* @ param : { string } { $format } { current format of date }
* @ param : { string } { $timestamp } { time to be converted to date }
* @ return : { string } { time formatted into date }
*/
function cbdate ( $format = NULL , $timestamp = NULL ) {
if ( ! $format ) {
2013-10-07 12:17:06 +00:00
$format = config ( " datE_format " );
}
2016-03-04 00:04:50 -08:00
if ( ! $timestamp ) {
2013-10-07 12:17:06 +00:00
return date ( $format );
2016-03-04 00:04:50 -08:00
} else {
2013-10-07 12:17:06 +00:00
return date ( $format , $timestamp );
2016-03-04 00:04:50 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-04 00:02:18 -08:00
* Function used to count pages and return total divided
* @ param { integer } { $total } { total number of pages }
* @ param { integer } { $count } { numeber of pages to be displayed }
* @ return : { integer } { $total_pages } { $total / $count }
*/
function count_pages ( $total , $count ) {
2013-10-07 12:17:06 +00:00
if ( $count < 1 ) $count = 1 ;
$records = $total / $count ;
return $total_pages = round ( $records + 0.49 , 0 );
}
/**
2016-03-03 23:59:19 -08:00
* Fetch user leve against a given userid
* @ uses : { class : $ userquery } { function : usr_levels () }
*/
2016-03-04 00:02:18 -08:00
function get_user_level ( $id ) {
2013-10-07 12:17:06 +00:00
global $userquery ;
return $userquery -> usr_levels [ $id ];
}
2016-03-03 23:58:05 -08:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 23:58:05 -08:00
* This function used to check weather user is online or not
*
* @ param : { string } { $time } { last active time }
* @ param : { integer } { $margin } { time margin }
* @ return : { string }{ status of user e . g online or ofline }
*/
function is_online ( $time , $margin = '5' ) {
2013-10-07 12:17:06 +00:00
$margin = $margin * 60 ;
$active = strtotime ( $time );
$curr = time ();
$diff = $curr - $active ;
2016-03-03 23:58:05 -08:00
if ( $diff > $margin ) {
2013-10-07 12:17:06 +00:00
return 'offline' ;
2016-03-03 23:58:05 -08:00
} else {
2013-10-07 12:17:06 +00:00
return 'online' ;
2016-03-03 23:58:05 -08:00
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:58:05 -08:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 23:55:22 -08:00
* ClipBucket Form Validator
* this function controls the whole logic of how to operate input
* validate it , generate proper error
*
* @ param : { array } { $input } { array of form values }
* @ param : { array } { $array } { array of form fields }
* @ return : { boolean } { true or false based on validation }
*/
function validate_cb_form ( $input , $array ) {
2014-03-07 10:04:33 +00:00
//Check the Collpase Category Checkboxes
2016-03-03 23:55:22 -08:00
if ( $input [ 'cat' ][ 'title' ] == 'Video Category' ) {
2014-03-07 09:15:07 +00:00
global $db ;
$query = " SELECT * FROM " . tbl ( " config " ) . " WHERE configid=234 " ;
2016-03-03 23:55:22 -08:00
$row = db_select ( $query );
2014-03-07 09:15:07 +00:00
$row [ 0 ][ 'value' ] . $input [ 'cat' ][ 'title' ];
2016-03-03 23:55:22 -08:00
if ( $row [ 0 ][ 'value' ] == '0' ) {
2014-03-07 09:15:07 +00:00
unset ( $input [ 'cat' ]);
}
}
2016-03-03 23:55:22 -08:00
if ( is_array ( $input )) {
foreach ( $input as $field ) {
$field [ 'name' ] = formObj :: rmBrackets ( $field [ 'name' ]);
$title = $field [ 'title' ];
$val = $array [ $field [ 'name' ]];
$req = $field [ 'required' ];
$invalid_err = $field [ 'invalid_err' ];
$function_error_msg = $field [ 'function_error_msg' ];
if ( is_string ( $val )) {
if ( ! isUTF8 ( $val ))
$val = utf8_decode ( $val );
$length = strlen ( $val );
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:55:22 -08:00
$min_len = $field [ 'min_length' ];
$min_len = $min_len ? $min_len : 0 ;
$max_len = $field [ 'max_length' ] ;
$rel_val = $array [ $field [ 'relative_to' ]];
2013-10-07 12:17:06 +00:00
2016-03-03 23:55:22 -08:00
if ( empty ( $invalid_err )) {
$invalid_err = sprintf ( " Invalid '%s' " , $title );
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:55:22 -08:00
if ( is_array ( $array [ $field [ 'name' ]])) {
$invalid_err = '' ;
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:55:22 -08:00
//Checking if its required or not
if ( $req == 'yes' ) {
if ( empty ( $val ) && ! is_array ( $array [ $field [ 'name' ]])) {
e ( $invalid_err );
$block = true ;
} else {
$block = false ;
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:55:22 -08:00
$funct_err = is_valid_value ( $field [ 'validate_function' ], $val );
if ( $block != true ) {
//Checking Syntax
if ( ! $funct_err ) {
if ( ! empty ( $function_error_msg )) {
e ( $function_error_msg );
} elseif ( ! empty ( $invalid_err )) {
2013-10-07 12:17:06 +00:00
e ( $invalid_err );
2016-03-03 23:55:22 -08:00
}
}
if ( ! is_valid_syntax ( $field [ 'syntax_type' ], $val )) {
if ( ! empty ( $invalid_err )) {
e ( $invalid_err );
}
}
if ( isset ( $max_len )) {
if ( $length > $max_len || $length < $min_len ) {
e ( sprintf ( lang ( 'please_enter_val_bw_min_max' ), $title , $min_len , $field [ 'max_length' ]));
}
}
if ( function_exists ( $field [ 'db_value_check_func' ])) {
$db_val_result = $field [ 'db_value_check_func' ]( $val );
if ( $db_val_result != $field [ 'db_value_exists' ]) {
if ( ! empty ( $field [ 'db_value_err' ])) {
e ( $field [ 'db_value_err' ]);
} elseif ( ! empty ( $invalid_err )) {
e ( $invalid_err );
}
}
}
if ( $field [ 'relative_type' ] != '' ) {
switch ( $field [ 'relative_type' ]) {
case 'exact' :
2013-10-07 12:17:06 +00:00
{
2016-03-03 23:55:22 -08:00
if ( $rel_val != $val ) {
if ( ! empty ( $field [ 'relative_err' ])) {
e ( $field [ 'relative_err' ]);
} elseif ( ! empty ( $invalid_err )) {
e ( $invalid_err );
}
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:55:22 -08:00
break ;
2013-10-07 12:17:06 +00:00
}
}
2016-03-03 23:55:22 -08:00
}
}
2013-10-07 12:17:06 +00:00
}
}
/**
2016-03-03 23:48:03 -08:00
* Function used to check weather tempalte file exists or not
*
* @ param : { string } { $file } { file name to be checked }
* @ param : { string } { $dir } { directory to check file in }
* @ return : { boolean } { true if file exists , else false }
*/
function template_file_exists ( $file , $dir ) {
if ( ! file_exists ( $dir . '/' . $file ) && ! empty ( $file ) && ! file_exists ( $file )) {
2013-10-07 12:17:06 +00:00
echo sprintf ( lang ( " temp_file_load_err " ), $file , $dir );
return false ;
2016-03-03 23:48:03 -08:00
} else {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 23:48:03 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 23:48:03 -08:00
* Function used to count age from date
* @ param : { string } { $input } { date to count age }
* @ return : { integer } { $iYears } { years old }
*/
function get_age ( $input ) {
2013-10-07 12:17:06 +00:00
$time = strtotime ( $input );
$iMonth = date ( " m " , $time );
$iDay = date ( " d " , $time );
$iYear = date ( " Y " , $time );
$iTimeStamp = ( mktime () - 86400 ) - mktime ( 0 , 0 , 0 , $iMonth , $iDay , $iYear );
$iDays = $iTimeStamp / 86400 ;
$iYears = floor ( $iDays / 365 );
return $iYears ;
}
2016-03-03 23:48:03 -08:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 23:43:12 -08:00
* Function used to check time span a time difference function that outputs the
* time passed in facebook ' s style : 1 day ago , or 4 months ago . I took andrew dot
* macrobert at gmail dot com function and tweaked it a bit . On a strict enviroment
* it was throwing errors , plus I needed it to calculate the difference in time between
* a past date and a future date
* thanks to yasmary at gmail dot com
*
* @ param : { string } { $date } { date to be converted in nicetime }
* @ param : { boolean } { false by default , considers date to be in time format if true }
2016-03-03 23:48:03 -08:00
* @ uses : { function : lang () }
2016-03-03 23:43:12 -08:00
*/
2016-03-04 02:01:49 -08:00
function nicetime ( $date , $istime = false ) {
2013-10-07 12:17:06 +00:00
if ( empty ( $date )) {
return lang ( 'no_date_provided' );
}
2016-03-03 23:43:12 -08:00
$periods = array ( lang ( " second " ), lang ( " minute " ), lang ( " hour " ), lang ( " day " ), lang ( " week " ), lang ( " month " ), lang ( " year " ), lang ( " decade " ));
$lengths = array ( lang ( " 60 " ), lang ( " 60 " ), lang ( " 24 " ), lang ( " 7 " ), lang ( " 4.35 " ), lang ( " 12 " ), lang ( " 10 " ));
$now = time ();
if ( ! $istime ) {
$unix_date = strtotime ( $date );
} else {
$unix_date = $date ;
}
2013-10-07 12:17:06 +00:00
// check validity of date
if ( empty ( $unix_date ) || $unix_date < 1 ) {
return lang ( " bad_date " );
}
// is it future date or past date
if ( $now > $unix_date ) {
//time_ago
2016-03-03 23:48:03 -08:00
$difference = $now - $unix_date ;
$tense = " time_ago " ;
2013-10-07 12:17:06 +00:00
} else {
//from_now
2016-03-03 23:48:03 -08:00
$difference = $unix_date - $now ;
$tense = " from_now " ;
2013-10-07 12:17:06 +00:00
}
for ( $j = 0 ; $difference >= $lengths [ $j ] && $j < count ( $lengths ) - 1 ; $j ++ ) {
$difference /= $lengths [ $j ];
}
$difference = round ( $difference );
if ( $difference != 1 ) {
$periods [ $j ] .= " s " ;
}
return sprintf ( lang ( $tense ), $difference , $periods [ $j ]);
}
/**
2016-03-03 23:37:41 -08:00
* Function used to format outgoing link
* @ param : { string } { $out } { link to some webpage }
* @ return : { string } { HTML anchor tag with link in place }
*/
function outgoing_link ( $out ) {
2013-10-07 12:17:06 +00:00
preg_match ( " /http/ " , $out , $matches );
2016-03-03 23:37:41 -08:00
if ( empty ( $matches [ 0 ])) {
2013-10-07 12:17:06 +00:00
$out = " http:// " . $out ;
2016-03-03 23:37:41 -08:00
}
2013-10-07 12:17:06 +00:00
return '<a href="' . $out . '" target="_blank">' . $out . '</a>' ;
}
/**
2016-03-03 23:37:41 -08:00
* Function used to get country via country code
*
* @ param : { string } { $code } { country code name }
* @ return : { string } { country name of flag }
*/
function get_country ( $code ) {
2013-10-07 12:17:06 +00:00
global $db ;
$result = $db -> select ( tbl ( " countries " ), " name_en,iso2 " , " iso2=' $code ' OR iso3=' $code ' " );
2016-03-03 23:37:41 -08:00
if ( $db -> num_rows > 0 ) {
2013-10-07 12:17:06 +00:00
$flag = '' ;
$result = $result [ 0 ];
2016-03-03 23:37:41 -08:00
if ( SHOW_COUNTRY_FLAG ) {
2013-10-07 12:17:06 +00:00
$flag = '<img src="' . BASEURL . '/images/icons/country/' . strtolower ( $result [ 'iso2' ]) . '.png" alt="" border="0"> ' ;
2016-03-03 23:37:41 -08:00
}
2013-10-07 12:17:06 +00:00
return $flag . $result [ 'name_en' ];
2016-03-03 23:37:41 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 23:37:41 -08:00
}
2013-10-07 12:17:06 +00:00
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 23:37:41 -08:00
* function used to get collections
* @ uses : { class : $ cbcollection } { function : get_collections }
*/
function get_collections ( $param ) {
2013-10-07 12:17:06 +00:00
global $cbcollection ;
return $cbcollection -> get_collections ( $param );
}
/**
2016-03-03 23:37:41 -08:00
* function used to get users
2016-03-03 23:26:04 -08:00
* @ uses : { class : $ userquery } { function : get_users }
*/
2016-03-03 23:37:41 -08:00
function get_users ( $param ) {
2013-10-07 12:17:06 +00:00
global $userquery ;
return $userquery -> get_users ( $param );
}
/**
2016-03-03 23:26:04 -08:00
* function used to get groups
* @ uses : { class : $ cbgroup } { function : get_groups }
* @ deprecated : { function is deprecated and will be removed in next version }
*/
function get_groups ( $param ) {
2013-10-07 12:17:06 +00:00
global $cbgroup ;
return $cbgroup -> get_groups ( $param );
}
/**
2016-03-03 23:23:27 -08:00
* Function used to call functions
*
* @ param : { array } { $in } { array with functions to be called }
* @ param : { array } { $params } { array with parameters for functions }
* @ return : { null }
*/
function call_functions ( $in , $params = NULL ) {
if ( is_array ( $in )) {
foreach ( $in as $i ) {
if ( function_exists ( $i )) {
if ( ! $params ) {
2013-10-07 12:17:06 +00:00
$i ();
2016-03-03 23:23:27 -08:00
} else {
2013-10-07 12:17:06 +00:00
$i ( $params );
2016-03-03 23:23:27 -08:00
}
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 23:23:27 -08:00
} else {
if ( function_exists ( $in )) {
if ( ! $params ) {
$in ();
} else {
$in ( $params );
}
}
2013-10-07 12:17:06 +00:00
}
}
/**
2016-03-03 23:20:10 -08:00
* In each plugin we will define a CONST such as plguin_installed
* that will be used weather plugin is installed or not
* ie define ( " editorspick_install " , " installed " );
* is_installed ( 'editorspic' );
*
* @ param : { string } { $plugin } { name of the plguin to check }
* @ return : { boolean } { true if plugin installed , else false }
*/
2014-09-19 06:30:04 +00:00
2016-03-03 23:20:10 -08:00
function is_installed ( $plugin ) {
if ( defined ( $plugin . " _install " )) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 23:20:10 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 23:20:10 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 23:17:43 -08:00
* Category Link is used to return category based link
*
* @ param : { array } { $data } { array with category details }
* @ param : { string } { $type } { type of category e . g videos }
* @ return : { string } { sorting link }
*/
function category_link ( $data , $type ) {
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case 'video' : case 'videos' : case 'v' :
{
2016-03-03 23:17:43 -08:00
if ( SEO == 'yes' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/videos/' . $data [ 'category_id' ] . '/' . SEO ( $data [ 'category_name' ]) . '/' . $_GET [ 'sort' ] . '/' . $_GET [ 'time' ] . '/' ;
2016-03-03 23:17:43 -08:00
} else {
2013-10-07 12:17:06 +00:00
return BASEURL . '/videos.php?cat=' . $data [ 'category_id' ] . '&sort=' . $_GET [ 'sort' ] . '&time=' . $_GET [ 'time' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2016-03-03 23:17:43 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
case 'channels' : case 'channel' : case 'c' : case 'user' :
{
2016-03-03 23:17:43 -08:00
if ( SEO == 'yes' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/channels/' . $data [ 'category_id' ] . '/' . SEO ( $data [ 'category_name' ]) . '/' . $_GET [ 'sort' ] . '/' . $_GET [ 'time' ] . '/' ;
2016-03-03 23:17:43 -08:00
} else {
2013-10-07 12:17:06 +00:00
return BASEURL . '/channels.php?cat=' . $data [ 'category_id' ] . '&sort=' . $_GET [ 'sort' ] . '&time=' . $_GET [ 'time' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2016-03-03 23:17:43 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
default :
{
2016-03-03 23:17:43 -08:00
if ( THIS_PAGE == 'photos' ) {
2013-10-07 12:17:06 +00:00
$type = 'photos' ;
2016-03-03 23:17:43 -08:00
}
2013-10-07 12:17:06 +00:00
2016-03-03 23:17:43 -08:00
if ( defined ( " IN_MODULE " )) {
2013-10-07 12:17:06 +00:00
global $prefix_catlink ;
2016-03-03 23:17:43 -08:00
$url = 'cat=' . $data [ 'category_id' ] . '&sort=' . $_GET [ 'sort' ] . '&time=' . $_GET [ 'time' ] . '&page=' . $_GET [ 'page' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2013-10-07 12:17:06 +00:00
$url = $prefix_catlink . $url ;
$rm_array = array ( " cat " , " sort " , " time " , " page " , " seo_cat_name " );
$p = " " ;
2016-03-03 23:17:43 -08:00
if ( $prefix_catlink ) {
2013-10-07 12:17:06 +00:00
$rm_array [] = 'p' ;
2016-03-03 23:17:43 -08:00
}
2013-10-07 12:17:06 +00:00
$plugURL = queryString ( $url , $rm_array );
return $plugURL ;
}
2016-03-03 23:17:43 -08:00
if ( SEO == 'yes' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/' . $type . '/' . $data [ 'category_id' ] . '/' . SEO ( $data [ 'category_name' ]) . '/' . $_GET [ 'sort' ] . '/' . $_GET [ 'time' ] . '/' ;
2016-03-03 23:17:43 -08:00
} else {
2013-10-07 12:17:06 +00:00
return BASEURL . '/' . $type . '.php?cat=' . $data [ 'category_id' ] . '&sort=' . $_GET [ 'sort' ] . '&time=' . $_GET [ 'time' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2016-03-03 23:17:43 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
}
}
/**
2016-03-03 23:10:51 -08:00
* Sorting Links is used to return Sorting based link
*
* @ param : { string } { $sort } { specifies sorting style }
* @ param : { string } { $mode } { element to sort e . g time }
* @ param : { string } { $type } { type of element to sort e . g channels }
* @ return : { string } { sorting link }
*/
function sort_link ( $sort , $mode = 'sort' , $type ) {
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case 'video' :
case 'videos' :
case 'v' :
{
if ( ! isset ( $_GET [ 'cat' ]))
$_GET [ 'cat' ] = 'all' ;
if ( ! isset ( $_GET [ 'time' ]))
$_GET [ 'time' ] = 'all_time' ;
if ( ! isset ( $_GET [ 'sort' ]))
$_GET [ 'sort' ] = 'most_recent' ;
if ( ! isset ( $_GET [ 'page' ]))
$_GET [ 'page' ] = 1 ;
if ( ! isset ( $_GET [ 'seo_cat_name' ]))
$_GET [ 'seo_cat_name' ] = 'All' ;
2016-03-03 23:10:51 -08:00
if ( $mode == 'sort' ) {
2013-10-07 12:17:06 +00:00
$sorting = $sort ;
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
$sorting = $_GET [ 'sort' ];
2016-03-03 23:10:51 -08:00
}
if ( $mode == 'time' ) {
2013-10-07 12:17:06 +00:00
$time = $sort ;
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
$time = $_GET [ 'time' ];
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
2016-03-03 23:10:51 -08:00
if ( SEO == 'yes' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/videos/' . $_GET [ 'cat' ] . '/' . $_GET [ 'seo_cat_name' ] . '/' . $sorting . '/' . $time . '/' . $_GET [ 'page' ];
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
return BASEURL . '/videos.php?cat=' . $_GET [ 'cat' ] . '&sort=' . $sorting . '&time=' . $time . '&page=' . $_GET [ 'page' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
case 'channels' :
case 'channel' :
{
if ( ! isset ( $_GET [ 'cat' ]))
$_GET [ 'cat' ] = 'all' ;
if ( ! isset ( $_GET [ 'time' ]))
$_GET [ 'time' ] = 'all_time' ;
if ( ! isset ( $_GET [ 'sort' ]))
$_GET [ 'sort' ] = 'most_recent' ;
if ( ! isset ( $_GET [ 'page' ]))
$_GET [ 'page' ] = 1 ;
if ( ! isset ( $_GET [ 'seo_cat_name' ]))
$_GET [ 'seo_cat_name' ] = 'All' ;
2016-03-03 23:10:51 -08:00
if ( $mode == 'sort' ) {
2013-10-07 12:17:06 +00:00
$sorting = $sort ;
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
$sorting = $_GET [ 'sort' ];
2016-03-03 23:10:51 -08:00
}
if ( $mode == 'time' ) {
2013-10-07 12:17:06 +00:00
$time = $sort ;
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
$time = $_GET [ 'time' ];
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
2016-03-03 23:10:51 -08:00
if ( SEO == 'yes' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/channels/' . $_GET [ 'cat' ] . '/' . $_GET [ 'seo_cat_name' ] . '/' . $sorting . '/' . $time . '/' . $_GET [ 'page' ];
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
return BASEURL . '/channels.php?cat=' . $_GET [ 'cat' ] . '&sort=' . $sorting . '&time=' . $time . '&page=' . $_GET [ 'page' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
default :
{
if ( ! isset ( $_GET [ 'cat' ]))
$_GET [ 'cat' ] = 'all' ;
if ( ! isset ( $_GET [ 'time' ]))
$_GET [ 'time' ] = 'all_time' ;
if ( ! isset ( $_GET [ 'sort' ]))
$_GET [ 'sort' ] = 'most_recent' ;
if ( ! isset ( $_GET [ 'page' ]))
$_GET [ 'page' ] = 1 ;
if ( ! isset ( $_GET [ 'seo_cat_name' ]))
$_GET [ 'seo_cat_name' ] = 'All' ;
2016-03-03 23:10:51 -08:00
if ( $mode == 'sort' ) {
2013-10-07 12:17:06 +00:00
$sorting = $sort ;
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
$sorting = $_GET [ 'sort' ];
2016-03-03 23:10:51 -08:00
}
if ( $mode == 'time' ) {
2013-10-07 12:17:06 +00:00
$time = $sort ;
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
$time = $_GET [ 'time' ];
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
2016-03-03 23:10:51 -08:00
if ( THIS_PAGE == 'photos' ) {
2013-10-07 12:17:06 +00:00
$type = 'photos' ;
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
2016-03-03 23:10:51 -08:00
if ( defined ( " IN_MODULE " )) {
2013-10-07 12:17:06 +00:00
$url = 'cat=' . $_GET [ 'cat' ] . '&sort=' . $sorting . '&time=' . $time . '&page=' . $_GET [ 'page' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
$plugURL = queryString ( $url , array ( " cat " , " sort " , " time " , " page " , " seo_cat_name " ));
return $plugURL ;
}
2016-03-03 23:10:51 -08:00
if ( SEO == 'yes' ) {
2013-10-07 12:17:06 +00:00
return BASEURL . '/' . $type . '/' . $_GET [ 'cat' ] . '/' . $_GET [ 'seo_cat_name' ] . '/' . $sorting . '/' . $time . '/' . $_GET [ 'page' ];
2016-03-03 23:10:51 -08:00
} else {
2013-10-07 12:17:06 +00:00
return BASEURL . '/' . $type . '.php?cat=' . $_GET [ 'cat' ] . '&sort=' . $sorting . '&time=' . $time . '&page=' . $_GET [ 'page' ] . '&seo_cat_name=' . $_GET [ 'seo_cat_name' ];
2016-03-03 23:10:51 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
}
}
2016-03-03 23:10:51 -08:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 23:10:51 -08:00
* Function used to get flag options
* @ uses : { class : $ action } { var : $report_opts }
*/
function get_flag_options () {
2013-10-07 12:17:06 +00:00
$action = new cbactions ();
$action -> init ();
return $action -> report_opts ;
}
/**
2016-03-03 23:10:51 -08:00
* Function used to display flag type
* @ uses : { get_flag_options () function }
*/
function flag_type ( $id ) {
2013-10-07 12:17:06 +00:00
$flag_opts = get_flag_options ();
return $flag_opts [ $id ];
}
2016-03-03 23:03:12 -08:00
/**
* Loads Captcha [ user get_captcha () instead ]
*
* @ deprecated : { Function is not used anymore and will be removed in next version }
*/
2014-06-02 07:07:29 +00:00
2016-03-03 23:03:12 -08:00
function get_captcha_2014 () {
2014-06-02 07:07:29 +00:00
global $Cbucket ;
2016-03-03 23:03:12 -08:00
if ( count ( $Cbucket -> captchas ) > 0 ) {
2014-06-02 07:07:29 +00:00
return $Cbucket -> captchas [ 0 ];
2016-03-03 23:03:12 -08:00
} else {
2014-06-02 07:07:29 +00:00
return false ;
2016-03-03 23:03:12 -08:00
}
2014-06-02 07:07:29 +00:00
}
2016-03-03 23:03:12 -08:00
/**
* Function used to load captcha field
* @ uses : { class : $ Cbucket } { var : $captchas }
*/
2014-06-02 07:07:29 +00:00
2016-03-03 23:03:12 -08:00
function get_captcha () {
global $Cbucket ;
if ( count ( $Cbucket -> captchas ) > 0 ) {
2013-10-07 12:17:06 +00:00
return $Cbucket -> captchas [ 0 ];
2016-03-03 23:03:12 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 23:03:12 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 22:54:49 -08:00
* Function used to load captcha
* @ param : { array } { $params } { an array of parametrs }
*/
2013-10-07 12:17:06 +00:00
define ( " GLOBAL_CB_CAPTCHA " , " cb_captcha " );
2016-03-03 23:03:12 -08:00
function load_captcha ( $params ) {
2013-10-07 12:17:06 +00:00
global $total_captchas_loaded ;
2016-03-03 23:03:12 -08:00
switch ( $params [ 'load' ]) {
2013-10-07 12:17:06 +00:00
case 'function' :
{
if ( $total_captchas_loaded != 0 )
$total_captchas_loaded = $total_captchas_loaded + 1 ;
else
$total_captchas_loaded = 1 ;
$_SESSION [ 'total_captchas_loaded' ] = $total_captchas_loaded ;
2016-03-03 23:03:12 -08:00
if ( function_exists ( $params [ 'captcha' ][ 'load_function' ])) {
2013-10-07 12:17:06 +00:00
return $params [ 'captcha' ][ 'load_function' ]() . '<input name="cb_captcha_enabled" type="hidden" id="cb_captcha_enabled" value="yes" />' ;
2016-03-03 23:03:12 -08:00
}
2013-10-07 12:17:06 +00:00
}
break ;
case 'field' :
{
echo '<input type="text" ' . $params [ 'field_params' ] . ' name="' . GLOBAL_CB_CAPTCHA . '" />' ;
}
break ;
}
}
/**
2016-03-03 22:54:49 -08:00
* Function used to verify captcha
*/
function verify_captcha () {
2013-10-07 12:17:06 +00:00
$var = post ( 'cb_captcha_enabled' );
2016-03-03 22:54:49 -08:00
if ( $var == 'yes' ) {
2013-10-07 12:17:06 +00:00
$captcha = get_captcha ();
$val = $captcha [ 'validate_function' ]( post ( GLOBAL_CB_CAPTCHA ));
return $val ;
2016-03-03 22:54:49 -08:00
} else {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 22:54:49 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 22:45:10 -08:00
* Function used to ingore errors
* that are created when there is wrong action done
* on clipbucket ie inavalid username etc
*
* @ deprecated : { function is not used anymore and will be removed in next version }
*/
function ignore_errors () {
2013-10-07 12:17:06 +00:00
global $ignore_cb_errors ;
$ignore_cb_errors = TRUE ;
}
/**
2016-03-03 22:45:10 -08:00
* Function used to set $ignore_cb_errors
* back to TRUE so our error catching system
* can generate errors
2016-03-03 22:54:49 -08:00
*
2016-03-03 22:45:10 -08:00
* @ deprecated : { function is not used anymore and will be removed in next version }
*/
function catch_error () {
2013-10-07 12:17:06 +00:00
global $ignore_cb_errors ;
$ignore_cb_errors = FALSE ;
}
/**
2016-03-03 22:45:10 -08:00
* Function used to call sub_menu_easily
*/
function sub_menu () {
# Submenu function used to used to display submenu links
# after navbar
2013-10-07 12:17:06 +00:00
$funcs = get_functions ( 'sub_menu' );
2016-03-03 22:45:10 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
foreach ( $funcs as $func ) {
if ( function_exists ( $func )) {
2013-10-07 12:17:06 +00:00
return $func ( $u );
}
}
}
}
/**
2016-03-03 22:37:34 -08:00
* Adds title for ClipBucket powered website
* @ param : { string } { $title } { title to be given to page }
*/
function cbtitle ( $params = false ) {
2013-10-07 12:17:06 +00:00
global $cbsubtitle ;
2014-02-18 14:02:48 +00:00
$sub_sep = getArrayValue ( $params , 'sub_sep' );
2016-03-03 22:37:34 -08:00
if ( ! $sub_sep ) {
2013-10-07 12:17:06 +00:00
$sub_sep = '-' ;
2016-03-03 22:37:34 -08:00
}
2013-10-07 12:17:06 +00:00
//Getting Subtitle
2016-03-03 22:37:34 -08:00
if ( ! $cbsubtitle ) {
2015-05-20 11:01:30 +00:00
echo TITLE . " - " . SLOGAN ;
2016-03-03 22:37:34 -08:00
} else {
2015-05-20 10:44:12 +00:00
echo $cbsubtitle . " $sub_sep " ;
2016-03-03 22:37:34 -08:00
echo TITLE ;
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 22:31:18 -08:00
* Adds subtitle for any given page
* @ param : { string } { $title } { title to be given to page }
*/
function subtitle ( $title ) {
2013-10-07 12:17:06 +00:00
global $cbsubtitle ;
$cbsubtitle = $title ;
}
/**
2016-03-03 22:31:18 -08:00
* Extract user ' s name using userid
* @ uses : { class : $ userquery } { function : get_username }
*/
function get_username ( $uid ) {
2013-10-07 12:17:06 +00:00
global $userquery ;
return $userquery -> get_username ( $uid , 'username' );
}
/**
2016-03-03 22:26:59 -08:00
* Extract collection 's name using Collection' s id
* function is mostly used via Smarty template engine
*
* @ uses : { class : $ cbcollection } { function : get_collection_field }
*/
function get_collection_field ( $cid , $field = 'collection_name' ) {
2013-10-07 12:17:06 +00:00
global $cbcollection ;
return $cbcollection -> get_collection_field ( $cid , $field );
}
/**
2016-03-03 22:21:38 -08:00
* Deletes all photos found inside of given collection
* function is used when whole collection is being deleted
*
* @ param : { array } { $details } { an array with collection ' s details }
* @ return : { null }
* @ action : makes photos orphan
*/
function delete_collection_photos ( $details ) {
2013-10-07 12:17:06 +00:00
global $cbcollection , $cbphoto ;
$type = $details [ 'type' ];
2016-03-03 22:21:38 -08:00
if ( $type == 'photos' ) {
2013-10-07 12:17:06 +00:00
$ps = $cbphoto -> get_photos ( array ( " collection " => $details [ 'collection_id' ]));
2016-03-03 22:21:38 -08:00
if ( ! empty ( $ps )) {
foreach ( $ps as $p ) {
2013-10-07 12:17:06 +00:00
$cbphoto -> make_photo_orphan ( $details , $p [ 'photo_id' ]);
}
unset ( $ps ); // Empty $ps. Avoiding the duplication prob
}
}
}
/**
2016-03-03 22:21:38 -08:00
* Get ClipBucket ' s header menu
* @ uses : { class : $ Cbucket } { function : head_menu }
*/
function head_menu ( $params = NULL ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
return $Cbucket -> head_menu ( $params );
}
2016-03-03 22:21:38 -08:00
/**
* Get ClipBucket ' s menu
* @ uses : { class : $ Cbucket } { function : cbMenu }
*/
2013-10-07 12:17:06 +00:00
2016-03-03 22:21:38 -08:00
function cbMenu ( $params = NULL ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
return $Cbucket -> cbMenu ( $params );
}
/**
2016-03-03 22:21:38 -08:00
* Get ClipBucket ' s footer menu
* @ uses : { class : $ Cbucket } { function : foot_menu }
*/
function foot_menu ( $params = NULL ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
return $Cbucket -> foot_menu ( $params );
}
/**
2016-03-03 22:21:38 -08:00
* Converts given array XML into a PHP array
*
* @ param : { array } { $array } { array to be converted into XML }
* @ return : { string } { $xml } { array converted into XML }
*/
function xml2array ( $url , $get_attributes = 1 , $priority = 'tag' , $is_url = true ) {
2013-10-07 12:17:06 +00:00
$contents = " " ;
2016-03-03 22:21:38 -08:00
if ( ! function_exists ( 'xml_parser_create' )) {
2013-10-07 12:17:06 +00:00
return false ;
}
$parser = xml_parser_create ( '' );
2016-03-03 22:21:38 -08:00
if ( $is_url ) {
if ( ! ( $fp = @ fopen ( $url , 'rb' ))) {
2013-10-07 12:17:06 +00:00
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
curl_setopt ( $ch , CURLOPT_USERAGENT ,
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/3.0.0.2' );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , true );
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION , true );
$contents = curl_exec ( $ch );
curl_close ( $ch );
if ( ! $contents )
return false ;
}
2016-03-03 22:21:38 -08:00
while ( ! feof ( $fp )) {
2013-10-07 12:17:06 +00:00
$contents .= fread ( $fp , 8192 );
}
fclose ( $fp );
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
$contents = $url ;
}
xml_parser_set_option ( $parser , XML_OPTION_TARGET_ENCODING , " UTF-8 " );
xml_parser_set_option ( $parser , XML_OPTION_CASE_FOLDING , 0 );
xml_parser_set_option ( $parser , XML_OPTION_SKIP_WHITE , 1 );
xml_parse_into_struct ( $parser , trim ( $contents ), $xml_values );
xml_parser_free ( $parser );
2016-03-03 22:21:38 -08:00
if ( ! $xml_values ) {
2013-10-07 12:17:06 +00:00
return ; //Hmm...
2016-03-03 22:21:38 -08:00
}
2013-10-07 12:17:06 +00:00
$xml_array = array ();
$parents = array ();
$opened_tags = array ();
$arr = array ();
$current = & $xml_array ;
$repeated_tag_index = array ();
2016-03-03 22:21:38 -08:00
foreach ( $xml_values as $data ) {
2013-10-07 12:17:06 +00:00
unset ( $attributes , $value );
extract ( $data );
$result = array ();
$attributes_data = array ();
2016-03-03 22:21:38 -08:00
if ( isset ( $value )) {
if ( $priority == 'tag' ) {
2013-10-07 12:17:06 +00:00
$result = $value ;
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
$result [ 'value' ] = $value ;
2016-03-03 22:21:38 -08:00
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 22:21:38 -08:00
if ( isset ( $attributes ) and $get_attributes ) {
foreach ( $attributes as $attr => $val ) {
if ( $priority == 'tag' ) {
2013-10-07 12:17:06 +00:00
$attributes_data [ $attr ] = $val ;
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
$result [ 'attr' ][ $attr ] = $val ; //Set all the attributes in a array called 'attr'
2016-03-03 22:21:38 -08:00
}
2013-10-07 12:17:06 +00:00
}
}
2016-03-03 22:21:38 -08:00
if ( $type == " open " ) {
2013-10-07 12:17:06 +00:00
$parent [ $level - 1 ] = & $current ;
2016-03-03 22:21:38 -08:00
if ( ! is_array ( $current ) or ( ! in_array ( $tag , array_keys ( $current )))) {
2013-10-07 12:17:06 +00:00
$current [ $tag ] = $result ;
2016-03-03 22:21:38 -08:00
if ( $attributes_data ) {
2013-10-07 12:17:06 +00:00
$current [ $tag . '_attr' ] = $attributes_data ;
2016-03-03 22:21:38 -08:00
}
2013-10-07 12:17:06 +00:00
$repeated_tag_index [ $tag . '_' . $level ] = 1 ;
$current = & $current [ $tag ];
2016-03-03 22:21:38 -08:00
} else {
if ( isset ( $current [ $tag ][ 0 ])) {
2013-10-07 12:17:06 +00:00
$current [ $tag ][ $repeated_tag_index [ $tag . '_' . $level ]] = $result ;
$repeated_tag_index [ $tag . '_' . $level ] ++ ;
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
$current [ $tag ] = array (
$current [ $tag ],
$result
);
$repeated_tag_index [ $tag . '_' . $level ] = 2 ;
2016-03-03 22:21:38 -08:00
if ( isset ( $current [ $tag . '_attr' ])) {
2013-10-07 12:17:06 +00:00
$current [ $tag ][ '0_attr' ] = $current [ $tag . '_attr' ];
unset ( $current [ $tag . '_attr' ]);
}
}
$last_item_index = $repeated_tag_index [ $tag . '_' . $level ] - 1 ;
$current = & $current [ $tag ][ $last_item_index ];
}
2016-03-03 22:21:38 -08:00
} elseif ( $type == " complete " ) {
if ( ! isset ( $current [ $tag ])) {
2013-10-07 12:17:06 +00:00
$current [ $tag ] = $result ;
$repeated_tag_index [ $tag . '_' . $level ] = 1 ;
if ( $priority == 'tag' and $attributes_data )
$current [ $tag . '_attr' ] = $attributes_data ;
2016-03-03 22:21:38 -08:00
} else {
if ( isset ( $current [ $tag ][ 0 ]) and is_array ( $current [ $tag ])) {
2013-10-07 12:17:06 +00:00
$current [ $tag ][ $repeated_tag_index [ $tag . '_' . $level ]] = $result ;
2016-03-03 22:21:38 -08:00
if ( $priority == 'tag' and $get_attributes and $attributes_data ) {
2013-10-07 12:17:06 +00:00
$current [ $tag ][ $repeated_tag_index [ $tag . '_' . $level ] . '_attr' ] = $attributes_data ;
}
$repeated_tag_index [ $tag . '_' . $level ] ++ ;
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
$current [ $tag ] = array (
$current [ $tag ],
$result
);
$repeated_tag_index [ $tag . '_' . $level ] = 1 ;
2016-03-03 22:21:38 -08:00
if ( $priority == 'tag' and $get_attributes ) {
if ( isset ( $current [ $tag . '_attr' ])) {
2013-10-07 12:17:06 +00:00
$current [ $tag ][ '0_attr' ] = $current [ $tag . '_attr' ];
unset ( $current [ $tag . '_attr' ]);
}
2016-03-03 22:21:38 -08:00
if ( $attributes_data ) {
2013-10-07 12:17:06 +00:00
$current [ $tag ][ $repeated_tag_index [ $tag . '_' . $level ] . '_attr' ] = $attributes_data ;
}
}
$repeated_tag_index [ $tag . '_' . $level ] ++ ; //0 and 1 index is already taken
}
}
2016-03-03 22:21:38 -08:00
} elseif ( $type == 'close' ) {
2013-10-07 12:17:06 +00:00
$current = & $parent [ $level - 1 ];
}
}
return ( $xml_array );
}
2016-03-03 22:21:38 -08:00
/**
* Converts given array into valid XML
*
* @ param : { array } { $array } { array to be converted into XML }
* @ return : { string } { $xml } { array converted into XML }
*/
function array2xml ( $array , $level = 1 ) {
2013-10-07 12:17:06 +00:00
$xml = '' ;
foreach ( $array as $key => $value ) {
2016-03-03 22:21:38 -08:00
$key = strtolower ( $key );
if ( is_object ( $value )) { $value = get_object_vars ( $value );} // convert object to array
if ( is_array ( $value )) {
$multi_tags = false ;
foreach ( $value as $key2 => $value2 ) {
if ( is_object ( $value2 )) { $value2 = get_object_vars ( $value2 );} // convert object to array
if ( is_array ( $value2 )) {
$xml .= str_repeat ( " \t " , $level ) . " < $key > \n " ;
$xml .= array2xml ( $value2 , $level + 1 );
$xml .= str_repeat ( " \t " , $level ) . " </ $key > \n " ;
$multi_tags = true ;
} else {
if ( trim ( $value2 ) != '' ) {
if ( htmlspecialchars ( $value2 ) != $value2 ) {
$xml .= str_repeat ( " \t " , $level ) .
" < $key2 ><![CDATA[ $value2 ]]> " . // changed $key to $key2... didn't work otherwise.
" </ $key2 > \n " ;
} else {
$xml .= str_repeat ( " \t " , $level ) .
" < $key2 > $value2 </ $key2 > \n " ; // changed $key to $key2
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 22:21:38 -08:00
$multi_tags = true ;
2013-10-07 12:17:06 +00:00
}
}
2016-03-03 22:21:38 -08:00
if ( ! $multi_tags and count ( $value ) > 0 ) {
$xml .= str_repeat ( " \t " , $level ) . " < $key > \n " ;
$xml .= array2xml ( $value , $level + 1 );
$xml .= str_repeat ( " \t " , $level ) . " </ $key > \n " ;
}
} else {
if ( trim ( $value ) != '' ) {
echo " value= $value <br> " ;
if ( htmlspecialchars ( $value ) != $value ) {
$xml .= str_repeat ( " \t " , $level ) . " < $key > " .
" <![CDATA[ $value ]]></ $key > \n " ;
} else {
$xml .= str_repeat ( " \t " , $level ) .
" < $key > $value </ $key > \n " ;
}
2013-10-07 12:17:06 +00:00
}
}
}
return $xml ;
}
/**
2016-03-03 22:21:38 -08:00
* FUnction used to display widget
* @ deprecated : { function is not used anymore and will be removed }
*/
function widget ( $params ) {
2013-10-07 12:17:06 +00:00
$name = $params [ 'name' ];
$content = $params [ 'content' ];
return
' < div class = " widget-box " >
< div class = " widget-head " >
'.$name.'
</ div >
< div class = " widget-cont " >
'.$content.'
</ div >
</ div > ' ;
}
/**
2016-03-03 22:21:38 -08:00
* Function used to get latest ClipBucket version info
* @ deprecated : { function is not used anymore and will be removed }
*/
function get_latest_cb_info () {
if ( $_SERVER [ 'HTTP_HOST' ] != 'localhost' ) {
2013-10-07 12:17:06 +00:00
$url = 'http://clip-bucket.com/versions.xml' ;
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
$url = 'http://localhost/clipbucket/2.x/2/upload/tester/versions.xml' ;
2016-03-03 22:21:38 -08:00
}
2013-10-07 12:17:06 +00:00
$version = xml2array ( $url );
2016-03-03 22:21:38 -08:00
if ( ! $version ) {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 22:21:38 -08:00
} else {
2013-10-07 12:17:06 +00:00
return $version [ 'phpbucket' ][ 'clipbucket' ][ 0 ];
}
}
2013-10-08 12:24:07 +00:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 22:21:38 -08:00
* This function used to include headers in < head > tag
* it will check weather to include the file or not
* it will take file and its type as an array
* then compare its type with THIS_PAGE constant
* if header has TYPE of THIS_PAGE then it will be inlucded
*
* @ param : { array } { $params } { paramters array e . g file , type }
* @ return : { false }
*/
function include_header ( $params ) {
2014-02-18 14:02:48 +00:00
$file = getArrayValue ( $params , 'file' );
$type = getArrayValue ( $params , 'type' );
2016-03-03 22:21:38 -08:00
if ( $file == 'global_header' ) {
2013-10-07 12:17:06 +00:00
Template ( BASEDIR . '/styles/global/head.html' , false );
return false ;
}
2016-03-03 22:21:38 -08:00
if ( $file == 'admin_bar' ) {
2013-10-07 12:17:06 +00:00
if ( has_access ( 'admin_access' , TRUE ))
Template ( BASEDIR . '/styles/global/admin_bar.html' , false );
return false ;
}
2016-03-03 22:21:38 -08:00
if ( ! $type ) {
2013-10-07 12:17:06 +00:00
$type = " global " ;
2016-03-03 22:21:38 -08:00
}
if ( is_includeable ( $type )) {
2013-10-07 12:17:06 +00:00
Template ( $file , false );
2016-03-03 22:21:38 -08:00
}
2013-10-07 12:17:06 +00:00
return false ;
}
/**
2016-03-03 06:48:12 -08:00
* Function used to check weather to include given file or not
* it will take array of pages if array has ACTIVE PAGE or has GLOBAL value
* it will return true otherwise FALSE
*
* @ param : { array } { $array } { array with files to include }
* @ return : { boolean } { true or false depending on situation }
*/
function is_includeable ( $array ) {
if ( ! is_array ( $array )) {
2013-10-07 12:17:06 +00:00
$array = array ( $array );
2016-03-03 06:48:12 -08:00
}
if ( in_array ( THIS_PAGE , $array ) || in_array ( 'global' , $array )) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 06:48:12 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 06:48:12 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 06:48:12 -08:00
* This function works the same way as include_header
* but the only difference is , it is used to include
* JS files only
2016-03-03 22:21:38 -08:00
*
2016-03-03 06:48:12 -08:00
* @ param : { arary } { $params } { array with parameters e . g file , type }
2016-03-03 22:21:38 -08:00
* @ return : { string } { javascript tag with file in src }
2016-03-03 06:48:12 -08:00
*/
2013-10-07 12:17:06 +00:00
$the_js_files = array ();
2016-03-03 06:48:12 -08:00
function include_js ( $params ) {
2013-10-07 12:17:06 +00:00
global $the_js_files ;
$file = $params [ 'file' ];
$type = $params [ 'type' ];
2016-03-03 06:48:12 -08:00
if ( ! in_array ( $file , $the_js_files )) {
2013-10-07 12:17:06 +00:00
$the_js_files [] = $file ;
2016-03-03 06:48:12 -08:00
if ( $type == 'global' ) {
2013-10-07 12:17:06 +00:00
return '<script src="' . JS_URL . '/' . $file . '" type="text/javascript"></script>' ;
2016-03-03 06:48:12 -08:00
} elseif ( is_array ( $type )) {
foreach ( $type as $t ) {
if ( $t == THIS_PAGE )
2013-10-07 12:17:06 +00:00
return '<script src="' . JS_URL . '/' . $file . '" type="text/javascript"></script>' ;
}
2016-03-03 06:48:12 -08:00
} elseif ( $type == THIS_PAGE ) {
2013-10-07 12:17:06 +00:00
return '<script src="' . JS_URL . '/' . $file . '" type="text/javascript"></script>' ;
2016-03-03 06:48:12 -08:00
}
2013-10-07 12:17:06 +00:00
}
return false ;
}
/**
2016-03-03 06:48:12 -08:00
* Checks if FFMPEG has all required modules installed on server
* @ param : { string } { $data } { false by default , version of ffmpeg }
* @ return : { array } { $codecs } { an array with all required modules }
*/
function get_ffmpeg_codecs ( $data = false ) {
if ( PHP_OS == " Linux " ) {
2014-09-29 11:02:53 +00:00
$a = 'libfaac' ;
2016-03-03 06:48:12 -08:00
} elseif ( PHP_OS == " WINNT " ) {
2014-09-29 11:02:53 +00:00
$a = 'libvo_aacenc' ;
}
2013-10-07 12:17:06 +00:00
$req_codecs = array
( 'libxvid' => 'Required for DIVX AVI files' ,
'libmp3lame' => 'Required for proper Mp3 Encoding' ,
2014-09-29 11:02:53 +00:00
$a => 'Required for AAC Audio Conversion' ,
2013-10-07 12:17:06 +00:00
// 'libfaad' => 'Required for AAC Audio Conversion',
'libx264' => 'Required for x264 video compression and conversion' ,
'libtheora' => 'Theora is an open video codec being developed by the Xiph.org' ,
'libvorbis' => 'Ogg Vorbis is a new audio compression format' ,
);
2016-03-03 06:48:12 -08:00
if ( $data ) {
2013-10-07 12:17:06 +00:00
$version = $data ;
2016-03-03 06:48:12 -08:00
} else {
2013-10-07 12:17:06 +00:00
$version = shell_output ( get_binaries ( 'ffmpeg' ) . ' -i xxx -acodec copy -vcodec copy -f null /dev/null 2>&1' );
2016-03-03 06:48:12 -08:00
}
2013-10-07 12:17:06 +00:00
preg_match_all ( " /enable \ -(.*) /Ui " , $version , $matches );
$installed = $matches [ 1 ];
$the_codecs = array ();
2016-03-03 06:48:12 -08:00
foreach ( $installed as $inst ) {
2013-10-07 12:17:06 +00:00
if ( empty ( $req_codecs [ $inst ]))
$the_codecs [ $inst ][ 'installed' ] = 'yes' ;
}
2016-03-03 06:48:12 -08:00
foreach ( $req_codecs as $key => $codec ) {
2013-10-07 12:17:06 +00:00
$the_req_codecs [ $key ] = array ();
$the_req_codecs [ $key ][ 'required' ] = 'yes' ;
$the_req_codecs [ $key ][ 'desc' ] = $req_codecs [ $key ];
2016-03-03 06:48:12 -08:00
if ( in_array ( $key , $installed )) {
2013-10-07 12:17:06 +00:00
$the_req_codecs [ $key ][ 'installed' ] = 'yes' ;
2016-03-03 06:48:12 -08:00
} else {
2013-10-07 12:17:06 +00:00
$the_req_codecs [ $key ][ 'installed' ] = 'no' ;
2016-03-03 06:48:12 -08:00
}
2013-10-07 12:17:06 +00:00
}
$the_codecs = array_merge ( $the_req_codecs , $the_codecs );
return $the_codecs ;
}
/**
2016-03-03 06:48:12 -08:00
* Check if a module is installed on server or not using path
* @ param : { array } { $params } { array with paramters including path }
* @ return : { string / boolean } { path if found , else fasle }
*/
function check_module_path ( $params ) {
2013-10-07 12:17:06 +00:00
$rPath = $path = $params [ 'path' ];
if ( $path [ 'get_path' ])
$path = get_binaries ( $path );
$array = array ();
$result = shell_output ( $path . " -version " );
2016-03-03 06:48:12 -08:00
if ( $result ) {
if ( strstr ( $result , 'error' ) || strstr (( $result ), 'No such file or directory' )) {
2013-10-07 12:17:06 +00:00
$error [ 'error' ] = $result ;
2016-03-03 06:48:12 -08:00
if ( $params [ 'assign' ]) {
2013-10-07 12:17:06 +00:00
assign ( $params [ 'assign' ], $error );
2016-03-03 06:48:12 -08:00
}
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 06:48:12 -08:00
}
2014-05-09 10:42:41 +00:00
if ( $params [ 'assign' ]) {
2013-10-07 12:17:06 +00:00
$array [ 'status' ] = 'ok' ;
$array [ 'version' ] = parse_version ( $params [ 'path' ], $result );
assign ( $params [ 'assign' ], $array );
2014-05-09 10:42:41 +00:00
return $array ;
2016-03-03 06:48:12 -08:00
} else {
2014-05-09 10:42:41 +00:00
return $result ;
}
2016-03-03 06:48:12 -08:00
} else {
if ( $params [ 'assign' ]) {
2014-05-09 10:42:41 +00:00
assign ( $params [ 'assign' ][ 'error' ], " error " );
2016-03-03 06:48:12 -08:00
} else {
2014-05-09 10:42:41 +00:00
return false ;
2016-03-03 06:48:12 -08:00
}
2016-03-03 22:21:38 -08:00
}
2014-05-09 10:42:41 +00:00
}
2016-03-03 06:48:12 -08:00
/**
* Check if FFMPEG is installed by exracting its version
*
* @ param : { string } { $path } { path to FFMPEG }
* @ return : { string } { version if found , else false }
*/
function check_ffmpeg ( $path ) {
2014-05-09 11:17:24 +00:00
$path = get_binaries ( $path );
$matches = array ();
2014-05-09 10:42:41 +00:00
$result = shell_output ( $path . " -version " );
if ( $result ) {
2016-03-03 06:48:12 -08:00
if ( preg_match ( " /git/i " , $result )) {
2014-09-24 14:28:56 +00:00
preg_match ( '@^(?:ffmpeg version)?([^C]+)@i' , $result , $matches );
$host = $matches [ 1 ];
2015-10-20 12:13:06 +00:00
return $host ;
2016-03-03 06:48:12 -08:00
} elseif ( preg_match ( " /ffmpeg version/i " , $result )) {
2014-09-24 14:28:56 +00:00
preg_match ( '@^(?:ffmpeg version)?([^,]+)@i' , $result , $matches );
$host = $matches [ 1 ];
// get last two segments of host name
preg_match ( '/[^.]+\.[^.]+$/' , $host , $matches );
$version = " { $matches [ 0 ] } " ;
2014-05-09 11:17:24 +00:00
return $version ;
2016-03-03 06:48:12 -08:00
} else {
2014-09-24 14:28:56 +00:00
preg_match ( " /(?:ffmpeg \\ s)(?:version \\ s)?( \\ d \\ . \\ d \\ .(?: \\ d|[ \\ w]+))/i " , strtolower ( $result ), $matches );
2016-03-03 06:48:12 -08:00
if ( count ( $matches ) > 0 ) {
2014-09-24 14:28:56 +00:00
$version = array_pop ( $matches );
return $version ;
}
2016-03-03 06:48:12 -08:00
}
2014-05-09 11:17:24 +00:00
return false ;
2016-03-03 06:48:12 -08:00
} else {
2014-05-09 11:17:24 +00:00
return false ;
2013-10-07 12:17:06 +00:00
}
}
2016-03-03 06:30:41 -08:00
/**
* Check if PHP_CLI is installed by exracting its version
*
* @ param : { string } { $path } { path to PHP_CLI }
* @ return : { string } { version if found , else false }
*/
2014-05-09 11:17:24 +00:00
2016-03-03 06:30:41 -08:00
function check_php_cli ( $path ) {
2014-05-09 11:17:24 +00:00
$path = get_binaries ( $path );
$matches = array ();
$result = shell_output ( $path . " --version " );
if ( $result ) {
preg_match ( " /(?:php \\ s)(?:version \\ s)?( \\ d \\ . \\ d \\ .(?: \\ d|[ \\ w]+))/i " , strtolower ( $result ), $matches );
2016-03-03 06:48:12 -08:00
if ( count ( $matches ) > 0 ) {
2014-05-09 11:17:24 +00:00
$version = array_pop ( $matches );
return $version ;
}
return false ;
2016-03-03 06:48:12 -08:00
} else {
2014-05-09 11:17:24 +00:00
return false ;
2016-03-03 06:48:12 -08:00
}
2014-05-09 11:17:24 +00:00
}
2014-05-09 11:25:46 +00:00
2016-03-03 06:30:41 -08:00
/**
* Check if MediaInfo is installed by exracting its version
*
* @ param : { string } { $path } { path to MediaInfo }
* @ return : { string } { version if found , else false }
*/
function check_media_info ( $path ) {
2015-08-17 14:11:40 +00:00
$path = get_binaries ( $path );
$result = shell_output ( $path . " --version " );
$media_info_version = explode ( 'v' , $result );
return $media_info_version [ 1 ];
}
2016-03-03 06:30:41 -08:00
/**
* Check if ImageMagick is installed by exracting its version
*
* @ param : { string } { $path } { path to ImageMagick }
* @ return : { string } { version if found , else false }
*/
function check_imagick ( $path ) {
2015-08-17 14:11:40 +00:00
$path = get_binaries ( $path );
$result = shell_output ( $path . " --version " );
$result = explode ( " " , $result );
return $result [ 2 ];
}
2016-03-03 06:30:41 -08:00
/**
* Check if FFPROBE is installed by exracting its version
*
* @ param : { string } { $path } { path to FFPROBE }
* @ return : { string } { version if found , else false }
*/
function check_ffprobe_path ( $path ) {
2015-08-17 14:11:40 +00:00
$path = get_binaries ( $path );
$result = shell_output ( $path . " -version " );
$result = explode ( " " , $result );
$result = $result [ 2 ];
return $result ;
}
2016-03-03 06:30:41 -08:00
/**
* Check if MP4Box is installed by exracting its version
*
* @ param : { string } { $path } { path to MP4Box }
* @ return : { string / false } { version if found , else false }
*/
2015-08-17 14:11:40 +00:00
2016-03-03 06:30:41 -08:00
function check_mp4box ( $path ) {
2014-05-09 11:25:46 +00:00
$path = get_binaries ( $path );
$matches = array ();
$result = shell_output ( $path . " -version " );
2016-03-03 06:30:41 -08:00
if ( $result ) {
2014-05-09 11:25:46 +00:00
preg_match ( " /(?:version \\ s)( \\ d \\ . \\ d \\ .(?: \\ d|[ \\ w]+))/i " , strtolower ( $result ), $matches );
2016-03-03 06:30:41 -08:00
if ( count ( $matches ) > 0 ) {
2014-05-09 11:25:46 +00:00
$version = array_pop ( $matches );
return $version ;
}
return false ;
2016-03-03 06:30:41 -08:00
} elseif ( preg_match ( " /GPAC version/i " , $result )) {
2014-09-29 11:02:53 +00:00
preg_match ( '@^(?:GPAC version)?([^-]+)@i' , $result , $matches );
$host = $matches [ 1 ];
// get last two segments of host name
preg_match ( '/[^.]+\.[^.]+$/' , $host , $matches );
//echo "{$matches[0]}\n";
$version = " { $matches [ 0 ] } " ;
return $version ;
2016-03-03 06:30:41 -08:00
} else {
2014-05-09 11:25:46 +00:00
return false ;
2016-03-03 06:30:41 -08:00
}
2014-05-09 11:25:46 +00:00
}
2013-10-07 12:17:06 +00:00
/**
2016-03-03 06:25:07 -08:00
* Function used to parse versions from info
* @ param : { string } { $path } { tool to check }
* @ param : { string } { $result } { data to parse version from }
*/
function parse_version ( $path , $result ) {
switch ( $path ) {
2013-10-07 12:17:06 +00:00
case 'ffmpeg' :
{
//Gett FFMPEG SVN version
2014-05-09 11:17:24 +00:00
dump ( $result );
2013-10-07 12:17:06 +00:00
preg_match ( " /svn-r([0-9]+)/i " , strtolower ( $result ), $matches );
//pr($matches);
if ( is_numeric ( floatval ( $matches [ 1 ])) && $matches [ 1 ]) {
return 'Svn ' . $matches [ 1 ];
}
//Get FFMPEG version
preg_match ( " /FFmpeg version ([0-9.]+),/i " , strtolower ( $result ), $matches );
if ( is_numeric ( floatval ( $matches [ 1 ])) && $matches [ 1 ]) {
return $matches [ 1 ];
}
//Get FFMPEG GIT version
preg_match ( " /ffmpeg version n \ -([0-9]+)/i " , strtolower ( $result ), $matches );
if ( is_numeric ( floatval ( $matches [ 1 ])) && $matches [ 1 ]) {
return 'Git ' . $matches [ 1 ];
}
}
break ;
case 'php' :
{
return phpversion ();
}
break ;
case 'flvtool2' :
{
preg_match ( " /flvtool2 ([0-9 \ .]+)/i " , $result , $matches );
if ( is_numeric ( floatval ( $matches [ 1 ]))){
return $matches [ 1 ];
} else {
return false ;
}
}
break ;
case 'mp4box' :
{
preg_match ( " /version (.*) \ (/Ui " , $result , $matches );
//pr($matches);
if ( is_numeric ( floatval ( $matches [ 1 ]))){
return $matches [ 1 ];
} else {
return false ;
}
}
}
}
/**
2016-03-03 06:25:07 -08:00
* Calls ClipBucket footer into the battlefield
* @ return : { null }
*/
function footer () {
2013-10-07 12:17:06 +00:00
$funcs = get_functions ( 'clipbucket_footer' );
2016-03-03 06:25:07 -08:00
if ( is_array ( $funcs ) && count ( $funcs ) > 0 ) {
foreach ( $funcs as $func ) {
if ( function_exists ( $func )) {
2013-10-07 12:17:06 +00:00
$func ();
}
}
}
}
2016-03-03 06:25:07 -08:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 06:25:07 -08:00
* Function used to generate RSS FEED links
* @ param : { array } { $params } { array with paramets }
*/
function rss_feeds ( $params ) {
2013-10-07 12:17:06 +00:00
/**
2016-03-03 06:25:07 -08:00
* setting up the feeds arrays ..
* if you want to call em in your functions .. simply call the global variable $rss_feeds
*/
2013-10-07 12:17:06 +00:00
$rss_link = cblink ( array ( " name " => " rss " ));
$rss_feeds = array ();
$rss_feeds [] = array ( " title " => " Recently added videos " , " link " => $rss_link . " recent " );
$rss_feeds [] = array ( " title " => " Most Viewed Videos " , " link " => $rss_link . " views " );
$rss_feeds [] = array ( " title " => " Top Rated Videos " , " link " => $rss_link . " rating " );
$rss_feeds [] = array ( " title " => " Videos Being Watched " , " link " => $rss_link . " watching " );
$funcs = get_functions ( 'rss_feeds' );
2016-03-03 06:25:07 -08:00
if ( is_array ( $funcs )) {
foreach ( $funcs as $func ) {
2013-10-07 12:17:06 +00:00
return $func ( $params );
}
}
2016-03-03 06:25:07 -08:00
if ( $params [ 'link_tag' ]) {
foreach ( $rss_feeds as $rss_feed ) {
2013-10-07 12:17:06 +00:00
echo " <link rel= \" alternate \" type= \" application/rss+xml \"
title = \ " " . $rss_feed [ 'title' ] . " \" href= \" " . $rss_feed [ 'link' ] . " \" /> \n " ;
}
}
}
/**
2016-03-03 06:25:07 -08:00
* Function used to insert Log
* @ uses { class : $ cblog } { function : insert }
*/
function insert_log ( $type , $details ) {
2013-10-07 12:17:06 +00:00
global $cblog ;
$cblog -> insert ( $type , $details );
}
/**
2016-03-03 06:25:07 -08:00
* Function used to get database size
* @ return : { array } { $dbsize } { array with data size }
*/
2014-02-12 09:27:02 +00:00
2016-03-03 06:25:07 -08:00
function get_db_size () {
2014-11-22 15:22:41 +00:00
global $db ;
$results = $db -> _select ( " SHOW TABLE STATUS " );
2016-03-03 06:25:07 -08:00
foreach ( $results as $row ) {
2013-10-07 12:17:06 +00:00
$dbsize += $row [ " Data_length " ] + $row [ " Index_length " ];
}
return $dbsize ;
}
2014-02-12 09:27:02 +00:00
2013-10-07 12:17:06 +00:00
/**
2016-03-03 06:25:07 -08:00
* Function used to check weather user has marked comment as spam or not
* @ param : { array } { $comment } { array with all details of comment }
* @ return : { boolean } { true if marked as spam , else fasle }
*/
function marked_spammed ( $comment ) {
2013-10-07 12:17:06 +00:00
$spam_voters = explode ( " | " , $comment [ 'spam_voters' ]);
$spam_votes = $comment [ 'spam_votes' ];
$admin_vote = in_array ( '1' , $spam_voters );
2016-03-03 06:25:07 -08:00
if ( userid () && in_array ( userid (), $spam_voters )) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 06:25:07 -08:00
} elseif ( $admin_vote ) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 06:25:07 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
}
}
/**
2016-03-03 06:25:07 -08:00
* function used to get all time zones
*/
function get_time_zones () {
2013-10-07 12:17:06 +00:00
$timezoneTable = array (
" -12 " => " (GMT -12:00) Eniwetok, Kwajalein " ,
" -11 " => " (GMT -11:00) Midway Island, Samoa " ,
" -10 " => " (GMT -10:00) Hawaii " ,
" -9 " => " (GMT -9:00) Alaska " ,
" -8 " => " (GMT -8:00) Pacific Time (US & Canada) " ,
" -7 " => " (GMT -7:00) Mountain Time (US & Canada) " ,
" -6 " => " (GMT -6:00) Central Time (US & Canada), Mexico City " ,
" -5 " => " (GMT -5:00) Eastern Time (US & Canada), Bogota, Lima " ,
" -4 " => " (GMT -4:00) Atlantic Time (Canada), Caracas, La Paz " ,
" -3.5 " => " (GMT -3:30) Newfoundland " ,
" -3 " => " (GMT -3:00) Brazil, Buenos Aires, Georgetown " ,
" -2 " => " (GMT -2:00) Mid-Atlantic " ,
" -1 " => " (GMT -1:00 hour) Azores, Cape Verde Islands " ,
" 0 " => " (GMT) Western Europe Time, London, Lisbon, Casablanca " ,
" 1 " => " (GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris " ,
" 2 " => " (GMT +2:00) Kaliningrad, South Africa " ,
" 3 " => " (GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg " ,
" 3.5 " => " (GMT +3:30) Tehran " ,
" 4 " => " (GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi " ,
" 4.5 " => " (GMT +4:30) Kabul " ,
" 5 " => " (GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent " ,
" 5.5 " => " (GMT +5:30) Bombay, Calcutta, Madras, New Delhi " ,
" 6 " => " (GMT +6:00) Almaty, Dhaka, Colombo " ,
" 7 " => " (GMT +7:00) Bangkok, Hanoi, Jakarta " ,
" 8 " => " (GMT +8:00) Beijing, Perth, Singapore, Hong Kong " ,
" 9 " => " (GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk " ,
" 9.5 " => " (GMT +9:30) Adelaide, Darwin " ,
" 10 " => " (GMT +10:00) Eastern Australia, Guam, Vladivostok " ,
" 11 " => " (GMT +11:00) Magadan, Solomon Islands, New Caledonia " ,
" 12 " => " (GMT +12:00) Auckland, Wellington, Fiji, Kamchatka "
);
return $timezoneTable ;
}
/**
2016-03-03 06:25:07 -08:00
* Function used to get object type from its code
*
* @ param : { string } { $type } { shortcode of type ie v => video }
* @ return : { string } { complete type name }
*/
function get_obj_type ( $type ) {
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case " v " :
{
return " video " ;
}
break ;
}
}
2016-03-03 06:25:07 -08:00
function check_cbvideo () {
2013-10-07 12:17:06 +00:00
if (( ! defined ( " isCBSecured " )
|| count ( get_functions ( 'clipbucket_footer' )) == 0 )
&& ! BACK_END )
{
2016-01-27 13:51:32 +00:00
// echo cbSecured(CB_SIGN_C);
2013-10-07 12:17:06 +00:00
}
}
/**
2016-03-03 06:05:35 -08:00
* Determines conversio status using provided string
*
* @ param : { string } { $in } { string with conversion value }
* @ return : { string } { determined conversion status }
*/
function conv_status ( $in ) {
switch ( $in ) {
2013-10-07 12:17:06 +00:00
case " p " :
return " Processing " ;
break ;
case " no " :
return " Pending " ;
break ;
case " yes " :
return " Done " ;
break ;
}
}
2016-03-03 03:07:21 -08:00
/**
* Check installation of ClipBucket
* @ param : { string } { $type } { type of check e . g before , after }
*/
2014-11-22 11:30:12 +00:00
2016-03-03 03:07:21 -08:00
function check_install ( $type ) {
2014-11-22 11:30:12 +00:00
if ( DEVELOPMENT_MODE ) return true ;
2013-10-07 12:17:06 +00:00
global $while_installing , $Cbucket ;
2016-03-03 03:07:21 -08:00
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case " before " :
{
if ( file_exists ( 'files/temp/install.me' ) && ! file_exists ( 'includes/clipbucket.php' ))
{
header ( 'Location: ' . get_server_url () . '/cb_install' );
}
}
break ;
case " after " :
{
if ( file_exists ( 'files/temp/install.me' ))
{
$Cbucket -> configs [ 'closed' ] = 1 ;
}
}
break ;
}
}
2016-03-03 03:07:21 -08:00
/**
* Function to get server URL
* @ param : { none }
* @ return { string } { url of server }
*/
function get_server_url () {
2013-10-07 12:17:06 +00:00
$DirName = dirname ( $_SERVER [ 'PHP_SELF' ]);
2016-03-03 03:07:21 -08:00
if ( preg_match ( '/admin_area/i' , $DirName )) {
2013-10-07 12:17:06 +00:00
$DirName = str_replace ( '/admin_area' , '' , $DirName );
}
2016-03-03 03:07:21 -08:00
2013-10-07 12:17:06 +00:00
if ( preg_match ( '/cb_install/i' , $DirName ))
{
$DirName = str_replace ( '/cb_install' , '' , $DirName );
}
return get_server_protocol () . $_SERVER [ 'HTTP_HOST' ] . $DirName ;
}
2016-03-03 03:07:21 -08:00
/**
* Get current protocol of server that CB is running on
* @ return { string } { $protocol } { http or https }
*/
function get_server_protocol () {
if ( isset ( $_SERVER [ 'HTTPS' ]) && $_SERVER [ 'HTTPS' ] == 'on' ) {
2013-10-07 12:17:06 +00:00
return 'https://' ;
2016-03-03 03:07:21 -08:00
} else {
2013-10-07 12:17:06 +00:00
$protocol = preg_replace ( '/^([a-z]+)\/.*$/' , '\\1' , strtolower ( $_SERVER [ 'SERVER_PROTOCOL' ]));
$protocol .= '://' ;
return $protocol ;
}
}
/**
2016-03-03 03:07:21 -08:00
* Returns < kbd > true </ kbd > if the string or array of string is encoded in UTF8 .
*
* Example of use . If you want to know if a file is saved in UTF8 format :
* < code > $array = file ( 'one file.txt' );
* $isUTF8 = isUTF8 ( $array );
* if ( ! $isUTF8 ) --> we need to apply utf8_encode () to be in UTF8
* else --> we are in UTF8 : )
* </ code >
* @ param mixed A string , or an array from a file () function .
* @ return boolean
*/
function isUTF8 ( $string ) {
if ( is_array ( $string )) {
2013-10-07 12:17:06 +00:00
$enc = implode ( '' , $string );
return @! (( ord ( $enc [ 0 ]) != 239 ) && ( ord ( $enc [ 1 ]) != 187 ) && ( ord ( $enc [ 2 ]) != 191 ));
2016-03-03 03:07:21 -08:00
} else {
2013-10-07 12:17:06 +00:00
return ( utf8_encode ( utf8_decode ( $string )) == $string );
}
}
2016-03-03 02:57:27 -08:00
/**
* Extract file extension from any given path or url
*
* @ param : { string } { $filepath } { path to be filtered for extension }
* @ return : { string } { $matches } { extension of file filtered from string }
2013-10-07 12:17:06 +00:00
*/
2016-03-03 02:57:27 -08:00
function fetch_file_extension ( $filepath ) {
2013-10-07 12:17:06 +00:00
preg_match ( '/[^?]*/' , $filepath , $matches );
$string = $matches [ 0 ];
$pattern = preg_split ( '/\./' , $string , - 1 , PREG_SPLIT_OFFSET_CAPTURE );
# check if there is any extension
2016-03-03 02:57:27 -08:00
if ( count ( $pattern ) == 1 ) {
2013-10-07 12:17:06 +00:00
// no file extension found
return ;
}
2016-03-03 02:57:27 -08:00
if ( count ( $pattern ) > 1 ) {
2013-10-07 12:17:06 +00:00
$filenamepart = $pattern [ count ( $pattern ) - 1 ][ 0 ];
preg_match ( '/[^?]*/' , $filenamepart , $matches );
return $matches [ 0 ];
}
}
2016-03-03 02:54:07 -08:00
/**
* Extract the file filename from any given path or url
*
* @ param : { string } { $filepath } { path to be filtered for filename }
2016-03-03 02:57:27 -08:00
* @ return : { string } { $filename } { name of file filtered from string }
2013-10-07 12:17:06 +00:00
*/
2016-03-03 02:54:07 -08:00
function fetch_filename ( $filepath ) {
2013-10-07 12:17:06 +00:00
preg_match ( '/[^?]*/' , $filepath , $matches );
$string = $matches [ 0 ];
#split the string by the literal dot in the filename
$pattern = preg_split ( '/\./' , $string , - 1 , PREG_SPLIT_OFFSET_CAPTURE );
#get the last dot position
$lastdot = $pattern [ count ( $pattern ) - 1 ][ 1 ];
#now extract the filename using the basename function
$filename = basename ( substr ( $string , 0 , $lastdot - 1 ));
#return the filename part
return $filename ;
}
/**
2016-03-03 02:50:26 -08:00
* Generate embed code of provided video
*
* @ param : { array } { $vdetails } { all details of video }
* @ return : { string } { $code } { embed code for video }
*/
function embeded_code ( $vdetails ) {
2013-10-07 12:17:06 +00:00
$code = '' ;
$code .= '<object width="' . EMBED_VDO_WIDTH . '" height="' . EMBED_VDO_HEIGHT . '">' ;
$code .= '<param name="allowFullScreen" value="true">' ;
$code .= '</param><param name="allowscriptaccess" value="always"></param>' ;
//Replacing Height And Width
$h_w_p = array ( " { Width} " , " { Height} " );
$h_w_r = array ( EMBED_VDO_WIDTH , EMBED_VDO_HEIGHT );
$embed_code = str_replace ( $h_w_p , $h_w_r , $vdetails [ 'embed_code' ]);
$code .= unhtmlentities ( $embed_code );
$code .= '</object>' ;
return $code ;
}
/**
2016-03-03 02:48:05 -08:00
* function used to convert input to proper date created formate
*
* @ param : { string } { date in string }
* @ return : { string } { proper date format }
*/
function datecreated ( $in ) {
2013-10-07 12:17:06 +00:00
$date_els = explode ( '-' , $in );
//checking date format
$df = config ( " date_format " );
$df_els = explode ( '-' , $df );
2016-03-03 02:48:05 -08:00
foreach ( $df_els as $key => $el ) {
2013-10-07 12:17:06 +00:00
$ { strtolower ( $el ) . 'id' } = $key ;
2016-03-03 02:48:05 -08:00
}
2013-10-07 12:17:06 +00:00
$month = $date_els [ $mid ];
$day = $date_els [ $did ];
$year = $date_els [ $yid ];
2016-03-03 02:48:05 -08:00
if ( $in ) {
2013-10-07 12:17:06 +00:00
return date ( " Y-m-d " , strtotime ( $year . '-' . $month . '-' . $day ));
2016-03-03 02:48:05 -08:00
} else {
2013-10-07 12:17:06 +00:00
return '0000-00-00' ;
2016-03-03 02:48:05 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 02:48:05 -08:00
* Get baseurl of working ClipBucket
*
* @ param : { none }
* @ return : { string } { url of website }
*/
function baseurl () {
2013-10-07 12:17:06 +00:00
$protocol = is_ssl () ? 'https://' : 'http://' ;
2016-03-03 02:48:05 -08:00
if ( ! $sub_dir ) {
return $base = $protocol . $_SERVER [ 'HTTP_HOST' ] . untrailingslashit ( stripslashes ( dirname (( $_SERVER [ 'SCRIPT_NAME' ]))));
} else {
return $base = $protocol . $_SERVER [ 'HTTP_HOST' ] . untrailingslashit ( stripslashes ( dirname ( dirname ( $_SERVER [ 'SCRIPT_NAME' ]))));
}
}
2013-10-07 12:17:06 +00:00
2016-03-03 02:48:05 -08:00
/**
* Get baseurl of website
* @ uses : baseurl ()
*/
function base_url (){ return baseurl ();}
2013-10-07 12:17:06 +00:00
/**
2016-03-03 02:48:05 -08:00
* SRC ( WordPress )
* Appends a trailing slash .
*
* Will remove trailing slash if it exists already before adding a trailing
* slash . This prevents double slashing a string or path .
*
* The primary use of this is for paths and thus should be used for paths . It is
* not restricted to paths and offers no specific path support .
*
* @ since 1.2 . 0
* @ uses untrailingslashit () Unslashes string if it was slashed already .
*
* @ param { string } { $string } { What to add the trailing slash to }
* @ return { string } { $string } { String with trailing slash added }
*/
2013-10-07 12:17:06 +00:00
function trailingslashit ( $string ) {
return untrailingslashit ( $string ) . '/' ;
}
/**
2016-03-03 02:48:05 -08:00
* SRC ( WordPress )
* Removes trailing slash if it exists .
*
* The primary use of this is for paths and thus should be used for paths . It is
* not restricted to paths and offers no specific path support .
*
* @ since 2.2 . 0
*
* @ param { string } { $string } { What to remove the trailing slash from }
* @ return { string } { $string } { String without the trailing slash }
*/
2013-10-07 12:17:06 +00:00
function untrailingslashit ( $string ) {
return rtrim ( $string , '/' );
}
/**
2016-03-03 02:38:27 -08:00
* Check if website is using SSL or not
*
* @ param { none }
* @ return { boolean } { true if SSL , else fasle }
* @ since 2.6 . 0
*/
2013-10-07 12:17:06 +00:00
function is_ssl () {
2016-03-03 02:38:27 -08:00
if ( isset ( $_SERVER [ 'HTTPS' ])) {
if ( 'on' == strtolower ( $_SERVER [ 'HTTPS' ])) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 02:38:27 -08:00
}
if ( '1' == $_SERVER [ 'HTTPS' ]) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 02:38:27 -08:00
}
2013-10-07 12:17:06 +00:00
} elseif ( isset ( $_SERVER [ 'SERVER_PORT' ]) && ( '443' == $_SERVER [ 'SERVER_PORT' ] ) ) {
return true ;
}
return false ;
}
/**
2016-03-03 02:33:24 -08:00
* This will update stats like Favorite count , Playlist count
*
* @ param : { string } { $type } { favorite by default , type of stats to update }
* @ param : { string } { $object } { video by default , object to update stats for e . g video , photo }
* @ param : { integer } { $id } { id of item to update stats for }
* @ param : { string } { $op } { + by default , increment of decrement }
* @ action : databse updation
*/
function updateObjectStats ( $type = 'favorite' , $object = 'video' , $id , $op = '+' ) {
2013-10-07 12:17:06 +00:00
global $db ;
2016-03-03 02:33:24 -08:00
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case " favorite " : case " favourite " :
case " favorites " : case " favourties " :
case " fav " :
{
2016-03-03 02:33:24 -08:00
switch ( $object ) {
2013-10-07 12:17:06 +00:00
case " video " :
case " videos " : case " v " :
{
$db -> update ( tbl ( 'video' ), array ( 'favourite_count' ), array ( " |f|favourite_count " . $op . " 1 " ), " videoid = ' " . $id . " ' " );
}
break ;
case " photo " :
case " photos " : case " p " :
{
$db -> update ( tbl ( 'photos' ), array ( 'total_favorites' ), array ( " |f|total_favorites " . $op . " 1 " ), " photo_id = ' " . $id . " ' " );
}
break ;
}
}
break ;
case " playlist " : case " playList " :
case " plist " :
{
2016-03-03 02:33:24 -08:00
switch ( $object ) {
2013-10-07 12:17:06 +00:00
case " video " :
case " videos " : case " v " :
{
$db -> update ( tbl ( 'video' ), array ( 'playlist_count' ), array ( " |f|playlist_count " . $op . " 1 " ), " videoid = ' " . $id . " ' " );
}
}
}
}
}
/**
2016-03-03 02:33:24 -08:00
* Function used to check weather conversion lock exists or not
2013-10-07 12:17:06 +00:00
* if converson log exists it means no further conersion commands will be executed
*
2016-03-03 02:17:10 -08:00
* @ return { boolean } { true if conversion lock exists , else false }
2013-10-07 12:17:06 +00:00
*/
2016-03-03 02:33:24 -08:00
2016-03-03 02:17:10 -08:00
function conv_lock_exists () {
if ( file_exists ( TEMP_DIR . '/conv_lock.loc' )) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 02:17:10 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 02:17:10 -08:00
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-03 02:17:10 -08:00
* Function used to return a well - formed queryString
* for passing variables to url
* @ input variable_name
*/
function queryString ( $var = false , $remove = false ) {
2013-10-07 12:17:06 +00:00
$queryString = $_SERVER [ 'QUERY_STRING' ];
2016-03-03 02:17:10 -08:00
if ( $var ) {
$queryString = preg_replace ( " /&? $var =([ \ w+ \ s \ b \ .? \ S]+|)/ " , " " , $queryString );
}
2013-10-07 12:17:06 +00:00
2016-03-03 02:17:10 -08:00
if ( $remove ) {
if ( ! is_array ( $remove )) {
$queryString = preg_replace ( " /&? $remove =([ \ w+ \ s \ b \ .? \ S]+|)/ " , " " , $queryString );
} else {
foreach ( $remove as $rm ) {
$queryString = preg_replace ( " /&? $rm =([ \ w+ \ s \ b \ .? \ S]+|)/ " , " " , $queryString );
}
}
2013-10-07 12:17:06 +00:00
}
2016-03-03 02:17:10 -08:00
if ( $queryString ) {
2013-10-07 12:17:06 +00:00
$preUrl = " ? $queryString & " ;
2016-03-03 02:17:10 -08:00
} else {
2013-10-07 12:17:06 +00:00
$preUrl = " ? " ;
2016-03-03 02:17:10 -08:00
}
2013-10-07 12:17:06 +00:00
$preUrl = preg_replace ( array ( " /( \ & { 2,10})/ " , " / \ ? \ &/ " ), array ( " & " , " ? " ), $preUrl );
return $preUrl . $var ;
}
/**
* Following two functions are taken from
* tutorialzine . com 's post ' Creating a Facebook - like Registration Form with jQuery '
* These function are written by Martin Angelov .
* Read post here : http :// tutorialzine . com / 2009 / 08 / creating - a - facebook - like - registration - form - with - jquery /
*/
2016-03-03 02:17:10 -08:00
function generate_options ( $params ) {
2013-10-07 12:17:06 +00:00
$reverse = false ;
2016-03-03 02:17:10 -08:00
if ( $params [ 'from' ] > $params [ 'to' ]) {
2013-10-07 12:17:06 +00:00
$tmp = $params [ 'from' ];
$params [ 'from' ] = $params [ 'to' ];
$params [ 'to' ] = $tmp ;
$reverse = true ;
}
$return_string = array ();
2016-03-03 02:17:10 -08:00
for ( $i = $params [ 'from' ]; $i <= $params [ 'to' ]; $i ++ ) {
2013-10-07 12:17:06 +00:00
//$return_string[$i] = ($callback?$callback($i):$i);
$return_string [] = '<option value="' . $i . '">' . ( $params [ 'callback' ] ? $params [ 'callback' ]( $i ) : $i ) . '</option>' ;
}
2016-03-03 02:17:10 -08:00
if ( $reverse ) {
2013-10-07 12:17:06 +00:00
$return_string = array_reverse ( $return_string );
}
2016-03-03 02:17:10 -08:00
2013-10-07 12:17:06 +00:00
return join ( '' , $return_string );
}
2016-03-03 02:01:04 -08:00
2013-10-07 12:17:06 +00:00
function callback_month ( $month )
{
return date ( 'M' , mktime ( 0 , 0 , 0 , $month , 1 ));
}
/**
2016-03-03 01:55:32 -08:00
* Download a remote file and store in given directory
*
* @ param : { string } { $snatching_file } { file to be downloaded }
* @ param : { string } { $destination } { where to save the downloaded file }
* @ param : { string } { $dest_name } { new name for file }
*/
function snatch_it ( $snatching_file , $destination , $dest_name , $rawdecode = true ) {
2013-10-07 12:17:06 +00:00
global $curl ;
if ( $rawdecode == true )
$snatching_file = rawurldecode ( $snatching_file );
2016-03-03 01:55:32 -08:00
if ( PHP_OS == " Linux " ) {
2014-09-29 11:02:53 +00:00
$destination . '/' . $dest_name ;
$fp = fopen ( $destination . '/' . $dest_name , 'w+' );
2016-03-03 01:55:32 -08:00
} elseif ( PHP_OS == " WINNT " ) {
2014-09-29 11:02:53 +00:00
$destination . '\\' . $dest_name ;
$fp = fopen ( $destination . '\\' . $dest_name , 'w+' );
}
2013-10-07 12:17:06 +00:00
$ch = curl_init ( $snatching_file );
curl_setopt ( $ch , CURLOPT_TIMEOUT , 600 );
curl_setopt ( $ch , CURLOPT_FILE , $fp );
curl_setopt ( $ch , CURLOPT_USERAGENT ,
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2' );
curl_exec ( $ch );
curl_close ( $ch );
fclose ( $fp );
2016-03-03 01:55:32 -08:00
}
2013-10-07 12:17:06 +00:00
/**
2016-03-03 01:55:32 -08:00
* Checks if CURL is installed on server
*
* @ param : { none }
* @ return : { boolean } { true if curl found , else false }
*/
2013-10-07 12:17:06 +00:00
function isCurlInstalled ()
{
2016-03-03 01:55:32 -08:00
if ( in_array ( 'curl' , get_loaded_extensions ())) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 01:55:32 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
}
}
/**
2016-03-03 01:55:32 -08:00
* Load configruation related files for uploader ( video , photo )
* @ return : { null }
*/
function uploaderDetails () {
2013-10-07 12:17:06 +00:00
global $uploaderType ;
$uploaderDetails = array
(
'uploadSwfPath' => JS_URL . '/uploadify/uploadify.swf' ,
'uploadScriptPath' => BASEURL . '/actions/file_uploader.php' ,
);
$photoUploaderDetails = array
(
'uploadSwfPath' => JS_URL . '/uploadify/uploadify.swf' ,
'uploadScriptPath' => BASEURL . '/actions/photo_uploader.php' ,
);
assign ( 'uploaderDetails' , $uploaderDetails );
assign ( 'photoUploaderDetails' , $photoUploaderDetails );
//Calling Custom Functions
cb_call_functions ( 'uploaderDetails' );
}
/**
2016-03-03 01:55:32 -08:00
* Checks if given section is enabled or not e . g videos , photos
*
* @ param : { string } { $input } { section to check }
* @ param : { boolean } { $restrict } { false by default , returns true on cb_install }
* @ return : { boolean } { true of false depending on situation }
*/
function isSectionEnabled ( $input , $restrict = false ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
$section = $Cbucket -> configs [ $input . 'Section' ];
2016-03-03 01:55:32 -08:00
if ( ! $restrict ) {
if ( $section == 'yes' ) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 01:55:32 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
2016-03-03 01:55:32 -08:00
}
} else {
if ( $section == 'yes' || THIS_PAGE == 'cb_install' ) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-03 01:55:32 -08:00
} else {
2013-10-07 12:17:06 +00:00
template_files ( 'blocked.html' );
display_it ();
exit ();
}
}
}
2016-03-02 23:35:40 -08:00
/**
* Get depth of an array ( nested elements )
*
* @ param : { array } { $array } { array to find depth for }
* @ return : { integer } { $ini_depth } { depth of array }
*/
2013-10-07 12:17:06 +00:00
function array_depth ( $array ) {
$ini_depth = 0 ;
2016-03-02 23:35:40 -08:00
foreach ( $array as $arr ) {
if ( is_array ( $arr )) {
2013-10-07 12:17:06 +00:00
$depth = array_depth ( $arr ) + 1 ;
2016-03-02 23:35:40 -08:00
if ( $depth > $ini_depth ) {
2013-10-07 12:17:06 +00:00
$ini_depth = $depth ;
2016-03-02 23:35:40 -08:00
}
2013-10-07 12:17:06 +00:00
}
}
return $ini_depth ;
}
/**
* JSON_ENCODE short
*/
2013-10-08 12:24:07 +00:00
if ( ! function_exists ( 'je' ) ) {
function je ( $in ){ return json_encode ( $in ); }
}
2013-10-07 12:17:06 +00:00
/**
* JSON_DECODE short
*/
2013-10-08 12:24:07 +00:00
if ( ! function_exists ( 'jd' ) ) {
function jd ( $in , $returnClass = false ){ if ( ! $returnClass ) return json_decode ( $in , true ); else return json_decode ( $in ); }
}
2013-10-07 12:17:06 +00:00
/**
2016-03-02 23:30:10 -08:00
* Updates last commented data - helps cache refresh
* @ param : { string } { $type } { type of comment e . g video , channel }
* @ param : { integer } { $id } { id of element to update }
* @ action : databse updation
*/
function update_last_commented ( $type , $id ) {
2013-10-07 12:17:06 +00:00
global $db ;
2016-03-02 23:30:10 -08:00
if ( $type && $id ) {
switch ( $type ) {
2013-10-07 12:17:06 +00:00
case " v " :
case " video " :
case " vdo " :
case " vid " :
case " videos " :
$db -> update ( tbl ( " video " ), array ( 'last_commented' ), array ( now ()), " videoid=' $id ' " );
break ;
case " c " :
case " channel " :
case " user " :
case " u " :
case " users " :
case " channels " :
$db -> update ( tbl ( " users " ), array ( 'last_commented' ), array ( now ()), " userid=' $id ' " );
break ;
case " cl " :
case " collection " :
case " collect " :
case " collections " :
case " collects " :
$db -> update ( tbl ( " collections " ), array ( 'last_commented' ), array ( now ()), " collection_id=' $id ' " );
break ;
case " p " :
case " photo " :
case " photos " :
case " picture " :
case " pictures " :
$db -> update ( tbl ( " photos " ), array ( 'last_commented' ), array ( now ()), " photo_id=' $id ' " );
break ;
case " t " :
case " topic " :
case " topics " :
$db -> update ( tbl ( " group_topics " ), array ( 'last_post_time' ), array ( now ()), " topic_id=' $id ' " );
2016-03-02 23:30:10 -08:00
break ;
2013-10-07 12:17:06 +00:00
}
}
}
/**
* Function used display privacy in text
* according to provided number
* 0 - Public
* 1 - Protected
* 2 - Private
2016-03-02 23:30:10 -08:00
* @ note : groups have been deprecated and will be removed soon
2013-10-07 12:17:06 +00:00
*/
2016-03-02 23:30:10 -08:00
function getGroupPrivacy ( $privacyID ) {
switch ( $privacyID ) {
case " 0 " : default :
2013-10-07 12:17:06 +00:00
{
2016-03-02 23:30:10 -08:00
return lang ( " group_is_public " );
}
break ;
case " 1 " :
{
return lang ( " group_is_protected " );
}
break ;
case " 2 " :
{
return lang ( " group_is_private " );
2013-10-07 12:17:06 +00:00
}
2016-03-02 23:30:10 -08:00
break ;
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-02 23:30:10 -08:00
* Inserts new feed against given user
*
* @ param : { array } { $array } { array with all details of feed e . g userid , action etc }
* @ action : inserts feed into database
*/
function addFeed ( $array ) {
2013-10-07 12:17:06 +00:00
global $cbfeeds , $cbphoto , $userquery ;
$action = $array [ 'action' ];
2016-03-02 23:30:10 -08:00
if ( $array [ 'uid' ]) {
2013-10-07 12:17:06 +00:00
$userid = $array [ 'uid' ];
2016-03-02 23:30:10 -08:00
} else {
2013-10-07 12:17:06 +00:00
$userid = userid ();
2016-03-02 23:30:10 -08:00
}
2013-10-07 12:17:06 +00:00
2016-03-02 23:30:10 -08:00
switch ( $action ) {
2013-10-07 12:17:06 +00:00
case " upload_photo " :
{
$feed [ 'action' ] = 'upload_photo' ;
$feed [ 'object' ] = 'photo' ;
$feed [ 'object_id' ] = $array [ 'object_id' ];
$feed [ 'uid' ] = $userid ;;
$cbfeeds -> addFeed ( $feed );
}
break ;
case " upload_video " :
case " add_favorite " :
{
$feed [ 'action' ] = $action ;
$feed [ 'object' ] = 'video' ;
$feed [ 'object_id' ] = $array [ 'object_id' ];
$feed [ 'uid' ] = $userid ;
$cbfeeds -> addFeed ( $feed );
}
break ;
case " signup " :
{
$feed [ 'action' ] = 'signup' ;
$feed [ 'object' ] = 'signup' ;
$feed [ 'object_id' ] = $array [ 'object_id' ];
$feed [ 'uid' ] = $userid ;;
$cbfeeds -> addFeed ( $feed );
}
break ;
case " create_group " :
case " join_group " :
{
$feed [ 'action' ] = $action ;
$feed [ 'object' ] = 'group' ;
$feed [ 'object_id' ] = $array [ 'object_id' ];
$feed [ 'uid' ] = $userid ;
$cbfeeds -> addFeed ( $feed );
}
break ;
case " add_friend " :
{
$feed [ 'action' ] = 'add_friend' ;
$feed [ 'object' ] = 'friend' ;
$feed [ 'object_id' ] = $array [ 'object_id' ];
$feed [ 'uid' ] = $userid ;
$cbfeeds -> addFeed ( $feed );
}
break ;
case " add_collection " :
{
$feed [ 'action' ] = 'add_collection' ;
$feed [ 'object' ] = 'collection' ;
$feed [ 'object_id' ] = $array [ 'object_id' ];
$feed [ 'uid' ] = $userid ;
$cbfeeds -> addFeed ( $feed );
}
}
}
/**
2016-03-02 23:12:35 -08:00
* Fetch directory of a plugin to make it dynamic
*
* @ param : { string } { $pluginFile } { false by default , main file of plugin }
* @ return : { string } { basename ( $pluginFile ) } { directory path of plugin }
*/
function this_plugin ( $pluginFile = NULL ) {
2013-10-07 12:17:06 +00:00
if ( ! $pluginFile )
global $pluginFile ;
return basename ( dirname ( $pluginFile ));
}
2013-10-30 13:03:33 +00:00
2013-10-07 12:17:06 +00:00
/**
2016-03-02 23:08:39 -08:00
* Fetch browser details for current user
*
* @ param : { string } { $in } { false by default , HTTP_USER_AGENT }
* @ param : { boolean } { $assign } { false by default , assigns browser details to this if true }
* @ return : { array } { $array } { array with all details of user }
*/
function get_browser_details ( $in = NULL , $assign = false ) {
2013-10-07 12:17:06 +00:00
//Checking if browser is firefox
2016-03-02 23:08:39 -08:00
if ( ! $in ) {
2013-10-07 12:17:06 +00:00
$in = $_SERVER [ 'HTTP_USER_AGENT' ];
2016-03-02 23:08:39 -08:00
}
2013-10-07 12:17:06 +00:00
$u_agent = $in ;
$bname = 'Unknown' ;
$platform = 'Unknown' ;
$version = " " ;
//First get the platform?
if ( preg_match ( '/linux/i' , $u_agent )) {
$platform = 'linux' ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/iPhone/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$platform = 'iphone' ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/iPad/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$platform = 'ipad' ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/macintosh|mac os x/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$platform = 'mac' ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/windows|win32/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$platform = 'windows' ;
}
// Next get the name of the useragent yes seperately and for good reason
2016-03-02 23:08:39 -08:00
if ( preg_match ( '/MSIE/i' , $u_agent ) && ! preg_match ( '/Opera/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Internet Explorer' ;
$ub = " MSIE " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Firefox/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Mozilla Firefox' ;
$ub = " Firefox " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Chrome/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Google Chrome' ;
$ub = " Chrome " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Safari/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Apple Safari' ;
$ub = " Safari " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Opera/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Opera' ;
$ub = " Opera " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Netscape/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Netscape' ;
$ub = " Netscape " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Googlebot/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Googlebot' ;
$ub = " bot " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/msnbot/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'MSNBot' ;
$ub = " bot " ;
2016-03-02 23:08:39 -08:00
} elseif ( preg_match ( '/Yahoo\! Slurp/i' , $u_agent )) {
2013-10-07 12:17:06 +00:00
$bname = 'Yahoo Slurp' ;
$ub = " bot " ;
}
// finally get the correct version number
$known = array ( 'Version' , $ub , 'other' );
$pattern = '#(?<browser>' . join ( '|' , $known ) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#' ;
if ( !@ preg_match_all ( $pattern , $u_agent , $matches )) {
// we have no matching number just continue
}
// see how many we have
$i = count ( $matches [ 'browser' ]);
if ( $i != 1 ) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
if ( strripos ( $u_agent , " Version " ) < strripos ( $u_agent , $ub )){
$version = $matches [ 'version' ][ 0 ];
2016-03-02 23:08:39 -08:00
} else {
2013-10-07 12:17:06 +00:00
$version = $matches [ 'version' ][ 1 ];
}
2016-03-02 23:08:39 -08:00
} else {
2013-10-07 12:17:06 +00:00
$version = $matches [ 'version' ][ 0 ];
}
// check if we have a number
if ( $version == null || $version == " " ) { $version = " ? " ;}
$array = array (
'userAgent' => $u_agent ,
'name' => $bname ,
'version' => $version ,
'platform' => $platform ,
'bname' => strtolower ( $ub ),
'pattern' => $pattern
);
if ( $assign ) assign ( $assign , $array ); else return $array ;
}
2016-03-02 23:08:39 -08:00
function update_user_voted ( $array , $userid = NULL ) {
2013-10-07 12:17:06 +00:00
global $userquery ;
return $userquery -> update_user_voted ( $array , $userid );
}
/**
2016-03-02 22:58:35 -08:00
* Deletes a video from a video collection
* @ param : { array } { $vdetails } { video details of video to be deleted }
* @ action : { calls function from video class }
*/
function delete_video_from_collection ( $vdetails ) {
2013-10-07 12:17:06 +00:00
global $cbvid ;
$cbvid -> collection -> deleteItemFromCollections ( $vdetails [ 'videoid' ]);
}
/**
2016-03-02 22:54:40 -08:00
* Check if a remote file exists or not via curl without downloading it
* @ param : { string } { $url } { URL of file to check }
* @ return : { boolean } { true if file exists , else fasle }
*/
2013-10-07 12:17:06 +00:00
2016-03-02 22:54:40 -08:00
function checkRemoteFile ( $url ) {
2013-10-07 12:17:06 +00:00
$ch = curl_init ();
curl_setopt ( $ch , CURLOPT_URL , $url );
// don't download content
curl_setopt ( $ch , CURLOPT_NOBODY , 1 );
curl_setopt ( $ch , CURLOPT_FAILONERROR , 1 );
curl_setopt ( $ch , CURLOPT_HEADER , 1 );
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
$result = curl_exec ( $ch );
2016-03-02 22:54:40 -08:00
if ( $result !== FALSE ) {
2013-10-07 12:17:06 +00:00
return true ;
2016-03-02 22:54:40 -08:00
} else {
2013-10-07 12:17:06 +00:00
return false ;
}
}
/**
2016-03-02 22:51:12 -08:00
* Fetch total count for videos , photos and channels
*
* @ param : { string } { $section } { section to select count for }
* @ param : { string } { $query } { query to fetch data against }
* @ return : { integer } { $select [ 0 ][ 'counts' ] } { count for requested field }
*/
function get_counter ( $section , $query ) {
2013-10-07 12:17:06 +00:00
global $db ;
2016-03-02 22:51:12 -08:00
if ( ! config ( 'use_cached_pagin' )) {
return false ;
}
2013-10-07 12:17:06 +00:00
$timeRefresh = config ( 'cached_pagin_time' );
$timeRefresh = $timeRefresh * 60 ;
$validTime = time () - $timeRefresh ;
unset ( $query [ 'order' ]);
$je_query = json_encode ( $query );
$query_md5 = md5 ( $je_query );
$select = $db -> select ( tbl ( 'counters' ), " * " , " section=' $section ' AND query_md5=' $query_md5 '
AND '$validTime' < date_added " );
2016-03-02 22:51:12 -08:00
if ( $db -> num_rows > 0 ) {
2013-10-07 12:17:06 +00:00
return $select [ 0 ][ 'counts' ];
2016-03-02 22:51:12 -08:00
} else {
return false ;
}
2013-10-07 12:17:06 +00:00
}
/**
2016-03-02 22:47:35 -08:00
* Updates total count for videos , photos and channels
*
* @ param : { string } { $section } { section to update counter for }
* @ param : { string } { $query } { query to run for updating }
* @ param : { integer } { $counter } { count to update }
* @ return : { null }
*/
function update_counter ( $section , $query , $counter ) {
2013-10-07 12:17:06 +00:00
global $db ;
unset ( $query [ 'order' ]);
$je_query = json_encode ( $query );
$query_md5 = md5 ( $je_query );
$count = $db -> count ( tbl ( 'counters' ), " * " , " section=' $section ' AND query_md5=' $query_md5 ' " );
2016-03-02 22:47:35 -08:00
if ( $count ) {
2013-10-07 12:17:06 +00:00
$db -> update ( tbl ( 'counters' ), array ( 'counts' , 'date_added' ), array ( $counter , strtotime ( now ())),
" section=' $section ' AND query_md5=' $query_md5 ' " );
2016-03-02 22:47:35 -08:00
} else {
2013-10-07 12:17:06 +00:00
$db -> insert ( tbl ( 'counters' ), array ( 'section' , 'query' , 'query_md5' , 'counts' , 'date_added' ),
array ( $section , '|no_mc|' . $je_query , $query_md5 , $counter , strtotime ( now ())));
}
}
/**
2016-03-02 22:41:17 -08:00
* Function for registering module file
2016-03-02 22:47:35 -08:00
*
2016-03-02 22:41:17 -08:00
* @ param : { string } { $mod_name } { name of module }
* @ param : { string } { $file } { file to be loaded for module }
* @ action : Adds module details into an existing array
*/
function register_module ( $mod_name , $file ) {
2013-10-07 12:17:06 +00:00
global $Cbucket ;
$Cbucket -> modules_list [ $mod_name ][] = $file ;
}
/**
2016-03-02 22:41:17 -08:00
* Loads all module files ( mostly used with plugins )
* @ param : { none } { all things handled inside function }
*/
2014-11-22 10:58:37 +00:00
2016-03-02 22:41:17 -08:00
function load_modules () {
2013-10-07 12:17:06 +00:00
global $Cbucket , $lang_obj , $signup , $Upload , $cbgroup ,
$adsObj , $formObj , $cbplugin , $eh , $sess , $cblog , $imgObj ,
$cbvideo , $cbplayer , $cbemail , $cbpm , $cbpage , $cbindex ,
$cbcollection , $cbphoto , $cbfeeds , $userquery , $db , $pages , $cbvid ;
2016-03-02 22:41:17 -08:00
foreach ( $Cbucket -> modules_list as $cbmod ) {
foreach ( $cbmod as $modfile ) {
2013-10-07 12:17:06 +00:00
if ( file_exists ( $modfile ))
include ( $modfile );
2014-11-22 10:58:37 +00:00
}
2013-10-07 12:17:06 +00:00
}
}
2016-03-02 05:38:53 -08:00
/**
2016-03-02 22:41:17 -08:00
* function used to verify user age
* @ param : { string } { $dob } { date of birth of user } \
* @ return : { boolean } { true / flase depending on situation }
*/
function verify_age ( $dob ) {
2016-03-02 05:38:53 -08:00
$allowed_age = config ( 'min_age_reg' );
if ( $allowed_age < 1 ) return true ;
$age_time = strtotime ( $dob );
$diff = time () - $age_time ;
$diff = $diff / 60 / 60 / 24 / 364 ;
if ( $diff >= $allowed_age ) return true ;
return false ;
}
2013-10-30 13:03:33 +00:00
2013-11-09 22:16:59 +00:00
2016-03-02 05:38:53 -08:00
/**
* Checks development mode
*
* @ return Boolean
*/
2016-03-02 22:41:17 -08:00
function in_dev () {
if ( defined ( 'DEVELOPMENT_MODE' )) {
2016-03-02 05:38:53 -08:00
return DEVELOPMENT_MODE ;
2016-03-02 22:41:17 -08:00
} else {
2016-03-02 05:38:53 -08:00
return false ;
2016-03-02 22:41:17 -08:00
}
2016-03-02 05:38:53 -08:00
}
2013-11-09 22:16:59 +00:00
2016-03-02 22:41:17 -08:00
/**
* Dumps data in pretty format [ latest CB prefers pr () instead ]
* @ param : { array } { $data } { data to be dumped }
*/
function dump ( $data ) {
2016-03-02 05:38:53 -08:00
echo " <pre> " ;
var_dump ( $data );
echo " </pre> " ;
}
2014-02-18 14:02:48 +00:00
2016-03-02 06:30:22 -08:00
2016-03-02 05:38:53 -08:00
/**
2016-03-02 06:30:22 -08:00
* Creates log files for video conversion
*
* @ param : { string } { $data } { data to be written in file }
* @ param : { string } { $file } { name of file to write data for }
* @ param : { string } { $path } { false by default , path to file }
* @ param : { boolean } { $force } { false by default , forces file creation }
*/
function logData ( $data , $file = NULL , $path = false , $force = false ) {
if ( $force != false &&! empty ( $path )) {
2016-03-02 05:38:53 -08:00
$file = $path ;
if ( is_array ( $data )) $data = json_encode ( $data );
if ( file_exists ( $file ))
$text = file_get_contents ( $file );
$text .= " \n { $data } " ;
file_put_contents ( $file , $text );
2016-03-02 06:30:22 -08:00
} else {
if ( ! empty ( $file )) {
2016-03-02 05:38:53 -08:00
$logFilePath = BASEDIR . " /files/ " . $file . " .txt " ;
2016-03-02 06:30:22 -08:00
} else {
2016-03-02 05:38:53 -08:00
$logFilePath = BASEDIR . " /files/ffmpegLog.txt " ;
2015-08-24 11:04:34 +00:00
}
2016-03-02 05:38:53 -08:00
if ( is_array ( $data )) $data = json_encode ( $data );
2016-03-02 06:30:22 -08:00
if ( file_exists ( $logFilePath )) {
2016-03-02 05:38:53 -08:00
$text = file_get_contents ( $logFilePath );
2016-03-02 06:30:22 -08:00
}
2016-03-02 05:38:53 -08:00
$text .= " \n \n { $data } " ;
2016-03-02 06:30:22 -08:00
if ( DEVELOPMENT_MODE || $force ) {
2016-03-02 05:38:53 -08:00
file_put_contents ( $logFilePath , $text );
2016-03-02 06:30:22 -08:00
}
2015-08-24 11:04:34 +00:00
}
2016-03-02 05:38:53 -08:00
}
2013-11-18 14:59:33 +00:00
2016-03-02 05:38:53 -08:00
/**
* Displays a code error in developer friendly way [ used with PHP exceptions ]
*
* @ param { Object } { $e } { complete current object }
*/
2014-11-18 10:30:16 +00:00
2016-03-02 05:38:53 -08:00
function show_cb_error ( $e ) {
echo $e -> getMessage ();
echo '<br>' ;
echo 'On Line Number ' ;
echo $e -> getLine ();
echo '<br>' ;
echo 'In file ' ;
echo $e -> getFile ();
}
2016-03-02 05:34:38 -08:00
2016-03-02 05:38:53 -08:00
/**
* Returns current page name or boolean for the given string
*
* @ param { string } { $name } { name of page to check against }
* @ return : { string / boolean } { page name if found , else false }
*/
2013-11-18 14:59:33 +00:00
2016-03-03 06:25:07 -08:00
function this_page ( $name = " " ) {
if ( defined ( 'THIS_PAGE' )) {
2016-03-02 05:38:53 -08:00
$page = THIS_PAGE ;
2016-03-03 06:25:07 -08:00
if ( $name ) {
if ( $page == $name ) {
return true ;
} else {
2016-03-02 05:38:53 -08:00
return false ;
2016-03-03 06:25:07 -08:00
}
2016-03-02 05:38:53 -08:00
}
return $page ;
}
return false ;
}
/**
* Returns current page ' s parent name or boolean for the given string
*
* @ param { string } { $name } { name of page to check against }
* @ return : { string / boolean } { page name if found , else false }
*/
function parent_page ( $name = " " ) {
if ( defined ( 'PARENT_PAGE' )) {
$page = PARENT_PAGE ;
if ( $name ) {
if ( $page == $name )
return true ;
else
return false ;
}
return $page ;
}
return false ;
}
2014-09-19 06:30:04 +00:00
2015-02-24 14:49:47 +00:00
/**
2016-03-02 05:17:27 -08:00
* Function used for building sort links that are used
* on main pages such as videos . php , photos . php etc
*
* @ param : { none }
* @ return : { array } { $array } { an array with all possible sort sorts }
*/
function sorting_links () {
2015-02-24 14:49:47 +00:00
if ( ! isset ( $_GET [ 'sort' ]))
$_GET [ 'sort' ] = 'most_recent' ;
if ( ! isset ( $_GET [ 'time' ]))
$_GET [ 'time' ] = 'all_time' ;
$array = array
2015-10-21 06:33:29 +00:00
( 'view_all' => lang ( 'All' ),
'most_recent' => lang ( 'recent' ),
2015-02-24 14:49:47 +00:00
'most_viewed' => lang ( 'viewed' ),
'featured' => lang ( 'featured' ),
'top_rated' => lang ( 'top_rated' ),
2015-10-21 06:33:29 +00:00
'most_commented' => lang ( 'commented' )
2015-02-24 14:49:47 +00:00
);
return $array ;
}
2016-03-02 05:17:27 -08:00
/**
* Function used for building time links that are used
* on main pages such as videos . php , photos . php etc
*
* @ param : { none }
* @ return : { array } { $array } { an array with all possible time sorts }
*/
function time_links () {
2015-02-24 14:49:47 +00:00
$array = array
( 'all_time' => lang ( 'alltime' ),
'today' => lang ( 'today' ),
'yesterday' => lang ( 'yesterday' ),
'this_week' => lang ( 'thisweek' ),
'last_week' => lang ( 'lastweek' ),
'this_month' => lang ( 'thismonth' ),
'last_month' => lang ( 'lastmonth' ),
'this_year' => lang ( 'thisyear' ),
'last_year' => lang ( 'lastyear' ),
);
return $array ;
}
2015-06-03 11:24:48 +00:00
/**
2016-03-02 05:13:09 -08:00
* Fetch videos from video collections
*
* @ param : { integer } { $id } { id of collection from which to fetch videos }
* @ param : { string } { $order } { sorting of videos }
* @ param : { integer } { $limit } { number of videos to fetch }
* @ param : { boolean } { $count_only } { false by default , if true , returns videos count only }
* @ return { array } { $items } { an array with videos data }
*/
function get_videos_of_collection ( $id , $order , $limit , $count_only = false ) {
2015-06-03 11:24:48 +00:00
global $cbvideo ;
$items = array ();
$items = $cbvideo -> collection -> get_collection_items_with_details ( $id , $order , $limit , $count_only );
return $items ;
}
2015-02-25 15:08:32 +00:00
/**
2016-03-02 05:13:09 -08:00
* Calls $lang_obj variable and returns a string
* @ return String
*/
function get_locale () {
2015-02-25 15:08:32 +00:00
global $lang_obj ;
return $lang_obj -> lang_iso ;
}
2015-08-03 14:16:06 +00:00
/*assign results to template for load more buttons on all_videos.html*/
function template_assign ( $results , $limit , $total_results , $template_path , $assigned_variable_smarty )
{
if ( $limit < $total_results )
{
$html = " " ;
$count = $limit ;
foreach ( $results as $key => $result )
{
assign ( " $assigned_variable_smarty " , $result );
$html .= Fetch ( $template_path );
//Template('blocks/videos/all_video.html');
}
$arr = array ( " template " => $html , 'count' => $count , 'total' => $limit );
}
else
{
$arr = 'limit_exceeds' ;
}
return $arr ;
}
2015-08-24 11:04:34 +00:00
/**
* function uses to parse certain string from bulk string
* @ author : Awais Tariq
* @ param : { string } { $needle_start } { string from where the parse starts }
* @ param : { string } { $needle_end } { string from where the parse end }
*@ param : { string } { $results } { total string in which we search }
*
* @ todo { ..... }
*
*
* @ return { bool / string / int } { true / $return_arr }
*/
2016-03-02 05:13:09 -08:00
function find_string ( $needle_start , $needle_end , $results ) {
if ( empty ( $results ) || empty ( $needle_start ) || empty ( $needle_end )) {
2015-08-24 11:04:34 +00:00
return false ;
}
$start = strpos ( $results , $needle_start );
$end = strpos ( $results , $needle_end );
2016-03-02 05:13:09 -08:00
if ( ! empty ( $start ) &&! empty ( $end )) {
2015-08-24 11:04:34 +00:00
$results = substr ( $results , $start , $end );
//echo $results;
$end = strpos ( $results , $needle_end );
2016-03-02 05:13:09 -08:00
if ( empty ( $end )) {
2015-08-24 11:04:34 +00:00
return false ;
}
$results = substr ( $results , 0 , $end );
$return_arr = explode ( ':' , $results );
return $return_arr ;
2016-03-02 05:13:09 -08:00
} else {
2015-08-24 11:04:34 +00:00
return false ;
}
}
2015-10-21 07:06:56 +00:00
/*
* Function used to check server configs
* Checks : MEMORY_LIMIT , UPLOAD_MAX_FILESIZE , POST_MAX_SIZE , MAX_EXECUTION_TIME
* If any of these configs are less than required value , warning is shown
*/
2016-03-02 05:02:56 -08:00
function check_server_confs () {
2015-10-21 07:06:56 +00:00
define ( 'POST_MAX_SIZE' , ini_get ( 'post_max_size' ));
define ( 'MEMORY_LIMIT' , ini_get ( 'memory_limit' ));
define ( 'UPLOAD_MAX_FILESIZE' , ini_get ( 'upload_max_filesize' ));
define ( 'MAX_EXECUTION_TIME' , ini_get ( 'max_execution_time' ));
2016-03-02 05:02:56 -08:00
if ( POST_MAX_SIZE >= 50 && MEMORY_LIMIT >= 128 && UPLOAD_MAX_FILESIZE >= 50 && MAX_EXECUTION_TIME >= 7200 ) {
2015-10-21 07:06:56 +00:00
define ( " SERVER_CONFS " , true );
2016-03-02 05:02:56 -08:00
} elseif ( POST_MAX_SIZE < 50 || MEMORY_LIMIT < 128 || UPLOAD_MAX_FILESIZE < 50 && MAX_EXECUTION_TIME < 7200 ) {
2015-10-21 07:06:56 +00:00
e ( 'You must update <strong>"Server Configurations"</strong>. Click here <a href=' . BASEURL . '/admin_area/cb_server_conf_info.php>for details</a>' , w );
define ( " SERVER_CONFS " , false );
2016-03-02 05:02:56 -08:00
} else {
2015-10-21 07:06:56 +00:00
define ( " SERVER_CONFS " , false );
}
}
2016-01-27 13:51:32 +00:00
/**
* Pulls subscribers ids for given userid
* @ param : { integer } { $userid } { id of user to get subscribers for }
* @ param : { integer / boolean } { false by default , number of subscribers to get }
* @ return : { array } { $ids } { ids of subscribers }
* @ author : Saqib Razzaq
* @ since : ClipBucket 2.8 . 1
*/
2016-03-02 04:59:00 -08:00
function get_user_subscibers ( $userid , $limit = false ) {
2016-01-27 13:51:32 +00:00
global $db ;
2016-03-02 04:59:00 -08:00
$result = $db -> select ( tbl ( " subscriptions " ), " userid " , " subscribed_to = ' $userid ' " , " $limit " );
2016-01-27 13:51:32 +00:00
$ids = array ();
foreach ( $result as $key => $value ) {
$ids [] = $value [ 'userid' ];
}
return $ids ;
}
2016-03-02 04:59:00 -08:00
/**
2016-01-29 13:33:10 +00:00
* Consider it an aleternative of regular template_files ()
* It is being introduced because plugin files load before
* anything else and if we load an HTML file via plugin ,
* it kills Cb structure because html loads before global_header ()
* with usage of this function , things will run smoothly instead
* @ param : { string } { $display_file } { path to html to be displayed }
* @ since : 31 st December , 2015
* @ author : Saqib Razzaq
*/
2016-03-02 04:59:00 -08:00
function display_module_file ( $display_file ) {
if ( file_exists ( $display_file )) {
2016-01-29 13:33:10 +00:00
global $ClipBucket ;
$ClipBucket -> template_files [] = array ( 'file' => $display_file );
2016-03-02 04:59:00 -08:00
} else {
if ( has_access ( " admin_access " )) {
2016-01-29 13:33:10 +00:00
e ( " Display template couldn't be loaded (admin only message) " , " e " );
}
}
}
2016-03-02 04:59:00 -08:00
/**
* Check where a function is being called from
* @ param : { boolean } { $file } { false by default , returns file path if true }
* @ param : { boolean } { $pex } { false by default , exists after pr () if true }
* @ since : 2 nd March , 2016 ClipBucket 2.8 . 1
* @ author : Saqib Razzaq
*/
function trace_func ( $file = false , $pex = false ) {
if ( ! $file ) {
$trace = debug_backtrace ();
} else {
$trace = debug_backtrace ();
$trace = $trace [ 1 ][ 'file' ];
}
if ( ! $pex ) {
pr ( $trace , true );
} else {
pex ( $trace , true );
}
}
2016-03-02 05:34:38 -08:00
/**
* Display an image or build image tag
*
* @ param : { string } { $src } { link to image file }
* @ param : { boolean } { $return } { false by default , returns img tag if true }
* @ since : 2 nd March , 2016 ClipBucket 2.8 . 1
* @ author : Saqib Razzaq
*/
function view_image ( $src , $return = false ) {
if ( ! empty ( $src )) {
if ( ! $return ) {
echo '<img src=' . $src . ' >' ;
} else {
return '<img src=' . $src . ' >' ;
}
}
}
2016-03-03 02:01:04 -08:00
/**
* Get part of a string between two characters
*
* @ param : { string } { $str } { string to read }
* @ param : { string } { $from } { character to start cutting }
* @ param : { string } { $to } { character to stop cutting }
* @ return : { string } { requested part of stirng }
* @ since : 3 rd March , 2016 ClipBucket 2.8 . 1
* @ author : Saqib Razzaq
*/
function getStringBetween ( $str , $from , $to ) {
$sub = substr ( $str , strpos ( $str , $from ) + strlen ( $from ), strlen ( $str ));
return substr ( $sub , 0 , strpos ( $sub , $to ));
}
2016-03-03 02:07:27 -08:00
/**
* Convert default youtube api timestamp in usable CB time
*
* @ param : { string } { $time } { youtube time stamp }
* @ return : { integer } { $total } { video duration in seconds }
* @ since : 3 rd March , 2016 ClipBucket 2.8 . 1
* @ author : Saqib Razzaq
*/
function yt_time_convert ( $time ) {
if ( ! empty ( $time )) {
$str = $time ;
$str = str_replace ( " P " , " " , $str );
$from = " T " ;
$to = " H " ;
$hours = getStringBetween ( $str , $from , $to );
$from = " H " ;
$to = " M " ;
$mins = getStringBetween ( $str , $from , $to );
$from = " M " ;
$to = " S " ;
$secs = getStringBetween ( $str , $from , $to );
$hours = $hours * 3600 ;
$mins = $mins * 60 ;
$total = $hours + $mins + $secs ;
if ( is_numeric ( $total )) {
return $total ;
} else {
return false ;
}
} else {
return false ;
}
}
2016-03-02 05:34:38 -08:00
2016-03-02 05:38:53 -08:00
include ( 'functions_db.php' );
include ( 'functions_filter.php' );
include ( 'functions_player.php' );
include ( 'functions_template.php' );
include ( 'functions_helper.php' );
2016-03-02 05:34:38 -08:00
2016-03-02 05:38:53 -08:00
include ( 'functions_video.php' );
include ( 'functions_user.php' );
include ( 'functions_photo.php' );
include ( 'functions_actions.php' );
include ( 'functions_playlist.php' );
2013-10-07 12:17:06 +00:00
?>