diff options
author | Sam <8619576+samjf@users.noreply.github.com> | 2021-09-21 13:09:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-21 13:09:37 +0300 |
commit | 85d46c82c7f8a409505bd2ca0474365bf75dbbd4 (patch) | |
tree | 6c1540e422ddd9b12c585b8cdc4fa87507bc7ee9 /plugins/Referrers | |
parent | ba2170d05ad9a251e04fd99c87b8289dba4c9871 (diff) |
Allow social & search definitions to be sourced locally (#18023)
Diffstat (limited to 'plugins/Referrers')
-rw-r--r-- | plugins/Referrers/SearchEngine.php | 39 | ||||
-rw-r--r-- | plugins/Referrers/Social.php | 39 | ||||
-rw-r--r-- | plugins/Referrers/Tasks.php | 4 |
3 files changed, 65 insertions, 17 deletions
diff --git a/plugins/Referrers/SearchEngine.php b/plugins/Referrers/SearchEngine.php index e947a6795f..9663ab9757 100644 --- a/plugins/Referrers/SearchEngine.php +++ b/plugins/Referrers/SearchEngine.php @@ -10,6 +10,7 @@ namespace Piwik\Plugins\Referrers; use Piwik\Cache; use Piwik\Common; +use Piwik\Config; use Piwik\Option; use Piwik\Piwik; use Piwik\SettingsPiwik; @@ -51,16 +52,12 @@ class SearchEngine extends Singleton private function loadDefinitions() { if (empty($this->definitionList)) { - // Read first from the auto-updated list in database - $list = Option::get(self::OPTION_STORAGE_NAME); + $referrerDefinitionSyncOpt = Config::getInstance()->General['enable_referrer_definition_syncs']; - if ($list && SettingsPiwik::isInternetEnabled()) { - $this->definitionList = Common::safe_unserialize(base64_decode($list)); + if( $referrerDefinitionSyncOpt == 1) { + $this->loadRemoteDefinitions(); } else { - // Fallback to reading the bundled list - $yml = file_get_contents(PIWIK_INCLUDE_PATH . self::DEFINITION_FILE); - $this->definitionList = $this->loadYmlData($yml); - Option::set(self::OPTION_STORAGE_NAME, base64_encode(serialize($this->definitionList))); + $this->loadLocalYmlData(); } } @@ -70,6 +67,32 @@ class SearchEngine extends Singleton } /** + * Loads definitions sourced from remote yaml with a local fallback + */ + private function loadRemoteDefinitions() + { + // Read first from the auto-updated list in database + $list = Option::get(self::OPTION_STORAGE_NAME); + + if ($list && SettingsPiwik::isInternetEnabled()) { + $this->definitionList = Common::safe_unserialize(base64_decode($list)); + } else { + // Fallback to reading the bundled list + $this->loadLocalYmlData(); + Option::set(self::OPTION_STORAGE_NAME, base64_encode(serialize($this->definitionList))); + } + } + + /** + * Loads the definition data from the local definitions file + */ + private function loadLocalYmlData() + { + $yml = file_get_contents(PIWIK_INCLUDE_PATH . self::DEFINITION_FILE); + $this->definitionList = $this->loadYmlData($yml); + } + + /** * Parses the given YML string and caches the resulting definitions * * @param string $yml diff --git a/plugins/Referrers/Social.php b/plugins/Referrers/Social.php index 8a84a95bfd..fc98ac85e5 100644 --- a/plugins/Referrers/Social.php +++ b/plugins/Referrers/Social.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\Referrers; use Piwik\Cache; use Piwik\Common; +use Piwik\Config; use Piwik\Option; use Piwik\Piwik; use Piwik\SettingsPiwik; @@ -49,16 +50,12 @@ class Social extends Singleton private function loadDefinitions() { if ($this->definitionList === null) { - // Read first from the auto-updated list in database - $list = Option::get(self::OPTION_STORAGE_NAME); + $referrerDefinitionSyncOpt = Config::getInstance()->General['enable_referrer_definition_syncs']; - if ($list && SettingsPiwik::isInternetEnabled()) { - $this->definitionList = Common::safe_unserialize(base64_decode($list)); + if( $referrerDefinitionSyncOpt == 1) { + $this->loadRemoteDefinitions(); } else { - // Fallback to reading the bundled list - $yml = file_get_contents(PIWIK_INCLUDE_PATH . self::DEFINITION_FILE); - $this->definitionList = $this->loadYmlData($yml); - Option::set(self::OPTION_STORAGE_NAME, base64_encode(serialize($this->definitionList))); + $this->loadLocalYmlData(); } } @@ -68,6 +65,32 @@ class Social extends Singleton } /** + * Loads definitions sourced from remote yaml with a local fallback + */ + private function loadRemoteDefinitions() + { + // Read first from the auto-updated list in database + $list = Option::get(self::OPTION_STORAGE_NAME); + + if ($list && SettingsPiwik::isInternetEnabled()) { + $this->definitionList = Common::safe_unserialize(base64_decode($list)); + } else { + // Fallback to reading the bundled list + $this->loadLocalYmlData(); + Option::set(self::OPTION_STORAGE_NAME, base64_encode(serialize($this->definitionList))); + } + } + + /** + * Loads the definition data from the local definitions file + */ + private function loadLocalYmlData() + { + $yml = file_get_contents(PIWIK_INCLUDE_PATH . self::DEFINITION_FILE); + $this->definitionList = $this->loadYmlData($yml); + } + + /** * Parses the given YML string and caches the resulting definitions * * @param string $yml diff --git a/plugins/Referrers/Tasks.php b/plugins/Referrers/Tasks.php index 28ac9838d8..68ce9a03f2 100644 --- a/plugins/Referrers/Tasks.php +++ b/plugins/Referrers/Tasks.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\Referrers; +use Piwik\Config; use Piwik\Http; use Piwik\Option; use Piwik\SettingsPiwik; @@ -17,7 +18,8 @@ class Tasks extends \Piwik\Plugin\Tasks { public function schedule() { - if(SettingsPiwik::isInternetEnabled() === true){ + if(SettingsPiwik::isInternetEnabled() === true && + Config::getInstance()->General['enable_referrer_definition_syncs'] == 1){ $this->weekly('updateSearchEngines'); $this->weekly('updateSocials'); } |