Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 178 lines (153 sloc) 4.292 kb
ad11834 @harrydeluxe initial import
harrydeluxe authored
1 <?php
2 /**
3 * Liquid for PHP
4 *
5 * @package Liquid
6 * @copyright Copyright (c) 2011 Harald Hanek,
7 * fork of php-liquid (c) 2006 Mateo Murphy,
8 * based on Liquid for Ruby (c) 2006 Tobias Luetke
9 * @license http://www.opensource.org/licenses/mit-license.php
10 */
11
12 /**
13 * The method is called on objects when resolving variables to see
14 * if a given property exists
15 *
16 */
17 define('LIQUID_HAS_PROPERTY_METHOD', 'field_exists');
18
19 /**
20 * This method is called on object when resolving variables when
21 * a given property exists
22 *
23 */
24 define('LIQUID_GET_PROPERTY_METHOD', 'get');
25
26 /**
27 * Seperator between filters
28 *
29 */
30 define('LIQUID_FILTER_SEPERATOR', '\|');
31
32 /**
33 * Seperator for arguments
34 *
35 */
36 define('LIQUID_ARGUMENT_SPERATOR', ',');
37
38 /**
39 * Seperator for argument names and values
40 *
41 */
42 define('LIQUID_FILTER_ARGUMENT_SEPERATOR', ':');
43
44 /**
45 * Seperator for variable attributes
46 *
47 */
48 define('LIQUID_VARIABLE_ATTRIBUTE_SEPERATOR', '.');
49
50 /**
51 * Suffix fuer include dateien
52 *
53 */
54 defined('LIQUID_INCLUDE_SUFFIX') or define('LIQUID_INCLUDE_SUFFIX', 'tpl');
55
56 /**
57 * Tag start
58 *
59 */
60 define('LIQUID_TAG_START', '{%');
61
62 /**
63 * Tag end
64 *
65 */
66 define('LIQUID_TAG_END', '%}');
67
68 /**
69 * Variable start
70 *
71 */
72 define('LIQUID_VARIABLE_START', '{{');
73
74 /**
75 * Variable end
76 *
77 */
78 define('LIQUID_VARIABLE_END', '}}');
79
80 /**
81 * The characters allowed in a variable
82 *
83 */
84 define('LIQUID_ALLOWED_VARIABLE_CHARS', '[a-zA-Z_.-]');
85
86 /**
87 * Regex for quoted fragments
88 *
89 */
90 define('LIQUID_QUOTED_FRAGMENT', '"[^"]+"|\'[^\']+\'|[^\s,|]+');
91
92 /**
93 * Regex for recongnizing tab attributes
94 *
95 */
96 define('LIQUID_TAG_ATTRIBUTES', '/(\w+)\s*\:\s*('.LIQUID_QUOTED_FRAGMENT.')/');
97
98 /**
99 * Regex used to split tokenss
100 *
101 */
102 define('LIQUID_TOKENIZATION_REGEXP', '/('.LIQUID_TAG_START.'.*?'.LIQUID_TAG_END.'|'.LIQUID_VARIABLE_START.'.*?'.LIQUID_VARIABLE_END.')/');
103
104
105 defined('LIQUID_PATH') or define('LIQUID_PATH',dirname(__FILE__));
106
107
108 class Liquid
109 {
110 /**
111 * Flatten a multidimensional array into a single array. Does not maintain keys.
112 *
113 * @param array $array
114 * @return array
115 */
116 public static function array_flatten($array)
117 {
118 $return = array();
119
120 foreach($array as $element)
121 {
122 if(is_array($element))
123 {
124 $return = array_merge($return, self::array_flatten($element));
125 }
126 else
127 {
128 $return[] = $element;
129 }
130 }
131 return $return;
132 }
133
134
135 /**
136 * Class autoload loader.
137 * This method is provided to be invoked within an __autoload() magic method.
138 * @param string $className class name
139 * @return boolean whether the class has been loaded successfully
140 */
141 public static function autoload($className)
142 {
143 // use include so that the error PHP file may appear
144 if(isset(self::$_coreClasses[$className]))
145 include(LIQUID_PATH.self::$_coreClasses[$className]);
146 //include_once(LIQUID_PATH.self::$_coreClasses[$className]);
147 return true;
148 }
149
150
151 private static $_coreClasses = array(
152 'LiquidException' => '/lib/LiquidException.class.php',
153 'LiquidRegexp' => '/lib/LiquidRegexp.class.php',
154 'LiquidBlock' => '/lib/LiquidBlock.class.php',
155 'LiquidContext' => '/lib/LiquidContext.class.php',
156 'LiquidDocument' => '/lib/LiquidDocument.class.php',
157 'LiquidDrop' => '/lib/LiquidDrop.class.php',
158 'LiquidBlankFileSystem' => '/lib/LiquidBlankFileSystem.class.php',
159 'LiquidLocalFileSystem' => '/lib/LiquidLocalFileSystem.class.php',
160 'LiquidFilterbank' => '/lib/LiquidFilterbank.class.php',
99235e7 @harrydeluxe rename tags
harrydeluxe authored
161 'LiquidTagTableRow' => '/lib/Tag/LiquidTagTableRow.class.php',
162 'LiquidDecisionBlock' => '/lib/LiquidDecisionBlock.class.php',
163 'LiquidTagInclude' => '/lib/Tag/LiquidTagInclude.class.php',
164 'LiquidTagCase' => '/lib/Tag/LiquidTagCase.class.php',
165 'LiquidTagAssign' => '/lib/Tag/LiquidTagAssign.class.php',
166 'LiquidTagComment' => '/lib/Tag/LiquidTagComment.class.php',
167 'LiquidTagCapture' => '/lib/Tag/LiquidTagCapture.class.php',
168 'LiquidTagCycle' => '/lib/Tag/LiquidTagCycle.class.php',
169 'LiquidTagFor' => '/lib/Tag/LiquidTagFor.class.php',
170 'LiquidTagIf' => '/lib/Tag/LiquidTagIf.class.php',
ad11834 @harrydeluxe initial import
harrydeluxe authored
171 'LiquidStandardFilters' => '/lib/LiquidStandardFilters.class.php',
172 'LiquidTag' => '/lib/LiquidTag.class.php',
173 'LiquidTemplate' => '/lib/LiquidTemplate.class.php',
174 'LiquidVariable' => '/lib/LiquidVariable.class.php'
175 );
176 }
177
178 spl_autoload_register(array('Liquid', 'autoload'));
Something went wrong with that request. Please try again.