Piwik\Plugins\SitesManager\API::addSite PHP 메소드

addSite() 공개 메소드

Requires Super User access. The website is defined by a name and an array of URLs.
public addSite ( string $siteName, array | string $urls = null, integer $ecommerce = null, null $siteSearch = null, string $searchKeywordParameters = null, string $searchCategoryParameters = null, string $excludedIps = null, null $excludedQueryParameters = null, string $timezone = null, string $currency = null, string $group = null, string $startDate = null, null | string $excludedUserAgents = null, integer $keepURLFragments = null, string $type = null, array | null $settingValues = null, boolean | null $excludeUnknownUrls = null ) : integer
$siteName string Site name
$urls array | string The URLs array must contain at least one URL called the 'main_url' ; if several URLs are provided in the array, they will be recorded as Alias URLs for this website. When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
$ecommerce integer Is Ecommerce Reporting enabled for this website?
$siteSearch null
$searchKeywordParameters string Comma separated list of search keyword parameter names
$searchCategoryParameters string Comma separated list of search category parameter names
$excludedIps string Comma separated list of IPs to exclude from the reports (allows wildcards)
$excludedQueryParameters null
$timezone string Timezone string, eg. 'Europe/London'
$currency string Currency, eg. 'EUR'
$group string Website group identifier
$startDate string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
$excludedUserAgents null | string
$keepURLFragments integer If 1, URL fragments will be kept when tracking. If 2, they will be removed. If 0, the default global behavior will be used.
$type string The website type, defaults to "website" if not set.
$settingValues array | null JSON serialized settings eg {settingName: settingValue, ...}
$excludeUnknownUrls boolean | null Track only URL matching one of website URLs
리턴 integer the website ID created
    public function addSite($siteName, $urls = null, $ecommerce = null, $siteSearch = null, $searchKeywordParameters = null, $searchCategoryParameters = null, $excludedIps = null, $excludedQueryParameters = null, $timezone = null, $currency = null, $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = null, $type = null, $settingValues = null, $excludeUnknownUrls = null)
    {
        Piwik::checkUserHasSuperUserAccess();
        $this->checkName($siteName);
        if (empty($settingValues)) {
            $settingValues = array();
        }
        if (isset($urls)) {
            $settingValues = $this->setSettingValue('urls', $urls, $settingValues);
        }
        if (isset($ecommerce)) {
            $settingValues = $this->setSettingValue('ecommerce', $ecommerce, $settingValues);
        }
        if (isset($siteSearch)) {
            $settingValues = $this->setSettingValue('sitesearch', $siteSearch, $settingValues);
        }
        if (isset($searchKeywordParameters)) {
            $settingValues = $this->setSettingValue('sitesearch_keyword_parameters', explode(',', $searchKeywordParameters), $settingValues);
        }
        if (isset($searchCategoryParameters)) {
            $settingValues = $this->setSettingValue('sitesearch_category_parameters', explode(',', $searchCategoryParameters), $settingValues);
        }
        if (isset($keepURLFragments)) {
            $settingValues = $this->setSettingValue('keep_url_fragment', $keepURLFragments, $settingValues);
        }
        if (isset($excludeUnknownUrls)) {
            $settingValues = $this->setSettingValue('exclude_unknown_urls', $excludeUnknownUrls, $settingValues);
        }
        if (isset($excludedIps)) {
            $settingValues = $this->setSettingValue('excluded_ips', explode(',', $excludedIps), $settingValues);
        }
        if (isset($excludedQueryParameters)) {
            $settingValues = $this->setSettingValue('excluded_parameters', explode(',', $excludedQueryParameters), $settingValues);
        }
        if (isset($excludedUserAgents)) {
            $settingValues = $this->setSettingValue('excluded_user_agents', explode(',', $excludedUserAgents), $settingValues);
        }
        $timezone = trim($timezone);
        if (empty($timezone)) {
            $timezone = $this->getDefaultTimezone();
        }
        $this->checkValidTimezone($timezone);
        if (empty($currency)) {
            $currency = $this->getDefaultCurrency();
        }
        $this->checkValidCurrency($currency);
        $bind = array('name' => $siteName);
        $bind['timezone'] = $timezone;
        $bind['currency'] = $currency;
        $bind['main_url'] = '';
        if (is_null($startDate)) {
            $bind['ts_created'] = Date::now()->getDatetime();
        } else {
            $bind['ts_created'] = Date::factory($startDate)->getDatetime();
        }
        $bind['type'] = $this->checkAndReturnType($type);
        if (!empty($group) && Piwik::hasUserSuperUserAccess()) {
            $bind['group'] = trim($group);
        } else {
            $bind['group'] = "";
        }
        $allSettings = $this->setAndValidateMeasurableSettings(0, $bind['type'], $settingValues);
        foreach ($allSettings as $settings) {
            foreach ($settings->getSettingsWritableByCurrentUser() as $setting) {
                $name = $setting->getName();
                if ($setting instanceof MeasurableProperty && $name !== 'urls') {
                    $default = $setting->getDefaultValue();
                    if (is_bool($default)) {
                        $default = (int) $default;
                    } elseif (is_array($default)) {
                        $default = implode(',', $default);
                    }
                    $bind[$name] = $default;
                }
            }
        }
        $idSite = $this->getModel()->createSite($bind);
        $this->saveMeasurableSettings($idSite, $bind['type'], $settingValues);
        // we reload the access list which doesn't yet take in consideration this new website
        Access::getInstance()->reloadAccess();
        $this->postUpdateWebsite($idSite);
        /**
         * Triggered after a site has been added.
         *
         * @param int $idSite The ID of the site that was added.
         */
        Piwik::postEvent('SitesManager.addSite.end', array($idSite));
        return (int) $idSite;
    }

Usage Example

예제 #1
0
 private function addSite($urls)
 {
     $this->api->addSite('siteName', func_get_args());
 }