/** * Validates the supplied segments. Attempts to determine the path to * the controller. * * @access private * @param array * @return array */ function _validate_request($segments) { // the first segment is our WordPress gateway, so we remove it $gateway = array_shift($segments); if ($gateway != wpci_get_slug()) { return false; } // the second segment might be an app spec if ($segments[0] == WPCI::get_active_app()) { $this->set_app(array_shift($segments)); } // and if there's nothing else, stop validating... if (!count($segments)) { return $segments; } // Does the requested controller exist in the root folder? if (file_exists(WPCI::active_app_path() . '/controllers/' . $segments[0] . EXT)) { return $segments; } // Is the controller in a sub-folder? if (is_dir(WPCI::active_app_path() . '/controllers/' . $segments[0])) { // Set the directory and remove it from the segment array $this->set_directory($segments[0]); $segments = array_slice($segments, 1); if (count($segments) > 0) { // Does the requested controller exist in the sub-folder? if (!file_exists(WPCI::active_app_path() . '/controllers/' . $this->fetch_directory() . $segments[0] . EXT)) { wp_die("There are no controllers for <b>" . $this->fetch_directory() . $segments[0] . "</b>."); } } else { $this->set_class($this->default_controller); $this->set_method('index'); // Does the default controller exist in the sub-folder? if (!file_exists(WPCI::active_app_path() . '/controllers/' . $this->fetch_directory() . $this->default_controller . EXT)) { $this->directory = ''; return array(); } } return $segments; } // Is the requested controller // Can't find the requested controller... wp_die("There are no controllers for <b>{$segments['0']}</b>."); }
static function generate_rewrite_rules($wp_rewrite) { if ($gateway = wpci_get_gateway()) { $wp_rewrite->rules = array('^' . wpci_get_slug() . '/.*' => 'index.php?pagename=' . $gateway->post_name) + $wp_rewrite->rules; } else { self::activate_gateway_missing_error(); } }
function wpci_generate_rewrite_rules($wp_rewrite) { $gateway = wpci_get_gateway(); $wp_rewrite->rules = array('^' . wpci_get_slug() . '/.*' => 'index.php?pagename=' . $gateway->post_name) + $wp_rewrite->rules; }
function get_link_to($path = array(), $params = array(), $return_array = FALSE) { extract($path = wpci_parse_path($path, $params)); if ($context == 'back') { /* Back-end links take one of two forms * <host>.php?page=wp-ci/<application>/<controller>/<directory>/<action> * admin.php?page=wp-ci&a=<application>&c=<controller>&d=<directory>&m=<action> * * The first form is generated when $path specifies a CI request that has a menu * or submenu item. The second form is generated in all other cases. * This approach is required by the necessity of the "page" request parameter, * which must be present lest WordPress reject the request. */ // the token is what is used to store menu references... $token = "wp-ci/{$application}" . $directory . "{$controller}/{$action}"; $host = 'admin.php'; if ($app = WPCI::find_app($token)) { // FIXME: set host here... } // if $menu was found for $token, then page = $token; otherwise $page = 'wp-ci' $page = $app ? $token : "wp-ci"; if ($return_array) { $path['host'] = $host; $path['page'] = $page; $path['app'] = $app; // whatever receives $path will have to decide whether or not to add additional parameters... return $path; } else { $query = array(); foreach ($params as $k => $p) { if (is_array($p)) { foreach ($p as $i => $v) { $query[] = urlencode($k) . '[' . urlencode($i) . ']=' . urlencode($v); } } else { $query[] = urlencode($k) . '=' . urlencode($p); } } $url = "{$host}?page={$page}"; if (!$app) { $url .= "&a={$application}&c={$controller}&m={$action}&d={$directory}"; } // absolute references by default, otherwise turned off... if ($absolute !== FALSE || $secure) { $home = get_bloginfo('home'); // secure? if ($secure) { $home = preg_replace('/^http/', 'https', $home); } $url = $home . '/wp-admin/' . $url; } if (count($query)) { $url .= '&' . join('&', $query); } return $url; } } else { // context ~= front /* Front-end links follow the typical CI format: * /application/directory/controller/action/param1/param2 */ $url = "/" . wpci_get_slug() . "/{$application}" . $directory . "{$controller}/{$action}"; // prepare the query parameters // TODO: do custom routing here... if (count($params)) { $values = array(); foreach ($params as $k => $p) { $values[] = urlencode($p); } $url .= "/" . join('/', $values); } // absolute references by default, otherwise turned off... if ($absolute !== FALSE || $secure) { $home = get_bloginfo('home'); // secure? if ($secure) { $home = preg_replace('/^http/', 'https', $home); } $url = $home . $url; } // trailing slash is a must in WordPress, without which we tend to // get two requests for the price of one, which screws up the Flash scope to no end... $url .= '/'; if ($return_array) { $path['url'] = $url; return $path; } else { return $url; } } }
</ul> <div id="general"> <table class="form-table"> <tr> <th class="row">Encryption Key</th> <td> <?php echo form_input(array('name' => 'encryption_key', 'value' => wpci_get_encryption_key(), 'class' => 'regular-text')); ?> </td> </tr> <tr> <th class="row">Gateway Slug</th> <td> <?php echo form_input(array('name' => 'slug', 'value' => wpci_get_slug(), 'class' => 'regular-text')); ?> </td> </tr> <tr> <th class="row">SSL Support</th> <td> <?php echo form_dropdown('ssl_enabled', array('' => 'Disabled ', 1 => 'Enabled'), wpci_get_ssl_enabled()); ?> </td> </tr> </table> </div> <div id="debugging"> <table class="form-table">
static function generate_rewrite_rules($wp_rewrite) { if ($gateway = wpci_get_gateway()) { $wp_rewrite->rules = array('^' . wpci_get_slug() . '/.*' => 'index.php?pagename=' . $gateway->post_name) + $wp_rewrite->rules; } else { add_action('admin_notices', create_function('', "\n\t\t\t\treturn '<div class=\"error\"><p>Gateway page is missing. To restore, please disable and then enable your WP-CI or WP-CMSPLUS plugin.</p></div>'; \n\t\t\t")); } }