Skip to content
Browse files

cambios en toda la estructura de directorios

A partir de ahora el backend tendrá integrado el core de una vez,
esto con la finalidad de que sea funcional solo con descargarlo :-)
  • Loading branch information...
1 parent c809115 commit 74907e06d30abd6e62dbd921789e90ff5182f06e @manuelj555 committed Apr 14, 2012
Showing with 18,894 additions and 4 deletions.
  1. +3 −4 .htaccess
  2. 0 {app → core}/.htaccess
  3. +85 −0 core/console/cache_console.php
  4. +140 −0 core/console/controller_console.php
  5. +10 −0 core/console/generators/controller.php
  6. +10 −0 core/console/generators/model.php
  7. +31 −0 core/console/kumbia.php
  8. +107 −0 core/console/model_console.php
  9. +177 −0 core/extensions/helpers/ajax.php
  10. +116 −0 core/extensions/helpers/flash.php
  11. +755 −0 core/extensions/helpers/form.php
  12. +287 −0 core/extensions/helpers/html.php
  13. +102 −0 core/extensions/helpers/js.php
  14. +105 −0 core/extensions/helpers/model_form.php
  15. +110 −0 core/extensions/helpers/tag.php
  16. +1,852 −0 core/extensions/helpers/tags.php
  17. 0 {app/temp/logs → core/extensions/scaffolds}/empty
  18. +154 −0 core/kumbia/bootstrap.php
  19. +110 −0 core/kumbia/config.php
  20. +213 −0 core/kumbia/console.php
  21. +138 −0 core/kumbia/controller.php
  22. +472 −0 core/kumbia/controller_deprecated.php
  23. +110 −0 core/kumbia/dispatcher.php
  24. +95 −0 core/kumbia/kumbia_exception.php
  25. +373 −0 core/kumbia/kumbia_view.php
  26. +108 −0 core/kumbia/load.php
  27. +260 −0 core/kumbia/router.php
  28. +220 −0 core/kumbia/util.php
  29. +464 −0 core/libs/acl/acl.php
  30. +66 −0 core/libs/acl/resource/resource.php
  31. +69 −0 core/libs/acl/role/role.php
  32. +136 −0 core/libs/acl2/acl2.php
  33. +140 −0 core/libs/acl2/adapters/simple_acl.php
  34. +147 −0 core/libs/auth/adapters/digest_auth.php
  35. +161 −0 core/libs/auth/adapters/kerberos5_auth.php
  36. +135 −0 core/libs/auth/adapters/model_auth.php
  37. +195 −0 core/libs/auth/adapters/radius_auth.php
  38. +315 −0 core/libs/auth/auth.php
  39. +48 −0 core/libs/auth/auth_interface.php
  40. +120 −0 core/libs/auth2/adapters/model_auth.php
  41. +254 −0 core/libs/auth2/auth2.php
  42. +125 −0 core/libs/benchmark/benchmark.php
  43. +175 −0 core/libs/cache/cache.php
  44. +99 −0 core/libs/cache/drivers/APC_cache.php
  45. +127 −0 core/libs/cache/drivers/file_cache.php
  46. +55 −0 core/libs/cache/drivers/memsqlite_cache.php
  47. +128 −0 core/libs/cache/drivers/nixfile_cache.php
  48. +151 −0 core/libs/cache/drivers/sqlite_cache.php
  49. +339 −0 core/libs/date/date.php
  50. +525 −0 core/libs/db/adapters/firebird.php
  51. +683 −0 core/libs/db/adapters/informix.php
  52. +526 −0 core/libs/db/adapters/mysql.php
  53. +494 −0 core/libs/db/adapters/mysqli.php
  54. +616 −0 core/libs/db/adapters/oracle.php
  55. +464 −0 core/libs/db/adapters/pdo.php
  56. +286 −0 core/libs/db/adapters/pdo/access.php
  57. +281 −0 core/libs/db/adapters/pdo/informix.php
  58. +95 −0 core/libs/db/adapters/pdo/interface.php
  59. +286 −0 core/libs/db/adapters/pdo/mssql.php
  60. +263 −0 core/libs/db/adapters/pdo/mysql.php
  61. +279 −0 core/libs/db/adapters/pdo/oracle.php
  62. +293 −0 core/libs/db/adapters/pdo/pgsql.php
  63. +256 −0 core/libs/db/adapters/pdo/sqlite.php
  64. +553 −0 core/libs/db/adapters/pgsql.php
  65. +450 −0 core/libs/db/adapters/sqlite.php
  66. +100 −0 core/libs/db/db.php
  67. +296 −0 core/libs/db/db_base.php
  68. +87 −0 core/libs/db/db_base_interface.php
  69. +776 −0 core/libs/deprecated/deprecated.php
  70. +168 −0 core/libs/event/event.php
  71. +30 −0 core/libs/event/hook.php
  72. +43 −0 core/libs/filter/base_filter/addslashes_filter.php
  73. +53 −0 core/libs/filter/base_filter/alnum_filter.php
  74. +44 −0 core/libs/filter/base_filter/alpha_filter.php
  75. +49 −0 core/libs/filter/base_filter/date_filter.php
  76. +45 −0 core/libs/filter/base_filter/digits_filter.php
  77. +45 −0 core/libs/filter/base_filter/htmlentities_filter.php
  78. +45 −0 core/libs/filter/base_filter/htmlspecialchars_filter.php
  79. +44 −0 core/libs/filter/base_filter/int_filter.php
  80. +49 −0 core/libs/filter/base_filter/ipv4_filter.php
  81. +44 −0 core/libs/filter/base_filter/lower_filter.php
  82. +48 −0 core/libs/filter/base_filter/md5_filter.php
  83. +44 −0 core/libs/filter/base_filter/nl2br_filter.php
  84. +46 −0 core/libs/filter/base_filter/numeric_filter.php
  85. +44 −0 core/libs/filter/base_filter/stripslashes_filter.php
  86. +45 −0 core/libs/filter/base_filter/stripspace_filter.php
  87. +44 −0 core/libs/filter/base_filter/striptags_filter.php
  88. +44 −0 core/libs/filter/base_filter/trim_filter.php
  89. +44 −0 core/libs/filter/base_filter/upper_filter.php
  90. +126 −0 core/libs/filter/filter.php
  91. +38 −0 core/libs/filter/filter_interface.php
  92. +156 −0 core/libs/i18n/i18n.php
  93. +154 −0 core/libs/input/input.php
  94. +201 −0 core/libs/kumbia_active_record/behaviors/paginate.php
Sorry, we could not display the entire diff because too many files (402) changed.
View
7 .htaccess
@@ -1,7 +1,6 @@
-Options -Multiviews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
- RewriteRule ^$ public/ [L]
- RewriteRule (.*) public/$1 [L]
-</IfModule>
+ RewriteRule ^$ default/public/ [L]
+ RewriteRule (.*) default/public/$1 [L]
+</IfModule>
View
0 app/config/config.ini
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/config/databases.ini
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/config/routes.ini
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/config/sql/backend_kumbia.sql.zip
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/config/sql/postgre_backend.sql
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/auditorias_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/index_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/menu_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/privilegios_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/recursos_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/roles_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/admin/usuarios_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/index_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/controllers/pages_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/console/empty
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/filters/empty
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/helpers/acciones.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/helpers/configuracion.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/helpers/flash.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/helpers/lector_clases.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/helpers/menu.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/helpers/table.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/extensions/scaffolds/empty
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/active_record.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/admin_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/app_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/application_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/bootstrap.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/lector_recursos.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/my_acl.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/my_auth.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/scaffold_controller.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/libs/view.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/locale/es_ES/LC_MESSAGES/default.mo
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/locale/es_ES/LC_MESSAGES/default.po
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/models/auditorias.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/models/menus.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/models/recursos.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/models/roles.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/models/roles_recursos.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/models/usuarios.php
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/temp/cache/empty
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/errors/404.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/partials/backend/cabecera_admin.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/partials/backend/cabecera_app.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/partials/backend/pie.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/partials/paginators/bootstrap.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/scaffolds/bootstrap/crear.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/scaffolds/bootstrap/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/scaffolds/bootstrap/ver.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/scaffolds/kumbia/crear.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/scaffolds/kumbia/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/scaffolds/kumbia/ver.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/templates/backend/backend.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/templates/backend/default.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/templates/backend/logueo.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/_shared/templates/default.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/auditorias/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/auditorias/usuario.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/index/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/menu/crear.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/menu/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/privilegios/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/recursos/crear.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/recursos/escaner.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/recursos/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/roles/agregar_padre.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/roles/crear.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/roles/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/usuarios/crear.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/usuarios/editar.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/usuarios/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/admin/usuarios/perfil.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/index/index.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/views/pages/kumbia/status.phtml
Sorry, we could not display the changes to this file because there were too many other changes to display.
View
0 app/.htaccess → core/.htaccess
File renamed without changes.
View
85 core/console/cache_console.php
@@ -0,0 +1,85 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * @category Kumbia
+ * @package Console
+ * @copyright Copyright (c) 2005-2012 Kumbia Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+// carga libreria para manejo de cache
+Load::lib('cache');
+
+/**
+ * Consola para manejar la cache
+ *
+ * @category Kumbia
+ * @package Console
+ */
+class CacheConsole
+{
+
+ /**
+ * Comando de consola para limpiar la cache
+ *
+ * @param array $params parametros nombrados de la consola
+ * @param string $group nombre de grupo
+ * @throw KumbiaException
+ */
+ public function clean($params, $group = FALSE)
+ {
+ // obtiene el driver de cache
+ if (isset($params['driver'])) {
+ $cache = Cache::driver($params['driver']);
+ } else {
+ $cache = Cache::driver();
+ }
+
+ // limpia la cache
+ if ($cache->clean($group)) {
+ if ($group) {
+ echo "-> Se ha limpiado el grupo $group", PHP_EOL;
+ } else {
+ echo "-> Se ha limpiado la cache", PHP_EOL;
+ }
+ } else {
+ throw new KumbiaException('No se ha logrado eliminar el contenido');
+ }
+ }
+
+ /**
+ * Comando de consola para eliminar un elemento cacheado
+ *
+ * @param array $params parametros nombrados de la consola
+ * @param string $id id del elemento
+ * @param string $group nombre de grupo
+ * @throw KumbiaException
+ */
+ public function remove($params, $id, $group = 'default')
+ {
+ // obtiene el driver de cache
+ if (isset($params['driver'])) {
+ $cache = Cache::driver($params['driver']);
+ } else {
+ $cache = Cache::driver();
+ }
+
+ // elimina el elemento
+ if ($cache->remove($id, $group)) {
+ echo '-> Se ha eliminado el elemento de la cache', PHP_EOL;
+ } else {
+ throw new KumbiaException("No se ha logrado eliminar el elemento \"$id\" del grupo \"$group\"");
+ }
+ }
+
+}
View
140 core/console/controller_console.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * @category Kumbia
+ * @package Console
+ * @copyright Copyright (c) 2005-2012 Kumbia Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+
+/**
+ * Consola para manejar controladores
+ *
+ * @category Kumbia
+ * @package Console
+ */
+class ControllerConsole
+{
+
+ /**
+ * Comando de consola para crear un controlador
+ *
+ * @param array $params parametros nombrados de la consola
+ * @param string $controller controlador
+ * @throw KumbiaException
+ */
+ public function create($params, $controller)
+ {
+ // nombre de archivo
+ $file = APP_PATH . 'controllers';
+
+ // limpia el path de controller
+ $clean_path = trim($controller, '/');
+
+ // obtiene el path
+ $path = explode('/', $clean_path);
+
+ // obtiene el nombre de controlador
+ $controller_name = array_pop($path);
+
+ // si se agrupa el controlador en un directorio
+ if (count($path)) {
+ $dir = implode('/', $path);
+ $file .= "/$dir";
+ if (!is_dir($file) && !Util::mkpath($file)) {
+ throw new KumbiaException("No se ha logrado crear el directorio \"$file\"");
+ }
+ }
+ $file .= "/{$controller_name}_controller.php";
+
+ // si no existe o se sobreescribe
+ if (!is_file($file) ||
+ Console::input("El controlador existe, ¿desea sobrescribirlo? (s/n): ", array('s', 'n')) == 's') {
+
+ // nombre de clase
+ $class = Util::camelcase($controller_name);
+
+ // codigo de controlador
+ ob_start();
+ include CORE_PATH . 'console/generators/controller.php';
+ $code = '<?php' . PHP_EOL . ob_get_clean();
+
+ // genera el archivo
+ if (file_put_contents($file, $code)) {
+ echo "-> Creado controlador $controller_name en: $file" . PHP_EOL;
+ } else {
+ throw new KumbiaException("No se ha logrado crear el archivo \"$file\"");
+ }
+
+ // directorio para vistas
+ $views_dir = APP_PATH . "views/$clean_path";
+
+ //si el directorio no existe
+ if (!is_dir($views_dir)) {
+ if (Util::mkpath($views_dir)) {
+ echo "-> Creado directorio para vistas: $views_dir" . PHP_EOL;
+ } else {
+ throw new KumbiaException("No se ha logrado crear el directorio \"$views_dir\"");
+ }
+ }
+ }
+ }
+
+ /**
+ * Comando de consola para eliminar un controlador
+ *
+ * @param array $params parametros nombrados de la consola
+ * @param string $controller controlador
+ * @throw KumbiaException
+ */
+ public function delete($params, $controller)
+ {
+ // path limpio al controlador
+ $clean_path = trim($controller, '/');
+
+ // nombre de archivo
+ $file = APP_PATH . "controllers/$clean_path";
+
+ // si es un directorio
+ if (is_dir($file)) {
+ $success = Util::removedir($file);
+ } else {
+ // entonces es un archivo
+ $file = "{$file}_controller.php";
+ $success = unlink($file);
+ }
+
+ // mensaje
+ if ($success) {
+ echo "-> Eliminado: $file" . PHP_EOL;
+ } else {
+ throw new KumbiaException("No se ha logrado eliminar \"$file\"");
+ }
+
+ // directorio para vistas
+ $views_dir = APP_PATH . "views/$clean_path";
+
+ // intenta eliminar el directorio de vistas
+ if (is_dir($views_dir)
+ && Console::input('¿Desea eliminar el directorio de vistas? (s/n): ', array('s', 'n')) == 's') {
+
+ if (!Util::removedir($views_dir)) {
+ throw new KumbiaException("No se ha logrado eliminar \"$views_dir\"");
+ }
+
+ echo "-> Eliminado: $views_dir" . PHP_EOL;
+ }
+ }
+
+}
View
10 core/console/generators/controller.php
@@ -0,0 +1,10 @@
+/**
+ * Controlador <?php echo $class, PHP_EOL ?>
+ *
+ * @category App
+ * @package Controllers
+ */
+class <?php echo $class ?>Controller extends AppController
+{
+
+}
View
10 core/console/generators/model.php
@@ -0,0 +1,10 @@
+/**
+ * Modelo <?php echo $class, PHP_EOL ?>
+ *
+ * @category App
+ * @package Models
+ */
+class <?php echo $class ?> extends ActiveRecord
+{
+
+}
View
31 core/console/kumbia.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * Script para consolas de KumbiaPHP
+ *
+ * @category Kumbia
+ * @package Console
+ * @copyright Copyright (c) 2005-2012 Kumbia Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+// Define el CORE_PATH
+define('CORE_PATH', dirname(dirname(__FILE__)) . '/');
+
+/**
+ * @see Console
+ */
+require CORE_PATH . 'kumbia/console.php';
+
+// Ejecuta el despachador
+Console::dispatch($argv);
View
107 core/console/model_console.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * @category Kumbia
+ * @package Console
+ * @copyright Copyright (c) 2005-2012 Kumbia Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+
+/**
+ * Consola para manejar modelos
+ *
+ * @category Kumbia
+ * @package Console
+ */
+class ModelConsole
+{
+
+ /**
+ * Comando de consola para crear un modelo
+ *
+ * @param array $params parametros nombrados de la consola
+ * @param string $model modelo
+ * @throw KumbiaException
+ */
+ public function create($params, $model)
+ {
+ // nombre de archivo
+ $file = APP_PATH . 'models';
+
+ // obtiene el path
+ $path = explode('/', trim($model, '/'));
+
+ // obtiene el nombre de modelo
+ $model_name = array_pop($path);
+
+ if (count($path)) {
+ $dir = implode('/', $path);
+ $file .= "/$dir";
+ if (!is_dir($file) && !Util::mkpath($file)) {
+ throw new KumbiaException("No se ha logrado crear el directorio \"$file\"");
+ }
+ }
+ $file .= "/$model_name.php";
+
+ // si no existe o se sobreescribe
+ if (!is_file($file) ||
+ Console::input("El modelo existe, �desea sobrescribirlo? (s/n): ", array('s', 'n')) == 's') {
+
+ // nombre de clase
+ $class = Util::camelcase($model_name);
+
+ // codigo de modelo
+ ob_start();
+ include CORE_PATH . 'console/generators/model.php';
+ $code = '<?php' . PHP_EOL . ob_get_clean();
+
+ // genera el archivo
+ if (file_put_contents($file, $code)) {
+ echo "-> Creado modelo $model_name en: $file" . PHP_EOL;
+ } else {
+ throw new KumbiaException("No se ha logrado crear el archivo \"$file\"");
+ }
+ }
+ }
+
+ /**
+ * Comando de consola para eliminar un modelo
+ *
+ * @param array $params parametros nombrados de la consola
+ * @param string $model modelo
+ * @throw KumbiaException
+ */
+ public function delete($params, $model)
+ {
+ // nombre de archivo
+ $file = APP_PATH . 'models/' . trim($model, '/');
+
+ // si es un directorio
+ if (is_dir($file)) {
+ $success = Util::removedir($file);
+ } else {
+ // entonces es un archivo
+ $file = "$file.php";
+ $success = unlink($file);
+ }
+
+ // mensaje
+ if ($success) {
+ echo "-> Eliminado: $file" . PHP_EOL;
+ } else {
+ throw new KumbiaException("No se ha logrado eliminar \"$file\"");
+ }
+ }
+
+}
View
177 core/extensions/helpers/ajax.php
@@ -0,0 +1,177 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * @category KumbiaPHP
+ * @package Helpers
+ * @copyright Copyright (c) 2005-2012 KumbiaPHP Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+
+/**
+ * Helper que utiliza Ajax
+ *
+ * @category KumbiaPHP
+ * @package Helpers
+ */
+class Ajax
+{
+
+ /**
+ * Crea un enlace en una Aplicacion actualizando la capa con ajax
+ *
+ * @param string $action ruta a la accion
+ * @param string $text texto a mostrar
+ * @param string $update capa a actualizar
+ * @param string $class clases adicionales
+ * @param string|array $attrs atributos adicionales
+ * @return string
+ */
+ public static function link($action, $text, $update, $class=NULL, $attrs=NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return '<a href="' . PUBLIC_PATH . "$action\" class=\"js-remote $class\" rel=\"#{$update}\" $attrs>$text</a>";
+ }
+
+ /**
+ * Crea un enlace a una acción actualizando la capa con ajax
+ *
+ * @param string $action ruta a la accion
+ * @param string $text texto a mostrar
+ * @param string $update capa a actualizar
+ * @param string $class clases adicionales
+ * @param string|array $attrs atributos adicionales
+ * @return string
+ */
+ public static function linkAction($action, $text, $update, $class=NULL, $attrs=NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return '<a href="' . PUBLIC_PATH . Router::get('controller_path') . "/$action\" class=\"js-remote $class\" rel=\"#{$update}\" $attrs>$text</a>";
+ }
+
+ /**
+ * Crea un enlace en una Aplicacion actualizando la capa con ajax con mensaje
+ * de confirmacion
+ *
+ * @param string $action ruta a la accion
+ * @param string $text texto a mostrar
+ * @param string $update capa a actualizar
+ * @param string $confirm mensaje de confirmacion
+ * @param string $class clases adicionales
+ * @param string|array $attrs atributos adicionales
+ * @return string
+ */
+ public static function linkConfirm($action, $text, $update, $confirm, $class=NULL, $attrs=NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return '<a href="' . PUBLIC_PATH . "$action\" class=\"js-remote-confirm $class\" rel=\"#{$update}\" title=\"$confirm\" $attrs>$text</a>";
+ }
+
+ /**
+ * Crea un enlace a una acción actualizando la capa con ajax con mensaje
+ * de confirmacion
+ *
+ * @param string $action ruta a la accion
+ * @param string $text texto a mostrar
+ * @param string $update capa a actualizar
+ * @param string $confirm mensaje de confirmacion
+ * @param string $class clases adicionales
+ * @param string|array $attrs atributos adicionales
+ * @return string
+ */
+ public static function linkActionConfirm($action, $text, $update, $confirm, $class=NULL, $attrs=NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return '<a href="' . PUBLIC_PATH . Router::get('controller_path') . "/$action\" class=\"js-remote-confirm $class\" rel=\"#{$update}\" title=\"$confirm\" $attrs>$text</a>";
+ }
+
+ /**
+ * Lista desplegable para actualizar usando ajax
+ *
+ * @param string $field nombre de campo
+ * @param array $data
+ * @param string $update capa que se actualizara
+ * @param string $action accion que se ejecutara
+ * @param string $class
+ * @param string|array $attrs
+ */
+ public static function select($field, $data, $update, $action, $class=null, $attrs=null)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // ruta a la accion
+ $action = PUBLIC_PATH . rtrim($action, '/') . '/';
+
+ // genera el campo
+ return Form::select($field, $data, "class=\"js-remote $class\" data-update=\"$update\" data-action=\"$action\" $attrs");
+ }
+
+ /**
+ * Lista desplegable para actualizar usando ajax que toma los valores de un array de objetos
+ *
+ * @param string $field nombre de campo
+ * @param string $show campo que se mostrará
+ * @param array $data Array('modelo','metodo','param')
+ * @param string $update capa que se actualizara
+ * @param string $action accion que se ejecutara
+ * @param string $blank campo en blanco
+ * @param string $class
+ * @param string|array $attrs
+ */
+ public static function dbSelect($field, $show, $data, $update, $action, $blank=null, $class=null, $attrs=null)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // ruta a la accion
+ $action = PUBLIC_PATH . rtrim($action, '/') . '/';
+
+ // genera el campo
+ return Form::dbSelect($field, $show, $data, $blank, "class=\"js-remote $class\" data-update=\"$update\" data-action=\"$action\" $attrs");
+ }
+
+ /**
+ * Genera un formulario Ajax
+ *
+ * @param string $update capa que se actualizara
+ * @param string $action accion a ejecutar
+ * @param string $class clase de estilo
+ * @param string $method metodo de envio
+ * @param string|array $attrs atributos
+ * @return string
+ */
+ public static function form($update, $action = NULL, $class = NULL, $method = 'post', $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ if ($action) {
+ $action = PUBLIC_PATH . $action;
+ } else {
+ $action = PUBLIC_PATH . ltrim(Router::get('route'), '/');
+ }
+ return "<form action=\"$action\" method=\"$method\" class=\"js-remote $class\" data-div=\"$update\" $attrs>";
+ }
+
+}
View
116 core/extensions/helpers/flash.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * Flash Es la clase standard para enviar advertencias,
+ * informacion y errores a la pantalla
+ *
+ * @category Kumbia
+ * @package Flash
+ * @copyright Copyright (c) 2005-2012 Kumbia Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+
+/**
+ * Clase para enviar mensajes a la vista
+ *
+ * Envio de mensajes de advertencia, éxito, información
+ * y errores a la vista.
+ * Tambien envia mensajes en la consola, si se usa desde consola.
+ *
+ * @category Kumbia
+ * @package Flash
+ */
+class Flash
+{
+
+ /**
+ * Visualiza un mensaje flash
+ *
+ * @param string $name Para tipo de mensaje y para CSS class='$name'.
+ * @param string $text Mensaje a mostrar
+ */
+ public static function show($name, $text)
+ {
+ if (isset($_SERVER['SERVER_SOFTWARE'])) {
+ echo '<div class="', $name, ' flash">', $text, '</div>', PHP_EOL;
+ } else {
+ echo $name, ': ', strip_tags($text), PHP_EOL;
+ }
+ }
+
+ /**
+ * Visualiza un mensaje de error
+ *
+ * @param string $text
+ */
+ public static function error($text)
+ {
+ return self::show('error', $text);
+ }
+
+ /**
+ * Visualiza un mensaje de advertencia en pantalla
+ *
+ * @param string $text
+ */
+ public static function warning($text)
+ {
+ return self::show('warning', $text);
+ }
+
+ /**
+ * Visualiza informacion en pantalla
+ *
+ * @param string $text
+ */
+ public static function info($text)
+ {
+ return self::show('info', $text);
+ }
+
+ /**
+ * Visualiza informacion de suceso correcto en pantalla
+ *
+ * @param string $text
+ */
+ public static function valid($text)
+ {
+ return self::show('valid', $text);
+ }
+
+ /**
+ * Visualiza informacion en pantalla
+ *
+ * @param string $text
+ *
+ * @deprecated ahora Flah::info()
+ */
+ public static function notice($text)
+ {
+ return self::show('info', $text);
+ }
+
+ /**
+ * Visualiza informacion de Suceso en pantalla
+ *
+ * @param string $text
+ *
+ * @deprecated ahora Flash::valid()
+ */
+ public static function success($text)
+ {
+ return self::show('valid', $text);
+ }
+
+}
View
755 core/extensions/helpers/form.php
@@ -0,0 +1,755 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * @category KumbiaPHP
+ * @package Helpers
+ * @copyright Copyright (c) 2005-2012 KumbiaPHP Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+
+/**
+ * Helper para Formularios
+ *
+ * @category KumbiaPHP
+ * @package Helpers
+ */
+class Form
+{
+
+ /**
+ * Utilizado para generar los id de los radio button,
+ * lleva un conteo interno
+ *
+ * @var array
+ */
+ protected static $_radios = array();
+ /**
+ * Utilizado para avisar al programador,si usa Form::file()
+ * y no tiene el form mulipart muestra un error
+ *
+ * @var bool
+ */
+ protected static $_multipart = FALSE;
+
+ /**
+ * Obtiene el valor de un componente tomado
+ * del mismo valor del nombre del campo y formulario
+ * que corresponda a un atributo del mismo nombre
+ * que sea un string, objeto o array.
+ *
+ * @param string $field
+ * @param mixed $value valor de campo
+ * @return mixed
+ */
+ public static function getFieldData($field, $value = null)
+ {
+ // Obtiene considerando el patrón de formato form.field
+ $formField = explode('.', $field, 2);
+
+ // Formato modelo.campo
+ if (isset($formField[1])) {
+ // Id de campo
+ $id = "{$formField[0]}_{$formField[1]}";
+ // Nombre de campo
+ $name = "{$formField[0]}[{$formField[1]}]";
+
+ // Verifica en $_POST
+ if (isset($_POST[$formField[0]][$formField[1]])) {
+ $value = $_POST[$formField[0]][$formField[1]];
+ } elseif ($value === null) {
+ // Autocarga de datos
+ $form = View::getVar($formField[0]);
+ if (is_array($form)) {
+ if (isset($form[$formField[1]]))
+ $value = $form[$formField[1]];
+ } elseif (is_object($form)) {
+ if (isset($form->$formField[1]))
+ $value = $form->{$formField[1]};
+ }
+ }
+ } else {
+ // Asignacion de Id y Nombre de campo
+ $id = $name = $field;
+
+ // Verifica en $_POST
+ if (isset($_POST[$field])) {
+ $value = $_POST[$field];
+ } elseif ($value === null) {
+ // Autocarga de datos
+ $value = View::getVar($field);
+ }
+ }
+
+ // Filtrar caracteres especiales
+ if ($value !== null) {
+ $value = htmlspecialchars($value, ENT_COMPAT, APP_CHARSET);
+ }
+
+ // Devuelve los datos
+ return array('id' => $id, 'name' => $name, 'value' => $value);
+ }
+
+ /**
+ * Obtiene el valor del campo por autocarga de valores
+ *
+ * @param string $field Nombre de campo
+ * @return mixed retorna NULL si no existe valor por autocarga
+ */
+ public static function getFieldValue($field)
+ {
+ // Obtiene considerando el patrón de formato form.field
+ $formField = explode('.', $field, 2);
+
+ // Formato modelo.campo
+ if (isset($formField[1])) {
+ // Verifica en $_POST
+ if (isset($_POST[$formField[0]][$formField[1]])) {
+ $value = $_POST[$formField[0]][$formField[1]];
+ } elseif ($value === null) {
+ // Autocarga de datos
+ $form = View::getVar($formField[0]);
+ if (is_array($form)) {
+ if (isset($form[$formField[1]]))
+ $value = $form[$formField[1]];
+ } elseif (is_object($form)) {
+ if (isset($form->$formField[1]))
+ $value = $form->{$formField[1]};
+ }
+ }
+ } else {
+ // Verifica en $_POST
+ if (isset($_POST[$field])) {
+ $value = $_POST[$field];
+ } elseif ($value === null) {
+ // Autocarga de datos
+ $value = View::getVar($field);
+ }
+ }
+
+ // Filtrar caracteres especiales
+ if ($value !== null) {
+ return htmlspecialchars($value, ENT_COMPAT, APP_CHARSET);
+ }
+
+ // Devuelve null
+ return null;
+ }
+
+ /**
+ * Crea un campo input "genérico"
+ *
+ * @param string $type
+ * @param string $field
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function in($type, $field, $attrs = NULL, $value = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name, id y value (solo para autoload) para el campo y los carga en el scope
+ extract(self::_getFieldData($field, $value), EXTR_OVERWRITE);
+
+ return "<input id=\"$id\" name=\"$name\" type=\"$type\" value=\"$value\" $attrs/>";
+ }
+
+ /**
+ * Crea un campo input
+ *
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $content Contenido interno (opcional)
+ * @return string
+ */
+ public static function input($attrs = NULL, $content = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ if (is_null($content)) {
+ return "<input $attrs/>";
+ }
+ return "<input $attrs>$content</input>";
+ }
+
+ /**
+ * Crea una etiqueta de formulario
+ *
+ * @param string $action Acción del formulario (opcional)
+ * @param string $method Por defecto es post (opcional)
+ * @param string|array $attrs Atributos de etiqueta (opcional)
+ * @return string
+ */
+ public static function open($action = NULL, $method = 'post', $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ if ($action) {
+ $action = PUBLIC_PATH . $action;
+ } else {
+ $action = PUBLIC_PATH . ltrim(Router::get('route'), '/');
+ }
+ return "<form action=\"$action\" method=\"$method\" $attrs>";
+ }
+
+ /**
+ * Crea una etiqueta de formulario multipart
+ *
+ * @param string $action Acción del formulario (opcional)
+ * @param string|array $attrs Atributos de etiqueta (opcional)
+ * @return string
+ */
+ public static function openMultipart($action = NULL, $attrs = NULL)
+ {
+ self::$_multipart = TRUE;
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ if ($action) {
+ $action = PUBLIC_PATH . $action;
+ } else {
+ $action = PUBLIC_PATH . substr(Router::get('route'), 1);
+ }
+ return "<form action=\"$action\" method=\"post\" enctype=\"multipart/form-data\" $attrs>";
+ }
+
+ /**
+ * Crea una etiqueta para cerrar un formulario
+ *
+ * @return string
+ */
+ public static function close()
+ {
+ self::$_multipart = FALSE;
+ return '</form>';
+ }
+
+ /**
+ * Crea un botón de submit para el formulario actual
+ *
+ * @param string $text Texto del botón
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @return string
+ */
+ public static function submit($text, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return "<input type=\"submit\" value=\"$text\" $attrs />";
+ }
+
+ /**
+ * Crea un botón reset
+ *
+ * @param string $text Texto del botón
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @return string
+ */
+ public static function reset($text, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return "<input type=\"reset\" value=\"$text\" $attrs />";
+ }
+
+ /**
+ * Crea un botón
+ *
+ * @param string $text Texto del botón
+ * @param array $attrs Atributos de campo (opcional)
+ * @return string
+ */
+ public static function button($text, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return "<input type=\"button\" value=\"$text\" $attrs />";
+ }
+
+ /**
+ * Crea un label
+ *
+ * @param string $text Texto a mostrar
+ * @param string $field Campo al que hace referencia
+ * @param string|array Atributos de campo (opcional)
+ * @return string
+ */
+ public static function label($text, $field, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return "<label for=\"$field\" $attrs>$text</label>";
+ }
+
+ /**
+ * Crea un campo text
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function text($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('text', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo select
+ *
+ * @param string $field Nombre de campo
+ * @param string $data Array de valores para la lista desplegable
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string|array $value Array para select multiple (opcional)
+ * @return string
+ */
+ public static function select($field, $data, $attrs = NULL, $value = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name, id y value (solo para autoload) para el campo y los carga en el scope
+ extract(self::getFieldData($field, $value), EXTR_OVERWRITE);
+
+ $options = '';
+ foreach ($data as $k => $v) {
+ $k = htmlspecialchars($k, ENT_COMPAT, APP_CHARSET);
+ $options .= "<option value=\"$k\"";
+ // Si es array $value para select multiple se seleccionan todos
+ if (is_array($value)) {
+ if (in_array($k, $value)) {
+ $options .= ' selected="selected"';
+ }
+ } else {
+ if ($k == $value) {
+ $options .= ' selected="selected"';
+ }
+ }
+ $options .= '>' . htmlspecialchars($v, ENT_COMPAT, APP_CHARSET) . '</option>';
+ }
+
+ return "<select id=\"$id\" name=\"$name\" $attrs>$options</select>";
+ }
+
+ /**
+ * Crea un campo checkbox
+ *
+ * @param string $field Nombre de campo
+ * @param string $checkValue Valor en el checkbox
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $checked Indica si se marca el campo (opcional)
+ * @return string
+ */
+ public static function check($field, $checkValue, $attrs = NULL, $checked = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name y id para el campo y los carga en el scope
+ extract(self::getFieldData($field, $checked === NULL), EXTR_OVERWRITE);
+
+ if ($checked || ($checked === NULL && $checkValue == $value)) {
+ $checked = 'checked="checked"';
+ }
+
+ return "<input id=\"$id\" name=\"$name\" type=\"checkbox\" value=\"$checkValue\" $attrs $checked/>";
+ }
+
+ /**
+ * Crea un campo radio button
+ *
+ * @param string $field Nombre de campo
+ * @param string $radioValue Valor en el radio
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $checked Indica si se marca el campo (opcional)
+ * @return string
+ */
+ public static function radio($field, $radioValue, $attrs = NULL, $checked = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name y id para el campo y los carga en el scope
+ extract(self::getFieldData($field, $checked === NULL), EXTR_OVERWRITE);
+
+ if ($checked || ($checked === NULL && $radioValue == $value)) {
+ $checked = 'checked="checked"';
+ }
+
+ // contador de campos radio
+ if (isset(self::$_radios[$field])) {
+ self::$_radios[$field]++;
+ } else {
+ self::$_radios[$field] = 0;
+ }
+ $id .= self::$_radios[$field];
+
+ return "<input id=\"$id\" name=\"$name\" type=\"radio\" value=\"$radioValue\" $attrs $checked/>";
+ }
+
+ /**
+ * Crea un botón de tipo imagen
+ *
+ * @param string $img Nombre o ruta de la imagen
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @return string
+ */
+ public static function submitImage($img, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return "<input type=\"image\" src=\"" . PUBLIC_PATH . "img/$img\" $attrs/>";
+ }
+
+ /**
+ * Crea un campo hidden
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function hidden($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('hidden', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo password
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ */
+ public static function pass($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('password', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo select que toma los valores de un array de objetos
+ *
+ * @param string $field Nombre de campo
+ * @param string $show Campo que se mostrara (opcional)
+ * @param array $data Array('modelo','metodo','param') (opcional)
+ * @param string $blank Campo en blanco (opcional)
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string|array $value (opcional) Array en select multiple
+ * @return string
+ */
+ public static function dbSelect($field, $show = NULL, $data = NULL, $blank = 'Seleccione', $attrs = NULL, $value = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name, id y value (solo para autoload) para el campo y los carga en el scope
+ extract(self::getFieldData($field, $value), EXTR_OVERWRITE);
+
+ // Si no se envía un campo por defecto, no se crea el tag option
+ if ($blank != NULL) {
+ $options = '<option value="">' . htmlspecialchars($blank, ENT_COMPAT, APP_CHARSET) . '</option>';
+ } else {
+ $options = '';
+ }
+
+ //por defecto el modelo de modelo(_id)
+ if ($data === NULL) {
+ $model_asoc = explode('.', $field, 2);
+ $model_asoc = substr(end($model_asoc), 0, -3); //se elimina el _id
+ $model_asoc = Load::model($model_asoc);
+ $pk = $model_asoc->primary_key[0];
+
+ if (!$show) {
+ //por defecto el primer campo no pk
+ $show = $model_asoc->non_primary[0];
+ }
+
+ $data = $model_asoc->find("columns: $pk,$show", "order: $show asc"); //mejor usar array
+ } else {
+ $model_asoc = Load::model($data[0]);
+ $pk = $model_asoc->primary_key[0];
+
+ // Verifica si existe el parámetro
+ if (isset($data[2])) {
+ $data = $model_asoc->$data[1]($data[2]);
+ } else {
+ $data = $model_asoc->$data[1]();
+ }
+ }
+
+ foreach ($data as $p) {
+ $options .= "<option value=\"{$p->$pk}\"";
+ // Si es array $value para select multiple se seleccionan todos
+ if (is_array($value)) {
+ if (in_array($p->$pk, $value)) {
+ $options .= ' selected="selected"';
+ }
+ } else {
+ if ($p->$pk == $value) {
+ $options .= ' selected="selected"';
+ }
+ }
+ $options .= '>' . htmlspecialchars($p->$show, ENT_COMPAT, APP_CHARSET) . '</option>';
+ }
+
+ return "<select id=\"$id\" name=\"$name\" $attrs>$options</select>" . PHP_EOL;
+ }
+
+ /**
+ * Crea un campo file
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @return string
+ */
+ public static function file($field, $attrs = NULL)
+ {
+ // aviso al programador
+ if (!self::$_multipart) {
+ Flash::error('Para poder subir ficheros, debe abrir el form con Form::openMultipart()');
+ }
+
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name y id, y los carga en el scope
+ extract(self::getFieldData($field, false), EXTR_OVERWRITE);
+
+ return "<input id=\"$id\" name=\"$name\" type=\"file\" $attrs/>";
+ }
+
+ /**
+ * Crea un campo textarea
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function textarea($field, $attrs = NULL, $value = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name, id y value (solo para autoload) para el campo y los carga en el scope
+ extract(self::getFieldData($field, $value), EXTR_OVERWRITE);
+
+ return "<textarea id=\"$id\" name=\"$name\" $attrs>$value</textarea>";
+ }
+
+ /**
+ * Crea un campo fecha
+ *
+ * @param string $field Nombre de campo
+ * @param string $class Clase de estilo (opcional)
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function date($field, $class = NULL, $attrs = NULL, $value = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ // Obtiene name, id y value (solo para autoload) para el campo y los carga en el scope
+ extract(self::getFieldData($field, $value), EXTR_OVERWRITE);
+
+ return "<input id=\"$id\" name=\"$name\" class=\"js-datepicker $class\" type=\"date\" value=\"$value\" $attrs/>";
+ }
+
+ /**
+ * Crea un campo search
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function search($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('search', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo tel
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function tel($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('tel', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo url
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function url($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('url', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo email
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function email($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('email', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo datetime
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function datetime($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('datetime', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo date
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function dateNew($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('date', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo month
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function month($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('month', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo week
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function week($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('week', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo time
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function time($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('time', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo datetime-local
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function datetimeLocal($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('datetime-local', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo number
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function number($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('number', $field, $attrs, $value);
+ }
+
+ /**
+ * Crea un campo range
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function range($field, $max=100, $min=0, $step=1, $attrs = NULL, $value = NULL)
+ {
+ return self::in('range', $field, "max=\"$max\" min=\"$min\" step=\"$step\" $attrs", $value);
+ }
+
+ /**
+ * Crea un campo color
+ *
+ * @param string $field Nombre de campo
+ * @param string|array $attrs Atributos de campo (opcional)
+ * @param string $value Valor de campo (opcional)
+ * @return string
+ */
+ public static function color($field, $attrs = NULL, $value = NULL)
+ {
+ return self::in('color', $field, $attrs, $value);
+ }
+
+}
View
287 core/extensions/helpers/html.php
@@ -0,0 +1,287 @@
+<?php
+/**
+ * KumbiaPHP web & app Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://wiki.kumbiaphp.com/Licencia
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@kumbiaphp.com so we can send you a copy immediately.
+ *
+ * @category KumbiaPHP
+ * @package Helpers
+ * @copyright Copyright (c) 2005-2012 KumbiaPHP Team (http://www.kumbiaphp.com)
+ * @license http://wiki.kumbiaphp.com/Licencia New BSD License
+ */
+
+/**
+ * Helper para Tags Html
+ *
+ * @category KumbiaPHP
+ * @package Helpers
+ */
+class Html
+{
+
+ /**
+ * Alternador para tabla zebra
+ *
+ * @var boolean
+ * @deprecated
+ */
+ protected static $_trClassAlternate = TRUE;
+ /**
+ * Metatags
+ *
+ * @var array
+ */
+ protected static $_metatags = array();
+ /**
+ * Enlaces de head
+ *
+ * @var array
+ */
+ protected static $_headLinks = array();
+
+ /**
+ * Crea un enlace usando la constante PUBLIC_PATH, para que siempre funcione
+ *
+ * @example Html::link
+ * echo Html::link('controller/action','Enlace')
+ * Crea un enlace a ese controller y acción con el nombre Enlace
+ *
+ * @param string $action Ruta a la acción
+ * @param string $text Texto a mostrar
+ * @param string|array $attrs Atributos adicionales
+ * @return string
+ */
+ public static function link($action, $text, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return '<a href="' . PUBLIC_PATH . "$action\" $attrs >$text</a>";
+ }
+
+ /**
+ * Devuelve una URL usando la constante PUBLIC_PATH, para que siempre funcione
+ *
+ * @example Html::url
+ * echo Html::url('controller/action')
+ * Devuelve una URL a ese controller y acción
+ *
+ * @param string $action Ruta a la acción
+ * @return string
+ */
+ public static function url($action)
+ {
+ return PUBLIC_PATH . $action;
+ }
+
+ /**
+ * Crea un enlace a una acción del mismo controller que estemos
+ *
+ * @example Html::linkAction
+ * echo Html::linkAction('accion/','Enlace a la acción del mismo controller')
+ *
+ * @param string $action
+ * @param string $text Texto a mostrar
+ * @param string|array $attrs Atributos adicionales
+ * @return string
+ */
+ public static function linkAction($action, $text, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ return '<a href="' . PUBLIC_PATH . Router::get('controller_path') . "/$action\" $attrs >$text</a>";
+ }
+
+ /**
+ * Permite incluir una imagen
+ *
+ * @param string $src Atributo src
+ * @param string $alt Atributo alt
+ * @param string|array $attrs Atributos adicionales
+ * @return string
+ */
+ public static function img($src, $alt=NULL, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ return '<img src="' . PUBLIC_PATH . "img/$src\" alt=\"$alt\" $attrs />";
+ }
+
+ /**
+ * Aplica estilo zebra a una tabla.
+ *
+ * @param string $class class css
+ * @param string|array $attrs
+ * @param unknown_type $start
+ * @return string
+ * @deprecated Mejor usar CSS
+ */
+ public static function trClass($class, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+ if (self::$_trClassAlternate) {
+ self::$_trClassAlternate = FALSE;
+ return "<tr class='$class' $attrs >";
+ } else {
+ self::$_trClassAlternate = TRUE;
+ return "<tr $attrs >";
+ }
+ }
+
+ /**
+ * Inicia el alternador de clase para tabla zebra
+ *
+ * @deprecated Mejor usar CSS
+ */
+ public static function trClassStart()
+ {
+ self::$_trClassAlternate = TRUE;
+ }
+
+ /**
+ * Crea un metatag
+ *
+ * @param string $content contenido del metatag
+ * @param string|array $attrs atributos
+ */
+ public static function meta($content, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = Tag::getAttrs($attrs);
+ }
+
+ self::$_metatags[] = array('content' => $content, 'attrs' => $attrs);
+ }
+
+ /**
+ * Incluye los metatags
+ *
+ * @return string
+ */
+ public static function includeMetatags()
+ {
+ return implode(array_unique(self::$_metatags), PHP_EOL);
+ }
+
+ /**
+ * Crea una lista a partir de un array
+ *
+ * @param string $content contenido del metatag
+ * @param string $type por defecto ul, y si no ol
+ * @param string|array $attrs atributos
+ * @return string
+ */
+ public static function lists($array, $type = 'ul', $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = self::getAttrs($attrs);
+ }
+
+ $list = "<$type $attrs>" . PHP_EOL;
+ foreach ($array as $item) {
+ $list .= "<li>$item</li>" . PHP_EOL;
+ }
+ $list .= "</$type>" . PHP_EOL;
+
+ return $list;
+ }
+
+ /**
+ * Incluye los CSS
+ *
+ * @return string
+ */
+ public static function includeCss()
+ {
+ $code = '';
+ foreach (Tag::getCss() as $css) {
+ $code .= '<link href="' . PUBLIC_PATH . "css/{$css['src']}.css\" rel=\"stylesheet\" type=\"text/css\" media=\"{$css['media']}\" />" . PHP_EOL;
+ }
+ return $code;
+ }
+
+ /**
+ * Enlaza un recurso externo
+ *
+ * @param string $href direccion url del recurso a enlazar
+ * @param string|array $attrs atributos
+ */
+ public static function headLink($href, $attrs = NULL)
+ {
+ if (is_array($attrs)) {
+ $attrs = self::getAttrs($attrs);
+ }
+
+ self::$_headLinks[] = array('href' => $href, 'attrs' => $attrs);
+ }
+
+ /**
+ * Enlaza una accion
+ *
+ * @param string $action ruta de accion
+ * @param string|array $attrs atributos
+ */
+ public static function headLinkAction($action, $attrs = NULL)
+ {
+ self::headLink(PUBLIC_PATH . $action, $attrs);
+ }
+
+ /**
+ * Enlaza un recurso de la aplicacion
+ *
+ * @param string $resource ubicacion del recurso en public
+ * @param string|array $attrs atributos
+ */
+ public static function headLinkResource($resource, $attrs = NULL)
+ {
+ self::headLink(PUBLIC_PATH . $resource, $attrs);
+ }
+
+ /**
+ * Incluye los links para el head
+ *
+ * @return string
+ */
+ public static function includeHeadLinks()
+ {
+ $code = '';
+ foreach (self::$_headLinks as $link) {
+ $code .= "<link href=\"{$link['href']}\" {$link['attrs']} />" . PHP_EOL;
+ }
+ return $code;
+ }
+
+ /**
+ * Incluye imágenes de gravatar.com
+ *
+ * Ejemplos: Html::gravatar
+ * Simple: echo Html::gravatar( $email ) <br>
+ * Completo: echo Html::gravatar( $email, $name, 20, 'http://www.example.com/default.jpg') <br>
+ * Un gravatar que es un link: echo Html::link( Html::gravatar($email), $url)
+ *
+ * @param string $email Correo para conseguir su gravatar
+ * @param string $alt Texto alternativo de la imagen. Por defecto: gravatar
+ * @param int $size Tamaño del gravatar. Un número de 1 a 512. Por defecto: 40
+ * @param string $default URL gravatar por defecto si no existe, o un default de gravatar. Por defecto: mm
+ * @return string
+ */
+ public static function gravatar($email, $alt='gravatar', $size=40, $default='mm')
+ {
+ $grav_url = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . '?d=' . urlencode($default) . '&s=' . $size;
+ return '<img src="' . $grav_url . '" alt="' . $alt . '" class="avatar" width="' . $size . '" height="'