123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- if (get_magic_quotes_gpc ()) {
- function stripslashes_deep($value) {
- $value = is_array ( $value ) ? array_map ( 'stripslashes_deep', $value ) : stripslashes ( $value );
- return $value;
- }
- $_POST = array_map ( 'stripslashes_deep', $_POST );
- $_GET = array_map ( 'stripslashes_deep', $_GET );
- $_COOKIE = array_map ( 'stripslashes_deep', $_COOKIE );
- }
- function cutString($str,$len){
- $str=strip_tags($str);
- $strLen=strlen($str);
-
- if($strLen<=$len*3){
- return $str;
- }
- return mb_substr($str,0,$len,'utf-8')."...";
- }
- function my_serialize($obj) {
- return base64_encode ( gzcompress ( serialize ( $obj ) ) );
- }
- function my_unserialize($txt) {
- return unserialize ( gzuncompress ( base64_decode ( $txt ) ) );
- }
- function request($key, $df_value = '') {
- return isset ( $_REQUEST [$key] ) ? trim ( $_REQUEST [$key] ) : $df_value;
- }
- function getParam($key){
-
- $val=request($key);
- if(empty($val)){
- $val=cookie($key);
- }
- return $val;
- }
- function img($file, $width = 200, $height = 200, $def = '') {
- if (preg_match ( '/^http:\/\//', $file )) {
-
- return $file;
- }
-
- $temp_arr = explode(".", $file);
- $file_ext = array_pop($temp_arr);
- $file_ext = trim($file_ext);
- $file_ext = strtolower($file_ext);
- $baseFile = basename ( $file );
- $basePath = str_replace ( $baseFile, "", $file ) . "temp/";
- $baseFile = str_replace ( ".", "", $baseFile );
- $baseFile .= $width . "x" . $height . ".jpg";
- $basePath = str_replace ( C ( 'VIR_DIR' ), ".", $basePath );
- if (! is_readable ( $basePath )) {
- is_file ( $basePath ) or mkdir ( $basePath, 0777 );
- }
- $baseFile = $basePath . $baseFile;
-
- $file = str_replace ( C ( 'VIR_DIR' ), ".", $file );
- if (! file_exists ( $file )) {
- if (empty ( $def )) {
- return $file;
- } else {
-
- return $def;
- }
- }
-
- if($file_ext=="gif"){
- return $file;
- }
- if (! file_exists ( $baseFile )) {
- $image = new \Think\Image ();
- $image->open ( $file );
- $image->thumb ( $width, $height, \Think\Image::IMAGE_THUMB_FILLED )->save ( $baseFile );
- }
- $str2 = substr ( $baseFile, 0, 2 );
- if ($str2 == "./") {
- $baseFile = C ( 'VIR_DIR' ) . substr ( $baseFile, 1 );
- }
- return $baseFile;
- }
- function getDescKey($descript,$content,$keyword){
- $startPre=80;
- $len=160;
-
- $index=intval( stripos($descript,$keyword));
- if($index>0){
- $begin = $index - $startPre > 0 ? $index - $startPre : 0;
- $descript = mb_strcut ( $descript, $begin, $len, "utf-8" );
- return showKeyword($keyword,$descript);
- }
- $content=strip_tags($content);
- $index=intval( stripos($content,$keyword));
- if($index>0){
- $begin=$index-$startPre>0?$index-$startPre:0;
- $content= mb_strcut($content,$begin,$len,"utf-8");
- return showKeyword($keyword,$content);
- }
- return getDescript($descript,$content);
-
-
- }
- function jumpUrl($url) {
- if (! empty ( $url )) {
- redirect ( $url );
- exit ();
- }
- }
- function simpleHtmlEncode($str){
- $str = str_replace ( "\r\n", "<br/>", $str );
- $str= str_replace ( "\r", "<br/>", $str );
- $str= str_replace ( "\n", "<br/>", $str );
- $str= str_replace ( " ", " ", $str );
- return $str;
- }
- function simpleHtmlDecode($str){
- $str=str_replace("<br/>","\r\n",$str);
- $str=str_replace(" "," ",$str);
- return $str;
- }
- function showKeyword($keyword,$content){
- return str_replace($keyword,"<font class='red'>$keyword</font>",$content);
- }
- function sendMail($mailto,$subject,$content){
- vendor("Mail.smtp");
- $conditon['code']='email';
- $result=M('config')->where($conditon)->find();
- $model=unserialize($result['content']);
-
- $smtpserver =$model['smtpserver'];
-
- $smtpserverport = 25;
-
- $smtpusermail =$model['smtpusermail'];
-
- $smtpemailto =$mailto;
-
- $smtpuser =$model['smtpuser'];
-
- $smtppass = $model['smtppass'];
-
- $mailsubject = $subject;
-
- $mailbody =$content;
-
- $mailtype = "HTML";
-
- $smtp = new \smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);
-
- $smtp->debug =false;
-
-
- $res=$smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype);
-
- }
- function get_url() {
- $sys_protocal = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
- $php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
- $path_info = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '';
- $relate_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $php_self.(isset($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : $path_info);
- return $sys_protocal.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '').$relate_url;
- }
- ?>
|