Пример #1
0
	/**
	 * Write the raw contents of this file
	 *
	 * Essentially file_put_contents()
	 *
	 * @param mixed $data
	 *
	 * @return boolean
	 */
	public function putContents($data) {
		// Resolve it from its default.
		// This is provided from a config define, (probably).
		$mode = (defined('DEFAULT_FILE_PERMS') ? DEFAULT_FILE_PERMS : 0644);

		// FTP requires a filename, not data...
		$tmpfile = Filestore\get_tmp_path() . 'ftpupload-' . \Core::RandomHex(4);
		file_put_contents($tmpfile, $data);

		if (!ftp_put($this->_ftp->getConn(), $this->_filename, $tmpfile, FTP_BINARY)) {
			// Well, delete the temp file anyway...
			unlink($tmpfile);
			return false;
		}

		if (!ftp_chmod($this->_ftp->getConn(), $mode, $this->_filename)) return false;

		// woot... but cleanup the trash first.
		unlink($tmpfile);
		$this->_tmplocal = null;
		return true;
	}
Пример #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);
	}
Пример #3
0
	/**
	 * Set the path for this directory.
	 *
	 * @param $path
	 *
	 * @return void
	 */
	public function setPath($path){
		if(substr($path, -1) != '/'){
			// Directories should always end in a trailing slash
			$path = $path . '/';
		}

		if ($path{0} != '/'){
			// Needs to be fully resolved
			$path = ROOT_PDIR . $path;
		}

		// Do some cleaning on the filename, ie: // should be just /.
		$path = preg_replace(':/+:', '/', $path);

		$this->_path = $path;

		// 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($this->_path, Filestore\get_asset_path()) === 0){
			$this->_type = 'asset';
		}
		elseif(strpos($this->_path, Filestore\get_public_path()) === 0){
			$this->_type = 'public';
		}
		elseif(strpos($this->_path, Filestore\get_tmp_path()) === 0){
			$this->_type = 'tmp';
		}
	}
Пример #4
0
	/**
	 * Set the path for this directory.
	 *
	 * @param $path
	 *
	 * @return void
	 */
	public function setPath($path){
		if(substr($path, -1) != '/'){
			// Directories should always end in a trailing slash
			$path = $path . '/';
		}

		$cwd = ftp_pwd($this->_ftp);

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

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

		// Do some cleaning on the filename, ie: // should be just /.
		$path = preg_replace(':/+:', '/', $path);

		$this->_prefix = $prefix;
		$this->_path = $path;

		// 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($this->_path, Filestore\get_asset_path()) === 0){
			$this->_type = 'asset';
		}
		elseif(strpos($this->_path, Filestore\get_public_path()) === 0){
			$this->_type = 'public';
		}
		elseif(strpos($this->_path, Filestore\get_tmp_path()) === 0){
			$this->_type = 'tmp';
		}
	}