package.xml100666 0 0 63015 11173437505 6262 Pager pear.php.net Data paging class It takes an array of data as input and pages it according to various parameters. It also builds links within a specified range, and allows complete customization of the output (it even works with front controllers and mod_rewrite). Two operating modes available: "Jumping" and "Sliding" window style. Lorenzo Alberton quipo l.alberton@quipo.it yes Richard Heyes richard richard@phpguru.org no 2009-04-21 2.4.8 2.4.8 stable stable BSD - request #15949: add autoSubmit option to getPerPageSelectBox() [Matt Rosenquist] - fix potential issues with encoding in getPerPageSelectBox() and getPageSelectBox() 4.0.0 1.4.0b1 2.4.8 2.4.8 stable stable 2009-04-21 BSD - request #15949: add autoSubmit option to getPerPageSelectBox() [Matt Rosenquist] - fix potential issues with encoding in getPerPageSelectBox() and getPageSelectBox() 2.4.7 2.4.7 stable stable 2008-08-11 BSD - fixed bug #13604: WARNINGS with PHP 5.3-dev [thanks to Chris Troup] - request #13567: support for regexp in 'excludeVars' [thanks to Stefano Coletta] - fixed bug #13913 empty prev/next image shown when only one page exists [cweiske] - fixed bug #13881: fix for relative links (introduced in v.2.4.5) may cause some issues with absolute links 2.4.6 2.4.6 stable stable 2008-03-28 BSD - fixed bug #13316: NOTICE in getLinks() in Jumping mode - fixed bug #13342: getLinks() returns wrong result with multi-byte arrays - fixed bug #13469: getPerPageSelectBox() can produce invalid xhtml with no data - fixed bug #13472: PHP 6 Removes get_magic_quotes_gpc() - fixed bug #13506: POST method deletes querystring - request #13509: added 'prevImgEmpty' and 'nextImgEmpty' options to show a disabled prev/next page link when you are on the last/first page (cweiske) 2.4.5 2.4.5 stable stable 2008-02-23 BSD - request #10869: added two reverse drivers in the /examples/ dir - fixed a few PHP5 Strict Standards warnings (bug #12257 and #12934) - Coding Standards fixes in the phpdoc blocks - added 'PAGER_' prefix to internal constant names - fixed bug #12267: correct detection of HTTPS on IIS (thanks to Carsten Wiedmann) - fixed bug #12306: allow relative links - fixed bug #12531: removed <u> tag from curPageSpan[Pre|Post] default options in Pager_Sliding to make links HTML 4.01 strict - request #12267: added $pager->linkTagsRaw array (same as $pager->linkTags but as array) to play nice with HTML_Page2 (patch by Carsten Wiedmann) - fixed bug #12796: curPageLinkClassName overrides curPageSpanPre and curPageSpanPost - request #12797: added '%d' as a placeholder to altPage (by default, page number is appended) - fixed bug #12837: if $_SESSION['setPerPage'] is set, Pager always uses it 2.4.4 2.4.4 stable stable 2007-07-29 BSD - handle UNION queries in the Wrapper (bug #9601) - getPerPagerSelectBox() with $showAllData = true and $start > $totalItems was returning an empty select menu (bug #9946) - added 'onclick' option (request #11241) - fixed bug #11697: Pager_Jumping::build() lose first and last page string concatenation 2.4.3 2.4.3 stable stable 2006-12-03 BSD - fixed issue with SSL (bug #7936) - items set in 'excludeVars' array were removed from the URL even if they were also set in the 'extraVars' array (bug #8969) - added new option 'checkMaxLimit' to getPerPageSelectBox(): if true, Pager checks if $end is bigger than $totalItems, and doesn't show the extra select options - moved Pager.php to the pear root and added a wrapper in the old location to adhere to PEAR policies (bug #2169) - switched to package.xml v2 2.4.2 2.4.2 stable stable 2006-06-07 BSD - fix double escaping of arg_separator when php.ini's arg_separator.output = "&amp;" 2.4.1 2.4.1 stable stable 2006-05-06 BSD - more flexible implementation of the factory pattern allowing people to use custom renderer classes that are not part of the Pager package (thanks to Martin Jansen) 2.4.0 2.4.0 stable stable 2006-04-23 BSD - added host to CURRENT_PATHNAME constant - added accesskey option (if true, accesskey attributes are added to the links) - fixed multibyte string issues with httpMethod==POST (bug #6812) - return empty array instead of FALSE in getPageData() on bad pageID (request #6986) - added Pager_HtmlWidgets class containing the methods getPerPageSelectBox() (moved from Pager_Common) and getPageSelectBox() (new, request #6998). The class is lazy-loaded when calling one of the two above methods from Pager. - Improved rewriteCountQuery() function in the Pager Wrapper. - added getOption($name) and getOptions() methods (request #7413) - changed _setOptions() [private] to setOptions() [public] - added build() to refresh the links and the paged data after a new call to setOptions() - added 'attributes' option to set extra attributes for the <a> tag (request #7452) 2.3.6 2.3.6 stable stable 2006-02-03 BSD - fixed bug #6680: error with fileName parameter having an extra "%" character 2.3.5 2.3.5 stable stable 2006-01-20 BSD - remove flicker (caused by href="#") during POST requests (request #6005) - added "formID" option to reuse an existing form in POST requests (thanks to Marc Veldman) - fixed bug #6529: problem with fields with quotes during POST requests 2.3.4 2.3.4 stable stable 2005-09-28 BSD - changed license to BSD - fixed bug #4897 (multibyte chars not handled correctly) 2.3.3 2.3.3 stable stable 2005-07-04 PHP - improved Pager_Wrapper and added tests - urlencoded square brackets (bug #4337) NB: We recommend that users of Pager < 2.3.0 immediately upgrade the package, otherwise they might be susceptible to XSS attacks 2.3.2 2.3.2 stable stable 2005-06-03 PHP - autodetect HTTP method used, when not specified, instead of forcing "GET" (bug #4277) - added "altFirst" and "altLast" options to set the "title" attribute of the first and last page links 2.3.1 2.3.1 stable stable 2005-05-02 PHP - fixed various issues with __http_build_query() and escaped entities - if the value of "arg_separator.output" in php.ini is "&amp;", don't encode it again - tweaked Pager_Wrapper query rewriting function, now it is fully case insensitive 2.3.0 2.3.0 stable stable 2005-04-22 PHP - tweaked Pager_Wrapper query rewriting function 2.3.0RC2 2.3.0RC2 beta beta 2005-04-06 PHP - fixed possible querystring duplication with front controllers 2.3.0RC1 2.3.0RC1 beta beta 2005-04-01 PHP - internal refactoring: added POST support: set the preferred http method ('GET' or 'POST') with the 'httpMethod' option. - used $_GET instead of reparsing the querystring [thanks to Nikolas 'Atrus' Coukouma] (fixed bugs #3450, #3878 and #3451) - added 'importQuery' boolean option to ignore the url vars entirely (bug #3449) - added 'excludeVars' array option to selectively exclude some url vars (bug #2461) - countless code optimizations - added many new test cases to the testsuite 2.2.7 2.2.7 stable stable 2005-03-18 PHP - added Pager_Wrapper_Eclipse() function in the /examples/Pager_Wrapper example (thanks to Matte Edens) - added support for statements with subqueries in the Pager Wrappers (thanks to Tobias Kuckuck) - fixed bug #3451 (arrays in extraVars not handled correctly) 2.2.6 2.2.6 stable stable 2005-02-04 PHP - better 'currentPage' option support (thanks to Andrew Nagy) - fixed typo (thanks to Massimiliano Arione) 2.2.5 2.2.5 stable stable 2005-01-17 PHP - allowed use of a javascript function in the fileName [bugs #2555 and #2754] - added Pager_Wrapper_DBDO() function in the /examples/Pager_Wrapper example (thanks to garak AT studenti DOT it) - replaced urlencode() with htmlentities() because it was too aggressive [bugs #2908, #3043 and #3212] - added 'currentPage' option (patch by Kendrick Vargas) 2.2.4 2.2.4 stable stable 2004-11-20 PHP - fixed "Notice: Undefined property: _totalPages" [bug #2714] - enforce errors (which weren't displayed at all) - fixed Pager_Wrapper (examples dir) with GROUP BY queries - changed $_GET to $_REQUEST. POST values should be valid too, now. - Pager can be used on a DirectoryIndex script, now (patch by ieure) [bug #2617] 2.2.3 2.2.3 stable stable 2004-08-17 PHP - just the last one of a set of array values given as GET parameters (i.e. site.php?foo[]=1&foo[]=2&foo[]=3) was carried on (bug #1904). - make 4th parameter of getPerPageSelectBox() an array, and add an "attribute" parameter to allow extra attributes for the select tag. - added an example to show how this class can be used with big database resultsets efficiently. - prevent XSS attacks (bug #2131), thanks to sou_sk at nifty dot com 2.2.2 2.2.2 stable stable 2004-05-18 PHP - set correct selected value for getPerPageSelectBox even when "useSession" option is false (bug #1263). - added two parameters to getPerPageSelectBox(): * $showAllData (if true, an <option> to show all the data is displayed in the generated <select>); * $optionText (text to show in each <option>; use '%d' where you want to see the number of pages selected) - added showAllText option for alternate text in the $showAllData <option> (the default is the number of total items). - fixed getPageData() when $pageID is specified (bug #1377) (thanks to Ian Eure) - added tests for getPageData() - avoid duplicate vars in querystring when using 'extraVars' option (bug #1383) (thanks to pauluz at gazeta dot pl) 2.2.1 2.2.1 stable stable 2004-04-15 PHP - PHP5 compatibility (fixed bug #812) - Forced ucfirst() on filename too 2.2.0 2.2.0 stable stable 2004-01-23 PHP - Fixed handling of errors raised in common base class - Added an 'extraVars' option to add vars to the querystring - Added <link> tags building (patch by Joerg Bruckmann) - Fixed Bug #589 (common.php raise a notice if the querystring has no '=' character) - Use '&amp;' instead of '&' in urls for better XHTML conformance 2.1.0 2.1.0 stable stable 2003-12-22 PHP - Added getPageRangeByPageId() - Fix getOffsetByPageId() in Pager_Jumping when totalItems == 0. - Fix getOffsetByPageId() in Pager_Sliding for BC with Pager 1.x and Pager_Jumping. N.B.: its previous (not-indended) behaviour is now provided by the new getPageRangeByPageId() method. - Fix isFirstPage() when totalItems == 0 - Added test suite. 2.0 2.0 stable stable 2003-09-10 PHP - New major version. - Pager and Pager_Sliding are now merged in the same package. Every option available in Pager_Sliding is now also available in Pager. The API is the same as the old one, BC is kept 100%. - Switch between "Jumping" and "Sliding" window mode just setting an option. - Improved error handling. 1.0.8 1.0.8 stable stable 2003-09-10 PHP - Minor patch for script_name vs php_self (not included in v.1.0.7) - Prevent URL modification 1.0.7 1.0.7 stable stable 2002-12-01 PHP Minor patch for script_name vs php_self 1.0.6 1.0.6 stable stable 2002-09-08 PHP Updated to no longer require an array of data. Now can be used with just a number of items. Thanks to Christian Dickmann for the patch. 1.0.5 1.0.5 stable stable 2002-07-27 PHP Changed getCurrentPage() to getCurrentPageID() and added getNextPageID() and getPreviousPageID() 1.0.4 1.0.4 stable stable 2002-06-29 PHP Changed getCurrentPage() to getCurrentPageID() and added getNextPageID() and getPreviousPageID() 1.0.3 1.0.3 stable stable 2002-05-31 PHP Couple of minor bugs 1.0.2 1.0.2 stable stable 2002-05-31 PHP Applied patch from Christian Dickmann adding getCurrentPage(), numItems() and optional CSS class for links. 1.0.1 1.0.1 stable stable 2002-05-27 PHP o No longer barfs with no querystring o Now works with associative data array 1.0 1.0 stable stable 2002-02-09 PHP This is the initial release of the Pager package. Pager-2.4.8/examples/example.php100666 0 0 3600 11173437505 11606 $myData, 'perPage' => 10, 'delta' => 8, // for 'Jumping'-style a lower number is better 'append' => true, //'separator' => ' | ', 'clearIfVoid' => false, 'urlVar' => 'entrant', 'useSessions' => true, 'closeSession' => true, //'mode' => 'Sliding', //try switching modes 'mode' => 'Jumping', ); $pager = & Pager::factory($params); $page_data = $pager->getPageData(); $links = $pager->getLinks(); $selectBox = $pager->getPerPageSelectBox(); ?> new PEAR::Pager example

Results from methods:

getCurrentPageID()...: getCurrentPageID()); ?>
getNextPageID()......: getNextPageID()); ?>
getPreviousPageID()..: getPreviousPageID()); ?>
numItems()...........: numItems()); ?>
numPages()...........: numPages()); ?>
isFirstPage()........: isFirstPage()); ?>
isLastPage().........: isLastPage()); ?>
isLastPageComplete().: isLastPageComplete()); ?>
$pager->range........: range); ?>

Select how many items per page should be shown:
 

Pager-2.4.8/examples/Pager_Wrapper.php100666 0 0 26433 11173437505 12742 'Sliding', // 'delta' => 2, // 'perPage' => 15, // ); // $paged_data = Pager_Wrapper_MDB2($db, $query, $pagerOptions); // //$paged_data['data']; //paged data // //$paged_data['links']; //xhtml links for page navigation // //$paged_data['page_numbers']; //array('current', 'total'); // /** * Helper method - Rewrite the query into a "SELECT COUNT(*)" query. * @param string $sql query * @return string rewritten query OR false if the query can't be rewritten * @access private */ function rewriteCountQuery($sql) { if (preg_match('/^\s*SELECT\s+\bDISTINCT\b/is', $sql) || preg_match('/\s+GROUP\s+BY\s+/is', $sql) || preg_match('/\s+UNION\s+/is', $sql)) { return false; } $open_parenthesis = '(?:\()'; $close_parenthesis = '(?:\))'; $subquery_in_select = $open_parenthesis.'.*\bFROM\b.*'.$close_parenthesis; $pattern = '/(?:.*'.$subquery_in_select.'.*)\bFROM\b\s+/Uims'; if (preg_match($pattern, $sql)) { return false; } $subquery_with_limit_order = $open_parenthesis.'.*\b(LIMIT|ORDER)\b.*'.$close_parenthesis; $pattern = '/.*\bFROM\b.*(?:.*'.$subquery_with_limit_order.'.*).*/Uims'; if (preg_match($pattern, $sql)) { return false; } $queryCount = preg_replace('/(?:.*)\bFROM\b\s+/Uims', 'SELECT COUNT(*) FROM ', $sql, 1); list($queryCount, ) = preg_split('/\s+ORDER\s+BY\s+/is', $queryCount); list($queryCount, ) = preg_split('/\bLIMIT\b/is', $queryCount); return trim($queryCount); } /** * @param object PEAR::DB instance * @param string db query * @param array PEAR::Pager options * @param boolean Disable pagination (get all results) * @param integer fetch mode constant * @param mixed parameters for query placeholders * If you use placeholders for table names or column names, please * count the # of items returned by the query and pass it as an option: * $pager_options['totalItems'] = count_records('some query'); * @return array with links and paged data */ function Pager_Wrapper_DB(&$db, $query, $pager_options = array(), $disabled = false, $fetchMode = DB_FETCHMODE_ASSOC, $dbparams = null) { if (!array_key_exists('totalItems', $pager_options)) { // be smart and try to guess the total number of records if ($countQuery = rewriteCountQuery($query)) { $totalItems = $db->getOne($countQuery, $dbparams); if (PEAR::isError($totalItems)) { return $totalItems; } } else { $res =& $db->query($query, $dbparams); if (PEAR::isError($res)) { return $res; } $totalItems = (int)$res->numRows(); $res->free(); } $pager_options['totalItems'] = $totalItems; } require_once 'Pager/Pager.php'; $pager = Pager::factory($pager_options); $page = array(); $page['totalItems'] = $pager_options['totalItems']; $page['links'] = $pager->links; $page['page_numbers'] = array( 'current' => $pager->getCurrentPageID(), 'total' => $pager->numPages() ); list($page['from'], $page['to']) = $pager->getOffsetByPageId(); $res = ($disabled) ? $db->limitQuery($query, 0, $totalItems, $dbparams) : $db->limitQuery($query, $page['from']-1, $pager_options['perPage'], $dbparams); if (PEAR::isError($res)) { return $res; } $page['data'] = array(); while ($res->fetchInto($row, $fetchMode)) { $page['data'][] = $row; } if ($disabled) { $page['links'] = ''; $page['page_numbers'] = array( 'current' => 1, 'total' => 1 ); } return $page; } /** * @param object PEAR::MDB instance * @param string db query * @param array PEAR::Pager options * @param boolean Disable pagination (get all results) * @param integer fetch mode constant * @return array with links and paged data */ function Pager_Wrapper_MDB(&$db, $query, $pager_options = array(), $disabled = false, $fetchMode = MDB_FETCHMODE_ASSOC) { if (!array_key_exists('totalItems', $pager_options)) { //be smart and try to guess the total number of records if ($countQuery = rewriteCountQuery($query)) { $totalItems = $db->queryOne($countQuery); if (PEAR::isError($totalItems)) { return $totalItems; } } else { $res = $db->query($query); if (PEAR::isError($res)) { return $res; } $totalItems = (int)$db->numRows($res); $db->freeResult($res); } $pager_options['totalItems'] = $totalItems; } require_once 'Pager/Pager.php'; $pager = Pager::factory($pager_options); $page = array(); $page['totalItems'] = $pager_options['totalItems']; $page['links'] = $pager->links; $page['page_numbers'] = array( 'current' => $pager->getCurrentPageID(), 'total' => $pager->numPages() ); list($page['from'], $page['to']) = $pager->getOffsetByPageId(); $res = ($disabled) ? $db->limitQuery($query, null, 0, $totalItems) : $db->limitQuery($query, null, $page['from']-1, $pager_options['perPage']); if (PEAR::isError($res)) { return $res; } $page['data'] = array(); while ($row = $db->fetchInto($res, $fetchMode)) { $page['data'][] = $row; } if ($disabled) { $page['links'] = ''; $page['page_numbers'] = array( 'current' => 1, 'total' => 1 ); } return $page; } /** * @param object PEAR::MDB2 instance * @param string db query * @param array PEAR::Pager options * @param boolean Disable pagination (get all results) * @param integer fetch mode constant * @return array with links and paged data */ function Pager_Wrapper_MDB2(&$db, $query, $pager_options = array(), $disabled = false, $fetchMode = MDB2_FETCHMODE_ASSOC) { if (!array_key_exists('totalItems', $pager_options)) { //be smart and try to guess the total number of records if ($countQuery = rewriteCountQuery($query)) { $totalItems = $db->queryOne($countQuery); if (PEAR::isError($totalItems)) { return $totalItems; } } else { //GROUP BY => fetch the whole resultset and count the rows returned $res =& $db->queryCol($query); if (PEAR::isError($res)) { return $res; } $totalItems = count($res); } $pager_options['totalItems'] = $totalItems; } require_once 'Pager/Pager.php'; $pager = Pager::factory($pager_options); $page = array(); $page['links'] = $pager->links; $page['totalItems'] = $pager_options['totalItems']; $page['page_numbers'] = array( 'current' => $pager->getCurrentPageID(), 'total' => $pager->numPages() ); list($page['from'], $page['to']) = $pager->getOffsetByPageId(); $page['limit'] = $page['to'] - $page['from'] +1; if (!$disabled) { $db->setLimit($pager_options['perPage'], $page['from']-1); } $page['data'] = $db->queryAll($query, null, $fetchMode); if (PEAR::isError($page['data'])) { return $page['data']; } if ($disabled) { $page['links'] = ''; $page['page_numbers'] = array( 'current' => 1, 'total' => 1 ); } return $page; } /** * @param object PEAR::DataObject instance * @param array PEAR::Pager options * @param boolean Disable pagination (get all results) * @return array with links and paged data * @author Massimiliano Arione */ function Pager_Wrapper_DBDO(&$db, $pager_options = array(), $disabled = false) { if (!array_key_exists('totalItems', $pager_options)) { $totalItems = $db->count(); $pager_options['totalItems'] = $totalItems; } require_once 'Pager/Pager.php'; $pager = Pager::factory($pager_options); $page = array(); $page['links'] = $pager->links; $page['totalItems'] = $pager_options['totalItems']; $page['page_numbers'] = array( 'current' => $pager->getCurrentPageID(), 'total' => $pager->numPages() ); list($page['from'], $page['to']) = $pager->getOffsetByPageId(); $page['limit'] = $page['to'] - $page['from'] + 1; if (!$disabled) { $db->limit($page['from'] - 1, $pager_options['perPage']); } $db->find(); while ($db->fetch()) { $db->getLinks(); $page['data'][] = $db->toArray('%s', true); } return $page; } /** * @param object PHP Eclipse instance * @param string db query * @param array PEAR::Pager options * @param boolean Disable pagination (get all results) * @return array with links and paged data * @author Matte Edens * @see http://sourceforge.net/projects/eclipselib/ */ function Pager_Wrapper_Eclipse(&$db, $query, $pager_options = array(), $disabled = false) { if (!$disabled) { require_once(ECLIPSE_ROOT . 'PagedQuery.php'); $query =& new PagedQuery($db->query($query), $pager_options['perPage']); $totalrows = $query->getRowCount(); $numpages = $query->getPageCount(); $whichpage = isset($_GET[$pager_options['urlVar']]) ? (int)$_GET[$pager_options['urlVar']] - 1 : 0; if ($whichpage >= $numpages) { $whichpage = $numpages - 1; } $result = $query->getPage($whichpage); } else { $result = $db->query($query); $totalrows = $result->getRowCount(); $numpages = 1; } if (!$result->isSuccess()) { return PEAR::raiseError($result->getErrorMessage()); } if (!array_key_exists('totalItems', $pager_options)) { $pager_options['totalItems'] = $totalrows; } $page = array(); require_once(ECLIPSE_ROOT . 'QueryIterator.php'); for ($it =& new QueryIterator($result); $it->isValid(); $it->next()) { $page['data'][] =& $it->getCurrent(); } require_once 'Pager/Pager.php'; $pager = Pager::factory($pager_options); $page['links'] = $pager->links; $page['totalItems'] = $pager_options['totalItems']; $page['page_numbers'] = array( 'current' => $pager->getCurrentPageID(), 'total' => $numpages ); $page['perPageSelectBox'] = $pager->getperpageselectbox(); list($page['from'], $page['to']) = $pager->getOffsetByPageId(); $page['limit'] = $page['to'] - $page['from'] +1; if ($disabled) { $page['links'] = ''; $page['page_numbers'] = array( 'current' => 1, 'total' => 1 ); } return $page; } ?>Pager-2.4.8/tests/all_tests.php100666 0 0 1203 11173437505 11466 GroupTest('All PEAR::Pager Tests'); $this->AddTestCase(new PagerTests()); $this->AddTestCase(new PagerJumpingTests()); $this->AddTestCase(new PagerSlidingTests()); } } $test = new AllTests(); $test->run(new HtmlReporter()); ?>Pager-2.4.8/tests/multibyte_post.php100666 0 0 2543 11173437505 12567 '测试', 'encoded2' => '안녕', ); $test_strings_plain = array( 'plain1' => '안녕', 'plain2' => '더보기', // 'plain3' => '이젠 전화도 //로 걸면 무료', ); $params = array( 'itemData' => $myData, 'perPage' => 10, 'delta' => 2, 'append' => true, 'clearIfVoid' => false, 'extraVars' => array_merge($test_strings_plain, $test_strings_encoded), 'httpMethod' => 'POST', 'path' => 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')), 'fileName' => basename(__FILE__), ); //var_dump($params['fileName']);exit; $pager = & Pager::factory($params); $page_data = $pager->getPageData(); ?> Pager Test: page <?php echo $pager->getCurrentPageID(); ?> links; ?>
Pager-2.4.8/tests/pager_include.php100666 0 0 150 11173437505 12255 Pager-2.4.8/tests/pager_jumping_noData_test.php100666 0 0 2062 11173437505 14654 UnitTestCase($name); } function setUp() { $options = array( 'totalItems' => 0, 'perPage' => 2, 'mode' => 'Jumping', ); $this->pager = Pager::factory($options); } function tearDown() { unset($this->pager); } function testOffsetByPageId() { $this->assertEqual(array(1, 0), $this->pager->getOffsetByPageId()); } function testPageIdByOffset() { $this->assertEqual(false, $this->pager->getPageIdByOffset(0)); } function testPageIdByOffset2() { $this->assertEqual(1, $this->pager->getPageIdByOffset(1)); } function testPageIdByOffset3() { $this->assertEqual(1, $this->pager->getPageIdByOffset(2)); } } ?>Pager-2.4.8/tests/pager_jumping_test.php100666 0 0 6317 11173437505 13375 UnitTestCase($name); } function setUp() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 'perPage' => 5, 'mode' => 'Jumping', 'delta' => 2 ); $this->pager = Pager::factory($options); } function tearDown() { unset($this->pager); } function testPageIdByOffset1() { $this->assertEqual(1, $this->pager->getPageIdByOffset(1)); } function testPageIdByOffset5() { $this->assertEqual(1, $this->pager->getPageIdByOffset(5)); } function testPageIdByOffset6() { $this->assertEqual(2, $this->pager->getPageIdByOffset(6)); } function testPageRangeByPageId1() { $this->assertEqual(array(1, 2), $this->pager->getPageRangeByPageId(1)); } function testPageRangeByPageId2() { $this->assertEqual(array(1, 2), $this->pager->getPageRangeByPageId(2)); } function testPageRangeByPageId3() { $this->assertEqual(array(3, 3), $this->pager->getPageRangeByPageId(3)); } function testPageRangeByPageId_outOfRange() { $this->assertEqual(array(0, 0), $this->pager->getPageRangeByPageId(20)); } function testGetPageData() { $this->assertEqual(array(0=>1, 1=>2, 2=>3, 3=>4, 4=>5), $this->pager->getPageData()); } function testGetPageData2() { $this->assertEqual(array(5=>6, 6=>7, 7=>8, 8=>9, 9=>10), $this->pager->getPageData(2)); } function testGetPageData_OutOfRange() { $this->assertEqual(false, $this->pager->getPageData(4)); } /** * Returns offsets for given pageID. Eg, if you pass pageID=5 and your * delta is 2, it will return 3 and 7. A pageID of 6 would give you 4 and 8 * If the method is called without parameter, pageID is set to currentPage#. * * Given a PageId, it returns the limits of the range of pages displayed. * While getOffsetByPageId() returns the offset of the data within the current * page, this method returns the offsets of the page numbers interval. * E.g., if you have perPage=10 and pageId=3, it will return you 1 and 10. * PageID of 8 would give you 1 and 10 as well, because 1 <= 8 <= 10. * PageID of 11 would give you 11 and 20. * * @param pageID PageID to get offsets for * @return array First and last offsets * @access public */ /** * Given a PageId, it returns the limits of the range of pages displayed. * While getOffsetByPageId() returns the offset of the data within the * current page, this method returns the offsets of the page numbers interval. * E.g., if you have perPage=10 and pageId=3, it will return you 1 and 10. * PageID of 8 would give you 1 and 10 as well, because 1 <= 8 <= 10. * PageID of 11 would give you 11 and 20. * * @param pageID PageID to get offsets for * @return array First and last offsets * @access public */ } ?>Pager-2.4.8/tests/pager_jumping_tests.php100666 0 0 1052 11173437505 13547 GroupTest('Pager_Jumping Tests'); $this->addTestFile('pager_jumping_test.php'); $this->addTestFile('pager_jumping_noData_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = new PagerTests(); $test->run(new HtmlReporter()); } ?>Pager-2.4.8/tests/pager_noData_test.php100666 0 0 2615 11173437505 13127 UnitTestCase($name); } function setUp() { $options = array( 'totalItems' => 0, 'perPage' => 5, 'mode' => 'Sliding', ); $this->pager = Pager::factory($options); } function tearDown() { unset($this->pager); } function testCurrentPageID () { $this->assertEqual(0, $this->pager->getCurrentPageID()); } function testNextPageID () { $this->assertEqual(false, $this->pager->getNextPageID()); } function testPrevPageID () { $this->assertEqual(false, $this->pager->getPreviousPageID()); } function testNumItems () { $this->assertEqual(0, $this->pager->numItems()); } function testNumPages () { $this->assertEqual(0, $this->pager->numPages()); } function testFirstPage () { $this->assertEqual(true, $this->pager->isFirstPage()); } function testLastPage () { $this->assertEqual(true, $this->pager->isLastPage()); } function testLastPageComplete () { $this->assertEqual(true, $this->pager->isLastPageComplete()); } } ?>Pager-2.4.8/tests/pager_post_test.php100666 0 0 4312 11173437505 12702 WebTestCase($name); } function setUp() { $this->options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 1, 'clearIfVoid' => false, 'httpMethod' => 'POST', ); //$this->pager = Pager::factory($this->options); $this->baseurl = 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); } function tearDown() { unset($this->pager); } function testMultibyteEncoded() { $test_strings_encoded = array( 'encoded1' => '测试', 'encoded2' => '안녕', ); $loaded = $this->get($this->baseurl.'/multibyte_post.php'); $this->assertTrue($loaded); $this->assertResponse(200); $this->assertTitle('Pager Test: page 1'); $this->assertNoLink('1'); $this->assertLink('2'); $this->assertLink('Next >>'); //$this->showSource(); foreach ($test_strings_encoded as $name => $value) { $this->assertWantedPattern('/'.$name.'.*'.preg_quote(str_replace('&', '&', $value)).'/Uims'); } } function testMultibytePlain() { $test_strings_plain = array( 'plain1' => '안녕', 'plain2' => '더보기', // 'plain3' => '이젠 전화도 //로 걸면 무료', ); $loaded = $this->get($this->baseurl.'/multibyte_post.php'); $this->assertTrue($loaded); $this->assertResponse(200); $this->assertTitle('Pager Test: page 1'); $this->assertNoLink('1'); $this->assertLink('2'); $this->assertLink('Next >>'); //$this->showSource(); foreach ($test_strings_plain as $name => $value) { $this->assertWantedPattern('/'.$name.'.*'.preg_quote(urlencode($value)).'/Uims'); } } } ?>Pager-2.4.8/tests/pager_post_tests.php100666 0 0 513 11173437505 13044 addTestFile('pager_post_test.php'); $test->addTestFile('pager_post_test_simple.php'); exit ($test->run(new HTMLReporter()) ? 0 : 1); ?>Pager-2.4.8/tests/pager_post_test_simple.php100666 0 0 2335 11173437505 14256 UnitTestCase($name); } function setUp() { $this->options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 1, 'clearIfVoid' => false, 'httpMethod' => 'POST', ); //$this->pager = Pager::factory($this->options); $this->baseurl = 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); //var_dump($this->baseurl.'/multibyte_post.php'); } function tearDown() { unset($this->pager); } function testGetAndPost() { $this->pager =& Pager::factory($this->options); $this->assertNoPattern('/id=/', $this->pager->links); $_GET['id'] = 123; $this->pager =& Pager::factory($this->options); $this->assertPattern('/id=123/', $this->pager->links); } } ?>Pager-2.4.8/tests/pager_sliding_noData_test.php100666 0 0 1516 11173437505 14637 UnitTestCase($name); } function setUp() { $options = array( 'totalItems' => 0, 'perPage' => 2, 'mode' => 'Sliding', ); $this->pager = Pager::factory($options); } function tearDown() { unset($this->pager); } function testOffsetByPageId() { $this->assertEqual(array(1, 0), $this->pager->getOffsetByPageId()); } function testPageIdByOffset() { $this->assertNull($this->pager->getPageIdByOffset(1)); } } ?>Pager-2.4.8/tests/pager_sliding_notExpanded_test.php100666 0 0 3357 11173437505 15707 UnitTestCase($name); } function setUp() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21), 'perPage' => 2, 'mode' => 'Sliding', 'expanded' => false ); $this->pager = new Pager($options); } function tearDown() { unset($this->pager); } function testPageRangeByPageId1() { $this->assertEqual(array(1, 3), $this->pager->getPageRangeByPageId(1)); } function testPageRangeByPageId2() { $this->assertEqual(array(1, 4), $this->pager->getPageRangeByPageId(2)); } function testPageRangeByPageId3() { $this->assertEqual(array(1, 5), $this->pager->getPageRangeByPageId(3)); } function testPageRangeByPageId4() { $this->assertEqual(array(2, 6), $this->pager->getPageRangeByPageId(4)); } function testPageRangeByPageId9() { $this->assertEqual(array(7, 11), $this->pager->getPageRangeByPageId(9)); } function testPageRangeByPageId10() { $this->assertEqual(array(8, 11), $this->pager->getPageRangeByPageId(10)); } function testPageRangeByPageId11() { $this->assertEqual(array(9, 11), $this->pager->getPageRangeByPageId(11)); } function testPageRangeByPageId_outOfRange() { $this->assertEqual(array(0, 0), $this->pager->getPageRangeByPageId(20)); } } ?>Pager-2.4.8/tests/pager_sliding_test.php100666 0 0 3534 11173437505 13353 UnitTestCase($name); } function setUp() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 'perPage' => 2, 'mode' => 'Sliding', ); $this->pager = Pager::factory($options); } function tearDown() { unset($this->pager); } function testPageRangeByPageId1() { $this->assertEqual(array(1, 5), $this->pager->getPageRangeByPageId(1)); } function testPageRangeByPageId4() { $this->assertEqual(array(2, 6), $this->pager->getPageRangeByPageId(4)); } function testPageRangeByPageId_outOfRange() { $this->assertEqual(array(0, 0), $this->pager->getPageRangeByPageId(20)); } function testPageRangeByPageId2() { $this->assertEqual(array(2, 6), $this->pager->getPageRangeByPageId(4)); } function testGetPageData() { $this->assertEqual(array(0=>1, 1=>2), $this->pager->getPageData()); } function testGetPageData2() { $this->assertEqual(array(2=>3, 3=>4), $this->pager->getPageData(2)); } function testGetPageData_OutOfRange() { $this->assertEqual(false, $this->pager->getPageData(20)); } function testClearIfVoid() { $this->assertTrue(strlen($this->pager->links) > 0); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 'perPage' => 20, 'mode' => 'Sliding', ); $this->pager = Pager::factory($options); $this->assertEqual('', $this->pager->links); } } ?>Pager-2.4.8/tests/pager_sliding_tests.php100666 0 0 1155 11173437505 13533 GroupTest('Pager_Sliding Tests'); $this->addTestFile('pager_sliding_test.php'); $this->addTestFile('pager_sliding_notExpanded_test.php'); $this->addTestFile('pager_sliding_noData_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = new PagerTests(); $test->run(new HtmlReporter()); } ?>Pager-2.4.8/tests/pager_test.php100666 0 0 74253 11173437505 11670 UnitTestCase($name); } function setUp() { $options = array( 'itemData' => range(1, 10), 'perPage' => 5, ); $this->pager = Pager::factory($options); $this->baseurl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); } function tearDown() { unset($this->pager); } function testCurrentPageID() { $this->assertEqual(1, $this->pager->getCurrentPageID()); } function testNextPageID() { $this->assertEqual(2, $this->pager->getNextPageID()); } function testPrevPageID() { $this->assertEqual(false, $this->pager->getPreviousPageID()); } function testNumItems() { $this->assertEqual(10, $this->pager->numItems()); } function testNumPages() { $this->assertEqual(2, $this->pager->numPages()); } function testFirstPage() { $this->assertEqual(true, $this->pager->isFirstPage()); } function testLastPage() { $this->assertEqual(false, $this->pager->isLastPage()); } function testLastPageComplete() { $this->assertEqual(true, $this->pager->isLastPageComplete()); } function testOffsetByPageId() { $this->assertEqual(array(1, 5), $this->pager->getOffsetByPageId(1)); $this->assertEqual(array(6, 10), $this->pager->getOffsetByPageId(2)); } function testOffsetByPageId_outOfRange() { $this->assertEqual(array(0, 0), $this->pager->getOffsetByPageId(20)); } function testGetPageData() { $this->assertEqual(array(0=>1, 1=>2, 2=>3, 3=>4, 4=>5), $this->pager->getPageData()); $this->assertEqual(array(5=>6, 6=>7, 7=>8, 8=>9, 9=>10), $this->pager->getPageData(2)); } function testGetPageData_OutOfRange() { $this->assertEqual(array(), $this->pager->getPageData(3)); } function testSelectBox() { $selectBox = ''; $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5)); } function testSelectBoxWithString() { $selectBox = ''; $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, false, '%d bugs')); } function testSelectBoxWithShowAll() { $selectBox = ''; $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true)); } function testSelectBoxWithShowAllAndText() { $this->pager->_showAllText = 'Show All'; $selectBox = ''; $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(3, 6, 1, true, '%d bugs')); } function testSelectBoxWithShowAllWithExtraAttribs() { $options = array( 'itemData' => range(1, 14), 'perPage' => 5, ); $this->pager = Pager::factory($options); $this->pager->_showAllText = 'Show All'; $selectBox = ''; $params = array( 'optionText' => '%d bugs', 'attributes' => 'onmouseover="doSth"', 'checkMaxLimit' => true, ); $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, true, $params)); } function testSelectBoxWithShowAllAndFewValues() { //test getPerPagerSelectBox() with $showAllData = true and $start > $totalItems $options = array( 'itemData' => range(1, 5), 'perPage' => 5, 'showAllText' => 'Show All', ); $this->pager = Pager::factory($options); $selectBox = ''; $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(25, 30, 1, true, array('checkMaxLimit' => true))); } function testSelectBoxInvalid() { $err = $this->pager->getPerPageSelectBox(5, 15, 5, false, '%s bugs'); $this->assertEqual(ERROR_PAGER_INVALID_PLACEHOLDER, $err->getCode()); } function testSelectBoxEmpty() { $options = array( 'itemData' => array(), 'totalItems' => 0, ); $this->pager = Pager::factory($options); $selectBox = ''; $this->assertEqual($selectBox, $this->pager->getPerPageSelectBox(5, 15, 5, false, array('checkMaxLimit' => true))); } function testAppendInvalid() { $options = array( 'totalItems' => 10, 'append' => false, 'fileName' => 'invalidFileName' ); $err =& Pager::factory($options); //ERROR_PAGER_INVALID_USAGE $this->assertError(); } function testAppendValid() { $options = array( 'totalItems' => 10, 'append' => false, 'fileName' => 'valid_%d_FileName' ); $err =& Pager::factory($options); $this->assertNoErrors(); } function testEscapeEntities() { //encode special chars $options = array( 'extraVars' => array( 'request' => array('aRequest'), 'escape' => 'äö%<>+', ), 'perPage' => 5, ); $this->pager =& Pager::factory($options); //$expected = '?request[]=aRequest&escape=äö%<>+&pageID='; //$this->assertEqual($expected, $this->pager->_getLinksUrl()); $expected = 'request%5B0%5D=aRequest&escape=%E4%F6%25%3C%3E%2B'; if (1 == version_compare(PHP_VERSION, '5.2.99')) { $expected = 'request%5B0%5D=aRequest&escape=%C3%A4%C3%B6%25%3C%3E%2B'; } $rendered = $this->pager->_renderLink('', ''); preg_match('/href="(.*)"/U', $rendered, $matches); $actual = str_replace($_SERVER['PHP_SELF'].'?', '', $matches[1]); $this->assertEqual($expected, $actual); //don't encode slashes $options = array( 'extraVars' => array( 'request' => 'cat/subcat', ), 'perPage' => 5, ); $this->pager =& Pager::factory($options); //$expected = '?request=cat/subcat&pageID='; //$this->assertEqual($expected, $this->pager->_getLinksUrl()); $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); } function testMultibyteStrings() { $options = array( 'extraVars' => array( 'test' => '测试', ), 'perPage' => 5, ); $this->pager =& Pager::factory($options); //$expected = ''; $rendered = $this->pager->_renderLink('', ''); preg_match('/href="(.*)"/U', $rendered, $matches); $actual = str_replace($_SERVER['PHP_SELF'].'?test=', '', $matches[1]); $this->assertEqual(urlencode($options['extraVars']['test']), $actual); } function testMultibyteJapaneseStrings() { $options = array( 'extraVars' => array( 'test' => '漢字', ), 'perPage' => 5, ); $this->pager =& Pager::factory($options); //$expected = ''; $rendered = $this->pager->_renderLink('', ''); preg_match('/href="(.*)"/U', $rendered, $matches); $actual = str_replace($_SERVER['PHP_SELF'].'?test=', '', $matches[1]); $this->assertEqual(urlencode($options['extraVars']['test']), $actual); } function testCurrentPage() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 2, 'currentPage' => 2, ); $this->pager =& Pager::factory($options); $this->assertEqual(3, $this->pager->getNextPageID()); $this->assertEqual(1, $this->pager->getPreviousPageID()); $this->assertEqual(2, $this->pager->_currentPage); } function testArrayExtraVars() { $arr = array( 'apple', 'orange', ); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'extraVars' => array('arr' => $arr, 'no' => 'test'), ); $this->pager =& Pager::factory($options); /* //old $expected = '?arr[0]=apple&arr[1]=orange&pageID='; $this->assertEqual($expected, $this->pager->_getLinksUrl()); */ $expected = $options['extraVars']; $this->assertEqual($expected, $this->pager->_getLinksData()); $separator = ini_get('arg_separator.output'); if ($separator == '&') { $separator = '&'; } $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); } function testExcludeVars() { $_GET['excludeMe'] = 'foo'; $extraVars = array( 'arr' => array( 'apple', 'orange', ), 'no' => 'test', // do not remove this one, because it has been explicitely added ); $excludeVars = array( 'no', // do not remove, @see above 'excludeMe', //remove ); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'extraVars' => $extraVars, 'excludeVars' => $excludeVars, ); $this->pager =& Pager::factory($options); $expected = array( 'arr' => array( 0 => 'apple', 1 => 'orange' ), 'no' => 'test', ); $actual = $this->pager->_getLinksData(); $this->assertEqual($expected, $actual); $separator = ini_get('arg_separator.output'); if ($separator == '&') { $separator = '&'; } $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); unset($_GET['excludeMe']); //cleanup //exclude with regexp $_GET['reMoveAAA'] = 'aaa'; $_GET['RemoveBBB'] = 'bbb'; $_GET['leaveCCC'] = 'ccc'; $excludeVars = array( '/remove.*/i', //regexp ); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'extraVars' => $extraVars, 'excludeVars' => $excludeVars, ); $this->pager =& Pager::factory($options); $expected = array( 'arr' => array( 0 => 'apple', 1 => 'orange' ), 'no' => 'test', 'leaveCCC' => 'ccc', ); $this->assertEqual($expected, $this->pager->_getLinksData()); //cleanup foreach (array_keys($_GET) as $k) { unset($_GET[$k]); } } function testArgSeparator() { $bkp_arg_separator = ini_get('arg_separator.output'); ini_set('arg_separator.output', '&'); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'extraVars' => array('apple' => 1), ); $this->pager =& Pager::factory($options); $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); ini_set('arg_separator.output', $bkp_arg_separator); } function testAttributes() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'linkClass' => 'testclass', 'attributes' => 'target="_blank"', ); $this->pager =& Pager::factory($options); $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); } function testOnClick() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'linkClass' => 'testclass', 'onclick' => 'doSomething(%d)', ); $this->pager =& Pager::factory($options); $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); } function testImportQuery() { //add some fake url vars $_GET['arr'] = array( 'apple', 'orange', ); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'importQuery' => false, ); $this->pager =& Pager::factory($options); $expected = array(); $actual = $this->pager->_getLinksData(); $this->assertEqual($expected, $this->pager->_getLinksData()); $expected = ''; $actual = $this->pager->_renderLink('', ''); $this->assertEqual($expected, $actual); //remove fake url vars unset($_GET['arr']); } function testGetNextLinkTag() { //append = true $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getNextLinkTag()); //append = false $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 1, 'append' => false, 'fileName' => 'myfile.%d.php', ); $this->pager = Pager::factory($options); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getNextLinkTag()); //test empty tag $options['currentPage'] = 2; $this->pager = Pager::factory($options); $this->assertEqual('', $this->pager->_getNextLinkTag()); } function testGetLastLinkTag() { //append = true $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getLastLinkTag()); //append = false $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 1, 'append' => false, 'fileName' => 'myfile.%d.php', ); $this->pager = Pager::factory($options); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getLastLinkTag()); //test empty tag $options['currentPage'] = 2; $this->pager = Pager::factory($options); $this->assertEqual('', $this->pager->_getLastLinkTag()); } function testGetFirstLinkTag() { //append = true $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, ); $this->pager = Pager::factory($options); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getFirstLinkTag()); //append = false $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, 'append' => false, 'fileName' => 'myfile.%d.php', ); $this->pager = Pager::factory($options); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getFirstLinkTag()); //test empty tag $options['currentPage'] = 1; $this->pager = Pager::factory($options); $this->assertEqual('', $this->pager->_getFirstLinkTag()); } function testGetPrevLinkTag() { //append = true $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, ); $this->pager = Pager::factory($options); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getPrevLinkTag()); //append = false $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, 'append' => false, 'fileName' => 'myfile.%d.php', ); $this->pager = Pager::factory($options); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getPrevLinkTag()); //test empty tag $options['currentPage'] = 1; $this->pager = Pager::factory($options); $this->assertEqual('', $this->pager->_getPrevLinkTag()); } function testPrintFirstPage() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, ); $this->pager = Pager::factory($options); $expected = '[1] '; $this->assertEqual($expected, $this->pager->_printFirstPage()); $this->pager->_firstPageText = 'FIRST'; $expected = '[FIRST] '; $this->assertEqual($expected, $this->pager->_printFirstPage()); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, 'altFirst' => 'page %d', ); $this->pager = Pager::factory($options); $expected = '[1] '; $this->assertEqual($expected, $this->pager->_printFirstPage()); } function testPrintLastPage() { $expected = '[2]'; $this->assertEqual($expected, $this->pager->_printLastPage()); $this->pager->_lastPageText = 'LAST'; $expected = '[LAST]'; $this->assertEqual($expected, $this->pager->_printLastPage()); $this->pager->_altLast = 'page %d'; $expected = '[LAST]'; $this->assertEqual($expected, $this->pager->_printLastPage()); } function testGetPageLinks() { $links = $this->pager->_getPageLinks(); $this->assertTrue(false !== strpos($links, 'title="page 2"')); $this->pager->setOptions(array('altPage' => '%d page')); $this->pager->build(); $links = $this->pager->_getPageLinks(); $this->assertTrue(false !== strpos($links, 'title="2 page"')); } function testGetBackLink() { $img = '«'; $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, 'prevImg' => $img, ); $this->pager = Pager::factory($options); $expected = ''.$img.' '; $this->assertEqual($expected, $this->pager->_getBackLink()); } function testGetBackLinkEmpty() { $img = '[FIRST]'; $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, ); $this->pager = Pager::factory($options); $expected = ''; $this->assertEqual($expected, $this->pager->_getBackLink()); $options['prevImgEmpty'] = $img; $this->pager = Pager::factory($options); $expected = $img.' '; $this->assertEqual($expected, $this->pager->_getBackLink()); } function testGetNexLink() { $img = '»'; $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 1, 'nextImg' => $img, ); $this->pager = Pager::factory($options); $expected = ' '.$img.' '; $this->assertEqual($expected, $this->pager->_getNextLink()); } function testGetNexLinkEmpty() { $img = '[LAST]'; $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'currentPage' => 2, ); $this->pager = Pager::factory($options); $expected = ''; $this->assertEqual($expected, $this->pager->_getNextLink()); $options['nextImgEmpty'] = $img; $this->pager = Pager::factory($options); $expected = ' '.$img.' '; $this->assertEqual($expected, $this->pager->_getNextLink()); } function testHttpMethodAutoDetect() { $_POST['pageID'] = 3; $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, ); $this->pager = Pager::factory($options); $this->assertEqual('POST', $this->pager->_httpMethod); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'httpMethod' => 'GET', ); $this->pager = Pager::factory($options); $this->assertEqual('GET', $this->pager->_httpMethod); unset($_POST['pageID']); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'httpMethod' => 'POST', ); $this->pager = Pager::factory($options); $this->assertEqual('POST', $this->pager->_httpMethod); $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, ); $this->pager = Pager::factory($options); $this->assertEqual('GET', $this->pager->_httpMethod); } function testAccesskey() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'accesskey' => true, ); $this->pager = Pager::factory($options); $this->assertPattern('/accesskey="\d"/i', $this->pager->links); //var_dump($this->pager->links); } function testIsEncoded() { //var_dump(urlencode('안녕')); $test_strings_encoded = array( 'encoded0' => '试', 'encoded1' => '测试', 'encoded2' => '안녕', 'encoded3' => '안 녕', 'encoded4' => '안 녕', ); $test_strings_plain = array( 'plain1' => '안녕', 'plain2' => '더보기', // 'plain3' => '이젠 전화도 //로 걸면 무료', 'plain4' => 'abcde', //not multibyte 'plain5' => '&#abcfg;', //invalid hex-encoded char 'plain5' => '안 nasty 녕', //mixed plain/encoded text ); foreach ($test_strings_encoded as $string) { //echo '
'.str_replace('&', '&', $string); $this->assertTrue($this->pager->_isEncoded($string)); } foreach ($test_strings_plain as $string) { $this->assertFalse($this->pager->_isEncoded($string)); } } function testGetOption() { $this->assertEqual(5, $this->pager->getOption('perPage')); $err = $this->pager->getOption('non_existent_option'); $this->assertEqual(ERROR_PAGER_INVALID, $err->getCode()); } function testGetOptions() { $options = $this->pager->getOptions(); $this->assertTrue(is_array($options)); $this->assertEqual(5, $options['perPage']); } function testSetOptionsAndBuild() { $options = array( 'perPage' => 2, ); $this->pager->setOptions($options); $this->pager->build(); $this->assertEqual(2, $this->pager->getOption('perPage')); $this->assertEqual(array(0=>1, 1=>2), $this->pager->getPageData()); $this->assertEqual(array(2=>3, 3=>4), $this->pager->getPageData(2)); $options = array( 'currentPage' => 2, 'append' => false, 'fileName' => 'myfile.%d.php', ); $this->pager->setOptions($options); $this->pager->build(); $expected = ''."\n"; $this->assertEqual($expected, $this->pager->_getPrevLinkTag()); } function testRelativeLinks() { $fileName = array_pop(explode('/', $_SERVER['PHP_SELF'])); $options = array( 'mode' => 'Sliding', 'path' => '', 'fileName' => $fileName, 'itemData' => range('a', 'z'), 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, ); $this->pager = Pager::factory($options); $expected = '»'; $this->assertEqual($expected, $this->pager->_getNextLink()); $options = array( 'mode' => 'Sliding', 'itemData' => range('a', 'z'), 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, ); $this->pager = Pager::factory($options); $this->pager->build(); $expected = '»'; $this->assertEqual($expected, $this->pager->_getNextLink()); } //http://pear.php.net/bugs/bug.php?id=12306 function testAbsoluteLinks() { // Reproduces bug #13881 $options = array ( 'mode' => 'Sliding', 'delta' => 5, 'totalItems' => 50, 'perPage' => 10, 'urlVar' => 'page', 'currentPage' => 1, 'append' => false, 'path' => '', 'fileName' => '/report/alpha/page/%d/orderBy/foo/direction/asc', 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, ); $this->pager = Pager::factory($options); $this->pager->build(); $expected = '»'; $this->assertEqual($expected, $this->pager->_getNextLink()); $options['path'] = '/'; $options['fileName'] = '/report/alpha/page/%d/orderBy/foo/direction/asc'; $this->pager = Pager::factory($options); $this->pager->build(); $expected = '»'; $this->assertEqual($expected, $this->pager->_getNextLink()); } //http://pear.php.net/bugs/bug.php?id=13913 function testEmptyPagerWithImgEmpty() { $options = array( 'itemData' => range(1, 2), 'perPage' => 5, 'prevImgEmpty' => 'YYY', 'nextImgEmpty' => 'XXX', ); $this->pager = Pager::factory($options); $expected = ''; $this->assertEqual($expected, $this->pager->links); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = new TestOfPager(); $test->run(new HtmlReporter()); } ?>Pager-2.4.8/tests/pager_tests.php100666 0 0 774 11173437505 12010 GroupTest('Pager Tests'); $this->addTestFile('pager_test.php'); $this->addTestFile('pager_noData_test.php'); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = new PagerTests(); $test->run(new HtmlReporter()); } ?>Pager-2.4.8/tests/pager_test_xss.php100666 0 0 2424 11173437505 12534 test'; require_once 'simple_include.php'; require_once 'pager_include.php'; class TestOfPagerXSS extends UnitTestCase { var $pager; var $baseurl; function TestOfPagerXSS($name='Test of Pager - XSS attacks') { $this->UnitTestCase($name); } function setUp() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, ); $this->pager = Pager::factory($options); $this->baseurl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); } function tearDown() { unset($this->pager); } function testXSS() { $options = array( 'itemData' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 'perPage' => 5, 'nextImg' => '»' ); $this->pager = Pager::factory($options); $expected = ' » '; $this->assertEqual($expected, $this->pager->_getNextLink()); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfPagerXSS(); $test->run(new HtmlReporter()); } ?>Pager-2.4.8/tests/pager_wrapper_include.php100666 0 0 222 11173437505 14015 Pager-2.4.8/tests/pager_wrapper_test.php100666 0 0 21556 11173437505 13426 UnitTestCase($name); } function setUp() { } function tearDown() { } /** * Basic tests for rewriteCountQuery() */ function testRewriteCountQuery() { //test LIMIT $query = 'SELECT a, b, c, d FROM mytable WHERE a=1 AND c="g" LIMIT 2'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); //test ORDER BY and quotes $query = 'SELECT a, b, c, d FROM mytable WHERE a=1 AND c="g" ORDER BY (a, b)'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); //test CR/LF $query = 'SELECT a, b, c, d FROM mytable WHERE a=1 AND c="g" ORDER BY (a, b)'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); //test GROUP BY $query = 'SELECT a, b, c, d FROM mytable WHERE a=1 GROUP BY c'; $this->assertFalse(rewriteCountQuery($query)); //test DISTINCT $query = 'SELECT DISTINCT a, b, c, d FROM mytable WHERE a=1 GROUP BY c'; $this->assertFalse(rewriteCountQuery($query)); //test UNION $query = 'SELECT a FROM mytable1 UNION SELECT a FROM mytable2'; $this->assertFalse(rewriteCountQuery($query)); //test MiXeD Keyword CaSe $query = 'SELECT a, b, c, d from mytable WHERE a=1 AND c="g"'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); //test function speed... this query used to be very slow to parse $query = "SELECT i.item_id, ia.addition, u.username, i.date_created, i.start_date, i.expiry_date FROM item i, item_addition ia, item_type it, item_type_mapping itm, usr u, category c WHERE ia.item_type_mapping_id = itm.item_type_mapping_id AND i.updated_by_id = u.usr_id AND it.item_type_id = itm.item_type_id AND i.item_id = ia.item_id AND i.item_type_id = it.item_type_id AND itm.field_name = 'title' AND it.item_type_id = 2 AND i.category_id = 1 AND i.status = 4 AND i.category_id = c.category_id AND 0 NOT IN (COALESCE(c.perms, '-1')) ORDER BY i.last_updated DESC"; $expected = "SELECT COUNT(*) FROM item i, item_addition ia, item_type it, item_type_mapping itm, usr u, category c WHERE ia.item_type_mapping_id = itm.item_type_mapping_id AND i.updated_by_id = u.usr_id AND it.item_type_id = itm.item_type_id AND i.item_id = ia.item_id AND i.item_type_id = it.item_type_id AND itm.field_name = 'title' AND it.item_type_id = 2 AND i.category_id = 1 AND i.status = 4 AND i.category_id = c.category_id AND 0 NOT IN (COALESCE(c.perms, '-1'))"; $this->assertEqual($expected, rewriteCountQuery($query)); } /** * Test rewriteCountQuery() with queries having a subquery in the SELECT clause */ function testRewriteCountQuery_SubqueriesInSelectClause() { $query = 'SELECT a, (SELECT a FROM b) AS b, c, d FROM mytable WHERE a=1 AND c="g" LIMIT 2'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertFalse(rewriteCountQuery($query)); $query = 'SELECT a, (SELECT a FROM b) AS b, (SELECT c FROM c) AS c, d FROM mytable WHERE a=1 AND c="g" LIMIT 2'; //$expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertFalse(rewriteCountQuery($query)); $query = 'SELECT `id`, `ip`, ( SELECT TIMEDIFF(MAX(P.`time`), MIN(P.`time`)) FROM `przejscia` as P WHERE P.`id_wejscia`=W.`id` ) as `czas` FROM `wejscia` as W WHERE W.id_domeny=? ORDER BY W.czas_wejscia DESC'; $expected = 'SELECT COUNT(*) FROM `wejscia` as W WHERE W.id_domeny=? ORDER BY W.czas_wejscia DESC'; $this->assertFalse(rewriteCountQuery($query)); } /** * Test rewriteCountQuery() with queries having a subquery in the FROM clause */ function testRewriteCountQuery_SubqueriesInFromClause() { $query = 'SELECT a, b, c, d FROM (SELECT a, b, c, d FROM mytable WHERE a=1) AS tbl_alias WHERE a=1'; $expected = 'SELECT COUNT(*) FROM (SELECT a, b, c, d FROM mytable WHERE a=1) AS tbl_alias WHERE a=1'; $this->assertEqual($expected, rewriteCountQuery($query)); } /** * Test rewriteCountQuery() with queries having a subquery in the WHERE clause */ function testRewriteCountQuery_SubqueriesInWhereClause() { //this one is not rewritten: subqueries with ORDER BY clauses might get truncated $query = 'SELECT Version.VersionId, Version.Identifier,News.* FROM VersionBroker JOIN ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId JOIN Version ON VersionBroker.Identifier = Version.Identifier JOIN News ON Version.ObjectId = News.NewsId WHERE Version.Status = \'Approved\' AND ObjectType.Name = \'News\' AND Version.ApprovedTS = ( SELECT SubV.ApprovedTS FROM Version SubV WHERE SubV.Identifier = VersionBroker.Identifier ORDER BY ApprovedTS DESC LIMIT 1) ORDER BY ApprovedTS DESC'; $expected = 'SELECT COUNT(*) FROM VersionBroker JOIN ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId JOIN Version ON VersionBroker.Identifier = Version.Identifier JOIN News ON Version.ObjectId = News.NewsId WHERE Version.Status = \'Approved\' AND ObjectType.Name = \'News\' AND Version.ApprovedTS = ( SELECT SubV.ApprovedTS FROM Version SubV WHERE SubV.Identifier = VersionBroker.Identifier ORDER BY ApprovedTS DESC LIMIT 1) ORDER BY ApprovedTS DESC'; //$this->assertEqual($expected, rewriteCountQuery($query)); $this->assertFalse(rewriteCountQuery($query)); //this one should pass... subquery without ORDER BY or LIMIT clause $query = 'SELECT Version.VersionId, Version.Identifier,News.* FROM VersionBroker JOIN ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId JOIN Version ON VersionBroker.Identifier = Version.Identifier JOIN News ON Version.ObjectId = News.NewsId WHERE Version.Status = \'Approved\' AND ObjectType.Name = \'News\' AND Version.ApprovedTS = ( SELECT SubV.ApprovedTS FROM Version SubV WHERE SubV.Identifier = VersionBroker.Identifier ) ORDER BY ApprovedTS DESC'; $expected = 'SELECT COUNT(*) FROM VersionBroker JOIN ObjectType ON ObjectType.ObjectTypeId = VersionBroker.ObjectTypeId JOIN Version ON VersionBroker.Identifier = Version.Identifier JOIN News ON Version.ObjectId = News.NewsId WHERE Version.Status = \'Approved\' AND ObjectType.Name = \'News\' AND Version.ApprovedTS = ( SELECT SubV.ApprovedTS FROM Version SubV WHERE SubV.Identifier = VersionBroker.Identifier )'; $this->assertEqual($expected, rewriteCountQuery($query)); } /** * Test rewriteCountQuery() with queries having keywords embedded in other words */ function testRewriteCountQuery_EmbeddedKeywords() { $query = 'SELECT afieldFROM, b, c, d FROM mytable WHERE a=1 AND c="g"'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); $query = 'SELECT FROMafield, b, c, d FROM mytable WHERE a=1 AND c="g"'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); $query = 'SELECT afieldFROMaaa, b, c, d FROM mytable WHERE a=1 AND c="gLIMIT"'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="gLIMIT"'; $this->assertEqual($expected, rewriteCountQuery($query)); $query = 'SELECT DISTINCTaaa, b, c, d FROM mytable WHERE a=1 AND c="g"'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g"'; $this->assertEqual($expected, rewriteCountQuery($query)); //this one fails... the regexp should NOT match keywords within quotes. //we need a full blown stack-based parser to catch this... $query = 'SELECT afieldFROMaaa, b, c, d FROM mytable WHERE a=1 AND c="g LIMIT a"'; $expected = 'SELECT COUNT(*) FROM mytable WHERE a=1 AND c="g LIMIT a"'; $this->assertEqual($expected, rewriteCountQuery($query)); } } if (!defined('TEST_RUNNING')) { define('TEST_RUNNING', true); $test = &new TestOfPagerWrapper(); $test->run(new HtmlReporter()); } ?>Pager-2.4.8/tests/README100666 0 0 370 11173437505 7627 These tests require Simple Test: http://www.lastcraft.com/simple_test.php - edit the simple_include.php script and set your SimpleTest install dir; - edit the pager_include.php and pager_wrapper_include.php scripts to set your Pager directory. Pager-2.4.8/tests/simple_include.php100666 0 0 757 11173437505 12465 Pager-2.4.8/Pager.php100666 0 0 22067 11173437505 7423 * @author Richard Heyes * @copyright 2003-2008 Lorenzo Alberton, Richard Heyes * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id: Pager.php,v 1.26 2008/02/02 16:55:04 quipo Exp $ * @link http://pear.php.net/package/Pager */ /** * Pager - Wrapper class for [Sliding|Jumping]-window Pager * Usage examples can be found in the PEAR manual * * @category HTML * @package Pager * @author Lorenzo Alberton * @author Richard Heyes * @copyright 2003-2008 Lorenzo Alberton, Richard Heyes * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Pager */ class Pager { // {{{ Pager() /** * Constructor * * ------------------------------------------------------------------------- * VALID options are (default values are set some lines before): * - mode (string): "Jumping" or "Sliding" -window - It determines * pager behaviour. See the manual for more details * - totalItems (int): # of items to page. * - perPage (int): # of items per page. * - delta (int): # of page #s to show before and after the current * one * - linkClass (string): name of CSS class used for link styling. * - append (bool): if true pageID is appended as GET value to the * URL - if false it is embedded in the URL * according to "fileName" specs * - httpMethod (string): Specifies the HTTP method to use. Valid values * are 'GET' or 'POST' * according to "fileName" specs * - importQuery (bool): if true (default behaviour), variables and * values are imported from the submitted data * (query string) and used in the generated links * otherwise they're ignored completely * - path (string): complete path to the page (without the page name) * - fileName (string): name of the page, with a %d if append=true * - urlVar (string): name of pageNumber URL var, for example "pageID" * - altPrev (string): alt text to display for prev page, on prev link. * - altNext (string): alt text to display for next page, on next link. * - altPage (string): alt text to display before the page number. * - prevImg (string): sth (it can be text such as "<< PREV" or an * as well...) to display instead of "<<". * - nextImg (string): same as prevImg, used for NEXT link, instead of * the default value, which is ">>". * - separator (string): what to use to separate numbers (can be an * , a comma, an hyphen, or whatever. * - spacesBeforeSeparator * (int): number of spaces before the separator. * - firstPagePre (string): * string used before first page number (can be an * , a "{", an empty string, or whatever. * - firstPageText (string): * string used in place of first page number * - firstPagePost (string): * string used after first page number (can be an * , a "}", an empty string, or whatever. * - lastPagePre (string): * similar to firstPagePre. * - lastPageText (string): * similar to firstPageText. * - lastPagePost (string): * similar to firstPagePost. * - spacesAfterSeparator * (int): number of spaces after the separator. * - firstLinkTitle (string): * string used as title in tag * - lastLinkTitle (string): * string used as title in tag * - prevLinkTitle (string): * string used as title in tag * - nextLinkTitle (string): * string used as title in tag * - curPageLinkClassName * (string): name of CSS class used for current page link. * - clearIfVoid(bool): if there's only one page, don't display pager. * - extraVars (array): additional URL vars to be added to the querystring * - excludeVars (array): URL vars to be excluded in the querystring * - itemData (array): array of items to page. * - useSessions (bool): if true, number of items to display per page is * stored in the $_SESSION[$_sessionVar] var. * - closeSession (bool): if true, the session is closed just after R/W. * - sessionVar (string): name of the session var for perPage value. * A value != from default can be useful when * using more than one Pager istance in the page. * - pearErrorMode (constant): * PEAR_ERROR mode for raiseError(). * Default is PEAR_ERROR_RETURN. * ------------------------------------------------------------------------- * REQUIRED options are: * - fileName IF append==false (default is true) * - itemData OR totalItems (if itemData is set, totalItems is overwritten) * ------------------------------------------------------------------------- * * @param mixed $options Associative array of option names and their values * * @access public */ function Pager($options = array()) { //this check evaluates to true on 5.0.0RC-dev, //so i'm using another one, for now... //if (version_compare(phpversion(), '5.0.0') == -1) { if (get_class($this) == 'pager') { //php4 lowers class names // assign factoried method to this for PHP 4 eval('$this = Pager::factory($options);'); } else { //php5 is case sensitive $msg = 'Pager constructor is deprecated.' .' You must use the "Pager::factory($params)" method' .' instead of "new Pager($params)"'; trigger_error($msg, E_USER_ERROR); } } // }}} // {{{ factory() /** * Return a pager based on $mode and $options * * @param array $options Optional parameters for the storage class * * @return object Storage object * @static * @access public */ function &factory($options = array()) { $mode = (isset($options['mode']) ? ucfirst($options['mode']) : 'Jumping'); $classname = 'Pager_' . $mode; $classfile = 'Pager' . DIRECTORY_SEPARATOR . $mode . '.php'; // Attempt to include a custom version of the named class, but don't treat // a failure as fatal. The caller may have already included their own // version of the named class. if (!class_exists($classname)) { include_once $classfile; } // If the class exists, return a new instance of it. if (class_exists($classname)) { $pager = new $classname($options); return $pager; } $null = null; return $null; } // }}} } ?>Pager-2.4.8/Common.php100666 0 0 140305 11173437505 7631 * @author Richard Heyes * @copyright 2003-2007 Lorenzo Alberton, Richard Heyes * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id: Common.php,v 1.82 2008/05/31 12:44:55 quipo Exp $ * @link http://pear.php.net/package/Pager */ /** * Two constants used to guess the path- and file-name of the page * when the user doesn't set any other value */ if (substr($_SERVER['PHP_SELF'], -1) == '/') { $http = (isset($_SERVER['HTTPS']) && ('on' == strtolower($_SERVER['HTTPS']))) ? 'https://' : 'http://'; define('PAGER_CURRENT_FILENAME', ''); define('PAGER_CURRENT_PATHNAME', $http.$_SERVER['HTTP_HOST'].str_replace('\\', '/', $_SERVER['PHP_SELF'])); } else { define('PAGER_CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename($_SERVER['PHP_SELF']))); define('PAGER_CURRENT_PATHNAME', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))); } /** * Error codes */ define('PAGER_OK', 0); define('ERROR_PAGER', -1); define('ERROR_PAGER_INVALID', -2); define('ERROR_PAGER_INVALID_PLACEHOLDER', -3); define('ERROR_PAGER_INVALID_USAGE', -4); define('ERROR_PAGER_NOT_IMPLEMENTED', -5); /** * Pager_Common - Common base class for [Sliding|Jumping] Window Pager * Extend this class to write a custom paging class * * @category HTML * @package Pager * @author Lorenzo Alberton * @author Richard Heyes * @copyright 2003-2007 Lorenzo Alberton, Richard Heyes * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Pager */ class Pager_Common { // {{{ class vars /** * @var integer number of items * @access private */ var $_totalItems; /** * @var integer number of items per page * @access private */ var $_perPage = 10; /** * @var integer number of page links for each window * @access private */ var $_delta = 10; /** * @var integer current page number * @access private */ var $_currentPage = 1; /** * @var integer total pages number * @access private */ var $_totalPages = 1; /** * @var string CSS class for links * @access private */ var $_linkClass = ''; /** * @var string wrapper for CSS class name * @access private */ var $_classString = ''; /** * @var string path name * @access private */ var $_path = PAGER_CURRENT_PATHNAME; /** * @var string file name * @access private */ var $_fileName = PAGER_CURRENT_FILENAME; /** * @var boolean If false, don't override the fileName option. Use at your own risk. * @access private */ var $_fixFileName = true; /** * @var boolean you have to use FALSE with mod_rewrite * @access private */ var $_append = true; /** * @var string specifies which HTTP method to use * @access private */ var $_httpMethod = 'GET'; /** * @var string specifies which HTML form to use * @access private */ var $_formID = ''; /** * @var boolean whether or not to import submitted data * @access private */ var $_importQuery = true; /** * @var string name of the querystring var for pageID * @access private */ var $_urlVar = 'pageID'; /** * @var array data to pass through the link * @access private */ var $_linkData = array(); /** * @var array additional URL vars * @access private */ var $_extraVars = array(); /** * @var array URL vars to ignore * @access private */ var $_excludeVars = array(); /** * @var boolean TRUE => expanded mode (for Pager_Sliding) * @access private */ var $_expanded = true; /** * @var boolean TRUE => show accesskey attribute on tags * @access private */ var $_accesskey = false; /** * @var string extra attributes for the tag * @access private */ var $_attributes = ''; /** * @var string onclick * @access private */ var $_onclick = ''; /** * @var string alt text for "first page" (use "%d" placeholder for page number) * @access private */ var $_altFirst = 'first page'; /** * @var string alt text for "previous page" * @access private */ var $_altPrev = 'previous page'; /** * @var string alt text for "next page" * @access private */ var $_altNext = 'next page'; /** * @var string alt text for "last page" (use "%d" placeholder for page number) * @access private */ var $_altLast = 'last page'; /** * @var string alt text for "page" (use optional "%d" placeholder for page number) * @access private */ var $_altPage = 'page'; /** * @var string image/text to use as "prev" link * @access private */ var $_prevImg = '<< Back'; /** * image/text to use as "prev" link when no prev link is needed (e.g. on the first page) * NULL deactivates it * * @var string * @access private */ var $_prevImgEmpty = null; /** * @var string image/text to use as "next" link * @access private */ var $_nextImg = 'Next >>'; /** * image/text to use as "next" link when * no next link is needed (e.g. on the last page) * NULL deactivates it * * @var string * @access private */ var $_nextImgEmpty = null; /** * @var string link separator * @access private */ var $_separator = ''; /** * @var integer number of spaces before separator * @access private */ var $_spacesBeforeSeparator = 0; /** * @var integer number of spaces after separator * @access private */ var $_spacesAfterSeparator = 1; /** * @var string CSS class name for current page link * @access private */ var $_curPageLinkClassName = ''; /** * @var string Text before current page link * @access private */ var $_curPageSpanPre = ''; /** * @var string Text after current page link * @access private */ var $_curPageSpanPost = ''; /** * @var string Text before first page link * @access private */ var $_firstPagePre = '['; /** * @var string Text to be used for first page link * @access private */ var $_firstPageText = ''; /** * @var string Text after first page link * @access private */ var $_firstPagePost = ']'; /** * @var string Text before last page link * @access private */ var $_lastPagePre = '['; /** * @var string Text to be used for last page link * @access private */ var $_lastPageText = ''; /** * @var string Text after last page link * @access private */ var $_lastPagePost = ']'; /** * @var string Will contain the HTML code for the spaces * @access private */ var $_spacesBefore = ''; /** * @var string Will contain the HTML code for the spaces * @access private */ var $_spacesAfter = ''; /** * @var string String used as title in tag * @access private */ var $_firstLinkTitle = 'first page'; /** * @var string String used as title in tag * @access private */ var $_nextLinkTitle = 'next page'; /** * @var string String used as title in tag * @access private */ var $_prevLinkTitle = 'previous page'; /** * @var string String used as title in tag * @access private */ var $_lastLinkTitle = 'last page'; /** * @var string Text to be used for the 'show all' option in the select box * @access private */ var $_showAllText = ''; /** * @var array data to be paged * @access private */ var $_itemData = null; /** * @var boolean If TRUE and there's only one page, links aren't shown * @access private */ var $_clearIfVoid = true; /** * @var boolean Use session for storing the number of items per page * @access private */ var $_useSessions = false; /** * @var boolean Close the session when finished reading/writing data * @access private */ var $_closeSession = false; /** * @var string name of the session var for number of items per page * @access private */ var $_sessionVar = 'setPerPage'; /** * Pear error mode (when raiseError is called) * (see PEAR doc) * * @var integer $_pearErrorMode * @access private */ var $_pearErrorMode = null; // }}} // {{{ public vars /** * @var string Complete set of links * @access public */ var $links = ''; /** * @var string Complete set of link tags * @access public */ var $linkTags = ''; /** * @var array Complete set of raw link tags * @access public */ var $linkTagsRaw = array(); /** * @var array Array with a key => value pair representing * page# => bool value (true if key==currentPageNumber). * can be used for extreme customization. * @access public */ var $range = array(); /** * @var array list of available options (safety check) * @access private */ var $_allowed_options = array( 'totalItems', 'perPage', 'delta', 'linkClass', 'path', 'fileName', 'fixFileName', 'append', 'httpMethod', 'formID', 'importQuery', 'urlVar', 'altFirst', 'altPrev', 'altNext', 'altLast', 'altPage', 'prevImg', 'prevImgEmpty', 'nextImg', 'nextImgEmpty', 'expanded', 'accesskey', 'attributes', 'onclick', 'separator', 'spacesBeforeSeparator', 'spacesAfterSeparator', 'curPageLinkClassName', 'curPageSpanPre', 'curPageSpanPost', 'firstPagePre', 'firstPageText', 'firstPagePost', 'lastPagePre', 'lastPageText', 'lastPagePost', 'firstLinkTitle', 'nextLinkTitle', 'prevLinkTitle', 'lastLinkTitle', 'showAllText', 'itemData', 'clearIfVoid', 'useSessions', 'closeSession', 'sessionVar', 'pearErrorMode', 'extraVars', 'excludeVars', 'currentPage', ); // }}} // {{{ build() /** * Generate or refresh the links and paged data after a call to setOptions() * * @return void * @access public */ function build() { //reset $this->_pageData = array(); $this->links = ''; $this->linkTags = ''; $this->linkTagsRaw = array(); $this->_generatePageData(); $this->_setFirstLastText(); if ($this->_totalPages > (2 * $this->_delta + 1)) { $this->links .= $this->_printFirstPage(); } $this->links .= $this->_getBackLink(); $this->links .= $this->_getPageLinks(); $this->links .= $this->_getNextLink(); $this->linkTags .= $this->_getFirstLinkTag(); $this->linkTags .= $this->_getPrevLinkTag(); $this->linkTags .= $this->_getNextLinkTag(); $this->linkTags .= $this->_getLastLinkTag(); $this->linkTagsRaw['first'] = $this->_getFirstLinkTag(true); $this->linkTagsRaw['prev'] = $this->_getPrevLinkTag(true); $this->linkTagsRaw['next'] = $this->_getNextLinkTag(true); $this->linkTagsRaw['last'] = $this->_getLastLinkTag(true); if ($this->_totalPages > (2 * $this->_delta + 1)) { $this->links .= $this->_printLastPage(); } } // }}} // {{{ getPageData() /** * Returns an array of current pages data * * @param integer $pageID Desired page ID (optional) * * @return array Page data * @access public */ function getPageData($pageID = null) { $pageID = empty($pageID) ? $this->_currentPage : $pageID; if (!isset($this->_pageData)) { $this->_generatePageData(); } if (!empty($this->_pageData[$pageID])) { return $this->_pageData[$pageID]; } return array(); } // }}} // {{{ getPageIdByOffset() /** * Returns pageID for given offset * * @param integer $index Offset to get pageID for * * @return integer PageID for given offset * @access public */ function getPageIdByOffset($index) { $msg = 'function "getPageIdByOffset()" not implemented.'; return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED); } // }}} // {{{ getOffsetByPageId() /** * Returns offsets for given pageID. Eg, if you * pass it pageID one and your perPage limit is 10 * it will return (1, 10). PageID of 2 would * give you (11, 20). * * @param integer $pageID PageID to get offsets for * * @return array First and last offsets * @access public */ function getOffsetByPageId($pageID = null) { $pageID = isset($pageID) ? $pageID : $this->_currentPage; if (!isset($this->_pageData)) { $this->_generatePageData(); } if (isset($this->_pageData[$pageID]) || is_null($this->_itemData)) { return array( max(($this->_perPage * ($pageID - 1)) + 1, 1), min($this->_totalItems, $this->_perPage * $pageID) ); } return array(0, 0); } // }}} // {{{ getPageRangeByPageId() /** * Given a PageId, it returns the limits of the range of pages displayed. * * @param integer $pageID PageID to get offsets for * * @return array First and last offsets * @access public */ function getPageRangeByPageId($pageID = null) { $msg = 'function "getPageRangeByPageId()" not implemented.'; return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED); } // }}} // {{{ getLinks() /** * Returns back/next/first/last and page links, * both as ordered and associative array. * * NB: in original PEAR::Pager this method accepted two parameters, * $back_html and $next_html. Now the only parameter accepted is * an integer ($pageID), since the html text for prev/next links can * be set in the factory. If a second parameter is provided, then * the method act as it previously did. This hack was done to mantain * backward compatibility only. * * @param integer $pageID Optional pageID. If specified, links for that * page are provided instead of current one. * [ADDED IN NEW PAGER VERSION] * @param string $next_html HTML to put inside the next link * [deprecated: use the factory instead] * * @return array back/next/first/last and page links * @access public */ function getLinks($pageID=null, $next_html='') { $msg = 'function "getLinks()" not implemented.'; return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED); } // }}} // {{{ getCurrentPageID() /** * Returns ID of current page * * @return integer ID of current page * @access public */ function getCurrentPageID() { return $this->_currentPage; } // }}} // {{{ getNextPageID() /** * Returns next page ID. If current page is last page * this function returns FALSE * * @return mixed Next page ID or false * @access public */ function getNextPageID() { return ($this->getCurrentPageID() == $this->numPages() ? false : $this->getCurrentPageID() + 1); } // }}} // {{{ getPreviousPageID() /** * Returns previous page ID. If current page is first page * this function returns FALSE * * @return mixed Previous page ID or false * @access public */ function getPreviousPageID() { return $this->isFirstPage() ? false : $this->getCurrentPageID() - 1; } // }}} // {{{ numItems() /** * Returns number of items * * @return integer Number of items * @access public */ function numItems() { return $this->_totalItems; } // }}} // {{{ numPages() /** * Returns number of pages * * @return integer Number of pages * @access public */ function numPages() { return (int)$this->_totalPages; } // }}} // {{{ isFirstPage() /** * Returns whether current page is first page * * @return bool First page or not * @access public */ function isFirstPage() { return ($this->_currentPage < 2); } // }}} // {{{ isLastPage() /** * Returns whether current page is last page * * @return bool Last page or not * @access public */ function isLastPage() { return ($this->_currentPage == $this->_totalPages); } // }}} // {{{ isLastPageComplete() /** * Returns whether last page is complete * * @return bool Last age complete or not * @access public */ function isLastPageComplete() { return !($this->_totalItems % $this->_perPage); } // }}} // {{{ _generatePageData() /** * Calculates all page data * * @return void * @access private */ function _generatePageData() { // Been supplied an array of data? if (!is_null($this->_itemData)) { $this->_totalItems = count($this->_itemData); } $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage); $i = 1; if (!empty($this->_itemData)) { foreach ($this->_itemData as $key => $value) { $this->_pageData[$i][$key] = $value; if (count($this->_pageData[$i]) >= $this->_perPage) { $i++; } } } else { $this->_pageData = array(); } //prevent URL modification $this->_currentPage = min($this->_currentPage, $this->_totalPages); } // }}} // {{{ _renderLink() /** * Renders a link using the appropriate method * * @param string $altText Alternative text for this link (title property) * @param string $linkText Text contained by this link * * @return string The link in string form * @access private */ function _renderLink($altText, $linkText) { if ($this->_httpMethod == 'GET') { if ($this->_append) { $href = '?' . $this->_http_build_query_wrapper($this->_linkData); } else { $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName); } $onclick = ''; if (array_key_exists($this->_urlVar, $this->_linkData)) { $onclick = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_onclick); } return sprintf('%s', htmlentities($this->_url . $href, ENT_COMPAT, 'UTF-8'), empty($this->_classString) ? '' : ' '.$this->_classString, empty($this->_attributes) ? '' : ' '.$this->_attributes, empty($this->_accesskey) ? '' : ' accesskey="'.$this->_linkData[$this->_urlVar].'"', empty($onclick) ? '' : ' onclick="'.$onclick.'"', $altText, $linkText ); } elseif ($this->_httpMethod == 'POST') { $href = $this->_url; if (!empty($_GET)) { $href .= '?' . $this->_http_build_query_wrapper($_GET); } return sprintf("%s", $this->_generateFormOnClick($href, $this->_linkData), empty($this->_classString) ? '' : ' '.$this->_classString, empty($this->_attributes) ? '' : ' '.$this->_attributes, empty($this->_accesskey) ? '' : ' accesskey=\''.$this->_linkData[$this->_urlVar].'\'', $altText, $linkText ); } return ''; } // }}} // {{{ _generateFormOnClick() /** * Mimics http_build_query() behavior in the way the data * in $data will appear when it makes it back to the server. * For example: * $arr = array('array' => array(array('hello', 'world'), * 'things' => array('stuff', 'junk')); * http_build_query($arr) * and _generateFormOnClick('foo.php', $arr) * will yield * $_REQUEST['array'][0][0] === 'hello' * $_REQUEST['array'][0][1] === 'world' * $_REQUEST['array']['things'][0] === 'stuff' * $_REQUEST['array']['things'][1] === 'junk' * * However, instead of generating a query string, it generates * Javascript to create and submit a form. * * @param string $formAction where the form should be submitted * @param array $data the associative array of names and values * * @return string A string of javascript that generates a form and submits it * @access private */ function _generateFormOnClick($formAction, $data) { // Check we have an array to work with if (!is_array($data)) { trigger_error( '_generateForm() Parameter 1 expected to be Array or Object. Incorrect value given.', E_USER_WARNING ); return false; } if (!empty($this->_formID)) { $str = 'var form = document.getElementById("'.$this->_formID.'"); var input = ""; '; } else { $str = 'var form = document.createElement("form"); var input = ""; '; } // We /shouldn't/ need to escape the URL ... $str .= sprintf('form.action = "%s"; ', htmlentities($formAction, ENT_COMPAT, 'UTF-8')); $str .= sprintf('form.method = "%s"; ', $this->_httpMethod); foreach ($data as $key => $val) { $str .= $this->_generateFormOnClickHelper($val, $key); } if (empty($this->_formID)) { $str .= 'document.getElementsByTagName("body")[0].appendChild(form);'; } $str .= 'form.submit(); return false;'; return $str; } // }}} // {{{ _generateFormOnClickHelper /** * This is used by _generateFormOnClick(). * Recursively processes the arrays, objects, and literal values. * * @param mixed $data Data that should be rendered * @param string $prev The name so far * * @return string A string of Javascript that creates form inputs * representing the data * @access private */ function _generateFormOnClickHelper($data, $prev = '') { $str = ''; if (is_array($data) || is_object($data)) { // foreach key/visible member foreach ((array)$data as $key => $val) { // append [$key] to prev $tempKey = sprintf('%s[%s]', $prev, $key); $str .= $this->_generateFormOnClickHelper($val, $tempKey); } } else { // must be a literal value // escape newlines and carriage returns $search = array("\n", "\r"); $replace = array('\n', '\n'); $escapedData = str_replace($search, $replace, $data); // am I forgetting any dangerous whitespace? // would a regex be faster? // if it's already encoded, don't encode it again if (!$this->_isEncoded($escapedData)) { $escapedData = urlencode($escapedData); } $escapedData = htmlentities($escapedData, ENT_QUOTES, 'UTF-8'); $str .= 'input = document.createElement("input"); '; $str .= 'input.type = "hidden"; '; $str .= sprintf('input.name = "%s"; ', $prev); $str .= sprintf('input.value = "%s"; ', $escapedData); $str .= 'form.appendChild(input); '; } return $str; } // }}} // {{{ _isRegexp() /** * Returns true if the string is a regexp pattern * * @param string $string the pattern to check * * @return boolean * @access private */ function _isRegexp($string) { return preg_match('/^\/.*\/([Uims]+)?$/', $string); } // }}} // {{{ _getLinksData() /** * Returns the correct link for the back/pages/next links * * @return array Data * @access private */ function _getLinksData() { $qs = array(); if ($this->_importQuery) { if ($this->_httpMethod == 'POST') { $qs = $_POST; } elseif ($this->_httpMethod == 'GET') { $qs = $_GET; } } foreach ($this->_excludeVars as $exclude) { $use_preg = $this->_isRegexp($exclude); foreach (array_keys($qs) as $qs_item) { if ($use_preg) { if (preg_match($exclude, $qs_item, $matches)) { foreach ($matches as $m) { unset($qs[$m]); } } } elseif ($qs_item == $exclude) { unset($qs[$qs_item]); break; } } } if (count($this->_extraVars)) { $this->_recursive_urldecode($this->_extraVars); $qs = array_merge($qs, $this->_extraVars); } if (count($qs) && function_exists('get_magic_quotes_gpc') && -1 == version_compare(PHP_VERSION, '5.2.99') && get_magic_quotes_gpc() ) { $this->_recursive_stripslashes($qs); } return $qs; } // }}} // {{{ _recursive_stripslashes() /** * Helper method * * @param string|array &$var variable to clean * * @return void * @access private */ function _recursive_stripslashes(&$var) { if (is_array($var)) { foreach (array_keys($var) as $k) { $this->_recursive_stripslashes($var[$k]); } } else { $var = stripslashes($var); } } // }}} // {{{ _recursive_urldecode() /** * Helper method * * @param string|array &$var variable to decode * * @return void * @access private */ function _recursive_urldecode(&$var) { if (is_array($var)) { foreach (array_keys($var) as $k) { $this->_recursive_urldecode($var[$k]); } } else { $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES)); $var = strtr($var, $trans_tbl); } } // }}} // {{{ _getBackLink() /** * Returns back link * * @param string $url URL to use in the link [deprecated: use the factory instead] * @param string $link HTML to use as the link [deprecated: use the factory instead] * * @return string The link * @access private */ function _getBackLink($url='', $link='') { //legacy settings... the preferred way to set an option //now is passing it to the factory if (!empty($url)) { $this->_path = $url; } if (!empty($link)) { $this->_prevImg = $link; } $back = ''; if ($this->_currentPage > 1) { $this->_linkData[$this->_urlVar] = $this->getPreviousPageID(); $back = $this->_renderLink($this->_altPrev, $this->_prevImg) . $this->_spacesBefore . $this->_spacesAfter; } else if ($this->_prevImgEmpty !== null && $this->_totalPages > 1) { $back = $this->_prevImgEmpty . $this->_spacesBefore . $this->_spacesAfter; } return $back; } // }}} // {{{ _getPageLinks() /** * Returns pages link * * @param string $url URL to use in the link [deprecated: use the factory instead] * * @return string Links * @access private */ function _getPageLinks($url='') { $msg = 'function "_getPageLinks()" not implemented.'; return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED); } // }}} // {{{ _getNextLink() /** * Returns next link * * @param string $url URL to use in the link [deprecated: use the factory instead] * @param string $link HTML to use as the link [deprecated: use the factory instead] * * @return string The link * @access private */ function _getNextLink($url='', $link='') { //legacy settings... the preferred way to set an option //now is passing it to the factory if (!empty($url)) { $this->_path = $url; } if (!empty($link)) { $this->_nextImg = $link; } $next = ''; if ($this->_currentPage < $this->_totalPages) { $this->_linkData[$this->_urlVar] = $this->getNextPageID(); $next = $this->_spacesAfter . $this->_renderLink($this->_altNext, $this->_nextImg) . $this->_spacesBefore . $this->_spacesAfter; } else if ($this->_nextImgEmpty !== null && $this->_totalPages > 1) { $next = $this->_spacesAfter . $this->_nextImgEmpty . $this->_spacesBefore . $this->_spacesAfter; } return $next; } // }}} // {{{ _getFirstLinkTag() /** * Returns first link tag * * @param bool $raw should tag returned as array * * @return mixed string with html link tag or separated as array * @access private */ function _getFirstLinkTag($raw = false) { if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) { return $raw ? array() : ''; } if ($raw) { return array( 'url' => $this->_getLinkTagUrl(1), 'title' => $this->_firstLinkTitle ); } return sprintf(''."\n", $this->_getLinkTagUrl(1), $this->_firstLinkTitle ); } // }}} // {{{ _getPrevLinkTag() /** * Returns previous link tag * * @param bool $raw should tag returned as array * * @return mixed string with html link tag or separated as array * @access private */ function _getPrevLinkTag($raw = false) { if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) { return $raw ? array() : ''; } if ($raw) { return array( 'url' => $this->_getLinkTagUrl($this->getPreviousPageID()), 'title' => $this->_prevLinkTitle ); } return sprintf(''."\n", $this->_getLinkTagUrl($this->getPreviousPageID()), $this->_prevLinkTitle ); } // }}} // {{{ _getNextLinkTag() /** * Returns next link tag * * @param bool $raw should tag returned as array * * @return mixed string with html link tag or separated as array * @access private */ function _getNextLinkTag($raw = false) { if ($this->isLastPage() || ($this->_httpMethod != 'GET')) { return $raw ? array() : ''; } if ($raw) { return array( 'url' => $this->_getLinkTagUrl($this->getNextPageID()), 'title' => $this->_nextLinkTitle ); } return sprintf(''."\n", $this->_getLinkTagUrl($this->getNextPageID()), $this->_nextLinkTitle ); } // }}} // {{{ _getLastLinkTag() /** * Returns last link tag * * @param bool $raw should tag returned as array * * @return mixed string with html link tag or separated as array * @access private */ function _getLastLinkTag($raw = false) { if ($this->isLastPage() || ($this->_httpMethod != 'GET')) { return $raw ? array() : ''; } if ($raw) { return array( 'url' => $this->_getLinkTagUrl($this->_totalPages), 'title' => $this->_lastLinkTitle ); } return sprintf(''."\n", $this->_getLinkTagUrl($this->_totalPages), $this->_lastLinkTitle ); } // }}} // {{{ _getLinkTagUrl() /** * Helper method * * @param integer $pageID page ID * * @return string the link tag url * @access private */ function _getLinkTagUrl($pageID) { $this->_linkData[$this->_urlVar] = $pageID; if ($this->_append) { $href = '?' . $this->_http_build_query_wrapper($this->_linkData); } else { $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName); } return htmlentities($this->_url . $href, ENT_COMPAT, 'UTF-8'); } // }}} // {{{ getPerPageSelectBox() /** * Returns a string with a XHTML SELECT menu, * useful for letting the user choose how many items per page should be * displayed. If parameter useSessions is TRUE, this value is stored in * a session var. The string isn't echoed right now so you can use it * with template engines. * * @param integer $start starting value for the select menu * @param integer $end ending value for the select menu * @param integer $step step between values in the select menu * @param boolean $showAllData If true, perPage is set equal to totalItems. * @param array $extraParams (or string $optionText for BC reasons) * - 'optionText': text to show in each option. * Use '%d' where you want to see the number of pages selected. * - 'attributes': (html attributes) Tag attributes or * HTML attributes (id="foo" pairs), will be inserted in the * tag * * @return string xhtml select box * @access public */ function getPageSelectBox($params = array(), $extraAttributes = '') { include_once 'Pager/HtmlWidgets.php'; $widget = new Pager_HtmlWidgets($this); return $widget->getPageSelectBox($params, $extraAttributes); } // }}} // {{{ _printFirstPage() /** * Print [1] * * @return string String with link to 1st page, * or empty string if this is the 1st page. * @access private */ function _printFirstPage() { if ($this->isFirstPage()) { return ''; } $this->_linkData[$this->_urlVar] = 1; return $this->_renderLink( str_replace('%d', 1, $this->_altFirst), $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost ) . $this->_spacesBefore . $this->_spacesAfter; } // }}} // {{{ _printLastPage() /** * Print [numPages()] * * @return string String with link to last page, * or empty string if this is the 1st page. * @access private */ function _printLastPage() { if ($this->isLastPage()) { return ''; } $this->_linkData[$this->_urlVar] = $this->_totalPages; return $this->_renderLink( str_replace('%d', $this->_totalPages, $this->_altLast), $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost ); } // }}} // {{{ _setFirstLastText() /** * sets the private _firstPageText, _lastPageText variables * based on whether they were set in the options * * @return void * @access private */ function _setFirstLastText() { if ($this->_firstPageText == '') { $this->_firstPageText = '1'; } if ($this->_lastPageText == '') { $this->_lastPageText = $this->_totalPages; } } // }}} // {{{ _http_build_query_wrapper() /** * This is a slightly modified version of the http_build_query() function; * it heavily borrows code from PHP_Compat's http_build_query(). * The main change is the usage of htmlentities instead of urlencode, * since it's too aggressive * * @param array $data array of querystring values * * @return string * @access private */ function _http_build_query_wrapper($data) { $data = (array)$data; if (empty($data)) { return ''; } $separator = ini_get('arg_separator.output'); if ($separator == '&') { $separator = '&'; //the string is escaped by htmlentities anyway... } $tmp = array (); foreach ($data as $key => $val) { if (is_scalar($val)) { //array_push($tmp, $key.'='.$val); $val = urlencode($val); array_push($tmp, $key .'='. str_replace('%2F', '/', $val)); continue; } // If the value is an array, recursively parse it if (is_array($val)) { array_push($tmp, $this->__http_build_query($val, urlencode($key))); continue; } } return implode($separator, $tmp); } // }}} // {{{ __http_build_query() /** * Helper function * * @param array $array array of querystring values * @param string $name key * * @return string * @access private */ function __http_build_query($array, $name) { $tmp = array (); $separator = ini_get('arg_separator.output'); if ($separator == '&') { $separator = '&'; //the string is escaped by htmlentities anyway... } foreach ($array as $key => $value) { if (is_array($value)) { //array_push($tmp, $this->__http_build_query($value, sprintf('%s[%s]', $name, $key))); array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D')); } elseif (is_scalar($value)) { //array_push($tmp, sprintf('%s[%s]=%s', $name, htmlentities($key), htmlentities($value))); array_push($tmp, $name.'%5B'.urlencode($key).'%5D='.urlencode($value)); } elseif (is_object($value)) { //array_push($tmp, $this->__http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key))); array_push($tmp, $this->__http_build_query(get_object_vars($value), $name.'%5B'.$key.'%5D')); } } return implode($separator, $tmp); } // }}} // {{{ _isEncoded() /** * Helper function * Check if a string is an encoded multibyte string * * @param string $string string to check * * @return boolean * @access private */ function _isEncoded($string) { $hexchar = '&#[\dA-Fx]{2,};'; return preg_match("/^(\s|($hexchar))*$/Uims", $string) ? true : false; } // }}} // {{{ raiseError() /** * conditionally includes PEAR base class and raise an error * * @param string $msg Error message * @param integer $code Error code * * @return PEAR_Error * @access private */ function raiseError($msg, $code) { include_once 'PEAR.php'; if (empty($this->_pearErrorMode)) { $this->_pearErrorMode = PEAR_ERROR_RETURN; } return PEAR::raiseError($msg, $code, $this->_pearErrorMode); } // }}} // {{{ setOptions() /** * Set and sanitize options * * @param mixed $options An associative array of option names and their values * * @return integer error code (PAGER_OK on success) * @access public */ function setOptions($options) { foreach ($options as $key => $value) { if (in_array($key, $this->_allowed_options) && (!is_null($value))) { $this->{'_' . $key} = $value; } } //autodetect http method if (!isset($options['httpMethod']) && !isset($_GET[$this->_urlVar]) && isset($_POST[$this->_urlVar]) ) { $this->_httpMethod = 'POST'; } else { $this->_httpMethod = strtoupper($this->_httpMethod); } if (substr($this->_path, -1, 1) == '/') { $this->_fileName = ltrim($this->_fileName, '/'); //strip leading slash } if ($this->_append) { if ($this->_fixFileName) { $this->_fileName = PAGER_CURRENT_FILENAME; //avoid possible user error; } $this->_url = $this->_path.(empty($this->_path) ? '' : '/').$this->_fileName; } else { $this->_url = $this->_path; if (0 != strncasecmp($this->_fileName, 'javascript', 10)) { $this->_url .= (empty($this->_path) ? '' : '/'); } if (false === strpos($this->_fileName, '%d')) { trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE), E_USER_WARNING); } } if (substr($this->_url, 0, 2) == '//') { $this->_url = substr($this->_url, 1); } if (false === strpos($this->_altPage, '%d')) { //by default, append page number at the end $this->_altPage .= ' %d'; } $this->_classString = ''; if (strlen($this->_linkClass)) { $this->_classString = 'class="'.$this->_linkClass.'"'; } if (strlen($this->_curPageLinkClassName)) { $this->_curPageSpanPre .= ''; $this->_curPageSpanPost = '' . $this->_curPageSpanPost; } $this->_perPage = max($this->_perPage, 1); //avoid possible user errors if ($this->_useSessions && !isset($_SESSION)) { session_start(); } if (!empty($_REQUEST[$this->_sessionVar])) { $this->_perPage = max(1, (int)$_REQUEST[$this->_sessionVar]); if ($this->_useSessions) { $_SESSION[$this->_sessionVar] = $this->_perPage; } } if (!empty($_SESSION[$this->_sessionVar]) && $this->_useSessions) { $this->_perPage = $_SESSION[$this->_sessionVar]; } if ($this->_closeSession) { session_write_close(); } $this->_spacesBefore = str_repeat(' ', $this->_spacesBeforeSeparator); $this->_spacesAfter = str_repeat(' ', $this->_spacesAfterSeparator); if (isset($_REQUEST[$this->_urlVar]) && empty($options['currentPage'])) { $this->_currentPage = (int)$_REQUEST[$this->_urlVar]; } $this->_currentPage = max($this->_currentPage, 1); $this->_linkData = $this->_getLinksData(); return PAGER_OK; } // }}} // {{{ getOption() /** * Return the current value of a given option * * @param string $name option name * * @return mixed option value * @access public */ function getOption($name) { if (!in_array($name, $this->_allowed_options)) { $msg = 'invalid option: '.$name; return $this->raiseError($msg, ERROR_PAGER_INVALID); } return $this->{'_' . $name}; } // }}} // {{{ getOptions() /** * Return an array with all the current pager options * * @return array list of all the pager options * @access public */ function getOptions() { $options = array(); foreach ($this->_allowed_options as $option) { $options[$option] = $this->{'_' . $option}; } return $options; } // }}} // {{{ errorMessage() /** * Return a textual error message for a PAGER error code * * @param integer $code error code * * @return string error message * @access public */ function errorMessage($code) { static $errorMessages; if (!isset($errorMessages)) { $errorMessages = array( ERROR_PAGER => 'unknown error', ERROR_PAGER_INVALID => 'invalid', ERROR_PAGER_INVALID_PLACEHOLDER => 'invalid format - use "%d" as placeholder.', ERROR_PAGER_INVALID_USAGE => 'if $options[\'append\'] is set to false, ' .' $options[\'fileName\'] MUST contain the "%d" placeholder.', ERROR_PAGER_NOT_IMPLEMENTED => 'not implemented' ); } return (isset($errorMessages[$code]) ? $errorMessages[$code] : $errorMessages[ERROR_PAGER]); } // }}} } ?>Pager-2.4.8/HtmlWidgets.php100666 0 0 27361 11173437505 10622 * @copyright 2003-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @version CVS: $Id: HtmlWidgets.php,v 1.7 2009/03/13 16:51:37 quipo Exp $ * @link http://pear.php.net/package/Pager */ /** * Pager_HtmlWidgets * * @category HTML * @package Pager * @author Lorenzo Alberton * @copyright 2003-2007 Lorenzo Alberton * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause) * @link http://pear.php.net/package/Pager */ class Pager_HtmlWidgets { var $pager = null; // {{{ constructor /** * Constructor * * @param object &$pager Pager instance */ function Pager_HtmlWidgets(&$pager) { $this->pager =& $pager; } // }}} // {{{ getPerPageSelectBox() /** * Returns a string with a XHTML SELECT menu, * useful for letting the user choose how many items per page should be * displayed. If parameter useSessions is TRUE, this value is stored in * a session var. The string isn't echoed right now so you can use it * with template engines. * * @param integer $start starting value for the select menu * @param integer $end ending value for the select menu * @param integer $step step between values in the select menu * @param boolean $showAllData If true, perPage is set equal to totalItems. * @param array $extraParams (or string $optionText for BC reasons) * - 'optionText': text to show in each option. * Use '%d' where you want to see the number of pages selected. * - 'attributes': (html attributes) Tag attributes or * HTML attributes (id="foo" pairs), will be inserted in the * pager->_httpMethod) { $selector = '\' + '.'this.options[this.selectedIndex].value + \''; if ($this->pager->_append) { $tmpLinkData = $this->pager->_linkData; if (isset($tmpLinkData[$this->pager->_urlVar])) { $tmpLinkData[$this->pager->_urlVar] = $this->pager->getCurrentPageID(); } $tmpLinkData[$this->pager->_sessionVar] = '1'; $href = '?' . $this->pager->_http_build_query_wrapper($tmpLinkData); $href = htmlentities($this->pager->_url, ENT_COMPAT, 'UTF-8'). preg_replace( '/(&|&|\?)('.$this->pager->_sessionVar.'=)(\d+)/', '\\1\\2'.$selector, htmlentities($href, ENT_COMPAT, 'UTF-8') ); } else { $href = htmlentities($this->pager->_url . str_replace('%d', $selector, $this->pager->_fileName), ENT_COMPAT, 'UTF-8'); } $tmp .= ' onchange="document.location.href=\'' . $href .'\'' . '"'; } elseif ($this->pager->_httpMethod == 'POST') { $tmp .= " onchange='" . $this->pager->_generateFormOnClick($this->pager->_url, $this->pager->_linkData) . "'"; $tmp = preg_replace( '/(input\.name = \"'.$this->pager->_sessionVar.'\"; input\.value =) \"(\d+)\";/', '\\1 this.options[this.selectedIndex].value;', $tmp ); } } $tmp .= '>'; $last = $start; for ($i=$start; $i<=$end; $i+=$step) { $last = $i; $tmp .= ''; } if (substr($tmp, -9, 9) !== '') { //empty select $tmp .= '