PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/common/libraries/plugin/pear/Pager/Common.php

https://bitbucket.org/chamilo/chamilo/
PHP | 1702 lines | 717 code | 180 blank | 805 comment | 124 complexity | 487db87c2a5fe2eb1bd851595a8da55d MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Contains the Pager_Common class
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @category HTML
  30. * @package Pager
  31. * @author Lorenzo Alberton <l.alberton@quipo.it>
  32. * @author Richard Heyes <richard@phpguru.org>
  33. * @copyright 2003-2007 Lorenzo Alberton, Richard Heyes
  34. * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
  35. * @version CVS: $Id: Common.php 137 2009-11-09 13:24:37Z vanpouckesven $
  36. * @link http://pear.php.net/package/Pager
  37. */
  38. /**
  39. * Two constants used to guess the path- and file-name of the page
  40. * when the user doesn't set any other value
  41. */
  42. if (substr($_SERVER['PHP_SELF'], -1) == '/') {
  43. $http = (isset($_SERVER['HTTPS']) && ('on' == strtolower($_SERVER['HTTPS']))) ? 'https://' : 'http://';
  44. define('PAGER_CURRENT_FILENAME', '');
  45. define('PAGER_CURRENT_PATHNAME', $http.$_SERVER['HTTP_HOST'].str_replace('\\', '/', $_SERVER['PHP_SELF']));
  46. } else {
  47. define('PAGER_CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename($_SERVER['PHP_SELF'])));
  48. define('PAGER_CURRENT_PATHNAME', str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])));
  49. }
  50. /**
  51. * Error codes
  52. */
  53. define('PAGER_OK', 0);
  54. define('ERROR_PAGER', -1);
  55. define('ERROR_PAGER_INVALID', -2);
  56. define('ERROR_PAGER_INVALID_PLACEHOLDER', -3);
  57. define('ERROR_PAGER_INVALID_USAGE', -4);
  58. define('ERROR_PAGER_NOT_IMPLEMENTED', -5);
  59. /**
  60. * Pager_Common - Common base class for [Sliding|Jumping] Window Pager
  61. * Extend this class to write a custom paging class
  62. *
  63. * @category HTML
  64. * @package Pager
  65. * @author Lorenzo Alberton <l.alberton@quipo.it>
  66. * @author Richard Heyes <richard@phpguru.org>
  67. * @copyright 2003-2007 Lorenzo Alberton, Richard Heyes
  68. * @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
  69. * @link http://pear.php.net/package/Pager
  70. */
  71. class Pager_Common
  72. {
  73. // {{{ class vars
  74. /**
  75. * @var integer number of items
  76. * @access private
  77. */
  78. var $_totalItems;
  79. /**
  80. * @var integer number of items per page
  81. * @access private
  82. */
  83. var $_perPage = 10;
  84. /**
  85. * @var integer number of page links for each window
  86. * @access private
  87. */
  88. var $_delta = 10;
  89. /**
  90. * @var integer current page number
  91. * @access private
  92. */
  93. var $_currentPage = 1;
  94. /**
  95. * @var integer total pages number
  96. * @access private
  97. */
  98. var $_totalPages = 1;
  99. /**
  100. * @var string CSS class for links
  101. * @access private
  102. */
  103. var $_linkClass = '';
  104. /**
  105. * @var string wrapper for CSS class name
  106. * @access private
  107. */
  108. var $_classString = '';
  109. /**
  110. * @var string path name
  111. * @access private
  112. */
  113. var $_path = PAGER_CURRENT_PATHNAME;
  114. /**
  115. * @var string file name
  116. * @access private
  117. */
  118. var $_fileName = PAGER_CURRENT_FILENAME;
  119. /**
  120. * @var boolean If false, don't override the fileName option. Use at your own risk.
  121. * @access private
  122. */
  123. var $_fixFileName = true;
  124. /**
  125. * @var boolean you have to use FALSE with mod_rewrite
  126. * @access private
  127. */
  128. var $_append = true;
  129. /**
  130. * @var string specifies which HTTP method to use
  131. * @access private
  132. */
  133. var $_httpMethod = 'GET';
  134. /**
  135. * @var string specifies which HTML form to use
  136. * @access private
  137. */
  138. var $_formID = '';
  139. /**
  140. * @var boolean whether or not to import submitted data
  141. * @access private
  142. */
  143. var $_importQuery = true;
  144. /**
  145. * @var string name of the querystring var for pageID
  146. * @access private
  147. */
  148. var $_urlVar = 'pageID';
  149. /**
  150. * @var array data to pass through the link
  151. * @access private
  152. */
  153. var $_linkData = array();
  154. /**
  155. * @var array additional URL vars
  156. * @access private
  157. */
  158. var $_extraVars = array();
  159. /**
  160. * @var array URL vars to ignore
  161. * @access private
  162. */
  163. var $_excludeVars = array();
  164. /**
  165. * @var boolean TRUE => expanded mode (for Pager_Sliding)
  166. * @access private
  167. */
  168. var $_expanded = true;
  169. /**
  170. * @var boolean TRUE => show accesskey attribute on <a> tags
  171. * @access private
  172. */
  173. var $_accesskey = false;
  174. /**
  175. * @var string extra attributes for the <a> tag
  176. * @access private
  177. */
  178. var $_attributes = '';
  179. /**
  180. * @var string onclick
  181. * @access private
  182. */
  183. var $_onclick = '';
  184. /**
  185. * @var string alt text for "first page" (use "%d" placeholder for page number)
  186. * @access private
  187. */
  188. var $_altFirst = 'first page';
  189. /**
  190. * @var string alt text for "previous page"
  191. * @access private
  192. */
  193. var $_altPrev = 'previous page';
  194. /**
  195. * @var string alt text for "next page"
  196. * @access private
  197. */
  198. var $_altNext = 'next page';
  199. /**
  200. * @var string alt text for "last page" (use "%d" placeholder for page number)
  201. * @access private
  202. */
  203. var $_altLast = 'last page';
  204. /**
  205. * @var string alt text for "page" (use optional "%d" placeholder for page number)
  206. * @access private
  207. */
  208. var $_altPage = 'page';
  209. /**
  210. * @var string image/text to use as "prev" link
  211. * @access private
  212. */
  213. var $_prevImg = '&lt;&lt; Back';
  214. /**
  215. * image/text to use as "prev" link when no prev link is needed (e.g. on the first page)
  216. * NULL deactivates it
  217. *
  218. * @var string
  219. * @access private
  220. */
  221. var $_prevImgEmpty = null;
  222. /**
  223. * @var string image/text to use as "next" link
  224. * @access private
  225. */
  226. var $_nextImg = 'Next &gt;&gt;';
  227. /**
  228. * image/text to use as "next" link when
  229. * no next link is needed (e.g. on the last page)
  230. * NULL deactivates it
  231. *
  232. * @var string
  233. * @access private
  234. */
  235. var $_nextImgEmpty = null;
  236. /**
  237. * @var string link separator
  238. * @access private
  239. */
  240. var $_separator = '';
  241. /**
  242. * @var integer number of spaces before separator
  243. * @access private
  244. */
  245. var $_spacesBeforeSeparator = 0;
  246. /**
  247. * @var integer number of spaces after separator
  248. * @access private
  249. */
  250. var $_spacesAfterSeparator = 1;
  251. /**
  252. * @var string CSS class name for current page link
  253. * @access private
  254. */
  255. var $_curPageLinkClassName = '';
  256. /**
  257. * @var string Text before current page link
  258. * @access private
  259. */
  260. var $_curPageSpanPre = '';
  261. /**
  262. * @var string Text after current page link
  263. * @access private
  264. */
  265. var $_curPageSpanPost = '';
  266. /**
  267. * @var string Text before first page link
  268. * @access private
  269. */
  270. var $_firstPagePre = '[';
  271. /**
  272. * @var string Text to be used for first page link
  273. * @access private
  274. */
  275. var $_firstPageText = '';
  276. /**
  277. * @var string Text after first page link
  278. * @access private
  279. */
  280. var $_firstPagePost = ']';
  281. /**
  282. * @var string Text before last page link
  283. * @access private
  284. */
  285. var $_lastPagePre = '[';
  286. /**
  287. * @var string Text to be used for last page link
  288. * @access private
  289. */
  290. var $_lastPageText = '';
  291. /**
  292. * @var string Text after last page link
  293. * @access private
  294. */
  295. var $_lastPagePost = ']';
  296. /**
  297. * @var string Will contain the HTML code for the spaces
  298. * @access private
  299. */
  300. var $_spacesBefore = '';
  301. /**
  302. * @var string Will contain the HTML code for the spaces
  303. * @access private
  304. */
  305. var $_spacesAfter = '';
  306. /**
  307. * @var string String used as title in <link rel="first"> tag
  308. * @access private
  309. */
  310. var $_firstLinkTitle = 'first page';
  311. /**
  312. * @var string String used as title in <link rel="next"> tag
  313. * @access private
  314. */
  315. var $_nextLinkTitle = 'next page';
  316. /**
  317. * @var string String used as title in <link rel="previous"> tag
  318. * @access private
  319. */
  320. var $_prevLinkTitle = 'previous page';
  321. /**
  322. * @var string String used as title in <link rel="last"> tag
  323. * @access private
  324. */
  325. var $_lastLinkTitle = 'last page';
  326. /**
  327. * @var string Text to be used for the 'show all' option in the select box
  328. * @access private
  329. */
  330. var $_showAllText = '';
  331. /**
  332. * @var array data to be paged
  333. * @access private
  334. */
  335. var $_itemData = null;
  336. /**
  337. * @var boolean If TRUE and there's only one page, links aren't shown
  338. * @access private
  339. */
  340. var $_clearIfVoid = true;
  341. /**
  342. * @var boolean Use session for storing the number of items per page
  343. * @access private
  344. */
  345. var $_useSessions = false;
  346. /**
  347. * @var boolean Close the session when finished reading/writing data
  348. * @access private
  349. */
  350. var $_closeSession = false;
  351. /**
  352. * @var string name of the session var for number of items per page
  353. * @access private
  354. */
  355. var $_sessionVar = 'setPerPage';
  356. /**
  357. * Pear error mode (when raiseError is called)
  358. * (see PEAR doc)
  359. *
  360. * @var integer $_pearErrorMode
  361. * @access private
  362. */
  363. var $_pearErrorMode = null;
  364. // }}}
  365. // {{{ public vars
  366. /**
  367. * @var string Complete set of links
  368. * @access public
  369. */
  370. var $links = '';
  371. /**
  372. * @var string Complete set of link tags
  373. * @access public
  374. */
  375. var $linkTags = '';
  376. /**
  377. * @var array Complete set of raw link tags
  378. * @access public
  379. */
  380. var $linkTagsRaw = array();
  381. /**
  382. * @var array Array with a key => value pair representing
  383. * page# => bool value (true if key==currentPageNumber).
  384. * can be used for extreme customization.
  385. * @access public
  386. */
  387. var $range = array();
  388. /**
  389. * @var array list of available options (safety check)
  390. * @access private
  391. */
  392. var $_allowed_options = array(
  393. 'totalItems',
  394. 'perPage',
  395. 'delta',
  396. 'linkClass',
  397. 'path',
  398. 'fileName',
  399. 'fixFileName',
  400. 'append',
  401. 'httpMethod',
  402. 'formID',
  403. 'importQuery',
  404. 'urlVar',
  405. 'altFirst',
  406. 'altPrev',
  407. 'altNext',
  408. 'altLast',
  409. 'altPage',
  410. 'prevImg',
  411. 'prevImgEmpty',
  412. 'nextImg',
  413. 'nextImgEmpty',
  414. 'expanded',
  415. 'accesskey',
  416. 'attributes',
  417. 'onclick',
  418. 'separator',
  419. 'spacesBeforeSeparator',
  420. 'spacesAfterSeparator',
  421. 'curPageLinkClassName',
  422. 'curPageSpanPre',
  423. 'curPageSpanPost',
  424. 'firstPagePre',
  425. 'firstPageText',
  426. 'firstPagePost',
  427. 'lastPagePre',
  428. 'lastPageText',
  429. 'lastPagePost',
  430. 'firstLinkTitle',
  431. 'nextLinkTitle',
  432. 'prevLinkTitle',
  433. 'lastLinkTitle',
  434. 'showAllText',
  435. 'itemData',
  436. 'clearIfVoid',
  437. 'useSessions',
  438. 'closeSession',
  439. 'sessionVar',
  440. 'pearErrorMode',
  441. 'extraVars',
  442. 'excludeVars',
  443. 'currentPage',
  444. );
  445. // }}}
  446. // {{{ build()
  447. /**
  448. * Generate or refresh the links and paged data after a call to setOptions()
  449. *
  450. * @return void
  451. * @access public
  452. */
  453. function build()
  454. {
  455. //reset
  456. $this->_pageData = array();
  457. $this->links = '';
  458. $this->linkTags = '';
  459. $this->linkTagsRaw = array();
  460. $this->_generatePageData();
  461. $this->_setFirstLastText();
  462. if ($this->_totalPages > (2 * $this->_delta + 1)) {
  463. $this->links .= $this->_printFirstPage();
  464. }
  465. $this->links .= $this->_getBackLink();
  466. $this->links .= $this->_getPageLinks();
  467. $this->links .= $this->_getNextLink();
  468. $this->linkTags .= $this->_getFirstLinkTag();
  469. $this->linkTags .= $this->_getPrevLinkTag();
  470. $this->linkTags .= $this->_getNextLinkTag();
  471. $this->linkTags .= $this->_getLastLinkTag();
  472. $this->linkTagsRaw['first'] = $this->_getFirstLinkTag(true);
  473. $this->linkTagsRaw['prev'] = $this->_getPrevLinkTag(true);
  474. $this->linkTagsRaw['next'] = $this->_getNextLinkTag(true);
  475. $this->linkTagsRaw['last'] = $this->_getLastLinkTag(true);
  476. if ($this->_totalPages > (2 * $this->_delta + 1)) {
  477. $this->links .= $this->_printLastPage();
  478. }
  479. }
  480. // }}}
  481. // {{{ getPageData()
  482. /**
  483. * Returns an array of current pages data
  484. *
  485. * @param integer $pageID Desired page ID (optional)
  486. *
  487. * @return array Page data
  488. * @access public
  489. */
  490. function getPageData($pageID = null)
  491. {
  492. $pageID = empty($pageID) ? $this->_currentPage : $pageID;
  493. if (!isset($this->_pageData)) {
  494. $this->_generatePageData();
  495. }
  496. if (!empty($this->_pageData[$pageID])) {
  497. return $this->_pageData[$pageID];
  498. }
  499. return array();
  500. }
  501. // }}}
  502. // {{{ getPageIdByOffset()
  503. /**
  504. * Returns pageID for given offset
  505. *
  506. * @param integer $index Offset to get pageID for
  507. *
  508. * @return integer PageID for given offset
  509. * @access public
  510. */
  511. function getPageIdByOffset($index)
  512. {
  513. $msg = 'function "getPageIdByOffset()" not implemented.';
  514. return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
  515. }
  516. // }}}
  517. // {{{ getOffsetByPageId()
  518. /**
  519. * Returns offsets for given pageID. Eg, if you
  520. * pass it pageID one and your perPage limit is 10
  521. * it will return (1, 10). PageID of 2 would
  522. * give you (11, 20).
  523. *
  524. * @param integer $pageID PageID to get offsets for
  525. *
  526. * @return array First and last offsets
  527. * @access public
  528. */
  529. function getOffsetByPageId($pageID = null)
  530. {
  531. $pageID = isset($pageID) ? $pageID : $this->_currentPage;
  532. if (!isset($this->_pageData)) {
  533. $this->_generatePageData();
  534. }
  535. if (isset($this->_pageData[$pageID]) || is_null($this->_itemData)) {
  536. return array(
  537. max(($this->_perPage * ($pageID - 1)) + 1, 1),
  538. min($this->_totalItems, $this->_perPage * $pageID)
  539. );
  540. }
  541. return array(0, 0);
  542. }
  543. // }}}
  544. // {{{ getPageRangeByPageId()
  545. /**
  546. * Given a PageId, it returns the limits of the range of pages displayed.
  547. *
  548. * @param integer $pageID PageID to get offsets for
  549. *
  550. * @return array First and last offsets
  551. * @access public
  552. */
  553. function getPageRangeByPageId($pageID = null)
  554. {
  555. $msg = 'function "getPageRangeByPageId()" not implemented.';
  556. return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
  557. }
  558. // }}}
  559. // {{{ getLinks()
  560. /**
  561. * Returns back/next/first/last and page links,
  562. * both as ordered and associative array.
  563. *
  564. * NB: in original PEAR::Pager this method accepted two parameters,
  565. * $back_html and $next_html. Now the only parameter accepted is
  566. * an integer ($pageID), since the html text for prev/next links can
  567. * be set in the factory. If a second parameter is provided, then
  568. * the method act as it previously did. This hack was done to mantain
  569. * backward compatibility only.
  570. *
  571. * @param integer $pageID Optional pageID. If specified, links for that
  572. * page are provided instead of current one.
  573. * [ADDED IN NEW PAGER VERSION]
  574. * @param string $next_html HTML to put inside the next link
  575. * [deprecated: use the factory instead]
  576. *
  577. * @return array back/next/first/last and page links
  578. * @access public
  579. */
  580. function getLinks($pageID=null, $next_html='')
  581. {
  582. $msg = 'function "getLinks()" not implemented.';
  583. return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
  584. }
  585. // }}}
  586. // {{{ getCurrentPageID()
  587. /**
  588. * Returns ID of current page
  589. *
  590. * @return integer ID of current page
  591. * @access public
  592. */
  593. function getCurrentPageID()
  594. {
  595. return $this->_currentPage;
  596. }
  597. // }}}
  598. // {{{ getNextPageID()
  599. /**
  600. * Returns next page ID. If current page is last page
  601. * this function returns FALSE
  602. *
  603. * @return mixed Next page ID or false
  604. * @access public
  605. */
  606. function getNextPageID()
  607. {
  608. return ($this->getCurrentPageID() == $this->numPages() ? false : $this->getCurrentPageID() + 1);
  609. }
  610. // }}}
  611. // {{{ getPreviousPageID()
  612. /**
  613. * Returns previous page ID. If current page is first page
  614. * this function returns FALSE
  615. *
  616. * @return mixed Previous page ID or false
  617. * @access public
  618. */
  619. function getPreviousPageID()
  620. {
  621. return $this->isFirstPage() ? false : $this->getCurrentPageID() - 1;
  622. }
  623. // }}}
  624. // {{{ numItems()
  625. /**
  626. * Returns number of items
  627. *
  628. * @return integer Number of items
  629. * @access public
  630. */
  631. function numItems()
  632. {
  633. return $this->_totalItems;
  634. }
  635. // }}}
  636. // {{{ numPages()
  637. /**
  638. * Returns number of pages
  639. *
  640. * @return integer Number of pages
  641. * @access public
  642. */
  643. function numPages()
  644. {
  645. return (int)$this->_totalPages;
  646. }
  647. // }}}
  648. // {{{ isFirstPage()
  649. /**
  650. * Returns whether current page is first page
  651. *
  652. * @return bool First page or not
  653. * @access public
  654. */
  655. function isFirstPage()
  656. {
  657. return ($this->_currentPage < 2);
  658. }
  659. // }}}
  660. // {{{ isLastPage()
  661. /**
  662. * Returns whether current page is last page
  663. *
  664. * @return bool Last page or not
  665. * @access public
  666. */
  667. function isLastPage()
  668. {
  669. return ($this->_currentPage == $this->_totalPages);
  670. }
  671. // }}}
  672. // {{{ isLastPageComplete()
  673. /**
  674. * Returns whether last page is complete
  675. *
  676. * @return bool Last age complete or not
  677. * @access public
  678. */
  679. function isLastPageComplete()
  680. {
  681. return !($this->_totalItems % $this->_perPage);
  682. }
  683. // }}}
  684. // {{{ _generatePageData()
  685. /**
  686. * Calculates all page data
  687. *
  688. * @return void
  689. * @access private
  690. */
  691. function _generatePageData()
  692. {
  693. // Been supplied an array of data?
  694. if (!is_null($this->_itemData)) {
  695. $this->_totalItems = count($this->_itemData);
  696. }
  697. $this->_totalPages = ceil((float)$this->_totalItems / (float)$this->_perPage);
  698. $i = 1;
  699. if (!empty($this->_itemData)) {
  700. foreach ($this->_itemData as $key => $value) {
  701. $this->_pageData[$i][$key] = $value;
  702. if (count($this->_pageData[$i]) >= $this->_perPage) {
  703. $i++;
  704. }
  705. }
  706. } else {
  707. $this->_pageData = array();
  708. }
  709. //prevent URL modification
  710. $this->_currentPage = min($this->_currentPage, $this->_totalPages);
  711. }
  712. // }}}
  713. // {{{ _renderLink()
  714. /**
  715. * Renders a link using the appropriate method
  716. *
  717. * @param string $altText Alternative text for this link (title property)
  718. * @param string $linkText Text contained by this link
  719. *
  720. * @return string The link in string form
  721. * @access private
  722. */
  723. function _renderLink($altText, $linkText)
  724. {
  725. if ($this->_httpMethod == 'GET') {
  726. if ($this->_append) {
  727. $href = '?' . $this->_http_build_query_wrapper($this->_linkData);
  728. } else {
  729. $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName);
  730. }
  731. $onclick = '';
  732. if (array_key_exists($this->_urlVar, $this->_linkData)) {
  733. $onclick = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_onclick);
  734. }
  735. return sprintf('<a href="%s"%s%s%s%s title="%s">%s</a>',
  736. htmlentities($this->_url . $href, ENT_COMPAT, 'UTF-8'),
  737. empty($this->_classString) ? '' : ' '.$this->_classString,
  738. empty($this->_attributes) ? '' : ' '.$this->_attributes,
  739. empty($this->_accesskey) ? '' : ' accesskey="'.$this->_linkData[$this->_urlVar].'"',
  740. empty($onclick) ? '' : ' onclick="'.$onclick.'"',
  741. $altText,
  742. $linkText
  743. );
  744. } elseif ($this->_httpMethod == 'POST') {
  745. $href = $this->_url;
  746. if (!empty($_GET)) {
  747. $href .= '?' . $this->_http_build_query_wrapper($_GET);
  748. }
  749. return sprintf("<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>",
  750. $this->_generateFormOnClick($href, $this->_linkData),
  751. empty($this->_classString) ? '' : ' '.$this->_classString,
  752. empty($this->_attributes) ? '' : ' '.$this->_attributes,
  753. empty($this->_accesskey) ? '' : ' accesskey=\''.$this->_linkData[$this->_urlVar].'\'',
  754. $altText,
  755. $linkText
  756. );
  757. }
  758. return '';
  759. }
  760. // }}}
  761. // {{{ _generateFormOnClick()
  762. /**
  763. * Mimics http_build_query() behavior in the way the data
  764. * in $data will appear when it makes it back to the server.
  765. * For example:
  766. * $arr = array('array' => array(array('hello', 'world'),
  767. * 'things' => array('stuff', 'junk'));
  768. * http_build_query($arr)
  769. * and _generateFormOnClick('foo.php', $arr)
  770. * will yield
  771. * $_REQUEST['array'][0][0] === 'hello'
  772. * $_REQUEST['array'][0][1] === 'world'
  773. * $_REQUEST['array']['things'][0] === 'stuff'
  774. * $_REQUEST['array']['things'][1] === 'junk'
  775. *
  776. * However, instead of generating a query string, it generates
  777. * Javascript to create and submit a form.
  778. *
  779. * @param string $formAction where the form should be submitted
  780. * @param array $data the associative array of names and values
  781. *
  782. * @return string A string of javascript that generates a form and submits it
  783. * @access private
  784. */
  785. function _generateFormOnClick($formAction, $data)
  786. {
  787. // Check we have an array to work with
  788. if (!is_array($data)) {
  789. trigger_error(
  790. '_generateForm() Parameter 1 expected to be Array or Object. Incorrect value given.',
  791. E_USER_WARNING
  792. );
  793. return false;
  794. }
  795. if (!empty($this->_formID)) {
  796. $str = 'var form = document.getElementById("'.$this->_formID.'"); var input = ""; ';
  797. } else {
  798. $str = 'var form = document.createElement("form"); var input = ""; ';
  799. }
  800. // We /shouldn't/ need to escape the URL ...
  801. $str .= sprintf('form.action = "%s"; ', htmlentities($formAction, ENT_COMPAT, 'UTF-8'));
  802. $str .= sprintf('form.method = "%s"; ', $this->_httpMethod);
  803. foreach ($data as $key => $val) {
  804. $str .= $this->_generateFormOnClickHelper($val, $key);
  805. }
  806. if (empty($this->_formID)) {
  807. $str .= 'document.getElementsByTagName("body")[0].appendChild(form);';
  808. }
  809. $str .= 'form.submit(); return false;';
  810. return $str;
  811. }
  812. // }}}
  813. // {{{ _generateFormOnClickHelper
  814. /**
  815. * This is used by _generateFormOnClick().
  816. * Recursively processes the arrays, objects, and literal values.
  817. *
  818. * @param mixed $data Data that should be rendered
  819. * @param string $prev The name so far
  820. *
  821. * @return string A string of Javascript that creates form inputs
  822. * representing the data
  823. * @access private
  824. */
  825. function _generateFormOnClickHelper($data, $prev = '')
  826. {
  827. $str = '';
  828. if (is_array($data) || is_object($data)) {
  829. // foreach key/visible member
  830. foreach ((array)$data as $key => $val) {
  831. // append [$key] to prev
  832. $tempKey = sprintf('%s[%s]', $prev, $key);
  833. $str .= $this->_generateFormOnClickHelper($val, $tempKey);
  834. }
  835. } else { // must be a literal value
  836. // escape newlines and carriage returns
  837. $search = array("\n", "\r");
  838. $replace = array('\n', '\n');
  839. $escapedData = str_replace($search, $replace, $data);
  840. // am I forgetting any dangerous whitespace?
  841. // would a regex be faster?
  842. // if it's already encoded, don't encode it again
  843. if (!$this->_isEncoded($escapedData)) {
  844. $escapedData = urlencode($escapedData);
  845. }
  846. $escapedData = htmlentities($escapedData, ENT_QUOTES, 'UTF-8');
  847. $str .= 'input = document.createElement("input"); ';
  848. $str .= 'input.type = "hidden"; ';
  849. $str .= sprintf('input.name = "%s"; ', $prev);
  850. $str .= sprintf('input.value = "%s"; ', $escapedData);
  851. $str .= 'form.appendChild(input); ';
  852. }
  853. return $str;
  854. }
  855. // }}}
  856. // {{{ _isRegexp()
  857. /**
  858. * Returns true if the string is a regexp pattern
  859. *
  860. * @param string $string the pattern to check
  861. *
  862. * @return boolean
  863. * @access private
  864. */
  865. function _isRegexp($string) {
  866. return preg_match('/^\/.*\/([Uims]+)?$/', $string);
  867. }
  868. // }}}
  869. // {{{ _getLinksData()
  870. /**
  871. * Returns the correct link for the back/pages/next links
  872. *
  873. * @return array Data
  874. * @access private
  875. */
  876. function _getLinksData()
  877. {
  878. $qs = array();
  879. if ($this->_importQuery) {
  880. if ($this->_httpMethod == 'POST') {
  881. $qs = $_POST;
  882. } elseif ($this->_httpMethod == 'GET') {
  883. $qs = $_GET;
  884. }
  885. }
  886. foreach ($this->_excludeVars as $exclude) {
  887. $use_preg = $this->_isRegexp($exclude);
  888. foreach (array_keys($qs) as $qs_item) {
  889. if ($use_preg) {
  890. if (preg_match($exclude, $qs_item, $matches)) {
  891. foreach ($matches as $m) {
  892. unset($qs[$m]);
  893. }
  894. }
  895. } elseif ($qs_item == $exclude) {
  896. unset($qs[$qs_item]);
  897. break;
  898. }
  899. }
  900. }
  901. if (count($this->_extraVars)) {
  902. $this->_recursive_urldecode($this->_extraVars);
  903. $qs = array_merge($qs, $this->_extraVars);
  904. }
  905. if (count($qs)
  906. && function_exists('get_magic_quotes_gpc')
  907. && -1 == version_compare(PHP_VERSION, '5.2.99')
  908. && get_magic_quotes_gpc()
  909. ) {
  910. $this->_recursive_stripslashes($qs);
  911. }
  912. return $qs;
  913. }
  914. // }}}
  915. // {{{ _recursive_stripslashes()
  916. /**
  917. * Helper method
  918. *
  919. * @param string|array &$var variable to clean
  920. *
  921. * @return void
  922. * @access private
  923. */
  924. function _recursive_stripslashes(&$var)
  925. {
  926. if (is_array($var)) {
  927. foreach (array_keys($var) as $k) {
  928. $this->_recursive_stripslashes($var[$k]);
  929. }
  930. } else {
  931. $var = stripslashes($var);
  932. }
  933. }
  934. // }}}
  935. // {{{ _recursive_urldecode()
  936. /**
  937. * Helper method
  938. *
  939. * @param string|array &$var variable to decode
  940. *
  941. * @return void
  942. * @access private
  943. */
  944. function _recursive_urldecode(&$var)
  945. {
  946. if (is_array($var)) {
  947. foreach (array_keys($var) as $k) {
  948. $this->_recursive_urldecode($var[$k]);
  949. }
  950. } else {
  951. $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES));
  952. $var = strtr($var, $trans_tbl);
  953. }
  954. }
  955. // }}}
  956. // {{{ _getBackLink()
  957. /**
  958. * Returns back link
  959. *
  960. * @param string $url URL to use in the link [deprecated: use the factory instead]
  961. * @param string $link HTML to use as the link [deprecated: use the factory instead]
  962. *
  963. * @return string The link
  964. * @access private
  965. */
  966. function _getBackLink($url='', $link='')
  967. {
  968. //legacy settings... the preferred way to set an option
  969. //now is passing it to the factory
  970. if (!empty($url)) {
  971. $this->_path = $url;
  972. }
  973. if (!empty($link)) {
  974. $this->_prevImg = $link;
  975. }
  976. $back = '';
  977. if ($this->_currentPage > 1) {
  978. $this->_linkData[$this->_urlVar] = $this->getPreviousPageID();
  979. $back = $this->_renderLink($this->_altPrev, $this->_prevImg)
  980. . $this->_spacesBefore . $this->_spacesAfter;
  981. } else if ($this->_prevImgEmpty !== null && $this->_totalPages > 1) {
  982. $back = $this->_prevImgEmpty
  983. . $this->_spacesBefore . $this->_spacesAfter;
  984. }
  985. return $back;
  986. }
  987. // }}}
  988. // {{{ _getPageLinks()
  989. /**
  990. * Returns pages link
  991. *
  992. * @param string $url URL to use in the link [deprecated: use the factory instead]
  993. *
  994. * @return string Links
  995. * @access private
  996. */
  997. function _getPageLinks($url='')
  998. {
  999. $msg = 'function "_getPageLinks()" not implemented.';
  1000. return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
  1001. }
  1002. // }}}
  1003. // {{{ _getNextLink()
  1004. /**
  1005. * Returns next link
  1006. *
  1007. * @param string $url URL to use in the link [deprecated: use the factory instead]
  1008. * @param string $link HTML to use as the link [deprecated: use the factory instead]
  1009. *
  1010. * @return string The link
  1011. * @access private
  1012. */
  1013. function _getNextLink($url='', $link='')
  1014. {
  1015. //legacy settings... the preferred way to set an option
  1016. //now is passing it to the factory
  1017. if (!empty($url)) {
  1018. $this->_path = $url;
  1019. }
  1020. if (!empty($link)) {
  1021. $this->_nextImg = $link;
  1022. }
  1023. $next = '';
  1024. if ($this->_currentPage < $this->_totalPages) {
  1025. $this->_linkData[$this->_urlVar] = $this->getNextPageID();
  1026. $next = $this->_spacesAfter
  1027. . $this->_renderLink($this->_altNext, $this->_nextImg)
  1028. . $this->_spacesBefore . $this->_spacesAfter;
  1029. } else if ($this->_nextImgEmpty !== null && $this->_totalPages > 1) {
  1030. $next = $this->_spacesAfter
  1031. . $this->_nextImgEmpty
  1032. . $this->_spacesBefore . $this->_spacesAfter;
  1033. }
  1034. return $next;
  1035. }
  1036. // }}}
  1037. // {{{ _getFirstLinkTag()
  1038. /**
  1039. * Returns first link tag
  1040. *
  1041. * @param bool $raw should tag returned as array
  1042. *
  1043. * @return mixed string with html link tag or separated as array
  1044. * @access private
  1045. */
  1046. function _getFirstLinkTag($raw = false)
  1047. {
  1048. if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) {
  1049. return $raw ? array() : '';
  1050. }
  1051. if ($raw) {
  1052. return array(
  1053. 'url' => $this->_getLinkTagUrl(1),
  1054. 'title' => $this->_firstLinkTitle
  1055. );
  1056. }
  1057. return sprintf('<link rel="first" href="%s" title="%s" />'."\n",
  1058. $this->_getLinkTagUrl(1),
  1059. $this->_firstLinkTitle
  1060. );
  1061. }
  1062. // }}}
  1063. // {{{ _getPrevLinkTag()
  1064. /**
  1065. * Returns previous link tag
  1066. *
  1067. * @param bool $raw should tag returned as array
  1068. *
  1069. * @return mixed string with html link tag or separated as array
  1070. * @access private
  1071. */
  1072. function _getPrevLinkTag($raw = false)
  1073. {
  1074. if ($this->isFirstPage() || ($this->_httpMethod != 'GET')) {
  1075. return $raw ? array() : '';
  1076. }
  1077. if ($raw) {
  1078. return array(
  1079. 'url' => $this->_getLinkTagUrl($this->getPreviousPageID()),
  1080. 'title' => $this->_prevLinkTitle
  1081. );
  1082. }
  1083. return sprintf('<link rel="previous" href="%s" title="%s" />'."\n",
  1084. $this->_getLinkTagUrl($this->getPreviousPageID()),
  1085. $this->_prevLinkTitle
  1086. );
  1087. }
  1088. // }}}
  1089. // {{{ _getNextLinkTag()
  1090. /**
  1091. * Returns next link tag
  1092. *
  1093. * @param bool $raw should tag returned as array
  1094. *
  1095. * @return mixed string with html link tag or separated as array
  1096. * @access private
  1097. */
  1098. function _getNextLinkTag($raw = false)
  1099. {
  1100. if ($this->isLastPage() || ($this->_httpMethod != 'GET')) {
  1101. return $raw ? array() : '';
  1102. }
  1103. if ($raw) {
  1104. return array(
  1105. 'url' => $this->_getLinkTagUrl($this->getNextPageID()),
  1106. 'title' => $this->_nextLinkTitle
  1107. );
  1108. }
  1109. return sprintf('<link rel="next" href="%s" title="%s" />'."\n",
  1110. $this->_getLinkTagUrl($this->getNextPageID()),
  1111. $this->_nextLinkTitle
  1112. );
  1113. }
  1114. // }}}
  1115. // {{{ _getLastLinkTag()
  1116. /**
  1117. * Returns last link tag
  1118. *
  1119. * @param bool $raw should tag returned as array
  1120. *
  1121. * @return mixed string with html link tag or separated as array
  1122. * @access private
  1123. */
  1124. function _getLastLinkTag($raw = false)
  1125. {
  1126. if ($this->isLastPage() || ($this->_httpMethod != 'GET')) {
  1127. return $raw ? array() : '';
  1128. }
  1129. if ($raw) {
  1130. return array(
  1131. 'url' => $this->_getLinkTagUrl($this->_totalPages),
  1132. 'title' => $this->_lastLinkTitle
  1133. );
  1134. }
  1135. return sprintf('<link rel="last" href="%s" title="%s" />'."\n",
  1136. $this->_getLinkTagUrl($this->_totalPages),
  1137. $this->_lastLinkTitle
  1138. );
  1139. }
  1140. // }}}
  1141. // {{{ _getLinkTagUrl()
  1142. /**
  1143. * Helper method
  1144. *
  1145. * @param integer $pageID page ID
  1146. *
  1147. * @return string the link tag url
  1148. * @access private
  1149. */
  1150. function _getLinkTagUrl($pageID)
  1151. {
  1152. $this->_linkData[$this->_urlVar] = $pageID;
  1153. if ($this->_append) {
  1154. $href = '?' . $this->_http_build_query_wrapper($this->_linkData);
  1155. } else {
  1156. $href = str_replace('%d', $this->_linkData[$this->_urlVar], $this->_fileName);
  1157. }
  1158. return htmlentities($this->_url . $href, ENT_COMPAT, 'UTF-8');
  1159. }
  1160. // }}}
  1161. // {{{ getPerPageSelectBox()
  1162. /**
  1163. * Returns a string with a XHTML SELECT menu,
  1164. * useful for letting the user choose how many items per page should be
  1165. * displayed. If parameter useSessions is TRUE, this value is stored in
  1166. * a session var. The string isn't echoed right now so you can use it
  1167. * with template engines.
  1168. *
  1169. * @param integer $start starting value for the select menu
  1170. * @param integer $end ending value for the select menu
  1171. * @param integer $step step between values in the select menu
  1172. * @param boolean $showAllData If true, perPage is set equal to totalItems.
  1173. * @param array $extraParams (or string $optionText for BC reasons)
  1174. * - 'optionText': text to show in each option.
  1175. * Use '%d' where you want to see the number of pages selected.
  1176. * - 'attributes': (html attributes) Tag attributes or
  1177. * HTML attributes (id="foo" pairs), will be inserted in the
  1178. * <select> tag
  1179. *
  1180. * @return string xhtml select box
  1181. * @access public
  1182. */
  1183. function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
  1184. {
  1185. include_once 'Pager/HtmlWidgets.php';
  1186. $widget = new Pager_HtmlWidgets($this);
  1187. return $widget->getPerPageSelectBox($start, $end, $step, $showAllData, $extraParams);
  1188. }
  1189. // }}}
  1190. // {{{ getPageSelectBox()
  1191. /**
  1192. * Returns a string with a XHTML SELECT menu with the page numbers,
  1193. * useful as an alternative to the links
  1194. *
  1195. * @param array $params - 'optionText': text to show in each option.
  1196. * Use '%d' where you want to see the number
  1197. * of pages selected.
  1198. * - 'autoSubmit': if TRUE, add some js code
  1199. * to submit the form on the onChange event
  1200. * @param string $extraAttributes (html attributes) Tag attributes or
  1201. * HTML attributes (id="foo" pairs), will be
  1202. * inserted in the <select> tag
  1203. *
  1204. * @return string xhtml select box
  1205. * @access public
  1206. */
  1207. function getPageSelectBox($params = array(), $extraAttributes = '')
  1208. {
  1209. include_once 'Pager/HtmlWidgets.php';
  1210. $widget = new Pager_HtmlWidgets($this);
  1211. return $widget->getPageSelectBox($params, $extraAttributes);
  1212. }
  1213. // }}}
  1214. // {{{ _printFirstPage()
  1215. /**
  1216. * Print [1]
  1217. *
  1218. * @return string String with link to 1st page,
  1219. * or empty string if this is the 1st page.
  1220. * @access private
  1221. */
  1222. function _printFirstPage()
  1223. {
  1224. if ($this->isFirstPage()) {
  1225. return '';
  1226. }
  1227. $this->_linkData[$this->_urlVar] = 1;
  1228. return $this->_renderLink(
  1229. str_replace('%d', 1, $this->_altFirst),
  1230. $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost
  1231. ) . $this->_spacesBefore . $this->_spacesAfter;
  1232. }
  1233. // }}}
  1234. // {{{ _printLastPage()
  1235. /**
  1236. * Print [numPages()]
  1237. *
  1238. * @return string String with link to last page,
  1239. * or empty string if this is the 1st page.
  1240. * @access private
  1241. */
  1242. function _printLastPage()
  1243. {
  1244. if ($this->isLastPage()) {
  1245. return '';
  1246. }
  1247. $this->_linkData[$this->_urlVar] = $this->_totalPages;
  1248. return $this->_renderLink(
  1249. str_replace('%d', $this->_totalPages, $this->_altLast),
  1250. $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost
  1251. );
  1252. }
  1253. // }}}
  1254. // {{{ _setFirstLastText()
  1255. /**
  1256. * sets the private _firstPageText, _lastPageText variables
  1257. * based on whether they were set in the options
  1258. *
  1259. * @return void
  1260. * @access private
  1261. */
  1262. function _setFirstLastText()
  1263. {
  1264. if ($this->_firstPageText == '') {
  1265. $this->_firstPageText = '1';
  1266. }
  1267. if ($this->_lastPageText == '') {
  1268. $this->_lastPageText = $this->_totalPages;
  1269. }
  1270. }
  1271. // }}}
  1272. // {{{ _http_build_query_wrapper()
  1273. /**
  1274. * This is a slightly modified version of the http_build_query() function;
  1275. * it heavily borrows code from PHP_Compat's http_build_query().
  1276. * The main change is the usage of htmlentities instead of urlencode,
  1277. * since it's too aggressive
  1278. *
  1279. * @param array $data array of querystring values
  1280. *
  1281. * @return string
  1282. * @access private
  1283. */
  1284. function _http_build_query_wrapper($data)
  1285. {
  1286. $data = (array)$data;
  1287. if (empty($data)) {
  1288. return '';
  1289. }
  1290. $separator = ini_get('arg_separator.output');
  1291. if ($separator == '&amp;') {
  1292. $separator = '&'; //the string is escaped by htmlentities anyway...
  1293. }
  1294. $tmp = array ();
  1295. foreach ($data as $key => $val) {
  1296. if (is_scalar($val)) {
  1297. //array_push($tmp, $key.'='.$val);
  1298. $val = urlencode($val);
  1299. array_push($tmp, $key .'='. str_replace('%2F', '/', $val));
  1300. continue;
  1301. }
  1302. // If the value is an array, recursively parse it
  1303. if (is_array($val)) {
  1304. array_push($tmp, $this->__http_build_query($val, urlencode($key)));
  1305. continue;
  1306. }
  1307. }
  1308. return implode($separator, $tmp);
  1309. }
  1310. // }}}
  1311. // {{{ __http_build_query()
  1312. /**
  1313. * Helper function
  1314. *
  1315. * @param array $array array of querystring values
  1316. * @param string $name key
  1317. *
  1318. * @return string
  1319. * @access private
  1320. */
  1321. function __http_build_query($array, $name)
  1322. {
  1323. $tmp = array ();
  1324. $separator = ini_get('arg_separator.output');
  1325. if ($separator == '&amp;') {
  1326. $separator = '&'; //the string is escaped by htmlentities anyway...
  1327. }
  1328. foreach ($array as $key => $value) {
  1329. if (is_array($value)) {
  1330. //array_push($tmp, $this->__http_build_query($value, sprintf('%s[%s]', $name, $key)));
  1331. array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D'));
  1332. } elseif (is_scalar($value)) {
  1333. //array_push($tmp, sprintf('%s[%s]=%s', $name, htmlentities($key), htmlentities($value)));
  1334. array_push($tmp, $name.'%5B'.urlencode($key).'%5D='.urlencode($value));
  1335. } elseif (is_object($value)) {
  1336. //array_push($tmp, $this->__http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key)));
  1337. array_push($tmp, $this->__http_build_query(get_object_vars($value), $name.'%5B'.$key.'%5D'));
  1338. }
  1339. }
  1340. return implode($separator, $tmp);
  1341. }
  1342. // }}}
  1343. // {{{ _isEncoded()
  1344. /**
  1345. * Helper function
  1346. * Check if a string is an encoded multibyte string
  1347. *
  1348. * @param string $string string to check
  1349. *
  1350. * @return boolean
  1351. * @access private
  1352. */
  1353. function _isEncoded($string)
  1354. {
  1355. $hexchar = '&#[\dA-Fx]{2,};';
  1356. return preg_match("/^(\s|($hexchar))*$/Uims", $string) ? true : false;
  1357. }
  1358. // }}}
  1359. // {{{ raiseError()
  1360. /**
  1361. * conditionally includes PEAR base class and raise an error
  1362. *
  1363. * @param string $msg Error message
  1364. * @param integer $code Error code
  1365. *
  1366. * @return PEAR_Error
  1367. * @access private
  1368. */
  1369. function raiseError($msg, $code)
  1370. {
  1371. include_once 'PEAR.php';
  1372. if (empty($this->_pearErrorMode)) {
  1373. $this->_pearErrorMode = PEAR_ERROR_RETURN;
  1374. }
  1375. return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
  1376. }
  1377. // }}}
  1378. // {{{ setOptions()
  1379. /**
  1380. * Set and sanitize options
  1381. *
  1382. * @param mixed $options An associative array of option names and their values
  1383. *
  1384. * @return integer error code (PAGER_OK on success)
  1385. * @access public
  1386. */
  1387. function setOptions($options)
  1388. {
  1389. foreach ($options as $key => $value) {
  1390. if (in_array($key, $this->_allowed_options) && (!is_null($value))) {
  1391. $this->{'_' . $key} = $value;
  1392. }
  1393. }
  1394. //autodetect http method
  1395. if (!isset($options['httpMethod'])
  1396. && !isset($_GET[$this->_urlVar])
  1397. && isset($_POST[$this->_urlVar])
  1398. ) {
  1399. $this->_httpMethod = 'POST';
  1400. } else {
  1401. $this->_httpMethod = strtoupper($this->_httpMethod);
  1402. }
  1403. if (substr($this->_path, -1, 1) == '/') {
  1404. $this->_fileName = ltrim($this->_fileName, '/'); //strip leading slash
  1405. }
  1406. if ($this->_append) {
  1407. if ($this->_fixFileName) {
  1408. $this->_fileName = PAGER_CURRENT_FILENAME; //avoid possible user error;
  1409. }
  1410. $this->_url = $this->_path.(empty($this->_path) ? '' : '/').$this->_fileName;
  1411. } else {
  1412. $this->_url = $this->_path;
  1413. if (0 != strncasecmp($this->_fileName, 'javascript', 10)) {
  1414. $this->_url .= (empty($this->_path) ? '' : '/');
  1415. }
  1416. if (false === strpos($this->_fileName, '%d')) {
  1417. trigger_error($this->errorMessage(ERROR_PAGER_INVALID_USAGE), E_USER_WARNING);
  1418. }
  1419. }
  1420. if (substr($this->_url, 0, 2) == '//') {
  1421. $this->_url = substr($this->_url, 1);
  1422. }
  1423. if (false === strpos($this->_altPage, '%d')) {
  1424. //by default, append page number at the end
  1425. $this->_altPage .= ' %d';
  1426. }
  1427. $this->_classString = '';
  1428. if (strlen($this->_linkClass)) {
  1429. $this->_classString = 'class="'.$this->_linkClass.'"';
  1430. }
  1431. if (strlen($this->_curPageLinkClassName)) {
  1432. $this->_curPageSpanPre .= '<span class="'.$this->_curPageLinkClassName.'">';
  1433. $this->_curPageSpanPost = '</span>' . $this->_curPageSpanPost;
  1434. }
  1435. $this->_perPage = max($this->_perPage, 1); //avoid possible user errors
  1436. if ($this->_useSessions && !isset($_SESSION)) {
  1437. session_start();
  1438. }
  1439. if (!empty($_REQUEST[$this->_sessionVar])) {
  1440. $this->_perPage = max(1, (int)$_REQUEST[$this->_sessionVar]);
  1441. if ($this->_useSessions) {
  1442. $_SESSION[$this->_sessionVar] = $this->_perPage;
  1443. }
  1444. }
  1445. if (!empty($_SESSION[$this->_sessionVar]) && $this->_useSessions) {
  1446. $this->_perPage = $_SESSION[$this->_sessionVar];
  1447. }
  1448. if ($this->_closeSession) {
  1449. session_write_close();
  1450. }
  1451. $this->_spacesBefore = str_repeat('&nbsp;', $this->_spacesBeforeSeparator);
  1452. $this->_spacesAfter = str_repeat('&nbsp;', $this->_spacesAfterSeparator);
  1453. if (isset($_REQUEST[$this->_urlVar]) && empty($options['currentPage'])) {
  1454. $this->_currentPage = (int)$_REQUEST[$this->_urlVar];
  1455. }
  1456. $this->_currentPage = max($this->_currentPage, 1);
  1457. $this->_linkData = $this->_getLinksData();
  1458. return PAGER_OK;
  1459. }
  1460. // }}}
  1461. // {{{ getOption()
  1462. /**
  1463. * Return the current value of a given option
  1464. *
  1465. * @param string $name option name
  1466. *
  1467. * @return mixed option value
  1468. * @access public
  1469. */
  1470. function getOption($name)
  1471. {
  1472. if (!in_array($name, $this->_allowed_options)) {
  1473. $msg = 'invalid option: '.$name;
  1474. return $this->raiseError($msg, ERROR_PAGER_INVALID);
  1475. }
  1476. return $this->{'_' . $name};
  1477. }
  1478. // }}}
  1479. // {{{ getOptions()
  1480. /**
  1481. * Return an array with all the current pager options
  1482. *
  1483. * @return array list of all the pager options
  1484. * @access public
  1485. */
  1486. function getOptions()
  1487. {
  1488. $options = array();
  1489. foreach ($this->_allowed_options as $option) {
  1490. $options[$option] = $this->{'_' . $option};
  1491. }
  1492. return $options;
  1493. }
  1494. // }}}

Large files files are truncated, but you can click here to view the full file