Exemple #1
0
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;
}
Exemple #2
0
 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);
 }
Exemple #3
0
 /**
  * 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>.");
 }
Exemple #4
0
 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);
             }
         }
     }
 }
Exemple #5
0
 /**
  * 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);
         }
     }
 }