📄 functions.php
字号:
<?php//////////////////////////// COPYRIGHT NOTICE ////////////////////////////////////// This script is part of BosClassifieds, a software application by BosDev, Inc //// Use of any kind of part or all of this script or modification of this //// script requires a license from BosDev, Inc. Use or modification of //// this script without a license constitutes Software Piracy and will //// result in legal action from BosDev, Inc. All rights reserved. //// http://www.bosdev.com sales@bosdev.com //// //// BosClassifieds Copyright 2004, BosDev, Inc. ////////////////////////////////////////////////////////////////////////////////////error_reporting(7);//Prep variablesif(PHP_VERSION < '4.1.0') { $_GET = &$HTTP_GET_VARS; $_POST = &$HTTP_POST_VARS; $_COOKIE = &$HTTP_COOKIE_VARS; $_SERVER = &$HTTP_SERVER_VARS; $_ENV = &$HTTP_ENV_VARS; $_FILES = &$HTTP_POST_FILES; }$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);unset($_REQUEST['insPath'],$_REQUEST['insUrl']);if($_POST['insPath'] != "" || $_GET['insPath'] != "") { die(); }$isMagic = get_magic_quotes_gpc();$typesToRegister = array($_REQUEST);foreach($typesToRegister as $varType) { if(is_array($varType)) { while(list($key,$value) = @each($varType)) { if ($isMagic) { if(!is_array($value)) { $value = stripslashes($value); } } ${$key} = $value; } } }set_magic_quotes_runtime(0);//Get system infofunction getSys ($name) { global $_SERVER,$_ENV; $theVar = ""; if (empty($_SERVER["$name"])) { $_SERVER["$name"]=""; } if (empty($_ENV["$name"])) { $_ENV["$name"]=""; } if(getenv($name) != '') { $theVar = getenv("$name"); } if(($theVar == '') && ($_SERVER["$name"] != '')) { $theVar = $_SERVER["$name"]; } if(($theVar == '') && ($_ENV["$name"] != '')) { $v = $_ENV["$name"]; } return $theVar; }//Find server pathsfunction getPath($new_path="",$levels=0) { $fullpath = getSys("PATH_TRANSLATED"); if (empty($fullpath)) { $fullpath = getSys("SCRIPT_FILENAME"); } if(strstr($fullpath,"\\")) { if($new_path != "") { $new_path = str_replace("/","\\",$new_path); } $fullpath = str_replace("\\\\","\\",$fullpath); for($pathloop=0; $pathloop<=$levels; $pathloop++) { $fullpath = substr($fullpath,0,strrpos($fullpath,"\\")); } if($new_path != "") { $fullpath .= "$new_path\\"; } else { $fullpath = "$fullpath\\"; } } else { for($pathloop=0; $pathloop<=$levels; $pathloop++) { $fullpath = substr($fullpath,0,strrpos($fullpath,"/")); } if($new_path != "") { $fullpath .= "$new_path/"; } else { $fullpath = "$fullpath/"; } } return $fullpath; }//Find URLsfunction getUrl($new_url="",$levels=0) { $server = getSys("SERVER_NAME"); $url = getSys("PHP_SELF"); for($pathloop=0; $pathloop<=$levels; $pathloop++) { $url = substr($url,0,strrpos($url,"/")); } if($new_url != "") { $url .= "$new_url"; } return "http://$server$url"; }//Get thumbnailfunction getThumb($image) { $pos = strrpos($image,"."); $name = substr($image,0,$pos); $ext = strtolower(substr($image,$pos)); $thumb = "{$name}_thumb{$ext}"; return $thumb; }//Update the category countsfunction updateCounts() { global $class_link,$class_prefix; $result = query("UPDATE {$class_prefix}categories SET category_subs=0,category_listings=0",$class_link); $catData = array(); //Get cat parent $result = query("SELECT category_id,category_parent FROM {$class_prefix}categories",$class_link); while(list($catID,$catParent) = mysql_fetch_row($result)) { $catData[$catID]['parent'] = $catParent; $catData[$catParent]['isparent'] = 1; } //Get number of ads $result = query("SELECT ad_category FROM {$class_prefix}ads WHERE ad_status=1",$class_link); while(list($adCategory) = mysql_fetch_row($result)) { $catData[$adCategory]['ads'] = intval($catData[$adCategory]['ads']) + 1; } $result = query("SELECT category_id FROM {$class_prefix}categories WHERE category_parent=0",$class_link); while(list($catID) = mysql_fetch_row($result)) { $passSubs = 0; $passAds = 0; walkCounts($catID,$catData,1); } return true; }function walkCounts($parentCat,$catData,$level) { global $passSubs,$passAds,$class_prefix,$class_link; $passSubs[$level] = 0; $passAds[$level] = 0; if($catData[$parentCat]['isparent'] == 1) { reset($catData); while(list($key,) = each($catData)) { if($catData[$key]['parent'] == $parentCat) { walkCounts($key,$catData,$level + 1); } } } //Running total for($i=1;$i<=$level;$i++) { $passSubs[$i] += 1; $passAds[$i] += $catData[$parentCat]['ads']; } if($catData[$parentCat]['isparent'] != 1) { $listings = intval($catData[$parentCat]['ads']); $result = query("UPDATE {$class_prefix}categories SET category_subs=0,category_listings=category_listings+$listings WHERE category_id=$parentCat",$class_link); } else { $passSubs[$level] = $passSubs[$level] - 1; $result = query("UPDATE {$class_prefix}categories SET category_subs=category_subs+{$passSubs[$level]},category_listings=category_listings+{$passAds[$level]} WHERE category_id=$parentCat",$class_link); $passSubs[$level] = 0; $passAds[$level] = 0; } $level -= 1; }//Get categories in order for dropdownsfunction getCats($par=0,$prev="",$sel="") { global $class_link,$class_prefix,$return; $par = protect($par); $result = query("SELECT category_id,category_title,category_ad_types FROM {$class_prefix}categories WHERE category_parent=$par ORDER BY category_title",$class_link); while(list($gcat_id,$cat_title,$category_ad_types) = mysql_fetch_row($result)) { if($gcat_id == $sel) { $selected = "selected"; } else { $selected = ""; } if($category_ad_types != 0) { if($prev == "") { $return .= "<option value=\"$gcat_id\" $selected>".stripslashes($cat_title)."</option>"; } else { $return .= "<option value=\"$gcat_id\" $selected>$prev".stripslashes($cat_title)."</option>"; } } if($prev != "") { $pass = "$prev{$cat_title}>"; } else { $pass = "$cat_title>"; } getCats($gcat_id,$pass,$sel); } return $return; }//Get categories in order for dropdowns with ad countsfunction getCatsAds($par=0,$prev="",$sel="") { global $class_link,$class_prefix,$return; $par = protect($par); $result = query("SELECT category_id,category_title FROM {$class_prefix}categories WHERE category_parent=$par ORDER BY category_title",$class_link); while(list($gcat_id,$cat_title) = mysql_fetch_row($result)) { $resultc = query("SELECT COUNT(ad_id) FROM {$class_prefix}ads WHERE ad_status=1 AND ad_category=$gcat_id",$class_link); list($ads) = mysql_fetch_row($resultc); if($gcat_id == $sel) { $selected = "selected"; } else { $selected = ""; } $return .= "<option value=\"$gcat_id\" $selected>$prev".stripslashes($cat_title)." ($ads)</option>"; if($prev != "") { $pass = "$prev{$cat_title}>"; } else { $pass = "$cat_title>"; } getCatsAds($gcat_id,$pass,$sel); } return $return; }//Get parentsfunction getTree($theCat=0) { global $SystemOptions,$class_link,$class_prefix,$insPath,$insUrl; while($theCat != 0) { $result = query("SELECT category_id,category_parent,category_title FROM {$class_prefix}categories WHERE category_id=$theCat",$class_link); list($catID,$theCat,$title) = mysql_fetch_row($result); $title = stripslashes($title); if($SystemOptions['spider'] == 1) { $foundPath = "<a class=\"sub_category_link\" href=\"{$insUrl}index.php/cat_id/$catID\">$title</a> ·> $foundPath"; } else { $foundPath = "<a class=\"sub_category_link\" href=\"{$insUrl}index.php?cat_id=$catID\">$title</a> ·> $foundPath"; } } return "<span class=\"sub_category_link\">[ ".substr($foundPath,0,-10)."]</span><br>"; }//Delete a category, with all subcats and ads within itfunction pruneTree($theCat=0) { global $SystemOptions,$class_link,$class_prefix,$insPath; $result = query("SELECT category_id FROM {$class_prefix}categories WHERE category_parent=$theCat",$class_link); if(mysql_num_rows($result) > 0) { while(list($r_id) = mysql_fetch_row($result)) { $result2 = query("DELETE FROM {$class_prefix}categories WHERE category_id=$r_id",$class_link); $result3 = query("DELETE FROM {$class_prefix}ads WHERE ad_category=$r_id",$class_link); pruneTree($r_id); } } $result4 = query("DELETE FROM {$class_prefix}categories WHERE category_id=$theCat",$class_link); $result5 = query("DELETE FROM {$class_prefix}ads WHERE ad_category=$theCat",$class_link); @unlink("{$insPath}images/categories/$theCat.jpg"); }//Create HTML emailfunction htmlMail($from,$to,$subject,$content) { global $SystemOptions,$Languages; $htmlContent = toHtml($content,1); $normalContent = strip_tags(str_replace("<br clear=\"all\">","\r\n",$content)); $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x".$semi_rand."x"; $headers = "From: $from"; $headers .= "\nMIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative;\n"; $headers .= " boundary=\"{$mime_boundary}\""; if($SystemOptions['language'] == "japanese") { $subject = "=?EUC-JP?B?".base64_encode($subject)."?="; } $message = "This is a multi-part message in MIME format.\n"; $message .= "\n"; $message .= "--{$mime_boundary}\n"; $message .= "Content-Type:text/html; charset=\"{$Languages['global']['charset']}\"\n"; $message .= "Content-Transfer-Encoding: 7bit\n\n"; $message .= "<html><head></head><body>\n"; $message .= $htmlContent."\n"; $message .= "</body></html>\n"; $message .= "\n"; $message .= "--{$mime_boundary}\n"; $message .= "Content-Type:text/plain; charset=\"{$Languages['global']['charset']}\"\n"; $message .= "Content-Transfer-Encoding: 7bit\n"; $message .= "\n"; $message .= $normalContent."\n"; $message .= "\n"; $message .= "--{$mime_boundary}--\n"; if($to != "") { mail($to,$subject,$message,$headers); } return; }//Store statisticsfunction recordUser($type="",$extra="") { global $class_link,$class_prefix; $date = date("Y-m"); if($type == "a") { $result = query("UPDATE {$class_prefix}ads SET ad_views=ad_views+1 WHERE ad_id=$extra",$class_link); } $result = query("SELECT stat_count FROM {$class_prefix}statistics WHERE stat_my LIKE '$date' AND stat_item='$type'",$class_link); list($count) = mysql_fetch_row($result); if($count != "") { $result = query("UPDATE {$class_prefix}statistics SET stat_count=stat_count+1 WHERE stat_my LIKE '$date' AND stat_item='$type'",$class_link); } else { $result = query("INSERT INTO {$class_prefix}statistics VALUES('$date','$type',1)",$class_link); } }function processImage($file,$type=0) { global $SystemOptions,$insPath; //Set maximum image size and path if($type == 0) { $maxSize = $SystemOptions['max_size']; $thumbSize = 100; $filePath = "{$insPath}images/listings/"; } else { $maxSize = 50; $filePath = "{$insPath}images/categories/"; } //Check to see if there is a file with the same name already, if so rename it $file['name'] = str_replace(array('<', '>', '"',' ','#'),array('<', '>', '"','',''),preg_replace('/&(?!' . ($entities ? '#[0-9]+' : '(#[0-9]+|[a-z]+)') . ';)/si','&', $file['name'])); $nameParts = explode(".",$file['name']); if(file_exists("{$filePath}{$nameParts[0]}.jpg")) { for($i=1;$i<=100;$i++) { if(!file_exists("{$filePath}{$nameParts[0]}$i.jpg")) { if($type == 0) { $newFileName = "{$nameParts[0]}{$i}.jpg"; $newSmallFileName = "{$nameParts[0]}{$i}_small.jpg"; $newThumbName = "{$nameParts[0]}{$i}_thumb.jpg"; } else { $newFileName = "{$nameParts[0]}{$i}.jpg"; $newSmallFileName = "{$nameParts[0]}{$i}.jpg"; } break; } } } else { if($type == 0) { $newFileName = "{$nameParts[0]}.jpg"; $newSmallFileName = "{$nameParts[0]}_small.jpg"; $newThumbName = "{$nameParts[0]}_thumb.jpg"; } else { $newFileName = "{$nameParts[0]}.jpg"; $newSmallFileName = "{$nameParts[0]}.jpg"; } } //Move the file so we can work on it @move_uploaded_file($file['tmp_name'],"{$filePath}{$newFileName}"); @chmod("{$filePath}{$newFileName}",0755); //Check to ensure it's an image we can work with $imageData = @getimagesize("{$filePath}{$newFileName}"); if($imageData[0] > 0) { //Resize the image, process main so it's a jpg resizeImage("{$filePath}{$newFileName}","{$filePath}{$newFileName}",100000000); resizeImage("{$filePath}{$newFileName}","{$filePath}{$newSmallFileName}",$maxSize); if($type == 0) { resizeImage("{$filePath}{$newFileName}","{$filePath}{$newThumbName}",$thumbSize); } return $newFileName; } else { //Not a valid image, remove the file and return a blank @unlink("{$filePath}{$newFileName}"); $newThumbName = ""; return $newThumbName; } }function resizeImage($orig,$new,$maxSize) { //Get the file info $imageData = @getimagesize($orig); //Check to see if we need to resize it, based on the max width above $new_width = $imageData[0]; $new_height = $imageData[1]; if($imageData[0] > $maxSize || $imageData[1] > $maxSize) { //Set the new file size if($imageData[0] > $imageData[1]) { $ratio = ( $imageData[0] > $maxSize ) ? (real)($maxSize / $imageData[0]) : 1 ; $new_width = $maxSize; $new_height = ((int)($imageData[1] * $ratio)); } else { $ratio = ( $imageData[1] > $maxSize ) ? (real)($maxSize / $imageData[1]) : 1 ; $new_width = ((int)($imageData[0] * $ratio)); $new_height = $maxSize; } } else { //No need to resize $new_width = $imageData[0]; $new_height = $imageData[1]; } //Create new source file switch($imageData[2]) { case 1: $srcImg = ImageCreateFromGif($orig); break; case 2: $srcImg = ImageCreateFromJpeg($orig); break; case 3: $srcImg = ImageCreateFromPng($orig); break; } if(@function_exists("ImageCreateTrueColor")) { if(!@$newID = ImageCreateTrueColor($new_width,$new_height)) { $newID = @ImageCreate($new_width,$new_height); } } else { $newID = @ImageCreate($new_width,$new_height); } if(@function_exists("imageCopyResampled")) { if(!@ImageCopyResampled($newID,$srcImg,0,0,0,0,$new_width,$new_height,$imageData[0],$imageData[1])) { @ImageCopyResized($newID,$srcImg,0,0,0,0,$new_width,$new_height,$imageData[0],$imageData[1]); } } else { @ImageCopyResized($newID,$srcImg,0,0,0,0,$new_width,$new_height,$imageData[0],$imageData[1]); } //Write new file @ImageJPEG($newID,$new,70); @chmod($new,0755); }//Strip unwanted HTMLfunction stripHtml($text) { $stripedText = strip_tags($text,"<b></b><i></i><u></u><a>"); return $stripedText; }//Convert markups to HTML for displayfunction toHtml($text,$isMail=0) { // Stripslashes $text = stripslashes($text); if($isMail == 0) { //Replace ' " ` $text = str_replace("
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -