public static function replaceRelativeUrls($content, $baseUrl) { $baseUrl = trim($baseUrl, '/ '); $baseUrl .= '/'; $object = new Customweb_Util_Html(); $url = new Customweb_Http_Url($baseUrl); $object->baseUrl = $baseUrl; $object->baseDomain = $url->getBaseUrl(); $patterns = array('/(href=")([^"]*)(")/', '/(href=\')([^\']*)(\')/', '/(src=")([^"]*)(")/', '/(src=\')([^\']*)(\')/', '/(srcset=")([^"]*)(")/', '/(srcset=\')([^\']*)(\')/'); foreach ($patterns as $pattern) { $content = preg_replace_callback($pattern, array($object, 'replaceRelativeUrl'), $content); } return $content; }
public function getFormActionUrl(Customweb_Payment_Authorization_ITransaction $transaction, array $formData) { $completeUrl = $this->getRedirectionUrl($transaction, $formData); $url = new Customweb_Http_Url($completeUrl); return $url->getBaseUrl() . $url->getPath(); }
/** * This method converts all relative and absolute URLs to absolute URLs. * * @param string $href * @param Customweb_Http_Url $baseUrl * @return Customweb_Http_Url */ public static function toAbsoluteUrl($href, Customweb_Http_Url $baseUrl) { if ($href instanceof Customweb_Http_Url) { return $href; } $href = (string) $href; $href = trim($href); // If the URL string contains :// then the protocol etc. defined. if (strstr($href, '://')) { return new Customweb_Http_Url($href); } else { // Append a slash at the begin, when there is no one. This // insures that we get always a valid URL. if (substr($href, 0, 1) !== '/') { $href = '/' . $href; } return new Customweb_Http_Url($baseUrl->getBaseUrl() . $href); } }