Browse Source

add urlencode and decode to Utility lib

euromark 13 years ago
parent
commit
a2d44fe67a

+ 1 - 13
Lib/Bootstrap/MyBootstrap.php

@@ -584,19 +584,7 @@ function shutDownFunction() {
 	CakeLog::write($type, $message);
 	CakeLog::write($type, $message);
 }
 }
 
 
-/*** < PHP5.3 ***/
-
-/**
- * until PHP5.3 is the PHP version in use
- * //BUGGY
- * 2010-06-21 ms
- */
-if (!function_exists('lcfirst')) {
-	function lcfirst($str) {
-		return (string) (mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1));
-	}
-}
-
+//TODO: move into separate lib!
 class DebugTab {
 class DebugTab {
 	public static $content = array();
 	public static $content = array();
 	public static $groups = array();
 	public static $groups = array();

+ 0 - 1
Lib/Error/MyErrorHandler.php

@@ -106,7 +106,6 @@ class MyErrorHandler extends ErrorHandler {
 			return false;
 			return false;
 		}
 		}
 
 
-		# cake bug? temporary!
 		if (Configure::read('debug')) {
 		if (Configure::read('debug')) {
 			return false;
 			return false;
 		}
 		}

+ 0 - 23
Lib/Error/MyExceptionRenderer.php

@@ -3,27 +3,4 @@ App::uses('ExceptionRenderer', 'Error');
 
 
 class MyExceptionRenderer extends ExceptionRenderer {
 class MyExceptionRenderer extends ExceptionRenderer {
 
 
-	/**
-	 * A safer way to render error messages, replaces all helpers, with basics
-	 * and doesn't call component methods.
-	 *
-	 * @param string $template The template to render
-	 * @return void
-	 */
-	protected function _outputMessageSafe($template) {
-		$this->controller->layoutPath = null;
-		$this->controller->subDir = null;
-		$this->controller->viewPath = 'Errors/';
-		$this->controller->viewClass = 'View';
-		$this->controller->layout = 'error';
-		$this->controller->helpers = array('Form', 'Html', 'Session');
-
-		$this->controller->render($template);
-		$this->controller->response->type('html');
-
-		$x = $this->controller->response->body(); $this->controller->response->body(h($x));
-
-		$this->controller->response->send();
-	}
-
 }
 }

+ 47 - 9
Lib/Utility/Utility.php

@@ -65,7 +65,9 @@ class Utility {
 	/**
 	/**
 	 * remove unnessary stuff + add http:// for external urls
 	 * remove unnessary stuff + add http:// for external urls
 	 * TODO: protocol to lower!
 	 * TODO: protocol to lower!
-	 * @static
+	 *
+	 * @param string $url
+	 * @return string Cleaned Url
 	 * 2009-12-22 ms
 	 * 2009-12-22 ms
 	 */
 	 */
 	public static function cleanUrl($url, $headerRedirect = false) {
 	public static function cleanUrl($url, $headerRedirect = false) {
@@ -99,7 +101,9 @@ class Utility {
 	}
 	}
 
 
 	/**
 	/**
-	 * @static
+	 * Parse headers
+	 *
+	 * @param string $url
 	 * @return mixed array of headers or FALSE on failure
 	 * @return mixed array of headers or FALSE on failure
 	 * 2009-12-26 ms
 	 * 2009-12-26 ms
 	 */
 	 */
@@ -130,10 +134,11 @@ class Utility {
 
 
 	/**
 	/**
 	 * add protocol prefix if necessary (and possible)
 	 * add protocol prefix if necessary (and possible)
-	 * static?
+	 *
+	 * @param string $url
 	 * 2010-06-02 ms
 	 * 2010-06-02 ms
 	 */
 	 */
-	public function autoPrefixUrl($url, $prefix = null) {
+	public static function autoPrefixUrl($url, $prefix = null) {
 		if ($prefix === null) {
 		if ($prefix === null) {
 			$prefix = 'http://';
 			$prefix = 'http://';
 		}
 		}
@@ -147,7 +152,33 @@ class Utility {
 	}
 	}
 
 
 	/**
 	/**
+	 * encode strings with base64_encode and also
+	 * replace chars base64 uses that would mess up the url
+	 *
+	 * @param string $string Unsafe string
+	 * @return string Encoded string
+	 * 2012-10-23 ms
+	 */
+	public static function urlEncode($string) {
+		return str_replace(array('/', '='), array('-', '_'), base64_encode($string));
+	}
+
+	/**
+	 * decode strings with base64_encode and also
+	 * replace back chars base64 uses that would mess up the url
+	 *
+	 * @param string $string Safe string
+	 * @return string Decoded string
+	 * 2012-10-23 ms
+	 */
+	public static function urlDecode($string) {
+		return base64_decode(str_replace(array('-', '_'), array('/', '='), $string));
+	}
+
+	/**
 	 * returns true only if all values are true
 	 * returns true only if all values are true
+	 *
+	 * @param array $array
 	 * @return bool $result
 	 * @return bool $result
 	 * maybe move to bootstrap?
 	 * maybe move to bootstrap?
 	 * 2011-11-02 ms
 	 * 2011-11-02 ms
@@ -166,6 +197,8 @@ class Utility {
 
 
 	/**
 	/**
 	 * returns true if at least one value is true
 	 * returns true if at least one value is true
+	 *
+	 * @param array $array
 	 * @return bool $result
 	 * @return bool $result
 	 * maybe move to bootstrap?
 	 * maybe move to bootstrap?
 	 * 2011-11-02 ms
 	 * 2011-11-02 ms
@@ -204,8 +237,10 @@ class Utility {
 
 
 	/**
 	/**
 	 * convinience function for automatic casting in form methods etc
 	 * convinience function for automatic casting in form methods etc
+	 *
+	 * @param mixed $value
+	 * @param string $type
 	 * @return safe value for DB query, or NULL if type was not a valid one
 	 * @return safe value for DB query, or NULL if type was not a valid one
-	 * @static
 	 * maybe move to bootstrap?
 	 * maybe move to bootstrap?
 	 * 2008-12-12 ms
 	 * 2008-12-12 ms
 	 */
 	 */
@@ -305,6 +340,8 @@ class Utility {
 	}
 	}
 
 
 	/**
 	/**
+	 * Similar to array_shift but on the keys of the array
+	 *
 	 * @param array $keyValuePairs
 	 * @param array $keyValuePairs
 	 * @return string $key
 	 * @return string $key
 	 * like array_shift() only for keys and not values
 	 * like array_shift() only for keys and not values
@@ -323,7 +360,8 @@ class Utility {
 	/**
 	/**
 	 * returns microtime as float value
 	 * returns microtime as float value
 	 * (to be subtracted right away)
 	 * (to be subtracted right away)
-	 * @static
+	 *
+	 * @return float
 	 * 2009-07-07 ms
 	 * 2009-07-07 ms
 	 */
 	 */
 	public static function microtime($precision = 8) {
 	public static function microtime($precision = 8) {
@@ -339,7 +377,7 @@ class Utility {
 	}
 	}
 
 
 	/**
 	/**
-	 * @static
+	 * @return float
 	 * 2009-07-07 ms
 	 * 2009-07-07 ms
 	 */
 	 */
 	public static function returnElapsedTime($precision = 8, $restartClock = false) {
 	public static function returnElapsedTime($precision = 8, $restartClock = false) {
@@ -353,7 +391,8 @@ class Utility {
 	/**
 	/**
 	 * returns microtime as float value
 	 * returns microtime as float value
 	 * (to be subtracted right away)
 	 * (to be subtracted right away)
-	 * @static
+	 *
+	 * @return float
 	 * 2009-07-07 ms
 	 * 2009-07-07 ms
 	 */
 	 */
 	public static function calcElapsedTime($start, $end, $precision = 8) {
 	public static function calcElapsedTime($start, $end, $precision = 8) {
@@ -362,4 +401,3 @@ class Utility {
 	}
 	}
 
 
 }
 }
-