download this file: func.bbs.php view text/plain: func.bbs.php file encoding: UTF-8 [goback]
<?php
##
## this file name is 'func.bbs.php'
##
## bbs function
##
## [author]
##  - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
##  - 2003.05.09 : add get_search_kwd() function
##  - 2003.04.12 : new build
##
## [references]
##
## [usage]
##
## [example]
##

## get first/last(total) page, and start/end idx for current page
##
## arguments :
##    $rows    integer, total record
##    $page    integer, current page
##    $nums    integer, article number per one page
##
## return :
##    $array['first']    boolean, first page, 1 or 0
##    $array['last']    integer, last page, or total page
##    $array['start']    integer, start idx for current page
##    $array['end']    integer, end idx for current page
##    $array['cpage']    integer, current page
##    $array['anum']    integer, article number for current page
##
function get_page_info($rows$page=1$nums=15)
{
  if(
$page 1$page 1;
  if(
$nums 1$nums 15;

  
$last ceil($rows/$nums); // total page
  
$anum $rows $nums*($page-1); // article number for current page

  ## get start/end idx for current page
  ##
  
if($last// $rows > 0
  
{
    
$first 1;
    
$start $nums*($page-1); // start idx for current page
    
if($last $page$end $start $nums 1;
    else 
$end $rows 1// is last page
  
} else
  {
    
$first $page $end 0;
    
$start 1;
  }

  return array(
'first'=>$first,'last'=>$last,'start'=>$start,
    
'end'=>$end,'cpage'=>$page,'anum'=>$anum);
}

## get page link block
##
## reference : jcafe
##
## arguments :
##    $page        integer, current page
##    $total_page    integer, total page(total_rows/number_per_page)
##    $tolink        string, to basic link
##    $pblock        integer, page per block
##
function get_page_block($page$total_page$tolink$pblock=5)
{
  if(
$pblock 1$pblock 5;

  if(
$total_page$first 1;
  else 
$first 0// force to, patch 2002.12.15

  ## get total/current/start/end block
  ##
  
$total_block ceil($total_page/$pblock);
  
$block ceil($page/$pblock); // current block
  
$start = ($block-1)*$pblock// start page for current block

  
if($total_block $block$end $block*$pblock;
  else 
$end $total_page// end page for current block

  ## go to first page
  ##
  
$link "<A HREF='$tolink$first'>&laquo;</A>\n";

  
## go to prev block
  ##
  
if($block 1$link .= "<A HREF='$tolink$start'>[Prev${pblock}]</A>\n";

  
## group pages of current block
  ##
  
if($total_block// do not set $page
  
{
    for(
$p=$start+1$p<=$end$p++)
    {
        if(
$p == $page$link .= "$page\n";
        else
        {
            
//if($p > $page) $np = 'Next';
            //else $np = 'Prev';
            
$link .= "<A HREF='$tolink$p'>[$p]</A>\n";
        }
    }
  }

  
## go to next block
  ##
  
if($block $total_block)
  {
    
$npage $end 1;
    
$link .= "<A HREF='$tolink$npage'>[Next$pblock]</A>\n";
  }

  
## go to last page
  ##
  
$link .= "<A HREF='$tolink$total_page'>&raquo;</A>\n";

  return 
$link;
}

function 
get_search_kwd($kwd)
{
  if(
$kwd trim($kwd))
  {
    
$kwd urldecode($kwd); // included quoted string
    
$kwd preg_replace('/[\[\]\|]+/','',$kwd); // search string patch
    
$strip stripslashes($kwd);

    
$search['form'] = htmlspecialchars($strip); // for <FORM> tag
    
$search['url'] = $search['uri'] = $search['link'] = urlencode($strip); // for GET link url
    
$search['kwd'] = $search['sql'] = $kwd// for general parsing, form sql search
  
}

  return 
$search;
}

require_once 
'_lib/func.html.php';

?>