| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Settings\Storage\Backend; |
|
|
| use Piwik\Plugins\SitesManager\Model; |
| use Piwik\Site; |
| use Exception; |
|
|
| |
| |
| |
| class SitesTable implements BackendInterface |
| { |
| |
| |
| |
| private $idSite; |
|
|
| |
| |
| |
| private $commaSeparatedArrayFields = array( |
| 'sitesearch_keyword_parameters', |
| 'sitesearch_category_parameters', |
| 'excluded_user_agents', |
| 'excluded_parameters', |
| 'excluded_ips', |
| 'excluded_referrers', |
| ); |
|
|
| |
| |
| |
| |
| 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', |
| ); |
|
|
| |
| |
| |
| public function __construct($idSite) |
| { |
| if (empty($idSite)) { |
| throw new Exception('No idSite given for Measurable backend'); |
| } |
|
|
| $this->idSite = (int) $idSite; |
| } |
|
|
| |
| |
| |
| public function getStorageId() |
| { |
| return 'SitesTable_' . $this->idSite; |
| } |
|
|
| |
| |
| |
| |
| public function save($values) |
| { |
| $model = $this->getModel(); |
|
|
| foreach ($values as $key => $value) { |
| if (!in_array($key, $this->allowedNames)) { |
| unset($values[$key]); |
| continue; |
| } |
|
|
| if (is_array($value) && in_array($key, $this->commaSeparatedArrayFields)) { |
| $values[$key] = implode(',', $value); |
| } elseif (is_bool($value)) { |
| $values[$key] = (int) $value; |
| } |
| } |
|
|
| if (!empty($values['urls']) && is_array($values['urls'])) { |
| $values['main_url'] = $this->processAdditionalUrls($values['urls']); |
| } |
|
|
| unset($values['urls']); |
|
|
| $model->updateSite($values, $this->idSite); |
| Site::clearCacheForSite($this->idSite); |
| } |
|
|
| public function load() |
| { |
| if (!empty($this->idSite)) { |
| $site = Site::getSite($this->idSite); |
|
|
| $urls = $this->getModel(); |
| $site['urls'] = $urls->getSiteUrlsFromId($this->idSite); |
|
|
| foreach ($this->commaSeparatedArrayFields as $field) { |
| if (!empty($site[$field]) && is_string($site[$field])) { |
| $site[$field] = explode(',', $site[$field]); |
| } |
| } |
|
|
| return $site; |
| } |
|
|
| return null; |
| } |
|
|
| |
| |
| |
| private function processAdditionalUrls(array $urls): string |
| { |
| $model = $this->getModel(); |
| $urls = array_unique($urls); |
| $mainUrl = array_shift($urls); |
|
|
| $model->deleteSiteAliasUrls($this->idSite); |
| foreach ($urls as $url) { |
| $model->insertSiteUrl($this->idSite, $url); |
| } |
|
|
| return $mainUrl; |
| } |
|
|
| private function getModel(): Model |
| { |
| return new Model(); |
| } |
|
|
| public function delete() |
| { |
| } |
| } |
|
|