景图 $bgimgdir = PLUGIN_PATH.'le_title_pic/bg_img/'; if( !is_dir($bgimgdir) ){exit();} $all_image_files = _scandir($bgimgdir);//背景图存放文件夹的jpg图片 foreach ($all_image_files as $k=>$file){ if($file == '.' || $file == '..'){ unset($all_image_files[$k]); } } if( empty($all_image_files) ){ exit(); } shuffle($all_image_files); $backgroundFile = array_slice($all_image_files, 0, 1); $backgroundPath = $bgimgdir.$backgroundFile[0]; $font = PLUGIN_PATH."le_title_pic/static/font.otf"; //字体 $size = 14; //默认字体大小 $oneline = 10; preg_match_all("/./u", $title, $t_arr);//将所有字符转成单个数组 $tarr = $t_arr[0]; $t_total = count($tarr); //标题长度 if($t_total > 30){ $t_total = 30; } $cha = 30 - $t_total; $size = $size + $cha; if($size > 28 ){ $size = 28; }elseif($size < 18){ $size = 18; } $text = ''; if($t_total > $oneline){ $line = 2; $bnum = $t_total/2; $snum = 0; for ($x = 0; $x < $t_total; $x++) { $snum++; if($snum >= $bnum){ $snum = 0; $text .= $tarr[$x].PHP_EOL; }else{ if($x > 27){ $text .= "..."; break; }else{ $text .= $tarr[$x]; } } } }else{ $text = $title; $line = 1; } //创建图片 $img = imagecreatefromjpeg($backgroundPath); $width = imagesx($img); $height = imagesy($img); if($line > 1){ $a = imagettfbbox($size, 0, $font, $text); //得到字符串虚拟方框四个点的坐标 $len = $a[2] - $a[0]; $x = ($width-$len)/2; $h = $size/10; $y = ($height/2)-15+$h; }else{ $a = imagettfbbox($size, 0, $font, $text); //得到字符串虚拟方框四个点的坐标 $len = $a[2] - $a[0]; $x = ($width-$len)/2; $h = $size/10; $y = ($height/2)+10+$h; } $color = imagecolorallocate($img, 255, 255, 255); // 0 0 0 表示黑色 $setting = $this->kv->get('le_title_pic_setting'); $cache_day = $setting['cache_day'].' day'; //缓存天数 //将规定当前页面缓存的时间(两天),并在下一次访问中使用这个缓存时间节点。接下来判断是否已经有缓存,如果有,就使用缓存。 header("Cache-Control: private, max-age=10800, pre-check=10800"); header("Pragma: private"); header("Expires: " . date(DATE_RFC822, strtotime($cache_day))); header("Content-type:image/jpeg"); imagettftext($img, $size, 0, $x, $y, $color, $font, $text); imagejpeg($img); imagedestroy($img); exit(); } // mz/ 路径解析 - 宝宝起名方案页 if(substr($uri , 0 , 4) == 'mz/' && strlen($uri) > 4){ $newurl = substr($uri, 0, -$url_suffix_len); $u_arr = explode('/', $newurl); if(!isset($u_arr[1])){ core::error404(); } $_GET['control'] = 'qm'; $_GET['action'] = 'mz'; $_GET['xing'] = $u_arr[1]; // 解析性别和类型 if(isset($u_arr[2])){ $sex_type = explode('_', $u_arr[2]); $_GET['sex'] = isset($sex_type[0]) ? $sex_type[0] : 0; $_GET['type'] = isset($sex_type[1]) ? $sex_type[1] : 1; } return; } // 笔画URL解析 - 移到最前面,确保最先被调用 $r = $this->bihua_url($cfg, $uri); if($r){return;} // 部首URL解析 $r = $this->bushou_url($cfg, $uri); if($r){return;} // 拼音URL解析 $r = $this->pinyin_url($cfg, $uri); if($r){return;} // 康熙字典URL解析 $r = $this->kangxi_url($cfg, $uri); if($r){return;} //站点地图 $sitemap_uri = array('sitemap.xml', 'sitemap.html', 'sitemap.txt'); if(in_array($uri, $sitemap_uri)){ $u_arr = explode('.', $uri); $_GET['control'] = 'sitemap'; $_GET['action'] = $u_arr[1]; return; } $r = $this->category_url($cfg, $uri); if($r){return;} $r = $this->content_url($cfg, $uri); if($r){return;} $r = $this->tag_url($cfg, $uri); if($r){return;} $r = $this->search_url($cfg, $uri); if($r){return;} $r = $this->comment_url($cfg, $uri); if($r){return;} $r = $this->index_page_url($cfg, $uri); if($r){return;} $r = $this->tag_like_url($cfg, $uri); if($r){return;} $r = $this->user_url($cfg, $uri); if($r){return;} $r = $this->model_url($cfg, $uri); if($r){return;} $r = $this->flags_url($cfg, $uri); if($r){return;} $r = $this->space_url($cfg, $uri); if($r){return;} } //伪静态结束------------------------------------------------------------------------------------------------------ // 伪静态时,如果 $uri 有值,但没有解析到相关 $_GET 时,就提示404 if(empty($_GET) && isset($uri) && !empty($uri)) { core::error404(); } if( !isset($_GET['control']) ) { $r = $this->other_url(); if($r){return;} } } //---------------------------------------------------------------------- 以下是各模块URL解析的具体函数实现 //模型页URL解析 protected function model_url($cfg = array(), $uri = ''){ // 如果是bihua开头的URL,直接返回false,不处理,让bihua_url方法处理 if(substr($uri, 0, 6) == 'bihua/') { return false; } //模型信息 table=>mid $model_arr = array_flip($cfg['table_arr']); // 模型URL未设置后缀/的情况,301重定向到已设置后缀的URL if( isset($model_arr[$uri]) ) { http_location($cfg['weburl'].$uri.'/', '301'); } $_GET['control'] = 'model'; $_GET['action'] = 'index'; if(substr($uri, -1) == '/'){ $newurl = substr($uri, 0, -1); }else{ $newurl = $uri; } //模型首页URL if( isset($model_arr[$newurl]) ) { $_GET['mid'] = (int)$model_arr[$newurl]; return true; } //模型分页URL $u_arr = explode('/', $newurl); if( isset($model_arr[$u_arr[0]]) ) { $_GET['mid'] = (int)$model_arr[$u_arr[0]]; //分页 if( isset($u_arr[1]) ){ if($page = $this->page_check($u_arr[1])){ $_GET['page'] = $page; }else{ core::error404(); } } return true; } unset($_GET['control']); unset($_GET['action']); return false; } //分类URL解析 protected function category_url($cfg = array(), $uri = ''){ //分类信息 alias=>cid $cate_arr = arr $mat); if( isset($mat[2]) ) { $_GET['cid'] = $mat[1]; $_GET['id'] = $mat[2]; return true; } }elseif( isset($mat['alias']) ) { // {alias} preg_match("/^(\d+)\_(\d+)$/i", $mat['alias'], $mat2); //没有设置别名,将用 cid_id 组合 if( isset($mat2[2]) ) { $_GET['cid'] = $mat2[1]; $_GET['id'] = $mat2[2]; return true; } $row = $this->only_alias->get($mat['alias']); if(!empty($row)) { $_GET['cid'] = $row['cid']; $_GET['id'] = $row['id']; return true; } }elseif( isset($mat['hashids']) ) { // {hashids} $newurl = hashids_decrypt($mat['hashids']);//解密得到 cid id 数组 if(is_array($newurl) && isset($newurl[1])){ $_GET['cid'] = $newurl[0]; $_GET['id'] = $newurl[1]; return true; } } // 比如article/id.html,只能一个文章模型(多模型的不行,没法区分id属于那个模型的),因此丢到最后 if ( isset($mat['id']) && $this->integer_check($mat['id']) ){ $u_arr = explode('/', $uri); if( substr($cfg['link_show'], 0, strlen($u_arr[0])) == $u_arr[0] ){ $_GET['mid'] = 2; $_GET['id'] = $mat['id']; return true; } } } break; case 8: //HashIDS $newurl = hashids_decrypt($newurl);//解密得到 cid id 数组 if(is_array($newurl) && isset($newurl[1])){ $_GET['cid'] = $newurl[0]; $_GET['id'] = $newurl[1]; return true; } break; } unset($_GET['control']); unset($_GET['action']); return false; } //标签URL解析 protected function tag_url($cfg = array(), $uri = ''){ $len = strlen($cfg['link_tag_pre']); if(substr($uri, 0, $len) == $cfg['link_tag_pre']) { $len2 = strlen($cfg['link_tag_end']); if(substr($uri, -$len2) == $cfg['link_tag_end']) { $_GET['control'] = 'tag'; $_GET['action'] = 'index'; $newurl = substr($uri, $len, -$len2); $u_arr = explode('/', $newurl); $u_arr_count = count($u_arr); if($u_arr_count > 2){ core::error404(); } //分页 if( isset($u_arr[1]) ){ $page = $this->page_check($u_arr[1]); if($page){ $_GET['page'] = $page; }else{ core::error404(); } } switch ($cfg['link_tag_type']){ case 0: preg_match('/^(\d+)\_(.+)$/i', $u_arr[0], $mat); if( isset($mat[2]) ) { if( !$this->mid_check($mat[1], $cfg) ){core::error404();} $_GET['mid'] = $mat[1]; $_GET['name'] = $mat[2]; return true; }else{ $_GET['mid'] = 2; $_GET['name'] = $u_arr[0]; return true; } break; case 1: preg_match("/^(\d+)\_(\d+)$/i", $u_arr[0], $mat); if( isset($mat[2]) ) { if( !$this->mid_check($mat[1], $cfg) ){core::error404();} $_GET['mid'] = $mat[1]; $_GET['tagid'] = $mat[2]; return true; }elseif( $this->integer_check($u_arr[0]) ){ $_GET['mid'] = 2; $_GET['tagid'] = $u_arr[0]; return true; } break; case 2: $newurl = decrypt($u_arr[0]);//解密得到 mid_tagid preg_match("/^(\d+)\_(\d+)$/i", $newurl, $mat); if( isset($mat[2]) ){ if( !$this->mid_check($mat[1], $cfg) ){core::error404();} $_GET['mid'] = (int)$mat[1]; $_GET['tagid'] = (int)$mat[2]; return true; } break; case 3: $newurl = hashids_decrypt($u_arr[0]);//解密得到 mid tagid 数组 if(is_array($newurl) && isset($newurl[1])){ $_GET['mid'] = (int)$newurl[0]; $_GET['tagid'] = (int)$newurl[1]; return true; } break; } }else{ //尝试301跳转到带后缀的链接试试看~ http_location($cfg['weburl'].$uri.$cfg['link_tag_end'], '301'); } } unset($_GET['control']); unset($_GET['action']); return false; } //搜索URL解析 protected function search_url($cfg = array(), $uri = ''){ if(substr($uri, 0, 7) == 'search/') { if(substr($uri, -1) != '/'){$uri .= '/';} $newurl = substr($uri, 7, -1); $uarr = explode('/', $newurl); //模型ID if(isset($uarr[0]) && substr($uarr[0], 0 ,4) == 'mid_'){ $mid = substr($uarr[0], 4); if($this->mid_check($mid, $cfg)){ $_GET['mid'] = $mid; array_shift($uarr); }else{ core::error404(); } }else{ $_GET['mid'] = 2; } //排除多余的参数 if(count($uarr) > 2){core::error404();} //关键词 $_GET['keyword'] = $uarr[0]; //分页 if( isset($uarr[1]) ){ $page = $this->page_check($uarr[1]); if($page){ $_GET['page'] = $page; }else{ core::error404(); } } $_GET['control'] = 'search'; $_GET['action'] = 'index'; return true; } //搜索页面链接解析 $url_suffix = isset($_ENV['_config']['url_suffix']) ? $_ENV['_config']['url_suffix'] : '.html'; $url_suffix_len = strlen($url_suffix); if(substr($uri, -$url_suffix_len) == $url_suffix && substr($uri, 0, -$url_suffix_len) == 'so') { $_GET['control'] = 'search'; $_GET['action'] = 'so'; return true; } return false; } //评论URL解析 protected function comment_url($cfg = array(), $uri = ''){ $len = Lecms 3.0.3 lang[error]

lang[error_info]

lang[error_line]

lang[basic_trace]

lang[program_flow]

SQL

$_GET

$_POST

$_COOKIE

lang[include_file]

lang[other_trace]