From 5a69e2d66d3d5a2d02a8b7a424ce5deef76bfb7a Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 16 Apr 2015 02:53:21 +0200 Subject: [PATCH 01/19] first commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..66038ed --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# phaview From 92e7b17f0e720986480893d8c6c25bff2d584453 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 19 Apr 2015 15:22:10 +0200 Subject: [PATCH 02/19] Added new files --- composer.json | 22 ++++++ src/View.php | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 composer.json create mode 100644 src/View.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c03ded6 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "phangoapp/phaview", + "description": "A simple class for create views", + "require-dev": { + "phpunit/phpunit": "~4.8@dev", + "phautils/utils": "dev-master" + }, + "license": "GPL", + "authors": [ + { + "name": "Antonio de la Rosa", + "email": "webmaster@web-t-sys.com" + } + ], + "minimum-stability": "dev-master", + "require": {}, + "autoload": { + "psr-4": { + "PhaRouter\\": "src" + } + } +} diff --git a/src/View.php b/src/View.php new file mode 100644 index 0000000..c58c89f --- /dev/null +++ b/src/View.php @@ -0,0 +1,180 @@ +0) + { + + $this->folder_env=$arr_arg; + + } + + $this->root_path=getcwd(); + + } + + /** + * Very important function used for load views. Is the V in the MVC paradigm. Phango is an MVC framework and has separate code and html. + * + * load_view is used for load the views. Views in Phango are php files with a function that have a special name with "View" suffix. For example, if you create a view file with the name blog.php, inside you need create a php function called BlogView(). The arguments of this function can be that you want, how on any normal php function. The view files need to be saved on a "view" folders inside of a theme folder, or a "views/module_name" folder inside of a module being "module_name" the name of the module. + * + * @param array $arr_template_values Arguments for the view function of the view. + * @param string $template Name of the view. Tipically views/$template.php or modules/name_module/views/name_module/$template.php + * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. + */ + + function load_view($arr_template_values_values, $template) + { + + //First see in controller/view/template, if not see in /views/template + + $yes_cache=0; + + if(!isset($this->cache_template[$template])) + { + + foreach($this->folder_env as $base_path) + { + + $view_path=$this->root_path.'/'.$base_path.'/'.$template.'.php'; + + if(is_file($view_path)) + { + + include($view_path); + + $yes_cache=1; + + break; + + } + + } + + //Search view first on an theme + + /*$theme_view=$this->root_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php'; + + //Search view on the real module + + $script_module_view=$this->root_path.'modules/'.$this->script_module.'/views/'.strtolower($template).'.php'; + + //Search view on other module specified. + + $module_view=$this->root_path.'modules/'.$module_theme.'/views/'.strtolower($template).'.php';*/ + + /*if(!is_file($theme_view)) + { + + if(!is_file($script_module_view)) + { + + if(!is_file($module_view)) + { + + $output=ob_get_contents(); + + ob_clean(); + + $check_error_lang[0]='Error while loading template, check that the view exists...'; + $check_error_lang[1]='Error while loading template library '.$template.' in path '.$theme_view.' ,'.$script_module_view.' and '.$module_view.', check config.php or that template library exists... '; + + show_error($check_error_lang[0], $check_error_lang[1], $output); + + ob_end_flush(); + + die; + + } + else + { + + include($module_view); + + } + + } + else + { + + include($script_module_view); + + } + + } + else + { + + include($theme_view); + + }*/ + + //If load view, save function name for call write the html again without call include view too + + if($yes_cache==1) + { + + $this->cache_template[$template]=basename($template).'View'; + + } + else + { + + throw new \Exception('Error: view not found: '.$view_path); + die; + + } + + } + + ob_start(); + + $func_view=$this->cache_template[$template]; + + //Load function from loaded view with his parameters + + call_user_func_array($func_view, $arr_template_values); + + $out_template=ob_get_contents(); + + ob_end_clean(); + + return $out_template; + + } + + +} + +?> \ No newline at end of file From 153927546886cacb36669951336d471cc5849990 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 20 Apr 2015 04:31:09 +0200 Subject: [PATCH 03/19] Fixes on view --- src/View.php | 306 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 247 insertions(+), 59 deletions(-) diff --git a/src/View.php b/src/View.php index c58c89f..0dd16cb 100644 --- a/src/View.php +++ b/src/View.php @@ -1,6 +1,7 @@ tag. For example, a view that need a initialitation code in the principal view can use this array and you can insert the code in principal View using loadHeader method for load all header code writed in the array by children views. + */ + + public $header=array(); + /** * The construct for create a view object * @@ -54,7 +103,7 @@ class View { * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. */ - function load_view($arr_template_values_values, $template) + public function loadView($arr_template_values, $template) { //First see in controller/view/template, if not see in /views/template @@ -82,64 +131,6 @@ class View { } - //Search view first on an theme - - /*$theme_view=$this->root_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php'; - - //Search view on the real module - - $script_module_view=$this->root_path.'modules/'.$this->script_module.'/views/'.strtolower($template).'.php'; - - //Search view on other module specified. - - $module_view=$this->root_path.'modules/'.$module_theme.'/views/'.strtolower($template).'.php';*/ - - /*if(!is_file($theme_view)) - { - - if(!is_file($script_module_view)) - { - - if(!is_file($module_view)) - { - - $output=ob_get_contents(); - - ob_clean(); - - $check_error_lang[0]='Error while loading template, check that the view exists...'; - $check_error_lang[1]='Error while loading template library '.$template.' in path '.$theme_view.' ,'.$script_module_view.' and '.$module_view.', check config.php or that template library exists... '; - - show_error($check_error_lang[0], $check_error_lang[1], $output); - - ob_end_flush(); - - die; - - } - else - { - - include($module_view); - - } - - } - else - { - - include($script_module_view); - - } - - } - else - { - - include($theme_view); - - }*/ - //If load view, save function name for call write the html again without call include view too if($yes_cache==1) @@ -163,6 +154,8 @@ class View { $func_view=$this->cache_template[$template]; //Load function from loaded view with his parameters + + array_unshift($arr_template_values, $this); call_user_func_array($func_view, $arr_template_values); @@ -174,6 +167,201 @@ class View { } + /** + * + */ + + public function dynamicGetMediaUrl($path_file) + { + + return $this->php_file.'/'.$path_file; + + } + + /** + * + */ + + public function staticGetMediaUrl($path_file) + { + + return $this->url_media.'/'.$path_file; + + } + + /** + * + */ + + public function setProduction($value=1) + { + + if($value==1) + { + + $production=1; + $this->func_media='staticGetMediaUrl'; + + } + else + { + + $production=0; + + $this->func_media='dynamicGetMediaUrl'; + + } + + } + + /** + * + */ + + public function getMediaUrl($path_file) + { + + $func_media=$this->func_media; + + return $this->$func_media($path_file); + + } + + /** + * Method for load media files. Method for load simple media file, is only for development + * + * This method is used on php files for retrieve media files using a very simple url dispatcher. + * + * @warning NO USE THIS METHOD IN PRODUCTION. + * + */ + + public function loadMediaFile($url) + { + + //Check files origin. + + if($this->production==0) + { + + $yes_file=0; + + $arr_url=explode($this->php_file.'/', $url); + + $final_path=''; + + if(isset($arr_url[1])) + { + + //Clean the path of undesirerable elements. + + $arr_path=explode('/', $arr_url[1]); + + $c=count($arr_path)-1; + + //foreach($arr_path as $key_path => $item_path) + for($x=0;$x<$c-1;$x++) + { + + $arr_path[$key_path]=Utils::slugify($item_path, $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); + + } + + $arr_path[$c]=Utils::slugify($arr_path[$c], $respect_upper=1, $replace_space='-', $replace_dot=0, $replace_barr=1); + + $final_path=implode('/', $arr_path); + + + } + + foreach($this->folder_env as $folder) + { + + $file_path=$this->root_path.'/'.$folder.'/'.$this->path_media.'/'.$final_path; + + if(is_file($file_path)) + { + $yes_file=1; + + break; + + } + + } + + if($yes_file==1) + { + + $ext_info=pathinfo($file_path); + + settype($ext_info['extension'], 'string'); + + switch($ext_info['extension']) + { + + default: + + $type_mime='text/plain'; + + break; + + case 'js': + + $type_mime='application/javascript'; + + break; + + case 'css': + + $type_mime='text/css'; + + break; + + case 'gif': + + $type_mime='image/gif'; + + break; + + case 'png': + + $type_mime='image/png'; + + break; + + case 'jpg': + + $type_mime='image/jpg'; + + break; + + } + + + + header('Content-Type: '.$type_mime); + + readfile($file_path); + + die; + + + } + else + { + + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); + + echo 'File not found...'; + + die; + + } + + } + + } + } From d81acb46c78cefe28929b3068d09c7f2532b0308 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 20 Apr 2015 17:54:32 +0200 Subject: [PATCH 04/19] Fixes on view --- src/View.php | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 0dd16cb..5f50198 100644 --- a/src/View.php +++ b/src/View.php @@ -215,7 +215,8 @@ class View { } /** - * + * Method for obtain a url for a media file. + * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ public function getMediaUrl($path_file) @@ -362,6 +363,73 @@ class View { } + /** + * Method that use $this->css array for create a series of html tags that load the css stylesheets + * + * This function is used inside of html tag normally for load css files. + */ + + public function loadCSS() + { + + $arr_final_css=array(); + + foreach($this->css as $css) + { + $url=$this->getMediaUrl('css/'.$css); + + $arr_final_css[]=''."\n"; + + } + + return implode('', $arr_final_css); + + } + + /** + * Method that use $this->js array for create a series of html tags that load the javascript files + * + * This function is used inside of html tag normally for load js files. + */ + + public function loadJS() + { + + $arr_final_js=array(); + + foreach($this->js as $js) + { + $url=$this->getMediaUrl('js/'.$js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n";; + + } + + return implode('', $arr_final_js); + + } + + /** + * Method that use $this->header array for create a series of code (normally javascript) on tag. + * + * This function is used inside of html tag normally for load inline javascript code. + */ + + public function loadHeader() + { + + $arr_final_header=array(); + + foreach($this->header as $header) + { + + $arr_final_header[]=$header."\n"; + + } + + return implode('', $arr_final_header); + + } } From 234c70d317816a406989e9b6c015a6b4c3b9c22f Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 20 Apr 2015 18:00:53 +0200 Subject: [PATCH 05/19] Added documentation in code --- src/View.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/View.php b/src/View.php index 5f50198..86efae0 100644 --- a/src/View.php +++ b/src/View.php @@ -168,7 +168,9 @@ class View { } /** + * Method for create a url for access files via .php script * + * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ public function dynamicGetMediaUrl($path_file) @@ -179,6 +181,9 @@ class View { } /** + * Method for create a url for access files via http server + * + * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media * */ @@ -190,7 +195,9 @@ class View { } /** + * Method for change the method for access to media files. * + * @param boolean $value Set the production property.If true then access to media files directly, if false, access to media files via specified .php script */ public function setProduction($value=1) From 6d8550a1bbdbbd16014ccf2e1294d25aba4a0af4 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 21 Apr 2015 04:25:21 +0200 Subject: [PATCH 06/19] Fixes for psr-4 standard --- composer.json | 2 +- src/View.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c03ded6..fd462e3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": {}, "autoload": { "psr-4": { - "PhaRouter\\": "src" + "PhangoApp\\PhaRouter\\": "src" } } } diff --git a/src/View.php b/src/View.php index 86efae0..f2ef7a7 100644 --- a/src/View.php +++ b/src/View.php @@ -1,7 +1,7 @@ Date: Fri, 24 Apr 2015 04:47:02 +0200 Subject: [PATCH 07/19] Fixes for the new behaviour --- src/View.php | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/View.php b/src/View.php index f2ef7a7..73bebec 100644 --- a/src/View.php +++ b/src/View.php @@ -9,37 +9,37 @@ class View { * Root path for includes app folders */ - public $root_path=__DIR__; + static public $root_path=__DIR__; /** * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break */ - public $folder_env=array('views/default', 'app/views'); + static public $folder_env=array('views/default', 'app/views'); /** * Array for caching the template call... */ - public $cache_template=array(); + static public $cache_template=array(); /** * Path of static media files (javascript, images and css). */ - public $path_media='media'; + static public $path_media='media'; /** * Url of static media files (javascript, images and css). */ - public $url_media='media'; + static public $url_media='media'; /** * Media .php path. */ - public $php_file='showmedia.php'; + static public $php_file='showmedia.php'; /** * Internal property used for see if this media are in production @@ -51,7 +51,7 @@ class View { * Internal property used for define the method used for retrieve the media files. */ - protected $func_media='dynamicGetMediaUrl'; + static protected $func_media='dynamicGetMediaUrl'; /** * An array where you can add new css in all views. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use loadCss method for load all css writed in the array by children views. @@ -85,11 +85,11 @@ class View { if(count($arr_arg)>0) { - $this->folder_env=$arr_arg; + View::$folder_env=$arr_arg; } - $this->root_path=getcwd(); + View::$root_path=getcwd(); } @@ -110,13 +110,13 @@ class View { $yes_cache=0; - if(!isset($this->cache_template[$template])) + if(!isset(View::$cache_template[$template])) { - foreach($this->folder_env as $base_path) + foreach(View::$folder_env as $base_path) { - $view_path=$this->root_path.'/'.$base_path.'/'.$template.'.php'; + $view_path=View::$root_path.'/'.$base_path.'/'.$template.'.php'; if(is_file($view_path)) { @@ -136,7 +136,7 @@ class View { if($yes_cache==1) { - $this->cache_template[$template]=basename($template).'View'; + View::$cache_template[$template]=basename($template).'View'; } else @@ -151,7 +151,7 @@ class View { ob_start(); - $func_view=$this->cache_template[$template]; + $func_view=View::$cache_template[$template]; //Load function from loaded view with his parameters @@ -176,7 +176,7 @@ class View { public function dynamicGetMediaUrl($path_file) { - return $this->php_file.'/'.$path_file; + return View::$php_file.'/'.$path_file; } @@ -190,7 +190,7 @@ class View { public function staticGetMediaUrl($path_file) { - return $this->url_media.'/'.$path_file; + return View::$url_media.'/'.$path_file; } @@ -200,14 +200,14 @@ class View { * @param boolean $value Set the production property.If true then access to media files directly, if false, access to media files via specified .php script */ - public function setProduction($value=1) + static public function setProduction($value=1) { if($value==1) { $production=1; - $this->func_media='staticGetMediaUrl'; + View::$func_media='staticGetMediaUrl'; } else @@ -215,7 +215,7 @@ class View { $production=0; - $this->func_media='dynamicGetMediaUrl'; + View::$func_media='dynamicGetMediaUrl'; } @@ -229,7 +229,7 @@ class View { public function getMediaUrl($path_file) { - $func_media=$this->func_media; + $func_media=View::$func_media; return $this->$func_media($path_file); @@ -254,7 +254,7 @@ class View { $yes_file=0; - $arr_url=explode($this->php_file.'/', $url); + $arr_url=explode(View::$php_file.'/', $url); $final_path=''; @@ -282,10 +282,10 @@ class View { } - foreach($this->folder_env as $folder) + foreach(View::$folder_env as $folder) { - $file_path=$this->root_path.'/'.$folder.'/'.$this->path_media.'/'.$final_path; + $file_path=View::$root_path.'/'.$folder.'/'.View::$path_media.'/'.$final_path; if(is_file($file_path)) { From 0c317280185be709b0ec2942b62a98ca5c21b8da Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 26 Apr 2015 17:54:17 +0200 Subject: [PATCH 08/19] Fix on composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fd462e3..021c805 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": {}, "autoload": { "psr-4": { - "PhangoApp\\PhaRouter\\": "src" + "PhangoApp\\PhaView\\": "src" } } } From 72a2bdab45556d0d4be2f9e7aca334bb20586c05 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 28 Apr 2015 16:14:32 +0200 Subject: [PATCH 09/19] Fixes on View --- src/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 73bebec..5984f4b 100644 --- a/src/View.php +++ b/src/View.php @@ -15,7 +15,7 @@ class View { * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break */ - static public $folder_env=array('views/default', 'app/views'); + static public $folder_env=array('views/default'); /** * Array for caching the template call... From 083ac7e20212a5382d14b24057b6ad1b271e3a85 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 8 May 2015 05:23:49 +0200 Subject: [PATCH 10/19] Fixes on views --- src/View.php | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/View.php b/src/View.php index 5984f4b..360ffec 100644 --- a/src/View.php +++ b/src/View.php @@ -45,7 +45,7 @@ class View { * Internal property used for see if this media are in production */ - protected $production=0; + static protected $production=0; /** * Internal property used for define the method used for retrieve the media files. @@ -57,19 +57,19 @@ class View { * An array where you can add new css in all views. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use loadCss method for load all css writed in the array by children views. */ - public $css=array(); + static public $css=array(); /** * An array where you can add new js in all views. For example, a view that use a special js can use this array and you can insert the value 'special.js' in principal View using loadJs method for load all js writed in the array by children views. */ - public $js=array(); + static public $js=array(); /** * An array where you can add new code in
tag. For example, a view that need a initialitation code in the principal view can use this array and you can insert the code in principal View using loadHeader method for load all header code writed in the array by children views. */ - public $header=array(); + static public $header=array(); /** * The construct for create a view object @@ -77,7 +77,7 @@ class View { * @param string $folder_base The folder used how base path for search view files */ - public function __construct() + /*public function __construct() { $arr_arg=func_get_args(); @@ -91,7 +91,7 @@ class View { View::$root_path=getcwd(); - } + }*/ /** * Very important function used for load views. Is the V in the MVC paradigm. Phango is an MVC framework and has separate code and html. @@ -103,7 +103,7 @@ class View { * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. */ - public function loadView($arr_template_values, $template) + static public function loadView($arr_template_values, $template) { //First see in controller/view/template, if not see in /views/template @@ -155,7 +155,7 @@ class View { //Load function from loaded view with his parameters - array_unshift($arr_template_values, $this); + //array_unshift($arr_template_values, $this); call_user_func_array($func_view, $arr_template_values); @@ -173,7 +173,7 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - public function dynamicGetMediaUrl($path_file) + static public function dynamicGetMediaUrl($path_file) { return View::$php_file.'/'.$path_file; @@ -187,7 +187,7 @@ class View { * */ - public function staticGetMediaUrl($path_file) + static public function staticGetMediaUrl($path_file) { return View::$url_media.'/'.$path_file; @@ -226,12 +226,12 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - public function getMediaUrl($path_file) + static public function getMediaUrl($path_file) { $func_media=View::$func_media; - return $this->$func_media($path_file); + return View::$func_media($path_file); } @@ -244,12 +244,12 @@ class View { * */ - public function loadMediaFile($url) + static public function loadMediaFile($url) { //Check files origin. - if($this->production==0) + if(View::$production==0) { $yes_file=0; @@ -376,14 +376,14 @@ class View { * This function is used inside of html tag normally for load css files. */ - public function loadCSS() + static public function loadCSS() { $arr_final_css=array(); - foreach($this->css as $css) + foreach(View::$css as $css) { - $url=$this->getMediaUrl('css/'.$css); + $url=View::getMediaUrl('css/'.$css); $arr_final_css[]=''."\n"; @@ -399,14 +399,14 @@ class View { * This function is used inside of html tag normally for load js files. */ - public function loadJS() + static public function loadJS() { $arr_final_js=array(); - foreach($this->js as $js) + foreach(View::$js as $js) { - $url=$this->getMediaUrl('js/'.$js); + $url=View::getMediaUrl('js/'.$js); $arr_final_js[]=$arr_final_jscript[]=''."\n";; @@ -422,12 +422,12 @@ class View { * This function is used inside of html tag normally for load inline javascript code. */ - public function loadHeader() + static public function loadHeader() { $arr_final_header=array(); - foreach($this->header as $header) + foreach(View::$header as $header) { $arr_final_header[]=$header."\n"; @@ -438,6 +438,18 @@ class View { } + /** + * A method for make a redirect based on a theme + * + */ + + static public function loadTheme($title, $cont_index) + { + + echo View::loadView(array($title, $cont_index),'home'); + + } + } ?> \ No newline at end of file From 92e4e9134cf31909b4d9b34b35376ff4100d3ee7 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 11 May 2015 01:27:07 +0200 Subject: [PATCH 11/19] Fixes --- src/View.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 360ffec..6a44d3f 100644 --- a/src/View.php +++ b/src/View.php @@ -271,7 +271,7 @@ class View { for($x=0;$x<$c-1;$x++) { - $arr_path[$key_path]=Utils::slugify($item_path, $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); + $arr_path[$x]=Utils::slugify($arr_path[$x], $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); } @@ -289,6 +289,7 @@ class View { if(is_file($file_path)) { + $yes_file=1; break; From 12f00ab1511ff4978128e2908d0282285789cd43 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 11 May 2015 04:10:42 +0200 Subject: [PATCH 12/19] Fixes on view --- src/View.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/src/View.php b/src/View.php index 6a44d3f..d2891b2 100644 --- a/src/View.php +++ b/src/View.php @@ -382,6 +382,8 @@ class View { $arr_final_css=array(); + View::$css=array_unique(View::$css); + foreach(View::$css as $css) { $url=View::getMediaUrl('css/'.$css); @@ -404,6 +406,8 @@ class View { { $arr_final_js=array(); + + View::$js=array_unique(View::$js); foreach(View::$js as $js) { @@ -427,7 +431,7 @@ class View { { $arr_final_header=array(); - + foreach(View::$header as $header) { @@ -435,7 +439,7 @@ class View { } - return implode('', $arr_final_header); + return implode("\n", $arr_final_header); } @@ -451,6 +455,98 @@ class View { } + /** + * Function for load multiple views for a only source file. + * + * Useful for functions where you need separated views for use on something, When you use load_view for execute a view function, the names used for views are in $func_views array. + * + * @param string $template of the view library. Use the same format for normal views. + * @param string The names of templates, used how template_name for call views with load_view. + */ + + static public function loadLibrariesViews($template, $func_views=array()) + { + + foreach(View::$folder_env as $base_path) + { + + $view_path=View::$root_path.'/'.$base_path.'/'.$template.'.php'; + + if(is_file($view_path)) + { + + include($view_path); + + foreach($func_views as $template) + { + + View::$cache_template[$template]=basename($template).'View'; + + } + + break; + + } + + } + + /*$theme=PhangoVar::$dir_theme; + + $container_theme=PhangoVar::$module_theme; + + $view=''; + + //Load views from a source file... + + //Check func views... + + $no_loaded=0; + + foreach($func_views as $template_check) + { + + if(isset(PhangoVar::$cache_template[$template_check])) + { + //Function view loaded, return because load_view load the function automatically. + + $no_loaded++; + + } + + } + + if($no_loaded==0) + { + if(!include_once(PhangoVar::$base_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php')) + { + + $output_error_view=ob_get_contents(); + + ob_clean(); + + if(!include_once(PhangoVar::$base_path.'modules/'.PhangoVar::$script_module.'/views/'.strtolower($template).'.php')) + { + + + + } + + } + + } + + //Forever register views if the code use different functions in a same library. + + foreach($func_views as $template) + { + + PhangoVar::$cache_template[$template]=basename($template).'View'; + + }*/ + + + } + } ?> \ No newline at end of file From fb64d50a0ed13138ec20b3217ca08620f3eea94e Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 12 May 2015 02:47:09 +0200 Subject: [PATCH 13/19] Fix on variables --- src/View.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/View.php b/src/View.php index d2891b2..6570b41 100644 --- a/src/View.php +++ b/src/View.php @@ -547,6 +547,30 @@ class View { } + static public function set_flash($text) + { + + $_SESSION['flash_txt']=$text; + + } + + static public function show_flash() + { + + if(isset($_SESSION['flash_txt'])) + { + if($_SESSION['flash_txt']!='') + { + + return View::loadView(array($_SESSION['flash_txt']), 'flash'); + + } + } + + return ''; + + } + } ?> \ No newline at end of file From 5948fe2c79cfb3c23c7a18302442c8f772c9d304 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 14 May 2015 17:34:32 +0200 Subject: [PATCH 14/19] Fixes --- src/View.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 6570b41..9069cb3 100644 --- a/src/View.php +++ b/src/View.php @@ -561,8 +561,11 @@ class View { { if($_SESSION['flash_txt']!='') { + $text=$_SESSION['flash_txt']; + + $_SESSION['flash_txt']=''; - return View::loadView(array($_SESSION['flash_txt']), 'flash'); + return View::loadView(array($text), 'common/utilities/flash'); } } From c43245ecdc113b55434f262a8a60ea14caafdd21 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 14 Jun 2015 17:16:01 +0200 Subject: [PATCH 15/19] Fixes --- src/View.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/View.php b/src/View.php index 9069cb3..06ef729 100644 --- a/src/View.php +++ b/src/View.php @@ -110,6 +110,8 @@ class View { $yes_cache=0; + $all_path=array(); + if(!isset(View::$cache_template[$template])) { @@ -118,6 +120,8 @@ class View { $view_path=View::$root_path.'/'.$base_path.'/'.$template.'.php'; + $all_path[]=$view_path; + if(is_file($view_path)) { @@ -142,7 +146,7 @@ class View { else { - throw new \Exception('Error: view not found: '.$view_path); + throw new \Exception('Error: view not found: '.implode(' and ', $all_path)); die; } @@ -167,6 +171,17 @@ class View { } + /** + * Simple alias of load_view + */ + + static public function load_view($arr_template_values, $template) + { + + return View::loadView($arr_template_values, $template); + + } + /** * Method for create a url for access files via .php script * @@ -382,13 +397,34 @@ class View { $arr_final_css=array(); - View::$css=array_unique(View::$css); + //View::$css=array_unique(View::$css); foreach(View::$css as $css) { - $url=View::getMediaUrl('css/'.$css); + + if(gettype($css)=='array') + { + + $css=array_unique($css); + + foreach($css as $module => $css_item) + { + + $url=View::getMediaUrl('css/'.$css); + + $arr_final_css[]=''."\n"; + + } + + } + else + { - $arr_final_css[]=''."\n"; + $url=View::getMediaUrl('css/'.$css); + + $arr_final_css[]=''."\n"; + + } } @@ -407,13 +443,23 @@ class View { $arr_final_js=array(); - View::$js=array_unique(View::$js); + //View::$js=array_unique(View::$js); foreach(View::$js as $js) { - $url=View::getMediaUrl('js/'.$js); - $arr_final_js[]=$arr_final_jscript[]=''."\n";; + if(gettype($js)=='array') + { + + } + else + { + + $url=View::getMediaUrl('js/'.$js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n";; + + } } From 2fb3fe49559a83d880d8a2354c5311eea782e05f Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 14 Jun 2015 23:04:03 +0200 Subject: [PATCH 16/19] Fixes on view --- src/View.php | 103 ++++++++++----------------------------------------- 1 file changed, 19 insertions(+), 84 deletions(-) diff --git a/src/View.php b/src/View.php index 06ef729..7ce2a62 100644 --- a/src/View.php +++ b/src/View.php @@ -51,7 +51,7 @@ class View { * Internal property used for define the method used for retrieve the media files. */ - static protected $func_media='dynamicGetMediaUrl'; + static protected $func_media='dynamic_get_media_url'; /** * An array where you can add new css in all views. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use loadCss method for load all css writed in the array by children views. @@ -103,7 +103,7 @@ class View { * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. */ - static public function loadView($arr_template_values, $template) + static public function load_view($arr_template_values, $template) { //First see in controller/view/template, if not see in /views/template @@ -171,24 +171,13 @@ class View { } - /** - * Simple alias of load_view - */ - - static public function load_view($arr_template_values, $template) - { - - return View::loadView($arr_template_values, $template); - - } - /** * Method for create a url for access files via .php script * * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - static public function dynamicGetMediaUrl($path_file) + static public function dynamic_get_media_url($path_file) { return View::$php_file.'/'.$path_file; @@ -202,7 +191,7 @@ class View { * */ - static public function staticGetMediaUrl($path_file) + static public function static_get_media_url($path_file) { return View::$url_media.'/'.$path_file; @@ -215,14 +204,14 @@ class View { * @param boolean $value Set the production property.If true then access to media files directly, if false, access to media files via specified .php script */ - static public function setProduction($value=1) + static public function set_production($value=1) { if($value==1) { $production=1; - View::$func_media='staticGetMediaUrl'; + View::$func_media='static_get_media_url'; } else @@ -230,7 +219,7 @@ class View { $production=0; - View::$func_media='dynamicGetMediaUrl'; + View::$func_media='dynamic_get_media_url'; } @@ -241,7 +230,7 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - static public function getMediaUrl($path_file) + static public function get_media_url($path_file) { $func_media=View::$func_media; @@ -259,7 +248,7 @@ class View { * */ - static public function loadMediaFile($url) + static public function load_media_file($url) { //Check files origin. @@ -392,7 +381,7 @@ class View { * This function is used inside of html tag normally for load css files. */ - static public function loadCSS() + static public function load_css() { $arr_final_css=array(); @@ -410,7 +399,7 @@ class View { foreach($css as $module => $css_item) { - $url=View::getMediaUrl('css/'.$css); + $url=View::get_media_url('css/'.$css); $arr_final_css[]=''."\n"; @@ -420,7 +409,7 @@ class View { else { - $url=View::getMediaUrl('css/'.$css); + $url=View::get_media_url('css/'.$css); $arr_final_css[]=''."\n"; @@ -438,7 +427,7 @@ class View { * This function is used inside of html tag normally for load js files. */ - static public function loadJS() + static public function load_js() { $arr_final_js=array(); @@ -455,7 +444,7 @@ class View { else { - $url=View::getMediaUrl('js/'.$js); + $url=View::get_media_url('js/'.$js); $arr_final_js[]=$arr_final_jscript[]=''."\n";; @@ -473,7 +462,7 @@ class View { * This function is used inside of html tag normally for load inline javascript code. */ - static public function loadHeader() + static public function load_header() { $arr_final_header=array(); @@ -494,10 +483,10 @@ class View { * */ - static public function loadTheme($title, $cont_index) + static public function load_theme($title, $cont_index) { - echo View::loadView(array($title, $cont_index),'home'); + echo View::load_view(array($title, $cont_index),'home'); } @@ -510,7 +499,7 @@ class View { * @param string The names of templates, used how template_name for call views with load_view. */ - static public function loadLibrariesViews($template, $func_views=array()) + static public function load_libraries_views($template, $func_views=array()) { foreach(View::$folder_env as $base_path) @@ -535,60 +524,6 @@ class View { } } - - /*$theme=PhangoVar::$dir_theme; - - $container_theme=PhangoVar::$module_theme; - - $view=''; - - //Load views from a source file... - - //Check func views... - - $no_loaded=0; - - foreach($func_views as $template_check) - { - - if(isset(PhangoVar::$cache_template[$template_check])) - { - //Function view loaded, return because load_view load the function automatically. - - $no_loaded++; - - } - - } - - if($no_loaded==0) - { - if(!include_once(PhangoVar::$base_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php')) - { - - $output_error_view=ob_get_contents(); - - ob_clean(); - - if(!include_once(PhangoVar::$base_path.'modules/'.PhangoVar::$script_module.'/views/'.strtolower($template).'.php')) - { - - - - } - - } - - } - - //Forever register views if the code use different functions in a same library. - - foreach($func_views as $template) - { - - PhangoVar::$cache_template[$template]=basename($template).'View'; - - }*/ } @@ -611,7 +546,7 @@ class View { $_SESSION['flash_txt']=''; - return View::loadView(array($text), 'common/utilities/flash'); + return View::load_view(array($text), 'common/utilities/flash'); } } From f01c99efc4aa5be60a90f4d1fb9c4cd582254ab9 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 29 Jun 2015 15:10:40 +0200 Subject: [PATCH 17/19] Fixes on view --- src/View.php | 54 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/View.php b/src/View.php index 7ce2a62..76964de 100644 --- a/src/View.php +++ b/src/View.php @@ -17,6 +17,18 @@ class View { static public $folder_env=array('views/default'); + /** + * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break + */ + + static public $media_env=array('views/default'); + + /** + * Basepath of the theme + */ + + static public $theme=''; + /** * Array for caching the template call... */ @@ -191,10 +203,19 @@ class View { * */ - static public function static_get_media_url($path_file) + static public function static_get_media_url($path_file, $module='') { - - return View::$url_media.'/'.$path_file; + + //Need that the paths was theme/media and theme/module/media + + if($module!='') + { + + $module.='/'; + + } + + return View::$url_media.'media/'.View::$theme.'/'.$module.$path_file; } @@ -230,12 +251,12 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - static public function get_media_url($path_file) + static public function get_media_url($path_file, $module='') { - + $func_media=View::$func_media; - return View::$func_media($path_file); + return View::$func_media($path_file, $module); } @@ -286,7 +307,7 @@ class View { } - foreach(View::$folder_env as $folder) + foreach(View::$media_env as $folder) { $file_path=View::$root_path.'/'.$folder.'/'.View::$path_media.'/'.$final_path; @@ -388,7 +409,7 @@ class View { //View::$css=array_unique(View::$css); - foreach(View::$css as $css) + foreach(View::$css as $module_css => $css) { if(gettype($css)=='array') @@ -399,7 +420,7 @@ class View { foreach($css as $module => $css_item) { - $url=View::get_media_url('css/'.$css); + $url=View::get_media_url('css/'.$css_item, $module_css); $arr_final_css[]=''."\n"; @@ -434,11 +455,22 @@ class View { //View::$js=array_unique(View::$js); - foreach(View::$js as $js) + foreach(View::$js as $module_js => $js) { if(gettype($js)=='array') { + + $js=array_unique($js); + + foreach($js as $module => $js_item) + { + + $url=View::get_media_url('js/'.$js_item, $module_js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n"; + + } } else @@ -446,7 +478,7 @@ class View { $url=View::get_media_url('js/'.$js); - $arr_final_js[]=$arr_final_jscript[]=''."\n";; + $arr_final_js[]=$arr_final_jscript[]=''."\n"; } From fe2d66792ce2e08fe906dffbf9850836c1e17f8b Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 8 Jul 2015 04:33:22 +0200 Subject: [PATCH 18/19] Fixes on views --- src/View.php | 82 ++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/View.php b/src/View.php index 76964de..9cb9ca0 100644 --- a/src/View.php +++ b/src/View.php @@ -71,12 +71,24 @@ class View { static public $css=array(); + /** + * An array where you can add new css in all views from modules. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use load_css method for load all css writed in the array by children views. + */ + + static public $css_module=array(); + /** * An array where you can add new js in all views. For example, a view that use a special js can use this array and you can insert the value 'special.js' in principal View using loadJs method for load all js writed in the array by children views. */ static public $js=array(); + /** + * An array where you can add new js in all views. For example, a view that use a special js can use this array and you can insert the value 'special.js' in principal View using load_js method for load all js writed in the array by children views. + */ + + static public $js_module=array(); + /** * An array where you can add new code in
tag. For example, a view that need a initialitation code in the principal view can use this array and you can insert the code in principal View using loadHeader method for load all header code writed in the array by children views. */ @@ -407,35 +419,29 @@ class View { $arr_final_css=array(); - //View::$css=array_unique(View::$css); + View::$css=array_unique(View::$css); - foreach(View::$css as $module_css => $css) + foreach(View::$css as $css) { - if(gettype($css)=='array') - { - - $css=array_unique($css); - - foreach($css as $module => $css_item) - { - - $url=View::get_media_url('css/'.$css_item, $module_css); - - $arr_final_css[]=''."\n"; - - } - - } - else - { + $url=View::get_media_url('css/'.$css); - $url=View::get_media_url('css/'.$css); + $arr_final_css[]=''."\n"; + + } + + foreach(View::$css_module as $module_css => $css) + { + $css=array_unique($css); + + foreach($css as $module => $css_item) + { + + $url=View::get_media_url('css/'.$css_item, $module_css); $arr_final_css[]=''."\n"; } - } return implode('', $arr_final_css); @@ -453,35 +459,29 @@ class View { $arr_final_js=array(); - //View::$js=array_unique(View::$js); + View::$js=array_unique(View::$js); foreach(View::$js as $module_js => $js) { - if(gettype($js)=='array') + $url=View::get_media_url('js/'.$js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n"; + + } + + foreach(View::$js_module as $module_js => $js) + { + $js=array_unique($js); + + foreach($js as $module => $js_item) { - $js=array_unique($js); + $url=View::get_media_url('js/'.$js_item, $module_js); - foreach($js as $module => $js_item) - { - - $url=View::get_media_url('js/'.$js_item, $module_js); - - $arr_final_js[]=$arr_final_jscript[]=''."\n"; - - } + $arr_final_js[]=''."\n"; } - else - { - - $url=View::get_media_url('js/'.$js); - - $arr_final_js[]=$arr_final_jscript[]=''."\n"; - - } - } return implode('', $arr_final_js); From fd61da4b7bb28b726e9e7a0105082d9cbf182807 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 02:03:22 +0200 Subject: [PATCH 19/19] Fixes for new behaviour --- src/View.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 9cb9ca0..e6da3ea 100644 --- a/src/View.php +++ b/src/View.php @@ -9,7 +9,7 @@ class View { * Root path for includes app folders */ - static public $root_path=__DIR__; + static public $root_path="."; /** * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break @@ -95,6 +95,12 @@ class View { static public $header=array(); + /** + * An array with config_paths for load configurations. + */ + + static public $config_path=['settings']; + /** * The construct for create a view object * @@ -117,6 +123,19 @@ class View { }*/ + static public function load_config() + { + + //Load config here + foreach(View::config_path as $config) + { + + Utils::load_config("config_views", $config); + + } + + } + /** * Very important function used for load views. Is the V in the MVC paradigm. Phango is an MVC framework and has separate code and html. * @@ -181,6 +200,14 @@ class View { $func_view=View::$cache_template[$template]; + if(!function_exists($func_view)) + { + + throw new \Exception('Error: Template file loaded but function '.$func_view.' not found: '.implode(' and ', $all_path)); + die; + + } + //Load function from loaded view with his parameters //array_unshift($arr_template_values, $this);