bernhard Posted November 4, 2018 Share Posted November 4, 2018 I need to send E-Mails with embedded images. Therefore the image urls need to be absolute httpUrls instead of relative ones like /site/assets/...; I didn't find one, so I created this: <?php namespace ProcessWire; /** * Converts relative CKEditor image urls to httpUrls * eg /site/assets/files/123/demo.png * to https://www.demo.com/site/assets/files/123/demo.png */ class TextformatterImagesHttpUrl extends Textformatter { public static function getModuleInfo() { return array( 'title' => 'Relative Image Urls to HttpUrls', 'version' => '1.0.0', 'summary' => "Converts relative CKEditor image urls to httpUrls.", ); } public function format(&$str) { $url = $this->wire->config->urls->files; $httpUrl = $this->wire->pages->get(1)->httpUrl; $httpUrl .= ltrim($url, "/"); $url = str_replace("/", "\/", $url); $str = preg_replace("/src=\"$url/m", "src=\"$httpUrl", $str); } } 4 1 Link to comment Share on other sites More sharing options...
dotnetic Posted November 4, 2018 Share Posted November 4, 2018 Should be added to the modules directory 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now