public function actionSaveCreator()
 {
     $this->requirePostRequest();
     $locale = craft()->request->getPost('locale');
     if (!$locale) {
         $locale = craft()->language;
     }
     $record = Seomatic_SettingsRecord::model()->findByAttributes(array('locale' => $locale));
     if (!$record) {
         throw new Exception(Craft::t('No SEOmatic Settings record exists'));
     }
     /* -- Set the Creator attributes, defaulting to the existing values for whatever is missing from the post data */
     $record->googleSiteVerification = craft()->request->getPost('googleSiteVerification', $record->googleSiteVerification);
     $record->siteCreatorType = craft()->request->getPost('siteCreatorType', $record->siteCreatorType);
     $record->siteCreatorSubType = craft()->request->getPost('siteCreatorSubType', $record->siteCreatorSubType);
     $record->siteCreatorSpecificType = craft()->request->getPost('siteCreatorSpecificType', $record->siteCreatorSpecificType);
     /* -- Generic Creator fields */
     $record->genericCreatorName = craft()->request->getPost('genericCreatorName', $record->genericCreatorName);
     $record->genericCreatorAlternateName = craft()->request->getPost('genericCreatorAlternateName', $record->genericCreatorAlternateName);
     $record->genericCreatorDescription = craft()->seomatic->truncateStringOnWord(craft()->request->getPost('genericCreatorDescription', $record->genericCreatorDescription), 1024);
     $record->genericCreatorUrl = craft()->request->getPost('genericCreatorUrl', $record->genericCreatorUrl);
     $record->genericCreatorTelephone = craft()->request->getPost('genericCreatorTelephone', $record->genericCreatorTelephone);
     $record->genericCreatorEmail = craft()->request->getPost('genericCreatorEmail', $record->genericCreatorEmail);
     $record->genericCreatorStreetAddress = craft()->request->getPost('genericCreatorStreetAddress', $record->genericCreatorStreetAddress);
     $record->genericCreatorAddressLocality = craft()->request->getPost('genericCreatorAddressLocality', $record->genericCreatorAddressLocality);
     $record->genericCreatorAddressRegion = craft()->request->getPost('genericCreatorAddressRegion', $record->genericCreatorAddressRegion);
     $record->genericCreatorPostalCode = craft()->request->getPost('genericCreatorPostalCode', $record->genericCreatorPostalCode);
     $record->genericCreatorAddressCountry = craft()->request->getPost('genericCreatorAddressCountry', $record->genericCreatorAddressCountry);
     $record->genericCreatorGeoLatitude = craft()->request->getPost('genericCreatorGeoLatitude', $record->genericCreatorGeoLatitude);
     $record->genericCreatorGeoLongitude = craft()->request->getPost('genericCreatorGeoLongitude', $record->genericCreatorGeoLongitude);
     /* -- Corporation Creator fields http://schema.org/Organization */
     $record->organizationCreatorDuns = craft()->request->getPost('organizationCreatorDuns', $record->organizationCreatorDuns);
     $record->organizationCreatorFounder = craft()->request->getPost('organizationCreatorFounder', $record->organizationCreatorFounder);
     $record->organizationCreatorFoundingDate = craft()->request->getPost('organizationCreatorFoundingDate', $record->organizationCreatorFoundingDate);
     $record->organizationCreatorFoundingLocation = craft()->request->getPost('organizationCreatorFoundingLocation', $record->organizationCreatorFoundingLocation);
     $record->organizationCreatorContactPoints = craft()->request->getPost('organizationCreatorContactPoints', array());
     /* -- Person Creator fields https://schema.org/Person */
     $record->personCreatorGender = craft()->request->getPost('personCreatorGender', $record->personCreatorGender);
     $record->personCreatorBirthPlace = craft()->request->getPost('personCreatorBirthPlace', $record->personCreatorBirthPlace);
     /* -- Corporation Creator fields http://schema.org/Corporation */
     $record->corporationCreatorTickerSymbol = craft()->request->getPost('corporationCreatorTickerSymbol', $record->corporationCreatorTickerSymbol);
     /* -- Restaurant creator fields https://schema.org/Restaurant */
     $record->restaurantCreatorServesCuisine = craft()->request->getPost('restaurantCreatorServesCuisine', $record->restaurantCreatorServesCuisine);
     $record->restaurantCreatorMenuUrl = craft()->request->getPost('restaurantCreatorMenuUrl', $record->restaurantCreatorMenuUrl);
     $record->restaurantCreatorReservationsUrl = craft()->request->getPost('restaurantCreatorReservationsUrl', $record->restaurantCreatorReservationsUrl);
     $record->genericCreatorImageId = craft()->request->getPost('genericCreatorImageId', $record->genericCreatorImageId);
     $assetId = !empty($record->genericCreatorImageId) ? $record->genericCreatorImageId[0] : null;
     $record->genericCreatorImageId = $assetId;
     /* -- Humans.txt */
     $record->genericCreatorHumansTxt = craft()->request->getPost('genericCreatorHumansTxt', $record->genericCreatorHumansTxt);
     if ($record->save()) {
         craft()->userSession->setNotice(Craft::t('SEOmatic Site Creator saved.'));
         $this->redirectToPostedUrl($record);
     } else {
         craft()->userSession->setError(Craft::t('Couldn’t save SEOmatic Site Creator.'));
         $this->redirectToPostedUrl($record);
     }
 }
 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;
 }