Pop\Feed\Reader::getSource PHP Method

getSource() protected static method

Static method to create a Feed Reader object from a URL
protected static getSource ( string $url ) : array
$url string
return array
    protected static function getSource($url)
    {
        $urlInfo = parse_url($url);
        $ary = explode('.', $urlInfo['host']);
        $i = count($ary) - 2;
        $domain = $ary[$i];
        $service = ucfirst(strtolower($domain));
        $options = array('http' => array('method' => 'GET', 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0'));
        if (isset($_SERVER['HTTP_USER_AGENT'])) {
            $options['http']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
        }
        $context = stream_context_create($options);
        $source = file_get_contents($url, false, $context);
        // If Twitter or Facebook
        if (strpos($url, 'twitter.com') !== false) {
            $format = 'Rss';
            // If XML
        } else {
            if (strpos($source, '<?xml') !== false || strpos($source, '<rss') !== false || strpos($source, '<feed') !== false) {
                // If Atom
                if (strpos($source, '<entry') !== false) {
                    $format = 'Atom';
                    // If RSS
                } else {
                    $format = 'Rss';
                }
                // If JSON
            } else {
                if (substr($source, 0, 1) == '{' || substr($source, 0, 1) == '[') {
                    $format = 'Json';
                    // If PHP
                } else {
                    $format = 'Php';
                }
            }
        }
        return array('url' => $url, 'context' => $context, 'source' => $source, 'domain' => $domain, 'service' => $service, 'format' => $format);
    }