/** * looked-up the email template_paths. * if not set, will look up both theme folder and project folder * in both cases, email folder exsits or Email folder exists * return an array containing all folders pointing to the bunch of email templates * * @return array */ public static function template_paths() { if (!isset(self::$template_paths)) { if (class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) { $theme = $config->Theme; } elseif (SSViewer::current_custom_theme()) { $theme = SSViewer::current_custom_theme(); } elseif (SSViewer::current_theme()) { $theme = SSViewer::current_theme(); } else { $theme = false; } if ($theme) { if (file_exists("../" . THEMES_DIR . "/" . $theme . "/templates/email")) { self::$template_paths[] = THEMES_DIR . "/" . $theme . "/templates/email"; } if (file_exists("../" . THEMES_DIR . "/" . $theme . "/templates/Email")) { self::$template_paths[] = THEMES_DIR . "/" . $theme . "/templates/Email"; } } $project = project(); if (file_exists("../" . $project . '/templates/email')) { self::$template_paths[] = $project . '/templates/email'; } if (file_exists("../" . $project . '/templates/Email')) { self::$template_paths[] = $project . '/templates/Email'; } } else { if (is_string(self::$template_paths)) { self::$template_paths = array(self::$template_paths); } } return self::$template_paths; }
/** * Get the fieldset to display in the administration section */ function getCMSFields() { $group = null; if ($this->GroupID) { $group = DataObject::get_one("Group", "ID = {$this->GroupID}"); } $fields = new FieldSet(new TextField("Title", _t('NewsletterType.NEWSLETTERTYPE', 'Newsletter Type')), new TextField("FromEmail", _t('NewsletterType.SENDFROM', 'Send newsletters from')), new TabSet("Root", new Tab(_t('NewsletterType.DRAFTS', 'Drafts'), $draftList = new NewsletterList("Draft", $this, _t('NewsletterType.DRAFT', 'Draft'))), new TabSet('Sent', new Tab(_t('NewsletterType.SENT', 'Sent'), $sendList = new NewsletterList("Send", $this, _t('NewsletterType.SEND', 'Send'))), new Tab(_t('NewsletterType.UNSUBSCRIBED', 'Unsubscribed'), $unsubscribedList = new UnsubscribedList("Unsubscribed", $this)), new Tab(_t('NewsletterType.BOUNCED', 'Bounced'), $bouncedList = new BouncedList("Bounced", $this))))); if ($this->GroupID) { $fields->addFieldToTab('Root', new TabSet("Recipients", new Tab(_t('NewsletterType.RECIPIENTS', 'Recipients'), $recipients = new MemberTableField($this, "Recipients", $group)), new Tab(_t('NewsletterType.IMPORT', 'Import'), $importField = new RecipientImportField("ImportFile", _t('NewsletterType.IMPORTFROM', 'Import from file'), $group)))); $recipients->setController($this); $importField->setController($this); $importField->setTypeID($this->ID); } $fields->addFieldToTab('Root', new Tab(_t('NewsletterType.TEMPLATE', 'Template'), $templates = new TemplateList("Template", "Template", $this->Template, NewsletterAdmin::template_path()))); $draftList->setController($this); $sendList->setController($this); $templates->setController($this); $unsubscribedList->setController($this); $bouncedList->setController($this); $fields->push($idField = new HiddenField("ID")); $fields->push(new HiddenField("executeForm", "", "TypeEditForm")); $idField->setValue($this->ID); return $fields; }
/** * return array containing all possible email templates file name * under the folders of both theme and project specific folder. * * @return array */ public function templateSource() { $paths = NewsletterAdmin::template_paths(); $templates = array("SimpleNewsletterTemplate" => _t('TemplateList.SimpleNewsletterTemplate', 'Simple Newsletter Template')); if (isset($paths) && is_array($paths)) { $absPath = Director::baseFolder(); if ($absPath[strlen($absPath) - 1] != "/") { $absPath .= "/"; } foreach ($paths as $path) { $path = $absPath . $path; if (is_dir($path)) { $templateDir = opendir($path); // read all files in the directory while (($templateFile = readdir($templateDir)) !== false) { // *.ss files are templates if (preg_match('/(.*)\\.ss$/', $templateFile, $match)) { // only grab those haveing $Body coded if (strpos("\$Body", file_get_contents($path . "/" . $templateFile)) === false) { $templates[$match[1]] = preg_replace('/_?([A-Z])/', " \$1", $match[1]); } } } } } } return $templates; }
/** * looked-up the email template_paths. * if not set, will look up both theme folder and project folder * in both cases, email folder exsits or Email folder exists * return an array containing all folders pointing to the bunch of email templates * * @return array */ public static function template_paths() { if (!isset(self::$template_paths)) { if (file_exists("../" . THEMES_DIR . "/" . SSViewer::current_theme() . "/templates/email")) { self::$template_paths[] = THEMES_DIR . "/" . SSViewer::current_theme() . "/templates/email"; } if (file_exists("../" . THEMES_DIR . "/" . SSViewer::current_theme() . "/templates/Email")) { self::$template_paths[] = THEMES_DIR . "/" . SSViewer::current_theme() . "/templates/Email"; } if (file_exists("../" . project() . '/templates/email')) { self::$template_paths[] = project() . '/templates/email'; } if (file_exists("../" . project() . '/templates/Email')) { self::$template_paths[] = project() . '/templates/Email'; } } else { if (is_string(self::$template_paths)) { self::$template_paths = array(self::$template_paths); } } return self::$template_paths; }
public static function template_path() { if (self::$template_path) { return self::$template_path; } else { return self::$template_path = project() . '/templates/email'; } }