<?
if (!defined('_GNUBOARD_')) exit;
/*************************************************************************
**
** Gunboard常用参数
**
*************************************************************************/
// 时间
function get_microtime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
// 页码计算
function get_paging($write_pages, $cur_page, $total_page, $url, $add="")
{
$str = "";
if ($cur_page > 1) {
$str .= "<a href='" . $url . "1{$add}'>第一页</a>";
//$str .= "[<a href='" . $url . ($cur_page-1) . "'>上一页</a>]";
}
$start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1;
$end_page = $start_page + $write_pages - 1;
if ($end_page >= $total_page) $end_page = $total_page;
if ($start_page > 1) $str .= " <a href='" . $url . ($start_page-1) . "{$add}'>上一页</a>";
if ($total_page > 1) {
for ($k=$start_page;$k<=$end_page;$k++) {
if ($cur_page != $k)
$str .= " <a href='$url$k{$add}'><span>$k</span></a>";
else
$str .= " <b>$k</b> ";
}
}
if ($total_page > $end_page) $str .= " <a href='" . $url . ($end_page+1) . "{$add}'>下一页</a>";
if ($cur_page < $total_page) {
//$str .= "[<a href='$url" . ($cur_page+1) . "'>下一页</a>]";
$str .= " <a href='$url$total_page{$add}'>最后一页</a>";
}
$str .= "";
return $str;
}
// print_r()
function print_r2($var)
{
ob_start();
print_r($var);
$str = ob_get_contents();
ob_end_clean();
$str = preg_replace("/ /", " ", $str);
echo nl2br("<span style='font-family:Tahoma, 宋体; font-size:9pt;'>$str</span>");
}
// URL 跳转
// header("location:URL") 代替代码
function goto_url($url)
{
/*
if (preg_match("/MSIE/", $_SERVER[HTTP_USER_AGENT]))
echo "<meta http-equiv='Refresh' content='0;url=$url'>";
else
echo "<script language='JavaScript'> document.location.href = '$url'; </script>";
*/
//header("Location:$url");
//flush();
//if (!headers_sent())
// header("Location:$url");
//else
//echo "<script language='JavaScript'> document.location.href = '$url'; </script>";
echo "<script language='JavaScript'> location.replace('$url'); </script>";
exit;
}
// session 创建
function set_session($session_name, $value)
{
if (PHP_VERSION < '5.3.0')
session_register($session_name);
// PHP 方式因版本不同导致的不兼容问题
$$session_name = $_SESSION["$session_name"] = $value;
}
// session变数
function get_session($session_name)
{
return $_SESSION[$session_name];
}
// 创建缓存变量
function set_cookie($cookie_name, $value, $expire)
{
global $g4;
setcookie(md5($cookie_name), base64_encode($value), $g4[server_time] + $expire, '/', $g4[cookie_domain]);
}
// 获取缓存
function get_cookie($cookie_name)
{
return base64_decode($_COOKIE[md5($cookie_name)]);
}
// 提示窗口
function alert($msg='', $url='')
{
global $g4;
if (!$msg) $msg = '请使用正确方式!';
//header("Content-Type: text/html; charset=$g4[charset]");
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=$g4[charset]\">";
echo "<script language='javascript'>alert('$msg');";
if (!$url)
echo "history.go(-1);";
echo "</script>";
if ($url)
// 4.06.00 : 火狐狸
//echo "<meta http-equiv='refresh' content='0;url=$url'>";
goto_url($url);
exit;
}
// 关闭提示
function alert_close($msg)
{
global $g4;
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=$g4[charset]\">";
echo "<script language='javascript'> alert('$msg'); window.close(); </script>";
exit;
}
// 参考way.co.kr wayboard
function url_auto_link($str)
{
global $config;
// 优化 031011
$str = preg_replace("/</", "\t_lt_\t", $str);
$str = preg_replace("/>/", "\t_gt_\t", $str);
$str = preg_replace("/&/", "&", $str);
$str = preg_replace("/"/", "\"", $str);
$str = preg_replace("/ /", "\t_nbsp_\t", $str);
$str = preg_replace("/([^(http:\/\/)]|\(|^)(www\.[^[:space:]]+)/i", "\\1<A HREF=\"http://\\2\" TARGET='$config[cf_link_target]'>\\2</A>", $str);
$str = preg_replace("/([^(HREF=\"?'?)|(SRC=\"?'?)]|\(|^)((http|https|ftp|telnet|news|mms):\/\/[a-zA-Z0-9\.-]+\.[\xA1-\xFEa-zA-Z0-9\.:&#=_\?\/~\+%@;\-\|\,]+)/i", "\\1<A HREF=\"\\2\" TARGET='$config[cf_link_target]'>\\2</A>", $str);
// 邮件地址表达式 061004
//$str = preg_replace("/(([a-z0-9_]|\-|\.)+@([^[:space:]]*)([[:alnum:]-]))/i", "<a href='mailto:\\1'>\\1</a>", $str);
$str = preg_replace("/([0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,4})/i", "<a href='mailto:\\1'>\\1</a>", $str);
$str = preg_replace("/\t_nbsp_\t/", " " , $str);
$str = preg_replace("/\t_lt_\t/", "<", $str);
$str = preg_replace("/\t_gt_\t/", ">", $str);
return $str;
}
// url添加 http://
function set_http($url)
{
if (!trim($url)) return;
if (!preg_match("/^(http|https|ftp|telnet|news|mms)\:\/\//i", $url))
$url = "http://" . $url;
return $url;
}
// 获取文件大小
//function get_filesize($file)
function get_filesize($size)
{
//$size = @filesize(addslashes($file));
if ($size >= 1048576) {
$size = number_format($size/1048576, 1) . "M";
} else if ($size >= 1024) {
$size = number_format($size/1024, 1) . "K";
} else {
$size = number_format($size, 0) . "byte";
}
return $size;
}
// 获取文件数量
function get_file($bo_table, $wr_id)
{
global $g4, $qstr;
$file["count"] = 0;
$sql = " select * from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no ";
$result = sql_query($sql);
while ($row = sql_fetch_array($result))
{
$no = $row[bf_no];
$file[$no][href] = "/bbs/download.php?bo_table=$bo_table&wr_id=$wr_id&no=$no" . $qstr;
$file[$no][download] = $row[bf_download];
// 4.00.11 - 附件path
$file[$no][path] = "$g4[path]/data/file/$bo_table";
//$file[$no][size] = get_filesize("{$file[$no][path]}/$row[bf_file]");
$file[$no][size] = get_filesize($row[bf_filesize]);
//$file[$no][datetime] = date("Y-m-d H:i:s", @filemtime("$g4[path]/data/file/$bo_table/$row[bf_file]"));
$file[$no][datetime] = $row[bf_datetime];
$file[$no][source] = addslashes($row[bf_source]);
$file[$no][bf_content] = $row[bf_content];
$file[$no][content] = get_text($row[bf_content]);
//$file[$no][view] = view_file_link($row[bf_file], $file[$no][content]);
$file[$no][view] = view_file_link($row[bf_file], $row[bf_width], $row[bf_height], $file[$no][content]);
$file[$no][file] = $row[bf_file];
// prosper 提供
//$file[$no][imgsize] = @getimagesize("{$file[$no][path]}/$row[bf_file]");
$file[$no][image_width] = $row[bf_width] ? $row[bf_width] : 640;
$file[$no][image_height] = $row[bf_height] ? $row[bf_height] : 480;
$file[$no][image_type] = $row[bf_type];
$file["count"]++;
}
return $file;
}
// 文件夹容量 ($dir不能使用 /符号 )
function get_dirsize($dir)
{
$size = 0;
$d = dir($dir);
while ($entry = $d->read()) {
if ($entry != "." && $entry != "..") {
$size += filesize("$dir/$entry");
}
}
$d->close();
return $size;
}
/*************************************************************************
**
** 关联参数
**
*********************************