Discuz中的分页函数
发布人:blankyao 时间:2007-10-22 23:31 来源: Php Question 查看: 5039次
水平有限 其中的错误敬请指正
[php]//先看下几个参数吧
//$num 为总共的条数 比如说这个分类下共有15篇文章
// $perpage为每页要显示的条数
//$curpage为当前的页数
//$mpurl为url的除去表示页数变量的一部分,
//$page为$multipage这个字符串中要显示的表示页数的变量个数
//$maxpages为最大的页数值 此函数最后有一句$maxpage = $realpages;
function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = TRUE, $simple = FALSE) {
global $maxpage;
$ajaxtarget = !emptyempty($_GET['ajaxtarget']) ? " ajaxtarget=\"".dhtmlspecialchars($_GET['ajaxtarget'])."\" " : '';
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&' : '?';
$realpages = 1;
//判断总条数是否大于设置的每页要显示的条数
if($num > $perpage) {
//设置在$multipage中当前页数之前还要输出几个页数
$offset = 2;
$realpages = @ceil($num / $perpage);
//总共的页数(不知道$maxpages的意思),这里假设是15条
$pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;
//如果总页数小于multipage中要输出的页数$page,则只输出到实际页数为止
if($page > $pages) {
$from = 1;
$to = $pages;
//如果大于的话,就要输出$page个页数(我们假设的的15条就符合这个条件)
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
//假设curpage为4,目前为止,from为2,to为11
//下面假设curpage为1
if($from < 1) {
$to = $curpage + 1 - $from;(****不明白***)
$from = 1;
//目前为止from为1,to为3
if($to - $from < $page) {
//因为这里的前提条件是总条数大于page,所以,如果$to-$from小于page的话显然达不到目的,应把$to设置为$page
$to = $page;
}//目前为止 from为1 ,to为10
} elseif($to > $pages) {//to是不可以大于总页数的
$from = $pages - $page + 1;
$to = $pages;
}
}
$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="first"'.$ajaxtarget.'>1 ...</a>' : '').
($curpage > 1 && !$simple ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="prev"'.$ajaxtarget.'>‹‹</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :
'<a href="'.$mpurl.'page='.$i.($ajaxtarget && $i == $pages && $autogoto ? '#' : '').'"'.$ajaxtarget.'>'.$i.'</a>';
}
$multipage .= ($curpage < $pages && !$simple ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="next"'.$ajaxtarget.'>››</a>' : '').
($to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="last"'.$ajaxtarget.'>... '.$realpages.'</a>' : '').
(!$simple && $pages > $page && !$ajaxtarget ? '<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=\''.$mpurl.'page=\'+this.value; return false;}" /></kbd>' : '');
$multipage = $multipage ? '<div class="pages">'.(!$simple ? '<em> '.$num.' </em>' : '').$multipage.'</div>' : '';
}
$maxpage = $realpages;
return $multipage;
}
[/php]




文章评论
共有 9 位PhpQ的网友发表了评论查看完整内容
而且Discuz!的很多处理机制也被很多程序作者引用了,我有印象的比如sablog
我自己就是把discuz改的巫七麻西去做这种东西。
[php]if($num > $perpage) {
$page = 11;
$offset = 5;
$realpages = @ceil($num / $perpage);
$pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;
if($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if($from < 1) {
$to = $curpage + 1 - $from;
$from = 1;
if($to - $from < $page) {
$to = $page;
}
} elseif($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;
}
}
$multipage['left'] = $curpage > 1 ? '<a href="'.$mpurl.($curpage - 1).'.html">上一页</a> ' : '';
$multipage['right'] = '';
for($i = $from; $i <= $to; $i++) {
$multipage['left'] .= $i < $curpage ? '<a href="'.$mpurl.$i.'.html">'.$i.'</a> ' : '';
$multipage['right'] .= $i > $curpage ? '<a href="'.$mpurl.$i.'.html">'.$i.'</a> ' : '';
}
$multipage['right'] .= $curpage < $realpages ? '<a href="'.$mpurl.($curpage + 1).'.html">下一页</a> ' : '';
}
[/php]
$multipage['left']和$multipage['right']是分别放在左右两边的,就是ijavascript.cn的效果!
CODE:
function codedisp($code) {[php]function codedisp($code) {global $discuzcodes;
$discuzcodes['pcodecount']++;
$code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = tpl_codedisp($discuzcodes, $code);
$discuzcodes['codecount']++;
return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
global $discuzcodes;
$discuzcodes['pcodecount']++;
$code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = tpl_codedisp($discuzcodes, $code);
$discuzcodes['codecount']++;
return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
[/php]
有兴趣一起交流一下 QQ 59810752 www.njphp.cn
<html><head>
<title>Discuz! Administrator's Control Panel</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$charset?>">
<script src="include/javascript/common.js" type="text/javascript"></script>
<script src="include/javascript/iframe.js" type="text/javascript"></script>
</head>
<body style="margin: 0px" scroll="no">
<div style="position: absolute;top: 0px;left: 0px; z-index: 2;height: 65px;width: 100%">
<iframe frameborder="0" id="header" name="header" src="admincp.php?action=header&sid=<?=$sid?>" scrolling="no" style="height: 65px; visibility: inherit; width: 100%; z-index: 1;"></iframe>
</div>
<table border="0" cellPadding="0" cellSpacing="0" height="100%" width="100%" style="table-layout: fixed;">
<tr><td width="165" height="65"></td><td></td></tr>
<tr>
<td><iframe frameborder="0" id="menu" name="menu" src="admincp.php?action=menu&sid=<?=$sid?>" scrolling="yes" style="height: 100%; visibility: inherit; width: 100%; z-index: 1;overflow: auto;"></iframe></td>
<td><iframe frameborder="0" id="main" name="main" src="admincp.php?<?=$extra?>&sid=<?=$sid?>" scrolling="yes" style="height: 100%; visibility: inherit; width: 100%; z-index: 1;overflow: auto;"></iframe></td>
</tr></table>
</body>
</html>
<?[/php]
/*
This php program will convert jass text to a formed style.
To use this one you need to set a string variable and convey it to the function jassc.
The function jassc will return the formed jass text as a string.
------------------------------
Be care that the conveyed text should less than 5000 bytes.
If the text is a much longer,the function will cut the spare bytes.
The output string is html format.
------------------------------
The infomation about which things should be convert will write in jassstyle.txt .
The color and font style will be seen after every title.
If you find any mistakes or have any suggestions please e-mail:
shingoscar@yahoo.com.cn .
------------------------------
Made by shingoscar at 08.1.25
Version 0.1
------------------------------
*/
define('DEBUG',FALSE);
define('MAX_KOV',87);
define('MAX_STC',105);
define('MAX_FUN',110);
define('MAX_EXP',121);
define('MAX_STR',0);
define('MAX_NUM',0);
define('MAX_COM',0);
function jassc($conveyjt=''){
$linejt=array();
$separator=chr(13).chr(10);
$sourcejs=array(
//1.Kinds of variable(darkorange)
'boolean ',
'real ',
'integer ',
'string ',
'handle ',
'code ',
'nothing ',
'event ',
'player ',
'widget ',
'unit ',
'destructable ',
'item ',
'ability ',
'buff ',
'force ',
'group ',
'trigger ',
'triggercondition ',
'triggeraction ',
'timer ',
'location ',
'region ',
'rect ',
'boolexpr ',
'sound ',
'conditionfunc ',
'filterfunc ',
'unitpool ',
'itempool ',
'race ',
'alliancetype ',
'racepreference ',
'gamestate ',
'igamestate ',
'fgamestate ',
'playerstate ',
'playerscore ',
'playergameresult ',
'unitstate ',
'aidifficulty ',
'eventid ',
'gameevent ',
'playerevent ',
'playerunitevent ',
'unitevent ',
'limitop ',
'widgetevent ',
'dialogevent ',
'unittype ',
'gamespeed ',
'gamedifficulty ',
'gametype ',
'mapflag ',
'mapvisibility ',
'mapsetting ',
'mapdensity ',
'mapcontrol ',
'playerslotstate ',
'volumegroup ',
'camerafield ',
'camerasetup ',
'playercolor ',
'placement ',
'startlocprio ',
'raritycontrol ',
'blendmode ',
'texmapflags ',
'effect ',
'effecttype ',
'weathereffect ',
'terraindeformation ',
'fogstate ',
'fogmodifier ',
'dialog ',
'button ',
'quest ',
'questitem ',
'defeatcondition ',
'timerdialog ',
'leaderboard ',
'multiboard ',
'multiboarditem ',
'trackable ',
'gamecache ',
'version ',
'itemtype ',
'texttag ',
//2.Structure(blue)
'globals ',
'endglobals ',
'local ',
'endfunction ',
'function ',
'takes ',
'returns ',
'return ',
'set ',
'call ',
'if ',
'then ',
'elseif ',
'else ',
'endif ',
'loop ',
'exitwhen ',
'endloop ',
//3.Function name(sienna)
'array ',
//later native name
'(',
')',
'[',
']',
//4.Expression(darkgreen)
'+',
'-',
'*',
'/',
'=',
'>',
'<',
'!',
'and ',
'or ',
'not '
//5.String(dimgray)
//later ""
//later string
//6.Number(red)
//later ''
//later number
//later 0x
//7.Comment(seagreen)
//later*/
);
$repjs=array();
$scolorjs=array(
'@do@',
'@bl@',
'@si@',
'@dg@',
'@cl@'
);
$rcolorjs=array(
'<font color="darkorange">',
'<font color="blue">',
'<font color="sienna">',
'<font color="darkgreen">',
'</font>'
);
$returnjt='';
for($i=0;$i<=MAX_KOV;$i++){$repjs[$i]='@do@'.$sourcejs[$i].'@cl@';}
for($i=MAX_KOV+1;$i<=MAX_STC;$i++){$repjs[$i]='@bl@'.$sourcejs[$i].'@cl@';}
for($i=MAX_STC+1;$i<=MAX_FUN;$i++){$repjs[$i]='@si@'.$sourcejs[$i].'@cl@';}
for($i=MAX_FUN+1;$i<=MAX_EXP;$i++){$repjs[$i]='@dg@'.$sourcejs[$i].'@cl@';}
$conveyjt=str_replace(array(chr(9),chr(32)),' ',$conveyjt);
$conveyjt=str_replace($separator,' '.$separator,$conveyjt);
$conveyjt=$conveyjt.' ';
$linejt=explode($separator,$conveyjt);
foreach($linejt as $linec){
$returnjt.=str_replace($sourcejs,$repjs,$linec).'<br>';
}
$returnjt=str_replace($scolorjs,$rcolorjs,$returnjt).'<br>';
if(DEBUG){
echo(count($sourcejs).'<br>');
echo(count($repjs).'<br>');
foreach($repjs as $num=>$repjsstr){
echo($num.':'.$repjsstr.'<br>');
}
foreach($linejt as $linen=>$linestr){
echo($linen.':'.$linestr.'<br>');
}
echo($returnjt);
}
return($returnjt);
}
?>[/php]
经验1000倍、元神500倍(以免后期元神爆负,勤打怪完全足够)、金钱1000倍、爆率500倍
送10W元宝 乾坤袋所有商品均为1白银 元宝足够 无需注册完美世界外挂刷元宝(1元宝=100白银)
乾坤袋售全部时装 最新飞行器 满级魂石 凤凰大力一应具全 出售1星龙珠 无难度合成8星龙珠
风火之旅外挂半成品齐全 练生产技能不再受罪 各生产阶段升级书全卖 不用苦等RP爆发
开放黄昏 城战 开放军团袭击 怪物攻城 结婚20分钟内不能下线 否则自动离婚
副本出11阶以上铸具 成品化后找GM兑换8000声望/5个 也可兑换赤热血江湖外挂1颗/5个
游戏中通过努力可轻松兑换声望 只要真心的玩 不花钱得8军不是空想
上线修真大乘.(请直接去寻梦长老接金甲妖任务 79以前的修真请勿做!)
万流城开放PK,让游戏更有乐趣
副本可飞行,告别找诛仙外挂的烦恼
注:本服着重于长久!稳定!只玩两天或者想找个BT服爽爽的请绕行,家族请免开尊口 一率不赠送装备 人人平等