= 0x81 ) {
$tmpstr = iconv( "gbk" , "utf-16" , $buffer[$i].$buffer[$i+1] );
$uni = hexdec( bin2hex( $tmpstr[3].$tmpstr[2] ) );
$unicode .= "".$uni.";";
$i++;
}
else {
$unicode .= $string[$i];
}
}
return $unicode;
} } /* ecstart_gbk2htmlunicode */
/* ********** ********** ********** ********** ********** */
if ( !function_exists('ecstart_utf8_convert') ) {
function ecstart_utf8_convert( $buffer ){
$buffer = iconv( "utf-8" , "gbk" , $buffer );
$buffer = ecstart_gbk_convert( $buffer );
return $buffer;
} } /* ecstart_utf8_convert */
/* ******* ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Show Code
********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fShowCD') ) {
function fShowCD($iText) {
echo "
";
echo "
";
echo "";
echo $iText;
echo "";
echo "
";
echo "";
} } /* fShowCD */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Show Error Message
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fShowErr') ) {
function fShowErr($iText) {
echo "";
echo "
";
echo "";
echo $iText;
echo "";
echo "
";
echo "";
} } /* fShowErr */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Show Message
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fShowMsg') ) {
function fShowMsg($iText) {
echo "";
echo "
";
echo "";
echo $iText;
echo "";
echo "
";
echo "";
} } /* fShowMsg */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Copy Resize Image
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iFiles Input Image File Location
** $iX Output Image Maximum Width
** $iY Output Image Maximum Height
** $iPath Output Image Location
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date : 2012-05-31
** Modify By : Jimmy
** Changes : 1. Add Coding For Support Transparent Image
** 2. Modify Output File Format To Original Image
** Type
** ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fCpyResizeImg') ) {
function fCpyResizeImg($iFiles,$iX,$iY,$iPath) {
$RtVal = true;
if ( is_uploaded_file($iFiles['tmp_name']) ) {
if ( $size = getimagesize($iFiles['tmp_name']) ) {
/* ---------- ---------- ---------- ---------- ---------- */
/* Calculate Image Size */
$imageX = $size[0]; $imageY = $size[1];
$resizeRatioX = $iX / $imageX;
$resizeRatioY = $iY / $imageY;
if ($resizeRatioX < $resizeRatioY ){
if ( $resizeRatioX >= 1 ) {
/* For Small Photo Keep Original Size */
$thumbX = $imageX;
$thumbY = $imageY;
}
else {
$thumbX = $iX;
$thumbY = intVal( $imageY * $resizeRatioX );
} }
else {
if ( $resizeRatioY >= 1 ) {
/* For Small Photo Keep Original Size */
$thumbX = $imageX;
$thumbY = $imageY;
}
else {
$thumbY = $iY;
$thumbX = intVal( $imageX * $resizeRatioY );
} }
/* ---------- ---------- ---------- ---------- ---------- */
switch ( $iFiles['type'] ) {
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/jpeg" :
case "image/pjpeg" :
/* Get Input Image */
if ( $getImage = imagecreatefromjpeg($iFiles['tmp_name']) ) {
} // imagecreatefromjpeg
else { $RtVal = false; }
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/gif" :
/* Get Input Image */
if ( $getImage = imagecreatefromgif( $iFiles['tmp_name'] ) ) {
$bgImage = imagecreatetruecolor( $imageX , $imageY );
$bgColor = imagecolorallocate( $bgImage , 0xDA , 0xD6, 0xCA ); //DAD6CA
imagefill( $bgImage , 0 , 0 , $bgColor );
imagecopymerge( $bgImage , $getImage , 0 , 0 , 0 , 0 , $imageX , $imageY , 75 );
$getImage = $bgImage;
} // imagecreatefromjpeg
else { $RtVal = false; }
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/png" :
case "image/x-png" :
/* Get Input Image */
if ( $getImage = imagecreatefrompng($iFiles['tmp_name']) ) {
} // imagecreatefromjpeg
else { $RtVal = false; }
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
default:
/* Invalid Image Format */
$RtVal = false;
fShowMsg( $iFiles['type'] );
break;
} /* switch */
if ( $RtVal != false ) {
/* Copy Image */
/* Act For Thumbnail Photo */
if ( function_exists('imagecreatetruecolor') )
{
$RtVal = ( $thumbImage = imagecreatetruecolor($thumbX, $thumbY) );
}
else
{
$RtVal = ( $thumbImage = imagecreate($thumbX, $thumbY) );
}
/* For Transparent Image */
if ( $RtVal )
{ /* $RtVal */
/* ---------- ---------- ---------- ---------- ---------- */
switch ( $iFiles['type'] ) {
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/gif" :
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/png" :
case "image/x-png" :
$RtVal = imagealphablending($thumbImage, false);
$RtVal = imagesavealpha($thumbImage,true);
$transparent = imagecolorallocatealpha($thumbImage, 255, 255, 255, 127);
$RtVal = imagefilledrectangle($thumbImage, 0, 0, $thumbX, $thumbY, $transparent);
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/jpeg" :
case "image/pjpeg" :
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
default:
break;
} /* switch */
} /* $RtVal */
if ( $RtVal )
{ /* $RtVal */
$RtVal = imagecopyresampled( $thumbImage, $getImage
, 0, 0, 0, 0
, $thumbX , $thumbY
, $imageX , $imageY);
} /* $RtVal */
// Save Image
if ( $RtVal )
{ /* $RtVal */
/* ---------- ---------- ---------- ---------- ---------- */
switch ( $iFiles['type'] ) {
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/gif" :
$RtVal = imagegif($thumbImage,$iPath);
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/png" :
case "image/x-png" :
$RtVal = imagepng($thumbImage,$iPath);
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
case "image/jpeg" :
case "image/pjpeg" :
$RtVal = imagejpeg($thumbImage,$iPath,100);
break;
/* +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ +--+--+--+ */
default:
break;
} /* switch */
} /* $RtVal */
}
} /* getimagesize */
else { $RtVal = false; }
} /* is_uploaded_file */
else { $RtVal = false; }
return $RtVal;
} } /* fCpyResizeImg */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Extry Box Show Value
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fBoxVal') ) {
function fBoxVal( $iText ) {
$oText = $iText;
/* Chop Escape Character */
$oText = fBoxChop( $oText );
$oText = htmlspecialchars( $oText );
return $oText;
} } /* fBoxVal */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Extry Box Show Value Chop Escape Char
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fBoxChop') ) {
function fBoxChop( $iText ) {
$oText = $iText;
/* Chop */
$oText = str_replace( '\\\\' , '\\' , $oText );
$oText = str_replace( '\"' , '"' , $oText );
$oText = str_replace( "\'" , "'" , $oText );
return $oText;
} } /* fBoxChop */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Extry Box Value For SQL Statment
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fBoxSQL') ) {
function fBoxSQL( $iText ) {
$oText = $iText;
/* Chop */
$oText = str_replace( '\\\\' , '\\' , $oText );
$oText = str_replace( '\"' , '"' , $oText );
$oText = str_replace( "\'" , "'" , $oText );
$oText = str_replace( "'" , "''" , $oText );
return $oText;
} } /* fBoxSQL */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Show SQL
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fShowSQL') ) {
function fShowSQL($iText) {
$oText = $iText;
/* Chop */
$oText = str_replace( 'IF ' , 'IF ' , $oText );
$oText = str_replace( 'BEGIN' , '
BEGIN ' , $oText );
$oText = str_replace( 'SELECT ' , '
SELECT ' , $oText );
$oText = str_replace( 'INSERT ' , '
INSERT ' , $oText );
$oText = str_replace( 'UPDATE ' , '
UPDATE ' , $oText );
$oText = str_replace( 'DELETE ' , '
DELETE ' , $oText );
$oText = str_replace( 'REPLACE ' , '
REPLACE ' , $oText );
$oText = str_replace( 'GROUP BY ' , '
GROUP BY ' , $oText );
$oText = str_replace( 'ORDER BY ' , '
ORDER BY ' , $oText );
$oText = str_replace( ' DESC ' , ' DESC ' , $oText );
$oText = str_replace( ' ASC ' , ' ASC ' , $oText );
$oText = str_replace( ' SET ' , '
SET ' , $oText );
$oText = str_replace( ' AS ' , ' AS ' , $oText );
$oText = str_replace( ' FROM ' , '
FROM ' , $oText );
$oText = str_replace( ' WHERE ' , '
WHERE ' , $oText );
$oText = str_replace( ' AND ' , '
AND ' , $oText );
$oText = str_replace( ' OR ' , '
OR ' , $oText );
$oText = str_replace( ' LEFT ' , '
LEFT ' , $oText );
$oText = str_replace( ' RIGHT ' , '
RIGHT ' , $oText );
$oText = str_replace( ' INNER ' , '
INNER ' , $oText );
$oText = str_replace( ' OUTER ' , ' OUTER ' , $oText );
$oText = str_replace( ' JOIN ' , ' JOIN ' , $oText );
$oText = str_replace( ' ON ' , '
ON ' , $oText );
$oText = str_replace( ' THEN ' , ' THEN ' , $oText );
$oText = str_replace( ' EXISTS ' , ' EXISTS ' , $oText );
$oText = str_replace( ' INTO ' , ' INTO ' , $oText );
$oText = str_replace( ' ELSE ' , '
ELSE ' , $oText );
$oText = str_replace( ' END ' , '
END ' , $oText );
$oText = str_replace( ' CONCAT' , ' CONCAT' , $oText );
$oText = str_replace( ' COALESCE' , ' COALESCE' , $oText );
$oText = str_replace( ' SUBSTRING' , ' SUBSTRING' , $oText );
$oText = str_replace( ' , ' , '
, ' , $oText );
$oText = str_replace( ' , ' , '
, ' , $oText );
$oText = str_replace( ' ` ' , ' ` ' , $oText );
echo "";
echo "
";
echo "";
echo $oText;
echo "";
echo "
";
echo "";
} } /* fShowSQL */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Remove Tag
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fRemoveTag') ) {
function fRemoveTag($iText) {
$oText = $iText;
$tagCnt = substr_count( $oText , "<" );
/* Remove Invisible String */
$oText = str_replace( "\r\n" , " " , $oText );
$oText = str_replace( "\n" , " " , $oText );
$oText = str_replace( " " , " " , $oText );
$oText = str_replace( "
" , " " , $oText );
$oText = str_replace( " " , " " , $oText );
$spcCnt = substr_count( $oText , " " );
for ( $i = 1 ; $i <= $spcCnt ; $i++ ) {
$oText = str_replace( " " , " " , $oText );
if ( substr_count( $oText , " " ) == 0 ) { break; }
}
for ( $i = 1 ; $i <= $tagCnt ; $i++ ) {
/* Get Start */
$intA = strpos( $oText , "<" );
/* Get End */
$intB = strpos( $oText , ">" , $intA ) + 1;
/* Get Ignore */
$intC = strpos( $oText , "?>" , $intA ) + 2;
if ( $intC == $intB ) {
$intB = strpos( $oText , ">" , $intC ) + 1;
}
$strC = substr( $oText , $intA , ( $intB - $intA ) );
$oText = str_replace( $strC , " " , $oText ) ;
$oText = str_replace( " " , " " , $oText );
if ( substr_count( $oText , "<" ) == 0 ) { break; }
}
return $oText;
} } /* fRemoveTag */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Sub-String UTF-8
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $string Input Text
** $start Start Position
** Default 0
** $sublen Output Text length
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fSubStrUtf8') ) {
function fSubStrUtf8($string, $start = 0, $sublen ) {
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen)
return join('', array_slice($t_string[0], $start, $sublen))."..";
return join('', array_slice($t_string[0], $start, $sublen));
} } /* fSubStrUtf8 */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Generate Password
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iLen Length Of Password
** Default 30
** $iRule Generation Rule
** +1 - Number 0123456789
** +2 - Lower Case Character abcdefghijklmnopqrstuvwxyz
** +4 - Upper Case Character ABCDEFGHIJKLMNOPQRSTUVWXYZ
** +8 - Symbol !@#$%^&*()_+-=[]{}?:;<>,.
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fGenPwd') ) {
function fGenPwd( $intLen = 30 , $iRule = 15 ) {
$oPwd = "";
$vNum = 0; $vLower = 0; $vUpper = 0; $vSymbol = 0;
/* */
$r = $iRule % 16; $vSymbol = ( $r >= 8 ) ? 1 : 0; $strSymbol = "!@#$%^&*()_+-=[]{}?:;<>,.";
$r = $iRule % 8 ; $vUpper = ( $r >= 4 ) ? 1 : 0; $strUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$r = $iRule % 4 ; $vLower = ( $r >= 2 ) ? 1 : 0; $strLower = "abcdefghijklmnopqrstuvwxyz";
$r = $iRule % 2 ; $vNum = ( $r >= 1 ) ? 1 : 0; $strNumber = "0123456789";
$strAcceptChar .= ( $vNum == 1 ) ? $strNumber : "" ;
$strAcceptChar .= ( $vLower == 1 ) ? $strLower : "" ;
$strAcceptChar .= ( $vUpper == 1 ) ? $strUpper : "" ;
$strAcceptChar .= ( $vSymbol == 1 ) ? $strSymbol : "" ;
/* */
for ( $xxx = 1 ; $xxx <= $intLen ; $xxx++ ) {
$oPwd .= substr( $strAcceptChar , rand( 0 , strlen( $strAcceptChar ) - 1 ) , 1 );
}
/* */
return $oPwd;
} } /* fGenPwd */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For include file
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iFileName Include File Location
** $iOnce Is include_once
** Default 1 (Yes)
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fInc') ) {
function fInc( $iFileName , $iOnce = 1 ) {
$maxLoop = substr_count( $_SERVER['SCRIPT_NAME'] , '/' );
for ( $vLoop = 1 ; $vLoop <= $maxLoop ; $vLoop++ ) {
$vPath = ( $vLoop == 1 ) ? $iFileName : '../'.$vPath ;
if ( file_exists( $vPath ) ) {
if ( dirname( $vPath ) == $vPath ) { break; } /* Check Is File */
if ( $iOnce == 1 ) {
include_once( $vPath );
}
else {
include( $vPath );
}
break;
} /* file_exists $vPath */
} /* for $vLoop */
} } /* fInc */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Check Browser
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Description :
** ========== ========== ========== ========== ==========
** Return Array
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fGetBrowser') ) {
function fGetBrowser() {
/* */
$userAgent = strtoupper( $_SERVER['HTTP_USER_AGENT'] );
$strBrowser = "Unknown"; $strVersion = "Unknown";
/* */
if ( preg_match( '/MSIE/i' , $userAgent ) )
{ /* Case MSIE */
$strBrowser = "MSIE";
$strBreak1 = ";"; $strBreak2 = " ";
} /* Case MSIE */
else
if ( preg_match( '/IPHONE/i' , $userAgent ) )
{ /* Case iPhone */
$strBrowser = "IPHONE";
$strBreak1 = " "; $strBreak2 = "/";
} /* Case iPhone */
else
if ( preg_match( '/IPAD/i' , $userAgent ) )
{ /* Case iPad */
$strBrowser = "IPAD";
$strBreak1 = " "; $strBreak2 = "/";
} /* Case iPad */
else
if ( preg_match( '/FIREFOX/i' , $userAgent ) )
{ /* Case FireFox */
$strBrowser = "FIREFOX";
$strBreak1 = " "; $strBreak2 = "/";
} /* Case FireFox */
else
if ( preg_match( '/CHROME/i' , $userAgent ) )
{ /* Case Google Chrome */
$strBrowser = "CHROME";
$strBreak1 = " "; $strBreak2 = "/";
} /* Case Google Chrome */
else
if ( preg_match( '/SAFARI/i' , $userAgent ) )
{ /* Case Safari */
$strBrowser = "SAFARI";
$strBreak1 = " "; $strBreak2 = "/";
} /* Case Safari */
else
if ( preg_match( '/OPERA/i' , $userAgent ) )
{ /* Case Opera */
$strBrowser = "OPERA";
$strBreak1 = " "; $strBreak2 = "/";
} /* Case Opera */
/* */
if ( $strVersion == "Unknown" ) {
$aryUserAgent = explode( $strBreak1 , $userAgent );
foreach ( $aryUserAgent as $k => $v ) {
$v = strtoupper( $v );
if ( preg_match( '/VERSION/i' , $v ) ) {
$strVersion = str_replace( 'VERSION/' , '' , $v );
break;
}
if ( preg_match( '/'.$strBrowser.'/i' , $v ) ) {
$strVersion = str_replace( $strBrowser.$strBreak2 , '' , $v );
}
} /* foreach $aryUserAgent */
} /* if $strVersion */
/* */
$vBowr = array( "Browser" => $strBrowser
, "Version" => $strVersion
);
/* */
return $vBowr;
} } /* fGetBrowser */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Injection
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Description :
** ========== ========== ========== ========== ==========
**
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Create Date : 2012-0-17
** Created By : Camby
** ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('getVarByPost') ) {
function getVarByPost() {
if(count($_POST)) {
foreach($_POST as $key => $value) {
global ${$key};
if (is_array($value)) {
$temp_array = array();
foreach($value as $key2 => $value2) {
if(function_exists('mysql_real_escape_string')) {
$temp_array[$key2] = fBoxSQL(trim($value2));
} else {
$temp_array[$key2] = str_replace('"','\"',str_replace("'","\'",(trim($value2))));
}
}
${$key} = $_POST[$key] = $temp_array;
} else {
if(function_exists('mysql_real_escape_string')) {
${$key} = fBoxSQL(trim($value));
} else {
${$key} = $_POST[$key] = str_replace('"','\"',str_replace("'","\'",(trim($value))));
}
}
}
}
}
} /* getVarByPost */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Injection
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Description :
** ========== ========== ========== ========== ==========
**
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Create Date : 2012-0-17
** Created By : Camby
** ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* ********** ********** ********** ********** ********** */
if ( !function_exists('getVarByGet') ) {
function getVarByGet() {
if(count($_GET)) {
foreach($_GET as $key => $value) {
global ${$key};
if (is_array($value)) {
$temp_array = array();
foreach($value as $key2 => $value2) {
if(function_exists('mysql_real_escape_string')) {
//$temp_array[$key2] = mysql_real_escape_string(trim($value2));
$temp_array[$key2] = fBoxSQL(trim($value2));
} else {
$temp_array[$key2] = str_replace('"','\"',str_replace("'","\'",(trim($value2))));
}
}
${$key} = $_GET[$key] = $temp_array;
} else {
if(function_exists('mysql_real_escape_string')) {
//${$key} = mysql_real_escape_string(trim($value));
${$key} = fBoxSQL(trim($value));
} else {
${$key} = $_GET[$key] = str_replace('"','\"',str_replace("'","\'",(trim($value))));
}
}
}
}
}
} /* getVarByGet */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Encrypt Url ID
** ========== ========== ========== ========== ==========
** Encypt Numeric ID To Look Like MD5 String
** General MD5 String --> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
** 12345678901234567890123456789012
** Numeric ID --> DDDD
** String Lenght Of ID --> L
** Output --> mmmLmmmmmDDDDmmmmmmmmmmmmmmmmmmmmmmmm
** 123 45678 901234567890123456789012
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Create Date : 2012-4-25
** Created By : Jimmy
** ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* ********** ********** ********** ********** ********** */
if ( !function_exists('enUrlID') ) {
function enUrlID($iText) {
fEncyAddNoise($iText);
} }
if ( !function_exists('fEncyAddNoise') ) {
function fEncyAddNoise($iText) {
$seed = ( rand( 10000 , 99999 ) );
$seed.= '_'.date('Y-m-d H:i:s');
$seed.= '_'.$iText;
$seed.= '_'.( rand( 10000 , 99999 ) );
$seed = md5( $seed );
$Ax1 = $iText;
$oText = substr( $seed , 0 , 3 ).strlen($Ax1).substr( $seed , 3 , 5 ).$Ax1.substr( $seed , 8 , 24 );
return trim( $oText );
} } /* fEncyAddNoise */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Decode Encyption Url ID
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Create Date : 2012-4-25
** Created By : Jimmy
** ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('deUrlID') ) {
function deUrlID($iText) {
fEncyClrNoise($iText);
} }
if ( !function_exists('fEncyClrNoise') ) {
function fEncyClrNoise($iText) {
$vStartPos = 9;
$vGetLen = substr( $iText , 3 , 1 );
$blnValid = ( strlen( $iText ) >= 16 );
$blnValid = ( $blnValid && is_numeric( $vStartPos ) && $vStartPos > 0 );
$blnValid = ( $blnValid && is_numeric( $vGetLen ) && $vGetLen > 0 );
$oText = ( $blnValid ) ? substr( $iText , $vStartPos , $vGetLen ) : $iText ;
return trim( $oText );
} } /* fEncyClrNoise */
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** **********
** Function For Encrypt MD5 String By Reorder Method
** ========== ========== ========== ========== ==========
** For Increase Security Reorder MD5 String
** Break Down MD5 String To 8 Pieces, And Then Reorder This String Plus Decode Key
** General MD5 String --> mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
** 12345678901234567890123456789012
** Break Down MD --> mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
** 1111 2222 3333 4444 5555 6666 7777 8888
** Order Key Break Down To 2 Pieces kkkk KKKK
** Output Look Like MD5 String --> mmmmkkkkmmmmKKKKmmmmmmmmmmmmmmmmmmmmmmmm
** 1234 5678 901234567890123456789012
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Parameter Description :
** ========== ========== ========== ========== ==========
** $iText Input String
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
/* Maintainence History
** ========== ========== ========== ========== ========== ========== ========== ========== ========== ==========
** Create Date : 2012-4-25
** Created By : Jimmy
** ========== ========== ========== ========== ==========
** Modify Date :
** Modify By :
** Changes :
** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('md5e') ) {
function md5e($iText , $iKey = "") {
fEncyMD5ReOen($iText,$iKey);
} }
if ( !function_exists('fEncyMD5ReOen') ) {
function fEncyMD5ReOen($iText , $iKey = "") {
/* ********** ********** ********** ********** ********** */
$debug = false;
$key1 = ""; $key2 = ""; $o1 = ""; $o2 = ""; $o3 = ""; $aryRnd = array(); $aryText = array(); $aryKey = array();
$md5Text = md5( $iText );
/* ********** ********** ********** ********** ********** */
$intPos = 0;
for ( $i = 1 ; $i <= 8 ; $i++ )
{ /* $i */
if ( $iKey == "" )
{ /* No Entry Key */
$aryRnd[$i] = rand( 10001000 , 9999999999 );
} /* No Entry Key */
else
{ /* Entry Key */
$intPosKey = $i - 1;
$aryRnd[$i] = 9 - substr( $iKey , $intPosKey , 1 );
} /* Entry Key */
$aryText[$i] = substr( $md5Text , $intPos , 4 );
$intPos+= 4;
} /* $i */
/* ********** ********** ********** ********** ********** */
if ( $debug )
{ /* $debug */
echo $md5Text;
echo '
'.$aryText[1].'-'.$aryText[2].'-'.$aryText[3].'-'.$aryText[4].'-'.$aryText[5].'-'.$aryText[6].'-'.$aryText[7].'-'.$aryText[8];
} /* $debug */
/* ********** ********** ********** ********** ********** */
for ( $i = 1 ; $i <= 8 ; $i++ )
{ /* $i */
$maxRnd = 0; $maxKey = 0;
for ( $j = 1 ; $j <= 8 ; $j++ )
{ /* $j */
if ( $aryRnd[$j] > $maxRnd )
{
$maxRnd = $aryRnd[$j];
$maxKey = $j;
}
} /* $j */
$aryRnd[$maxKey] = 0;
/* */
if ( $i <= 4 ) {
$key1.= $maxKey;
}
else {
$key2.= $maxKey;
}
/* */
if ( $i == 1 ) {
$o1 = $aryText[$maxKey];
}
elseif ( $i == 2 ) {
$o2 = $aryText[$maxKey];
}
else {
$o3.= $aryText[$maxKey];
}
} /* $i */
if ( $iKey == "" )
{ /* No Entry Key */
$oText = $o1.$key1.$o2.$key2.$o3;
} /* No Entry Key */
else
{ /* Entry Key */
$oText = $o1.$o2.$o3;
} /* Entry Key */
if ( $debug )
{ /* $debug */
echo '
'.$key1.'-'.$key2;
echo '
'.$aryText[substr($key1,0,1)].'-'.$aryText[substr($key1,1,1)].'-'.$aryText[substr($key1,2,1)].'-'.$aryText[substr($key1,3,1)];
echo '-'.$aryText[substr($key2,0,1)].'-'.$aryText[substr($key2,1,1)].'-'.$aryText[substr($key2,2,1)].'-'.$aryText[substr($key2,3,1)];
} /* $debug */
/* ********** ********** ********** ********** ********** */
return trim( $oText );
/* ********** ********** ********** ********** ********** */
} } /* fEncyMD5ReOen */
if ( !function_exists('md5en') ) {
function md5en($iText , $iKey = "") {
return fEncyMD5ReOen($iText,$iKey);
} }
/*** ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('md5de') ) {
function md5de($iText , $iKey = "") {
return fEncyMD5ReOde($iText,$iKey);
} }
if ( !function_exists('fEncyMD5ReOde') ) {
function fEncyMD5ReOde($iText , $iKey = "") {
$debug = false;
$oText = "";
$aryText = array(); $aryKey = array(); $aryNew = array();
$intPos = 0;
for ( $i = 1 ; $i <= 8 ; $i++ )
{ /* $i */
$aryText[$i] = substr( $iText , $intPos , 4 );
$intPos+= 4;
if ( $i == 1 || $i == 2 )
{ /* $i == 1 || 3*/
$jForFrom = ( $i == 1 ) ? 1 : 5;
$jForTo = ( $i == 1 ) ? 4 : 8;
for ( $j = $jForFrom ; $j <= $jForTo ; $j++ )
{ /* $j */
if ( $iKey == "" )
{ /* No Key Entry */
$aryKey[$j] = substr( $iText , $intPos , 1 );
$intPos+= 1;
} /* No Key Entry */
else
{ /* Key Entry */
$intPosKey = $j - 1;
$aryKey[$j] = substr( $iKey , $intPosKey , 1 );
} /* Key Entry */
} /* $j */
} /* $i == 1 || 3*/
} /* $i */
if ( $debug )
{ /* $debug */
echo '
'.$aryText[1].'-'.$aryText[2].'-'.$aryText[3].'-'.$aryText[4].'-'.$aryText[5].'-'.$aryText[6].'-'.$aryText[7].'-'.$aryText[8];
echo '
'.$aryKey[1].'-'.$aryKey[2].'-'.$aryKey[3].'-'.$aryKey[4].'-'.$aryKey[5].'-'.$aryKey[6].'-'.$aryKey[7].'-'.$aryKey[8];
} /* $debug */
$oText = "";
for ( $i = 1 ; $i <= 8 ; $i++ )
{ /* $i */
$aryNew[$aryKey[$i]] = $aryText[$i];
} /* $i */
if ( $debug )
{ /* $debug */
echo '
'.$aryNew[1].'-'.$aryNew[2].'-'.$aryNew[3].'-'.$aryNew[4].'-'.$aryNew[5].'-'.$aryNew[6].'-'.$aryNew[7].'-'.$aryNew[8];
} /* $debug */
$oText = $aryNew[1].$aryNew[2].$aryNew[3].$aryNew[4].$aryNew[5].$aryNew[6].$aryNew[7].$aryNew[8];
return trim( $oText );
} } /* fEncyMD5ReOde */
/* ********** ********** Camby @ 2012-04 ********** ********** */
if (!function_exists('json_encode')) {
function json_encode($a=false) {
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a)) {
if (is_float($a)) {
// Always use "." for floats.
return floatval(str_replace(",", ".", strval($a)));
}
if (is_string($a)) {
static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
} else {
return $a;
}
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a)) {
if (key($a) !== $i) {
$isList = false;
break;
}
}
$result = array();
if ($isList) {
foreach ($a as $v) $result[] = json_encode($v);
return '[' . join(',', $result) . ']';
} else {
foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
return '{' . join(',', $result) . '}';
}
}
}
/* ********** ********** Camby @ 2012-01 ********** ********** */
function genRandomString($length=8,$no=1,$a=1,$A=1,$o=0) {
if($no==1) {$characters .= '0123456789';}
if($a==1) {$characters .= 'abcdefghijklmnopqrstuvwxyz';}
if($A==1) {$characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';}
if($o==1) {$characters .= '~!@#$%^&*()_-+=?.,:;';}
$string ='';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
/* ********** ********** Camby @ 2011-12 ********** ********** */
function echoarray($ary) {
echo '';
foreach($ary as $key => $a) {
if(is_array($a)) {
echo '| '.$key.' => |
| ';
echoarray($a);
echo ' |
';
} else {
echo '| '.$key.' => '.$a.' |
';
}
}
echo '
';
}
/* ********** ********** Camby @ 2011-12 ********** ********** */
function getDirImage($imageDir) {
$imageArr = array();
$f = opendir($imageDir);
while($files = readdir($f)) {
if ($files != '..' && $files != '.' && preg_match("/(jpg|gif|png)$/i", $files)) {
$imageArr[] = $files;
}
}
closedir($f);
return $imageArr;
}
/** ********** ********** Camby @ 2012-05 ********** ********** */
function ResizeImg($opath,$npath,$newwidth,$newheight = 0,$haveWatermark = false) {
// Get new sizes
$l = getimagesize($opath);
$width = $l[0];
$height = $l[1];
$type = $l['mime'];
if($newwidth && $width>$newwidth) {
$ratio = $newwidth / $width;
$resizeWidth = $newwidth;
$resizeHeight = round($height * $ratio);
}
if($newheight && $resizeHeight>$newheight) {
$ratio = $newheight / $height;
$resizeHeight = $newheight;
$resizeWidth = round($width * $ratio);
}
if($resizeHeight > 0) {
ob_start();
echo "Image '$opath' cannot resize to $resizeWidth * $resizeHeight.";
// Load
$thumb = imagecreatetruecolor($resizeWidth, $resizeHeight);
//PreWrite Error
//$f = @fopen('../../cache/imageResizeError.txt','w');
//fwrite($f,"Image '$opath' cannot resize.");
switch($type) {
case "image/gif":
$source=imagecreatefromgif($opath);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($opath);
break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($opath);
$white = imagecolorallocate($thumb, 255, 255, 255);
imagefilledrectangle($thumb, 0, 0, $resizeWidth, $resizeHeight, $white);
imagecopy($thumb, $source, 0, 0, 0, 0, $resizeWidth, $resizeHeight);
break;
}
// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $resizeWidth, $resizeHeight, $width, $height);
if ($haveWatermark)
{
// WaterMark with resized image
// Image
$watermark = '../images/water_mark/logo.png';
$watermark = imagecreatefrompng($watermark);
$margin_left = 0;
$margin_top = 0;
$opacity = 100;
imagecopymerge($thumb, $watermark, $margin_left, $margin_top, 0, 0, imagesx($watermark), imagesy($watermark), $opacity);
// Text
$wx = imagesx($thumb);
$wy = imagesy($thumb);
$watermarktext="chungsen.com.hk";
$font="../images/water_mark/fonts/arial.ttf";
$fontsize="8";
$white = imagecolorallocate($thumb, 255, 255, 255);
imagettftext($thumb, $fontsize, 0, $wx/8, $wy/2, $white, $font, $watermarktext);
// WaterMark with source
// Image
$source=imagecreatefromjpeg($opath);
$margin_left = 0;
$margin_top = 0;
imagecopymerge($source, $watermark, $margin_left, $margin_top, 0, 0, imagesx($watermark), imagesy($watermark), $opacity);
// Text
$wx = imagesx($source);
$wy = imagesy($source);
$watermarktext="chungsen.com.hk";
$font="../images/water_mark/fonts/arial.ttf";
$fontsize="20";
$white = imagecolorallocate($source, 255, 255, 255);
imagettftext($source, $fontsize, 0, $wx/3, $wy/2, $white, $font, $watermarktext);
// Output
echo 1;
switch($type) {
case "image/gif":
imagegif($source,$opath);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($source,$opath,100);
break;
case "image/png":
case "image/x-png":
imagepng($source,$opath);
break;
}
}
// Output
echo 1;
switch($type) {
case "image/gif":
imagegif($thumb,$npath);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($thumb,$npath,100);
break;
case "image/png":
case "image/x-png":
imagepng($thumb,$npath);
break;
}
ob_clean();
//Delete Error
//$f = @fopen('../../cache/imageResizeError.txt','w');
}
}
/* ********** ********** Camby @ 2012-05 ********** ********** */
function img_path($path,$resize='thumb',$type='path') {
// $imgname = end(explode('/',$path));
$pathway = explode('/',$path);
$imgname = end($pathway);
if($type=='name') {
return $resize.'_'.$imgname;
} else {
return str_replace($imgname,$resize.'/'.$resize.'_'.$imgname,$path);
}
}
/**************************** Camby **********************************/
function classifyarray($thearray, $type='makearray') {
if($type=='makearray') {//-------------將 statment 變成 array statment (加 ' 號)
$thearray = explode(',',$thearray);
for($i=0;$i')/*array('< Prev','Next >')*/, $varname = '', $tab = false, $ajax = false, $cutpage = '20') {
//varname = passed page name (page, page2, page3,...)
//tab = passed tab name
$totalpage = ceil($total / $cpp);
if($totalpage>1) {
if($ajax) {
if($cutpage > 5 && $totalpage > $cutpage) {
$showpage = $cutpage-3;
for($i=$showpage;$i>1;$i = $i-2) {
$deduct++;
$plus++;
}
if($showpage>0) {$plus++;}
$startpage = $thispage - $deduct;
$endpage = $thispage + $plus;
if($startpage<1) {
$startpage = 1;
$endpage = $startpage + $plus + $deduct;
} elseif($endpage>$totalpage) {
$endpage = $totalpage;
$startpage = $endpage - $plus - $deduct;
}
for($i=$startpage;$i<=$endpage;$i++) {
$wlink = 'javascript:'.str_replace('ajaxpage',$i,$ajax);
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
if($startpage-1>1) {
$wlink = 'javascript:'.str_replace('ajaxpage','1',$ajax);
$multipage = '1..';
}
if($endpage+1<$totalpage) {
$wlink = 'javascript:'.str_replace('ajaxpage',$totalpage,$ajax);
$multipage .= ''.$totalpage.'';
}
} else {
for($i=1;$i<=$totalpage;$i++) {
$wlink = 'javascript:'.str_replace('ajaxpage',$i,$ajax);
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
}
} else {
/**/
if($tab){$target = "#".$tab;}
/**/
if(strpos($wlink,'?')) {
if($varname)
{
$wlink .= '&'.$varname.'=';
}
else
{
$wlink .= '&page=';
}
} else {
if($varname)
{
$wlink .= '&'.$varname.'=';
}
else
{
$wlink .= '&page=';
}
}
if($cutpage > 5 && $totalpage > $cutpage) {
$showpage = $cutpage-3;
for($i=$showpage;$i>1;$i = $i-2) {
$deduct++;
$plus++;
}
if($showpage>0) {$plus++;}
$startpage = $thispage - $deduct;
$endpage = $thispage + $plus;
if($startpage<1) {
$startpage = 1;
$endpage = $startpage + $plus + $deduct;
} elseif($endpage>$totalpage) {
$endpage = $totalpage;
$startpage = $endpage - $plus - $deduct;
}
for($i=$startpage;$i<=$endpage;$i++) {
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
if($startpage>1) {
$multipage = '1..'.$multipage;
}
if($endpage<$totalpage) {
$multipage .= '..'.$totalpage.'';
}
} else {
for($i=1;$i<=$totalpage;$i++) {
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
}
}
if($withnext) {
if($ajax) {
$back = $thispage-1;
$wlink = 'javascript:'.str_replace('ajaxpage',$back,$ajax);
$back = $back > 0 ? '
'.$withnext[0].'' : '
'.$withnext[0].'';
$next = $thispage+1;
$wlink = 'javascript:'.str_replace('ajaxpage',$next,$ajax);
$next = $next <= $totalpage ? '
'.$withnext[1].'' : '
'.$withnext[1].'';
$multipage = $back.$multipage.$next;
} else {
$back = $thispage-1;
$back = $back > 0 ? '
'.$withnext[0].'' : '
'.$withnext[0].'';
$next = $thispage+1;
$next = $next <= $totalpage ? '
'.$withnext[1].'' : '
'.$withnext[1].'';
$multipage = $back.$multipage.$next;
}
}
$multipage = ''.$multipage.'
';
}
return $multipage;
}
}
if( !function_exists('multipage_news') ) {
function multipage_news($total, $cpp, $thispage, $wlink, $withnext = array('< Prev','Next >')/*array('< Prev','Next >')*/, $varname = '', $tab = false, $ajax = false, $cutpage = '20') {
//varname = passed page name (page, page2, page3,...)
//tab = passed tab name
$totalpage = ceil($total / $cpp);
if($totalpage>1) {
if($ajax) {
if($cutpage > 5 && $totalpage > $cutpage) {
$showpage = $cutpage-3;
for($i=$showpage;$i>1;$i = $i-2) {
$deduct++;
$plus++;
}
if($showpage>0) {$plus++;}
$startpage = $thispage - $deduct;
$endpage = $thispage + $plus;
if($startpage<1) {
$startpage = 1;
$endpage = $startpage + $plus + $deduct;
} elseif($endpage>$totalpage) {
$endpage = $totalpage;
$startpage = $endpage - $plus - $deduct;
}
for($i=$startpage;$i<=$endpage;$i++) {
$wlink = 'javascript:'.str_replace('ajaxpage',$i,$ajax);
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
if($startpage-1>1) {
$wlink = 'javascript:'.str_replace('ajaxpage','1',$ajax);
$multipage = '1..';
}
if($endpage+1<$totalpage) {
$wlink = 'javascript:'.str_replace('ajaxpage',$totalpage,$ajax);
$multipage .= ''.$totalpage.'';
}
} else {
for($i=1;$i<=$totalpage;$i++) {
$wlink = 'javascript:'.str_replace('ajaxpage',$i,$ajax);
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
}
} else {
/**/
if($tab){$target = "#".$tab;}
/**/
if(strpos($wlink,'?')) {
if($varname)
{
$wlink .= '&'.$varname.'=';
}
else
{
$wlink .= '&page=';
}
} else {
if($varname)
{
$wlink .= '&'.$varname.'=';
}
else
{
$wlink .= '&page=';
}
}
if($cutpage > 5 && $totalpage > $cutpage) {
$showpage = $cutpage-3;
for($i=$showpage;$i>1;$i = $i-2) {
$deduct++;
$plus++;
}
if($showpage>0) {$plus++;}
$startpage = $thispage - $deduct;
$endpage = $thispage + $plus;
if($startpage<1) {
$startpage = 1;
$endpage = $startpage + $plus + $deduct;
} elseif($endpage>$totalpage) {
$endpage = $totalpage;
$startpage = $endpage - $plus - $deduct;
}
for($i=$startpage;$i<=$endpage;$i++) {
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
if($startpage>1) {
$multipage = '1..'.$multipage;
}
if($endpage<$totalpage) {
$multipage .= '..'.$totalpage.'';
}
} else {
for($i=1;$i<=$totalpage;$i++) {
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
}
}
if($withnext) {
if($ajax) {
$back = $thispage-1;
$wlink = 'javascript:'.str_replace('ajaxpage',$back,$ajax);
$back = $back > 0 ? '
'.$withnext[0].'' : '
'.$withnext[0].'';
$next = $thispage+1;
$wlink = 'javascript:'.str_replace('ajaxpage',$next,$ajax);
$next = $next <= $totalpage ? '
'.$withnext[1].'' : '
'.$withnext[1].'';
$multipage = $back.$multipage.$next;
} else {
$back = $thispage-1;
$back = $back > 0 ? '
'.$withnext[0].'' : '
'.$withnext[0].'';
$next = $thispage+1;
$next = $next <= $totalpage ? '
'.$withnext[1].'' : '
'.$withnext[1].'';
$multipage = $back.$multipage.$next;
}
}
$multipage = ''.$multipage.'
';
}
return $multipage;
}
}
if( !function_exists('multipage_gallery') ) {
function multipage_gallery($total, $cpp, $thispage, $wlink, $withnext = array('< Prev','Next >')/*array('< Prev','Next >')*/, $varname = '', $tab = false, $ajax = false, $cutpage = '20') {
//varname = passed page name (page, page2, page3,...)
//tab = passed tab name
$totalpage = ceil($total / $cpp);
if($totalpage>1) {
if($ajax) {
if($cutpage > 5 && $totalpage > $cutpage) {
$showpage = $cutpage-3;
for($i=$showpage;$i>1;$i = $i-2) {
$deduct++;
$plus++;
}
if($showpage>0) {$plus++;}
$startpage = $thispage - $deduct;
$endpage = $thispage + $plus;
if($startpage<1) {
$startpage = 1;
$endpage = $startpage + $plus + $deduct;
} elseif($endpage>$totalpage) {
$endpage = $totalpage;
$startpage = $endpage - $plus - $deduct;
}
for($i=$startpage;$i<=$endpage;$i++) {
$wlink = 'javascript:'.str_replace('ajaxpage',$i,$ajax);
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
if($startpage-1>1) {
$wlink = 'javascript:'.str_replace('ajaxpage','1',$ajax);
$multipage = '1..';
}
if($endpage+1<$totalpage) {
$wlink = 'javascript:'.str_replace('ajaxpage',$totalpage,$ajax);
$multipage .= ''.$totalpage.'';
}
} else {
for($i=1;$i<=$totalpage;$i++) {
$wlink = 'javascript:'.str_replace('ajaxpage',$i,$ajax);
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
}
} else {
/**/
if($tab){$target = "#".$tab;}
/**/
if(strpos($wlink,'?')) {
if($varname)
{
$wlink .= '&'.$varname.'=';
}
else
{
$wlink .= '&page=';
}
} else {
if($varname)
{
$wlink .= '&'.$varname.'=';
}
else
{
$wlink .= '&page=';
}
}
if($cutpage > 5 && $totalpage > $cutpage) {
$showpage = $cutpage-3;
for($i=$showpage;$i>1;$i = $i-2) {
$deduct++;
$plus++;
}
if($showpage>0) {$plus++;}
$startpage = $thispage - $deduct;
$endpage = $thispage + $plus;
if($startpage<1) {
$startpage = 1;
$endpage = $startpage + $plus + $deduct;
} elseif($endpage>$totalpage) {
$endpage = $totalpage;
$startpage = $endpage - $plus - $deduct;
}
for($i=$startpage;$i<=$endpage;$i++) {
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
if($startpage>1) {
$multipage = '1..'.$multipage;
}
if($endpage<$totalpage) {
$multipage .= '..'.$totalpage.'';
}
} else {
for($i=1;$i<=$totalpage;$i++) {
if($thispage==$i) {
$multipage .= '
'.$i.'';
} else {
$multipage .= '
'.$i.'';
}
}
}
}
if($withnext) {
if($ajax) {
$back = $thispage-1;
$wlink = 'javascript:'.str_replace('ajaxpage',$back,$ajax);
$back = $back > 0 ? '
'.$withnext[0].'' : '
'.$withnext[0].'';
$next = $thispage+1;
$wlink = 'javascript:'.str_replace('ajaxpage',$next,$ajax);
$next = $next <= $totalpage ? '
'.$withnext[1].'' : '
'.$withnext[1].'';
$multipage = $back.$multipage.$next;
} else {
$back = $thispage-1;
$back = $back > 0 ? '
'.$withnext[0].'' : '
'.$withnext[0].'';
$next = $thispage+1;
$next = $next <= $totalpage ? '
'.$withnext[1].'' : '
'.$withnext[1].'';
$multipage = $back.$multipage.$next;
}
}
$multipage = ''.$multipage.'
';
}
return $multipage;
}
}
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale = 1){
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
$imageType = image_type_to_mime_type($imageType);
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
switch($imageType) {
case "image/gif":
$source=imagecreatefromgif($image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($image);
break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
switch($imageType) {
case "image/gif":
imagegif($newImage,$thumb_image_name);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newImage,$thumb_image_name,90);
break;
case "image/png":
case "image/x-png":
imagepng($newImage,$thumb_image_name);
break;
}
chmod($thumb_image_name, 0777);
return $thumb_image_name;
}
/* ********** ********** ********** Camby @ 2012-07 ********** ********** ********** ********** ********** */
if ( !function_exists('jsMsg') )
{ function jsMsg($msg,$window='parent') {
echo ''; exit;
} }
/* ********** ********** ********** Camby @ 2012-07 ********** ********** ********** ********** ********** */
if ( !function_exists('jsCMsg') )
{ function jsCMsg($msg,$location,$window='parent') {
echo ''; exit;
} }
/* ********** ********** ********** Camby @ 2012-07 ********** ********** ********** ********** ********** */
if ( !function_exists('jsReload') )
{ function jsReload($window='parent') {
echo ''; exit;
} }
/* ********** ********** ********** Camby @ 2012-07 ********** ********** ********** ********** ********** */
if ( !function_exists('jsURL') )
{ function jsURL($url,$window='parent') {
echo ''; exit;
} }
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fAddItemSQL') )
{ function fAddItemSQL($iFldName , $iValue , $iIsText = 0 , $iAllowNULL = 1 ) {
$oText = trim( fClrHeadChr( $iValue ) );
if ( $oText == '' && $iAllowNULL == 1 )
{
$oText = " , `".trim( $iFldName )."` = NULL ";
}
else
{
$oText = ( $iIsText == 1 ) ? fBig5ToUtf8( $oText ) : $oText ;
$oText = " , `".trim( $iFldName )."` = '".fBoxSQL( trim( $oText ) )."' ";
}
return ( $oText );
} }
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fClrHeadChr') )
{ function fClrHeadChr($iText) {
$oText = $iText;
if ( substr( trim( $iText ) , 0 , 1 ) == "'" )
{
$vLen = strlen( trim( $iText ) ) - 1 ;
$oText = substr( trim( $iText ) , 1 , $vLen );
}
return ( trim( $oText ) );
} }
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if ( !function_exists('fCheckDateCSV') )
{ function fCheckDateCSV($iDate) {
$oDate = '';
$aryA = explode( ' ' , fClrHeadChr( $iDate ) );
$aryB = explode( '-' , $aryA[0] );
$vY = '' ; $vM = ''; $vD = '';
if ( sizeof( $aryB ) == 3 )
{
for ( $i = 1 ; $i <= 3 ; $i++ ) { if ( substr( $aryB[$i] , 0 , 1 ) == '0' ) { $aryB[$i] = substr( $aryB[$i] , 1 , 2 ); } }
if ( checkdate( $aryB[1] , $aryB[2] , $aryB[0] ) )
{
$vM = $aryB[1] ; $vD = $aryB[2] ; $vY = $aryB[0] ;
}
}
else
{
$aryB = explode( '/' , $aryA[0] );
if ( sizeof( $aryB ) == 3 )
{
for ( $i = 1 ; $i <= 3 ; $i++ ) { if ( substr( $aryB[$i] , 0 , 1 ) == '0' ) { $aryB[$i] = substr( $aryB[$i] , 1 , 2 ); } }
if ( checkdate( $aryB[1] , $aryB[2] , $aryB[0] ) ) /* Y/M/D */
{
$vM = $aryB[1] ; $vD = $aryB[2] ; $vY = $aryB[0] ;
}
elseif ( checkdate( $aryB[1] , $aryB[0] , $aryB[2] ) ) /* D/M/Y */
{
$vM = $aryB[1] ; $vD = $aryB[0] ; $vY = $aryB[2] ;
}
elseif ( checkdate( $aryB[0] , $aryB[1] , $aryB[2] ) ) /* M/D/Y */
{
$vM = $aryB[0] ; $vD = $aryB[1] ; $vY = $aryB[2] ;
}
}
}
if ( $vY != '' && $vM != '' && $vD != '' )
{
$oDate = $vY.'-'.str_pad( $vM , 2 , '0' , STR_PAD_LEFT ).'-'.str_pad( $vD , 2 , '0' , STR_PAD_LEFT );
}
return($oDate);
} }
/* ********** ********** ********** Camby @ 2012-07 ********** ********** ********** ********** ********** */
function tuneYouTube($url,$type='url') {
$uid = str_replace('http://www.youtube.com/embed/','',$url);
$uid = str_replace('http://www.youtube.com/watch?v=','',$uid);
$uid = str_replace('http://www.youtube.com/v/','',$uid);
$uid = str_replace('?fs=1&autoplay=1','',$uid);
$uid = str_replace('&autoplay=1&autoplay=1','',$uid);
$uid = str_replace('?fs=1','',$uid);
$uid = current(explode('&',$uid));
return $type=='url' ? 'http://www.youtube.com/embed/'.$uid : $uid;
}
/* ********** ********** ********** Camby @ 2012-08 ********** ********** ********** ********** ********** */
function trimUrl($var,$url = '') {
if(!$url) { $url = $_SERVER['REQUEST_URI']; }
if(!is_array($var)) {
$var = array($var);
}
foreach($var as $v) {
$w = explode($v,$url);
$ww = explode('&',$w[1]);
$url = $w[0].$ww[1];
}
while(strstr($url,'&&') && $i<100) {
$url = str_replace('&&','&',$url);
$i++;
}
if(substr($url,strlen($url)-1,1)=='&') {
$url = substr($url,0,strlen($uel)-1);
}
if(!strstr($url,'?')) { $url = $url.'?'; }
return $url;
}
/* ********** ********** ********** Camby @ 2013-07 ********** ********** ********** ********** ********** */
function echoLoop($ary) {
$list = '';
foreach($ary as $a) { $list .= $a; }
return $list;
}
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
if (!function_exists('watermark')) {
function watermark($source, $watermark, $output, $margin_right, $margin_bottom, $opacity) {
$watermark = imagecreatefrompng($watermark);
$gis = getimagesize($source);
$type = $gis['mime'];
switch($type) {
case "image/gif":
$source = imagecreatefromgif($source);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source = imagecreatefromjpeg($source);
break;
case "image/png":
case "image/x-png":
$source = imagecreatefrompng($source);
break;
}
$wx = imagesx($watermark);
$wy = imagesy($watermark);
imagecopymerge($source, $watermark, imagesx($source) - $wx - $margin_right, imagesy($source) - $wy - $margin_bottom, 0, 0, imagesx($watermark), imagesy($watermark), $opacity);
imagejpeg($source, $output);
imagedestroy($source);
}
}
/* ********** ********** ********** Multi Category ********** ********** ********** ********** ********** */
function _findChildren($list,$p_id){
$r = array();
foreach($list as $id=>$item){
if($item['cate_pid'] == $p_id) {
$length = count($r);
$r[$length] = $item;
if($t = _findChildren($list, $item['cate_id'])){
$r[$length]['children'] = $t;
}
}
}
return $r;
}
function _findChildren2($list,$p_id){
$r = array();
foreach($list as $id=>$item){
if($item['color_id'] == $p_id) {
$length = count($r);
$r[$length] = $item;
if($t = _findChildren($list, $item['color_id'])){
$r[$length]['children'] = $t;
}
}
}
return $r;
}
function getCateOption($c,$level,$maximumLevel=0) {
global $cateOption;
// $level = level of category
if($maximumLevel<2) { $maximumLevel = 0; }
if($c[name]) {
for($j=1;$j<=$level;$j++) { $space .= $j>1 ? ' ' : ($level==1 ? '└' : ''); }
if($level>1) { $space .= '└'; }
$cateOption .= '';
}
if(is_array($c[children])) {
$level++;
if($level<$maximumLevel-1 || $maximumLevel==0) {
foreach($c[children] as $cn) {
getCateOption($cn,$level,$maximumLevel);
}
}
}
}
function getCateArray($c,$level,$maximumLevel=0) {
global $cateOption;
// $level = level of category
if($maximumLevel<2) { $maximumLevel = 0; }
if($c[name]) {
for($j=1;$j<=$level;$j++) { $space .= $j>1 ? ' ' : ($level==1 ? '└' : ''); }
if($level>1) { $space .= '└'; }
$c[value] = $c[cate_id];
$c[label] = $space.' '.$c[name];
$c[level] = $level;
if(is_array($c[children])) { $hasChild = true; $child = $c[children]; $c[haschildren] = 1; }
unset($c[children]);
$cateOption[] = $c;
}
if($hasChild) {
$level++;
if($level<$maximumLevel-1 || $maximumLevel==0) {
foreach($child as $cn) {
getCateArray($cn,$level,$maximumLevel);
}
}
}
}
function getCateArray2($c,$level,$maximumLevel=0) {
global $cateOption;
// $level = level of category
if($maximumLevel<2) { $maximumLevel = 0; }
if($c[name]) {
for($j=1;$j<=$level;$j++) { $space .= $j>1 ? ' ' : ($level==1 ? '└' : ''); }
if($level>1) { $space .= '└'; }
$c[value] = $c[color_id];
$c[label] = $space.' '.$c[name];
$c[level] = $level;
if(is_array($c[children])) { $hasChild = true; $child = $c[children]; $c[haschildren] = 1; }
unset($c[children]);
$cateOption[] = $c;
}
if($hasChild) {
$level++;
if($level<$maximumLevel-1 || $maximumLevel==0) {
foreach($child as $cn) {
getCateArray($cn,$level,$maximumLevel);
}
}
}
}
function getCateArray3($c,$level,$maximumLevel=0) {
global $cateOption;
// $level = level of category
if($maximumLevel<2) { $maximumLevel = 0; }
if($c[date]) {
for($j=1;$j<=$level;$j++) { $space .= $j>1 ? ' ' : ($level==1 ? '└' : ''); }
if($level>1) { $space .= '└'; }
$c[value] = $c[cate_id];
$c[label] = $space.' '.$c[date];
$c[level] = $level;
if(is_array($c[children])) { $hasChild = true; $child = $c[children]; $c[haschildren] = 1; }
unset($c[children]);
$cateOption[] = $c;
}
if($hasChild) {
$level++;
if($level<$maximumLevel-1 || $maximumLevel==0) {
foreach($child as $cn) {
getCateArray($cn,$level,$maximumLevel);
}
}
}
}
/* ********** ********** ********** ********** ********** ********** ********** ********** ********** ********** */
?>