piwik/plugins/SitesManager/API.php
/**
     * Add a website.
     * Requires Super User access.
     *
     * The website is defined by a name and an array of URLs.
     * @param string $siteName Site name
     * @param array|string $urls 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.
     * @param int $ecommerce Is Ecommerce Reporting enabled for this website?
     * @param null $siteSearch
     * @param string $searchKeywordParameters Comma separated list of search keyword parameter names
     * @param string $searchCategoryParameters Comma separated list of search category parameter names
     * @param string $excludedIps Comma separated list of IPs to exclude from the reports (allows wildcards)
     * @param null $excludedQueryParameters
     * @param string $timezone Timezone string, eg. 'Europe/London'
     * @param string $currency Currency, eg. 'EUR'
     * @param string $group Website group identifier
     * @param string $startDate Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
     * @param null|string $excludedUserAgents
     * @param int $keepURLFragments If 1, URL fragments will be kept when tracking. If 2, they
     *                              will be removed. If 0, the default global behavior will be used.
     * @see getKeepURLFragmentsGlobal.
     * @param string $type The website type, defaults to "website" if not set.
     *
     * @return int the website ID created
     */
Add a website.
Requires Super User access.

The website is defined by a name and an array of URLs.
@param string $siteName Site name
@param array|string $urls 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.
@param int $ecommerce Is Ecommerce Reporting enabled for this website.

@return int the website ID created
Add a website . Requires Super User access . The website is defined by a name and an array of URLs . @param string $siteName Site name @param array|string $urls 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 . @param int $ecommerce Is Ecommerce Reporting enabled for this website . @return int the website ID created
public function addSite($siteName,
                            $urls,
                            $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)
    {
        Piwik::checkUserHasSuperUserAccess();
        $this->checkName($siteName);
        $urls = $this->cleanParameterUrls($urls);
        $this->checkUrls($urls);
        $this->checkAtLeastOneUrl($urls);
        $siteSearch = $this->checkSiteSearch($siteSearch);
        list($searchKeywordParameters, $searchCategoryParameters) = $this->checkSiteSearchParameters($searchKeywordParameters, $searchCategoryParameters);
        $keepURLFragments = (int)$keepURLFragments;
        self::checkKeepURLFragmentsValue($keepURLFragments);
        $timezone = trim($timezone);
        if (empty($timezone)) {
            $timezone = $this->getDefaultTimezone();
        }
        $this->checkValidTimezone($timezone);
        if (empty($currency)) {
            $currency = $this->getDefaultCurrency();
        }
        $this->checkValidCurrency($currency);
        $url  = $urls[0];
        $urls = array_slice($urls, 1);
        $bind = array('name'     => $siteName,
                      'main_url' => $url,
        );
        $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps);
        $bind['excluded_parameters']  = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters);
        $bind['excluded_user_agents'] = $this->checkAndReturnCommaSeparatedStringList($excludedUserAgents);
        $bind['keep_url_fragment']    = $keepURLFragments;
        $bind['timezone']   = $timezone;
        $bind['currency']   = $currency;
        $bind['ecommerce']  = (int)$ecommerce;
        $bind['sitesearch'] = $siteSearch;
        $bind['sitesearch_keyword_parameters']  = $searchKeywordParameters;
        $bind['sitesearch_category_parameters'] = $searchCategoryParameters;
        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'] = "";
        }
        $idSite = $this->getModel()->createSite($bind);
        $this->insertSiteUrls($idSite, $urls);
        Access::getInstance()->reloadAccess();
        $this->postUpdateWebsite($idSite);
        Piwik::postEvent('SitesManager.addSite.end', array($idSite));
        return (int) $idSite;
    }
public function addSite ( $ siteName , $ urls , $ 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 ) { Piwik :: checkUserHasSuperUserAccess ( ) ; $ this -> checkName ( $ siteName ) ; $ urls = $ this -> cleanParameterUrls ( $ urls ) ; $ this -> checkUrls ( $ urls ) ; $ this -> checkAtLeastOneUrl ( $ urls ) ; $ siteSearch = $ this -> checkSiteSearch ( $ siteSearch ) ; list ( $ searchKeywordParameters , $ searchCategoryParameters ) = $ this -> checkSiteSearchParameters ( $ searchKeywordParameters , $ searchCategoryParameters ) ; $ keepURLFragments = ( int ) $ keepURLFragments ; self :: checkKeepURLFragmentsValue ( $ keepURLFragments ) ; $ timezone = trim ( $ timezone ) ; if ( empty ( $ timezone ) ) { $ timezone = $ this -> getDefaultTimezone ( ) ; } $ this -> checkValidTimezone ( $ timezone ) ; if ( empty ( $ currency ) ) { $ currency = $ this -> getDefaultCurrency ( ) ; } $ this -> checkValidCurrency ( $ currency ) ; $ url = $ urls [ 0 ] ; $ urls = array_slice ( $ urls , 1 ) ; $ bind = array ( 'name' => $ siteName , 'main_url' => $ url , ) ; $ bind [ 'excluded_ips' ] = $ this -> checkAndReturnExcludedIps ( $ excludedIps ) ; $ bind [ 'excluded_parameters' ] = $ this -> checkAndReturnCommaSeparatedStringList ( $ excludedQueryParameters ) ; $ bind [ 'excluded_user_agents' ] = $ this -> checkAndReturnCommaSeparatedStringList ( $ excludedUserAgents ) ; $ bind [ 'keep_url_fragment' ] = $ keepURLFragments ; $ bind [ 'timezone' ] = $ timezone ; $ bind [ 'currency' ] = $ currency ; $ bind [ 'ecommerce' ] = ( int ) $ ecommerce ; $ bind [ 'sitesearch' ] = $ siteSearch ; $ bind [ 'sitesearch_keyword_parameters' ] = $ searchKeywordParameters ; $ bind [ 'sitesearch_category_parameters' ] = $ searchCategoryParameters ; 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' ] = " " ; } $ idSite = $ this -> getModel ( ) -> createSite ( $ bind ) ; $ this -> insertSiteUrls ( $ idSite , $ urls ) ; Access :: getInstance ( ) -> reloadAccess ( ) ; $ this -> postUpdateWebsite ( $ idSite ) ; Piwik :: postEvent ( 'SitesManager.addSite.end' , array ( $ idSite ) ) ; return ( int ) $ idSite ; }
Add a website.
Add a website .
// we reload the access list which doesn't yet take in consideration this new website /**
         * Triggered after a site has been added.
         *
         * @param int $idSite The ID of the site that was added.
         */