@@ -36,6 +36,9 @@ |
||
| 36 | 36 | return $temp; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + /** |
|
| 40 | + * @param string $_type |
|
| 41 | + */ |
|
| 39 | 42 | function jBlockFileMan( $_path, $_type, $_parameters = [] ) { |
| 40 | 43 | try { |
| 41 | 44 | $temp = Parser::parseFileMan($_path, $_parameters, $_type); |
@@ -2,64 +2,64 @@ |
||
| 2 | 2 | jRequire("../modules/Parser/Parser.php"); |
| 3 | 3 | jRequire("../modules/JException/JException.php"); |
| 4 | 4 | function jBlock() { |
| 5 | - return ob_start(); |
|
| 5 | + return ob_start(); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | function jBlockClose( $_type = "html", $_parameters = [] ) { |
| 9 | - return jBlockEnd($_type, $_parameters); |
|
| 9 | + return jBlockEnd($_type, $_parameters); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | function jBlockFile( $_path, $_parameters = [] ) { |
| 13 | - try { |
|
| 14 | - $temp = Parser::parseFile($_path, $_parameters); |
|
| 15 | - } catch (Exception $e) { |
|
| 16 | - throw new JException($e->getMessage(), 1); |
|
| 17 | - } |
|
| 18 | - return $temp; |
|
| 13 | + try { |
|
| 14 | + $temp = Parser::parseFile($_path, $_parameters); |
|
| 15 | + } catch (Exception $e) { |
|
| 16 | + throw new JException($e->getMessage(), 1); |
|
| 17 | + } |
|
| 18 | + return $temp; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function view( $_path, $_parameters = [] ) { |
| 22 | - try { |
|
| 23 | - $temp = jBlockFile("bundles/views/$_path", $_parameters); |
|
| 24 | - } catch (Exception $e) { |
|
| 25 | - throw new JException($e->getMessage(), 1); |
|
| 26 | - } |
|
| 27 | - return $temp; |
|
| 22 | + try { |
|
| 23 | + $temp = jBlockFile("bundles/views/$_path", $_parameters); |
|
| 24 | + } catch (Exception $e) { |
|
| 25 | + throw new JException($e->getMessage(), 1); |
|
| 26 | + } |
|
| 27 | + return $temp; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | function sql( $_path, $_parameters = [] ) { |
| 31 | - try { |
|
| 32 | - $temp = jBlockFileMan("bundles/sql/$_path", "sql", $_parameters); |
|
| 33 | - } catch (Exception $e) { |
|
| 34 | - throw new JException($e->getMessage(), 1); |
|
| 35 | - } |
|
| 36 | - return $temp; |
|
| 31 | + try { |
|
| 32 | + $temp = jBlockFileMan("bundles/sql/$_path", "sql", $_parameters); |
|
| 33 | + } catch (Exception $e) { |
|
| 34 | + throw new JException($e->getMessage(), 1); |
|
| 35 | + } |
|
| 36 | + return $temp; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | function jBlockFileMan( $_path, $_type, $_parameters = [] ) { |
| 40 | - try { |
|
| 41 | - $temp = Parser::parseFileMan($_path, $_parameters, $_type); |
|
| 42 | - } catch (Exception $e) { |
|
| 43 | - throw new JException($e->getMessage(), 1); |
|
| 44 | - } |
|
| 45 | - return $temp; |
|
| 40 | + try { |
|
| 41 | + $temp = Parser::parseFileMan($_path, $_parameters, $_type); |
|
| 42 | + } catch (Exception $e) { |
|
| 43 | + throw new JException($e->getMessage(), 1); |
|
| 44 | + } |
|
| 45 | + return $temp; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | function jBlockEnd( $_type = "html", $_parameters = [] ) { |
| 49 | - $text = ob_get_clean(); |
|
| 50 | - try { |
|
| 51 | - $temp = Parser::parseText($text, $_parameters, $_type); |
|
| 52 | - } catch (Exception $e) { |
|
| 53 | - throw new JException($e->getMessage(), 1); |
|
| 54 | - } |
|
| 55 | - return $temp; |
|
| 49 | + $text = ob_get_clean(); |
|
| 50 | + try { |
|
| 51 | + $temp = Parser::parseText($text, $_parameters, $_type); |
|
| 52 | + } catch (Exception $e) { |
|
| 53 | + throw new JException($e->getMessage(), 1); |
|
| 54 | + } |
|
| 55 | + return $temp; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function minifyOutput($_buffer) { |
| 59 | - $search = array ( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' ); |
|
| 60 | - $replace = array ( '>', '<', '\\1' ); |
|
| 61 | - if (preg_match("/\<html/i",$_buffer) == 1 && preg_match("/\<\/html\>/i",$_buffer) == 1) |
|
| 62 | - $_buffer = preg_replace($search, $replace, utf8_decode($_buffer)); |
|
| 63 | - return utf8_encode($_buffer); |
|
| 59 | + $search = array ( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' ); |
|
| 60 | + $replace = array ( '>', '<', '\\1' ); |
|
| 61 | + if (preg_match("/\<html/i",$_buffer) == 1 && preg_match("/\<\/html\>/i",$_buffer) == 1) |
|
| 62 | + $_buffer = preg_replace($search, $replace, utf8_decode($_buffer)); |
|
| 63 | + return utf8_encode($_buffer); |
|
| 64 | 64 | } |
| 65 | 65 | ?> |
@@ -5,11 +5,11 @@ discard block |
||
| 5 | 5 | return ob_start(); |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | - function jBlockClose( $_type = "html", $_parameters = [] ) { |
|
| 8 | + function jBlockClose($_type = "html", $_parameters = []) { |
|
| 9 | 9 | return jBlockEnd($_type, $_parameters); |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | - function jBlockFile( $_path, $_parameters = [] ) { |
|
| 12 | + function jBlockFile($_path, $_parameters = []) { |
|
| 13 | 13 | try { |
| 14 | 14 | $temp = Parser::parseFile($_path, $_parameters); |
| 15 | 15 | } catch (Exception $e) { |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | return $temp; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - function view( $_path, $_parameters = [] ) { |
|
| 21 | + function view($_path, $_parameters = []) { |
|
| 22 | 22 | try { |
| 23 | 23 | $temp = jBlockFile("bundles/views/$_path", $_parameters); |
| 24 | 24 | } catch (Exception $e) { |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | return $temp; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - function sql( $_path, $_parameters = [] ) { |
|
| 30 | + function sql($_path, $_parameters = []) { |
|
| 31 | 31 | try { |
| 32 | 32 | $temp = jBlockFileMan("bundles/sql/$_path", "sql", $_parameters); |
| 33 | 33 | } catch (Exception $e) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return $temp; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - function jBlockFileMan( $_path, $_type, $_parameters = [] ) { |
|
| 39 | + function jBlockFileMan($_path, $_type, $_parameters = []) { |
|
| 40 | 40 | try { |
| 41 | 41 | $temp = Parser::parseFileMan($_path, $_parameters, $_type); |
| 42 | 42 | } catch (Exception $e) { |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | return $temp; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - function jBlockEnd( $_type = "html", $_parameters = [] ) { |
|
| 48 | + function jBlockEnd($_type = "html", $_parameters = []) { |
|
| 49 | 49 | $text = ob_get_clean(); |
| 50 | 50 | try { |
| 51 | 51 | $temp = Parser::parseText($text, $_parameters, $_type); |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | function minifyOutput($_buffer) { |
| 59 | - $search = array ( '/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s' ); |
|
| 60 | - $replace = array ( '>', '<', '\\1' ); |
|
| 61 | - if (preg_match("/\<html/i",$_buffer) == 1 && preg_match("/\<\/html\>/i",$_buffer) == 1) |
|
| 59 | + $search = array('/\>[^\S ]+/s', '/[^\S ]+\</s', '/(\s)+/s'); |
|
| 60 | + $replace = array('>', '<', '\\1'); |
|
| 61 | + if (preg_match("/\<html/i", $_buffer) == 1 && preg_match("/\<\/html\>/i", $_buffer) == 1) |
|
| 62 | 62 | $_buffer = preg_replace($search, $replace, utf8_decode($_buffer)); |
| 63 | 63 | return utf8_encode($_buffer); |
| 64 | 64 | } |
@@ -2,67 +2,67 @@ |
||
| 2 | 2 | requireComponents("Adapters"); |
| 3 | 3 | jRequire("../JException/JException.php"); |
| 4 | 4 | class Parser { |
| 5 | - private static function setParser ( $_type ) { |
|
| 6 | - $parser = null; |
|
| 7 | - $_type = strtolower($_type); |
|
| 8 | - switch ($_type) { |
|
| 9 | - case "twig": |
|
| 10 | - case "sql": |
|
| 11 | - $parser = new TwigAdapter(); |
|
| 12 | - break; |
|
| 13 | - case "jate": |
|
| 14 | - $parser = new JTagAdapter(); |
|
| 15 | - break; |
|
| 16 | - case 'jade': |
|
| 17 | - case "pug": |
|
| 18 | - $parser = new PugAdapter(); |
|
| 19 | - break; |
|
| 20 | - case "md": |
|
| 21 | - case "markdown": |
|
| 22 | - case "parsedown": |
|
| 23 | - $parser = new ParsedownAdapter(); |
|
| 24 | - break; |
|
| 25 | - default: |
|
| 26 | - $parser = -1; |
|
| 27 | - break; |
|
| 28 | - } |
|
| 29 | - return $parser; |
|
| 30 | - } |
|
| 31 | - public static function parseText( $_text, $_parameters = [], $_type = "html" ) { |
|
| 32 | - if(!is_string($_text) || !is_string($_type)) |
|
| 33 | - throw new JException("Parameter must be a string."); |
|
| 34 | - if(!is_array($_parameters)) |
|
| 35 | - throw new JException("Parameter must be an array."); |
|
| 36 | - $parser = self::setParser($_type); |
|
| 37 | - if($parser === -1) |
|
| 38 | - return $_text; |
|
| 39 | - return $parser->drawText($_text, $_parameters); |
|
| 40 | - } |
|
| 41 | - public static function parseFileMan( $_path, $_parameters = [], $_type = "html" ) { |
|
| 42 | - if(!is_string($_path)) |
|
| 43 | - throw new JException("Parameter must be a string."); |
|
| 44 | - if(!file_exists($_path)) |
|
| 45 | - throw new JException("File [$_path] not found."); |
|
| 46 | - $string = file_get_contents($_path); |
|
| 47 | - try { |
|
| 48 | - $text = self::parseText($string, $_parameters, $_type); |
|
| 49 | - } catch (Exception $e) { |
|
| 50 | - throw new JException($e->getMessage()); |
|
| 51 | - } |
|
| 52 | - return $text; |
|
| 53 | - } |
|
| 54 | - public static function parseFile( $_path, $_parameters = [] ) { |
|
| 55 | - if(!is_string($_path)) |
|
| 56 | - throw new JException("Parameter must be a string."); |
|
| 57 | - $extension = explode(".", $_path); |
|
| 58 | - $extension = $extension[count($extension)-1]; |
|
| 59 | - $extension = strtolower($extension); |
|
| 60 | - try { |
|
| 61 | - $text = self::parseFileMan($_path, $_parameters, $extension); |
|
| 62 | - } catch (Exception $e) { |
|
| 63 | - throw new JException($e->getMessage()); |
|
| 64 | - } |
|
| 65 | - return $text; |
|
| 66 | - } |
|
| 5 | + private static function setParser ( $_type ) { |
|
| 6 | + $parser = null; |
|
| 7 | + $_type = strtolower($_type); |
|
| 8 | + switch ($_type) { |
|
| 9 | + case "twig": |
|
| 10 | + case "sql": |
|
| 11 | + $parser = new TwigAdapter(); |
|
| 12 | + break; |
|
| 13 | + case "jate": |
|
| 14 | + $parser = new JTagAdapter(); |
|
| 15 | + break; |
|
| 16 | + case 'jade': |
|
| 17 | + case "pug": |
|
| 18 | + $parser = new PugAdapter(); |
|
| 19 | + break; |
|
| 20 | + case "md": |
|
| 21 | + case "markdown": |
|
| 22 | + case "parsedown": |
|
| 23 | + $parser = new ParsedownAdapter(); |
|
| 24 | + break; |
|
| 25 | + default: |
|
| 26 | + $parser = -1; |
|
| 27 | + break; |
|
| 28 | + } |
|
| 29 | + return $parser; |
|
| 30 | + } |
|
| 31 | + public static function parseText( $_text, $_parameters = [], $_type = "html" ) { |
|
| 32 | + if(!is_string($_text) || !is_string($_type)) |
|
| 33 | + throw new JException("Parameter must be a string."); |
|
| 34 | + if(!is_array($_parameters)) |
|
| 35 | + throw new JException("Parameter must be an array."); |
|
| 36 | + $parser = self::setParser($_type); |
|
| 37 | + if($parser === -1) |
|
| 38 | + return $_text; |
|
| 39 | + return $parser->drawText($_text, $_parameters); |
|
| 40 | + } |
|
| 41 | + public static function parseFileMan( $_path, $_parameters = [], $_type = "html" ) { |
|
| 42 | + if(!is_string($_path)) |
|
| 43 | + throw new JException("Parameter must be a string."); |
|
| 44 | + if(!file_exists($_path)) |
|
| 45 | + throw new JException("File [$_path] not found."); |
|
| 46 | + $string = file_get_contents($_path); |
|
| 47 | + try { |
|
| 48 | + $text = self::parseText($string, $_parameters, $_type); |
|
| 49 | + } catch (Exception $e) { |
|
| 50 | + throw new JException($e->getMessage()); |
|
| 51 | + } |
|
| 52 | + return $text; |
|
| 53 | + } |
|
| 54 | + public static function parseFile( $_path, $_parameters = [] ) { |
|
| 55 | + if(!is_string($_path)) |
|
| 56 | + throw new JException("Parameter must be a string."); |
|
| 57 | + $extension = explode(".", $_path); |
|
| 58 | + $extension = $extension[count($extension)-1]; |
|
| 59 | + $extension = strtolower($extension); |
|
| 60 | + try { |
|
| 61 | + $text = self::parseFileMan($_path, $_parameters, $extension); |
|
| 62 | + } catch (Exception $e) { |
|
| 63 | + throw new JException($e->getMessage()); |
|
| 64 | + } |
|
| 65 | + return $text; |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | ?> |