Implements Phata\Widgetfy\Site\Common::translate

preprocess the URL
by this site adapter
@param string[] $url_parsed result of parse_url($url)
@return mixed array of preprocess result; boolean FALSE if not translatable
19519
public static function preprocess($url_parsed) {

        // replace current path with fragment
        // that starts with '!' mark
        if (isset($url_parsed['fragment']) &&
                (substr($url_parsed['fragment'], 0, 1) == '!')) {
            $path = substr($url_parsed['fragment'], 1);
            $url = 'http://www.facebook.com'.$path;
            $url_parsed = parse_url($url);
        }

        // test if the path can be preprocess
        if (in_array($url_parsed['path'],
                array('/video/video.php', '/video.php', '/photo.php'))) {
            // build data-href from old style video url
            parse_str($url_parsed['query'], $args);
            if (isset($args['v'])) {
                $query = array('v' => $args['v'], 'type' => 1,);
                if (isset($args['set'])) $query['set'] = $args['set'];
                return array(
                  'data-href' => 'https://www.facebook.com/video.php?' . http_build_query($query),
                );
            }
        } elseif (preg_match(RE_VIDEO_PATH_2015, $url_parsed['path'], $matches)) {
            return array(
                'data-href' => $matches[1] . '?type=1',
            );
        }

        return FALSE;
    }
900406
public static function routeParse($from, $to, $url)
    {
        // validation and parse route pattern
        $result = preg_match('/^(\(([^\)]+)\)|[^\/]*)(.*)/', $from, $data);

        if ($result !== 1) {
            return false;
        }

        // prepare patter to test url and replacement
        $pattern = '/^' . str_replace('/', '\/', $data[3]) . '$/';

        // test route pattern match
        $result = preg_match($pattern, $url);

        if ($result !== 1) {
            return false;
        }

        // create RouteInfo object and fill fields
        $route = new RouteInfo();
        // make array of supported methods
        $route->methods = empty($data[2]) ? [] : explode('|', $data[2]);
        // replace pattern url
        $route->url = preg_replace($pattern, $to, $url);

        return $route;
    }
1312558
public function parseUrl($url) {
		$url = parse_url($url);
		$url['vars'] = array();
		if (!isset($url['fragment'])) {
			$url['fragment'] = null;
		}
		if (isset($url['query'])) {
			parse_str($url['query'], $url['vars']);
		}

		return $url;
	}
166196
public static function prepareUrl($url)
    {
        // $url = urlencode($url);

        $replacement = [
            '&' => '&amp;',
            "'" => '&apos;',
            '"' => '&quot;',
            '>' => '&gt;',
            '<' => '&lt;',
        ];

        $url = str_replace(array_keys($replacement), array_values($replacement), $url);

        return $url;
    }
1061603
public function parse($url)
    {
        $content = $this->performRequest($url)->getBody()->getContents();

        $content = $this->convertEncodingToUTF8($content);

        return $this->getHtmlDomParser($content);
    }
953389
public static function _parse_url_query($url)
    {
        $array = parse_url($url);
        $query = $array['query'];

        $queryParts = explode('&', $query);

        $params = array();
        foreach ($queryParts as $param) {
            $item = explode('=', $param);
            $params[$item[0]] = empty($item[1]) ? '' : $item[1];
        }

        return $params;
    }
1261690
public function parse($url)
    {
        if (!$url) {
            $url = '/';
        }

        $Routes = TableRegistry::get('Wasabi/Core.Routes');

        $route = $Routes->find()
            ->orWhere([$Routes->aliasField('page_type') => 'collection'])
            ->orWhere([$Routes->aliasField('page_type') => 'simple'])
            ->andWhere([$Routes->aliasField('url') => $url])
            ->first();

        $pageNumber = false;

        $urlParts = explode('/', $url);

        // no direct route found -> try paged collection routes
        if (!$route) {
            $part = array_pop($urlParts);

            if (preg_match('/^[0-9]+$/', $part)) {
                $pageNumber = (int)$part;
                $part = array_pop($urlParts);
            }

            // paged url found so lets try to find a proper collection route
            if ($pageNumber !== false && $part === self::PAGE_PART) {
                $route = $Routes->find()->where([
                    $Routes->aliasField('page_type') => 'collection',
                    $Routes->aliasField('url') => join('/', $urlParts)
                ])->first();
            }
        }

        if (!$route) {
            return false;
        }

        if ($route->redirect_to !== null) {
            /** @var \Wasabi\Core\Model\Entity\Route $redirectRoute */
            $redirectRoute = $Routes->get($route->redirect_to);

            $redirectUrl = $redirectRoute->url;
            $statusCode = 301;
            if ($pageNumber !== false && $pageNumber > 1) {
                $redirectUrl .= '/' . self::PAGE_PART . '/' . $pageNumber;
            }
            if ($route->status_code !== null) {
                $statusCode = (int)$route->status_code;
            }

            $this->_redirect($redirectUrl, $statusCode);
        }

        // Dispatch Wasabi.Routes.parse event to all plugin listeners to get params.
        $routesParseEvent = new Event('Wasabi.Routes.parse', $url, [
            'route' => $route,
            'pageNumber' => $pageNumber
        ]);

        EventManager::instance()->dispatch($routesParseEvent);

        if (!$routesParseEvent->isStopped() || empty($routesParseEvent->result['params'])) {
            return false;
        }

        $params = $routesParseEvent->result['params'];

        return $params;
    }
967625
public static function segmentizeUrl($url)
        {
            $url = self::normalizeUrl($url);
            $segments = explode('/', $url);

            $result = array();

            foreach ($segments as $segment) {
                if (strlen($segment)) $result[] = $segment;
            }

            return $result;
        }
1065949
public static function build($url_parsed) {

        // add default values to prevent empty
        $url_parsed = (array) $url_parsed + array(
            'scheme' => '',
            'host' => '',
            'port' => '',
            'user' => '',
            'pass' => '',
            'path' => '',
            'query' => '',
            'fragment' => '',
        );

        $url = '';

        // add components that depends on host
        if (!empty($url_parsed['host'])){

            // scheme
            $url = empty($url_parsed['scheme']) ?
                '//' : $url_parsed['scheme'].'://';

            // components that depends on user
            if (!empty($url_parsed['user'])) {
                $url .= empty($url_parsed['pass']) ?
                    $url_parsed['user'] :
                    $url_parsed['user'] . ':' . $url_parsed['pass'] ;
                $url .= '@';
            }

            // host
            $url .= $url_parsed['host'];

            // port
            $url .= empty($url_parsed['port']) ?
                '' : ':' . ((int) $url_parsed['port']);

        }

        // path
        $url .= empty($url_parsed['path']) ?
            '' : $url_parsed['path'];

        // query
        $url .= empty($url_parsed['query']) ?
            '' : '?' . $url_parsed['query'];

        // fragment
        $url .= empty($url_parsed['fragment']) ? 
            '' : '#' . $url_parsed['fragment'];

        return $url;

    }
631399
public static function parse($url)
    {
        if (!strlen($url)) {
            return null;
        }
        $_urls = array_merge( @parse_url($url), array('params'=>array()) );
        if (isset($_urls['query'])) {
            parse_str($_urls['query'], $_urls['params']);
        }
        return $_urls;  
    }
86211
protected static function parseUrl($url)
    {
        $components = @parse_url($url);
        if (! empty($components)) {
            return $components;
        }

        if (is_null(static::$is_parse_url_bugged)) {
            static::$is_parse_url_bugged = ! is_array(@parse_url("//example.org:80"));
        }

        //bugfix for https://bugs.php.net/bug.php?id=68917
        if (static::$is_parse_url_bugged &&
            strpos($url, '/') === 0 &&
            is_array($components = @parse_url('http:'.$url))
        ) {
            unset($components['scheme']);
            return $components;
        }
        throw new RuntimeException(sprintf("The given URL: `%s` could not be parse", $url));
    }
824845
public static function preprocess($url_parsed) {
        if (preg_match('/\/([^\/]+)\.(rm|rmvb)$/i', $url_parsed['path'], $matches) == 1) {
            $filename = htmlspecialchars($matches[1] . '.' . $matches[2]);
            $extension = strtolower($matches[2]);
            return array(
                'filetype' => $extension,
                'url' => URL::build($url_parsed),
            );
        }
        return FALSE;
    }
1067972
static function url_parse_into($url, &$request)
    {
        $url = str_replace(self::$url_add_end, '', $url);
        if (self::$url_key_join == self::$url_param_join)
        {
            $urls = explode(self::$url_param_join, $url);
            $c = intval(count($urls) / 2);
            for ($i = 0; $i < $c; $i++)
            {
                $request[$urls[$i * 2]] = $urls[$i * 2 + 1];
            }
        }
        else
        {
            $urls = explode(self::$url_param_join, $url);
            foreach ($urls as $u)
            {
                $us = explode(self::$url_key_join, $u);
                $request[$us[0]] = $us[1];
            }
        }
    }
1188080
function parse(url) {
  ['?', '#'].forEach(function(separator) {
    var index = url.indexOf(separator);
    if (index !== -1) url = url.substring(0, index);
  });
  return url;
}
1241978
public function normalizeLinkText($url)
    {
        if( property_exists($this,'normalizeLinkText') && is_callable($this->normalizeLinkText)){
            $fn = $this->normalizeLinkText;
            return $fn($url);
        }
        $parsed = $this->mdurl->parse($url, true);

        if ($parsed->hostname) {
            // Encode hostnames in urls like:
            // `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
            //
            // We don't encode unknown schemas, because it's likely that we encode
            // something we shouldn't (e.g. `skype:name` treated as `skype:host`)
            //
            $is = false;
            foreach (self::RECODE_HOSTNAME_FOR as &$v) {
                if( ($is = $v === $parsed->protocol) ) break;
            }
            if (empty($parsed->protocol) || $is) {
                try {
                    $parsed->hostname = $this->punycode->toUnicode($parsed->hostname);
                } catch (\Exception $e) { /**/ }
            }
        }
        return $this->mdurl->decode($this->mdurl->format($parsed));
    }
1162887
public static function url_parser($url)
    {
        $regex = '/(?<=v=|v\/|vi=|vi\/|youtu.be\/|embed\/)([a-zA-Z0-9_-]{11})/';

        if (!empty($url)) {
            //full youtube URL
            if (strpos($url, 'youtu') !== false) {
                if (preg_match($regex, $url, $matches)) {
                    return $matches[1];
                }
            } elseif (strlen($url) == 11) {
                return $url;
            }
        }

        return false;
    }
152781
private static function checkParsedUrl(array $parsed)
    {
        $scheme   =& $parsed['scheme'];
        $user     =& $parsed['user'];
        $pass     =& $parsed['pass'];
        $host     =& $parsed['host'];
        $port     =& $parsed['port'];
        $path     =& $parsed['path'];
        $path     = '/'.ltrim($path, '/'); // If / is missing for path.
        $query    =& $parsed['query'];
        $fragment =& $parsed['fragment'];

        return compact(
            'scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'
        );
    }