Exemplo n.º 1
0
Arquivo: view.php Projeto: azuya/Wi3
 public function set_filename($file)
 {
     // Get path for possible translations
     if (strrpos($file, "/") !== FALSE) {
         $split = strrpos($file, "/");
         $firstpart = substr($file, 0, $split + 1);
         // The +1 to catch the /
         $lastpart = substr($file, $split + 1);
     } else {
         $firstpart = "";
         $lastpart = $file;
     }
     // Try to get translated view, with complete area suffix (e.g. en-us)
     try {
         parent::set_filename($firstpart . "i18n/" . i18n::lang() . "/" . $lastpart);
         // Will try to load file, and fail if file cannot be found
     } catch (Exception $e) {
         //  Try to get translated view for the overall language, without area suffix (e.g. 'en' from 'en-us')
         try {
             parent::set_filename($firstpart . "i18n/" . substr(i18n::lang(), 0, 2) . "/" . $lastpart);
         } catch (Exception $e) {
             parent::set_filename($file);
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * render current view
  * @return type
  * @throws Exception
  */
 public function renderView()
 {
     if (!$this->view) {
         throw new Exception(__METHOD__ . " set view first");
     }
     $rhtml = $this->view->render();
     return $rhtml;
 }
Exemplo n.º 3
0
 /**
  * Constructor
  *
  * @param array $data 
  * @author Jonathan Geiger
  */
 public function __construct($file = NULL, $data = NULL, $env = 'default')
 {
     parent::__construct($file, $data);
     // Allow passing a Twig_Environment
     if (is_string($env)) {
         $env = Kohana_Twig_Environment::instance($env);
     }
     $this->_environment = $env;
 }
Exemplo n.º 4
0
 public function __construct($options = NULL, array $data = NULL)
 {
     Kohana::$profiling === TRUE && ($bm = Profiler::start('View', __FUNCTION__));
     $this->_compile_dir = APPPATH . 'cache/haml/';
     if (!is_dir($this->_compile_dir)) {
         mkdir($this->_compile_dir, 0777, TRUE);
     }
     parent::__construct($options, $data);
     isset($bm) && Profiler::stop($bm);
 }
Exemplo n.º 5
0
 public function set_filename($file)
 {
     if (isset(self::$_files[$file])) {
         return parent::set_filename(self::$_files[$file]);
     }
     // На основе данных из Request попробуем сообразить, где искать нужный скрипт вида
     $request = Request::current();
     if ($request) {
         // Ищем файл либо в <directory>/<controller> и <directory>, либо в <controller>
         // в зависимости от того, указана ли <directory>
         $directory = mb_strtolower($request->directory());
         $controller = mb_strtolower($request->controller());
         if ($directory) {
             // <directory>/<controller>
             $new_file = $directory . '/' . $controller . '/' . $file;
             if (($path = Kohana::find_file('views', $new_file)) !== FALSE) {
                 self::$_files[$file] = $new_file;
                 return parent::set_filename($new_file);
             }
             // <directory>
             $new_file = $directory . '/' . $file;
             if (($path = Kohana::find_file('views', $new_file)) !== FALSE) {
                 self::$_files[$file] = $new_file;
                 return parent::set_filename($new_file);
             }
         } else {
             // <controller>
             $new_file = $controller . '/' . $file;
             if (($path = Kohana::find_file('views', $new_file)) !== FALSE) {
                 self::$_files[$file] = $new_file;
                 return parent::set_filename($new_file);
             }
         }
         // Если не нашли в подходящих директориях - пытаемся поискать в обычном месте
         if (($path = Kohana::find_file('views', $file)) !== FALSE) {
             self::$_files[$file] = $file;
             return parent::set_filename($file);
         }
         // Последний оплот - ядро экстази
         $new_file = 'extasy/' . $file;
         if (($path = Kohana::find_file('views', $new_file)) !== FALSE) {
             self::$_files[$file] = $new_file;
             return parent::set_filename($new_file);
         }
     }
     // Нигде не нашли - ну и пусть Kohana сама разбирается с этой ситуацией
     self::$_files[$file] = $file;
     return parent::set_filename($file);
 }
Exemplo n.º 6
0
 protected static function capture($kohana_view_filename, array $kohana_view_data)
 {
     $extension = func_get_args()[2];
     // is mustache ?
     // If it's not a mustache file, do the default:
     if ($extension == 'php') {
         return Kohana_View::capture($kohana_view_filename, $kohana_view_data);
     }
     // continue
     $vars = Arr::merge(self::kohanaVariables(), View::$_global_data);
     $vars = Arr::merge($vars, $kohana_view_data);
     $conf = Kohana::$config->load('mustache')->as_array();
     $mustache = new Mustache_Engine($conf);
     $tpl = $mustache->loadTemplate($kohana_view_filename);
     return $tpl->render($vars);
 }
Exemplo n.º 7
0
 /**
  * Captures the output that is generated when a view is included.
  * The view data will be extracted to make local variables. This method
  * is static to prevent object scope resolution.
  *
  * @param   string  filename
  * @param   array   variables
  * @return  string
  */
 protected static function capture($template, array $data)
 {
     if ($template == '') {
         return;
     }
     // Load Ksmarty only if it's activated and the template-extension matches
     $config = Kohana::$config->load('smarty');
     if ($config->integration && substr(strrchr($template, '.'), 1) == $config->template_ext) {
         // Get the Smarty instance
         $smarty = Ksmarty::instance();
         // Assign all the variables
         foreach ($data as $key => $value) {
             $smarty->assign($key, $value);
         }
         // Fetch the template output
         $output = $smarty->fetch($template);
     } else {
         $output = parent::capture($template, $data);
     }
     // Return the parsed output
     return $output;
 }
Exemplo n.º 8
0
 /**
  * Loads test suite
  */
 public function before()
 {
     parent::before();
     if (!Unittest_tests::enabled()) {
         // Pretend this is a normal 404 error...
         $this->status = 404;
         throw new Kohana_Request_Exception('Unable to find a route to match the URI: :uri', array(':uri' => $this->request->uri()));
     }
     // Prevent the whitelist from being autoloaded, but allow the blacklist
     // to be loaded
     Unittest_Tests::configure_environment(FALSE);
     $this->config = Kohana::config('unittest');
     // This just stops some very very long lines
     $route = Route::get('unittest');
     $this->report_uri = $route->uri(array('action' => 'report'));
     $this->run_uri = $route->uri(array('action' => 'run'));
     // Switch used to disable cc settings
     $this->xdebug_loaded = extension_loaded('xdebug');
     $this->cc_archive_enabled = class_exists('Archive');
     Kohana_View::set_global('xdebug_enabled', $this->xdebug_loaded);
     Kohana_View::set_global('cc_archive_enabled', $this->cc_archive_enabled);
 }
Exemplo n.º 9
0
 /**
  * Renders the view object to a string. Global and local data are merged
  * and extracted to create local variables within the view file.
  *
  * Note: Global variables with the same key name as local variables will be
  * overwritten by the local variable.
  *
  * @throws   View_Exception
  * @param    view filename
  * @return   string
  */
 public function render($file = null, array $options = array())
 {
     if ($this->_renderer == 'parent') {
         return parent::render($file);
     }
     if ($file !== null) {
         $this->set_filename($file);
     }
     if (empty($this->_file)) {
         throw new Kohana_View_Exception('You must set the file to use within your view before rendering');
     }
     $method = 'Render_' . ucfirst($this->_renderer) . '::render';
     return call_user_func($method, $this->_data, View::$_global_data, $this->_file, $options);
 }
Exemplo n.º 10
0
 /**
  * Sets the initial view filename and local data.
  *
  * @param   string  view filename
  * @param   array   array of values
  * @return  void
  */
 public function __construct($file = NULL, array $data = NULL)
 {
     parent::__construct($file, $data);
     //add this view to $loaded (only once)
     self::$loaded[$file] = $file;
 }
Exemplo n.º 11
0
 public static function set($data)
 {
     self::$view = self::$view->set($data);
 }
Exemplo n.º 12
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  Kohana_View_Exception
  */
 public function set_filename($file)
 {
     if (self::is_smarty_template($file)) {
         throw new Kohana_Exception('Cannot use set_filename to initialise Smarty template :tpl; use View::factory instead', array(':tpl' => $file));
     }
     return parent::set_filename($file);
 }
Exemplo n.º 13
0
 public function set_filename($file)
 {
     parent::set_filename($file);
     $this->_file = $file;
     return $this;
 }
Exemplo n.º 14
0
 public function render($file = NULL)
 {
     $file = parent::render($file);
     return $this->_markdown ? Markdown($file) : $file;
 }