Exemple #1
0
 /**
  * Replaces an autoloader in a module to help development
  *
  * @param string $module
  *
  * @return boolean
  */
 public static function module($module)
 {
     if ($module = \Module::exists($module)) {
         return static::path($module . 'vendor/autoload.php');
     }
     return false;
 }
 /**
  * Run the credential importer
  * 
  * @param string $json_file The JSON file that contains a list of the APIs and their credentials
  */
 public static function run($json_file = null)
 {
     if (empty($json_file) || file_exists($json_file) === false) {
         exit('You must specify a valid JSON file that contains your credentials.' . PHP_EOL);
     }
     if (($json = json_decode(file_get_contents($json_file), true)) === null) {
         exit('The JSON file does not contain valid JSON text.' . PHP_EOL);
     }
     // Find the API version to use for importing the keys
     $version = 'V1';
     if (!empty($json[0]['version'])) {
         if (is_int($json[0]['version']) && \Module::exists('V' . $json[0]['version'])) {
             \Module::load('V' . $json[0]['version']);
             $version = 'V' . $json[0]['version'];
         } else {
             \Module::load($version);
         }
         array_shift($json);
     } else {
         \Module::load($version);
     }
     $error = false;
     foreach ($json as $entry) {
         // We need these keys for each entry.
         if (!array_key_exists('api', $entry) || !array_key_exists('credentials', $entry)) {
             echo \Cli::color('The JSON data is in the wrong format. Skipping.' . PHP_EOL, 'yellow');
             $error = true;
             continue;
         }
         if (!is_string($entry['api'])) {
             echo \Cli::color('The API name must be a string. Skipping.' . PHP_EOL, 'yellow');
             $error = true;
             continue;
         }
         // Make sure that we have credentials to add to the DB.
         if (empty($entry['credentials']) || !is_array($entry['credentials'])) {
             echo \Cli::color('The array of credentials for ' . $entry['api'] . ' is empty. Skipping.' . PHP_EOL, 'yellow');
             $error = true;
             continue;
         }
         $response = call_user_func('\\' . $version . '\\Keyring::set_credentials', $entry['credentials'], $entry['api']);
         // Show and log the result
         if ($response === true) {
             $success_text = 'Successfully imported the credentials for API: ' . $entry['api'];
             echo \Cli::color($success_text . PHP_EOL, 'green');
             \Log::logger('INFO', 'CLI:ADD_CREDENTIALS', $success_text, __METHOD__, array('api' => $entry['api']));
         } else {
             $error_text = 'Failed to import the credentials for API: ' . $entry['api'];
             echo \Cli::color('Warning: ' . $error_text . PHP_EOL, 'red');
             $error = true;
             \Log::logger('ERROR', 'CLI:ADD_CREDENTIALS', $error_text, __METHOD__, array('api' => $entry['api']));
         }
     }
     // Display the summary.
     if ($error === true) {
         echo \Cli::color(PHP_EOL . 'Some credentials were not added to the database. See the error log for more details.' . PHP_EOL, 'red');
     } else {
         echo \Cli::color(PHP_EOL . 'All credentials were successfully added to the database.' . PHP_EOL, 'green');
     }
 }
Exemple #3
0
 /**
  * Runs the needed checks to see if the value is valid. A non
  * true value will be returned if it failed.
  *
  * @param mixed $value
  * @return bool|string
  */
 public function validate($value)
 {
     if (Module::exists($value, $this->checkInstallable)) {
         return true;
     }
     return t('%1$s must be a valid module', I18n::_DTD);
 }
Exemple #4
0
 public function get_all_paths($theme_name = null)
 {
     $paths = array();
     if ($theme_name === null) {
         $theme_name = $this->active['name'];
     }
     $path_prefix = null;
     $module_path = null;
     if ($this->config['use_modules'] and class_exists('Request', false) and $request = \Request::active() and $module = $request->module) {
         // we're using module name prefixing
         $path_prefix = $module . DS;
         // and modules are in a separate path
         is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/') . DS . $path_prefix;
         // do we need to check the module too?
         $this->config['use_modules'] === true and $module_path = \Module::exists($module) . 'themes' . DS;
     }
     foreach ($this->get_parent_themes($theme_name) as $theme) {
         if ($this->config['use_modules'] and $module) {
             $paths[] = $theme['path'] . $path_prefix;
             $paths[] = $module_path . $theme['name'] . DS;
         }
         foreach ($this->paths as $path) {
             $paths[] = $path . $theme['name'] . DS;
         }
     }
     return array_filter(array_unique($paths), 'is_dir');
 }
Exemple #5
0
    /**
     * Sets project defaults such as ACL rules, additional content,
     * load order of modules etc.
     *
     * @return null
     */
    protected function setProjectDefaults()
    {
        $guestInherit = $adminInherit = array('group_root');
        foreach ($this->_acl->getRoleTree('group_guest', true) as $role) {
            array_unshift($guestInherit, $role['name']);
        }
        foreach ($this->_acl->getRoleTree('group_admin', true) as $role) {
            array_unshift($adminInherit, $role['name']);
        }
        $aclResources = array('layout_controller_456' => $guestInherit, 'layout_controller_974' => $guestInherit, 'layout_controller_110' => $guestInherit, 'layout_controller_119' => $guestInherit, 'layout_controller_168' => $guestInherit, 'layout_controller_409' => $adminInherit, 'layout_controller_909' => $adminInherit, 'layout_controller_425' => $adminInherit, 'layout_controller_551' => $adminInherit);
        foreach ($aclResources as $resource => $roles) {
            $this->_acl->allowOnly($resource, $roles);
        }
        // Setup module load order
        if (Module::exists('comments')) {
            $comments = new Module('comments');
            $comments->setLoadOrder(1);
            # Should force it below Shareable by default
        }
        if (Module::exists('contact')) {
            // Set the contact form email to be the same as the initial user
            try {
                $this->_sql->exec('UPDATE {PREFIX}mod_contact
										SET email = (SELECT email FROM {PREFIX}users WHERE id = 2)');
            } catch (Exception $e) {
            }
        }
    }
Exemple #6
0
 public static function run($task, $args = array())
 {
     $task = strtolower($task);
     // Make sure something is set
     if (empty($task) or $task === 'help') {
         static::help();
         return;
     }
     $module = false;
     list($module, $task) = array_pad(explode('::', $task), 2, null);
     if ($task === null) {
         $task = $module;
         $module = false;
     }
     if ($module) {
         try {
             \Module::load($module);
             $path = \Module::exists($module);
             \Finder::instance()->add_path($path);
         } catch (\FuelException $e) {
             throw new Exception(sprintf('Module "%s" does not exist.', $module));
         }
     }
     // Just call and run() or did they have a specific method in mind?
     list($task, $method) = array_pad(explode(':', $task), 2, 'run');
     // Find the task
     if (!($file = \Finder::search('tasks', $task))) {
         $files = \Finder::instance()->list_files('tasks');
         $possibilities = array();
         foreach ($files as $file) {
             $possible_task = pathinfo($file, \PATHINFO_FILENAME);
             $difference = levenshtein($possible_task, $task);
             $possibilities[$difference] = $possible_task;
         }
         ksort($possibilities);
         if ($possibilities and current($possibilities) <= 5) {
             throw new Exception(sprintf('Task "%s" does not exist. Did you mean "%s"?', $task, current($possibilities)));
         } else {
             throw new Exception(sprintf('Task "%s" does not exist.', $task));
         }
         return;
     }
     require_once $file;
     $task = '\\Fuel\\Tasks\\' . ucfirst($task);
     $new_task = new $task();
     // The help option has been called, so call help instead
     if ((\Cli::option('help') or $method == 'help') and is_callable(array($new_task, 'help'))) {
         $method = 'help';
     } else {
         // if the task has an init method, call it now
         is_callable($task . '::_init') and $task::_init();
     }
     if ($return = call_fuel_func_array(array($new_task, $method), $args)) {
         \Cli::write($return);
     }
 }
Exemple #7
0
 /**
  * hook: 'cntrlr_error_output'
  * Provides 'Wiki like' functionaility for the Page module
  *
  * @param int $statusCode
  * @param string $output
  * @return string
  */
 public function hookCntrlrErrorOutput($statusCode, $output)
 {
     if ($statusCode == 404 && Module::exists('page') && !Module::isDisabled('page') && $this->_acl->checkMulti(array('page_manage', 'aliases_add'), ACL::_MULTI_ALL)) {
         $alias = $this->_router->getRequestPath();
         if (trim($alias)) {
             $msgStr = t('This page can be <a href="%1$s">created</a> with an alias of <strong>"%2$s"</strong>, simply <a href="%1$s">add this page</a> now.', _PROJECT_ID . '-page');
             $output .= '<h3>' . t('Create this Page', _PROJECT_ID . '-page') . '</h3>';
             $output .= sprintf('<p>' . $msgStr . '</p>', $this->_router->makeUrl('page', 'config', 'add', null, array('qe' => 'true', 'alias' => base64_encode($alias))), zula_htmlspecialchars($alias));
         }
     }
     return $output;
 }
Exemple #8
0
 public function before()
 {
     parent::before();
     $this->_upgrade = new \Upgrade();
     if (Module::exists('whmcs')) {
         Module::load('whmcs');
         if (\Whmcs\Whmcs::route()) {
             $data = array();
             return Response::forge(View::forge('whmcs/route', $data));
         }
     }
 }
Exemple #9
0
 public function actionAccountMemberEditAccount($account_id = '', $args = '')
 {
     $testmod_path = \Module::exists('testmod');
     $log_file_name = 'member-edit-account.txt';
     $log_file_path = $testmod_path . $log_file_name;
     // delete if exists.
     if (\File::exists($log_file_path) && !is_writable($log_file_path)) {
         return false;
     } elseif (\File::exists($log_file_path) && is_writable($log_file_path)) {
         \File::delete($log_file_path);
     }
     \File::create($testmod_path, $log_file_name, 'Member has edit to made changed their account. Account id = ' . $account_id . '. Arguments = ' . json_encode($args));
     return true;
 }
Exemple #10
0
 /**
  * find view file<br>
  * this method that extends fuelphp core theme is for re-arrange priority of theme and views.
  * 
  * @param string $view
  * @param string $themes
  * @return string
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     // determine the path prefix and optionally the module path
     $path_prefix = '';
     $module_path = null;
     if ($this->config['use_modules'] and class_exists('Request', false) and $request = \Request::active() and $module = $request->module) {
         // we're using module name prefixing
         $path_prefix = $module . DS;
         // and modules are in a separate path
         is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/') . DS . $path_prefix;
         // do we need to check the module too?
         $this->config['use_modules'] === true and $module_path = \Module::exists($module) . 'themes' . DS;
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if ($module_path and !empty($theme['name']) and is_file($path = $module_path . $theme['name'] . DS . $file . $ext)) {
                 // if use_modules is true then this $path will be /www/root/modules/<module name>/themes/<theme name>/<$view>.php
                 return $path;
             } elseif (is_file($path = $theme['path'] . $path_prefix . $file . $ext)) {
                 // if use_modules is true then $path will be /www/root/<theme path>/<theme name>/<module name>/<$view>.php
                 // if use_modules is 'modules' then $path will be /www/root/<theme path>/<theme name>/modules/<module name>/<$view>.php
                 return $path;
             } elseif (is_file($path = \Module::exists($module) . 'views' . DS . $file . $ext)) {
                 /**
                  * this condition was added by Vee W.
                  * look directly in modules/module_name/views. this $path will be /www/root/<modules path>/<module name>/views/<$view>.php
                  * 
                  * @author Vee W.
                  */
                 return $path;
             } elseif (is_file($path = $theme['path'] . $file . $ext)) {
                 // this will not look into module name anymore. $path will be /www/root/<theme path>/<theme name>/<$view>.php
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'] . $path_prefix, $file, $ext)) {
                 return $path;
             }
         }
     }
     // not found, return the viewname to fall back to the standard View processing
     return $view;
 }
 /**
  *  Load every call to the API with this method.
  *  
  *  @return void
  *  @access public
  */
 public function action_index()
 {
     // Profile the loader
     \Profiler::mark('Start of loader\'s action_index() function');
     \Profiler::mark_memory($this, 'Start of loader\'s action_index() function');
     // Make sure we aren't processing crap.
     if (in_array($this->format, array('csv', 'php', 'serialize'))) {
         $this->format = 'json';
     }
     // For some reason this value is quoted when set to html.
     if (\Input::post('format') === '"html"') {
         $this->format = 'html';
     }
     // Cleanse the session to keep things stable.
     \Session::destroy();
     // For error handling
     \Session::set('response_format', $this->format);
     // External error processing through Apache
     if (\Uri::segment(1) === 'error' && is_numeric(\Uri::segment(2)) && strlen(\Uri::segment(2)) === 3) {
         return $this->response(\Utility::format_error(\Uri::segment(2)));
     }
     // /loader/index/error/404 style (Due to routing)
     if (substr_count(\Uri::current(), 'loader/index/error') === 1 && is_numeric(\Uri::segment(4)) && strlen(\Uri::segment(4)) === 3) {
         return $this->response(\Utility::format_error(\Uri::segment(4)));
     }
     // We need a version number
     if (empty(\Uri::segment(1)) || \Module::exists(\Uri::segment(1)) === false) {
         $error_data = \Utility::format_error(400, \Err::BAD_OR_NO_VERSION, \Lang::get('errors.bad_version'));
         return $this->response($error_data, 400);
     }
     // We need a request.
     if (empty(\Input::post()) || \Input::method() !== 'POST') {
         $error_data = \Utility::format_error(405, null, \Lang::get('errors.no_request'));
         return $this->response($error_data, 405);
     }
     // Pass the request to the proper API version request handler. (Module)
     if (!empty(\Input::post())) {
         \Module::load(\Uri::segment(1));
         $response = \Request::forge(\Uri::segment(1) . '/index', false)->execute()->response->body;
         // HTML only Data Calls
         if (is_string($response)) {
             return $this->response($response, 200);
         }
         return $this->response($response[0], $response[1]);
     }
 }
Exemple #12
0
 public function action_index()
 {
     //$testModel = Model_Sales_Disposition::test();
     /*
     
     	    if (\Reports\Query::forge(\Reports\Query::LOAD, 3)->isComplete())
     	    {
         	    print_r('complete');
     	    }
     */
     // Load the required data module
     if (!\Module::loaded('data') && \Module::exists('data')) {
         \Module::load('data');
     } else {
         throw new \Exception("Data Module not found!");
     }
     $impData = \Data\Import::forge(\Data\Import::COPY, 1);
     $this->template->title = 'Example Page';
     $this->template->content = "hello";
 }
Exemple #13
0
 /**
  * Called by: php oil r movescaffoldtomodule
  * Moves scaffold files to module.
  */
 public function run($args = NULL)
 {
     /* We handle here options:
      *  * scaffold alias s: name of the scaffold to move
      *  * module alias m: module to move the scaffold into
      *  * force alias f: do we override existing files ?
      */
     $scaffold = \Cli::option('scaffold', \Cli::option('s'));
     $module = \Cli::option('module', \Cli::option('m'));
     static::$force = \Cli::option('force', \Cli::option('f', false));
     // Checking if the scaffold and module options are
     // defined
     if (is_null($scaffold) || is_null($module)) {
         \Cli::error('Some parameters are missing.');
         \Cli::error('Ex: php oil r moveScaffoldToModule' . ' -scaffold=category -module=blog');
         return;
     }
     $module_path = \Module::exists($module);
     // Is the module found ?
     if ($module_path == null) {
         \Cli::error('The specified module doesn\'t exists!');
         return;
     }
     // Now processing each scaffold file / folders
     foreach (static::$files_to_move as $item) {
         $path = str_replace('(:scaffold)', $scaffold, $item['path']);
         if (file_exists(APPPATH . $path)) {
             /*
              * As each file type must be processed
              * differently, a different method is called
              * depending on the type. For instance, if
              * the file type is controller, we will call
              * the process_controller method.
              */
             static::{'process_' . $item['type']}($path, $module, $module_path);
         }
     }
     // Processing migration as it is a special cases.
     static::process_migration($scaffold, $module, $module_path);
 }
Exemple #14
0
     break;
     ////////////////////////////
     //模块升级
 ////////////////////////////
 //模块升级
 case 'upgrade':
     //通信已关闭
     if ($connect == 'off') {
         exit(serialize(array('return' => 'connect', 'connect' => $connect)));
     }
     //缺少必要参数
     if (!$command['appid'] || !$command['package']) {
         exit(serialize(array('return' => 'argument', 'appid' => $command['appid'], 'package' => $command['package'])));
     }
     //无效模块
     if (Module::exists($command['appid']) === FALSE) {
         exit(serialize(array('return' => 'invalid', 'appid' => $command['appid'])));
     }
     //测试读写权限
     $status = Cloud::valid_perm($module);
     if (count($status)) {
         exit(serialize(array('return' => 'permission', 'catalog' => $status)));
     }
     //升级模块
     $status = Cloud::upgrade_module($command['package'], $command['hash'], $command['appid'], $command['option']['upgrade']['ignore']);
     //升级成功
     if ($status > 0) {
         //执行升级脚本
         Module::upgrade($command['appid']);
         //缓存模块
         Module::search();
Exemple #15
0
 /**
  * catches requested method call and runs as needed
  *
  * @param string	name of the method to run
  * @param string	any additional method arguments (not used here!)
  */
 public function __call($name, $args)
 {
     // set method name
     $name = '_' . $name;
     // make sure the called name exists
     if (!method_exists(get_called_class(), $name)) {
         return static::help();
     }
     // run app (default) migrations if default is true
     if (static::$default) {
         static::$name('default', 'app');
     }
     // run migrations on all specified modules
     foreach (static::$modules as $module) {
         // check if the module exists
         if (!\Module::exists($module)) {
             \Cli::write('Requested module "' . $module . '" does not exist!', 'light_red');
         } else {
             // run the migration
             static::$name($module, 'module');
         }
     }
     // run migrations on all specified packages
     foreach (static::$packages as $package) {
         // check if the module exists
         if (!\Package::exists($package)) {
             \Cli::write('Requested package "' . $package . '" does not exist!', 'light_red');
         } else {
             static::$name($package, 'package');
         }
     }
 }
Exemple #16
0
 /**
  * @deprecated  Keep until v1.3
  */
 public static function module_exists($module)
 {
     logger(\Fuel::L_WARNING, 'This method is deprecated.  Please use a Module::exists() instead.', __METHOD__);
     return \Module::exists($module);
 }
Exemple #17
0
 /**
  * EXTENDED URI FUEL CORE CLASS
  *
  * Replaces segments to load proper module (example - admin/club loads club module admin controller
  *
  * @return void
  */
 private function _set_correct_segments()
 {
     if (empty($this->segments)) {
         $default_route = \Config::get('routes._root_');
         if (isset($default_route)) {
             $this->segments = explode('/', \Config::get('routes._root_'));
         } else {
             throw Exception('Set the root route in route config');
         }
     }
     $all_segments = $this->segments;
     $this->segments = array();
     // we have to replace segments to load proper module (example - admin/club loads club module admin controller
     if ($all_segments[0] == 'admin' and count($all_segments) > 1) {
         if ($module_path = \Module::exists($all_segments[1])) {
             $additional_segment = 0;
             $this->segments[0] = $all_segments[1];
             $this->segments[1] = $all_segments[0];
             if (empty($all_segments[2])) {
                 $all_segments[2] = $all_segments[1];
             }
             if (!file_exists($module_path . 'classes' . DS . 'controller' . DS . 'admin' . DS . $all_segments[2] . '.php')) {
                 $this->segments[2] = $all_segments[1];
                 $additional_segment = 1;
             }
             for ($i = 2; $i < count($all_segments); $i++) {
                 $this->segments[$i + $additional_segment] = $all_segments[$i];
             }
         }
     } elseif (!\Module::exists($all_segments[0])) {
         //			$this->segments[0] = 'member';
         //			$this->segments[1] = 'index';
         //			$this->segments[2] = 'index';
         //			foreach ($all_segments as $segment => $value)
         //			{
         //				$this->segments[] = $value;
         //			}
     } elseif (1 == 2 && ($module_path = \Module::exists($all_segments[0]))) {
         // if we have route like score/news we want to make it like score/news/news/index
         if (count($all_segments) == 1) {
             $this->segments[0] = $all_segments[0];
             $this->segments[1] = $all_segments[0];
             $this->segments[2] = 'index';
         } elseif (count($all_segments) == 2) {
             if (!file_exists($module_path . 'classes' . DS . 'controller' . DS . $all_segments[1]) && !file_exists($module_path . 'classes' . DS . 'controller' . DS . $all_segments[1] . '.php')) {
                 $this->segments[0] = $all_segments[0];
                 $this->segments[1] = $all_segments[0];
                 $this->segments[2] = $all_segments[1];
             }
         }
     } elseif ($all_segments[0] != 'admin') {
         switch (count($all_segments)) {
             case 0:
                 $this->segments[0] = 'page';
                 $this->segments[1] = 'index';
                 break;
             case 1:
                 $this->segments[0] = $all_segments[0];
                 $this->segments[1] = 'index';
                 break;
             default:
                 if ($module_path = \Module::exists($all_segments[0])) {
                     \Module::load($all_segments[0]);
                     // Check if submodule exists like Category controller inside Product module (product/category/)
                     if (file_exists($module_path . 'classes' . DS . 'controller' . DS . $all_segments[1] . '.php')) {
                         if (isset($all_segments[2])) {
                             if (!method_exists('\\' . ucfirst($all_segments[0]) . '\\Controller_' . ucfirst($all_segments[1]), strtolower('action_' . $all_segments[2]))) {
                                 // Insert "default" method as second uri string
                                 array_splice($all_segments, 2, 0, array('index'));
                             }
                         } else {
                             // Insert "default" method as next uri string
                             $all_segments[2] = 'index';
                         }
                     } else {
                         // Default behavior, no submodule calls
                         if (file_exists($module_path . 'classes' . DS . 'controller' . DS . $all_segments[0] . '.php')) {
                             if (!method_exists('\\' . ucfirst($all_segments[0]) . '\\Controller_' . ucfirst($all_segments[0]), strtolower('action_' . $all_segments[1]))) {
                                 // Insert "default" method as second uri string
                                 array_splice($all_segments, 1, 0, array('index'));
                             }
                         }
                     }
                 }
                 $this->segments = $all_segments;
                 break;
         }
         // If we ever want to have more than one method in languge controller then we have to uncoment this part of code and we need to change route config in language module
         /*
         // Rewrite for language
         if(strlen($all_segments[1]) == 2 || ((preg_match('#(\w{2}/)#', $all_segments[1])) && (count($all_segments) >= 1)))
         {
         $this->segments[0] = 'language';
         $this->segments[1] = 'language';
         $this->segments[2] = 'set';
         $this->segments[3] = $all_segments[1];
         }
         */
     } else {
         // If we ever want to have more than one method in languge controller then we have to uncoment this part of code and we need to change route config in language module
         /*
         // Rewrite for language
         if(strlen($all_segments[1]) == 2 || ((preg_match('#(\w{2}/)#', $all_segments[1])) && (count($all_segments) >= 1)))
         {
         $this->segments[0] = 'language';
         $this->segments[1] = 'language';
         $this->segments[2] = 'set';
         $this->segments[3] = $all_segments[1];
         }
         */
     }
     if (empty($this->segments)) {
         $this->segments = $all_segments;
     }
     $this->uri = '';
     $i = 1;
     $segments_count = count($this->segments);
     foreach ($this->segments as $segment) {
         $this->uri .= $segment;
         if ($i < $segments_count) {
             $this->uri .= '/';
         }
         ++$i;
     }
     //		echo $this->uri; exit;
 }
Exemple #18
0
 /**
  * Find the absolute path to a file in a set of Themes.  You can optionally
  * send an array of themes to search.  If you do not, it will search active
  * then fallback (in that order).
  *
  * @param   string  $view    name of the view to find
  * @param   array   $themes  optional array of themes to search
  * @return  string  absolute path to the view
  * @throws  \ThemeException  when not found
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     // determine the path prefix and optionally the module path
     $path_prefix = '';
     $module_path = null;
     if ($this->config['use_modules'] and class_exists('Request', false) and $request = \Request::active() and $module = $request->module) {
         // we're using module name prefixing
         $path_prefix = $module . DS;
         // and modules are in a separate path
         is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/') . DS . $path_prefix;
         // do we need to check the module too?
         $this->config['use_modules'] === true and $module_path = \Module::exists($module) . 'themes' . DS;
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if ($module_path and !empty($theme['name']) and is_file($path = $module_path . $theme['name'] . DS . $file . $ext)) {
                 return $path;
             } elseif (is_file($path = $theme['path'] . $path_prefix . $file . $ext)) {
                 return $path;
             } elseif (is_file($path = $theme['path'] . $file . $ext)) {
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'] . $path_prefix, $file, $ext)) {
                 return $path;
             }
         }
     }
     // not found, return the viewname to fall back to the standard View processing
     return $view;
 }
Exemple #19
0
 /**
  * Find the controller that matches the route requested
  *
  * @param	Route  $match  the given Route object
  * @return	mixed  the match array or false
  */
 protected static function parse_match($match)
 {
     $namespace = '';
     $segments = $match->segments;
     $module = false;
     // First port of call: request for a module?
     if (\Module::exists($segments[0])) {
         // make the module known to the autoloader
         \Module::load($segments[0]);
         $match->module = array_shift($segments);
         $namespace .= ucfirst($match->module) . '\\';
         $module = $match->module;
     }
     if ($info = static::parse_segments($segments, $namespace, $module)) {
         $match->controller = $info['controller'];
         $match->action = $info['action'];
         $match->method_params = $info['method_params'];
         return $match;
     } else {
         return null;
     }
 }
Exemple #20
0
 /**
  * Creates the new Request object by getting a new URI object, then parsing
  * the uri with the Route class.
  *
  * Usage:
  *
  *     $request = new Request('foo/bar');
  *
  * @param   string  the uri string
  * @param   bool    whether or not to route the URI
  * @param   string  request method
  * @return  void
  */
 public function __construct($uri, $route = true, $method = null)
 {
     $this->uri = new \Uri($uri);
     $this->method = $method;
     logger(\Fuel::L_INFO, 'Creating a new Request with URI = "' . $uri . '"', __METHOD__);
     // check if a module was requested
     if (count($this->uri->segments()) and $module_path = \Module::exists($this->uri->get_segment(0))) {
         // check if the module has routes
         if (is_file($module_path .= 'config/routes.php')) {
             $module = $this->uri->segments[0];
             // load and add the module routes
             $module_routes = \Fuel::load($module_path);
             $prepped_routes = array();
             foreach ($module_routes as $name => $_route) {
                 if ($name === '_root_') {
                     $name = $module;
                 } elseif (strpos($name, $module . '/') !== 0 and $name != $module and $name !== '_404_') {
                     $name = $module . '/' . $name;
                 }
                 $prepped_routes[$name] = $_route;
             }
             // update the loaded list of routes
             \Router::add($prepped_routes, null, true);
         }
     }
     $this->route = \Router::process($this, $route);
     if (!$this->route) {
         return;
     }
     $this->module = $this->route->module;
     $this->controller = $this->route->controller;
     $this->action = $this->route->action;
     $this->method_params = $this->route->method_params;
     $this->named_params = $this->route->named_params;
     if ($this->route->module !== null) {
         $this->add_path(\Module::exists($this->module));
     }
 }
Exemple #21
0
 /**
  * generate the module
  * 
  * @param string $module_name the module name is StudlyCaps as PSR-1 specified.
  */
 public static function module($args)
 {
     $module_name = array_shift($args);
     $module_name = str_replace(' ', '', $module_name);
     if ($path = \Module::exists(strtolower($module_name))) {
         throw new Exception('A module named ' . $module_name . ' already exists at ' . $path);
         exit;
     }
     $module_paths = \Config::get('module_paths');
     $base = reset($module_paths);
     if (count($module_paths) > 1) {
         \Cli::write('Your app has multiple module paths defined. Please choose the appropriate path from the list below', 'yellow', 'blue');
         $options = array();
         foreach ($module_paths as $key => $path) {
             $idx = $key + 1;
             \Cli::write('[' . $idx . '] ' . $path);
             $options[] = $idx;
         }
         $path_idx = \Cli::prompt('Please choose the desired module path', $options);
         $base = $module_paths[$path_idx - 1];
     }
     $module_path = $base . strtolower($module_name) . DS;
     static::$create_folders[] = $module_path;
     static::$create_folders[] = $module_path . 'classes/controller/admin';
     static::$create_folders[] = $module_path . 'classes/model';
     static::$create_folders[] = $module_path . 'config';
     $languages = \Config::get('locales');
     if (is_array($languages) && !empty($languages)) {
         foreach ($languages as $key => $item) {
             static::$create_folders[] = $module_path . 'lang/' . $key;
         }
     } else {
         static::$create_folders[] = $module_path . 'lang/en';
     }
     unset($item, $key, $languages);
     static::$create_folders[] = $module_path . 'views/admin/templates/index';
     static::$create_folders[] = $module_path . 'views/front/templates/index';
     // create _module.php file
     static::createModuleFile($module_path, $module_name);
     // create [module name]admin.php file for define permissions
     static::createAdminFile($module_path, $module_name);
     // create config file
     static::createConfig($module_path, $module_name);
     // create language files
     static::createLangFiles($module_path, $module_name);
     // create controllers
     static::createControllers($module_path, $module_name);
     // create views
     static::createViews($module_path, $module_name);
     $result = static::build();
     if (isset($result) && $result === true) {
         \Cli::write('Completed create folders.');
     }
     unset($result);
 }
 /**
  * Find the URL prefix for a given entity
  * 
  * @param  \CMF\Model\Base $entity
  * @return string
  */
 protected function getPrefix($entity)
 {
     $entity_class = get_class($entity);
     $metadata = $entity_class::metadata();
     $entity_class = $metadata->name;
     $entity_namespace = $entity_class::getModule();
     $module = \Module::exists($entity_namespace);
     $prefix = $entity->urlPrefix();
     if ($module !== false && $entity_namespace != '') {
         $module_prefix = \Arr::get($this->moduleUrls, $entity_namespace, $entity_namespace);
         if (strpos($prefix, '/' . $module_prefix) === 0) {
             return $prefix;
         }
         return "/{$module_prefix}" . $prefix;
     }
     return $prefix;
 }
Exemple #23
0
                    $module = new $codename();
                    echo $module->getContent();
                    define('MODULE', u0);
                } catch (Exception $e) {
                    define('MODULE', 'error_404-module');
                    echo $e->getMessage() . '<br/><br/>In file <strong>' . $e->getFile() . '</strong> ar line ' . $e->getLine() . '';
                    //				not_found(t('Podstrona <strong>%page</strong> nie istnieje.', array('%page' => u0)), array(
                    //					'Moduł obsługujący nie jest zainstalowany.',
                    //					'FIRST_404_COUSE',
                    //					'SECOND_404_COUSE'));
                }
        }
    } else {
        try {
            $codename = Kio::getConfig('front_page');
            if (!Module::exists($codename)) {
                throw new Exception(t('Module dosn&apos;t exists'));
            }
            require_once ROOT . 'modules/' . $codename . '/' . $codename . '.module.php';
            $module = new $codename();
            echo $module->getContent();
            define('MODULE', $codename);
        } catch (Exception $e) {
            define('MODULE', 'error_404-module');
            echo $e->getMessage() . '<br/>' . $e->getFile() . ':' . $e->getLine();
        }
        //if (!$module->name) $module->name = end($kio->path);
    }
}
if (!$module->name) {
    $module->name = Kio::getModuleName();
Exemple #24
0
 private static function _find_migration_number()
 {
     $base_path = APPPATH;
     if ($module = \Cli::option('module')) {
         if (!($base_path = \Module::exists($module))) {
             throw new Exception('Module ' . $module . ' was not found within any of the defined module paths');
         }
     }
     $files = new \GlobIterator($base_path . 'migrations/*_*.php');
     try {
         $migrations = array();
         foreach ($files as $file) {
             $migrations[] = $file->getPathname();
         }
         sort($migrations);
         list($last) = explode('_', basename(end($migrations)));
     } catch (\LogicException $e) {
         throw new Exception("Unable to read existing migrations. Path does not exist, or you may have an 'open_basedir' defined");
     }
     return str_pad($last + 1, 3, '0', STR_PAD_LEFT);
 }
Exemple #25
0
<h1>Test account apis</h1>

<h3>Hash password</h3>
<?php 
// stored password.
$password = '******';
// this module path.
$testmod_path = \Module::exists('testmod');
?>
<p>
    password: <?php 
echo $password;
?>
<br>
    hashed password: <?php 
$hashed_pass = $account_model->hashPassword('pass');
echo $hashed_pass;
?>
 
</p>

<h3>Check password</h3>
stored password: <?php 
echo $password;
?>
<br>
entered password: notpass || result: <?php 
var_dump($account_model->checkPassword('notpass', $hashed_pass));
?>
<br>
entered password: <?php