Ejemplo n.º 1
0
 /**
  * Factory
  *
  * Produces fully configured session driver instances
  *
  * @param	array|string	full driver config or just driver type
  */
 public static function forge($custom = array())
 {
     $config = \Config::get('session', array());
     // When a string was passed it's just the driver type
     if (!empty($custom) and !is_array($custom)) {
         $custom = array('driver' => $custom);
     }
     $config = array_merge(static::$_defaults, $config, $custom);
     if (empty($config['driver'])) {
         throw new \Session_Exception('No session driver given or no default session driver set.');
     }
     // determine the driver to load
     $class = '\\Session_' . ucfirst($config['driver']);
     $driver = new $class($config);
     // get the driver's cookie name
     $cookie = $driver->get_config('cookie_name');
     // do we already have a driver instance for this cookie?
     if (isset(static::$_instances[$cookie])) {
         // if so, they must be using the same driver class!
         $class_instance = 'Fuel\\Core\\' . $class;
         if (static::$_instances[$cookie] instanceof $class_instance) {
             throw new \FuelException('You can not instantiate two different sessions using the same cookie name "' . $cookie . '"');
         }
     } else {
         // register a shutdown event to update the session
         \Event::register('shutdown', array($driver, 'write'));
         // init the session
         $driver->init();
         $driver->read();
         // store this instance
         static::$_instances[$cookie] =& $driver;
     }
     return static::$_instances[$cookie];
 }
Ejemplo n.º 2
0
 /**
  * Loads in all the messages from flash.
  *
  * @return  void
  */
 public function __construct($name = 'messages')
 {
     $this->instance = $name;
     $this->messages = \Session::get_flash($this->instance, array());
     // register a shutdown event to write messages to flash
     \Event::register('shutdown', array($this, 'shutdown'), true);
 }
Ejemplo n.º 3
0
 public function __construct()
 {
     // If the CI object is needed :
     self::$ci =& get_instance();
     // Register the Event :
     // Event::register(<event_name>, array($this, 'on_public_load'));
     Event::register('Filemanager.move.success', array($this, 'on_filemanager_move_success'));
     Event::register('Filemanager.destroy.success', array($this, 'on_filemanager_destroy_success'));
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     // If the CI object is needed :
     self::$ci =& get_instance();
     // Register the Event :
     // Event::register(<event_name>, array($this, 'on_public_load'));
     Event::register('Ionize.front.load', array($this, 'on_front_load'));
     Event::register('Article.save.before', array($this, 'on_article_save_before'));
 }
Ejemplo n.º 5
0
 /**
  * Runs on 'controller_started' event
  */
 public static function start()
 {
     $controller = \Request::active()->controller_instance;
     $nocache = \Input::param('nocache', \Session::get_flash('nocache', false, true));
     $controller_nocache = !is_null($controller) && method_exists($controller, 'cache') && $controller->cache() === false;
     // Don't run if it's already started, if we have a POST or if the controller says not to
     if ($nocache !== false || strtolower(\Input::method()) == 'post' || $controller_nocache) {
         if (static::$started === true) {
             static::stop();
         }
         return false;
     }
     $config = \Config::get('cmf.cache');
     if ($config['enabled'] !== true) {
         return;
     }
     // Check for excluded URLS
     $uri = '/' . str_replace(array('?debug', '&debug'), '', trim($_SERVER['REQUEST_URI'], '/'));
     if ($uriPath = parse_url($uri, PHP_URL_PATH)) {
         $uri = $uriPath;
     }
     $jq = \Input::get('_', null);
     if ($jq !== null) {
         $uri = str_replace(array("?_={$jq}", "&_={$jq}"), '', $uri);
     }
     $excluded_urls = $config['excluded_urls'];
     foreach ($excluded_urls as $url) {
         $url = \Uri::create($url);
         if ($urlPath = parse_url($url, PHP_URL_PATH)) {
             $url = $urlPath;
         }
         if (strpos($url, '*') !== false && strpos($uri . '/', str_replace('*', '', $url)) === 0) {
             return;
         }
         if ($uri == $url) {
             return;
         }
     }
     // Create the driver and try to get cached content from it
     $driver = static::driver();
     static::$started = true;
     // Add any extra files to check
     $files = \Arr::get($config, 'check_files', array());
     foreach ($files as $file) {
         $driver->addFile($file);
     }
     // Try and get the cached content
     $content = $driver->get($uri);
     // Serve the cached content if found, or continue and add the finish listener
     if (static::$active = $content !== false) {
         $driver->serve($content, static::$modified);
     } else {
         \Event::register('request_finished', 'CMF\\Cache::finish');
     }
 }
Ejemplo n.º 6
0
 public function set($response)
 {
     if ($response->status !== 200) {
         return;
     }
     $this->request = \Request::active();
     $view = $this->request->response->body;
     $driver = $this;
     \Event::register('shutdown', function () use($driver) {
         $driver->shutdown();
     });
 }
Ejemplo n.º 7
0
 public function __construct($config)
 {
     $this->config = $config;
     $this->config['auto_save'] and \Event::register('shutdown', array($this, 'save'));
     $items = $this->config_get('items', '');
     empty($items) and $items = $this->_get($this->config['storage_key']);
     is_string($items) and $items = unserialize(stripslashes($items));
     foreach ($items as $rowid => $item) {
         $content = is_object($item) ? $item->_as_array() : $item;
         $this->items[$rowid] = new \Cart_Item($content, &$this, $rowid);
     }
 }
Ejemplo n.º 8
0
 public function __construct()
 {
     $shutdown = function () {
         $quiet = \Cli::option('quiet', \Cli::option('q', false));
         $quiet or \Cli::write(PHP_EOL . 'Worker ' . getmypid() . ' is stopping', 'red');
     };
     try {
         pcntl_signal(SIGINT, $shutdown);
         pcntl_signal(SIGINT, function () {
             exit;
         });
     } catch (\PhpErrorException $e) {
     }
     \Event::register('shutdown', $shutdown);
 }
Ejemplo n.º 9
0
 public function __set($name, $value)
 {
     if (FALSE === $this->template) {
         $dispatcher = \Dispatcher::getInstance();
         $this->template = $dispatcher->controller() . '/' . $dispatcher->action();
     }
     if (is_string($this->template)) {
         $this->template = new \View($this->template);
         if (!$this->render) {
             $ref = new \ReflectionMethod($this, 'render');
             $ref->setAccessible(TRUE);
             \Event::register(\Dispatcher::PostDispatch, array($ref, 'invoke'), array($this));
             $this->render = TRUE;
         }
     }
     $this->template->set($name, $value);
 }
Ejemplo n.º 10
0
 /**
  * @param $user	Ionize\User
  */
 public static function initialize($user)
 {
     log_message('debug', "Authority Class Initialized");
     static::$initialized = TRUE;
     self::$ci =& get_instance();
     self::$ci->load->library('session');
     self::$session =& self::$ci->session;
     Event::register('User.logout', array(__CLASS__, 'on_logout'));
     Event::register('User.login', array(__CLASS__, 'on_login'));
     if ($user->logged_in()) {
         // Super Admin shortcut : Will never depend on DB.
         if ($user->is('super-admin')) {
             Authority::allow('manage', 'all');
         } else {
             // Set Rules from DB or session
             self::set_rules($user);
         }
     }
 }
Ejemplo n.º 11
0
 public function __construct()
 {
     // If the CI object is needed :
     self::$ci =& get_instance();
     // Config Events
     $config = Modules()->get_module_config('Sfs');
     $events = explode(',', $config['events']);
     // ionize < 1.0.4 hack : Be able to load module libraries
     $installed_modules = Modules()->get_installed_modules();
     foreach ($installed_modules as $module) {
         if (isset($module['folder'])) {
             Finder::add_path(MODPATH . $module['folder'] . '/');
         }
     }
     // Stop Forum Spam lib
     // @TODO : Enhance here to handle more services:
     // 1. Create one lib / service
     // 2. Rewrite the config system, which should have one key / service
     self::$ci->load->library('Sfs_Sfs');
     foreach ($events as $event) {
         $event = trim($event);
         Event::register($event, array('Sfs_Sfs', 'on_post_check_before'));
     }
 }
Ejemplo n.º 12
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \FuelException("You can't initialize Fuel more than once.");
     }
     static::$_paths = array(APPPATH, COREPATH);
     // Is Fuel running on the command line?
     static::$is_cli = (bool) defined('STDIN');
     \Config::load($config);
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         \Finder::instance()->read_cache('Fuel::paths');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     static::$encoding = \Config::get('encoding', static::$encoding);
     MBSTRING and mb_internal_encoding(static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
     }
     // Run Input Filtering
     \Security::clean_input();
     \Event::register('shutdown', 'Fuel::finish');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package => $path) {
         is_string($package) and $path = array($package => $path);
         \Package::load($path);
     }
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set  locale
     static::$locale and setlocale(LC_ALL, static::$locale);
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Ejemplo n.º 13
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \FuelException("You can't initialize Fuel more than once.");
     }
     static::$_paths = array(APPPATH, COREPATH);
     // Is Fuel running on the command line?
     static::$is_cli = (bool) defined('STDIN');
     \Config::load($config);
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         \Finder::instance()->read_cache('Fuel::paths');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     static::$encoding = \Config::get('encoding', static::$encoding);
     MBSTRING and mb_internal_encoding(static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
     }
     // Run Input Filtering
     \Security::clean_input();
     \Event::register('shutdown', 'Fuel::finish');
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set locale, log warning when it fails
     if (static::$locale) {
         setlocale(LC_ALL, static::$locale) or logger(\Fuel::L_WARNING, 'The configured locale ' . static::$locale . ' is not installed on your system.', __METHOD__);
     }
     static::$initialized = true;
     // fire any app created events
     \Event::instance()->has_events('app_created') and \Event::instance()->trigger('app_created', '', 'none');
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Ejemplo n.º 14
0
 protected function setUp()
 {
     Event::register('test', function (&$data = null) {
         $data = 'ok';
     });
 }
Ejemplo n.º 15
0
 /**
  * Executed every time a user is authorized.
  *
  * <code>
  * Warden::after_authorization(function($user) {
  *      logger(\Fuel::L_INFO, 'User '.$user->id.' was successfully authorized to access '.\Input::server('REQUEST_URI'));
  * });
  *
  * // OR
  *
  * Warden::after_authorization('Myclass::method');
  * </code>
  *
  * @param mixed $callback The callable function to execute
  *
  * @uses \Fuel\Core\Event::register()
  */
 public static function after_authorization($callback)
 {
     \Event::register('warden_after_authorization', $callback);
 }
Ejemplo n.º 16
0
 public static function _init()
 {
     static::$messages = Session::get_flash('messages', []);
     // register a shutdown event to write messages to flash
     Event::register('shutdown', 'Messages::shutdown', true);
 }
Ejemplo n.º 17
0
/******************************
------Глобальные объекты-------
******************************/
App::setProperty('test', 'test_value');
/******************************
-----------События-------------
******************************/
Event::register('test', function (&$data) {
    echo "firstHandler\n";
    $data['testEvent'] = 'triggered';
});
Event::register('test', function ($data = null) {
    echo "secondHandler\n";
});
Event::register('another', function ($data = null) {
    echo "anotherHandler\n";
});
/******************************
-----------Маршруты------------
******************************/
// error 404
Route::error('PageNotFound', function () {
    Response::status(404);
    return Response::text('404 страница не найдена');
});
// index
Route::any('/', 'Index@index');
Route::any('/test_model', 'Index@testModel');
Route::any('/user', 'Index@user');
Route::any('/rows', 'Index@rows');
Route::any('/products', 'Index@products');
Ejemplo n.º 18
0
 /**
  * Test for Event::register()
  *
  * @test
  */
 public function test_register_invalid()
 {
     $output = Event::register('test_register_invalid', 'Imaginary::callback');
     $this->assertFalse($output);
 }
Ejemplo n.º 19
0
 /**
  * When autoloaded this will method will be fired, load once and once only
  * 
  * @static
  * @access public
  */
 public static function _init()
 {
     \Event::register('load_language', '\\Factory::load_language');
     \Event::register('load_acl', '\\Factory::load_acl');
 }
Ejemplo n.º 20
0
 /**
  * Initialize the manager (and plugins)
  */
 public static function initialize()
 {
     self::initializePlugins();
     Event::register('before', 'rest_request', get_called_class() . '::handlePluginRESTRequest');
 }
Ejemplo n.º 21
0
 public function action_index()
 {
     Event::register('shutdown', 'Test::event_test', '引数1', '引数2');
 }
Ejemplo n.º 22
0
<?php

class Event
{
    public static $events = array();
    public static function fire($event, $args = array())
    {
        if (isset(self::$events[$event])) {
            foreach (self::$events[$event] as $func) {
                call_user_func_array($func, $args);
            }
        }
    }
    public static function register($event, Closure $func)
    {
        self::$events[$event][] = $func;
    }
}
Event::register('error', function ($args = array('to' => null, 'text' => null, 'subject' => null)) {
    include_once ENGINE_PATH . 'class/classMail.php';
    $subject = isset($args['subject']) ? $args['subject'] : "[error] {$_SERVER['HTTP_HOST']} ";
    $mail = new SMTP_Mail();
    $mail->add_text($args['text']);
    $mail->build_message();
    $to = isset($args['to']) ? $args['to'] : '*****@*****.**';
    @$mail->send($to, 'noreaply@' . $_SERVER['HTTP_HOST'], $subject);
});
Ejemplo n.º 23
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     \Config::load($config);
     if (static::$initialized) {
         throw new \Fuel_Exception("You can't initialize Fuel more than once.");
     }
     register_shutdown_function('fuel_shutdown_handler');
     set_exception_handler('fuel_exception_handler');
     set_error_handler('fuel_error_handler');
     // Start up output buffering
     ob_start(\Config::get('ob_callback', null));
     static::$profiling = \Config::get('profiling', false);
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = \Config::get('cache_dir', APPPATH . 'cache/');
     static::$caching = \Config::get('caching', false);
     static::$cache_lifetime = \Config::get('cache_lifetime', 3600);
     if (static::$caching) {
         static::$path_cache = static::cache('Fuel::path_cache');
     }
     // set a default timezone if one is defined
     static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
     date_default_timezone_set(static::$timezone);
     // set the encoding and locale to use
     static::$encoding = \Config::get('encoding', static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     static::$_paths = array(APPPATH, COREPATH);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
         \Uri::detect();
     }
     // Run Input Filtering
     \Security::clean_input();
     static::$env = \Config::get('environment');
     \Event::register('shutdown', 'Fuel::finish');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package => $path) {
         is_string($package) and $path = array($package => $path);
         static::add_package($path);
     }
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set  locale
     static::$locale and setlocale(LC_ALL, static::$locale);
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Ejemplo n.º 24
0
    }
    // Only care about our custom endpoint
    $event->stopPropagation();
    // Forbid any remaining handlers to run
    $event->preventDefault();
    // prevent default endpoint lookup and execution
    if ($request->method != 'get') {
        throw new RestException('rest_method_not_implemented', 501);
    }
    $event->result = array('r' => $request, 'bar' => $request->path);
    // Set our own data to be sent to the client after json encoding
});
Event::register('after', 'rest_request', function ($event) {
    $request = $event->data[0];
    if ($request->endpoint != 'vote') {
        return;
    }
    // Only care about our custom endpoint
    if ($request->method != 'get') {
        return;
    }
    if (!is_array($event->result)) {
        return;
    }
    $event->result[0]['toto'] = 'tata';
});
Event::register(Event::AFTER, 'resource_items', function ($event) {
    $event->result[0] = preg_replace('`</a>`', ' {tr:yes}</a>', $event->result[0]);
    $event->result[] = '<a href="http://renater.fr">RENATER</a>';
    $event->result[] = '<a href="{url:home}">{tr:home_page}</a>';
});
Ejemplo n.º 25
0
} else {
    if (\Config::get('cmf.module_urls', false) !== false) {
        \Config::set('security.uri_filter', array_merge(array('\\CMF::module_url_filter'), \Config::get('security.uri_filter')));
    }
}
// Load up the required packages
Package::load(array('email', 'parser'));
// Override some external classes
Autoloader::add_core_namespace('CMF\\Core', true);
Autoloader::add_classes(array('CMF\\Core\\View_Twig' => __DIR__ . '/classes/CMF/Core/View_Twig.php', 'CMF\\Core\\Image_Driver' => __DIR__ . '/classes/CMF/Core/Image_Driver.php', 'CMF\\Core\\Lang' => __DIR__ . '/classes/CMF/Core/Lang.php', 'CMF\\Core\\Format' => __DIR__ . '/classes/CMF/Core/Format.php', 'CMF\\Core\\Error' => __DIR__ . '/classes/CMF/Core/Error.php', 'CMF\\Core\\HttpException' => __DIR__ . '/classes/CMF/Core/HttpException.php'));
// Sort out the language
\Lang::load('errors', true);
\Lang::load('admin', true);
\Lang::load('site', true);
$lang = \CMF::lang();
// Quick and easy profiling using 'debug' in the query string
if (isset($_GET['debug']) && !\Fuel::$profiling) {
    \Fuel::$profiling = true;
    \Profiler::init();
    \Config::load('db', true);
    \Config::set('db.default.profiling', true);
}
// Listen for events at the beginning of the request for caching
\Event::register('controller_started', 'CMF\\Cache::start');
// Add CMF's modules directory so it's modules can be autoloaded
$module_paths = Config::get('module_paths');
$module_paths[] = CMFPATH . 'modules/';
Config::set('module_paths', $module_paths);
if ($isAdmin) {
    \Admin::initialize();
}
Ejemplo n.º 26
0
 /**
  * Initializes the framework.
  * This can only be called once.
  *
  * @access public
  * @return void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \FuelException("You can't initialize Fuel more than once.");
     }
     // BC FIX FOR APPLICATIONS <= 1.6.1, makes Redis_Db available as Redis,
     // like it was in versions before 1.7
     class_exists('Redis', false) or class_alias('Redis_Db', 'Redis');
     static::$_paths = array(APPPATH, COREPATH);
     // Is Fuel running on the command line?
     static::$is_cli = (bool) defined('STDIN');
     \Config::load($config);
     // Start up output buffering
     static::$is_cli or ob_start(\Config::get('ob_callback', null));
     if (\Config::get('caching', false)) {
         \Finder::instance()->read_cache('FuelFileFinder');
     }
     static::$profiling = \Config::get('profiling', false);
     static::$profiling and \Profiler::init();
     // set a default timezone if one is defined
     try {
         static::$timezone = \Config::get('default_timezone') ?: date_default_timezone_get();
         date_default_timezone_set(static::$timezone);
     } catch (\Exception $e) {
         date_default_timezone_set('UTC');
         throw new \PHPErrorException($e->getMessage());
     }
     static::$encoding = \Config::get('encoding', static::$encoding);
     MBSTRING and mb_internal_encoding(static::$encoding);
     static::$locale = \Config::get('locale', static::$locale);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
     }
     // Run Input Filtering
     \Security::clean_input();
     \Event::register('fuel-shutdown', 'Fuel::finish');
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set locale, log warning when it fails
     if (static::$locale) {
         setlocale(LC_ALL, static::$locale) or logger(\Fuel::L_WARNING, 'The configured locale ' . static::$locale . ' is not installed on your system.', __METHOD__);
     }
     static::$initialized = true;
     // fire any app created events
     \Event::instance()->has_events('app_created') and \Event::instance()->trigger('app_created', '', 'none');
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }
Ejemplo n.º 27
0
Archivo: file.php Proyecto: wushian/MDD
 /**
  * Download a file
  *
  * @param  string       file path
  * @param  string|null  custom name for the file to be downloaded
  * @param  string|null  custom mime type or null for file mime type
  * @param  string|File_Area|null  file area name, object or null for base area
  */
 public static function download($path, $name = null, $mime = null, $area = null)
 {
     $info = static::file_info($path, $area);
     $class = get_called_class();
     empty($mime) or $info['mimetype'] = $mime;
     empty($name) or $info['basename'] = $name;
     \Event::register('shutdown', function () use($info, $area, $class) {
         if (!($file = call_user_func(array($class, 'open_file'), @fopen($info['realpath'], 'rb'), LOCK_SH, $area))) {
             throw new \FileAccessException('Filename given could not be opened for download.');
         }
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         ini_get('zlib.output_compression') and ini_set('zlib.output_compression', 0);
         !ini_get('safe_mode') and set_time_limit(0);
         header('Content-Type: ' . $info['mimetype']);
         header('Content-Disposition: attachment; filename="' . $info['basename'] . '"');
         header('Content-Description: File Transfer');
         header('Content-Length: ' . $info['size']);
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         while (!feof($file)) {
             echo fread($file, 2048);
         }
         call_user_func(array($class, 'close_file'), $file, $area);
     });
     exit;
 }
Ejemplo n.º 28
0
 /**
  * Gets the current language from either TLD, URL prefix or 
  */
 public static function lang()
 {
     if (static::$lang !== null) {
         return static::$lang;
     }
     // Give up if we haven't enabled multi lingual
     if (!(static::$lang_enabled = \Config::get('cmf.languages.enabled', false))) {
         return static::$lang = \Lang::get_lang();
     }
     // First load our languages
     \Lang::load('languages', true);
     // Get the language from cookies
     $iso = \Cookie::get('default_language');
     $fallback = \Lang::get_lang();
     // Get the language from URL
     if (!$iso) {
         $languages = static::languages();
         $host = preg_replace("/^www\\./i", '', strtolower(\Input::server('HTTP_HOST', '')));
         foreach ($languages as $language) {
             if ($tld = \Arr::get($language, 'top_level_domain')) {
                 $parts = array_filter(array_map(function ($part) {
                     return preg_replace("/^www\\./i", '', strtolower(trim($part)));
                 }, explode(',', $tld)));
                 if (in_array($host, $parts)) {
                     $iso = $language['code'];
                     break;
                 }
             }
         }
     }
     // Get the language from the request
     if (!$iso) {
         $iso = strtolower(\Arr::get(explode('/', static::original_uri()), 1, \Lang::get_lang()) . "");
         if (strpos($iso, '_') !== false) {
             $parts = explode('_', $iso);
             $iso = strtolower($parts[0]) . '_' . strtoupper($parts[1]);
         }
         if (\Lang::_get("languages.{$iso}", array(), 'notfound') == 'notfound') {
             $iso = \Lang::get_lang();
         }
     }
     // Set the languages into Fuel for future reference
     \Config::set('language_fallback', $fallback);
     \Config::set('language', $iso);
     \CMF\Doctrine\Extensions\Translatable::setLang($iso);
     // Load the languages back in, now we might have a translation for them
     if ($fallback != $iso) {
         \Lang::load('errors', true, $iso, false, true);
         \Lang::load('languages', true, $iso, false, true);
         \Lang::load('admin', true, $iso, false, true);
         \Lang::load('site', true, $iso, false, true);
         static::$lang_prefix = "/{$iso}";
     }
     // Set the uri filter so we don't see the lang prefix
     \Config::set('security.uri_filter', array_merge(array('\\CMF::removeLangPrefix'), \Config::get('security.uri_filter')));
     // Log to console
     if (\Fuel::$profiling) {
         \Profiler::console('Language is ' . $iso);
     }
     // Add shutdown event to catch unsaved translation strings
     \Event::register('shutdown', 'Lang::shutdown');
     // Set the lang vars
     static::$lang_default = $fallback;
     static::$lang = $iso;
     // Set locale if necessary
     if (is_array($locale_map = \Config::get('locale_map')) && ($new_locale = \Arr::get($locale_map, $iso))) {
         $result = setlocale(LC_TIME, $new_locale);
         if ($result !== false) {
             \Fuel::$locale = $result;
             \Config::set('locale', $result);
             if (class_exists('Locale')) {
                 \Locale::setDefault($result);
             }
         }
     }
     // Redirect to default language if this one isn't configured
     if (!array_key_exists($iso, static::languages()) && array_key_exists($fallback, static::languages())) {
         \Response::redirect(static::link(\Input::uri(), $fallback));
     }
     return $iso;
 }
Ejemplo n.º 29
0
 /**
  * Initializes the framework.  This can only be called once.
  *
  * @access	public
  * @return	void
  */
 public static function init($config)
 {
     if (static::$initialized) {
         throw new \Fuel_Exception("You can't initialize Fuel more than once.");
     }
     register_shutdown_function('fuel_shutdown_handler');
     set_exception_handler('fuel_exception_handler');
     set_error_handler('fuel_error_handler');
     // Start up output buffering
     ob_start();
     static::$profiling = isset($config['profiling']) ? $config['profiling'] : false;
     if (static::$profiling) {
         \Profiler::init();
         \Profiler::mark(__METHOD__ . ' Start');
     }
     static::$cache_dir = isset($config['cache_dir']) ? $config['cache_dir'] : APPPATH . 'cache/';
     static::$caching = isset($config['caching']) ? $config['caching'] : false;
     static::$cache_lifetime = isset($config['cache_lifetime']) ? $config['cache_lifetime'] : 3600;
     if (static::$caching) {
         static::$path_cache = static::cache('Fuel::path_cache');
     }
     \Config::load($config);
     static::$_paths = array(APPPATH, COREPATH);
     if (!static::$is_cli) {
         if (\Config::get('base_url') === null) {
             \Config::set('base_url', static::generate_base_url());
         }
         \Uri::detect();
     }
     // Run Input Filtering
     \Security::clean_input();
     static::$env = \Config::get('environment');
     static::$locale = \Config::get('locale');
     \Event::register('shutdown', 'Fuel::finish');
     //Load in the packages
     foreach (\Config::get('always_load.packages', array()) as $package) {
         static::add_package($package);
     }
     // Load in the routes
     \Config::load('routes', true);
     \Router::add(\Config::get('routes'));
     // Set some server options
     setlocale(LC_ALL, static::$locale);
     // Always load classes, config & language set in always_load.php config
     static::always_load();
     static::$initialized = true;
     if (static::$profiling) {
         \Profiler::mark(__METHOD__ . ' End');
     }
 }