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); global $db; if (get_magic_quotes_gpc()) { $id = stripslashes($id); } $id = htmlspecialchars(mysqli_real_escape_string($db->mysqli,$id)); if($replacer) $id = Replacer($id); return $id; } function escape_gpc($in) { if (get_magic_quotes_gpc()) { $in = stripslashes($in); } return $in; } //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[] = '' . mysql_clean($tag) . ''; } $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('//',$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()) { e("Mailer Error: " . $mail->ErrorInfo); 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 '
'.$content.''; } /** * Function used to get file name */ function GetName($file) { if(!is_string($file)) return false; $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 { if(!DEVELOPMENT_MODE) return false; else return true; } } // 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; } /** * 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 'FAILED: $cmd
' . htmlentities( $data ) . ''; } /** * 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"; */ //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... echo ""; echo 'i dont care if you try to play with my code, but what really pisses me off is INSULT'; } } /** * 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 = ''; 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']; } $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; if(!$params['count_only']) { $result = db_select($query); //$result = db_select(tbl("comments".($params['sectionTable']?",".$params['sectionTable']:NULL)),"*",$cond,$limit,$order); } //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 .= '
"; print_r($text); echo ""; } } /** * 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; //dump($userquery->login_check($access,$check_only,$verify_logged_user)); 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) { if(DEVELOPMENT_MODE && DEV_INGNORE_SYNTAX) 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; } /** * 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; 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"); if($return_path) return $return_path; else return "Unable to find ffmpeg path"; break; } } } /** * Function in case htmlspecialchars_decode does not exist */ function unhtmlentities ($string) { $trans_tbl =get_html_translation_table (HTML_ENTITIES ); $trans_tbl =array_flip ($trans_tbl ); return strtr ($string ,$trans_tbl ); } /** * 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 ''.$cat[1].''; 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='#page#') { 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'] ); if(isset($LANG[$var])) { $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; } function smarty_lang($param) { if(getArrayValue($param, 'assign')=='') return lang($param['code'],getArrayValue($param, 'sprintf')); else assign($param['assign'],lang($param['code'],$param['sprintf'])); } function getArrayValue($array = array(), $key = false){ if(!empty($array) && $key){ if(isset($array[$key])){ return $array[$key]; }else{ return false; } } return false; } function getConstant($constantName = false){ if($constantName && defined($constantName)) return constant($constantName); return false; } /** * Function used to assign link */ function cblink($params) { global $ClipBucket; $name = getArrayValue($params, 'name'); $ref = getArrayValue($params, 'ref'); if($name=='category') { return category_link($params['data'],$params['type']); } if($name=='sort') { return sort_link($params['sort'],'sort',$params['type']); } if($name=='time') { return sort_link($params['sort'],'time',$params['type']); } if($name=='tag') { return BASEURL.'/search_result.php?query='.urlencode($params['tag']).'&type='.$params['type']; } if($name=='category_search') { return BASEURL.'/search_result.php?category[]='.$params['category'].'&type='.$params['type']; } if(SEO!='yes') { preg_match('/http:\/\//',$ClipBucket->links[$name][0],$matches); if($matches) $link = $ClipBucket->links[$name][0]; else $link = BASEURL.'/'.$ClipBucket->links[$name][0]; }else { preg_match('/http:\/\//',$ClipBucket->links[$name][1],$matches); if($matches) $link = $ClipBucket->links[$name][1]; else $link = BASEURL.'/'.$ClipBucket->links[$name][1]; } $param_link = ""; if(!empty($params['extra_params'])) { preg_match('/\?/',$link,$matches); if(!empty($matches[0])) { $param_link = '&'.$params['extra_params']; }else{ $param_link = '?'.$params['extra_params']; } } if(isset($params['assign'])) assign($params['assign'],$link.$param_link); else return $link.$param_link; } /** * Function used to show rating * @inputs * class : class used to show rating usually rating_stars * rating : rating of video or something * ratings : number of rating * total : total rating or out of */ function show_rating($params) { $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'); //Checking Percent { if($total<=10) $total = 10; $perc = $rating*100/$total; $disperc = 100 - $perc; if($ratings <= 0 && $disperc == 100) $disperc = 0; } $perc = $perc.'%'; $disperc = $disperc."%"; switch($style) { case "percentage": case "percent": case "perc": default: { $likeClass = "UserLiked"; if(str_replace('%','',$perc) < '50') $likeClass = 'UserDisliked'; $ratingTemplate = '
$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 :)
*
* @param mixed A string, or an array from a file() function.
* @return boolean
*/
function isUTF8($string)
{
if (is_array($string))
{
$enc = implode('', $string);
return @!((ord($enc[0]) != 239) && (ord($enc[1]) != 187) && (ord($enc[2]) != 191));
}
else
{
return (utf8_encode(utf8_decode($string)) == $string);
}
}
/*
extract the file extension from any given path or url.
source: http://www.php.net/manual/en/function.basename.php#89127
*/
function fetch_file_extension($filepath)
{
preg_match('/[^?]*/', $filepath, $matches);
$string = $matches[0];
$pattern = preg_split('/\./', $string, -1, PREG_SPLIT_OFFSET_CAPTURE);
# check if there is any extension
if(count($pattern) == 1)
{
// no file extension found
return;
}
if(count($pattern) > 1)
{
$filenamepart = $pattern[count($pattern)-1][0];
preg_match('/[^?]*/', $filenamepart, $matches);
return $matches[0];
}
}
/*
extract the file filename from any given path or url.
source: http://www.php.net/manual/en/function.basename.php#89127
*/
function fetch_filename($filepath)
{
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;
}
/**
* Function used to generate
* embed code of embedded video
*/
function embeded_code($vdetails)
{
$code = '';
$code .= '';
return $code;
}
/**
* function used to convert input to proper date created formate
*/
function datecreated($in)
{
$date_els = explode('-',$in);
//checking date format
$df = config("date_format");
$df_els = explode('-',$df);
foreach($df_els as $key => $el)
${strtolower($el).'id'} = $key;
$month = $date_els[$mid];
$day = $date_els[$did];
$year = $date_els[$yid];
if($in)
return date("Y-m-d",strtotime($year.'-'.$month.'-'.$day));
else
return '0000-00-00';
}
/**
* After struggling alot with baseurl problem
* i finally able to found its nice and working solkution..
* its not my original but its a genuine working copy
* its still in beta mode
*/
function baseurl()
{
$protocol = is_ssl() ? 'https://' : 'http://';
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']))));
}function base_url(){ return baseurl();}
/**
* SRC (WORD PRESS)
* 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 with trailing slash added.
*/
function trailingslashit($string) {
return untrailingslashit($string) . '/';
}
/**
* SRC (WORD PRESS)
* 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 without the trailing slash.
*/
function untrailingslashit($string) {
return rtrim($string, '/');
}
/**
* Determine if SSL is used.
*
* @since 2.6.0
*
* @return bool True if SSL, false if not used.
*/
function is_ssl() {
if ( isset($_SERVER['HTTPS']) ) {
if ( 'on' == strtolower($_SERVER['HTTPS']) )
return true;
if ( '1' == $_SERVER['HTTPS'] )
return true;
} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
}
return false;
}
/**
* This will update stats like Favorite count, Playlist count
*/
function updateObjectStats($type='favorite',$object='video',$id,$op='+')
{
global $db;
switch($type)
{
case "favorite": case "favourite":
case "favorites": case "favourties":
case "fav":
{
switch($object)
{
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;
/*case "collection":
case "collections": case "cl":
{
$db->update(tbl('photos'),array('total_favorites'),array("|f|total_favorites".$op."1")," photo_id = '".$id."'");
}
break;*/
}
}
break;
case "playlist": case "playList":
case "plist":
{
switch($object)
{
case "video":
case "videos": case "v":
{
$db->update(tbl('video'),array('playlist_count'),array("|f|playlist_count".$op."1")," videoid = '".$id."'");
}
}
}
}
}
/**
* FUnction used to check weather conversion lock exists or not
* if converson log exists it means no further conersion commands will be executed
*
* @return BOOLEAN
*/
function conv_lock_exists()
{
if(file_exists(TEMP_DIR.'/conv_lock.loc'))
return true;
else
return false;
}
/**
* Function used to return a well-formed queryString
* for passing variables to url
* @input variable_name
*/
function queryString($var=false,$remove=false)
{
$queryString = $_SERVER['QUERY_STRING'];
if($var)
$queryString = preg_replace("/&?$var=([\w+\s\b\.?\S]+|)/","",$queryString);
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);
}
if($queryString)
$preUrl = "?$queryString&";
else
$preUrl = "?";
$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/
*/
function generate_options($params)
{
$reverse=false;
if($params['from']>$params['to'])
{
$tmp=$params['from'];
$params['from']=$params['to'];
$params['to']=$tmp;
$reverse=true;
}
$return_string=array();
for($i=$params['from'];$i<=$params['to'];$i++)
{
//$return_string[$i] = ($callback?$callback($i):$i);
$return_string[] = '';
}
if($reverse)
{
$return_string=array_reverse($return_string);
}
return join('',$return_string);
}
function callback_month($month)
{
return date('M',mktime(0,0,0,$month,1));
}
/**
* Function use to download file to server
*
* @param URL
* @param destination
*/
function snatch_it($snatching_file,$destination,$dest_name,$rawdecode=true)
{
global $curl;
if($rawdecode==true)
$snatching_file= rawurldecode($snatching_file);
$destination.'/'.$dest_name;
$fp = fopen ($destination.'/'.$dest_name, 'w+');
$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);
}
/**
* Function check curl
*/
function isCurlInstalled()
{
if (in_array ('curl', get_loaded_extensions())) {
return true;
}
else{
return false;
}
}
/**
* Function for loading
* uploader file url & other configurations
*/
function uploaderDetails()
{
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');
}
/**
* Function isSectionEnabled
* This function used to check weather INPUT section is enabled or not
*/
function isSectionEnabled($input,$restrict=false)
{
global $Cbucket;
$section = $Cbucket->configs[$input.'Section'];
if(!$restrict)
{
if($section =='yes')
return true;
else
return false;
}else
{
if($section =='yes' || THIS_PAGE=='cb_install')
{
return true;
}else
{
template_files('blocked.html');
display_it();
exit();
}
}
}
function array_depth($array) {
$ini_depth = 0;
foreach($array as $arr)
{
if(is_array($arr))
{
$depth = array_depth($arr) + 1;
if($depth > $ini_depth)
$ini_depth = $depth;
}
}
return $ini_depth;
}
/**
* JSON_ENCODE short
*/
if( !function_exists( 'je' ) ) {
function je($in){ return json_encode($in); }
}
/**
* JSON_DECODE short
*/
if ( !function_exists( 'jd' ) ) {
function jd($in,$returnClass=false){ if(!$returnClass) return json_decode($in,true); else return json_decode($in); }
}
/**
* function used to update last commented option
* so comment cache can be refreshed
*/
function update_last_commented($type,$id)
{
global $db;
if($type && $id)
{
switch($type)
{
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'");
break;
}
}
}
/**
* Function used display privacy in text
* according to provided number
* 0 - Public
* 1 - Protected
* 2 - Private
*/
function getGroupPrivacy($privacyID)
{
{
switch($privacyID)
{
case "0": default:
{
return lang("group_is_public");
}
break;
case "1":
{
return lang("group_is_protected");
}
break;
case "2":
{
return lang("group_is_private");
}
break;
}
}
}
/**
* Function used to create user feed
* this function simple takes ID as input
* and do the rest seemlessli ;)
*/
function addFeed($array)
{
global $cbfeeds,$cbphoto,$userquery;
$action = $array['action'];
if($array['uid'])
$userid = $array['uid'];
else
$userid = userid();
switch($action)
{
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);
}
}
}
/**
* function used to get plugin directory name
*/
function this_plugin($pluginFile=NULL)
{
if(!$pluginFile)
global $pluginFile;
return basename(dirname($pluginFile));
}
/**
* function used to get user agent details
* Thanks to ruudrp at live dot nl 28-Nov-2010 11:31 PHP.NET
*/
function get_browser_details($in=NULL,$assign=false)
{
//Checking if browser is firefox
if(!$in)
$in = $_SERVER['HTTP_USER_AGENT'];
$u_agent = $in;
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
elseif (preg_match('/iPhone/i', $u_agent)) {
$platform = 'iphone';
}
elseif (preg_match('/iPad/i', $u_agent)) {
$platform = 'ipad';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/windows|win32/i', $u_agent)) {
$platform = 'windows';
}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$bname = 'Mozilla Firefox';
$ub = "Firefox";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$bname = 'Google Chrome';
$ub = "Chrome";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$bname = 'Opera';
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$bname = 'Netscape';
$ub = "Netscape";
}
elseif(preg_match('/Googlebot/i',$u_agent))
{
$bname = 'Googlebot';
$ub = "bot";
}elseif(preg_match('/msnbot/i',$u_agent))
{
$bname = 'MSNBot';
$ub = "bot";
}elseif(preg_match('/Yahoo\! Slurp/i',$u_agent))
{
$bname = 'Yahoo Slurp';
$ub = "bot";
}
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?"; var_dump($data); echo ""; } function logData($data){ $logFilePath = "/home/sajjad/Desktop/ffmpegLog.txt"; if(is_array($data)) $data = json_encode($data); $text = file_get_contents($logFilePath); $text .= " \n {$data}"; file_put_contents($logFilePath, $text); } /** * displays a runtime error * * @param Object $e */ function show_cb_error($e) { echo $e->getMessage(); echo '