public static function ellipsizeMiddle($string, $max, $ellipses = '...') {
		$string = trim($string);
		$firstPiece = '';
		$lastPiece = '';

		// don't ellipsize if the string is short enough
		if (strlen($string) <= $max) {
			return $string;
		}
		
		// check if the string is all one giant word
		$hasSpace = strpos($string, ' ');
		
		// the entire string is one word
		if ($hasSpace === false) {
			$firstPiece = substr($string, 0, $max / 2);
			$lastPiece = substr($string, - ($max - strlen($firstPiece)));
		} else {
			
			$lastPiece = substr($string, - ($max / 2));
			$lastPiece = trim($lastPiece);
		
			$lastSpace = strrpos($lastPiece, ' ');
			if ($lastSpace !== false)
				$lastPiece = substr($lastPiece, $lastSpace + 1);
			
			$maxFirst = $max - strlen($lastPiece);
			
			$firstPiece = self::ellipsizeRight($string, $maxFirst, '');
		}
	
		$string = $firstPiece . $ellipses . $lastPiece;
		return $string;
	}