Craft\SeomaticService::getSettings PHP Method

getSettings() public method

--------------------------------------------------------------------------------
public getSettings ( $locale )
    public function getSettings($locale)
    {
        /* -- Cache it in our class; no need to fetch it more than once */
        if (isset($this->cachedSettings[$locale])) {
            return $this->cachedSettings[$locale];
        }
        /* -- There's only one Seomatic_SettingsRecord per locale */
        $settings = Seomatic_SettingsRecord::model()->findByAttributes(array('locale' => $locale));
        if (!$settings) {
            $this->saveDefaultSettings($locale);
            $settings = Seomatic_SettingsRecord::model()->findByAttributes(array('locale' => $locale));
        }
        $result = $settings->attributes;
        /* -- If our Humans.txt field is empty, fill it with the default template */
        if ($result['genericCreatorHumansTxt'] == "") {
            $result['genericCreatorHumansTxt'] = $settings->getDefaultHumans();
        }
        /* -- If our robots.txt field is empty, fill it with the default template */
        if ($result['siteRobotsTxt'] == "") {
            $result['siteRobotsTxt'] = $settings->getDefaultRobots();
        }
        /* -- If our siteSeoTitleSeparator &  empty, fill it with the default template */
        if ($result['siteSeoTitleSeparator'] == "") {
            $result['siteSeoTitleSeparator'] = '|';
        }
        if ($result['siteSeoTitlePlacement'] == "") {
            $result['siteSeoTitlePlacement'] = 'after';
        }
        /* -- If this Craft install is localized, and they are asking for a locale other than the main one,
           merge this local settings with their base language */
        if (craft()->isLocalized()) {
            $baseLocales = craft()->i18n->getSiteLocales();
            $baseLocale = $baseLocales[0]->id;
            if ($baseLocale != $locale) {
                /* -- Cache it in our class; no need to fetch it more than once */
                if (isset($this->cachedSettings[$baseLocale])) {
                    $baseResult = $this->cachedSettings[$baseLocale];
                } else {
                    /* -- There's only one Seomatic_SettingsRecord per locale */
                    $baseSettings = Seomatic_SettingsRecord::model()->findByAttributes(array('locale' => $baseLocale));
                    if (!$baseSettings) {
                        $this->saveDefaultSettings($baseLocale);
                        $baseSettings = Seomatic_SettingsRecord::model()->findByAttributes(array('locale' => $baseLocale));
                    }
                    $baseResult = $baseSettings->attributes;
                }
                $result = array_filter($result);
                $result = array_merge($baseResult, $result);
            }
        }
        /* -- Get rid of properties we don't care about */
        if ($result) {
            unset($result['id']);
            unset($result['dateCreated']);
            unset($result['dateUpdated']);
            unset($result['uid']);
        }
        $this->cachedSettings[$locale] = $result;
        return $result;
    }