-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
81 lines (72 loc) · 2.29 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
// module local use functions
// $Id: functions.php,v 1.13 2010/01/31 06:04:36 nobu Exp $
define('TBL', $xoopsDB->prefix("refpage"));
define('TBR', $xoopsDB->prefix("refpage_ref"));
define('URI_BASE', preg_replace('/^http:\/\/[^\/]*/', '', XOOPS_URL)."/");
define('REG_MOD', "/^".preg_quote(URI_BASE."modules/", "/").'([^\/]+)\//');
function uri_to_name($uri) {
if ($uri==URI_BASE) return _TB_TOPPAGE;
if (preg_match(REG_MOD, $uri, $d)) {
// module pages
$mod = XoopsModule::getByDirname($d[1]);
$name = is_object($mod)?$mod->getVar("name"):$d[1];
$rest = myurldecode(preg_replace(REG_MOD, '', $uri));
$rest = str_replace("index.php?","",$rest);
return $name.($rest==""?"":" - ").$rest;
}
return $uri;
}
function strim($s, $l=50) {
if (strlen($s)<$l) return $s;
$h = intval(($l-3)/2);
$t = strlen($s)-$h+3;
return htmlspecialchars(mysubstr($s,0,$h)._TB_LEADER.mysubstr($s,$t));
}
function myurldecode($url) {
$url = rawurldecode($url);
if (XOOPS_USE_MULTIBYTES && function_exists("mb_convert_encoding")) {
$url = @mb_convert_encoding($url, _CHARSET, "ISO-2022-JP,JIS,EUC-JP,UTF-8,SJIS");
}
return $url;
}
// substrings with support multibytes (--with-mbstring)
function mysubstr($s, $f, $l=99999) {
if (XOOPS_USE_MULTIBYTES && function_exists("mb_strcut")) {
return mb_strcut($s, $f, $l, _CHARSET);
} else {
return substr($s, $f, $l);
}
}
function make_page_index($title, $max, $cur, $format, $asis=" <b>[%d]</b>") {
global $xoopsModuleConfig;
$npg = intval(($max-1)/$xoopsModuleConfig['list_max'])+1;
if ($npg<2) $npg=1;
$result = "<div class='pgindex'>$title: ";
$side = 2;
if ($cur > $side+2) {
$result .= sprintf($format, 1, 1)." "._TB_LEADER." ";
$start = $cur-$side;
} else {
$start = 1;
}
for ($i=$start; $i<=$npg;$i++) {
if ($i==$cur) {
$result .= sprintf($asis, $i);
} else {
$result .= sprintf($format, $i, $i);
if ($i>=$cur+$side && $i<=$npg-$side) {
$result .= " "._TB_LEADER." ".sprintf($format, $npg, $npg);
break;
}
}
}
$result .= "</div>";
return $result;
}
// Win/Mac/Unix's newline normalize
function crlf2nl($s) {
return preg_replace("/\x0D\x0A|\x0D|\x0A/","\n", $s);
}
$tags = preg_match("/^XOOPS 1\\./",XOOPS_VERSION)?array("bg1","bg3"):array("even","odd");
?>