Fetch all conversions relating to the specified file.

Only conversions which have a valid file are returned.

@param   stored_file $file The source file being converted
@param   string $format The targetforamt to filter to
@return  conversion[]
502415
public static function get_conversions_for_file(stored_file $file, $format) {
        global $DB;
        $instances = [];

        // Conversion records are intended for tracking a conversion in progress or recently completed.
        // The record is removed periodically, but the destination file is not.
        // We need to fetch all conversion records which match the source file and target, and also all source and
        // destination files which do not have a conversion record.
        $sqlfields = self::get_sql_fields('c', 'conversion');

        // Fetch actual conversions which relate to the specified source file, and have a matching conversion record,
        // and either have a valid destination file which still exists, or do not have a destination file at all.
        $sql = "SELECT {$sqlfields}
                FROM {" . self::TABLE . "} c
                INNER JOIN {files} conversionsourcefile ON conversionsourcefile.id = c.sourcefileid
                LEFT JOIN {files} conversiondestfile ON conversiondestfile.id = c.destfileid
                WHERE
                    conversionsourcefile.contenthash = :ccontenthash
                AND c.targetformat = :cformat
                AND (
                    c.destfileid IS NULL OR conversiondestfile.id IS NOT NULL
                )";

        // Fetch a empty conversion record for each source/destination combination that we find to match where the
        // destination file is in the correct filearea/filepath/filename combination to meet the requirements.
        // This ensures that existing conversions are used where possible, even if there is no 'conversion' record for
        // them.
        $sql .= "
            UNION ALL
                SELECT
                    NULL AS conversionid,
                    orphanedsourcefile.id AS conversionsourcefileid,
                    :oformat AS conversiontargetformat,
                    2 AS conversionstatus,
                    NULL AS conversionstatusmessage,
                    NULL AS conversionconverter,
                    orphaneddestfile.id AS conversiondestfileid,
                    NULL AS conversiondata,
                    0 AS conversiontimecreated,
                    0 AS conversiontimemodified,
                    0 AS conversionusermodified
                FROM {files} orphanedsourcefile
                INNER JOIN {files} orphaneddestfile ON (
                        orphaneddestfile.filename = orphanedsourcefile.contenthash
                    AND orphaneddestfile.component = 'core'
                    AND orphaneddestfile.filearea = 'documentconversion'
                    AND orphaneddestfile.filepath = :ofilepath
                )
                LEFT JOIN {" . self::TABLE . "} orphanedconversion ON orphanedconversion.destfileid = orphaneddestfile.id
                WHERE
                    orphanedconversion.id IS NULL
                AND
                    orphanedsourcefile.id = :osourcefileid
                ";
        $records = $DB->get_records_sql($sql, [
            'ccontenthash' => $file->get_contenthash(),
            'osourcefileid' => $file->get_id(),
            'cfilepath' => "/{$format}/",
            'ofilepath' => "/{$format}/",
            'cformat' => $format,
            'oformat' => $format,
        ]);

        foreach ($records as $record) {
            $data = self::extract_record($record, 'conversion');
            $newrecord = new static(0, $data);
            $instances[] = $newrecord;
        }

        return $instances;
    }
438412
public function upload($file, $format = 'json')
	{
		// Is this "file" a URL?
		$url = filter_var($file, FILTER_VALIDATE_URL) !== false;

		$data = array(
			'key' => $this->key,
			'format' => $format
		);

		if ($url) {
			$data['url'] = $file;
		} else {
			$data['fileupload'] = $file;
		}

		if ($this->credentials) {
			$data['a_username'] = $this->credentials['username'];
			$data['a_password'] = $this->credentials['password'];
		} else if($this->cookie) {
			$data['cookie'] = $this->cookie;
		}

		return $this->post('https://post.imageshack.us/upload_api.php', $data);
	}
1209394
public function read($file)
    {
        $file = '/settings/' . $file;

        /**
         * @todo validate that $file is a string
         */

        $result = [];

        if ($this->source_filesystem->has($file . '.yml')) {

            $result = $this->yaml->parse($this->source_filesystem->read($file . '.yml'));
        }

        return $result;
    }
1304800
public function getExpectedMimeTypes($file)
    {
        $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));

        // if the finfo php extension isn't loaded, we can't complete this check.
        if (!class_exists('finfo')) {
            throw new MimeUploadValidatorException('PHP extension finfo is not loaded');
        }

        // Attempt to figure out which mime types are expected/acceptable here.
        $expectedMimes = array();

        // Get the mime types set in framework core
        $knownMimes = Config::inst()->get(HTTP::class, 'MimeTypes');
        if (isset($knownMimes[$extension])) {
            $expectedMimes[] = $knownMimes[$extension];
        }

        // Get the mime types and their variations from mime validator
        $knownMimes = $this->config()->get('MimeTypes');
        if (isset($knownMimes[$extension])) {
            $mimes = (array) $knownMimes[$extension];

            foreach ($mimes as $mime) {
                if (!in_array($mime, $expectedMimes)) {
                    $expectedMimes[] = $mime;
                }
            }
        }

        return $expectedMimes;
    }
138278
protected static function convertFile($file)
    {
        $error = $file->getError();
        $tmpName = '';
        if ($error === UPLOAD_ERR_OK) {
            $tmpName = $file->getStream()->getMetadata('uri');
        }

        return [
            'name' => $file->getClientFilename(),
            'type' => $file->getClientMediaType(),
            'tmp_name' => $tmpName,
            'error' => $error,
            'size' => $file->getSize(),
        ];
    }
507105
private function getRelatedFiles(FileInterface $file)
    {
        // Match foo(_local).*(.dist)
        $base = $file->getFilename();
        $ext = Path::getExtension($base);
        $base = Path::getFilenameWithoutExtension($base);
        $base = Str::replaceLast($base, '_local', '');

        $dir = $file->getParent();
        $related = [];
        foreach ([".$ext", "_local.$ext"] as $tail) {
            $f = $dir->getFile($base . $tail);
            if ($f->getFilename() !== $file->getFilename() && $f->exists()) {
                $related[] = $f;
            }
        }

        return $related;
    }
374756
private static function convertFilesArray($files) {
		
		$result = [];

		foreach($files as $field => $data) {
			
			foreach($data as $key => $val) {
				
				$result[$field] = [];
				
				if(false === is_array($val)) {
					$result[$field] = $data;
				} 
				else {
					
					$res = [];
					static :: filesFlip($res, [], $data);
					$result[$field] += $res;
				}
			}
		}

		return $result;
	}
769150
public static function size($file = false, $format = 'bytes') {

        if ($file && self::isFile($file)) {

            $size = filesize($file);

            switch ($format) {
                case 'bytes':
                    return $size;
                    break;
                case 'kb':
                    return Number::round(($size / 1024), 2);
                    break;
                case 'mb':
                    return Number::round(($size / 1048576), 2);
                    break;
            }
        }

        return false;
    }
1006275
public function sync_reference(stored_file $file) {
        global $CFG;
        if ($file->get_referencelastsync() + DAYSECS > time()) {
            // Synchronise not more often than once a day.
            return false;
        }
        $c = new curl();
        $reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
        $url = $reference->downloadurl;
        if (file_extension_in_typegroup($file->get_filename(), 'web_image')) {
            $path = $this->prepare_file('');
            $result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorysyncimagetimeout));
            $info = $c->get_info();
            if ($result === true && isset($info['http_code']) && $info['http_code'] == 200) {
                $file->set_synchronised_content_from_file($path);
                return true;
            }
        }
        $c->get($url, null, array('timeout' => $CFG->repositorysyncimagetimeout, 'followlocation' => true, 'nobody' => true));
        $info = $c->get_info();
        if (isset($info['http_code']) && $info['http_code'] == 200 &&
                array_key_exists('download_content_length', $info) &&
                $info['download_content_length'] >= 0) {
            $filesize = (int)$info['download_content_length'];
            $file->set_synchronized(null, $filesize);
            return true;
        }
        $file->set_missingsource();
        return true;
    }
826998
public function get($file)
    {
        $result = null;
        $this->hook->attach('help.get.before', $file, $result, $this);

        if (isset($result)) {
            return (array) $result;
        }

        $result = $this->getMeta($file);

        if (empty($result)) {
            return array();
        }

        $hash = gplcart_string_encode(gplcart_path_relative($file));

        $result += array(
            'file' => $file,
            'path' => "admin/help/$hash"
        );

        $this->hook->attach('help.get.after', $file, $result, $this);
        return (array) $result;
    }
798672
public function copy_content_from_storedfile(stored_file $file, $target) {
        $source = $this->get_local_path_from_storedfile($file, true);
        return copy($source, $target);
    }
398469
public function transform($file)
    {
        $thumb = null;

        if ($file->type === 'image') {
            $width  = config('gzero.image.thumb.width');
            $height = config('gzero.image.thumb.height');
            $thumb  = croppaUrl($file->getFullPath(), $width, $height);
        }

        $file = $this->entityToArray(File::class, $file);
        return [
            'id'        => (int) $file['id'],
            'type'      => $file['type'],
            'name'      => $file['name'],
            'extension' => $file['extension'],
            'size'      => (int) $file['size'],
            'mimeType'  => $file['mime_type'],
            'info'      => $file['info'],
            'thumb'     => $thumb,
            'weight'    => $this->setPivotNullableValue($file, 'weight'),
            'isActive'  => (bool) $file['is_active'],
            'createdBy' => (int) $file['created_by'],
            'createdAt' => $file['created_at'],
            'updatedAt' => $file['updated_at']
        ];
    }
122201
public function can_convert_storedfile_to(stored_file $file, $to) {
        if ($file->is_directory()) {
            // Directories cannot be converted.
            return false;
        }

        if (!$file->get_filesize()) {
            // Empty files cannot be converted.
            return false;
        }

        $from = pathinfo($file->get_filename(), PATHINFO_EXTENSION);
        if (!$from) {
            // No file extension could be found. Unable to determine converter.
            return false;
        }

        return $this->can_convert_format_to($from, $to);
    }
905275
public function loadFile(string $file) : array
    {
        if (!file_exists($file)) {
            throw new LoaderException("Requested YAML file '{$file}' doesn't exist");
        }

        if (!$this->forceSymfony && $this->hasExtension) {
            $data = yaml_parse_file($file);
        } else {
            $data = Yaml::parse(file_get_contents($file));
        }

        if (!is_array($data)) {
            throw new LoaderException("Requested YAML file '{$file}' does not parse to an array");
        }

        return $data;
    }
674980
private static function getLinks(string $file): array
    {
        $links    = [];
        $contents = (string)file_get_contents($file);
        if (false !== preg_match_all(
            '/\[(.+?)\].*?\((.+?)\)/',
            $contents,
            $matches,
            PREG_SET_ORDER
        )) {
            $links = array_merge($links, $matches);
        }

        return $links;
    }
634581
static public function createFromFile( $format, $file )
    {
        $className = ezcDbSchemaHandlerManager::getReaderByFormat( $format );
        $reader = new $className();
        self::checkSchemaReader( $reader, self::FILE );
        return $reader->loadFromFile( $file );
    }
643261
protected function loadLanguageFile($file, $format)
    {
        if (is_file($file)) {
            $this->load($file, $format);

            $loaded = $this->config['language.loaded'];

            $loaded[] = $file;

            $this->config->set('language.loaded', $loaded);
        }

        return $this;
    }