BackendInterface.php
2 years ago
BaseSettingsTable.php
2 years ago
Cache.php
2 years ago
Config.php
2 years ago
MeasurableSettingsTable.php
1 year ago
NullBackend.php
2 years ago
PluginSettingsTable.php
1 year ago
SitesTable.php
2 years ago
SitesTable.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Settings\Storage\Backend; |
| 10 | |
| 11 | use Piwik\Plugins\SitesManager\Model; |
| 12 | use Piwik\Site; |
| 13 | use Exception; |
| 14 | /** |
| 15 | * Backend for an existing site. Stores all settings in the "site" database table. |
| 16 | */ |
| 17 | class SitesTable implements \Piwik\Settings\Storage\Backend\BackendInterface |
| 18 | { |
| 19 | /** |
| 20 | * @var int |
| 21 | */ |
| 22 | private $idSite; |
| 23 | private $commaSeparatedArrayFields = array('sitesearch_keyword_parameters', 'sitesearch_category_parameters', 'excluded_user_agents', 'excluded_parameters', 'excluded_ips', 'excluded_referrers'); |
| 24 | // these fields are standard fields of a site and cannot be adjusted via a setting |
| 25 | private $allowedNames = array('ecommerce', 'sitesearch', 'sitesearch_keyword_parameters', 'sitesearch_category_parameters', 'exclude_unknown_urls', 'excluded_ips', 'excluded_parameters', 'excluded_referrers', 'excluded_user_agents', 'keep_url_fragment', 'urls'); |
| 26 | public function __construct($idSite) |
| 27 | { |
| 28 | if (empty($idSite)) { |
| 29 | throw new Exception('No idSite given for Measurable backend'); |
| 30 | } |
| 31 | $this->idSite = (int) $idSite; |
| 32 | } |
| 33 | /** |
| 34 | * @inheritdoc |
| 35 | */ |
| 36 | public function getStorageId() |
| 37 | { |
| 38 | return 'SitesTable_' . $this->idSite; |
| 39 | } |
| 40 | /** |
| 41 | * Saves (persists) the current setting values in the database. |
| 42 | */ |
| 43 | public function save($values) |
| 44 | { |
| 45 | $model = $this->getModel(); |
| 46 | foreach ($values as $key => $value) { |
| 47 | if (!in_array($key, $this->allowedNames)) { |
| 48 | unset($values[$key]); |
| 49 | continue; |
| 50 | } |
| 51 | if (is_array($value) && in_array($key, $this->commaSeparatedArrayFields)) { |
| 52 | $values[$key] = implode(',', $value); |
| 53 | } elseif (is_bool($value)) { |
| 54 | $values[$key] = (int) $value; |
| 55 | } |
| 56 | } |
| 57 | if (!empty($values['urls'])) { |
| 58 | $urls = array_unique($values['urls']); |
| 59 | $values['main_url'] = array_shift($urls); |
| 60 | $model->deleteSiteAliasUrls($this->idSite); |
| 61 | foreach ($urls as $url) { |
| 62 | $model->insertSiteUrl($this->idSite, $url); |
| 63 | } |
| 64 | } |
| 65 | unset($values['urls']); |
| 66 | $model->updateSite($values, $this->idSite); |
| 67 | Site::clearCacheForSite($this->idSite); |
| 68 | } |
| 69 | public function load() |
| 70 | { |
| 71 | if (!empty($this->idSite)) { |
| 72 | $site = Site::getSite($this->idSite); |
| 73 | $urls = $this->getModel(); |
| 74 | $site['urls'] = $urls->getSiteUrlsFromId($this->idSite); |
| 75 | foreach ($this->commaSeparatedArrayFields as $field) { |
| 76 | if (!empty($site[$field]) && is_string($site[$field])) { |
| 77 | $site[$field] = explode(',', $site[$field]); |
| 78 | } |
| 79 | } |
| 80 | return $site; |
| 81 | } |
| 82 | } |
| 83 | private function getModel() |
| 84 | { |
| 85 | return new Model(); |
| 86 | } |
| 87 | public function delete() |
| 88 | { |
| 89 | } |
| 90 | } |
| 91 |