/** * 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; }