Пример #1
0
 protected function embedImages()
 {
     $root = Helper::getWebroot();
     //Diretório raiz do site
     $baseUrlFull = Helper::getBaseUrl(true);
     //Encontra todas as imagens
     $this->body = HtmlParser::normalizeImgs($this->body);
     //echo $this->body; exit;
     $imgs = HtmlParser::extrairImgs($this->body);
     //Faz todas as substituições de IMAGENS por CIDs
     foreach ($imgs as $img) {
         $urlFormat = $img[0] == '/' && !is_file($img);
         //No linux o caminho pode começar com /
         $path = $urlFormat ? dirname($root) . $img : $img;
         //Gera um path ou usa o que foi lido
         $internal = !(strpos($path, $baseUrlFull) !== 0 && strpos($path, 'http:') === 0);
         //É http e endereço é diferente
         if ($internal or $this->embedExternal) {
             //Só adiciona externo se estive habilitado
             $cid = $this->message->message->embed(Swift_Image::fromPath($path));
             $this->body = str_replace($img, $cid, $this->body);
         }
     }
 }