*/ 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; // trace ( $baseFile, "basefiel" ); $file = str_replace ( C ( 'VIR_DIR' ), ".", $file ); // 替换掉虚拟目录 if (! file_exists ( $file )) { // 判断原文件是否存在,不存在直接返回。 if (empty ( $def )) { // 如果没有默认图片 return $file; } else { // trace($def,"def"); 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; } /** * 从摘要和内容中显示关键字 * @param unknown $descript * @param unknown $content * @param unknown $keyword */ 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" ); // 视为字节流,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");//视为字节流,utf-8下一个汉 return showKeyword($keyword,$content); } return getDescript($descript,$content);//如果都没有关键字 //echo intval( stripos($str,'斯')); //echo mb_strcut($str,4,10,"utf-8");//视为字节流,utf-8下一个汉 } /** * 跳转 * * @param unknown $url */ function jumpUrl($url) { if (! empty ( $url )) { redirect ( $url ); exit (); } } function simpleHtmlEncode($str){ $str = str_replace ( "\r\n", "
", $str ); // \r\n $str= str_replace ( "\r", "
", $str ); // 替换"\r" $str= str_replace ( "\n", "
", $str ); // 替换"\n" $str= str_replace ( " ", " ", $str ); // 替换"\n" return $str; } function simpleHtmlDecode($str){ $str=str_replace("
","\r\n",$str); $str=str_replace(" "," ",$str); return $str; } /** * 显示关键字 * @param unknown $keyword * @param unknown $content * @return mixed */ function showKeyword($keyword,$content){ return str_replace($keyword,"$keyword",$content); } function sendMail($mailto,$subject,$content){ vendor("Mail.smtp"); $conditon['code']='email'; $result=M('config')->where($conditon)->find(); $model=unserialize($result['content']); //使用163邮箱服务器 $smtpserver =$model['smtpserver'];// "smtp.qq.com"; //163邮箱服务器端口 $smtpserverport = 25; //你的163服务器邮箱账号 $smtpusermail =$model['smtpusermail'];// "ycxxkj002@qq.com"; //收件人邮箱 $smtpemailto =$mailto;// "lzj500@qq.com"; //你的邮箱账号(去掉@163.com) $smtpuser =$model['smtpuser'];// "2936890167";//SMTP服务器的用户帐号 //你的邮箱密码 $smtppass = $model['smtppass'];//"mail2015"; //SMTP服务器的用户密码 //邮件主题 $mailsubject = $subject;//"测试邮件发送"; //邮件内容 $mailbody =$content;// " PHP+MySQL+点击跳转"; //邮件格式(HTML/TXT),TXT为文本邮件 $mailtype = "HTML"; //这里面的一个true是表示使用身份验证,否则不使用身份验证. $smtp = new \smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass); //是否显示发送的调试信息 $smtp->debug =false;// TRUE; //$smtp->debug = TRUE; //发送邮件 $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; } ?>