12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727 |
- <?php
- if (substr(api_get_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('\\', '/', api_get_self()));
- } else {
- define('PAGER_CURRENT_FILENAME', preg_replace('/(.*)\?.*/', '\\1', basename(api_get_self())));
- define('PAGER_CURRENT_PATHNAME', str_replace('\\', '/', dirname(api_get_self())));
- }
- 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);
- class Pager_Common
- {
-
-
- var $_totalItems;
-
- var $_perPage = 10;
-
- var $_delta = 10;
-
- var $_currentPage = 1;
-
- var $_totalPages = 1;
-
- var $_linkClass = '';
-
- var $_classString = '';
-
- var $_path = PAGER_CURRENT_PATHNAME;
-
- var $_fileName = PAGER_CURRENT_FILENAME;
-
- var $_fixFileName = true;
-
- var $_append = true;
-
- var $_httpMethod = 'GET';
-
- var $_formID = '';
-
- var $_importQuery = true;
-
- var $_urlVar = 'pageID';
-
- var $_linkData = array();
-
- var $_extraVars = array();
-
- var $_excludeVars = array();
-
- var $_expanded = true;
-
- var $_accesskey = false;
-
- var $_attributes = '';
-
- var $_onclick = '';
-
- var $_altFirst = 'first page';
-
- var $_altPrev = 'previous page';
-
- var $_altNext = 'next page';
-
- var $_altLast = 'last page';
-
- var $_altPage = 'page';
-
- var $_prevImg = '<< Back';
-
- var $_prevImgEmpty = null;
-
- var $_nextImg = 'Next >>';
-
- var $_nextImgEmpty = null;
-
- var $_separator = '';
-
- var $_spacesBeforeSeparator = 0;
-
- var $_spacesAfterSeparator = 1;
-
- var $_curPageLinkClassName = '';
-
- var $_curPageSpanPre = '';
-
- var $_curPageSpanPost = '';
-
- var $_firstPagePre = '[';
-
- var $_firstPageText = '';
-
- var $_firstPagePost = ']';
-
- var $_lastPagePre = '[';
-
- var $_lastPageText = '';
-
- var $_lastPagePost = ']';
-
- var $_spacesBefore = '';
-
- var $_spacesAfter = '';
-
- var $_firstLinkTitle = 'first page';
-
- var $_nextLinkTitle = 'next page';
-
- var $_prevLinkTitle = 'previous page';
-
- var $_lastLinkTitle = 'last page';
-
- var $_showAllText = '';
-
- var $_itemData = null;
-
- var $_clearIfVoid = true;
-
- var $_useSessions = false;
-
- var $_closeSession = false;
-
- var $_sessionVar = 'setPerPage';
-
- var $_pearErrorMode = null;
-
-
-
- var $links = '';
-
- var $linkTags = '';
-
- var $linkTagsRaw = array();
-
- var $range = array();
-
- 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',
- );
-
-
-
- function build()
- {
-
- $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();
- }
- }
-
-
-
- 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();
- }
-
-
-
- function getPageIdByOffset($index)
- {
- $msg = 'function "getPageIdByOffset()" not implemented.';
- return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
- }
-
-
-
- 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);
- }
-
-
-
- function getPageRangeByPageId($pageID = null)
- {
- $msg = 'function "getPageRangeByPageId()" not implemented.';
- return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
- }
-
-
-
- function getLinks($pageID=null, $next_html='')
- {
- $msg = 'function "getLinks()" not implemented.';
- return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
- }
-
-
-
- function getCurrentPageID()
- {
- return $this->_currentPage;
- }
-
-
-
- function getNextPageID()
- {
- return ($this->getCurrentPageID() == $this->numPages() ? false : $this->getCurrentPageID() + 1);
- }
-
-
-
- function getPreviousPageID()
- {
- return $this->isFirstPage() ? false : $this->getCurrentPageID() - 1;
- }
-
-
-
- function numItems()
- {
- return $this->_totalItems;
- }
-
-
-
- function numPages()
- {
- return (int)$this->_totalPages;
- }
-
-
-
- function isFirstPage()
- {
- return ($this->_currentPage < 2);
- }
-
-
-
- function isLastPage()
- {
- return ($this->_currentPage == $this->_totalPages);
- }
-
-
-
- function isLastPageComplete()
- {
- return !($this->_totalItems % $this->_perPage);
- }
-
-
-
- function _generatePageData()
- {
-
- 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();
- }
-
- $this->_currentPage = min($this->_currentPage, $this->_totalPages);
- }
-
-
-
- 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('<a href="%s"%s%s%s%s title="%s">%s</a>',
-
-
- api_htmlentities($this->_url . $href),
-
- 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("<a href='javascript:void(0)' onclick='%s'%s%s%s title='%s'>%s</a>",
- $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 '';
- }
-
-
-
- function _generateFormOnClick($formAction, $data)
- {
-
- 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 = ""; ';
- }
-
-
-
- $str .= sprintf('form.action = "%s"; ', api_htmlentities($formAction));
-
- $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;
- }
-
-
-
- function _generateFormOnClickHelper($data, $prev = '')
- {
- $str = '';
- if (is_array($data) || is_object($data)) {
-
- foreach ((array)$data as $key => $val) {
-
- $tempKey = sprintf('%s[%s]', $prev, $key);
- $str .= $this->_generateFormOnClickHelper($val, $tempKey);
- }
- } else {
-
- $search = array("\n", "\r");
- $replace = array('\n', '\n');
- $escapedData = str_replace($search, $replace, $data);
-
-
-
- if (!$this->_isEncoded($escapedData)) {
- $escapedData = urlencode($escapedData);
- }
-
-
- $escapedData = api_htmlentities($escapedData, ENT_QUOTES);
-
- $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;
- }
-
-
-
- function _isRegexp($string) {
- return preg_match('/^\/.*\/([Uims]+)?$/', $string);
- }
-
-
-
- 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;
- }
-
-
-
- function _recursive_stripslashes(&$var)
- {
- if (is_array($var)) {
- foreach (array_keys($var) as $k) {
- $this->_recursive_stripslashes($var[$k]);
- }
- } else {
- $var = stripslashes($var);
- }
- }
-
-
-
- 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);
- }
- }
-
-
-
- function _getBackLink($url='', $link='')
- {
-
-
- 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;
- }
-
-
-
- function _getPageLinks($url='')
- {
- $msg = 'function "_getPageLinks()" not implemented.';
- return $this->raiseError($msg, ERROR_PAGER_NOT_IMPLEMENTED);
- }
-
-
-
- function _getNextLink($url='', $link='')
- {
-
-
- 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;
- }
-
-
-
- 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('<link rel="first" href="%s" title="%s" />'."\n",
- $this->_getLinkTagUrl(1),
- $this->_firstLinkTitle
- );
- }
-
-
-
- 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('<link rel="previous" href="%s" title="%s" />'."\n",
- $this->_getLinkTagUrl($this->getPreviousPageID()),
- $this->_prevLinkTitle
- );
- }
-
-
-
- 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('<link rel="next" href="%s" title="%s" />'."\n",
- $this->_getLinkTagUrl($this->getNextPageID()),
- $this->_nextLinkTitle
- );
- }
-
-
-
- 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('<link rel="last" href="%s" title="%s" />'."\n",
- $this->_getLinkTagUrl($this->_totalPages),
- $this->_lastLinkTitle
- );
- }
-
-
-
- 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 api_htmlentities($this->_url . $href);
-
- }
-
-
-
- function getPerPageSelectBox($start=5, $end=30, $step=5, $showAllData=false, $extraParams=array())
- {
- include_once 'Pager/HtmlWidgets.php';
- $widget = new Pager_HtmlWidgets($this);
- return $widget->getPerPageSelectBox($start, $end, $step, $showAllData, $extraParams);
- }
-
-
-
- function getPageSelectBox($params = array(), $extraAttributes = '')
- {
- include_once 'Pager/HtmlWidgets.php';
- $widget = new Pager_HtmlWidgets($this);
- return $widget->getPageSelectBox($params, $extraAttributes);
- }
-
-
-
- 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;
- }
-
-
-
- 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
- );
- }
-
-
-
- function _setFirstLastText()
- {
- if ($this->_firstPageText == '') {
- $this->_firstPageText = '1';
- }
- if ($this->_lastPageText == '') {
- $this->_lastPageText = $this->_totalPages;
- }
- }
-
-
-
- function _http_build_query_wrapper($data)
- {
- $data = (array)$data;
- if (empty($data)) {
- return '';
- }
- $separator = ini_get('arg_separator.output');
- if ($separator == '&') {
- $separator = '&';
- }
- $tmp = array ();
- foreach ($data as $key => $val) {
- if (is_scalar($val)) {
-
- $val = urlencode($val);
- array_push($tmp, $key .'='. str_replace('%2F', '/', $val));
- continue;
- }
-
- if (is_array($val)) {
- array_push($tmp, $this->__http_build_query($val, urlencode($key)));
- continue;
- }
- }
- return implode($separator, $tmp);
- }
-
-
-
- function __http_build_query($array, $name)
- {
- $tmp = array ();
- $separator = ini_get('arg_separator.output');
- if ($separator == '&') {
- $separator = '&';
- }
- foreach ($array as $key => $value) {
- if (is_array($value)) {
-
- array_push($tmp, $this->__http_build_query($value, $name.'%5B'.$key.'%5D'));
- } elseif (is_scalar($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), $name.'%5B'.$key.'%5D'));
- }
- }
- return implode($separator, $tmp);
- }
-
-
-
- function _isEncoded($string)
- {
- $hexchar = '&#[\dA-Fx]{2,};';
- return preg_match("/^(\s|($hexchar))*$/Uims", $string) ? true : false;
- }
-
-
-
- function raiseError($msg, $code)
- {
- include_once 'PEAR.php';
- if (empty($this->_pearErrorMode)) {
- $this->_pearErrorMode = PEAR_ERROR_RETURN;
- }
- return PEAR::raiseError($msg, $code, $this->_pearErrorMode);
- }
-
-
-
- function setOptions($options)
- {
- foreach ($options as $key => $value) {
- if (in_array($key, $this->_allowed_options) && (!is_null($value))) {
- $this->{'_' . $key} = $value;
- }
- }
-
- 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, '/');
- }
- if ($this->_append) {
- if ($this->_fixFileName) {
- $this->_fileName = PAGER_CURRENT_FILENAME;
- }
- $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')) {
-
- $this->_altPage .= ' %d';
- }
- $this->_classString = '';
- if (strlen($this->_linkClass)) {
- $this->_classString = 'class="'.$this->_linkClass.'"';
- }
- if (strlen($this->_curPageLinkClassName)) {
- $this->_curPageSpanPre .= '<span class="'.$this->_curPageLinkClassName.'">';
- $this->_curPageSpanPost = '</span>' . $this->_curPageSpanPost;
- }
- $this->_perPage = max($this->_perPage, 1);
- 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(' ', intval($this->_spacesBeforeSeparator));
- $this->_spacesAfter = str_repeat(' ', intval($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;
- }
-
-
-
- function getOption($name)
- {
- if (!in_array($name, $this->_allowed_options)) {
- $msg = 'invalid option: '.$name;
- return $this->raiseError($msg, ERROR_PAGER_INVALID);
- }
- return $this->{'_' . $name};
- }
-
-
-
- function getOptions()
- {
- $options = array();
- foreach ($this->_allowed_options as $option) {
- $options[$option] = $this->{'_' . $option};
- }
- return $options;
- }
-
-
-
- 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]);
- }
-
- }
- ?>
|