Ejemplo n.º 1
0
 public function action_init()
 {
     $format = Options::get('dateyurl__format');
     // for backwards compatibility. the first time, set the option
     if ($format == null) {
         Options::set('dateyurl__format', 'date');
         $format = 'date';
     }
     if ($format == 'date') {
         // /{year}/{month}/{day}/{slug}
         $parse_regex = '%(?P<year>\\d{4})/(?P<mon0>\\d{2})/(?P<mday0>\\d{2})/(?P<slug>[^/]+)(?:/page/(?P<page>\\d+))?/?$%i';
         $build_str = '{$year}/{$mon0}/{$mday0}/{$slug}(/page/{$page})';
     }
     if ($format == 'month') {
         // /{year}/{month}/{slug}
         $parse_regex = '%(?P<year>\\d{4})/(?P<mon0>\\d{2})/(?P<slug>[^/]+)(?:/page/(?P<page>\\d+))?/?$%i';
         $build_str = '{$year}/{$mon0}/{$slug}(/page/{$page})';
     }
     // For backwards compatability. the first time, set the rules
     $rules = Options::get('dateyurl__rules');
     // for backwards compatibility. the first time, set the option
     if ($rules == null) {
         $rules = array('display_entry');
         Options::set('dateyurl__rules', $rules);
     }
     foreach ($rules as $rule_name) {
         $rule = RewriteRules::by_name($rule_name);
         $rule = $rule[0];
         $rule->parse_regex = $parse_regex;
         $rule->build_str = $build_str;
     }
 }
Ejemplo n.º 2
0
 /**
  * Cause the matched rule to be unset in the case of a 404
  *
  * @return \Habari\RewriteRule A rewrite rule that represents a 404 error - no match on the URL requested
  */
 public static function set_404()
 {
     if (empty(URL::instance()->matched_rule) || URL::instance()->matched_rule->name != 'display_404') {
         $rule = RewriteRules::by_name('display_404');
         URL::instance()->matched_rule = reset($rule);
         URL::instance()->matched_rule->match(self::$stub);
     }
     return URL::instance()->matched_rule;
 }
Ejemplo n.º 3
0
 private function add_rewrite_rule($name, $params)
 {
     $rule = RewriteRules::by_name($name);
     if (count($rule) == 1) {
         $rule = $rule[0];
         foreach ($params as $key => $param) {
             $rule->{$key} = $param;
         }
         $rule->update();
     } else {
         $rule = new RewriteRule($params);
         $rule->insert();
     }
 }
Ejemplo n.º 4
0
 /**
  * function page_selector
  * Returns a page selector
  *
  * The $paramarray can contain:
  * 'current' => Current page
  * 'total' => Total pages
  * 'token' => Token for the URL calls
  * 'settings' => Array of settings for the URL calls
  *
  * @param array parameters to render the pagination
  * @return array contains a 'current' and 'pages' key
  **/
 public function get($current, $total, $rr_name = NULL, $settings = array())
 {
     // Extract the style and remove it from the array.
     if (isset($settings['style'])) {
         $style = $settings['style'];
         unset($settings['style']);
     } else {
         $style = 'span';
     }
     // If RewriteRule name is not supplied, use the current RewriteRule
     if ($rr_name == '') {
         $rr = URL::get_matched_rule();
     } else {
         list($rr) = RewriteRules::by_name($rr_name);
     }
     // Retrieve the RewriteRule and aggregate an array of matching arguments
     $rr_named_args = $rr->named_args;
     $rr_args = array_merge($rr_named_args['required'], $rr_named_args['optional']);
     $rr_args_values = array();
     foreach ($rr_args as $rr_arg) {
         $rr_arg_value = Controller::get_var($rr_arg);
         if ($rr_arg_value != '') {
             $rr_args_values[$rr_arg] = $rr_arg_value;
         }
     }
     $settings = array_merge($settings, $rr_args_values);
     // Current page
     if ($current > $total) {
         $current = $total;
     }
     $p = array('current' => $current);
     // 1 - First page
     $p['pages'][1]['caption'] = 1;
     // Skip if there is only one page
     if ($total > 1) {
         // &amp;
         if (($current != 1 || $current != $total) && $current - 2 > 1) {
             $p['pages'][] = '&hellip;';
         }
         // Previous Page
         if ($current - 1 > 1) {
             $p['pages'][]['caption'] = $current - 1;
         }
         // Current Page
         if ($current > 1 && $current < $total) {
             $p['pages'][]['caption'] = $current;
         }
         // Next Page
         if ($current + 1 < $total) {
             $p['pages'][]['caption'] = $current + 1;
         }
         // &hellip;
         if (($current != 1 || $current != $total) && $current + 2 < $total) {
             $p['pages'][] = '&hellip;';
         }
         // Last page
         $p['pages'][]['caption'] = $total;
     }
     $count = count($p['pages']);
     for ($z = 1; $z <= $count; $z++) {
         if (is_array($p['pages'][$z])) {
             $p['pages'][$z]['url'] = $rr->build(array_merge($settings, array('page' => $p['pages'][$z]['caption'])), false);
         }
     }
     return self::format($p, $style);
 }