예제 #1
0
	/**
	 * Set the filename of this file manually.
	 * Useful for operating on a file after construction.
	 *
	 * @param $filename string
	 */
	public function setFilename($filename) {

		// If this file already has a filename, ensure that it's deleted from cache!
		if($this->_filename){
			Filestore\Factory::RemoveFromCache($this);
		}

		//$cwd = ftp_pwd($this->_ftp->conn);
		$cwd = $this->_ftp->root;

		if(strpos($filename, ROOT_PDIR) === 0){
			// If the file starts with the PDIR... trim that off!
			$filename = substr($filename, strlen(ROOT_PDIR));
			$prefix = ROOT_PDIR;
		}
		elseif(strpos($filename, $cwd) === 0){
			// If the file already starts with the CWD... trim that off!
			$filename = substr($filename, strlen($cwd));
			$prefix = $cwd;
		}
		else{
			$prefix = $cwd;
		}

		// Make sure that prefix ends with a '/'.
		if(substr($prefix, -1) != '/') $prefix .= '/';

		// Resolve if this is an asset, public, etc.
		// This is to speed up the other functions so they don't have to perform this operation.
		if(strpos($prefix . $filename, Filestore\get_asset_path()) === 0){
			$this->_type = 'asset';
		}
		elseif(strpos($prefix . $filename, Filestore\get_public_path()) === 0){
			$this->_type = 'public';
		}
		elseif(strpos($prefix . $filename, Filestore\get_private_path()) === 0){
			$this->_type = 'private';
		}

		$this->_filename = $filename;
		$this->_prefix = $prefix;
		// Clear the local cache too
		$this->_tmplocal = null;
	}
예제 #2
0
	/**
	 * Get an ascii hash of the filename.
	 * useful for transposing this file to another page call.
	 *
	 * @return string The encoded string
	 */
	public function getFilenameHash() {
		if ($this->_type == 'asset'){
			$base = 'assets/';
			$filename = substr($this->_filename, strlen(Filestore\get_asset_path()));
			// If the filename starts with the current theme, (which it very well may),
			// trim that off too.
			// this script is meant to be a generic resource handle that gets resolved by the receiving script.
			if(strpos($filename, \ConfigHandler::Get('/theme/selected') . '/') === 0){
				$filename = substr($filename, strlen(\ConfigHandler::Get('/theme/selected')) + 1);
			}
			elseif(strpos($filename, 'default/') === 0){
				$filename = substr($filename, 8);
			}
			// And now I can add the base onto it.
			$filename = $base . $filename;
		}
		elseif ($this->_type == 'public'){
			$filename = 'public/' . substr($this->_filename, strlen(Filestore\get_public_path() ));
		}
		elseif ($this->_type == 'private'){
			$filename = 'private/' . substr($this->_filename, strlen(Filestore\get_private_path() ));
		}
		elseif ($this->_type == 'tmp'){
			$filename = 'tmp/' . substr($this->_filename, strlen(Filestore\get_tmp_path() ));
		}
		else{
			$filename = $this->_filename;
		}

		return 'base64:' . base64_encode($filename);
	}