/*$sn=session_name();
if(isset($_GET[$sn])) if(strlen($_GET[$sn])!=32) unset($_GET[$sn]);
if(isset($_POST[$sn])) if(strlen($_POST[$sn])!=32) unset($_POST[$sn]);
if(isset($_COOKIE[$sn])) if(strlen($_COOKIE[$sn])!=32) unset($_COOKIE[$sn]);
if(isset($PHPSESSID)) if(strlen($PHPSESSID)!=32) unset($PHPSESSID);*/
session_start();
/*if(!isset($_SESSION["ava_session"]) || !isset($_SESSION["ava_page"]))
{
$ava_session = md5(uniqid(rand(), true)) ;
$_SESSION["ava_session"] = $ava_session ;
$_SESSION["ava_page" ] = "www.ava.vn" ;
}*/
//unset($_SESSION["ava_session"]) ;
?>
$id1="l11";
$id2="l12";
$id3="l13";
$id4="l14";
$id5="l15";
$id6="l16";
if($ava=="dichvu") $id2="current";
elseif($ava=="register-checkout") $id3="current";
elseif($ava=="khuyenmai") $id4="current";
elseif($ava=="contactus") $id6="current";
else $id1="current";
?>
Deprecated: Call-time pass-by-reference has been deprecated in /home/ava/domains/ava.vn/public_html/include/classtemplate.php on line 20
Deprecated: Call-time pass-by-reference has been deprecated in /home/ava/domains/ava.vn/public_html/include/classtemplate.php on line 61
Deprecated: Call-time pass-by-reference has been deprecated in /home/ava/domains/ava.vn/public_html/include/classtemplate.php on line 81
Deprecated: Call-time pass-by-reference has been deprecated in /home/ava/domains/ava.vn/public_html/include/classtemplate.php on line 81
Deprecated: Call-time pass-by-reference has been deprecated in /home/ava/domains/ava.vn/public_html/include/classtemplate.php on line 245
Deprecated: Call-time pass-by-reference has been deprecated in /home/ava/domains/ava.vn/public_html/include/classtemplate.php on line 260
//20060829
//20070725
//-option2text
//20071101
//-repairprefix($data, $needprefix)
function adddot($blockname)
{
if ($blockname)
if ($blockname[strlen($blockname)-1]!=".") $blockname .= "." ;
return $blockname ;
}
function option2text($value, $option1, $value1, $option2, $value2)
{
if ($value == $value1)
return $option1 ;
elseif ($value == $value2)
return $option2 ;
}
function refinetextview($value)
{
if ($value==='') return "''" ;
elseif (($value==='NULL') || ($value==='null') || ($value==='Null')) return "(null)" ;
else return $value ;
}
function isnull($value)
{
if (($value===NULL) || ($value==='NULL') || ($value==='null'))
return true ;
else
return false ;
}
function refineimagename($imagename)
{
for ($i=0; $i', '\n', $value) ;
$value = str_replace('
' , '\n', $value) ;
$value = str_replace('
' , '\n', $value) ;
return $value ;
}
function is_email_valid($email)
{
if(eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $email)) return TRUE;
else return FALSE;
}
function isinteger($value)
{
if (isset($value))
{
if ((strlen($value)>=1) && is_numeric($value))
{
return true ;
}
}
return false ;
}
function isgreaterzerointeger($value)
{
if (isinteger($value))
{
if ($value>0)
return true ;
}
return false ;
}
function stringmaxlength($myvalue)
{
$maxstrlen = 12 ;
if (strlen($myvalue)>$maxstrlen)
{
$myvalue = substr($myvalue, 0, $maxstrlen)."..." ;
}
return $myvalue ;
}
function add2list(&$list, $value)
{
if ($value)
{
if ($list != "") $list .= "," ;
$list .= $value ;
}
return $list ;
}
function refinedatabasedatetime($value)
{
return $value ;
}
function refineformchecked($value)
{
if (isset($value))
{
if (strlen($value)==1)
{
if (($value==1)) return " checked ";
}
}
return "" ;
}
function refineformimagechecked($value, $imagecheck, $imagecheckoff)
{
if (isset($value))
{
if (strlen($value)==1)
{
if (($value==1)) return $imagecheck;
}
}
return $imagecheckoff ;
}
function refineformischecked($checkvalue, $checked)
{
$checkvalue = parseanynoyes2value($checkvalue) ;
$checked = parseanynoyes2value($checked) ;
//echo "$checkvalue = $checked" ;
if ($checkvalue==$checked) return " checked " ;
else return "" ;
}
function parseanynoyes2value($value)
{
if (isset($value))
{
if (strlen($value)==1)
{
if (($value==0) or ($value==1)) return $value;
}
}
return -1;
}
function refinedatabasetext($value)
{
$value = str_replace('\\"', """, $value);
$value = str_replace("\\'", "'", $value);
/*
$value = eregi_replace('"', """, $value);
$value = eregi_replace("'", "'", $value);
*/
$value = addslashes($value);
return $value ;
}
function refineformtext($value)
{
$value = stripslashes($value);
$value = eregi_replace('"', "'", $value) ;
$value = eregi_replace("'" , "'" , $value) ;
return $value ;
}
/*
function refinedatabasevarchar($value)
{
return refinedatabasetext($value) ;
}
*/
function refinedatabaseVARCHAR($value)
{
return refinedatabasetext($value) ;
}
function refinedatabaseDESCRIPTION($value)
{
return refinedatabasetext($value) ;
}
function refinedatabaseTEXTAREA($value)
{
return refineline(nl2br(refinedatabasetext($value))) ;
}
function refinedatabaseDOUBLE($value)
{
return refinedatabasezerointeger($value) ;
}
function refineformINTZEROUP($value)
{
return refinezerointeger($value) ;
}
function refineformDOUBLE($value)
{
return refinedatabasezerointeger($value) ;
}
function refineformVARCHAR($value)
{
return refinedatabasetext($value) ;
}
function refineformDESCRIPTION($value)
{
return refinedatabasetext($value) ;
}
function hidezero($value)
{
if ($value==0)
{
$value = "" ;
}
return $value ;
}
function refinedatabaseintzeroup($value)
{
return refinezerointeger($value) ;
}
function refinedatabasezerointeger($value)
{
return refinezerointeger($value) ;
}
function refinezerointeger($value)
{
if (isset($value))
{
if ((strlen($value)>=1) && is_numeric($value))
{
if ($value>0) return $value ;
}
}
return 0 ;
}
function refinedatabasecheckbox($value)
{
if (isset($value))
{
if (strlen($value)==1)
{
if (($value==0) or ($value==1)) return $value ;
}
}
return 0 ;
}
//0 1 NULL
function refinedatabaseanynoyes($value)
{
if (isset($value))
{
if (strlen($value)==1)
{
if (($value==0) or ($value==1)) return $value;
}
}
return 'NULL' ;
}
// 1 co 2 khong 3 bat ky
function refinedatabase3value($value)
{
if (isset($value))
{
if ((strlen($value)==1) && is_numeric($value))
{
if (($value==1) or ($value==2) or ($value==3)) return $value;
}
}
return 3 ;
}
//length : ??
//format :
//- remove "
//- replace ' with quote
function refinetext($value)
{
$value = stripslashes($value);
$value = eregi_replace('"', """, $value);
$value = eregi_replace("'", "'", $value);
return $value ;
}
function refineline($value)
{
$value = str_replace(chr(10), "", $value);
$value = str_replace(chr(13), "", $value);
return $value ;
}
function refinetinyint($value)
{
return $result ;
}
//length: ??
//format: -8..8+
function refinefloat($value)
{
return $result ;
}
//length : 1
//format : 0 / 1
function refineboolean($value)
{
return $result ;
}
//length : 14
//format : yyyymmddhhmmss
function refinedate($value)
{
return $result ;
}
//input : dd/mm/yyyy
//output : yyyy-mm-dd
function ConvertDMY2YMD($Date)
{
list($day, $month, $year) = split('[/.]', $Date);
if (($day) && ($month) && ($year))
{
$MyDate = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year)) ;
}
else
{
$MyDate = date("Y-m-d", time()) ;
}
return $MyDate ;
}
function ConvertDate2DMY($Date)
{
list($year, $month, $day) = split('[-.]', $Date);
if (($year) && ($month) && ($day))
{
if (($year>0) && ($month>0) && ($day>0))
{
//echo $year."-".$month."-".$day ;
$MyDate = date("d/m/Y", mktime(0, 0, 0, $month, $day, $year)) ;
}
}
return $MyDate ;
}
function ConvertTextDMY2Timestamp($Date, $splitchar="/")
{
$result = 0 ;
list($day, $month, $year) = split('['.$splitchar.'.]', $Date);
if (($year) && ($month) && ($day))
{
if (($year>0) && ($month>0) && ($day>0) && ($year>1900) & ($year<=2010) & ($month>=1) & ($month<=12) & ($day>=1) & ($day<=31))
{
//echo "0, 0, 0, $month, $day, $year" ;
//exit() ;
$result = @mktime(0, 0, 0, $month, $day, $year) ;
if ($result<0) $result = time() ;
}
}
return $result ;
}
function MakeTimestamp($second, $minute, $hour, $day, $month, $year)
{
return mktime($hour, $minute, $second, $month, $day, $year) ;
}
function ConvertTimestamp2TextDM($Timestamp, $splitchar="/")
{
return date("d".$splitchar."m", $Timestamp) ;
}
function ConvertTimestamp2TextDMY($Timestamp, $splitchar="/")
{
$Timestamp = $Timestamp<0?time():$Timestamp ;
return date("d".$splitchar."m".$splitchar."Y", $Timestamp) ;
}
function ConvertTimestamp2TextDMYHMS($Timestamp, $splitchar="/")
{
$dayofweek = array(
"0"=>"Chủ nhật",
"1"=>"Thứ 2",
"2"=>"Thứ 3",
"3"=>"Thứ 4",
"4"=>"Thứ 5",
"5"=>"Thứ 6",
"6"=>"Thứ 7"
);
return date("d".$splitchar."m".$splitchar."Y-h:i ", $Timestamp).$dayofweek[@date("w", $Timestamp)] ;
}
function getcurrentdateparts(&$newsdatedayofweek,
&$newsdateday, &$newsdatemonth, &$newsdateyear,
&$newsdatehour, &$newsdateminute)
{
$currenttime = time() + (7*60*60) ;
$newsdatedayofweek = gmdate("D", $currenttime) ;
$newsdateday = gmdate("d", $currenttime) ;
$newsdatemonth = gmdate("m", $currenttime) ;
$newsdateyear = gmdate("Y", $currenttime) ;
$newsdatehour = gmdate('h', $currenttime) ;
$newsdateminute = gmdate('i', $currenttime) ;
}
function ConvertDateSystem2DMY($Date)
{
return date("d/m/Y", strtotime($Date)) ;
}
function ConvertVarchar2DMY($Date)
{
return date("d/m/Y", $Date) ;
}
function CurrentDateDMY()
{
return date("d/m/Y", time()) ;
}
function DateAdd($date, $numofday, $format="Y-m-d")
{
return date($format,strtotime($numofday." days",strtotime($date)));
}
function DateCompare($date1, $date2)
{
$time1 = strtotime($date1) ;
$time2 = strtotime($date2) ;
return ($time1<$time2?-1:($time1==$time2?0:1)) ;
}
function convertcomma2list($commalist)
{
return split(",", $commalist) ;
}
function AfterTax($value, $tax)
{
return doubleval($value)+(doubleval($value)*doubleval($tax)/100) ;
}
function BeforeTax($value, $tax)
{
return doubleval($value)*100/(doubleval($tax)+100) ;
}
function AfterDiscount($value, $discount)
{
return round(doubleval($value)-(doubleval($value)*doubleval($discount)/100),2);
}
function ChangeLocation($location)
{
echo "
";
}
function stringpad($data, $length, $pad)
{
$datalen = strlen($data) ;
if ($datalen<$length)
{
for ($i=0; $i<($length-$datalen); $i++)
{
$data .= $pad ;
}
}
return $data ;
}
/*
function getsecond()
{
return time()/60 ;
}
*/
function getminute()
{
return intval(time()/60) ;
}
function daydiffbetween2date($date1, $date2)
{
$day1 = $date1/(60*60*24) ;
$day2 = $date2/(60*60*24) ;
return $day2-$day1 ;
}
function repairprefix($data, $needprefix)
{
if ($data)
{
$temp = substr($data, 0, strlen($needprefix)) ;
if ($temp == $needprefix) return $data ;
else return $needprefix.$data ;
}
}
function convertbyte2string($bytestr, $mb, $kb, $bytes)
{
if ($bytestr>=1000000)
{
return number_format(intval($bytestr/1000000), 0, '', ',').$mb ;
}
elseif($bytestr>=1000)
{
return number_format(intval($bytestr/1000), 0, '', ',').$kb ;
}
else
{
return number_format($bytestr, 0, '', ',').$bytes ;
}
}
?>
//created by tuanpro - www.ava.vn
//20070822
//20071027
//-add getandresizeflash
//-modify getimageinformation
function concatfolder($parentpath, $sonpath)
{
$result = $parentpath ;
if ($result)
{
if ($result[strlen($result)-1] != "/") $result = $result."/" ;
}
$result = $result.$sonpath ;
return $result ;
}
function parsenameandext($nameext, &$name, &$ext)
{
$basename = basename($nameext) ;
$dotpos = strrpos($basename, ".") ;
$name = substr($basename, 0 , $dotpos) ;
$ext = substr($basename, $dotpos+1, strlen($basename)-$dotpos) ;
}
function parsefilepath($filepath, &$path, &$name, &$ext)
{
$slashpos = strrpos($filepath, "/") ;
$path = substr($filepath, 0, $slashpos) ;
$basename = basename($filepath) ;
$dotpos = strpos($basename, ".") ;
$name = substr($basename, 0 , $dotpos) ;
$ext = substr($basename, $dotpos+1, strlen($basename)-$dotpos) ;
//echo "[".$path."-".$basename."-".$name."-".$ext."-".$dotpos."]" ;
}
function revertslash($filepath)
{
return str_replace("\\", "/", $filepath) ;
}
function removeafterquestionmark($filepath)
{
$pos = strpos($filepath, "?") ;
if ($pos === false) return $filepath ;
else return substr($filepath, 0, $pos-1) ;
}
function addlastslash($url)
{
if ($url)
{
if ($url[strlen($url)-1] != "/") $url = $url."/" ;
}
return $url ;
}
function useimagesmallorcreateitanduse($filename, $smallpattern, $maxwidth, $maxheight, $imagefolder, &$smallwidth, &$smallheight, $filterchars=0, $flagimagefix=false, $flagimageexpand=false, $backgroundcolor=false)
{
$imagesrc = "" ;
$smallfilename = getsmallfilename($filename, $smallpattern, $filterchars) ;
//echo "[[[smallfilename : $smallfilename]]]
" ;
if (getimageinformation($smallfilename, &$smallwidth, &$smallheight))
$imagesrc = $smallfilename ;
else
{
/*
echo "
" ;
echo "[".$filename."]
" ;
echo "[[$maxwidth - $maxheight]]
" ;
*/
//echo "[[[smallfilename : $smallfilename]]]
" ;
$classimage = new CLASSIMAGE($filename, $imagefolder, $smallpattern, $filterchars) ;
if ($classimage->loadresizedeleteandcache($maxwidth, $maxheight, &$smallwidth, &$smallheight, $flagimagefix, $flagimageexpand, $backgroundcolor))
$imagesrc = $smallfilename ;
}
return $imagesrc ;
}
function checkbmpimage($filename, $maxwidth, $maxheight, &$imagesrc, &$optionwidth, &$optionheight, $flagimagefix=false)
{
$optionwidth = 0 ;
$optionheight = 0 ;
if ($filename)
{
$imagename = basename($filename) ;
if (strlen($imagename)>=5)
{
$secondpart = substr($imagename, -3) ;
if ($secondpart == "bmp")
{
if (resizeimage($filename, &$width, &$height, &$optionwidth, &$optionheight, $maxwidth, $maxheight, $flagimagefix))
{
$imagesrc = $filename ;
return true ;
}
}
}
}
return false ;
}
function filterfilename($filenamepart)
{
return preg_replace("/[^a-zA-Z0-9. _-]/", "", $filenamepart) ;
}
function parsefilename($filename, &$filefolder, &$firstpart, &$secondpart, $filterchars=0)
{
$filefolder = "" ;
$firstpart = "" ;
$secondpart = "" ;
if ($filename)
{
$filefolder = str_replace("\\", "/", dirname($filename)) ;
//echo "
".$filename."-".strlen($filename)."-".strlen($filefolder)."-".$filefolder."
" ;
if (($filefolder{strlen($filefolder)-1}!="/") && (strlen($filefolder)>=1)) $filefolder .= "/" ;
$namewithoutfolder = basename($filename) ;
if ($filterchars) $namewithoutfolder = filterfilename($namewithoutfolder) ;
//echo $namewithoutfolder."
" ;
if (strlen($namewithoutfolder)>=5)
{
$pointpos = strrpos($namewithoutfolder, ".") ;
$pointpos = $pointpos===false?strlen($namewithoutfolder):$pointpos ;
$firstpart = substr($namewithoutfolder, 0, $pointpos) ;
$secondpart = substr($namewithoutfolder, $pointpos+1, strlen($namewithoutfolder)) ;
return true ;
}
}
return false ;
}
function getsmallfilename($filename, $pattern, $filterchars=0)
{
if (parsefilename($filename, &$filefolder, &$firstpart, &$secondpart, $filterchars))
{
return $filefolder.$firstpart.$pattern.".jpg" ;
}
}
function deletefile($filename)
{
if (@is_file($filename))
{
if (@unlink($filename)) return true ;
return false ;
}
return 0 ;
}
function deletefilesmalloffilename($filename, $pattern, $filterchars=0)
{
$smallfile = getsmallfilename($filename, $pattern, $filterchars) ;
return deletefile($smallfile) ;
}
function deleteallsmallfilesoffilename($filename, $filterchars=0)
{
if (parsefilename($filename, &$filefolder, &$firstpart, &$secondpart, $filterchars))
{
$files = @glob($filefolder.$firstpart."*.*") ;
if ($files)
{
foreach ($files as $fileone)
{
deletefile($fileone);
}
}
}
}
function getandresizeflash($flashfile, $maxwidth, $maxheight, &$newwidth, &$newheight, $flagimagefix=false)
{
$newwidth = 0 ;
$newheight = 0 ;
if (getimageinformation($flashfile, &$width, &$height))
{
convertimagesize(&$width, &$height, $maxwidth, $maxheight, $flagimagefix) ;
$newwidth = $width ;
$newheight = $height ;
return true ;
}
return false ;
}
function getimageinformation($imagefile, &$width, &$height)
{
$width = 0 ;
$height = 0 ;
if (@is_file($imagefile))
{
list($width, $height) = @getimagesize($imagefile);
return true ;
}
return false ;
}
function convertimagesize(&$width, &$height, $maxwidth, $maxheight, $fix=false)
{
//echo "&$width, &$height, $maxwidth, $maxheight, $fix=false
" ;
if ($fix)
{
if ($maxwidth != 0 && $maxheight ==0)
{
$height = round($height * ($maxwidth / $width));
$width = $maxwidth;
}
elseif ($maxwidth == 0 && $maxheight !=0)
{
$width = round($width * ($maxheight / $height));
$height = $maxheight;
}
elseif ($maxwidth != 0 && $maxheight !=0)
{
$width = $maxwidth ;
$height = $maxheight ;
//echo "XXX>>> &$width, &$height, $maxwidth, $maxheight, $fix=false
" ;
return ;
}
}
else
{
if ($width > $maxwidth && $maxwidth !=0)
{
$height = round($height * ($maxwidth / $width));
$width = $maxwidth;
}
if ($height > $maxheight && $maxheight !=0)
{
$width = round($width * ($maxheight / $height));
$height = $maxheight;
}
}
//echo ">>> &$width, &$height, $maxwidth, $maxheight, $fix=false
" ;
//echo $width."XXXXXXX".$height."
" ;
}
function imageresize($imagefolder, $imagename, $maxwidth, $maxheight, &$width, &$height, $flagimagefix=false)
{
$width = 0 ;
$height = 0 ;
$imagefile = $imagefolder.$imagename ;
if (getimageinformation($imagefile, &$w, &$h))
{
$width = $w ;
$height = $h ;
convertimagesize(&$w, &$h, $maxwidth, $maxheight, $flagimagefix) ;
return "thumbnails.php?src=".$imagefile."&w=".$w."&h=".$h."&iar=1&bw=0" ;
}
else
return "images/no-image1.gif" ;
}
function resizeimage($imagefile, &$width, &$height, &$resizedwidth, &$resizedheight, $maxwidth=150, $maxheight=150, $flagimagefix=false)
{
$width = 0 ;
$height = 0 ;
$resizedwidth = 0 ;
$resizedheight = 0 ;
if (getimageinformation($imagefile, &$width, &$height))
{
$resizedwidth = $width ;
$resizedheight = $height ;
convertimagesize(&$resizedwidth, &$resizedheight, $maxwidth, $maxheight, $flagimagefix) ;
return true ;
}
return false ;
}
function ResizeImageTag($imagefile, &$width, &$height, &$resizedwidth, &$resizedheight, $maxwidth=150, $maxheight=150, $tagattribute="", $flagimagefix=false)
{
$result = resizeimage($imagefile, &$width, &$height, &$resizedwidth, &$resizedheight, $maxwidth, $maxheight, $flagimagefix) ;
if ($result)
return "";
else
return "" ;
}
function ResizeImageTemplate($imagefile, &$template, $blockdotted="", $maxwidth=150, $maxheight=150, $flagimagefix=false)
{
$result = resizeimage($imagefile, &$width, &$height, &$resizedwidth, &$resizedheight, $maxwidth, $maxheight, $flagimagefix) ;
if ($result)
{
$template($blockdotted."filename", $imagefile ) ;
$template($blockdotted."width" , $resizedwidth ) ;
$template($blockdotted."height" , $resizedheight) ;
}
}
function refineresizepic($imagename, $imagefolder, &$picture, &$openimage, $maxwidth=150, $maxheight=150, $maxwidth2open=150)
{
$picture = "" ;
$openimage = "" ;
if ($imagename != NULL)
{
$imagefile = $imagefolder.$imagename ;
if (getimageinformation($imagefile, &$width, &$height))
{
if($width>$maxwidth2open)
$openimage = "";
$picture = ResizeImageTag($imagefile, &$width, &$height, &$resizedwidth, &$resizedheight, $maxwidth, $maxheight, "");
}
}
}
function uploadimage($imagefile, $imagesize, $imagetemp, $imagefolder, $messagenoimage)
{
if ($imagefile != "")
{
$ishttp = substr_count($imagefile, "http://") ;
if($imagesize > 5000000)
{
echo "File size is bigger than 5MB!";
exit;
}
//http://www.linh.com/tuan.jpg
if ($ishttp==0)
{
//echo "[".$imagefile."]
" ;
$newimagename = randomimagefile($imagefile);
$destinationfile = $imagefolder.$newimagename ;
echo "new file : ".$destinationfile."
" ;
@move_uploaded_file($imagetemp, $destinationfile."2")
or die("No copy!");
@rename($destinationfile."2", $destinationfile) ;
}
else // ishttp
{
$newimagename = randomimagefile() ;
$fd = fopen ($imagefile, "r");
if ($fd)
{
$buffer="";
$total ="";
while (!feof ($fd))
{
$buffer = fgets($fd, 4096);
$total .= $buffer;
}
$filename = $imagefolder.$newimagename;
$pos = strpos($imagefile, ".jpg");
if ($pos>0)
{
$filename .= ".jpg" ;
$newimagename .= ".jpg" ;
$fdw = fopen ($filename, "w"); // $saveto se la /image/tenfilerandom.jpg
}
$pos = strpos($imagefile, ".gif");
if ($pos>0)
{
$filename .= ".gif";
$img2_name .=".gif";
$fdw = fopen ($filename, "w"); // $saveto se la /image/tenfilerandom.jpg
}
fclose($fd);
fwrite($fdw,$total);
fclose($fdw);
}
}
}
else
{
echo ($messagenoimage);
}
return $newimagename ;
}
function randomimagefile($filename="")
{
return rand(50,96)."_".time()."_".rand(1019,9999991)."_".$filename;
}
function uploadfile($filename, $filetemp, $folder)
{
$filenew = $folder.randomimagefile($filename) ;
@move_uploaded_file($filetemp, $filenew) or die("Không upload lên được hãy kiểm tra lại file!");
return $filenew ;
}
function getrealfilesize($filename)
{
$fh = fopen($filename, "rb") ;
$fstat = fstat($fh) ;
fclose($fh) ;
return $fstat['size'] ;
}
?>
/*
created by tuanpro - Nguyen Anh Tuan
email : tuanpro@gmail.com
created date : 2007-03-13
Ref : DHKold
Func : ImageCreateFromBMP
Posted on php.net
modified date :
- 20070822
*/
class CLASSIMAGE
{
var $image = '' ;
var $temp = '' ;
var $sourceimagefile = '' ;
var $cacheimagefile = '' ;
var $cachefolder = '' ;
var $imageext = '' ;
var $imagename = '' ;
function CLASSIMAGE($sourceimagefile, $cachefolder, $pattern="_small", $filterchars=0) //or withxheight_small
{
$this->classimagesetup($sourceimagefile, $cachefolder, $pattern, $filterchars) ;
}
function classimagesetup($sourceimagefile, $cachefolder, $pattern="_small", $filterchars=0)
{
$this->sourceimagefile = $sourceimagefile ;
$this->cachefolder = $cachefolder ;
if (strlen($sourceimagefile)>4)
{
parsefilename($sourceimagefile, &$filefolder, &$firstpart, &$secondpart, $filterchars) ;
$this->imagename = $firstpart ;
$this->imageext = strtolower($secondpart) ;
$this->cacheimagefile = $this->cachefolder.$this->imagename.$pattern.".jpg" ;
}
}
function existsourceimage()
{
if (@is_file($this->sourceimagefile)) return true ;
return false ;
}
function existcacheimage()
{
if ((@is_file($this->cacheimagefile)) && ($this->cachefolder))
return true ;
return false ;
}
function isimage()
{
if (($this->imageext == "gif") || ($this->imageext == "jpg") || ($this->imageext == "jpeg") || ($this->imageext == "png") || ($this->imageext == "bmp"))
return true ;
return false ;
}
function loadimageone()
{
if ($this->isimage())
{
$this->image = "" ;
if ($this->imageext == "gif") $this->image = @ImageCreateFromGIF ($this->sourceimagefile) ;
elseif ($this->imageext == "jpg" || $this->imageext == "jpeg") $this->image = @ImageCreateFromJPEG($this->sourceimagefile) ;
elseif ($this->imageext == "png") $this->image = @ImageCreateFromPNG ($this->sourceimagefile) ;
elseif ($this->imageext == "bmp") $this->image = @$this->ImageCreateFromBMP ($this->sourceimagefile) ;
if ($this->image) return true ;
}
return false ;
}
function loadimage()
{
$result = $this->loadimageone() ;
if (!$result)
{
$this->imageext = $this->getrealfiletype() ;
if ($this->imageext)
$result = $this->loadimageone() ;
}
return $result ;
}
function getrealfiletype()
{
$file = @fopen($this->sourceimagefile, 'r');
$data = @fread($file, 10);
@fclose($file);
if (($data) && (strlen($data)==10))
{
if (substr($data, -4 ) == "JFIF") return "jpg" ;
if (substr($data, 0, 3) == "GIF" ) return "gif" ;
if (substr($data, 0, 3) == "PNG" ) return "png" ;
}
}
function loadresizedeleteandcache($width, $height, &$newwidth, &$newheight, $flagimagefix=false, $flagimageexpand=false, $backgroundcolor=false)
{
//echo $this->cacheimagefile."-".$this->existsourceimage()."-".$this->isimage()."
" ;
if (($this->existsourceimage()) && ($this->isimage()))
{
if ($this->loadimage())
{
$this->resize($width, $height, &$newwidth, &$newheight, true, false, $flagimagefix, $flagimageexpand, $backgroundcolor) ;
$this->deleteimage($this->cacheimagefile) ;
$this->store ($this->cacheimagefile) ;
//echo $this->cacheimagefile ;
return true ;
}
}
return false ;
}
function loadresizeandshow($resize=0, $width=100, $height=100)
{
if (($this->existsourceimage()) && ($this->isimage()))
{
if ($this->loadimage())
{
if ($resize) $this->resize($width, $height) ;
$this->show() ;
return true ;
}
}
return false ;
}
function deleteimage($imagefile)
{
if (@is_file($imagefile))
{
@unlink($imagefile) ;
}
}
function color2rgb($color, &$red, &$green, &$blue)
{
$red = 0 ;
$green = 0 ;
$blue = 0 ;
if ($color)
{
if ($color[0] == '#') $color = substr($color, 1, strlen($color)-1) ;
$colordec = hexdec($color) ;
$red = 0xFF & ($colordec >> 0x10) ;
$green = 0xFF & ($colordec >> 0x8 ) ;
$blue = 0xFF & $colordec ;
}
}
function resize($maxwidth, $maxheight, &$newwidth, &$newheight, $aspectradio = true, $allowoveroldsize = false, $flagimagefix=false, $flagimageexpand=false, $backgroundcolor=false)
{
$o_wd = imagesx($this->image);
$o_ht = imagesy($this->image);
$newwidth = $o_wd ;
$newheight = $o_ht ;
//echo "before [[$o_wd - $o_ht]][".$newwidth."-".$newheight."][".$maxwidth."-".$maxheight."]
" ;
if(isset($aspectradio)&&$aspectradio)
{
if (!$allowoveroldsize)
{
if ($flagimageexpand)
{
convertimagesize(&$newwidth, &$newheight, $maxwidth, $maxheight, false) ;
}
else
{
convertimagesize(&$newwidth, &$newheight, $maxwidth, $maxheight, $flagimagefix) ;
}
}
}
//echo "after [[$o_wd - $o_ht]][".$newwidth."-".$newheight."][".$maxwidth."-".$maxheight."]
" ;
if ($flagimageexpand)
{
$this->tempstep0 = imageCreateTrueColor($newwidth, $newheight) ;
imageCopyResampled(
$this->tempstep0, $this->image,
0, 0, 0, 0,
$newwidth, $newheight,
$o_wd , $o_ht) ;
$this->temp = imageCreateTrueColor($maxwidth, $maxheight) ;
if ($backgroundcolor !== false)
{
imagefill($this->temp, 0, 0, hexdec($backgroundcolor[0]=='#'?substr($backgroundcolor, 1, strlen($backgroundcolor)-1):$backgroundcolor)) ;
}
$posx = 0 ;
$posy = 0 ;
if ($maxwidth >$newwidth ) $posx = intval(($maxwidth -$newwidth )/2) ;
if ($maxheight>$newheight) $posy = intval(($maxheight-$newheight)/2) ;
imagecopy(
$this->temp, $this->tempstep0,
$posx, $posy,
0, 0,
$newwidth, $newheight) ;
$newwidth = $maxwidth ;
$newheight = $maxheight ;
//echo "[[[$newwidth, $newheight $o_wd $o_ht]]]
" ;
}
else
{
$this->temp = imageCreateTrueColor($newwidth, $newheight) ;
imageCopyResampled(
$this->temp, $this->image,
0, 0, 0, 0,
$newwidth, $newheight,
$o_wd , $o_ht) ;
}
$this->sync() ;
return;
}
function sync(){
$this->image =& $this->temp;
unset($this->temp);
$this->temp = '';
return;
}
function show(){
$this->_sendHeader();
ImageJPEG($this->image);
return;
}
function _sendHeader(){
header('Content-Type: image/jpeg');
}
function store($file){
ImageJPEG($this->image, $file);
return;
}
function watermark($pngImage, $left = 0, $top = 0){
ImageAlphaBlending($this->image, true);
$layer = ImageCreateFromPNG($pngImage);
$logoW = ImageSX($layer);
$logoH = ImageSY($layer);
ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH);
}
/*********************************************/
/* Fonction: ImageCreateFromBMP */
/* Author: DHKold */
/* Contact: admin@dhkold.com */
/* Date: The 15th of June 2005 */
/* Version: 2.0B */
/*********************************************/
function ImageCreateFromBMP($filename)
{
//Ouverture du fichier en mode binaire
if (! $f1 = @fopen($filename,"rb")) return FALSE;
//1 : Chargement des ent�tes FICHIER
$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1,14));
if ($FILE['file_type'] != 19778) return FALSE;
//2 : Chargement des ent�tes BMP
$BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
'/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1,40));
$BMP['colors'] = pow(2,$BMP['bits_per_pixel']);
if ($BMP['size_bitmap'] == 0) $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
$BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8;
$BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
$BMP['decal'] = ($BMP['width']*$BMP['bytes_per_pixel']/4);
$BMP['decal'] -= floor($BMP['width']*$BMP['bytes_per_pixel']/4);
$BMP['decal'] = 4-(4*$BMP['decal']);
if ($BMP['decal'] == 4) $BMP['decal'] = 0;
//3 : Chargement des couleurs de la palette
$PALETTE = array();
if ($BMP['colors'] < 16777216)
{
$PALETTE = unpack('V'.$BMP['colors'], fread($f1,$BMP['colors']*4));
}
//4 : Cr�ation de l'image
$IMG = fread($f1,$BMP['size_bitmap']);
$VIDE = chr(0);
$res = imagecreatetruecolor($BMP['width'],$BMP['height']);
$P = 0;
$Y = $BMP['height']-1;
while ($Y >= 0)
{
$X=0;
while ($X < $BMP['width'])
{
if ($BMP['bits_per_pixel'] == 24)
$COLOR = unpack("V",substr($IMG,$P,3).$VIDE);
elseif ($BMP['bits_per_pixel'] == 16)
{
$COLOR = unpack("n",substr($IMG,$P,2));
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
elseif ($BMP['bits_per_pixel'] == 8)
{
$COLOR = unpack("n",$VIDE.substr($IMG,$P,1));
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
elseif ($BMP['bits_per_pixel'] == 4)
{
$COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
if (($P*2)%2 == 0) $COLOR[1] = ($COLOR[1] >> 4) ; else $COLOR[1] = ($COLOR[1] & 0x0F);
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
elseif ($BMP['bits_per_pixel'] == 1)
{
$COLOR = unpack("n",$VIDE.substr($IMG,floor($P),1));
if (($P*8)%8 == 0) $COLOR[1] = $COLOR[1] >>7;
elseif (($P*8)%8 == 1) $COLOR[1] = ($COLOR[1] & 0x40)>>6;
elseif (($P*8)%8 == 2) $COLOR[1] = ($COLOR[1] & 0x20)>>5;
elseif (($P*8)%8 == 3) $COLOR[1] = ($COLOR[1] & 0x10)>>4;
elseif (($P*8)%8 == 4) $COLOR[1] = ($COLOR[1] & 0x8)>>3;
elseif (($P*8)%8 == 5) $COLOR[1] = ($COLOR[1] & 0x4)>>2;
elseif (($P*8)%8 == 6) $COLOR[1] = ($COLOR[1] & 0x2)>>1;
elseif (($P*8)%8 == 7) $COLOR[1] = ($COLOR[1] & 0x1);
$COLOR[1] = $PALETTE[$COLOR[1]+1];
}
else
return FALSE;
imagesetpixel($res,$X,$Y,$COLOR[1]);
$X++;
$P += $BMP['bytes_per_pixel'];
}
$Y--;
$P+=$BMP['decal'];
}
//Fermeture du fichier
fclose($f1);
return $res;
}
}
?>
.:: AVA - Domain - Hosting - Webdesign ::.
|
|
Thiết kế và phát triển bởi Công ty TNHH An Vạn An - AVA |
|