Files
Testing/include/functions_general.php

4007 lines
118 KiB
PHP
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
<?php
/* $Id: functions_general.php 278 2009-12-14 20:43:46Z john $ */
// THIS FILE CONTAINS GENERAL FUNCTIONS
// FUNCTIONS IN THIS FILE:
// cheader()
// make_page()
// bumplog()
// randomcode()
// is_email_address()
// str_ireplace()
// htmlspecialchars_decode()
// str_split()
// security()
// select_subnet()
// link_field_values()
// censor()
// dirsize()
// user_privacy_levels()
// search_profile()
// getmicrotime()
// cleanHTML()
// chopHTML()
// choptext()
// chunkHTML_split()
// strlen_utf8()
// mb_unserialize()
// online_users()
// site_statistics()
// recent_signups()
// recent_logins()
// popular_users()
// site_news()
// friends_birthdays()
// get_simple_cookie_domain()
// check_ip_in_banned_list()
if(!defined("IMAGECDN")){define(IMAGECDN, "https://cdn.bateworld.com/");}
if(!defined("IMAGECDN1")){define(IMAGECDN1, "https://cloudcdn.bateworld.com/");}
function isYesterday($dateString) {
$inputDate = new DateTime($dateString);
$yesterday = new DateTime();
$yesterday->sub(new DateInterval('P1D'));
$formattedInputDate = $inputDate->format('Y-m-d');
$formattedYesterday = $yesterday->format('Y-m-d');
return $formattedInputDate === $formattedYesterday;
}
function wrapup($type, $owner_id=null, $user_id=null) {
global $user, $database, $owner;
// send_admin("sean@bateworld.com", "ok", $type);
if($type=="profile_comments"){
$field="profile_comments";
}
elseif($type=="phototagged"){
$field="photo_tagged";
}
elseif($type=="groupphototagged"){
$field="groupphoto_tagged";
}
elseif($type=="eventphototagged"){
$field="eventphoto_tagged";
}
elseif($type=="clubphototagged"){
$field="clubphoto_tagged";
}
elseif($type=="videotagged"){
$field="video_tagged";
}
elseif($type=="groupvideotagged"){
$field="groupvideo_tagged";
}
elseif($type=="eventvideotagged"){
$field="eventvideo_tagged";
}
elseif($type=="clubvideotagged"){
$field="clubvideo_tagged";
}
elseif($type=="bateoffcomments"){
$field="bateoff_comments";
}
elseif($type=="bate_videocomments"){
$field="batetube_comments";
}
elseif($type=="poll_created"){
$field="polls_created";
}
elseif($type=="upload_video"){
$field="videos_uploaded";
}
elseif($type=="eventupload_photo"){
$field="eventphoto_uploaded";
}
elseif($type=="groupupload_photo"){
$field="groupphoto_uploaded";
}
elseif($type=="clubupload_photo"){
$field="clubphoto_uploaded";
}
elseif($type=="upload_photo"){
$field="photo_uploaded";
}
elseif($type=="club_video"){
$field="clubvideo_upload";
}
elseif($type=="group_video"){
$field="groupvideo_upload";
}
elseif($type=="video_watched"){
$field="video_watched";
}
elseif($type=="eventvideo_watched"){
$field="eventvideo_watched";
}
elseif($type=="photo_viewed"){
$field="photo_viewed";
}
elseif($type=="eventphoto_viewed"){
$field="eventphoto_viewed";
}
elseif($type=="clubphoto_viewed"){
$field="clubphoto_viewed";
}
elseif($type=="media_liked"){
$field="media_liked";
}
elseif($type=="groupmedia_liked"){
$field="groupmedia_liked";
}
elseif($type=="clubmedia_liked"){
$field="clubmedia_liked";
}
elseif($type=="eventmedia_liked"){
$field="eventmedia_liked";
}
elseif($type=="videos_liked"){
$field="video_liked";
}
elseif($type=="groupvideos_liked"){
$field="groupvideo_liked";
}
elseif($type=="clubvideos_liked"){
$field="clubvideo_liked";
}
elseif($type=="eventvideos_liked"){
$field="eventvideo_liked";
}
elseif($type=="groupphoto_viewed"){
$field="groupphoto_viewed";
}
elseif($type=="clubvideo_watched"){
$field="clubvideo_watched";
}
elseif($type=="groupvideo_watched"){
$field="groupvideo_watched";
}
elseif($type=="event_video"){
$field="eventvideo_upload";
}
elseif($type=="create_event"){
$field="event_created";
}
elseif($type=="create_group"){
$field="group_created";
}
elseif($type=="create_club"){
$field="club_created";
}
elseif($type=="event_join"){
$field="event_rsvp";
}
elseif($type=="group_joined"){
$field="group_joined";
}
elseif($type=="club_joined"){
$field="club_joined";
}
elseif($type=="batortrainingcomments"){
$field="batortraining_comments";
}
elseif($type=="mms_comment"){
$field="meditation_comments";
}
elseif($type=="note"){
$field="notes_written";
}
elseif($type=="media_comments"){
$field="picture_comments";
}
elseif($type=="video_votes"){
$field=$type;
}
elseif($type=="video_comments"){
$field="video_comments";
}
elseif($type=="groupmedia_comments"){
$field="grouppicture_comments";
}
elseif($type=="clubmedia_comments"){
$field="clubphoto_comments";
}
elseif($type=="club_comments"){$field="club_comments";}
elseif($type=="eventmedia_comments"){$field="eventphoto_comments";}
elseif($type=="group_comments"){$field="group_comments";}
elseif($type=="poll_comments"){$field="poll_comments";}
elseif($type=="poll_vote"){$field="poll_votes";}
elseif($type=="blog_comments"){$field="blog_comments";}
elseif($type=="event_comments"){$field="event_comments";}
else{return;}
if($user->user_info["user_id"]!=null && $user->user_info["user_id"]>0&&$user_id==null){$user_id=$user->user_info["user_id"];}
if($owner->user_info["user_id"]!=null && $owner->user_info["user_id"]>0&&$owner_id==null){$owner_id=$owner->user_info["user_id"];}
$query=$database->database_query("SELECT user_id FROM yearlywrapped WHERE user_id='".$user_id."' AND year='".date("Y")."'");
if($database->database_num_rows($query)==0)
{
$database->database_query("INSERT INTO yearlywrapped SET ".$field."=".$field."+1, user_id='".$user_id."', year='".date("Y")."'");
}
else
{
$database->database_query("UPDATE yearlywrapped SET ".$field."=".$field."+1 WHERE user_id='".$user_id."' AND year='".date("Y")."'");
}
//send_admin("sean@bateworld.com", "aaa", "INSERT INTO yearlywrapped_received SET ".$field."=".$field."+1, user_id='".$user->user_info["user_id"]."', year='".date("Y")."'");
// THIS MAKES THE CODE GIVE THE SENDER THE RECIPIENT
if($owner_id!=null){
$query=$database->database_query("SELECT user_id FROM yearlywrapped_received WHERE user_id='".$owner_id."' AND year='".date("Y")."'");
if($database->database_num_rows($query)==0)
{
$database->database_query("INSERT INTO yearlywrapped_received SET ".$field."=".$field."+1, user_id='".$owner_id."', year='".date("Y")."'");
}
else
{
$database->database_query("UPDATE yearlywrapped_received SET ".$field."=".$field."+1 WHERE user_id='".$owner_id."' AND year='".date("Y")."'");
}
}
}
function detectIpVersion(string $ip): string {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return '1';
}
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return '2';
}
return '0';
}
function addspampoint($pointid, $user)
{
global $database;
$query=$database->database_query("SELECT * FROM bateworldcom_wall.user_points WHERE user_id='".$database->database_real_escape_string($user)."' AND point_id='".$database->database_real_escape_string($pointid)."'");
if($database->database_num_rows($query)==0){
$query=$database->database_query("SELECT * FROM bateworldcom_wall.potential_points WHERE id='".$database->database_real_escape_string($pointid)."'");
$row=$database->database_fetch_array($query);
$database->database_query("INSERT INTO bateworldcom_wall.user_points SET user_id='".$database->database_real_escape_string($user)."', point_id='".$row["id"]."', points='".$row["points"]."', `date`='".time()."'");
}
}
// THIS FUNCTION CHANGES LOCATION HEADER TO REDIRECT FOR IIS PRIOR TO SETTING COOKIES
// INPUT: $url REPRESENTING THE URL TO REDIRECT TO
// OUTPUT:
function cheader($url)
{
if( strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'microsoft') !== false )
{
header("Refresh: 0; URL=".$url);
}
else
{
header("Location: $url");
}
exit();
}
// END cheader() FUNCTION
function approvemedia($table, $object, $action)
{
global $database, $actions, $url, $misc;
if($action=="newmedia"){
$query=$database->database_query("SELECT * FROM se_albums, se_media WHERE media_album_id=album_id AND media_id='".$database->database_real_escape_string($object)."'");
$album_info=$database->database_fetch_array($query);
$user=new SEUser(Array($album_info["album_user_id"]));
//send_admin("sean@bateworld.com", "TEST1", var_export($user, true));
$database->database_query("UPDATE se_media SET approved=1 WHERE media_id='".$database->database_real_escape_string($object)."'");
if($album_info["album_privacy"]!=35){
$media_path = str_replace('./', '', $url->url_userdir($user->user_info['user_id']).$album_info["media_id"].".".$album_info['media_ext']);
$media_link = str_replace($url->url_base, '', $url->url_create('album_file', $user->user_info['user_username'], $album_info["album_id"], $album_info['media_id']));
$media_width = $misc->photo_size($media_path, "100", "100", "w");
$media_height = $misc->photo_size($media_path, "100", "100", "h");
$action_media[] = Array(
'media_link' => $media_link,
'media_path' => $media_path,
'media_width' => $media_width,
'media_height' => $media_height
);
$actions->actions_add($user, "newmedia", Array($user->user_info['user_username'], $user->user_displayname, $album_info["album_id"], $album_info["album_title"]), $action_media, 60, FALSE, "user", $album_info['album_id'], $album_info['album_privacy']);
}
}
elseif($action=="newvideo"){
$query=$database->database_query("SELECT * FROM se_videos WHERE video_id='".$database->database_real_escape_string($object)."'");
$row=$database->database_fetch_array($query);
$user=new SEUser(Array($row["video_user_id"]));
//send_admin("sean@bateworld.com", "TEST1", var_export($user, true));
$database->database_query("UPDATE se_videos SET approved=1 WHERE video_id='".$database->database_real_escape_string($object)."'");
$action_media = array();
$directory1=str_replace("./", "/", video_dir($row["video_user_id"], true));
$action_media = array();
$thumb_path = str_replace('./', '/', $directory1.$row["video_id"].".jpg");
$media_link = str_replace($url->url_base, '', $url->url_create('video', $user->user_info['user_username'], $row['video_id']));
//if( file_exists($thumb_path) )
{
//$media_width = $misc->photo_size($thumb_path, "100", "100", "w");
//$media_height = $misc->photo_size($thumb_path, "100", "100", "h");
$action_media[] = array(
'media_link' => $media_link,
'media_path' => $thumb_path,
'media_width' => 100,
'media_height' => 100
);
}
$actions->actions_add($user, "newvideo", array($user->user_info['user_username'], $user->user_displayname, $row["video_id"], $row["video_title"]), $action_media, 0, FALSE, "user", $row["video_id"], $user->user_info['user_privacy']);
}
elseif($action=="neweventmedia"){
$query=$database->database_query("SELECT * FROM se_events, se_eventalbums, se_eventmedia WHERE eventalbum_event_id=event_id AND eventmedia_eventalbum_id=eventalbum_id AND eventmedia_id='".$database->database_real_escape_string($object)."'");
$album_info=$database->database_fetch_array($query);
$database->database_query("UPDATE se_eventmedia SET approved=1 WHERE eventmedia_id='".$database->database_real_escape_string($object)."'");
$user=new SEUser(Array($album_info["eventmedia_user_id"]));
$event = new se_event($user->user_info['user_id'], $album_info["event_id"]);
$action_media = array();
$media_path = str_replace('./', '', $event->event_dir($event->event_info['event_id']).$album_info['eventmedia_id'].".".$album_info['eventmedia_ext']);
$media_link = str_replace($url->url_base, '', $url->url_create('event_media', NULL, $event->event_info['event_id'], $album_info['eventmedia_id']));
$media_width = $misc->photo_size($media_path, "100", "100", "w");
$media_height = $misc->photo_size($media_path, "100", "100", "h");
$action_media[] = Array(
'media_link' => $media_link,
'media_path' => $media_path,
'media_width' => $media_width,
'media_height' => $media_height
);
$actions->actions_add($user, "neweventmedia", Array( $user->user_info['user_username'], $user->user_displayname, $event->event_info['event_id'], $event->event_info['event_title'] ), $action_media, 60, FALSE, "event", $event->event_info['event_id'], $event->event_info['event_privacy']);
}
elseif($action=="newgroupmedia"){
$query=$database->database_query("SELECT * FROM se_groups, se_groupalbums, se_groupmedia WHERE groupalbum_group_id=group_id AND groupmedia_groupalbum_id=groupalbum_id AND groupmedia_id='".$database->database_real_escape_string($object)."'");
$album_info=$database->database_fetch_array($query);
$database->database_query("UPDATE se_groupmedia SET approved=1 WHERE groupmedia_id='".$database->database_real_escape_string($object)."'");
$user=new SEUser(Array($album_info["groupmedia_user_id"]));
$group = new se_group($user->user_info['user_id'], $album_info["group_id"]);
$action_media = array();
$media_path = str_replace('./', '', $group->group_dir($group->group_info['group_id']).$album_info['groupmedia_id'].".".$album_info['groupmedia_ext']);
$media_link = str_replace($url->url_base, '', $url->url_create('group_media', NULL, $group->group_info['group_id'], $album_info['groupmedia_id']));
$media_width = $misc->photo_size($media_path, "100", "100", "w");
$media_height = $misc->photo_size($media_path, "100", "100", "h");
$action_media[] = Array(
'media_link' => $media_link,
'media_path' => $media_path,
'media_width' => $media_width,
'media_height' => $media_height
);
if($group->group_info['shadowbanned']==0){
//send_admin("sean@bateworld.com", "PP", var_export($user, true));
$actions->actions_add($user, "newgroupmedia", Array($user->user_info['user_username'], $user->user_displayname, $group->group_info['group_id'], $group->group_info['group_title']), $action_media, 60, FALSE, "group", $group->group_info['group_id'], $group->group_info['group_privacy']);
}
}
}
// THIS FUNCTION RETURNS APPROPRIATE PAGE VARIABLES
// INPUT: $total_items REPRESENTING THE TOTAL NUMBER OF ITEMS
// $items_per_page REPRESENTING THE NUMBER OF ITEMS PER PAGE
// $p REPRESENTING THE CURRENT PAGE
// OUTPUT: AN ARRAY CONTAINING THE STARTING ITEM, THE PAGE, AND THE MAX PAGE
function make_page($total_items, $items_per_page, $p)
{
if( !$items_per_page ) $items_per_page = 1;
$maxpage = ceil($total_items / $items_per_page);
if( $maxpage <= 0 ) $maxpage = 1;
$p = ( ($p > $maxpage) ? $maxpage : ( ($p < 1) ? 1 : $p ) );
$start = ($p - 1) * $items_per_page;
return array($start, $p, $maxpage);
}
// END make_page() FUNCTION
// THIS FUNCTION BUMPS LOGIN LOG
// INPUT:
// OUTPUT:
function bumplog()
{
global $database;
$log_entries = $database->database_num_rows($database->database_query("SELECT login_id FROM se_logins"));
if( $log_entries > 1000 )
{
$oldest_log = $database->database_fetch_assoc($database->database_query("SELECT login_id FROM se_logins ORDER BY login_id ASC LIMIT 0,1"));
$database->database_query("DELETE FROM se_logins WHERE login_id='{$oldest_log['login_id']}'");
bumplog();
}
}
// END bumplog() FUNCTION
// THIS FUNCTION RETURNS A RANDOM CODE OF DEFAULT LENGTH 8
// INPUT: $len (OPTIONAL) REPRESENTING THE LENGTH OF THE RANDOM STRING
// OUTPUT: A RANDOM ALPHANUMERIC STRING
function randomcode($len=8)
{
$code = NULL;
for( $i=0; $i<$len; $i++ )
{
$char = chr(rand(48,122));
while( !preg_match("~[a-zA-Z0-9]~", $char) )
{
if( $char == $lchar ) continue;
$char = chr(rand(48,90));
}
$pass .= $char;
$lchar = $char;
}
return $pass;
}
// END randomcode() FUNCTION
// THIS FUNCTION CHECKS IF PROVIDED STRING IS AN EMAIL ADDRESS
// INPUT: $email REPRESENTING THE EMAIL ADDRESS TO CHECK
// OUTPUT: TRUE/FALSE DEPENDING ON WHETHER THE EMAIL ADDRESS IS VALIDLY CONSTRUCTED
function is_email_address($email)
{
$regexp = "/^[a-z0-9]+([a-z0-9_\+\\.-]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
return (bool) preg_match($regexp, $email);
}
// END is_email_address() FUNCTION
// THIS FUNCTION SETS STR_IREPLACE IF FUNCTION DOESN'T EXIST
// INPUT: $search REPRESENTING THE STRING TO SEARCH FOR
// $replace REPRESENTING THE STRING TO REPLACE IT WITH
// $subject REPRESENTING THE STRING WITHIN WHICH TO SEARCH
// OUTPUT: RETURNS A STRING IN WHICH ONE STRING HAS BEEN CASE-INSENSITIVELY REPLACED BY ANOTHER
if( !function_exists('str_ireplace') )
{
function str_ireplace($search, $replace, $subject)
{
$search = preg_quote($search, "/");
return preg_replace_callback("/".$search."/i", $replace, $subject);
}
}
// END str_ireplace() FUNCTION
// 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 = ENT_COMPAT)
{
if( $ent_quotes === ENT_QUOTES ) $text = str_replace("&quot;", "\"", $text);
if( $ent_quotes !== ENT_NOQUOTES ) $text = str_replace("&#039;", "'", $text);
$text = str_replace("&lt;", "<", $text);
$text = str_replace("&gt;", ">", $text);
$text = str_replace("&amp;", "&", $text);
return $text;
}
}
// END htmlspecialchars() FUNCTION
// THIS FUNCTION SETS STR_SPLIT IF FUNCTION DOESN'T EXIST
// INPUT: $string REPRESENTING THE STRING TO SPLIT
// $split_length (OPTIONAL) REPRESENTING WHERE TO CUT THE STRING
// OUTPUT: AN ARRAY OF STRINGS
if( !function_exists('str_split') )
{
function str_split($string, $split_length = 1)
{
$count = strlen($string);
if($split_length < 1)
{
return false;
}
elseif($split_length > $count)
{
return array($string);
}
else
{
$num = (int)ceil($count/$split_length);
$ret = array();
for($i=0;$i<$num;$i++)
{
$ret[] = substr($string,$i*$split_length,$split_length);
}
return $ret;
}
}
}
// END str_split() FUNCTION
// THIS FUNCTION STRIPSLASHES AND ENCODES HTML ENTITIES FOR SECURITY PURPOSES
// INPUT: $value REPRESENTING A STRING OR ARRAY TO CLEAN
// OUTPUT: THE ARRAY OR STRING WITH HTML CHARACTERS ENCODED
function security($value)
{
if( is_array($value) )
{
$value = array_map('security', $value);
}
else
{
/*if( !get_magic_quotes_gpc() )
{
$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
else
{
$value = htmlspecialchars(stripslashes($value), ENT_QUOTES, 'UTF-8');
}
*/
$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
$value = str_replace("\\", "\\\\", $value);
}
return $value;
}
// END security() FUNCTION
// THIS FUNCTION LINKS FIELD VALUES
// INPUT: $field_value REPRESENTING THE VALUE TO LINK
// $key (NEEDED TO USE ARRAY WALK)
// $additional REPRESENTING THE ADDITIONAL PARAMETERS
// OUTPUT:
function link_field_values(&$field_value, $key, $additional)
{
global $url;
$field_id = $additional[0];
$field_browse = $additional[1];
$field_link = $additional[2];
$field_display = $additional[3];
$field_value = trim($field_value);
if( !trim($field_link) && $field_display == 2 )
{
if( !$field_browse ) $field_browse = urlencode(htmlspecialchars_decode($field_value, ENT_QUOTES));
$browse_url = $url->url_base."search_advanced.php?task=browse&field_id={$field_id}&field_value={$field_browse}";
if( $field_value ) $field_value = "<a href='{$browse_url}'>{$field_value}</a>";
}
elseif( trim($field_link) && $field_value )
{
if( preg_match('/^www([.]?[a-zA-Z0-9_\/-])*/', $field_value) ) $field_link = "http://".$field_value;
$link_to = str_replace("[field_value]", $field_value, $field_link);
$field_value = "<a href='{$link_to}' target='_blank'>{$field_value}</a>";
}
}
// END link_field_values() FUNCTION
// THIS FUNCTION CENSORS WORDS FROM A STRING
// INPUT: $field_value REPRESENTING THE VALUE TO CENSOR
// OUTPUT: THE VALUE WITH BANNED WORDS CENSORED
function censor($field_value)
{
global $setting, $user;
//if($setting["drawbridge"]==1){
if($user->user_info["user_signupdate"]>=(time()-(60*60*24))){
if(forbidden($field_value))
{
return NULL;
}}
//}
$field_value1=$field_value;
$censored_array = explode(",", trim($setting['setting_banned_words']));
foreach($censored_array as $key => $value)
{
$trimvalue = trim($value);
$escaped_trimvalue = preg_quote($trimvalue, '#');
$pattern = "#".str_replace('*', ".*", $escaped_trimvalue)."#i";
if (preg_match($pattern, $field_value)) {
//if (preg_match("/".str_replace('*', ".*", $trimvalue)."/i", $field_value)){
$replace_value = str_pad("", strlen(trim($value)), "*");
//$field_value = preg_replace_callback("/\b".$trimvalue."\b/i", $replace_value, $field_value);
$field_value = str_ireplace(trim(str_replace("*", "", $value)), $replace_value, $field_value);
}
$escaped_trimvalue = preg_quote($trimvalue, '/');
if (preg_match("/\b" . $escaped_trimvalue . "\b/i", $field_value)) {
//if (preg_match("/\b".$trimvalue."\b/i", $field_value)){
$replace_value = str_pad("", strlen(trim($value)), "*");
//$field_value = preg_replace_callback("/\b".$trimvalue."\b/i", $replace_value, $field_value);
$field_value = str_ireplace(trim($value), $replace_value, $field_value);
}
}
return $field_value;
}
function forbidden($field_value)
{
global $setting, $user, $database;
$field_value1=$field_value;
if($setting['forbidden']!=""){
$censored_array = explode(",", trim($setting['forbidden']));
foreach($censored_array as $key => $value)
{
$trimvalue = trim($value);
if($trimvalue!=""){
$escaped_trimvalue = preg_quote($trimvalue, '#'); // Escape any regex special characters
$pattern = "#\b" . $escaped_trimvalue . "\b#i"; // Use '#' as the delimiter
if (preg_match($pattern, $field_value)) {
//if (preg_match("/\b".$trimvalue."\b/i", $field_value)){
mail("leprakhauns@gmail.com", "Forbidden word triggered", $user->user_info["user_id"]." \n ".$field_value);
$database->database_query("UPDATE se_users SET user_enabled='-1', user_pdp_evc = '0' WHERE user_id='".$database->database_real_escape_string($user->user_info["user_id"])."'");
$query = $database->database_query("SELECT * FROM ips WHERE user_id='".$user->user_info["user_id"]."'");
while($row = $database->database_fetch_array($query))
{
$database->database_query("Insert into bateworldcom_zips.abuseips SET ip = '".$row["ip"]."', date='".time()."'");
}
$database->database_query("Insert into bateworldcom_zips.abuseips SET ip = '".$user->user_info["user_ip_signup"]."', date='".time()."'");
$database->database_query("Insert into bateworldcom_zips.abuseips SET ip = '".$user->user_info["user_ip_lastactive"]."', date='".time()."'");
$xml='<?xml version="1.0" encoding="UTF-8" ?>
<xmlrequest>
<username>bateworld@gmail.com</username>
<usertoken>405a1b48556d1ffd09416751a6c915a61a2beb2d</usertoken>
<requesttype>subscribers</requesttype>
<requestmethod>deleteSubscriber</requestmethod>
<details>
<listId>33624</listId>
<subscriberId>'.$user_email.'</subscriberId>
</details>
</xmlrequest>';
return true;
}
if (strpos( $field_value, $trimvalue)){
//if(SE_DEBUG1){echo "AAA";}
mail("leprakhauns@gmail.com", "Forbidden word triggered", $user->user_info["user_id"]." \n ".$field_value);
$database->database_query("UPDATE se_users SET user_enabled='-1', user_pdp_evc = '0' WHERE user_id='".$database->database_real_escape_string($user->user_info["user_id"])."'");
$query = $database->database_query("SELECT * FROM ips WHERE user_id='".$user->user_info["user_id"]."'");
while($row = $database->database_fetch_array($query))
{
$database->database_query("Insert into bateworldcom_zips.abuseips SET ip = '".$row["ip"]."', date='".time()."'");
}
$database->database_query("Insert into bateworldcom_zips.abuseips SET ip = '".$user->user_info["user_ip_signup"]."', date='".time()."'");
$database->database_query("Insert into bateworldcom_zips.abuseips SET ip = '".$user->user_info["user_ip_lastactive"]."', date='".time()."'");
$xml='<?xml version="1.0" encoding="UTF-8" ?>
<xmlrequest>
<username>bateworld@gmail.com</username>
<usertoken>405a1b48556d1ffd09416751a6c915a61a2beb2d</usertoken>
<requesttype>subscribers</requesttype>
<requestmethod>deleteSubscriber</requestmethod>
<details>
<listId>33624</listId>
<subscriberId>'.$user_email.'</subscriberId>
</details>
</xmlrequest>';
return true;
}
}
}
}
return false;
}
// THIS FUNCTION RETURNS THE SIZE OF A DIRECTORY
// INPUT: $dirname REPRESENTING THE PATH TO A DIRECTORY
// OUTPUT: THE SIZE OF ALL THE FILES WITHIN THE DIRECTORY
function dirsize($dirname)
{
if( !is_dir($dirname) || !is_readable($dirname) )
return false;
$dirname_stack[] = $dirname;
$size = 0;
do {
$dirname = array_shift($dirname_stack);
$handle = opendir($dirname);
while(false !== ($file = readdir($handle)))
{
if($file != '.' && $file != '..' && is_readable($dirname . DIRECTORY_SEPARATOR . $file))
{
if(is_dir($dirname . DIRECTORY_SEPARATOR . $file))
{
$dirname_stack[] = $dirname . DIRECTORY_SEPARATOR . $file;
}
$size += filesize($dirname . DIRECTORY_SEPARATOR . $file);
}
}
closedir($handle);
} while( count($dirname_stack) > 0 );
return $size;
}
// END dirsize() FUNCTION
// THIS FUNCTION RETURNS TEXT CORRESPONDING TO THE GIVEN USER PRIVACY LEVEL
// INPUT: $privacy_level REPRESENTING THE LEVEL OF USER PRIVACY
// OUTPUT: A STRING EXPLAINING THE GIVEN PRIVACY SETTING
function user_privacy_levels($privacy_level)
{
global $functions_general;
switch($privacy_level)
{
case 63: $privacy = 323; break;
case 31: $privacy = 324; break;
case 15: $privacy = 325; break;
case 7: $privacy = 326; break;
case 3: $privacy = 327; break;
case 1: $privacy = 328; break;
case 0: $privacy = 329; break;
default: $privacy = ""; break;
}
return $privacy;
}
// END user_privacy_levels() FUNCTION
function tag_profile()
{
global $database, $url, $results_per_page, $p, $search_text, $t, $search_objects, $results, $total_results, $user, $id;
$blocked=explode(",", $user->user_info["user_blocklist"]);
foreach($blocked as $block){
if($block!=""){$blockstr=$block.",";}
}
$blockstr.="0";
$blocked="";
$query=$database->database_query("SELECT user_id FROM se_users WHERE user_enabled=1 AND MATCH(user_blocklist) AGAINST('".$user->user_info["user_id"]."' IN NATURAL LANGUAGE MODE)");
while($row2=$database->database_fetch_array($query))
{
if($blocked==""){$blocked=$database->database_real_escape_string($row2["user_id"]);}
else{
$blocked.=",".$database->database_real_escape_string($row2["user_id"]);
}
}
if($blocked==""){$blocked="0";}
// GET FIELDS
$fields = $database->database_query("
SELECT
profilefield_id AS field_id,
profilefield_type AS field_type,
profilefield_options AS field_options
FROM
se_profilefields
WHERE
profilefield_type<>'5' &&
(profilefield_dependency<>'0' OR (profilefield_dependency='0' AND profilefield_display<>'0'))
");
//$search_text = preg_replace('/[^a-zA-Z0-9 ]/', '', $search_text);
$searchtext='*'.$database->database_real_escape_string($search_text).'*';
$profile_query = "(MATCH(se_users.user_username) AGAINST('".$searchtext."' IN BOOLEAN MODE) OR MATCH(se_profilevalues.profilevalue_13, se_profilevalues.profilevalue_21, se_profilevalues.profilevalue_27) AGAINST('".$searchtext."' IN BOOLEAN MODE)) ";
// $profile_query = "(MATCH(se_users.user_username) AGAINST('".$searchtext."' IN BOOLEAN MODE) OR se_profilevalues.profilevalue_21 LIKE '%".$database->database_real_escape_string($search_text)."%') ";
$profile_query .=" AND se_users.user_id NOT IN(".$blockstr.") ";
$profile_query.=" AND se_users.user_id NOT IN (".$blocked.")";
//echo $profile_query;
/*
// LOOP OVER FIELDS
while($field_info = $database->database_fetch_assoc($fields))
{
// TEXT FIELD OR TEXTAREA
if( $field_info['field_type'] == 1 || $field_info['field_type'] == 2 )
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` LIKE '{$search_text}%'";
}
/* // RADIO OR SELECT BOX
elseif($field_info[field_type] == 3 || $field_info[field_type] == 4)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN {$options[$i]['value']}";
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` IN (SELECT CASE ".implode(" ", $cases)." END AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '{$search_text}%')";
}
}
// CHECKBOX
elseif($field_info[field_type] == 6)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN ".(pow(2, $i));
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
if( $profile_query ) {$profile_query .= " OR ";}
if($field_info['field_id']==5||$field_info['field_id']==9||$field_info['field_id']==10||$field_info['field_id']==15||$field_info['field_id']==16||$field_info['field_id']==17||$field_info['field_id']==19||$field_info['field_id']==20||$field_info['field_id']==28){$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value = '{$search_text}%')";}
else{
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '{$search_text}%')";}
}
}*/
//}
// CONSTRUCT QUERY
$profile_query = "
SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
se_users.user_photo, se_users.verified, se_users.online, se_users.user_level_id
FROM
se_users, bateworldcom_zips.profileinteresttagged
WHERE
se_users.user_id=bateworldcom_zips.profileinteresttagged.user_id AND bateworldcom_zips.profileinteresttagged.interest_id='".$database->database_real_escape_string($id)."'
";
//profileinteresttagged
// GET TOTAL PROFILES
$total_profiles = $database->database_num_rows($database->database_query($profile_query.""));
// IF NOT TOTAL ONLY
if($t == "" || $t == "profile")
{
// MAKE PROFILE PAGES
$start = ($p - 1) * $results_per_page;
$limit = $results_per_page+1;
// SEARCH PROFILES
$online_users_array = online_users();
$profiles = $database->database_query($profile_query." ORDER BY se_users.user_id DESC LIMIT $start, $limit");
while($profile_info = $database->database_fetch_assoc($profiles))
{
$profile = new se_user();
$profile->user_info['user_id'] = $profile_info['user_id'];
$profile->user_info['user_username'] = $profile_info['user_username'];
$profile->user_info['user_fname'] = $profile_info['user_fname'];
$profile->user_info['user_lname'] = $profile_info['user_lname'];
$profile->user_info['user_photo'] = $profile_info['user_photo'];
$profile->user_displayname();
$profile_info['user_photo']=$profile->user_photo('./images/nophoto.png', TRUE);
//if(SE_DEBUG1){echo $profile->user_photo('./images/nophoto.png', TRUE)."<br>";}
// DETERMINE IF USER IS ONLINE
$is_online = (bool) in_array($profile_info['user_username'], $online_users_array[0]);
$results[] = Array(
'result_url' => $url->url_create('profile', $profile_info['user_username']),
'result_icon' => $profile->user_photo('./images/nophoto.png', TRUE),
'result_name' => 509,
'result_name_1' => $profile->user_displayname,
'result_desc' => '',
'result_online' => $is_online,
'profile' => $profile_info
);
}
// SET TOTAL RESULTS
$total_results = $total_profiles;
}
// SET ARRAY VALUES
SE_Language::_preload_multi(509, 1072);
//if($total_profiles > 200) { $total_profiles = "200+"; }
$search_objects[] = Array(
'search_type' => '0',
'search_lang' => 1072,
'search_total' => $total_profiles
);
//if($_SERVER['REMOTE_ADDR']=="24.47.141.40"){echo $profile_query;}
}
// THIS FUNCTION SEARCHES THROUGH PROFILE INFORMATION
// INPUT:
// OUTPUT:
function search_profile_new()
{
global $database, $url, $results_per_page, $p, $search_text, $t, $search_objects, $results, $total_results, $user;
$blocked=explode(",", $user->user_info["user_blocklist"]);
foreach($blocked as $block){
if($block!=""){$blockstr=$block.",";}
}
$blockstr.="0";
$blocked="";
$query=$database->database_query("SELECT user_id FROM se_users WHERE user_enabled=1 AND MATCH(user_blocklist) AGAINST('".$user->user_info["user_id"]."' IN NATURAL LANGUAGE MODE)");
while($row2=$database->database_fetch_array($query))
{
if($blocked==""){$blocked=$database->database_real_escape_string($row2["user_id"]);}
else{
$blocked.=",".$database->database_real_escape_string($row2["user_id"]);
}
}
if($blocked==""){$blocked="0";}
// GET FIELDS
$fields = $database->database_query("
SELECT
profilefield_id AS field_id,
profilefield_type AS field_type,
profilefield_options AS field_options
FROM
se_profilefields
WHERE
profilefield_type<>'5' &&
(profilefield_dependency<>'0' OR (profilefield_dependency='0' AND profilefield_display<>'0'))
");
//$search_text = preg_replace('/[^a-zA-Z0-9 ]/', '', $search_text);
$searchtext=''.$database->database_real_escape_string($search_text).'';
$profile_query = "(MATCH(se_users.user_username) AGAINST('".$searchtext."' IN BOOLEAN MODE) OR MATCH(se_profilevalues.profilevalue_13, se_profilevalues.profilevalue_21, se_profilevalues.profilevalue_27) AGAINST('".$searchtext."' IN BOOLEAN MODE)) ";
// $profile_query = "(MATCH(se_users.user_username) AGAINST('".$searchtext."' IN BOOLEAN MODE) OR se_profilevalues.profilevalue_21 LIKE '%".$database->database_real_escape_string($search_text)."%') ";
$profile_query .=" AND se_users.user_id NOT IN(".$blockstr.") ";
$profile_query.=" AND se_users.user_id NOT IN (".$blocked.")";
//echo $profile_query;
/*
// LOOP OVER FIELDS
while($field_info = $database->database_fetch_assoc($fields))
{
// TEXT FIELD OR TEXTAREA
if( $field_info['field_type'] == 1 || $field_info['field_type'] == 2 )
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` LIKE '{$search_text}%'";
}
/* // RADIO OR SELECT BOX
elseif($field_info[field_type] == 3 || $field_info[field_type] == 4)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN {$options[$i]['value']}";
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` IN (SELECT CASE ".implode(" ", $cases)." END AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '{$search_text}%')";
}
}
// CHECKBOX
elseif($field_info[field_type] == 6)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN ".(pow(2, $i));
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
if( $profile_query ) {$profile_query .= " OR ";}
if($field_info['field_id']==5||$field_info['field_id']==9||$field_info['field_id']==10||$field_info['field_id']==15||$field_info['field_id']==16||$field_info['field_id']==17||$field_info['field_id']==19||$field_info['field_id']==20||$field_info['field_id']==28){$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value = '{$search_text}%')";}
else{
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '{$search_text}%')";}
}
}*/
//}
// CONSTRUCT QUERY
$profile_query = "
SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
se_users.user_photo, se_users.verified, se_users.online, se_users.user_level_id
FROM
se_profilevalues
LEFT JOIN
se_users
ON se_profilevalues.profilevalue_user_id=se_users.user_id
WHERE
se_users.user_verified='1' AND
se_users.user_enabled='1' AND
se_users.user_search='1' AND
($profile_query)
";
// GET TOTAL PROFILES
$total_profiles = $database->database_num_rows($database->database_query($profile_query.""));
// IF NOT TOTAL ONLY
if($t == "" || $t == "profile")
{
// MAKE PROFILE PAGES
$start = ($p - 1) * $results_per_page;
$limit = $results_per_page+1;
// SEARCH PROFILES
$online_users_array = online_users();
$profiles = $database->database_query($profile_query." ORDER BY se_users.user_id DESC LIMIT $start, $limit");
while($profile_info = $database->database_fetch_assoc($profiles))
{
$profile = new se_user();
$profile->user_info['user_id'] = $profile_info['user_id'];
$profile->user_info['user_username'] = $profile_info['user_username'];
$profile->user_info['user_fname'] = $profile_info['user_fname'];
$profile->user_info['user_lname'] = $profile_info['user_lname'];
$profile->user_info['user_photo'] = $profile_info['user_photo'];
$profile->user_displayname();
$profile_info['user_photo']=$profile->user_photo('./images/nophoto.png', TRUE);
//if(SE_DEBUG1){echo $profile->user_photo('./images/nophoto.png', TRUE)."<br>";}
// DETERMINE IF USER IS ONLINE
$is_online = (bool) in_array($profile_info['user_username'], $online_users_array[0]);
$results[] = Array(
'result_url' => $url->url_create('profile', $profile_info['user_username']),
'result_icon' => $profile->user_photo('./images/nophoto.png', TRUE),
'result_name' => 509,
'result_name_1' => $profile->user_displayname,
'result_desc' => '',
'result_online' => $is_online,
'profile' => $profile_info
);
}
// SET TOTAL RESULTS
$total_results = $total_profiles;
}
// SET ARRAY VALUES
SE_Language::_preload_multi(509, 1072);
//if($total_profiles > 200) { $total_profiles = "200+"; }
$search_objects[] = Array(
'search_type' => '0',
'search_lang' => 1072,
'search_total' => $total_profiles
);
//if($_SERVER['REMOTE_ADDR']=="24.47.141.40"){echo $profile_query;}
}
function search_profile()
{
global $database, $url, $results_per_page, $p, $search_text, $t, $search_objects, $results, $total_results, $user;
$blocked=explode(",", $user->user_info["user_blocklist"]);
foreach($blocked as $block){
if($block!=""){$blockstr=$block.",";}
}
$blockstr.="0";
$blocked="";
$query=$database->database_query("SELECT user_id FROM se_users WHERE user_enabled=1 AND MATCH(user_blocklist) AGAINST('".$user->user_info["user_id"]."' IN NATURAL LANGUAGE MODE)");
while($row2=$database->database_fetch_array($query))
{
if($blocked==""){$blocked=$database->database_real_escape_string($row2["user_id"]);}
else{
$blocked.=",".$database->database_real_escape_string($row2["user_id"]);
}
}
if($blocked==""){$blocked="0";}
// GET FIELDS
$fields = $database->database_query("
SELECT
profilefield_id AS field_id,
profilefield_type AS field_type,
profilefield_options AS field_options
FROM
se_profilefields
WHERE
profilefield_type<>'5' &&
(profilefield_dependency<>'0' OR (profilefield_dependency='0' AND profilefield_display<>'0'))
");
//$search_text = preg_replace('/[^a-zA-Z0-9 ]/', '', $search_text);
$searchtext=''.$database->database_real_escape_string($search_text).'';
$profile_query = "(MATCH(se_users.user_username) AGAINST('".$database->database_real_escape_string($searchtext)."' IN BOOLEAN MODE) OR MATCH(se_profilevalues.profilevalue_13, se_profilevalues.profilevalue_21, se_profilevalues.profilevalue_27) AGAINST('".$database->database_real_escape_string($searchtext)."' IN BOOLEAN MODE)) ";
// $profile_query = "(MATCH(se_users.user_username) AGAINST('".$searchtext."' IN BOOLEAN MODE) OR se_profilevalues.profilevalue_21 LIKE '%".$database->database_real_escape_string($search_text)."%') ";
$profile_query .=" AND se_users.user_id NOT IN(".$blockstr.") ";
$profile_query.=" AND se_users.user_id NOT IN (".$blocked.")";
//echo $profile_query;
/*
// LOOP OVER FIELDS
while($field_info = $database->database_fetch_assoc($fields))
{
// TEXT FIELD OR TEXTAREA
if( $field_info['field_type'] == 1 || $field_info['field_type'] == 2 )
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` LIKE '{$search_text}%'";
}
/* // RADIO OR SELECT BOX
elseif($field_info[field_type] == 3 || $field_info[field_type] == 4)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN {$options[$i]['value']}";
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
if( $profile_query ) $profile_query .= " OR ";
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` IN (SELECT CASE ".implode(" ", $cases)." END AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '{$search_text}%')";
}
}
// CHECKBOX
elseif($field_info[field_type] == 6)
{
$options = unserialize($field_info['field_options']);
$langids = Array();
$cases = Array();
for($i=0,$max=count($options);$i<$max;$i++)
{
$cases[] = "WHEN languagevar_id='{$options[$i]['label']}' THEN ".(pow(2, $i));
$langids[] = $options[$i][label];
}
if(count($cases) != 0)
{
if( $profile_query ) {$profile_query .= " OR ";}
if($field_info['field_id']==5||$field_info['field_id']==9||$field_info['field_id']==10||$field_info['field_id']==15||$field_info['field_id']==16||$field_info['field_id']==17||$field_info['field_id']==19||$field_info['field_id']==20||$field_info['field_id']==28){$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value = '{$search_text}%')";}
else{
$profile_query .= "`se_profilevalues`.`profilevalue_{$field_info['field_id']}` & (SELECT sum(CASE ".implode(" ", $cases)." END) AS value FROM se_languagevars WHERE languagevar_id IN (".implode(", ", $langids).") AND languagevar_value LIKE '{$search_text}%')";}
}
}*/
//}
// CONSTRUCT QUERY
$profile_query = "
SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
se_users.user_photo
FROM
se_profilevalues
LEFT JOIN
se_users
ON se_profilevalues.profilevalue_user_id=se_users.user_id
WHERE
se_users.user_verified='1' AND
se_users.user_enabled='1' AND
se_users.user_search='1' AND
($profile_query)
";
// GET TOTAL PROFILES
$total_profiles = $database->database_num_rows($database->database_query($profile_query." LIMIT 201"));
// IF NOT TOTAL ONLY
if($t == "0" || $t == "profile")
{
// MAKE PROFILE PAGES
$start = ($p - 1) * $results_per_page;
$limit = $results_per_page+1;
// SEARCH PROFILES
$online_users_array = online_users();
$profiles = $database->database_query($profile_query." ORDER BY se_users.user_id DESC LIMIT $start, $limit");
while($profile_info = $database->database_fetch_assoc($profiles))
{
// CREATE AN OBJECT FOR USER
$profile = new se_user();
$profile->user_info['user_id'] = $profile_info['user_id'];
$profile->user_info['user_username'] = $profile_info['user_username'];
$profile->user_info['user_fname'] = $profile_info['user_fname'];
$profile->user_info['user_lname'] = $profile_info['user_lname'];
$profile->user_info['user_photo'] = $profile_info['user_photo'];
$profile->user_displayname();
// DETERMINE IF USER IS ONLINE
$is_online = (bool) in_array($profile_info['user_username'], $online_users_array[0]);
$results[] = Array(
'result_url' => $url->url_create('profile', $profile_info['user_username']),
'result_icon' => $profile->user_photo('./images/nophoto.png', TRUE),
'result_name' => 509,
'result_name_1' => $profile->user_displayname,
'result_desc' => '',
'result_online' => $is_online
);
}
// SET TOTAL RESULTS
$total_results = $total_profiles;
}
// SET ARRAY VALUES
SE_Language::_preload_multi(509, 1072);
if($total_profiles > 200) { $total_profiles = "200+"; }
$search_objects[] = Array(
'search_type' => '0',
'search_lang' => 1072,
'search_total' => $total_profiles
);
//if($_SERVER['REMOTE_ADDR']=="24.47.141.40"){echo $profile_query;}
}
// END search_profile() FUNCTION
// THIS FUNCTION RETURNS TIME IN SECONDS WITH MICROSECONDS
// INPUT:
// OUTPUT: RETURNS THE TIME IN SECONDS WITH MICROSECONDS
if( !function_exists('getmicrotime') )
{
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
}
// END getmicrotime() FUNCTION
// THIS FUNCTION CLEANS HTML TAGS FROM TEXT
// INPUT: $text REPRESENTING THE STRING TO CLEAN
// $allowable_tags REPRESENTING THE ALLOWABLE HTML TAGS (AS A COMMA-DELIMITED STRING)
// $forbidden_attr (OPTIONAL) REPRESENTING AND ARRAY OF ANY ADDITIONAL FORBIDDEN ATTRIBUTES (SUCH AS A STYLE TAG)
// OUTPUT: THE CLEANED TEXT
function cleanHTML($text, $allowable_tags = null, $forbidden_attr = null)
{
// INCLUDE FILTER CLASS
if( !class_exists("InputFilter") )
{
require(SE_ROOT."/include/class_inputfilter.php");
}
// New method
if( !method_exists('InputFilter', 'safeSQL') )
{
return (new InputFilter())->process($text, array(
'allowedTags' => $allowable_tags,
'forbiddenAttributes' => $forbidden_attr,
));
}
// Old method
else
{
// INSTANTIATE INPUT FILTER CLASS WITH APPROPRIATE TAGS
$xssFilter = new InputFilter(explode(",", str_replace(" ", "", $allowable_tags)), "", 0, 1, 1);
// ADD NECESSARY BLACKLIST ITEMS
for($i=0;$i<count($forbidden_attr);$i++)
{
$xssFilter->attrBlacklist[] = $forbidden_attr[$i];
}
// RETURN PROCESSED TEXT
return $xssFilter->process($text);
}
}
// END cleanHTML() FUNCTION
// THIS FUNCTION TRIMS A GIVEN STRING PRESERVING HTML
// INPUT: $string REPRESENTING THE STRING TO SHORTEN
// $start REPRESENTING THE CHARACTER TO START WITH
// $length REPRESENTING THE LENGTH OF THE STRING TO RETURN
// OUTPUT: THE CLEANED TEXT
function chopHTML($string, $start, $length=false)
{
$pattern = '/(\[\w+[^\]]*?\]|\[\/\w+\]|<\w+[^>]*?>|<\/\w+>)/i';
$clean = preg_replace_callback($pattern, chr(1), $string);
if(!$length)
$str = substr($clean, $start);
else {
$str = substr($clean, $start, $length);
$str = substr($clean, $start, $length + substr_count($str, chr(1)));
}
$pattern = str_replace(chr(1),'(.*?)',preg_quote($str));
if(preg_match('/'.$pattern.'/is', $string, $matched))
return $matched[0];
return $string;
}
// END chopHTML() FUNCTION
// THIS FUNCTION CHOPS A GIVEN STRING AND INSERTS A STRING AT THE END OF EACH CHOP
// INPUT: $string REPRESENTING THE STRING TO CHOP
// $length REPRESENTING THE LENGTH OF EACH SEGMENT
// $insert_char REPRESENTING THE STRING TO INSERT AT THE END OF EACH SEGMENT
function choptext($string, $length=32, $insert_char=' ')
{
return preg_replace_callback("!(?:^|\s)([\w\!\?\.]{" . $length . ",})(?:\s|$)!e",'chunk_split("\\1",' . $length . ',"' . $insert_char. '")',$string);
}
// END choptext() FUNCTION
// THIS FUNCTION CHOPS A GIVEN STRING AND INSERTS A STRING AT THE END OF EACH CHOP (PRESERVING HTML ENTITIES)
// INPUT: $html REPRESENTING THE STRING TO CHOP
// $size REPRESENTING THE LENGTH OF EACH SEGMENT
// $delim REPRESENTING THE STRING TO INSERT AT THE END OF EACH SEGMENT
function chunkHTML_split($html, $size, $delim)
{
$pos=0;
for($i=0;$i<strlen($html);$i++)
{
if($pos >= $size && !$unsafe)
{
$out .= $delim;
$unsafe = 0;
$pos = 0;
}
$c = substr($html,$i,1);
if($c == "&")
$unsafe = 1;
elseif($c == ";")
$unsafe = 0;
$out .= $c;
$pos++;
}
return $out;
}
// END chunkHTML_split
// THIS FUNCTION RETURNS THE LENGTH OF A STRING, ACCOUNTING FOR UTF8 CHARS
// INPUT: $str REPRESENTING THE STRING
// OUTPUT: THE LENGTH OF THE STRING
function strlen_utf8($str)
{
$i = 0;
$count = 0;
$len = strlen($str);
while($i < $len)
{
$chr = ord ($str[$i]);
$count++;
$i++;
if($i >= $len)
break;
if($chr & 0x80)
{
$chr <<= 1;
while ($chr & 0x80)
{
$i++;
$chr <<= 1;
}
}
}
return $count;
}
// END strlen_utf8() FUNCTION
// THIS FUNCTION MAKES UTF8 CHARS WORK IN SERIALIZE BY BASICALLY IGNORING THE STRING LENGTH PARAM
// INPUT: $str REPRESENTING THE SERIALIZED STRING
// OUTPUT: THE UNSERIALIZED DATA
function mb_unserialize($serial_str)
{
//$out = preg_replace_callback('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );
$out = preg_replace_callback(
'!s:(\d+):"(.*?)";!', // The pattern to match
function ($matches) {
return 's:' . strlen($matches[2]) . ':"' . $matches[2] . '";';
},
$serial_str
);
return unserialize($out);
}
// END mb_unserialize() FUNCTION
// THIS FUNCTION RETURNS AN ARRAY CONTAINING THE USERNAMES OF ONLINE USERS
// INPUT:
// OUTPUT: AN ARRAY OF USERNAMES FOR USERS CURRENTLY ACTIVE IN THE SYSTEM
function online_users_count($nocash="")
{
global $database;
$online_array = NULL;
if($nocash==""){
// CACHING
$cache_object = SECache::getInstance('serial', array('lifetime' => 60));
if( is_object($cache_object) )
{
$online_array = $cache_object->get('online_users');
}
}
if( !is_array($online_array) )
{
$total_visitors = 0;
$onlineusers_array = array();
$onlineusers_usernames = array();
$online_time = time() - (10 * 60);
if($_GET["membersonline"]=="alphabetical"){$orderby="user_displayname ASC";}
else{$orderby="visitor_lastactive DESC";}
$sql = "SELECT `se_visitors`.`visitor_user_id` AS `user_id`, `se_visitors`.`visitor_user_username` AS `user_username`,
`se_visitors`.`visitor_user_displayname` AS `user_displayname`, `se_users`.`user_photo` AS `user_photo`, `se_users`.`user_status` AS `user_status` FROM `se_visitors`
Left Outer Join `se_users` ON `se_users`.`user_id` = `se_visitors`.`visitor_user_id`
WHERE visitor_invisible=0 && visitor_lastactive>'{$online_time}' ORDER BY ".$orderby." LIMIT 2000";
$resource = $database->database_query($sql);
while( $online_user_info = $database->database_fetch_assoc($resource) )
{
// THIS IS A USER
if( !empty($online_user_info['user_id']) )
{
if( in_array($online_user_info['user_username'], $onlineusers_usernames) ) continue;
$ou_status=$online_user_info['user_status'];
$ou_status=str_replace("\\","/",$ou_status);
$ou_status=str_replace("<wbr>&shy;","",$ou_status);
$ou_status=str_replace("'","\\'",$ou_status);
$ou_status=str_replace("&#039;","\'",$ou_status);
$ou_status=str_replace("&quot;","\'",$ou_status);
$ou_status=str_replace("%27","\'",$ou_status);
$ou_status=substr($ou_status, 0, 50);
$online_user = new se_user();
$online_user->user_info['user_id'] = $online_user_info['user_id'];
$online_user->user_info['user_username'] = $online_user_info['user_username'];
$online_user->user_info['user_displayname'] = $online_user_info['user_displayname'];
$online_user->user_info['user_status'] = $ou_status;
$online_user->user_displayname = $online_user_info['user_displayname'];
$online_user->user_info['user_photo'] = $online_user_info['user_photo'];
$onlineusers_array[] = $online_user;
$onlineusers_usernames[] = $online_user->user_info['user_username'];
$ou_status="";
}
// THIS IS A VISITOR
else
{
$total_visitors++;
}
}
$online_array = array($onlineusers_array, 0, $onlineusers_usernames);
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($online_array, 'online_users');
}
}
return $online_array;
}
function online_users($nocash="")
{
global $database;
$online_array = NULL;
if($nocash==""){
// CACHING
$cache_object = SECache::getInstance('serial', array('lifetime' => 60));
if( is_object($cache_object) )
{
$online_array = $cache_object->get('online_users');
}
}
if( !is_array($online_array) )
{
$total_visitors = 0;
$onlineusers_array = array();
$onlineusers_usernames = array();
$online_time = time() - (10 * 60);
if($_GET["membersonline"]=="alphabetical"){$orderby="user_displayname ASC";}
else{$orderby="user_lastactive DESC";}
$sql = "SELECT `user_id`,`user_username`,
`user_username` as `user_displayname`, `se_users`.`user_photo` AS `user_photo`, `se_users`.`user_status` AS `user_status`, se_profilevalues.profilevalue_22 FROM `se_users`, se_profilevalues
WHERE se_profilevalues.profilevalue_user_id =se_users.user_id AND online='1' ORDER BY ".$orderby." LIMIT 2000";
$resource = $database->database_query($sql);
while( $online_user_info = $database->database_fetch_assoc($resource) )
{
if($online_user_info['profilevalue_22']!=1){
// THIS IS A USER
//if( !empty($online_user_info['user_id']) )
//{
if( in_array($online_user_info['user_username'], $onlineusers_usernames) ) continue;
$ou_status=$online_user_info['user_status'];
$ou_status=str_replace("\\","/",$ou_status);
$ou_status=str_replace("<wbr>&shy;","",$ou_status);
$ou_status=str_replace("'","\\'",$ou_status);
$ou_status=str_replace("&#039;","\'",$ou_status);
$ou_status=str_replace("&quot;","\'",$ou_status);
$ou_status=str_replace("%27","\'",$ou_status);
$ou_status=substr($ou_status, 0, 50);
$online_user = new se_user();
$online_user->user_info['user_id'] = $online_user_info['user_id'];
$online_user->user_info['user_username'] = $online_user_info['user_username'];
$online_user->user_info['user_displayname'] = $online_user_info['user_displayname'];
$online_user->user_info['user_status'] = $ou_status;
$online_user->user_displayname = $online_user_info['user_displayname'];
$online_user->user_info['user_photo'] = $online_user_info['user_photo'];
$onlineusers_array[] = $online_user;
$onlineusers_usernames[] = $online_user->user_info['user_username'];
$ou_status="";
}
// THIS IS A VISITOR
else
{
$total_visitors++;
}
}
$online_array = array($onlineusers_array, 0, $onlineusers_usernames);
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($online_array, 'online_users');
}
}
return $online_array;
}
function online_users_admin($nocash="1")
{
global $database;
$online_array = NULL;/*
if($nocash==""){
// CACHING
$cache_object = SECache::getInstance('serial', array('lifetime' => 60));
if( is_object($cache_object) )
{
$online_array = $cache_object->get('online_users');
}
}*/
if( !is_array($online_array) )
{
$total_visitors = 0;
$onlineusers_array = array();
$onlineusers_usernames = array();
$online_time = time() - (30 * 60);
if($_GET["membersonline"]=="alphabetical"){$orderby="user_displayname ASC";}
else{$orderby="visitor_lastactive DESC";}
$sql = "SELECT `se_visitors`.`visitor_user_id` AS `user_id`, `se_visitors`.`visitor_user_username` AS `user_username`,
`se_visitors`.`visitor_user_displayname` AS `user_displayname`, `se_users`.`user_photo` AS `user_photo`, `se_users`.`user_status` AS `user_status` FROM `se_visitors`
Left Outer Join `se_users` ON `se_users`.`user_id` = `se_visitors`.`visitor_user_id`
WHERE visitor_lastactive>'{$online_time}' ORDER BY ".$orderby." LIMIT 2000";
if(SE_DEBUG1){echo $sql;}
$resource = $database->database_query($sql);
/*
while( $online_user_info = $database->database_fetch_assoc($resource) )
{
// THIS IS A USER
if( !empty($online_user_info['user_id']) )
{
if( in_array($online_user_info['user_username'], $onlineusers_usernames) ) continue;
$ou_status=$online_user_info['user_status'];
$ou_status=str_replace("\\","/",$ou_status);
$ou_status=str_replace("<wbr>&shy;","",$ou_status);
$ou_status=str_replace("'","\\'",$ou_status);
$ou_status=str_replace("&#039;","\'",$ou_status);
$ou_status=str_replace("&quot;","\'",$ou_status);
$ou_status=str_replace("%27","\'",$ou_status);
$ou_status=substr($ou_status, 0, 50);
$online_user = new se_user();
$online_user->user_info['user_id'] = $online_user_info['user_id'];
$online_user->user_info['user_username'] = $online_user_info['user_username'];
$online_user->user_info['user_displayname'] = $online_user_info['user_displayname'];
$online_user->user_info['user_status'] = $ou_status;
$online_user->user_displayname = $online_user_info['user_displayname'];
$online_user->user_info['user_photo'] = $online_user_info['user_photo'];
$onlineusers_array[] = $online_user;
$onlineusers_usernames[] = $online_user->user_info['user_username'];
$ou_status="";
}
// THIS IS A VISITOR
else
{
$total_visitors++;
}
$total_visitors++;
}*/
//$online_array = array($onlineusers_array, 0, $onlineusers_usernames);
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($online_array, 'online_users');
}
}
return $database->database_num_rows($resource);
}
// END online_users() FUNCTION
// THIS FUNCTION RETURNS AN ARRAY CONTAINING SITE STATISTICS
// INPUT:
// OUTPUT: AN ARRAY OF STATISTICS
function site_statistics()
{
global $setting, $database, $database_name;
$statistics = NULL;
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$statistics = $cache_object->get('site_statistics');
}
// RETRIEVAL
//if( !is_array($statistics) || empty($statistics) )
if( !is_array($statistics) )
{
$statistics = array();
// Get default stats
$total_members = $database->database_fetch_assoc($database->database_query("SELECT count(*) AS total_members FROM se_users"));
$statistics['members'] = array(
'title' => 661,
'stat' => (int) ( isset($total_members['total_members']) ? $total_members['total_members'] : 0 )
);
if( $setting['setting_connection_allow'] )
{
//$total_friends = $database->database_fetch_assoc($database->database_query("SELECT count(*) AS total_friends FROM se_friends WHERE friend_status='1'"));
$total_friends=$database->database_result($database->database_query("SELECT friendships AS total_friends FROM bateworldcom_zips.statistics WHERE id=1"),0);
$statistics['friends'] = array(
'title' => 662,
'stat' => (int) ( isset($total_friends) ? $total_friends : 0 )
);
}
$total_comments = 0;
$comment_tables = $database->database_query("SHOW TABLES FROM `{$database_name}` LIKE 'se_%comments'");
while($table_info = $database->database_fetch_array($comment_tables))
{
$comment_type = strrev(substr(strrev(substr($table_info[0], 3)), 8));
$table_comments = $database->database_fetch_assoc($database->database_query("SELECT count(*) AS total_comments FROM `se_{$comment_type}comments`"));
$total_comments += $table_comments['total_comments'];
}
$statistics['comments'] = array(
'title' => 663,
'stat' => (int) $total_comments
);
/*
$total_media = 0;
$media_tables = $database->database_query("SHOW TABLES FROM `{$database_name}` LIKE 'se_%media'");
while($table_info = $database->database_fetch_array($media_tables))
{
$comment_type = strrev(substr(strrev(substr($table_info[0], 3)), 8));
$table_media = $database->database_fetch_assoc($database->database_query("SELECT count(*) AS total_media FROM se_{$comment_type}media"));
$total_media += $total_media['total_media'];
}
$statistics['media'] = array(
'title' => 663, // TODO
'stat' => (int) $total_media
);
*/
/*
$total_mediatags = 0;
$mediatag_tables = $database->database_query("SHOW TABLES FROM `{$database_name}` LIKE 'se_%mediatags'");
while($table_info = $database->database_fetch_array($media_tables))
{
$comment_type = strrev(substr(strrev(substr($table_info[0], 3)), 8));
$table_mediatags = $database->database_fetch_assoc($database->database_query("SELECT count(*) AS total_mediatags FROM se_{$comment_type}mediatags"));
$total_mediatags += $total_mediatags['total_mediatags'];
}
$statistics['mediatags'] = array(
'title' => 663, // TODO
'stat' => (int) $total_mediatags
);
*/
// CALL HOOK
// COMMENT OUT THIS NEXT LINE IF YOU ONLY WANT THE BASIC STATISTICS
($hook = SE_Hook::exists('se_site_statistics')) ? SE_Hook::call($hook, array('statistics' => &$statistics)) : NULL;
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($statistics, 'site_statistics');
}
}
// Load language
foreach( $statistics as $stat )
{
SE_Language::_preload($stat['title']);
}
return $statistics;
}
// END site_statistics() FUNCTION
function recent_verified()
{
global $setting, $database;
$signups = NULL;
if(!isset($_GET["nocacheonstuff"])){
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$signups = $cache_object->get('recent_verified');
}
}
// RETRIEVAL
//if( !is_array($signups) || empty($signups) )
if( !is_array($signups) )
{
$sql = "SELECT user_id, user_username, user_photo FROM se_users, se_albums, se_media WHERE se_albums.album_user_id=user_id AND media_album_id=user_id AND se_media.approved=1 AND user_verified='1' AND user_enabled='1' AND user_search='1' AND (user_photo<>'' AND TRIM(user_photo)<>'.') AND verified=1 GROUP BY user_id ORDER BY verifieddate DESC, user_id DESC LIMIT 36";
$resource = $database->database_query($sql);
$signups = array();
while( $user_info = $database->database_fetch_assoc($resource) )
{
$signup_user = new se_user();
$signup_user->user_info['user_id'] = $user_info['user_id'];
$signup_user->user_info['user_username'] = $user_info['user_username'];
$signup_user->user_info['user_photo'] = $user_info['user_photo'];
$signup_user->user_info['user_fname'] = $user_info['user_fname'];
$signup_user->user_info['user_lname'] = $user_info['user_lname'];
$signup_user->user_displayname();
$signups[] =& $signup_user;
unset($signup_user);
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($signups, 'recent_verified');
}
}
return $signups;
}
// THIS FUNCTION RETURNS AN ARRAY CONTAINING THE USERS THAT RECENTLY SIGNED UP
// INPUT:
// OUTPUT:
function recent_signups()
{
global $setting, $database;
$signups = NULL;
if(!isset($_GET["nocacheonstuff"])){
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$signups = $cache_object->get('recent_signups');
}
}
// RETRIEVAL
//if( !is_array($signups) || empty($signups) )
if( !is_array($signups) )
{
$sql = "SELECT user_id, user_username, user_fname, user_lname, user_photo FROM se_users, se_media, se_albums WHERE media_album_id=album_id AND user_photo=media_id AND album_user_id=user_id AND se_media.approved=1 AND user_verified='1' AND user_enabled='1' AND user_search='1' AND (user_photo<>'' AND TRIM(user_photo)<>'.') ORDER BY user_signupdate DESC LIMIT 36";
$resource = $database->database_query($sql);
$signups = array();
while( $user_info = $database->database_fetch_assoc($resource) )
{
$signup_user = new se_user();
$signup_user->user_info['user_id'] = $user_info['user_id'];
$signup_user->user_info['user_username'] = $user_info['user_username'];
$signup_user->user_info['user_photo'] = $user_info['user_photo'];
$signup_user->user_info['user_fname'] = $user_info['user_fname'];
$signup_user->user_info['user_lname'] = $user_info['user_lname'];
$signup_user->user_displayname();
$signups[] =& $signup_user;
unset($signup_user);
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($signups, 'recent_signups');
}
}
return $signups;
}
// END recent_signups() FUNCTION
// THIS FUNCTION RETURNS AN ARRAY CONTAINING THE MOST RECENTLY LOGGED IN USERS
// INPUT:
// OUTPUT:
function recent_logins()
{
global $setting, $database;
$logins = NULL;
// CACHING
/*$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$logins = $cache_object->get('recent_logins');
}*/
// RETRIEVAL
//if( !is_array($logins) || empty($logins) )
if( !is_array($logins) )
{
$sql = "SELECT user_id, user_username, user_fname, user_lname, user_photo, user_level_id FROM se_users WHERE user_photo<>'' AND user_search='1' ORDER BY user_lastlogindate DESC LIMIT 20";
$resource = $database->database_query($sql);
$logins = array();
while( $user_info = $database->database_fetch_assoc($resource) )
{
$login_user = new se_user();
$login_user->user_info['user_id'] = $user_info['user_id'];
$login_user->user_info['user_username'] = $user_info['user_username'];
$login_user->user_info['user_photo'] = $user_info['user_photo'];
$login_user->user_info['user_fname'] = $user_info['user_fname'];
$login_user->user_info['user_lname'] = $user_info['user_lname'];
$login_user->user_info['user_level_id'] = $user_info['user_level_id'];
$login_user->user_displayname();
$logins[] =& $login_user;
unset($login_user);
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($logins, 'recent_logins');
}
}
return $logins;
}
// END recent_logins() FUNCTION
function recent_videos_cron()
{
global $database, $user, $owner;
// BEGIN QUERY
$sql = "
SELECT
se_videos.*, se_users.user_username
";
// CONTINUE QUERY
$sql .= "
FROM
se_videos
";
// IF NO USER ID SPECIFIED, JOIN TO USER TABLE
$sql .= "
LEFT JOIN
se_users
ON se_videos.video_user_id=se_users.user_id
WHERE
video_search='1' AND se_videos.video_is_converted='1' AND approved=1 AND video_admin_approved='1'
";
//$rand=rand(1, $this->video_total()-56);
//$rand=rand(1, 1000-56);
if($rand<1){$rand=1;}
$top=$rand+55;
// ADD ORDER, AND LIMIT CLAUSE
$sql .= "
ORDER BY
video_id DESC
LIMIT
27
";
//echo $sql;
// RUN QUERY
$resource = $database->database_query($sql);
// GET ALBUMS INTO AN ARRAY
$video_array = Array();
while($video_info = $database->database_fetch_assoc($resource))
{
// IF NO USER ID SPECIFIED, CREATE OBJECT FOR AUTHOR
if($owner->user_exists != 0 && $owner->user_info['user_id'] == $video_info['video_user_id'])
{
$author = $owner;
}
elseif($user->user_exists != 0 && $user->user_info['user_id'] == $video_info['video_user_id'])
{
$author = $user;
}
// SET AUTHOR AND DIRECTORY
$video_info['video_author'] = $author;
$video_info['video_dir'] = cronvideo_dir($video_info['video_user_id'], TRUE);
// CHECK FOR THUMBNAIL
$video_info['video_thumb'] = file_exists("../".$video_info['video_dir'].$video_info['video_id']."_thumb.jpg");
// SET UP DURATION
$minutes = floor($video_info['video_duration_in_sec']/60);
$seconds = $video_info['video_duration_in_sec']-60*$minutes;
$video_info['video_duration_in_min'] = sprintf("%02d:%02d", $minutes, $seconds);
// SET UP RATING
$video_info['video_rating_full'] = floor($video_info['video_cache_rating']);
$video_info['video_rating_part'] = (($video_info['video_cache_rating']-$video_info['video_rating_full']) == 0) ? 0 : 1;
$video_info['video_rating_none'] = 5-$video_info['video_rating_full']-$video_info['video_rating_part'];
// CREATE ARRAY OF VIDEO DATA
$video_array[] = $video_info;
}
//$album_array[] =& $signup_user;
unset($author, $album_info, $signup_user);
//if(SE_DEBUG)var_dump($video_info);
// RETURN ARRAY
return $video_array;
}
function cronvideo_dir($user_id = 0, $create_if_missing = false)
{
/*if( !$user_id && $this->user_id )
$user_id = $this->user_id;
*/
if( !$user_id && !is_numeric($user_id) )
return FALSE;
$subdir = $user_id + 999 - ( ( $user_id - 1 ) % 1000 );
$videodir = "../uploads_video/{$subdir}/{$user_id}/";
/*if( $create_if_missing )
{
// IN ADMIN DIRECTORY, ABORT
if( !is_dir('../uploads_video') )
return FALSE;
$video_path_array = explode("/", $videodir);
array_pop($video_path_array);
array_pop($video_path_array);
$subdir = implode("/", $video_path_array)."/";
if( !is_dir($subdir) )
{
@mkdir($subdir, 0777);
@chmod($subdir, 0777);
$handle = @fopen($subdir."index.php", 'x+');
@fclose($handle);
}
if( !is_dir($videodir) )
{
@mkdir($videodir, 0777);
@chmod($videodir, 0777);
$handle = @fopen($videodir."/index.php", 'x+');
@fclose($handle);
}
}*/
return $videodir;
}
function recent_videos()
{
global $database, $user, $owner;
// BEGIN QUERY
$sql = "
SELECT
se_videos.*, se_users.user_username
";
// CONTINUE QUERY
$sql .= "
FROM
se_videos
";
// IF NO USER ID SPECIFIED, JOIN TO USER TABLE
$sql .= "
LEFT JOIN
se_users
ON se_videos.video_user_id=se_users.user_id
WHERE
video_search='1' AND se_videos.video_is_converted='1' AND video_admin_approved='1'
";
//$rand=rand(1, $this->video_total()-56);
//$rand=rand(1, 1000-56);
if($rand<1){$rand=1;}
$top=$rand+55;
// ADD ORDER, AND LIMIT CLAUSE
$sql .= "
ORDER BY
video_id DESC
LIMIT
20
";
//echo $sql;
// RUN QUERY
$resource = $database->database_query($sql);
// GET ALBUMS INTO AN ARRAY
$video_array = Array();
while($video_info = $database->database_fetch_assoc($resource))
{
// IF NO USER ID SPECIFIED, CREATE OBJECT FOR AUTHOR
if($owner->user_exists != 0 && $owner->user_info['user_id'] == $video_info['video_user_id'])
{
$author = $owner;
}
elseif($user->user_exists != 0 && $user->user_info['user_id'] == $video_info['video_user_id'])
{
$author = $user;
}
// SET AUTHOR AND DIRECTORY
$video_info['video_author'] = $author;
$video_info['video_dir'] = video_dir($video_info['video_user_id'], TRUE);
// CHECK FOR THUMBNAIL
$video_info['video_thumb'] = file_exists($video_info['video_dir'].$video_info['video_id']."_thumb.jpg");
// SET UP DURATION
$minutes = floor($video_info['video_duration_in_sec']/60);
$seconds = $video_info['video_duration_in_sec']-60*$minutes;
$video_info['video_duration_in_min'] = sprintf("%02d:%02d", $minutes, $seconds);
// SET UP RATING
$video_info['video_rating_full'] = floor($video_info['video_cache_rating']);
$video_info['video_rating_part'] = (($video_info['video_cache_rating']-$video_info['video_rating_full']) == 0) ? 0 : 1;
$video_info['video_rating_none'] = 5-$video_info['video_rating_full']-$video_info['video_rating_part'];
// CREATE ARRAY OF VIDEO DATA
$video_array[] = $video_info;
}
//$album_array[] =& $signup_user;
unset($author, $album_info, $signup_user);
//if(SE_DEBUG)var_dump($video_info);
// RETURN ARRAY
return $video_array;
}
function recent_photos_cron()
{ global $database, $user, $owner;
// BEGIN QUERY
$sql = "
SELECT
se_media.*,
se_albums.album_id,
se_albums.album_user_id,
se_albums.album_title,
se_users.user_id,
se_users.user_username,
se_users.user_photo,
se_users.user_fname,
se_users.user_lname
FROM
se_media, se_users,
se_albums
WHERE se_albums.album_user_id=se_users.user_id AND se_albums.album_id=se_media.media_album_id AND se_albums.album_search=1 AND se_media.approved=1 AND album_privacy=31";// AND media_date>=".(time()-(60*60*48))."";
// IF NO USER ID SPECIFIED, RETRIEVE USER INFORMATION
// ADD ADDITIONAL SELECTS
// CONTINUE QUERY
// IF NO USER ID SPECIFIED, JOIN TO USER TABLE
// ADD WHERE IF NECESSARY
/* $sql .= "
WHERE se_albums.album_search=1 AND album_privacy=31
";*/
// ENSURE USER ID IS NOT EMPTY
// INSERT AND IF NECESSARY
// ADD WHERE CLAUSE, IF NECESSARY
/*if( !empty($where) ) $sql .= "
{$where}
";*/
// $rand=rand(1, 1000-56);
if($rand<1){$rand=1;}
$top=$rand+55;
// ADD ORDER, AND LIMIT CLAUSE
$sql .= "
ORDER BY
media_id DESC
LIMIT
100
";
//send_admin("sean@bateworld.com", "EE", $sql);
//echo $sql;
// RUN QUERY
$resource = $database->database_query($sql);
// GET MEDIA INTO AN ARRAY
$media_array = array();
while($media_info = $database->database_fetch_assoc($resource))
{
// IF NO USER ID SPECIFIED, CREATE OBJECT FOR AUTHOR
if( $owner->user_exists && $owner->user_info['user_id']==$media_info['album_user_id'] )
{
$author =& $owner;
}
elseif( $user->user_exists && $user->user_info['user_id']==$media_info['album_user_id'] )
{
$author =& $user;
}
$media_info['media_author'] =& $author;
// BACKWARDS COMPAT
$media_info['media_comments_total'] = $media_info['total_comments'];
$media_info['media_desc'] = str_replace("<br>", "\r\n", $media_info['media_desc']);
// CREATE ARRAY OF MEDIA DATA
$media_array[] = $media_info;
unset($media_info, $author);
}
// RETURN ARRAY
return $media_array;}
function recent_photos()
{ global $database, $user, $owner;
// BEGIN QUERY
$sql = "
SELECT
se_media.*,
se_albums.album_id,
se_albums.album_user_id,
se_albums.album_title,
se_users.user_id,
se_users.user_username,
se_users.user_photo,
se_users.user_fname,
se_users.user_lname
FROM
se_media, se_users,
se_albums
WHERE se_albums.album_user_id=se_users.user_id AND se_albums.album_id=se_media.media_album_id
";
// IF NO USER ID SPECIFIED, RETRIEVE USER INFORMATION
// ADD ADDITIONAL SELECTS
// CONTINUE QUERY
// IF NO USER ID SPECIFIED, JOIN TO USER TABLE
// ADD WHERE IF NECESSARY
/* $sql .= "
WHERE se_albums.album_search=1 AND album_privacy=31
";*/
// ENSURE USER ID IS NOT EMPTY
// INSERT AND IF NECESSARY
// ADD WHERE CLAUSE, IF NECESSARY
/*if( !empty($where) ) $sql .= "
{$where}
";*/
// $rand=rand(1, 1000-56);
if($rand<1){$rand=1;}
$top=$rand+55;
// ADD ORDER, AND LIMIT CLAUSE
$sql .= "
ORDER BY
media_id DESC
LIMIT
20
";
//echo $sql;
// RUN QUERY
$resource = $database->database_query($sql);
// GET MEDIA INTO AN ARRAY
$media_array = array();
while($media_info = $database->database_fetch_assoc($resource))
{
// IF NO USER ID SPECIFIED, CREATE OBJECT FOR AUTHOR
if( $owner->user_exists && $owner->user_info['user_id']==$media_info['album_user_id'] )
{
$author =& $owner;
}
elseif( $user->user_exists && $user->user_info['user_id']==$media_info['album_user_id'] )
{
$author =& $user;
}
$media_info['media_author'] =& $author;
// BACKWARDS COMPAT
$media_info['media_comments_total'] = $media_info['total_comments'];
$media_info['media_desc'] = str_replace("<br>", "\r\n", $media_info['media_desc']);
// CREATE ARRAY OF MEDIA DATA
$media_array[] = $media_info;
unset($media_info, $author);
}
// RETURN ARRAY
return $media_array;}
// THIS FUNCTION RETURNS AN ARRAY CONTAINING THE MOST POPULAR USERS
// INPUT:
// OUTPUT:
function popular_users()
{
global $setting, $database;
$popular_users = NULL;
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$popular_users = $cache_object->get('popular_users');
}
// RETRIEVAL
//if( !is_array($popular_users) || empty($popular_users) )
if( !is_array($popular_users) )
{
$sql = "SELECT count(se_friends.friend_user_id2) AS num_friends, se_users.user_id, se_users.user_username, se_users.user_fname, se_users.user_lname, se_users.user_photo FROM se_friends LEFT JOIN se_users ON se_friends.friend_user_id1=se_users.user_id WHERE se_friends.friend_status='1' AND se_users.user_search='1' GROUP BY se_users.user_id ORDER BY num_friends DESC LIMIT 20";
$resource = $database->database_query($sql);
$popular_users = array();
while( $user_info = $database->database_fetch_assoc($resource) )
{
$popular_user = new se_user();
$popular_user->user_info['user_id'] = $user_info['user_id'];
$popular_user->user_info['user_username'] = $user_info['user_username'];
$popular_user->user_info['user_photo'] = $user_info['user_photo'];
$popular_user->user_info['user_fname'] = $user_info['user_fname'];
$popular_user->user_info['user_lname'] = $user_info['user_lname'];
$popular_user->user_displayname();
$popular_users[] = array(
'friend' => &$popular_user,
'total_friends' => $user_info['num_friends']
);
unset($popular_user);
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($popular_users, 'popular_users');
}
}
return $popular_users;
}
// END popular_users() FUNCTION
// THIS FUNCTION RETURNS AN ARRAY CONTAINING THE MOST POPULAR USERS
// INPUT:
// OUTPUT:
function site_news()
{
global $setting, $database;
$news = NULL;
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$news = $cache_object->get('site_news');
}
// RETRIEVAL
//if( !is_array($news) || empty($news) )
if( !is_array($news) )
{
$sql = "SELECT * FROM se_announcements WHERE (enddate=0 AND startdate=0) OR (startdate=0 AND enddate>=".time().") OR (startdate<=".time()." AND enddate=0) OR (startdate<=".time()." AND enddate>=".time().") ORDER BY announcement_order DESC LIMIT 20";
$resource = $database->database_query($sql);
$news = array();
while( $news_info = $database->database_fetch_assoc($resource) )
{
// CONVERT SUBJECT/BODY BACK TO HTML
$news_info['announcement_body'] = htmlspecialchars_decode($news_info['announcement_body'], ENT_QUOTES);
$news_info['announcement_subject'] = htmlspecialchars_decode($news_info['announcement_subject'], ENT_QUOTES);
$news[] = $news_info;
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($news, 'site_news');
}
}
return $news;
}
function checkitout_news()
{
global $setting, $database;
$news = NULL;
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) )
{
$news = $cache_object->get('checkitout_news');
}
// RETRIEVAL
//if( !is_array($news) || empty($news) )
if( !is_array($news) )
{
$sql = "SELECT * FROM bateworldcom_zips.checkitout ORDER BY announcement_order DESC LIMIT 20";
$resource = $database->database_query($sql);
$news = array();
while( $news_info = $database->database_fetch_assoc($resource) )
{
// CONVERT SUBJECT/BODY BACK TO HTML
$news_info['announcement_body'] = htmlspecialchars_decode($news_info['announcement_body'], ENT_QUOTES);
$news_info['announcement_subject'] = htmlspecialchars_decode($news_info['announcement_subject'], ENT_QUOTES);
$news[] = $news_info;
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($news, 'checkitout_news');
}
}
return $news;
}
// END site_news() FUNCTION
// THIS FUNCTION RETURNS AN ARRAY CONTAINING THE USERS FRIENDS BIRTHDAYS INFO
// INPUT:
// OUTPUT:
function friends_birthdays()
{
global $setting, $database, $user;
$birthdays = NULL;
// CACHING
$cache_object = SECache::getInstance('serial');
if( is_object($cache_object) && $user->user_info['user_id'] !=10 )
{
$birthdays = $cache_object->get('friends_birthdays_user_'.$user->user_info['user_id']);
}
// RETRIEVAL
//if( !is_array($birthdays) || empty($birthdays) )
if( !is_array($birthdays) )
{
$birthdays = array();
$sql = "SELECT profilefield_id, t2.profilecat_id FROM se_profilefields LEFT JOIN se_profilecats AS t1 ON se_profilefields.profilefield_profilecat_id=t1.profilecat_id LEFT JOIN se_profilecats AS t2 ON t1.profilecat_dependency=t2.profilecat_id WHERE profilefield_special='1'";
$resource = $database->database_query($sql);
if( $database->database_num_rows($resource) > 0 )
{
// CONSTRUCT QUERY
$birthdays_upcoming_query = "
(SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
CASE
";
while( $birthday_field = $database->database_fetch_assoc($resource) )
{
$birthdays_upcoming_query .= " WHEN se_users.user_profilecat_id='{$birthday_field['profilecat_id']}' THEN DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d')";
$birthdays_upcoming_where[] = "(se_users.user_profilecat_id='{$birthday_field['profilecat_id']}' AND DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)<>'0' AND MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)<>'0' AND CURDATE() <= DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d') AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) >= DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d'))";
}
$birthdays_upcoming_query .= " ELSE '0000-00-00' END AS birthday FROM se_friends LEFT JOIN se_users ON se_friends.friend_user_id2=se_users.user_id LEFT JOIN se_profilevalues ON se_users.user_id=se_profilevalues.profilevalue_user_id WHERE se_friends.friend_user_id1='{$user->user_info['user_id']}' AND (".implode(" OR ", $birthdays_upcoming_where).")AND se_users.user_enabled=1 AND se_profilevalues.`profilevalue_42`<>'1'
)
UNION(
SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
CASE";
$sql = "SELECT profilefield_id, t2.profilecat_id FROM se_profilefields LEFT JOIN se_profilecats AS t1 ON se_profilefields.profilefield_profilecat_id=t1.profilecat_id LEFT JOIN se_profilecats AS t2 ON t1.profilecat_dependency=t2.profilecat_id WHERE profilefield_special='1'";
$resource = $database->database_query($sql);
while( $birthday_field = $database->database_fetch_assoc($resource) )
{
$birthdays_upcoming_query .= " WHEN se_users.user_profilecat_id='{$birthday_field['profilecat_id']}' THEN DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d')";
$birthdays_upcoming_where1[] = "(se_users.user_profilecat_id='{$birthday_field['profilecat_id']}' AND DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)<>'0' AND MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)<>'0' AND CURDATE() <= DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d') AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) >= DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d'))";
}
$birthdays_upcoming_query .= " ELSE '0000-00-00' END AS birthday FROM se_users LEFT JOIN se_profilevalues ON se_users.user_id=se_profilevalues.profilevalue_user_id WHERE se_users.user_id='{$user->user_info['user_id']}' AND (".implode(" OR ", $birthdays_upcoming_where1).")
AND se_users.user_enabled=1 AND se_profilevalues.`profilevalue_42`<>'1'
)
ORDER BY birthday";
/*$birthdays_upcoming_query="
SELECT
se_users.user_id,
se_users.user_username,
se_users.user_fname,
se_users.user_lname,
CASE";
while( $birthday_field = $database->database_fetch_assoc($resource) )
{
$birthdays_upcoming_query .= " WHEN se_users.user_profilecat_id='{$birthday_field['profilecat_id']}' THEN DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d')";
$birthdays_upcoming_where[] = "(se_users.user_profilecat_id='{$birthday_field['profilecat_id']}' AND DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)<>'0' AND MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)<>'0' AND CURDATE() <= DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d') AND DATE_ADD(CURDATE(), INTERVAL 7 DAY) >= DATE_FORMAT(CONCAT(YEAR(CURDATE()), \"-\", MONTH(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`), \"-\", DAY(se_profilevalues.`profilevalue_{$birthday_field['profilefield_id']}`)), '%Y-%m-%d'))";
}
$birthdays_upcoming_query .= " ELSE '0000-00-00' END AS birthday FROM se_users LEFT JOIN se_profilevalues ON se_users.user_id=se_profilevalues.profilevalue_user_id WHERE se_users.user_id='{$user->user_info['user_id']}' AND (".implode(" OR ", $birthdays_upcoming_where).")
ORDER BY birthday";*/
$resource = $database->database_query($birthdays_upcoming_query);
while( $birthday_info = $database->database_fetch_assoc($resource) )
{
$birthday_user = new se_user();
$birthday_user->user_info['user_id'] = $birthday_info['user_id'];
$birthday_user->user_info['user_username'] = $birthday_info['user_username'];
$birthday_user->user_info['user_fname'] = $birthday_info['user_fname'];
$birthday_user->user_info['user_lname'] = $birthday_info['user_lname'];
$birthday_user->user_displayname();
// SET BIRTHDAY
$byear = substr( $birthday_info['birthday'], 0, 4 ) == '0000' ? '1990' : substr( $birthday_info['birthday'], 0, 4 );
$birthday_date = mktime(0, 0, 0, substr($birthday_info['birthday'], 5, 2), substr($birthday_info['birthday'], 8, 2), $byear );
$birthdays[] = array(
'birthday_user_id' => $birthday_user->user_info['user_id'],
'birthday_user_username' => $birthday_user->user_info['user_username'],
'birthday_user_displayname' => $birthday_user->user_displayname,
'birthday_date' => $birthday_date,
'birthday_user' => &$birthday_user
);
unset($birthday_user);
}
}
// CACHE
if( is_object($cache_object) )
{
$cache_object->store($birthdays, 'friends_birthdays_user_'.$user->user_info['user_id']);
}
}
return $birthdays;
}
// END friends_birthdays() FUNCTION
function get_simple_cookie_domain($host = null)
{
// Quick config
if( defined('SE_COOKIE_DOMAIN') )
{
return SE_COOKIE_DOMAIN;
}
if( !$host )
{
$host = $_SERVER["HTTP_HOST"];
}
$host = parse_url($host);
$host = $host['path'];
$parts = explode('.', $host);
switch( TRUE )
{
// Do not use custom for these:
// IP Address
case ( preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $host) ):
// Intranet host
case ( count($parts) === 1 ):
return null;
break;
// Second level ccld
case ( strlen($parts[count($parts)-1]) == 2 && strlen($parts[count($parts)-2]) <= 3 ):
array_splice($parts, 0, count($parts) - 3);
return join('.', $parts);
break;
// tld or first-level ccld
default:
array_splice($parts, 0, count($parts) - 2);
return join('.', $parts);
}
return null;
}
function check_ip_in_banned_list_simple($ip, $list)
{
$x=explode(",", $list);
foreach($x as $y)
{
if($y==$ip){return true;}
}
return false;
}
function check_ip_in_banned_list($ip, $list)
{
// We were passed a string address
$ip6=false;
if( !is_numeric($ip) )
{
$ip = ip2long($ip);
}
if( !$ip )
{
$ip = ip2long_v6($ip);
$ip6=true;
}
// Wth it's not an ip!
/* if( !$ip )
{
trigger_error('That isn\'t an IP address!', E_USER_NOTICE);
return false;
}
*/
// Passed a , separated string
if( !is_array($list) )
{
$list = explode(',', $list);
}
// No banned ips
if( empty($list) )
{
return false;
}
// Sort into banned specific IPs and ranges
$banned_ip_addr = array();
$banned_ip_ranges = array();
foreach( $list as $banned_ip )
{
if( strpos($banned_ip, '*') !== false )
{
$ip6=false;
if( !is_numeric($banned_ip) )
{
$banned_ip1 = ip2long($banned_ip);
}
if( !$banned_ip1 )
{
//$ip = ip2long_v6($banned_ip);
$ip6=true;
}
// Decode
if($ip6){
$tmp_low = ip2long_v6(str_replace('*', '0', $banned_ip));
$tmp_high = ip2long_v6(str_replace('*', '255', $banned_ip)); // this might not work for some bytes
}else{
$tmp_low = ip2long(str_replace('*', '0', $banned_ip));
$tmp_high = ip2long(str_replace('*', '255', $banned_ip)); // this might not work for some bytes
}
// If failed to decode, or low is larger than high, skip
if( !$tmp_low || !$tmp_high || $tmp_low > $tmp_high )
{
continue;
}
// Add
$banned_ip_ranges[] = array(
$tmp_low,
$tmp_high
);
}
else if( strpos($banned_ip, '-') !== false )
{
// Decode
list($tmp_low, $tmp_high) = explode('-', $banned_ip, 2);
$ip6=false;
if( !is_numeric($banned_ip) )
{
$banned_ip1 = ip2long($banned_ip);
}
if( !$banned_ip1 )
{
//$ip = ip2long_v6($banned_ip);
$ip6=true;
}
if($ip6){
$tmp_low = ip2long_v6($tmp_low);
$tmp_high = ip2long_v6($tmp_high);
}
else{
$tmp_low = ip2long($tmp_low);
$tmp_high = ip2long($tmp_high);
}
// If failed to decode, or low is larger than high, skip
if( !$tmp_low || !$tmp_high || $tmp_low > $tmp_high )
{
continue;
}
// Add
$banned_ip_ranges[] = array(
$tmp_low,
$tmp_high
);
}
else
{
$ip6=false;
if( !is_numeric($banned_ip) )
{
$banned_ip1 = ip2long($banned_ip);
}
if( !$banned_ip1 )
{
//$ip = ip2long_v6($banned_ip);
$ip6=true;
}
if($ip6){
$tmp = ip2long_v6($banned_ip);
}
else{
$tmp = ip2long($banned_ip);
}
if( $tmp )
{
$banned_ip_addr[] = $tmp;
}
}
}
// Now check against ip lists
if( in_array($ip, $banned_ip_addr) )
{
return true;
}
// Check against IP ranges
foreach( $banned_ip_ranges as $range )
{
if( $ip >= $range[0] && $ip <= $range[1] )
{
return true;
}
}
return false;
}
function is_mobile() {
// Get the user agent
$user_agent = $_SERVER['HTTP_USER_AGENT'];
// Create an array of known mobile user agents
// This list is from the 21 October 2010 WURFL File.
// Most mobile devices send a pretty standard string that can be covered by
// one of these. I believe I have found all the agents (as of the date above)
// that do not and have included them below. If you use this function, you
// should periodically check your list against the WURFL file, available at:
// http://wurfl.sourceforge.net/
$mobile_agents = Array(
"240x320",
"acer",
"acoon",
"acs-",
"abacho",
"ahong",
"airness",
"alcatel",
"amoi",
"android",
"anywhereyougo.com",
"applewebkit/525",
"applewebkit/532",
"asus",
"audio",
"au-mic",
"avantogo",
"becker",
"benq",
"bilbo",
"bird",
"blackberry",
"blazer",
"bleu",
"cdm-",
"compal",
"coolpad",
"danger",
"dbtel",
"dopod",
"elaine",
"eric",
"etouch",
"fly " ,
"fly_",
"fly-",
"go.web",
"goodaccess",
"gradiente",
"grundig",
"haier",
"hedy",
"hitachi",
"htc",
"huawei",
"hutchison",
"inno",
"ipad",
"ipaq",
"ipod",
"jbrowser",
"kddi",
"kgt",
"kwc",
"lenovo",
"lg ",
"lg2",
"lg3",
"lg4",
"lg5",
"lg7",
"lg8",
"lg9",
"lg-",
"lge-",
"lge9",
"longcos",
"maemo",
"mercator",
"meridian",
"micromax",
"midp",
"mini",
"mitsu",
"mmm",
"mmp",
"mobi",
"mot-",
"moto",
"nec-",
"netfront",
"newgen",
"nexian",
"nf-browser",
"nintendo",
"nitro",
"nokia",
"nook",
"novarra",
"obigo",
"palm",
"panasonic",
"pantech",
"philips",
"phone",
"pg-",
"playstation",
"pocket",
"pt-",
"qc-",
"qtek",
"rover",
"sagem",
"sama",
"samu",
"sanyo",
"samsung",
"sch-",
"scooter",
"sec-",
"sendo",
"sgh-",
"sharp",
"siemens",
"sie-",
"softbank",
"sony",
"spice",
"sprint",
"spv",
"symbian",
"tablet",
"talkabout",
"tcl-",
"teleca",
"telit",
"tianyu",
"tim-",
"toshiba",
"tsm",
"up.browser",
"utec",
"utstar",
"verykool",
"virgin",
"vk-",
"voda",
"voxtel",
"vx",
"wap",
"wellco",
"wig browser",
"wii",
"windows ce",
"wireless",
"xda",
"xde",
"zte"
);
// Pre-set $is_mobile to false.
$is_mobile = false;
// Cycle through the list in $mobile_agents to see if any of them
// appear in $user_agent.
foreach ($mobile_agents as $device) {
// Check each element in $mobile_agents to see if it appears in
// $user_agent. If it does, set $is_mobile to true.
if (stristr($user_agent, $device)) {
$is_mobile = true;
// break out of the foreach, we don't need to test
// any more once we get a true value.
break;
}
}
return $is_mobile;
}
if(!function_exists("xmlstr"))
{
function xmlstr($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
}
if(!function_exists("getmicrotime"))
{
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
}
function ip2long_v6($ip) {
$ip_n = inet_pton($ip);
$bin = '';
for ($bit = strlen($ip_n) - 1; $bit >= 0; $bit--) {
$bin = sprintf('%08b', ord($ip_n[$bit])) . $bin;
}
if (function_exists('gmp_init')) {
return gmp_strval(gmp_init($bin, 2), 10);
} elseif (function_exists('bcadd')) {
$dec = '0';
for ($i = 0; $i < strlen($bin); $i++) {
$dec = bcmul($dec, '2', 0);
$dec = bcadd($dec, $bin[$i], 0);
}
return $dec;
} else {
trigger_error('GMP or BCMATH extension not installed!', E_USER_ERROR);
}
}
function long2ip_v6($dec) {
if (function_exists('gmp_init')) {
$bin = gmp_strval(gmp_init($dec, 10), 2);
} elseif (function_exists('bcadd')) {
$bin = '';
do {
$bin = bcmod($dec, '2') . $bin;
$dec = bcdiv($dec, '2', 0);
} while (bccomp($dec, '0'));
} else {
trigger_error('GMP or BCMATH extension not installed!', E_USER_ERROR);
}
$bin = str_pad($bin, 128, '0', STR_PAD_LEFT);
$ip = array();
for ($bit = 0; $bit <= 7; $bit++) {
$bin_part = substr($bin, $bit * 16, 16);
$ip[] = dechex(bindec($bin_part));
}
$ip = implode(':', $ip);
return inet_ntop(inet_pton($ip));
}
function get_userdir($user_id)
{
$subdir = $user_id+999-(($user_id-1)%1000);
$userdir = "./uploads_user/$subdir/$user_id/";
return $userdir;
}
function get_groupdir($user_id)
{
$subdir = $user_id+999-(($user_id-1)%1000);
$userdir = "./uploads_group/$subdir/$user_id/";
return $userdir;
}
function get_clubdir($user_id)
{
$subdir = $user_id+999-(($user_id-1)%1000);
$userdir = "./uploads_club/$subdir/$user_id/";
return $userdir;
}
function get_eventdir($user_id)
{
$subdir = $user_id+999-(($user_id-1)%1000);
$userdir = "./uploads_event/$subdir/$user_id/";
return $userdir;
}
function highwindsdelete($file){
/*$key="c3f1d5e147a2a0d673894d1950254bc17bc85b56a924d7e09f4271a4deae7e49";
$hash="t2x8q5x9";
$ch = curl_init();
$url="https://striketracker.highwinds.com/api/v1/accounts/".$hash."/purge";
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $url);
$data = array(
'url' => $file,
'recursive' => "true",
'purgeAllDynamic' => 'false'
);
//$payload = json_encode($data);
//$payload1 = json_decode($payload);
//$payload = json_encode(array("list" => $payload1));
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Authorization: Bearer c3f1d5e147a2a0d673894d1950254bc17bc85b56a924d7e09f4271a4deae7e49'));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"list": [
{
"url": "'.$file.'",
"recursive": false,
"purgeAllDynamic": true
}
]
}');
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);*/
//if(SE_DEBUG1){echo $file."<br>";}
//Start new CDN API HERE
$file1=str_replace(IMAGECDN1, "", $file);
$file=str_replace(IMAGECDN, "", $file);
$file=str_replace(IMAGECDN1, "", $file);
$file1=str_replace(IMAGECDN, "", $file1);
if(substr($file, 0, 1)!="/"){$file="/".$file;}
if(substr($file1, 0, 1)!="/"){$file1="/".$file1;}
$id="1531793993";
$key="aGvDE5_AMbZkgATzp8gV8P5xd2Uc=_HJ$OWYyZmM5NWQtNWQxMy00OGQ4LWJhYmYtNDAzNDIxZDA4MmM1";
$hash="t2x8q5x9";
$ch = curl_init();
$url="https://api.cdn77.com/v3/cdn/".$id."/job/purge";
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $url);
$data = array(
'url' => $file,
'recursive' => "true",
'purgeAllDynamic' => 'true'
);
//$payload = json_encode($data);
//$payload1 = json_decode($payload);
//$payload = json_encode(array("list" => $payload1));
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Authorization: Bearer aGvDE5_AMbZkgATzp8gV8P5xd2Uc=_HJ$OWYyZmM5NWQtNWQxMy00OGQ4LWJhYmYtNDAzNDIxZDA4MmM1'));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"paths": [
"'.$file.'"
]
}');
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
$id="1094707133";
$key="aGvDE5_AMbZkgATzp8gV8P5xd2Uc=_HJ$OWYyZmM5NWQtNWQxMy00OGQ4LWJhYmYtNDAzNDIxZDA4MmM1";
$hash="t2x8q5x9";
$ch = curl_init();
$url="https://api.cdn77.com/v3/cdn/".$id."/job/purge";
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $url);
$data = array(
'url' => $file1,
'recursive' => "true",
'purgeAllDynamic' => 'true'
);
//$payload = json_encode($data);
//$payload1 = json_decode($payload);
//$payload = json_encode(array("list" => $payload1));
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Authorization: Bearer aGvDE5_AMbZkgATzp8gV8P5xd2Uc=_HJ$OWYyZmM5NWQtNWQxMy00OGQ4LWJhYmYtNDAzNDIxZDA4MmM1'));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"paths": [
"'.$file1.'"
]
}');
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
}
function showad($spot)
{
global $database, $group_id;
if($spot==21){
$query=$database->database_query("SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND objectid='{$group_id}' AND paused=0 AND website=1 AND (max_views=0 OR (max_views>0 AND max_views>views)) AND (max_clicks=0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0)) ORDER BY RAND() LIMIT 1");
if($database->database_num_rows($query)==0){
$query=$database->database_query("SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND paused=0 AND website=1 AND (max_views=0 OR (max_views>0 AND max_views>views)) AND (max_clicks=0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0)) ORDER BY RAND() LIMIT 1");
}
}
else{
$query=$database->database_query("SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND paused=0 AND website=1 AND (max_views=0 OR (max_views>0 AND max_views>views)) AND (max_clicks=0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0)) ORDER BY RAND() LIMIT 1");
}
if($row["code"]!=""){
echo $row["code"];
}else{
if($row["link"]==""){?><img src="<?php echo $row["image"];?>" class="img-responsive center-block img-fluid"><?php }else{
?>
<a href="<?php echo $row["link"];?>" target="_blank" onclick="adaddclick('<?php echo $row["id"];?>', '<?php echo urlencode($_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"]);?>');"><img data-src="<?php
echo str_replace("https://bateworld.com/", IMAGECDN, $row["image"]);?>" class="img-responsive center-block lozad img-fluid"></a>
<?php
}
}
$database->database_query("UPDATE ads.ads SET views=views+1 WHERE id='".$row["id"]."'");
}
function showad1($spot)
{
global $database, $group_id;
if($spot==21){
$query=$database->database_query("SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND find_in_set('".$database->database_real_escape_string($group_id)."',objectid) AND paused=0 AND website=1 AND (max_views =0 OR (max_views>0 AND max_views>views)) AND (max_clicks =0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0)) ORDER BY RAND() LIMIT 1");
if($database->database_num_rows($query)==0){
$query=$database->database_query("(SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND paused=0 AND website=1 AND (max_views =0 OR (max_views>0 AND max_views>views)) AND (max_clicks =0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0))) ORDER BY RAND() LIMIT 1");
}
}
else{
$query=$database->database_query("SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND paused=0 AND website=1 AND (max_views =0 OR (max_views>0 AND max_views>views)) AND (max_clicks =0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0)) ORDER BY RAND() LIMIT 1");
}
$row=$database->database_fetch_array($query);
if($row["max_clicks_day"]>=1)
{
$query1=$database->database_query("SELECT COUNT(ad_id) as cnt FROM ads.ad_clicks WHERE time>=UNIX_TIMESTAMP(CURDATE())");
$row1=$database->database_fetch_array($query1);
}
if($row["max_views_day"]>=1)
{
$query2=$database->database_query("SELECT ad_views FROM ads.ad_views WHERE ad_date>=UNIX_TIMESTAMP(CURDATE())");
$row2=$database->database_fetch_array($query1);
}
if(($row["max_views_day"]>0&&$row["max_views_day"]>=$row2["ad_views"]) || ($row["max_clicks_day"]>0 && $row["max_clicks_day"]>=$row1["cnt"]))
{
$query=$database->database_query("SELECT * FROM ads.ads WHERE location=".$database->database_real_escape_string($spot)." AND paused=0 AND website=1 AND max_views_day =0 AND max_clicks_day =0 AND (max_views =0 OR (max_views>0 AND max_views>views)) AND (max_clicks =0 OR (max_clicks>0 AND max_clicks>clicks)) AND ((startdate<='".time()."' AND enddate>='".time()."') OR (startdate<='".time()."' AND enddate='0') OR (startdate=0 AND enddate=0)) ORDER BY RAND() LIMIT 1");
$row=$database->database_fetch_array($query);
}
if($database->database_num_rows($query) > 0) {
$views = $database->database_query("SELECT ad_views FROM ads.ad_stats WHERE ad_id='".$row["id"]."' AND ad_date=UNIX_TIMESTAMP(CURDATE())");
if($database->database_num_rows($views) == 0) {
$database->database_query("
INSERT INTO ads.ad_stats
(`ad_date`, `ad_id`, ad_views)
VALUES
(UNIX_TIMESTAMP(CURDATE()), '".$row["id"]."', 1)
");
} else {
//mail("leprakhauns@gmail.com", "AAA", " UPDATE ads.ad_stats SET `ad_views`=adviews+1 WHERE ad_id='".$row["id"]."' AND `ad_date`=UNIX_TIMESTAMP(CURDATE())");
$database->database_query("
UPDATE ads.ad_stats SET `ad_views`=ad_views+1 WHERE ad_id='".$row["id"]."' AND `ad_date`=UNIX_TIMESTAMP(CURDATE())
");
}
if($row["code"]!=""){
echo $row["code"];
}else{
if($row["link"]==""){?><img src="<?php echo $row["image"];?>" class="img-responsive center-block" <?php if($spot==23){?>style="max-height:70px;"<?php }?>><?php
}else{
?>
<a href="<?php echo $row["link"];?>" target="_blank" onclick="adaddclick('<?php echo $row["id"];?>', '<?php echo urlencode($_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"]);?>');"><img src="<?php
echo str_replace("https://bateworld.com/", IMAGECDN, $row["image"]);?>" class="img-responsive center-block lozad img-fluid" <?php if($spot==23){?>style="max-height:70px;"<?php }?>></a>
<?php
}
if($spot==15){if($row["user"]!=""){echo '<a href="/profile.php?user='.$row["user"].'">'.$row["user"].'</a>';}}
}
$database->database_query("UPDATE ads.ads SET views=views+1 WHERE id='".$row["id"]."'");
}
//else{mail("leprakhauns@gmail.com", "RRaa", $spot);}
}
function user_photo2($owner, $nophoto_image = "", $thumb = FALSE)
{
global $url;
//if( !$user->user_exists || !$this->user_info['user_photo'] )
if(!$owner['user_photo'] )
return $nophoto_image;
$user_photo = $url->url_userdir($owner['user_id']).$owner['user_photo'];
if( $thumb )
{
$user_thumb = substr($user_photo, 0, strrpos($user_photo, "."))."_thumb".substr($user_photo, strrpos($user_photo, "."));
if( file_exists($user_thumb) ){
$user_thumb=str_replace("./", "", $user_thumb);
return IMAGECDN1.$user_thumb;
}
}
//if( file_exists($user_photo) ){
$user_photo = $url->cloud_userdir($owner['user_id']).$owner['user_photo'];
return $user_photo;
//}
return $nophoto_image;
}
function userprofiledot($owner, $picture="", $width="", $height="", $lazod="1", $forcesize="0")
{
$image="
<div style='position: relative; margin:auto; display: inline-block;
";
if($width!=""){
//$image.="width:{$width}";
}
$image.="'><img ";
if($lazod=="1"){$image.="src='".IMAGECDN."images/blank.gif' data-src='{$picture}'";
}else{$image.="src='{$picture}'";}
$image.=" class='photo";
if($lazod=="1"){$image.=" lozad";}
$image.="' style='";
if($width!=""){
$image.="max-width:{$width};";
if($forcesize==1)
{
$image.=" width:{$width};";
}
}
if($height!=""){
$image.="max-height:{$height};";
if($forcesize==1)
{
$image.=" height:{$height};";
}
}
$image.="' border='0' alt=' ' />";
$level=$owner["user_level_id"];
$verified=$owner["verified"];
if($level==2){
if($owner["staff"]==1){
$image.="<img src='".IMAGECDN."images/goldstar.png' style='position:absolute; bottom:25px; right:0; width:10px !important; height:auto!important;' data-toggle='tooltip' title='Premium Member' data-original-title='Premium Member' class='tiptool'>";
}else{
$image.="<img src='".IMAGECDN."images/goldstar.png' style='position:absolute; bottom:0px; right:0; width:10px !important; height:auto!important;' data-toggle='tooltip' title='Premium Member' data-original-title='Premium Member' class='tiptool'>";
}
}
if($verified==1)
{
$image.="<img src='".IMAGECDN."images/bwverification.png' style='position:absolute; top:0px; right:0; width:10px !important; height:auto!important;' data-toggle='tooltip' title='Verified Member' data-original-title='Verified Member' class='tiptool'>";
}
if(online_now($owner)){
$image.="<img src='".IMAGECDN."images/greendot.png' style='position:absolute; bottom:0px; left:0; width:5px !important; height:auto!important;' data-toggle='tooltip' title='Online Member' data-original-title='Online Member' class='tiptool'>";
}
if($owner["staff"]==1){$image.='<div style="background:red; color:yellow; font-weight:bold;">BateWorld Staff</div>';}
$image.="</div>";
return $image;
}
function online_now($owner)
{
global $database;
//$online_users_array = online_users();
//if(in_array($this->user_info['user_username'], $online_users_array[2])) { $this->is_online = 1; } else { $this->is_online = 0; }
$profile_query = "SELECT profilevalue_22 FROM se_profilevalues WHERE profilevalue_user_id='".$owner['user_id']."'";
$query=$database->database_query($profile_query);
$row=$database->database_fetch_array($query);
$profile_info["profilevalue_22"]=$row["profilevalue_22"];
if($profile_info["profilevalue_22"]==1){return false;}
if($owner['online']==""||$owner['online']==null)
{
$query=$database->database_query("SELECT `online` FROM se_users WHERE user_id='".$owner['user_id']."'");
$row=$database->database_fetch_array($query);
$owner['online']=$row["online"];
}
$is_online = $owner['online'];
return $is_online;
}