@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | * @param string $period |
| 31 | 31 | * @param (null|int) Number of visits |
| 32 | 32 | */ |
| 33 | - private function getNumberOfVisitsPiwik($block_id, $period='year'){ |
|
| 33 | + private function getNumberOfVisitsPiwik($block_id, $period = 'year') { |
|
| 34 | 34 | |
| 35 | 35 | $piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url'); |
| 36 | 36 | $piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid'); |
| 37 | 37 | $piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token'); |
| 38 | 38 | |
| 39 | - if($piwik_url && strlen($piwik_url) > 0 && |
|
| 40 | - $piwik_siteid && strlen($piwik_siteid) > 0 && |
|
| 39 | + if ($piwik_url && strlen($piwik_url) > 0 && |
|
| 40 | + $piwik_siteid && strlen($piwik_siteid) > 0 && |
|
| 41 | 41 | $piwik_token && strlen($piwik_token) |
| 42 | 42 | ) |
| 43 | 43 | { |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | $url .= '&format=PHP'; |
| 49 | 49 | $url .= '&token_auth='.$piwik_token; |
| 50 | 50 | |
| 51 | - if($fetched = File::fetchUrl($url)) { |
|
| 51 | + if ($fetched = File::fetchUrl($url)) { |
|
| 52 | 52 | $content = @unserialize($fetched); |
| 53 | - if(is_numeric($content)) return $content; |
|
| 53 | + if (is_numeric($content)) return $content; |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
@@ -72,17 +72,17 @@ discard block |
||
| 72 | 72 | $data->set('has_stats', false); |
| 73 | 73 | |
| 74 | 74 | $block_id = Filter::get('block_id'); |
| 75 | - if($block_id){ |
|
| 75 | + if ($block_id) { |
|
| 76 | 76 | $cached_item = Cache::get('piwikCountYear', $this->module); |
| 77 | 77 | $visitCountYear = $cached_item->get(); |
| 78 | - if(!$cached_item->isHit()) { |
|
| 78 | + if (!$cached_item->isHit()) { |
|
| 79 | 79 | $visitCountYear = $this->getNumberOfVisitsPiwik($block_id); |
| 80 | 80 | Cache::save($cached_item, $visitCountYear); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if($visitCountYear){ |
|
| 83 | + if ($visitCountYear) { |
|
| 84 | 84 | $visitCountToday = max(0, $this->getNumberOfVisitsPiwik($block_id, 'day')); |
| 85 | - $visitCountYear = max( 0, $visitCountYear); |
|
| 85 | + $visitCountYear = max(0, $visitCountYear); |
|
| 86 | 86 | |
| 87 | 87 | $data->set('has_stats', true); |
| 88 | 88 | $data->set('visits_today', $visitCountToday); |
@@ -50,7 +50,9 @@ |
||
| 50 | 50 | |
| 51 | 51 | if($fetched = File::fetchUrl($url)) { |
| 52 | 52 | $content = @unserialize($fetched); |
| 53 | - if(is_numeric($content)) return $content; |
|
| 53 | + if(is_numeric($content)) { |
|
| 54 | + return $content; |
|
| 55 | + } |
|
| 54 | 56 | } |
| 55 | 57 | } |
| 56 | 58 | |
@@ -20,13 +20,13 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * Cache component to speed up some potential data retrievals |
| 22 | 22 | */ |
| 23 | -class Cache{ |
|
| 23 | +class Cache { |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Underlying Cache object |
| 27 | 27 | * @var CacheItemPoolInterface $cache |
| 28 | 28 | */ |
| 29 | - protected $cache=null; |
|
| 29 | + protected $cache = null; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Defines whether the cache has been initialised |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | */ |
| 61 | 61 | protected function init() { |
| 62 | - if(Apc::isAvailable()) { |
|
| 62 | + if (Apc::isAvailable()) { |
|
| 63 | 63 | $driver = new Apc(); |
| 64 | 64 | } else { |
| 65 | 65 | if (!is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) { |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | * Initiliase the Cache if not done. |
| 84 | 84 | * |
| 85 | 85 | */ |
| 86 | - protected function checkInit(){ |
|
| 87 | - if(!$this->is_init) $this->init(); |
|
| 86 | + protected function checkInit() { |
|
| 87 | + if (!$this->is_init) $this->init(); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | * @param AbstractModule $mod Calling module |
| 95 | 95 | * @return string Cached key name |
| 96 | 96 | */ |
| 97 | - protected function getKeyName($value, AbstractModule $mod = null){ |
|
| 97 | + protected function getKeyName($value, AbstractModule $mod = null) { |
|
| 98 | 98 | $this->checkInit(); |
| 99 | 99 | $mod_name = 'myartjaub'; |
| 100 | - if($mod !== null) $mod_name = $mod->getName(); |
|
| 100 | + if ($mod !== null) $mod_name = $mod->getName(); |
|
| 101 | 101 | return $mod_name.'_'.$value; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * @param AbstractModule $mod Calling module |
| 109 | 109 | * @return \Psr\Cache\CacheItemInterface |
| 110 | 110 | */ |
| 111 | - public function getI($value, AbstractModule $mod = null){ |
|
| 111 | + public function getI($value, AbstractModule $mod = null) { |
|
| 112 | 112 | $this->checkInit(); |
| 113 | 113 | return $this->cache->getItem($this->getKeyName($value, $mod)); |
| 114 | 114 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param AbstractModule $mod Calling module |
| 121 | 121 | * @return \Psr\Cache\CacheItemInterface |
| 122 | 122 | */ |
| 123 | - public static function get($value, AbstractModule $mod = null){ |
|
| 123 | + public static function get($value, AbstractModule $mod = null) { |
|
| 124 | 124 | return self::getInstance()->getI($value, $mod); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | * @param mixed $data Value |
| 132 | 132 | * @param AbstractModule $mod Calling module |
| 133 | 133 | */ |
| 134 | - public function saveI($value, $data, AbstractModule $mod = null){ |
|
| 134 | + public function saveI($value, $data, AbstractModule $mod = null) { |
|
| 135 | 135 | $this->checkInit(); |
| 136 | 136 | |
| 137 | 137 | $item = $value; |
| 138 | - if(!($value instanceof CacheItemInterface)) { |
|
| 138 | + if (!($value instanceof CacheItemInterface)) { |
|
| 139 | 139 | $item = new \Stash\Item(); |
| 140 | 140 | $item->setKey($this->getKeyName($value, $mod)); |
| 141 | 141 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param mixed $data Value |
| 151 | 151 | * @param AbstractModule $mod Calling module |
| 152 | 152 | */ |
| 153 | - public static function save($value, $data, AbstractModule $mod = null){ |
|
| 153 | + public static function save($value, $data, AbstractModule $mod = null) { |
|
| 154 | 154 | self::getInstance()->saveI($value, $data, $mod); |
| 155 | 155 | } |
| 156 | 156 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param AbstractModule $mod Calling module |
| 162 | 162 | * @return bool Deletion successful? |
| 163 | 163 | */ |
| 164 | - public function deleteI($value, AbstractModule $mod = null){ |
|
| 164 | + public function deleteI($value, AbstractModule $mod = null) { |
|
| 165 | 165 | $this->checkInit(); |
| 166 | 166 | return $this->cache->deleteItem($this->getKeyName($value, $mod)); |
| 167 | 167 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @param AbstractModule $mod Calling module |
| 174 | 174 | * @return bool Deletion successful? |
| 175 | 175 | */ |
| 176 | - public static function delete($value, AbstractModule $mod = null){ |
|
| 176 | + public static function delete($value, AbstractModule $mod = null) { |
|
| 177 | 177 | return self::getInstance()->deleteI($value, $mod); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * Clean the cache |
| 182 | 182 | * |
| 183 | 183 | */ |
| 184 | - public function cleanI(){ |
|
| 184 | + public function cleanI() { |
|
| 185 | 185 | $this->checkInit(); |
| 186 | 186 | $this->cache->clear(); |
| 187 | 187 | } |