Assembla home | Assembla project page
 

Changeset 743

Show
Ignore:
Timestamp:
01/03/09 14:02:08 (6 months ago)
Author:
joanhey
Message:

Pequeñas modificaciones para optimizar

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 0.5/library/kumbia/helpers/helpers.php

    r95 r743  
    2424 * @see Registry 
    2525 */ 
    26  require_once "library/kumbia/registry/registry.php"
     26 require_once 'library/kumbia/registry/registry.php'
    2727 
    2828/** 
    2929 * Tags 
    3030 */ 
    31  require_once "library/kumbia/helpers/tags.php"
     31 require_once 'library/kumbia/helpers/tags.php'
    3232 
    3333/** 
    3434 * Utils 
    3535 */ 
    36  require_once "library/kumbia/helpers/utils.php"
     36 require_once 'library/kumbia/helpers/utils.php'
    3737 
    3838 
  • 0.5/library/kumbia/helpers/utils.php

    r733 r743  
    287287function get_params($params){ 
    288288        $data = array(); 
    289         $i = 0; 
    290289        foreach ($params as $p) { 
    291290                if(is_string($p) && preg_match('/(\w+): (.*)/', $p, $match)){ 
    292291                        $data[$match[1]] = $match[2]; 
    293292                } else { 
    294                         $data[$i] = $p; 
    295                         $i++; 
     293                        $data[] = $p; 
    296294                } 
    297295        } 
  • 0.5/library/kumbia/kumbia.php

    r741 r743  
    1818 * @author    Andres Felipe Gutierrez <andresfelipe@vagoogle.net> 
    1919 * @copyright 2008-2008 Emilio Rafael Silveira Tovar <emilio.rst at gmail.com> 
    20  * @copyright 2007-2008 Deivinson Jose Tejeda Brito <deivinsontejeda at gmail.com> 
     20 * @copyright 2007-2009 Deivinson Jose Tejeda Brito <deivinsontejeda at gmail.com>  
    2121 * @license   http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GNU/GPL 
    2222 * @version   SVN:$id 
    2323 * @see       Object 
    2424 */ 
    25 require "library/kumbia/object.php"
     25require 'library/kumbia/object.php'
    2626/** 
    2727 * Esta es la clase principal del framework, contiene metodos importantes 
     
    6868     * @var string 
    6969     */ 
    70     static public $content = ""
     70    static public $content = ''
    7171    /** 
    7272     * Almacena el objeto Smarty 
     
    7474     * @var string 
    7575     */ 
    76     private static $_smarty_object = ""
     76    private static $_smarty_object = ''
    7777    /** 
    7878     * Lista de todos los modelos disponibles en la aplicacion 
     
    134134         * Inicializar el ExceptionHandler 
    135135         */ 
    136         set_exception_handler(array("Kumbia", "manage_exceptions")); 
     136        set_exception_handler(array('Kumbia', 'manage_exceptions')); 
    137137        /** 
    138138         * Crear el KUMBIA_PATH 
    139139         */ 
    140         $delete_session_cache = false; 
    141         $path = join(array_slice(explode("/", dirname($_SERVER['PHP_SELF'])), 1, -1), "/"); 
    142         if (isset($_SESSION['KUMBIA_PATH'])) { 
    143             if ($path != $_SESSION['KUMBIA_PATH']) { 
    144                 $delete_session_cache = true; 
    145             } 
    146         } 
     140        $path = dirname($_SERVER['PHP_SELF']); 
    147141        $_SESSION['KUMBIA_PATH'] = $path; 
    148         if ($_SESSION['KUMBIA_PATH']) { 
    149             define('KUMBIA_PATH', "/" . $_SESSION['KUMBIA_PATH'] . "/"); 
     142        if ($path = '/') { 
     143            define('KUMBIA_PATH', '/'); 
    150144        } else { 
    151             define('KUMBIA_PATH', "/"); 
     145            $path = str_replace($path,'public','');//substr($path, 0, -6) 
     146            define('KUMBIA_PATH', $path); 
    152147        } 
    153148        /** 
     
    170165         * 
    171166         */ 
    172         if (!isset($_SESSION['KUMBIA_MODULES'])) { 
    173             $_SESSION['KUMBIA_MODULES'] = array(); 
    174         } 
    175         if (!isset($_SESSION['KUMBIA_MODULES'][$_SESSION['KUMBIA_PATH']])) { 
    176             $_SESSION['KUMBIA_MODULES'][$_SESSION['KUMBIA_PATH']] = array(); 
    177         } 
    178167        if (!isset($_SESSION['KUMBIA_MODULES'][$_SESSION['KUMBIA_PATH']][$active_app])) { 
    179168            $_SESSION['KUMBIA_MODULES'][$_SESSION['KUMBIA_PATH']][$active_app] = array(); 
    180169            if ($kumbia_config = Config::read('boot.ini')) { 
    181                 $kumbia_config->modules->extensions = str_replace(" ", "", $kumbia_config->modules->extensions); 
    182                 $extensions = explode(",", $kumbia_config->modules->extensions); 
     170                $kumbia_config->modules->extensions = strtr($kumbia_config->modules->extensions,' ', ''); 
     171                $extensions = explode(',', $kumbia_config->modules->extensions); 
    183172                foreach($extensions as $extension) { 
    184                     $ex = explode(".", $extension); 
    185                     if ($ex[0] == "kumbia") { 
     173                    $ex = explode('.', $extension); 
     174                    if ($ex[0] == 'kumbia') { 
    186175                        $_SESSION['KUMBIA_MODULES'][$_SESSION['KUMBIA_PATH']][$active_app][] = "library/{$ex[0]}/{$ex[1]}/{$ex[1]}.php"; 
    187176                    } else { 
     
    197186         * Cargar plug-ins de la aplicaci&oacute;n 
    198187         */ 
    199         if (!isset($_SESSION['KUMBIA_PLUGINS'])) { 
    200             $_SESSION['KUMBIA_PLUGINS'] = array(); 
    201         } 
    202         if (!isset($_SESSION['KUMBIA_PLUGINS'][$_SESSION['KUMBIA_PATH']])) { 
    203             $_SESSION['KUMBIA_PLUGINS'][$_SESSION['KUMBIA_PATH']] = array(); 
    204             $_SESSION['KUMBIA_PLUGINS_CLASSES'][$_SESSION['KUMBIA_PATH']] = array(); 
    205         } 
    206188        if (!isset($_SESSION['KUMBIA_PLUGINS'][$_SESSION['KUMBIA_PATH']][$active_app])) { 
    207189            $_SESSION['KUMBIA_PLUGINS'][$_SESSION['KUMBIA_PATH']][$active_app] = array(); 
     
    210192             * Rutas a Plugins 
    211193             */ 
    212             $config = Config::read("config.ini"); 
     194            $config = Config::read('config.ini'); 
    213195            $plugins_dir = "apps/{$config->$active_app->plugins_dir}"; 
    214196            foreach(scandir($plugins_dir) as $plugin) { 
    215                 if (strpos($plugin, ".php")) { 
     197                if (strpos($plugin, '.php')) { 
    216198                    $_SESSION['KUMBIA_PLUGINS'][$_SESSION['KUMBIA_PATH']][$active_app][] = "{$plugins_dir}/$plugin";; 
    217                     $plugin = str_replace(".php", "", $plugin); 
     199                    $plugin = str_replace('.php', '', $plugin); 
    218200                    $_SESSION['KUMBIA_PLUGINS_CLASSES'][$_SESSION['KUMBIA_PATH']][$active_app][] = $plugin; 
    219201                } 
     
    226208         * Establecer el timezone para las fechas y horas 
    227209         */ 
    228         $config = Config::read("config.ini"); 
     210        $config = Config::read('config.ini'); 
    229211        if (isset($config->kumbia->timezone)) { 
    230212            date_default_timezone_set($config->kumbia->timezone); 
     
    246228         * Rutas Base 
    247229         */ 
    248         $config = Config::read("config.ini"); 
     230        $config = Config::read('config.ini'); 
    249231        //Aplicacion Activa 
    250232        self::$active_app = $active_app = Router::get_application(); 
    251233        //Directorio de controladores Activo 
    252         $controllers_dir = "apps/" . $config->$active_app->controllers_dir; 
    253         self::$active_controllers_dir = "apps/" . $config->$active_app->controllers_dir; 
     234        $controllers_dir = self::$active_controllers_dir = 'apps/' . $config->$active_app->controllers_dir; 
    254235        //Directorio de modelos activo 
    255         $models_dir = "apps/" . $config->$active_app->models_dir; 
    256         self::$active_models_dir = "apps/" . $config->$active_app->models_dir; 
     236        $models_dir = self::$active_models_dir = 'apps/' . $config->$active_app->models_dir; 
    257237        //Directorio de Vistas Activo 
    258         $views_dir = "apps/" . $config->$active_app->views_dir; 
    259         self::$active_views_dir = "apps/" . $config->$active_app->views_dir; 
     238        $views_dir = self::$active_views_dir = 'apps/' . $config->$active_app->views_dir; 
    260239        //Directorio de Plugins Activo 
    261         $plugins_dir = "apps/" . $config->$active_app->plugins_dir; 
    262         self::$active_plugins_dir = $plugins_dir; 
     240        $plugins_dir = self::$active_plugins_dir = 'apps/' . $config->$active_app->plugins_dir; 
    263241        //Directorio de Helpers Activo 
    264         $helpers_dir = "apps/" . $config->$active_app->helpers_dir; 
    265         self::$active_helpers_dir = $helpers_dir; 
     242        $helpers_dir = self::$active_helpers_dir = 'apps/' . $config->$active_app->helpers_dir; 
    266243        /** 
    267244         * Leer la configuraci&oacute;n. La primera vez que se lee 
     
    351328                     * desde el core del framework 
    352329                     */ 
    353                     if (Router::get_controller() == "builder" && $config->$active_app->interactive) { 
    354                         Dispatcher::set_controller_dir("library/kumbia/controller"); 
     330                    if (Router::get_controller() == 'builder' && $config->$active_app->interactive) { 
     331                        Dispatcher::set_controller_dir('library/kumbia/controller'); 
    355332                    } else { 
    356333                        Dispatcher::set_controller_dir($controllers_dir); 
     
    405382            if (!empty($controller_name)) { 
    406383                extract(self::$models, EXTR_OVERWRITE); 
    407                 if (is_subclass_of($controller, "ApplicationController")) { 
     384                if (is_subclass_of($controller, 'ApplicationController')) { 
    408385                    foreach($controller as $var => $value) { 
    409386                        $$var = $value; 
     
    434411                 */ 
    435412                $view_cache_dir = null; 
    436                 if ($controller_name != "") { 
     413                if ($controller_name) { 
    437414                    /* 
    438415                     * Creando el directorio Cache 
     
    492469                                        Kumbia::$_smarty_object->assign($_model_name, $_model); 
    493470                                    } 
    494                                     Kumbia::$_smarty_object->display($action_name . ".tpl"); 
     471                                    Kumbia::$_smarty_object->display($action_name . '.tpl'); 
    495472                                    Kumbia::$content = ob_get_contents(); 
    496473                                } 
     
    506483                             * Aqui verifica si existe un valor en minutos para el cache 
    507484                             */ 
    508                             if (file_exists("$views_dir/layouts/" . $controller->template . ".phtml")) { 
     485                            if (file_exists("$views_dir/layouts/" . $controller->template . '.phtml')) { 
    509486                                ob_clean(); 
    510487                                if ($controller->get_layout_cache()) { 
     
    514491                                     * para cada sesion 
    515492                                     */ 
    516                                     if (!file_exists($view_cache_dir . "/layout")) { 
    517                                         include "$views_dir/layouts/" . $controller->template . ".phtml"
    518                                         file_put_contents($view_cache_dir . "/layout", ob_get_contents()); 
     493                                    if (!file_exists($view_cache_dir . '/layout')) { 
     494                                        include "$views_dir/layouts/" . $controller->template . '.phtml'
     495                                        file_put_contents($view_cache_dir . '/layout', ob_get_contents()); 
    519496                                    } else { 
    520497                                        $time_cache = $controller->get_layout_cache(); 
    521                                         if ((time() - $time_cache * 60) < filemtime($view_cache_dir . "/layout")) { 
    522                                             include $view_cache_dir . "/layout"
     498                                        if ((time() - $time_cache * 60) < filemtime($view_cache_dir . '/layout')) { 
     499                                            include $view_cache_dir . '/layout'
    523500                                        } else { 
    524                                             include "$views_dir/layouts/" . $controller->template . ".phtml"
    525                                             file_put_contents($view_cache_dir . "/layout", ob_get_contents()); 
     501                                            include "$views_dir/layouts/" . $controller->template . '.phtml'
     502                                            file_put_contents($view_cache_dir . '/layout', ob_get_contents()); 
    526503                                        } 
    527504                                    } 
    528505                                } else { 
    529                                     include "$views_dir/layouts/" . $controller->template . ".phtml"
     506                                    include "$views_dir/layouts/" . $controller->template . '.phtml'
    530507                                } 
    531508                                Kumbia::$content = ob_get_contents(); 
     
    539516                                 * para cada sesion 
    540517                                 */ 
    541                                 if (!file_exists($view_cache_dir . "/layout")) { 
     518                                if (!file_exists($view_cache_dir . '/layout')) { 
    542519                                    include "$views_dir/layouts/$controller_name.phtml"; 
    543                                     file_put_contents($view_cache_dir . "/layout", ob_get_contents()); 
     520                                    file_put_contents($view_cache_dir . '/layout', ob_get_contents()); 
    544521                                } else { 
    545522                                    $time_cache = $controller->get_layout_cache(); 
    546                                     if ((time() - $time_cache * 60) < filemtime($view_cache_dir . "/layout")) { 
    547                                         include $view_cache_dir . "/layout"
     523                                    if ((time() - $time_cache * 60) < filemtime($view_cache_dir . '/layout')) { 
     524                                        include $view_cache_dir . '/layout'
    548525                                    } else { 
    549526                                        include "$views_dir/layouts/" . $controller_name . ".phtml"; 
    550                                         file_put_contents($view_cache_dir . "/layout", ob_get_contents()); 
     527                                        file_put_contents($view_cache_dir . '/layout', ob_get_contents()); 
    551528                                    } 
    552529                                } 
     
    613590                if (!isset($config->$active_app->interactive) || !$config->$active_app->interactive) { 
    614591                    ob_end_clean(); 
    615                     Kumbia::$content = ""
     592                    Kumbia::$content = ''
    616593                    ob_start(); 
    617594                } 
     
    633610    private static function _init_models($models_dir) { 
    634611        foreach(scandir($models_dir) as $model) { 
    635             if (!in_array($model, array('.', '..', 'base'))) { 
    636                 if (is_dir($models_dir . "/" . $model)) { 
    637                     self::_init_models($models_dir . "/" . $model); 
    638                 } 
    639             } 
    640             if (ereg("\.php$", $model))
     612            if ( !in_array($model, array('.', '..', 'base'))) { 
     613                if (is_dir($models_dir.'/'.$model)) { 
     614                    self::_init_models($models_dir.'/'.$model); 
     615                } 
     616            } 
     617            if (strpos($model, '.php'))
    641618                require_once "$models_dir/$model"; 
    642                 $model = str_replace(".php", "", $model); 
    643                 $object_model = str_replace("_", " ", $model); 
     619                $model = str_replace('.php', '', $model); 
     620                $object_model = strtr($model, '_', ' '); 
    644621                $object_model = ucwords($object_model); 
    645                 $object_model = str_replace(" ", "", $object_model); 
     622                $object_model = strtr($object_model, ' ', ''); 
    646623                if (!class_exists($object_model)) { 
    647624                    throw new KumbiaException("No se encontr&oacute; la Clase \"$object_model\"", "Es necesario definir una clase en el modelo 
     
    649626                } else { 
    650627                    self::$models[$object_model] = new $object_model(); 
    651                     if (!is_subclass_of(self::$models[$object_model], "ActiveRecord")) { 
     628                    if (!is_subclass_of(self::$models[$object_model], 'ActiveRecord')) { 
    652629                        throw new KumbiaException("Error inicializando modelo \"$object_model\"", "El modelo '$model' debe ser una clase o sub-clase de ActiveRecord"); 
    653630                    } 
     
    708685     */ 
    709686    public static function is_model($model) { 
    710         if ($model == '') { 
     687        if (!$model) { 
    711688            return false; 
    712689        } 
     
    720697     */ 
    721698    public static function get_model_name($model) { 
    722         if ($model == '') { 
     699        if (!$model) { 
    723700            return false; 
    724701        } 
    725         $objModel = str_replace("_", " ", $model); 
     702        $objModel = strtr($model, '_', ' '); 
    726703        $objModel = ucwords($objModel); 
    727         $objModel = str_replace(" ", "", $objModel); 
     704        $objModel = strtr($objModel, ' ', ''); 
    728705        return $objModel; 
    729706    } 
     
    734711     */ 
    735712    private static function _create_cache_dir($module_name, $controller_name){ 
    736         $view_cache_dir = "cache/" . session_id() . "/"
    737                 if (!file_exists("cache/" . session_id() . "/")) { 
     713        $view_cache_dir = 'cache/' . session_id() . '/'
     714                if (!file_exists('cache/' . session_id() . '/')) { 
    738715                        mkdir($view_cache_dir); 
    739716                } 
     
    792769     */ 
    793770    public static function stylesheet_link_tags() { 
    794         $imports = Registry::get("KUMBIA_CSS_IMPORTS"); 
     771        $imports = Registry::get('KUMBIA_CSS_IMPORTS'); 
    795772        if ($imports && is_array($imports)) { 
    796773            foreach ($imports as $css) { 
     
    813790    public static function route_to() { 
    814791        $args = func_get_args(); 
    815         return call_user_func_array(array("Router", "route_to"), $args); 
     792        return Router::route_to($args); 
     793        //self::main(); 
     794        //return call_user_func_array(array("Router", "route_to"), $args); 
    816795    } 
    817796    /** 
     
    903882        foreach(scandir($package_dir) as $file) { 
    904883            if ($file != '.' && $file != '..') { 
    905                 if (is_dir($package_dir . "/" . $file)) { 
    906                     $files = self::_scandir_recursive($package_dir . "/" . $file, $files); 
     884                if (is_dir($package_dir . '/' . $file)) { 
     885                    $files = self::_scandir_recursive($package_dir . '/' . $file, $files); 
    907886                } else { 
    908887                    if (ereg("(.)+\.php$", $file)) { 
    909                         $files[] = $package_dir . "/" . $file; 
     888                        $files[] = $package_dir . '/' . $file; 
    910889                    } 
    911890                } 
     
    920899     */ 
    921900    public static function import($package) { 
    922         $package_array = explode(".", $package); 
    923         $package_dir = ""
    924         $class = ""
     901        $package_array = explode('.', $package); 
     902        $package_dir = ''
     903        $class = ''
    925904        if ($package_array[count($package_array) - 1] == '*') { 
    926905            unset($package_array[count($package_array) - 1]); 
    927             $package_dir = join(".", $package_array); 
     906            $package_dir = join('.', $package_array); 
    928907            $class = '*'; 
    929908        } else { 
     
    931910        } 
    932911        if ($class == '*') { 
    933             $package_dir = str_replace('.', '/', $package_dir); 
     912            $package_dir = strtr($package_dir, '.', '/'); 
    934913            if (!file_exists($package_dir)) { 
    935914                throw new kumbiaException("No existe el directorio '$package_dir'\n"); 
     
    983962         * @see Dispatcher 
    984963         */ 
    985         include_once "library/kumbia/dispatcher/dispatcher.php"
     964        include_once 'library/kumbia/dispatcher/dispatcher.php'
    986965        /** 
    987966         * @see Session 
    988967         */ 
    989         include_once "library/kumbia/session/session.php"
     968        include_once 'library/kumbia/session/session.php'
    990969        /** 
    991970         * @see Controller 
    992971         */ 
    993         include_once "library/kumbia/controller/controller.php"
     972        include_once 'library/kumbia/controller/controller.php'
    994973        /** 
    995974         * @see ApplicationController 
    996975         */ 
    997         include_once "library/kumbia/controller/application/application.php"
     976        include_once 'library/kumbia/controller/application/application.php'
    998977        /** 
    999978         * @see StandardForm 
    1000979         */ 
    1001         include_once "library/kumbia/controller/standard_form/standard_form.php"
     980        include_once 'library/kumbia/controller/standard_form/standard_form.php'
    1002981        /** 
    1003982         * @see BuilderController 
    1004983         */ 
    1005         include_once "library/kumbia/controller/builder/builder.php"
     984        include_once 'library/kumbia/controller/builder/builder.php'
    1006985        /** 
    1007986         * @see Filter 
    1008987         */ 
    1009         include_once "library/kumbia/filter/filter.php"
     988        include_once 'library/kumbia/filter/filter.php'
    1010989        /** 
    1011990         * @see Db 
    1012991         */ 
    1013         include_once "library/kumbia/db/db.php"
     992        include_once 'library/kumbia/db/db.php'
    1014993        /** 
    1015994         * @see ActiveRecordBase 
    1016995         */ 
    1017         include_once "library/kumbia/db/active_record_base/active_record_base.php"
     996        include_once 'library/kumbia/db/active_record_base/active_record_base.php'
    1018997        /** 
    1019998         * @see Flash 
    1020999         */ 
    1021         include_once "library/kumbia/messages/flash.php"
     1000        include_once 'library/kumbia/messages/flash.php'
    10221001        /** 
    10231002         * @see Helpers 
    10241003         */ 
    1025         include_once "library/kumbia/helpers/helpers.php"
     1004        include_once 'library/kumbia/helpers/helpers.php'
    10261005        /** 
    10271006         * @see Benchmark 
    10281007         */ 
    1029         include_once 'library/kumbia/benchmark/benchmark.php'; 
     1008        //include_once 'library/kumbia/benchmark/benchmark.php'; 
    10301009    } 
    10311010}