コード例 #1
0
ファイル: activation.php プロジェクト: asalce/wp-ci
function wpci_deactivate()
{
    WPCI::log('info', 'wpci_deactivate()');
    // remove our gateway page, otherwise it'll show up in page lists
    if ($page = wpci_get_gateway()) {
        wp_delete_post($page->ID);
    }
}
コード例 #2
0
ファイル: localization_helper.php プロジェクト: asalce/wp-ci
function load_locale($locale, $return = FALSE)
{
    if ($locale == '') {
        $CI =& get_instance();
        $deft_lang = $CI->config->item('locale');
        $locale = $deft_lang == '' ? 'en_US' : $deft_lang;
    }
    if (in_array($locale, Localization::$locales, TRUE)) {
        return;
    }
    $langfile = $locale . '.properties';
    if (file_exists(WPCI::active_app_path() . '/language/' . $langfile)) {
        $lang = file_get_contents(WPCI::active_app_path() . '/language/' . $langfile);
    } else {
        if (file_exists(BASEPATH . 'language/' . $langfile)) {
            $lang = file_get_contents(BASEPATH . 'language/' . $langfile);
            if (!$lang) {
                log_message('error', 'Language file contains no data: language/' . $langfile);
                return;
            }
        } else {
            //show_error('Unable to load the requested language file: language/'.$langfile);
            log_message('error', 'Unable to load the requested language file: language/' . $langfile);
            return;
        }
    }
    Localization::$locales[$locale] = array();
    // parse the language file
    foreach (split("\n", $lang) as $entry) {
        // if line starts with #, ignore
        if (strncmp($entry, '#', 1) == 0) {
            continue;
        }
        list($phrase, $trans) = split("=", $entry);
        Localization::$locales[$locale][trim($phrase)] = trim($trans);
    }
    log_message('debug', 'Language file loaded: language/' . $langfile);
    if ($return == TRUE) {
        return Localization::$locales[$locale];
    }
    return TRUE;
}
コード例 #3
0
ファイル: MY_Config.php プロジェクト: asalce/wp-ci
 function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
 {
     if ($app_path = WPCI::active_app_path(FALSE)) {
         $file_path = $app_path . '/config/' . $file . EXT;
         if (file_exists($file_path)) {
             if (in_array($file_path, $this->is_loaded, TRUE)) {
                 return TRUE;
             }
             @(include $file_path);
             if ($use_sections === TRUE) {
                 if (isset($this->config[$file])) {
                     $this->config[$file] = array_merge($this->config[$file], $config);
                 } else {
                     $this->config[$file] = $config;
                 }
             } else {
                 $this->config = array_merge($this->config, $config);
             }
             return TRUE;
         }
     }
     parent::load($file, $use_sections, $fail_gracefully);
 }
コード例 #4
0
ファイル: MY_Router.php プロジェクト: asalce/wp-ci
 /**
  * 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>.");
 }
コード例 #5
0
ファイル: wp-ci.php プロジェクト: asalce/wp-ci
define('HAS_WPCI', true);
// absolute path to wp-ci src
if (!defined('WPCI_FILE')) {
    define('WPCI_FILE', __FILE__);
}
if (!defined('WPCI_ROOT')) {
    define('WPCI_ROOT', dirname(__FILE__));
}
// request methods
define('GET', "GET");
define('POST', "POST");
define('PUT', "PUT");
define('DELETE', "DELETE");
// WP-CI plugin
require_once WPCI_ROOT . '/WPCI.php';
WPCI::add_actions();
// load dependencies and support libraries
/*
if (!class_exists('clAPI')) 
	require_once(WPCI_ROOT.'/lib/coreylib/coreylib.php');

if (!class_exists('Spyc')) 
	require_once(WPCI_ROOT.'/lib/spyc/spyc.php');
//*/
if (!class_exists('Annotations')) {
    require_once WPCI_ROOT . '/lib/annotations.php';
}
// load the hacks file, if it exists, allowing for pluggable overrides.
if (file_exists(WPCI_ROOT . '/hacks.php')) {
    require_once WPCI_ROOT . '/hacks.php';
}
コード例 #6
0
ファイル: WPCI.php プロジェクト: allviss/wp-ci
 private static function execute_admin()
 {
     global $RTR, $CI, $EXT, $BM, $URI, $OUT;
     // process annotations so that tokens are defined
     WPCI::process_menu_annotations();
     if ($token = isset($_REQUEST['page']) ? $_REQUEST['page'] : null) {
         $class = null;
         $method = null;
         $app = null;
         $directory = null;
         $app_path = null;
         // exact match for token?
         if (isset(WPCI::$app_index[$token])) {
             // load the menu settings
             $menu = WPCI::$app_index[$token];
             // tell WPCI which app is active
             $app = $menu['app'];
             WPCI::activate($app);
             // load the application controller
             $app_path = $menu['app_path'];
             require_once $app_path;
             $BM->mark('loading_time_base_classes_end');
             // create an instance of the controller
             $class = $menu['class'];
             $method = $menu['method_name'];
         } else {
             if ($token == 'wp-ci') {
                 $app = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
                 $class = isset($_REQUEST['c']) ? strtolower($_REQUEST['c']) : 'settings';
                 $method = isset($_REQUEST['m']) ? $_REQUEST['m'] : 'index';
                 $directory = isset($_REQUEST['d']) ? $_REQUEST['d'] : null;
                 // if app is specified, activate it... (otherwise the core application will be used)
                 if ($app) {
                     WPCI::activate($app);
                 }
                 if ($directory) {
                     $app_path = WPCI::active_app_path() . "/controllers/{$directory}/{$class}" . EXT;
                 } else {
                     $app_path = WPCI::active_app_path() . "/controllers/{$class}" . EXT;
                 }
                 if (!file_exists($app_path)) {
                     wp_die("I don't know how to do <b>{$class}/{$method}</b>.");
                 }
                 // load the contorller
                 require_once $app_path;
             }
         }
         if ($class && $method) {
             // fake the router into thinking he did his job...
             $RTR->set_app($app);
             $RTR->set_class($class);
             $RTR->set_method($method);
             $RTR->set_directory($directory);
             $BM->mark('loading_time_base_classes_end');
             if (!class_exists($class)) {
                 wp_die("I can't find <b>{$class}/{$method}</b>.");
             }
             // make sure app class is at the top of the annotations stack
             $ann = Annotations::get("{$app}/{$class}", $app_path);
             // evaluate permissions, but only when they are specified for evaluation
             $user_can = true;
             if (count($ann->for_class('user_must') + $ann->for_class('user_can') + $ann->for_method($method, 'user_must') + $ann->for_method($method, 'user_can'))) {
                 // first, test all user_must annotations
                 foreach ($ann->for_class('user_must') as $cap) {
                     if (!current_user_can($cap)) {
                         $user_can = false;
                         break;
                     }
                 }
                 // next, test for method
                 if ($user_can) {
                     foreach ($ann->for_method($method, 'user_must') as $cap) {
                         if (!current_user_can($cap)) {
                             $user_can = false;
                             break;
                         }
                     }
                     // then, test user_can
                     if ($user_can) {
                         $user_can = false;
                         foreach ($ann->for_class('user_can') as $cap) {
                             $user_can = $user_can || current_user_can($cap);
                         }
                         foreach ($ann->for_method($method, 'user_can') as $cap) {
                             $user_can = $user_can || current_user_can($cap);
                         }
                     }
                 }
             }
             if ($method == 'controller' or strncmp($method, '_', 1) == 0 or in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) or !$user_can) {
                 wp_die("You're not allowed to do <b>{$class}/{$method}</b>.");
             }
             $EXT->_call_hook('pre_controller');
             $BM->mark('controller_execution_time_( ' . $class . ' / ' . $method . ' )_start');
             $CI = new $class();
             $CI->method = strtoupper($_SERVER['REQUEST_METHOD']);
             $EXT->_call_hook('post_controller_constructor');
             // ajax annotation = no header
             $is_ajax = $ann->for_class('ajax') || $ann->for_method($method, 'ajax');
             $no_chrome = $ann->for_class('no_chrome') || $ann->for_method($method, 'chrome');
             if ($is_ajax || $no_chrome) {
                 $_GET['noheader'] = 1;
             }
             $ajax_content = null;
             // Is there a "remap" function?
             if (method_exists($CI, '_remap')) {
                 $CI->_remap($method);
             } else {
                 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
                 // methods, so we'll use this workaround for consistent behavior
                 if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($CI)))) {
                     wp_die("I'm not allowed to do <b>{$class}/{$method}</b>.");
                 }
                 log_message('debug', "Executing {$class}/{$method}()");
                 // Call the requested method.
                 // Any URI segments present (besides the class/function) will be passed to the method for convenience
                 if ($is_ajax || $no_chrome) {
                     ob_start();
                 }
                 call_user_func_array(array(&$CI, $method), array());
                 if ($is_ajax || $no_chrome) {
                     $ajax_content = ob_get_clean();
                 }
             }
             $BM->mark('controller_execution_time_( ' . $class . ' / ' . $method . ' )_end');
             $EXT->_call_hook('post_controller');
             $EXT->_call_hook('post_system');
             if (class_exists('CI_DB') and isset($CI->db)) {
                 $CI->db->close();
             }
             // if this was an ajax request, then we display the output and terminate
             if ($is_ajax || $no_chrome) {
                 if ($is_ajax) {
                     header('Content-type: application/json', true);
                 }
                 echo $ajax_content;
                 $OUT->_display();
                 exit(0);
             }
         }
     }
 }
コード例 #7
0
ファイル: pluggable.php プロジェクト: asalce/wp-ci
 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;
         }
     }
 }
コード例 #8
0
ファイル: MY_Loader.php プロジェクト: allviss/wp-ci
 /**
  * Autoloader
  *
  * The config/autoload.php file contains an array that permits sub-systems,
  * libraries, plugins, and helpers to be loaded automatically.
  *
  * @access	private
  * @param	array
  * @return	void
  */
 function _ci_autoloader()
 {
     // core auto-loader
     @(include_once APPPATH . 'config/autoload' . EXT);
     if (isset($autoload)) {
         $this->_ci_autoload($autoload);
         unset($autoload);
     }
     // active app auto-loader
     if (WPCI::active_app_path() != APPPATH) {
         if (file_exists($autoload_path = WPCI::active_app_path() . '/config/autoload' . EXT)) {
             @(include_once $autoload_path);
         }
         if (isset($autoload)) {
             $this->_ci_autoload($autoload);
             unset($autoload);
         }
     }
 }
コード例 #9
0
ファイル: hello-sparky.php プロジェクト: asalce/wp-ci
function sparky_register_app()
{
    WPCI::register_app(__FILE__);
}
コード例 #10
0
ファイル: content.php プロジェクト: asalce/wp-ci
function wpci_wp_title($title, $sep, $seplocation)
{
    return is_codeigniter() ? WPCI::get_title($sep, $seplocation) : $title;
}