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; } }
function get_rules() { $rules = $this->rules; $rules = RewriteRules::sort_rules(RewriteRules::get_active()); $this->rules = $rules; return $rules; }
/** * 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; }
/** * Return the active rewrite rules, both in the database and applied by plugins * * @return array Array of RewriteRule objects for active rewrite rules */ public static function get_active() { static $system_rules; if (!isset($system_rules)) { $sql = "\n\t\t\t\tSELECT rr.rule_id, rr.name, rr.parse_regex, rr.build_str, rr.handler, rr.action, rr.priority, rr.parameters\n\t\t\t\tFROM {rewrite_rules} AS rr\n\t\t\t\tWHERE rr.is_active= 1\n\t\t\t\tORDER BY rr.priority"; $db_rules = DB::get_results($sql, array(), 'RewriteRule'); $system_rules = self::add_system_rules($db_rules); } $rewrite_rules = Plugins::filter('rewrite_rules', $system_rules); $rewrite_rules = self::sort_rules($rewrite_rules); // cache the sorted rules for this instance to use $c = __CLASS__; self::$sorted_rules_cache = new $c($rewrite_rules); return self::$sorted_rules_cache; }
public function action_plugin_ui($plugin_id, $action) { if ($plugin_id == $this->plugin_id()) { switch ($action) { case _t('Configure', 'customquery'): $ui = new FormUI('customquery'); foreach (RewriteRules::get_active()->getArrayCopy() as $rule) { if (strpos($rule->name, 'display_') === 0 and $rule->name != 'display_404') { $ui->append('text', $rule->name, 'customquery__' . $rule->name, 'Number of Posts for ' . $rule->name); } } $ui->append('submit', 'save', _t('Save')); $ui->out(); break; } } }
/** * All handlers must implement act() to conform to handler API. * This is the default implementation of act(), which attempts * to call a class member method of $this->act_$action(). Any * subclass is welcome to override this default implementation. * * @param string $action the action that was in the URL rule */ public function act($action) { if (null === $this->handler_vars) { $this->handler_vars = new SuperGlobal(array()); } $this->action = $action; $this->theme->assign('matched_rule', URL::get_matched_rule()); $request = new StdClass(); foreach (RewriteRules::get_active() as $rule) { $request->{$rule->name} = false; } $request->{$this->theme->matched_rule->name} = true; $this->theme->assign('request', $request); $action_hook = 'plugin_act_' . $action; $before_action_hook = 'before_' . $action_hook; $after_action_hook = 'after_' . $action_hook; Plugins::act($before_action_hook, $this); Plugins::act($action_hook, $this); Plugins::act($after_action_hook); }
/** * Load the active theme and create a new Theme instance. * Also, assign the request variables. */ public function setup_theme() { $this->theme = Themes::create(); $this->theme->assign('matched_rule', URL::get_matched_rule()); $request = new StdClass(); foreach (RewriteRules::get_active() as $rule) { $request->{$rule->name} = false; } $request->{$this->theme->matched_rule->name} = true; $this->theme->assign('request', $request); }
/** * Display the login form * * @param string $name Pre-fill the name field with this name */ protected function login_form($name) { // Display the login form. $this->theme = Themes::create(); if (!$this->theme->template_exists('login')) { $this->theme = Themes::create('admin', 'RawPHPEngine', Site::get_dir('admin_theme', TRUE)); $this->theme->assign('admin_page', 'login'); } $request = new StdClass(); foreach (RewriteRules::get_active() as $rule) { $request->{$rule->name} = $rule->name == URL::get_matched_rule()->name; } $this->theme->assign('request', $request); $this->theme->assign('habari_username', htmlentities($name, ENT_QUOTES, 'UTF-8')); $this->display('login'); return TRUE; }
/** * 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) { // & if (($current != 1 || $current != $total) && $current - 2 > 1) { $p['pages'][] = '…'; } // 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; } // … if (($current != 1 || $current != $total) && $current + 2 < $total) { $p['pages'][] = '…'; } // 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); }
public function setup() { $this->rules = RewriteRules::get_active(); }