帮我翻译一个PHP方法
//分页
function multi($num, $perpage, $curpage, $mpurl) {
global $_SCONFIG = array();
$page = 5;
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&' : '?';
$realpages = 1;
if($num > $perpage) {
$offset = 2;
$realpages = @ceil($num / $perpage);
$pages = $_SCONFIG['maxpage'] && $_SCONFIG['maxpage'] < $realpages ? $_SCONFIG['maxpage'] : $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 = ($curpage - $offset > 1 && $pages > $page ? '<a href="'.$mpurl.'page=1" class="first">1 ...</a>' : '').
($curpage > 1 ? '<a href="'.$mpurl.'page='.($curpage - 1).'" class="prev">‹‹</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>'.$i.'</strong>' :
'<a href="'.$mpurl.'page='.$i.'">'.$i.'</a>';
}
$multipage .= ($curpage < $pages ? '<a href="'.$mpurl.'page='.($curpage + 1).'" class="next">››</a>' : '').
(0 && $to < $pages ? '<a href="'.$mpurl.'page='.$pages.'" class="last">... '.$realpages.'</a>' : '');
$multipage = $multipage ? '<div class="pages">'.'<em> '.$num.' </em>'.$multipage.'</div>' : '';
}
$maxpage = $realpages;
return $multipage;
}
因为看起来和你的代码差不多。
request是一个页面全局变量来的。
--->
<cfset pages = bitand(request.SCONFIG["maxpage"], iif(request.SCONFIG["maxpage"] lt realpages, de("#request.SCONFIG["maxpage"]#"), de("realpages")))>
<!--- Initial the local variables --->
<cfset var from = 0>
<cfset var to = 0>
<cfif page gt pages>
<cfset from = 1>
<cfset to = pages>
<cfelse>
<cfset from = curpage - offset>
<cfset to = from + page - 1>
<cfif from lt 1>
<cfset to = curpage + 1 - from>
<cfset from = 1>
<cfif (to - from) lt page>
<cfset to = page>
</cfif>
<cfelseif to gt pages>
<cfset from = pages - page + 1>
<cfset to = pages>
</cfif>
</cfif>
<!---
没有写复合的语句,拆开来写。毕竟是翻译,不知道理解是否对。
--->
<cfif (curpage - offset) gt 1 and pages gt page>
<cfset multipage = "<a href=""#mpurl#page=1"" class=""first"">1 ...</a>">
</cfif>
<cfif curpage gt 1>
<cfset multipage = multipage & "<a href=""#mpurl#page=#curpage-1#"" class=""prev"">‹‹</a>">
</cfif>
<cfset var l_key =0>
<cfloop from="#from#" to="#to#" index="l_key">
<cfif l_key eq curpage>
<cfset multipage = multipage & "<strong>#l_key#</strong>">
<cfelse>
<cfset multipage = multipage & "<a href=""#mpurl#page=#l_key#"">#l_key#</a>">
</cfif>
</cfloop>
<cfif curpage lt pages>
<cfset multipage = multipage & "<a href=""#mpurl#page=#curpage+1#"" class=""next"">››</a>">
</cfif>
<cfif bitand(0,(to lt pages))>
<cfset multipage = multipage & "<a href=""#mpurl#page=#pages#"" class=""last"">... #realpages#</a>">
</cfif>
<cfif trim(multipage) neq "">
<cfset multipage = "<div class=""pages""><em> #num# </em>#multipage#</div>">
</cfif>
</cfif>
<cfset maxpage = realpages>
<cfreturn multipage>
</cffunction>