예제 #1
0
	/**
	 * Save this meta file back up to the FTP server.
	 *
	 * @throws \Exception
	 */
	public function saveMetas(){
		if($this->_contents === null){
			// Contents never loaded, nothing to save.
			return;
		}

		if(!$this->_changed){
			// File wasn't changed, nothing to save.
			return;
		}

		$remotefile = $this->_dir . '.ftpmetas';

		// Make sure the local directory exists and is writable first!
		// This will effectively touch the file to ensure it's writable and everything.
		$this->_local->putContents('');

		$fh = fopen($this->_local->getFilename(), 'w');
		if(!$fh){
			throw new \Exception('Unable to open ' . $this->_local->getFilename() . ' for writing.');
		}

		// Write the current header.
		fputcsv($fh, ['filename', 'hash', 'modified', 'size']);

		// And each line.
		foreach($this->_contents as $c){
			fputcsv($fh, array_values($c));
		}
		fclose($fh);

		// And publish to the FTP server.
		ftp_put($this->_ftp->getConn(), $remotefile, $this->_local->getFilename(), FTP_BINARY);
		$this->_changed = false;
	}
예제 #2
0
	/**
	 * Static function to act as Factory for the underlying Filestore system.
	 * This will parse the incoming URI and return the appropriate type based on Core settings and filetype.
	 *
	 * @param $uri
	 *
	 * @return File
	 */
	public static function File($uri) {

		// GOGO caching ;)
		if(isset(self::$_ResolveCache[$uri])){
			$resolved = self::$_ResolveCache[$uri]->getFilename();
			if(isset(self::$_Files[$resolved])){
				return self::$_Files[$resolved];
			}
		}

		// self::$_Files[$originaluri]

		//var_dump($uri);

		// base64 comes first.  If the filename is encoded in that, decode it first.
		if (strpos($uri, 'base64:') === 0){
			$uri = base64_decode(substr($uri, 7));
		}

		// Allow FTP files to be requested here!
		// This needs to be before the :// check, because technically FTP can be a remote file,
		// but it has extra functionality, (namely being able to write or perform other operations through FTP)
		if(strpos($uri, 'ftp://') === 0){
			// Don't cache remote files.
			return new Backends\FileFTP($uri);
		}


		if(strpos($uri, ROOT_PDIR) === 0){
			// No change needed ;)
		}
		elseif(strpos($uri, ROOT_URL_NOSSL) === 0){
			// If this is a local file, just the URL version.... allow that remap too!
			$uri = ROOT_PDIR . substr($uri, strlen(ROOT_URL_NOSSL));
		}
		elseif(strpos($uri, ROOT_URL_SSL) === 0){
			// If this is a local file, just the URL version.... allow that remap too!
			$uri = ROOT_PDIR . substr($uri, strlen(ROOT_URL_SSL));
		}

		// Allow remote files to be requested here too!
		if(strpos($uri, '://') !== false){
			// Don't cache remote files.
			return new Backends\FileRemote($uri);
		}




		if(
			strpos($uri, 'asset/') === 0 ||
			strpos($uri, 'assets/') === 0 ||
			strpos($uri, get_asset_path()) === 0
		){
			// Is this an asset request?
			$file = resolve_asset_file($uri);
		}
		elseif(
			strpos($uri, 'public/') === 0 ||
			strpos($uri, get_public_path()) === 0
		){
			// Is this a public request?
			$file = resolve_public_file($uri);
		}
		elseif(
			strpos($uri, 'private/') === 0 ||
			strpos($uri, get_private_path()) === 0
		){
			// Is this a private request?
			$file = resolve_private_file($uri);
		}
		elseif(
			strpos($uri, 'tmp/') === 0
		){
			// Is this a tmp request?
			$file = new Backends\FileLocal(get_tmp_path() . substr($uri, 4));
		}
		elseif(
			strpos($uri, get_tmp_path()) === 0 ||
			strpos($uri, '/tmp/') === 0
		){
			// tmp fully resolved?
			$file = new Backends\FileLocal($uri);
		}
		elseif(\Core\ftp() && EXEC_MODE == 'WEB'){
			// Umm.... ok
			// Still, try to use the FTP proxy files if it's enabled.
			$file = new Backends\FileFTP($uri);
		}
		else{
			// Screw it... regular file it is!
			$file = new Backends\FileLocal($uri);
		}

		// Cache this for future calls on this page load.
		self::$_Files[$file->getFilename()] = $file;
		return $file;
	}