Gather Details

@param String $file
@return void
@author Dan Cox
354466
public function load($file)
	{
		$details = pathinfo($file);
		$this->filename = $details['basename'];
		$this->extension = $details['extension'];
		$this->directory = $details['dirname'];
	}
122598
protected function setFileInformations($file)
    {
        $this->fileInfo = array(); // reset previously information to have a cleaned object
        if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
            $this->file = $file;
        } elseif ($file instanceof \TYPO3\CMS\Core\Resource\FileReference) {
            $this->file = $file = $file->getOriginalFile();
        }

        if (is_string($file) && !empty($file)) {
            $this->fileInfo = GeneralUtility::split_fileref($file);
            $this->fileInfo['mtime'] = filemtime($file);
            $this->fileInfo['atime'] = fileatime($file);
            $this->fileInfo['owner'] = fileowner($file);
            $this->fileInfo['group'] = filegroup($file);
            $this->fileInfo['size'] = filesize($file);
            $this->fileInfo['type'] = filetype($file);
            $this->fileInfo['perms'] = fileperms($file);
            $this->fileInfo['is_dir'] = is_dir($file);
            $this->fileInfo['is_file'] = is_file($file);
            $this->fileInfo['is_link'] = is_link($file);
            $this->fileInfo['is_readable'] = is_readable($file);
            $this->fileInfo['is_uploaded'] = is_uploaded_file($file);
            $this->fileInfo['is_writeable'] = is_writeable($file);
        }

        if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
            $pathInfo = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($file->getName());
            $this->fileInfo = array(
                'file' => $file->getName(),
                'filebody' => $file->getNameWithoutExtension(),
                'fileext' => $file->getExtension(),
                'realFileext' => $pathInfo['extension'],
                'atime' => $file->getCreationTime(),
                'mtime' => $file->getModificationTime(),
                'owner' => '',
                'group' => '',
                'size' => $file->getSize(),
                'type' => 'file',
                'perms' => '',
                'is_dir' => false,
                'is_file' => ($file->getStorage()->getDriverType() === 'Local' ?
                    is_file($file->getForLocalProcessing(false)) : true),
                'is_link' => ($file->getStorage()->getDriverType() === 'Local' ?
                    is_link($file->getForLocalProcessing(false)) : false),
                'is_readable' => true,
                'is_uploaded' => false,
                'is_writeable' => false,
            );
        }
        return $this->fileInfo !== array();
    }
1070145
public  function loadConfig( $file ){
		if( file_exists( $file ) ){
			$config = include $file;
			$driver = $config['driver'];
			if( $driver == 'file'){
				$session = new \Wudimei\Session\File($config);
			}
			$this->session = $session;
		}
		else{
			throw new \Exception('sesstion config file "' . $file . '" does not exists');
		}
		

	}
206107
public function load($file)
    {
        $this->temporaryFileManager->enterModule('Templating');
        $this->temporaryFileManager->load($file . '.php');
        $this->temporaryFileManager->exitModule();
    }
957777
public static function process($file = NULL){

        $exists = isset( self::$data[ self::$level ] );

        if( $exists ){
            $variables = self::$data[ self::$level ];

            foreach( $variables as $key => $value ){
                global $$key;
                $$key = $value;
            }
        }

        if( $file ){
            require $file;
        }

    }
1103924
public function fromFile($file)
    {
        if (!array_key_exists($file, $this->files)) {
            $xmlData = $this->getXmlData($file);

            $schemaId = SchemaId::fromString($xmlData['schema']['id']);
            $filePath = substr($file, 0, -strlen(basename($file)) - 1);

            // check "latest.xml"
            $latestPath = sprintf('%s/latest.xml', $filePath);
            if (!file_exists($latestPath)) {
                file_put_contents($latestPath, file_get_contents($file));

                $this->files[$latestPath] = $xmlData['schema'];
            }

            // override schema with "latest"
            if (basename($file) != 'latest.xml' && file_exists($latestPath)) {
                $lastestXmlData = $this->getXmlData($latestPath);

                $latestSchemaId = SchemaId::fromString($lastestXmlData['schema']['id']);

                if ($schemaId->getVersion()->toString() === $latestSchemaId->getVersion()->toString()
                    && $xmlData != $lastestXmlData
                ) {
                    file_put_contents($file, file_get_contents($latestPath));

                    $xmlData = $lastestXmlData;
                }
            }

            // update "latest" with schema
            if (isset($this->files[$latestPath])) {
                $version = SchemaId::fromString($this->files[$latestPath]['id'])->getVersion()->toString();

                if (version_compare($schemaId->getVersion()->toString(), $version) === 1) {
                    file_put_contents($latestPath, file_get_contents($file));

                    $this->files[$latestPath] = $xmlData['schema'];
                }
            }

            // override or create "latest" version file
            $versionPath = sprintf('%s/%s.xml', $filePath, $schemaId->getVersion()->toString());
            if (basename($file) == 'latest.xml') {
                file_put_contents($versionPath, file_get_contents($file));
            }

            $this->files[$file] = $xmlData['schema'];
        }

        return $this->parse($this->files[$file]);
    }
1100985
public function addFile($file)
    {
        $this->box->addFile($file, $this->pharComposer->getPathLocalToBase($file));
    }
612788
public function analyze_file(string $file): array
  {
    $res = [];
    $ext = bbn\str::file_ext($file);
    if ( \in_array($ext, self::$extensions, true) && is_file($file) ){
      switch ( $ext ){
        case 'html':
          $res = $this->analyze_php($file);
          break;
        case 'php':
          $res = $this->analyze_php($file);
          break;
        case 'js':
          $res = $this->analyze_js($file);
          break;
        /*case 'json':
          $res = $this->analyze_json($file);
          break;*/
      }
    }
    return $res;
  }
402189
public function addResource(string $file): void
    {
        $contents = file_get_contents($file);
        
        if ($contents === false) {
            throw new \RuntimeException("Error reading file at $file.");
        }
        
        $this->processData(json_decode($contents, true));
    }
336260
public function setUploadedFile($file)
    {
        // If set, this just clears the image.
        if ($file == MEDIASORT_NULL) {
            $this->clear();

            return;
        }

        // Determine if this attachment should be processed
        // now or later using queued job.
        if ($this->isQueueable()) {
            $this->queueUploadedFile($file);
        }

        // Standard upload, nothing fancy here.
        else {
            $this->addUploadedFile($file);
        }
    }
212062
public function fileGetContents($file)
    {
        $client = new Client();
        $response = $client->createRequest()
            ->setMethod('get')
            ->setUrl($file)
            ->addHeaders(['user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'])
            ->setOptions([
                'timeout' => $this->readFileTimeout, // set timeout to 1 seconds for the case server is not responding
            ])
            ->send();

        if ($response->isOk) {
            return $response->content;
        }

        throw new \Exception("File get contents '{$file}' error: ".$response->content);
    }
733030
public function setCache($file)
	{
		if ( ! empty($file)) {
			$this->cache = new AccessTokenCache($file);

			$this->setAccessToken($this->cache->get());
		}
	}
1136609
public function renderFile(File &$file)
    {
        if ($file->isRendered()) {
            return;
        }
        $fileRenderer = $this->get($file->getExt());
        $file->setContent($fileRenderer->render($file));
        $file->setExt($fileRenderer->getDestinationExtension($file->getExt()));
        $file->setRendered(true);
        $fileRenderer->mutateFile($file);
    }
858738
public function delete($file = null)
	{
		$file = $file ?: $this->file;
		if ($this->fs->exists($file))
			$this->fs->delete($file);
		if ($this->f3->get('CACHE')) {
			$cache = \Cache::instance();
			if($cache->exists($cacheHash = $this->getCacheHash($file)))
				$cache->clear($cacheHash);
		}
		$this->metaHandle->delete($file);
	}
210844
function parse( $file ) {

		// ------------------------------------------------------------------------------------------------------------
		// Setup & sanity check
		// ------------------------------------------------------------------------------------------------------------

		$authors = [];
		$posts = [];
		$categories = [];
		$tags = [];
		$terms = [];

		libxml_use_internal_errors( true );

		$old_value = libxml_disable_entity_loader( true );
		$dom = new \DOMDocument;
		$dom->recover = true; // Try to parse non-well formed documents
		$success = $dom->loadXML( \Pressbooks\Utility\get_contents( $file ) );
		foreach ( $dom->childNodes as $child ) {
			if ( XML_DOCUMENT_TYPE_NODE === $child->nodeType ) {
				// Invalid XML: Detected use of disallowed DOCTYPE
				$success = false;
				break;
			}
		}
		libxml_disable_entity_loader( $old_value );

		// @codingStandardsIgnoreStart
		if ( ! $success || isset( $dom->doctype ) ) {
			throw new \Exception( print_r( libxml_get_errors(), true ) );
		}

		$xml = @simplexml_import_dom( $dom );
		unset( $dom );

		// halt if loading produces an error
		if ( ! $xml ) {
			throw new \Exception( print_r( libxml_get_errors(), true ) );
		}
		// @codingStandardsIgnoreEnd

		$wxr_version = $xml->xpath( '/rss/channel/wp:wxr_version' );
		if ( ! $wxr_version ) {
			throw new \Exception( __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'pressbooks' ) );
		}

		$wxr_version = (string) trim( $wxr_version[0] );
		// confirm that we are dealing with the correct file format
		if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) {
			throw new \Exception( __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'pressbooks' ) );
		}

		// ------------------------------------------------------------------------------------------------------------
		// Ladies and gentlemen, start your parsing
		// ------------------------------------------------------------------------------------------------------------

		$base_url = $xml->xpath( '/rss/channel/wp:base_site_url' );
		$base_url = (string) trim( $base_url[0] );

		$namespaces = $xml->getDocNamespaces();
		if ( ! isset( $namespaces['wp'] ) ) {
			$namespaces['wp'] = 'http://wordpress.org/export/1.1/';
		}
		if ( ! isset( $namespaces['excerpt'] ) ) {
			$namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
		}

		// grab authors
		foreach ( $xml->xpath( '/rss/channel/wp:author' ) as $author_arr ) {
			$a = $author_arr->children( $namespaces['wp'] );
			$login = (string) $a->author_login;
			$authors[ $login ] = [
				'author_id' => (int) $a->author_id,
				'author_login' => $login,
				'author_email' => (string) $a->author_email,
				'author_display_name' => (string) $a->author_display_name,
				'author_first_name' => (string) $a->author_first_name,
				'author_last_name' => (string) $a->author_last_name,
			];
		}

		// grab cats, tags and terms
		foreach ( $xml->xpath( '/rss/channel/wp:category' ) as $term_arr ) {
			$t = $term_arr->children( $namespaces['wp'] );
			$category = [
				'term_id' => (int) $t->term_id,
				'category_nicename' => (string) $t->category_nicename,
				'category_parent' => (string) $t->category_parent,
				'cat_name' => (string) $t->cat_name,
				'category_description' => (string) $t->category_description,
			];

			foreach ( $t->termmeta as $meta ) {
				$category['termmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			$categories[] = $category;
		}

		foreach ( $xml->xpath( '/rss/channel/wp:tag' ) as $term_arr ) {
			$t = $term_arr->children( $namespaces['wp'] );
			$tag = [
				'term_id' => (int) $t->term_id,
				'tag_slug' => (string) $t->tag_slug,
				'tag_name' => (string) $t->tag_name,
				'tag_description' => (string) $t->tag_description,
			];

			foreach ( $t->termmeta as $meta ) {
				$tag['termmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			$tags[] = $tag;
		}

		foreach ( $xml->xpath( '/rss/channel/wp:term' ) as $term_arr ) {
			$t = $term_arr->children( $namespaces['wp'] );
			$term = [
				'term_id' => (int) $t->term_id,
				'term_taxonomy' => (string) $t->term_taxonomy,
				'slug' => (string) $t->term_slug,
				'term_parent' => (string) $t->term_parent,
				'term_name' => (string) $t->term_name,
				'term_description' => (string) $t->term_description,
			];

			foreach ( $t->termmeta as $meta ) {
				$term['termmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			$terms[] = $term;
		}

		// grab posts
		foreach ( $xml->channel->item as $item ) {
			$post = [
				'post_title' => (string) $item->title,
				'guid' => (string) $item->guid,
			];

			$dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
			$post['post_author'] = (string) $dc->creator;

			$content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
			$excerpt = $item->children( $namespaces['excerpt'] );
			$post['post_content'] = (string) $content->encoded;
			$post['post_excerpt'] = (string) $excerpt->encoded;

			$wp = $item->children( $namespaces['wp'] );
			$post['post_id'] = (int) $wp->post_id;
			$post['post_date'] = (string) $wp->post_date;
			$post['post_date_gmt'] = (string) $wp->post_date_gmt;
			$post['comment_status'] = (string) $wp->comment_status;
			$post['ping_status'] = (string) $wp->ping_status;
			$post['post_name'] = (string) $wp->post_name;
			$post['status'] = (string) $wp->status;
			$post['post_parent'] = (int) $wp->post_parent;
			$post['menu_order'] = (int) $wp->menu_order;
			$post['post_type'] = (string) $wp->post_type;
			$post['post_password'] = (string) $wp->post_password;
			$post['is_sticky'] = (int) $wp->is_sticky;

			if ( isset( $wp->attachment_url ) ) {
				$post['attachment_url'] = (string) $wp->attachment_url;
			}

			foreach ( $item->category as $c ) {
				$att = $c->attributes();
				if ( isset( $att['nicename'] ) ) {
					$post['terms'][] = [
						'name' => (string) $c,
						'slug' => (string) $att['nicename'],
						'domain' => (string) $att['domain'],
					];
				}
			}

			foreach ( $wp->postmeta as $meta ) {
				$post['postmeta'][] = [
					'key' => (string) $meta->meta_key,
					'value' => (string) $meta->meta_value,
				];
			}

			foreach ( $wp->comment as $comment ) {
				$meta = [];
				if ( isset( $comment->commentmeta ) ) {
					foreach ( $comment->commentmeta as $m ) {
						$meta[] = [
							'key' => (string) $m->meta_key,
							'value' => (string) $m->meta_value,
						];
					}
				}

				$post['comments'][] = [
					'comment_id' => (int) $comment->comment_id,
					'comment_author' => (string) $comment->comment_author,
					'comment_author_email' => (string) $comment->comment_author_email,
					'comment_author_IP' => (string) $comment->comment_author_IP,
					'comment_author_url' => (string) $comment->comment_author_url,
					'comment_date' => (string) $comment->comment_date,
					'comment_date_gmt' => (string) $comment->comment_date_gmt,
					'comment_content' => (string) $comment->comment_content,
					'comment_approved' => (string) $comment->comment_approved,
					'comment_type' => (string) $comment->comment_type,
					'comment_parent' => (string) $comment->comment_parent,
					'comment_user_id' => (int) $comment->comment_user_id,
					'commentmeta' => $meta,
				];
			}

			$posts[] = $post;
		}

		return [
			'authors' => $authors,
			'posts' => $posts,
			'categories' => $categories,
			'tags' => $tags,
			'terms' => $terms,
			'base_url' => $base_url,
			'version' => $wxr_version,
		];
	}
206791
protected function setFileSize($file)
    {
        $this->fileSize = ! is_null($this->elfinderFilePath) ? $this->getFileSize() : (is_string($file) ? $this->size($file) : $file->getClientSize());
    }
480481
public function loadDatabase(string $file): void
	{
		$this->connection->transactional(function (Connection $db) use ($file) {
			$db->query('SET foreign_key_checks = 0');
			FileImporter::executeFile($db, $file);
			$db->query('SET foreign_key_checks = 1');
		});
	}