Esempio n. 1
0
 public static function getInstance()
 {
     if (!is_object(self::$instance)) {
         self::$instance = new i18n();
     }
     return self::$instance;
 }
Esempio n. 2
0
File: i18n.php Progetto: swk/bluebox
 /**
  * Create an instance if one does not already exists
  * or return the current instance
  *
  * @return void
  */
 public static function instance($args = '')
 {
     //instantiate i18n if necessary and store the instance
     if (!isset(self::$instance)) {
         self::$instance = new i18n();
     }
     // If there are no args passed then return the instance
     // without setting the iteration vars
     if (empty($args)) {
         return self::$instance;
     }
     // clear the iteration specific values
     self::$message = '';
     self::$args = self::$options = array();
     // If there is an array of arguments then the first is assumed
     // to be the message and the rest are stored in args
     if (is_array($args)) {
         self::$message = reset($args);
         array_shift($args);
         self::$args = $args;
     } else {
         // if the args are not an array then we recieved just a message
         self::$message = $args;
     }
     // return the instance to allow method chaining
     return self::$instance;
 }
Esempio n. 3
0
 public static function get_instance()
 {
     if (!self::$instance instanceof self) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Esempio n. 4
0
 public function __construct()
 {
     /*****************
      * GENERAL SETUP *
      *****************/
     // Guess at the baseModel name if none has been set. Use the controller's basename as the guess
     if (!$this->baseModel) {
         $this->baseModel = ucfirst(str_replace('_Controller', '', get_class()));
     }
     // Instantiate sessions
     $this->session = Session::instance();
     if (!request::is_ajax()) {
         $this->session->set('ajax.base_controller', strtolower(Router::$controller));
         $this->session->set('ajax.base_method', strtolower(Router::$method));
     }
     // Instantiate internationalization
     $this->i18n = i18n::instance();
     /**
      * TODO: This is so nasty...
      */
     if (!empty($_POST['lang'])) {
         if (empty(i18n::$langs[$_POST['lang']])) {
             die;
         }
         $this->session->set('lang', $_POST['lang']);
         echo i18n::$langs[$_POST['lang']];
         die;
     }
     // Create a static validator, if one does not already exist. By default we populate it with post variables
     // This will hold all errors that occur within Doctrine and provides easy access for the controller to grab those errors
     // Note carefully that this is intentionally a singleton - Doctrine does not otherwise know which controller is associated
     // with which record. This implies that your errors will get stacked up on top of each other, but since it's one controller
     // per run of Kohana, we should be OK here. You can also use Kohana's validation class methods here, too.
     // FIXME: This should be moved!!!
     self::$validation = new Validation($_POST);
     // Setup anything related to this website's pages rendering
     Event::run('bluebox.setup', $this);
     // Setup anything related to authenticating the user
     Event::run('bluebox.authenticate', $this);
     // Setup anything related to authorizing the user
     Event::run('bluebox.authorize', $this);
     /*******************
      * RENDERING SETUP *
      *******************/
     // For safety, fail back to HTML if this is not set
     if (!defined('CONTENT_TYPE')) {
         // take all the URL elements used for routing and explode on /
         $pathParts = explode('/', Router::$current_uri);
         $content_type = 'html';
         foreach ($pathParts as $part) {
             // see if there is an extension on each part
             $extension = pathinfo($part, PATHINFO_EXTENSION);
             // if we find a html, json, xml extension then save it, keeping the last found extension
             if (!empty($extension) && in_array(strtolower($extension), array('html', 'json', 'xml'))) {
                 $content_type = strtolower($extension);
             }
         }
         define('CONTENT_TYPE', $content_type);
     }
     // Set the default template, viewName and failback view to use, based on the content type.
     // NOTE: It's perfectly fine to override this in the template setup hooks
     switch (CONTENT_TYPE) {
         case 'json':
             $this->viewParams['template'] = 'json/layout';
             $this->viewParams['name'] = Router::$controller . '/json/' . Router::$method;
             $this->viewParams['fallback'] = 'NO CONTENT';
             break;
         case 'xml':
             $this->viewParams['template'] = 'xml/layout';
             $this->viewParams['name'] = Router::$controller . '/xml/' . Router::$method;
             $this->viewParams['fallback'] = '<xml><error>No Content</error></xml>';
             break;
         default:
             if (request::is_ajax() or !empty($_REQUEST['qtipAjaxForm'])) {
                 $this->viewParams['template'] = 'ajax';
             } else {
                 $this->viewParams['template'] = 'layout';
             }
             $this->viewParams['name'] = Router::$controller . '/' . Router::$method;
             $this->viewParams['fallback'] = 'ERROR: There is no viewable content for this page';
             break;
     }
     // NOTE: You can optionally set $viewFolder here to try an alternate folder for all views.
     // If the view doesn't exist, $viewFolder is ignored
     $this->viewParams['folder'] = '';
     // Call all setup hooks related to content type.
     Event::run('bluebox.createtemplate.' . CONTENT_TYPE, $this);
     /********************
      * PREPARE TEMPLATE *
      ********************/
     $this->template = $this->viewParams['folder'] . $this->viewParams['template'];
     // Call our parent controller's constructor
     // NOTE: This prepares our view and converts $this->template into an object.
     // Changes to $this->viewParams['template'] are ignored past this point
     parent::__construct();
     /*******************
      * PREPARE CONTENT *
      *******************/
     if (CONTENT_TYPE == 'html') {
         // Initialize default HTML content
         $this->template->css = '';
         $this->template->js = '';
         $this->template->meta = '';
         $this->template->header = '';
         $this->template->footer = '';
         // Set the page title
         $this->template->title = ucfirst(Router::$controller);
         if (Router::$method != 'index') {
             // Index is always a boring name, don't use it (but use everything else)
             $this->template->title .= ' -> ' . ucfirst(Router::$method);
         }
     }
     try {
         $this->template->content = new View($this->viewParams['folder'] . $this->viewParams['name']);
     } catch (Exception $e) {
         try {
             $this->template->content = new View($this->viewParams['name']);
         } catch (Exception $e) {
             $this->template->content = new View();
             $this->template->body = $this->viewParams['fallback'];
         }
     }
     /********************
      * FINALIZE CONTENT *
      ********************/
     // Make it easier to get to and remember how to access the core view by setting up a reference to the template, called view
     $this->view =& $this->template->content;
     // Call the constructor's for all plugins registered
     plugins::construct();
     // Setup anything related to authorizing the user
     Event::run('bluebox.ready', $this);
 }