Example #1
0
 public function make($filename, $data = [])
 {
     $view = new View($this);
     $view->setPath($this->app->basePath($this->app->config->get('app.view.templates', 'app' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR)));
     $view->setCachePath($this->app->cachePath($this->app->config->get('app.view.cache', 'views' . DIRECTORY_SEPARATOR)));
     $view->setFilename($filename);
     $view->data($data);
     return $view;
 }
Example #2
0
 /**
  * Constructor
  *
  * @param array $args
  */
 public function __construct($args)
 {
     /*modulo al que pertenece el controlador*/
     $this->module_name = $args['module'];
     $this->controller_name = $args['controller'];
     $this->parameters = $args['parameters'];
     $this->action_name = $args['action'];
     View::select($args['action']);
     View::setPath($args['controller_path']);
 }
 /**
  * Realiza el dispatch de una ruta
  *
  * @return Object
  */
 public static function execute($route)
 {
     extract($route, EXTR_OVERWRITE);
     if (!(include_once APP_PATH . "controllers/{$controller_path}" . '_controller.php')) {
         throw new KumbiaException(NULL, 'no_controller');
     }
     //Asigna el controlador activo
     $app_controller = Util::camelcase($controller) . 'Controller';
     $cont = self::$_controller = new $app_controller($module, $controller, $action, $parameters);
     View::select($action);
     View::setPath($controller_path);
     // Se ejecutan los filtros before
     if ($cont->k_callback('initialize') === FALSE) {
         return $cont;
     }
     if ($cont->k_callback('before_filter') === FALSE) {
         return $cont;
     }
     //Se ejecuta el metodo con el nombre de la accion
     //en la clase de acuerdo al convenio
     if (!method_exists($cont, $action)) {
         throw new KumbiaException(NULL, 'no_action');
     }
     //Obteniendo el metodo
     $reflectionMethod = new ReflectionMethod($cont, $action);
     //k_callback y __constructor metodo reservado
     if ($reflectionMethod->name == 'k_callback' || $reflectionMethod->isConstructor()) {
         throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP');
     }
     //se verifica que el metodo sea public
     if (!$reflectionMethod->isPublic()) {
         throw new KumbiaException(NULL, 'no_action');
     }
     //se verifica que los parametros que recibe
     //la action sea la cantidad correcta
     $num_params = count($parameters);
     if ($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() || $num_params > $reflectionMethod->getNumberOfParameters())) {
         throw new KumbiaException("Número de parámetros erroneo para ejecutar la acción \"{$action}\" en el controlador \"{$controller}\"");
     }
     $reflectionMethod->invokeArgs($cont, $parameters);
     //Corre los filtros after
     $cont->k_callback('after_filter');
     $cont->k_callback('finalize');
     //Si esta routed volver a ejecutar
     if (Router::getRouted()) {
         Router::setRouted(FALSE);
         return Dispatcher::execute(Router::get());
         // Vuelve a ejecutar el dispatcher
     }
     return $cont;
 }
 /**
  * Metodo para cerrar la sesion del usuario actual
  */
 public function salir()
 {
     if (!Auth::is_valid()) {
         Flash::info("Identifícate nuevamente.");
     } else {
         Auth::destroy_identity();
         Session::delete('ip');
         Session::delete("usuario");
         Session::delete('grupo');
         Session::delete('nivel');
         Flash::valid("La sesión se ha cerrado correctamente.");
     }
     //Cambio la vista
     View::setPath('dc-admin/usuario');
     View::select('entrar', 'login');
 }
Example #5
0
 /**
  * Loads the template, replaced place holders and returns string.
  * @param string $file The template file to use.
  * @return string The complete template output.
  */
 public function render($file)
 {
     $file = $this->extension == '' ? $file : $file . '.' . $this->extension;
     // Load the template file
     $view = new View();
     $view->setPath($this->path);
     $return = $view->render($file);
     // Replace placeholders
     foreach ($this->outputs as $output) {
         $type = gettype($output['output']);
         if ($type == 'object') {
             $class = get_class($output['output']);
             if ($class === 'Twuddle\\Core\\View') {
                 $output['output'] = $output['output']->render();
             }
         }
         $return = str_replace($output['placeholder'], $output['output'], $return);
     }
     $this->outputs = array();
     return $return;
 }
 /**
  * Realiza el dispatch de la ruta actual
  *
  * @return Controller
  */
 private static function _dispatch()
 {
     // Extrae las variables para manipularlas facilmente
     extract(self::$_vars, EXTR_OVERWRITE);
     if (!(include_once APP_PATH . "controllers/{$controller_path}" . '_controller.php')) {
         throw new KumbiaException(null, 'no_controller');
     }
     View::select($action);
     //TODO: mover al constructor del controller base las 2 lineas
     View::setPath($controller_path);
     //Asigna el controlador activo
     $app_controller = Util::camelcase($controller) . 'Controller';
     $cont = new $app_controller($module, $controller, $action, $parameters);
     // Se ejecutan los filtros initialize y before
     if ($cont->k_callback(true) === false) {
         return $cont;
     }
     //Obteniendo el metodo
     try {
         $reflectionMethod = new ReflectionMethod($cont, $cont->action_name);
     } catch (ReflectionException $e) {
         throw new KumbiaException(null, 'no_action');
         //TODO: enviar a un método del controller
     }
     //k_callback y __constructor metodo reservado
     if ($cont->action_name == 'k_callback' || $reflectionMethod->isConstructor()) {
         throw new KumbiaException('Esta intentando ejecutar un método reservado de KumbiaPHP');
     }
     //se verifica que los parametros que recibe
     //la action sea la cantidad correcta
     $num_params = count($cont->parameters);
     if ($cont->limit_params && ($num_params < $reflectionMethod->getNumberOfRequiredParameters() || $num_params > $reflectionMethod->getNumberOfParameters())) {
         throw new KumbiaException(NULL, 'num_params');
     }
     try {
         $reflectionMethod->invokeArgs($cont, $cont->parameters);
     } catch (ReflectionException $e) {
         throw new KumbiaException(null, 'no_action');
         //TODO: mejor no_public
     }
     //Corre los filtros after y finalize
     $cont->k_callback();
     //Si esta routed internamente volver a ejecutar
     if (self::$_routed) {
         self::$_routed = FALSE;
         return self::_dispatch();
         // Vuelve a ejecutar el dispatcher
     }
     return $cont;
 }
Example #7
0
 public function run($app = '', $ac = '')
 {
     $c = sha1(url());
     $S = !empty($_SESSION['pe_s'][$c]) ? $_SESSION['pe_s'][$c] : '';
     for ($i = 1; $i <= 9; ++$i) {
         if (isset($_REQUEST['pe_try' . $i]) && !empty($_REQUEST['pe_s']) && $_REQUEST['pe_s'] == $S) {
             $this->try = $i;
             $this->form = !empty($_REQUEST['pe_f']) ? trim($_REQUEST['pe_f']) : '';
             $_SESSION['pe_s'][$c] = 0;
             break;
         }
     }
     if (empty($_SESSION['pe_s'][$c])) {
         $_SESSION['pe_s'][$c] = sha1(uniqid() . 'PHPPE' . VERSION);
     }
     if (!empty($_SESSION['pe_v'])) {
         self::$v = $_SESSION['pe_v'];
     }
     View::init();
     if (empty($this->maintenance)) {
         list($app, $ac, $args) = HTTP::urlMatch($app, $ac, $this->url);
         list($app, $ac) = self::event('route', [$app, $ac]);
         $c = $app . '_' . $ac;
         if (strpos($c, '..') !== false || strpos($c, '/') !== false || substr($app, -4) == '.php' || substr($ac, -4) == '.php') {
             $app = $this->template = '403';
         } else {
             $this->template = self::$w ? $app . '_' . $ac : '';
         }
         $appCls = $app;
         foreach (['PHPPE\\Ctrl\\' . $app . ucfirst($ac), 'PHPPE\\Ctrl\\' . $app, 'PHPPE\\' . $app, $app] as $a) {
             if (ClassMap::has($a)) {
                 $appCls = $a;
                 if ($a[0] == "\\") {
                     $a = substr($a, 1);
                 }
                 $p = dirname(ClassMap::$map[strtolower($a)]);
                 if (basename($p) == "ctrl" || basename($p) == "libs") {
                     $p = dirname($p);
                 }
                 self::$paths[strtolower($app)] = $p;
                 break;
             }
         }
         if (!ClassMap::has($appCls)) {
             if (!self::$w) {
                 die($this->app == 'cron' ? self::event('cron' . ucfirst($this->action), 0) : 'PHPPE-C: ' . L($this->app . '_' . $this->action . ' not found!') . "\n");
             }
             $appCls = 'PHPPE\\Content';
             $ac = 'action';
         }
         $appObj = new $appCls();
         View::setPath(self::$paths[strtolower($app)]);
         View::assign('app', $appObj);
         self::log('D', $this->url . " ->{$app}::{$ac} " . $this->template, 'routes');
         $N = 'p_' . sha1($this->base . $this->url . '/' . self::$user->id . '/' . self::$client->lang);
         if (empty($this->nocache) && !self::isTry()) {
             $T = View::fromCache($N);
         }
         if (empty($T)) {
             Content::getDDS($appObj);
             self::event('ctrl', [$app, $ac]);
             if (!method_exists($appObj, $ac)) {
                 $ac = 'action';
             }
             if (method_exists($appObj, $ac)) {
                 !empty($args) ? call_user_func_array([$appObj, $ac], $args) : $appObj->{$ac}($this->item);
             }
             $T = View::generate($this->template, $N);
         }
     } else {
         session_destroy();
         $T = View::template('maintenance');
         if (empty($T)) {
             $T = L('Site is temporarily down for maintenance');
         }
     }
     if ((@in_array('--dump', $_SERVER['argv']) || isset($_REQUEST['--dump'])) && $this->runlevel > 0) {
         View::dump();
     }
     DS::close();
     $T = self::event('view', $T);
     View::output($T);
     session_write_close();
 }
Example #8
0
 public function show($key)
 {
     if (!($id = Security::getKey($key, 'show_calendar', 'int'))) {
         return Redirect::toAction('listar');
     }
     $usuario_id = $id;
     $this->eventos = Calendario::getCalendario($usuario_id);
     $reporte = new Reporte();
     $this->progress_report = $reporte->getListadoReportePorTipo($usuario_id, 'progress_report');
     $this->demographics_report = $reporte->getListadoReportePorTipo($usuario_id, 'demographics_report');
     $this->beehive_report = $reporte->getListadoReportePorTipo($usuario_id, 'beehive_report');
     $this->read_only = true;
     View::setPath('dashboard/index');
     View::select('index', 'backend/bee');
 }
Example #9
0
            if (!String::startsWith($currentRoute, 'admin/install')) {
                Url::redirect('admin/install');
            }
        } elseif (!String::startsWith($currentRoute, 'admin/login')) {
            $noAccess = !User::current()->hasPermission('admin.access');
            $isAnon = User::current()->isAnonymous();
            if (!$isAnon && $noAccess) {
                Message::error('You do not have admin access permissions.');
                unset($_SESSION[Config::get('user.session_key')]);
            }
            if ($isAnon || $noAccess) {
                Url::redirect('admin/login');
            }
        }
        Admin::setInAdmin(true);
        View::setPath(ROOT . 'core/admin/');
    }
}, 'module.response' => function ($response = null) {
    if (Admin::inAdmin()) {
        View::data('adminContent', $response);
    }
}, 'view.load' => function ($module, $controller, $method) {
    if (Admin::inAdmin()) {
        $paths = array(sprintf('%s/%s', $controller, $method), sprintf('%s_%s', $controller, $method));
        foreach ($paths as $path) {
            $viewFile = Load::getModulePath($module) . Config::get('view.dir') . $path . EXT;
            Log::debug('admin', 'Checking for custom view: ' . $viewFile);
            if (file_exists($viewFile)) {
                Log::debug('admin', 'Loading custom view: ' . $viewFile);
                return $viewFile;
            }