From 49f67757f906d3d53de7209d61844554955eff07 Mon Sep 17 00:00:00 2001 From: Esperat Julian Date: Mon, 17 Oct 2011 12:25:25 +0300 Subject: [PATCH 001/120] View::$global_data array is already included in the data, don't need to extract it twice. Also View::$global_data should be without leading underscore. --- classes/view/markdown.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/classes/view/markdown.php b/classes/view/markdown.php index d0e0cb9..736b050 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -42,13 +42,7 @@ protected static function pre_process($_type = 'php', $_view_filename, array $_d if ($_type == 'php') { // Import the view variables to local namespace - $_data AND extract($_data, EXTR_SKIP); - - if (static::$_global_data) - { - // Import the global view variables to local namespace and maintain references - extract(static::$_global_data, EXTR_REFS); - } + $_data AND extract($_data, EXTR_REFS); // Capture the view output ob_start(); From ab640352cfd6b9ba09eec4ea357ff313998f3555 Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Mon, 24 Oct 2011 01:53:43 -0700 Subject: [PATCH 002/120] Adding the 'extensions' setting to the Twig config. Allows you to automatically add extensions to Twig --- classes/view/twig.php | 5 +++++ config/parser.php | 1 + 2 files changed, 6 insertions(+) diff --git a/classes/view/twig.php b/classes/view/twig.php index b271a64..dd621a3 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -68,6 +68,11 @@ public static function parser() $twig_env_conf = \Config::get('parser.View_Twig.environment', array('optimizer' => -1)); static::$_parser = new \Twig_Environment(static::$_parser_loader, $twig_env_conf); + foreach (\Config::get('parser.View_Twig.extensions') as $ext) + { + static::$_parser->addExtension(new $ext()); + } + // Twig Lexer $twig_lexer_conf = \Config::get('parser.View_Twig.delimiters', null); if (isset($twig_lexer_conf)) diff --git a/config/parser.php b/config/parser.php index 84c2388..29bcba5 100644 --- a/config/parser.php +++ b/config/parser.php @@ -68,6 +68,7 @@ 'autoescape' => false, 'optimizations' => -1, ), + 'extensions' => array(), ), // DWOO ( http://wiki.dwoo.org/ ) From 30f8a757554e27eab4752db325da651d76b158bb Mon Sep 17 00:00:00 2001 From: Jelmer Schreuder Date: Sat, 12 Nov 2011 17:56:20 +0100 Subject: [PATCH 003/120] Added @return to all ::parser() methods for IDE code completion and made use of "use" consistent throughout. --- classes/view/dwoo.php | 15 ++++++++++++--- classes/view/haml.php | 5 +++++ classes/view/jade.php | 5 +++++ classes/view/markdown.php | 9 +++++++-- classes/view/mustache.php | 9 ++++++++- classes/view/smarty.php | 9 ++++++++- classes/view/twig.php | 18 ++++++++++++++---- 7 files changed, 59 insertions(+), 11 deletions(-) diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 84966d6..6695795 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -14,6 +14,10 @@ namespace Parser; +use Dwoo; +use Dwoo_Compiler; +use Dwoo_Security_Policy; + class View_Dwoo extends \View { protected static $_parser; @@ -39,6 +43,11 @@ protected function process_file($file_override = false) public $extension = 'tpl'; + /** + * Returns the Parser lib object + * + * @return Dwoo + */ public static function parser() { if ( ! empty(static::$_parser)) @@ -47,13 +56,13 @@ public static function parser() } // Parser - static::$_parser = new \Dwoo(); + static::$_parser = new Dwoo(); static::$_parser->setCacheTime(\Config::get('parser.View_Dwoo.environment.cache_time', 0)); static::$_parser->setCacheDir(\Config::get('parser.View_Dwoo.environment.cache_dir', APPPATH.'cache'.DS.'dwoo'.DS)); static::$_parser->setCompileDir(\Config::get('parser.View_Dwoo.environment.compile_dir', APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS)); // Compiler - static::$_parser_compiler = new \Dwoo_Compiler; + static::$_parser_compiler = new Dwoo_Compiler; static::$_parser_compiler->setAutoEscape(\Config::get('parser.View_Dwoo.environment.autoescape', false)); static::$_parser_compiler->setLooseOpeningHandling(\Config::get('parser.View_Dwoo.environment.allow_spaces', false)); static::$_parser_compiler->setNestedCommentsHandling(\Config::get('parser.View_Dwoo.environment.nested_comments', false)); @@ -63,7 +72,7 @@ public static function parser() ); // Security - static::$_parser_security = new \Dwoo_Security_Policy; + static::$_parser_security = new Dwoo_Security_Policy; static::$_parser_security->setPhpHandling(\Config::get('parser.View_Dwoo.environment.allow_php_tags', 2)); static::$_parser_security->allowPhpFunction(\Config::get('parser.View_Dwoo.environment.allow_php_func', array())); diff --git a/classes/view/haml.php b/classes/view/haml.php index bef6e69..b5c532b 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -33,6 +33,11 @@ protected function process_file($file_override = false) public $extension = 'haml'; + /** + * Returns the Parser lib object + * + * @return HamlParser + */ public static function parser() { if ( ! empty(static::$_parser)) diff --git a/classes/view/jade.php b/classes/view/jade.php index 68b3355..85ba85a 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -32,6 +32,11 @@ protected function process_file($file_override = false) public $extension = 'jade'; + /** + * Returns the Parser lib object + * + * @return Jade\Parser + */ public static function parser() { if ( ! empty(static::$_parser)) diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 9480f0b..cb21de8 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -32,10 +32,10 @@ protected function process_file($file_override = false) { $contents = file_get_contents($file); } - + return static::parser()->transform($contents); } - + protected static function pre_process($_type = 'php', $_view_filename, array $_data = array()) { if ($_type == 'php') @@ -73,6 +73,11 @@ protected static function pre_process($_type = 'php', $_view_filename, array $_d public $extension = 'md'; + /** + * Returns the Parser lib object + * + * @return Markdown_Parser + */ public static function parser() { static $parser = null; diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 8d5b122..e406aa0 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -14,6 +14,8 @@ namespace Parser; +use Mustache; + class View_Mustache extends \View { protected static $_parser; @@ -37,6 +39,11 @@ protected function process_file($file_override = false) public $extension = 'mustache'; + /** + * Returns the Parser lib object + * + * @return Mustache + */ public static function parser() { if ( ! empty(static::$_parser)) @@ -50,7 +57,7 @@ public static function parser() 'pragmas' => \Config::get('parser.View_Mustache.environment.pragmas', array()), ); - static::$_parser = new \Mustache(null, null, null, $options); + static::$_parser = new Mustache(null, null, null, $options); return static::$_parser; } diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 84dd6cb..5b77170 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -14,6 +14,8 @@ namespace Parser; +use Smarty; + class View_Smarty extends \View { protected static $_parser; @@ -37,6 +39,11 @@ protected function process_file($file_override = false) public $extension = 'smarty'; + /** + * Returns the Parser lib object + * + * @return Smarty + */ public static function parser() { if ( ! empty(static::$_parser)) @@ -45,7 +52,7 @@ public static function parser() } // Parser - static::$_parser = new \Smarty(); + static::$_parser = new Smarty(); static::$_parser->template_dir = \Config::get('parser.View_Smarty.environment.template_dir', APPPATH.'views'.DS); static::$_parser->compile_dir = \Config::get('parser.View_Smarty.environment.compile_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS); static::$_parser->config_dir = \Config::get('parser.View_Smarty.environment.config_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS); diff --git a/classes/view/twig.php b/classes/view/twig.php index 4228ad7..f13633d 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -14,6 +14,11 @@ namespace Parser; +use Twig_Autoloader; +use Twig_Environment; +use Twig_Loader_Filesystem; +use Twig_Lexer; + class View_Twig extends \View { protected static $_parser; @@ -22,7 +27,7 @@ class View_Twig extends \View { public static function _init() { parent::_init(); - \Twig_Autoloader::register(); + Twig_Autoloader::register(); } protected function process_file($file_override = false) @@ -36,7 +41,7 @@ protected function process_file($file_override = false) // Twig Loader $views_paths = \Config::get('parser.View_Twig.views_paths', array(APPPATH . 'views')); array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); - static::$_parser_loader = new \Twig_Loader_Filesystem($views_paths); + static::$_parser_loader = new Twig_Loader_Filesystem($views_paths); try { @@ -52,6 +57,11 @@ protected function process_file($file_override = false) public $extension = 'twig'; + /** + * Returns the Parser lib object + * + * @return Twig_Environment + */ public static function parser() { if ( ! empty(static::$_parser)) @@ -62,13 +72,13 @@ public static function parser() // Twig Environment $twig_env_conf = \Config::get('parser.View_Twig.environment', array('optimizer' => -1)); - static::$_parser = new \Twig_Environment(static::$_parser_loader, $twig_env_conf); + static::$_parser = new Twig_Environment(static::$_parser_loader, $twig_env_conf); // Twig Lexer $twig_lexer_conf = \Config::get('parser.View_Twig.delimiters', null); if (isset($twig_lexer_conf)) { - $twig_lexer = new \Twig_Lexer(static::$_parser, $twig_lexer_conf); + $twig_lexer = new Twig_Lexer(static::$_parser, $twig_lexer_conf); static::$_parser->setLexer($twig_lexer); } From d535b7082f600bd8e132d82adb9ed5e4fa7001d4 Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Mon, 14 Nov 2011 09:12:01 -0800 Subject: [PATCH 004/120] Adding initial version of the Twig Fuel Extension Signed-off-by: Dan Horrigan --- bootstrap.php | 1 + classes/twig/fuel/extension.php | 87 +++++++++++++++++++++++++++++++++ config/parser.php | 4 +- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 classes/twig/fuel/extension.php diff --git a/bootstrap.php b/bootstrap.php index d2b2c58..62ad1f1 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -21,6 +21,7 @@ 'Parser\\View_Markdown' => __DIR__.'/classes/view/markdown.php', 'Parser\\View_SimpleTags' => __DIR__.'/classes/view/simpletags.php', 'Parser\\View_Twig' => __DIR__.'/classes/view/twig.php', + 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php new file mode 100644 index 0000000..3030444 --- /dev/null +++ b/classes/twig/fuel/extension.php @@ -0,0 +1,87 @@ + new Twig_Function_Method($this, 'url'), + 'base_url' => new Twig_Function_Function('Uri::base'), + 'uri_segment' => new Twig_Function_Function('Uri::segment'), + 'uri_segments' => new Twig_Function_Function('Uri::segments'), + 'config' => new Twig_Function_Function('Config::get'), + + 'form_open' => new Twig_Function_Function('Form::open'), + 'form_close' => new Twig_Function_Function('Form::close'), + 'form_input' => new Twig_Function_Function('Form::input'), + 'form_password' => new Twig_Function_Function('Form::password'), + 'form_hidden' => new Twig_Function_Function('Form::hidden'), + 'form_radio' => new Twig_Function_Function('Form::radio'), + 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), + 'form_textarea' => new Twig_Function_Function('Form::textarea'), + 'form_file' => new Twig_Function_Function('Form::file'), + 'form_button' => new Twig_Function_Function('Form::button'), + 'form_reset' => new Twig_Function_Function('Form::reset'), + 'form_submit' => new Twig_Function_Function('Form::submit'), + 'form_select' => new Twig_Function_Function('Form::select'), + 'form_label' => new Twig_Function_Function('Form::label'), + 'form_val' => new Twig_Function_Function('Input::param'), + ); + } + + /** + * Provides the url() functionality. Generates a full url (including + * domain and index.php). + * + * @param string URI to make a full URL for (or name of a named route) + * @param array Array of named params for named routes + * @return string + */ + public function url($uri = '', $named_params = array()) + { + if ($named_uri = Router::get($uri, $named_params)) + { + $uri = $named_uri; + } + + return Uri::create($uri); + } +} diff --git a/config/parser.php b/config/parser.php index 29bcba5..1b5231a 100644 --- a/config/parser.php +++ b/config/parser.php @@ -68,7 +68,9 @@ 'autoescape' => false, 'optimizations' => -1, ), - 'extensions' => array(), + 'extensions' => array( + 'Twig_Fuel_Extension' + ), ), // DWOO ( http://wiki.dwoo.org/ ) From 788bbc98c5d5035406ed27dfcb430b04886e489e Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Mon, 14 Nov 2011 09:16:18 -0800 Subject: [PATCH 005/120] Changing alignment Signed-off-by: Dan Horrigan --- classes/twig/fuel/extension.php | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 3030444..c1a8ace 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -43,27 +43,27 @@ public function getName() public function getFunctions() { return array( - 'url' => new Twig_Function_Method($this, 'url'), - 'base_url' => new Twig_Function_Function('Uri::base'), - 'uri_segment' => new Twig_Function_Function('Uri::segment'), - 'uri_segments' => new Twig_Function_Function('Uri::segments'), - 'config' => new Twig_Function_Function('Config::get'), + 'url' => new Twig_Function_Method($this, 'url'), + 'base_url' => new Twig_Function_Function('Uri::base'), + 'uri_segment' => new Twig_Function_Function('Uri::segment'), + 'uri_segments' => new Twig_Function_Function('Uri::segments'), + 'config' => new Twig_Function_Function('Config::get'), - 'form_open' => new Twig_Function_Function('Form::open'), - 'form_close' => new Twig_Function_Function('Form::close'), - 'form_input' => new Twig_Function_Function('Form::input'), + 'form_open' => new Twig_Function_Function('Form::open'), + 'form_close' => new Twig_Function_Function('Form::close'), + 'form_input' => new Twig_Function_Function('Form::input'), 'form_password' => new Twig_Function_Function('Form::password'), - 'form_hidden' => new Twig_Function_Function('Form::hidden'), - 'form_radio' => new Twig_Function_Function('Form::radio'), + 'form_hidden' => new Twig_Function_Function('Form::hidden'), + 'form_radio' => new Twig_Function_Function('Form::radio'), 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), 'form_textarea' => new Twig_Function_Function('Form::textarea'), - 'form_file' => new Twig_Function_Function('Form::file'), - 'form_button' => new Twig_Function_Function('Form::button'), - 'form_reset' => new Twig_Function_Function('Form::reset'), - 'form_submit' => new Twig_Function_Function('Form::submit'), - 'form_select' => new Twig_Function_Function('Form::select'), - 'form_label' => new Twig_Function_Function('Form::label'), - 'form_val' => new Twig_Function_Function('Input::param'), + 'form_file' => new Twig_Function_Function('Form::file'), + 'form_button' => new Twig_Function_Function('Form::button'), + 'form_reset' => new Twig_Function_Function('Form::reset'), + 'form_submit' => new Twig_Function_Function('Form::submit'), + 'form_select' => new Twig_Function_Function('Form::select'), + 'form_label' => new Twig_Function_Function('Form::label'), + 'form_val' => new Twig_Function_Function('Input::param'), ); } From a70d27d8d42612ea93c85e137b261f20fc8d328e Mon Sep 17 00:00:00 2001 From: Jelmer Schreuder Date: Tue, 15 Nov 2011 14:32:24 +0100 Subject: [PATCH 006/120] Auto-filter no longer switched off for Twig non-consistently with the other drivers and in a non-configurable way. Made it a lib-specific config setting. --- classes/view.php | 5 +++++ classes/view/twig.php | 3 --- config/parser.php | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/classes/view.php b/classes/view.php index 2996243..4ff2566 100644 --- a/classes/view.php +++ b/classes/view.php @@ -83,6 +83,11 @@ public static function forge($file = null, $data = null, $auto_encode = null) } // Instantiate the Parser class without auto-loading the view file + if ($auto_encode === null) + { + $auto_encode = \Config::get('parser.'.$class.'.auto_encode', null); + } + $view = new $class(null, $data, $auto_encode); // Set extension when given diff --git a/classes/view/twig.php b/classes/view/twig.php index 3c5d477..77a3772 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -32,9 +32,6 @@ public static function _init() protected function process_file($file_override = false) { - // Twig does it's own filtering, so don't let the View class do it. - $this->auto_filter = false; - $file = $file_override ?: $this->file_name; $data = $this->get_data(); diff --git a/config/parser.php b/config/parser.php index 1b5231a..60efb79 100644 --- a/config/parser.php +++ b/config/parser.php @@ -44,14 +44,16 @@ // MARKDOWN ( http://michelf.com/projects/php-markdown/ ) // ------------------------------------------------------------------------ 'View_Markdown' => array( - 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'markdown'.DS.'markdown.php', - 'allow_php' => true, + 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'markdown'.DS.'markdown.php', + 'auto_encode' => true, + 'allow_php' => true, ), // TWIG ( http://www.twig-project.org/documentation ) // ------------------------------------------------------------------------ 'View_Twig' => array( 'include' => APPPATH.'vendor'.DS.'Twig'.DS.'Autoloader.php', + 'auto_encode' => true, 'views_paths' => array(APPPATH.'views'), 'delimiters' => array( 'tag_block' => array('{%', '%}'), @@ -77,6 +79,7 @@ // ------------------------------------------------------------------------ 'View_Dwoo' => array( 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', + 'auto_encode' => true, 'delimiters' => array('{{', '}}'), 'environment' => array( 'autoescape' => false, @@ -99,6 +102,7 @@ // ------------------------------------------------------------------------ 'View_Mustache' => array( 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', + 'auto_encode' => true, 'delimiters' => array('{{', '}}'), 'environment' => array( 'charset' => 'UTF-8', @@ -110,21 +114,24 @@ // See notes in /parser/classes/view/jade.php // ------------------------------------------------------------------------ 'View_Jade' => array( - 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', - 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, + 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, ), // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) // ------------------------------------------------------------------------ 'View_Haml' => array( - 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', - 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, + 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, ), // SMARTY ( http://www.smarty.net/documentation ) // ------------------------------------------------------------------------ 'View_Smarty' => array( 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', + 'auto_encode' => true, 'delimiters' => array('{', '}'), 'environment' => array( 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, From b9e705a649b4cdfad8ef5928d6dd66521b1fc88c Mon Sep 17 00:00:00 2001 From: Dan Horrigan Date: Wed, 16 Nov 2011 10:55:28 -0800 Subject: [PATCH 007/120] Adding the lang() method to Twig extension. Signed-off-by: Dan Horrigan --- classes/twig/fuel/extension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index c1a8ace..67ea4fa 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -48,6 +48,7 @@ public function getFunctions() 'uri_segment' => new Twig_Function_Function('Uri::segment'), 'uri_segments' => new Twig_Function_Function('Uri::segments'), 'config' => new Twig_Function_Function('Config::get'), + 'lang' => new Twig_Function_Function('Lang::get'), 'form_open' => new Twig_Function_Function('Form::open'), 'form_close' => new Twig_Function_Function('Form::close'), From 3b70dee5c3918d1935c79f8ad9a7f4bf6a3571b9 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Wed, 30 Nov 2011 08:06:40 +0900 Subject: [PATCH 008/120] Adding PHPTAL Signed-off-by: Fumito Mizuno --- classes/view/phptal.php | 64 +++++++++++++++ config/parser.php | 174 ++++++++++++++++++++++------------------ 2 files changed, 158 insertions(+), 80 deletions(-) create mode 100644 classes/view/phptal.php diff --git a/classes/view/phptal.php b/classes/view/phptal.php new file mode 100644 index 0000000..ca151db --- /dev/null +++ b/classes/view/phptal.php @@ -0,0 +1,64 @@ +file_name; + + try + { + $parser = static::parser(); + foreach($this->get_data() as $key => $value) { + $parser->set($key,$value); + } + $parser->setTemplate($file); + return $parser->execute(); + } + catch (\Exception $e) + { + // Delete the output buffer & re-throw the exception + ob_end_clean(); + throw $e; + } + } + + public $extension = 'phptal'; + + public static function parser() + { + if ( ! empty(static::$_parser)) + { + return static::$_parser; + } + + static::$_parser = new \PHPTAL(); + static::$_parser->setEncoding(\Config::get('parser.View_Phptal.encoding', 'UTF-8')); + static::$_parser->setOutputMode(constant('\\'.\Config::get('parser.View_Phptal.output_mode', 'PHPTAL::XHTML'))); + static::$_parser->setTemplateRepository(\Config::get('parser.View_Phptal.template_repository', '')); + static::$_parser->setPhpCodeDestination(\Config::get('parser.View_Phptal.cache_dir', APPPATH.'cache'.DS.'PHPTAL'.DS)); + static::$_parser->setCacheLifetime(\Config::get('parser.View_Phptal.cache_lifetime', 0)); + static::$_parser->setForceReparse(\Config::get('parser.View_Phptal.encoding', false)); + + return static::$_parser; + } +} + +// end of file phptal.php diff --git a/config/parser.php b/config/parser.php index 60efb79..dec572e 100644 --- a/config/parser.php +++ b/config/parser.php @@ -33,6 +33,7 @@ 'jade' => 'View_Jade', 'haml' => 'View_Haml', 'smarty' => 'View_Smarty', + 'phptal' => 'View_Phptal', ), @@ -58,94 +59,107 @@ 'delimiters' => array( 'tag_block' => array('{%', '%}'), 'tag_comment' => array('{#', '#}'), - 'tag_variable' => array('{{', '}}'), + 'tag_variable' => array('{{', '}}'), + ), + 'environment' => array( + 'debug' => false, + 'charset' => 'utf-8', + 'base_template_class' => 'Twig_Template', + 'cache' => APPPATH.'cache'.DS.'twig'.DS, + 'auto_reload' => true, + 'strict_variables' => false, + 'autoescape' => false, + 'optimizations' => -1, + ), + 'extensions' => array( + 'Twig_Fuel_Extension' + ), ), - 'environment' => array( - 'debug' => false, - 'charset' => 'utf-8', - 'base_template_class' => 'Twig_Template', - 'cache' => APPPATH.'cache'.DS.'twig'.DS, - 'auto_reload' => true, - 'strict_variables' => false, - 'autoescape' => false, - 'optimizations' => -1, - ), - 'extensions' => array( - 'Twig_Fuel_Extension' + + // DWOO ( http://wiki.dwoo.org/ ) + // ------------------------------------------------------------------------ + 'View_Dwoo' => array( + 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', + 'auto_encode' => true, + 'delimiters' => array('{{', '}}'), + 'environment' => array( + 'autoescape' => false, + 'nested_comments' => false, + 'allow_spaces' => false, + 'cache_dir' => APPPATH.'cache'.DS.'dwoo'.DS, + 'compile_dir' => APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS, + 'cache_time' => 0, + + // Set what parser should do with PHP tags + // 1 - Encode tags | 2 - Remove tags | 3 - Allow tags + 'allow_php_tags' => 2, + + // Which PHP functions should be accessible through Parser + 'allow_php_func' => array(), + ), ), - ), - // DWOO ( http://wiki.dwoo.org/ ) - // ------------------------------------------------------------------------ - 'View_Dwoo' => array( - 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', - 'auto_encode' => true, - 'delimiters' => array('{{', '}}'), - 'environment' => array( - 'autoescape' => false, - 'nested_comments' => false, - 'allow_spaces' => false, - 'cache_dir' => APPPATH.'cache'.DS.'dwoo'.DS, - 'compile_dir' => APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS, - 'cache_time' => 0, - - // Set what parser should do with PHP tags - // 1 - Encode tags | 2 - Remove tags | 3 - Allow tags - 'allow_php_tags' => 2, - - // Which PHP functions should be accessible through Parser - 'allow_php_func' => array(), + // MUSTACHE ( https://github.com/bobthecow/mustache.php ) + // ------------------------------------------------------------------------ + 'View_Mustache' => array( + 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', + 'auto_encode' => true, + 'delimiters' => array('{{', '}}'), + 'environment' => array( + 'charset' => 'UTF-8', + 'pragmas' => array(), + ), ), - ), - // MUSTACHE ( https://github.com/bobthecow/mustache.php ) - // ------------------------------------------------------------------------ - 'View_Mustache' => array( - 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', - 'auto_encode' => true, - 'delimiters' => array('{{', '}}'), - 'environment' => array( - 'charset' => 'UTF-8', - 'pragmas' => array(), + // JADE PHP ( https://github.com/everzet/jade.php ) + // See notes in /parser/classes/view/jade.php + // ------------------------------------------------------------------------ + 'View_Jade' => array( + 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, ), - ), - // JADE PHP ( https://github.com/everzet/jade.php ) - // See notes in /parser/classes/view/jade.php - // ------------------------------------------------------------------------ - 'View_Jade' => array( - 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, - ), + // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) + // ------------------------------------------------------------------------ + 'View_Haml' => array( + 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, + ), - // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) - // ------------------------------------------------------------------------ - 'View_Haml' => array( - 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, - ), + // SMARTY ( http://www.smarty.net/documentation ) + // ------------------------------------------------------------------------ + 'View_Smarty' => array( + 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', + 'auto_encode' => true, + 'delimiters' => array('{', '}'), + 'environment' => array( + 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, + 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, + 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, + 'caching' => false, + 'cache_lifetime' => 0, + 'force_compile' => false, + 'compile_check' => true, + 'debugging' => false, + 'autoload_filters' => array(), + 'default_modifiers' => array(), + ), + ), - // SMARTY ( http://www.smarty.net/documentation ) - // ------------------------------------------------------------------------ - 'View_Smarty' => array( - 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', - 'auto_encode' => true, - 'delimiters' => array('{', '}'), - 'environment' => array( - 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, - 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, - 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, - 'caching' => false, - 'cache_lifetime' => 0, - 'force_compile' => false, - 'compile_check' => true, - 'debugging' => false, - 'autoload_filters' => array(), - 'default_modifiers' => array(), + // Phptal ( http://phptal.org/manual/en/ ) + // ------------------------------------------------------------------------ + 'View_Phptal' => array( + 'include' => APPPATH.'vendor'.DS.'PHPTAL'.DS.'PHPTAL.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'PHPTAL'.DS, + 'cache_lifetime' => 0, + 'encoding' => 'UTF-8', + 'output_mode' => 'PHPTAL::XHTML', + 'template_repository' => '', + 'force_reparse' => false, ), - ), -); + ); -// end of file parser.php + // end of file parser.php From ccf26b7117c6d6214bcab2d15f7dff8b17cf1e13 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 4 Dec 2011 07:52:21 +0900 Subject: [PATCH 009/120] Add View_Phptal on bootstrap.php --- bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap.php b/bootstrap.php index 62ad1f1..299d5d3 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -25,6 +25,7 @@ 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', + 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', )); From 020972eabfd30ce0122b408e35c6ce3b60961e0f Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 4 Dec 2011 09:12:16 +0900 Subject: [PATCH 010/120] fix indent --- config/parser.php | 182 +++++++++++++++++++++++----------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/config/parser.php b/config/parser.php index dec572e..7728cef 100644 --- a/config/parser.php +++ b/config/parser.php @@ -60,106 +60,106 @@ 'tag_block' => array('{%', '%}'), 'tag_comment' => array('{#', '#}'), 'tag_variable' => array('{{', '}}'), - ), - 'environment' => array( - 'debug' => false, - 'charset' => 'utf-8', - 'base_template_class' => 'Twig_Template', - 'cache' => APPPATH.'cache'.DS.'twig'.DS, - 'auto_reload' => true, - 'strict_variables' => false, - 'autoescape' => false, - 'optimizations' => -1, - ), - 'extensions' => array( - 'Twig_Fuel_Extension' - ), ), - - // DWOO ( http://wiki.dwoo.org/ ) - // ------------------------------------------------------------------------ - 'View_Dwoo' => array( - 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', - 'auto_encode' => true, - 'delimiters' => array('{{', '}}'), - 'environment' => array( - 'autoescape' => false, - 'nested_comments' => false, - 'allow_spaces' => false, - 'cache_dir' => APPPATH.'cache'.DS.'dwoo'.DS, - 'compile_dir' => APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS, - 'cache_time' => 0, - - // Set what parser should do with PHP tags - // 1 - Encode tags | 2 - Remove tags | 3 - Allow tags - 'allow_php_tags' => 2, - - // Which PHP functions should be accessible through Parser - 'allow_php_func' => array(), - ), + 'environment' => array( + 'debug' => false, + 'charset' => 'utf-8', + 'base_template_class' => 'Twig_Template', + 'cache' => APPPATH.'cache'.DS.'twig'.DS, + 'auto_reload' => true, + 'strict_variables' => false, + 'autoescape' => false, + 'optimizations' => -1, ), - - // MUSTACHE ( https://github.com/bobthecow/mustache.php ) - // ------------------------------------------------------------------------ - 'View_Mustache' => array( - 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', - 'auto_encode' => true, - 'delimiters' => array('{{', '}}'), - 'environment' => array( - 'charset' => 'UTF-8', - 'pragmas' => array(), - ), + 'extensions' => array( + 'Twig_Fuel_Extension' ), + ), - // JADE PHP ( https://github.com/everzet/jade.php ) - // See notes in /parser/classes/view/jade.php - // ------------------------------------------------------------------------ - 'View_Jade' => array( - 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, + // DWOO ( http://wiki.dwoo.org/ ) + // ------------------------------------------------------------------------ + 'View_Dwoo' => array( + 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', + 'auto_encode' => true, + 'delimiters' => array('{{', '}}'), + 'environment' => array( + 'autoescape' => false, + 'nested_comments' => false, + 'allow_spaces' => false, + 'cache_dir' => APPPATH.'cache'.DS.'dwoo'.DS, + 'compile_dir' => APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS, + 'cache_time' => 0, + + // Set what parser should do with PHP tags + // 1 - Encode tags | 2 - Remove tags | 3 - Allow tags + 'allow_php_tags' => 2, + + // Which PHP functions should be accessible through Parser + 'allow_php_func' => array(), ), + ), - // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) - // ------------------------------------------------------------------------ - 'View_Haml' => array( - 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, + // MUSTACHE ( https://github.com/bobthecow/mustache.php ) + // ------------------------------------------------------------------------ + 'View_Mustache' => array( + 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', + 'auto_encode' => true, + 'delimiters' => array('{{', '}}'), + 'environment' => array( + 'charset' => 'UTF-8', + 'pragmas' => array(), ), + ), - // SMARTY ( http://www.smarty.net/documentation ) - // ------------------------------------------------------------------------ - 'View_Smarty' => array( - 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', - 'auto_encode' => true, - 'delimiters' => array('{', '}'), - 'environment' => array( - 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, - 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, - 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, - 'caching' => false, - 'cache_lifetime' => 0, - 'force_compile' => false, - 'compile_check' => true, - 'debugging' => false, - 'autoload_filters' => array(), - 'default_modifiers' => array(), - ), - ), + // JADE PHP ( https://github.com/everzet/jade.php ) + // See notes in /parser/classes/view/jade.php + // ------------------------------------------------------------------------ + 'View_Jade' => array( + 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, + ), + + // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) + // ------------------------------------------------------------------------ + 'View_Haml' => array( + 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, + ), - // Phptal ( http://phptal.org/manual/en/ ) - // ------------------------------------------------------------------------ - 'View_Phptal' => array( - 'include' => APPPATH.'vendor'.DS.'PHPTAL'.DS.'PHPTAL.php', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'PHPTAL'.DS, - 'cache_lifetime' => 0, - 'encoding' => 'UTF-8', - 'output_mode' => 'PHPTAL::XHTML', - 'template_repository' => '', - 'force_reparse' => false, + // SMARTY ( http://www.smarty.net/documentation ) + // ------------------------------------------------------------------------ + 'View_Smarty' => array( + 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', + 'auto_encode' => true, + 'delimiters' => array('{', '}'), + 'environment' => array( + 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, + 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, + 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, + 'caching' => false, + 'cache_lifetime' => 0, + 'force_compile' => false, + 'compile_check' => true, + 'debugging' => false, + 'autoload_filters' => array(), + 'default_modifiers' => array(), ), - ); + ), + + // Phptal ( http://phptal.org/manual/en/ ) + // ------------------------------------------------------------------------ + 'View_Phptal' => array( + 'include' => APPPATH.'vendor'.DS.'PHPTAL'.DS.'PHPTAL.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'PHPTAL'.DS, + 'cache_lifetime' => 0, + 'encoding' => 'UTF-8', + 'output_mode' => 'PHPTAL::XHTML', + 'template_repository' => '', + 'force_reparse' => false, + ), +); // end of file parser.php From 91fbb114b2dd59c7f3bf80187a4eeca5254c1877 Mon Sep 17 00:00:00 2001 From: Jelmer Schreuder Date: Sun, 18 Mar 2012 01:17:10 +0100 Subject: [PATCH 011/120] Fixes #32 - numerical indexed config arrays aren't mergeable, now all associative. --- classes/view/dwoo.php | 4 ++-- classes/view/mustache.php | 2 +- classes/view/smarty.php | 4 ++-- classes/view/twig.php | 7 +++++++ config/parser.php | 12 ++++++------ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 76a9627..b70aaa7 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -67,8 +67,8 @@ public static function parser() static::$_parser_compiler->setLooseOpeningHandling(\Config::get('parser.View_Dwoo.environment.allow_spaces', false)); static::$_parser_compiler->setNestedCommentsHandling(\Config::get('parser.View_Dwoo.environment.nested_comments', false)); static::$_parser_compiler->setDelimiters( - \Config::get('parser.View_Dwoo.delimiters.0', '{'), - \Config::get('parser.View_Dwoo.delimiters.1', '}') + \Config::get('parser.View_Dwoo.delimiters.left', '{'), + \Config::get('parser.View_Dwoo.delimiters.right', '}') ); // Security diff --git a/classes/view/mustache.php b/classes/view/mustache.php index ee642bf..3acab14 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -52,7 +52,7 @@ public static function parser() } $options = array( - 'delimiters' => \Config::get('parser.View_Mustache.delimiters', array('{{','}}')), + 'delimiters' => array_keys(\Config::get('parser.View_Mustache.delimiters', array('{{','}}'))), 'charset' => \Config::get('parser.View_Mustache.environment.charset', 'UTF-8'), 'pragmas' => \Config::get('parser.View_Mustache.environment.pragmas', array()), ); diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 88f51cd..87d7053 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -66,8 +66,8 @@ public static function parser() static::$_parser->compile_check = \Config::get('parser.View_Smarty.environment.compile_check', true); static::$_parser->debugging = \Config::get('parser.View_Smarty.environment.debugging', false); - static::$_parser->left_delimiter = \Config::get('parser.View_Smarty.delimiters.0', '{'); - static::$_parser->right_delimiter = \Config::get('parser.View_Smarty.delimiters.1', '}'); + static::$_parser->left_delimiter = \Config::get('parser.View_Smarty.delimiters.left', '{'); + static::$_parser->right_delimiter = \Config::get('parser.View_Smarty.delimiters.right', '}'); static::$_parser->autoload_filters = \Config::get('parser.View_Smarty.environment.autoload_filters', array()); static::$_parser->default_modifiers = \Config::get('parser.View_Smarty.environment.default_modifiers', array()); diff --git a/classes/view/twig.php b/classes/view/twig.php index 77a3772..d9ebff2 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -83,6 +83,13 @@ public static function parser() $twig_lexer_conf = \Config::get('parser.View_Twig.delimiters', null); if (isset($twig_lexer_conf)) { + isset($twig_lexer_conf['tag_block']) + and $twig_lexer_conf['tag_block'] = array_keys($twig_lexer_conf['tag_block']); + isset($twig_lexer_conf['tag_comment']) + and $twig_lexer_conf['tag_comment'] = array_keys($twig_lexer_conf['tag_comment']); + isset($twig_lexer_conf['tag_variable']) + and $twig_lexer_conf['tag_variable'] = array_keys($twig_lexer_conf['tag_variable']); + $twig_lexer = new Twig_Lexer(static::$_parser, $twig_lexer_conf); static::$_parser->setLexer($twig_lexer); } diff --git a/config/parser.php b/config/parser.php index 60efb79..ecb0f20 100644 --- a/config/parser.php +++ b/config/parser.php @@ -56,9 +56,9 @@ 'auto_encode' => true, 'views_paths' => array(APPPATH.'views'), 'delimiters' => array( - 'tag_block' => array('{%', '%}'), - 'tag_comment' => array('{#', '#}'), - 'tag_variable' => array('{{', '}}'), + 'tag_block' => array('left' => '{%', 'right' => '%}'), + 'tag_comment' => array('left' => '{#', 'right' => '#}'), + 'tag_variable' => array('left' => '{{', 'right' => '}}'), ), 'environment' => array( 'debug' => false, @@ -80,7 +80,7 @@ 'View_Dwoo' => array( 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', 'auto_encode' => true, - 'delimiters' => array('{{', '}}'), + 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( 'autoescape' => false, 'nested_comments' => false, @@ -103,7 +103,7 @@ 'View_Mustache' => array( 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', 'auto_encode' => true, - 'delimiters' => array('{{', '}}'), + 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( 'charset' => 'UTF-8', 'pragmas' => array(), @@ -132,7 +132,7 @@ 'View_Smarty' => array( 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', 'auto_encode' => true, - 'delimiters' => array('{', '}'), + 'delimiters' => array('left' => '{', 'right' => '}'), 'environment' => array( 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, From eed93b7fb5fd94e427a350380083447c8f3f0f42 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 18 Mar 2012 10:10:37 +0900 Subject: [PATCH 012/120] newline for {, instead of the end of "foreach" --- classes/view/phptal.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/view/phptal.php b/classes/view/phptal.php index ca151db..1a2c1db 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -26,7 +26,8 @@ protected function process_file($file_override = false) try { $parser = static::parser(); - foreach($this->get_data() as $key => $value) { + foreach($this->get_data() as $key => $value) + { $parser->set($key,$value); } $parser->setTemplate($file); From f0f0c42d68c2796cc1f03c6f12cf6d0ab41e6051 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 18 Mar 2012 10:12:08 +0900 Subject: [PATCH 013/120] Remove unnecessary spaces --- config/parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/parser.php b/config/parser.php index 7728cef..a355a37 100644 --- a/config/parser.php +++ b/config/parser.php @@ -59,7 +59,7 @@ 'delimiters' => array( 'tag_block' => array('{%', '%}'), 'tag_comment' => array('{#', '#}'), - 'tag_variable' => array('{{', '}}'), + 'tag_variable' => array('{{', '}}'), ), 'environment' => array( 'debug' => false, @@ -162,4 +162,4 @@ ), ); - // end of file parser.php +// end of file parser.php \ No newline at end of file From b6fab8ce2da89a40e0954570bae9cd7b02351209 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 18 Mar 2012 10:14:25 +0900 Subject: [PATCH 014/120] newline for {, instead of the end of "foreach" --- classes/view/phptal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 1a2c1db..8c45f49 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -27,7 +27,7 @@ protected function process_file($file_override = false) { $parser = static::parser(); foreach($this->get_data() as $key => $value) - { + { $parser->set($key,$value); } $parser->setTemplate($file); From 21d8c2e5edfdb32ad630d384392338865e4c20a4 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 18 Mar 2012 10:16:16 +0900 Subject: [PATCH 015/120] newline for {, instead of the end of "foreach" --- classes/view/phptal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 8c45f49..e6462ff 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -27,7 +27,7 @@ protected function process_file($file_override = false) { $parser = static::parser(); foreach($this->get_data() as $key => $value) - { + { $parser->set($key,$value); } $parser->setTemplate($file); From 0a828cfbb66092f3349785a38fd4565a61edce45 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Sun, 18 Mar 2012 10:30:32 +0900 Subject: [PATCH 016/120] newline for {, instead of the end of "foreach" --- classes/view/phptal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/phptal.php b/classes/view/phptal.php index e6462ff..ba4abf9 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -27,7 +27,7 @@ protected function process_file($file_override = false) { $parser = static::parser(); foreach($this->get_data() as $key => $value) - { + { $parser->set($key,$value); } $parser->setTemplate($file); From 52a6490ade45d0a062831466e4803f09fc5f506d Mon Sep 17 00:00:00 2001 From: Davide Bellini Date: Mon, 19 Mar 2012 15:52:36 +0100 Subject: [PATCH 017/120] Added .gitignore --- .gitignore | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b0bd70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*~ +*.bak +Thumbs.db +desktop.ini +.DS_Store +.buildpath +.project +.settings +fuel/app/logs/*/*/* +fuel/app/cache/*/* +nbproject/ +.idea +*.tmproj +*.sublime-project +*.sublime-workspace \ No newline at end of file From ef9bba014101d49c7d96ecf63888f7f1cd95af79 Mon Sep 17 00:00:00 2001 From: Davide Bellini Date: Mon, 19 Mar 2012 15:53:11 +0100 Subject: [PATCH 018/120] Fixed delimiters passed to Twig_Lexer --- classes/view/twig.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index d9ebff2..2929a50 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -84,11 +84,11 @@ public static function parser() if (isset($twig_lexer_conf)) { isset($twig_lexer_conf['tag_block']) - and $twig_lexer_conf['tag_block'] = array_keys($twig_lexer_conf['tag_block']); + and $twig_lexer_conf['tag_block'] = array_values($twig_lexer_conf['tag_block']); isset($twig_lexer_conf['tag_comment']) - and $twig_lexer_conf['tag_comment'] = array_keys($twig_lexer_conf['tag_comment']); + and $twig_lexer_conf['tag_comment'] = array_values($twig_lexer_conf['tag_comment']); isset($twig_lexer_conf['tag_variable']) - and $twig_lexer_conf['tag_variable'] = array_keys($twig_lexer_conf['tag_variable']); + and $twig_lexer_conf['tag_variable'] = array_values($twig_lexer_conf['tag_variable']); $twig_lexer = new Twig_Lexer(static::$_parser, $twig_lexer_conf); static::$_parser->setLexer($twig_lexer); From 08ff3c0ce18ff4db8e0f6f2c3fc24d92b2fb3453 Mon Sep 17 00:00:00 2001 From: Davide Bellini Date: Mon, 19 Mar 2012 15:53:49 +0100 Subject: [PATCH 019/120] Updated Copyright to 2012 --- bootstrap.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/jade.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 299d5d3..66a5ed9 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 67ea4fa..8f548dd 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 4ff2566..202dd9c 100644 --- a/classes/view.php +++ b/classes/view.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index b70aaa7..73773f5 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index 2b2488b..efd4877 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index be8ffde..77c4a79 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 3ee520a..35a1ea3 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 3acab14..6f7df3c 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index ba4abf9..b696ff9 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 87d7053..4e0936f 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -8,7 +8,7 @@ * @version 1.0 * @author b3ha * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index 2929a50..8303494 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -8,7 +8,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index 63d5bde..992da80 100644 --- a/config/parser.php +++ b/config/parser.php @@ -6,7 +6,7 @@ * @version 1.0 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2011 Fuel Development Team + * @copyright 2010 - 2012 Fuel Development Team * @link http://fuelphp.com */ From 941aede14a900fa00b0feed7c3c9508027dfae41 Mon Sep 17 00:00:00 2001 From: Jelmer Schreuder Date: Mon, 19 Mar 2012 16:35:58 +0100 Subject: [PATCH 020/120] Fixes usage of array_keys() instead of array_values(). --- classes/view/mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 6f7df3c..5d7e4e6 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -52,7 +52,7 @@ public static function parser() } $options = array( - 'delimiters' => array_keys(\Config::get('parser.View_Mustache.delimiters', array('{{','}}'))), + 'delimiters' => array_values(\Config::get('parser.View_Mustache.delimiters', array('{{','}}'))), 'charset' => \Config::get('parser.View_Mustache.environment.charset', 'UTF-8'), 'pragmas' => \Config::get('parser.View_Mustache.environment.pragmas', array()), ); From 52764220d6fc850894f46962b2f027902ae09692 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Tue, 20 Mar 2012 20:21:28 +0100 Subject: [PATCH 021/120] Docblock for ::forge. Signed-off-by: Frank de Jonge --- classes/view.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/classes/view.php b/classes/view.php index 202dd9c..545e060 100644 --- a/classes/view.php +++ b/classes/view.php @@ -54,10 +54,18 @@ public static function factory($file = null, $data = null, $auto_encode = null) return static::forge($file, $data, $auto_encode); } + /** + * Forges a new View object based on the extension + * + * @param string $file view filename + * @param array $data view data + * @param bool $auto_encode auto encode boolean, null for default + * @return object a new view instance + */ public static function forge($file = null, $data = null, $auto_encode = null) { - $extension = pathinfo($file, PATHINFO_EXTENSION); - $class = \Config::get('parser.extensions.'.$extension, get_called_class()); + $extension = pathinfo($file, PATHINFO_EXTENSION); + $class = \Config::get('parser.extensions.'.$extension); // Only get rid of the extension if it is not an absolute file path if ($file[0] !== '/' and $file[1] !== ':') @@ -99,5 +107,3 @@ public static function forge($file = null, $data = null, $auto_encode = null) return $view; } } - -// end of file view.php From 6aba6b28e4f0a5c9b271dcc7f97eef9a3f83e79b Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Wed, 21 Mar 2012 22:26:44 +0100 Subject: [PATCH 022/120] Fixes error in parse class without extension. Signed-off-by: Frank de Jonge --- classes/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view.php b/classes/view.php index 545e060..5ef6bab 100644 --- a/classes/view.php +++ b/classes/view.php @@ -65,7 +65,7 @@ public static function factory($file = null, $data = null, $auto_encode = null) public static function forge($file = null, $data = null, $auto_encode = null) { $extension = pathinfo($file, PATHINFO_EXTENSION); - $class = \Config::get('parser.extensions.'.$extension); + $class = \Config::get('parser.extensions.'.$extension, get_called_class()); // Only get rid of the extension if it is not an absolute file path if ($file[0] !== '/' and $file[1] !== ':') From 6bc91f3f6b9154afec559dff13897bd504e7f480 Mon Sep 17 00:00:00 2001 From: Davide Bellini Date: Thu, 22 Mar 2012 14:51:03 +0100 Subject: [PATCH 023/120] Implemented the Twig addGloba() method for views global data It can be useful to get a variable accessible in all views using a global context (e.g. Twig Macros) --- classes/view/twig.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index 8303494..0c77eb0 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -33,7 +33,9 @@ public static function _init() protected function process_file($file_override = false) { $file = $file_override ?: $this->file_name; - $data = $this->get_data(); + + $local_data = $this->get_data('local'); + $global_data = $this->get_data('global'); // Extract View name/extension (ex. "template.twig") $view_name = pathinfo($file, PATHINFO_BASENAME); @@ -43,9 +45,17 @@ protected function process_file($file_override = false) array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); static::$_parser_loader = new Twig_Loader_Filesystem($views_paths); + if ( ! empty($global_data)) + { + foreach ($global_data as $key => $value) + { + static::parser()->addGlobal($key, $value); + } + } + try { - return static::parser()->loadTemplate($view_name)->render($data); + return static::parser()->loadTemplate($view_name)->render($local_data); } catch (\Exception $e) { From 49cfbfcec3fda3ae33c61addebf8a631b4f25be0 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 30 Apr 2012 12:00:44 +0200 Subject: [PATCH 024/120] Removed Simpletags from the parser readme. Closes #47 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d07e64..7f13c58 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ View::forge('example.dwoo'); ## Installing parsers -Only SimpleTags and Mustache are included. While many other drivers are included, their libraries are not and are by default expected in `app/vendor/lib_name` (capitalize lib_name), you'll have to download them yourself. Don't change the casing or anything, keep it as much original as possible within the `vendor/lib_name` dir to keep updating easy (also because some come with their own autoloader). +Only Markdown and Mustache are included. While many other drivers are included, their libraries are not and are by default expected in `app/vendor/lib_name` (capitalize lib_name), you'll have to download them yourself. Don't change the casing or anything, keep it as much original as possible within the `vendor/lib_name` dir to keep updating easy (also because some come with their own autoloader). You can configure them to be loaded from other locations by copying the parser.php config file to your app and editing it. @@ -50,4 +50,4 @@ Currently the drivers still lack a lot of config options they should probably ac ```php $view = View::forge('example.stags'); $view->parser()->set_delimiters('{', '}'); -``` \ No newline at end of file +``` From c5c4ceef88578e8dfd88117ad4fd84d7828baa39 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 30 Apr 2012 12:01:17 +0200 Subject: [PATCH 025/120] added Asset methods to the list of twig custom functions --- classes/twig/fuel/extension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 8f548dd..b894bf9 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -65,6 +65,11 @@ public function getFunctions() 'form_select' => new Twig_Function_Function('Form::select'), 'form_label' => new Twig_Function_Function('Form::label'), 'form_val' => new Twig_Function_Function('Input::param'), + + 'asset_css' => new Twig_Function_Function('Asset::css'), + 'asset_js' => new Twig_Function_Function('Asset::js'), + 'asset_img' => new Twig_Function_Function('Asset::img'), + 'asset_render' => new Twig_Function_Function('Asset::render'), ); } From 875b7f342ad2ba8a4f1d96244eeb9cd57d588caf Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 5 May 2012 00:24:08 +0200 Subject: [PATCH 026/120] removed deprecated code from the Parser classes --- classes/view.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/classes/view.php b/classes/view.php index 5ef6bab..6f47eff 100644 --- a/classes/view.php +++ b/classes/view.php @@ -43,17 +43,6 @@ public static function _init() } } - /** - * This method is deprecated...use forge() instead. - * - * @deprecated until 1.2 - */ - public static function factory($file = null, $data = null, $auto_encode = null) - { - \Log::warning('This method is deprecated. Please use a forge() instead.', __METHOD__); - return static::forge($file, $data, $auto_encode); - } - /** * Forges a new View object based on the extension * From 1d6aff702fcb000c70a481eb212c671a09bfcd36 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 29 Jun 2012 21:29:34 +0200 Subject: [PATCH 027/120] added support for relocating the package to a non-default path --- config/parser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/parser.php b/config/parser.php index 992da80..73010e6 100644 --- a/config/parser.php +++ b/config/parser.php @@ -45,7 +45,7 @@ // MARKDOWN ( http://michelf.com/projects/php-markdown/ ) // ------------------------------------------------------------------------ 'View_Markdown' => array( - 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'markdown'.DS.'markdown.php', + 'include' => \Package::exists('parser').'vendor'.DS.'markdown'.DS.'markdown.php', 'auto_encode' => true, 'allow_php' => true, ), @@ -102,7 +102,7 @@ // MUSTACHE ( https://github.com/bobthecow/mustache.php ) // ------------------------------------------------------------------------ 'View_Mustache' => array( - 'include' => PKGPATH.'parser'.DS.'vendor'.DS.'Mustache'.DS.'Mustache.php', + 'include' => \Package::exist('parser').'vendor'.DS.'Mustache'.DS.'Mustache.php', 'auto_encode' => true, 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( From 6193c982e5dd9474ac8595c1fd934f80c863394a Mon Sep 17 00:00:00 2001 From: Thomas David Baker Date: Sun, 1 Jul 2012 13:08:09 +0100 Subject: [PATCH 028/120] Add support for the plugins_dir setting in Smarty. --- classes/view/smarty.php | 1 + config/parser.php | 1 + 2 files changed, 2 insertions(+) diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 4e0936f..1a39402 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -59,6 +59,7 @@ public static function parser() static::$_parser->compile_dir = \Config::get('parser.View_Smarty.environment.compile_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS); static::$_parser->config_dir = \Config::get('parser.View_Smarty.environment.config_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS); static::$_parser->cache_dir = \Config::get('parser.View_Smarty.environment.cache_dir', APPPATH.'cache'.DS.'Smarty'.DS); + static::$_parser->plugins_dir = array_merge(static::$_parser->plugins_dir, array(\Config::get('parser.View_Smarty.environment.plugins_dir', APPPATH.'cache'.DS.'Smarty'.DS))); static::$_parser->caching = \Config::get('parser.View_Smarty.environment.caching', false); static::$_parser->cache_lifetime = \Config::get('parser.View_Smarty.environment.cache_lifetime', 0); diff --git a/config/parser.php b/config/parser.php index 992da80..4f544d9 100644 --- a/config/parser.php +++ b/config/parser.php @@ -138,6 +138,7 @@ 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, + 'plugins_dir' => APPPATH.'cache'.DS.'Smarty'.DS, 'caching' => false, 'cache_lifetime' => 0, 'force_compile' => false, From 5c92fd1b02f6e6c6940be72fc8dbaaa5ecc463e4 Mon Sep 17 00:00:00 2001 From: Thomas David Baker Date: Sun, 1 Jul 2012 14:33:26 +0100 Subject: [PATCH 029/120] Update Smarty plugins_dir default path to something more sensible. --- classes/view/smarty.php | 2 +- config/parser.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 1a39402..00de413 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -59,7 +59,7 @@ public static function parser() static::$_parser->compile_dir = \Config::get('parser.View_Smarty.environment.compile_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS); static::$_parser->config_dir = \Config::get('parser.View_Smarty.environment.config_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS); static::$_parser->cache_dir = \Config::get('parser.View_Smarty.environment.cache_dir', APPPATH.'cache'.DS.'Smarty'.DS); - static::$_parser->plugins_dir = array_merge(static::$_parser->plugins_dir, array(\Config::get('parser.View_Smarty.environment.plugins_dir', APPPATH.'cache'.DS.'Smarty'.DS))); + static::$_parser->plugins_dir = array_merge(static::$_parser->plugins_dir, array(\Config::get('parser.View_Smarty.environment.plugins_dir', APPPATH.'smarty'.DS))); static::$_parser->caching = \Config::get('parser.View_Smarty.environment.caching', false); static::$_parser->cache_lifetime = \Config::get('parser.View_Smarty.environment.cache_lifetime', 0); diff --git a/config/parser.php b/config/parser.php index 4f544d9..bc0889b 100644 --- a/config/parser.php +++ b/config/parser.php @@ -138,7 +138,7 @@ 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, - 'plugins_dir' => APPPATH.'cache'.DS.'Smarty'.DS, + 'plugins_dir' => APPPATH.'smarty'.DS, 'caching' => false, 'cache_lifetime' => 0, 'force_compile' => false, From 50d794c8d8dbf7587d07bbe0f77240ca8e843f64 Mon Sep 17 00:00:00 2001 From: Thomas David Baker Date: Sun, 1 Jul 2012 14:55:32 +0100 Subject: [PATCH 030/120] Use the official Smarty API way of adding a plugins directory. Use an array as the default value so that (a) we don't point at directories that don't exist and (b) we hint to the client programmer that more than one directory can be added. This way you can add more than one plugins dir, too, giving you more flexibility. --- classes/view/smarty.php | 3 ++- config/parser.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 00de413..b130802 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -59,7 +59,8 @@ public static function parser() static::$_parser->compile_dir = \Config::get('parser.View_Smarty.environment.compile_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS); static::$_parser->config_dir = \Config::get('parser.View_Smarty.environment.config_dir', APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS); static::$_parser->cache_dir = \Config::get('parser.View_Smarty.environment.cache_dir', APPPATH.'cache'.DS.'Smarty'.DS); - static::$_parser->plugins_dir = array_merge(static::$_parser->plugins_dir, array(\Config::get('parser.View_Smarty.environment.plugins_dir', APPPATH.'smarty'.DS))); + $plugins_dir = \Config::get('parser.View_Smarty.environment.plugins_dir', array()); + static::$_parser->addPluginsDir($plugins_dir); static::$_parser->caching = \Config::get('parser.View_Smarty.environment.caching', false); static::$_parser->cache_lifetime = \Config::get('parser.View_Smarty.environment.cache_lifetime', 0); diff --git a/config/parser.php b/config/parser.php index bc0889b..ac2223d 100644 --- a/config/parser.php +++ b/config/parser.php @@ -138,7 +138,7 @@ 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, - 'plugins_dir' => APPPATH.'smarty'.DS, + 'plugins_dir' => array(), 'caching' => false, 'cache_lifetime' => 0, 'force_compile' => false, From 783a174a4db936bc4e3a8d8fb9dce0223e7db434 Mon Sep 17 00:00:00 2001 From: Peter Wiggers - laptop Date: Sun, 1 Jul 2012 19:24:34 +0200 Subject: [PATCH 031/120] Typo (exist() must be exists()) --- config/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/parser.php b/config/parser.php index c6143ef..c307b2e 100644 --- a/config/parser.php +++ b/config/parser.php @@ -102,7 +102,7 @@ // MUSTACHE ( https://github.com/bobthecow/mustache.php ) // ------------------------------------------------------------------------ 'View_Mustache' => array( - 'include' => \Package::exist('parser').'vendor'.DS.'Mustache'.DS.'Mustache.php', + 'include' => \Package::exists('parser').'vendor'.DS.'Mustache'.DS.'Mustache.php', 'auto_encode' => true, 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( From 79ee2fd78c3d46adee793261473c5a199f0b9750 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Mon, 23 Jul 2012 19:29:18 +0900 Subject: [PATCH 032/120] phptal config fixed --- classes/view/phptal.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/phptal.php b/classes/view/phptal.php index b696ff9..39725d9 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -56,7 +56,7 @@ public static function parser() static::$_parser->setTemplateRepository(\Config::get('parser.View_Phptal.template_repository', '')); static::$_parser->setPhpCodeDestination(\Config::get('parser.View_Phptal.cache_dir', APPPATH.'cache'.DS.'PHPTAL'.DS)); static::$_parser->setCacheLifetime(\Config::get('parser.View_Phptal.cache_lifetime', 0)); - static::$_parser->setForceReparse(\Config::get('parser.View_Phptal.encoding', false)); + static::$_parser->setForceReparse(\Config::get('parser.View_Phptal.force_reparse', false)); return static::$_parser; } From 7e7876efa297122f74320a823aa9347cd7730f00 Mon Sep 17 00:00:00 2001 From: Craig Hooghiem Date: Thu, 6 Sep 2012 12:04:54 -0300 Subject: [PATCH 033/120] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f13c58..eff65bd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Simply add `parser` to your config.php `always_loaded.packages` config option. ## Included Parsers * Mustache - A lightweight, yet powerful templating library. -* SimpleTags - A library released by Dan Horrigan for basic template tag usage. +* Markdown - A PHP version of Markdown by Michael Fortin. ## Usage From 8f1d5ef05c775821773f3521ea3f3ac124fa1d26 Mon Sep 17 00:00:00 2001 From: Craig Hooghiem Date: Thu, 6 Sep 2012 12:08:05 -0300 Subject: [PATCH 034/120] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eff65bd..ab1f981 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Simply add `parser` to your config.php `always_loaded.packages` config option. ## Included Parsers * Mustache - A lightweight, yet powerful templating library. -* Markdown - A PHP version of Markdown by Michael Fortin. +* Markdown - A PHP version of Markdown by Michel Fortin. ## Usage From c6eaeaafe64f13515ccdadd67637360e5ede1e3a Mon Sep 17 00:00:00 2001 From: Derek Myers Date: Sun, 23 Sep 2012 18:13:21 -0500 Subject: [PATCH 035/120] Changed forge to be more like core fuel View and allow setting filename later after getting the view object. Signed-off-by: Derek Myers --- classes/view.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/classes/view.php b/classes/view.php index 6f47eff..5a82e9e 100644 --- a/classes/view.php +++ b/classes/view.php @@ -53,11 +53,22 @@ public static function _init() */ public static function forge($file = null, $data = null, $auto_encode = null) { - $extension = pathinfo($file, PATHINFO_EXTENSION); - $class = \Config::get('parser.extensions.'.$extension, get_called_class()); + $class = null; + + if ($file !== null) + { + $extension = pathinfo($file, PATHINFO_EXTENSION); + + $class = \Config::get('parser.extensions.'.$extension, null); + } + + if ($class === null) + { + $class = get_called_class(); + } // Only get rid of the extension if it is not an absolute file path - if ($file[0] !== '/' and $file[1] !== ':') + if ($file !== null and $file[0] !== '/' and $file[1] !== ':') { $file = $extension ? preg_replace('/\.'.preg_quote($extension).'$/i', '', $file) : $file; } @@ -87,11 +98,14 @@ public static function forge($file = null, $data = null, $auto_encode = null) $view = new $class(null, $data, $auto_encode); - // Set extension when given - $extension and $view->extension = $extension; - - // Load the view file - $view->set_filename($file); + if ($file !== null) + { + // Set extension when given + $extension and $view->extension = $extension; + + // Load the view file + $view->set_filename($file); + } return $view; } From 634204f87047fdb2d5957b74a7c24a4faea33cc2 Mon Sep 17 00:00:00 2001 From: Frank de Jonge Date: Mon, 5 Nov 2012 00:33:24 +0100 Subject: [PATCH 036/120] Fixed #56: upgrade markdown. --- vendor/markdown/markdown.php | 599 +++++++++++++++++------------------ 1 file changed, 299 insertions(+), 300 deletions(-) diff --git a/vendor/markdown/markdown.php b/vendor/markdown/markdown.php index ee3dddb..7f4ae23 100755 --- a/vendor/markdown/markdown.php +++ b/vendor/markdown/markdown.php @@ -3,17 +3,17 @@ # Markdown Extra - A text-to-HTML conversion tool for web writers # # PHP Markdown & Extra -# Copyright (c) 2004-2009 Michel Fortin +# Copyright (c) 2004-2012 Michel Fortin # # # Original Markdown -# Copyright (c) 2004-2006 John Gruber +# Copyright (c) 2004-2006 John Gruber # # -define( 'MARKDOWN_VERSION', "1.0.1n" ); # Sat 10 Oct 2009 -define( 'MARKDOWNEXTRA_VERSION', "1.2.4" ); # Sat 10 Oct 2009 +define( 'MARKDOWN_VERSION', "1.0.1o" ); # Sun 8 Jan 2012 +define( 'MARKDOWNEXTRA_VERSION', "1.2.5" ); # Sun 8 Jan 2012 # @@ -71,7 +71,7 @@ function Markdown($text) { Plugin Name: Markdown Extra Plugin URI: http://michelf.com/projects/php-markdown/ Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... -Version: 1.2.4 +Version: 1.2.5 Author: Michel Fortin Author URI: http://michelf.com/ */ @@ -79,7 +79,7 @@ function Markdown($text) { if (isset($wp_version)) { # More details about how it works here: # - + # Post content and excerpts # - Remove WordPress paragraph generator. # - Run Markdown on excerpt, then remove all tags. @@ -94,13 +94,13 @@ function Markdown($text) { add_filter('get_the_excerpt', 'trim', 7); add_filter('the_excerpt', 'mdwp_add_p'); add_filter('the_excerpt_rss', 'mdwp_strip_p'); - + remove_filter('content_save_pre', 'balanceTags', 50); remove_filter('excerpt_save_pre', 'balanceTags', 50); add_filter('the_content', 'balanceTags', 50); add_filter('get_the_excerpt', 'balanceTags', 9); } - + # Add a footnote id prefix to posts when inside a loop. function mdwp_MarkdownPost($text) { static $parser; @@ -115,7 +115,7 @@ function mdwp_MarkdownPost($text) { } return $parser->transform($text); } - + # Comments # - Remove WordPress paragraph generator. # - Remove WordPress auto-link generator. @@ -130,7 +130,7 @@ function mdwp_MarkdownPost($text) { add_filter('get_comment_text', 'Markdown', 6); add_filter('get_comment_excerpt', 'Markdown', 6); add_filter('get_comment_excerpt', 'mdwp_strip_p', 7); - + global $mdwp_hidden_tags, $mdwp_placeholders; $mdwp_hidden_tags = explode(' ', '

 
  • '); @@ -138,7 +138,7 @@ function mdwp_MarkdownPost($text) { 'pEj07ZbbBZ U1kqgh4w4p pre2zmeN6K QTi31t9pre ol0MP1jzJR '. 'ML5IjmbRol ulANi1NsGY J7zRLJqPul liA8ctl16T K9nhooUHli')); } - + function mdwp_add_p($text) { if (!preg_match('{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $text)) { $text = '

    '.$text.'

    '; @@ -146,7 +146,7 @@ function mdwp_add_p($text) { } return $text; } - + function mdwp_strip_p($t) { return preg_replace('{}i', '', $t); } function mdwp_hide_tags($text) { @@ -218,7 +218,7 @@ class Markdown_Parser { # Needed to insert a maximum bracked depth while converting to PHP. var $nested_brackets_depth = 6; var $nested_brackets_re; - + var $nested_url_parenthesis_depth = 4; var $nested_url_parenthesis_re; @@ -229,11 +229,11 @@ class Markdown_Parser { # Change to ">" for HTML output. var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX; var $tab_width = MARKDOWN_TAB_WIDTH; - + # Change to `true` to disallow markup or entities. var $no_markup = false; var $no_entities = false; - + # Predefined urls and titles for reference links and images. var $predef_urls = array(); var $predef_titles = array(); @@ -245,17 +245,17 @@ function Markdown_Parser() { # $this->_initDetab(); $this->prepareItalicsAndBold(); - - $this->nested_brackets_re = + + $this->nested_brackets_re = str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). str_repeat('\])*', $this->nested_brackets_depth); - - $this->nested_url_parenthesis_re = + + $this->nested_url_parenthesis_re = str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); - + $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; - + # Sort document, block, and span gamut in ascendent priority order. asort($this->document_gamut); asort($this->block_gamut); @@ -267,27 +267,27 @@ function Markdown_Parser() { var $urls = array(); var $titles = array(); var $html_hashes = array(); - + # Status flag to avoid invalid nesting. var $in_anchor = false; - - + + function setup() { # - # Called before the transformation process starts to setup parser + # Called before the transformation process starts to setup parser # states. # # Clear global hashes. $this->urls = $this->predef_urls; $this->titles = $this->predef_titles; $this->html_hashes = array(); - + $in_anchor = false; } - + function teardown() { # - # Called after the transformation process to clear any variable + # Called after the transformation process to clear any variable # which may be taking up memory unnecessarly. # $this->urls = array(); @@ -302,7 +302,7 @@ function transform($text) { # and pass it through the document gamut. # $this->setup(); - + # Remove UTF-8 BOM and marker character in input, if present. $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); @@ -329,16 +329,16 @@ function transform($text) { foreach ($this->document_gamut as $method => $priority) { $text = $this->$method($text); } - + $this->teardown(); return $text . "\n"; } - + var $document_gamut = array( # Strip link definitions, store in hashes. "stripLinkDefinitions" => 20, - + "runBasicBlockGamut" => 30, ); @@ -399,8 +399,8 @@ function hashHTMLBlocks($text) { # hard-coded: # # * List "a" is made of tags which can be both inline or block-level. - # These will be treated block-level when the start tag is alone on - # its line, otherwise they're not matched here and will be taken as + # These will be treated block-level when the start tag is alone on + # its line, otherwise they're not matched here and will be taken as # inline later. # * List "b" is made of tags which are always block-level; # @@ -422,7 +422,7 @@ function hashHTMLBlocks($text) { | \'[^\']*\' # text inside single quotes (tolerate ">") )* - )? + )? '; $content = str_repeat(' @@ -439,7 +439,7 @@ function hashHTMLBlocks($text) { str_repeat(' # closing nested tag ) - | + | <(?!/\2\s*> # other tags with a different name ) )*', @@ -465,9 +465,9 @@ function hashHTMLBlocks($text) { ) ( # save in $1 - # Match from `\n` to `\n`, handling nested tags + # Match from `\n` to `\n`, handling nested tags # in between. - + [ ]{0,'.$less_than_tab.'} <('.$block_tags_b_re.')# start tag = $2 '.$attr.'> # attributes followed by > and \n @@ -485,28 +485,28 @@ function hashHTMLBlocks($text) { # the matching end tag [ ]* # trailing spaces/tabs (?=\n+|\Z) # followed by a newline or end of document - - | # Special case just for
    . It was easier to make a special + + | # Special case just for
    . It was easier to make a special # case than to make the other regex more complicated. - + [ ]{0,'.$less_than_tab.'} <(hr) # start tag = $2 '.$attr.' # attributes /?> # the matching end tag [ ]* (?=\n{2,}|\Z) # followed by a blank line or end of document - + | # Special case for standalone HTML comments: - + [ ]{0,'.$less_than_tab.'} (?s: ) [ ]* (?=\n{2,}|\Z) # followed by a blank line or end of document - + | # PHP and ASP-style processor instructions (hashBlock($text); return "\n\n$key\n\n"; } - - + + function hashPart($text, $boundary = 'X') { # - # Called whenever a tag must be hashed when a function insert an atomic + # Called whenever a tag must be hashed when a function insert an atomic # element in the text stream. Passing $text to through this function gives # a unique text-token which will be reverted back when calling unhash. # @@ -544,7 +544,7 @@ function hashPart($text, $boundary = 'X') { # Swap back any tag hash found in $text so we do not have to `unhash` # multiple times at the end. $text = $this->unhash($text); - + # Then hash the block. static $i = 0; $key = "$boundary\x1A" . ++$i . $boundary; @@ -568,7 +568,7 @@ function hashBlock($text) { # "doHeaders" => 10, "doHorizontalRules" => 20, - + "doLists" => 40, "doCodeBlocks" => 50, "doBlockQuotes" => 60, @@ -578,33 +578,33 @@ function runBlockGamut($text) { # # Run block gamut tranformations. # - # We need to escape raw HTML in Markdown source before doing anything - # else. This need to be done for each block, and not only at the + # We need to escape raw HTML in Markdown source before doing anything + # else. This need to be done for each block, and not only at the # begining in the Markdown function since hashed blocks can be part of - # list items and could have been indented. Indented blocks would have + # list items and could have been indented. Indented blocks would have # been seen as a code block in a previous pass of hashHTMLBlocks. $text = $this->hashHTMLBlocks($text); - + return $this->runBasicBlockGamut($text); } - + function runBasicBlockGamut($text) { # - # Run block gamut tranformations, without hashing HTML blocks. This is + # Run block gamut tranformations, without hashing HTML blocks. This is # useful when HTML blocks are known to be already hashed, like in the first # whole-document pass. # foreach ($this->block_gamut as $method => $priority) { $text = $this->$method($text); } - + # Finally form paragraph and restore hashed blocks. $text = $this->formParagraphs($text); return $text; } - - + + function doHorizontalRules($text) { # Do Horizontal Rules: return preg_replace( @@ -618,7 +618,7 @@ function doHorizontalRules($text) { [ ]* # Tailing spaces $ # End of line. }mx', - "\n".$this->hashBlock("empty_element_suffix")."\n", + "\n".$this->hashBlock("empty_element_suffix")."\n", $text); } @@ -636,7 +636,7 @@ function doHorizontalRules($text) { # because ![foo][f] looks like an anchor. "doImages" => 10, "doAnchors" => 20, - + # Make links out of things like `` # Must come after doAnchors, because you can use < and > # delimiters in inline links like [this](). @@ -657,11 +657,11 @@ function runSpanGamut($text) { return $text; } - - + + function doHardBreaks($text) { # Do hard breaks: - return preg_replace_callback('/ {2,}\n/', + return preg_replace_callback('/ {2,}\n/', array(&$this, '_doHardBreaks_callback'), $text); } function _doHardBreaks_callback($matches) { @@ -675,7 +675,7 @@ function doAnchors($text) { # if ($this->in_anchor) return $text; $this->in_anchor = true; - + # # First, handle reference-style links: [link text] [id] # @@ -748,7 +748,7 @@ function _doAnchors_reference_callback($matches) { # for shortcut links like [this][] or [this]. $link_id = $link_text; } - + # lower-case and turn embedded newlines into spaces $link_id = strtolower($link_id); $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); @@ -756,14 +756,14 @@ function _doAnchors_reference_callback($matches) { if (isset($this->urls[$link_id])) { $url = $this->urls[$link_id]; $url = $this->encodeAttribute($url); - + $result = "titles[$link_id] ) ) { $title = $this->titles[$link_id]; $title = $this->encodeAttribute($title); $result .= " title=\"$title\""; } - + $link_text = $this->runSpanGamut($link_text); $result .= ">$link_text"; $result = $this->hashPart($result); @@ -786,7 +786,7 @@ function _doAnchors_inline_callback($matches) { $title = $this->encodeAttribute($title); $result .= " title=\"$title\""; } - + $link_text = $this->runSpanGamut($link_text); $result .= ">$link_text"; @@ -815,7 +815,7 @@ function doImages($text) { \] ) - }xs', + }xs', array(&$this, '_doImages_reference_callback'), $text); # @@ -900,7 +900,7 @@ function doHeaders($text) { # Setext-style headers: # Header 1 # ======== - # + # # Header 2 # -------- # @@ -930,7 +930,7 @@ function _doHeaders_callback_setext($matches) { # Terrible hack to check we haven't found an empty list item. if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) return $matches[0]; - + $level = $matches[2]{0} == '=' ? 1 : 2; $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; @@ -950,7 +950,7 @@ function doLists($text) { # Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[.]'; + $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; $markers_relist = array( @@ -986,10 +986,10 @@ function doLists($text) { ) ) '; // mx - + # We use a different prefix before nested lists than top-level lists. # See extended comment in _ProcessListItems(). - + if ($this->list_level) { $text = preg_replace_callback('{ ^ @@ -1011,17 +1011,17 @@ function doLists($text) { function _doLists_callback($matches) { # Re-usable patterns to match list item bullets and number markers: $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[.]'; + $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - + $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; - + $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); - + $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); - + $result = $this->hashBlock("<$list_type>\n" . $result . ""); return "\n". $result ."\n\n"; } @@ -1053,7 +1053,7 @@ function processListItems($list_str, $marker_any_re) { # without resorting to mind-reading. Perhaps the solution is to # change the syntax rules such that sub-lists must start with a # starting cardinal number; e.g. "1." or "a.". - + $this->list_level++; # trim trailing blank lines: @@ -1081,7 +1081,7 @@ function _processListItems_callback($matches) { $marker_space = $matches[3]; $tailing_blank_line =& $matches[5]; - if ($leading_line || $tailing_blank_line || + if ($leading_line || $tailing_blank_line || preg_match('/\n{2,}/', $item)) { # Replace marker with the appropriate whitespace indentation @@ -1141,22 +1141,22 @@ function makeCodeSpan($code) { var $em_relist = array( - '' => '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(?em_strong_prepared_relist["$em$strong"] = $token_re; } } } - + function doItalicsAndBold($text) { $token_stack = array(''); $text_stack = array(''); $em = ''; $strong = ''; $tree_char_em = false; - + while (1) { # # Get prepared regular expression for seraching emphasis tokens # in current context. # $token_re = $this->em_strong_prepared_relist["$em$strong"]; - + # - # Each loop iteration search for the next emphasis token. + # Each loop iteration search for the next emphasis token. # Each token is then passed to handleSpanToken. # $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); $text_stack[0] .= $parts[0]; $token =& $parts[1]; $text =& $parts[2]; - + if (empty($token)) { # Reached end of text span: empty stack without emitting. # any more emphasis. @@ -1211,7 +1211,7 @@ function doItalicsAndBold($text) { } break; } - + $token_len = strlen($token); if ($tree_char_em) { # Reached closing marker while inside a three-char emphasis. @@ -1250,7 +1250,7 @@ function doItalicsAndBold($text) { $$tag = ''; # $$tag stands for $em or $strong } } else { - # Reached opening three-char emphasis marker. Push on token + # Reached opening three-char emphasis marker. Push on token # stack; will be handled by the special condition above. $em = $token{0}; $strong = "$em$em"; @@ -1324,9 +1324,9 @@ function _doBlockQuotes_callback($matches) { $bq = $this->runBlockGamut($bq); # recurse $bq = preg_replace('/^/m', " ", $bq); - # These leading spaces cause problem with
     content, 
    +		# These leading spaces cause problem with 
     content,
     		# so we need to fix that:
    -		$bq = preg_replace_callback('{(\s*
    .+?
    )}sx', + $bq = preg_replace_callback('{(\s*
    .+?
    )}sx', array(&$this, '_doBlockQuotes_callback2'), $bq); return "\n". $this->hashBlock("
    \n$bq\n
    ")."\n\n"; @@ -1389,7 +1389,7 @@ function formParagraphs($text) { // # We can't call Markdown(), because that resets the hash; // # that initialization code should be pulled into its own sub, though. // $div_content = $this->hashHTMLBlocks($div_content); -// +// // # Run document gamut methods on the content. // foreach ($this->document_gamut as $method => $priority) { // $div_content = $this->$method($div_content); @@ -1417,11 +1417,11 @@ function encodeAttribute($text) { $text = str_replace('"', '"', $text); return $text; } - - + + function encodeAmpsAndAngles($text) { # - # Smart processing for ampersands and angle brackets that need to + # Smart processing for ampersands and angle brackets that need to # be encoded. Valid character entities are left alone unless the # no-entities mode is set. # @@ -1430,7 +1430,7 @@ function encodeAmpsAndAngles($text) { } else { # Ampersand-encoding based entirely on Nat Irons's Amputator # MT plugin: - $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', + $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', '&', $text);; } # Encode remaining <'s @@ -1441,7 +1441,7 @@ function encodeAmpsAndAngles($text) { function doAutoLinks($text) { - $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', + $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', array(&$this, '_doAutoLinks_url_callback'), $text); # Email addresses: @@ -1498,7 +1498,7 @@ function encodeEmailAddress($addr) { $addr = "mailto:" . $addr; $chars = preg_split('/(? $char) { $ord = ord($char); # Ignore non-ascii chars. @@ -1511,7 +1511,7 @@ function encodeEmailAddress($addr) { else $chars[$key] = '&#'.$ord.';'; } } - + $addr = implode('', $chars); $text = implode('', array_slice($chars, 7)); # text without `mailto:` $addr = "$text"; @@ -1526,7 +1526,7 @@ function parseSpan($str) { # escaped characters and handling code spans. # $output = ''; - + $span_re = '{ ( \\\\'.$this->escape_chars_re.' @@ -1551,17 +1551,17 @@ function parseSpan($str) { while (1) { # - # Each loop iteration seach for either the next tag, the next - # openning code span marker, or the next escaped character. + # Each loop iteration seach for either the next tag, the next + # openning code span marker, or the next escaped character. # Each token is then passed to handleSpanToken. # $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); - + # Create token from text preceding tag. if ($parts[0] != "") { $output .= $parts[0]; } - + # Check if we reach the end. if (isset($parts[1])) { $output .= $this->handleSpanToken($parts[1], $parts[2]); @@ -1571,14 +1571,14 @@ function parseSpan($str) { break; } } - + return $output; } - - + + function handleSpanToken($token, &$str) { # - # Handle $token provided by parseSpan by determining its nature and + # Handle $token provided by parseSpan by determining its nature and # returning the corresponding value that should replace it. # switch ($token{0}) { @@ -1586,7 +1586,7 @@ function handleSpanToken($token, &$str) { return $this->hashPart("&#". ord($token{1}). ";"); case "`": # Search for end marker in remaining text. - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', + if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', $str, $matches)) { $str = $matches[2]; @@ -1608,18 +1608,18 @@ function outdent($text) { } - # String length function for detab. `_initDetab` will create a function to + # String length function for detab. `_initDetab` will create a function to # hanlde UTF-8 if the default function does not exist. var $utf8_strlen = 'mb_strlen'; - + function detab($text) { # # Replace tabs with the appropriate amount of space. # # For each line we separate the line in blocks delemited by - # tab characters. Then we reconstruct every line by adding the + # tab characters. Then we reconstruct every line by adding the # appropriate number of space between each blocks. - + $text = preg_replace_callback('/^.*\t.*$/m', array(&$this, '_detab_callback'), $text); @@ -1628,7 +1628,7 @@ function detab($text) { function _detab_callback($matches) { $line = $matches[0]; $strlen = $this->utf8_strlen; # strlen function for UTF-8. - + # Split in blocks. $blocks = explode("\t", $line); # Add each blocks to the line. @@ -1636,7 +1636,7 @@ function _detab_callback($matches) { unset($blocks[0]); # Do not add first block twice. foreach ($blocks as $block) { # Calculate amount of space, insert spaces, insert block. - $amount = $this->tab_width - + $amount = $this->tab_width - $strlen($line, 'UTF-8') % $this->tab_width; $line .= str_repeat(" ", $amount) . $block; } @@ -1645,13 +1645,13 @@ function _detab_callback($matches) { function _initDetab() { # # Check for the availability of the function in the `utf8_strlen` property - # (initially `mb_strlen`). If the function is not available, create a + # (initially `mb_strlen`). If the function is not available, create a # function that will loosely count the number of UTF-8 characters with a # regular expression. # if (function_exists($this->utf8_strlen)) return; $this->utf8_strlen = create_function('$text', 'return preg_match_all( - "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", + "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", $text, $m);'); } @@ -1660,7 +1660,7 @@ function unhash($text) { # # Swap back in all the tags hashed by _HashHTMLBlocks. # - return preg_replace_callback('/(.)\x1A[0-9]+\1/', + return preg_replace_callback('/(.)\x1A[0-9]+\1/', array(&$this, '_unhash_callback'), $text); } function _unhash_callback($matches) { @@ -1678,15 +1678,15 @@ class MarkdownExtra_Parser extends Markdown_Parser { # Prefix for footnote ids. var $fn_id_prefix = ""; - + # Optional title attribute for footnote links and backlinks. var $fn_link_title = MARKDOWN_FN_LINK_TITLE; var $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE; - + # Optional class attribute for footnote links and backlinks. var $fn_link_class = MARKDOWN_FN_LINK_CLASS; var $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS; - + # Predefined abbreviations. var $predef_abbr = array(); @@ -1695,11 +1695,11 @@ function MarkdownExtra_Parser() { # # Constructor function. Initialize the parser object. # - # Add extra escapable characters before parent constructor + # Add extra escapable characters before parent constructor # initialize the table. $this->escape_chars .= ':|'; - - # Insert extra document, block, and span transformations. + + # Insert extra document, block, and span transformations. # Parent constructor will do the sorting. $this->document_gamut += array( "doFencedCodeBlocks" => 5, @@ -1716,33 +1716,33 @@ function MarkdownExtra_Parser() { "doFootnotes" => 5, "doAbbreviations" => 70, ); - + parent::Markdown_Parser(); } - - + + # Extra variables used during extra transformations. var $footnotes = array(); var $footnotes_ordered = array(); var $abbr_desciptions = array(); var $abbr_word_re = ''; - + # Give the current footnote number. var $footnote_counter = 1; - - + + function setup() { # # Setting up Extra-specific variables. # parent::setup(); - + $this->footnotes = array(); $this->footnotes_ordered = array(); $this->abbr_desciptions = array(); $this->abbr_word_re = ''; $this->footnote_counter = 1; - + foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { if ($this->abbr_word_re) $this->abbr_word_re .= '|'; @@ -1750,7 +1750,7 @@ function setup() { $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); } } - + function teardown() { # # Clearing Extra-specific variables. @@ -1759,29 +1759,29 @@ function teardown() { $this->footnotes_ordered = array(); $this->abbr_desciptions = array(); $this->abbr_word_re = ''; - + parent::teardown(); } - - + + ### HTML Block Parser ### - + # Tags that are always treated as block tags: var $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend'; - + # Tags treated as block tags only if the opening tag is alone on it's line: var $context_block_tags_re = 'script|noscript|math|ins|del'; - + # Tags where markdown="1" default to span mode: var $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; - - # Tags which must not have their contents modified, no matter where + + # Tags which must not have their contents modified, no matter where # they appear: var $clean_tags_re = 'script|math'; - + # Tags that do not need to be closed. var $auto_close_tags_re = 'hr|img'; - + function hashHTMLBlocks($text) { # @@ -1794,7 +1794,7 @@ function hashHTMLBlocks($text) { # hard-coded. # # This works by calling _HashHTMLBlocks_InMarkdown, which then calls - # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" + # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" # attribute is found whitin a tag, _HashHTMLBlocks_InHTML calls back # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. # These two functions are calling each other. It's recursive! @@ -1803,17 +1803,17 @@ function hashHTMLBlocks($text) { # Call the HTML-in-Markdown hasher. # list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); - + return $text; } - function _hashHTMLBlocks_inMarkdown($text, $indent = 0, + function _hashHTMLBlocks_inMarkdown($text, $indent = 0, $enclosing_tag_re = '', $span = false) { # # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. # - # * $indent is the number of space to be ignored when checking for code - # blocks. This is important because if we don't take the indent into + # * $indent is the number of space to be ignored when checking for code + # blocks. This is important because if we don't take the indent into # account, something like this (which looks right) won't work as expected: # #
    @@ -1825,11 +1825,11 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # If you don't like this, just don't indent the tag on which # you apply the markdown="1" attribute. # - # * If $enclosing_tag_re is not empty, stops at the first unmatched closing + # * If $enclosing_tag_re is not empty, stops at the first unmatched closing # tag with that name. Nested tags supported. # - # * If $span is true, text inside must treated as span. So any double - # newline will be replaced by a single newline so that it does not create + # * If $span is true, text inside must treated as span. So any double + # newline will be replaced by a single newline so that it does not create # paragraphs. # # Returns an array of that form: ( processed text , remaining text ) @@ -1838,13 +1838,13 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # Regex to check for the presense of newlines around a block tag. $newline_before_re = '/(?:^\n?|\n\n)*$/'; - $newline_after_re = + $newline_after_re = '{ ^ # Start of text following the tag. (?>[ ]*)? # Optional comment. [ ]*\n # Must be followed by newline. }xs'; - + # Regex to match any tag. $block_tag_re = '{ @@ -1885,12 +1885,12 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, | # Fenced code block marker (?> ^ | \n ) - [ ]{'.($indent).'}~~~+[ ]*\n + [ ]{0,'.($indent).'}~~~+[ ]*\n ' : '' ). ' # End (if not is span). ) }xs'; - + $depth = 0; # Current depth inside the tag tree. $parsed = ""; # Parsed text that will be returned. @@ -1902,32 +1902,32 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # # Split the text using the first $tag_match pattern found. # Text before pattern will be first in the array, text after - # pattern will be at the end, and between will be any catches made + # pattern will be at the end, and between will be any catches made # by the pattern. # - $parts = preg_split($block_tag_re, $text, 2, + $parts = preg_split($block_tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); - - # If in Markdown span mode, add a empty-string span-level hash + + # If in Markdown span mode, add a empty-string span-level hash # after each newline to prevent triggering any block element. if ($span) { $void = $this->hashPart("", ':'); $newline = "$void\n"; $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; } - + $parsed .= $parts[0]; # Text before current tag. - + # If end of $text has been reached. Stop loop. if (count($parts) < 3) { $text = ""; break; } - + $tag = $parts[1]; # Tag to handle. $text = $parts[2]; # Remaining text after current tag. $tag_re = preg_quote($tag); # For use in a regular expression. - + # # Check for: Code span marker # @@ -1947,21 +1947,13 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, } } # - # Check for: Indented code block. - # - else if ($tag{0} == "\n" || $tag{0} == " ") { - # Indented code block: pass it unchanged, will be handled - # later. - $parsed .= $tag; - } - # # Check for: Fenced code block marker. # - else if ($tag{0} == "~") { + else if (preg_match('{^\n?[ ]{0,'.($indent+3).'}~}', $tag)) { # Fenced code block marker: find matching end marker. $tag_re = preg_quote(trim($tag)); - if (preg_match('{^(?>.*\n)+?'.$tag_re.' *\n}', $text, - $matches)) + if (preg_match('{^(?>.*\n)+?[ ]{0,'.($indent).'}'.$tag_re.'[ ]*\n}', $text, + $matches)) { # End marker found: pass text unchanged until marker. $parsed .= $tag . $matches[0]; @@ -1973,8 +1965,16 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, } } # + # Check for: Indented code block. + # + else if ($tag{0} == "\n" || $tag{0} == " ") { + # Indented code block: pass it unchanged, will be handled + # later. + $parsed .= $tag; + } + # # Check for: Opening Block level tag or - # Opening Context Block tag (like ins and del) + # Opening Context Block tag (like ins and del) # used as a block tag (tag is alone on it's line). # else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || @@ -1984,9 +1984,9 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, ) { # Need to parse tag and following text using the HTML parser. - list($block_text, $text) = + list($block_text, $text) = $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); - + # Make sure it stays outside of any paragraph by adding newlines. $parsed .= "\n\n$block_text\n\n"; } @@ -1999,9 +1999,9 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, { # Need to parse tag and following text using the HTML parser. # (don't check for markdown attribute) - list($block_text, $text) = + list($block_text, $text) = $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); - + $parsed .= $block_text; } # @@ -2025,14 +2025,14 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, $text = $tag . $text; break; } - + $parsed .= $tag; } else { $parsed .= $tag; } } while ($depth >= 0); - + return array($parsed, $text); } function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { @@ -2047,7 +2047,7 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # Returns an array of that form: ( processed text , remaining text ) # if ($text === '') return array('', ''); - + # Regex to match `markdown` attribute inside of a tag. $markdown_attr_re = ' { @@ -2055,15 +2055,15 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { markdown \s*=\s* (?> - (["\']) # $1: quote delimiter + (["\']) # $1: quote delimiter (.*?) # $2: attribute value - \1 # matching delimiter + \1 # matching delimiter | ([^\s>]*) # $3: unquoted attribute value ) () # $4: make $3 always defined (avoid warnings) }xs'; - + # Regex to match any tag. $tag_re = '{ ( # $2: Capture hole tag. @@ -2086,9 +2086,9 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # CData Block ) }xs'; - + $original_text = $text; # Save original text in case of faliure. - + $depth = 0; # Current depth inside the tag tree. $block_text = ""; # Temporary text holder for current text. $parsed = ""; # Parsed text that will be returned. @@ -2107,25 +2107,25 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # # Split the text using the first $tag_match pattern found. # Text before pattern will be first in the array, text after - # pattern will be at the end, and between will be any catches made + # pattern will be at the end, and between will be any catches made # by the pattern. # $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); - + if (count($parts) < 3) { # # End of $text reached with unbalenced tag(s). # In that case, we return original text unchanged and pass the - # first character as filtered to prevent an infinite loop in the + # first character as filtered to prevent an infinite loop in the # parent function. # return array($original_text{0}, substr($original_text, 1)); } - + $block_text .= $parts[0]; # Text before current tag. $tag = $parts[1]; # Tag to handle. $text = $parts[2]; # Remaining text after current tag. - + # # Check for: Auto-close tag (like
    ) # Comments and Processing Instructions. @@ -2145,22 +2145,22 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { if ($tag{1} == '/') $depth--; else if ($tag{strlen($tag)-2} != '/') $depth++; } - + # # Check for `markdown="1"` attribute and handle it. # - if ($md_attr && + if ($md_attr && preg_match($markdown_attr_re, $tag, $attr_m) && preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) { # Remove `markdown` attribute from opening tag. $tag = preg_replace($markdown_attr_re, '', $tag); - + # Check if text inside this tag must be parsed in span mode. $this->mode = $attr_m[2] . $attr_m[3]; $span_mode = $this->mode == 'span' || $this->mode != 'block' && preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); - + # Calculate indent before tag. if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { $strlen = $this->utf8_strlen; @@ -2168,44 +2168,44 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { } else { $indent = 0; } - + # End preceding block with this tag. $block_text .= $tag; $parsed .= $this->$hash_method($block_text); - + # Get enclosing tag name for the ParseMarkdown function. # (This pattern makes $tag_name_re safe without quoting.) preg_match('/^<([\w:$]*)\b/', $tag, $matches); $tag_name_re = $matches[1]; - + # Parse the content using the HTML-in-Markdown parser. list ($block_text, $text) - = $this->_hashHTMLBlocks_inMarkdown($text, $indent, + = $this->_hashHTMLBlocks_inMarkdown($text, $indent, $tag_name_re, $span_mode); - + # Outdent markdown text. if ($indent > 0) { - $block_text = preg_replace("/^[ ]{1,$indent}/m", "", + $block_text = preg_replace("/^[ ]{1,$indent}/m", "", $block_text); } - + # Append tag content to parsed text. if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; else $parsed .= "$block_text"; - + # Start over a new block. $block_text = ""; } else $block_text .= $tag; } - + } while ($depth > 0); - + # # Hash last block text that wasn't processed inside the loop. # $parsed .= $this->$hash_method($block_text); - + return array($parsed, $text); } @@ -2213,7 +2213,7 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { function hashClean($text) { # # Called whenever a tag must be hashed when a function insert a "clean" tag - # in $text, it pass through this function and is automaticaly escaped, + # in $text, it pass through this function and is automaticaly escaped, # blocking invalid nested overlap. # return $this->hashPart($text, 'C'); @@ -2227,7 +2227,7 @@ function doHeaders($text) { # Setext-style headers: # Header 1 {#header1} # ======== - # + # # Header 2 {#header2} # -------- # @@ -2299,10 +2299,10 @@ function doTables($text) { [ ]{0,'.$less_than_tab.'} # Allowed whitespace. [|] # Optional leading pipe (present) (.+) \n # $1: Header row (at least one pipe) - + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. [|] ([ ]*[-:]+[-| :]*) \n # $2: Header underline - + ( # $3: Cells (?> [ ]* # Allowed whitespace. @@ -2312,7 +2312,7 @@ function doTables($text) { (?=\n|\Z) # Stop at final double newline. }xm', array(&$this, '_doTable_leadingPipe_callback'), $text); - + # # Find tables without leading pipe. # @@ -2326,10 +2326,10 @@ function doTables($text) { ^ # Start of a line [ ]{0,'.$less_than_tab.'} # Allowed whitespace. (\S.*[|].*) \n # $1: Header row (at least one pipe) - + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. ([-:]+[ ]*[|][-| :]*) \n # $2: Header underline - + ( # $3: Cells (?> .* [|] .* \n # Row content @@ -2345,10 +2345,10 @@ function _doTable_leadingPipe_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; - + # Remove leading pipe for each row. $content = preg_replace('/^ *[|]/m', '', $content); - + return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); } function _doTable_callback($matches) { @@ -2360,7 +2360,7 @@ function _doTable_callback($matches) { $head = preg_replace('/[|] *$/m', '', $head); $underline = preg_replace('/[|] *$/m', '', $underline); $content = preg_replace('/[|] *$/m', '', $content); - + # Reading alignement from header underline. $separators = preg_split('/ *[|] */', $underline); foreach ($separators as $n => $s) { @@ -2369,13 +2369,13 @@ function _doTable_callback($matches) { else if (preg_match('/^ *:-+ *$/', $s)) $attr[$n] = ' align="left"'; else $attr[$n] = ''; } - - # Parsing span elements, including code spans, character escapes, + + # Parsing span elements, including code spans, character escapes, # and inline HTML tags, so that pipes inside those gets ignored. $head = $this->parseSpan($head); $headers = preg_split('/ *[|] */', $head); $col_count = count($headers); - + # Write column headers. $text = "\n"; $text .= "\n"; @@ -2384,20 +2384,20 @@ function _doTable_callback($matches) { $text .= " ".$this->runSpanGamut(trim($header))."\n"; $text .= "\n"; $text .= "\n"; - + # Split content by row. $rows = explode("\n", trim($content, "\n")); - + $text .= "\n"; foreach ($rows as $row) { - # Parsing span elements, including code spans, character escapes, + # Parsing span elements, including code spans, character escapes, # and inline HTML tags, so that pipes inside those gets ignored. $row = $this->parseSpan($row); - + # Split row by cell. $row_cells = preg_split('/ *[|] */', $row, $col_count); $row_cells = array_pad($row_cells, $col_count, ''); - + $text .= "\n"; foreach ($row_cells as $n => $cell) $text .= " ".$this->runSpanGamut(trim($cell))."\n"; @@ -2405,11 +2405,11 @@ function _doTable_callback($matches) { } $text .= "\n"; $text .= "
    "; - + return $this->hashBlock($text) . "\n"; } - + function doDefLists($text) { # # Form HTML definition lists. @@ -2455,7 +2455,7 @@ function doDefLists($text) { function _doDefLists_callback($matches) { # Re-usable patterns to match list item bullets and number markers: $list = $matches[1]; - + # Turn double returns into triple returns, so that we can make a # paragraph for the last item in a list, if necessary: $result = trim($this->processDefListItems($list)); @@ -2470,7 +2470,7 @@ function processDefListItems($list_str) { # into individual term and definition list items. # $less_than_tab = $this->tab_width - 1; - + # trim trailing blank lines: $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); @@ -2479,11 +2479,11 @@ function processDefListItems($list_str) { (?>\A\n?|\n\n+) # leading line ( # definition terms = $1 [ ]{0,'.$less_than_tab.'} # leading whitespace - (?![:][ ]|[ ]) # negative lookahead for a definition + (?![:][ ]|[ ]) # negative lookahead for a definition # mark (colon) or more whitespace. - (?> \S.* \n)+? # actual term (not whitespace). - ) - (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed + (?> \S.* \n)+? # actual term (not whitespace). + ) + (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed # with a definition mark. }xm', array(&$this, '_processDefListItems_callback_dt'), $list_str); @@ -2500,8 +2500,8 @@ function processDefListItems($list_str) { (?: # next term or end of text [ ]{0,'.$less_than_tab.'} [:][ ] |
    | \z - ) - ) + ) + ) }xm', array(&$this, '_processDefListItems_callback_dd'), $list_str); @@ -2545,7 +2545,7 @@ function doFencedCodeBlocks($text) { # ~~~ # $less_than_tab = $this->tab_width; - + $text = preg_replace_callback('{ (?:\n|\A) # 1: Opening marker @@ -2553,7 +2553,7 @@ function doFencedCodeBlocks($text) { ~{3,} # Marker: three tilde or more. ) [ ]* \n # Whitespace and newline following marker. - + # 2: Content ( (?> @@ -2561,7 +2561,7 @@ function doFencedCodeBlocks($text) { .*\n+ )+ ) - + # Closing marker. \1 [ ]* \n }xm', @@ -2578,7 +2578,7 @@ function _doFencedCodeBlocks_callback($matches) { return "\n\n".$this->hashBlock($codeblock)."\n\n"; } function _doFencedCodeBlocks_newlines($matches) { - return str_repeat("empty_element_suffix", + return str_repeat("empty_element_suffix", strlen($matches[0])); } @@ -2588,17 +2588,17 @@ function _doFencedCodeBlocks_newlines($matches) { # work in the middle of a word. # var $em_relist = array( - '' => '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? $value) { $value = trim($this->runSpanGamut($value)); - + # Check if this should be enclosed in a paragraph. # Clean tag hashes & block tag hashes are left alone. $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); - + if ($is_p) { $value = "

    $value

    "; } $grafs[$key] = $value; } - - # Join grafs in one text, then unhash HTML tags. + + # Join grafs in one text, then unhash HTML tags. $text = implode("\n\n", $grafs); - + # Finish by removing any tag hashes still present in $text. $text = $this->unhash($text); - + return $text; } - - + + ### Footnotes - + function stripFootnotes($text) { # # Strips link definitions from text, stores the URLs and titles in @@ -2655,15 +2655,15 @@ function stripFootnotes($text) { [ ]* \n? # maybe *one* newline ( # text = $2 (no blank lines allowed) - (?: + (?: .+ # actual text | - \n # newlines but + \n # newlines but (?!\[\^.+?\]:\s)# negative lookahead for footnote marker. - (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed + (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed # by non-indented content )* - ) + ) }xm', array(&$this, '_stripFootnotes_callback'), $text); @@ -2678,7 +2678,7 @@ function _stripFootnotes_callback($matches) { function doFootnotes($text) { # - # Replace footnote references in $text [^id] with a special text-token + # Replace footnote references in $text [^id] with a special text-token # which will be replaced by the actual footnote marker in appendFootnotes. # if (!$this->in_anchor) { @@ -2687,20 +2687,20 @@ function doFootnotes($text) { return $text; } - + function appendFootnotes($text) { # # Append footnote list to text. # - $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', + $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', array(&$this, '_appendFootnotes_callback'), $text); - + if (!empty($this->footnotes_ordered)) { $text .= "\n\n"; $text .= "
    \n"; $text .= "empty_element_suffix ."\n"; $text .= "
      \n\n"; - + $attr = " rev=\"footnote\""; if ($this->fn_backlink_class != "") { $class = $this->fn_backlink_class; @@ -2713,20 +2713,20 @@ function appendFootnotes($text) { $attr .= " title=\"$title\""; } $num = 0; - + while (!empty($this->footnotes_ordered)) { $footnote = reset($this->footnotes_ordered); $note_id = key($this->footnotes_ordered); unset($this->footnotes_ordered[$note_id]); - + $footnote .= "\n"; # Need to append newline before parsing. - $footnote = $this->runBlockGamut("$footnote\n"); - $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', + $footnote = $this->runBlockGamut("$footnote\n"); + $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', array(&$this, '_appendFootnotes_callback'), $footnote); - + $attr = str_replace("%%", ++$num, $attr); $note_id = $this->encodeAttribute($note_id); - + # Add backlink to last paragraph; create new paragraph if needed. $backlink = ""; if (preg_match('{

      $}', $footnote)) { @@ -2734,12 +2734,12 @@ function appendFootnotes($text) { } else { $footnote .= "\n\n

      $backlink

      "; } - + $text .= "
    1. \n"; $text .= $footnote . "\n"; $text .= "
    2. \n\n"; } - + $text .= "
    \n"; $text .= "
    "; } @@ -2747,14 +2747,14 @@ function appendFootnotes($text) { } function _appendFootnotes_callback($matches) { $node_id = $this->fn_id_prefix . $matches[1]; - + # Create footnote marker only if it has a corresponding footnote *and* # the footnote hasn't been used by another marker. if (isset($this->footnotes[$node_id])) { # Transfert footnote content to the ordered list. $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; unset($this->footnotes[$node_id]); - + $num = $this->footnote_counter++; $attr = " rel=\"footnote\""; if ($this->fn_link_class != "") { @@ -2767,22 +2767,22 @@ function _appendFootnotes_callback($matches) { $title = $this->encodeAttribute($title); $attr .= " title=\"$title\""; } - + $attr = str_replace("%%", $num, $attr); $node_id = $this->encodeAttribute($node_id); - + return "". "$num". ""; } - + return "[^".$matches[1]."]"; } - - + + ### Abbreviations ### - + function stripAbbreviations($text) { # # Strips abbreviations from text, stores titles in hash references. @@ -2792,7 +2792,7 @@ function stripAbbreviations($text) { # Link defs are in the form: [id]*: url "optional title" $text = preg_replace_callback('{ ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 - (.*) # text = $2 (no blank lines allowed) + (.*) # text = $2 (no blank lines allowed) }xm', array(&$this, '_stripAbbreviations_callback'), $text); @@ -2807,20 +2807,20 @@ function _stripAbbreviations_callback($matches) { $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); return ''; # String that will replace the block } - - + + function doAbbreviations($text) { # # Find defined abbreviations in text and wrap them in elements. # if ($this->abbr_word_re) { - // cannot use the /x modifier because abbr_word_re may + // cannot use the /x modifier because abbr_word_re may // contain significant spaces: $text = preg_replace_callback('{'. '(?abbr_word_re.')'. '(?![\w\x1A])'. - '}', + '}', array(&$this, '_doAbbreviations_callback'), $text); } return $text; @@ -2851,9 +2851,9 @@ function _doAbbreviations_callback($matches) { Description ----------- -This is a PHP port of the original Markdown formatter written in Perl -by John Gruber. This special "Extra" version of PHP Markdown features -further enhancements to the syntax for making additional constructs +This is a PHP port of the original Markdown formatter written in Perl +by John Gruber. This special "Extra" version of PHP Markdown features +further enhancements to the syntax for making additional constructs such as tables and definition list. Markdown is a text-to-HTML filter; it translates an easy-to-read / @@ -2883,7 +2883,7 @@ function _doAbbreviations_callback($matches) { Version History ---------------- +--------------- See the readme file for detailed release notes for this version. @@ -2891,14 +2891,14 @@ function _doAbbreviations_callback($matches) { Copyright and License --------------------- -PHP Markdown & Extra -Copyright (c) 2004-2009 Michel Fortin - +PHP Markdown & Extra +Copyright (c) 2004-2009 Michel Fortin + All rights reserved. -Based on Markdown -Copyright (c) 2003-2006 John Gruber - +Based on Markdown +Copyright (c) 2003-2006 John Gruber + All rights reserved. Redistribution and use in source and binary forms, with or without @@ -2928,5 +2928,4 @@ function _doAbbreviations_callback($matches) { negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. -*/ -?> \ No newline at end of file +*/ \ No newline at end of file From 468ee76ed58d8820bd4cbf99e824d29967185a6b Mon Sep 17 00:00:00 2001 From: Davide Bellini Date: Wed, 9 Jan 2013 20:05:38 +0100 Subject: [PATCH 037/120] Fixed issue #57 for the latest release of Twig --- classes/view/twig.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index 0c77eb0..4252057 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -23,6 +23,7 @@ class View_Twig extends \View { protected static $_parser; protected static $_parser_loader; + protected static $_twig_lexer_conf; public static function _init() { @@ -53,6 +54,9 @@ protected function process_file($file_override = false) } } + $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); + static::$_parser->setLexer($twig_lexer); + try { return static::parser()->loadTemplate($view_name)->render($local_data); @@ -90,18 +94,15 @@ public static function parser() } // Twig Lexer - $twig_lexer_conf = \Config::get('parser.View_Twig.delimiters', null); - if (isset($twig_lexer_conf)) + static::$_twig_lexer_conf = \Config::get('parser.View_Twig.delimiters', null); + if (isset(static::$_twig_lexer_conf)) { - isset($twig_lexer_conf['tag_block']) - and $twig_lexer_conf['tag_block'] = array_values($twig_lexer_conf['tag_block']); - isset($twig_lexer_conf['tag_comment']) - and $twig_lexer_conf['tag_comment'] = array_values($twig_lexer_conf['tag_comment']); - isset($twig_lexer_conf['tag_variable']) - and $twig_lexer_conf['tag_variable'] = array_values($twig_lexer_conf['tag_variable']); - - $twig_lexer = new Twig_Lexer(static::$_parser, $twig_lexer_conf); - static::$_parser->setLexer($twig_lexer); + isset(static::$_twig_lexer_conf['tag_block']) + and static::$_twig_lexer_conf['tag_block'] = array_values(static::$_twig_lexer_conf['tag_block']); + isset(static::$_twig_lexer_conf['tag_comment']) + and static::$_twig_lexer_conf['tag_comment'] = array_values(static::$_twig_lexer_conf['tag_comment']); + isset(static::$_twig_lexer_conf['tag_variable']) + and static::$_twig_lexer_conf['tag_variable'] = array_values(static::$_twig_lexer_conf['tag_variable']); } return static::$_parser; From 08633ef91fa522563e373f584e498bb9b27728fe Mon Sep 17 00:00:00 2001 From: Tom Schlick Date: Thu, 17 Jan 2013 00:10:21 -0500 Subject: [PATCH 038/120] Init the parser if no global data is set Without doing this the parser will not exist and will pass NULL to the Twig_Lexer which causes it to fail. --- classes/view/twig.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classes/view/twig.php b/classes/view/twig.php index 4252057..467b819 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -53,6 +53,11 @@ protected function process_file($file_override = false) static::parser()->addGlobal($key, $value); } } + else + { + // Init the parser if you have no global data + static::parser(); + } $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); static::$_parser->setLexer($twig_lexer); From bb264bd14f5dec985f13791ed21ab8732f0890f5 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 19 Jan 2013 00:41:21 +0100 Subject: [PATCH 039/120] bumped the copyright to 2013 --- bootstrap.php | 4 ++-- classes/twig/fuel/extension.php | 4 ++-- classes/view.php | 8 ++++---- classes/view/dwoo.php | 6 +++--- classes/view/haml.php | 6 +++--- classes/view/jade.php | 4 ++-- classes/view/markdown.php | 6 +++--- classes/view/mustache.php | 6 +++--- classes/view/phptal.php | 4 ++-- classes/view/smarty.php | 6 +++--- classes/view/twig.php | 4 ++-- config/parser.php | 4 ++-- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 66a5ed9..9a07674 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index b894bf9..ed199c7 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 5a82e9e..37bd24e 100644 --- a/classes/view.php +++ b/classes/view.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ @@ -61,7 +61,7 @@ public static function forge($file = null, $data = null, $auto_encode = null) $class = \Config::get('parser.extensions.'.$extension, null); } - + if ($class === null) { $class = get_called_class(); @@ -102,7 +102,7 @@ public static function forge($file = null, $data = null, $auto_encode = null) { // Set extension when given $extension and $view->extension = $extension; - + // Load the view file $view->set_filename($file); } diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 73773f5..60371b2 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ @@ -82,4 +82,4 @@ public static function parser() } } -// end of file dwoo.php \ No newline at end of file +// end of file dwoo.php diff --git a/classes/view/haml.php b/classes/view/haml.php index efd4877..34f9480 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ @@ -72,4 +72,4 @@ public function cache_init($file_path) } -/* end of file haml.php */ \ No newline at end of file +/* end of file haml.php */ diff --git a/classes/view/jade.php b/classes/view/jade.php index 77c4a79..ca54ed6 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 35a1ea3..4e56d2d 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ @@ -86,4 +86,4 @@ public static function parser() } } -// end of file mustache.php \ No newline at end of file +// end of file mustache.php diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 5d7e4e6..7abacd0 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ @@ -63,4 +63,4 @@ public static function parser() } } -// end of file mustache.php \ No newline at end of file +// end of file mustache.php diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 39725d9..8c5d954 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index b130802..a2ba35b 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 - * @author b3ha + * @version 1.5 + * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index 4252057..11b4bf5 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index c307b2e..6e24dea 100644 --- a/config/parser.php +++ b/config/parser.php @@ -3,10 +3,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.0 + * @version 1.5 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2012 Fuel Development Team + * @copyright 2010 - 2013 Fuel Development Team * @link http://fuelphp.com */ From 3cd873c28de50c64c41f869b3b76fd8e9b82da6d Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Wed, 23 Jan 2013 16:25:42 -0800 Subject: [PATCH 040/120] Use Composer for Mustache, Smarty and Twig. Remove vendor Mustache.php library. Remove autoload configuration for Mustache, Smarty and Twig. Update recommendation in README. Signed-off-by: Justin Hileman --- README.md | 17 +- config/parser.php | 5 +- vendor/Mustache/LICENSE | 22 - vendor/Mustache/Mustache.php | 861 ----------------------------------- 4 files changed, 16 insertions(+), 889 deletions(-) delete mode 100644 vendor/Mustache/LICENSE delete mode 100644 vendor/Mustache/Mustache.php diff --git a/README.md b/README.md index ab1f981..274875c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ Simply add `parser` to your config.php `always_loaded.packages` config option. ## Included Parsers -* Mustache - A lightweight, yet powerful templating library. * Markdown - A PHP version of Markdown by Michel Fortin. ## Usage @@ -39,7 +38,21 @@ View::forge('example.dwoo'); ## Installing parsers -Only Markdown and Mustache are included. While many other drivers are included, their libraries are not and are by default expected in `app/vendor/lib_name` (capitalize lib_name), you'll have to download them yourself. Don't change the casing or anything, keep it as much original as possible within the `vendor/lib_name` dir to keep updating easy (also because some come with their own autoloader). +Only Markdown is included. While many other drivers are included, their libraries are not and are by default. + +Mustache, Twig and Smarty should be installed via Composer. Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: + +```json +{ + "require": { + "mustache/mustache" : "*", + "smarty/smarty" : "*", + "twig/twig" : "*" + } +} +``` + +Other libraries are expected in `app/vendor/lib_name` (capitalize lib_name), you'll have to download them yourself. Don't change the casing or anything, keep it as much original as possible within the `vendor/lib_name` dir to keep updating easy (also because some come with their own autoloader). You can configure them to be loaded from other locations by copying the parser.php config file to your app and editing it. diff --git a/config/parser.php b/config/parser.php index 6e24dea..1697662 100644 --- a/config/parser.php +++ b/config/parser.php @@ -53,7 +53,6 @@ // TWIG ( http://www.twig-project.org/documentation ) // ------------------------------------------------------------------------ 'View_Twig' => array( - 'include' => APPPATH.'vendor'.DS.'Twig'.DS.'Autoloader.php', 'auto_encode' => true, 'views_paths' => array(APPPATH.'views'), 'delimiters' => array( @@ -102,7 +101,6 @@ // MUSTACHE ( https://github.com/bobthecow/mustache.php ) // ------------------------------------------------------------------------ 'View_Mustache' => array( - 'include' => \Package::exists('parser').'vendor'.DS.'Mustache'.DS.'Mustache.php', 'auto_encode' => true, 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( @@ -131,8 +129,7 @@ // SMARTY ( http://www.smarty.net/documentation ) // ------------------------------------------------------------------------ 'View_Smarty' => array( - 'include' => APPPATH.'vendor'.DS.'Smarty'.DS.'libs'.DS.'Smarty.class.php', - 'auto_encode' => true, + 'auto_encode' => true, 'delimiters' => array('left' => '{', 'right' => '}'), 'environment' => array( 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, diff --git a/vendor/Mustache/LICENSE b/vendor/Mustache/LICENSE deleted file mode 100644 index 9dcc497..0000000 --- a/vendor/Mustache/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2010 Justin Hileman - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/Mustache/Mustache.php b/vendor/Mustache/Mustache.php deleted file mode 100644 index 2100c2b..0000000 --- a/vendor/Mustache/Mustache.php +++ /dev/null @@ -1,861 +0,0 @@ - false, - MustacheException::UNCLOSED_SECTION => true, - MustacheException::UNEXPECTED_CLOSE_SECTION => true, - MustacheException::UNKNOWN_PARTIAL => false, - MustacheException::UNKNOWN_PRAGMA => true, - ); - - // Override charset passed to htmlentities() and htmlspecialchars(). Defaults to UTF-8. - protected $_charset = 'UTF-8'; - - /** - * Pragmas are macro-like directives that, when invoked, change the behavior or - * syntax of Mustache. - * - * They should be considered extremely experimental. Most likely their implementation - * will change in the future. - */ - - /** - * The {{%UNESCAPED}} pragma swaps the meaning of the {{normal}} and {{{unescaped}}} - * Mustache tags. That is, once this pragma is activated the {{normal}} tag will not be - * escaped while the {{{unescaped}}} tag will be escaped. - * - * Pragmas apply only to the current template. Partials, even those included after the - * {{%UNESCAPED}} call, will need their own pragma declaration. - * - * This may be useful in non-HTML Mustache situations. - */ - const PRAGMA_UNESCAPED = 'UNESCAPED'; - - /** - * Constants used for section and tag RegEx - */ - const SECTION_TYPES = '\^#\/'; - const TAG_TYPES = '#\^\/=!<>\\{&'; - - protected $_otag = '{{'; - protected $_ctag = '}}'; - - protected $_tagRegEx; - - protected $_template = ''; - protected $_context = array(); - protected $_partials = array(); - protected $_pragmas = array(); - - protected $_pragmasImplemented = array( - self::PRAGMA_UNESCAPED - ); - - protected $_localPragmas = array(); - - /** - * Mustache class constructor. - * - * This method accepts a $template string and a $view object. Optionally, pass an associative - * array of partials as well. - * - * Passing an $options array allows overriding certain Mustache options during instantiation: - * - * $options = array( - * // `charset` -- must be supported by `htmlspecialentities()`. defaults to 'UTF-8' - * 'charset' => 'ISO-8859-1', - * - * // opening and closing delimiters, as an array or a space-separated string - * 'delimiters' => '<% %>', - * - * // an array of pragmas to enable - * 'pragmas' => array( - * Mustache::PRAGMA_UNESCAPED - * ), - * ); - * - * @access public - * @param string $template (default: null) - * @param mixed $view (default: null) - * @param array $partials (default: null) - * @param array $options (default: array()) - * @return void - */ - public function __construct($template = null, $view = null, $partials = null, array $options = null) { - if ($template !== null) $this->_template = $template; - if ($partials !== null) $this->_partials = $partials; - if ($view !== null) $this->_context = array($view); - if ($options !== null) $this->_setOptions($options); - } - - /** - * Helper function for setting options from constructor args. - * - * @access protected - * @param array $options - * @return void - */ - protected function _setOptions(array $options) { - if (isset($options['charset'])) { - $this->_charset = $options['charset']; - } - - if (isset($options['delimiters'])) { - $delims = $options['delimiters']; - if (!is_array($delims)) { - $delims = array_map('trim', explode(' ', $delims, 2)); - } - $this->_otag = $delims[0]; - $this->_ctag = $delims[1]; - } - - if (isset($options['pragmas'])) { - foreach ($options['pragmas'] as $pragma_name) { - if (!in_array($pragma_name, $this->_pragmasImplemented)) { - throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA); - } - } - $this->_pragmas = $options['pragmas']; - } - } - - /** - * Mustache class clone method. - * - * A cloned Mustache instance should have pragmas, delimeters and root context - * reset to default values. - * - * @access public - * @return void - */ - public function __clone() { - $this->_otag = '{{'; - $this->_ctag = '}}'; - $this->_localPragmas = array(); - - if ($keys = array_keys($this->_context)) { - $last = array_pop($keys); - if ($this->_context[$last] instanceof Mustache) { - $this->_context[$last] =& $this; - } - } - } - - /** - * Render the given template and view object. - * - * Defaults to the template and view passed to the class constructor unless a new one is provided. - * Optionally, pass an associative array of partials as well. - * - * @access public - * @param string $template (default: null) - * @param mixed $view (default: null) - * @param array $partials (default: null) - * @return string Rendered Mustache template. - */ - public function render($template = null, $view = null, $partials = null) { - if ($template === null) $template = $this->_template; - if ($partials !== null) $this->_partials = $partials; - - $otag_orig = $this->_otag; - $ctag_orig = $this->_ctag; - - if ($view) { - $this->_context = array($view); - } else if (empty($this->_context)) { - $this->_context = array($this); - } - - $template = $this->_renderPragmas($template); - $template = $this->_renderTemplate($template, $this->_context); - - $this->_otag = $otag_orig; - $this->_ctag = $ctag_orig; - - return $template; - } - - /** - * Wrap the render() function for string conversion. - * - * @access public - * @return string - */ - public function __toString() { - // PHP doesn't like exceptions in __toString. - // catch any exceptions and convert them to strings. - try { - $result = $this->render(); - return $result; - } catch (Exception $e) { - return "Error rendering mustache: " . $e->getMessage(); - } - } - - /** - * Internal render function, used for recursive calls. - * - * @access protected - * @param string $template - * @return string Rendered Mustache template. - */ - protected function _renderTemplate($template) { - if ($section = $this->_findSection($template)) { - list($before, $type, $tag_name, $content, $after) = $section; - - $rendered_before = $this->_renderTags($before); - - $rendered_content = ''; - $val = $this->_getVariable($tag_name); - switch($type) { - // inverted section - case '^': - if (empty($val)) { - $rendered_content = $this->_renderTemplate($content); - } - break; - - // regular section - case '#': - if ($this->_varIsIterable($val)) { - foreach ($val as $local_context) { - $this->_pushContext($local_context); - $rendered_content .= $this->_renderTemplate($content); - $this->_popContext(); - } - } else if ($val) { - if (is_array($val) || is_object($val)) { - $this->_pushContext($val); - $rendered_content = $this->_renderTemplate($content); - $this->_popContext(); - } else { - $rendered_content = $this->_renderTemplate($content); - } - } - break; - } - - return $rendered_before . $rendered_content . $this->_renderTemplate($after); - } - - return $this->_renderTags($template); - } - - /** - * Prepare a section RegEx string for the given opening/closing tags. - * - * @access protected - * @param string $otag - * @param string $ctag - * @return string - */ - protected function _prepareSectionRegEx($otag, $ctag) { - return sprintf( - '/(?:(?<=\\n)[ \\t]*)?%s(?:(?P[%s])(?P.+?)|=(?P.*?)=)%s\\n?/s', - preg_quote($otag, '/'), - self::SECTION_TYPES, - preg_quote($ctag, '/') - ); - } - - /** - * Extract the first section from $template. - * - * @access protected - * @param string $template - * @return array $before, $type, $tag_name, $content and $after - */ - protected function _findSection($template) { - $regEx = $this->_prepareSectionRegEx($this->_otag, $this->_ctag); - - $section_start = null; - $section_type = null; - $content_start = null; - - $search_offset = 0; - - $section_stack = array(); - $matches = array(); - while (preg_match($regEx, $template, $matches, PREG_OFFSET_CAPTURE, $search_offset)) { - if (isset($matches['delims'][0])) { - list($otag, $ctag) = explode(' ', $matches['delims'][0]); - $regEx = $this->_prepareSectionRegEx($otag, $ctag); - $search_offset = $matches[0][1] + strlen($matches[0][0]); - continue; - } - - $match = $matches[0][0]; - $offset = $matches[0][1]; - $type = $matches['type'][0]; - $tag_name = trim($matches['tag_name'][0]); - - $search_offset = $offset + strlen($match); - - switch ($type) { - case '^': - case '#': - if (empty($section_stack)) { - $section_start = $offset; - $section_type = $type; - $content_start = $search_offset; - } - array_push($section_stack, $tag_name); - break; - case '/': - if (empty($section_stack) || ($tag_name !== array_pop($section_stack))) { - if ($this->_throwsException(MustacheException::UNEXPECTED_CLOSE_SECTION)) { - throw new MustacheException('Unexpected close section: ' . $tag_name, MustacheException::UNEXPECTED_CLOSE_SECTION); - } - } - - if (empty($section_stack)) { - // $before, $type, $tag_name, $content, $after - return array( - substr($template, 0, $section_start), - $section_type, - $tag_name, - substr($template, $content_start, $offset - $content_start), - substr($template, $search_offset), - ); - } - break; - } - } - - if (!empty($section_stack)) { - if ($this->_throwsException(MustacheException::UNCLOSED_SECTION)) { - throw new MustacheException('Unclosed section: ' . $section_stack[0], MustacheException::UNCLOSED_SECTION); - } - } - } - - /** - * Prepare a pragma RegEx for the given opening/closing tags. - * - * @access protected - * @param string $otag - * @param string $ctag - * @return string - */ - protected function _preparePragmaRegEx($otag, $ctag) { - return sprintf( - '/%s%%\\s*(?P[\\w_-]+)(?P(?: [\\w]+=[\\w]+)*)\\s*%s\\n?/s', - preg_quote($otag, '/'), - preg_quote($ctag, '/') - ); - } - - /** - * Initialize pragmas and remove all pragma tags. - * - * @access protected - * @param string $template - * @return string - */ - protected function _renderPragmas($template) { - $this->_localPragmas = $this->_pragmas; - - // no pragmas - if (strpos($template, $this->_otag . '%') === false) { - return $template; - } - - $regEx = $this->_preparePragmaRegEx($this->_otag, $this->_ctag); - return preg_replace_callback($regEx, array($this, '_renderPragma'), $template); - } - - /** - * A preg_replace helper to remove {{%PRAGMA}} tags and enable requested pragma. - * - * @access protected - * @param mixed $matches - * @return void - * @throws MustacheException unknown pragma - */ - protected function _renderPragma($matches) { - $pragma = $matches[0]; - $pragma_name = $matches['pragma_name']; - $options_string = $matches['options_string']; - - if (!in_array($pragma_name, $this->_pragmasImplemented)) { - throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA); - } - - $options = array(); - foreach (explode(' ', trim($options_string)) as $o) { - if ($p = trim($o)) { - $p = explode('=', $p); - $options[$p[0]] = $p[1]; - } - } - - if (empty($options)) { - $this->_localPragmas[$pragma_name] = true; - } else { - $this->_localPragmas[$pragma_name] = $options; - } - - return ''; - } - - /** - * Check whether this Mustache has a specific pragma. - * - * @access protected - * @param string $pragma_name - * @return bool - */ - protected function _hasPragma($pragma_name) { - if (array_key_exists($pragma_name, $this->_localPragmas) && $this->_localPragmas[$pragma_name]) { - return true; - } else { - return false; - } - } - - /** - * Return pragma options, if any. - * - * @access protected - * @param string $pragma_name - * @return mixed - * @throws MustacheException Unknown pragma - */ - protected function _getPragmaOptions($pragma_name) { - if (!$this->_hasPragma($pragma_name)) { - throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA); - } - - return (is_array($this->_localPragmas[$pragma_name])) ? $this->_localPragmas[$pragma_name] : array(); - } - - /** - * Check whether this Mustache instance throws a given exception. - * - * Expects exceptions to be MustacheException error codes (i.e. class constants). - * - * @access protected - * @param mixed $exception - * @return void - */ - protected function _throwsException($exception) { - return (isset($this->_throwsExceptions[$exception]) && $this->_throwsExceptions[$exception]); - } - - /** - * Prepare a tag RegEx for the given opening/closing tags. - * - * @access protected - * @param string $otag - * @param string $ctag - * @return string - */ - protected function _prepareTagRegEx($otag, $ctag, $first = false) { - return sprintf( - '/(?P(?:%s\\r?\\n)[ \\t]*)?%s(?P[%s]?)(?P.+?)(?:\\2|})?%s(?P\\s*(?:\\r?\\n|\\Z))?/s', - ($first ? '\\A|' : ''), - preg_quote($otag, '/'), - self::TAG_TYPES, - preg_quote($ctag, '/') - ); - } - - /** - * Loop through and render individual Mustache tags. - * - * @access protected - * @param string $template - * @return void - */ - protected function _renderTags($template) { - if (strpos($template, $this->_otag) === false) { - return $template; - } - - $first = true; - $this->_tagRegEx = $this->_prepareTagRegEx($this->_otag, $this->_ctag, true); - - $html = ''; - $matches = array(); - while (preg_match($this->_tagRegEx, $template, $matches, PREG_OFFSET_CAPTURE)) { - $tag = $matches[0][0]; - $offset = $matches[0][1]; - $modifier = $matches['type'][0]; - $tag_name = trim($matches['tag_name'][0]); - - if (isset($matches['leading']) && $matches['leading'][1] > -1) { - $leading = $matches['leading'][0]; - } else { - $leading = null; - } - - if (isset($matches['trailing']) && $matches['trailing'][1] > -1) { - $trailing = $matches['trailing'][0]; - } else { - $trailing = null; - } - - $html .= substr($template, 0, $offset); - - $next_offset = $offset + strlen($tag); - if ((substr($html, -1) == "\n") && (substr($template, $next_offset, 1) == "\n")) { - $next_offset++; - } - $template = substr($template, $next_offset); - - $html .= $this->_renderTag($modifier, $tag_name, $leading, $trailing); - - if ($first == true) { - $first = false; - $this->_tagRegEx = $this->_prepareTagRegEx($this->_otag, $this->_ctag); - } - } - - return $html . $template; - } - - /** - * Render the named tag, given the specified modifier. - * - * Accepted modifiers are `=` (change delimiter), `!` (comment), `>` (partial) - * `{` or `&` (don't escape output), or none (render escaped output). - * - * @access protected - * @param string $modifier - * @param string $tag_name - * @param string $leading Whitespace - * @param string $trailing Whitespace - * @throws MustacheException Unmatched section tag encountered. - * @return string - */ - protected function _renderTag($modifier, $tag_name, $leading, $trailing) { - switch ($modifier) { - case '=': - return $this->_changeDelimiter($tag_name, $leading, $trailing); - break; - case '!': - return $this->_renderComment($tag_name, $leading, $trailing); - break; - case '>': - case '<': - return $this->_renderPartial($tag_name, $leading, $trailing); - break; - case '{': - // strip the trailing } ... - if ($tag_name[(strlen($tag_name) - 1)] == '}') { - $tag_name = substr($tag_name, 0, -1); - } - case '&': - if ($this->_hasPragma(self::PRAGMA_UNESCAPED)) { - return $this->_renderEscaped($tag_name, $leading, $trailing); - } else { - return $this->_renderUnescaped($tag_name, $leading, $trailing); - } - break; - case '#': - case '^': - case '/': - // remove any leftover section tags - return $leading . $trailing; - break; - default: - if ($this->_hasPragma(self::PRAGMA_UNESCAPED)) { - return $this->_renderUnescaped($modifier . $tag_name, $leading, $trailing); - } else { - return $this->_renderEscaped($modifier . $tag_name, $leading, $trailing); - } - break; - } - } - - /** - * Returns true if any of its args contains the "\r" character. - * - * @access protected - * @param string $str - * @return boolean - */ - protected function _stringHasR($str) { - foreach (func_get_args() as $arg) { - if (strpos($arg, "\r") !== false) { - return true; - } - } - return false; - } - - /** - * Escape and return the requested tag. - * - * @access protected - * @param string $tag_name - * @param string $leading Whitespace - * @param string $trailing Whitespace - * @return string - */ - protected function _renderEscaped($tag_name, $leading, $trailing) { - return $leading . htmlentities($this->_getVariable($tag_name), ENT_COMPAT, $this->_charset) . $trailing; - } - - /** - * Render a comment (i.e. return an empty string). - * - * @access protected - * @param string $tag_name - * @param string $leading Whitespace - * @param string $trailing Whitespace - * @return string - */ - protected function _renderComment($tag_name, $leading, $trailing) { - if ($leading !== null && $trailing !== null) { - if (strpos($leading, "\n") === false) { - return ''; - } - return $this->_stringHasR($leading, $trailing) ? "\r\n" : "\n"; - } - return $leading . $trailing; - } - - /** - * Return the requested tag unescaped. - * - * @access protected - * @param string $tag_name - * @param string $leading Whitespace - * @param string $trailing Whitespace - * @return string - */ - protected function _renderUnescaped($tag_name, $leading, $trailing) { - return $leading . $this->_getVariable($tag_name) . $trailing; - } - - /** - * Render the requested partial. - * - * @access protected - * @param string $tag_name - * @param string $leading Whitespace - * @param string $trailing Whitespace - * @return string - */ - protected function _renderPartial($tag_name, $leading, $trailing) { - $partial = $this->_getPartial($tag_name); - if ($leading !== null && $trailing !== null) { - $whitespace = trim($leading, "\r\n"); - $partial = preg_replace('/(\\r?\\n)(?!$)/s', "\\1" . $whitespace, $partial); - } - - $view = clone($this); - - if ($leading !== null && $trailing !== null) { - return $leading . $view->render($partial); - } else { - return $leading . $view->render($partial) . $trailing; - } - } - - /** - * Change the Mustache tag delimiter. This method also replaces this object's current - * tag RegEx with one using the new delimiters. - * - * @access protected - * @param string $tag_name - * @param string $leading Whitespace - * @param string $trailing Whitespace - * @return string - */ - protected function _changeDelimiter($tag_name, $leading, $trailing) { - list($otag, $ctag) = explode(' ', $tag_name); - $this->_otag = $otag; - $this->_ctag = $ctag; - - $this->_tagRegEx = $this->_prepareTagRegEx($this->_otag, $this->_ctag); - - if ($leading !== null && $trailing !== null) { - if (strpos($leading, "\n") === false) { - return ''; - } - return $this->_stringHasR($leading, $trailing) ? "\r\n" : "\n"; - } - return $leading . $trailing; - } - - /** - * Push a local context onto the stack. - * - * @access protected - * @param array &$local_context - * @return void - */ - protected function _pushContext(&$local_context) { - $new = array(); - $new[] =& $local_context; - foreach (array_keys($this->_context) as $key) { - $new[] =& $this->_context[$key]; - } - $this->_context = $new; - } - - /** - * Remove the latest context from the stack. - * - * @access protected - * @return void - */ - protected function _popContext() { - $new = array(); - - $keys = array_keys($this->_context); - array_shift($keys); - foreach ($keys as $key) { - $new[] =& $this->_context[$key]; - } - $this->_context = $new; - } - - /** - * Get a variable from the context array. - * - * If the view is an array, returns the value with array key $tag_name. - * If the view is an object, this will check for a public member variable - * named $tag_name. If none is available, this method will execute and return - * any class method named $tag_name. Failing all of the above, this method will - * return an empty string. - * - * @access protected - * @param string $tag_name - * @throws MustacheException Unknown variable name. - * @return string - */ - protected function _getVariable($tag_name) { - if ($tag_name === '.') { - return $this->_context[0]; - } else if (strpos($tag_name, '.') !== false) { - $chunks = explode('.', $tag_name); - $first = array_shift($chunks); - - $ret = $this->_findVariableInContext($first, $this->_context); - while ($next = array_shift($chunks)) { - // Slice off a chunk of context for dot notation traversal. - $c = array($ret); - $ret = $this->_findVariableInContext($next, $c); - } - return $ret; - } else { - return $this->_findVariableInContext($tag_name, $this->_context); - } - } - - /** - * Get a variable from the context array. Internal helper used by getVariable() to abstract - * variable traversal for dot notation. - * - * @access protected - * @param string $tag_name - * @param array $context - * @throws MustacheException Unknown variable name. - * @return string - */ - protected function _findVariableInContext($tag_name, $context) { - foreach ($context as $view) { - if (is_object($view)) { - if (method_exists($view, $tag_name)) { - return $view->$tag_name(); - } else if (isset($view->$tag_name)) { - return $view->$tag_name; - } - } else if (is_array($view) && array_key_exists($tag_name, $view)) { - return $view[$tag_name]; - } - } - - if ($this->_throwsException(MustacheException::UNKNOWN_VARIABLE)) { - throw new MustacheException("Unknown variable: " . $tag_name, MustacheException::UNKNOWN_VARIABLE); - } else { - return ''; - } - } - - /** - * Retrieve the partial corresponding to the requested tag name. - * - * Silently fails (i.e. returns '') when the requested partial is not found. - * - * @access protected - * @param string $tag_name - * @throws MustacheException Unknown partial name. - * @return string - */ - protected function _getPartial($tag_name) { - if (is_array($this->_partials) && isset($this->_partials[$tag_name])) { - return $this->_partials[$tag_name]; - } - - if ($this->_throwsException(MustacheException::UNKNOWN_PARTIAL)) { - throw new MustacheException('Unknown partial: ' . $tag_name, MustacheException::UNKNOWN_PARTIAL); - } else { - return ''; - } - } - - /** - * Check whether the given $var should be iterated (i.e. in a section context). - * - * @access protected - * @param mixed $var - * @return bool - */ - protected function _varIsIterable($var) { - return $var instanceof Traversable || (is_array($var) && !array_diff_key($var, array_keys(array_keys($var)))); - } -} - - -/** - * MustacheException class. - * - * @extends Exception - */ -class MustacheException extends Exception { - - // An UNKNOWN_VARIABLE exception is thrown when a {{variable}} is not found - // in the current context. - const UNKNOWN_VARIABLE = 0; - - // An UNCLOSED_SECTION exception is thrown when a {{#section}} is not closed. - const UNCLOSED_SECTION = 1; - - // An UNEXPECTED_CLOSE_SECTION exception is thrown when {{/section}} appears - // without a corresponding {{#section}} or {{^section}}. - const UNEXPECTED_CLOSE_SECTION = 2; - - // An UNKNOWN_PARTIAL exception is thrown whenever a {{>partial}} tag appears - // with no associated partial. - const UNKNOWN_PARTIAL = 3; - - // An UNKNOWN_PRAGMA exception is thrown whenever a {{%PRAGMA}} tag appears - // which can't be handled by this Mustache instance. - const UNKNOWN_PRAGMA = 4; - -} From 54afa318f1de56b0233bdee5ba068b02eeea7db6 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Wed, 23 Jan 2013 16:26:39 -0800 Subject: [PATCH 041/120] Update View_Mustache for v2.x Yay! Signed-off-by: Justin Hileman --- classes/view/mustache.php | 20 ++++++++++++++------ config/parser.php | 7 ++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 7abacd0..34732a7 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -14,7 +14,7 @@ namespace Parser; -use Mustache; +use Mustache_Engine; class View_Mustache extends \View { @@ -42,7 +42,7 @@ protected function process_file($file_override = false) /** * Returns the Parser lib object * - * @return Mustache + * @return Mustache_Engine */ public static function parser() { @@ -52,12 +52,20 @@ public static function parser() } $options = array( - 'delimiters' => array_values(\Config::get('parser.View_Mustache.delimiters', array('{{','}}'))), - 'charset' => \Config::get('parser.View_Mustache.environment.charset', 'UTF-8'), - 'pragmas' => \Config::get('parser.View_Mustache.environment.pragmas', array()), + // TODO: set 'logger' with Monolog instance. + 'cache' => \Config::get('parser.View_Mustache.environment.cache_dir', APPPATH.'cache'.DS.'mustache'.DS), + 'charset' => \Config::get('parser.View_Mustache.environment.charset', 'UTF-8'), ); - static::$_parser = new Mustache(null, null, null, $options); + if ($partials = \Config::get('parser.View_Mustache.environment.partials', array())) { + $options['partials'] = $partials; + } + + if ($helpers = \Config::get('parser.View_Mustache.environment.helpers', array())) { + $options['helpers'] = $helpers; + } + + static::$_parser = new Mustache_Engine($options); return static::$_parser; } diff --git a/config/parser.php b/config/parser.php index 1697662..e7bed3c 100644 --- a/config/parser.php +++ b/config/parser.php @@ -102,10 +102,11 @@ // ------------------------------------------------------------------------ 'View_Mustache' => array( 'auto_encode' => true, - 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( - 'charset' => 'UTF-8', - 'pragmas' => array(), + 'cache_dir' => APPPATH.'cache'.DS.'mustache'.DS, + 'partials' => array(), + 'helpers' => array(), + 'charset' => 'UTF-8', ), ), From 865ad8558f0a608aeb6d9f7bef2c8181bcf802b1 Mon Sep 17 00:00:00 2001 From: ronan-gloo Date: Mon, 28 Jan 2013 16:52:31 +0100 Subject: [PATCH 042/120] add MtHaml Twig specific parser --- classes/view/hamltwig.php | 123 ++++++++++++++++++++++++++++++++++++++ config/parser.php | 18 ++++++ 2 files changed, 141 insertions(+) create mode 100644 classes/view/hamltwig.php diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php new file mode 100644 index 0000000..594926b --- /dev/null +++ b/classes/view/hamltwig.php @@ -0,0 +1,123 @@ +file_name; + + $local_data = $this->get_data('local'); + $global_data = $this->get_data('global'); + + // Extract View name/extension (ex. "template.twig") + $view_name = pathinfo($file, PATHINFO_BASENAME); + + // Twig Loader + $views_paths = \Config::get('parser.View_Twig.views_paths', array(APPPATH . 'views')); + array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); + + $filesyst = new Twig_Loader_Filesystem($views_paths); + + if ( ! empty($global_data)) + { + foreach ($global_data as $key => $value) + { + static::parser()->addGlobal($key, $value); + } + } + else + { + // Init the parser if you have no global data + static::parser(); + } + + static::$_parser_loader = new MtHaml\Support\Twig\Loader(static::$_environment, $filesyst); + + $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); + static::$_parser->setLexer($twig_lexer); + //\Debug::dump(static::parser()); exit(); + try + { + return static::parser()->render($view_name, $local_data); + } + catch (\Exception $e) + { + // Delete the output buffer & re-throw the exception + ob_end_clean(); + throw $e; + } + } + + /** + * @access public + * @static + * @return Twig_Environment + */ + public static function parser() + { + if (empty(static::$_parser)) + { + parent::parser(); + + // Register Haml twig supports + static::$_parser->addExtension(new MtHaml\Support\Twig\Extension()); + // Store MtHaml environment + static::$_environment = new MtHaml\Environment('twig', \Config::get('parser.View_HamlTwig.environment')); + + return static::$_parser; + } + return parent::parser(); + } +} + +// end of file hamltwig.php \ No newline at end of file diff --git a/config/parser.php b/config/parser.php index e7bed3c..5a9dc0e 100644 --- a/config/parser.php +++ b/config/parser.php @@ -27,6 +27,7 @@ 'extensions' => array( 'php' => 'View', 'twig' => 'View_Twig', + 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'twig'), 'mustache' => 'View_Mustache', 'md' => 'View_Markdown', 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), @@ -74,6 +75,23 @@ 'Twig_Fuel_Extension' ), ), + + // HamlTwig with MtHaml https://github.com/arnaud-lb/MtHaml + // Twig configuration is grabbed from 'View_Twig' config key + // Packagist url: https://packagist.org/packages/mthaml/mthaml + // Uses > 1.1.1 (Master branch ATM) + // ------------------------------------------------------------------------ + 'View_HamlTwig' => array( + //'include' => APPPATH.'vendor'.DS.'MtHaml'.DS.'Autoloader.php', + 'auto_encode' => true, + 'environment' => array( + 'auto_escaper' => true, + 'escape_html' => true, + 'escape_attrs' => true, + 'charset' => 'UTF-8', + 'format' => 'html5', + ), + ), // DWOO ( http://wiki.dwoo.org/ ) // ------------------------------------------------------------------------ From 73602d09e38bbbc92936ad98903292912c6ada19 Mon Sep 17 00:00:00 2001 From: ronan-gloo Date: Mon, 28 Jan 2013 17:04:38 +0100 Subject: [PATCH 043/120] add hamltwig to bootstrap --- bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bootstrap.php b/bootstrap.php index 9a07674..d9c40c2 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -21,6 +21,7 @@ 'Parser\\View_Markdown' => __DIR__.'/classes/view/markdown.php', 'Parser\\View_SimpleTags' => __DIR__.'/classes/view/simpletags.php', 'Parser\\View_Twig' => __DIR__.'/classes/view/twig.php', + 'Parser\\View_HamlTwig' => __DIR__.'/classes/view/hamltwig.php', 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', From 292a0ba7f32b3fac873076dde721431788c55e5b Mon Sep 17 00:00:00 2001 From: ronan-gloo Date: Mon, 28 Jan 2013 17:44:10 +0100 Subject: [PATCH 044/120] Add mthaml/mthaml to the composer list --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 274875c..d461c37 100644 --- a/README.md +++ b/README.md @@ -40,14 +40,15 @@ View::forge('example.dwoo'); Only Markdown is included. While many other drivers are included, their libraries are not and are by default. -Mustache, Twig and Smarty should be installed via Composer. Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: +Mustache, Twig, MtHaml and Smarty should be installed via Composer. Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: ```json { "require": { "mustache/mustache" : "*", "smarty/smarty" : "*", - "twig/twig" : "*" + "twig/twig" : "*", + "mthaml/mthaml": "*" } } ``` From 6135fd8d1fb2ddae79b86c0d21f009d3961b4649 Mon Sep 17 00:00:00 2001 From: ronan-gloo Date: Mon, 28 Jan 2013 17:55:31 +0100 Subject: [PATCH 045/120] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d461c37..b6fd316 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ View::forge('example.mustache'); // load a Twig template, will load and parse app/views/example.twig View::forge('example.twig'); +// load a Hybrid Haml / Twig template, ATTENTION: this one expects app/views/example.twig and {% haml %} code at the top of the view +View::forge('example.mthaml'); + // load a Jade template, will load and parse app/views/example.jade View::forge('example.jade'); From 2ea6c7c8af407a9f66d9eb92effd89c57276b9e9 Mon Sep 17 00:00:00 2001 From: ronan-gloo Date: Mon, 28 Jan 2013 17:57:29 +0100 Subject: [PATCH 046/120] little cosmetic change under process_file() method --- classes/view/hamltwig.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 594926b..1740c85 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -65,9 +65,7 @@ protected function process_file($file_override = false) // Twig Loader $views_paths = \Config::get('parser.View_Twig.views_paths', array(APPPATH . 'views')); array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); - - $filesyst = new Twig_Loader_Filesystem($views_paths); - + if ( ! empty($global_data)) { foreach ($global_data as $key => $value) @@ -81,6 +79,8 @@ protected function process_file($file_override = false) static::parser(); } + // Set the HtHaml Twig loader + $filesyst = new Twig_Loader_Filesystem($views_paths); static::$_parser_loader = new MtHaml\Support\Twig\Loader(static::$_environment, $filesyst); $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); @@ -120,4 +120,4 @@ public static function parser() } } -// end of file hamltwig.php \ No newline at end of file +// end of file hamltwig.php From a2be4b58a0a9211972629d56ad6693c809822d35 Mon Sep 17 00:00:00 2001 From: ibookpro Date: Tue, 26 Mar 2013 21:56:51 +0900 Subject: [PATCH 047/120] upgrade markdown. 1.2.5->1.2.6 --- vendor/markdown/markdown.php | 785 ++++++++++++++++++++--------------- 1 file changed, 452 insertions(+), 333 deletions(-) diff --git a/vendor/markdown/markdown.php b/vendor/markdown/markdown.php index 7f4ae23..2e0ae85 100755 --- a/vendor/markdown/markdown.php +++ b/vendor/markdown/markdown.php @@ -2,18 +2,18 @@ # # Markdown Extra - A text-to-HTML conversion tool for web writers # -# PHP Markdown & Extra -# Copyright (c) 2004-2012 Michel Fortin -# +# PHP Markdown & Extra +# Copyright (c) 2004-2013 Michel Fortin +# # -# Original Markdown -# Copyright (c) 2004-2006 John Gruber +# Original Markdown +# Copyright (c) 2004-2006 John Gruber # # -define( 'MARKDOWN_VERSION', "1.0.1o" ); # Sun 8 Jan 2012 -define( 'MARKDOWNEXTRA_VERSION', "1.2.5" ); # Sun 8 Jan 2012 +define( 'MARKDOWN_VERSION', "1.0.1p" ); # Sun 13 Jan 2013 +define( 'MARKDOWNEXTRA_VERSION', "1.2.6" ); # Sun 13 Jan 2013 # @@ -34,6 +34,13 @@ @define( 'MARKDOWN_FN_LINK_CLASS', "" ); @define( 'MARKDOWN_FN_BACKLINK_CLASS', "" ); +# Optional class prefix for fenced code block. +@define( 'MARKDOWN_CODE_CLASS_PREFIX', "" ); + +# Class attribute for code blocks goes on the `code` tag; +# setting this to true will put attributes on the `pre` tag instead. +@define( 'MARKDOWN_CODE_ATTR_ON_PRE', false ); + # # WordPress settings: @@ -69,17 +76,18 @@ function Markdown($text) { /* Plugin Name: Markdown Extra -Plugin URI: http://michelf.com/projects/php-markdown/ -Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... -Version: 1.2.5 +Plugin Name: Markdown +Plugin URI: http://michelf.ca/projects/php-markdown/ +Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... +Version: 1.2.6 Author: Michel Fortin -Author URI: http://michelf.com/ +Author URI: http://michelf.ca/ */ if (isset($wp_version)) { # More details about how it works here: - # - + # + # Post content and excerpts # - Remove WordPress paragraph generator. # - Run Markdown on excerpt, then remove all tags. @@ -94,13 +102,13 @@ function Markdown($text) { add_filter('get_the_excerpt', 'trim', 7); add_filter('the_excerpt', 'mdwp_add_p'); add_filter('the_excerpt_rss', 'mdwp_strip_p'); - + remove_filter('content_save_pre', 'balanceTags', 50); remove_filter('excerpt_save_pre', 'balanceTags', 50); add_filter('the_content', 'balanceTags', 50); add_filter('get_the_excerpt', 'balanceTags', 9); } - + # Add a footnote id prefix to posts when inside a loop. function mdwp_MarkdownPost($text) { static $parser; @@ -115,7 +123,7 @@ function mdwp_MarkdownPost($text) { } return $parser->transform($text); } - + # Comments # - Remove WordPress paragraph generator. # - Remove WordPress auto-link generator. @@ -130,7 +138,7 @@ function mdwp_MarkdownPost($text) { add_filter('get_comment_text', 'Markdown', 6); add_filter('get_comment_excerpt', 'Markdown', 6); add_filter('get_comment_excerpt', 'mdwp_strip_p', 7); - + global $mdwp_hidden_tags, $mdwp_placeholders; $mdwp_hidden_tags = explode(' ', '

     
  • '); @@ -138,7 +146,7 @@ function mdwp_MarkdownPost($text) { 'pEj07ZbbBZ U1kqgh4w4p pre2zmeN6K QTi31t9pre ol0MP1jzJR '. 'ML5IjmbRol ulANi1NsGY J7zRLJqPul liA8ctl16T K9nhooUHli')); } - + function mdwp_add_p($text) { if (!preg_match('{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $text)) { $text = '

    '.$text.'

    '; @@ -146,7 +154,7 @@ function mdwp_add_p($text) { } return $text; } - + function mdwp_strip_p($t) { return preg_replace('{}i', '', $t); } function mdwp_hide_tags($text) { @@ -171,7 +179,7 @@ function identify_modifier_markdown() { 'authors' => 'Michel Fortin and John Gruber', 'licence' => 'GPL', 'version' => MARKDOWNEXTRA_VERSION, - 'help' => 'Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More...', + 'help' => 'Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More...', ); } @@ -214,48 +222,53 @@ function blockLite($text) { return $text; } class Markdown_Parser { - # Regex to match balanced [brackets]. - # Needed to insert a maximum bracked depth while converting to PHP. - var $nested_brackets_depth = 6; - var $nested_brackets_re; - - var $nested_url_parenthesis_depth = 4; - var $nested_url_parenthesis_re; - - # Table of hash values for escaped characters: - var $escape_chars = '\`*_{}[]()>#+-.!'; - var $escape_chars_re; + ### Configuration Variables ### # Change to ">" for HTML output. var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX; var $tab_width = MARKDOWN_TAB_WIDTH; - + # Change to `true` to disallow markup or entities. var $no_markup = false; var $no_entities = false; - + # Predefined urls and titles for reference links and images. var $predef_urls = array(); var $predef_titles = array(); + ### Parser Implementation ### + + # Regex to match balanced [brackets]. + # Needed to insert a maximum bracked depth while converting to PHP. + var $nested_brackets_depth = 6; + var $nested_brackets_re; + + var $nested_url_parenthesis_depth = 4; + var $nested_url_parenthesis_re; + + # Table of hash values for escaped characters: + var $escape_chars = '\`*_{}[]()>#+-.!'; + var $escape_chars_re; + + function Markdown_Parser() { # # Constructor function. Initialize appropriate member variables. # $this->_initDetab(); $this->prepareItalicsAndBold(); - - $this->nested_brackets_re = + + $this->nested_brackets_re = str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). str_repeat('\])*', $this->nested_brackets_depth); - - $this->nested_url_parenthesis_re = + + $this->nested_url_parenthesis_re = str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); - + $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; - + # Sort document, block, and span gamut in ascendent priority order. asort($this->document_gamut); asort($this->block_gamut); @@ -267,27 +280,27 @@ function Markdown_Parser() { var $urls = array(); var $titles = array(); var $html_hashes = array(); - + # Status flag to avoid invalid nesting. var $in_anchor = false; - - + + function setup() { # - # Called before the transformation process starts to setup parser + # Called before the transformation process starts to setup parser # states. # # Clear global hashes. $this->urls = $this->predef_urls; $this->titles = $this->predef_titles; $this->html_hashes = array(); - + $in_anchor = false; } - + function teardown() { # - # Called after the transformation process to clear any variable + # Called after the transformation process to clear any variable # which may be taking up memory unnecessarly. # $this->urls = array(); @@ -302,7 +315,7 @@ function transform($text) { # and pass it through the document gamut. # $this->setup(); - + # Remove UTF-8 BOM and marker character in input, if present. $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); @@ -329,16 +342,16 @@ function transform($text) { foreach ($this->document_gamut as $method => $priority) { $text = $this->$method($text); } - + $this->teardown(); return $text . "\n"; } - + var $document_gamut = array( # Strip link definitions, store in hashes. "stripLinkDefinitions" => 20, - + "runBasicBlockGamut" => 30, ); @@ -399,14 +412,16 @@ function hashHTMLBlocks($text) { # hard-coded: # # * List "a" is made of tags which can be both inline or block-level. - # These will be treated block-level when the start tag is alone on - # its line, otherwise they're not matched here and will be taken as + # These will be treated block-level when the start tag is alone on + # its line, otherwise they're not matched here and will be taken as # inline later. # * List "b" is made of tags which are always block-level; # $block_tags_a_re = 'ins|del'; $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. - 'script|noscript|form|fieldset|iframe|math'; + 'script|noscript|form|fieldset|iframe|math|svg|'. + 'article|section|nav|aside|hgroup|header|footer|'. + 'figure'; # Regular expression for the content of a block tag. $nested_tags_level = 4; @@ -422,7 +437,7 @@ function hashHTMLBlocks($text) { | \'[^\']*\' # text inside single quotes (tolerate ">") )* - )? + )? '; $content = str_repeat(' @@ -439,7 +454,7 @@ function hashHTMLBlocks($text) { str_repeat(' # closing nested tag ) - | + | <(?!/\2\s*> # other tags with a different name ) )*', @@ -465,9 +480,9 @@ function hashHTMLBlocks($text) { ) ( # save in $1 - # Match from `\n` to `\n`, handling nested tags + # Match from `\n` to `\n`, handling nested tags # in between. - + [ ]{0,'.$less_than_tab.'} <('.$block_tags_b_re.')# start tag = $2 '.$attr.'> # attributes followed by > and \n @@ -485,28 +500,28 @@ function hashHTMLBlocks($text) { # the matching end tag [ ]* # trailing spaces/tabs (?=\n+|\Z) # followed by a newline or end of document - - | # Special case just for
    . It was easier to make a special + + | # Special case just for
    . It was easier to make a special # case than to make the other regex more complicated. - + [ ]{0,'.$less_than_tab.'} <(hr) # start tag = $2 '.$attr.' # attributes /?> # the matching end tag [ ]* (?=\n{2,}|\Z) # followed by a blank line or end of document - + | # Special case for standalone HTML comments: - + [ ]{0,'.$less_than_tab.'} (?s: ) [ ]* (?=\n{2,}|\Z) # followed by a blank line or end of document - + | # PHP and ASP-style processor instructions (hashBlock($text); return "\n\n$key\n\n"; } - - + + function hashPart($text, $boundary = 'X') { # - # Called whenever a tag must be hashed when a function insert an atomic + # Called whenever a tag must be hashed when a function insert an atomic # element in the text stream. Passing $text to through this function gives # a unique text-token which will be reverted back when calling unhash. # @@ -544,7 +559,7 @@ function hashPart($text, $boundary = 'X') { # Swap back any tag hash found in $text so we do not have to `unhash` # multiple times at the end. $text = $this->unhash($text); - + # Then hash the block. static $i = 0; $key = "$boundary\x1A" . ++$i . $boundary; @@ -568,7 +583,7 @@ function hashBlock($text) { # "doHeaders" => 10, "doHorizontalRules" => 20, - + "doLists" => 40, "doCodeBlocks" => 50, "doBlockQuotes" => 60, @@ -578,33 +593,33 @@ function runBlockGamut($text) { # # Run block gamut tranformations. # - # We need to escape raw HTML in Markdown source before doing anything - # else. This need to be done for each block, and not only at the + # We need to escape raw HTML in Markdown source before doing anything + # else. This need to be done for each block, and not only at the # begining in the Markdown function since hashed blocks can be part of - # list items and could have been indented. Indented blocks would have + # list items and could have been indented. Indented blocks would have # been seen as a code block in a previous pass of hashHTMLBlocks. $text = $this->hashHTMLBlocks($text); - + return $this->runBasicBlockGamut($text); } - + function runBasicBlockGamut($text) { # - # Run block gamut tranformations, without hashing HTML blocks. This is + # Run block gamut tranformations, without hashing HTML blocks. This is # useful when HTML blocks are known to be already hashed, like in the first # whole-document pass. # foreach ($this->block_gamut as $method => $priority) { $text = $this->$method($text); } - + # Finally form paragraph and restore hashed blocks. $text = $this->formParagraphs($text); return $text; } - - + + function doHorizontalRules($text) { # Do Horizontal Rules: return preg_replace( @@ -618,7 +633,7 @@ function doHorizontalRules($text) { [ ]* # Tailing spaces $ # End of line. }mx', - "\n".$this->hashBlock("empty_element_suffix")."\n", + "\n".$this->hashBlock("empty_element_suffix")."\n", $text); } @@ -636,7 +651,7 @@ function doHorizontalRules($text) { # because ![foo][f] looks like an anchor. "doImages" => 10, "doAnchors" => 20, - + # Make links out of things like `` # Must come after doAnchors, because you can use < and > # delimiters in inline links like [this](). @@ -657,11 +672,11 @@ function runSpanGamut($text) { return $text; } - - + + function doHardBreaks($text) { # Do hard breaks: - return preg_replace_callback('/ {2,}\n/', + return preg_replace_callback('/ {2,}\n/', array(&$this, '_doHardBreaks_callback'), $text); } function _doHardBreaks_callback($matches) { @@ -675,7 +690,7 @@ function doAnchors($text) { # if ($this->in_anchor) return $text; $this->in_anchor = true; - + # # First, handle reference-style links: [link text] [id] # @@ -748,7 +763,7 @@ function _doAnchors_reference_callback($matches) { # for shortcut links like [this][] or [this]. $link_id = $link_text; } - + # lower-case and turn embedded newlines into spaces $link_id = strtolower($link_id); $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); @@ -756,14 +771,14 @@ function _doAnchors_reference_callback($matches) { if (isset($this->urls[$link_id])) { $url = $this->urls[$link_id]; $url = $this->encodeAttribute($url); - + $result = "titles[$link_id] ) ) { $title = $this->titles[$link_id]; $title = $this->encodeAttribute($title); $result .= " title=\"$title\""; } - + $link_text = $this->runSpanGamut($link_text); $result .= ">$link_text"; $result = $this->hashPart($result); @@ -786,7 +801,7 @@ function _doAnchors_inline_callback($matches) { $title = $this->encodeAttribute($title); $result .= " title=\"$title\""; } - + $link_text = $this->runSpanGamut($link_text); $result .= ">$link_text"; @@ -815,7 +830,7 @@ function doImages($text) { \] ) - }xs', + }xs', array(&$this, '_doImages_reference_callback'), $text); # @@ -900,7 +915,7 @@ function doHeaders($text) { # Setext-style headers: # Header 1 # ======== - # + # # Header 2 # -------- # @@ -930,7 +945,7 @@ function _doHeaders_callback_setext($matches) { # Terrible hack to check we haven't found an empty list item. if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) return $matches[0]; - + $level = $matches[2]{0} == '=' ? 1 : 2; $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; @@ -986,10 +1001,10 @@ function doLists($text) { ) ) '; // mx - + # We use a different prefix before nested lists than top-level lists. # See extended comment in _ProcessListItems(). - + if ($this->list_level) { $text = preg_replace_callback('{ ^ @@ -1013,15 +1028,15 @@ function _doLists_callback($matches) { $marker_ul_re = '[*+-]'; $marker_ol_re = '\d+[\.]'; $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - + $list = $matches[1]; $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; - + $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); - + $list .= "\n"; $result = $this->processListItems($list, $marker_any_re); - + $result = $this->hashBlock("<$list_type>\n" . $result . ""); return "\n". $result ."\n\n"; } @@ -1053,7 +1068,7 @@ function processListItems($list_str, $marker_any_re) { # without resorting to mind-reading. Perhaps the solution is to # change the syntax rules such that sub-lists must start with a # starting cardinal number; e.g. "1." or "a.". - + $this->list_level++; # trim trailing blank lines: @@ -1081,7 +1096,7 @@ function _processListItems_callback($matches) { $marker_space = $matches[3]; $tailing_blank_line =& $matches[5]; - if ($leading_line || $tailing_blank_line || + if ($leading_line || $tailing_blank_line || preg_match('/\n{2,}/', $item)) { # Replace marker with the appropriate whitespace indentation @@ -1156,7 +1171,7 @@ function makeCodeSpan($code) { '___' => '(?<=\S|^)(?em_strong_prepared_relist["$em$strong"] = $token_re; } } } - + function doItalicsAndBold($text) { $token_stack = array(''); $text_stack = array(''); $em = ''; $strong = ''; $tree_char_em = false; - + while (1) { # # Get prepared regular expression for seraching emphasis tokens # in current context. # $token_re = $this->em_strong_prepared_relist["$em$strong"]; - + # - # Each loop iteration search for the next emphasis token. + # Each loop iteration search for the next emphasis token. # Each token is then passed to handleSpanToken. # $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); $text_stack[0] .= $parts[0]; $token =& $parts[1]; $text =& $parts[2]; - + if (empty($token)) { # Reached end of text span: empty stack without emitting. # any more emphasis. @@ -1211,7 +1226,7 @@ function doItalicsAndBold($text) { } break; } - + $token_len = strlen($token); if ($tree_char_em) { # Reached closing marker while inside a three-char emphasis. @@ -1250,7 +1265,7 @@ function doItalicsAndBold($text) { $$tag = ''; # $$tag stands for $em or $strong } } else { - # Reached opening three-char emphasis marker. Push on token + # Reached opening three-char emphasis marker. Push on token # stack; will be handled by the special condition above. $em = $token{0}; $strong = "$em$em"; @@ -1324,9 +1339,9 @@ function _doBlockQuotes_callback($matches) { $bq = $this->runBlockGamut($bq); # recurse $bq = preg_replace('/^/m', " ", $bq); - # These leading spaces cause problem with
     content,
    +		# These leading spaces cause problem with 
     content, 
     		# so we need to fix that:
    -		$bq = preg_replace_callback('{(\s*
    .+?
    )}sx', + $bq = preg_replace_callback('{(\s*
    .+?
    )}sx', array(&$this, '_doBlockQuotes_callback2'), $bq); return "\n". $this->hashBlock("
    \n$bq\n
    ")."\n\n"; @@ -1389,7 +1404,7 @@ function formParagraphs($text) { // # We can't call Markdown(), because that resets the hash; // # that initialization code should be pulled into its own sub, though. // $div_content = $this->hashHTMLBlocks($div_content); -// +// // # Run document gamut methods on the content. // foreach ($this->document_gamut as $method => $priority) { // $div_content = $this->$method($div_content); @@ -1417,11 +1432,11 @@ function encodeAttribute($text) { $text = str_replace('"', '"', $text); return $text; } - - + + function encodeAmpsAndAngles($text) { # - # Smart processing for ampersands and angle brackets that need to + # Smart processing for ampersands and angle brackets that need to # be encoded. Valid character entities are left alone unless the # no-entities mode is set. # @@ -1430,7 +1445,7 @@ function encodeAmpsAndAngles($text) { } else { # Ampersand-encoding based entirely on Nat Irons's Amputator # MT plugin: - $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', + $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', '&', $text);; } # Encode remaining <'s @@ -1441,7 +1456,7 @@ function encodeAmpsAndAngles($text) { function doAutoLinks($text) { - $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', + $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', array(&$this, '_doAutoLinks_url_callback'), $text); # Email addresses: @@ -1498,7 +1513,7 @@ function encodeEmailAddress($addr) { $addr = "mailto:" . $addr; $chars = preg_split('/(? $char) { $ord = ord($char); # Ignore non-ascii chars. @@ -1511,7 +1526,7 @@ function encodeEmailAddress($addr) { else $chars[$key] = '&#'.$ord.';'; } } - + $addr = implode('', $chars); $text = implode('', array_slice($chars, 7)); # text without `mailto:` $addr = "$text"; @@ -1526,7 +1541,7 @@ function parseSpan($str) { # escaped characters and handling code spans. # $output = ''; - + $span_re = '{ ( \\\\'.$this->escape_chars_re.' @@ -1539,29 +1554,33 @@ function parseSpan($str) { | <\?.*?\?> | <%.*?%> # processing instruction | - <[/!$]?[-a-zA-Z0-9:_]+ # regular tags + <[!$]?[-a-zA-Z0-9:_]+ # regular tags (?> \s (?>[^"\'>]+|"[^"]*"|\'[^\']*\')* )? > + | + <[-a-zA-Z0-9:_]+\s*/> # xml-style empty tag + | + # closing tag ').' ) }xs'; while (1) { # - # Each loop iteration seach for either the next tag, the next - # openning code span marker, or the next escaped character. + # Each loop iteration seach for either the next tag, the next + # openning code span marker, or the next escaped character. # Each token is then passed to handleSpanToken. # $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); - + # Create token from text preceding tag. if ($parts[0] != "") { $output .= $parts[0]; } - + # Check if we reach the end. if (isset($parts[1])) { $output .= $this->handleSpanToken($parts[1], $parts[2]); @@ -1571,14 +1590,14 @@ function parseSpan($str) { break; } } - + return $output; } - - + + function handleSpanToken($token, &$str) { # - # Handle $token provided by parseSpan by determining its nature and + # Handle $token provided by parseSpan by determining its nature and # returning the corresponding value that should replace it. # switch ($token{0}) { @@ -1586,7 +1605,7 @@ function handleSpanToken($token, &$str) { return $this->hashPart("&#". ord($token{1}). ";"); case "`": # Search for end marker in remaining text. - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', + if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', $str, $matches)) { $str = $matches[2]; @@ -1608,18 +1627,18 @@ function outdent($text) { } - # String length function for detab. `_initDetab` will create a function to + # String length function for detab. `_initDetab` will create a function to # hanlde UTF-8 if the default function does not exist. var $utf8_strlen = 'mb_strlen'; - + function detab($text) { # # Replace tabs with the appropriate amount of space. # # For each line we separate the line in blocks delemited by - # tab characters. Then we reconstruct every line by adding the + # tab characters. Then we reconstruct every line by adding the # appropriate number of space between each blocks. - + $text = preg_replace_callback('/^.*\t.*$/m', array(&$this, '_detab_callback'), $text); @@ -1628,7 +1647,7 @@ function detab($text) { function _detab_callback($matches) { $line = $matches[0]; $strlen = $this->utf8_strlen; # strlen function for UTF-8. - + # Split in blocks. $blocks = explode("\t", $line); # Add each blocks to the line. @@ -1636,7 +1655,7 @@ function _detab_callback($matches) { unset($blocks[0]); # Do not add first block twice. foreach ($blocks as $block) { # Calculate amount of space, insert spaces, insert block. - $amount = $this->tab_width - + $amount = $this->tab_width - $strlen($line, 'UTF-8') % $this->tab_width; $line .= str_repeat(" ", $amount) . $block; } @@ -1645,13 +1664,13 @@ function _detab_callback($matches) { function _initDetab() { # # Check for the availability of the function in the `utf8_strlen` property - # (initially `mb_strlen`). If the function is not available, create a + # (initially `mb_strlen`). If the function is not available, create a # function that will loosely count the number of UTF-8 characters with a # regular expression. # if (function_exists($this->utf8_strlen)) return; $this->utf8_strlen = create_function('$text', 'return preg_match_all( - "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", + "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", $text, $m);'); } @@ -1660,7 +1679,7 @@ function unhash($text) { # # Swap back in all the tags hashed by _HashHTMLBlocks. # - return preg_replace_callback('/(.)\x1A[0-9]+\1/', + return preg_replace_callback('/(.)\x1A[0-9]+\1/', array(&$this, '_unhash_callback'), $text); } function _unhash_callback($matches) { @@ -1676,30 +1695,40 @@ function _unhash_callback($matches) { class MarkdownExtra_Parser extends Markdown_Parser { + ### Configuration Variables ### + # Prefix for footnote ids. var $fn_id_prefix = ""; - + # Optional title attribute for footnote links and backlinks. var $fn_link_title = MARKDOWN_FN_LINK_TITLE; var $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE; - + # Optional class attribute for footnote links and backlinks. var $fn_link_class = MARKDOWN_FN_LINK_CLASS; var $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS; + # Optional class prefix for fenced code block. + var $code_class_prefix = MARKDOWN_CODE_CLASS_PREFIX; + # Class attribute for code blocks goes on the `code` tag; + # setting this to true will put attributes on the `pre` tag instead. + var $code_attr_on_pre = MARKDOWN_CODE_ATTR_ON_PRE; + # Predefined abbreviations. var $predef_abbr = array(); + ### Parser Implementation ### + function MarkdownExtra_Parser() { # # Constructor function. Initialize the parser object. # - # Add extra escapable characters before parent constructor + # Add extra escapable characters before parent constructor # initialize the table. $this->escape_chars .= ':|'; - - # Insert extra document, block, and span transformations. + + # Insert extra document, block, and span transformations. # Parent constructor will do the sorting. $this->document_gamut += array( "doFencedCodeBlocks" => 5, @@ -1716,33 +1745,37 @@ function MarkdownExtra_Parser() { "doFootnotes" => 5, "doAbbreviations" => 70, ); - + parent::Markdown_Parser(); } - - + + # Extra variables used during extra transformations. var $footnotes = array(); var $footnotes_ordered = array(); + var $footnotes_ref_count = array(); + var $footnotes_numbers = array(); var $abbr_desciptions = array(); var $abbr_word_re = ''; - + # Give the current footnote number. var $footnote_counter = 1; - - + + function setup() { # # Setting up Extra-specific variables. # parent::setup(); - + $this->footnotes = array(); $this->footnotes_ordered = array(); + $this->footnotes_ref_count = array(); + $this->footnotes_numbers = array(); $this->abbr_desciptions = array(); $this->abbr_word_re = ''; $this->footnote_counter = 1; - + foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { if ($this->abbr_word_re) $this->abbr_word_re .= '|'; @@ -1750,38 +1783,83 @@ function setup() { $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); } } - + function teardown() { # # Clearing Extra-specific variables. # $this->footnotes = array(); $this->footnotes_ordered = array(); + $this->footnotes_ref_count = array(); + $this->footnotes_numbers = array(); $this->abbr_desciptions = array(); $this->abbr_word_re = ''; - + parent::teardown(); } + + + ### Extra Attribute Parser ### + # Expression to use to catch attributes (includes the braces) + var $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; + # Expression to use when parsing in a context when no capture is desired + var $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; - ### HTML Block Parser ### + function doExtraAttributes($tag_name, $attr) { + # + # Parse attributes caught by the $this->id_class_attr_catch_re expression + # and return the HTML-formatted list of attributes. + # + # Currently supported attributes are .class and #id. + # + if (empty($attr)) return ""; + + # Split on components + preg_match_all("/[.#][-_:a-zA-Z0-9]+/", $attr, $matches); + $elements = $matches[0]; - # Tags that are always treated as block tags: - var $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend'; + # handle classes and ids (only first id taken into account) + $classes = array(); + $id = false; + foreach ($elements as $element) { + if ($element{0} == '.') { + $classes[] = substr($element, 1); + } else if ($element{0} == '#') { + if ($id === false) $id = substr($element, 1); + } + } + + # compose attributes as string + $attr_str = ""; + if (!empty($id)) { + $attr_str .= ' id="'.$id.'"'; + } + if (!empty($classes)) { + $attr_str .= ' class="'.implode(" ", $classes).'"'; + } + return $attr_str; + } - # Tags treated as block tags only if the opening tag is alone on it's line: - var $context_block_tags_re = 'script|noscript|math|ins|del'; + ### HTML Block Parser ### + + # Tags that are always treated as block tags: + var $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption'; + + # Tags treated as block tags only if the opening tag is alone on its line: + var $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; + # Tags where markdown="1" default to span mode: var $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; - - # Tags which must not have their contents modified, no matter where + + # Tags which must not have their contents modified, no matter where # they appear: - var $clean_tags_re = 'script|math'; - + var $clean_tags_re = 'script|math|svg'; + # Tags that do not need to be closed. - var $auto_close_tags_re = 'hr|img'; - + var $auto_close_tags_re = 'hr|img|param|source|track'; + function hashHTMLBlocks($text) { # @@ -1794,26 +1872,28 @@ function hashHTMLBlocks($text) { # hard-coded. # # This works by calling _HashHTMLBlocks_InMarkdown, which then calls - # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" - # attribute is found whitin a tag, _HashHTMLBlocks_InHTML calls back + # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" + # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. # These two functions are calling each other. It's recursive! # + if ($this->no_markup) return $text; + # # Call the HTML-in-Markdown hasher. # list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); - + return $text; } - function _hashHTMLBlocks_inMarkdown($text, $indent = 0, + function _hashHTMLBlocks_inMarkdown($text, $indent = 0, $enclosing_tag_re = '', $span = false) { # # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. # - # * $indent is the number of space to be ignored when checking for code - # blocks. This is important because if we don't take the indent into + # * $indent is the number of space to be ignored when checking for code + # blocks. This is important because if we don't take the indent into # account, something like this (which looks right) won't work as expected: # #
    @@ -1825,11 +1905,11 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # If you don't like this, just don't indent the tag on which # you apply the markdown="1" attribute. # - # * If $enclosing_tag_re is not empty, stops at the first unmatched closing + # * If $enclosing_tag_re is not empty, stops at the first unmatched closing # tag with that name. Nested tags supported. # - # * If $span is true, text inside must treated as span. So any double - # newline will be replaced by a single newline so that it does not create + # * If $span is true, text inside must treated as span. So any double + # newline will be replaced by a single newline so that it does not create # paragraphs. # # Returns an array of that form: ( processed text , remaining text ) @@ -1838,17 +1918,17 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # Regex to check for the presense of newlines around a block tag. $newline_before_re = '/(?:^\n?|\n\n)*$/'; - $newline_after_re = + $newline_after_re = '{ ^ # Start of text following the tag. (?>[ ]*)? # Optional comment. [ ]*\n # Must be followed by newline. }xs'; - + # Regex to match any tag. $block_tag_re = '{ - ( # $2: Capture hole tag. + ( # $2: Capture whole tag. # Tag name. '.$this->block_tags_re.' | @@ -1884,13 +1964,21 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, )* | # Fenced code block marker - (?> ^ | \n ) - [ ]{0,'.($indent).'}~~~+[ ]*\n + (?<= ^ | \n ) + [ ]{0,'.($indent+3).'}~{3,} + [ ]* + (?: + [.]?[-_:a-zA-Z0-9]+ # standalone class name + | + '.$this->id_class_attr_nocatch_re.' # extra attributes + )? + [ ]* + \n ' : '' ). ' # End (if not is span). ) }xs'; - + $depth = 0; # Current depth inside the tag tree. $parsed = ""; # Parsed text that will be returned. @@ -1902,32 +1990,32 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # # Split the text using the first $tag_match pattern found. # Text before pattern will be first in the array, text after - # pattern will be at the end, and between will be any catches made + # pattern will be at the end, and between will be any catches made # by the pattern. # - $parts = preg_split($block_tag_re, $text, 2, + $parts = preg_split($block_tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); - - # If in Markdown span mode, add a empty-string span-level hash + + # If in Markdown span mode, add a empty-string span-level hash # after each newline to prevent triggering any block element. if ($span) { $void = $this->hashPart("", ':'); $newline = "$void\n"; $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; } - + $parsed .= $parts[0]; # Text before current tag. - + # If end of $text has been reached. Stop loop. if (count($parts) < 3) { $text = ""; break; } - + $tag = $parts[1]; # Tag to handle. $text = $parts[2]; # Remaining text after current tag. $tag_re = preg_quote($tag); # For use in a regular expression. - + # # Check for: Code span marker # @@ -1949,11 +2037,12 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # # Check for: Fenced code block marker. # - else if (preg_match('{^\n?[ ]{0,'.($indent+3).'}~}', $tag)) { + else if (preg_match('{^\n?([ ]{0,'.($indent+3).'})(~+)}', $tag, $capture)) { # Fenced code block marker: find matching end marker. - $tag_re = preg_quote(trim($tag)); - if (preg_match('{^(?>.*\n)+?[ ]{0,'.($indent).'}'.$tag_re.'[ ]*\n}', $text, - $matches)) + $fence_indent = strlen($capture[1]); # use captured indent in re + $fence_re = $capture[2]; # use captured fence in re + if (preg_match('{^(?>.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, + $matches)) { # End marker found: pass text unchanged until marker. $parsed .= $tag . $matches[0]; @@ -1968,13 +2057,13 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, # Check for: Indented code block. # else if ($tag{0} == "\n" || $tag{0} == " ") { - # Indented code block: pass it unchanged, will be handled + # Indented code block: pass it unchanged, will be handled # later. $parsed .= $tag; } # # Check for: Opening Block level tag or - # Opening Context Block tag (like ins and del) + # Opening Context Block tag (like ins and del) # used as a block tag (tag is alone on it's line). # else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || @@ -1984,9 +2073,9 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, ) { # Need to parse tag and following text using the HTML parser. - list($block_text, $text) = + list($block_text, $text) = $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); - + # Make sure it stays outside of any paragraph by adding newlines. $parsed .= "\n\n$block_text\n\n"; } @@ -1999,9 +2088,9 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, { # Need to parse tag and following text using the HTML parser. # (don't check for markdown attribute) - list($block_text, $text) = + list($block_text, $text) = $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); - + $parsed .= $block_text; } # @@ -2025,14 +2114,14 @@ function _hashHTMLBlocks_inMarkdown($text, $indent = 0, $text = $tag . $text; break; } - + $parsed .= $tag; } else { $parsed .= $tag; } } while ($depth >= 0); - + return array($parsed, $text); } function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { @@ -2047,7 +2136,7 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # Returns an array of that form: ( processed text , remaining text ) # if ($text === '') return array('', ''); - + # Regex to match `markdown` attribute inside of a tag. $markdown_attr_re = ' { @@ -2055,18 +2144,18 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { markdown \s*=\s* (?> - (["\']) # $1: quote delimiter + (["\']) # $1: quote delimiter (.*?) # $2: attribute value - \1 # matching delimiter + \1 # matching delimiter | ([^\s>]*) # $3: unquoted attribute value ) () # $4: make $3 always defined (avoid warnings) }xs'; - + # Regex to match any tag. $tag_re = '{ - ( # $2: Capture hole tag. + ( # $2: Capture whole tag. # CData Block ) }xs'; - + $original_text = $text; # Save original text in case of faliure. - + $depth = 0; # Current depth inside the tag tree. $block_text = ""; # Temporary text holder for current text. $parsed = ""; # Parsed text that will be returned. @@ -2107,25 +2196,25 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { # # Split the text using the first $tag_match pattern found. # Text before pattern will be first in the array, text after - # pattern will be at the end, and between will be any catches made + # pattern will be at the end, and between will be any catches made # by the pattern. # $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); - + if (count($parts) < 3) { # # End of $text reached with unbalenced tag(s). # In that case, we return original text unchanged and pass the - # first character as filtered to prevent an infinite loop in the + # first character as filtered to prevent an infinite loop in the # parent function. # return array($original_text{0}, substr($original_text, 1)); } - + $block_text .= $parts[0]; # Text before current tag. $tag = $parts[1]; # Tag to handle. $text = $parts[2]; # Remaining text after current tag. - + # # Check for: Auto-close tag (like
    ) # Comments and Processing Instructions. @@ -2145,22 +2234,22 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { if ($tag{1} == '/') $depth--; else if ($tag{strlen($tag)-2} != '/') $depth++; } - + # # Check for `markdown="1"` attribute and handle it. # - if ($md_attr && + if ($md_attr && preg_match($markdown_attr_re, $tag, $attr_m) && preg_match('/^1|block|span$/', $attr_m[2] . $attr_m[3])) { # Remove `markdown` attribute from opening tag. $tag = preg_replace($markdown_attr_re, '', $tag); - + # Check if text inside this tag must be parsed in span mode. $this->mode = $attr_m[2] . $attr_m[3]; $span_mode = $this->mode == 'span' || $this->mode != 'block' && preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); - + # Calculate indent before tag. if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { $strlen = $this->utf8_strlen; @@ -2168,52 +2257,52 @@ function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { } else { $indent = 0; } - + # End preceding block with this tag. $block_text .= $tag; $parsed .= $this->$hash_method($block_text); - + # Get enclosing tag name for the ParseMarkdown function. # (This pattern makes $tag_name_re safe without quoting.) preg_match('/^<([\w:$]*)\b/', $tag, $matches); $tag_name_re = $matches[1]; - + # Parse the content using the HTML-in-Markdown parser. list ($block_text, $text) - = $this->_hashHTMLBlocks_inMarkdown($text, $indent, + = $this->_hashHTMLBlocks_inMarkdown($text, $indent, $tag_name_re, $span_mode); - + # Outdent markdown text. if ($indent > 0) { - $block_text = preg_replace("/^[ ]{1,$indent}/m", "", + $block_text = preg_replace("/^[ ]{1,$indent}/m", "", $block_text); } - + # Append tag content to parsed text. if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; else $parsed .= "$block_text"; - - # Start over a new block. + + # Start over with a new block. $block_text = ""; } else $block_text .= $tag; } - + } while ($depth > 0); - + # # Hash last block text that wasn't processed inside the loop. # $parsed .= $this->$hash_method($block_text); - + return array($parsed, $text); } function hashClean($text) { # - # Called whenever a tag must be hashed when a function insert a "clean" tag - # in $text, it pass through this function and is automaticaly escaped, + # Called whenever a tag must be hashed when a function inserts a "clean" tag + # in $text, it passes through this function and is automaticaly escaped, # blocking invalid nested overlap. # return $this->hashPart($text, 'C'); @@ -2222,19 +2311,19 @@ function hashClean($text) { function doHeaders($text) { # - # Redefined to add id attribute support. + # Redefined to add id and class attribute support. # # Setext-style headers: # Header 1 {#header1} # ======== - # - # Header 2 {#header2} + # + # Header 2 {#header2 .class1 .class2} # -------- # $text = preg_replace_callback( '{ (^.+?) # $1: Header text - (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # $2: Id attribute + (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer }mx', array(&$this, '_doHeaders_callback_setext'), $text); @@ -2242,9 +2331,9 @@ function doHeaders($text) { # atx-style headers: # # Header 1 {#header1} # ## Header 2 {#header2} - # ## Header 2 with closing hashes ## {#header3} + # ## Header 2 with closing hashes ## {#header3.class1.class2} # ... - # ###### Header 6 {#header2} + # ###### Header 6 {.class2} # $text = preg_replace_callback('{ ^(\#{1,6}) # $1 = string of #\'s @@ -2252,7 +2341,7 @@ function doHeaders($text) { (.+?) # $2 = Header text [ ]* \#* # optional closing #\'s (not counted) - (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # id attribute + (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes [ ]* \n+ }xm', @@ -2260,21 +2349,17 @@ function doHeaders($text) { return $text; } - function _doHeaders_attr($attr) { - if (empty($attr)) return ""; - return " id=\"$attr\""; - } function _doHeaders_callback_setext($matches) { if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) return $matches[0]; $level = $matches[3]{0} == '=' ? 1 : 2; - $attr = $this->_doHeaders_attr($id =& $matches[2]); + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); $block = "".$this->runSpanGamut($matches[1]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } function _doHeaders_callback_atx($matches) { $level = strlen($matches[1]); - $attr = $this->_doHeaders_attr($id =& $matches[3]); + $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); $block = "".$this->runSpanGamut($matches[2]).""; return "\n" . $this->hashBlock($block) . "\n\n"; } @@ -2299,10 +2384,10 @@ function doTables($text) { [ ]{0,'.$less_than_tab.'} # Allowed whitespace. [|] # Optional leading pipe (present) (.+) \n # $1: Header row (at least one pipe) - + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. [|] ([ ]*[-:]+[-| :]*) \n # $2: Header underline - + ( # $3: Cells (?> [ ]* # Allowed whitespace. @@ -2312,7 +2397,7 @@ function doTables($text) { (?=\n|\Z) # Stop at final double newline. }xm', array(&$this, '_doTable_leadingPipe_callback'), $text); - + # # Find tables without leading pipe. # @@ -2326,10 +2411,10 @@ function doTables($text) { ^ # Start of a line [ ]{0,'.$less_than_tab.'} # Allowed whitespace. (\S.*[|].*) \n # $1: Header row (at least one pipe) - + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. ([-:]+[ ]*[|][-| :]*) \n # $2: Header underline - + ( # $3: Cells (?> .* [|] .* \n # Row content @@ -2345,10 +2430,10 @@ function _doTable_leadingPipe_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; - + # Remove leading pipe for each row. $content = preg_replace('/^ *[|]/m', '', $content); - + return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); } function _doTable_callback($matches) { @@ -2360,7 +2445,7 @@ function _doTable_callback($matches) { $head = preg_replace('/[|] *$/m', '', $head); $underline = preg_replace('/[|] *$/m', '', $underline); $content = preg_replace('/[|] *$/m', '', $content); - + # Reading alignement from header underline. $separators = preg_split('/ *[|] */', $underline); foreach ($separators as $n => $s) { @@ -2369,13 +2454,13 @@ function _doTable_callback($matches) { else if (preg_match('/^ *:-+ *$/', $s)) $attr[$n] = ' align="left"'; else $attr[$n] = ''; } - - # Parsing span elements, including code spans, character escapes, + + # Parsing span elements, including code spans, character escapes, # and inline HTML tags, so that pipes inside those gets ignored. $head = $this->parseSpan($head); $headers = preg_split('/ *[|] */', $head); $col_count = count($headers); - + # Write column headers. $text = "\n"; $text .= "\n"; @@ -2384,20 +2469,20 @@ function _doTable_callback($matches) { $text .= " ".$this->runSpanGamut(trim($header))."\n"; $text .= "\n"; $text .= "\n"; - + # Split content by row. $rows = explode("\n", trim($content, "\n")); - + $text .= "\n"; foreach ($rows as $row) { - # Parsing span elements, including code spans, character escapes, + # Parsing span elements, including code spans, character escapes, # and inline HTML tags, so that pipes inside those gets ignored. $row = $this->parseSpan($row); - + # Split row by cell. $row_cells = preg_split('/ *[|] */', $row, $col_count); $row_cells = array_pad($row_cells, $col_count, ''); - + $text .= "\n"; foreach ($row_cells as $n => $cell) $text .= " ".$this->runSpanGamut(trim($cell))."\n"; @@ -2405,11 +2490,11 @@ function _doTable_callback($matches) { } $text .= "\n"; $text .= "
    "; - + return $this->hashBlock($text) . "\n"; } - + function doDefLists($text) { # # Form HTML definition lists. @@ -2455,7 +2540,7 @@ function doDefLists($text) { function _doDefLists_callback($matches) { # Re-usable patterns to match list item bullets and number markers: $list = $matches[1]; - + # Turn double returns into triple returns, so that we can make a # paragraph for the last item in a list, if necessary: $result = trim($this->processDefListItems($list)); @@ -2470,7 +2555,7 @@ function processDefListItems($list_str) { # into individual term and definition list items. # $less_than_tab = $this->tab_width - 1; - + # trim trailing blank lines: $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); @@ -2479,11 +2564,11 @@ function processDefListItems($list_str) { (?>\A\n?|\n\n+) # leading line ( # definition terms = $1 [ ]{0,'.$less_than_tab.'} # leading whitespace - (?![:][ ]|[ ]) # negative lookahead for a definition + (?![:][ ]|[ ]) # negative lookahead for a definition # mark (colon) or more whitespace. - (?> \S.* \n)+? # actual term (not whitespace). - ) - (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed + (?> \S.* \n)+? # actual term (not whitespace). + ) + (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed # with a definition mark. }xm', array(&$this, '_processDefListItems_callback_dt'), $list_str); @@ -2500,8 +2585,8 @@ function processDefListItems($list_str) { (?: # next term or end of text [ ]{0,'.$less_than_tab.'} [:][ ] |
    | \z - ) - ) + ) + ) }xm', array(&$this, '_processDefListItems_callback_dd'), $list_str); @@ -2545,23 +2630,29 @@ function doFencedCodeBlocks($text) { # ~~~ # $less_than_tab = $this->tab_width; - + $text = preg_replace_callback('{ (?:\n|\A) # 1: Opening marker ( ~{3,} # Marker: three tilde or more. ) + [ ]* + (?: + [.]?([-_:a-zA-Z0-9]+) # 2: standalone class name + | + '.$this->id_class_attr_catch_re.' # 3: Extra attributes + )? [ ]* \n # Whitespace and newline following marker. - - # 2: Content + + # 4: Content ( (?> (?!\1 [ ]* \n) # Not a closing marker. .*\n+ )+ ) - + # Closing marker. \1 [ ]* \n }xm', @@ -2570,15 +2661,28 @@ function doFencedCodeBlocks($text) { return $text; } function _doFencedCodeBlocks_callback($matches) { - $codeblock = $matches[2]; + $classname =& $matches[2]; + $attrs =& $matches[3]; + $codeblock = $matches[4]; $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); $codeblock = preg_replace_callback('/^\n+/', array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); - $codeblock = "
    $codeblock
    "; + + if ($classname != "") { + if ($classname{0} == '.') + $classname = substr($classname, 1); + $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; + } else { + $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); + } + $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; + $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; + $codeblock = "$codeblock
    "; + return "\n\n".$this->hashBlock($codeblock)."\n\n"; } function _doFencedCodeBlocks_newlines($matches) { - return str_repeat("empty_element_suffix", + return str_repeat("empty_element_suffix", strlen($matches[0])); } @@ -2611,7 +2715,7 @@ function formParagraphs($text) { # # Strip leading and trailing lines: $text = preg_replace('/\A\n+|\n+\z/', '', $text); - + $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); # @@ -2619,29 +2723,29 @@ function formParagraphs($text) { # foreach ($grafs as $key => $value) { $value = trim($this->runSpanGamut($value)); - + # Check if this should be enclosed in a paragraph. # Clean tag hashes & block tag hashes are left alone. $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); - + if ($is_p) { $value = "

    $value

    "; } $grafs[$key] = $value; } - - # Join grafs in one text, then unhash HTML tags. + + # Join grafs in one text, then unhash HTML tags. $text = implode("\n\n", $grafs); - + # Finish by removing any tag hashes still present in $text. $text = $this->unhash($text); - + return $text; } - - + + ### Footnotes - + function stripFootnotes($text) { # # Strips link definitions from text, stores the URLs and titles in @@ -2655,15 +2759,15 @@ function stripFootnotes($text) { [ ]* \n? # maybe *one* newline ( # text = $2 (no blank lines allowed) - (?: + (?: .+ # actual text | - \n # newlines but + \n # newlines but (?!\[\^.+?\]:\s)# negative lookahead for footnote marker. - (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed + (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed # by non-indented content )* - ) + ) }xm', array(&$this, '_stripFootnotes_callback'), $text); @@ -2678,7 +2782,7 @@ function _stripFootnotes_callback($matches) { function doFootnotes($text) { # - # Replace footnote references in $text [^id] with a special text-token + # Replace footnote references in $text [^id] with a special text-token # which will be replaced by the actual footnote marker in appendFootnotes. # if (!$this->in_anchor) { @@ -2687,20 +2791,20 @@ function doFootnotes($text) { return $text; } - + function appendFootnotes($text) { # # Append footnote list to text. # - $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', + $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', array(&$this, '_appendFootnotes_callback'), $text); - + if (!empty($this->footnotes_ordered)) { $text .= "\n\n"; $text .= "
    \n"; $text .= "empty_element_suffix ."\n"; $text .= "
      \n\n"; - + $attr = " rev=\"footnote\""; if ($this->fn_backlink_class != "") { $class = $this->fn_backlink_class; @@ -2713,33 +2817,40 @@ function appendFootnotes($text) { $attr .= " title=\"$title\""; } $num = 0; - + while (!empty($this->footnotes_ordered)) { $footnote = reset($this->footnotes_ordered); $note_id = key($this->footnotes_ordered); unset($this->footnotes_ordered[$note_id]); - + $ref_count = $this->footnotes_ref_count[$note_id]; + unset($this->footnotes_ref_count[$note_id]); + unset($this->footnotes[$note_id]); + $footnote .= "\n"; # Need to append newline before parsing. - $footnote = $this->runBlockGamut("$footnote\n"); - $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', + $footnote = $this->runBlockGamut("$footnote\n"); + $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', array(&$this, '_appendFootnotes_callback'), $footnote); - + $attr = str_replace("%%", ++$num, $attr); $note_id = $this->encodeAttribute($note_id); - # Add backlink to last paragraph; create new paragraph if needed. + # Prepare backlink, multiple backlinks if multiple references $backlink = ""; + for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { + $backlink .= " "; + } + # Add backlink to last paragraph; create new paragraph if needed. if (preg_match('{

      $}', $footnote)) { $footnote = substr($footnote, 0, -4) . " $backlink

      "; } else { $footnote .= "\n\n

      $backlink

      "; } - + $text .= "
    1. \n"; $text .= $footnote . "\n"; $text .= "
    2. \n\n"; } - + $text .= "
    \n"; $text .= "
    "; } @@ -2747,15 +2858,22 @@ function appendFootnotes($text) { } function _appendFootnotes_callback($matches) { $node_id = $this->fn_id_prefix . $matches[1]; - + # Create footnote marker only if it has a corresponding footnote *and* # the footnote hasn't been used by another marker. if (isset($this->footnotes[$node_id])) { - # Transfert footnote content to the ordered list. - $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; - unset($this->footnotes[$node_id]); - - $num = $this->footnote_counter++; + $num =& $this->footnotes_numbers[$node_id]; + if (!isset($num)) { + # Transfer footnote content to the ordered list and give it its + # number + $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; + $this->footnotes_ref_count[$node_id] = 1; + $num = $this->footnote_counter++; + $ref_count_mark = ''; + } else { + $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; + } + $attr = " rel=\"footnote\""; if ($this->fn_link_class != "") { $class = $this->fn_link_class; @@ -2767,22 +2885,22 @@ function _appendFootnotes_callback($matches) { $title = $this->encodeAttribute($title); $attr .= " title=\"$title\""; } - + $attr = str_replace("%%", $num, $attr); $node_id = $this->encodeAttribute($node_id); - + return - "". + "". "$num". ""; } - + return "[^".$matches[1]."]"; } - - + + ### Abbreviations ### - + function stripAbbreviations($text) { # # Strips abbreviations from text, stores titles in hash references. @@ -2792,7 +2910,7 @@ function stripAbbreviations($text) { # Link defs are in the form: [id]*: url "optional title" $text = preg_replace_callback('{ ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 - (.*) # text = $2 (no blank lines allowed) + (.*) # text = $2 (no blank lines allowed) }xm', array(&$this, '_stripAbbreviations_callback'), $text); @@ -2807,20 +2925,20 @@ function _stripAbbreviations_callback($matches) { $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); return ''; # String that will replace the block } - - + + function doAbbreviations($text) { # # Find defined abbreviations in text and wrap them in elements. # if ($this->abbr_word_re) { - // cannot use the /x modifier because abbr_word_re may + // cannot use the /x modifier because abbr_word_re may // contain significant spaces: $text = preg_replace_callback('{'. '(?abbr_word_re.')'. '(?![\w\x1A])'. - '}', + '}', array(&$this, '_doAbbreviations_callback'), $text); } return $text; @@ -2851,14 +2969,14 @@ function _doAbbreviations_callback($matches) { Description ----------- -This is a PHP port of the original Markdown formatter written in Perl -by John Gruber. This special "Extra" version of PHP Markdown features -further enhancements to the syntax for making additional constructs +This is a PHP port of the original Markdown formatter written in Perl +by John Gruber. This special "Extra" version of PHP Markdown features +further enhancements to the syntax for making additional constructs such as tables and definition list. Markdown is a text-to-HTML filter; it translates an easy-to-read / easy-to-write structured text format into HTML. Markdown's text format -is most similar to that of plain text email, and supports features such +is mostly similar to that of plain text email, and supports features such as headers, *emphasis*, code blocks, blockquotes, and links. Markdown's syntax is designed not as a generic markup language, but @@ -2876,14 +2994,14 @@ function _doAbbreviations_callback($matches) { To file bug reports please send email to: - + Please include with your report: (1) the example input; (2) the output you expected; (3) the output Markdown actually produced. Version History ---------------- +--------------- See the readme file for detailed release notes for this version. @@ -2892,13 +3010,13 @@ function _doAbbreviations_callback($matches) { --------------------- PHP Markdown & Extra -Copyright (c) 2004-2009 Michel Fortin - +Copyright (c) 2004-2013 Michel Fortin + All rights reserved. -Based on Markdown -Copyright (c) 2003-2006 John Gruber - +Based on Markdown +Copyright (c) 2003-2006 John Gruber + All rights reserved. Redistribution and use in source and binary forms, with or without @@ -2928,4 +3046,5 @@ function _doAbbreviations_callback($matches) { negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. -*/ \ No newline at end of file +*/ +?> \ No newline at end of file From f7bc5a3e112460384b4c6e475fc354b386afba41 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sun, 21 Apr 2013 14:45:42 +0200 Subject: [PATCH 048/120] bumped the docblock version to 1.6 --- bootstrap.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 30 +++++++++++++++--------------- classes/view/jade.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 7 ++++--- 13 files changed, 30 insertions(+), 29 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index d9c40c2..9c78d93 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index ed199c7..a1b8cb1 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view.php b/classes/view.php index 37bd24e..a519d83 100644 --- a/classes/view.php +++ b/classes/view.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 60371b2..4cffbbb 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/haml.php b/classes/view/haml.php index 34f9480..f134751 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 1740c85..942100f 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team @@ -21,34 +21,34 @@ use MtHaml; class View_HamlTwig extends View_Twig { - + protected static $_environment; - + /** * @access public * @static * @return void */ public static function _init() - { + { // Include View_HamlTwig file(s) defined in config. $includes = \Config::get('parser.View_Twig.include'); - + foreach ((array)$includes as $include) { require $include; static::$loaded_files[$include] = true; } - + parent::_init(); - + MtHaml\Autoloader::register(); - + } - + /** * We Override the parser Loader here - * + * * @access protected * @static */ @@ -65,7 +65,7 @@ protected function process_file($file_override = false) // Twig Loader $views_paths = \Config::get('parser.View_Twig.views_paths', array(APPPATH . 'views')); array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); - + if ( ! empty($global_data)) { foreach ($global_data as $key => $value) @@ -78,11 +78,11 @@ protected function process_file($file_override = false) // Init the parser if you have no global data static::parser(); } - + // Set the HtHaml Twig loader $filesyst = new Twig_Loader_Filesystem($views_paths); static::$_parser_loader = new MtHaml\Support\Twig\Loader(static::$_environment, $filesyst); - + $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); static::$_parser->setLexer($twig_lexer); //\Debug::dump(static::parser()); exit(); @@ -97,7 +97,7 @@ protected function process_file($file_override = false) throw $e; } } - + /** * @access public * @static @@ -108,7 +108,7 @@ public static function parser() if (empty(static::$_parser)) { parent::parser(); - + // Register Haml twig supports static::$_parser->addExtension(new MtHaml\Support\Twig\Extension()); // Store MtHaml environment diff --git a/classes/view/jade.php b/classes/view/jade.php index ca54ed6..3d2e91a 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 4e56d2d..c955dd4 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 34732a7..d25adf3 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 8c5d954..b40011c 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/smarty.php b/classes/view/smarty.php index a2ba35b..993c269 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/twig.php b/classes/view/twig.php index 787a613..54aeeb8 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.5 + * @version 1.6 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/config/parser.php b/config/parser.php index 5a9dc0e..a04b396 100644 --- a/config/parser.php +++ b/config/parser.php @@ -1,14 +1,15 @@ Date: Sun, 28 Apr 2013 18:08:31 +0200 Subject: [PATCH 049/120] Added current_url method to the list of twig custom functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristián Feldsam --- classes/twig/fuel/extension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index a1b8cb1..05380d8 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -45,6 +45,7 @@ public function getFunctions() return array( 'url' => new Twig_Function_Method($this, 'url'), 'base_url' => new Twig_Function_Function('Uri::base'), + 'current_url' => new Twig_Function_Function('Uri::current'), 'uri_segment' => new Twig_Function_Function('Uri::segment'), 'uri_segments' => new Twig_Function_Function('Uri::segments'), 'config' => new Twig_Function_Function('Config::get'), From ed79cd2179ee425b1b3edaf86634d6fdf8550e8c Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 3 May 2013 14:53:12 +0200 Subject: [PATCH 050/120] Updated the twig fuel extensions list. Closes #65 --- classes/twig/fuel/extension.php | 65 ++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 05380d8..fdeb0a9 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -43,34 +43,42 @@ public function getName() public function getFunctions() { return array( - 'url' => new Twig_Function_Method($this, 'url'), - 'base_url' => new Twig_Function_Function('Uri::base'), - 'current_url' => new Twig_Function_Function('Uri::current'), - 'uri_segment' => new Twig_Function_Function('Uri::segment'), - 'uri_segments' => new Twig_Function_Function('Uri::segments'), - 'config' => new Twig_Function_Function('Config::get'), - 'lang' => new Twig_Function_Function('Lang::get'), + 'fuel_version' => new Twig_Function_Method($this, 'fuel_version'), + 'url' => new Twig_Function_Method($this, 'url'), + 'base_url' => new Twig_Function_Function('Uri::base'), + 'current_url' => new Twig_Function_Function('Uri::current'), + 'uri_segment' => new Twig_Function_Function('Uri::segment'), + 'uri_segments' => new Twig_Function_Function('Uri::segments'), + 'config' => new Twig_Function_Function('Config::get'), + 'lang' => new Twig_Function_Function('Lang::get'), - 'form_open' => new Twig_Function_Function('Form::open'), - 'form_close' => new Twig_Function_Function('Form::close'), - 'form_input' => new Twig_Function_Function('Form::input'), - 'form_password' => new Twig_Function_Function('Form::password'), - 'form_hidden' => new Twig_Function_Function('Form::hidden'), - 'form_radio' => new Twig_Function_Function('Form::radio'), - 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), - 'form_textarea' => new Twig_Function_Function('Form::textarea'), - 'form_file' => new Twig_Function_Function('Form::file'), - 'form_button' => new Twig_Function_Function('Form::button'), - 'form_reset' => new Twig_Function_Function('Form::reset'), - 'form_submit' => new Twig_Function_Function('Form::submit'), - 'form_select' => new Twig_Function_Function('Form::select'), - 'form_label' => new Twig_Function_Function('Form::label'), - 'form_val' => new Twig_Function_Function('Input::param'), + 'form_open' => new Twig_Function_Function('Form::open'), + 'form_close' => new Twig_Function_Function('Form::close'), + 'form_input' => new Twig_Function_Function('Form::input'), + 'form_password' => new Twig_Function_Function('Form::password'), + 'form_hidden' => new Twig_Function_Function('Form::hidden'), + 'form_radio' => new Twig_Function_Function('Form::radio'), + 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), + 'form_textarea' => new Twig_Function_Function('Form::textarea'), + 'form_file' => new Twig_Function_Function('Form::file'), + 'form_button' => new Twig_Function_Function('Form::button'), + 'form_reset' => new Twig_Function_Function('Form::reset'), + 'form_submit' => new Twig_Function_Function('Form::submit'), + 'form_select' => new Twig_Function_Function('Form::select'), + 'form_label' => new Twig_Function_Function('Form::label'), + 'form_val' => new Twig_Function_Function('Input::param'), - 'asset_css' => new Twig_Function_Function('Asset::css'), - 'asset_js' => new Twig_Function_Function('Asset::js'), - 'asset_img' => new Twig_Function_Function('Asset::img'), - 'asset_render' => new Twig_Function_Function('Asset::render'), + 'asset_add_path' => new Twig_Function_Function('Asset::add_path'), + 'asset_css' => new Twig_Function_Function('Asset::css'), + 'asset_js' => new Twig_Function_Function('Asset::js'), + 'asset_img' => new Twig_Function_Function('Asset::img'), + 'asset_render' => new Twig_Function_Function('Asset::render'), + + 'html_anchor' => new Twig_Function_Function('Html::anchor'), + 'input_get' => new Twig_Function_Function('Input::get'), + 'input_post' => new Twig_Function_Function('Input::post'), + + 'session_get_flash' => new Twig_Function_Function('Session::get_flash') ); } @@ -91,4 +99,9 @@ public function url($uri = '', $named_params = array()) return Uri::create($uri); } + + public function fuel_version() + { + return Fuel::VERSION; + } } From 074c7d7bb0f5005417c1c46f0e2a021c0ef31745 Mon Sep 17 00:00:00 2001 From: Denis Favreau Date: Mon, 6 May 2013 16:17:37 +0300 Subject: [PATCH 051/120] Alow Asset::find_file usable by twig Allow for example to add a favicon to your page : {{ base_url() ~ asset_find_file("favicon.png", "img") }} --- classes/twig/fuel/extension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index fdeb0a9..fca7dc3 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -73,6 +73,7 @@ public function getFunctions() 'asset_js' => new Twig_Function_Function('Asset::js'), 'asset_img' => new Twig_Function_Function('Asset::img'), 'asset_render' => new Twig_Function_Function('Asset::render'), + 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), 'html_anchor' => new Twig_Function_Function('Html::anchor'), 'input_get' => new Twig_Function_Function('Input::get'), From 828f0a5053a1ae77f687a046d733eb4de3e422f8 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 8 May 2013 22:15:43 +0200 Subject: [PATCH 052/120] bumped the docblock version to 1.7 --- bootstrap.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 2 +- classes/view/jade.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 9c78d93..475350a 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index fca7dc3..d97318c 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view.php b/classes/view.php index a519d83..535d09a 100644 --- a/classes/view.php +++ b/classes/view.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 4cffbbb..994a2b0 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/haml.php b/classes/view/haml.php index f134751..f0b160d 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 942100f..b5ac4c0 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/jade.php b/classes/view/jade.php index 3d2e91a..8835c26 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/markdown.php b/classes/view/markdown.php index c955dd4..396cbf1 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/mustache.php b/classes/view/mustache.php index d25adf3..ac60e18 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/phptal.php b/classes/view/phptal.php index b40011c..35edc2f 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 993c269..6d30434 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/classes/view/twig.php b/classes/view/twig.php index 54aeeb8..dc8476f 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team diff --git a/config/parser.php b/config/parser.php index a04b396..6a6e62b 100644 --- a/config/parser.php +++ b/config/parser.php @@ -5,7 +5,7 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.6 + * @version 1.7 * @author Fuel Development Team * @license MIT License * @copyright 2010 - 2013 Fuel Development Team From 9b98a6212926d44aa61f7b1dde3814612f858a65 Mon Sep 17 00:00:00 2001 From: "Shiina, Yuji" <417yuji@gmail.com> Date: Sat, 18 May 2013 11:57:13 +0900 Subject: [PATCH 053/120] Add markdown parse. --- classes/twig/fuel/extension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index d97318c..acd7ed1 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -79,7 +79,9 @@ public function getFunctions() 'input_get' => new Twig_Function_Function('Input::get'), 'input_post' => new Twig_Function_Function('Input::post'), - 'session_get_flash' => new Twig_Function_Function('Session::get_flash') + 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), + + 'markdown_parse' => new Twig_Function_Function('Markdown::parse') ); } From f550882b032bf2af1421093867c88e94883e43b3 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 31 May 2013 11:38:30 +0200 Subject: [PATCH 054/120] corrected file permissions --- vendor/markdown/License.text | 0 vendor/markdown/markdown.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 vendor/markdown/License.text mode change 100755 => 100644 vendor/markdown/markdown.php diff --git a/vendor/markdown/License.text b/vendor/markdown/License.text old mode 100755 new mode 100644 diff --git a/vendor/markdown/markdown.php b/vendor/markdown/markdown.php old mode 100755 new mode 100644 From 76d4cdd929fa05b1c59ae9aedb2b4347377899a6 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Tue, 10 Sep 2013 10:00:15 +0200 Subject: [PATCH 055/120] access Fuel core classes from global see http://fuelphp.com/forums/discussion/12567/problem-fuel_version-on- parsertwig --- classes/twig/fuel/extension.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index acd7ed1..1b9f1f3 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -80,7 +80,7 @@ public function getFunctions() 'input_post' => new Twig_Function_Function('Input::post'), 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), - + 'markdown_parse' => new Twig_Function_Function('Markdown::parse') ); } @@ -95,16 +95,16 @@ public function getFunctions() */ public function url($uri = '', $named_params = array()) { - if ($named_uri = Router::get($uri, $named_params)) + if ($named_uri = \Router::get($uri, $named_params)) { $uri = $named_uri; } - return Uri::create($uri); + return \Uri::create($uri); } public function fuel_version() { - return Fuel::VERSION; + return \Fuel::VERSION; } } From 500653827a0d7d01a4f7d2097526c0f4e0e6936c Mon Sep 17 00:00:00 2001 From: sagikazarmark Date: Thu, 24 Oct 2013 02:10:46 +0200 Subject: [PATCH 056/120] Include auth_has_access function I think this is very important. There is no auth with twig without this. --- classes/twig/fuel/extension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 1b9f1f3..8a1ed22 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -81,7 +81,9 @@ public function getFunctions() 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), - 'markdown_parse' => new Twig_Function_Function('Markdown::parse') + 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), + + 'auth_has_access' => new Twig_Function_Function('Auth::has_access') ); } From 3ffbb7e2b309c1199a2f20121d530d35175c7169 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 27 Dec 2013 13:08:15 +0100 Subject: [PATCH 057/120] bumped the copyright to 2014 --- bootstrap.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 2 +- classes/view/jade.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 475350a..6ca2118 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 8a1ed22..fd7765f 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 535d09a..5732e56 100644 --- a/classes/view.php +++ b/classes/view.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 994a2b0..c8c1659 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index f0b160d..3389652 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index b5ac4c0..31aaa38 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index 8835c26..3bcae27 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 396cbf1..229677c 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index ac60e18..c054302 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 35edc2f..1e04046 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 6d30434..74bb852 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index dc8476f..a7dd773 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index 6a6e62b..b0c4568 100644 --- a/config/parser.php +++ b/config/parser.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2013 Fuel Development Team + * @copyright 2010 - 2014 Fuel Development Team * @link http://fuelphp.com /** From 94af8b80aa726c5d185a313456817b05bbb08070 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 28 Dec 2013 19:31:05 +0100 Subject: [PATCH 058/120] Added Auth::check() and Session::get() to the Twig extension class --- classes/twig/fuel/extension.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index fd7765f..cd5ad4b 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -45,11 +45,14 @@ public function getFunctions() return array( 'fuel_version' => new Twig_Function_Method($this, 'fuel_version'), 'url' => new Twig_Function_Method($this, 'url'), + 'base_url' => new Twig_Function_Function('Uri::base'), 'current_url' => new Twig_Function_Function('Uri::current'), 'uri_segment' => new Twig_Function_Function('Uri::segment'), 'uri_segments' => new Twig_Function_Function('Uri::segments'), + 'config' => new Twig_Function_Function('Config::get'), + 'lang' => new Twig_Function_Function('Lang::get'), 'form_open' => new Twig_Function_Function('Form::open'), @@ -66,7 +69,10 @@ public function getFunctions() 'form_submit' => new Twig_Function_Function('Form::submit'), 'form_select' => new Twig_Function_Function('Form::select'), 'form_label' => new Twig_Function_Function('Form::label'), + 'form_val' => new Twig_Function_Function('Input::param'), + 'input_get' => new Twig_Function_Function('Input::get'), + 'input_post' => new Twig_Function_Function('Input::post'), 'asset_add_path' => new Twig_Function_Function('Asset::add_path'), 'asset_css' => new Twig_Function_Function('Asset::css'), @@ -76,14 +82,14 @@ public function getFunctions() 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), 'html_anchor' => new Twig_Function_Function('Html::anchor'), - 'input_get' => new Twig_Function_Function('Input::get'), - 'input_post' => new Twig_Function_Function('Input::post'), + 'session_get' => new Twig_Function_Function('Session::get'), 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), - + 'auth_has_access' => new Twig_Function_Function('Auth::has_access') + 'auth_check' => new Twig_Function_Function('Auth::check') ); } From 82dcd803c92c061af13f26c1b0ee770383c772a9 Mon Sep 17 00:00:00 2001 From: Takanao Yoshii Date: Sun, 5 Jan 2014 05:55:13 +0900 Subject: [PATCH 059/120] fixed syntax --- classes/twig/fuel/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index cd5ad4b..b9b0af2 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -88,7 +88,7 @@ public function getFunctions() 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), - 'auth_has_access' => new Twig_Function_Function('Auth::has_access') + 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), 'auth_check' => new Twig_Function_Function('Auth::check') ); } From eda4214727ca180bdc85046a0410e73f98a62a18 Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Fri, 31 Jan 2014 13:49:51 -0500 Subject: [PATCH 060/120] Add Smarty plugins based on Twig Extensions --- bootstrap.php | 1 + classes/smarty/fuel/extension.php | 536 ++++++++++++++++++++++++++++++ classes/view/smarty.php | 4 +- 3 files changed, 540 insertions(+), 1 deletion(-) create mode 100644 classes/smarty/fuel/extension.php diff --git a/bootstrap.php b/bootstrap.php index 6ca2118..cf2532f 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -26,6 +26,7 @@ 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', + 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', )); diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php new file mode 100644 index 0000000..3f707ee --- /dev/null +++ b/classes/smarty/fuel/extension.php @@ -0,0 +1,536 @@ +registerPlugin('function', 'fuel_version', array($this, 'fuel_version')); + $smarty->registerPlugin('function', 'url', array($this, 'url')); + $smarty->registerPlugin('function', 'base_url', array('Uri', 'base')); + $smarty->registerPlugin('function', 'current_url', array('Uri', 'current')); + $smarty->registerPlugin('function', 'uri_segment', array($this, 'uri_segment')); + $smarty->registerPlugin('function', 'uri_segments', array('Uri', 'segments')); + $smarty->registerPlugin('function', 'config', array($this, 'config_get')); + $smarty->registerPlugin('function', 'lang', array($this, 'lang_get')); + $smarty->registerPlugin('block', 'form', array($this, 'form')); + $smarty->registerPlugin('function', 'form_input', array($this, 'form_input')); + $smarty->registerPlugin('function', 'form_password', array($this, 'form_password')); + $smarty->registerPlugin('function', 'form_hidden', array($this, 'form_hidden')); + $smarty->registerPlugin('function', 'form_button', array($this, 'form_button')); + $smarty->registerPlugin('function', 'form_reset', array($this, 'form_reset')); + $smarty->registerPlugin('function', 'form_submit', array($this, 'form_submit')); + $smarty->registerPlugin('function', 'form_textarea', array($this, 'form_textarea')); + $smarty->registerPlugin('block', 'form_fieldset', array($this, 'form_fieldset')); + $smarty->registerPlugin('function', 'form_label', array($this, 'form_label')); + $smarty->registerPlugin('function', 'form_checkbox', array($this, 'form_checkbox')); + $smarty->registerPlugin('function', 'form_radio', array($this, 'form_radio')); + $smarty->registerPlugin('function', 'form_file', array($this, 'form_file')); + $smarty->registerPlugin('function', 'form_select', array($this, 'form_select')); + $smarty->registerPlugin('function', 'form_val', array($this, 'form_val')); + $smarty->registerPlugin('function', 'input_get', array($this, 'input_get')); + $smarty->registerPlugin('function', 'input_post', array($this, 'input_post')); + $smarty->registerPlugin('function', 'asset_add_path', array($this, 'asset_add_path')); + $smarty->registerPlugin('function', 'asset_css', array($this, 'asset_css')); + $smarty->registerPlugin('function', 'asset_js', array($this, 'asset_js')); + $smarty->registerPlugin('function', 'asset_img', array($this, 'asset_img')); + $smarty->registerPlugin('function', 'asset_render', array($this, 'asset_render')); + $smarty->registerPlugin('function', 'asset_find_file', array($this, 'asset_find_file')); + $smarty->registerPlugin('function', 'html_anchor', array($this, 'html_anchor')); + $smarty->registerPlugin('function', 'session_get_flash', array($this, 'session_get_flash')); + $smarty->registerPlugin('block', 'markdown', array($this, 'markdown_parse')); + $smarty->registerPlugin('function', 'auth_has_access', array($this, 'auth_has_access')); + $smarty->registerPlugin('function', 'auth_check', array('Auth', 'check')); + } + + public function fuel_version() { + return \Fuel::VERSION; + } + + /** + * Provides the url() functionality. Generates a full url (including + * domain and index.php). + * + * Usage: {url uri='' params=[name=>$value]} + * + * @return string + */ + public function url($params) { + $uri = isset($params['uri']) ? $params['uri'] : ''; + $named_params = isset($params['params']) ? $params['params'] : array(); + if ($named_uri = Router::get($uri, $named_params)) { + $uri = $named_uri; + } + return Uri::create($uri); + } + + /** + * Usage: {uri_segment segment=''} + * Required: segment + * + * @return mixed segment string or false + */ + public function uri_segment($params) { + if (isset($params['segment'])) { + return Uri::segment($params['segment']); + } + return false; + } + + /** + * Usage: {config item='' default=''} + * Required: item + * + * @return mixed string or array + */ + public function config_get($params) { + if (isset($params['item'])) { + $default = $params['default'] ? null : $params['default']; + return Config::get($params['item'], $default); + } + return ''; + } + + /** + * Usage: {lang line='id' params=[] default='default value' lang='en'} + * Required: line + * + * @return mixed string or false + */ + public function lang_get($params) { + if (isset($params['line'])) { + $parameters = isset($params['params']) ? $params['params'] : array(); + $default = isset($params['default']) ? $params['default'] : null; + $language = isset($params['lang']) ? $params['lang'] : null; + return Lang::get($params['line'], $parameters, $default, $language); + } + return false; + } + + /** + * Usage: {form attrs=[] hidden=[]}...{/form} + * + * @return string + */ + public function form($params, $content, $smarty, &$repeat) { + //$content is null when repeat is true and has block content when repeat is false + if ($repeat) { + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $hidden = isset($params['hidden']) ? $params['hidden'] : array(); + return Form::open($attributes, $hidden); + } else { + return $content . Form::close(); + } + } + + /** + * Usage: {form_fieldset attrs=[] legend=''}...{/form} + * + * @return string + */ + public function form_fieldset($params, $content, $smarty, &$repeat) { + //$content is null when repeat is true and has block content when repeat is false + if ($repeat) { + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $legend = isset($params['legend']) ? $params['legend'] : null; + return Form::fieldset_open($attributes, $legend); + } else { + return $content . Form::fieldset_close(); + } + } + + /** + * Usage: {form_input field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_input($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::input($params['field'], $value, $attributes); + } + + /** + * Usage: {form_password field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_password($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::password($params['field'], $value, $attributes); + } + + /** + * Usage: {form_hidden field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_hidden($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::hidden($params['field'], $value, $attributes); + } + + /** + * Usage: {form_button field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_button($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::button($params['field'], $value, $attributes); + } + + /** + * Usage: {form_submit field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_submit($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::submit($params['field'], $value, $attributes); + } + + /** + * Usage: {form_reset field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_reset($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::reset($params['field'], $value, $attributes); + } + + /** + * Usage: {form_textarea field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_textarea($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::textarea($params['field'], $value, $attributes); + } + + /** + * Usage: {form_label text='' id='' attrs=[]} + * Required: text + * + * @return string + */ + public function form_label($params) { + if (!isset($params['text'])) { + throw new \UnexpectedValueException("The text parameter is required."); + } + $id = isset($params['id']) ? $params['id'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::label($params['text'], $id, $attributes); + } + + /** + * Usage: {form_checkbox field='' value='' checked=false attrs=[]} + * Required: field + * + * @return string + */ + public function form_checkbox($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $checked = isset($params['checked']) ? $params['checked'] : null; + return Form::checkbox($params['field'], $value, $checked, $attributes); + } + + /** + * Usage: {form_radio field='' value='' checked=false attrs=[]} + * Required: field + * + * @return string + */ + public function form_radio($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $checked = isset($params['checked']) ? $params['checked'] : null; + return Form::checkbox($params['field'], $value, $checked, $attributes); + } + + /** + * Usage: {form_select field='' values='' options=[] attrs=[]} + * Required: field + * + * @return string + */ + public function form_select($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $values = isset($params['values']) ? $params['values'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $options = isset($params['options']) ? $params['options'] : array(); + return Form::select($params['field'], $values, $options, $attributes); + } + + /** + * Usage: {form_file field='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_file($params) { + if (!isset($params['field'])) { + throw new \UnexpectedValueException("The field parameter is required."); + } + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return Form::file($params['field'], $attributes); + } + + /** + * Provide access to Input::param + * Usage: {form_val index='' default=''} + * + * @return string + */ + public function form_val($params) { + $index = isset($params['index']) ? $params['index'] : null; + $default = isset($params['default']) ? $params['default'] : null; + return Input::param($index, $default); + } + + /** + * Provide access to Input::get + * Usage: {input_get index='' default=''} + * + * @return string + */ + public function input_get($params) { + $index = isset($params['index']) ? $params['index'] : null; + $default = isset($params['default']) ? $params['default'] : null; + return Input::get($index, $default); + } + + /** + * Provide access to Input::post + * Usage: {input_post index='' default=''} + * + * @return string + */ + public function input_post($params) { + $index = isset($params['index']) ? $params['index'] : null; + $default = isset($params['default']) ? $params['default'] : null; + return Input::post($index, $default); + } + + /** + * Provide addess to Asset::add_path + * Usage: {form_val path='' type=''} + * Required: path + * + */ + public function asset_add_path($params) { + if (!isset($params['path'])) + throw new \UnexpectedValueException('Asset path must be specified'); + $type = isset($params['type']) ? $params['type'] : null; + Asset::add_path($params['path'], $type); + } + + /** + * Usage: {asset_css refs='' attrs=[] group='' raw=false} + * Required: refs + * + * @return mixed string or nothing if group is filled + */ + public function asset_css($params) { + if (!isset($params['refs'])) { + throw new \UnexpectedValueException("The refs parameter is required."); + } + $group = isset($params['group']) ? $params['group'] : null; + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + $raw = isset($params['raw']) ? $params['raw'] : false; + return Asset::css($params['refs'], $attrs, $group, $raw); + } + + /** + * Usage: {asset_js refs='' attrs=[] group='' raw=false} + * Required: refs + * + * @return mixed string or nothing if group is filled + */ + public function asset_js($params) { + if (!isset($params['refs'])) { + throw new \UnexpectedValueException("The refs parameter is required."); + } + $group = isset($params['group']) ? $params['group'] : null; + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + $raw = isset($params['raw']) ? $params['raw'] : false; + return Asset::js($params['refs'], $attrs, $group, $raw); + } + + /** + * Usage: {asset_img refs='' attrs=[] group=''} + * Required: refs + * + * @return mixed string or nothing if group is filled + */ + public function asset_img($params) { + if (!isset($params['refs'])) { + throw new \UnexpectedValueException("The refs parameter is required."); + } + $group = isset($params['group']) ? $params['group'] : null; + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + return Asset::img($params['refs'], $attrs, $group); + } + + /** + * Render a group of assets + * Usage: {asset_render group='' raw=false} + * + * @return string + */ + public function asset_render($params) { + $group = isset($params['group']) ? $params['group'] : null; + $raw = isset($params['raw']) ? $params['raw'] : false; + return Asset::render($group, $raw); + } + + /** + * Usage: {asset_find_file file='' type='' folder=''} + * Required: file and type + * + * @return string + */ + public function asset_find_file($params) { + if (!isset($params['file'])) { + throw new \UnexpectedValueException("The file parameter is required."); + } + if (!isset($params['type'])) { + throw new \UnexpectedValueException("The type parameter is required."); + } + $folder = isset($params['folder']) ? $params['folder'] : ''; + return Asset::find_file($params['file'], $params['file'], $folder); + } + + /** + * Usage: {html_anchor href='' text='' attrs='' secure=false} + * Required: href and text + * + * @return string + */ + public function html_anchor($params) { + if (!isset($params['href'])) { + throw new \UnexpectedValueException("The href parameter is required."); + } + if (!isset($params['text'])) { + throw new \UnexpectedValueException("The text parameter is required."); + } + $attrs = isset($params['folder']) ? $params['folder'] : array(); + $secure = isset($params['secure']) ? $params['secure'] : null; + return Html::anchor($params['file'], $params['text'], $attrs, $secure); + } + + /** + * Usage: {session_get_flash var='' default='' expire=false} + * Required: var + * + * @return mixed + */ + public function session_get_flash($params) { + if (!isset($params['var'])) { + throw new \UnexpectedValueException("The var parameter is required."); + } + $default = isset($params['default']) ? $params['default'] : null; + $expire = isset($params['expire']) ? $params['expire'] : false; + return Session::get_flash($params['var'], $default, $expire); + } + + /** + * Usage: {markdown}...{/markdown} + * + * @return string + */ + public function markdown_parse($params, $content, $smarty, &$repeat) { + //only take action when repeat = false as that is the closing tag + if (!$repeat) { + return Markdown::parse($content); + } + } + + /** + * Usage: {auth_has_access cond=''} + * Required: cond + * + * @return bool + */ + public function auth_has_access($params) { + if (!isset($params['cond'])) { + throw new \UnexpectedValueException("The cond parameter is required."); + } + return Auth::has_access($params['cond']); + } + +} diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 74bb852..023d445 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -73,7 +73,9 @@ public static function parser() static::$_parser->autoload_filters = \Config::get('parser.View_Smarty.environment.autoload_filters', array()); static::$_parser->default_modifiers = \Config::get('parser.View_Smarty.environment.default_modifiers', array()); - + foreach (\Config::get('parser.View_Smarty.extensions', array()) as $extension){ + new $extension(static::$_parser); + } return static::$_parser; } } From 04b217920ea3419861ef4f8267a3daf219eeffbb Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Mon, 3 Feb 2014 09:35:38 -0500 Subject: [PATCH 061/120] Remove Core references --- classes/smarty/fuel/extension.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index 3f707ee..b79300e 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -14,16 +14,17 @@ namespace Parser; -use Fuel\Core\Asset; -use Fuel\Core\Config; -use Fuel\Core\Form; -use Fuel\Core\Html; -use Fuel\Core\Input; -use Fuel\Core\Lang; -use Fuel\Core\Markdown; -use Fuel\Core\Router; -use Fuel\Core\Session; -use Fuel\Core\Uri; +use Asset; +use Auth; +use Config; +use Form; +use Html; +use Input; +use Lang; +use Markdown; +use Router; +use Session; +use Uri; /** * Provides Smarty support for commonly used FuelPHP classes and methods. @@ -69,7 +70,7 @@ public function __construct(\Smarty $smarty) { $smarty->registerPlugin('function', 'session_get_flash', array($this, 'session_get_flash')); $smarty->registerPlugin('block', 'markdown', array($this, 'markdown_parse')); $smarty->registerPlugin('function', 'auth_has_access', array($this, 'auth_has_access')); - $smarty->registerPlugin('function', 'auth_check', array('Auth', 'check')); + $smarty->registerPlugin('function', 'auth_check', array($this, 'auth_check')); } public function fuel_version() { @@ -533,4 +534,12 @@ public function auth_has_access($params) { return Auth::has_access($params['cond']); } + /** + * Usage: {auth_check} + * + * @return bool + */ + public function auth_check() { + return Auth::check(); + } } From 424d9b94a6321253960937f958bf8385ffab9094 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 19 Jun 2014 16:50:33 +0200 Subject: [PATCH 062/120] Added support for the Lex parser --- README.md | 8 ++++-- bootstrap.php | 1 + classes/view/lex.php | 65 ++++++++++++++++++++++++++++++++++++++++++++ config/parser.php | 8 ++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 classes/view/lex.php diff --git a/README.md b/README.md index b6fd316..3618383 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ View::forge('example.haml'); // load a Smarty template, will load and parse app/views/example.smarty View::forge('example.smarty'); +// load a Lex template, will load and parse app/views/example.lex +View::forge('example.lex'); + // load a Dwoo template, ATTENTION: this one expects app/views/example.tpl View::forge('example.dwoo'); ``` @@ -43,7 +46,7 @@ View::forge('example.dwoo'); Only Markdown is included. While many other drivers are included, their libraries are not and are by default. -Mustache, Twig, MtHaml and Smarty should be installed via Composer. Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: +Mustache, Twig, MtHaml, Lex and Smarty should be installed via Composer. Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: ```json { @@ -51,7 +54,8 @@ Mustache, Twig, MtHaml and Smarty should be installed via Composer. Simply add t "mustache/mustache" : "*", "smarty/smarty" : "*", "twig/twig" : "*", - "mthaml/mthaml": "*" + "mthaml/mthaml": "*", + "pyrocms/lex": "2.2.*" } } ``` diff --git a/bootstrap.php b/bootstrap.php index cf2532f..adfdc6c 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -28,6 +28,7 @@ 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', + 'Parser\\View_Lex' => __DIR__.'/classes/view/lex.php', )); diff --git a/classes/view/lex.php b/classes/view/lex.php new file mode 100644 index 0000000..5ebd427 --- /dev/null +++ b/classes/view/lex.php @@ -0,0 +1,65 @@ +callback = $callback; + + return $this; + } + + protected function process_file($file_override = false) + { + $file = $file_override ?: $this->file_name; + + try + { + static::parser()->scopeGlue(\Config::get('parser.View_Lex.scope_glue', '.')); + return static::parser()->parse(file_get_contents($file), $this->get_data(), $this->callback, \Config::get('parser.View_Lex.allow_php', false)); + } + catch (\Exception $e) + { + // Delete the output buffer & re-throw the exception + ob_end_clean(); + throw $e; + } + } +} diff --git a/config/parser.php b/config/parser.php index b0c4568..c0e6d8c 100644 --- a/config/parser.php +++ b/config/parser.php @@ -36,6 +36,7 @@ 'haml' => 'View_Haml', 'smarty' => 'View_Smarty', 'phptal' => 'View_Phptal', + 'lex' => 'View_Lex', ), @@ -178,6 +179,13 @@ 'template_repository' => '', 'force_reparse' => false, ), + + // Lex ( http://github.com/pyrocms/lex/ ) + // ------------------------------------------------------------------------ + 'View_Lex' => array( + 'scope_glue' => '.', + 'allow_php' => false, + ), ); // end of file parser.php From 5901dc3f4ac37ec7e0d602954d3b6e46530e26b2 Mon Sep 17 00:00:00 2001 From: Derrick Egersdorfer Date: Thu, 19 Jun 2014 17:24:59 +0200 Subject: [PATCH 063/120] Update lex.php Just needed the forward slash to find lex - otherwise it works perfect. --- classes/view/lex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/lex.php b/classes/view/lex.php index 5ebd427..80f9688 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -25,7 +25,7 @@ public static function parser() return static::$_parser; } - static::$_parser = new Lex\Parser(); + static::$_parser = new \Lex\Parser(); return static::$_parser; } From 4ba6f6c011262a5d32ce69c2ff8a88c5ec71b44d Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 19 Jun 2014 18:17:38 +0200 Subject: [PATCH 064/120] Removed Markdown; switched to the composer package installed by the core --- classes/view/markdown.php | 5 +- vendor/markdown/License.text | 36 - vendor/markdown/markdown.php | 3050 ---------------------------------- 3 files changed, 1 insertion(+), 3090 deletions(-) delete mode 100644 vendor/markdown/License.text delete mode 100644 vendor/markdown/markdown.php diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 229677c..d41f138 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -78,12 +78,9 @@ public static function parser() static $parser = null; if (is_null($parser)) { - $parser_class = \MARKDOWN_PARSER_CLASS; - $parser = new $parser_class; + $parser = new \Michelf\MarkdownExtra(); } return $parser; } } - -// end of file mustache.php diff --git a/vendor/markdown/License.text b/vendor/markdown/License.text deleted file mode 100644 index 4d6bf8b..0000000 --- a/vendor/markdown/License.text +++ /dev/null @@ -1,36 +0,0 @@ -PHP Markdown & Extra -Copyright (c) 2004-2009 Michel Fortin - -All rights reserved. - -Based on Markdown -Copyright (c) 2003-2006 John Gruber - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -* Neither the name "Markdown" nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. - -This software is provided by the copyright holders and contributors "as -is" and any express or implied warranties, including, but not limited -to, the implied warranties of merchantability and fitness for a -particular purpose are disclaimed. In no event shall the copyright owner -or contributors be liable for any direct, indirect, incidental, special, -exemplary, or consequential damages (including, but not limited to, -procurement of substitute goods or services; loss of use, data, or -profits; or business interruption) however caused and on any theory of -liability, whether in contract, strict liability, or tort (including -negligence or otherwise) arising in any way out of the use of this -software, even if advised of the possibility of such damage. diff --git a/vendor/markdown/markdown.php b/vendor/markdown/markdown.php deleted file mode 100644 index 2e0ae85..0000000 --- a/vendor/markdown/markdown.php +++ /dev/null @@ -1,3050 +0,0 @@ - -# -# Original Markdown -# Copyright (c) 2004-2006 John Gruber -# -# - - -define( 'MARKDOWN_VERSION', "1.0.1p" ); # Sun 13 Jan 2013 -define( 'MARKDOWNEXTRA_VERSION', "1.2.6" ); # Sun 13 Jan 2013 - - -# -# Global default settings: -# - -# Change to ">" for HTML output -@define( 'MARKDOWN_EMPTY_ELEMENT_SUFFIX', " />"); - -# Define the width of a tab for code blocks. -@define( 'MARKDOWN_TAB_WIDTH', 4 ); - -# Optional title attribute for footnote links and backlinks. -@define( 'MARKDOWN_FN_LINK_TITLE', "" ); -@define( 'MARKDOWN_FN_BACKLINK_TITLE', "" ); - -# Optional class attribute for footnote links and backlinks. -@define( 'MARKDOWN_FN_LINK_CLASS', "" ); -@define( 'MARKDOWN_FN_BACKLINK_CLASS', "" ); - -# Optional class prefix for fenced code block. -@define( 'MARKDOWN_CODE_CLASS_PREFIX', "" ); - -# Class attribute for code blocks goes on the `code` tag; -# setting this to true will put attributes on the `pre` tag instead. -@define( 'MARKDOWN_CODE_ATTR_ON_PRE', false ); - - -# -# WordPress settings: -# - -# Change to false to remove Markdown from posts and/or comments. -@define( 'MARKDOWN_WP_POSTS', true ); -@define( 'MARKDOWN_WP_COMMENTS', true ); - - - -### Standard Function Interface ### - -@define( 'MARKDOWN_PARSER_CLASS', 'MarkdownExtra_Parser' ); - -function Markdown($text) { -# -# Initialize the parser and return the result of its transform method. -# - # Setup static parser variable. - static $parser; - if (!isset($parser)) { - $parser_class = MARKDOWN_PARSER_CLASS; - $parser = new $parser_class; - } - - # Transform text using parser. - return $parser->transform($text); -} - - -### WordPress Plugin Interface ### - -/* -Plugin Name: Markdown Extra -Plugin Name: Markdown -Plugin URI: http://michelf.ca/projects/php-markdown/ -Description: Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More... -Version: 1.2.6 -Author: Michel Fortin -Author URI: http://michelf.ca/ -*/ - -if (isset($wp_version)) { - # More details about how it works here: - # - - # Post content and excerpts - # - Remove WordPress paragraph generator. - # - Run Markdown on excerpt, then remove all tags. - # - Add paragraph tag around the excerpt, but remove it for the excerpt rss. - if (MARKDOWN_WP_POSTS) { - remove_filter('the_content', 'wpautop'); - remove_filter('the_content_rss', 'wpautop'); - remove_filter('the_excerpt', 'wpautop'); - add_filter('the_content', 'mdwp_MarkdownPost', 6); - add_filter('the_content_rss', 'mdwp_MarkdownPost', 6); - add_filter('get_the_excerpt', 'mdwp_MarkdownPost', 6); - add_filter('get_the_excerpt', 'trim', 7); - add_filter('the_excerpt', 'mdwp_add_p'); - add_filter('the_excerpt_rss', 'mdwp_strip_p'); - - remove_filter('content_save_pre', 'balanceTags', 50); - remove_filter('excerpt_save_pre', 'balanceTags', 50); - add_filter('the_content', 'balanceTags', 50); - add_filter('get_the_excerpt', 'balanceTags', 9); - } - - # Add a footnote id prefix to posts when inside a loop. - function mdwp_MarkdownPost($text) { - static $parser; - if (!$parser) { - $parser_class = MARKDOWN_PARSER_CLASS; - $parser = new $parser_class; - } - if (is_single() || is_page() || is_feed()) { - $parser->fn_id_prefix = ""; - } else { - $parser->fn_id_prefix = get_the_ID() . "."; - } - return $parser->transform($text); - } - - # Comments - # - Remove WordPress paragraph generator. - # - Remove WordPress auto-link generator. - # - Scramble important tags before passing them to the kses filter. - # - Run Markdown on excerpt then remove paragraph tags. - if (MARKDOWN_WP_COMMENTS) { - remove_filter('comment_text', 'wpautop', 30); - remove_filter('comment_text', 'make_clickable'); - add_filter('pre_comment_content', 'Markdown', 6); - add_filter('pre_comment_content', 'mdwp_hide_tags', 8); - add_filter('pre_comment_content', 'mdwp_show_tags', 12); - add_filter('get_comment_text', 'Markdown', 6); - add_filter('get_comment_excerpt', 'Markdown', 6); - add_filter('get_comment_excerpt', 'mdwp_strip_p', 7); - - global $mdwp_hidden_tags, $mdwp_placeholders; - $mdwp_hidden_tags = explode(' ', - '

     
  • '); - $mdwp_placeholders = explode(' ', str_rot13( - 'pEj07ZbbBZ U1kqgh4w4p pre2zmeN6K QTi31t9pre ol0MP1jzJR '. - 'ML5IjmbRol ulANi1NsGY J7zRLJqPul liA8ctl16T K9nhooUHli')); - } - - function mdwp_add_p($text) { - if (!preg_match('{^$|^<(p|ul|ol|dl|pre|blockquote)>}i', $text)) { - $text = '

    '.$text.'

    '; - $text = preg_replace('{\n{2,}}', "

    \n\n

    ", $text); - } - return $text; - } - - function mdwp_strip_p($t) { return preg_replace('{}i', '', $t); } - - function mdwp_hide_tags($text) { - global $mdwp_hidden_tags, $mdwp_placeholders; - return str_replace($mdwp_hidden_tags, $mdwp_placeholders, $text); - } - function mdwp_show_tags($text) { - global $mdwp_hidden_tags, $mdwp_placeholders; - return str_replace($mdwp_placeholders, $mdwp_hidden_tags, $text); - } -} - - -### bBlog Plugin Info ### - -function identify_modifier_markdown() { - return array( - 'name' => 'markdown', - 'type' => 'modifier', - 'nicename' => 'PHP Markdown Extra', - 'description' => 'A text-to-HTML conversion tool for web writers', - 'authors' => 'Michel Fortin and John Gruber', - 'licence' => 'GPL', - 'version' => MARKDOWNEXTRA_VERSION, - 'help' => 'Markdown syntax allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by John Gruber. More...', - ); -} - - -### Smarty Modifier Interface ### - -function smarty_modifier_markdown($text) { - return Markdown($text); -} - - -### Textile Compatibility Mode ### - -# Rename this file to "classTextile.php" and it can replace Textile everywhere. - -if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) { - # Try to include PHP SmartyPants. Should be in the same directory. - @include_once 'smartypants.php'; - # Fake Textile class. It calls Markdown instead. - class Textile { - function TextileThis($text, $lite='', $encode='') { - if ($lite == '' && $encode == '') $text = Markdown($text); - if (function_exists('SmartyPants')) $text = SmartyPants($text); - return $text; - } - # Fake restricted version: restrictions are not supported for now. - function TextileRestricted($text, $lite='', $noimage='') { - return $this->TextileThis($text, $lite); - } - # Workaround to ensure compatibility with TextPattern 4.0.3. - function blockLite($text) { return $text; } - } -} - - - -# -# Markdown Parser Class -# - -class Markdown_Parser { - - ### Configuration Variables ### - - # Change to ">" for HTML output. - var $empty_element_suffix = MARKDOWN_EMPTY_ELEMENT_SUFFIX; - var $tab_width = MARKDOWN_TAB_WIDTH; - - # Change to `true` to disallow markup or entities. - var $no_markup = false; - var $no_entities = false; - - # Predefined urls and titles for reference links and images. - var $predef_urls = array(); - var $predef_titles = array(); - - - ### Parser Implementation ### - - # Regex to match balanced [brackets]. - # Needed to insert a maximum bracked depth while converting to PHP. - var $nested_brackets_depth = 6; - var $nested_brackets_re; - - var $nested_url_parenthesis_depth = 4; - var $nested_url_parenthesis_re; - - # Table of hash values for escaped characters: - var $escape_chars = '\`*_{}[]()>#+-.!'; - var $escape_chars_re; - - - function Markdown_Parser() { - # - # Constructor function. Initialize appropriate member variables. - # - $this->_initDetab(); - $this->prepareItalicsAndBold(); - - $this->nested_brackets_re = - str_repeat('(?>[^\[\]]+|\[', $this->nested_brackets_depth). - str_repeat('\])*', $this->nested_brackets_depth); - - $this->nested_url_parenthesis_re = - str_repeat('(?>[^()\s]+|\(', $this->nested_url_parenthesis_depth). - str_repeat('(?>\)))*', $this->nested_url_parenthesis_depth); - - $this->escape_chars_re = '['.preg_quote($this->escape_chars).']'; - - # Sort document, block, and span gamut in ascendent priority order. - asort($this->document_gamut); - asort($this->block_gamut); - asort($this->span_gamut); - } - - - # Internal hashes used during transformation. - var $urls = array(); - var $titles = array(); - var $html_hashes = array(); - - # Status flag to avoid invalid nesting. - var $in_anchor = false; - - - function setup() { - # - # Called before the transformation process starts to setup parser - # states. - # - # Clear global hashes. - $this->urls = $this->predef_urls; - $this->titles = $this->predef_titles; - $this->html_hashes = array(); - - $in_anchor = false; - } - - function teardown() { - # - # Called after the transformation process to clear any variable - # which may be taking up memory unnecessarly. - # - $this->urls = array(); - $this->titles = array(); - $this->html_hashes = array(); - } - - - function transform($text) { - # - # Main function. Performs some preprocessing on the input text - # and pass it through the document gamut. - # - $this->setup(); - - # Remove UTF-8 BOM and marker character in input, if present. - $text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text); - - # Standardize line endings: - # DOS to Unix and Mac to Unix - $text = preg_replace('{\r\n?}', "\n", $text); - - # Make sure $text ends with a couple of newlines: - $text .= "\n\n"; - - # Convert all tabs to spaces. - $text = $this->detab($text); - - # Turn block-level HTML blocks into hash entries - $text = $this->hashHTMLBlocks($text); - - # Strip any lines consisting only of spaces and tabs. - # This makes subsequent regexen easier to write, because we can - # match consecutive blank lines with /\n+/ instead of something - # contorted like /[ ]*\n+/ . - $text = preg_replace('/^[ ]+$/m', '', $text); - - # Run document gamut methods. - foreach ($this->document_gamut as $method => $priority) { - $text = $this->$method($text); - } - - $this->teardown(); - - return $text . "\n"; - } - - var $document_gamut = array( - # Strip link definitions, store in hashes. - "stripLinkDefinitions" => 20, - - "runBasicBlockGamut" => 30, - ); - - - function stripLinkDefinitions($text) { - # - # Strips link definitions from text, stores the URLs and titles in - # hash references. - # - $less_than_tab = $this->tab_width - 1; - - # Link defs are in the form: ^[id]: url "optional title" - $text = preg_replace_callback('{ - ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 - [ ]* - \n? # maybe *one* newline - [ ]* - (?: - <(.+?)> # url = $2 - | - (\S+?) # url = $3 - ) - [ ]* - \n? # maybe one newline - [ ]* - (?: - (?<=\s) # lookbehind for whitespace - ["(] - (.*?) # title = $4 - [")] - [ ]* - )? # title is optional - (?:\n+|\Z) - }xm', - array(&$this, '_stripLinkDefinitions_callback'), - $text); - return $text; - } - function _stripLinkDefinitions_callback($matches) { - $link_id = strtolower($matches[1]); - $url = $matches[2] == '' ? $matches[3] : $matches[2]; - $this->urls[$link_id] = $url; - $this->titles[$link_id] =& $matches[4]; - return ''; # String that will replace the block - } - - - function hashHTMLBlocks($text) { - if ($this->no_markup) return $text; - - $less_than_tab = $this->tab_width - 1; - - # Hashify HTML blocks: - # We only want to do this for block-level HTML tags, such as headers, - # lists, and tables. That's because we still want to wrap

    s around - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, - # phrase emphasis, and spans. The list of tags we're looking for is - # hard-coded: - # - # * List "a" is made of tags which can be both inline or block-level. - # These will be treated block-level when the start tag is alone on - # its line, otherwise they're not matched here and will be taken as - # inline later. - # * List "b" is made of tags which are always block-level; - # - $block_tags_a_re = 'ins|del'; - $block_tags_b_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|'. - 'script|noscript|form|fieldset|iframe|math|svg|'. - 'article|section|nav|aside|hgroup|header|footer|'. - 'figure'; - - # Regular expression for the content of a block tag. - $nested_tags_level = 4; - $attr = ' - (?> # optional tag attributes - \s # starts with whitespace - (?> - [^>"/]+ # text outside quotes - | - /+(?!>) # slash not followed by ">" - | - "[^"]*" # text inside double quotes (tolerate ">") - | - \'[^\']*\' # text inside single quotes (tolerate ">") - )* - )? - '; - $content = - str_repeat(' - (?> - [^<]+ # content without tag - | - <\2 # nested opening tag - '.$attr.' # attributes - (?> - /> - | - >', $nested_tags_level). # end of opening tag - '.*?'. # last level nested tag content - str_repeat(' - # closing nested tag - ) - | - <(?!/\2\s*> # other tags with a different name - ) - )*', - $nested_tags_level); - $content2 = str_replace('\2', '\3', $content); - - # First, look for nested blocks, e.g.: - #

    - #
    - # tags for inner block must be indented. - #
    - #
    - # - # The outermost tags must start at the left margin for this to match, and - # the inner nested divs must be indented. - # We need to do this before the next, more liberal match, because the next - # match will start at the first `
    ` and stop at the first `
    `. - $text = preg_replace_callback('{(?> - (?> - (?<=\n\n) # Starting after a blank line - | # or - \A\n? # the beginning of the doc - ) - ( # save in $1 - - # Match from `\n` to `\n`, handling nested tags - # in between. - - [ ]{0,'.$less_than_tab.'} - <('.$block_tags_b_re.')# start tag = $2 - '.$attr.'> # attributes followed by > and \n - '.$content.' # content, support nesting - # the matching end tag - [ ]* # trailing spaces/tabs - (?=\n+|\Z) # followed by a newline or end of document - - | # Special version for tags of group a. - - [ ]{0,'.$less_than_tab.'} - <('.$block_tags_a_re.')# start tag = $3 - '.$attr.'>[ ]*\n # attributes followed by > - '.$content2.' # content, support nesting - # the matching end tag - [ ]* # trailing spaces/tabs - (?=\n+|\Z) # followed by a newline or end of document - - | # Special case just for
    . It was easier to make a special - # case than to make the other regex more complicated. - - [ ]{0,'.$less_than_tab.'} - <(hr) # start tag = $2 - '.$attr.' # attributes - /?> # the matching end tag - [ ]* - (?=\n{2,}|\Z) # followed by a blank line or end of document - - | # Special case for standalone HTML comments: - - [ ]{0,'.$less_than_tab.'} - (?s: - - ) - [ ]* - (?=\n{2,}|\Z) # followed by a blank line or end of document - - | # PHP and ASP-style processor instructions ( - ) - [ ]* - (?=\n{2,}|\Z) # followed by a blank line or end of document - - ) - )}Sxmi', - array(&$this, '_hashHTMLBlocks_callback'), - $text); - - return $text; - } - function _hashHTMLBlocks_callback($matches) { - $text = $matches[1]; - $key = $this->hashBlock($text); - return "\n\n$key\n\n"; - } - - - function hashPart($text, $boundary = 'X') { - # - # Called whenever a tag must be hashed when a function insert an atomic - # element in the text stream. Passing $text to through this function gives - # a unique text-token which will be reverted back when calling unhash. - # - # The $boundary argument specify what character should be used to surround - # the token. By convension, "B" is used for block elements that needs not - # to be wrapped into paragraph tags at the end, ":" is used for elements - # that are word separators and "X" is used in the general case. - # - # Swap back any tag hash found in $text so we do not have to `unhash` - # multiple times at the end. - $text = $this->unhash($text); - - # Then hash the block. - static $i = 0; - $key = "$boundary\x1A" . ++$i . $boundary; - $this->html_hashes[$key] = $text; - return $key; # String that will replace the tag. - } - - - function hashBlock($text) { - # - # Shortcut function for hashPart with block-level boundaries. - # - return $this->hashPart($text, 'B'); - } - - - var $block_gamut = array( - # - # These are all the transformations that form block-level - # tags like paragraphs, headers, and list items. - # - "doHeaders" => 10, - "doHorizontalRules" => 20, - - "doLists" => 40, - "doCodeBlocks" => 50, - "doBlockQuotes" => 60, - ); - - function runBlockGamut($text) { - # - # Run block gamut tranformations. - # - # We need to escape raw HTML in Markdown source before doing anything - # else. This need to be done for each block, and not only at the - # begining in the Markdown function since hashed blocks can be part of - # list items and could have been indented. Indented blocks would have - # been seen as a code block in a previous pass of hashHTMLBlocks. - $text = $this->hashHTMLBlocks($text); - - return $this->runBasicBlockGamut($text); - } - - function runBasicBlockGamut($text) { - # - # Run block gamut tranformations, without hashing HTML blocks. This is - # useful when HTML blocks are known to be already hashed, like in the first - # whole-document pass. - # - foreach ($this->block_gamut as $method => $priority) { - $text = $this->$method($text); - } - - # Finally form paragraph and restore hashed blocks. - $text = $this->formParagraphs($text); - - return $text; - } - - - function doHorizontalRules($text) { - # Do Horizontal Rules: - return preg_replace( - '{ - ^[ ]{0,3} # Leading space - ([-*_]) # $1: First marker - (?> # Repeated marker group - [ ]{0,2} # Zero, one, or two spaces. - \1 # Marker character - ){2,} # Group repeated at least twice - [ ]* # Tailing spaces - $ # End of line. - }mx', - "\n".$this->hashBlock("empty_element_suffix")."\n", - $text); - } - - - var $span_gamut = array( - # - # These are all the transformations that occur *within* block-level - # tags like paragraphs, headers, and list items. - # - # Process character escapes, code spans, and inline HTML - # in one shot. - "parseSpan" => -30, - - # Process anchor and image tags. Images must come first, - # because ![foo][f] looks like an anchor. - "doImages" => 10, - "doAnchors" => 20, - - # Make links out of things like `` - # Must come after doAnchors, because you can use < and > - # delimiters in inline links like [this](). - "doAutoLinks" => 30, - "encodeAmpsAndAngles" => 40, - - "doItalicsAndBold" => 50, - "doHardBreaks" => 60, - ); - - function runSpanGamut($text) { - # - # Run span gamut tranformations. - # - foreach ($this->span_gamut as $method => $priority) { - $text = $this->$method($text); - } - - return $text; - } - - - function doHardBreaks($text) { - # Do hard breaks: - return preg_replace_callback('/ {2,}\n/', - array(&$this, '_doHardBreaks_callback'), $text); - } - function _doHardBreaks_callback($matches) { - return $this->hashPart("empty_element_suffix\n"); - } - - - function doAnchors($text) { - # - # Turn Markdown link shortcuts into XHTML tags. - # - if ($this->in_anchor) return $text; - $this->in_anchor = true; - - # - # First, handle reference-style links: [link text] [id] - # - $text = preg_replace_callback('{ - ( # wrap whole match in $1 - \[ - ('.$this->nested_brackets_re.') # link text = $2 - \] - - [ ]? # one optional space - (?:\n[ ]*)? # one optional newline followed by spaces - - \[ - (.*?) # id = $3 - \] - ) - }xs', - array(&$this, '_doAnchors_reference_callback'), $text); - - # - # Next, inline-style links: [link text](url "optional title") - # - $text = preg_replace_callback('{ - ( # wrap whole match in $1 - \[ - ('.$this->nested_brackets_re.') # link text = $2 - \] - \( # literal paren - [ \n]* - (?: - <(.+?)> # href = $3 - | - ('.$this->nested_url_parenthesis_re.') # href = $4 - ) - [ \n]* - ( # $5 - ([\'"]) # quote char = $6 - (.*?) # Title = $7 - \6 # matching quote - [ \n]* # ignore any spaces/tabs between closing quote and ) - )? # title is optional - \) - ) - }xs', - array(&$this, '_doAnchors_inline_callback'), $text); - - # - # Last, handle reference-style shortcuts: [link text] - # These must come last in case you've also got [link text][1] - # or [link text](/foo) - # - $text = preg_replace_callback('{ - ( # wrap whole match in $1 - \[ - ([^\[\]]+) # link text = $2; can\'t contain [ or ] - \] - ) - }xs', - array(&$this, '_doAnchors_reference_callback'), $text); - - $this->in_anchor = false; - return $text; - } - function _doAnchors_reference_callback($matches) { - $whole_match = $matches[1]; - $link_text = $matches[2]; - $link_id =& $matches[3]; - - if ($link_id == "") { - # for shortcut links like [this][] or [this]. - $link_id = $link_text; - } - - # lower-case and turn embedded newlines into spaces - $link_id = strtolower($link_id); - $link_id = preg_replace('{[ ]?\n}', ' ', $link_id); - - if (isset($this->urls[$link_id])) { - $url = $this->urls[$link_id]; - $url = $this->encodeAttribute($url); - - $result = "titles[$link_id] ) ) { - $title = $this->titles[$link_id]; - $title = $this->encodeAttribute($title); - $result .= " title=\"$title\""; - } - - $link_text = $this->runSpanGamut($link_text); - $result .= ">$link_text"; - $result = $this->hashPart($result); - } - else { - $result = $whole_match; - } - return $result; - } - function _doAnchors_inline_callback($matches) { - $whole_match = $matches[1]; - $link_text = $this->runSpanGamut($matches[2]); - $url = $matches[3] == '' ? $matches[4] : $matches[3]; - $title =& $matches[7]; - - $url = $this->encodeAttribute($url); - - $result = "encodeAttribute($title); - $result .= " title=\"$title\""; - } - - $link_text = $this->runSpanGamut($link_text); - $result .= ">$link_text"; - - return $this->hashPart($result); - } - - - function doImages($text) { - # - # Turn Markdown image shortcuts into tags. - # - # - # First, handle reference-style labeled images: ![alt text][id] - # - $text = preg_replace_callback('{ - ( # wrap whole match in $1 - !\[ - ('.$this->nested_brackets_re.') # alt text = $2 - \] - - [ ]? # one optional space - (?:\n[ ]*)? # one optional newline followed by spaces - - \[ - (.*?) # id = $3 - \] - - ) - }xs', - array(&$this, '_doImages_reference_callback'), $text); - - # - # Next, handle inline images: ![alt text](url "optional title") - # Don't forget: encode * and _ - # - $text = preg_replace_callback('{ - ( # wrap whole match in $1 - !\[ - ('.$this->nested_brackets_re.') # alt text = $2 - \] - \s? # One optional whitespace character - \( # literal paren - [ \n]* - (?: - <(\S*)> # src url = $3 - | - ('.$this->nested_url_parenthesis_re.') # src url = $4 - ) - [ \n]* - ( # $5 - ([\'"]) # quote char = $6 - (.*?) # title = $7 - \6 # matching quote - [ \n]* - )? # title is optional - \) - ) - }xs', - array(&$this, '_doImages_inline_callback'), $text); - - return $text; - } - function _doImages_reference_callback($matches) { - $whole_match = $matches[1]; - $alt_text = $matches[2]; - $link_id = strtolower($matches[3]); - - if ($link_id == "") { - $link_id = strtolower($alt_text); # for shortcut links like ![this][]. - } - - $alt_text = $this->encodeAttribute($alt_text); - if (isset($this->urls[$link_id])) { - $url = $this->encodeAttribute($this->urls[$link_id]); - $result = "\"$alt_text\"";titles[$link_id])) { - $title = $this->titles[$link_id]; - $title = $this->encodeAttribute($title); - $result .= " title=\"$title\""; - } - $result .= $this->empty_element_suffix; - $result = $this->hashPart($result); - } - else { - # If there's no such link ID, leave intact: - $result = $whole_match; - } - - return $result; - } - function _doImages_inline_callback($matches) { - $whole_match = $matches[1]; - $alt_text = $matches[2]; - $url = $matches[3] == '' ? $matches[4] : $matches[3]; - $title =& $matches[7]; - - $alt_text = $this->encodeAttribute($alt_text); - $url = $this->encodeAttribute($url); - $result = "\"$alt_text\"";encodeAttribute($title); - $result .= " title=\"$title\""; # $title already quoted - } - $result .= $this->empty_element_suffix; - - return $this->hashPart($result); - } - - - function doHeaders($text) { - # Setext-style headers: - # Header 1 - # ======== - # - # Header 2 - # -------- - # - $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', - array(&$this, '_doHeaders_callback_setext'), $text); - - # atx-style headers: - # # Header 1 - # ## Header 2 - # ## Header 2 with closing hashes ## - # ... - # ###### Header 6 - # - $text = preg_replace_callback('{ - ^(\#{1,6}) # $1 = string of #\'s - [ ]* - (.+?) # $2 = Header text - [ ]* - \#* # optional closing #\'s (not counted) - \n+ - }xm', - array(&$this, '_doHeaders_callback_atx'), $text); - - return $text; - } - function _doHeaders_callback_setext($matches) { - # Terrible hack to check we haven't found an empty list item. - if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) - return $matches[0]; - - $level = $matches[2]{0} == '=' ? 1 : 2; - $block = "".$this->runSpanGamut($matches[1]).""; - return "\n" . $this->hashBlock($block) . "\n\n"; - } - function _doHeaders_callback_atx($matches) { - $level = strlen($matches[1]); - $block = "".$this->runSpanGamut($matches[2]).""; - return "\n" . $this->hashBlock($block) . "\n\n"; - } - - - function doLists($text) { - # - # Form HTML ordered (numbered) and unordered (bulleted) lists. - # - $less_than_tab = $this->tab_width - 1; - - # Re-usable patterns to match list item bullets and number markers: - $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[\.]'; - $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - - $markers_relist = array( - $marker_ul_re => $marker_ol_re, - $marker_ol_re => $marker_ul_re, - ); - - foreach ($markers_relist as $marker_re => $other_marker_re) { - # Re-usable pattern to match any entirel ul or ol list: - $whole_list_re = ' - ( # $1 = whole list - ( # $2 - ([ ]{0,'.$less_than_tab.'}) # $3 = number of spaces - ('.$marker_re.') # $4 = first list item marker - [ ]+ - ) - (?s:.+?) - ( # $5 - \z - | - \n{2,} - (?=\S) - (?! # Negative lookahead for another list item marker - [ ]* - '.$marker_re.'[ ]+ - ) - | - (?= # Lookahead for another kind of list - \n - \3 # Must have the same indentation - '.$other_marker_re.'[ ]+ - ) - ) - ) - '; // mx - - # We use a different prefix before nested lists than top-level lists. - # See extended comment in _ProcessListItems(). - - if ($this->list_level) { - $text = preg_replace_callback('{ - ^ - '.$whole_list_re.' - }mx', - array(&$this, '_doLists_callback'), $text); - } - else { - $text = preg_replace_callback('{ - (?:(?<=\n)\n|\A\n?) # Must eat the newline - '.$whole_list_re.' - }mx', - array(&$this, '_doLists_callback'), $text); - } - } - - return $text; - } - function _doLists_callback($matches) { - # Re-usable patterns to match list item bullets and number markers: - $marker_ul_re = '[*+-]'; - $marker_ol_re = '\d+[\.]'; - $marker_any_re = "(?:$marker_ul_re|$marker_ol_re)"; - - $list = $matches[1]; - $list_type = preg_match("/$marker_ul_re/", $matches[4]) ? "ul" : "ol"; - - $marker_any_re = ( $list_type == "ul" ? $marker_ul_re : $marker_ol_re ); - - $list .= "\n"; - $result = $this->processListItems($list, $marker_any_re); - - $result = $this->hashBlock("<$list_type>\n" . $result . ""); - return "\n". $result ."\n\n"; - } - - var $list_level = 0; - - function processListItems($list_str, $marker_any_re) { - # - # Process the contents of a single ordered or unordered list, splitting it - # into individual list items. - # - # The $this->list_level global keeps track of when we're inside a list. - # Each time we enter a list, we increment it; when we leave a list, - # we decrement. If it's zero, we're not in a list anymore. - # - # We do this because when we're not inside a list, we want to treat - # something like this: - # - # I recommend upgrading to version - # 8. Oops, now this line is treated - # as a sub-list. - # - # As a single paragraph, despite the fact that the second line starts - # with a digit-period-space sequence. - # - # Whereas when we're inside a list (or sub-list), that line will be - # treated as the start of a sub-list. What a kludge, huh? This is - # an aspect of Markdown's syntax that's hard to parse perfectly - # without resorting to mind-reading. Perhaps the solution is to - # change the syntax rules such that sub-lists must start with a - # starting cardinal number; e.g. "1." or "a.". - - $this->list_level++; - - # trim trailing blank lines: - $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); - - $list_str = preg_replace_callback('{ - (\n)? # leading line = $1 - (^[ ]*) # leading whitespace = $2 - ('.$marker_any_re.' # list marker and space = $3 - (?:[ ]+|(?=\n)) # space only required if item is not empty - ) - ((?s:.*?)) # list item text = $4 - (?:(\n+(?=\n))|\n) # tailing blank line = $5 - (?= \n* (\z | \2 ('.$marker_any_re.') (?:[ ]+|(?=\n)))) - }xm', - array(&$this, '_processListItems_callback'), $list_str); - - $this->list_level--; - return $list_str; - } - function _processListItems_callback($matches) { - $item = $matches[4]; - $leading_line =& $matches[1]; - $leading_space =& $matches[2]; - $marker_space = $matches[3]; - $tailing_blank_line =& $matches[5]; - - if ($leading_line || $tailing_blank_line || - preg_match('/\n{2,}/', $item)) - { - # Replace marker with the appropriate whitespace indentation - $item = $leading_space . str_repeat(' ', strlen($marker_space)) . $item; - $item = $this->runBlockGamut($this->outdent($item)."\n"); - } - else { - # Recursion for sub-lists: - $item = $this->doLists($this->outdent($item)); - $item = preg_replace('/\n+$/', '', $item); - $item = $this->runSpanGamut($item); - } - - return "
  • " . $item . "
  • \n"; - } - - - function doCodeBlocks($text) { - # - # Process Markdown `
    ` blocks.
    -	#
    -		$text = preg_replace_callback('{
    -				(?:\n\n|\A\n?)
    -				(	            # $1 = the code block -- one or more lines, starting with a space/tab
    -				  (?>
    -					[ ]{'.$this->tab_width.'}  # Lines must start with a tab or a tab-width of spaces
    -					.*\n+
    -				  )+
    -				)
    -				((?=^[ ]{0,'.$this->tab_width.'}\S)|\Z)	# Lookahead for non-space at line-start, or end of doc
    -			}xm',
    -			array(&$this, '_doCodeBlocks_callback'), $text);
    -
    -		return $text;
    -	}
    -	function _doCodeBlocks_callback($matches) {
    -		$codeblock = $matches[1];
    -
    -		$codeblock = $this->outdent($codeblock);
    -		$codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES);
    -
    -		# trim leading newlines and trailing newlines
    -		$codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
    -
    -		$codeblock = "
    $codeblock\n
    "; - return "\n\n".$this->hashBlock($codeblock)."\n\n"; - } - - - function makeCodeSpan($code) { - # - # Create a code span markup for $code. Called from handleSpanToken. - # - $code = htmlspecialchars(trim($code), ENT_NOQUOTES); - return $this->hashPart("$code"); - } - - - var $em_relist = array( - '' => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(?em_relist as $em => $em_re) { - foreach ($this->strong_relist as $strong => $strong_re) { - # Construct list of allowed token expressions. - $token_relist = array(); - if (isset($this->em_strong_relist["$em$strong"])) { - $token_relist[] = $this->em_strong_relist["$em$strong"]; - } - $token_relist[] = $em_re; - $token_relist[] = $strong_re; - - # Construct master expression from list. - $token_re = '{('. implode('|', $token_relist) .')}'; - $this->em_strong_prepared_relist["$em$strong"] = $token_re; - } - } - } - - function doItalicsAndBold($text) { - $token_stack = array(''); - $text_stack = array(''); - $em = ''; - $strong = ''; - $tree_char_em = false; - - while (1) { - # - # Get prepared regular expression for seraching emphasis tokens - # in current context. - # - $token_re = $this->em_strong_prepared_relist["$em$strong"]; - - # - # Each loop iteration search for the next emphasis token. - # Each token is then passed to handleSpanToken. - # - $parts = preg_split($token_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); - $text_stack[0] .= $parts[0]; - $token =& $parts[1]; - $text =& $parts[2]; - - if (empty($token)) { - # Reached end of text span: empty stack without emitting. - # any more emphasis. - while ($token_stack[0]) { - $text_stack[1] .= array_shift($token_stack); - $text_stack[0] .= array_shift($text_stack); - } - break; - } - - $token_len = strlen($token); - if ($tree_char_em) { - # Reached closing marker while inside a three-char emphasis. - if ($token_len == 3) { - # Three-char closing marker, close em and strong. - array_shift($token_stack); - $span = array_shift($text_stack); - $span = $this->runSpanGamut($span); - $span = "$span"; - $text_stack[0] .= $this->hashPart($span); - $em = ''; - $strong = ''; - } else { - # Other closing marker: close one em or strong and - # change current token state to match the other - $token_stack[0] = str_repeat($token{0}, 3-$token_len); - $tag = $token_len == 2 ? "strong" : "em"; - $span = $text_stack[0]; - $span = $this->runSpanGamut($span); - $span = "<$tag>$span"; - $text_stack[0] = $this->hashPart($span); - $$tag = ''; # $$tag stands for $em or $strong - } - $tree_char_em = false; - } else if ($token_len == 3) { - if ($em) { - # Reached closing marker for both em and strong. - # Closing strong marker: - for ($i = 0; $i < 2; ++$i) { - $shifted_token = array_shift($token_stack); - $tag = strlen($shifted_token) == 2 ? "strong" : "em"; - $span = array_shift($text_stack); - $span = $this->runSpanGamut($span); - $span = "<$tag>$span"; - $text_stack[0] .= $this->hashPart($span); - $$tag = ''; # $$tag stands for $em or $strong - } - } else { - # Reached opening three-char emphasis marker. Push on token - # stack; will be handled by the special condition above. - $em = $token{0}; - $strong = "$em$em"; - array_unshift($token_stack, $token); - array_unshift($text_stack, ''); - $tree_char_em = true; - } - } else if ($token_len == 2) { - if ($strong) { - # Unwind any dangling emphasis marker: - if (strlen($token_stack[0]) == 1) { - $text_stack[1] .= array_shift($token_stack); - $text_stack[0] .= array_shift($text_stack); - } - # Closing strong marker: - array_shift($token_stack); - $span = array_shift($text_stack); - $span = $this->runSpanGamut($span); - $span = "$span"; - $text_stack[0] .= $this->hashPart($span); - $strong = ''; - } else { - array_unshift($token_stack, $token); - array_unshift($text_stack, ''); - $strong = $token; - } - } else { - # Here $token_len == 1 - if ($em) { - if (strlen($token_stack[0]) == 1) { - # Closing emphasis marker: - array_shift($token_stack); - $span = array_shift($text_stack); - $span = $this->runSpanGamut($span); - $span = "$span"; - $text_stack[0] .= $this->hashPart($span); - $em = ''; - } else { - $text_stack[0] .= $token; - } - } else { - array_unshift($token_stack, $token); - array_unshift($text_stack, ''); - $em = $token; - } - } - } - return $text_stack[0]; - } - - - function doBlockQuotes($text) { - $text = preg_replace_callback('/ - ( # Wrap whole match in $1 - (?> - ^[ ]*>[ ]? # ">" at the start of a line - .+\n # rest of the first line - (.+\n)* # subsequent consecutive lines - \n* # blanks - )+ - ) - /xm', - array(&$this, '_doBlockQuotes_callback'), $text); - - return $text; - } - function _doBlockQuotes_callback($matches) { - $bq = $matches[1]; - # trim one level of quoting - trim whitespace-only lines - $bq = preg_replace('/^[ ]*>[ ]?|^[ ]+$/m', '', $bq); - $bq = $this->runBlockGamut($bq); # recurse - - $bq = preg_replace('/^/m', " ", $bq); - # These leading spaces cause problem with
     content, 
    -		# so we need to fix that:
    -		$bq = preg_replace_callback('{(\s*
    .+?
    )}sx', - array(&$this, '_doBlockQuotes_callback2'), $bq); - - return "\n". $this->hashBlock("
    \n$bq\n
    ")."\n\n"; - } - function _doBlockQuotes_callback2($matches) { - $pre = $matches[1]; - $pre = preg_replace('/^ /m', '', $pre); - return $pre; - } - - - function formParagraphs($text) { - # - # Params: - # $text - string to process with html

    tags - # - # Strip leading and trailing lines: - $text = preg_replace('/\A\n+|\n+\z/', '', $text); - - $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); - - # - # Wrap

    tags and unhashify HTML blocks - # - foreach ($grafs as $key => $value) { - if (!preg_match('/^B\x1A[0-9]+B$/', $value)) { - # Is a paragraph. - $value = $this->runSpanGamut($value); - $value = preg_replace('/^([ ]*)/', "

    ", $value); - $value .= "

    "; - $grafs[$key] = $this->unhash($value); - } - else { - # Is a block. - # Modify elements of @grafs in-place... - $graf = $value; - $block = $this->html_hashes[$graf]; - $graf = $block; -// if (preg_match('{ -// \A -// ( # $1 =
    tag -//
    ]* -// \b -// markdown\s*=\s* ([\'"]) # $2 = attr quote char -// 1 -// \2 -// [^>]* -// > -// ) -// ( # $3 = contents -// .* -// ) -// (
    ) # $4 = closing tag -// \z -// }xs', $block, $matches)) -// { -// list(, $div_open, , $div_content, $div_close) = $matches; -// -// # We can't call Markdown(), because that resets the hash; -// # that initialization code should be pulled into its own sub, though. -// $div_content = $this->hashHTMLBlocks($div_content); -// -// # Run document gamut methods on the content. -// foreach ($this->document_gamut as $method => $priority) { -// $div_content = $this->$method($div_content); -// } -// -// $div_open = preg_replace( -// '{\smarkdown\s*=\s*([\'"]).+?\1}', '', $div_open); -// -// $graf = $div_open . "\n" . $div_content . "\n" . $div_close; -// } - $grafs[$key] = $graf; - } - } - - return implode("\n\n", $grafs); - } - - - function encodeAttribute($text) { - # - # Encode text for a double-quoted HTML attribute. This function - # is *not* suitable for attributes enclosed in single quotes. - # - $text = $this->encodeAmpsAndAngles($text); - $text = str_replace('"', '"', $text); - return $text; - } - - - function encodeAmpsAndAngles($text) { - # - # Smart processing for ampersands and angle brackets that need to - # be encoded. Valid character entities are left alone unless the - # no-entities mode is set. - # - if ($this->no_entities) { - $text = str_replace('&', '&', $text); - } else { - # Ampersand-encoding based entirely on Nat Irons's Amputator - # MT plugin: - $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', - '&', $text);; - } - # Encode remaining <'s - $text = str_replace('<', '<', $text); - - return $text; - } - - - function doAutoLinks($text) { - $text = preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', - array(&$this, '_doAutoLinks_url_callback'), $text); - - # Email addresses: - $text = preg_replace_callback('{ - < - (?:mailto:)? - ( - (?: - [-!#$%&\'*+/=?^_`.{|}~\w\x80-\xFF]+ - | - ".*?" - ) - \@ - (?: - [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+ - | - \[[\d.a-fA-F:]+\] # IPv4 & IPv6 - ) - ) - > - }xi', - array(&$this, '_doAutoLinks_email_callback'), $text); - - return $text; - } - function _doAutoLinks_url_callback($matches) { - $url = $this->encodeAttribute($matches[1]); - $link = "$url"; - return $this->hashPart($link); - } - function _doAutoLinks_email_callback($matches) { - $address = $matches[1]; - $link = $this->encodeEmailAddress($address); - return $this->hashPart($link); - } - - - function encodeEmailAddress($addr) { - # - # Input: an email address, e.g. "foo@example.com" - # - # Output: the email address as a mailto link, with each character - # of the address encoded as either a decimal or hex entity, in - # the hopes of foiling most address harvesting spam bots. E.g.: - # - #

    foo@exampl - # e.com

    - # - # Based by a filter by Matthew Wickline, posted to BBEdit-Talk. - # With some optimizations by Milian Wolff. - # - $addr = "mailto:" . $addr; - $chars = preg_split('/(? $char) { - $ord = ord($char); - # Ignore non-ascii chars. - if ($ord < 128) { - $r = ($seed * (1 + $key)) % 100; # Pseudo-random function. - # roughly 10% raw, 45% hex, 45% dec - # '@' *must* be encoded. I insist. - if ($r > 90 && $char != '@') /* do nothing */; - else if ($r < 45) $chars[$key] = '&#x'.dechex($ord).';'; - else $chars[$key] = '&#'.$ord.';'; - } - } - - $addr = implode('', $chars); - $text = implode('', array_slice($chars, 7)); # text without `mailto:` - $addr = "$text"; - - return $addr; - } - - - function parseSpan($str) { - # - # Take the string $str and parse it into tokens, hashing embeded HTML, - # escaped characters and handling code spans. - # - $output = ''; - - $span_re = '{ - ( - \\\\'.$this->escape_chars_re.' - | - (?no_markup ? '' : ' - | - # comment - | - <\?.*?\?> | <%.*?%> # processing instruction - | - <[!$]?[-a-zA-Z0-9:_]+ # regular tags - (?> - \s - (?>[^"\'>]+|"[^"]*"|\'[^\']*\')* - )? - > - | - <[-a-zA-Z0-9:_]+\s*/> # xml-style empty tag - | - # closing tag - ').' - ) - }xs'; - - while (1) { - # - # Each loop iteration seach for either the next tag, the next - # openning code span marker, or the next escaped character. - # Each token is then passed to handleSpanToken. - # - $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE); - - # Create token from text preceding tag. - if ($parts[0] != "") { - $output .= $parts[0]; - } - - # Check if we reach the end. - if (isset($parts[1])) { - $output .= $this->handleSpanToken($parts[1], $parts[2]); - $str = $parts[2]; - } - else { - break; - } - } - - return $output; - } - - - function handleSpanToken($token, &$str) { - # - # Handle $token provided by parseSpan by determining its nature and - # returning the corresponding value that should replace it. - # - switch ($token{0}) { - case "\\": - return $this->hashPart("&#". ord($token{1}). ";"); - case "`": - # Search for end marker in remaining text. - if (preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', - $str, $matches)) - { - $str = $matches[2]; - $codespan = $this->makeCodeSpan($matches[1]); - return $this->hashPart($codespan); - } - return $token; // return as text since no ending marker found. - default: - return $this->hashPart($token); - } - } - - - function outdent($text) { - # - # Remove one level of line-leading tabs or spaces - # - return preg_replace('/^(\t|[ ]{1,'.$this->tab_width.'})/m', '', $text); - } - - - # String length function for detab. `_initDetab` will create a function to - # hanlde UTF-8 if the default function does not exist. - var $utf8_strlen = 'mb_strlen'; - - function detab($text) { - # - # Replace tabs with the appropriate amount of space. - # - # For each line we separate the line in blocks delemited by - # tab characters. Then we reconstruct every line by adding the - # appropriate number of space between each blocks. - - $text = preg_replace_callback('/^.*\t.*$/m', - array(&$this, '_detab_callback'), $text); - - return $text; - } - function _detab_callback($matches) { - $line = $matches[0]; - $strlen = $this->utf8_strlen; # strlen function for UTF-8. - - # Split in blocks. - $blocks = explode("\t", $line); - # Add each blocks to the line. - $line = $blocks[0]; - unset($blocks[0]); # Do not add first block twice. - foreach ($blocks as $block) { - # Calculate amount of space, insert spaces, insert block. - $amount = $this->tab_width - - $strlen($line, 'UTF-8') % $this->tab_width; - $line .= str_repeat(" ", $amount) . $block; - } - return $line; - } - function _initDetab() { - # - # Check for the availability of the function in the `utf8_strlen` property - # (initially `mb_strlen`). If the function is not available, create a - # function that will loosely count the number of UTF-8 characters with a - # regular expression. - # - if (function_exists($this->utf8_strlen)) return; - $this->utf8_strlen = create_function('$text', 'return preg_match_all( - "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", - $text, $m);'); - } - - - function unhash($text) { - # - # Swap back in all the tags hashed by _HashHTMLBlocks. - # - return preg_replace_callback('/(.)\x1A[0-9]+\1/', - array(&$this, '_unhash_callback'), $text); - } - function _unhash_callback($matches) { - return $this->html_hashes[$matches[0]]; - } - -} - - -# -# Markdown Extra Parser Class -# - -class MarkdownExtra_Parser extends Markdown_Parser { - - ### Configuration Variables ### - - # Prefix for footnote ids. - var $fn_id_prefix = ""; - - # Optional title attribute for footnote links and backlinks. - var $fn_link_title = MARKDOWN_FN_LINK_TITLE; - var $fn_backlink_title = MARKDOWN_FN_BACKLINK_TITLE; - - # Optional class attribute for footnote links and backlinks. - var $fn_link_class = MARKDOWN_FN_LINK_CLASS; - var $fn_backlink_class = MARKDOWN_FN_BACKLINK_CLASS; - - # Optional class prefix for fenced code block. - var $code_class_prefix = MARKDOWN_CODE_CLASS_PREFIX; - # Class attribute for code blocks goes on the `code` tag; - # setting this to true will put attributes on the `pre` tag instead. - var $code_attr_on_pre = MARKDOWN_CODE_ATTR_ON_PRE; - - # Predefined abbreviations. - var $predef_abbr = array(); - - - ### Parser Implementation ### - - function MarkdownExtra_Parser() { - # - # Constructor function. Initialize the parser object. - # - # Add extra escapable characters before parent constructor - # initialize the table. - $this->escape_chars .= ':|'; - - # Insert extra document, block, and span transformations. - # Parent constructor will do the sorting. - $this->document_gamut += array( - "doFencedCodeBlocks" => 5, - "stripFootnotes" => 15, - "stripAbbreviations" => 25, - "appendFootnotes" => 50, - ); - $this->block_gamut += array( - "doFencedCodeBlocks" => 5, - "doTables" => 15, - "doDefLists" => 45, - ); - $this->span_gamut += array( - "doFootnotes" => 5, - "doAbbreviations" => 70, - ); - - parent::Markdown_Parser(); - } - - - # Extra variables used during extra transformations. - var $footnotes = array(); - var $footnotes_ordered = array(); - var $footnotes_ref_count = array(); - var $footnotes_numbers = array(); - var $abbr_desciptions = array(); - var $abbr_word_re = ''; - - # Give the current footnote number. - var $footnote_counter = 1; - - - function setup() { - # - # Setting up Extra-specific variables. - # - parent::setup(); - - $this->footnotes = array(); - $this->footnotes_ordered = array(); - $this->footnotes_ref_count = array(); - $this->footnotes_numbers = array(); - $this->abbr_desciptions = array(); - $this->abbr_word_re = ''; - $this->footnote_counter = 1; - - foreach ($this->predef_abbr as $abbr_word => $abbr_desc) { - if ($this->abbr_word_re) - $this->abbr_word_re .= '|'; - $this->abbr_word_re .= preg_quote($abbr_word); - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); - } - } - - function teardown() { - # - # Clearing Extra-specific variables. - # - $this->footnotes = array(); - $this->footnotes_ordered = array(); - $this->footnotes_ref_count = array(); - $this->footnotes_numbers = array(); - $this->abbr_desciptions = array(); - $this->abbr_word_re = ''; - - parent::teardown(); - } - - - ### Extra Attribute Parser ### - - # Expression to use to catch attributes (includes the braces) - var $id_class_attr_catch_re = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}'; - # Expression to use when parsing in a context when no capture is desired - var $id_class_attr_nocatch_re = '\{(?:[ ]*[#.][-_:a-zA-Z0-9]+){1,}[ ]*\}'; - - function doExtraAttributes($tag_name, $attr) { - # - # Parse attributes caught by the $this->id_class_attr_catch_re expression - # and return the HTML-formatted list of attributes. - # - # Currently supported attributes are .class and #id. - # - if (empty($attr)) return ""; - - # Split on components - preg_match_all("/[.#][-_:a-zA-Z0-9]+/", $attr, $matches); - $elements = $matches[0]; - - # handle classes and ids (only first id taken into account) - $classes = array(); - $id = false; - foreach ($elements as $element) { - if ($element{0} == '.') { - $classes[] = substr($element, 1); - } else if ($element{0} == '#') { - if ($id === false) $id = substr($element, 1); - } - } - - # compose attributes as string - $attr_str = ""; - if (!empty($id)) { - $attr_str .= ' id="'.$id.'"'; - } - if (!empty($classes)) { - $attr_str .= ' class="'.implode(" ", $classes).'"'; - } - return $attr_str; - } - - - ### HTML Block Parser ### - - # Tags that are always treated as block tags: - var $block_tags_re = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|address|form|fieldset|iframe|hr|legend|article|section|nav|aside|hgroup|header|footer|figcaption'; - - # Tags treated as block tags only if the opening tag is alone on its line: - var $context_block_tags_re = 'script|noscript|ins|del|iframe|object|source|track|param|math|svg|canvas|audio|video'; - - # Tags where markdown="1" default to span mode: - var $contain_span_tags_re = 'p|h[1-6]|li|dd|dt|td|th|legend|address'; - - # Tags which must not have their contents modified, no matter where - # they appear: - var $clean_tags_re = 'script|math|svg'; - - # Tags that do not need to be closed. - var $auto_close_tags_re = 'hr|img|param|source|track'; - - - function hashHTMLBlocks($text) { - # - # Hashify HTML Blocks and "clean tags". - # - # We only want to do this for block-level HTML tags, such as headers, - # lists, and tables. That's because we still want to wrap

    s around - # "paragraphs" that are wrapped in non-block-level tags, such as anchors, - # phrase emphasis, and spans. The list of tags we're looking for is - # hard-coded. - # - # This works by calling _HashHTMLBlocks_InMarkdown, which then calls - # _HashHTMLBlocks_InHTML when it encounter block tags. When the markdown="1" - # attribute is found within a tag, _HashHTMLBlocks_InHTML calls back - # _HashHTMLBlocks_InMarkdown to handle the Markdown syntax within the tag. - # These two functions are calling each other. It's recursive! - # - if ($this->no_markup) return $text; - - # - # Call the HTML-in-Markdown hasher. - # - list($text, ) = $this->_hashHTMLBlocks_inMarkdown($text); - - return $text; - } - function _hashHTMLBlocks_inMarkdown($text, $indent = 0, - $enclosing_tag_re = '', $span = false) - { - # - # Parse markdown text, calling _HashHTMLBlocks_InHTML for block tags. - # - # * $indent is the number of space to be ignored when checking for code - # blocks. This is important because if we don't take the indent into - # account, something like this (which looks right) won't work as expected: - # - #

    - #
    - # Hello World. <-- Is this a Markdown code block or text? - #
    <-- Is this a Markdown code block or a real tag? - #
    - # - # If you don't like this, just don't indent the tag on which - # you apply the markdown="1" attribute. - # - # * If $enclosing_tag_re is not empty, stops at the first unmatched closing - # tag with that name. Nested tags supported. - # - # * If $span is true, text inside must treated as span. So any double - # newline will be replaced by a single newline so that it does not create - # paragraphs. - # - # Returns an array of that form: ( processed text , remaining text ) - # - if ($text === '') return array('', ''); - - # Regex to check for the presense of newlines around a block tag. - $newline_before_re = '/(?:^\n?|\n\n)*$/'; - $newline_after_re = - '{ - ^ # Start of text following the tag. - (?>[ ]*)? # Optional comment. - [ ]*\n # Must be followed by newline. - }xs'; - - # Regex to match any tag. - $block_tag_re = - '{ - ( # $2: Capture whole tag. - # Tag name. - '.$this->block_tags_re.' | - '.$this->context_block_tags_re.' | - '.$this->clean_tags_re.' | - (?!\s)'.$enclosing_tag_re.' - ) - (?: - (?=[\s"\'/a-zA-Z0-9]) # Allowed characters after tag name. - (?> - ".*?" | # Double quotes (can contain `>`) - \'.*?\' | # Single quotes (can contain `>`) - .+? # Anything but quotes and `>`. - )*? - )? - > # End of tag. - | - # HTML Comment - | - <\?.*?\?> | <%.*?%> # Processing instruction - | - # CData Block - | - # Code span marker - `+ - '. ( !$span ? ' # If not in span. - | - # Indented code block - (?: ^[ ]*\n | ^ | \n[ ]*\n ) - [ ]{'.($indent+4).'}[^\n]* \n - (?> - (?: [ ]{'.($indent+4).'}[^\n]* | [ ]* ) \n - )* - | - # Fenced code block marker - (?<= ^ | \n ) - [ ]{0,'.($indent+3).'}~{3,} - [ ]* - (?: - [.]?[-_:a-zA-Z0-9]+ # standalone class name - | - '.$this->id_class_attr_nocatch_re.' # extra attributes - )? - [ ]* - \n - ' : '' ). ' # End (if not is span). - ) - }xs'; - - - $depth = 0; # Current depth inside the tag tree. - $parsed = ""; # Parsed text that will be returned. - - # - # Loop through every tag until we find the closing tag of the parent - # or loop until reaching the end of text if no parent tag specified. - # - do { - # - # Split the text using the first $tag_match pattern found. - # Text before pattern will be first in the array, text after - # pattern will be at the end, and between will be any catches made - # by the pattern. - # - $parts = preg_split($block_tag_re, $text, 2, - PREG_SPLIT_DELIM_CAPTURE); - - # If in Markdown span mode, add a empty-string span-level hash - # after each newline to prevent triggering any block element. - if ($span) { - $void = $this->hashPart("", ':'); - $newline = "$void\n"; - $parts[0] = $void . str_replace("\n", $newline, $parts[0]) . $void; - } - - $parsed .= $parts[0]; # Text before current tag. - - # If end of $text has been reached. Stop loop. - if (count($parts) < 3) { - $text = ""; - break; - } - - $tag = $parts[1]; # Tag to handle. - $text = $parts[2]; # Remaining text after current tag. - $tag_re = preg_quote($tag); # For use in a regular expression. - - # - # Check for: Code span marker - # - if ($tag{0} == "`") { - # Find corresponding end marker. - $tag_re = preg_quote($tag); - if (preg_match('{^(?>.+?|\n(?!\n))*?(?.*\n)*?[ ]{'.($fence_indent).'}'.$fence_re.'[ ]*(?:\n|$)}', $text, - $matches)) - { - # End marker found: pass text unchanged until marker. - $parsed .= $tag . $matches[0]; - $text = substr($text, strlen($matches[0])); - } - else { - # No end marker: just skip it. - $parsed .= $tag; - } - } - # - # Check for: Indented code block. - # - else if ($tag{0} == "\n" || $tag{0} == " ") { - # Indented code block: pass it unchanged, will be handled - # later. - $parsed .= $tag; - } - # - # Check for: Opening Block level tag or - # Opening Context Block tag (like ins and del) - # used as a block tag (tag is alone on it's line). - # - else if (preg_match('{^<(?:'.$this->block_tags_re.')\b}', $tag) || - ( preg_match('{^<(?:'.$this->context_block_tags_re.')\b}', $tag) && - preg_match($newline_before_re, $parsed) && - preg_match($newline_after_re, $text) ) - ) - { - # Need to parse tag and following text using the HTML parser. - list($block_text, $text) = - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashBlock", true); - - # Make sure it stays outside of any paragraph by adding newlines. - $parsed .= "\n\n$block_text\n\n"; - } - # - # Check for: Clean tag (like script, math) - # HTML Comments, processing instructions. - # - else if (preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) || - $tag{1} == '!' || $tag{1} == '?') - { - # Need to parse tag and following text using the HTML parser. - # (don't check for markdown attribute) - list($block_text, $text) = - $this->_hashHTMLBlocks_inHTML($tag . $text, "hashClean", false); - - $parsed .= $block_text; - } - # - # Check for: Tag with same name as enclosing tag. - # - else if ($enclosing_tag_re !== '' && - # Same name as enclosing tag. - preg_match('{^= 0); - - return array($parsed, $text); - } - function _hashHTMLBlocks_inHTML($text, $hash_method, $md_attr) { - # - # Parse HTML, calling _HashHTMLBlocks_InMarkdown for block tags. - # - # * Calls $hash_method to convert any blocks. - # * Stops when the first opening tag closes. - # * $md_attr indicate if the use of the `markdown="1"` attribute is allowed. - # (it is not inside clean tags) - # - # Returns an array of that form: ( processed text , remaining text ) - # - if ($text === '') return array('', ''); - - # Regex to match `markdown` attribute inside of a tag. - $markdown_attr_re = ' - { - \s* # Eat whitespace before the `markdown` attribute - markdown - \s*=\s* - (?> - (["\']) # $1: quote delimiter - (.*?) # $2: attribute value - \1 # matching delimiter - | - ([^\s>]*) # $3: unquoted attribute value - ) - () # $4: make $3 always defined (avoid warnings) - }xs'; - - # Regex to match any tag. - $tag_re = '{ - ( # $2: Capture whole tag. - - ".*?" | # Double quotes (can contain `>`) - \'.*?\' | # Single quotes (can contain `>`) - .+? # Anything but quotes and `>`. - )*? - )? - > # End of tag. - | - # HTML Comment - | - <\?.*?\?> | <%.*?%> # Processing instruction - | - # CData Block - ) - }xs'; - - $original_text = $text; # Save original text in case of faliure. - - $depth = 0; # Current depth inside the tag tree. - $block_text = ""; # Temporary text holder for current text. - $parsed = ""; # Parsed text that will be returned. - - # - # Get the name of the starting tag. - # (This pattern makes $base_tag_name_re safe without quoting.) - # - if (preg_match('/^<([\w:$]*)\b/', $text, $matches)) - $base_tag_name_re = $matches[1]; - - # - # Loop through every tag until we find the corresponding closing tag. - # - do { - # - # Split the text using the first $tag_match pattern found. - # Text before pattern will be first in the array, text after - # pattern will be at the end, and between will be any catches made - # by the pattern. - # - $parts = preg_split($tag_re, $text, 2, PREG_SPLIT_DELIM_CAPTURE); - - if (count($parts) < 3) { - # - # End of $text reached with unbalenced tag(s). - # In that case, we return original text unchanged and pass the - # first character as filtered to prevent an infinite loop in the - # parent function. - # - return array($original_text{0}, substr($original_text, 1)); - } - - $block_text .= $parts[0]; # Text before current tag. - $tag = $parts[1]; # Tag to handle. - $text = $parts[2]; # Remaining text after current tag. - - # - # Check for: Auto-close tag (like
    ) - # Comments and Processing Instructions. - # - if (preg_match('{^auto_close_tags_re.')\b}', $tag) || - $tag{1} == '!' || $tag{1} == '?') - { - # Just add the tag to the block as if it was text. - $block_text .= $tag; - } - else { - # - # Increase/decrease nested tag count. Only do so if - # the tag's name match base tag's. - # - if (preg_match('{^mode = $attr_m[2] . $attr_m[3]; - $span_mode = $this->mode == 'span' || $this->mode != 'block' && - preg_match('{^<(?:'.$this->contain_span_tags_re.')\b}', $tag); - - # Calculate indent before tag. - if (preg_match('/(?:^|\n)( *?)(?! ).*?$/', $block_text, $matches)) { - $strlen = $this->utf8_strlen; - $indent = $strlen($matches[1], 'UTF-8'); - } else { - $indent = 0; - } - - # End preceding block with this tag. - $block_text .= $tag; - $parsed .= $this->$hash_method($block_text); - - # Get enclosing tag name for the ParseMarkdown function. - # (This pattern makes $tag_name_re safe without quoting.) - preg_match('/^<([\w:$]*)\b/', $tag, $matches); - $tag_name_re = $matches[1]; - - # Parse the content using the HTML-in-Markdown parser. - list ($block_text, $text) - = $this->_hashHTMLBlocks_inMarkdown($text, $indent, - $tag_name_re, $span_mode); - - # Outdent markdown text. - if ($indent > 0) { - $block_text = preg_replace("/^[ ]{1,$indent}/m", "", - $block_text); - } - - # Append tag content to parsed text. - if (!$span_mode) $parsed .= "\n\n$block_text\n\n"; - else $parsed .= "$block_text"; - - # Start over with a new block. - $block_text = ""; - } - else $block_text .= $tag; - } - - } while ($depth > 0); - - # - # Hash last block text that wasn't processed inside the loop. - # - $parsed .= $this->$hash_method($block_text); - - return array($parsed, $text); - } - - - function hashClean($text) { - # - # Called whenever a tag must be hashed when a function inserts a "clean" tag - # in $text, it passes through this function and is automaticaly escaped, - # blocking invalid nested overlap. - # - return $this->hashPart($text, 'C'); - } - - - function doHeaders($text) { - # - # Redefined to add id and class attribute support. - # - # Setext-style headers: - # Header 1 {#header1} - # ======== - # - # Header 2 {#header2 .class1 .class2} - # -------- - # - $text = preg_replace_callback( - '{ - (^.+?) # $1: Header text - (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes - [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer - }mx', - array(&$this, '_doHeaders_callback_setext'), $text); - - # atx-style headers: - # # Header 1 {#header1} - # ## Header 2 {#header2} - # ## Header 2 with closing hashes ## {#header3.class1.class2} - # ... - # ###### Header 6 {.class2} - # - $text = preg_replace_callback('{ - ^(\#{1,6}) # $1 = string of #\'s - [ ]* - (.+?) # $2 = Header text - [ ]* - \#* # optional closing #\'s (not counted) - (?:[ ]+ '.$this->id_class_attr_catch_re.' )? # $3 = id/class attributes - [ ]* - \n+ - }xm', - array(&$this, '_doHeaders_callback_atx'), $text); - - return $text; - } - function _doHeaders_callback_setext($matches) { - if ($matches[3] == '-' && preg_match('{^- }', $matches[1])) - return $matches[0]; - $level = $matches[3]{0} == '=' ? 1 : 2; - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]); - $block = "".$this->runSpanGamut($matches[1]).""; - return "\n" . $this->hashBlock($block) . "\n\n"; - } - function _doHeaders_callback_atx($matches) { - $level = strlen($matches[1]); - $attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]); - $block = "".$this->runSpanGamut($matches[2]).""; - return "\n" . $this->hashBlock($block) . "\n\n"; - } - - - function doTables($text) { - # - # Form HTML tables. - # - $less_than_tab = $this->tab_width - 1; - # - # Find tables with leading pipe. - # - # | Header 1 | Header 2 - # | -------- | -------- - # | Cell 1 | Cell 2 - # | Cell 3 | Cell 4 - # - $text = preg_replace_callback(' - { - ^ # Start of a line - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - [|] # Optional leading pipe (present) - (.+) \n # $1: Header row (at least one pipe) - - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - [|] ([ ]*[-:]+[-| :]*) \n # $2: Header underline - - ( # $3: Cells - (?> - [ ]* # Allowed whitespace. - [|] .* \n # Row content. - )* - ) - (?=\n|\Z) # Stop at final double newline. - }xm', - array(&$this, '_doTable_leadingPipe_callback'), $text); - - # - # Find tables without leading pipe. - # - # Header 1 | Header 2 - # -------- | -------- - # Cell 1 | Cell 2 - # Cell 3 | Cell 4 - # - $text = preg_replace_callback(' - { - ^ # Start of a line - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - (\S.*[|].*) \n # $1: Header row (at least one pipe) - - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - ([-:]+[ ]*[|][-| :]*) \n # $2: Header underline - - ( # $3: Cells - (?> - .* [|] .* \n # Row content - )* - ) - (?=\n|\Z) # Stop at final double newline. - }xm', - array(&$this, '_DoTable_callback'), $text); - - return $text; - } - function _doTable_leadingPipe_callback($matches) { - $head = $matches[1]; - $underline = $matches[2]; - $content = $matches[3]; - - # Remove leading pipe for each row. - $content = preg_replace('/^ *[|]/m', '', $content); - - return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); - } - function _doTable_callback($matches) { - $head = $matches[1]; - $underline = $matches[2]; - $content = $matches[3]; - - # Remove any tailing pipes for each line. - $head = preg_replace('/[|] *$/m', '', $head); - $underline = preg_replace('/[|] *$/m', '', $underline); - $content = preg_replace('/[|] *$/m', '', $content); - - # Reading alignement from header underline. - $separators = preg_split('/ *[|] */', $underline); - foreach ($separators as $n => $s) { - if (preg_match('/^ *-+: *$/', $s)) $attr[$n] = ' align="right"'; - else if (preg_match('/^ *:-+: *$/', $s))$attr[$n] = ' align="center"'; - else if (preg_match('/^ *:-+ *$/', $s)) $attr[$n] = ' align="left"'; - else $attr[$n] = ''; - } - - # Parsing span elements, including code spans, character escapes, - # and inline HTML tags, so that pipes inside those gets ignored. - $head = $this->parseSpan($head); - $headers = preg_split('/ *[|] */', $head); - $col_count = count($headers); - - # Write column headers. - $text = "\n"; - $text .= "\n"; - $text .= "\n"; - foreach ($headers as $n => $header) - $text .= " ".$this->runSpanGamut(trim($header))."\n"; - $text .= "\n"; - $text .= "\n"; - - # Split content by row. - $rows = explode("\n", trim($content, "\n")); - - $text .= "\n"; - foreach ($rows as $row) { - # Parsing span elements, including code spans, character escapes, - # and inline HTML tags, so that pipes inside those gets ignored. - $row = $this->parseSpan($row); - - # Split row by cell. - $row_cells = preg_split('/ *[|] */', $row, $col_count); - $row_cells = array_pad($row_cells, $col_count, ''); - - $text .= "\n"; - foreach ($row_cells as $n => $cell) - $text .= " ".$this->runSpanGamut(trim($cell))."\n"; - $text .= "\n"; - } - $text .= "\n"; - $text .= "
    "; - - return $this->hashBlock($text) . "\n"; - } - - - function doDefLists($text) { - # - # Form HTML definition lists. - # - $less_than_tab = $this->tab_width - 1; - - # Re-usable pattern to match any entire dl list: - $whole_list_re = '(?> - ( # $1 = whole list - ( # $2 - [ ]{0,'.$less_than_tab.'} - ((?>.*\S.*\n)+) # $3 = defined term - \n? - [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition - ) - (?s:.+?) - ( # $4 - \z - | - \n{2,} - (?=\S) - (?! # Negative lookahead for another term - [ ]{0,'.$less_than_tab.'} - (?: \S.*\n )+? # defined term - \n? - [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition - ) - (?! # Negative lookahead for another definition - [ ]{0,'.$less_than_tab.'}:[ ]+ # colon starting definition - ) - ) - ) - )'; // mx - - $text = preg_replace_callback('{ - (?>\A\n?|(?<=\n\n)) - '.$whole_list_re.' - }mx', - array(&$this, '_doDefLists_callback'), $text); - - return $text; - } - function _doDefLists_callback($matches) { - # Re-usable patterns to match list item bullets and number markers: - $list = $matches[1]; - - # Turn double returns into triple returns, so that we can make a - # paragraph for the last item in a list, if necessary: - $result = trim($this->processDefListItems($list)); - $result = "
    \n" . $result . "\n
    "; - return $this->hashBlock($result) . "\n\n"; - } - - - function processDefListItems($list_str) { - # - # Process the contents of a single definition list, splitting it - # into individual term and definition list items. - # - $less_than_tab = $this->tab_width - 1; - - # trim trailing blank lines: - $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); - - # Process definition terms. - $list_str = preg_replace_callback('{ - (?>\A\n?|\n\n+) # leading line - ( # definition terms = $1 - [ ]{0,'.$less_than_tab.'} # leading whitespace - (?![:][ ]|[ ]) # negative lookahead for a definition - # mark (colon) or more whitespace. - (?> \S.* \n)+? # actual term (not whitespace). - ) - (?=\n?[ ]{0,3}:[ ]) # lookahead for following line feed - # with a definition mark. - }xm', - array(&$this, '_processDefListItems_callback_dt'), $list_str); - - # Process actual definitions. - $list_str = preg_replace_callback('{ - \n(\n+)? # leading line = $1 - ( # marker space = $2 - [ ]{0,'.$less_than_tab.'} # whitespace before colon - [:][ ]+ # definition mark (colon) - ) - ((?s:.+?)) # definition text = $3 - (?= \n+ # stop at next definition mark, - (?: # next term or end of text - [ ]{0,'.$less_than_tab.'} [:][ ] | -
    | \z - ) - ) - }xm', - array(&$this, '_processDefListItems_callback_dd'), $list_str); - - return $list_str; - } - function _processDefListItems_callback_dt($matches) { - $terms = explode("\n", trim($matches[1])); - $text = ''; - foreach ($terms as $term) { - $term = $this->runSpanGamut(trim($term)); - $text .= "\n
    " . $term . "
    "; - } - return $text . "\n"; - } - function _processDefListItems_callback_dd($matches) { - $leading_line = $matches[1]; - $marker_space = $matches[2]; - $def = $matches[3]; - - if ($leading_line || preg_match('/\n{2,}/', $def)) { - # Replace marker with the appropriate whitespace indentation - $def = str_repeat(' ', strlen($marker_space)) . $def; - $def = $this->runBlockGamut($this->outdent($def . "\n\n")); - $def = "\n". $def ."\n"; - } - else { - $def = rtrim($def); - $def = $this->runSpanGamut($this->outdent($def)); - } - - return "\n
    " . $def . "
    \n"; - } - - - function doFencedCodeBlocks($text) { - # - # Adding the fenced code block syntax to regular Markdown: - # - # ~~~ - # Code block - # ~~~ - # - $less_than_tab = $this->tab_width; - - $text = preg_replace_callback('{ - (?:\n|\A) - # 1: Opening marker - ( - ~{3,} # Marker: three tilde or more. - ) - [ ]* - (?: - [.]?([-_:a-zA-Z0-9]+) # 2: standalone class name - | - '.$this->id_class_attr_catch_re.' # 3: Extra attributes - )? - [ ]* \n # Whitespace and newline following marker. - - # 4: Content - ( - (?> - (?!\1 [ ]* \n) # Not a closing marker. - .*\n+ - )+ - ) - - # Closing marker. - \1 [ ]* \n - }xm', - array(&$this, '_doFencedCodeBlocks_callback'), $text); - - return $text; - } - function _doFencedCodeBlocks_callback($matches) { - $classname =& $matches[2]; - $attrs =& $matches[3]; - $codeblock = $matches[4]; - $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); - $codeblock = preg_replace_callback('/^\n+/', - array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock); - - if ($classname != "") { - if ($classname{0} == '.') - $classname = substr($classname, 1); - $attr_str = ' class="'.$this->code_class_prefix.$classname.'"'; - } else { - $attr_str = $this->doExtraAttributes($this->code_attr_on_pre ? "pre" : "code", $attrs); - } - $pre_attr_str = $this->code_attr_on_pre ? $attr_str : ''; - $code_attr_str = $this->code_attr_on_pre ? '' : $attr_str; - $codeblock = "$codeblock
    "; - - return "\n\n".$this->hashBlock($codeblock)."\n\n"; - } - function _doFencedCodeBlocks_newlines($matches) { - return str_repeat("empty_element_suffix", - strlen($matches[0])); - } - - - # - # Redefining emphasis markers so that emphasis by underscore does not - # work in the middle of a word. - # - var $em_relist = array( - '' => '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? '(?:(? '(?<=\S|^)(? '(?<=\S|^)(? tags - # - # Strip leading and trailing lines: - $text = preg_replace('/\A\n+|\n+\z/', '', $text); - - $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); - - # - # Wrap

    tags and unhashify HTML blocks - # - foreach ($grafs as $key => $value) { - $value = trim($this->runSpanGamut($value)); - - # Check if this should be enclosed in a paragraph. - # Clean tag hashes & block tag hashes are left alone. - $is_p = !preg_match('/^B\x1A[0-9]+B|^C\x1A[0-9]+C$/', $value); - - if ($is_p) { - $value = "

    $value

    "; - } - $grafs[$key] = $value; - } - - # Join grafs in one text, then unhash HTML tags. - $text = implode("\n\n", $grafs); - - # Finish by removing any tag hashes still present in $text. - $text = $this->unhash($text); - - return $text; - } - - - ### Footnotes - - function stripFootnotes($text) { - # - # Strips link definitions from text, stores the URLs and titles in - # hash references. - # - $less_than_tab = $this->tab_width - 1; - - # Link defs are in the form: [^id]: url "optional title" - $text = preg_replace_callback('{ - ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 - [ ]* - \n? # maybe *one* newline - ( # text = $2 (no blank lines allowed) - (?: - .+ # actual text - | - \n # newlines but - (?!\[\^.+?\]:\s)# negative lookahead for footnote marker. - (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed - # by non-indented content - )* - ) - }xm', - array(&$this, '_stripFootnotes_callback'), - $text); - return $text; - } - function _stripFootnotes_callback($matches) { - $note_id = $this->fn_id_prefix . $matches[1]; - $this->footnotes[$note_id] = $this->outdent($matches[2]); - return ''; # String that will replace the block - } - - - function doFootnotes($text) { - # - # Replace footnote references in $text [^id] with a special text-token - # which will be replaced by the actual footnote marker in appendFootnotes. - # - if (!$this->in_anchor) { - $text = preg_replace('{\[\^(.+?)\]}', "F\x1Afn:\\1\x1A:", $text); - } - return $text; - } - - - function appendFootnotes($text) { - # - # Append footnote list to text. - # - $text = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', - array(&$this, '_appendFootnotes_callback'), $text); - - if (!empty($this->footnotes_ordered)) { - $text .= "\n\n"; - $text .= "
    \n"; - $text .= "empty_element_suffix ."\n"; - $text .= "
      \n\n"; - - $attr = " rev=\"footnote\""; - if ($this->fn_backlink_class != "") { - $class = $this->fn_backlink_class; - $class = $this->encodeAttribute($class); - $attr .= " class=\"$class\""; - } - if ($this->fn_backlink_title != "") { - $title = $this->fn_backlink_title; - $title = $this->encodeAttribute($title); - $attr .= " title=\"$title\""; - } - $num = 0; - - while (!empty($this->footnotes_ordered)) { - $footnote = reset($this->footnotes_ordered); - $note_id = key($this->footnotes_ordered); - unset($this->footnotes_ordered[$note_id]); - $ref_count = $this->footnotes_ref_count[$note_id]; - unset($this->footnotes_ref_count[$note_id]); - unset($this->footnotes[$note_id]); - - $footnote .= "\n"; # Need to append newline before parsing. - $footnote = $this->runBlockGamut("$footnote\n"); - $footnote = preg_replace_callback('{F\x1Afn:(.*?)\x1A:}', - array(&$this, '_appendFootnotes_callback'), $footnote); - - $attr = str_replace("%%", ++$num, $attr); - $note_id = $this->encodeAttribute($note_id); - - # Prepare backlink, multiple backlinks if multiple references - $backlink = ""; - for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { - $backlink .= " "; - } - # Add backlink to last paragraph; create new paragraph if needed. - if (preg_match('{

      $}', $footnote)) { - $footnote = substr($footnote, 0, -4) . " $backlink

      "; - } else { - $footnote .= "\n\n

      $backlink

      "; - } - - $text .= "
    1. \n"; - $text .= $footnote . "\n"; - $text .= "
    2. \n\n"; - } - - $text .= "
    \n"; - $text .= "
    "; - } - return $text; - } - function _appendFootnotes_callback($matches) { - $node_id = $this->fn_id_prefix . $matches[1]; - - # Create footnote marker only if it has a corresponding footnote *and* - # the footnote hasn't been used by another marker. - if (isset($this->footnotes[$node_id])) { - $num =& $this->footnotes_numbers[$node_id]; - if (!isset($num)) { - # Transfer footnote content to the ordered list and give it its - # number - $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id]; - $this->footnotes_ref_count[$node_id] = 1; - $num = $this->footnote_counter++; - $ref_count_mark = ''; - } else { - $ref_count_mark = $this->footnotes_ref_count[$node_id] += 1; - } - - $attr = " rel=\"footnote\""; - if ($this->fn_link_class != "") { - $class = $this->fn_link_class; - $class = $this->encodeAttribute($class); - $attr .= " class=\"$class\""; - } - if ($this->fn_link_title != "") { - $title = $this->fn_link_title; - $title = $this->encodeAttribute($title); - $attr .= " title=\"$title\""; - } - - $attr = str_replace("%%", $num, $attr); - $node_id = $this->encodeAttribute($node_id); - - return - "". - "$num". - ""; - } - - return "[^".$matches[1]."]"; - } - - - ### Abbreviations ### - - function stripAbbreviations($text) { - # - # Strips abbreviations from text, stores titles in hash references. - # - $less_than_tab = $this->tab_width - 1; - - # Link defs are in the form: [id]*: url "optional title" - $text = preg_replace_callback('{ - ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 - (.*) # text = $2 (no blank lines allowed) - }xm', - array(&$this, '_stripAbbreviations_callback'), - $text); - return $text; - } - function _stripAbbreviations_callback($matches) { - $abbr_word = $matches[1]; - $abbr_desc = $matches[2]; - if ($this->abbr_word_re) - $this->abbr_word_re .= '|'; - $this->abbr_word_re .= preg_quote($abbr_word); - $this->abbr_desciptions[$abbr_word] = trim($abbr_desc); - return ''; # String that will replace the block - } - - - function doAbbreviations($text) { - # - # Find defined abbreviations in text and wrap them in elements. - # - if ($this->abbr_word_re) { - // cannot use the /x modifier because abbr_word_re may - // contain significant spaces: - $text = preg_replace_callback('{'. - '(?abbr_word_re.')'. - '(?![\w\x1A])'. - '}', - array(&$this, '_doAbbreviations_callback'), $text); - } - return $text; - } - function _doAbbreviations_callback($matches) { - $abbr = $matches[0]; - if (isset($this->abbr_desciptions[$abbr])) { - $desc = $this->abbr_desciptions[$abbr]; - if (empty($desc)) { - return $this->hashPart("$abbr"); - } else { - $desc = $this->encodeAttribute($desc); - return $this->hashPart("$abbr"); - } - } else { - return $matches[0]; - } - } - -} - - -/* - -PHP Markdown Extra -================== - -Description ------------ - -This is a PHP port of the original Markdown formatter written in Perl -by John Gruber. This special "Extra" version of PHP Markdown features -further enhancements to the syntax for making additional constructs -such as tables and definition list. - -Markdown is a text-to-HTML filter; it translates an easy-to-read / -easy-to-write structured text format into HTML. Markdown's text format -is mostly similar to that of plain text email, and supports features such -as headers, *emphasis*, code blocks, blockquotes, and links. - -Markdown's syntax is designed not as a generic markup language, but -specifically to serve as a front-end to (X)HTML. You can use span-level -HTML tags anywhere in a Markdown document, and you can use block level -HTML tags (like
    and as well). - -For more information about Markdown's syntax, see: - - - - -Bugs ----- - -To file bug reports please send email to: - - - -Please include with your report: (1) the example input; (2) the output you -expected; (3) the output Markdown actually produced. - - -Version History ---------------- - -See the readme file for detailed release notes for this version. - - -Copyright and License ---------------------- - -PHP Markdown & Extra -Copyright (c) 2004-2013 Michel Fortin - -All rights reserved. - -Based on Markdown -Copyright (c) 2003-2006 John Gruber - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -* Neither the name "Markdown" nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. - -This software is provided by the copyright holders and contributors "as -is" and any express or implied warranties, including, but not limited -to, the implied warranties of merchantability and fitness for a -particular purpose are disclaimed. In no event shall the copyright owner -or contributors be liable for any direct, indirect, incidental, special, -exemplary, or consequential damages (including, but not limited to, -procurement of substitute goods or services; loss of use, data, or -profits; or business interruption) however caused and on any theory of -liability, whether in contract, strict liability, or tort (including -negligence or otherwise) arising in any way out of the use of this -software, even if advised of the possibility of such damage. - -*/ -?> \ No newline at end of file From 4dc305a81bef8f0419cb22a110d918f3777e43bd Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 19 Jun 2014 18:17:44 +0200 Subject: [PATCH 065/120] updated the README --- README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3618383..d07b9c2 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,6 @@ Simply add `parser` to your config.php `always_loaded.packages` config option. // old usage still valid, will load app/views/example.php View::forge('example'); -// load a SimpleTags template, will load and parse app/views/example.stags -View::forge('example.stags'); - // load a Mustache template, will load and parse app/views/example.mustache View::forge('example.mustache'); @@ -44,23 +41,27 @@ View::forge('example.dwoo'); ## Installing parsers -Only Markdown is included. While many other drivers are included, their libraries are not and are by default. - -Mustache, Twig, MtHaml, Lex and Smarty should be installed via Composer. Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: +To be able to use one of the supported parsers, you need to install them via composer. +Simply add the libraries to your project's `composer.json` then run `php composer.phar install`: ```json { "require": { + "dwoo/dwoo" : "*", "mustache/mustache" : "*", "smarty/smarty" : "*", "twig/twig" : "*", "mthaml/mthaml": "*", - "pyrocms/lex": "2.2.*" + "pyrocms/lex": "*" } } ``` -Other libraries are expected in `app/vendor/lib_name` (capitalize lib_name), you'll have to download them yourself. Don't change the casing or anything, keep it as much original as possible within the `vendor/lib_name` dir to keep updating easy (also because some come with their own autoloader). +Note that the Markdown parser is installed by default, as it is also used by the FuelPHP core class `Markdown`. + +Libraries that can not be installed through composer are expected to be installed in in `APPPATH/vendor/lib_name` (capitalize lib_name), +and you'll have to download them yourself. Don't change the casing or anything, keep it as much original as possible within the `vendor/lib_name` +dir to keep updating easy (also because some come with their own autoloader). You can configure them to be loaded from other locations by copying the parser.php config file to your app and editing it. @@ -69,6 +70,10 @@ You can configure them to be loaded from other locations by copying the parser.p Currently the drivers still lack a lot of config options they should probably accept. They are currently all configured to work with one instance of their parser library, which is available to config: ```php -$view = View::forge('example.stags'); -$view->parser()->set_delimiters('{', '}'); +// Clear the cache for a specific Smarty template +$view = View::forge('example.smarty'); +$view->parser()->clearCache('example.smarty'); + +// Example static usage +View_Smarty::parser()->clearCache('example.smarty'); ``` From 4863bfb517fa2794fcd507c7fb47490714ed9016 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 19 Jun 2014 18:17:55 +0200 Subject: [PATCH 066/120] removed SimpleTags from the bootstrap --- bootstrap.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index adfdc6c..9dd3f94 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -19,17 +19,14 @@ 'Parser\\View_Dwoo' => __DIR__.'/classes/view/dwoo.php', 'Parser\\View_Mustache' => __DIR__.'/classes/view/mustache.php', 'Parser\\View_Markdown' => __DIR__.'/classes/view/markdown.php', - 'Parser\\View_SimpleTags' => __DIR__.'/classes/view/simpletags.php', 'Parser\\View_Twig' => __DIR__.'/classes/view/twig.php', 'Parser\\View_HamlTwig' => __DIR__.'/classes/view/hamltwig.php', - 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', - 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', 'Parser\\View_Lex' => __DIR__.'/classes/view/lex.php', -)); - -/* End of file bootstrap.php */ + 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', + 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', +)); From ff5fb75f3d4dbc3647a94dadda486f7d4728640f Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 19 Jun 2014 18:18:08 +0200 Subject: [PATCH 067/120] added Lex packagist URL --- config/parser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/parser.php b/config/parser.php index c0e6d8c..511c638 100644 --- a/config/parser.php +++ b/config/parser.php @@ -181,11 +181,10 @@ ), // Lex ( http://github.com/pyrocms/lex/ ) + // Packagist url: https://packagist.org/packages/pyrocms/lex // ------------------------------------------------------------------------ 'View_Lex' => array( 'scope_glue' => '.', 'allow_php' => false, ), ); - -// end of file parser.php From 6b2018a7bccd4bc719b6eec43dd2500a06d2a995 Mon Sep 17 00:00:00 2001 From: Brian Evans Date: Mon, 14 Jul 2014 09:24:38 -0400 Subject: [PATCH 068/120] Fix one parameter on html_anchor Smarty extension which will throw a notice on use --- classes/smarty/fuel/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index b79300e..e9915f0 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -491,7 +491,7 @@ public function html_anchor($params) { } $attrs = isset($params['folder']) ? $params['folder'] : array(); $secure = isset($params['secure']) ? $params['secure'] : null; - return Html::anchor($params['file'], $params['text'], $attrs, $secure); + return Html::anchor($params['href'], $params['text'], $attrs, $secure); } /** From 55083335adae8a68987a019a30bbf78f19a71f51 Mon Sep 17 00:00:00 2001 From: Denis Favreau Date: Tue, 15 Jul 2014 16:37:19 +0200 Subject: [PATCH 069/120] Add theme_asset_css, theme_asset_js, theme_asset_img and html_mail_to_safe to the Twig extension class --- classes/twig/fuel/extension.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index b9b0af2..eda0bc6 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -81,7 +81,12 @@ public function getFunctions() 'asset_render' => new Twig_Function_Function('Asset::render'), 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), + 'theme_asset_css' => new Twig_Function_Method($this, 'theme_asset_css'), + 'theme_asset_js' => new Twig_Function_Method($this, 'theme_asset_js'), + 'theme_asset_img' => new Twig_Function_Method($this, 'theme_asset_img'), + 'html_anchor' => new Twig_Function_Function('Html::anchor'), + 'html_mail_to_safe' => new Twig_Function_Function('Html::mail_to_safe'), 'session_get' => new Twig_Function_Function('Session::get'), 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), @@ -115,4 +120,19 @@ public function fuel_version() { return \Fuel::VERSION; } + + public function theme_asset_css($stylesheets = array(), $attr = array(), $group = null, $raw = false) + { + return \Theme::instance()->asset->css($stylesheets, $attr, $group, $raw); + } + + public function theme_asset_js($scripts = array(), $attr = array(), $group = null, $raw = false) + { + return \Theme::instance()->asset->js($scripts, $attr, $group, $raw); + } + + public function theme_asset_img($images = array(), $attr = array(), $group = null) + { + return \Theme::instance()->asset->img($images, $attr, $group); + } } From 8b12ad7ff56eac2ee190381625f4648685b6e2d4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 16 Aug 2014 09:50:39 +0900 Subject: [PATCH 070/120] Add composer.json Signed-off-by: Kenji Suzuki --- composer.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d28f9e7 --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "fuel/parser", + "description" : "FuelPHP 1.x Parser Package", + "type": "fuel-package", + "homepage": "https://github.com/fuel/parser", + "license": "MIT", + "authors": [ + { + "name": "FuelPHP Development Team", + "email": "team@fuelphp.com" + } + ], + "require": { + "composer/installers": "~1.0" + } +} From 3bd71ab274a4cdba4d274750e367857cecbafc5c Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sun, 16 Nov 2014 17:28:28 +0100 Subject: [PATCH 071/120] have the parsers View extension also parse plain php files correctly --- classes/view.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/classes/view.php b/classes/view.php index 5732e56..7d11762 100644 --- a/classes/view.php +++ b/classes/view.php @@ -55,6 +55,8 @@ public static function forge($file = null, $data = null, $auto_encode = null) { $class = null; + $extension = 'php'; + if ($file !== null) { $extension = pathinfo($file, PATHINFO_EXTENSION); @@ -109,4 +111,24 @@ public static function forge($file = null, $data = null, $auto_encode = null) return $view; } + + /** + * Sets the view filename. + * + * $view->set_filename($file); + * + * @param string view filename + * @return View + * @throws FuelException + */ + public function set_filename($file) + { + switch ($this->extension) + { + case 'php': + return parent::set_filename($file); + + default: + } + } } From 2a251abc5b9a45e7e0304fd5802c37062fe9b061 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sun, 16 Nov 2014 18:53:36 +0100 Subject: [PATCH 072/120] remove the empty set_filename method; the parent one now supports alternative extensions --- classes/view.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/classes/view.php b/classes/view.php index 7d11762..42ad462 100644 --- a/classes/view.php +++ b/classes/view.php @@ -111,24 +111,4 @@ public static function forge($file = null, $data = null, $auto_encode = null) return $view; } - - /** - * Sets the view filename. - * - * $view->set_filename($file); - * - * @param string view filename - * @return View - * @throws FuelException - */ - public function set_filename($file) - { - switch ($this->extension) - { - case 'php': - return parent::set_filename($file); - - default: - } - } } From 31fc3b803780ab8aa7468c256a1c4ef3e42dd768 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 22 Jan 2015 11:02:48 +0100 Subject: [PATCH 073/120] bumped the copyright to 2015 --- bootstrap.php | 2 +- classes/smarty/fuel/extension.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 2 +- classes/view/jade.php | 2 +- classes/view/lex.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 9dd3f94..398b25f 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index e9915f0..5c1635c 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index eda0bc6..85ba7bf 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 42ad462..5afa5a7 100644 --- a/classes/view.php +++ b/classes/view.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index c8c1659..f2ba7ae 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index 3389652..a274711 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 31aaa38..5a343a2 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index 3bcae27..da7d6dc 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/lex.php b/classes/view/lex.php index 80f9688..0e1eaf1 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index d41f138..30d40be 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index c054302..3f99569 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 1e04046..ea715ad 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 023d445..f59337c 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index a7dd773..c3ef50e 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index 511c638..f2446a2 100644 --- a/config/parser.php +++ b/config/parser.php @@ -8,7 +8,7 @@ * @version 1.7 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2014 Fuel Development Team + * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com /** From 3a36a16d04620dee26f275f23f578ecab12e831c Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Thu, 26 Feb 2015 23:06:05 +0100 Subject: [PATCH 074/120] style fixes --- bootstrap.php | 26 +++---- classes/smarty/fuel/extension.php | 9 +-- classes/twig/fuel/extension.php | 2 +- classes/view.php | 1 - classes/view/haml.php | 1 - classes/view/hamltwig.php | 3 +- classes/view/jade.php | 1 - classes/view/markdown.php | 1 - classes/view/phptal.php | 3 +- config/parser.php | 122 +++++++++++++++--------------- 10 files changed, 81 insertions(+), 88 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 398b25f..42d0358 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -12,20 +12,20 @@ * @link http://fuelphp.com */ -Autoloader::add_core_namespace('Parser'); +\Autoloader::add_core_namespace('Parser'); -Autoloader::add_classes(array( - 'Parser\\View' => __DIR__.'/classes/view.php', - 'Parser\\View_Dwoo' => __DIR__.'/classes/view/dwoo.php', - 'Parser\\View_Mustache' => __DIR__.'/classes/view/mustache.php', - 'Parser\\View_Markdown' => __DIR__.'/classes/view/markdown.php', - 'Parser\\View_Twig' => __DIR__.'/classes/view/twig.php', - 'Parser\\View_HamlTwig' => __DIR__.'/classes/view/hamltwig.php', - 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', - 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', - 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', - 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', - 'Parser\\View_Lex' => __DIR__.'/classes/view/lex.php', +\Autoloader::add_classes(array( + 'Parser\\View' => __DIR__.'/classes/view.php', + 'Parser\\View_Dwoo' => __DIR__.'/classes/view/dwoo.php', + 'Parser\\View_Mustache' => __DIR__.'/classes/view/mustache.php', + 'Parser\\View_Markdown' => __DIR__.'/classes/view/markdown.php', + 'Parser\\View_Twig' => __DIR__.'/classes/view/twig.php', + 'Parser\\View_HamlTwig' => __DIR__.'/classes/view/hamltwig.php', + 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', + 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', + 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', + 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', + 'Parser\\View_Lex' => __DIR__.'/classes/view/lex.php', 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index 5c1635c..25cdee8 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -30,7 +30,6 @@ * Provides Smarty support for commonly used FuelPHP classes and methods. */ class Smarty_Fuel_Extension { - /** * Sets up all of the functions this extension makes available. */ @@ -80,7 +79,7 @@ public function fuel_version() { /** * Provides the url() functionality. Generates a full url (including * domain and index.php). - * + * * Usage: {url uri='' params=[name=>$value]} * * @return string @@ -139,7 +138,7 @@ public function lang_get($params) { /** * Usage: {form attrs=[] hidden=[]}...{/form} - * + * * @return string */ public function form($params, $content, $smarty, &$repeat) { @@ -155,7 +154,7 @@ public function form($params, $content, $smarty, &$repeat) { /** * Usage: {form_fieldset attrs=[] legend=''}...{/form} - * + * * @return string */ public function form_fieldset($params, $content, $smarty, &$repeat) { @@ -511,7 +510,7 @@ public function session_get_flash($params) { /** * Usage: {markdown}...{/markdown} - * + * * @return string */ public function markdown_parse($params, $content, $smarty, &$repeat) { diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 85ba7bf..8456348 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -94,7 +94,7 @@ public function getFunctions() 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), - 'auth_check' => new Twig_Function_Function('Auth::check') + 'auth_check' => new Twig_Function_Function('Auth::check'), ); } diff --git a/classes/view.php b/classes/view.php index 5afa5a7..9ebae40 100644 --- a/classes/view.php +++ b/classes/view.php @@ -16,7 +16,6 @@ class View extends \Fuel\Core\View { - /** * @var array Holds the list of loaded files. */ diff --git a/classes/view/haml.php b/classes/view/haml.php index a274711..f1311f2 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -18,7 +18,6 @@ class View_Haml extends \View { - protected static $_parser; protected static $_cache; diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 5a343a2..801972f 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -21,7 +21,6 @@ use MtHaml; class View_HamlTwig extends View_Twig { - protected static $_environment; /** @@ -34,7 +33,7 @@ public static function _init() // Include View_HamlTwig file(s) defined in config. $includes = \Config::get('parser.View_Twig.include'); - foreach ((array)$includes as $include) + foreach ((array) $includes as $include) { require $include; static::$loaded_files[$include] = true; diff --git a/classes/view/jade.php b/classes/view/jade.php index da7d6dc..349ad3e 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -18,7 +18,6 @@ class View_Jade extends \View { - protected static $_jade; protected static $_cache; diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 30d40be..43589e5 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -16,7 +16,6 @@ class View_Markdown extends \View { - protected static $_parser; protected function process_file($file_override = false) diff --git a/classes/view/phptal.php b/classes/view/phptal.php index ea715ad..a87ef6d 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -16,7 +16,6 @@ class View_Phptal extends \View { - protected static $_parser; protected function process_file($file_override = false) @@ -28,7 +27,7 @@ protected function process_file($file_override = false) $parser = static::parser(); foreach($this->get_data() as $key => $value) { - $parser->set($key,$value); + $parser->set($key, $value); } $parser->setTemplate($file); return $parser->execute(); diff --git a/config/parser.php b/config/parser.php index f2446a2..75d191b 100644 --- a/config/parser.php +++ b/config/parser.php @@ -10,6 +10,7 @@ * @license MIT License * @copyright 2010 - 2015 Fuel Development Team * @link http://fuelphp.com + */ /** * NOTICE: @@ -26,20 +27,19 @@ // Register extensions to their parsers, either classname or array config // ------------------------------------------------------------------------ 'extensions' => array( - 'php' => 'View', - 'twig' => 'View_Twig', - 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'twig'), - 'mustache' => 'View_Mustache', - 'md' => 'View_Markdown', - 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), - 'jade' => 'View_Jade', - 'haml' => 'View_Haml', - 'smarty' => 'View_Smarty', - 'phptal' => 'View_Phptal', - 'lex' => 'View_Lex', + 'php' => 'View', + 'twig' => 'View_Twig', + 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'twig'), + 'mustache' => 'View_Mustache', + 'md' => 'View_Markdown', + 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), + 'jade' => 'View_Jade', + 'haml' => 'View_Haml', + 'smarty' => 'View_Smarty', + 'phptal' => 'View_Phptal', + 'lex' => 'View_Lex', ), - // ------------------------------------------------------------------------ // Individual class config by classname // ------------------------------------------------------------------------ @@ -48,9 +48,9 @@ // MARKDOWN ( http://michelf.com/projects/php-markdown/ ) // ------------------------------------------------------------------------ 'View_Markdown' => array( - 'include' => \Package::exists('parser').'vendor'.DS.'markdown'.DS.'markdown.php', - 'auto_encode' => true, - 'allow_php' => true, + 'include' => \Package::exists('parser').'vendor'.DS.'markdown'.DS.'markdown.php', + 'auto_encode' => true, + 'allow_php' => true, ), // TWIG ( http://www.twig-project.org/documentation ) @@ -58,23 +58,23 @@ 'View_Twig' => array( 'auto_encode' => true, 'views_paths' => array(APPPATH.'views'), - 'delimiters' => array( - 'tag_block' => array('left' => '{%', 'right' => '%}'), - 'tag_comment' => array('left' => '{#', 'right' => '#}'), - 'tag_variable' => array('left' => '{{', 'right' => '}}'), + 'delimiters' => array( + 'tag_block' => array('left' => '{%', 'right' => '%}'), + 'tag_comment' => array('left' => '{#', 'right' => '#}'), + 'tag_variable' => array('left' => '{{', 'right' => '}}'), ), 'environment' => array( - 'debug' => false, - 'charset' => 'utf-8', - 'base_template_class' => 'Twig_Template', - 'cache' => APPPATH.'cache'.DS.'twig'.DS, - 'auto_reload' => true, - 'strict_variables' => false, - 'autoescape' => false, - 'optimizations' => -1, + 'debug' => false, + 'charset' => 'utf-8', + 'base_template_class' => 'Twig_Template', + 'cache' => APPPATH.'cache'.DS.'twig'.DS, + 'auto_reload' => true, + 'strict_variables' => false, + 'autoescape' => false, + 'optimizations' => -1, ), 'extensions' => array( - 'Twig_Fuel_Extension' + 'Twig_Fuel_Extension', ), ), @@ -84,37 +84,37 @@ // Uses > 1.1.1 (Master branch ATM) // ------------------------------------------------------------------------ 'View_HamlTwig' => array( - //'include' => APPPATH.'vendor'.DS.'MtHaml'.DS.'Autoloader.php', + //'include' => APPPATH.'vendor'.DS.'MtHaml'.DS.'Autoloader.php', 'auto_encode' => true, 'environment' => array( 'auto_escaper' => true, - 'escape_html' => true, + 'escape_html' => true, 'escape_attrs' => true, - 'charset' => 'UTF-8', - 'format' => 'html5', + 'charset' => 'UTF-8', + 'format' => 'html5', ), ), // DWOO ( http://wiki.dwoo.org/ ) // ------------------------------------------------------------------------ 'View_Dwoo' => array( - 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', + 'include' => APPPATH.'vendor'.DS.'Dwoo'.DS.'dwooAutoload.php', 'auto_encode' => true, - 'delimiters' => array('left' => '{{', 'right' => '}}'), + 'delimiters' => array('left' => '{{', 'right' => '}}'), 'environment' => array( - 'autoescape' => false, - 'nested_comments' => false, - 'allow_spaces' => false, - 'cache_dir' => APPPATH.'cache'.DS.'dwoo'.DS, - 'compile_dir' => APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS, - 'cache_time' => 0, + 'autoescape' => false, + 'nested_comments' => false, + 'allow_spaces' => false, + 'cache_dir' => APPPATH.'cache'.DS.'dwoo'.DS, + 'compile_dir' => APPPATH.'cache'.DS.'dwoo'.DS.'compiled'.DS, + 'cache_time' => 0, // Set what parser should do with PHP tags // 1 - Encode tags | 2 - Remove tags | 3 - Allow tags - 'allow_php_tags' => 2, + 'allow_php_tags' => 2, // Which PHP functions should be accessible through Parser - 'allow_php_func' => array(), + 'allow_php_func' => array(), ), ), @@ -134,25 +134,25 @@ // See notes in /parser/classes/view/jade.php // ------------------------------------------------------------------------ 'View_Jade' => array( - 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, + 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, ), // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) // ------------------------------------------------------------------------ - 'View_Haml' => array( - 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, + 'View_Haml' => array( + 'include' => APPPATH.'vendor'.DS.'Phamlp'.DS.'haml'.DS.'HamlParser.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'haml'.DS, ), // SMARTY ( http://www.smarty.net/documentation ) // ------------------------------------------------------------------------ - 'View_Smarty' => array( - 'auto_encode' => true, - 'delimiters' => array('left' => '{', 'right' => '}'), - 'environment' => array( + 'View_Smarty' => array( + 'auto_encode' => true, + 'delimiters' => array('left' => '{', 'right' => '}'), + 'environment' => array( 'compile_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS, 'config_dir' => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS, 'cache_dir' => APPPATH.'cache'.DS.'Smarty'.DS, @@ -169,15 +169,15 @@ // Phptal ( http://phptal.org/manual/en/ ) // ------------------------------------------------------------------------ - 'View_Phptal' => array( - 'include' => APPPATH.'vendor'.DS.'PHPTAL'.DS.'PHPTAL.php', - 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'PHPTAL'.DS, - 'cache_lifetime' => 0, - 'encoding' => 'UTF-8', - 'output_mode' => 'PHPTAL::XHTML', + 'View_Phptal' => array( + 'include' => APPPATH.'vendor'.DS.'PHPTAL'.DS.'PHPTAL.php', + 'auto_encode' => true, + 'cache_dir' => APPPATH.'cache'.DS.'PHPTAL'.DS, + 'cache_lifetime' => 0, + 'encoding' => 'UTF-8', + 'output_mode' => 'PHPTAL::XHTML', 'template_repository' => '', - 'force_reparse' => false, + 'force_reparse' => false, ), // Lex ( http://github.com/pyrocms/lex/ ) From e2dda996bd6255fbbbb9f50bb7eaa3a935d0f45f Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 14 Mar 2015 11:12:01 +0100 Subject: [PATCH 075/120] added Debug::dump as a Twig extension; closes #83 --- classes/twig/fuel/extension.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 8456348..c869da3 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -53,6 +53,8 @@ public function getFunctions() 'config' => new Twig_Function_Function('Config::get'), + 'dump' => new Twig_Function_Function('Debug::dump'), + 'lang' => new Twig_Function_Function('Lang::get'), 'form_open' => new Twig_Function_Function('Form::open'), From 4b24ded1ac1b2bf06eff80a68b064a2bdb960f49 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 7 Aug 2015 14:26:41 +0100 Subject: [PATCH 076/120] fixed typo in find_file argument list; closes #86 --- classes/smarty/fuel/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index 25cdee8..89e8eac 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -472,7 +472,7 @@ public function asset_find_file($params) { throw new \UnexpectedValueException("The type parameter is required."); } $folder = isset($params['folder']) ? $params['folder'] : ''; - return Asset::find_file($params['file'], $params['file'], $folder); + return Asset::find_file($params['file'], $params['type'], $folder); } /** From 24b6821503f78cc92dc62c7e1609002a45a2542b Mon Sep 17 00:00:00 2001 From: Takashi Fujita Date: Mon, 13 Jul 2015 15:48:38 +0900 Subject: [PATCH 077/120] add partials_loader options for Mustache --- classes/view/mustache.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 3f99569..4b524a7 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -15,6 +15,7 @@ namespace Parser; use Mustache_Engine; +use Mustache_Loader_FilesystemLoader; class View_Mustache extends \View { @@ -57,14 +58,21 @@ public static function parser() 'charset' => \Config::get('parser.View_Mustache.environment.charset', 'UTF-8'), ); - if ($partials = \Config::get('parser.View_Mustache.environment.partials', array())) { + if ($partials = \Config::get('parser.View_Mustache.environment.partials', array())) + { $options['partials'] = $partials; } - if ($helpers = \Config::get('parser.View_Mustache.environment.helpers', array())) { + if ($helpers = \Config::get('parser.View_Mustache.environment.helpers', array())) + { $options['helpers'] = $helpers; } + if ($partials = \Config::get('parser.View_Mustache.environment.partials_loader', 'UTF-8')) + { + $options['partials_loader'] = new Mustache_Loader_FilesystemLoader($partials); + } + static::$_parser = new Mustache_Engine($options); return static::$_parser; From 40cb0bbf547cc0d20df8492cc84fd96f687251ce Mon Sep 17 00:00:00 2001 From: "Steve \"Uru\" West" Date: Thu, 8 Oct 2015 07:13:10 +0100 Subject: [PATCH 078/120] Fixes typo. Closes #87 --- classes/smarty/fuel/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index 89e8eac..fae17d6 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -488,7 +488,7 @@ public function html_anchor($params) { if (!isset($params['text'])) { throw new \UnexpectedValueException("The text parameter is required."); } - $attrs = isset($params['folder']) ? $params['folder'] : array(); + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); $secure = isset($params['secure']) ? $params['secure'] : null; return Html::anchor($params['href'], $params['text'], $attrs, $secure); } From ea5b34d528819590e8517ac313cad736f88add66 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 23 Jan 2016 12:34:25 +0000 Subject: [PATCH 079/120] Bumped the copyright to 2016, the version to 1.8 --- bootstrap.php | 4 ++-- classes/smarty/fuel/extension.php | 4 ++-- classes/twig/fuel/extension.php | 4 ++-- classes/view.php | 4 ++-- classes/view/dwoo.php | 4 ++-- classes/view/haml.php | 4 ++-- classes/view/hamltwig.php | 4 ++-- classes/view/jade.php | 4 ++-- classes/view/lex.php | 4 ++-- classes/view/markdown.php | 4 ++-- classes/view/mustache.php | 4 ++-- classes/view/phptal.php | 4 ++-- classes/view/smarty.php | 4 ++-- classes/view/twig.php | 4 ++-- config/parser.php | 4 ++-- 15 files changed, 30 insertions(+), 30 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 42d0358..03589aa 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index fae17d6..069a63d 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index c869da3..3d72a35 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 9ebae40..5f465dd 100644 --- a/classes/view.php +++ b/classes/view.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index f2ba7ae..33ab0b3 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index f1311f2..4ab9af3 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 801972f..a0dfb3e 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index 349ad3e..962a5c4 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/lex.php b/classes/view/lex.php index 0e1eaf1..5f762ce 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 43589e5..a786be3 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 4b524a7..3110a3d 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index a87ef6d..d8091dc 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index f59337c..a347b64 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index c3ef50e..c4203d0 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index 75d191b..e5f4437 100644 --- a/config/parser.php +++ b/config/parser.php @@ -5,10 +5,10 @@ * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package Fuel - * @version 1.7 + * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2015 Fuel Development Team + * @copyright 2010 - 2016 Fuel Development Team * @link http://fuelphp.com */ From 4d29b069182fa4c43e00681467e3fd909f46b1f3 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 25 Feb 2016 21:31:59 +0100 Subject: [PATCH 080/120] unsanitize data after rendering; related fuel/core#1973 --- classes/view/dwoo.php | 5 ++++- classes/view/hamltwig.php | 7 ++++++- classes/view/lex.php | 6 +++++- classes/view/markdown.php | 3 ++- classes/view/mustache.php | 5 ++++- classes/view/phptal.php | 8 ++++++-- classes/view/smarty.php | 7 +++++-- classes/view/twig.php | 7 ++++++- 8 files changed, 38 insertions(+), 10 deletions(-) diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 33ab0b3..bd1756d 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -31,7 +31,7 @@ protected function process_file($file_override = false) try { - return static::parser()->get($file, $data); + $result = static::parser()->get($file, $data); } catch (\Exception $e) { @@ -39,6 +39,9 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($data); + return $result; } public $extension = 'tpl'; diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index a0dfb3e..77fe52d 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -87,7 +87,7 @@ protected function process_file($file_override = false) //\Debug::dump(static::parser()); exit(); try { - return static::parser()->render($view_name, $local_data); + $result = static::parser()->render($view_name, $local_data); } catch (\Exception $e) { @@ -95,6 +95,11 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($local_data); + $this->unsanitize($global_data); + + return $result; } /** diff --git a/classes/view/lex.php b/classes/view/lex.php index 5f762ce..818fc61 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -52,8 +52,9 @@ protected function process_file($file_override = false) try { + $data = $this->get_data(); static::parser()->scopeGlue(\Config::get('parser.View_Lex.scope_glue', '.')); - return static::parser()->parse(file_get_contents($file), $this->get_data(), $this->callback, \Config::get('parser.View_Lex.allow_php', false)); + $result = static::parser()->parse(file_get_contents($file), $data, $this->callback, \Config::get('parser.View_Lex.allow_php', false)); } catch (\Exception $e) { @@ -61,5 +62,8 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($data); + return $result; } } diff --git a/classes/view/markdown.php b/classes/view/markdown.php index a786be3..0ab91f2 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -26,7 +26,8 @@ protected function process_file($file_override = false) if (\Config::get('parser.View_Markdown.allow_php', false)) { - $contents = static::pre_process('php', $file, $this->get_data()); + $contents = static::pre_process('php', $file, $data = $this->get_data()); + $this->unsanitize($data); } else { diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 3110a3d..c676285 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -28,7 +28,7 @@ protected function process_file($file_override = false) try { - return static::parser()->render(file_get_contents($file), $data); + $result = static::parser()->render(file_get_contents($file), $data); } catch (\Exception $e) { @@ -36,6 +36,9 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($data); + return $result; } public $extension = 'mustache'; diff --git a/classes/view/phptal.php b/classes/view/phptal.php index d8091dc..f3cad51 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -25,12 +25,13 @@ protected function process_file($file_override = false) try { $parser = static::parser(); - foreach($this->get_data() as $key => $value) + $data = $this->get_data(); + foreach($data as $key => $value) { $parser->set($key, $value); } $parser->setTemplate($file); - return $parser->execute(); + $result = $parser->execute(); } catch (\Exception $e) { @@ -38,6 +39,9 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($data); + return $result; } public $extension = 'phptal'; diff --git a/classes/view/smarty.php b/classes/view/smarty.php index a347b64..6e73daf 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -28,8 +28,8 @@ protected function process_file($file_override = false) { // Smarty doesn't support method chaining $parser = static::parser(); - $parser->assign($this->get_data()); - return $parser->fetch($file); + $parser->assign($data = $this->get_data()); + $result = $parser->fetch($file); } catch (\Exception $e) { @@ -37,6 +37,9 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($data); + return $result; } public $extension = 'smarty'; diff --git a/classes/view/twig.php b/classes/view/twig.php index c4203d0..aea3f03 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -64,7 +64,7 @@ protected function process_file($file_override = false) try { - return static::parser()->loadTemplate($view_name)->render($local_data); + $result = static::parser()->loadTemplate($view_name)->render($local_data); } catch (\Exception $e) { @@ -72,6 +72,11 @@ protected function process_file($file_override = false) ob_end_clean(); throw $e; } + + $this->unsanitize($local_data); + $this->unsanitize($global_data); + + return $result; } public $extension = 'twig'; From 25950948372bea5101f9ab13932e7432903d552f Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 25 Feb 2016 21:32:17 +0100 Subject: [PATCH 081/120] Added support for Talesofts Jade renderer --- classes/view/jade.php | 89 +++++++++++++++++++++++++++++++------------ config/parser.php | 9 ++++- 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/classes/view/jade.php b/classes/view/jade.php index 962a5c4..cc89d5c 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -14,54 +14,95 @@ namespace Parser; -use Everzet\Jade; +use Everzet\Jade as Everzet; +use Tale\Jade as Tale; class View_Jade extends \View { - protected static $_jade; + protected static $_parser; protected static $_cache; - protected function process_file($file_override = false) + /** + * Returns the Parser lib object + * + * @return Everzet\Jade + */ + public static function everzet_parser() { - $file = $file_override ?: $this->file_name; - static::cache_init($file); + // load a parser object + if (empty(static::$_parser)) + { + $parser = new Everzet\Parser(new Everzet\Lexer\Lexer()); + $dumper = new Everzet\Dumper\PHPDumper(); + $dumper->registerVisitor('tag', new Everzet\Visitor\AutotagsVisitor()); + $dumper->registerFilter('javascript', new Everzet\Filter\JavaScriptFilter()); + $dumper->registerFilter('cdata', new Everzet\Filter\CDATAFilter()); + $dumper->registerFilter('php', new Everzet\Filter\PHPFilter()); + $dumper->registerFilter('style', new Everzet\Filter\CSSFilter()); - $file = static::parser()->cache($file); - return parent::process_file($file); + static::$_parser = new Everzet\Jade($parser, $dumper, static::$_cache); + } + + return static::$_parser; } + /** + * @InheritDoc + */ public $extension = 'jade'; /** - * Returns the Parser lib object - * - * @return Jade\Parser + * @InheritDoc */ - public static function parser() + protected function process_file($file_override = false) { - if ( ! empty(static::$_parser)) + // update the cache path + $this->cache_init($file); + + // determine the filename + $file = $file_override ?: $this->file_name; + + // render the template using the Everzet implementation + if (class_exists('Everzet\\Jade\\Jade')) { - return static::$_parser; + // render the template + $file = static::everzet_parser()->cache($file); + $result = parent::process_file($file); } - $parser = new Jade\Parser(new Jade\Lexer\Lexer()); - $dumper = new Jade\Dumper\PHPDumper(); - $dumper->registerVisitor('tag', new Jade\Visitor\AutotagsVisitor()); - $dumper->registerFilter('javascript', new Jade\Filter\JavaScriptFilter()); - $dumper->registerFilter('cdata', new Jade\Filter\CDATAFilter()); - $dumper->registerFilter('php', new Jade\Filter\PHPFilter()); - $dumper->registerFilter('style', new Jade\Filter\CSSFilter()); + // render the template using the Tale implementation + elseif (class_exists('Tale\\Jade\\Renderer')) + { + // get the config + $config = \Config::get('parser.View_Jade', array()); + + // set our cache path + $config['cachePath'] = static::$_cache; + + // create a renderer instance + static::$_jade = new Tale\Renderer($config); - static::$_jade = new Jade\Jade($parser, $dumper, static::$_cache); + // render the template + $result = static::$_jade->render($file, $data = $this->get_data()); - return static::$_jade; + // disable sanitization on objects that support it + $this->unsanitize($data); + } + + // no known renderer found + else + { + throw new \FuelException("No supported Jade renderer found. Please check the documentation"); + } + + return $result; } // Jade stores cached templates as the filename in plain text, // so there is a high chance of name collisions (ex: index.jade). // This function attempts to create a unique directory for each // compiled template. - public function cache_init($file_path) + protected function cache_init($file_path) { $cache_key = md5($file_path); $cache_path = \Config::get('parser.View_Jade.cache_dir', null) @@ -76,5 +117,3 @@ public function cache_init($file_path) } } - -/* end of file jade.php */ diff --git a/config/parser.php b/config/parser.php index e5f4437..bcfb13c 100644 --- a/config/parser.php +++ b/config/parser.php @@ -134,9 +134,16 @@ // See notes in /parser/classes/view/jade.php // ------------------------------------------------------------------------ 'View_Jade' => array( + // global config + 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, + + // Everzet config 'include' => APPPATH.'vendor'.DS.'Jade'.DS.'autoload.php.dist', 'auto_encode' => true, - 'cache_dir' => APPPATH.'cache'.DS.'jade'.DS, + + // Tale config + 'lifetime' => 3600, + 'pretty' => false, ), // HAML / PHAMLP ( http://code.google.com/p/phamlp/ ) From 13d33a79d41ac6a4cf0bdbcf0a0cbdfc601ec14f Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 26 Feb 2016 13:22:43 +0100 Subject: [PATCH 082/120] fixed using template filenames with multiple dots --- classes/view.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/classes/view.php b/classes/view.php index 5f465dd..f22968e 100644 --- a/classes/view.php +++ b/classes/view.php @@ -68,12 +68,6 @@ public static function forge($file = null, $data = null, $auto_encode = null) $class = get_called_class(); } - // Only get rid of the extension if it is not an absolute file path - if ($file !== null and $file[0] !== '/' and $file[1] !== ':') - { - $file = $extension ? preg_replace('/\.'.preg_quote($extension).'$/i', '', $file) : $file; - } - // Class can be an array config if (is_array($class)) { @@ -97,16 +91,7 @@ public static function forge($file = null, $data = null, $auto_encode = null) $auto_encode = \Config::get('parser.'.$class.'.auto_encode', null); } - $view = new $class(null, $data, $auto_encode); - - if ($file !== null) - { - // Set extension when given - $extension and $view->extension = $extension; - - // Load the view file - $view->set_filename($file); - } + $view = new $class($file, $data, $auto_encode); return $view; } From 952f33d6295dd734b35610365f06afce05ea7e44 Mon Sep 17 00:00:00 2001 From: Caleb Williams Date: Thu, 10 Mar 2016 23:07:46 -0600 Subject: [PATCH 083/120] Add "auth_get" function for Twig extension to get the authenticated user's attributes --- classes/twig/fuel/extension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 3d72a35..0f3475e 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -97,6 +97,7 @@ public function getFunctions() 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), 'auth_check' => new Twig_Function_Function('Auth::check'), + 'auth_get' => new Twig_Function_Function('Auth::get'), ); } From 8ef41abf6008e2eab660f46e0157b675c46c977b Mon Sep 17 00:00:00 2001 From: Caleb Williams Date: Fri, 11 Mar 2016 17:28:21 -0600 Subject: [PATCH 084/120] Fix indention to use spaces --- classes/twig/fuel/extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 0f3475e..6a1102a 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -97,7 +97,7 @@ public function getFunctions() 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), 'auth_check' => new Twig_Function_Function('Auth::check'), - 'auth_get' => new Twig_Function_Function('Auth::get'), + 'auth_get' => new Twig_Function_Function('Auth::get'), ); } From dd8f60343c71ccd141403749b0c5f48823d501d9 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 23 Apr 2016 14:32:22 +0100 Subject: [PATCH 085/120] reverse the search order for parser view files; related fuel/core#1992 --- classes/view.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/classes/view.php b/classes/view.php index f22968e..9f7d575 100644 --- a/classes/view.php +++ b/classes/view.php @@ -53,13 +53,11 @@ public static function _init() public static function forge($file = null, $data = null, $auto_encode = null) { $class = null; - $extension = 'php'; if ($file !== null) { $extension = pathinfo($file, PATHINFO_EXTENSION); - $class = \Config::get('parser.extensions.'.$extension, null); } @@ -91,8 +89,8 @@ public static function forge($file = null, $data = null, $auto_encode = null) $auto_encode = \Config::get('parser.'.$class.'.auto_encode', null); } - $view = new $class($file, $data, $auto_encode); + $view = new $class(null, $data, $auto_encode); - return $view; + return $view->set_filename($file, true); } } From 262378f93def45ffd7cdde0c1ff6dee873f5979e Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 25 Jul 2016 12:22:18 +0100 Subject: [PATCH 086/120] added missing extension class to the default config for Smarty --- config/parser.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/parser.php b/config/parser.php index bcfb13c..23a55af 100644 --- a/config/parser.php +++ b/config/parser.php @@ -172,6 +172,9 @@ 'autoload_filters' => array(), 'default_modifiers' => array(), ), + 'extensions' => array( + 'Smarty_Fuel_Extension', + ), ), // Phptal ( http://phptal.org/manual/en/ ) From de6416ede782627621f10e11d2a202dc949298a2 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 25 Jul 2016 13:37:03 +0100 Subject: [PATCH 087/120] fixed not being able to overload the used template extension --- classes/view.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/classes/view.php b/classes/view.php index 9f7d575..4d5e260 100644 --- a/classes/view.php +++ b/classes/view.php @@ -23,7 +23,17 @@ class View extends \Fuel\Core\View public static function _init() { - \Config::load('parser', true); + // get and normalize the config + $parser = \Config::load('parser', true); + foreach (\Config::get('parser.extensions', array()) as $extension => $config) + { + if (isset($config['extension'])) + { + unset($parser['extensions'][$extension]); + $parser['extensions'][$config['extension']] = $config; + } + } + \Config::set('parser', $parser); // Get class name $class = \Inflector::denamespace(get_called_class()); From c0045f38e77c6e18a2c7a3a85d58fe66cfd534ac Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 30 Jul 2016 12:40:15 +0100 Subject: [PATCH 088/120] coding standards --- classes/smarty/fuel/extension.php | 1096 +++++++++++++++-------------- 1 file changed, 584 insertions(+), 512 deletions(-) diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index 069a63d..8399cd7 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -29,516 +29,588 @@ /** * Provides Smarty support for commonly used FuelPHP classes and methods. */ -class Smarty_Fuel_Extension { - /** - * Sets up all of the functions this extension makes available. - */ - public function __construct(\Smarty $smarty) { - $smarty->registerPlugin('function', 'fuel_version', array($this, 'fuel_version')); - $smarty->registerPlugin('function', 'url', array($this, 'url')); - $smarty->registerPlugin('function', 'base_url', array('Uri', 'base')); - $smarty->registerPlugin('function', 'current_url', array('Uri', 'current')); - $smarty->registerPlugin('function', 'uri_segment', array($this, 'uri_segment')); - $smarty->registerPlugin('function', 'uri_segments', array('Uri', 'segments')); - $smarty->registerPlugin('function', 'config', array($this, 'config_get')); - $smarty->registerPlugin('function', 'lang', array($this, 'lang_get')); - $smarty->registerPlugin('block', 'form', array($this, 'form')); - $smarty->registerPlugin('function', 'form_input', array($this, 'form_input')); - $smarty->registerPlugin('function', 'form_password', array($this, 'form_password')); - $smarty->registerPlugin('function', 'form_hidden', array($this, 'form_hidden')); - $smarty->registerPlugin('function', 'form_button', array($this, 'form_button')); - $smarty->registerPlugin('function', 'form_reset', array($this, 'form_reset')); - $smarty->registerPlugin('function', 'form_submit', array($this, 'form_submit')); - $smarty->registerPlugin('function', 'form_textarea', array($this, 'form_textarea')); - $smarty->registerPlugin('block', 'form_fieldset', array($this, 'form_fieldset')); - $smarty->registerPlugin('function', 'form_label', array($this, 'form_label')); - $smarty->registerPlugin('function', 'form_checkbox', array($this, 'form_checkbox')); - $smarty->registerPlugin('function', 'form_radio', array($this, 'form_radio')); - $smarty->registerPlugin('function', 'form_file', array($this, 'form_file')); - $smarty->registerPlugin('function', 'form_select', array($this, 'form_select')); - $smarty->registerPlugin('function', 'form_val', array($this, 'form_val')); - $smarty->registerPlugin('function', 'input_get', array($this, 'input_get')); - $smarty->registerPlugin('function', 'input_post', array($this, 'input_post')); - $smarty->registerPlugin('function', 'asset_add_path', array($this, 'asset_add_path')); - $smarty->registerPlugin('function', 'asset_css', array($this, 'asset_css')); - $smarty->registerPlugin('function', 'asset_js', array($this, 'asset_js')); - $smarty->registerPlugin('function', 'asset_img', array($this, 'asset_img')); - $smarty->registerPlugin('function', 'asset_render', array($this, 'asset_render')); - $smarty->registerPlugin('function', 'asset_find_file', array($this, 'asset_find_file')); - $smarty->registerPlugin('function', 'html_anchor', array($this, 'html_anchor')); - $smarty->registerPlugin('function', 'session_get_flash', array($this, 'session_get_flash')); - $smarty->registerPlugin('block', 'markdown', array($this, 'markdown_parse')); - $smarty->registerPlugin('function', 'auth_has_access', array($this, 'auth_has_access')); - $smarty->registerPlugin('function', 'auth_check', array($this, 'auth_check')); - } - - public function fuel_version() { - return \Fuel::VERSION; - } - - /** - * Provides the url() functionality. Generates a full url (including - * domain and index.php). - * - * Usage: {url uri='' params=[name=>$value]} - * - * @return string - */ - public function url($params) { - $uri = isset($params['uri']) ? $params['uri'] : ''; - $named_params = isset($params['params']) ? $params['params'] : array(); - if ($named_uri = Router::get($uri, $named_params)) { - $uri = $named_uri; - } - return Uri::create($uri); - } - - /** - * Usage: {uri_segment segment=''} - * Required: segment - * - * @return mixed segment string or false - */ - public function uri_segment($params) { - if (isset($params['segment'])) { - return Uri::segment($params['segment']); - } - return false; - } - - /** - * Usage: {config item='' default=''} - * Required: item - * - * @return mixed string or array - */ - public function config_get($params) { - if (isset($params['item'])) { - $default = $params['default'] ? null : $params['default']; - return Config::get($params['item'], $default); - } - return ''; - } - - /** - * Usage: {lang line='id' params=[] default='default value' lang='en'} - * Required: line - * - * @return mixed string or false - */ - public function lang_get($params) { - if (isset($params['line'])) { - $parameters = isset($params['params']) ? $params['params'] : array(); - $default = isset($params['default']) ? $params['default'] : null; - $language = isset($params['lang']) ? $params['lang'] : null; - return Lang::get($params['line'], $parameters, $default, $language); - } - return false; - } - - /** - * Usage: {form attrs=[] hidden=[]}...{/form} - * - * @return string - */ - public function form($params, $content, $smarty, &$repeat) { - //$content is null when repeat is true and has block content when repeat is false - if ($repeat) { - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - $hidden = isset($params['hidden']) ? $params['hidden'] : array(); - return Form::open($attributes, $hidden); - } else { - return $content . Form::close(); - } - } - - /** - * Usage: {form_fieldset attrs=[] legend=''}...{/form} - * - * @return string - */ - public function form_fieldset($params, $content, $smarty, &$repeat) { - //$content is null when repeat is true and has block content when repeat is false - if ($repeat) { - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - $legend = isset($params['legend']) ? $params['legend'] : null; - return Form::fieldset_open($attributes, $legend); - } else { - return $content . Form::fieldset_close(); - } - } - - /** - * Usage: {form_input field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_input($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::input($params['field'], $value, $attributes); - } - - /** - * Usage: {form_password field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_password($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::password($params['field'], $value, $attributes); - } - - /** - * Usage: {form_hidden field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_hidden($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::hidden($params['field'], $value, $attributes); - } - - /** - * Usage: {form_button field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_button($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::button($params['field'], $value, $attributes); - } - - /** - * Usage: {form_submit field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_submit($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::submit($params['field'], $value, $attributes); - } - - /** - * Usage: {form_reset field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_reset($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::reset($params['field'], $value, $attributes); - } - - /** - * Usage: {form_textarea field='' value='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_textarea($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::textarea($params['field'], $value, $attributes); - } - - /** - * Usage: {form_label text='' id='' attrs=[]} - * Required: text - * - * @return string - */ - public function form_label($params) { - if (!isset($params['text'])) { - throw new \UnexpectedValueException("The text parameter is required."); - } - $id = isset($params['id']) ? $params['id'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::label($params['text'], $id, $attributes); - } - - /** - * Usage: {form_checkbox field='' value='' checked=false attrs=[]} - * Required: field - * - * @return string - */ - public function form_checkbox($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - $checked = isset($params['checked']) ? $params['checked'] : null; - return Form::checkbox($params['field'], $value, $checked, $attributes); - } - - /** - * Usage: {form_radio field='' value='' checked=false attrs=[]} - * Required: field - * - * @return string - */ - public function form_radio($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $value = isset($params['value']) ? $params['value'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - $checked = isset($params['checked']) ? $params['checked'] : null; - return Form::checkbox($params['field'], $value, $checked, $attributes); - } - - /** - * Usage: {form_select field='' values='' options=[] attrs=[]} - * Required: field - * - * @return string - */ - public function form_select($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $values = isset($params['values']) ? $params['values'] : null; - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - $options = isset($params['options']) ? $params['options'] : array(); - return Form::select($params['field'], $values, $options, $attributes); - } - - /** - * Usage: {form_file field='' attrs=[]} - * Required: field - * - * @return string - */ - public function form_file($params) { - if (!isset($params['field'])) { - throw new \UnexpectedValueException("The field parameter is required."); - } - $attributes = isset($params['attrs']) ? $params['attrs'] : array(); - return Form::file($params['field'], $attributes); - } - - /** - * Provide access to Input::param - * Usage: {form_val index='' default=''} - * - * @return string - */ - public function form_val($params) { - $index = isset($params['index']) ? $params['index'] : null; - $default = isset($params['default']) ? $params['default'] : null; - return Input::param($index, $default); - } - - /** - * Provide access to Input::get - * Usage: {input_get index='' default=''} - * - * @return string - */ - public function input_get($params) { - $index = isset($params['index']) ? $params['index'] : null; - $default = isset($params['default']) ? $params['default'] : null; - return Input::get($index, $default); - } - - /** - * Provide access to Input::post - * Usage: {input_post index='' default=''} - * - * @return string - */ - public function input_post($params) { - $index = isset($params['index']) ? $params['index'] : null; - $default = isset($params['default']) ? $params['default'] : null; - return Input::post($index, $default); - } - - /** - * Provide addess to Asset::add_path - * Usage: {form_val path='' type=''} - * Required: path - * - */ - public function asset_add_path($params) { - if (!isset($params['path'])) - throw new \UnexpectedValueException('Asset path must be specified'); - $type = isset($params['type']) ? $params['type'] : null; - Asset::add_path($params['path'], $type); - } - - /** - * Usage: {asset_css refs='' attrs=[] group='' raw=false} - * Required: refs - * - * @return mixed string or nothing if group is filled - */ - public function asset_css($params) { - if (!isset($params['refs'])) { - throw new \UnexpectedValueException("The refs parameter is required."); - } - $group = isset($params['group']) ? $params['group'] : null; - $attrs = isset($params['attrs']) ? $params['attrs'] : array(); - $raw = isset($params['raw']) ? $params['raw'] : false; - return Asset::css($params['refs'], $attrs, $group, $raw); - } - - /** - * Usage: {asset_js refs='' attrs=[] group='' raw=false} - * Required: refs - * - * @return mixed string or nothing if group is filled - */ - public function asset_js($params) { - if (!isset($params['refs'])) { - throw new \UnexpectedValueException("The refs parameter is required."); - } - $group = isset($params['group']) ? $params['group'] : null; - $attrs = isset($params['attrs']) ? $params['attrs'] : array(); - $raw = isset($params['raw']) ? $params['raw'] : false; - return Asset::js($params['refs'], $attrs, $group, $raw); - } - - /** - * Usage: {asset_img refs='' attrs=[] group=''} - * Required: refs - * - * @return mixed string or nothing if group is filled - */ - public function asset_img($params) { - if (!isset($params['refs'])) { - throw new \UnexpectedValueException("The refs parameter is required."); - } - $group = isset($params['group']) ? $params['group'] : null; - $attrs = isset($params['attrs']) ? $params['attrs'] : array(); - return Asset::img($params['refs'], $attrs, $group); - } - - /** - * Render a group of assets - * Usage: {asset_render group='' raw=false} - * - * @return string - */ - public function asset_render($params) { - $group = isset($params['group']) ? $params['group'] : null; - $raw = isset($params['raw']) ? $params['raw'] : false; - return Asset::render($group, $raw); - } - - /** - * Usage: {asset_find_file file='' type='' folder=''} - * Required: file and type - * - * @return string - */ - public function asset_find_file($params) { - if (!isset($params['file'])) { - throw new \UnexpectedValueException("The file parameter is required."); - } - if (!isset($params['type'])) { - throw new \UnexpectedValueException("The type parameter is required."); - } - $folder = isset($params['folder']) ? $params['folder'] : ''; - return Asset::find_file($params['file'], $params['type'], $folder); - } - - /** - * Usage: {html_anchor href='' text='' attrs='' secure=false} - * Required: href and text - * - * @return string - */ - public function html_anchor($params) { - if (!isset($params['href'])) { - throw new \UnexpectedValueException("The href parameter is required."); - } - if (!isset($params['text'])) { - throw new \UnexpectedValueException("The text parameter is required."); - } - $attrs = isset($params['attrs']) ? $params['attrs'] : array(); - $secure = isset($params['secure']) ? $params['secure'] : null; - return Html::anchor($params['href'], $params['text'], $attrs, $secure); - } - - /** - * Usage: {session_get_flash var='' default='' expire=false} - * Required: var - * - * @return mixed - */ - public function session_get_flash($params) { - if (!isset($params['var'])) { - throw new \UnexpectedValueException("The var parameter is required."); - } - $default = isset($params['default']) ? $params['default'] : null; - $expire = isset($params['expire']) ? $params['expire'] : false; - return Session::get_flash($params['var'], $default, $expire); - } - - /** - * Usage: {markdown}...{/markdown} - * - * @return string - */ - public function markdown_parse($params, $content, $smarty, &$repeat) { - //only take action when repeat = false as that is the closing tag - if (!$repeat) { - return Markdown::parse($content); - } - } - - /** - * Usage: {auth_has_access cond=''} - * Required: cond - * - * @return bool - */ - public function auth_has_access($params) { - if (!isset($params['cond'])) { - throw new \UnexpectedValueException("The cond parameter is required."); - } - return Auth::has_access($params['cond']); - } - - /** - * Usage: {auth_check} - * - * @return bool - */ - public function auth_check() { - return Auth::check(); - } +class Smarty_Fuel_Extension +{ + /** + * Sets up all of the functions this extension makes available. + */ + public function __construct(\Smarty $smarty) + { + $smarty->registerPlugin('function', 'fuel_version', array($this, 'fuel_version')); + $smarty->registerPlugin('function', 'url', array($this, 'url')); + $smarty->registerPlugin('function', 'base_url', array('Uri', 'base')); + $smarty->registerPlugin('function', 'current_url', array('Uri', 'current')); + $smarty->registerPlugin('function', 'uri_segment', array($this, 'uri_segment')); + $smarty->registerPlugin('function', 'uri_segments', array('Uri', 'segments')); + $smarty->registerPlugin('function', 'config', array($this, 'config_get')); + $smarty->registerPlugin('function', 'lang', array($this, 'lang_get')); + $smarty->registerPlugin('block', 'form', array($this, 'form')); + $smarty->registerPlugin('function', 'form_input', array($this, 'form_input')); + $smarty->registerPlugin('function', 'form_password', array($this, 'form_password')); + $smarty->registerPlugin('function', 'form_hidden', array($this, 'form_hidden')); + $smarty->registerPlugin('function', 'form_button', array($this, 'form_button')); + $smarty->registerPlugin('function', 'form_reset', array($this, 'form_reset')); + $smarty->registerPlugin('function', 'form_submit', array($this, 'form_submit')); + $smarty->registerPlugin('function', 'form_textarea', array($this, 'form_textarea')); + $smarty->registerPlugin('block', 'form_fieldset', array($this, 'form_fieldset')); + $smarty->registerPlugin('function', 'form_label', array($this, 'form_label')); + $smarty->registerPlugin('function', 'form_checkbox', array($this, 'form_checkbox')); + $smarty->registerPlugin('function', 'form_radio', array($this, 'form_radio')); + $smarty->registerPlugin('function', 'form_file', array($this, 'form_file')); + $smarty->registerPlugin('function', 'form_select', array($this, 'form_select')); + $smarty->registerPlugin('function', 'form_val', array($this, 'form_val')); + $smarty->registerPlugin('function', 'input_get', array($this, 'input_get')); + $smarty->registerPlugin('function', 'input_post', array($this, 'input_post')); + $smarty->registerPlugin('function', 'asset_add_path', array($this, 'asset_add_path')); + $smarty->registerPlugin('function', 'asset_css', array($this, 'asset_css')); + $smarty->registerPlugin('function', 'asset_js', array($this, 'asset_js')); + $smarty->registerPlugin('function', 'asset_img', array($this, 'asset_img')); + $smarty->registerPlugin('function', 'asset_render', array($this, 'asset_render')); + $smarty->registerPlugin('function', 'asset_find_file', array($this, 'asset_find_file')); + $smarty->registerPlugin('function', 'html_anchor', array($this, 'html_anchor')); + $smarty->registerPlugin('function', 'session_get_flash', array($this, 'session_get_flash')); + $smarty->registerPlugin('block', 'markdown', array($this, 'markdown_parse')); + $smarty->registerPlugin('function', 'auth_has_access', array($this, 'auth_has_access')); + $smarty->registerPlugin('function', 'auth_check', array($this, 'auth_check')); + } + + /** + * Return the current Fuel version + */ + public function fuel_version() + { + return \Fuel::VERSION; + } + + /** + * Provides the url() functionality. Generates a full url (including + * domain and index.php). + * + * Usage: {url uri='' params=[name=>$value]} + * + * @return string + */ + public function url($params) + { + $uri = isset($params['uri']) ? $params['uri'] : ''; + $named_params = isset($params['params']) ? $params['params'] : array(); + if ($named_uri = \Router::get($uri, $named_params)) + { + $uri = $named_uri; + } + return \Uri::create($uri); + } + + /** + * Usage: {uri_segment segment=''} + * Required: segment + * + * @return mixed segment string or false + */ + public function uri_segment($params) + { + if (isset($params['segment'])) + { + return \Uri::segment($params['segment']); + } + return false; + } + + /** + * Usage: {config item='' default=''} + * Required: item + * + * @return mixed string or array + */ + public function config_get($params) + { + if (isset($params['item'])) + { + $default = $params['default'] ? null : $params['default']; + return \Config::get($params['item'], $default); + } + return ''; + } + + /** + * Usage: {lang line='id' params=[] default='default value' lang='en'} + * Required: line + * + * @return mixed string or false + */ + public function lang_get($params) + { + if (isset($params['line'])) + { + $parameters = isset($params['params']) ? $params['params'] : array(); + $default = isset($params['default']) ? $params['default'] : null; + $language = isset($params['lang']) ? $params['lang'] : null; + return \Lang::get($params['line'], $parameters, $default, $language); + } + return false; + } + + /** + * Usage: {form attrs=[] hidden=[]}...{/form} + * + * @return string + */ + public function form($params, $content, $smarty, &$repeat) + { + //$content is null when repeat is true and has block content when repeat is false + if ($repeat) + { + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $hidden = isset($params['hidden']) ? $params['hidden'] : array(); + return \Form::open($attributes, $hidden); + } + else + { + return $content . \Form::close(); + } + } + + /** + * Usage: {form_fieldset attrs=[] legend=''}...{/form} + * + * @return string + */ + public function form_fieldset($params, $content, $smarty, &$repeat) + { + //$content is null when repeat is true and has block content when repeat is false + if ($repeat) + { + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $legend = isset($params['legend']) ? $params['legend'] : null; + return \Form::fieldset_open($attributes, $legend); + } + else + { + return $content . \Form::fieldset_close(); + } + } + + /** + * Usage: {form_input field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_input($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::input($params['field'], $value, $attributes); + } + + /** + * Usage: {form_password field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_password($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::password($params['field'], $value, $attributes); + } + + /** + * Usage: {form_hidden field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_hidden($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::hidden($params['field'], $value, $attributes); + } + + /** + * Usage: {form_button field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_button($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::button($params['field'], $value, $attributes); + } + + /** + * Usage: {form_submit field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_submit($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::submit($params['field'], $value, $attributes); + } + + /** + * Usage: {form_reset field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_reset($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::reset($params['field'], $value, $attributes); + } + + /** + * Usage: {form_textarea field='' value='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_textarea($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::textarea($params['field'], $value, $attributes); + } + + /** + * Usage: {form_label text='' id='' attrs=[]} + * Required: text + * + * @return string + */ + public function form_label($params) + { + if ( ! isset($params['text'])) + { + throw new \UnexpectedValueException("The text parameter is required."); + } + $id = isset($params['id']) ? $params['id'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::label($params['text'], $id, $attributes); + } + + /** + * Usage: {form_checkbox field='' value='' checked=false attrs=[]} + * Required: field + * + * @return string + */ + public function form_checkbox($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $checked = isset($params['checked']) ? $params['checked'] : null; + return \Form::checkbox($params['field'], $value, $checked, $attributes); + } + + /** + * Usage: {form_radio field='' value='' checked=false attrs=[]} + * Required: field + * + * @return string + */ + public function form_radio($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $value = isset($params['value']) ? $params['value'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $checked = isset($params['checked']) ? $params['checked'] : null; + return \Form::checkbox($params['field'], $value, $checked, $attributes); + } + + /** + * Usage: {form_select field='' values='' options=[] attrs=[]} + * Required: field + * + * @return string + */ + public function form_select($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $values = isset($params['values']) ? $params['values'] : null; + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + $options = isset($params['options']) ? $params['options'] : array(); + return \Form::select($params['field'], $values, $options, $attributes); + } + + /** + * Usage: {form_file field='' attrs=[]} + * Required: field + * + * @return string + */ + public function form_file($params) + { + if ( ! isset($params['field'])) + { + throw new \UnexpectedValueException("The field parameter is required."); + } + $attributes = isset($params['attrs']) ? $params['attrs'] : array(); + return \Form::file($params['field'], $attributes); + } + + /** + * Provide access to Input::param + * Usage: {form_val index='' default=''} + * + * @return string + */ + public function form_val($params) + { + $index = isset($params['index']) ? $params['index'] : null; + $default = isset($params['default']) ? $params['default'] : null; + return \Input::param($index, $default); + } + + /** + * Provide access to Input::get + * Usage: {input_get index='' default=''} + * + * @return string + */ + public function input_get($params) + { + $index = isset($params['index']) ? $params['index'] : null; + $default = isset($params['default']) ? $params['default'] : null; + return \Input::get($index, $default); + } + + /** + * Provide access to Input::post + * Usage: {input_post index='' default=''} + * + * @return string + */ + public function input_post($params) + { + $index = isset($params['index']) ? $params['index'] : null; + $default = isset($params['default']) ? $params['default'] : null; + return \Input::post($index, $default); + } + + /** + * Provide addess to Asset::add_path + * Usage: {form_val path='' type=''} + * Required: path + * + */ + public function asset_add_path($params) + { + if ( ! isset($params['path'])) + { + throw new \UnexpectedValueException('Asset path must be specified'); + } + $type = isset($params['type']) ? $params['type'] : null; + \Asset::add_path($params['path'], $type); + } + + /** + * Usage: {asset_css refs='' attrs=[] group='' raw=false} + * Required: refs + * + * @return mixed string or nothing if group is filled + */ + public function asset_css($params) + { + if ( ! isset($params['refs'])) + { + throw new \UnexpectedValueException("The refs parameter is required."); + } + $group = isset($params['group']) ? $params['group'] : null; + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + $raw = isset($params['raw']) ? $params['raw'] : false; + return \Asset::css($params['refs'], $attrs, $group, $raw); + } + + /** + * Usage: {asset_js refs='' attrs=[] group='' raw=false} + * Required: refs + * + * @return mixed string or nothing if group is filled + */ + public function asset_js($params) + { + if ( ! isset($params['refs'])) + { + throw new \UnexpectedValueException("The refs parameter is required."); + } + $group = isset($params['group']) ? $params['group'] : null; + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + $raw = isset($params['raw']) ? $params['raw'] : false; + return \Asset::js($params['refs'], $attrs, $group, $raw); + } + + /** + * Usage: {asset_img refs='' attrs=[] group=''} + * Required: refs + * + * @return mixed string or nothing if group is filled + */ + public function asset_img($params) + { + if ( ! isset($params['refs'])) + { + throw new \UnexpectedValueException("The refs parameter is required."); + } + $group = isset($params['group']) ? $params['group'] : null; + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + return \Asset::img($params['refs'], $attrs, $group); + } + + /** + * Render a group of assets + * Usage: {asset_render group='' raw=false} + * + * @return string + */ + public function asset_render($params) + { + $group = isset($params['group']) ? $params['group'] : null; + $raw = isset($params['raw']) ? $params['raw'] : false; + return \Asset::render($group, $raw); + } + + /** + * Usage: {asset_find_file file='' type='' folder=''} + * Required: file and type + * + * @return string + */ + public function asset_find_file($params) + { + if ( ! isset($params['file'])) + { + throw new \UnexpectedValueException("The file parameter is required."); + } + if ( ! isset($params['type'])) + { + throw new \UnexpectedValueException("The type parameter is required."); + } + $folder = isset($params['folder']) ? $params['folder'] : ''; + return \Asset::find_file($params['file'], $params['type'], $folder); + } + + /** + * Usage: {html_anchor href='' text='' attrs='' secure=false} + * Required: href and text + * + * @return string + */ + public function html_anchor($params) + { + if ( ! isset($params['href'])) + { + throw new \UnexpectedValueException("The href parameter is required."); + } + if ( ! isset($params['text'])) + { + throw new \UnexpectedValueException("The text parameter is required."); + } + $attrs = isset($params['attrs']) ? $params['attrs'] : array(); + $secure = isset($params['secure']) ? $params['secure'] : null; + return \Html::anchor($params['href'], $params['text'], $attrs, $secure); + } + + /** + * Usage: {session_get_flash var='' default='' expire=false} + * Required: var + * + * @return mixed + */ + public function session_get_flash($params) + { + if ( ! isset($params['var'])) + { + throw new \UnexpectedValueException("The var parameter is required."); + } + $default = isset($params['default']) ? $params['default'] : null; + $expire = isset($params['expire']) ? $params['expire'] : false; + return \Session::get_flash($params['var'], $default, $expire); + } + + /** + * Usage: {markdown}...{/markdown} + * + * @return string + */ + public function markdown_parse($params, $content, $smarty, &$repeat) + { + //only take action when repeat = false as that is the closing tag + if (!$repeat) + { + return \Markdown::parse($content); + } + } + + /** + * Usage: {auth_has_access cond=''} + * Required: cond + * + * @return bool + */ + public function auth_has_access($params) + { + if ( ! isset($params['cond'])) + { + throw new \UnexpectedValueException("The cond parameter is required."); + } + return \Auth::has_access($params['cond']); + } + + /** + * Usage: {auth_check} + * + * @return bool + */ + public function auth_check() + { + return \Auth::check(); + } } From 7fc3807833350f5328334bf86939f67e015278f9 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Fri, 23 Dec 2016 13:46:42 +0000 Subject: [PATCH 089/120] Added Security token functions to Twig. closes #2041 --- classes/twig/fuel/extension.php | 113 ++++++++++++++++---------------- 1 file changed, 58 insertions(+), 55 deletions(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 6a1102a..be2a6ec 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -43,61 +43,64 @@ public function getName() public function getFunctions() { return array( - 'fuel_version' => new Twig_Function_Method($this, 'fuel_version'), - 'url' => new Twig_Function_Method($this, 'url'), - - 'base_url' => new Twig_Function_Function('Uri::base'), - 'current_url' => new Twig_Function_Function('Uri::current'), - 'uri_segment' => new Twig_Function_Function('Uri::segment'), - 'uri_segments' => new Twig_Function_Function('Uri::segments'), - - 'config' => new Twig_Function_Function('Config::get'), - - 'dump' => new Twig_Function_Function('Debug::dump'), - - 'lang' => new Twig_Function_Function('Lang::get'), - - 'form_open' => new Twig_Function_Function('Form::open'), - 'form_close' => new Twig_Function_Function('Form::close'), - 'form_input' => new Twig_Function_Function('Form::input'), - 'form_password' => new Twig_Function_Function('Form::password'), - 'form_hidden' => new Twig_Function_Function('Form::hidden'), - 'form_radio' => new Twig_Function_Function('Form::radio'), - 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), - 'form_textarea' => new Twig_Function_Function('Form::textarea'), - 'form_file' => new Twig_Function_Function('Form::file'), - 'form_button' => new Twig_Function_Function('Form::button'), - 'form_reset' => new Twig_Function_Function('Form::reset'), - 'form_submit' => new Twig_Function_Function('Form::submit'), - 'form_select' => new Twig_Function_Function('Form::select'), - 'form_label' => new Twig_Function_Function('Form::label'), - - 'form_val' => new Twig_Function_Function('Input::param'), - 'input_get' => new Twig_Function_Function('Input::get'), - 'input_post' => new Twig_Function_Function('Input::post'), - - 'asset_add_path' => new Twig_Function_Function('Asset::add_path'), - 'asset_css' => new Twig_Function_Function('Asset::css'), - 'asset_js' => new Twig_Function_Function('Asset::js'), - 'asset_img' => new Twig_Function_Function('Asset::img'), - 'asset_render' => new Twig_Function_Function('Asset::render'), - 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), - - 'theme_asset_css' => new Twig_Function_Method($this, 'theme_asset_css'), - 'theme_asset_js' => new Twig_Function_Method($this, 'theme_asset_js'), - 'theme_asset_img' => new Twig_Function_Method($this, 'theme_asset_img'), - - 'html_anchor' => new Twig_Function_Function('Html::anchor'), - 'html_mail_to_safe' => new Twig_Function_Function('Html::mail_to_safe'), - - 'session_get' => new Twig_Function_Function('Session::get'), - 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), - - 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), - - 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), - 'auth_check' => new Twig_Function_Function('Auth::check'), - 'auth_get' => new Twig_Function_Function('Auth::get'), + 'fuel_version' => new Twig_Function_Method($this, 'fuel_version'), + 'url' => new Twig_Function_Method($this, 'url'), + + 'base_url' => new Twig_Function_Function('Uri::base'), + 'current_url' => new Twig_Function_Function('Uri::current'), + 'uri_segment' => new Twig_Function_Function('Uri::segment'), + 'uri_segments' => new Twig_Function_Function('Uri::segments'), + + 'config' => new Twig_Function_Function('Config::get'), + + 'dump' => new Twig_Function_Function('Debug::dump'), + + 'lang' => new Twig_Function_Function('Lang::get'), + + 'form_open' => new Twig_Function_Function('Form::open'), + 'form_close' => new Twig_Function_Function('Form::close'), + 'form_input' => new Twig_Function_Function('Form::input'), + 'form_password' => new Twig_Function_Function('Form::password'), + 'form_hidden' => new Twig_Function_Function('Form::hidden'), + 'form_radio' => new Twig_Function_Function('Form::radio'), + 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), + 'form_textarea' => new Twig_Function_Function('Form::textarea'), + 'form_file' => new Twig_Function_Function('Form::file'), + 'form_button' => new Twig_Function_Function('Form::button'), + 'form_reset' => new Twig_Function_Function('Form::reset'), + 'form_submit' => new Twig_Function_Function('Form::submit'), + 'form_select' => new Twig_Function_Function('Form::select'), + 'form_label' => new Twig_Function_Function('Form::label'), + + 'form_val' => new Twig_Function_Function('Input::param'), + 'input_get' => new Twig_Function_Function('Input::get'), + 'input_post' => new Twig_Function_Function('Input::post'), + + 'asset_add_path' => new Twig_Function_Function('Asset::add_path'), + 'asset_css' => new Twig_Function_Function('Asset::css'), + 'asset_js' => new Twig_Function_Function('Asset::js'), + 'asset_img' => new Twig_Function_Function('Asset::img'), + 'asset_render' => new Twig_Function_Function('Asset::render'), + 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), + + 'theme_asset_css' => new Twig_Function_Method($this, 'theme_asset_css'), + 'theme_asset_js' => new Twig_Function_Method($this, 'theme_asset_js'), + 'theme_asset_img' => new Twig_Function_Method($this, 'theme_asset_img'), + + 'html_anchor' => new Twig_Function_Function('Html::anchor'), + 'html_mail_to_safe' => new Twig_Function_Function('Html::mail_to_safe'), + + 'session_get' => new Twig_Function_Function('Session::get'), + 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), + + 'security_js_fetch_token' => new Twig_Function_Function('Security::js_fetch_token'), + 'security_js_set_token' => new Twig_Function_Function('Security::js_set_token'), + + 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), + + 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), + 'auth_check' => new Twig_Function_Function('Auth::check'), + 'auth_get' => new Twig_Function_Function('Auth::get'), ); } From fd7999c2629f288bbc01daa946a150e11e34772b Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 12 Jan 2017 17:26:17 +0000 Subject: [PATCH 090/120] change the default extension for haml files, extensions have to be unique --- config/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/parser.php b/config/parser.php index 23a55af..e1fbf97 100644 --- a/config/parser.php +++ b/config/parser.php @@ -29,7 +29,7 @@ 'extensions' => array( 'php' => 'View', 'twig' => 'View_Twig', - 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'twig'), + 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'haml'), 'mustache' => 'View_Mustache', 'md' => 'View_Markdown', 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), From e647c56566ddc439801ae966821f37dc35a3c5bb Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 12 Jan 2017 17:26:53 +0000 Subject: [PATCH 091/120] added support for Twig 2.x; closes #91 --- classes/twig/fuel/extension.php | 190 ++++++++++++++++++++++---------- classes/view/twig.php | 7 +- 2 files changed, 136 insertions(+), 61 deletions(-) diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index be2a6ec..f7e92d5 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -17,6 +17,7 @@ use Router; use Uri; use Twig_Extension; +use Twig_SimpleFunction; use Twig_Function_Function; use Twig_Function_Method; @@ -42,66 +43,135 @@ public function getName() */ public function getFunctions() { - return array( - 'fuel_version' => new Twig_Function_Method($this, 'fuel_version'), - 'url' => new Twig_Function_Method($this, 'url'), - - 'base_url' => new Twig_Function_Function('Uri::base'), - 'current_url' => new Twig_Function_Function('Uri::current'), - 'uri_segment' => new Twig_Function_Function('Uri::segment'), - 'uri_segments' => new Twig_Function_Function('Uri::segments'), - - 'config' => new Twig_Function_Function('Config::get'), - - 'dump' => new Twig_Function_Function('Debug::dump'), - - 'lang' => new Twig_Function_Function('Lang::get'), - - 'form_open' => new Twig_Function_Function('Form::open'), - 'form_close' => new Twig_Function_Function('Form::close'), - 'form_input' => new Twig_Function_Function('Form::input'), - 'form_password' => new Twig_Function_Function('Form::password'), - 'form_hidden' => new Twig_Function_Function('Form::hidden'), - 'form_radio' => new Twig_Function_Function('Form::radio'), - 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), - 'form_textarea' => new Twig_Function_Function('Form::textarea'), - 'form_file' => new Twig_Function_Function('Form::file'), - 'form_button' => new Twig_Function_Function('Form::button'), - 'form_reset' => new Twig_Function_Function('Form::reset'), - 'form_submit' => new Twig_Function_Function('Form::submit'), - 'form_select' => new Twig_Function_Function('Form::select'), - 'form_label' => new Twig_Function_Function('Form::label'), - - 'form_val' => new Twig_Function_Function('Input::param'), - 'input_get' => new Twig_Function_Function('Input::get'), - 'input_post' => new Twig_Function_Function('Input::post'), - - 'asset_add_path' => new Twig_Function_Function('Asset::add_path'), - 'asset_css' => new Twig_Function_Function('Asset::css'), - 'asset_js' => new Twig_Function_Function('Asset::js'), - 'asset_img' => new Twig_Function_Function('Asset::img'), - 'asset_render' => new Twig_Function_Function('Asset::render'), - 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), - - 'theme_asset_css' => new Twig_Function_Method($this, 'theme_asset_css'), - 'theme_asset_js' => new Twig_Function_Method($this, 'theme_asset_js'), - 'theme_asset_img' => new Twig_Function_Method($this, 'theme_asset_img'), - - 'html_anchor' => new Twig_Function_Function('Html::anchor'), - 'html_mail_to_safe' => new Twig_Function_Function('Html::mail_to_safe'), - - 'session_get' => new Twig_Function_Function('Session::get'), - 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), - - 'security_js_fetch_token' => new Twig_Function_Function('Security::js_fetch_token'), - 'security_js_set_token' => new Twig_Function_Function('Security::js_set_token'), - - 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), - - 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), - 'auth_check' => new Twig_Function_Function('Auth::check'), - 'auth_get' => new Twig_Function_Function('Auth::get'), - ); + // new Twig 2.x syntax + if (class_exists('Twig_SimpleFunction')) + { + return array( + new Twig_SimpleFunction('fuel_version', array($this, 'fuel_version')), + new Twig_SimpleFunction('url', array($this, 'url')), + + new Twig_SimpleFunction('base_url', array('Uri', 'base')), + new Twig_SimpleFunction('current_url', array('Uri', 'current')), + new Twig_SimpleFunction('uri_segment' , array('Uri', 'segment')), + new Twig_SimpleFunction('uri_segments', array('Uri', 'segments')), + + new Twig_SimpleFunction('config', array('Config', 'get')), + + new Twig_SimpleFunction('dump', array('Debug', 'dump')), + + new Twig_SimpleFunction('lang', array('Lang', 'get')), + + new Twig_SimpleFunction('form_open', array('Form', 'open')), + new Twig_SimpleFunction('form_close', array('Form', 'close')), + new Twig_SimpleFunction('form_input', array('Form', 'input')), + new Twig_SimpleFunction('form_password', array('Form', 'password')), + new Twig_SimpleFunction('form_hidden', array('Form', 'hidden')), + new Twig_SimpleFunction('form_radio' , array('Form', 'radio')), + new Twig_SimpleFunction('form_checkbox', array('Form', 'checkbox')), + new Twig_SimpleFunction('form_textarea', array('Form', 'textarea')), + new Twig_SimpleFunction('form_file', array('Form', 'file')), + new Twig_SimpleFunction('form_button', array('Form', 'button')), + new Twig_SimpleFunction('form_reset', array('Form', 'reset')), + new Twig_SimpleFunction('form_submit', array('Form', 'submit')), + new Twig_SimpleFunction('form_select', array('Form', 'select')), + new Twig_SimpleFunction('form_label', array('Form', 'label')), + + new Twig_SimpleFunction('form_val', array('Input', 'param')), + new Twig_SimpleFunction('input_get', array('Input', 'get')), + new Twig_SimpleFunction('input_post', array('Input', 'post')), + + new Twig_SimpleFunction('asset_add_path', array('Asset', 'add_path')), + new Twig_SimpleFunction('asset_css', array('Asset', 'css')), + new Twig_SimpleFunction('asset_js', array('Asset', 'js')), + new Twig_SimpleFunction('asset_img', array('Asset', 'img')), + new Twig_SimpleFunction('asset_render', array('Asset', 'render')), + new Twig_SimpleFunction('asset_find_file', array('Asset', 'find_file')), + + new Twig_SimpleFunction('theme_asset_css', array($this, 'theme_asset_css')), + new Twig_SimpleFunction('theme_asset_js', array($this, 'theme_asset_js')), + new Twig_SimpleFunction('theme_asset_img', array($this, 'theme_asset_img')), + + new Twig_SimpleFunction('html_anchor', array('Html', 'anchor')), + new Twig_SimpleFunction('html_mail_to_safe', array('Html', 'mail_to_safe')), + + new Twig_SimpleFunction('session_get', array('Session', 'get')), + new Twig_SimpleFunction('session_get_flash', array('Session', 'get_flash')), + + new Twig_SimpleFunction('security_js_fetch_token', array('Security', 'js_fetch_token')), + new Twig_SimpleFunction('security_js_set_token', array('Security', 'js_set_token')), + + new Twig_SimpleFunction('markdown_parse', array('Markdown', 'parse')), + + new Twig_SimpleFunction('auth_has_access', array('Auth', 'has_access')), + new Twig_SimpleFunction('auth_check', array('Auth', 'check')), + new Twig_SimpleFunction('auth_get', array('Auth', 'get')), + ); + } + + // backward compatibility for twig 1.x + else + { + return array( + 'fuel_version' => new Twig_Function_Method($this, 'fuel_version'), + 'url' => new Twig_Function_Method($this, 'url'), + + 'base_url' => new Twig_Function_Function('Uri::base'), + 'current_url' => new Twig_Function_Function('Uri::current'), + 'uri_segment' => new Twig_Function_Function('Uri::segment'), + 'uri_segments' => new Twig_Function_Function('Uri::segments'), + + 'config' => new Twig_Function_Function('Config::get'), + + 'dump' => new Twig_Function_Function('Debug::dump'), + + 'lang' => new Twig_Function_Function('Lang::get'), + + 'form_open' => new Twig_Function_Function('Form::open'), + 'form_close' => new Twig_Function_Function('Form::close'), + 'form_input' => new Twig_Function_Function('Form::input'), + 'form_password' => new Twig_Function_Function('Form::password'), + 'form_hidden' => new Twig_Function_Function('Form::hidden'), + 'form_radio' => new Twig_Function_Function('Form::radio'), + 'form_checkbox' => new Twig_Function_Function('Form::checkbox'), + 'form_textarea' => new Twig_Function_Function('Form::textarea'), + 'form_file' => new Twig_Function_Function('Form::file'), + 'form_button' => new Twig_Function_Function('Form::button'), + 'form_reset' => new Twig_Function_Function('Form::reset'), + 'form_submit' => new Twig_Function_Function('Form::submit'), + 'form_select' => new Twig_Function_Function('Form::select'), + 'form_label' => new Twig_Function_Function('Form::label'), + + 'form_val' => new Twig_Function_Function('Input::param'), + 'input_get' => new Twig_Function_Function('Input::get'), + 'input_post' => new Twig_Function_Function('Input::post'), + + 'asset_add_path' => new Twig_Function_Function('Asset::add_path'), + 'asset_css' => new Twig_Function_Function('Asset::css'), + 'asset_js' => new Twig_Function_Function('Asset::js'), + 'asset_img' => new Twig_Function_Function('Asset::img'), + 'asset_render' => new Twig_Function_Function('Asset::render'), + 'asset_find_file' => new Twig_Function_Function('Asset::find_file'), + + 'theme_asset_css' => new Twig_Function_Method($this, 'theme_asset_css'), + 'theme_asset_js' => new Twig_Function_Method($this, 'theme_asset_js'), + 'theme_asset_img' => new Twig_Function_Method($this, 'theme_asset_img'), + + 'html_anchor' => new Twig_Function_Function('Html::anchor'), + 'html_mail_to_safe' => new Twig_Function_Function('Html::mail_to_safe'), + + 'session_get' => new Twig_Function_Function('Session::get'), + 'session_get_flash' => new Twig_Function_Function('Session::get_flash'), + + 'security_js_fetch_token' => new Twig_Function_Function('Security::js_fetch_token'), + 'security_js_set_token' => new Twig_Function_Function('Security::js_set_token'), + + 'markdown_parse' => new Twig_Function_Function('Markdown::parse'), + + 'auth_has_access' => new Twig_Function_Function('Auth::has_access'), + 'auth_check' => new Twig_Function_Function('Auth::check'), + 'auth_get' => new Twig_Function_Function('Auth::get'), + ); + } } /** diff --git a/classes/view/twig.php b/classes/view/twig.php index aea3f03..85f7530 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -28,7 +28,12 @@ class View_Twig extends \View public static function _init() { parent::_init(); - Twig_Autoloader::register(); + + // backward compatibility for Twig 1.x + if (class_exists('Twig_Autoloader')) + { + Twig_Autoloader::register(); + } } protected function process_file($file_override = false) From 0a8917df368ae0b8ad9f5ae50cb5d1640a795bde Mon Sep 17 00:00:00 2001 From: WanWizard Date: Tue, 17 Jan 2017 15:34:29 +0000 Subject: [PATCH 092/120] Refactored the Jade parser code; closes #92 --- classes/view/jade.php | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/classes/view/jade.php b/classes/view/jade.php index cc89d5c..484ec45 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -19,46 +19,55 @@ class View_Jade extends \View { - protected static $_parser; - protected static $_cache; + /** + * @InheritDoc + */ + public $extension = 'jade'; /** * Returns the Parser lib object * * @return Everzet\Jade */ - public static function everzet_parser() + protected function everzet_parser($cachepath) { - // load a parser object - if (empty(static::$_parser)) - { - $parser = new Everzet\Parser(new Everzet\Lexer\Lexer()); - $dumper = new Everzet\Dumper\PHPDumper(); - $dumper->registerVisitor('tag', new Everzet\Visitor\AutotagsVisitor()); - $dumper->registerFilter('javascript', new Everzet\Filter\JavaScriptFilter()); - $dumper->registerFilter('cdata', new Everzet\Filter\CDATAFilter()); - $dumper->registerFilter('php', new Everzet\Filter\PHPFilter()); - $dumper->registerFilter('style', new Everzet\Filter\CSSFilter()); - - static::$_parser = new Everzet\Jade($parser, $dumper, static::$_cache); - } - - return static::$_parser; + // create a parser object + $parser = new Everzet\Parser(new Everzet\Lexer\Lexer()); + + // create a dumper object + $dumper = new Everzet\Dumper\PHPDumper(); + $dumper->registerVisitor('tag', new Everzet\Visitor\AutotagsVisitor()); + $dumper->registerFilter('javascript', new Everzet\Filter\JavaScriptFilter()); + $dumper->registerFilter('cdata', new Everzet\Filter\CDATAFilter()); + $dumper->registerFilter('php', new Everzet\Filter\PHPFilter()); + $dumper->registerFilter('style', new Everzet\Filter\CSSFilter()); + + // return the Jade parser + return new Everzet\Jade($parser, $dumper, $cachepath); } /** - * @InheritDoc + * Returns the Parser lib object + * + * @return Tale\Jade */ - public $extension = 'jade'; + protected function tale_parser($cachepath) + { + // get the config + $config = \Config::get('parser.View_Jade', array()); + + // add the cache path for this template + $config['cachePath'] = $cachepath; + + // create a renderer instance + return new Tale\Renderer($config); + } /** * @InheritDoc */ protected function process_file($file_override = false) { - // update the cache path - $this->cache_init($file); - // determine the filename $file = $file_override ?: $this->file_name; @@ -66,24 +75,15 @@ protected function process_file($file_override = false) if (class_exists('Everzet\\Jade\\Jade')) { // render the template - $file = static::everzet_parser()->cache($file); + $file = $this->everzet_parser($this->cache_init($file))->cache($file); $result = parent::process_file($file); } // render the template using the Tale implementation elseif (class_exists('Tale\\Jade\\Renderer')) { - // get the config - $config = \Config::get('parser.View_Jade', array()); - - // set our cache path - $config['cachePath'] = static::$_cache; - - // create a renderer instance - static::$_jade = new Tale\Renderer($config); - // render the template - $result = static::$_jade->render($file, $data = $this->get_data()); + $result = $this->jade_parser($this->cache_init($file))->render($file, $data = $this->get_data()); // disable sanitization on objects that support it $this->unsanitize($data); @@ -113,7 +113,7 @@ protected function cache_init($file_path) mkdir($cache_path, 0777, true); } - static::$_cache = $cache_path; + return $cache_path; } } From f8ff2ab371f369446666a2f8c2a1ed9cc18deb85 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 25 Jan 2017 02:28:23 +0000 Subject: [PATCH 093/120] updated the copyright header --- bootstrap.php | 2 +- classes/smarty/fuel/extension.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 2 +- classes/view/jade.php | 2 +- classes/view/lex.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 03589aa..8156e12 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index 8399cd7..c723546 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index f7e92d5..8a05cbb 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 4d5e260..bf2486c 100644 --- a/classes/view.php +++ b/classes/view.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index bd1756d..2caf7b7 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index 4ab9af3..d05ca23 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 77fe52d..d1443c1 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index 484ec45..319a631 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/lex.php b/classes/view/lex.php index 818fc61..a4d55ef 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 0ab91f2..a39019c 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index c676285..39c0eab 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index f3cad51..ae0a0f6 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 6e73daf..157908e 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index 85f7530..bc2f842 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index e1fbf97..3b0875c 100644 --- a/config/parser.php +++ b/config/parser.php @@ -8,7 +8,7 @@ * @version 1.8 * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2016 Fuel Development Team + * @copyright 2010 - 2017 Fuel Development Team * @link http://fuelphp.com */ From 29d6d2379aca04c22c09ec6aed05d22950955b72 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 6 May 2017 15:11:38 +0100 Subject: [PATCH 094/120] Remove the markdown include, the View parser uses the composer package closes #95 --- config/parser.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/parser.php b/config/parser.php index 3b0875c..d995d14 100644 --- a/config/parser.php +++ b/config/parser.php @@ -48,7 +48,6 @@ // MARKDOWN ( http://michelf.com/projects/php-markdown/ ) // ------------------------------------------------------------------------ 'View_Markdown' => array( - 'include' => \Package::exists('parser').'vendor'.DS.'markdown'.DS.'markdown.php', 'auto_encode' => true, 'allow_php' => true, ), From e10d61687b0564b8649b6fe52a2da4c9eba2db0c Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 5 Jul 2017 15:02:34 +0100 Subject: [PATCH 095/120] fixes exception when no view file is given; related fuel/core#1992 related dd8f60343c71ccd141403749b0c5f48823d501d9 --- classes/view.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/classes/view.php b/classes/view.php index bf2486c..8e1a115 100644 --- a/classes/view.php +++ b/classes/view.php @@ -65,25 +65,34 @@ public static function forge($file = null, $data = null, $auto_encode = null) $class = null; $extension = 'php'; + // if a view file was given if ($file !== null) { + // get its type and check if a parser extension is defined $extension = pathinfo($file, PATHINFO_EXTENSION); $class = \Config::get('parser.extensions.'.$extension, null); } + // if no extension is defined, use the called class if ($class === null) { $class = get_called_class(); } - // Class can be an array config - if (is_array($class)) + // class can also be an array config + elseif (is_array($class)) { $class['extension'] and $extension = $class['extension']; $class = $class['class']; } - // Include necessary files + // if no auto-encode flag is given, get it from config + if ($auto_encode === null) + { + $auto_encode = \Config::get('parser.'.$class.'.auto_encode', null); + } + + // include necessary parser files foreach ((array) \Config::get('parser.'.$class.'.include', array()) as $include) { if ( ! array_key_exists($include, static::$loaded_files)) @@ -93,14 +102,16 @@ public static function forge($file = null, $data = null, $auto_encode = null) } } - // Instantiate the Parser class without auto-loading the view file - if ($auto_encode === null) + // instantiate the Parser class without auto-loading the view file + $view = new $class(null, $data, $auto_encode); + + // if we have a view file, set it + if ($file) { - $auto_encode = \Config::get('parser.'.$class.'.auto_encode', null); + $view->set_filename($file, true); } - $view = new $class(null, $data, $auto_encode); - - return $view->set_filename($file, true); + // and return the view object + return $view; } } From 765b4a2676f87d9b1e0ead524181563207a54e7d Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sun, 8 Oct 2017 21:46:11 +0100 Subject: [PATCH 096/120] fixed typo in the mustache partial loader --- classes/view/mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 39c0eab..a618a4e 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -71,7 +71,7 @@ public static function parser() $options['helpers'] = $helpers; } - if ($partials = \Config::get('parser.View_Mustache.environment.partials_loader', 'UTF-8')) + if ($partials = \Config::get('parser.View_Mustache.environment.partials_loader', array())) { $options['partials_loader'] = new Mustache_Loader_FilesystemLoader($partials); } From 418851996747c00302dcdfd1afc4552f96559f75 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 15 Jan 2018 13:37:28 +0100 Subject: [PATCH 097/120] fixed severly broken template loading, 1.8 functionality restored --- classes/view.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/classes/view.php b/classes/view.php index 8e1a115..5a06d3f 100644 --- a/classes/view.php +++ b/classes/view.php @@ -23,17 +23,7 @@ class View extends \Fuel\Core\View public static function _init() { - // get and normalize the config - $parser = \Config::load('parser', true); - foreach (\Config::get('parser.extensions', array()) as $extension => $config) - { - if (isset($config['extension'])) - { - unset($parser['extensions'][$extension]); - $parser['extensions'][$config['extension']] = $config; - } - } - \Config::set('parser', $parser); + \Config::load('parser', true); // Get class name $class = \Inflector::denamespace(get_called_class()); @@ -63,7 +53,6 @@ public static function _init() public static function forge($file = null, $data = null, $auto_encode = null) { $class = null; - $extension = 'php'; // if a view file was given if ($file !== null) @@ -73,6 +62,12 @@ public static function forge($file = null, $data = null, $auto_encode = null) $class = \Config::get('parser.extensions.'.$extension, null); } + // Only get rid of the extension if it is not an absolute file path + if ($file !== null and $file[0] !== '/' and $file[1] !== ':') + { + $file = $extension ? preg_replace('/\.'.preg_quote($extension).'$/i', '', $file) : $file; + } + // if no extension is defined, use the called class if ($class === null) { @@ -108,6 +103,9 @@ public static function forge($file = null, $data = null, $auto_encode = null) // if we have a view file, set it if ($file) { + // Set extension when given + $extension and $view->extension = $extension; + $view->set_filename($file, true); } From 7a12c3e6e8e2ad49b4ee69327a9565207dc74778 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 15 Jan 2018 13:40:57 +0100 Subject: [PATCH 098/120] only strip the extension if there is a filename; avoid a PHP notice error --- classes/view.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/view.php b/classes/view.php index 5a06d3f..7a08dcf 100644 --- a/classes/view.php +++ b/classes/view.php @@ -60,12 +60,12 @@ public static function forge($file = null, $data = null, $auto_encode = null) // get its type and check if a parser extension is defined $extension = pathinfo($file, PATHINFO_EXTENSION); $class = \Config::get('parser.extensions.'.$extension, null); - } - // Only get rid of the extension if it is not an absolute file path - if ($file !== null and $file[0] !== '/' and $file[1] !== ':') - { - $file = $extension ? preg_replace('/\.'.preg_quote($extension).'$/i', '', $file) : $file; + // Only get rid of the extension if it is not an absolute file path + if ($file[0] !== '/' and $file[1] !== ':') + { + $file = $extension ? preg_replace('/\.'.preg_quote($extension).'$/i', '', $file) : $file; + } } // if no extension is defined, use the called class @@ -104,7 +104,7 @@ public static function forge($file = null, $data = null, $auto_encode = null) if ($file) { // Set extension when given - $extension and $view->extension = $extension; + isset($extension) and $view->extension = $extension; $view->set_filename($file, true); } From 3bd46e283daa7622ac8a7996e754ed28d900375f Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 15 Jan 2018 15:11:01 +0100 Subject: [PATCH 099/120] only set the view object extension when the requested file had one --- classes/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view.php b/classes/view.php index 7a08dcf..0bb8040 100644 --- a/classes/view.php +++ b/classes/view.php @@ -104,7 +104,7 @@ public static function forge($file = null, $data = null, $auto_encode = null) if ($file) { // Set extension when given - isset($extension) and $view->extension = $extension; + empty($extension) or $view->extension = $extension; $view->set_filename($file, true); } From 8e4ffaefa2c9ec7b9de9f0511a8fa17732c9af3b Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 17 Jan 2018 14:30:25 +0100 Subject: [PATCH 100/120] experimental support for Handlebar templates using the zordius/lightncandy renderer --- bootstrap.php | 1 + classes/view/handlebars.php | 63 +++++++++++++++++++++++++++++++++++++ config/parser.php | 38 +++++++++++++++------- 3 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 classes/view/handlebars.php diff --git a/bootstrap.php b/bootstrap.php index 8156e12..3aee2eb 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -22,6 +22,7 @@ 'Parser\\View_Twig' => __DIR__.'/classes/view/twig.php', 'Parser\\View_HamlTwig' => __DIR__.'/classes/view/hamltwig.php', 'Parser\\View_Jade' => __DIR__.'/classes/view/jade.php', + 'Parser\\View_Handlebars' => __DIR__.'/classes/view/handlebars.php', 'Parser\\View_Haml' => __DIR__.'/classes/view/haml.php', 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php new file mode 100644 index 0000000..2ee0201 --- /dev/null +++ b/classes/view/handlebars.php @@ -0,0 +1,63 @@ +file_name; + + // compiled template path + $path = rtrim(\Config::get('parser.View_Handlebars.compile_dir', APPPATH.'tmp'.DS.'handlebars'),DS).DS; + + // construct the compiled filename + $compiled = md5($file); + $compiled = $path.substr($compiled, 0, 1).DS.substr($compiled, 1, 1).DS.substr($compiled, 2).'.'.$this->extension; + + // do we need to compile? + if ( ! is_file($compiled) or filemtime($file) > filemtime($compiled) or \Config::get('parser.View_Handlebars.force_compile', true)) + { + file_put_contents($compiled, ' function($cx, $name) { return \Finder::search('views', $name, '.'.$this->extension, false, false); } + ) + \Config::get('parser.View_Handlebars.environment', array()) + )); + } + + // fetch the compiled template and render it + try + { + $result = include($compiled); + $result = $result($this->get_data()); + } + catch (\Exception $e) + { + // Delete the output buffer & re-throw the exception + ob_end_clean(); + throw $e; + } + + $this->unsanitize($data); + return $result; + } +} diff --git a/config/parser.php b/config/parser.php index d995d14..e6f15a9 100644 --- a/config/parser.php +++ b/config/parser.php @@ -21,23 +21,26 @@ * This will allow you to upgrade fuel without losing your custom config. */ +use LightnCandy\LightnCandy; + return array( // ------------------------------------------------------------------------ // Register extensions to their parsers, either classname or array config // ------------------------------------------------------------------------ 'extensions' => array( - 'php' => 'View', - 'twig' => 'View_Twig', - 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'haml'), - 'mustache' => 'View_Mustache', - 'md' => 'View_Markdown', - 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), - 'jade' => 'View_Jade', - 'haml' => 'View_Haml', - 'smarty' => 'View_Smarty', - 'phptal' => 'View_Phptal', - 'lex' => 'View_Lex', + 'php' => 'View', + 'twig' => 'View_Twig', + 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'haml'), + 'mustache' => 'View_Mustache', + 'md' => 'View_Markdown', + 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), + 'jade' => 'View_Jade', + 'handlebars' => 'View_Handlebars', + 'haml' => 'View_Haml', + 'smarty' => 'View_Smarty', + 'phptal' => 'View_Phptal', + 'lex' => 'View_Lex', ), // ------------------------------------------------------------------------ @@ -196,4 +199,17 @@ 'scope_glue' => '.', 'allow_php' => false, ), + + // Handlebars ( https://github.com/zordius/lightncandy ) + // Packagist url: https://packagist.org/packages/zordius/lightncandy + // ------------------------------------------------------------------------ + 'View_Handlebars' => array( + 'force_compile' => true, + 'compile_dir' => APPPATH.'tmp'.DS.'handlebars'.DS, + 'environment' => array( + 'flags' => LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_ELSE | LightnCandy::FLAG_HBESCAPE | LightnCandy::FLAG_JS, + 'helpers' => array(), + 'helperresolver' => function($cx, $name) { return; }, + ), + ), ); From 71450b27a0787bd76b77581bf4b405af260e1480 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 17 Jan 2018 17:20:29 +0100 Subject: [PATCH 101/120] make sure the path to store the compiled template exists --- classes/view/handlebars.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 2ee0201..62544e1 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -36,6 +36,13 @@ protected function process_file($file_override = false) // do we need to compile? if ( ! is_file($compiled) or filemtime($file) > filemtime($compiled) or \Config::get('parser.View_Handlebars.force_compile', true)) { + // make sure the directory exists + if ( ! is_dir($compiled_path = dirname($compiled))) + { + \File::create_dir($path, substr($compiled_path, strlen($path))); + } + + // write the compiled code file_put_contents($compiled, ' Date: Wed, 17 Jan 2018 18:27:45 +0100 Subject: [PATCH 102/120] create the path from APPPATH, to make sure it completely exists --- classes/view/handlebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 62544e1..6d4d895 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -39,7 +39,7 @@ protected function process_file($file_override = false) // make sure the directory exists if ( ! is_dir($compiled_path = dirname($compiled))) { - \File::create_dir($path, substr($compiled_path, strlen($path))); + \File::create_dir(APPPATH, substr($compiled_path, strlen(APPPATH))); } // write the compiled code From 142cb4c171798b49c82ae2d4a474f7e606c1c8ee Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 17 Jan 2018 19:59:03 +0100 Subject: [PATCH 103/120] fetch the data into a variable so cleaning can be reversed after rendering --- classes/view/handlebars.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 6d4d895..179d753 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -54,8 +54,9 @@ protected function process_file($file_override = false) // fetch the compiled template and render it try { + $data = $this->get_data(); $result = include($compiled); - $result = $result($this->get_data()); + $result = $result($data); } catch (\Exception $e) { From 9126328b14156a3767e9614592d7c50391bb393d Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 20 Jan 2018 13:28:09 +0100 Subject: [PATCH 104/120] return the partial content instead of the path --- classes/view/handlebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 179d753..d0aae16 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -46,7 +46,7 @@ protected function process_file($file_override = false) file_put_contents($compiled, ' function($cx, $name) { return \Finder::search('views', $name, '.'.$this->extension, false, false); } + 'partialresolver' => function($cx, $name) { $file = \Finder::search('views', $name, '.'.$this->extension, false, false); return empty($file) ? '' : include($file); } ) + \Config::get('parser.View_Handlebars.environment', array()) )); } From bcfa2fcaec32914388475f23ef8b2f39d5a8cb79 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 20 Jan 2018 14:40:11 +0100 Subject: [PATCH 105/120] do not include the partial but return it's content --- classes/view/handlebars.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index d0aae16..7fddd05 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -46,7 +46,7 @@ protected function process_file($file_override = false) file_put_contents($compiled, ' function($cx, $name) { $file = \Finder::search('views', $name, '.'.$this->extension, false, false); return empty($file) ? '' : include($file); } + 'partialresolver' => function($cx, $name) { $file = \Finder::search('views', $name, '.'.$this->extension, false, false); return empty($file) ? "[ PARTIAL $name NOT FOUND!]" : file_get_contents($file); } ) + \Config::get('parser.View_Handlebars.environment', array()) )); } From dac973f2240213e5df68ced84f543bc71605826e Mon Sep 17 00:00:00 2001 From: WanWizard Date: Sat, 20 Jan 2018 14:43:48 +0100 Subject: [PATCH 106/120] reformat for better readability --- classes/view/handlebars.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 7fddd05..86ea13b 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -46,7 +46,10 @@ protected function process_file($file_override = false) file_put_contents($compiled, ' function($cx, $name) { $file = \Finder::search('views', $name, '.'.$this->extension, false, false); return empty($file) ? "[ PARTIAL $name NOT FOUND!]" : file_get_contents($file); } + 'partialresolver' => function($cx, $name) { + $file = \Finder::search('views', $name, '.'.$this->extension, false, false); + return empty($file) ? "[ PARTIAL $name NOT FOUND!]" : file_get_contents($file); + } ) + \Config::get('parser.View_Handlebars.environment', array()) )); } From 1134929886e53dbabfff21d5f618f74136869762 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 8 Feb 2018 22:28:06 +0000 Subject: [PATCH 107/120] remove unintended dependency on the lightncandy package --- config/parser.php | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/config/parser.php b/config/parser.php index e6f15a9..9238036 100644 --- a/config/parser.php +++ b/config/parser.php @@ -21,26 +21,23 @@ * This will allow you to upgrade fuel without losing your custom config. */ -use LightnCandy\LightnCandy; - return array( // ------------------------------------------------------------------------ // Register extensions to their parsers, either classname or array config // ------------------------------------------------------------------------ 'extensions' => array( - 'php' => 'View', - 'twig' => 'View_Twig', - 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'haml'), - 'mustache' => 'View_Mustache', - 'md' => 'View_Markdown', - 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), - 'jade' => 'View_Jade', - 'handlebars' => 'View_Handlebars', - 'haml' => 'View_Haml', - 'smarty' => 'View_Smarty', - 'phptal' => 'View_Phptal', - 'lex' => 'View_Lex', + 'php' => 'View', + 'twig' => 'View_Twig', + 'mthaml' => array('class' => 'View_HamlTwig', 'extension' => 'haml'), + 'mustache' => 'View_Mustache', + 'md' => 'View_Markdown', + 'dwoo' => array('class' => 'View_Dwoo', 'extension' => 'tpl'), + 'jade' => 'View_Jade', + 'haml' => 'View_Haml', + 'smarty' => 'View_Smarty', + 'phptal' => 'View_Phptal', + 'lex' => 'View_Lex', ), // ------------------------------------------------------------------------ @@ -179,7 +176,7 @@ ), ), - // Phptal ( http://phptal.org/manual/en/ ) + // PHPTAL ( http://phptal.org/manual/en/ ) // ------------------------------------------------------------------------ 'View_Phptal' => array( 'include' => APPPATH.'vendor'.DS.'PHPTAL'.DS.'PHPTAL.php', @@ -192,7 +189,7 @@ 'force_reparse' => false, ), - // Lex ( http://github.com/pyrocms/lex/ ) + // LEX ( http://github.com/pyrocms/lex/ ) // Packagist url: https://packagist.org/packages/pyrocms/lex // ------------------------------------------------------------------------ 'View_Lex' => array( @@ -200,16 +197,17 @@ 'allow_php' => false, ), - // Handlebars ( https://github.com/zordius/lightncandy ) + // HANDLEBARS ( https://github.com/zordius/lightncandy ) // Packagist url: https://packagist.org/packages/zordius/lightncandy // ------------------------------------------------------------------------ 'View_Handlebars' => array( 'force_compile' => true, 'compile_dir' => APPPATH.'tmp'.DS.'handlebars'.DS, 'environment' => array( - 'flags' => LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_ELSE | LightnCandy::FLAG_HBESCAPE | LightnCandy::FLAG_JS, + 'flags' => class_exists('LightnCandy\LightnCandy') ? LightnCandy\LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy\LightnCandy::FLAG_ELSE | LightnCandy\LightnCandy::FLAG_HBESCAPE | LightnCandy\LightnCandy::FLAG_JS : 0, 'helpers' => array(), 'helperresolver' => function($cx, $name) { return; }, ), ), + ); From ffcfea36cd3608a5da56a5757649c40af104324c Mon Sep 17 00:00:00 2001 From: WanWizard Date: Thu, 19 Apr 2018 00:03:28 +0100 Subject: [PATCH 108/120] unified docblock headers --- README.md | 9 +++++++-- bootstrap.php | 8 +++----- classes/smarty/fuel/extension.php | 8 +++----- classes/twig/fuel/extension.php | 8 +++----- classes/view.php | 8 +++----- classes/view/dwoo.php | 8 +++----- classes/view/haml.php | 8 +++----- classes/view/hamltwig.php | 8 +++----- classes/view/handlebars.php | 8 +++----- classes/view/jade.php | 8 +++----- classes/view/lex.php | 8 +++----- classes/view/markdown.php | 8 +++----- classes/view/mustache.php | 8 +++----- classes/view/phptal.php | 8 +++----- classes/view/smarty.php | 8 +++----- classes/view/twig.php | 8 +++----- config/parser.php | 8 +++----- 17 files changed, 55 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index d07b9c2..feb6680 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ View::forge('example.lex'); // load a Dwoo template, ATTENTION: this one expects app/views/example.tpl View::forge('example.dwoo'); + +// load a Handlebars template, will load and parse app/views/example.handlebars +View::forge('example.handlebars'); + ``` ## Installing parsers @@ -50,9 +54,10 @@ Simply add the libraries to your project's `composer.json` then run `php compose "dwoo/dwoo" : "*", "mustache/mustache" : "*", "smarty/smarty" : "*", - "twig/twig" : "*", + "twig/twig" : "2.*", "mthaml/mthaml": "*", - "pyrocms/lex": "*" + "pyrocms/lex": "*", + "zordius/lightncandy" : "dev-master" } } ``` diff --git a/bootstrap.php b/bootstrap.php index 3aee2eb..f653252 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,14 +1,12 @@ Date: Thu, 27 Jun 2019 15:09:47 +0100 Subject: [PATCH 109/120] bumped copyright and website link --- bootstrap.php | 4 ++-- classes/smarty/fuel/extension.php | 4 ++-- classes/twig/fuel/extension.php | 4 ++-- classes/view.php | 4 ++-- classes/view/dwoo.php | 4 ++-- classes/view/haml.php | 4 ++-- classes/view/hamltwig.php | 4 ++-- classes/view/handlebars.php | 4 ++-- classes/view/jade.php | 4 ++-- classes/view/lex.php | 4 ++-- classes/view/markdown.php | 4 ++-- classes/view/mustache.php | 4 ++-- classes/view/phptal.php | 4 ++-- classes/view/smarty.php | 4 ++-- classes/view/twig.php | 4 ++-- config/parser.php | 4 ++-- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index f653252..8e6f2ba 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ \Autoloader::add_core_namespace('Parser'); diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index dc95698..a2b5e8b 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 13a0b3c..3f1b092 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view.php b/classes/view.php index b8fdf08..0d7735b 100644 --- a/classes/view.php +++ b/classes/view.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 679f410..7f9462a 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/haml.php b/classes/view/haml.php index 64c2caa..6003693 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 0c9270a..3658468 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 3ce41a8..bd9132b 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/jade.php b/classes/view/jade.php index a61de31..4f1246e 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/lex.php b/classes/view/lex.php index 983ba74..18bcf24 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/markdown.php b/classes/view/markdown.php index 7d5e6db..b704b24 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 2860066..de7f66b 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 108afab..f82c149 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/smarty.php b/classes/view/smarty.php index 9268395..abd01d8 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/classes/view/twig.php b/classes/view/twig.php index 0587f19..5bc945c 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ namespace Parser; diff --git a/config/parser.php b/config/parser.php index d7a31c9..0e4de88 100644 --- a/config/parser.php +++ b/config/parser.php @@ -6,8 +6,8 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2018 Fuel Development Team - * @link http://fuelphp.com + * @copyright 2010 - 2019 Fuel Development Team + * @link https://fuelphp.com */ /** From 93c29875b57d95baf1fb7aea600e8b13ef0195cf Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 2 Mar 2020 12:54:37 +0000 Subject: [PATCH 110/120] added support for Twig v3 (untested) --- classes/view/twig.php | 47 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index 5bc945c..7ef8db7 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -45,9 +45,31 @@ protected function process_file($file_override = false) $view_name = pathinfo($file, PATHINFO_BASENAME); // Twig Loader - $views_paths = \Config::get('parser.View_Twig.views_paths', array(APPPATH . 'views')); + $views_paths = \Config::get('parser.View_Twig.views_paths'); + if ( ! $view_paths) + { + // get the paths defined in the active request + if (class_exists('Request', false) and ($request = \Request::active())) + { + $views_paths = array(); + foreach ($request->get_paths() as $path) + { + $views_paths[] = $path . 'views'; + } + } + $views_pathsp[] = APPPATH . 'views'; + } array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); - static::$_parser_loader = new Twig_Loader_Filesystem($views_paths); + + // check if we're using Twig v3 + if (class_exists('\Twig\Loader\FileSystemLoader')) + { + static::$_parser_loader = new \Twig\Loader\FileSystemLoader($views_paths); + } + else + { + static::$_parser_loader = new Twig_Loader_Filesystem($views_paths); + } if ( ! empty($global_data)) { @@ -62,7 +84,15 @@ protected function process_file($file_override = false) static::parser(); } - $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); + // check if we're using Twig v3 + if (class_exists('\Twig\Lexer')) + { + $twig_lexer = new \Twig\Lexer(static::$_parser, static::$_twig_lexer_conf); + } + else + { + $twig_lexer = new Twig_Lexer(static::$_parser, static::$_twig_lexer_conf); + } static::$_parser->setLexer($twig_lexer); try @@ -99,7 +129,16 @@ public static function parser() // Twig Environment $twig_env_conf = \Config::get('parser.View_Twig.environment', array('optimizer' => -1)); - static::$_parser = new Twig_Environment(static::$_parser_loader, $twig_env_conf); + + // check if we're using Twig v3 + if (class_exists('\Twig\Environment')) + { + static::$_parser = new \Twig\Environment(static::$_parser_loader, $twig_env_conf); + } + else + { + static::$_parser = new Twig_Environment(static::$_parser_loader, $twig_env_conf); + } foreach (\Config::get('parser.View_Twig.extensions') as $ext) { From f139e47c9615e418960e5d2de5c701391622b5dc Mon Sep 17 00:00:00 2001 From: omoon Date: Mon, 23 Mar 2020 15:35:35 +0900 Subject: [PATCH 111/120] fix variable typo of twig $views_paths --- classes/view/twig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index 7ef8db7..b6ccd43 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -46,7 +46,7 @@ protected function process_file($file_override = false) // Twig Loader $views_paths = \Config::get('parser.View_Twig.views_paths'); - if ( ! $view_paths) + if ( ! $views_paths) { // get the paths defined in the active request if (class_exists('Request', false) and ($request = \Request::active())) From 16979a5f44443909a611d6a43483ca9c91be1161 Mon Sep 17 00:00:00 2001 From: Benjamin_adam Date: Fri, 12 Aug 2022 13:10:19 +0200 Subject: [PATCH 112/120] Full support for twig 3.x --- bootstrap.php | 5 +- classes/twig/fuel/extension.php | 68 ++++++++++++++++++++++++- classes/twig/fuel/extension/wrapper.php | 35 +++++++++++++ classes/view/twig.php | 15 +++++- 4 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 classes/twig/fuel/extension/wrapper.php diff --git a/bootstrap.php b/bootstrap.php index 8e6f2ba..515ba97 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -26,6 +26,7 @@ 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', 'Parser\\View_Lex' => __DIR__.'/classes/view/lex.php', - 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', - 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', + 'Parser\\Twig_Fuel_Extension_Wrapper' => __DIR__.'/classes/twig/fuel/extension/wrapper.php', + 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', + 'Parser\\Smarty_Fuel_Extension' => __DIR__.'/classes/smarty/fuel/extension.php', )); diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index 3f1b092..e05f715 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -22,7 +22,7 @@ /** * Provides Twig support for commonly used FuelPHP classes and methods. */ -class Twig_Fuel_Extension extends Twig_Extension +class Twig_Fuel_Extension extends Twig_Fuel_Extension_Wrapper { /** * Gets the name of the extension. @@ -41,8 +41,72 @@ public function getName() */ public function getFunctions() { + // new Twig 3.x syntax + if(class_exists('\Twig\TwigFunction')) + { + return array( + new \Twig\TwigFunction('fuel_version', array($this, 'fuel_version')), + new \Twig\TwigFunction('url', array($this, 'url')), + + new \Twig\TwigFunction('base_url', array('Uri', 'base')), + new \Twig\TwigFunction('current_url', array('Uri', 'current')), + new \Twig\TwigFunction('uri_segment' , array('Uri', 'segment')), + new \Twig\TwigFunction('uri_segments', array('Uri', 'segments')), + + new \Twig\TwigFunction('config', array('Config', 'get')), + + new \Twig\TwigFunction('dump', array('Debug', 'dump')), + + new \Twig\TwigFunction('lang', array('Lang', 'get')), + + new \Twig\TwigFunction('form_open', array('Form', 'open')), + new \Twig\TwigFunction('form_close', array('Form', 'close')), + new \Twig\TwigFunction('form_input', array('Form', 'input')), + new \Twig\TwigFunction('form_password', array('Form', 'password')), + new \Twig\TwigFunction('form_hidden', array('Form', 'hidden')), + new \Twig\TwigFunction('form_radio' , array('Form', 'radio')), + new \Twig\TwigFunction('form_checkbox', array('Form', 'checkbox')), + new \Twig\TwigFunction('form_textarea', array('Form', 'textarea')), + new \Twig\TwigFunction('form_file', array('Form', 'file')), + new \Twig\TwigFunction('form_button', array('Form', 'button')), + new \Twig\TwigFunction('form_reset', array('Form', 'reset')), + new \Twig\TwigFunction('form_submit', array('Form', 'submit')), + new \Twig\TwigFunction('form_select', array('Form', 'select')), + new \Twig\TwigFunction('form_label', array('Form', 'label')), + + new \Twig\TwigFunction('form_val', array('Input', 'param')), + new \Twig\TwigFunction('input_get', array('Input', 'get')), + new \Twig\TwigFunction('input_post', array('Input', 'post')), + + new \Twig\TwigFunction('asset_add_path', array('Asset', 'add_path')), + new \Twig\TwigFunction('asset_css', array('Asset', 'css')), + new \Twig\TwigFunction('asset_js', array('Asset', 'js')), + new \Twig\TwigFunction('asset_img', array('Asset', 'img')), + new \Twig\TwigFunction('asset_render', array('Asset', 'render')), + new \Twig\TwigFunction('asset_find_file', array('Asset', 'find_file')), + + new \Twig\TwigFunction('theme_asset_css', array($this, 'theme_asset_css')), + new \Twig\TwigFunction('theme_asset_js', array($this, 'theme_asset_js')), + new \Twig\TwigFunction('theme_asset_img', array($this, 'theme_asset_img')), + + new \Twig\TwigFunction('html_anchor', array('Html', 'anchor')), + new \Twig\TwigFunction('html_mail_to_safe', array('Html', 'mail_to_safe')), + + new \Twig\TwigFunction('session_get', array('Session', 'get')), + new \Twig\TwigFunction('session_get_flash', array('Session', 'get_flash')), + + new \Twig\TwigFunction('security_js_fetch_token', array('Security', 'js_fetch_token')), + new \Twig\TwigFunction('security_js_set_token', array('Security', 'js_set_token')), + + new \Twig\TwigFunction('markdown_parse', array('Markdown', 'parse')), + + new \Twig\TwigFunction('auth_has_access', array('Auth', 'has_access')), + new \Twig\TwigFunction('auth_check', array('Auth', 'check')), + new \Twig\TwigFunction('auth_get', array('Auth', 'get')), + ); + } // new Twig 2.x syntax - if (class_exists('Twig_SimpleFunction')) + elseif (class_exists('Twig_SimpleFunction')) { return array( new Twig_SimpleFunction('fuel_version', array($this, 'fuel_version')), diff --git a/classes/twig/fuel/extension/wrapper.php b/classes/twig/fuel/extension/wrapper.php new file mode 100644 index 0000000..cb5a2c1 --- /dev/null +++ b/classes/twig/fuel/extension/wrapper.php @@ -0,0 +1,35 @@ +loadTemplate($view_name)->render($local_data); + // Arguments of loadTemplate changed in twig 3.x + if (static::$_version >= 3) + { + $template_classe = static::parser()->getTemplateClass($view_name); + $result = static::parser()->loadTemplate($template_classe, $view_name)->render($local_data); + } + else + { + $result = static::parser()->loadTemplate($view_name)->render($local_data); + } } catch (\Exception $e) { From 9ba7b272fe649061734573d12969faeb20de08cd Mon Sep 17 00:00:00 2001 From: Benjamin_adam Date: Tue, 16 Aug 2022 11:27:52 +0200 Subject: [PATCH 113/120] fix on the name of the FilesystemLoader class --- classes/view/twig.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index ce66298..b51e432 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -66,9 +66,9 @@ protected function process_file($file_override = false) array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); // check if we're using Twig v3 - if (class_exists('\Twig\Loader\FileSystemLoader')) + if (class_exists('\Twig\Loader\FilesystemLoader')) { - static::$_parser_loader = new \Twig\Loader\FileSystemLoader($views_paths); + static::$_parser_loader = new \Twig\Loader\FilesystemLoader($views_paths); } else { From 13f2d6ae2ea7d1cf731c69b654e076817ffb60c4 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 30 Jan 2023 23:26:34 +0000 Subject: [PATCH 114/120] initial support for the PHP League Plates engine --- README.md | 11 ++++- bootstrap.php | 1 + classes/view.php | 11 ++++- classes/view/plates.php | 89 +++++++++++++++++++++++++++++++++++++++++ config/parser.php | 12 +++++- 5 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 classes/view/plates.php diff --git a/README.md b/README.md index feb6680..4c3bec0 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,15 @@ View::forge('example.mustache'); // load a Twig template, will load and parse app/views/example.twig View::forge('example.twig'); -// load a Hybrid Haml / Twig template, ATTENTION: this one expects app/views/example.twig and {% haml %} code at the top of the view +// load a Hybrid Haml / Twig template, ATTENTION: this one actually loads app/views/example.twig and {% haml %} code at the top of the view View::forge('example.mthaml'); // load a Jade template, will load and parse app/views/example.jade View::forge('example.jade'); +// load a Plates template, will load and parse app/views/example.plates +View::forge('example.plates'); + // load a Haml template, will load and parse app/views/example.haml View::forge('example.haml'); @@ -35,12 +38,15 @@ View::forge('example.smarty'); // load a Lex template, will load and parse app/views/example.lex View::forge('example.lex'); -// load a Dwoo template, ATTENTION: this one expects app/views/example.tpl +// load a Dwoo template, ATTENTION: this one actually loads app/views/example.tpl View::forge('example.dwoo'); // load a Handlebars template, will load and parse app/views/example.handlebars View::forge('example.handlebars'); +// load a Plates template, ATTENTION: this one actually loads app/views/example.tpl +View::forge('example.plates'); + ``` ## Installing parsers @@ -57,6 +63,7 @@ Simply add the libraries to your project's `composer.json` then run `php compose "twig/twig" : "2.*", "mthaml/mthaml": "*", "pyrocms/lex": "*", + "league/plates" : "3.*", "zordius/lightncandy" : "dev-master" } } diff --git a/bootstrap.php b/bootstrap.php index 515ba97..4b5aad7 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -25,6 +25,7 @@ 'Parser\\View_Smarty' => __DIR__.'/classes/view/smarty.php', 'Parser\\View_Phptal' => __DIR__.'/classes/view/phptal.php', 'Parser\\View_Lex' => __DIR__.'/classes/view/lex.php', + 'Parser\\View_Plates' => __DIR__.'/classes/view/plates.php', 'Parser\\Twig_Fuel_Extension_Wrapper' => __DIR__.'/classes/twig/fuel/extension/wrapper.php', 'Parser\\Twig_Fuel_Extension' => __DIR__.'/classes/twig/fuel/extension.php', diff --git a/classes/view.php b/classes/view.php index 0d7735b..9ed12b5 100644 --- a/classes/view.php +++ b/classes/view.php @@ -33,8 +33,15 @@ public static function _init() { if ( ! array_key_exists($include, static::$loaded_files)) { - require $include; - static::$loaded_files[$include] = true; + if (file_exists($include)) + { + require $include; + static::$loaded_files[$include] = true; + } + else + { + throw new \FuelException("Parser: required include \"$include\" not found"); + } } } } diff --git a/classes/view/plates.php b/classes/view/plates.php new file mode 100644 index 0000000..0085bd6 --- /dev/null +++ b/classes/view/plates.php @@ -0,0 +1,89 @@ +extension); + + // any extensions defined? + foreach (\Config::get('parser.View_Plates.extensions', array()) as $extension) + { + if (class_exists($extension)) + { + $extension = new $extension(); + } + if ($extension instanceOf League\Plates\Extension\ExtensionInterface) + { + static::$_parser->loadExtension($class); + } + else + { + throw new \FuelException("Parser: defined Plates extension \"$extension\" is not a valid extension"); + } + } + + return static::$_parser; + } + + // extension used by this template engine + public $extension = 'tpl'; + + protected function process_file($file_override = false) + { + // get the template filename + $file = $file_override ?: $this->file_name; + + // split it into parts + $file = pathinfo($file); + + // set the directory and extension for this template + static::parser()->setDirectory($file['dirname']); + if ( ! empty($file['extension'])) + { + static::parser()->setFileExtension($file['extension']); + } + else + { + static::parser()->setFileExtension(null); + } + + // render the template + try + { + $data = $this->get_data(); + $result = static::parser()->render($file['filename'], $data); + } + catch (\Exception $e) + { + // Delete the output buffer & re-throw the exception + ob_end_clean(); + throw $e; + } + + $this->unsanitize($data); + return $result; + } +} diff --git a/config/parser.php b/config/parser.php index 0e4de88..23924a3 100644 --- a/config/parser.php +++ b/config/parser.php @@ -36,6 +36,7 @@ 'smarty' => 'View_Smarty', 'phptal' => 'View_Phptal', 'lex' => 'View_Lex', + 'plates' => array('class' => 'View_Plates', 'extension' => 'tpl'), ), // ------------------------------------------------------------------------ @@ -81,7 +82,7 @@ // Uses > 1.1.1 (Master branch ATM) // ------------------------------------------------------------------------ 'View_HamlTwig' => array( - //'include' => APPPATH.'vendor'.DS.'MtHaml'.DS.'Autoloader.php', + 'include' => APPPATH.'vendor'.DS.'MtHaml'.DS.'Autoloader.php', 'auto_encode' => true, 'environment' => array( 'auto_escaper' => true, @@ -208,4 +209,13 @@ ), ), + // PLATES ( http://platesphp.com ) + // ------------------------------------------------------------------------ + 'View_Plates' => array( + + // plates extensions, either class names or ExtensionInterface instances + 'extensions' => array( + ), + ), + ); From 0f258160964f2960dc2edce9f6abafc2233bb9be Mon Sep 17 00:00:00 2001 From: WanWizard Date: Tue, 31 Jan 2023 00:03:36 +0000 Subject: [PATCH 115/120] fixed PHP 8.x deprecated error 'optional declared before required' --- classes/view/markdown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/view/markdown.php b/classes/view/markdown.php index b704b24..bd43b4c 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -24,7 +24,7 @@ protected function process_file($file_override = false) if (\Config::get('parser.View_Markdown.allow_php', false)) { - $contents = static::pre_process('php', $file, $data = $this->get_data()); + $contents = static::pre_process($file, 'php', $data = $this->get_data()); $this->unsanitize($data); } else @@ -35,7 +35,7 @@ protected function process_file($file_override = false) return static::parser()->transform($contents); } - protected static function pre_process($_type = 'php', $_view_filename, array $_data = array()) + protected static function pre_process($_view_filename, $_type = 'php', array $_data = array()) { if ($_type == 'php') { From f9c59a19b276a037ac361f58f8feafeac79eeeec Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 31 Jan 2024 18:58:21 +0000 Subject: [PATCH 116/120] pass the template extension to static::parser() $this can't be used since parser() is a static method, and does not have access to $this. --- classes/view/plates.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/view/plates.php b/classes/view/plates.php index 0085bd6..2354720 100644 --- a/classes/view/plates.php +++ b/classes/view/plates.php @@ -18,7 +18,7 @@ class View_Plates extends \View protected static $_parser; // create a parser instance - public static function parser() + public static function parser($extension = 'tpl') { if ( ! empty(static::$_parser)) { @@ -26,7 +26,7 @@ public static function parser() } // create a parser instance - static::$_parser = new \League\Plates\Engine(null, $this->extension); + static::$_parser = new \League\Plates\Engine(null, $extension); // any extensions defined? foreach (\Config::get('parser.View_Plates.extensions', array()) as $extension) @@ -60,21 +60,21 @@ protected function process_file($file_override = false) $file = pathinfo($file); // set the directory and extension for this template - static::parser()->setDirectory($file['dirname']); + static::parser($this->extension)->setDirectory($file['dirname']); if ( ! empty($file['extension'])) { - static::parser()->setFileExtension($file['extension']); + static::parser($this->extension)->setFileExtension($file['extension']); } else { - static::parser()->setFileExtension(null); + static::parser($this->extension)->setFileExtension(null); } // render the template try { $data = $this->get_data(); - $result = static::parser()->render($file['filename'], $data); + $result = static::parser($this->extension)->render($file['filename'], $data); } catch (\Exception $e) { From 697291d028997262191a63260f58fb2d895940b2 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Wed, 25 Dec 2024 19:13:24 +0000 Subject: [PATCH 117/120] move the copyright to 2025 --- bootstrap.php | 2 +- classes/smarty/fuel/extension.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/twig/fuel/extension/wrapper.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 2 +- classes/view/handlebars.php | 2 +- classes/view/jade.php | 2 +- classes/view/lex.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/plates.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index 4b5aad7..de4cf42 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index a2b5e8b..ddd9003 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index e05f715..f816563 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/twig/fuel/extension/wrapper.php b/classes/twig/fuel/extension/wrapper.php index cb5a2c1..d1e5d1c 100644 --- a/classes/twig/fuel/extension/wrapper.php +++ b/classes/twig/fuel/extension/wrapper.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 9ed12b5..0508c7d 100644 --- a/classes/view.php +++ b/classes/view.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index 7f9462a..a200c59 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index 6003693..96d51dd 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 3658468..2a7b4d7 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index bd9132b..5e84072 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index 4f1246e..a35631c 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/lex.php b/classes/view/lex.php index 18bcf24..1b59c7d 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index bd43b4c..f073adc 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index de7f66b..8ad9807 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index f82c149..0824288 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/plates.php b/classes/view/plates.php index 2354720..9ed0a5c 100644 --- a/classes/view/plates.php +++ b/classes/view/plates.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index abd01d8..c8144be 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index b51e432..70021f1 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index 23924a3..3c63156 100644 --- a/config/parser.php +++ b/config/parser.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010 - 2019 Fuel Development Team + * @copyright 2010-2025 Fuel Development Team * @link https://fuelphp.com */ From 8ee73ae9e94247360c000059e0dfda26cd8d95c5 Mon Sep 17 00:00:00 2001 From: Marc Bush Date: Thu, 6 Nov 2025 09:59:35 +0000 Subject: [PATCH 118/120] Twig parser - fix typo in views_paths variable assignment also fixes CLI rendering paths where output buffering may be disabled --- classes/view/twig.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/classes/view/twig.php b/classes/view/twig.php index 70021f1..82db649 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -61,7 +61,7 @@ protected function process_file($file_override = false) $views_paths[] = $path . 'views'; } } - $views_pathsp[] = APPPATH . 'views'; + $views_paths[] = APPPATH . 'views'; } array_unshift($views_paths, pathinfo($file, PATHINFO_DIRNAME)); @@ -115,7 +115,10 @@ protected function process_file($file_override = false) catch (\Exception $e) { // Delete the output buffer & re-throw the exception - ob_end_clean(); + if (ob_get_level() > 0) + { + ob_end_clean(); + } throw $e; } From c64aa766b2e836960b82fd77ac6bc2df4f1c81fa Mon Sep 17 00:00:00 2001 From: WanWizard Date: Tue, 11 Nov 2025 18:03:26 +0000 Subject: [PATCH 119/120] bumped composer installers to v2.3.0+ --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d28f9e7..763f25d 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,6 @@ } ], "require": { - "composer/installers": "~1.0" + "composer/installers": "^2.3.0" } } From 679eaf0344d538ae30043d30374ad462da08ec59 Mon Sep 17 00:00:00 2001 From: WanWizard Date: Mon, 5 Jan 2026 19:59:43 +0000 Subject: [PATCH 120/120] Update the copyright to 2026 --- bootstrap.php | 2 +- classes/smarty/fuel/extension.php | 2 +- classes/twig/fuel/extension.php | 2 +- classes/twig/fuel/extension/wrapper.php | 2 +- classes/view.php | 2 +- classes/view/dwoo.php | 2 +- classes/view/haml.php | 2 +- classes/view/hamltwig.php | 2 +- classes/view/handlebars.php | 2 +- classes/view/jade.php | 2 +- classes/view/lex.php | 2 +- classes/view/markdown.php | 2 +- classes/view/mustache.php | 2 +- classes/view/phptal.php | 2 +- classes/view/plates.php | 2 +- classes/view/smarty.php | 2 +- classes/view/twig.php | 2 +- config/parser.php | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bootstrap.php b/bootstrap.php index de4cf42..511ea3f 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/smarty/fuel/extension.php b/classes/smarty/fuel/extension.php index ddd9003..e81576a 100644 --- a/classes/smarty/fuel/extension.php +++ b/classes/smarty/fuel/extension.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/twig/fuel/extension.php b/classes/twig/fuel/extension.php index f816563..d45a4c7 100644 --- a/classes/twig/fuel/extension.php +++ b/classes/twig/fuel/extension.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/twig/fuel/extension/wrapper.php b/classes/twig/fuel/extension/wrapper.php index d1e5d1c..ba522ae 100644 --- a/classes/twig/fuel/extension/wrapper.php +++ b/classes/twig/fuel/extension/wrapper.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view.php b/classes/view.php index 0508c7d..aabc1d7 100644 --- a/classes/view.php +++ b/classes/view.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/dwoo.php b/classes/view/dwoo.php index a200c59..e66455c 100644 --- a/classes/view/dwoo.php +++ b/classes/view/dwoo.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/haml.php b/classes/view/haml.php index 96d51dd..509e2a2 100644 --- a/classes/view/haml.php +++ b/classes/view/haml.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/hamltwig.php b/classes/view/hamltwig.php index 2a7b4d7..f6e0db5 100644 --- a/classes/view/hamltwig.php +++ b/classes/view/hamltwig.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/handlebars.php b/classes/view/handlebars.php index 5e84072..e185fbe 100644 --- a/classes/view/handlebars.php +++ b/classes/view/handlebars.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/jade.php b/classes/view/jade.php index a35631c..4e743ab 100644 --- a/classes/view/jade.php +++ b/classes/view/jade.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/lex.php b/classes/view/lex.php index 1b59c7d..2f1613a 100644 --- a/classes/view/lex.php +++ b/classes/view/lex.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/markdown.php b/classes/view/markdown.php index f073adc..63a32af 100644 --- a/classes/view/markdown.php +++ b/classes/view/markdown.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/mustache.php b/classes/view/mustache.php index 8ad9807..dce0a0b 100644 --- a/classes/view/mustache.php +++ b/classes/view/mustache.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/phptal.php b/classes/view/phptal.php index 0824288..7cb8ca5 100644 --- a/classes/view/phptal.php +++ b/classes/view/phptal.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/plates.php b/classes/view/plates.php index 9ed0a5c..27b4653 100644 --- a/classes/view/plates.php +++ b/classes/view/plates.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/smarty.php b/classes/view/smarty.php index c8144be..d78cf73 100644 --- a/classes/view/smarty.php +++ b/classes/view/smarty.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/classes/view/twig.php b/classes/view/twig.php index 82db649..55bcff9 100644 --- a/classes/view/twig.php +++ b/classes/view/twig.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */ diff --git a/config/parser.php b/config/parser.php index 3c63156..b39d0ac 100644 --- a/config/parser.php +++ b/config/parser.php @@ -6,7 +6,7 @@ * @version 1.9-dev * @author Fuel Development Team * @license MIT License - * @copyright 2010-2025 Fuel Development Team + * @copyright 2010-2026 Fuel Development Team * @link https://fuelphp.com */