1 | <?php |
||
22 | class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract { |
||
|
|||
23 | |||
24 | /** |
||
25 | * Contains a newly generated v4 uuid whenever read, possibly not available |
||
26 | * on all kernels |
||
27 | */ |
||
28 | const UUID_SOURCE = '/proc/sys/kernel/random/uuid'; |
||
29 | |||
30 | /** |
||
31 | * Compression level for serialization compression |
||
32 | * |
||
33 | * Testing showed no significant (size) difference between levels 1 and 9 |
||
34 | * so using 1 since it's faster |
||
35 | */ |
||
36 | const COMPRESSION_LEVEL = 1; |
||
37 | |||
38 | /** |
||
39 | * Hash algorithm to use in various cryptographic methods |
||
40 | */ |
||
41 | const HASH_ALGORITHM = 'sha256'; |
||
42 | |||
43 | /** |
||
44 | * Cookie name for the Varnish bypass |
||
45 | * |
||
46 | * @var string |
||
47 | */ |
||
48 | const BYPASS_COOKIE_NAME = 'varnish_bypass'; |
||
49 | |||
50 | /** |
||
51 | * encryption singleton thing |
||
52 | * |
||
53 | * @var Mage_Core_Model_Encryption |
||
54 | */ |
||
55 | protected $_crypt = null; |
||
56 | |||
57 | /** |
||
58 | * Like built-in explode() but applies trim to each exploded element and |
||
59 | * filters out empty elements from result |
||
60 | * |
||
61 | * @param string $token [description] |
||
62 | * @param string $data [description] |
||
63 | * @return array |
||
64 | */ |
||
65 | public function cleanExplode($token, $data) { |
||
69 | |||
70 | /** |
||
71 | * Generate a v4 UUID |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | public function generateUuid() { |
||
109 | |||
110 | /** |
||
111 | * Get the Turpentine version |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getVersion() { |
||
116 | return Mage::getConfig() |
||
117 | ->getModuleConfig('Nexcessnet_Turpentine')->version; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Base64 encode a string |
||
122 | * |
||
123 | * NOTE this changes the last 2 characters to be friendly to URLs |
||
124 | * / => . |
||
125 | * + => - |
||
126 | * |
||
127 | * @param string $str |
||
128 | * @return string |
||
129 | */ |
||
130 | public function urlBase64Encode($str) { |
||
136 | |||
137 | /** |
||
138 | * Base64 decode a string, counterpart to urlBase64Encode |
||
139 | * |
||
140 | * @param string $str |
||
141 | * @return string |
||
142 | */ |
||
143 | public function urlBase64Decode($str) { |
||
150 | |||
151 | /** |
||
152 | * Serialize a variable into a string that can be used in a URL |
||
153 | * |
||
154 | * Using gzdeflate to avoid the checksum/metadata overhead in gzencode and |
||
155 | * gzcompress |
||
156 | * |
||
157 | * @param mixed $data |
||
158 | * @return string |
||
159 | */ |
||
160 | public function freeze($data) { |
||
170 | |||
171 | /** |
||
172 | * Unserialize data |
||
173 | * |
||
174 | * @param string $data |
||
175 | * @return mixed |
||
176 | */ |
||
177 | public function thaw($data) { |
||
186 | |||
187 | /** |
||
188 | * Get SHA256 hash of a string, salted with encryption key |
||
189 | * |
||
190 | * @param string $data |
||
191 | * @return string |
||
192 | */ |
||
193 | public function secureHash($data) { |
||
197 | |||
198 | /** |
||
199 | * Get the HMAC hash for given data |
||
200 | * |
||
201 | * @param string $data |
||
202 | * @return string |
||
203 | */ |
||
204 | public function getHmac($data) { |
||
207 | |||
208 | /** |
||
209 | * Hash a cache key the same way blocks do |
||
210 | * |
||
211 | * @param array $key |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getCacheKeyHash($key) { |
||
217 | |||
218 | /** |
||
219 | * Get a list of child blocks inside the given block |
||
220 | * |
||
221 | * @param Mage_Core_Model_Layout_Element $blockNode |
||
222 | * @return array |
||
223 | */ |
||
224 | public function getChildBlockNames($blockNode) { |
||
227 | |||
228 | /** |
||
229 | * Get the getModel formatted name of a model classname or object |
||
230 | * |
||
231 | * @param string|object $model |
||
232 | * @return string |
||
233 | */ |
||
234 | public function getModelName($model) { |
||
249 | |||
250 | /** |
||
251 | * Check config to see if Turpentine should handle the flash messages |
||
252 | * |
||
253 | * @return bool |
||
254 | */ |
||
255 | public function useFlashMessagesFix() { |
||
256 | return (bool) Mage::getStoreConfig( |
||
257 | 'turpentine_varnish/general/ajax_messages' ); |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Check config to see if Turpentine should apply the product list toolbar |
||
262 | * fix |
||
263 | * |
||
264 | * @return bool |
||
265 | */ |
||
266 | public function useProductListToolbarFix() { |
||
267 | return (bool) Mage::getStoreConfig( |
||
268 | 'turpentine_varnish/general/fix_product_toolbar' ); |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * Check if Turpentine should apply the new VCL on config changes |
||
273 | * |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function getAutoApplyOnSave() { |
||
277 | return (bool) Mage::getStoreConfig( |
||
278 | 'turpentine_varnish/general/auto_apply_on_save' ); |
||
279 | } |
||
280 | |||
281 | /** |
||
282 | * Get config value specifying when to strip VCL whitespaces |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | public function getVclFix() { |
||
290 | |||
291 | /** |
||
292 | * Get config value specifying when to strip VCL whitespaces |
||
293 | * |
||
294 | * @return string |
||
295 | */ |
||
296 | public function getStripVclWhitespace() { |
||
300 | |||
301 | /** |
||
302 | * Check if VCL whitespaces should be stripped for the given action |
||
303 | * |
||
304 | * @param string $action can be either "apply", "save" or "download" |
||
305 | * @return bool |
||
306 | */ |
||
307 | public function shouldStripVclWhitespace($action) { |
||
316 | |||
317 | /** |
||
318 | * Get the cookie name for the Varnish bypass |
||
319 | * |
||
320 | * @return string |
||
321 | */ |
||
322 | public function getBypassCookieName() { |
||
323 | return self::BYPASS_COOKIE_NAME; |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * The actual recursive implementation of getChildBlockNames |
||
328 | * |
||
329 | * @param Mage_Core_Model_Layout_Element $blockNode |
||
330 | * @return array |
||
331 | */ |
||
332 | protected function _getChildBlockNames($blockNode) { |
||
355 | |||
356 | /** |
||
357 | * Get encryption singleton thing |
||
358 | * |
||
359 | * Not using core/cryption because it auto-base64 encodes stuff which we |
||
360 | * don't want in this case |
||
361 | * |
||
362 | * @return Mage_Core_Model_Encryption |
||
363 | */ |
||
364 | protected function _getCrypt() { |
||
371 | |||
372 | /** |
||
373 | * Get Magento's encryption key |
||
374 | * |
||
375 | * @return string |
||
376 | */ |
||
377 | protected function _getCryptKey() { |
||
380 | } |
||
381 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.