codice:
<?php
function getStats() {
global $HTTP_SERVER_VARS;
global $HTTP_COOKIE_VARS;
$votesleft = $HTTP_COOKIE_VARS["votesleft"];
include("settings.php");
$online = getUsersOnline();
$totpics = getTotpics();
$topStats = "<font color=\"#f5f5f5\">Users Online:</font><font color=\"yellow\">$online</font> | Total Photos: <font color=\"yellow\">$totpics</font> | ";
if ($showvotes =="1") {
$vleft = $maxvotes -$votesleft;
if($votesleft < 1) { $tempv ="0";} else { $tempv = $votesleft;}
$topStats = $topStats ."Votes Remaining: <font color=\"yellow\">$vleft</font> | ";
$topStats = $topStats ."Votes Today:<font color=\"yellow\">$tempv</font> | ";
}
return $topStats;
exit;
}
function getCatnum($catid) {
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$sql = "select * from $r_picuploads where catagory='$catid'"; // Catagory list
$sql_result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($sql_result)) {
$catnum++;
}
return $catnum;
}
function CheckBan($ip) {
require('settings.php');
$today = date("Y-m-d"); // check todays date
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database in $r_banip!";
exit;
}
// check for existing record
$sql = "select * from $r_banip where ip ='$ip'";
$sql_result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($sql_result)) {
$dbip = $row["ip"];
if ($dbip == "$ip"){ $status= "ban"; }
}
return $status;
}
function BanIp($ip,$today) {
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database in banip!";
exit;
}
// check for existing record
$isban = CheckBan($ip);
if ($isban == "ban") {
$sql = "update $r_banip set today='$today' where ip='$ip'";
$sql_result = mysql_query($sql,$connection);
} else {
$sql = "insert into $r_banip values('','$ip','$today')";
$sql_result = mysql_query($sql,$connection);
}
}
function CheckIp($ip,$today) {
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database in Checkip!";
exit;
}
$sql = "select * from $r_banip where ip ='$ip' AND today='$today'";
$sql_result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($sql_result)) {
$dbip = $row["ip"];
$dbtoday = $row["today"];
if ($dbip == "$ip" && $dbtoday == "$today") { $status = "ban"; }
}
return $status;
}
// GD Library
function RatioResizeImgGD($src_file, $dest_file, $newWidth) {
global
$gallerypath
;
// find the image size & type
if(!function_exists('imagecreate')){return $src_file;}
$imginfo = @getimagesize($src_file);
switch($imginfo[2]) {
case 1: $type = IMG_GIF; break;
case 2: $type = IMG_JPG; break;
case 3: $type = IMG_PNG; break;
case 4: $type = IMG_WBMP; break;
default: return $src_file; break;
}
switch($type) {
case IMG_GIF:
if(!function_exists('imagecreatefromgif')){return $src_file;}
$srcImage = @imagecreatefromgif("$src_file");
break;
case IMG_JPG:
if(!function_exists('imagecreatefromjpeg')){return $src_file;}
$srcImage = @ImageCreateFromJpeg($src_file);
break;
case IMG_PNG:
if(!function_exists('imagecreatefrompng')){return $src_file;}
$srcImage = @imagecreatefrompng("$src_file");
break;
case IMG_WBMP:
if(!function_exists('imagecreatefromwbmp')){return $src_file;}
$srcImage = @imagecreatefromwbmp("$src_file");
break;
default: return $src_file;
}
if($srcImage){
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
$ratioWidth = $srcWidth/$newWidth;
$destWidth = $newWidth;
$destHeight = $srcHeight / $ratioWidth;
// resize
$destImage = @imagecreate($destWidth, $destHeight);
imagecopyresized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
// create and save final picture
switch($type){
case IMG_GIF: @imagegif($destImage, "$dest_file"); break;
case IMG_JPG: @imagejpeg($destImage, "$dest_file"); break;
case IMG_PNG: @imagepng($destImage, "$dest_file"); break;
case IMG_WBMP: @imagewbmp($destImage, "$dest_file"); break;
}
// free the memory
@imagedestroy($srcImage);
@imagedestroy($destImage);
return $dest_file;
}
else
{
return $src_file;
}
}
// ImageMagick
function RatioResizeImgImageMagick($src_file, $dest_file, $newWidth){
global
$gallerypath
;
// find the image size
$imginfo = @getimagesize($src_file);
if ($imginfo == NULL)
return $src_file;
// height/width
$srcWidth = $imginfo[0];
$srcHeight = $imginfo[1];
$ratioWidth = $srcWidth/$newWidth;
$ratioHeight = 0;
$destWidth = $newWidth;
$destHeight = $srcHeight / $ratioWidth;
// resize
//echo "convert -quality 80 -antialias -sample \"".$destWidth."x".$destHeight."\" \"$src_file\" \"$dest_file\"";
exec("convert -quality 80 -antialias -sample \"".$destWidth."x".$destHeight."\" \"$src_file\" \"$dest_file\"");
return $dest_file;
}
function getUcomments($id){
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$ucomments= "
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n
<tbody>\n
<tr valign=\"top\">
<td width=\"100%\">\n
";
$sql = "select * from $r_ucomments where pid ='$id' ORDER BY id DESC LIMIT $maxcomments";
$sql_result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($sql_result)) {
$user = $row["userid"];
$text = $row["text"];
if($bg == "#fff8dc") { $bg = "#fffaf0";} else { $bg ="#fff8dc";}
$ucomments = $ucomments ."
$user\n
<div class=\"hilite\">\n
$text<hr color=\"black\">\n
</div>\n";
}
$query = ("select count(*) from $r_ucomments where pid ='$id'");
$num2 = mysql_query($query) or die("Select Failed!");
$num = mysql_fetch_array($num2);
if($num[0] >0) {
if($num[0] >$maxcomments) {
$ucomments = $ucomments ."<a href=\"#\" onClick=\"MoreComments=window.open('$PHP_SELF?allcomments=on&id=$id','MoreComments','toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizeable=yes,width=400,height=400,left=20,top=20'); return false;\">more comments..</a></td>\n</tr></table>\n";
} else {
$ucomments = $ucomments ."</td>\n</tr></table>\n";
}
} else {
$ucomments = "No comments have been submitted.";
}
return $ucomments;
}
function getUsersOnline(){
include("dbinfo.php");
include("settings.php");
global $HTTP_SERVER_VARS;
// Set length of session to twenty minutes
define("SESSION_LENGTH", 5);
$userIP = $HTTP_SERVER_VARS["REMOTE_ADDR"];
$sConn = @mysql_connect($dbServer, $dbUser, $dbPass)
or die("Couldnt connect to database");
$dbConn = @mysql_select_db($dbName, $sConn)
or die("Couldnt select database $dbName");
$timeMax = time() - (60 * SESSION_LENGTH);
$result = mysql_query("select count(*) from $r_usersonline where unix_timestamp(dateAdded) >= '$timeMax' and userIP = '$userIP'");
$recordExists = mysql_result($result, 0, 0) > 0 ? true : false;
if(!$recordExists)
{
// Add a record for this user
@mysql_query("insert into $r_usersonline(userIP) values('$userIP')");
}
$query = ("select count(*) from $r_usersonline where unix_timestamp(dateAdded) >= '$timeMax'");
$numguests = mysql_query($query) or die("Select Failed!");
$numguest = mysql_fetch_array($numguests);
return $numguest[0];
}
function getTotpics(){
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$query = ("select count(*) from $r_picuploads");
$numpics1 = mysql_query($query) or die("Select Failed!");
$numpics = mysql_fetch_array($numpics1);
return $numpics[0];
}
function getProfilebox($userid){ //12
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database!";
exit;
}
// GET USERS LAST POSTINGS FIRST
if($preapprove == "0") { $prea = "AND approved = '1' "; }
else {
$prea = "";}
$sql = "select * from $r_picuploads where userid ='$userid' $prea ORDER BY id DESC LIMIT 5";// postings by user
$sql_result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($sql_result)) {
$pid = $row["id"]; // id title userid
$title = $row["title"];
$tempString = $tempString ."<a href=\"$PHP_SELF?showpic=$pid\">$title</a>
";
}
$sql = "select * from $r_users where userid ='$userid'";//user info
$sql_result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($sql_result)) {
$proemail = $row["email"];
$prosex = $row["sex"];
$prohobbies = $row["hobbies"];
$promusic = $row["music"];
$prochat = $row["chat"];
$proupdated = $row["updated"];
$proemailvisible = $row["emailvisible"];
}
if($proemailvisble == "0") { $proemail = "not shown";} // redundent?
if($proemailvisible == "0") {
$proemail = "not shown";
} else {
$proemail = "<a href=\"mailto:$proemail?subject=$title\">$proemail</a>";
}
$profilebox = array("$proemail","$prosex","$prohobbies","$promusic","$prochat","$proupdated","$tempString");
return $profilebox;
}
function getMemberbox($loggedinName,$template){
require('settings.php');
$connection = mysql_connect("$sqlhost","$sqluser","$sqlpass");
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}
$db = mysql_select_db("$sqldb", $connection);
if (!$db) {
echo "Couldn't select database!";
exit;
}
$sql = "select * from $r_messages where touserid ='$loggedinName' AND isread = '0'"; //check messages
$sql_result = mysql_query($sql,$connection);
$totmsgs = 0;
while ($row = mysql_fetch_array($sql_result)) {
$isread = $row["isread"];
$totmsgs++;
}
$content_array = file("$theme/memberbox.html");
$memberbox = implode("", $content_array);
if(isset($loggedinName)) { // IS VISITOR A MEMBER?
$template = str_replace('<:LOGIN:>', "$memberbox", $template);
$template = str_replace('<:LOGOUT:>', "$PHP_SELF?logout=now", $template);
$template = str_replace('<:URPROFILE:>', "$PHP_SELF?yourprofile=on", $template);
$template = str_replace('<:UPLOAD:>', "$PHP_SELF?upload=on", $template);
$template = str_replace('<:FEEDBACK:>', "$PHP_SELF?feedback=on", $template);
$template = str_replace('<:UNREAD:>', "$totmsgs", $template);
$template = str_replace('<:INBOX:>', "$PHP_SELF?inbox=on", $template);
} else {
$content_array = file("$theme/login.html");
$loginform= implode("", $content_array);
$template = str_replace('<:LOGIN:>', "$loginform\n", $template);
}
return $template;
}
function generate() {
$length ="4"; // the length of the password required
$possible = '23456789' .
'abcdefghijkmnpqrstuvwxyz';
// 'ABCDEFGHJKLMNPQRSTUVWXYZ';
$str ="";
while (strlen($str) < $length) {
$str.=substr($possible, (rand() % strlen($possible)),1);
}
return($str);
}