1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729 |
- <?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)
- {
- throw new Exception($msg);
-
- }
-
-
-
- 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]);
- }
-
- }
- ?>
|