예제 #1
0
	/**
	 * Add a file as an attachment!
	 *
	 * @param \Core\Filestore\File $file
	 *
	 * @throws phpmailerException
	 */
	public function addAttachment(\Core\Filestore\File $file){
		$this->getMailer()->AddAttachment(
			$file->getFilename(), // Full Path
			$file->getBasename(), // Base Filename (to be exposed in client)
			'base64', // Yup, just do this
			$file->getMimetype() // Mimetype, try to use correct hinting for client
		);
	}
예제 #2
0
/**
 * Get an array of the various resize components from a given dimension set.
 * These include: width, height, mode, key.
 *
 * @param string|int $dimensions
 * @param File $file
 *
 * @return array
 */
function get_resized_key_components($dimensions, $file){
	// The legacy support for simply a number.
	if (is_numeric($dimensions)) {
		$width  = $dimensions;
		$height = $dimensions;
		$mode = '';
	}
	elseif ($dimensions === null) {
		$width  = 300;
		$height = 300;
		$mode = '';
	}
	elseif($dimensions === false){
		$width = false;
		$height = false;
		$mode = '';
	}
	else {
		// Allow some special modifiers.
		if(strpos($dimensions, '^') !== false){
			// Fit the smallest dimension instead of the largest, (useful for overflow tricks)
			$mode = '^';
			$dimensions = str_replace('^', '', $dimensions);
		}
		elseif(strpos($dimensions, '!') !== false){
			// Absolutely resize, regardless of aspect ratio
			$mode = '!';
			$dimensions = str_replace('!', '', $dimensions);
		}
		elseif(strpos($dimensions, '>') !== false){
			// Only increase images.
			$mode = '>';
			$dimensions = str_replace('>', '', $dimensions);
		}
		elseif(strpos($dimensions, '<') !== false){
			// Only decrease images.
			$mode = '<';
			$dimensions = str_replace('<', '', $dimensions);
		}
		else{
			// Default mode
			$mode = '';
		}
		// New method. Split on the "x" and that should give me the width/height.
		$vals   = explode('x', strtolower($dimensions));
		$width  = (int)$vals[0];
		$height = (int)$vals[1];
	}

	$ext = $file->getExtension();
	// Ensure that an extension is used if none present, (may happen with temporary files).
	if(!$ext){
		$ext = mimetype_to_extension($file->getMimetype());
	}

	// The basename is for SEO purposes, that way even resized images still contain the filename.
	// The hash is just to ensure that no two files conflict, ie: /public/a/file1.png and /public/b/file1.png
	//  might conflict without this hash.
	// Finally, the width and height dimensions are there just because as well; it gives more of a human
	//  touch to the file. :p
	// Also, keep the original file extension, this way PNGs remain PNGs, GIFs remain GIFs, JPEGs remain JPEGs.
	// This is critical particularly when it comes to animated GIFs.
	$key = str_replace(' ', '-', $file->getBasename(true)) . '-' . $file->getHash() . '-' . $width . 'x' . $height . $mode . '.' . $ext;

	// The directory can be used with the new File backend to create this file in a correctly nested subdirectory.
	$dir = dirname($file->getFilename(false)) . '/';

	if(substr($dir, 0, 7) == 'public/'){
		// Replace the necessary prefix with a more useful one.
		// Anything within public/ needs to be remapped to public/tmp
		$dir = 'public/tmp/' . substr($dir, 7);
	}
	else{
		// Everything else gets prepended to public/tmp/
		// so if the original file is in themes/blah/imgs/blah.jpg,
		// it will be copied to public/tmp/blah.jpg
		$dir = 'public/tmp/';
	}

	return array(
		'width'  => $width,
		'height' => $height,
		'mode'   => $mode,
		'key'    => $key,
		'ext'    => $ext,
		'dir'    => $dir,
	);
}