-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathBlock.php
135 lines (123 loc) · 3.76 KB
/
Block.php
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
<?php
/**
* Lesti_Fpc (http:gordonlesti.com/lestifpc)
*
* PHP version 5
*
* @link https://github.com/GordonLesti/Lesti_Fpc
* @package Lesti_Fpc
* @author Gordon Lesti <info@gordonlesti.com>
* @copyright Copyright (c) 2013-2016 Gordon Lesti (http://gordonlesti.com)
* @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
/**
* Class Lesti_Fpc_Helper_Block
*/
class Lesti_Fpc_Helper_Block extends Lesti_Fpc_Helper_Abstract
{
const DYNAMIC_BLOCKS_XML_PATH = 'system/fpc/dynamic_blocks';
const LAZY_BLOCKS_XML_PATH = 'system/fpc/lazy_blocks';
const LAZY_BLOCKS_VALID_SESSION_PARAM = 'fpc_lazy_blocks_valid';
const USE_RECENTLY_VIEWED_PRODUCTS_XML_PATH =
'system/fpc/use_recently_viewed_products';
/**
* @return array
*/
public function getDynamicBlocks()
{
return $this->getCSStoreConfigs(self::DYNAMIC_BLOCKS_XML_PATH);
}
/**
* @return array
*/
public function getLazyBlocks()
{
return $this->getCSStoreConfigs(self::LAZY_BLOCKS_XML_PATH);
}
/**
* @return bool
*/
public function areLazyBlocksValid()
{
$hash = $this->_getLazyBlocksValidHash();
$session = Mage::getSingleton('customer/session');
$sessionHash = $session->getData(self::LAZY_BLOCKS_VALID_SESSION_PARAM);
if ($sessionHash === false || $hash != $sessionHash) {
$session->setData(self::LAZY_BLOCKS_VALID_SESSION_PARAM, $hash);
return false;
}
return true;
}
/**
* @return string
*/
protected function _getLazyBlocksValidHash()
{
$params = array();
$request = Mage::app()->getRequest();
$params['host'] = $request->getServer('HTTP_HOST');
$params['port'] = $request->getServer('SERVER_PORT');
// store
$storeCode = Mage::app()->getStore()->getCode();
if ($storeCode) {
$params['store'] = $storeCode;
}
// currency
$currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
if ($currencyCode) {
$params['currency'] = $currencyCode;
}
$customerSession = Mage::getSingleton('customer/session');
$params['customer_group_id'] = $customerSession->getCustomerGroupId();
$design = Mage::getDesign();
$params['design'] = $design->getPackageName().'_'.
$design->getTheme('template');
$params['blocks'] = implode(',', $this->getLazyBlocks());
return sha1(serialize($params));
}
/**
* @param $blockName
* @return string
*/
public function getPlaceholderHtml($blockName)
{
return '<!-- fpc ' . sha1($blockName) . ' -->';
}
/**
* @param $blockName
* @return string
*/
public function getKey($blockName)
{
return sha1($blockName) . '_block';
}
/**
* @return mixed
*/
public function useRecentlyViewedProducts()
{
return (bool)Mage::getStoreConfig(
self::USE_RECENTLY_VIEWED_PRODUCTS_XML_PATH
);
}
/**
* @param $block
* @return array
*/
public function getCacheTags($block)
{
$cacheTags = array();
$blockName = $block->getNameInLayout();
if ($blockName == 'product_list') {
$cacheTags[] = sha1('product');
foreach ($block->getLoadedProductCollection() as $product) {
$cacheTags[] = sha1('product_' . $product->getId());
}
} else if ($block instanceof Mage_Cms_Block_Block ||
is_subclass_of($block, 'Mage_Cms_Block_Block')) {
$cacheTags[] = sha1('cmsblock');
$cacheTags[] = sha1('cmsblock_' . $block->getBlockId());
}
return $cacheTags;
}
}