public function index() { $p_var = Config::getPaginationVariable(); $current_page = array_get($this->context, 'current_page'); $total_pages = array_get($this->context, 'total_pages'); $pages_to_show = $this->fetchParam('pages_to_show', 5, 'is_numeric', false, false); $q_strings = URL::sanitize($_GET); // catch less than 1 total pages if ($total_pages <= 1) { return 0; } $listing = ''; $lower = max(1, min(floor($current_page - ($pages_to_show - 1) / 2), $total_pages - $pages_to_show + 1)); $upper = $lower + min($total_pages, $pages_to_show) - 1; for ($i = $lower; $i <= $upper; $i++) { if ($i == $current_page) { $listing .= '<li class="active">'; } else { $listing .= '<li>'; } $q = http_build_query(array_merge($q_strings, array($p_var => $i))); $listing .= '<a href="{{ url }}?' . $q . '">' . $i . '</a></li>'; } return $listing; }
/** * Gets the current URL without needing the public API * * @return string */ private function getCurrentURL() { if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']) { $url = $_SERVER['REQUEST_URI']; } else { // doesn't exist, hand-make it // code ported from \Slim\Environment if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) { $script_name = $_SERVER['SCRIPT_NAME']; //Without URL rewrite } else { $script_name = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])); //With URL rewrite } $url = '/' . ltrim(substr_replace($_SERVER['REQUEST_URI'], '', 0, strlen($script_name)), '/'); } return URL::sanitize($url); }
/** * Add to the top of the publish form * * @return string */ public function control_panel__add_to_publish_form_header() { // master switch for revisions if (!$this->core->isEnabled()) { return false; } $app = \Slim\Slim::getInstance(); // hidden message field $html = '<input type="hidden" name="revisions__commit_message" id="revision-message">'; $html .= '<div id="revision-default-serialized" style="display: none !important;"></div>'; if ($this->blink->get('is_revision') && !$this->blink->get('is_latest_revision')) { // get the revision data $timestamp = $this->core->getRevisionTimestamp($this->core->getPath(), $this->blink->get('current_revision')); $html .= '<div class="revisions-feedback">'; $html .= ' <span class="ss-icon">help</span>'; $html .= ' ' . sprintf(__('viewing_revision'), Date::format(Config::getDateFormat(), $timestamp)) . ' '; $html .= ' <a href="' . $app->urlFor('publish') . '?path=' . URL::sanitize(Request::get('path')) . '">' . __('viewing_revision_link') . '.'; $html .= '</div>'; } return $html; }
// mark milestone for debug panel Debug::markMilestone('page ready'); $app->halt($response_code, ob_get_clean()); })->via('GET', 'POST', 'HEAD'); // a second route that captures all routes, but will always return the 404 page $app->map('/(:segments+)', function ($segments = array()) use ($app) { global $is_debuggable_route; $is_debuggable_route = true; // clean segments $segments = URL::sanitize($segments); // segments foreach ($segments as $key => $seg) { $count = $key + 1; $app->config['segment_' . $count] = $seg; } $app->config['last_segment'] = end($segments); $path = '/404'; $app->config['current_path'] = $path; // init some variables for below $app->config['current_url'] = $app->config['current_path']; $app->config['current_path'] = $path; # override global current_path
/** * Set up any and all global vars, tags, and other defaults * * @return void */ public static function setDefaultTags() { $app = \Slim\Slim::getInstance(); /* |-------------------------------------------------------------------------- | User & Session Authentication |-------------------------------------------------------------------------- | | This may be overwritten later, but let's go ahead and set the default | layout file to start assembling our front-end view. | */ $current_member = Auth::getCurrentMember(); $app->config['logged_in'] = !is_null($current_member); $app->config['username'] = $current_member ? $current_member->get('username') : false; $app->config['is_admin'] = $current_member ? $current_member->hasRole('admin') : false; // current member data if ($current_member) { $app->config['current_member'] = array('logged_in' => !is_null($current_member), 'username' => $current_member->get('username')) + $current_member->export(); // load up roles foreach ($current_member->get('roles') as $role) { $app->config['current_member']['is_' . $role] = 'true'; } } /* |-------------------------------------------------------------------------- | GET and POST global vars |-------------------------------------------------------------------------- | | Use these at your own risk, of course. Don't be stupid. | */ $app->config['get'] = URL::sanitize($_GET); $app->config['post'] = URL::sanitize($_POST); $app->config['get_post'] = $app->config['get'] + $app->config['post']; $app->config['homepage'] = Config::getSiteRoot(); $app->config['now'] = time(); }
/** * Retrieves the resource URI for this request * * @param mixed $default Default value to use if not set * @return string */ public static function getResourceURI($default = NULL) { return Helper::pick(URL::sanitize(\Slim\Slim::getInstance()->request()->getResourceUri()), $default); }
public static function createPaginationData($count, $limit) { $q_strings = URL::sanitize($_GET); $p_var = Config::getPaginationVariable(); $page = Request::get($p_var, 1); $current_page = (int) min(max(1, $page), max(1, $page)); $data = array(); $data['current_page'] = $current_page; $data['total_items'] = (int) max(0, $count); $data['items_per_page'] = (int) max(1, $limit); $data['total_pages'] = (int) ceil($count / $limit); $data['current_first_item'] = (int) min(($page - 1) * $limit + 1, $count); $data['current_last_item'] = (int) min($data['current_first_item'] + $limit - 1, $count); $data['offset'] = (int) (($current_page - 1) * $limit); $data['previous_page'] = $current_page > 1 ? '?' . http_build_query(array_merge($q_strings, array($p_var => $current_page - 1))) : FALSE; $data['next_page'] = $current_page < $data['total_pages'] ? '?' . http_build_query(array_merge($q_strings, array($p_var => $current_page + 1))) : FALSE; $data['first_page'] = $current_page === 1 ? FALSE : '?' . http_build_query(array_merge($q_strings, array($p_var => 1))); $data['last_page'] = $current_page >= $data['total_pages'] ? FALSE : '?' . http_build_query(array_merge($q_strings, array($p_var => $data['total_pages']))); return $data; }