public function getContent($template = false, $additional_replacements = false) { require_once 'ContentBuilder.class.php'; if (!$template) { $template = 'templates/slideshow.tpl'; } if (!$this->images) { $this->createThumbnails(); } //echo 'DEBUG images <pre>'; //print_r($this->images); //echo '</pre>'; // This turned out to be neccessary foreach ($this->images as &$i) { $i['slideshow_alias'] = $this->alias; } $replacements = array('alias' => $this->alias, 'images' => $this->images, 'image_count' => count($this->images), 'thumbnail_sizes' => $this->thumbnail_sizes, 'viewport_size' => $this->viewport_size, 'viewport_width' => $this->thumbnail_sizes[$this->viewport_size]['width'], 'viewport_height' => $this->thumbnail_sizes[$this->viewport_size]['height']); if (isset($this->images[0])) { $replacements['initial_image_web_filepath'] = $this->images[0]['thumbnail_web_filepaths'][$this->viewport_size]; } if ($additional_replacements && is_array($additional_replacements)) { $replacements = array_merge($replacements, $additional_replacements); } $cb = new ContentBuilder($template, $replacements); $content = $cb->getContent(); return $content; }
/** * Builds a raw email message by the given parameters * * @param string[] $to The array of recipients * @param string $subject The subject of the email * @param string $plain The Plain text version of the email * @param string $html The HTML version of the email * @param Attachment[] $attachments The array of attachments to send * @return string The built raw email * @throws RawEmailException */ public function build(array $to, $subject, $plain, $html, array $attachments = array()) { if (!self::isPresent($plain) && !self::isPresent($html)) { throw new RawEmailException("Either 'plain' or 'html' parameter must be passed"); } $outerBoundary = new Boundary(Boundary::generate()); $innerBoundary = new Boundary(Boundary::generate()); $content = new ContentBuilder(); $basic = new Item(); $basic->addField(new Field(Field::RETURN_PATH, array($this->returnPath))); $basic->addField(new Field(Field::FROM, array($this->from))); $basic->addField(new Field(Field::TO, array(join(', ', $to)))); $basic->addField(new Field(Field::SUBJECT, array($subject))); $basic->addField(new Field(Field::MIME_VERSION, array('1.0'))); $basic->addField(new Field(Field::CONTENT_TYPE, array('multipart/mixed', "boundary={$outerBoundary->getBoundary()}"))); $content->insertItem($basic); $content->insertBoundary($outerBoundary); $message = new Item(); $message->addField(new Field(Field::CONTENT_TYPE, array('multipart/alternative', "boundary={$innerBoundary->getBoundary()}"))); $content->insertItem($message); if (self::isPresent($plain)) { $content->insertBoundary($innerBoundary); $plainItem = new Item(); $plainItem->addField(new Field(Field::CONTENT_TRANSFER_ENCODING, array('base64'))); $plainItem->addField(new Field(Field::CONTENT_TYPE, array('text/plain', 'charset=UTF-8', 'format=flowed'))); $plainItem->setValue(base64_encode($plain)); $content->insertItem($plainItem); } if (self::isPresent($html)) { $content->insertBoundary($innerBoundary); $htmlItem = new Item(); $htmlItem->addField(new Field(Field::CONTENT_TRANSFER_ENCODING, array('7bit'))); $htmlItem->addField(new Field(Field::CONTENT_TYPE, array('text/html', 'charset=UTF-8'))); $htmlItem->setValue($html); $content->insertItem($htmlItem); } $content->closeBoundary($innerBoundary); foreach ($attachments as $attachment) { $content->insertBoundary($outerBoundary); $item = new Item(); $item->addField(new Field(Field::CONTENT_DISPOSITION, array('attachment', "filename=\"{$attachment->getName()}\""))); $item->addField(new Field(Field::CONTENT_TYPE, array($attachment->getContentType(), "name=\"{$attachment->getName()}\""))); $item->addField(new Field(Field::CONTENT_TRANSFER_ENCODING, array('base64'))); $item->setValue($attachment->getBody()); $content->insertItem($item); } $content->closeBoundary($outerBoundary); return $content->getOutput(); }
public static function getSitePath() { if (isset(self::$site_path) && strlen(self::$site_path)) { return self::$site_path; } // Attempt to use the first web directory on current path, otherwise use the web ("document") root $web_pos = strrpos($_SERVER['SCRIPT_FILENAME'], self::$web_directory); if ($web_pos !== false) { self::$site_web_path = substr($_SERVER['SCRIPT_FILENAME'], 0, $web_pos + strlen(self::$web_directory)); } else { if (isset($_SERVER['DOCUMENT_ROOT'])) { self::$site_web_path = $_SERVER['DOCUMENT_ROOT']; } } // Usually site path is one directory up from the site web path self::$site_path = dirname(self::$site_web_path); //echo 'DEBUG site path: '.self::$site_path."<br/>"; return self::$site_path; }
public function getFooterContent($alias = false, $template = false) { global $site_path; if (!isset($site_path)) { $site_path = ContentBuilder::getSitePath(); } if (isset($this->footer_content) && strlen($this->footer_content)) { return $this->footer_content; } if (!$alias) { $alias = $this->getAlias(); } if (!$template) { $template = $site_path . ContentBuilder::$template_directory . '/' . ($this->hasType() ? $this->type . '_' : '') . 'footer.' . ContentBuilder::$template_extension; } if (is_file($template)) { $replacements = $this->getReplacements(); $this->cb->reset($template, $replacements); $this->footer_content = $this->cb->getContent(); } return $this->footer_content; }
public function getContent($template = false, $additional_replacements = false) { if (!$template) { $template = $this->template; } if ($this->require_processing_for_render && !$this->processed) { $this->process(); } if ($this->should_build_fields && !$this->fields_built) { $this->buildFields(); } $replacements = $this->getData(); if (is_array($additional_replacements)) { $replacements = array_merge($replacements, $additional_replacements); } $content = parent::getContent($template, $replacements); return $content; }
public function getContent($template = false, $replacements = false) { // Check if the first parameter is actually just the collection alias $pos = stripos($template, ContentBuilder::getTemplateExtension()); if ($pos === false || $pos !== strlen($template) - strlen(ContentBuilder::getTemplateExtension())) { //echo 'DEBUG This is NOT a template? '.$template.' Cause pos: '.$pos.' != '.(strlen($template)-strlen(ContentBuilder::getTemplateExtension()))."\n"; $collection_alias = $template; $template = $this->template; //.= '.'.ContentBuilder::getTemplateExtension(); } else { $collection_alias = substr($template, 0, -strlen(ContentBuilder::getTemplateExtension())); } //echo 'DEBUG collection alias: '.$collection_alias."\n"; // We need to know the collection alias in order to determine the set of slides (aka the "slide collection") to work with if (!$template) { $template = $this->template; } $slides = $this->getSlides($this->slides_subpath); //echo 'DEBUG slides<pre>'; //print_r($slides); //echo '</pre>'; if (count($slides) > 1) { // We need to make the slide paths webroot-relative if (self::$slides_webpath) { foreach ($slides as &$s) { $s = self::$slides_webpath . ($this->slides_subpath ? $this->slides_subpath . DIRECTORY_SEPARATOR : '') . $s; } } $replacements['slides'] = $slides; return self::$cb->getContent($template, $replacements); } else { return false; } }