// 入库过滤 非管理员全部过滤 $post['message'] = isset($post['gid']) && 1 == $post['gid'] ? $post['message'] : xn_html_safe($post['message']); break; case '1': $post['message'] = xn_txt_to_html($post['message']); break; default: $post['message'] = htmlspecialchars($post['message'], ENT_QUOTES); // html标签全部转换 break; } // 对引用进行处理 !empty($post['quotepid']) && $post['quotepid'] > 0 && $post['message'] = comment_quote($post['quotepid']) . $post['message']; } unset($post['gid']); } /*公用的附件模板,采用函数,效率比 include 高 * @param $filelist 附件列表 * @param bool $include_delete 删除 * @param bool $access TRUE编辑时附件路径 * @param bool $path TRUE后台编辑时附件路径 * @return string */ function data_file_list_html($filelist, $include_delete = FALSE, $access = FALSE, $path = FALSE) { global $conf; if (empty($filelist)) return ''; if (FALSE != $path) { if ($conf['url_rewrite_on'] > 1) { $path = $conf['path']; } else { $path = '../'; } } else { $path = ''; } $s = '
' . "\r\n"; $s .= '' . lang('uploaded_attach') . ':' . "\r\n"; $s .= '' . "\r\n"; $s .= '
' . "\r\n"; return $s; } //--------------------------cache-------------------------- // 从缓存中读取,避免重复从数据库取数据 function data_read_cache($tid) { global $conf; $key = 'website_data_' . $tid; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,要跨进程,可以再加一层缓存: memcached/xcache/apc/ if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $r = data_read($tid); } else { $r = cache_get($key); if (NULL === $r) { $r = data_read($tid); $r and cache_set($key, $r, 1800); // 30分钟 } } $cache[$key] = $r ? $r : NULL; return $cache[$key]; } ?>break; } $r = array('filesize' => filesize($tmpfile), 'width' => $des_width, 'height' => $des_height);; copy($tmpfile, $destfile); is_file($tmpfile) && unlink($tmpfile); imagedestroy($img_dst); return $r; } /** * 图片裁切 * * @param string $sourcefile 原图片路径(绝对路径/abc.jpg) * @param string $destfile 裁切后生成新名称(绝对路径/rename.jpg) * @param int $clipx 被裁切图片的X坐标 * @param int $clipy 被裁切图片的Y坐标 * @param int $clipwidth 被裁区域的宽度 * @param int $clipheight 被裁区域的高度 * image_clip('xxx/x.jpg', 'xxx/newx.jpg', 10, 40, 150, 150) */ function well_image_clip($sourcefile, $destfile, $clipx, $clipy, $clipwidth, $clipheight, $getimgsize = '') { global $conf; empty($getimgsize) AND $getimgsize = getimagesize($sourcefile); if (empty($getimgsize)) { return 0; } else { $imgwidth = $getimgsize[0]; $imgheight = $getimgsize[1]; if (0 == $imgwidth || 0 == $imgheight) { return 0; } } if (!function_exists('imagecreatefromjpeg')) { copy($sourcefile, $destfile); return filesize($destfile); } switch ($getimgsize[2]) { case 1 : $imgcolor = imagecreatefromgif($sourcefile); break; case 2 : $imgcolor = imagecreatefromjpeg($sourcefile); break; case 3 : $imgcolor = imagecreatefrompng($sourcefile); break; case 15: // WBMP $imgcolor = imagecreatefromwbmp($sourcefile); break; case 18: // WEBP $imgcolor = imagecreatefromwebp($sourcefile); break; } if (!$imgcolor) return 0; $img_dst = imagecreatetruecolor($clipwidth, $clipheight); imagefill($img_dst, 0, 0, 0xFFFFFF); imagecopyresampled($img_dst, $imgcolor, 0, 0, $clipx, $clipy, $imgwidth, $imgheight, $imgwidth, $imgheight); $tmppath = isset($conf['tmp_path']) ? $conf['tmp_path'] : ini_get('upload_tmp_dir') . '/'; '/' == $tmppath AND $tmppath = './tmp/'; $tmpfile = $tmppath . md5($destfile) . '.tmp'; imagejpeg($img_dst, $tmpfile, 75); $n = filesize($tmpfile); copy($tmpfile, $destfile); is_file($tmpfile) && unlink($tmpfile); return $n; } function well_image_ext($filename) { return strtolower(substr(strrchr($filename, '.'), 1)); } ?>