Esempio n. 1
0
    /**
     * Fetch main article images for specified URL
     */
    public function fetchImage($url, $customFilename = '')
    {
        $remoteImageUpload = new RemoteImageUpload();
        $remoteImageUpload->customFilename = 'youtube_feed_' . $customFilename;
        $attachmentIdentifier = $remoteImageUpload->processImage($url);

        if ($attachmentIdentifier)
            return $attachmentIdentifier;
    }
    /**
     * Fetch main article images for specified URL
     */
    public function fetchImage($url)
    {
        $pageSource = @file_get_contents($url);

        if ($pageSource !== false) {
            preg_match_all('/<img[^>]+>/i', $pageSource, $images);

            foreach ($images[0] as $image) {
                $xml = @simplexml_load_string($image);
                if ($xml) {
                    $classes = $xml->xpath("//@class");

                    $class = $classes ? (string) $classes[0]['class'] : '';

                    // If the image is the main article image
                    if ($class == 'article_img') {
                        $src = $xml->xpath("//@src");
                        $src = $src ? (string) $src[0]['src'] : '';

                        // If the image path doesn't include the domain...
                        if (strpos($src, 'http') === false) {

                            $urlParts = parse_url($url);
                            $src = $urlParts['scheme'] . '://' . $urlParts['host'] . $src;

                            $remoteImageUpload = new RemoteImageUpload();
                            $attachmentIdentifier = $remoteImageUpload->processImage($src);

                            if ($attachmentIdentifier) {
                                return $attachmentIdentifier;
                            } else
                                return false;
                        }

                        return $src;
                    }
                }
            }
        }

        return false;
    }