예제 #1
0
 /**
  * Parse URI structure and get current_page
  *
  * @access  protected
  * @return  void
  */
 protected function initiate()
 {
     // Parse based from provided `uri`, for custom routing
     if (!empty($this->uri)) {
         $segments = explode('/', str_replace(Uri::base(), '', $this->uri));
         $key = array_search(':page', $segments);
         // only find current_page if specifically set to null, otherwise assume current_page is provided
         if (null === $this->current_page) {
             if (false !== $key) {
                 $this->uri_segment = intval($key) + 1;
             }
             $this->current_page = (int) Uri::segment($this->uri_segment);
         }
         // make sure it's an integer
         $this->current_page = (int) $this->current_page;
     } else {
         // URI is not given, we need to automatically detect request URI
         $get = Input::get(null, array());
         $segments = \Uri::segments();
         // use $_GET if uri_segment is specifically set to null
         if (null === $this->uri_segment) {
             if (!isset($get['page'])) {
                 $get['page'] = 1;
             }
             $this->current_page = (int) $get['page'];
             $get['page'] = ':page';
         } else {
             // start URI detection
             $key = $this->uri_segment - 1;
             // @todo it's should basically be the same.
             if (isset($segments[$key])) {
                 $this->current_page = (int) $segments[$key];
             } else {
                 $this->current_page = (int) Uri::segment($this->uri_segment);
             }
             // get the route translation, as comparison to current URI segment
             $translation = explode('/', \Request::active()->route->translation);
             // we need to merge translation when Uri::segments is not enough
             if ($key >= count($segments)) {
                 foreach ($translation as $seg_id => $seg_value) {
                     if (!isset($segments[$seg_id])) {
                         $segments[$seg_id] = $seg_value;
                     }
                 }
             }
             // add in action index when not available
             if (null === \Request::active()->route->action and count($translation) <= count($segments)) {
                 $segments[$key - 1] = 'index';
             }
             $segments[$key] = ':page';
         }
         // we should add in all $_GET (useful for listing with filters)
         if (!empty($get)) {
             $get = Uri::build_get_query($get);
             $get = str_replace('page=%3Apage', 'page=:page', $get);
         } else {
             $get = '';
         }
         // generate an formatted uri with :page
         $this->uri = implode('/', $segments) . $get;
     }
 }