forked from harrydeluxe/php-liquid
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLiquid.class.php
More file actions
192 lines (166 loc) · 5.68 KB
/
Copy pathLiquid.class.php
File metadata and controls
192 lines (166 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* Liquid for PHP
*
* @package Liquid
* @copyright Copyright (c) 2011-2012 Harald Hanek,
* fork of php-liquid (c) 2006 Mateo Murphy,
* based on Liquid for Ruby (c) 2006 Tobias Luetke
* @license http://harrydeluxe.mit-license.org
*/
/**
* The method is called on objects when resolving variables to see
* if a given property exists
*
*/
defined('LIQUID_HAS_PROPERTY_METHOD') or define('LIQUID_HAS_PROPERTY_METHOD', 'field_exists');
/**
* This method is called on object when resolving variables when
* a given property exists
*
*/
defined('LIQUID_GET_PROPERTY_METHOD') or define('LIQUID_GET_PROPERTY_METHOD', 'get');
/**
* Separator between filters
*
*/
defined('LIQUID_FILTER_SEPARATOR') or define('LIQUID_FILTER_SEPARATOR', '\|');
/**
* Separator for arguments
*
*/
defined('LIQUID_ARGUMENT_SEPARATOR') or define('LIQUID_ARGUMENT_SEPARATOR', ',');
/**
* Separator for argument names and values
*
*/
defined('LIQUID_FILTER_ARGUMENT_SEPARATOR') or define('LIQUID_FILTER_ARGUMENT_SEPARATOR', ':');
/**
* Separator for variable attributes
*
*/
defined('LIQUID_VARIABLE_ATTRIBUTE_SEPARATOR') or define('LIQUID_VARIABLE_ATTRIBUTE_SEPARATOR', '.');
/**
* Allow Templatenames with extension in include and extends tags. default = false
*
*/
defined('LIQUID_INCLUDE_ALLOW_EXT') or define('LIQUID_INCLUDE_ALLOW_EXT', false);
/**
* Suffix for include files
*
*/
defined('LIQUID_INCLUDE_SUFFIX') or define('LIQUID_INCLUDE_SUFFIX', 'liquid');
/**
* Prefix for include files
*
*/
defined('LIQUID_INCLUDE_PREFIX') or define('LIQUID_INCLUDE_PREFIX', '_');
/**
* Tag start
*
*/
defined('LIQUID_TAG_START') or define('LIQUID_TAG_START', '{%');
/**
* Tag end
*
*/
defined('LIQUID_TAG_END') or define('LIQUID_TAG_END', '%}');
/**
* Variable start
*
*/
defined('LIQUID_VARIABLE_START') or define('LIQUID_VARIABLE_START', '{{');
/**
* Variable end
*
*/
defined('LIQUID_VARIABLE_END') or define('LIQUID_VARIABLE_END', '}}');
/**
* The characters allowed in a variable
*
*/
defined('LIQUID_ALLOWED_VARIABLE_CHARS') or define('LIQUID_ALLOWED_VARIABLE_CHARS', '[a-zA-Z_.-]');
/**
* Regex for quoted fragments
*
*/
defined('LIQUID_QUOTED_FRAGMENT') or define('LIQUID_QUOTED_FRAGMENT', '"[^"]+"|\'[^\']+\'|[^\s,|]+');
/**
* Regex for recognizing tab attributes
*
*/
defined('LIQUID_TAG_ATTRIBUTES') or define('LIQUID_TAG_ATTRIBUTES', '/(\w+)\s*\:\s*(' . LIQUID_QUOTED_FRAGMENT . ')/');
/**
* Regex used to split tokens
*
*/
defined('LIQUID_TOKENIZATION_REGEXP') or define('LIQUID_TOKENIZATION_REGEXP', '/(' . LIQUID_TAG_START . '.*?' . LIQUID_TAG_END . '|' . LIQUID_VARIABLE_START . '.*?' . LIQUID_VARIABLE_END . ')/');
defined('LIQUID_PATH') or define('LIQUID_PATH', dirname(__FILE__));
defined('LIQUID_AUTOLOAD') or define('LIQUID_AUTOLOAD', true);
class Liquid
{
/**
* Flatten a multidimensional array into a single array. Does not maintain keys.
*
* @param array $array
* @return array
*/
public static function array_flatten($array)
{
$return = [];
foreach($array as $element)
{
if (is_array($element))
{
$return = array_merge($return, self::array_flatten($element));
}
else
{
$return[] = $element;
}
}
return $return;
}
/**
* Checks if class exists in $_coreClasses array
*
* @param string $className class name
* @return boolean whether the class exists in $_coreClasses
*/
public static function classExists($className)
{
return (isset(self::$_coreClasses[$className])) ? true : false;
}
private static $_coreClasses = array(
'LiquidException' => '/lib/LiquidException.class.php',
'LiquidRegexp' => '/lib/LiquidRegexp.class.php',
'LiquidBlock' => '/lib/LiquidBlock.class.php',
'LiquidContext' => '/lib/LiquidContext.class.php',
'LiquidDocument' => '/lib/LiquidDocument.class.php',
'LiquidDrop' => '/lib/LiquidDrop.class.php',
'LiquidCache' => '/lib/LiquidCache.class.php',
'LiquidCacheApc' => '/lib/Cache/LiquidCacheApc.class.php',
'LiquidCacheFile' => '/lib/Cache/LiquidCacheFile.class.php',
'LiquidBlankFileSystem' => '/lib/LiquidBlankFileSystem.class.php',
'LiquidLocalFileSystem' => '/lib/LiquidLocalFileSystem.class.php',
'LiquidFilterbank' => '/lib/LiquidFilterbank.class.php',
'LiquidTagTablerow' => '/lib/Tag/LiquidTagTablerow.class.php',
'LiquidDecisionBlock' => '/lib/LiquidDecisionBlock.class.php',
'LiquidTagInclude' => '/lib/Tag/LiquidTagInclude.class.php',
'LiquidTagCase' => '/lib/Tag/LiquidTagCase.class.php',
'LiquidTagAssign' => '/lib/Tag/LiquidTagAssign.class.php',
'LiquidTagBlock' => '/lib/Tag/LiquidTagBlock.class.php',
'LiquidTagExtends' => '/lib/Tag/LiquidTagExtends.class.php',
'LiquidTagComment' => '/lib/Tag/LiquidTagComment.class.php',
'LiquidTagCapture' => '/lib/Tag/LiquidTagCapture.class.php',
'LiquidTagCycle' => '/lib/Tag/LiquidTagCycle.class.php',
'LiquidTagFor' => '/lib/Tag/LiquidTagFor.class.php',
'LiquidTagIf' => '/lib/Tag/LiquidTagIf.class.php',
'LiquidTagIncrement' => '/lib/Tag/LiquidTagIncrement.class.php',
'LiquidTagDecrement' => '/lib/Tag/LiquidTagDecrement.class.php',
'LiquidStandardFilters' => '/lib/LiquidStandardFilters.class.php',
'LiquidTag' => '/lib/LiquidTag.class.php',
'LiquidTemplate' => '/lib/LiquidTemplate.class.php',
'LiquidVariable' => '/lib/LiquidVariable.class.php'
);
}