Browse Source

Make flash message support more types and add test cases.

euromark 11 years ago
parent
commit
f982196f40

+ 25 - 32
Controller/Component/CommonComponent.php

@@ -1,4 +1,7 @@
 <?php
+if (!defined('CLASS_USER')) {
+	define('CLASS_USER', 'User');
+}
 
 App::uses('Component', 'Controller');
 App::uses('Sanitize', 'Utility');
@@ -15,7 +18,7 @@ class CommonComponent extends Component {
 
 	public $components = array('Session', 'RequestHandler');
 
-	public $userModel = 'User';
+	public $userModel = CLASS_USER;
 
 	/**
 	 * For automatic startup
@@ -136,55 +139,45 @@ class CommonComponent extends Component {
 	}
 
 	/**
-	 * Updates FlashMessage SessionContent (to enable unlimited messages of one case)
+	 * Adds a flash message.
+	 * Updates "messages" session content (to enable multiple messages of one type).
 	 *
-	 * @param string messagestring
-	 * @param string class ['error', 'warning', 'success', 'info']
+	 * @param string $message Message to output.
+	 * @param string $type Type ('error', 'warning', 'success', 'info' or custom class).
 	 * @return void
 	 */
-	public function flashMessage($messagestring, $class = null) {
-		switch ($class) {
-			case 'error':
-			case 'warning':
-			case 'success':
-				break;
-			default:
-				$class = 'info';
-				break;
+	public function flashMessage($message, $type = null) {
+		if (!$type) {
+			$type = 'info';
 		}
 
 		$old = (array)$this->Session->read('messages');
-		if (isset($old[$class]) && count($old[$class]) > 99) {
-			array_shift($old[$class]);
+		if (isset($old[$type]) && count($old[$type]) > 99) {
+			array_shift($old[$type]);
 		}
-		$old[$class][] = $messagestring;
+		$old[$type][] = $message;
 		$this->Session->write('messages', $old);
 	}
 
 	/**
-	 * FlashMessages that are not saved (only for current view)
-	 * will be merged into the session flash ones prior to output
+	 * Adds a transient flash message.
+	 * These flash messages that are not saved (only available for current view),
+	 * will be merged into the session flash ones prior to output.
 	 *
-	 * @param string messagestring
-	 * @param string class ['error', 'warning', 'success', 'info']
+	 * @param string $message Message to output.
+	 * @param string $type Type ('error', 'warning', 'success', 'info' or custom class).
 	 * @return void
 	 */
-	public static function transientFlashMessage($messagestring, $class = null) {
-		switch ($class) {
-			case 'error':
-			case 'warning':
-			case 'success':
-				break;
-			default:
-				$class = 'info';
-				break;
+	public static function transientFlashMessage($message, $type = null) {
+		if (!$type) {
+			$type = 'info';
 		}
 
 		$old = (array)Configure::read('messages');
-		if (isset($old[$class]) && count($old[$class]) > 99) {
-			array_shift($old[$class]);
+		if (isset($old[$type]) && count($old[$type]) > 99) {
+			array_shift($old[$type]);
 		}
-		$old[$class][] = $messagestring;
+		$old[$type][] = $message;
 		Configure::write('messages', $old);
 	}
 

+ 11 - 3
Lib/WeatherLib.php

@@ -80,7 +80,14 @@ class WeatherLib {
 
 	//.../feed/weather.ashx?q=Neufahrn&format=json&num_of_days=2&key=598dfbdaeb121715111208
 
-	public function _get($url, $options) {
+	/**
+	 * WeatherLib::_get()
+	 *
+	 * @param mixed $url
+	 * @param mixed $options
+	 * @return array|false
+	 */
+	protected function _get($url, $options) {
 		if (isset($options['cache'])) {
 			$cache = $options['cache'];
 			unset($options['cache']);
@@ -103,13 +110,14 @@ class WeatherLib {
 		}
 		switch ($options['format']) {
 			case 'json':
-				$res = json_decode($content);
+				$res = json_decode($content, true);
 				break;
 			case 'xml':
 				$res = Xml::build($content);
 				$res = Xml::toArray($res);
 				break;
 			case 'csv':
+			default:
 				//TODO?
 				$res = array();
 				throw new CakeException('Not implemented yet');
@@ -128,7 +136,7 @@ class WeatherLib {
 	/**
 	 * @return string Url
 	 */
-	public function _url($url, $options = array()) {
+	protected function _url($url, $options = array()) {
 		$params = array();
 		foreach ($options as $key => $option) {
 			$params[] = $key . '=' . $option;

+ 2 - 2
Model/MyModel.php

@@ -548,7 +548,7 @@ class MyModel extends Model {
 				$results = Cache::read($key, 'sql');
 			}
 
-			if ($results === null) {
+			if (!isset($results)) {
 				$results = parent::find($type, $query);
 				Cache::write($key, $results, 'sql');
 			}
@@ -1474,7 +1474,7 @@ class MyModel extends Model {
 		if ($fields === '*') {
 			$fields = $this->alias . '.*';
 		} elseif (!empty($fields)) {
-			foreach ($fields as $row => $field) {
+			foreach ((array)$fields as $row => $field) {
 				if (strpos($field, '.') !== false) {
 					continue;
 				}

+ 47 - 1
Test/Case/View/Helper/CommonHelperTest.php

@@ -21,6 +21,52 @@ class CommonHelperTest extends MyCakeTestCase {
 	}
 
 	/**
+	 * CommonHelperTest::testFlash()
+	 *
+	 * @return void
+	 */
+	public function testFlash() {
+		$this->Common->addFlashMessage(h('Foo & bar'), 'success');
+
+		$result = $this->Common->flash();
+		$expected = '<div class="flashMessages"><div class="message success">Foo &amp; bar</div></div>';
+		$this->assertEquals($expected, $result);
+
+		$this->Common->addFlashMessage('I am an error', 'error');
+		$this->Common->addFlashMessage('I am a warning', 'warning');
+		$this->Common->addFlashMessage('I am some info', 'info');
+		$this->Common->addFlashMessage('I am also some info');
+		$this->Common->addFlashMessage('I am sth custom', 'custom');
+
+		$result = $this->Common->flash();
+		$this->assertTextContains('message error', $result);
+		$this->assertTextContains('message warning', $result);
+		$this->assertTextContains('message info', $result);
+		$this->assertTextContains('message custom', $result);
+
+		$result = substr_count($result, 'message info');
+		$this->assertSame(2, $result);
+	}
+
+	/**
+	 * Test that you can define your own order or just output a subpart of
+	 * the types.
+	 *
+	 * @return void
+	 */
+	public function testFlashWithTypes() {
+		$this->Common->addFlashMessage('I am an error', 'error');
+		$this->Common->addFlashMessage('I am a warning', 'warning');
+		$this->Common->addFlashMessage('I am some info', 'info');
+		$this->Common->addFlashMessage('I am also some info');
+		$this->Common->addFlashMessage('I am sth custom', 'custom');
+
+		$result = $this->Common->flash(array('warning', 'error'));
+		$expected = '<div class="flashMessages"><div class="message warning">I am a warning</div><div class="message error">I am an error</div></div>';
+		$this->assertEquals($expected, $result);
+	}
+
+	/**
 	 * @return void
 	 */
 	public function testMetaCanonical() {
@@ -45,7 +91,7 @@ class CommonHelperTest extends MyCakeTestCase {
 
 		$is = $this->Common->metaAlternate(array('controller' => 'some', 'action' => 'url'), array('de', 'de-ch'), true);
 		$this->out(h($is));
-		$this->assertEquals('<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de" />' . PHP_EOL . '<link href="' . FULL_BASE_URL . $this->Html->url('/some/url') . '" rel="alternate" hreflang="de-ch" />', trim($is));
+		$this->assertEquals('<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de" />' . PHP_EOL . '<link href="' . $this->Html->url('/some/url', true) . '" rel="alternate" hreflang="de-ch" />', trim($is));
 
 		$is = $this->Common->metaAlternate(array('controller' => 'some', 'action' => 'url'), array('de' => array('ch', 'at'), 'en' => array('gb', 'us')), true);
 		$this->out(h($is));

+ 249 - 248
View/Helper/CommonHelper.php

@@ -1,5 +1,7 @@
 <?php
 App::uses('AppHelper', 'View/Helper');
+App::uses('CommonComponent', 'Tools.Controller/Component');
+App::uses('Hash', 'Utility');
 
 /**
  * All site-wide necessary stuff for the view layer
@@ -8,9 +10,222 @@ class CommonHelper extends AppHelper {
 
 	public $helpers = array('Session', 'Html');
 
-	public $packages = array(
-		'Tools.Jquery' // Used by showDebug
-	);
+	/**
+	 * Display all flash messages
+	 *
+	 * TODO: export div wrapping method (for static messaging on a page)
+	 * TODO: sorting
+	 *
+	 * @param array $types Types to output. Defaults to all if none are specified.
+	 * @return string HTML
+	 */
+	public function flash(array $types = array()) {
+		// Get the messages from the session
+		$messages = (array)$this->Session->read('messages');
+		$cMessages = (array)Configure::read('messages');
+		if (!empty($cMessages)) {
+			$messages = (array)Hash::merge($messages, $cMessages);
+		}
+		$html = '';
+		if (!empty($messages)) {
+			$html = '<div class="flashMessages">';
+
+			if ($types) {
+				foreach ($types as $type) {
+					// Add a div for each message using the type as the class.
+					foreach ($messages as $messageType => $msgs) {
+						if ($messageType !== $type) {
+							continue;
+						}
+						foreach ((array)$msgs as $msg) {
+							$html .= $this->_message($msg, $messageType);
+						}
+					}
+				}
+			} else {
+				foreach ($messages as $messageType => $msgs) {
+					foreach ((array)$msgs as $msg) {
+						$html .= $this->_message($msg, $messageType);
+					}
+				}
+			}
+			$html .= '</div>';
+			if (method_exists($this->Session, 'delete')) {
+				$this->Session->delete('messages');
+			} else {
+				CakeSession::delete('messages');
+			}
+			Configure::delete('messages');
+		}
+
+		return $html;
+	}
+
+	/**
+	 * Outputs a single flashMessage directly.
+	 * Note that this does not use the Session.
+	 *
+	 * @param string $message String to output.
+	 * @param string $type Type (success, warning, error, info)
+	 * @param boolean $escape Set to false to disable escaping.
+	 * @return string HTML
+	 */
+	public function flashMessage($msg, $type = 'info', $escape = true) {
+		$html = '<div class="flashMessages">';
+		if ($escape) {
+			$msg = h($msg);
+		}
+		$html .= $this->_message($msg, $type);
+		$html .= '</div>';
+		return $html;
+	}
+
+	/**
+	 * Formats a message
+	 *
+	 * @param string $msg Message to output.
+	 * @param string $type Type that will be formatted to a class tag.
+	 * @return string
+	 */
+	protected function _message($msg, $type) {
+		if (!empty($msg)) {
+			return '<div class="message' . (!empty($type) ? ' ' . $type : '') . '">' . $msg . '</div>';
+		}
+		return '';
+	}
+
+	/**
+	 * Add a message on the fly
+	 *
+	 * @param string $msg
+	 * @param string $class
+	 * @return boolean Success
+	 */
+	public function addFlashMessage($msg, $class = null) {
+		return CommonComponent::transientFlashMessage($msg, $class);
+	}
+
+	/**
+	 * CommonHelper::transientFlashMessage()
+	 *
+	 * @param mixed $msg
+	 * @param mixed $class
+	 * @return boolean Success
+	 * @deprecated Use addFlashMessage() instead
+	 */
+	public function transientFlashMessage($msg, $class = null) {
+		return $this->addFlashMessage($msg, $class);
+	}
+
+	/**
+	 * Escape text with some more automagic
+	 * TODO: move into TextExt?
+	 *
+	 * @param string $text
+	 * @param array $options
+	 * @return string processedText
+	 * - nl2br: true/false (defaults to true)
+	 * - escape: false prevents h() and space transformation (defaults to true)
+	 * - tabsToSpaces: int (defaults to 4)
+	 */
+	public function esc($text, $options = array()) {
+		if (!isset($options['escape']) || $options['escape'] !== false) {
+			//$text = str_replace(' ', '&nbsp;', h($text));
+			$text = h($text);
+			// try to fix indends made out of spaces
+			$text = explode(NL, $text);
+			foreach ($text as $key => $t) {
+				$i = 0;
+				while (!empty($t[$i]) && $t[$i] === ' ') {
+					$i++;
+				}
+				if ($i > 0) {
+					$t = str_repeat('&nbsp;', $i) . substr($t, $i);
+					$text[$key] = $t;
+				}
+			}
+			$text = implode(NL, $text);
+			$esc = true;
+		}
+		if (!isset($options['nl2br']) || $options['nl2br'] !== false) {
+			$text = nl2br($text);
+		}
+		if (!isset($options['tabsToSpaces'])) {
+			$options['tabsToSpaces'] = 4;
+		}
+		if (!empty($options['tabsToSpaces'])) {
+
+			$text = str_replace(TB, str_repeat(!empty($esc) ? '&nbsp;' : ' ', $options['tabsToSpaces']), $text);
+		}
+
+		return $text;
+	}
+
+
+	/**
+	 * Alternates between two or more strings.
+	 *
+	 * echo CommonHelper::alternate('one', 'two'); // "one"
+	 * echo CommonHelper::alternate('one', 'two'); // "two"
+	 * echo CommonHelper::alternate('one', 'two'); // "one"
+	 *
+	 * Note that using multiple iterations of different strings may produce
+	 * unexpected results.
+	 * TODO: move to booststrap/lib!!!
+	 *
+	 * @param string strings to alternate between
+	 * @return string
+	 */
+	public static function alternate() {
+		static $i;
+
+		if (func_num_args() === 0) {
+			$i = 0;
+			return '';
+		}
+
+		$args = func_get_args();
+		return $args[($i++ % count($args))];
+	}
+
+	/**
+	 * Auto-pluralizing a word using the Inflection class
+	 * //TODO: move to lib or bootstrap
+	 *
+	 * @param string $singular The string to be pl.
+	 * @param integer $count
+	 * @return string "member" or "members" OR "Mitglied"/"Mitglieder" if autoTranslate TRUE
+	 */
+	public function asp($singular, $count, $autoTranslate = false) {
+		if ((int)$count !== 1) {
+			$pural = Inflector::pluralize($singular);
+		} else {
+			$pural = null; // No pluralization necessary
+		}
+		return $this->sp($singular, $pural, $count, $autoTranslate);
+	}
+
+	/**
+	 * Manual pluralizing a word using the Inflection class
+	 * //TODO: move to lib or bootstrap
+	 *
+	 * @param string $singular
+	 * @param string $plural
+	 * @param integer $count
+	 * @return string result
+	 */
+	public function sp($singular, $plural, $count, $autoTranslate = false) {
+		if ((int)$count !== 1) {
+			$result = $plural;
+		} else {
+			$result = $singular;
+		}
+
+		if ($autoTranslate) {
+			$result = __($result);
+		}
+		return $result;
+	}
 
 	/**
 	 * Convenience method for clean ROBOTS allowance
@@ -40,17 +255,15 @@ class CommonHelper extends AppHelper {
 	 * Convenience method for clean meta name tags
 	 *
 	 * @param string $name: author, date, generator, revisit-after, language
-	 * @param MIXED $content: if array, it will be seperated by commas
-	 * @return string htmlMarkup
+	 * @param mixed $content: if array, it will be seperated by commas
+	 * @return string HTML Markup
 	 */
 	public function metaName($name = null, $content = null) {
 		if (empty($name) || empty($content)) {
 			return '';
 		}
 
-		if (!is_array($content)) {
-			$content = (array)$content;
-		}
+		$content = (array)$content;
 		$return = '<meta name="' . $name . '" content="' . implode(', ', $content) . '" />';
 		return $return;
 	}
@@ -61,7 +274,7 @@ class CommonHelper extends AppHelper {
 	 * @param string $content
 	 * @param string $language (iso2: de, en-us, ...)
 	 * @param array $additionalOptions
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 */
 	public function metaDescription($content, $language = null, $options = array()) {
 		if (!empty($language)) {
@@ -78,7 +291,7 @@ class CommonHelper extends AppHelper {
 	 * @param string|array $keywords
 	 * @param string $language (iso2: de, en-us, ...)
 	 * @param boolean $escape
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 */
 	public function metaKeywords($keywords = null, $language = null, $escape = true) {
 		if ($keywords === null) {
@@ -103,7 +316,7 @@ class CommonHelper extends AppHelper {
 	 *
 	 * @param mixed $url
 	 * @param boolean $full
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 */
 	public function metaCanonical($url = null, $full = false) {
 		$canonical = $this->Html->url($url, $full);
@@ -120,7 +333,7 @@ class CommonHelper extends AppHelper {
 	 * - de
 	 * - de-ch
 	 * etc
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 */
 	public function metaAlternate($url, $lang, $full = false) {
 		//$canonical = $this->Html->url($url, $full);
@@ -147,20 +360,18 @@ class CommonHelper extends AppHelper {
 	/**
 	 * Convenience method for META Tags
 	 *
-	 * @param string $type
-	 * @param string $content
-	 * @return string htmlMarkup
+	 * @param mixed $url
+	 * @param string $title
+	 * @return string HTML Markup
 	 */
-	public function metaRss($url = null, $title = null) {
+	public function metaRss($url, $title = null) {
 		$tags = array(
 			'meta' => '<link rel="alternate" type="application/rss+xml" title="%s" href="%s" />',
 		);
-		$content = array();
-		if (empty($url)) {
-			return '';
-		}
 		if (empty($title)) {
-			$title = 'Diesen Feed abonnieren';
+			$title = __('Subscribe to this feed');
+		} else {
+			$title = h($title);
 		}
 
 		return sprintf($tags['meta'], $title, $this->url($url));
@@ -171,7 +382,7 @@ class CommonHelper extends AppHelper {
 	 *
 	 * @param string $type
 	 * @param string $content
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 */
 	public function metaEquiv($type, $value, $escape = true) {
 		$tags = array(
@@ -192,7 +403,7 @@ class CommonHelper extends AppHelper {
 	 * => y is in plugins/tools/webroot/
 	 * => z is in plugins/tools/packages/jquery/files/jquery/sub/
 	 *
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 * @deprecated Use AssetCompress plugin instead
 	 */
 	public function css($files = array(), $options = array()) {
@@ -214,7 +425,7 @@ class CommonHelper extends AppHelper {
 	 * => y is in plugins/tools/webroot/
 	 * => z is in plugins/tools/packages/jquery/files/jquery/sub/
 	 *
-	 * @return string htmlMarkup
+	 * @return string HTML Markup
 	 * @deprecated Use AssetCompress plugin instead
 	 */
 	public function script($files = array(), $options = array()) {
@@ -230,41 +441,6 @@ class CommonHelper extends AppHelper {
 	}
 
 	/**
-	 * Special css tag generator with the option to add '?...' to the link (for caching prevention)
-	 * IN USAGE
-	 * needs manual adjustment, but still better than the core one!
-	 *
-	 * Note: needs Asset.cssversion => xyz (going up with counter)
-	 *
-	 * @return string htmlMarkup
-	 * @deprecated Use AssetCompress plugin instead
-	 */
-	public function cssDyn($path, $options = array()) {
-		$v = (int)Configure::read('Asset.version');
-		return $this->Html->css($path . '.css?' . $v, $options);
-	}
-
-	/**
-	 * Css Auto Path
-	 * NOT IN USAGE
-	 * but better than the core one!
-	 * Note: needs Asset.timestamp => force
-	 *
-	 * @return string htmlMarkup
-	 * @deprecated Use AssetCompress plugin instead
-	 */
-	public function cssAuto($path, $htmlAttributes = array()) {
-		$compress = Configure::read('App.compressCss');
-		$cssUrl = Configure::read('App.cssBaseUrl') ? Configure::read('App.cssBaseUrl') : CSS_URL;
-
-		$time = date('YmdHis', filemtime(APP . 'webroot' . DS . $cssUrl . $path . '.css'));
-		$url = "{$this->request->webroot}" . ($compress ? 'c' : '') . $cssUrl . $this->themeWeb . $path . ".css?" . $time;
-		return $url;
-	}
-
-/*** Content Stuff ***/
-
-	/**
 	 * Still necessary?
 	 *
 	 * @param array $fields
@@ -299,32 +475,6 @@ class CommonHelper extends AppHelper {
 	}
 
 	/**
-	 * Alternates between two or more strings.
-	 *
-	 * echo CommonHelper::alternate('one', 'two'); // "one"
-	 * echo CommonHelper::alternate('one', 'two'); // "two"
-	 * echo CommonHelper::alternate('one', 'two'); // "one"
-	 *
-	 * Note that using multiple iterations of different strings may produce
-	 * unexpected results.
-	 * TODO: move to booststrap/lib!!!
-	 *
-	 * @param string strings to alternate between
-	 * @return string
-	 */
-	public static function alternate() {
-		static $i;
-
-		if (func_num_args() === 0) {
-			$i = 0;
-			return '';
-		}
-
-		$args = func_get_args();
-		return $args[($i++ % count($args))];
-	}
-
-	/**
 	 * Check if session works due to allowed cookies
 	 *
 	 * @param boolean Success
@@ -352,167 +502,9 @@ class CommonHelper extends AppHelper {
 	}
 
 	/**
-	 * Auto-pluralizing a word using the Inflection class
-	 * //TODO: move to lib or bootstrap
-	 *
-	 * @param string $singular The string to be pl.
-	 * @param integer $count
-	 * @return string "member" or "members" OR "Mitglied"/"Mitglieder" if autoTranslate TRUE
-	 */
-	public function asp($singular, $count, $autoTranslate = false) {
-		if ((int)$count !== 1) {
-			$pural = Inflector::pluralize($singular);
-		} else {
-			$pural = null; # no pluralization necessary
-		}
-		return $this->sp($singular, $pural, $count, $autoTranslate);
-	}
-
-	/**
-	 * Manual pluralizing a word using the Inflection class
-	 * //TODO: move to lib or bootstrap
-	 *
-	 * @param string $singular
-	 * @param string $plural
-	 * @param integer $count
-	 * @return string result
-	 */
-	public function sp($singular, $plural, $count, $autoTranslate = false) {
-		if ((int)$count !== 1) {
-			$result = $plural;
-		} else {
-			$result = $singular;
-		}
-
-		if ($autoTranslate) {
-			$result = __($result);
-		}
-		return $result;
-	}
-
-	/**
-	 * Show flash messages
-	 *
-	 * TODO: export div wrapping method (for static messaging on a page)
-	 * TODO: sorting
-	 *
-	 * @param boolean unsorted true/false [default:FALSE = sorted by priority]
-	 * @return string HTML
-	 */
-	public function flash($unsorted = false) {
-		// Get the messages from the session
-		$messages = (array)$this->Session->read('messages');
-		$cMessages = (array)Configure::read('messages');
-		if (!empty($cMessages)) {
-			$messages = (array)Set::merge($messages, $cMessages);
-		}
-		$html = '';
-		if (!empty($messages)) {
-			$html = '<div class="flashMessages">';
-
-			if ($unsorted !== true) {
-				// Add a div for each message using the type as the class.
-				foreach ($messages as $type => $msgs) {
-					foreach ((array)$msgs as $msg) {
-						$html .= $this->_message($msg, $type);
-					}
-				}
-			} else {
-				foreach ($messages as $type) {
-					//
-				}
-			}
-			$html .= '</div>';
-			if (method_exists($this->Session, 'delete')) {
-				$this->Session->delete('messages');
-			} else {
-				CakeSession::delete('messages');
-			}
-		}
-
-		return $html;
-	}
-
-	/**
-	 * Output a single flashMessage
-	 *
-	 * @param string $message
-	 * @return string HTML
-	 */
-	public function flashMessage($msg, $type = 'info', $escape = true) {
-		$html = '<div class="flashMessages">';
-		if ($escape) {
-			$msg = h($msg);
-		}
-		$html .= $this->_message($msg, $type);
-		$html .= '</div>';
-		return $html;
-	}
-
-	protected function _message($msg, $type) {
-		if (!empty($msg)) {
-			return '<div class="message' . (!empty($type) ? ' ' . $type : '') . '">' . $msg . '</div>';
-		}
-		return '';
-	}
-
-	/**
-	 * Add a message on the fly
-	 *
-	 * @param string $msg
-	 * @param string $class
-	 * @return boolean Success
-	 */
-	public function transientFlashMessage($msg, $class = null) {
-		return CommonComponent::transientFlashMessage($msg, $class);
-	}
-
-	/**
-	 * Escape text with some more automagic
-	 * TODO: move into TextExt?
-	 *
-	 * @param string $text
-	 * @param array $options
-	 * @return string processedText
-	 * - nl2br: true/false (defaults to true)
-	 * - escape: false prevents h() and space transformation (defaults to true)
-	 * - tabsToSpaces: int (defaults to 4)
-	 */
-	public function esc($text, $options = array()) {
-		if (!isset($options['escape']) || $options['escape'] !== false) {
-			//$text = str_replace(' ', '&nbsp;', h($text));
-			$text = h($text);
-			// try to fix indends made out of spaces
-			$text = explode(NL, $text);
-			foreach ($text as $key => $t) {
-				$i = 0;
-				while (!empty($t[$i]) && $t[$i] === ' ') {
-					$i++;
-				}
-				if ($i > 0) {
-					$t = str_repeat('&nbsp;', $i) . substr($t, $i);
-					$text[$key] = $t;
-				}
-			}
-			$text = implode(NL, $text);
-			$esc = true;
-		}
-		if (!isset($options['nl2br']) || $options['nl2br'] !== false) {
-			$text = nl2br($text);
-		}
-		if (!isset($options['tabsToSpaces'])) {
-			$options['tabsToSpaces'] = 4;
-		}
-		if (!empty($options['tabsToSpaces'])) {
-
-			$text = str_replace(TB, str_repeat(!empty($esc) ? '&nbsp;' : ' ', $options['tabsToSpaces']), $text);
-		}
-
-		return $text;
-	}
-
-	/**
 	 * Prevents site being opened/included by others/websites inside frames
+	 *
+	 * @return string
 	 */
 	public function framebuster() {
 		return $this->Html->scriptBlock('
@@ -526,6 +518,8 @@ if (top!=self) top.location.ref=self.location.href;
 	 * - engine (js, jquery)
 	 * - escape
 	 * needs the id element to be a present (div) container in the layout
+	 *
+	 * @return string
 	 */
 	public function browserAlert($id, $message, $options = array()) {
 		$engine = 'js';
@@ -563,6 +557,8 @@ jQuery(document).ready(function() {
 	 * In noscript tags:
 	 * - link which should not be followed by bots!
 	 * - "pseudo"image which triggers log
+	 *
+	 * @return string
 	 */
 	public function honeypot($noFollowUrl, $noscriptUrl = array()) {
 		$res = '<div class="invisible" style="display:none"><noscript>';
@@ -576,11 +572,11 @@ jQuery(document).ready(function() {
 		return $res;
 	}
 
-/*** Stats ***/
-
 	/**
 	 * Print js-visit-stats-link to layout
 	 * uses Piwik open source statistics framework
+	 *
+	 * @return string
 	 */
 
 	public function visitStats($viewPath = null) {
@@ -618,6 +614,8 @@ piwikTracker.enableLinkTracking();
 
 	/**
 	 * Non js browsers
+	 *
+	 * @return string
 	 */
 	public function visitStatsImg($trackingUrl = null) {
 		if (empty($trackingUrl)) {
@@ -635,7 +633,7 @@ piwikTracker.enableLinkTracking();
 	 * Checks if a role is in the current users session
 	 *
 	 * @param necessary right(s) as array - or a single one as string possible
-	 * Note: all of them need to be in the user roles to return true by default
+	 * @return array
 	 * @deprecated - use Auth class instead
 	 */
 	public function roleNames($sessionRoles = null) {
@@ -675,6 +673,7 @@ piwikTracker.enableLinkTracking();
 
 	/**
 	 * Display Roles separated by Commas
+	 *
 	 * @deprecated - use Auth class instead
 	 */
 	public function displayRoles($sessionRoles = null, $placeHolder = '---') {
@@ -687,7 +686,9 @@ piwikTracker.enableLinkTracking();
 
 	/**
 	 * Takes int / array(int) and finds the role name to it
+	 *
 	 * @return array roles
+	 * @deprecated - use Auth class instead
 	 */
 	public function roleNamesTranslated($value) {
 		if (empty($value)) {

+ 14 - 5
View/Helper/DatetimeHelper.php

@@ -9,8 +9,14 @@ class DatetimeHelper extends TimeHelper {
 
 	public $helpers = array('Html');
 
+	/**
+	 * @deprecated Let timezone handle that
+	 */
 	public $userOffset = null;
 
+	/**
+	 * @deprecated Let timezone handle that
+	 */
 	public $daylightSavings = false;
 
 	public function __construct($View = null, $settings = array()) {
@@ -27,6 +33,9 @@ class DatetimeHelper extends TimeHelper {
 	}
 
 	/**
+	 * Output the age of a person within a sane range.
+	 * Defaults to the $default string if outside of that range.
+	 *
 	 * @param string date (from db)
 	 * @return integer age on success, mixed $default otherwise
 	 */
@@ -61,7 +70,7 @@ class DatetimeHelper extends TimeHelper {
 
 	/**
 	 * Returns red/specialGreen/green date depending on the current day
-	 * // TODO refactor!
+	 * // TODO refactor! $userOffset is deprecated!
 	 *
 	 * @param date in DB Format (xxxx-xx-xx)
 	 * ...
@@ -143,11 +152,11 @@ class DatetimeHelper extends TimeHelper {
 	 * returns hh:mm
 	 * TODO: move to lib, but more generic
 	 *
-	 * @param badTime
-	 * @return string Nice time
+	 * @param string $time
+	 * @return string Time
 	 */
-	public function niceTime($badTime) {
-		return substr($badTime, 0, 5);
+	public function niceTime($time) {
+		return substr($time, 0, 5);
 	}
 
 	/**