/** * Recursively embed all images in the array into the message * @param \Swift_Message $message * @param array $params * @return array $params */ private function embedImages(&$message, &$params) { // loop throug the array foreach ($params as $key => $value) { // if the current value is an array if (is_array($value)) { // search for more images deeper in the arrays $value = $this->embedImages($message, $value); $params[$key] = $value; // if the current value is an existing file from the image-folder, embed it } elseif (is_string($value)) { if (is_file($value)) { // check if the file is from an allowed folder if ($this->templateProvider->isFileAllowed($value) !== false) { $encodedImage = $this->cachedEmbedImage($value); if ($encodedImage != null) { $id = $message->embed($encodedImage); $params[$key] = $id; } } // the $filePath isn't a regular file } else { // ignore the imageDir itself, but log all other directories and symlinks that were not embeded if ($value != $this->templateProvider->getTemplateImageDir()) { $this->logger->info("'{$value}' is not a regular file and will not be embeded in the email."); } // add a null-value to the cache for this path, so we don't try again. $this->imageCache[$value] = null; } //if the current value is a generated image } elseif (is_resource($value) && stripos(get_resource_type($value), "gd") == 0) { // get the image-data as string ob_start(); imagepng($value); $imageData = ob_get_clean(); // encode the image $encodedImage = \Swift_Image::newInstance($imageData, "generatedImage" . md5($imageData)); $id = $message->embed($encodedImage); $params[$key] = $id; } else { // don't do anything } } // remove duplicate-attachments $message->setChildren(array_unique($message->getChildren())); return $params; }
/** * Convenience-function to add and save a Notification-entity for a message => see AzineTemplateProvider::CONTENT_ITEM_MESSAGE_TYPE * * The following default are used: * $importance = NORMAL * $sendImmediately = fale * $template = template for type AzineTemplateProvider::CONTENT_ITEM_MESSAGE_TYPE * $templateVars = only those from the template-provider * * @param integer $recipientId * @param string $title * @param string $content nl2br will be applied in the html-version of the email * @param string $goToUrl if this is supplied, a link "Go to message" will be added. */ public function addNotificationMessage($recipientId, $title, $content, $goToUrl = null) { $nt = $this->em->getRepository('AzineEmailBundle:NotificationType'); $contentItemTemplate = $nt->findOneByTemplate($this->configParameter[AzineEmailExtension::TEMPLATES . "_" . AzineEmailExtension::CONTENT_ITEM_TEMPLATE]); $templateVars = array(); if ($goToUrl != null) { $templateVars['goToUrl'] = $goToUrl; } $this->addNotification($recipientId, $title, $content, $contentItemTemplate, $this->templateProvider->addTemplateVariablesFor($contentItemTemplate->getTemplate(), $templateVars), Notification::IMPORTANCE_NORMAL, false); }
public function addCampaignParamsForTemplate($html, $templateId, $templateParams) { $campaignParams = $this->templateProvider->getCampaignParamsFor($templateId, $templateParams); return $this->addCampaignParamsToAllUrls($html, $campaignParams); }
/** * Convenience-function to add and save a Notification-entity for a message => see AzineTemplateProvider::CONTENT_ITEM_MESSAGE_TYPE * * The following default are used: * $importance = NORMAL * $sendImmediately = fale * $template = template for type AzineTemplateProvider::CONTENT_ITEM_MESSAGE_TYPE * $templateVars = only those from the template-provider * * @param integer $recipientId * @param string $title * @param string $content nl2br will be applied in the html-version of the email * @param string $goToUrl if this is supplied, a link "Go to message" will be added. */ public function addNotificationMessage($recipientId, $title, $content, $goToUrl = null) { $contentItemTemplate = $this->configParameter[AzineEmailExtension::TEMPLATES . "_" . AzineEmailExtension::CONTENT_ITEM_TEMPLATE]; $templateVars = array(); if ($goToUrl !== null && strlen($goToUrl) > 0) { $templateVars['goToUrl'] = $goToUrl; } $this->addNotification($recipientId, $title, $content, $contentItemTemplate, $this->templateProvider->addTemplateVariablesFor($contentItemTemplate, $templateVars), Notification::IMPORTANCE_NORMAL, false); }