/fw-panel/fw-files/libs/class.freshwork.php

https://bitbucket.org/freshworkstudio/sparta-ipad-pos · PHP · 230 lines · 192 code · 23 blank · 15 comment · 54 complexity · e16458e716027abfb244c05d02c36638 MD5 · raw file

  1. <?php
  2. class Freshwork{
  3. static $instance = null;
  4. var $modules = array();
  5. var $models = array();
  6. var $controllers = array();
  7. var $base_jss = array();
  8. var $reload_jss = array();
  9. var $base_csss = array();
  10. function Freshwork(){
  11. $this->getInstalledModules();
  12. $this->getModels();
  13. $this->getControllers();
  14. $this->base_js_file = "panel_base_js.js";
  15. $this->reload_js_file = "panel_reload_js.js";
  16. $this->base_css_file = "panel.css";
  17. $this->addBaseJs(PANEL_DIR."resources/js/jquery-1.4.1.min.js");
  18. }
  19. function getInstalledModules(){
  20. global $jump_folders;
  21. $tmp = array();
  22. //Obtiene nombre de carpetas dentro de MODULES_DIR
  23. if ($dh = opendir(MODULES_DIR)) {
  24. while (($module = readdir($dh)) !== false) {
  25. if (is_dir(MODULES_DIR.$module) && strpos($module, ".") !== 0 && strpos($module, "_") !== 0 && !in_array($module,$jump_folders))
  26. $tmp[] = $module;
  27. }
  28. }
  29. closedir($dh);
  30. $this->modules = $tmp;
  31. }
  32. function getModels(){
  33. $tmp = array();
  34. /* ESTO DEBIESE DESAPARECER */
  35. if(file_exists(MODELS_DIR)){
  36. if ($dh = opendir(MODELS_DIR)) {
  37. while (($model = readdir($dh)) !== false) {
  38. if (!is_dir(MODELS_DIR.$model) && $model!="." && $model!="..")
  39. $tmp[MODELS_DIR.$model] = Model::file2name($model);
  40. }
  41. }
  42. closedir($dh);
  43. }
  44. foreach($this->modules as $module){
  45. $dir = MODULES_DIR.$module."/models/";
  46. /* ESTO SE DEBIESE QUEDAR SOLO */
  47. if(file_exists($dir)){
  48. if ($dh = opendir($dir)) {
  49. while (($model = readdir($dh)) !== false) {
  50. if (!is_dir($dir.$model) && $model!="." && $model!=".."){
  51. if(substr($model,-4) == ".php"){
  52. //Convertir nombre de Archivos a Camel Case with _
  53. $tmp[$dir.$model] = Model::file2name($model);
  54. }
  55. }
  56. }
  57. }
  58. closedir($dh);
  59. }
  60. }
  61. $this->models = $tmp;
  62. }
  63. function getControllers(){
  64. $tmp = array();
  65. /* ESTO DEBIESE DESAPARECER */
  66. if(file_exists(CONTROLLERS_DIR)){
  67. if ($dh = opendir(CONTROLLERS_DIR)) {
  68. while (($model = readdir($dh)) !== false) {
  69. if (!is_dir(CONTROLLERS_DIR.$model) && $model!="." && $model!="..")
  70. $tmp[CONTROLLERS_DIR.$model] = substr($model,0,-4);
  71. }
  72. }
  73. closedir($dh);
  74. }
  75. foreach($this->modules as $module){
  76. $dir = MODULES_DIR.$module."/controllers/";
  77. /* ESTO SE DEBIESE QUEDAR SOLO */
  78. if(file_exists($dir)){
  79. if ($dh = opendir($dir)) {
  80. while (($model = readdir($dh)) !== false) {
  81. if (!is_dir($dir.$model) && $model!="." && $model!=".."){
  82. if(substr($model,-4) == ".php"){
  83. //Convertir nombre de Archivos a Camel Case with _
  84. $words = explode("_",substr($model,0,-4));
  85. foreach($words as $key => $word)$words[$key] = ucfirst($word);
  86. $name = implode("_",$words);
  87. $tmp[$dir.$model] = $name;
  88. }
  89. }
  90. }
  91. }
  92. closedir($dh);
  93. }
  94. }
  95. $this->controllers = $tmp;
  96. }
  97. //BASE JAVASCRIPTS
  98. function addBaseJs($str,$prepend = false){
  99. $args = (is_array($str))?$str:func_get_args();
  100. foreach($args as $js){
  101. if(is_string($js)){
  102. if($prepend)array_unshift($this->base_jss, $js);
  103. else $this->base_jss[] = $js;
  104. }
  105. }
  106. }
  107. function loadBaseJs(){
  108. $rewrite = false;
  109. if(file_exists(TMP_DIR.$this->base_js_file))$jsmtime = filemtime(TMP_DIR.$this->base_js_file);
  110. else $rewrite = true;
  111. foreach($this->base_jss as $js){
  112. if($rewrite)break;
  113. $mtime = filemtime($js);
  114. if($mtime >= $jsmtime)$rewrite = true;
  115. }
  116. //echo "<pre>";
  117. //print_r($this->base_jss);
  118. //echo "</pre>";
  119. if($rewrite){
  120. $str = "";
  121. foreach($this->base_jss as $js){
  122. $str .= file_get_contents($js);
  123. }
  124. file_put_contents(TMP_DIR.$this->base_js_file,JSMin::minify($str));
  125. }
  126. }
  127. function getBaseJsFilename($php = false){
  128. return ($php)?TMP_DIR.$this->base_js_file:TMP_URL.$this->base_js_file."?v=".rand(1,221422);
  129. }
  130. function putBaseJs(){
  131. foreach($this->base_jss as $js){
  132. echo '<script type="text/javascript" src="'.substr($js,strlen(PANEL_DIR)).'"></script>'."\n\t";
  133. }
  134. /*echo '<script type="text/javascript" src="'.$this->getBaseJsFilename().'"></script>';*/
  135. }
  136. //RELOAD JAVSCRIPTS
  137. function addReloadJs($str){
  138. $args = (is_array($str))?$str:func_get_args();
  139. foreach($args as $js){
  140. $this->reload_jss[] = $js;
  141. }
  142. }
  143. function loadReloadJs(){
  144. $rewrite = false;
  145. if(file_exists(TMP_DIR.$this->reload_js_file))$jsmtime = filemtime(TMP_DIR.$this->reload_js_file);
  146. else $rewrite = true;
  147. foreach($this->reload_jss as $js){
  148. if($rewrite)break;
  149. $mtime = filemtime($js);
  150. if($mtime >= $jsmtime)$rewrite = true;
  151. }
  152. if($rewrite){
  153. $str = "";
  154. foreach($this->reload_jss as $js){
  155. $str .= file_get_contents($js);
  156. }
  157. file_put_contents(TMP_DIR.$this->reload_js_file,JSMin::minify($str));
  158. }
  159. }
  160. function getReloadJsFilename($php = false){
  161. return ($php)?TMP_DIR.$this->reload_js_file:TMP_URL.$this->reload_js_file;
  162. }
  163. function putReloadJs(){
  164. echo '<script type="text/javascript" src="'.$this->getReloadJsFilename().'"></script>';
  165. }
  166. //PANEL BASE CSS
  167. function addBaseCss($str){
  168. $args = (is_array($str))?$str:func_get_args();
  169. foreach($args as $css){
  170. $this->base_csss[] = $css;
  171. }
  172. }
  173. function loadBaseCss(){
  174. $rewrite = false;
  175. if(file_exists(TMP_DIR.$this->base_css_file))$cssmtime = filemtime(TMP_DIR.$this->base_css_file);
  176. else $rewrite = true;
  177. foreach($this->base_csss as $css){
  178. if($rewrite)break;
  179. $mtime = filemtime($css);
  180. if($mtime >= $cssmtime)$rewrite = true;
  181. }
  182. if($rewrite){
  183. $str = "";
  184. foreach($this->base_csss as $css){
  185. $str .= file_get_contents($css);
  186. }
  187. file_put_contents(TMP_DIR.$this->base_css_file,css_compress($str));
  188. }
  189. }
  190. function getBaseCssFilename(){
  191. return TMP_URL.$this->base_css_file;
  192. }
  193. function putBaseCss(){
  194. foreach($this->base_csss as $css){
  195. $css = substr($css,strlen(PANEL_DIR));
  196. echo '<link type="text/css" media="screen" rel="stylesheet" href="'.$css.'" />'."\n\t";
  197. }
  198. //echo '<link type="text/css" media="screen" rel="stylesheet" href="'.$this->getBaseCssFilename().'" />';
  199. }
  200. static function getInstance(){
  201. if(self::$instance == null){
  202. self::$instance = new self();
  203. }
  204. return self::$instance;
  205. }
  206. }
  207. ?>