/** * Render item pagination * * @param array $config Configuration array * @return string Html * @see http://developer.yahoo.com/ypatterns/navigation/pagination/ */ public function pagination($config = array()) { $config = new KConfig($config); $config->append(array('total' => 0, 'display' => 5, 'ajax' => false, 'name' => $this->name)); $this->_ajax = (bool) $config->ajax; if (is_string($config->ajax)) { $this->_ajax_layout = $config->ajax; } KFactory::get('admin::com.ninja.helper.default')->css('/pagination.css'); // Paginator object $paginator = KFactory::tmp('lib.koowa.model.paginator')->setData(array('total' => $config->total, 'offset' => $config->offset, 'limit' => $config->limit, 'dispay' => $config->display)); $view = $config->name; $items = (int) $config->total === 1 ? KInflector::singularize($view) : $view; if ($config->total <= 10) { return '<div class="pagination"><div class="limit">' . sprintf(JText::_('Listing %s ' . KInflector::humanize($items)), $config->total) . '</div></div>'; } // Get the paginator data $list = $paginator->getList(); $limitlist = $config->total > 10 ? $this->limit($config->toArray()) : $config->total; $html = '<div class="pagination">'; $html .= '<div class="limit">' . sprintf(JText::_('Listing %s ' . KInflector::humanize($items)), $limitlist) . '</div>'; $html .= $this->pages($list); $html .= '<div class="count"> ' . JText::_('Pages') . ' ' . $paginator->current . ' ' . JText::_('of') . ' ' . $paginator->count . '</div>'; $html .= '</div>'; if ($this->_ajax) { jimport('joomla.environment.browser'); $uagent = JBrowser::getInstance()->getAgentString(); $windoze = strpos($uagent, 'Windows') ? true : false; $url = clone KRequest::url(); $url->fragment = 'offset=@{offset}'; $formid = KFactory::tmp('admin::com.ninja.helper.default')->formid(); $cookie = KRequest::get('cookie.' . $formid, 'string', false); $states = array('total' => $total, 'offset' => $offset, 'limit' => $limit, 'display' => $display); if ($cookie) { $merge = KHelperArray::merge(json_decode($cookie, true), $states); KRequest::set('cookie.' . $formid, json_encode($merge), 'string'); } //Temp fix $cookie = false; $states = $cookie ? array() : array('state' => $states); KFactory::get('admin::com.ninja.helper.default')->js('/pagination.js'); KFactory::get('admin::com.ninja.helper.default')->js('window.addEvent(\'domready\', function(){ $$(\'div.pagination\')[0].paginator(' . json_encode(array_merge(array('identificator' => $formid, 'text' => array('count' => sprintf(JText::_('Pages %s of %s'), '@{current}', '@{total}'), 'first' => sprintf(JText::_('%s First'), $windoze ? '<<' : '❮❮'), 'previous' => sprintf(JText::_('%s Previous'), $windoze ? '<' : '❮'), 'next' => sprintf(JText::_('Next %s'), $windoze ? '>' : '❯'), 'last' => sprintf(JText::_('Last %s'), $windoze ? '>>' : '❯❯'))), $states)) . '); });'); } return $html; }
/** * Set a variable in the request. Cookies and session data are stored persistently. * * @param mixed Variable identifier, prefixed by hash name eg post.foo.bar * @param mixed Variable value */ public static function set($identifier, $value) { list($hash, $keys) = self::_parseIdentifier($identifier); // Add to _REQUEST hash if original hash is get, post, or cookies if (in_array($hash, array('GET', 'POST', 'COOKIE'))) { self::set('request.' . implode('.', $keys), $value); } // Store cookies persistently if ($hash == 'COOKIE' && strpos(KRequest::protocol(), 'http') !== false) { // rewrite the $keys as foo[bar][bar] $ckeys = $keys; // get a copy $name = array_shift($ckeys); foreach ($ckeys as $ckey) { $name .= '[' . $ckey . ']'; } if (!setcookie($name, $value)) { throw new KRequestException("Couldn't set cookie, headers already sent."); } } // Store in $GLOBALS foreach (array_reverse($keys, true) as $key) { $value = array($key => $value); } // Add the global if it's doesn't exist if (!isset($GLOBALS['_' . $hash])) { $GLOBALS['_' . $hash] = array(); } $GLOBALS['_' . $hash] = KHelperArray::merge($GLOBALS['_' . $hash], $value); }