<commit_before><?php
namespace KBackend\Libs;
/**
 * KBackend
 * PHP version 5
 * @package Libs
 * @license https://raw.github.com/Ashrey/KBackend/master/LICENSE.txt
 * @author KumbiaPHP Development Team
 */
require_once CORE_PATH . 'kumbia/kumbia_view.php';
use \Haanga;
class Template extends \KumbiaView {
    /**
     * Muestra las excepciones generadas y crea un log de las mismas.
     * @param  Exception $e [description]
     */
    public static function excepcion(\Exception $e) {
        Flash::warning('Ha Ocurrido un error');
        if (Config::get('config.application.log_exception') || !PRODUCTION) {
            Flash::error($e->getMessage());
        }else{
            Flash::error($e->getTraceAsString());
        }
        Logger::log("Exception $e");
        Flash::info('Si el problema persiste por favor informe al administrador del sistema');
    }

    /**
     * Muestra la vista de notFound de la app.
     * 
     */
    public function notFound() {
        throw new KumbiaException(NULL, 'no_controller');
    }

    /**
     * Renderiza la vista
     * @overload
     * @todo add the cache
     * @param Controller $controller
     */
    public static function render($controller)
    {
        /*Establece las configuraciones de haanga*/
        Haanga::configure(array(
            'template_dir' => KBACKEND_PATH.'/views',
            'cache_dir' => KBACKEND_PATH.'/temp/cache/haanga',
            'compiler' => array( /* opts for the tpl compiler */
                'strip_whitespace' => TRUE,
                'allow_exec'  => TRUE
            ),
        ));


        /*Si no hay nada termina el proceso y descarga el buffer*/
        if (!self::$_view && !self::$_template)
            return ob_end_flush();
         
        // Guarda el controlador
        self::$_controller = $controller;
         
        /*extrae las variables del controllador*/
        $vars = get_object_vars($controller);
        
         // carga la vista si no esta en produccion o se usa scaffold o no hay contenido cargado
        if (!PRODUCTION || $scaffold || !self::$_content) {
            // Carga el contenido del buffer de salida
            self::$_content = ob_get_clean();
            $file = static::getFile();
            try{
                self::$_content = static::getTpl($file, $vars);
            }catch(\Exception $e){
                parent::render($controller);
            }
        } else {
            ob_clean();
        }
        echo self::$_content;
    }

    static protected function getFile(){
        /*Captura el posible scaffold*/
        $c = self::$_controller;
        $scaffold = $c->scaffold;
        $file =  self::getPath();
        if (!is_file(KBACKEND_PATH ."/views/$file")){
            $view = self::$_view;
            return ( $scaffold && $view ) ?
                "_shared/scaffolds/$scaffold/$view.phtml":
                self::$_template. '.phtml';
        }
        return $file;
    }

    public static function getTpl($file, $vars){
        return Haanga::Load($file, $vars, true);
    }


    public static function content()
    {
        if (isset($_SESSION['KUMBIA.CONTENT'])) {
            $content = $_SESSION['KUMBIA.CONTENT'];
            unset($_SESSION['KUMBIA.CONTENT']);
            return $content;
        }
        return self::$_content;
    }
}
<commit_msg>Move configuration<commit_after><?php
namespace KBackend\Libs;
/**
 * KBackend
 * PHP version 5
 * @package Libs
 * @license https://raw.github.com/Ashrey/KBackend/master/LICENSE.txt
 * @author KumbiaPHP Development Team
 */
require_once CORE_PATH . 'kumbia/kumbia_view.php';
use \Haanga;
class Template extends \KumbiaView {
    /**
     * Muestra las excepciones generadas y crea un log de las mismas.
     * @param  Exception $e [description]
     */
    public static function excepcion(\Exception $e) {
        Flash::warning('Ha Ocurrido un error');
        if (Config::get('config.application.log_exception') || !PRODUCTION) {
            Flash::error($e->getMessage());
        }else{
            Flash::error($e->getTraceAsString());
        }
        Logger::log("Exception $e");
        Flash::info('Si el problema persiste por favor informe al administrador del sistema');
    }

    /**
     * Muestra la vista de notFound de la app.
     * 
     */
    public function notFound() {
        throw new KumbiaException(NULL, 'no_controller');
    }

    /**
     * Renderiza la vista
     * @overload
     * @todo add the cache
     * @param Controller $controller
     */
    public static function render($controller)
    {

        /*Si no hay nada termina el proceso y descarga el buffer*/
        if (!self::$_view && !self::$_template)
            return ob_end_flush();
         
        // Guarda el controlador
        self::$_controller = $controller;
         
        /*extrae las variables del controllador*/
        $vars = get_object_vars($controller);
        
         // carga la vista si no esta en produccion o se usa scaffold o no hay contenido cargado
        if (!PRODUCTION || $scaffold || !self::$_content) {
            $file = static::getFile();
            try{
                self::$_content = static::getTpl($file, $vars);
            }catch(\Exception $e){
                parent::render($controller);
            }
        } else {
            ob_clean();
        }
        echo self::$_content;
    }

    static protected function getFile(){
        /*Captura el posible scaffold*/
        $c = self::$_controller;
        $scaffold = $c->scaffold;
        $file =  self::getPath();
        if (!is_file(KBACKEND_PATH ."/views/$file")){
            $view = self::$_view;
            return ( $scaffold && $view ) ?
                "_shared/scaffolds/$scaffold/$view.phtml":
                self::$_template. '.phtml';
        }
        return $file;
    }

    public static function getTpl($file, $vars){
         /*Establece las configuraciones de haanga*/
        Haanga::configure(array(
            'template_dir' => KBACKEND_PATH.'/views',
            'cache_dir' => KBACKEND_PATH.'/temp/cache/haanga',
            'compiler' => array( /* opts for the tpl compiler */
                'strip_whitespace' => TRUE,
                'allow_exec'  => TRUE
            ),
        ));
        return Haanga::Load($file, $vars, true);
    }


    public static function content()
    {
        if (isset($_SESSION['KUMBIA.CONTENT'])) {
            $content = $_SESSION['KUMBIA.CONTENT'];
            unset($_SESSION['KUMBIA.CONTENT']);
            return $content;
        }
        return self::$_content;
    }
}

{'fraction_non_alphanumeric': 0.1308227465214761, 'fraction_numerical': 0.00030248033877797946, 'mean_word_length': 1.97480881691408, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3490334', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1911, 'n_words': 468}