/** * Resolves URL to the format appropriate for widget mode * * @param string $url URL */ public static function resolveUrl($url) { $url = str_replace('&', '&', $url); if (parse_url($url, PHP_URL_SCHEME) == '' && strpos($url, '//') !== 0) { $url = Url::resolve($url, Registry::get('config.current_location')); } $path = Registry::get('config.current_host') . Registry::get('config.current_path'); if (false !== ($pos = strpos($url, $path))) { $query = urlencode(substr($url, $pos + strlen($path))); $params = self::getParams(); if (!empty($params['fb_app_id']) && !empty($params['fb_page_id'])) { $url = sprintf("https://www.facebook.com/pages/~/%s?sk=app_%s&app_data=%s", $params['fb_page_id'], $params['fb_app_id'], $query); } else { $url = self::getUrl() . "#!{$query}"; } } return $url; }
/** * Output filter: Transforms URLs to the appropriate format for the embedded mode * @param string $content template content * @param \Smarty_Internal_Template $template template instance * @return string template content */ public static function outputEmbeddedUrl($content, \Smarty_Internal_Template $template) { $path = Registry::get('config.current_host') . Registry::get('config.current_path'); // Transform 'href' attribute values of the 'a' elements, which: // - have 'href' attribute // - the 'href' value contains current path and host, or its a relative url // - do not have class attribute starting with 'cm-' prefix $pattern = '{' . '<(?:a)\\s+' . '(?=[^>]*\\bhref="([^"]*//' . $path . '[^"]*|(?!//)(?!https?)[^"]*)")' . '(?![^>]*\\bclass="[^"]*cm-[^"]*")' . '[^>]*>' . '}Usi'; $content = preg_replace_callback($pattern, function ($matches) { return str_replace($matches[1], Embedded::resolveUrl($matches[1]), $matches[0]); }, $content); // Transform relative 'src'attribute values $pattern = '{<[^>]+\\bsrc="((?!//)(?!https?)[^"]+)"[^>]*>}Usi'; $content = preg_replace_callback($pattern, function ($matches) { return str_replace($matches[1], Url::resolve($matches[1], Registry::get('config.current_location')), $matches[0]); }, $content); $area = Registry::get('view')->getArea(); if ($area[1] == 'mail') { // Transform URLs in the text $pattern = '{\\bhttps?://' . $path . '[^\\s<>"\']*(?=[^>]*<)}s'; $content = preg_replace_callback($pattern, function ($matches) { return Embedded::resolveUrl($matches[0]); }, $content); } return $content; }