/** * Settings page for HTML email styling. * * Exposes config settings: * Garden.EmailTemplate.BackgroundColor * Garden.EmailTemplate.ButtonBackgroundColor * Garden.EmailTemplate.ButtonTextColor * Garden.EmailTemplate.Image * * Saves the image based on 2 config settings: * Garden.EmailTemplate.ImageMaxWidth (default 400px) and * Garden.EmailTemplate.ImageMaxHeight (default 300px) * * @throws Gdn_UserException */ public function emailStyles() { // Set default colors if (!c('Garden.EmailTemplate.TextColor')) { saveToConfig('Garden.EmailTemplate.TextColor', EmailTemplate::DEFAULT_TEXT_COLOR, false); } if (!c('Garden.EmailTemplate.BackgroundColor')) { saveToConfig('Garden.EmailTemplate.BackgroundColor', EmailTemplate::DEFAULT_BACKGROUND_COLOR, false); } if (!c('Garden.EmailTemplate.ContainerBackgroundColor')) { saveToConfig('Garden.EmailTemplate.ContainerBackgroundColor', EmailTemplate::DEFAULT_CONTAINER_BACKGROUND_COLOR, false); } if (!c('Garden.EmailTemplate.ButtonTextColor')) { saveToConfig('Garden.EmailTemplate.ButtonTextColor', EmailTemplate::DEFAULT_BUTTON_TEXT_COLOR, false); } if (!c('Garden.EmailTemplate.ButtonBackgroundColor')) { saveToConfig('Garden.EmailTemplate.ButtonBackgroundColor', EmailTemplate::DEFAULT_BUTTON_BACKGROUND_COLOR, false); } $this->permission('Garden.Settings.Manage'); $this->setHighlightRoute('dashboard/settings/emailstyles'); $this->addJsFile('email.js'); // Get the current logo. $image = c('Garden.EmailTemplate.Image'); if ($image) { $image = ltrim($image, '/'); $this->setData('EmailImage', Gdn_UploadImage::url($image)); } $this->Form = new Gdn_Form(); $validation = new Gdn_Validation(); $configurationModel = new Gdn_ConfigurationModel($validation); $configurationModel->setField(array('Garden.EmailTemplate.TextColor', 'Garden.EmailTemplate.BackgroundColor', 'Garden.EmailTemplate.ContainerBackgroundColor', 'Garden.EmailTemplate.ButtonTextColor', 'Garden.EmailTemplate.ButtonBackgroundColor')); // Set the model on the form. $this->Form->setModel($configurationModel); // If seeing the form for the first time... if ($this->Form->authenticatedPostBack() === false) { // Apply the config settings to the form. $this->Form->setData($configurationModel->Data); } else { $image = c('Garden.EmailTemplate.Image'); $upload = new Gdn_UploadImage(); if ($upload->isUpload('EmailImage')) { try { $tmpImage = $upload->validateUpload('EmailImage'); if ($tmpImage) { // Generate the target image name $targetImage = $upload->generateTargetName(PATH_UPLOADS); $imageBaseName = pathinfo($targetImage, PATHINFO_BASENAME); // Delete any previously uploaded images. if ($image) { $upload->delete($image); } // Save the uploaded image $parts = $upload->saveImageAs($tmpImage, $imageBaseName, c('Garden.EmailTemplate.ImageMaxWidth', 400), c('Garden.EmailTemplate.ImageMaxHeight', 300)); $imageBaseName = $parts['SaveName']; saveToConfig('Garden.EmailTemplate.Image', $imageBaseName); $this->setData('EmailImage', Gdn_UploadImage::url($imageBaseName)); } } catch (Exception $ex) { $this->Form->addError($ex); } } if ($this->Form->save() !== false) { $this->informMessage(t("Your settings have been saved.")); } } $this->render(); }