/*!
\private

Fetch Image from current ezrss export object. If non exist, or invalid, return false

\return valid image url
321846
function fetchImageURL()
    {

        $imageNode =  $this->attribute( 'image_node' );
        if ( !$imageNode )
            return false;

        $imageObject =  $imageNode->attribute( 'object' );
        if ( !$imageObject )
            return false;

        $dataMap =  $imageObject->attribute( 'data_map' );
        if ( !$dataMap )
            return false;

        $imageAttribute =  $dataMap['image'];
        if ( !$imageAttribute )
            return false;

        $imageHandler =  $imageAttribute->attribute( 'content' );
        if ( !$imageHandler )
            return false;

        $imageAlias =  $imageHandler->imageAlias( 'rss' );
        if( !$imageAlias )
            return false;

        $url = eZSys::hostname() . eZSys::wwwDir() .'/'. $imageAlias['url'];
        $url = preg_replace( "#^(//)#", "/", $url );

        return 'http://'.$url;
    }
228447
function(params, callback) {
                getImageData = {};

                if (params) {
                    if (parseInt(params.imageId) > 0) {
                        getImageData.imageId = params.imageId;
                    }

                    if (typeof params.hashCode == 'string') {
                        getImageData.hashCode = params.hashCode;
                    }

                    if (parseInt(params.width) > 0) {
                        getImageData.width = params.width;
                    }

                    if (parseInt(params.height) > 0) {
                        getImageData.height = params.height;
                    }

                    if (parseInt(params.actual) > 0) {
                        getImageData.actual = params.actual;
                    }

                    if (parseInt(params.downloadable) > 0) {
                        getImageData.downloadable = params.downloadable;
                    }
                }

                httpRequest({
                    url: SERVICE_ADDRESSES.FILESERVER_ADDRESS + SERVICES_PATH.GET_IMAGE,
                    method: 'GET',
                    data: getImageData
                }, function(result) {
                    if (!result.hasError) {
                        var queryString = '?';
                        for (var i in params) {
                            queryString += i + '=' + params[i] + '&';
                        }
                        queryString = queryString.slice(0, -1);
                        var image = SERVICE_ADDRESSES.FILESERVER_ADDRESS + SERVICES_PATH.GET_IMAGE + queryString;
                        callback({
                            hasError: result.hasError,
                            result: image
                        });
                    }
                    else {
                        callback({
                            hasError: true
                        });
                    }
                });
            }
794480
function LinkImageSort($_by,$sby,$soby,$soby2,$stitle) {
   if($_by==$sby)
    return <<<EOF
  <a href="{$_SERVER['PHP_SELF']}?sort={$soby}&amp;by={$sby}" class="formfont" onmouseover="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby}.gif'; }" onmouseout="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby2}.gif'; }"><b>{$stitle}</b> <img src="./swat4query/images/server_{$soby2}.gif" width="11" height="9" border="0" alt="{$soby}" id="so{$sby}" />
EOF;
   else return '<a href="'.$_SERVER['PHP_SELF'].'?sort='.$soby.'&amp;by='.$sby.'" class="formfont"><b>'.$stitle.'</b>';
  }
153417
static function fetchFromFile( $filename )
    {
        $dom = eZPackage::fetchDOMFromFile( $filename );

        if ( $dom === false )
        {
            return false;
        }

        $package = new eZPackage();
        $parameters = $package->parseDOMTree( $dom );
        if ( !$parameters )
        {
            return false;
        }

        return $package;
    }
1157236
private function getExport(): bool
    {
        if (false === $this->export) {
            $this->export = (bool)Configure::read('Search.dashboardExport');
        }

        return $this->export;
    }
188243
public function getImage()
    {
        if (class_exists('O2System\Framework') or class_exists('\O2System\Reactor', false)) {
            $tempFilePath = @tempnam(PATH_CACHE, 'captcha');
        } else {
            $tempFilePath = @tempnam(
                sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'o2system' . DIRECTORY_SEPARATOR,
                'captcha'
            );
        }

        if ($image = imagecreatetruecolor(200, 50)) {
            $backgroundColor = imagecolorallocate($image, 255, 255, 255);
            $lineColor = imagecolorallocate($image, 64, 64, 64);
            $pixelColor = imagecolorallocate($image, 0, 0, 255);

            imagefilledrectangle($image, 0, 0, 200, 50, $backgroundColor);

            for ($i = 0; $i < 3; $i++) {
                imageline($image, 0, rand() % 50, 200, rand() % 50, $lineColor);
            }

            for ($i = 0; $i < 1000; $i++) {
                imagesetpixel($image, rand() % 200, rand() % 50, $pixelColor);
            }

            $textColor = imagecolorallocate($image, 0, 0, 0);

            for ($i = 0; $i < 6; $i++) {
                imagestring($image, 10, 20 + ($i * 30), 20, substr($this->getToken(), $i, 1), $textColor);
            }

            imagepng($image, $tempFilePath);

            $base64Image = base64_encode(file_get_contents($tempFilePath));
            @unlink($tempFilePath);

            return 'data:image/png;base64,' . $base64Image;
        }

        // Cannot Initialize new GD image stream
        throw new RuntimeException('SECURITY_E_CAPTCHA_GD_IMAGE_STREAM');
    }
1193898
function downloadFileObject( $contentObject, $contentObjectAttribute )
    {
        $contentObjectAttributeID = $contentObjectAttribute->attribute( 'id' );
        $version = $contentObject->attribute( 'current_version' );
        $fileObject = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
        if ( $fileObject )
            return $fileObject;
        $fileObject = eZMedia::fetch( $contentObjectAttributeID, $version );
        return $fileObject;
    }
574409
protected function fetchAndSaveUniqueImage( $url ) {

		if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
			return '';
		}

		$remote_img_location = $url;

		// Cheap cache
		static $already_done = [];
		if ( isset( $already_done[ $remote_img_location ] ) ) {
			return $already_done[ $remote_img_location ];
		}

		/* Process */

		// Basename without query string
		$filename = explode( '?', basename( $url ) );
		$filename = array_shift( $filename );

		$filename = sanitize_file_name( urldecode( $filename ) );

		if ( ! preg_match( '/\.(jpe?g|gif|png)$/i', $filename ) ) {
			// Unsupported image type
			$already_done[ $remote_img_location ] = '';
			return '';
		}

		$tmp_name = download_url( $remote_img_location );
		if ( is_wp_error( $tmp_name ) ) {
			// Download failed
			$already_done[ $remote_img_location ] = '';
			return '';
		}

		if ( ! \Pressbooks\Image\is_valid_image( $tmp_name, $filename ) ) {

			try { // changing the file name so that extension matches the mime type
				$filename = $this->properImageExtension( $tmp_name, $filename );

				if ( ! \Pressbooks\Image\is_valid_image( $tmp_name, $filename ) ) {
					throw new \Exception( 'Image is corrupt, and file extension matches the mime type' );
				}
			} catch ( \Exception $exc ) {
				// Garbage, don't import
				$already_done[ $remote_img_location ] = '';
				unlink( $tmp_name );
				return '';
			}
		}

		$pid = media_handle_sideload(
			[
				'name' => $filename,
				'tmp_name' => $tmp_name,
			], 0
		);
		$src = wp_get_attachment_url( $pid );
		if ( ! $src ) {
			$src = ''; // Change false to empty string
		}
		$already_done[ $remote_img_location ] = $src;
		@unlink( $tmp_name ); // @codingStandardsIgnoreLine

		return $src;
	}
42479
function fetchData(token) {
    sdk.feed.startpage(token).then(function(stream) {
        return stream.messages.map(function(message) {
            return message.attachments.filter(function(attachment) {
                return attachment.type === 'IMAGE';
            });
        });
    }).then(function(imageAttachmentArrays) {
        return imageAttachmentArrays.reduce(function(prev, cur) {
            return prev.concat(cur);
        }, []);
    }).then(function(imageAttachments) {
        imageAttachments.forEach(function(attachment) {
            var file_name = attachment.url.split('/').reverse()[0];
            request('https://' + sdk.config.domain + attachment.url)
                .pipe(fs.createWriteStream(file_name))
                .on('finish', function() {
                    console.log('saved attachment ' + file_name);
                });
        });
    }).catch(function(err) {
        console.log('Error:', err);
    });
}
1049150
public function getImageUrl($admin = false, $ssl = null, $nativeImg = null, $file = null)
    {
        $nativeImg = is_null($nativeImg) ? $this->getConfigParam('blNativeImages') : $nativeImg;

        return $this->getUrl($file, $this->_sImageDir, $admin, $ssl, $nativeImg);
    }
431697
def _image_url(array, fmt='png', mode="data", quality=90, domain=None):
  
  supported_modes = ("data")
  if mode not in supported_modes:
    message = "Unsupported mode '%s', should be one of '%s'."
    raise ValueError(message, mode, supported_modes)

  image_data = serialize_array(array, fmt=fmt, quality=quality)
  base64_byte_string = base64.b64encode(image_data).decode('ascii')
  return "data:image/" + fmt.upper() + ";base64," + base64_byte_string
1133222
public static function download_lorem_image()
    {
        $url = 'http://lorempixel.com/1024/768?t='.uniqid();
        $img_filename = "mock-file-".uniqid().".jpeg";

        $img = self::get_mock_folder()->getFullPath().$img_filename;

        if (ini_get('allow_url_fopen')) {
            file_put_contents($img, file_get_contents($url));
        } else {
            $ch = curl_init($url);
            $fp = fopen($img, 'wb');
            curl_setopt($ch, CURLOPT_FILE, $fp);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_exec($ch);
            curl_close($ch);
            fclose($fp);
        }

        if (!file_exists($img) || !filesize($img)) {
            return false;
        }

        $i = Image::create();
        $i->Filename = self::get_mock_folder()->Filename.$img_filename;
        $i->Title = $img_filename;
        $i->Name = $img_filename;
        $i->ParentID = self::get_mock_folder()->ID;
        $i->write();

        return $i;
    }
844210
function fetchRemoteImages(rootFolder, currentFile, $) {
    var currentDirectory = path.dirname(currentFile);

    return editHTMLElement($, 'img', function($img) {
        var src = $img.attr('src');
        var extension = path.extname(src);

        if (!LocationUtils.isExternal(src)) {
            return;
        }

        // We avoid generating twice the same PNG
        var hash = crc.crc32(src).toString(16);
        var fileName = hash + extension;
        var filePath = path.join(rootFolder, fileName);

        return fs.assertFile(filePath, function() {
            return fs.download(src, filePath);
        })
        .then(function() {
            // Convert to relative
            src = LocationUtils.relative(currentDirectory, fileName);

            $img.replaceWith('<img src="' + src + '" />');
        });
    });
}
457509
static function fetchByName( $name, $asObject = true )
    {
        $conds = array( 'name' => $name );
        return eZPersistentObject::fetchObject( eZContentClassGroup::definition(),
                                                null,
                                                $conds,
                                                $asObject );
    }
1030374
static function exportByNode( $nodeID )
    {
        if ( !$nodeID )
            return array( 'error' => array( 'error_type' => 'kernel',
                                            'error_code' => eZError::KERNEL_NOT_FOUND ) );

        $rssExport = eZPersistentObject::fetchObject( eZRSSExport::definition(),
                                                null,
                                                array( 'node_id' => $nodeID,
                                                       'status' => eZRSSExport::STATUS_VALID ),
                                                true );

        return array( 'result' => $rssExport );
    }
989402
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        eZBinaryFileType::checkFileUploads();
        if ( $this->isDeletingFile( $http, $contentObjectAttribute ) )
        {
            return false;
        }

        if ( !eZHTTPFile::canFetch( $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" ) ) )
            return false;

        $httpBinaryFile = eZHTTPFile::fetch( $base . "_data_binaryfilename_" . $contentObjectAttribute->attribute( "id" ) );

        $contentObjectAttribute->setContent( $httpBinaryFile );

        if ( $httpBinaryFile instanceof eZHTTPFile )
        {
            $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
            $version = $contentObjectAttribute->attribute( "version" );

            /*
            $mimeObj = new  eZMimeType();
            $mimeData = $mimeObj->findByURL( $httpBinaryFile->attribute( "original_filename" ), true );
            $mime = $mimeData['name'];
            */

            $mimeData = eZMimeType::findByFileContents( $httpBinaryFile->attribute( "original_filename" ) );
            $mime = $mimeData['name'];

            if ( $mime == '' )
            {
                $mime = $httpBinaryFile->attribute( "mime_type" );
            }
            $extension = eZFile::suffix( $httpBinaryFile->attribute( "original_filename" ) );
            $httpBinaryFile->setMimeType( $mime );
            if ( !$httpBinaryFile->store( "original", $extension ) )
            {
                eZDebug::writeError( "Failed to store http-file: " . $httpBinaryFile->attribute( "original_filename" ),
                                     "eZBinaryFileType" );
                return false;
            }

            $binary = eZBinaryFile::fetch( $contentObjectAttributeID, $version );
            if ( $binary === null )
            {
                $binary = eZBinaryFile::create( $contentObjectAttributeID, $version );
            }
            else
            {
                // if storing a different file for the same version, see if the existing file can be removed.
                $newFileName = basename( $httpBinaryFile->attribute( "filename" ) );
                if ( $newFileName != $binary->Filename )
                {
                    $this->deleteStoredObjectAttribute( $contentObjectAttribute, $version );
                }
            }

            $orig_dir = $httpBinaryFile->storageDir( "original" );

            $binary->setAttribute( "contentobject_attribute_id", $contentObjectAttributeID );
            $binary->setAttribute( "version", $version );
            $binary->setAttribute( "filename", basename( $httpBinaryFile->attribute( "filename" ) ) );
            $binary->setAttribute( "original_filename", $httpBinaryFile->attribute( "original_filename" ) );
            $binary->setAttribute( "mime_type", $mime );

            $binary->store();

            $filePath = $httpBinaryFile->attribute( 'filename' );
            $fileHandler = eZClusterFileHandler::instance();
            $fileHandler->fileStore( $filePath, 'binaryfile', true, $mime );

            $contentObjectAttribute->setContent( $binary );
        }
        return true;
    }
558726
function processPostData()
    {
        if ( $this->Http->hasPostVariable( 'UploadPackageButton' ) )
        {
            $this->uploadPackage();
            return false; // force displaying the same step.
        }

        if ( !$this->Http->hasPostVariable( 'eZSetup_site_type' ) )
        {
            $this->ErrorMsg = ezpI18n::tr( 'design/standard/setup/init',
                                      'No site package chosen.' );
            return false;
        }

        $sitePackageInfo = $this->Http->postVariable( 'eZSetup_site_type' );
        $downloaded = false; // true - if $sitePackageName package has been downloaded.
        if ( preg_match( '/^(\w+)\|(.+)$/', $sitePackageInfo, $matches ) )
        {
            // remote site package chosen: download it.
            $sitePackageName = $matches[1];
            $sitePackageURL  = $matches[2];

            // we already know that we should download the package anyway as it has newer version
            // so use force download mode
            $package = $this->downloadAndImportPackage( $sitePackageName, $sitePackageURL, true );
            if ( is_object( $package ) )
            {
                $downloaded = true;
                $this->Message = ezpI18n::tr( 'design/standard/setup/init', 'Package \'%packageName\' and it\'s dependencies have been downloaded successfully. Press \'Next\' to continue.', false, array( '%packageName' => $sitePackageName ) );
            }
        }
        else
        {
            // local (already imported) site package chosen: just fetch it.
            $sitePackageName = $sitePackageInfo;

            $package = eZPackage::fetch( $sitePackageName, false, false, false );
            $this->ErrorMsg = ezpI18n::tr( 'design/standard/setup/init', 'Invalid package' ) . '.';
        }

        // Verify package.
        if ( !is_object( $package ) || !$this->selectSiteType( $sitePackageName ) )
            return false;

        // Download packages that the site package requires.
        $downloadDependandPackagesResult = $this->downloadDependantPackages( $package );
        return $downloadDependandPackagesResult == false ? false : !$downloaded;
    }