Browse Source

spelling corrections and minor fixes

euromark 13 years ago
parent
commit
71b6397bd6

+ 2 - 2
Controller/Component/CommonComponent.php

@@ -758,7 +758,7 @@ class CommonComponent extends Component {
 /*** deprecated ***/
 
 	/**
-	 * add protocol prefix if neccessary (and possible)
+	 * add protocol prefix if necessary (and possible)
 	 * static?
 	 * 2010-06-02 ms
 	 */
@@ -872,7 +872,7 @@ class CommonComponent extends Component {
 
 	/**
 	 * for month and year it returns the amount of days of this month
-	 * year is neccessary due to leap years!
+	 * year is necessary due to leap years!
 	 * @param int $year
 	 * @param int $month
 	 * @static

+ 8 - 6
Lib/MyModel.php

@@ -1248,7 +1248,7 @@ class MyModel extends Model {
 	 * NOW: can be set to work offline only (if server is down etc)
 	 *
 	 * checks if a email is not from a garbige hoster
-	 * @param string email (neccessary)
+	 * @param string email (necessary)
 	 * @return boolean true if valid, else false
 	 * 2009-03-09 ms
 	 */
@@ -1465,10 +1465,12 @@ class MyModel extends Model {
 
 
 	/**
-	 * find a specific entry
-	 * @param id
-	 * @param fields
-	 * @param contain
+	 * find a specific entry via primary key
+	 *
+	 * @param mixed $id
+	 * @param array $fields
+	 * @param array $contain
+	 * @return mixed
 	 * 2009-11-14 ms
 	 */
 	public function get($id, $fields = array(), $contain = array()) {
@@ -1495,7 +1497,7 @@ class MyModel extends Model {
 		}
 
 		$options = array(
-			'conditions' => array($this->alias .'.'. $column => $value),
+			'conditions' => array($this->alias . '.' . $column => $value),
 			'fields' => $fields,
 		);
 		if (!empty($contain)) {

+ 1 - 1
Lib/RandomLib.php

@@ -174,7 +174,7 @@ class RandomLib {
 	/**
 	 * //TODO: move to password lib?
 	 * generate random passwords
-	 * @param int $lenght (neccessary!)
+	 * @param int $lenght (necessary!)
 	 * @return pwd
 	 * @static
 	 * 2009-12-26 ms

+ 1 - 1
Lib/Utility/Utility.php

@@ -127,7 +127,7 @@ class Utility {
 	}
 
 	/**
-	 * add protocol prefix if neccessary (and possible)
+	 * add protocol prefix if necessary (and possible)
 	 * static?
 	 * 2010-06-02 ms
 	 */

+ 6 - 6
Model/Behavior/CaptchaBehavior.php

@@ -61,19 +61,19 @@ class CaptchaBehavior extends ModelBehavior {
 			$this->Model->whitelist = array_merge($Model->whitelist, $this->fields());
 		}
 		if (empty($Model->data[$Model->alias])) {
-			$this->Model->invalidate('captcha', 'captchaContentMissing', true);
+			$this->Model->invalidate('captcha', __('captchaContentMissing'));
 
 		} elseif (!$this->_validateDummyField($Model->data[$Model->alias])) {
-			$this->Model->invalidate('captcha', 'captchaIllegalContent', true);
+			$this->Model->invalidate('captcha', __('captchaIllegalContent'));
 
 		} elseif (!$this->_validateCaptchaMinTime($Model->data[$Model->alias])) {
-			$this->Model->invalidate('captcha', 'captchaResultTooFast', true);
+			$this->Model->invalidate('captcha', __('captchaResultTooFast'));
 
 		} elseif (!$this->_validateCaptchaMaxTime($Model->data[$Model->alias])) {
-			$this->Model->invalidate('captcha', 'captchaResultTooLate', true);
+			$this->Model->invalidate('captcha', __('captchaResultTooLate'));
 
 		} elseif (in_array($this->settings[$Model->alias]['type'], array('active', 'both')) && !$this->_validateCaptcha($Model->data[$Model->alias])) {
-			$this->Model->invalidate('captcha', 'captchaResultIncorrect', true);
+			$this->Model->invalidate('captcha', __('captchaResultIncorrect'));
 
 		}
 
@@ -173,7 +173,7 @@ class CaptchaBehavior extends ModelBehavior {
 	}
 
 	/**
-	 * only neccessary if there is more than one request per model
+	 * only necessary if there is more than one request per model
 	 * 2009-12-18 ms
 	 */
 	public function reset() {

+ 1 - 1
Model/Behavior/GeocoderBehavior.php

@@ -188,7 +188,7 @@ class GeocoderBehavior extends ModelBehavior {
 				}
 			}
 
-			# correct country id if neccessary
+			# correct country id if necessary
 			/*
 			if (in_array('country_name', $this->settings[$Model->alias]['address'])) {
 				App::uses('Country', 'Tools.Model');

+ 180 - 168
Model/Behavior/RevisionBehavior.php

@@ -1,9 +1,8 @@
 <?php
-
 App::uses('ModelBehavior', 'Model');
 
 /**
- * Revision Behavior
+ * Revision Behavior 2.0.4
  *
  * Revision is a solution for adding undo and other versioning functionality
  * to your database models. It is set up to be easy to apply to your project,
@@ -95,15 +94,11 @@ App::uses('ModelBehavior', 'Model');
  * 	 - api change: removed shadow(), changed revertToDate() to only recurse into related models that
  *     are dependent when cascade is true
  *
- * 2.0.5 => CakePHP 2.x
- *
  * @author Ronny Vindenes
  * @author Alexander 'alkemann' Morland
  * @license MIT
  * @modifed 27. march 2009
- * @version 2.0.5
- * @modified 2012-07-28 Mark Scherer (2.x ready)
- * @cakephp 2.x
+ * @version 2.0.4
  */
 class RevisionBehavior extends ModelBehavior {
 
@@ -133,7 +128,8 @@ class RevisionBehavior extends ModelBehavior {
 		'auto' => true,
 		'ignore' => array(),
 		'useDbConfig' => null,
-		'model' => null);
+		'model' => null
+	);
 	/**
 	 * Old data, used to detect changes
 	 *
@@ -148,7 +144,7 @@ class RevisionBehavior extends ModelBehavior {
 	 * @param array $config
 	 */
 	public function setup(Model $Model, $config = null) {
-		if (!empty($config)) {
+		if (is_array($config)) {
 			$this->settings[$Model->alias] = array_merge($this->defaults, $config);
 		} else {
 			$this->settings[$Model->alias] = $this->defaults;
@@ -165,9 +161,8 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return boolean success
 	 */
 	public function createRevision(Model $Model) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
@@ -180,13 +175,15 @@ class RevisionBehavior extends ModelBehavior {
 				$habtm[] = $assocAlias;
 			}
 		}
-		$data = $Model->find('first', array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id),
-				'contain' => $habtm));
+		$data = $Model->find('first', array(
+			'conditions'=>array($Model->alias.'.'.$Model->primaryKey => $Model->id),
+			'contain' => $habtm
+		));
 		$Model->ShadowModel->create($data);
 		$Model->ShadowModel->set('version_created', date('Y-m-d H:i:s'));
 		foreach ($habtm as $assocAlias) {
-			$foreign_keys = Set::extract($data, '/' . $assocAlias . '/' . $Model->{$assocAlias}->primaryKey);
-			$Model->ShadowModel->set($assocAlias, implode(',', $foreign_keys));
+			$foreign_keys = Set::extract($data,'/'.$assocAlias.'/'.$Model->{$assocAlias}->primaryKey);
+			$Model->ShadowModel->set($assocAlias, implode(',',$foreign_keys));
 		}
 		return $Model->ShadowModel->save();
 	}
@@ -204,23 +201,22 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return array
 	 */
 	public function diff(Model $Model, $from_version_id = null, $to_version_id = null, $options = array()) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return null;
 		}
 		if (isset($options['conditions'])) {
-			$conditions = am($options['conditions'], array($Model->primaryKey => $Model->id));
+			$conditions = am($options['conditions'],array($Model->primaryKey => $Model->id));
 		} else {
-			$conditions = array($Model->primaryKey => $Model->id);
+			$conditions = array( $Model->primaryKey => $Model->id);
 		}
 		if (is_numeric($from_version_id) || is_numeric($to_version_id)) {
 			if (is_numeric($from_version_id) && is_numeric($to_version_id)) {
-				$conditions['version_id'] = array($from_version_id, $to_version_id);
-				if ($Model->ShadowModel->find('count', array('conditions' => $conditions)) < 2) {
+				$conditions['version_id'] = array($from_version_id,$to_version_id);
+				if ($Model->ShadowModel->find('count',array('conditions'=>$conditions)) < 2) {
 					return false;
 				}
 			} else {
@@ -229,12 +225,12 @@ class RevisionBehavior extends ModelBehavior {
 				} else {
 					$conditions['version_id'] = $to_version_id;
 				}
-				if ($Model->ShadowModel->find('count', array('conditions' => $conditions)) < 1) {
+				if ($Model->ShadowModel->find('count',array('conditions'=>$conditions)) < 1) {
 					return false;
 				}
 			}
 		}
-		$conditions = array($Model->primaryKey => $Model->id);
+		$conditions = array($Model->primaryKey 	=> $Model->id);
 		if (is_numeric($from_version_id)) {
 			$conditions['version_id >='] = $from_version_id;
 		}
@@ -242,15 +238,15 @@ class RevisionBehavior extends ModelBehavior {
 			$conditions['version_id <='] = $to_version_id;
 		}
 		$options['conditions'] = $conditions;
-		$all = $this->revisions($Model, $options, true);
+		$all = $this->revisions($Model,$options,true);
 		if (sizeof($all) == 0) {
 			return null;
 		}
 		$unified = array();
 		$keys = array_keys($all[0][$Model->alias]);
 		foreach ($keys as $field) {
-			$all_values = Set::extract($all, '/' . $Model->alias . '/' . $field);
-			$all_values = array_reverse(array_unique(array_reverse($all_values, true)), true);
+			$all_values = Set::extract($all,'/'.$Model->alias.'/'.$field);
+			$all_values = array_reverse(array_unique(array_reverse($all_values,true)),true);
 			if (sizeof($all_values) == 1) {
 				$unified[$field] = reset($all_values);
 			} else {
@@ -278,7 +274,7 @@ class RevisionBehavior extends ModelBehavior {
 			return false;
 		}
 		if ($Model->ShadowModel->useTable == false) {
-			trigger_error('RevisionBehavior: Missing shadowtable : ' . $Model->table . $this->suffix, E_USER_WARNING);
+			trigger_error('RevisionBehavior: Missing shadowtable : '.$Model->table.$this->suffix, E_USER_WARNING);
 			return null;
 		}
 		if ($Model->ShadowModel->find('count') != 0) {
@@ -287,7 +283,7 @@ class RevisionBehavior extends ModelBehavior {
 		$count = $Model->find('count');
 		if ($limit < $count) {
 			$remaining = $count;
-			for ($p = 1; true; $p++) {
+			for ($p = 1; true; $p++ ) {
 
 				$this->init($Model, $p, $limit);
 
@@ -320,7 +316,8 @@ class RevisionBehavior extends ModelBehavior {
 		$all = $Model->find('all', array(
 			'limit' => $limit,
 			'page' => $page,
-			'contain' => $habtm));
+			'contain' => $habtm
+		));
 		$version_created = date('Y-m-d H:i:s');
 		foreach ($all as $data) {
 			$Model->ShadowModel->create($data);
@@ -340,21 +337,20 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return array
 	 */
 	public function newest(Model $Model, $options = array()) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return null;
 		}
 		if (isset($options['conditions'])) {
-			$options['conditions'] = am($options['conditions'], array($Model->alias . '.' . $Model->primaryKey => $Model->id));
+			$options['conditions'] = am($options['conditions'],array($Model->alias.'.'.$Model->primaryKey => $Model->id));
 		} else {
-			$options['conditions'] = array($Model->alias . '.' . $Model->primaryKey => $Model->id);
+			$options['conditions'] = array( $Model->alias.'.'.$Model->primaryKey => $Model->id);
 		}
 
-		return $Model->ShadowModel->find('first', $options);
+		return $Model->ShadowModel->find('first',$options);
 	}
 
 	/**
@@ -368,21 +364,20 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return array
 	 */
 	public function oldest(Model $Model, $options = array()) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return null;
 		}
 		if (isset($options['conditions'])) {
-			$options['conditions'] = am($options['conditions'], array($Model->primaryKey => $Model->id));
+			$options['conditions'] = am($options['conditions'],array($Model->primaryKey => $Model->id));
 		} else {
-			$options['conditions'] = array($Model->primaryKey => $Model->id);
+			$options['conditions'] = array( $Model->primaryKey => $Model->id);
 		}
 		$options['order'] = 'version_created ASC, version_id ASC';
-		return $Model->ShadowModel->find('first', $options);
+		return $Model->ShadowModel->find('first',$options);
 	}
 
 	/**
@@ -394,9 +389,8 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return array
 	 */
 	public function previous(Model $Model, $options = array()) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
@@ -405,11 +399,11 @@ class RevisionBehavior extends ModelBehavior {
 		$options['limit'] = 1;
 		$options['page'] = 2;
 		if (isset($options['conditions'])) {
-			$options['conditions'] = am($options['conditions'], array($Model->primaryKey => $Model->id));
+			$options['conditions'] = am($options['conditions'],array($Model->primaryKey => $Model->id));
 		} else {
-			$options['conditions'] = array($Model->primaryKey => $Model->id);
+			$options['conditions'] = array( $Model->primaryKey => $Model->id);
 		}
-		$revisions = $Model->ShadowModel->find('all', $options);
+		$revisions = $Model->ShadowModel->find('all',$options);
 		if (!$revisions) {
 			return null;
 		}
@@ -431,7 +425,7 @@ class RevisionBehavior extends ModelBehavior {
 			return false;
 		}
 		if (empty($options) || !isset($options['date'])) {
-			return false;
+			return FALSE;
 		}
 		if (!isset($options['conditions'])) {
 			$options['conditions'] = array();
@@ -439,36 +433,38 @@ class RevisionBehavior extends ModelBehavior {
 		// leave model rows out side of condtions alone
 		// leave model rows not edited since date alone
 
-		$all = $Model->find('all', array('conditions' => $options['conditions'], 'fields' => $Model->primaryKey));
-		$allIds = Set::extract($all, '/' . $Model->alias . '/' . $Model->primaryKey);
+		$all = $Model->find('all',array('conditions'=>$options['conditions'],'fields'=>$Model->primaryKey));
+		$allIds = Set::extract($all,'/'.$Model->alias.'/'.$Model->primaryKey);
 
 		$cond = $options['conditions'];
 		$cond['version_created <'] = $options['date'];
-		$created_before_date = $Model->ShadowModel->find('all', array(
+		$created_before_date = $Model->ShadowModel->find('all',array(
 			'order' => $Model->primaryKey,
 			'conditions' => $cond,
-			'fields' => array('version_id', $Model->primaryKey)));
-		$created_before_dateIds = Set::extract($created_before_date, '/' . $Model->alias . '/' . $Model->primaryKey);
+			'fields' => array('version_id',$Model->primaryKey)
+		));
+		$created_before_dateIds = Set::extract($created_before_date,'/'.$Model->alias.'/'.$Model->primaryKey);
 
-		$deleteIds = array_diff($allIds, $created_before_dateIds);
+		$deleteIds = array_diff($allIds,$created_before_dateIds);
 
 		// delete all Model rows where there are only version_created later than date
-		$Model->deleteAll(array($Model->alias . '.' . $Model->primaryKey => $deleteIds), false, true);
+		$Model->deleteAll(array($Model->alias.'.'.$Model->primaryKey => $deleteIds),false,true);
 
 		unset($cond['version_created <']);
 		$cond['version_created >='] = $options['date'];
-		$created_after_date = $Model->ShadowModel->find('all', array(
+		$created_after_date = $Model->ShadowModel->find('all',array(
 			'order' => $Model->primaryKey,
 			'conditions' => $cond,
-			'fields' => array('version_id', $Model->primaryKey)));
-		$created_after_dateIds = Set::extract($created_after_date, '/' . $Model->alias . '/' . $Model->primaryKey);
-		$updateIds = array_diff($created_after_dateIds, $deleteIds);
+			'fields' => array('version_id',$Model->primaryKey)
+		));
+		$created_after_dateIds = Set::extract($created_after_date,'/'.$Model->alias.'/'.$Model->primaryKey);
+		$updateIds = array_diff($created_after_dateIds,$deleteIds);
 
 		$revertSuccess = true;
 		// update model rows that have version_created earlier than date to latest before date
 		foreach ($updateIds as $mid) {
 			$Model->id = $mid;
-			if (!$Model->revertToDate($options['date'])) {
+			if ( ! $Model->revertToDate($options['date']) ) {
 				$revertSuccess = false;
 			}
 		}
@@ -485,21 +481,20 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return boolean
 	 */
 	public function revertTo(Model $Model, $version_id) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return false;
 		}
-		$data = $Model->ShadowModel->find('first', array('conditions' => array('version_id' => $version_id)));
+		$data = $Model->ShadowModel->find('first',array('conditions'=>array('version_id'=>$version_id)));
 		if ($data == false) {
 			return false;
 		}
 		foreach ($Model->getAssociated('hasAndBelongsToMany') as $assocAlias) {
 			if (isset($Model->ShadowModel->_schema[$assocAlias])) {
-				$data[$assocAlias][$assocAlias] = explode(',', $data[$Model->alias][$assocAlias]);
+				$data[$assocAlias][$assocAlias] = explode(',',$data[$Model->alias][$assocAlias]);
 			}
 		}
 		return $Model->save($data);
@@ -519,7 +514,7 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return boolean
 	 */
 	public function revertToDate(Model $Model, $datetime, $cascade = false, $force_delete = false) {
-		if (!$Model->id) {
+		if (! $Model->id) {
 			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
 			return null;
 		}
@@ -544,19 +539,21 @@ class RevisionBehavior extends ModelBehavior {
 				}
 
 				/* Query live data for children */
-				$children = $Model->$assoc->find('list', array('conditions' => array($data['foreignKey'] => $Model->id), 'recursive' =>
-						-1));
+				$children = $Model->$assoc->find('list', array('conditions'=>array($data['foreignKey']=>$Model->id),'recursive'=>-1));
 				if (!empty($children)) {
 					$ids = array_keys($children);
 				}
 
 				/* Query shadow table for deleted children */
 				$revision_children = $Model->$assoc->ShadowModel->find('all', array(
-					'fields' => array('DISTINCT ' . $Model->primaryKey),
-					'conditions' => array($data['foreignKey'] => $Model->id, 'NOT' => array($Model->primaryKey => $ids)),
-					));
+					'fields'=>array('DISTINCT '.$Model->primaryKey),
+					'conditions'=>array(
+						$data['foreignKey']=>$Model->id,
+						'NOT' => array( $Model->primaryKey => $ids )
+					),
+				));
 				if (!empty($revision_children)) {
-					$ids = am($ids, Set::extract($revision_children, '/' . $assoc . '/' . $Model->$assoc->primaryKey));
+					$ids = am($ids,Set::extract($revision_children,'/'.$assoc.'/'.$Model->$assoc->primaryKey));
 				}
 
 				/* Revert all children */
@@ -569,12 +566,17 @@ class RevisionBehavior extends ModelBehavior {
 		if (empty($Model->ShadowModel)) {
 			return true;
 		}
-		$data = $Model->ShadowModel->find('first', array('conditions' => array($Model->primaryKey => $Model->id,
-					'version_created <=' => $datetime), 'order' => 'version_created ASC, version_id ASC'));
+		$data = $Model->ShadowModel->find('first',array(
+			'conditions'=>array(
+				$Model->primaryKey => $Model->id,
+				'version_created <='=>$datetime
+			),
+			'order'=>'version_created ASC, version_id ASC'
+		));
 		/* If no previous version was found and revertToDate() was called with force_delete, then delete the live data, else leave it alone */
 		if ($data == false) {
 			if ($force_delete) {
-				$Model->logableAction['Revision'] = 'revertToDate(' . $datetime . ') delete';
+				$Model->logableAction['Revision'] = 'revertToDate('.$datetime.') delete';
 				return $Model->delete($Model->id);
 			}
 			return true;
@@ -585,33 +587,34 @@ class RevisionBehavior extends ModelBehavior {
 				$habtm[] = $assocAlias;
 			}
 		}
-		$liveData = $Model->find('first', array('contain' => $habtm, 'conditions' => array($Model->alias . '.' . $Model->
-					primaryKey => $Model->id)));
+		$liveData = $Model->find('first', array(
+			 		'contain'=> $habtm,
+			 		'conditions'=>array($Model->alias.'.'.$Model->primaryKey => $Model->id)));
 
-		$Model->logableAction['Revision'] = 'revertToDate(' . $datetime . ') add';
+		$Model->logableAction['Revision'] = 'revertToDate('.$datetime.') add';
 		if ($liveData) {
-			$Model->logableAction['Revision'] = 'revertToDate(' . $datetime . ') edit';
+			$Model->logableAction['Revision'] = 'revertToDate('.$datetime.') edit';
 			foreach ($Model->getAssociated('hasAndBelongsToMany') as $assocAlias) {
 				if (isset($Model->ShadowModel->_schema[$assocAlias])) {
-					$ids = Set::extract($liveData, '/' . $assocAlias . '/' . $Model->$assocAlias->primaryKey);
+					$ids = Set::extract($liveData,'/'.$assocAlias.'/'.$Model->$assocAlias->primaryKey);
 					if (empty($ids) || is_string($ids)) {
 						$liveData[$Model->alias][$assocAlias] = '';
 					} else {
-						$liveData[$Model->alias][$assocAlias] = implode(',', $ids);
+						$liveData[$Model->alias][$assocAlias] = implode(',',$ids);
 					}
-					$data[$assocAlias][$assocAlias] = explode(',', $data[$Model->alias][$assocAlias]);
+					$data[$assocAlias][$assocAlias] = explode(',',$data[$Model->alias][$assocAlias]);
 				}
 				unset($liveData[$assocAlias]);
 			}
 
 			$changeDetected = false;
 			foreach ($liveData[$Model->alias] as $key => $value) {
-				if (isset($data[$Model->alias][$key])) {
+				if ( isset($data[$Model->alias][$key])) {
 					$old_value = $data[$Model->alias][$key];
 				} else {
 					$old_value = '';
 				}
-				if ($value != $old_value) {
+				if ($value != $old_value ) {
 					$changeDetected = true;
 				}
 			}
@@ -623,11 +626,11 @@ class RevisionBehavior extends ModelBehavior {
 
 		$auto = $this->settings[$Model->alias]['auto'];
 		$this->settings[$Model->alias]['auto'] = false;
-		$Model->ShadowModel->create($data, true);
+		$Model->ShadowModel->create($data,true);
 		$Model->ShadowModel->set('version_created', date('Y-m-d H:i:s'));
 		$Model->ShadowModel->save();
 		$Model->version_id = $Model->ShadowModel->id;
-		$success = $Model->save($data);
+		$success =  $Model->save($data);
 		$this->settings[$Model->alias]['auto'] = $auto;
 		return $success;
 	}
@@ -645,24 +648,23 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return array
 	 */
 	public function revisions(Model $Model, $options = array(), $include_current = false) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return null;
 		}
 		if (isset($options['conditions'])) {
-			$options['conditions'] = am($options['conditions'], array($Model->alias . '.' . $Model->primaryKey => $Model->id));
+			$options['conditions'] = am($options['conditions'],array($Model->alias.'.'.$Model->primaryKey => $Model->id));
 		} else {
-			$options['conditions'] = array($Model->alias . '.' . $Model->primaryKey => $Model->id);
+			$options['conditions'] = array($Model->alias.'.'.$Model->primaryKey => $Model->id);
 		}
-		if ($include_current == false) {
-			$current = $this->newest($Model, array('fields' => array($Model->alias . '.version_id', $Model->primaryKey)));
-			$options['conditions'][$Model->alias . '.version_id !='] = $current[$Model->alias]['version_id'];
+		if ( $include_current == false ) {
+			$current = $this->newest($Model, array('fields'=>array($Model->alias.'.version_id',$Model->primaryKey)));
+			$options['conditions'][$Model->alias.'.version_id !='] = $current[$Model->alias]['version_id'];
 		}
-		return $Model->ShadowModel->find('all', $options);
+		return $Model->ShadowModel->find('all',$options);
 	}
 
 	/**
@@ -675,15 +677,16 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return boolean
 	 */
 	public function undelete(Model $Model) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return false;
 		}
-		if ($Model->find('count', array('conditions' => array($Model->primaryKey => $Model->id), 'recursive' => -1)) > 0) {
+		if  ($Model->find('count',array(
+			'conditions'=>array($Model->primaryKey=>$Model->id),
+			'recursive'=>-1)) > 0) {
 			return false;
 		}
 		$data = $this->newest($Model);
@@ -691,7 +694,7 @@ class RevisionBehavior extends ModelBehavior {
 			return false;
 		}
 		$beforeUndeleteSuccess = true;
-		if (method_exists($Model, 'beforeUndelete')) {
+		if (method_exists($Model,'beforeUndelete')) {
 			$beforeUndeleteSuccess = $Model->beforeUndelete();
 		}
 		if (!$beforeUndeleteSuccess) {
@@ -699,19 +702,22 @@ class RevisionBehavior extends ModelBehavior {
 		}
 		$model_id = $data[$Model->alias][$Model->primaryKey];
 		unset($data[$Model->alias][$Model->ShadowModel->primaryKey]);
-		$Model->create($data, true);
+		$Model->create($data,true);
 		$auto_setting = $this->settings[$Model->alias]['auto'];
 		$this->settings[$Model->alias]['auto'] = false;
-		$save_success = $Model->save();
+		$save_success =  $Model->save();
 		$this->settings[$Model->alias]['auto'] = $auto_setting;
 		if (!$save_success) {
 			return false;
 		}
-		$Model->updateAll(array($Model->primaryKey => $model_id), array($Model->primaryKey => $Model->id));
+		$Model->updateAll(
+			array($Model->primaryKey => $model_id),
+			array($Model->primaryKey => $Model->id)
+		);
 		$Model->id = $model_id;
 		$Model->createRevision();
 		$afterUndeleteSuccess = true;
-		if (method_exists($Model, 'afterUndelete')) {
+		if (method_exists($Model,'afterUndelete')) {
 			$afterUndeleteSuccess = $Model->afterUndelete();
 		}
 		return $afterUndeleteSuccess;
@@ -725,9 +731,8 @@ class RevisionBehavior extends ModelBehavior {
 	 * @return boolean
 	 */
 	public function undo(Model $Model) {
-		if (!$Model->id) {
-			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING);
-			return null;
+		if (! $Model->id) {
+			trigger_error('RevisionBehavior: Model::id must be set', E_USER_WARNING); return null;
 		}
 		if (!$Model->ShadowModel) {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
@@ -741,7 +746,7 @@ class RevisionBehavior extends ModelBehavior {
 		}
 		foreach ($Model->getAssociated('hasAndBelongsToMany') as $assocAlias) {
 			if (isset($Model->ShadowModel->_schema[$assocAlias])) {
-				$data[$assocAlias][$assocAlias] = explode(',', $data[$Model->alias][$assocAlias]);
+				$data[$assocAlias][$assocAlias] = explode(',',$data[$Model->alias][$assocAlias]);
 			}
 		}
 		$Model->logableAction['Revision'] = 'undo changes';
@@ -760,7 +765,7 @@ class RevisionBehavior extends ModelBehavior {
 			trigger_error('RevisionBehavior: ShadowModel doesnt exist.', E_USER_WARNING);
 			return null;
 		}
-		foreach ($idlist as $id) {
+		foreach ($idlist as $id ) {
 			$Model->id = $id;
 			$Model->createRevision();
 		}
@@ -804,13 +809,13 @@ class RevisionBehavior extends ModelBehavior {
 			return true;
 		}
 		if ($created) {
-			$Model->ShadowModel->create($Model->data, true);
-			$Model->ShadowModel->set($Model->primaryKey, $Model->id);
-			$Model->ShadowModel->set('version_created', date('Y-m-d H:i:s'));
+			$Model->ShadowModel->create($Model->data,true);
+			$Model->ShadowModel->set($Model->primaryKey,$Model->id);
+			$Model->ShadowModel->set('version_created',date('Y-m-d H:i:s'));
 			foreach ($Model->data as $alias => $alias_data) {
 				if (isset($Model->ShadowModel->_schema[$alias])) {
 					if (isset($alias_data[$alias]) && !empty($alias_data[$alias])) {
-						$Model->ShadowModel->set($alias, implode(',', $alias_data[$alias]));
+						$Model->ShadowModel->set($alias,implode(',',$alias_data[$alias]));
 					}
 				}
 			}
@@ -825,56 +830,58 @@ class RevisionBehavior extends ModelBehavior {
 				$habtm[] = $assocAlias;
 			}
 		}
-		$data = $Model->find('first', array('contain' => $habtm, 'conditions' => array($Model->alias . '.' . $Model->primaryKey =>
-					$Model->id)));
+		$data = $Model->find('first', array(
+			 		'contain'=> $habtm,
+			 		'conditions'=>array($Model->alias.'.'.$Model->primaryKey => $Model->id)));
 
 		$changeDetected = false;
 		foreach ($data[$Model->alias] as $key => $value) {
-			if (isset($data[$Model->alias][$Model->primaryKey]) && !empty($this->oldData[$Model->alias]) && isset($this->oldData[$Model->
-				alias][$Model->alias][$key])) {
-
-				$old_value = $this->oldData[$Model->alias][$Model->alias][$key];
-			} else {
-				$old_value = '';
-			}
-			if ($value != $old_value && !in_array($key, $this->settings[$Model->alias]['ignore'])) {
-				$changeDetected = true;
+	 			if ( isset($data[$Model->alias][$Model->primaryKey])
+	 					&& !empty($this->oldData[$Model->alias])
+	 					&& isset($this->oldData[$Model->alias][$Model->alias][$key])) {
+
+	 				$old_value = $this->oldData[$Model->alias][$Model->alias][$key];
+	 			} else {
+	 				$old_value = '';
+	 			}
+	 			if ($value != $old_value && !in_array($key,$this->settings[$Model->alias]['ignore'])) {
+	 				$changeDetected = true;
+	 			}
+	 		}
+	 		$Model->ShadowModel->create($data);
+	 		if (!empty($habtm)) {
+		 		foreach ($habtm as $assocAlias) {
+		 			if (in_array($assocAlias,$this->settings[$Model->alias]['ignore'])) {
+		 				continue;
+		 			}
+		 			$oldIds = Set::extract($this->oldData[$Model->alias],$assocAlias.'.{n}.id');
+			if (!isset($Model->data[$assocAlias])) {
+			$Model->ShadowModel->set($assocAlias, implode(',',$oldIds));
+			continue;
 			}
-		}
-		$Model->ShadowModel->create($data);
-		if (!empty($habtm)) {
-			foreach ($habtm as $assocAlias) {
-				if (in_array($assocAlias, $this->settings[$Model->alias]['ignore'])) {
-					continue;
-				}
-				$oldIds = Set::extract($this->oldData[$Model->alias], $assocAlias . '.{n}.id');
-				if (!isset($Model->data[$assocAlias])) {
-					$Model->ShadowModel->set($assocAlias, implode(',', $oldIds));
-					continue;
-				}
-				$currentIds = Set::extract($data, $assocAlias . '.{n}.id');
-				$id_changes = array_diff($currentIds, $oldIds);
-				if (!empty($id_changes)) {
-					$Model->ShadowModel->set($assocAlias, implode(',', $currentIds));
-					$changeDetected = true;
-				} else {
-					$Model->ShadowModel->set($assocAlias, implode(',', $oldIds));
-				}
+			$currentIds = Set::extract($data,$assocAlias.'.{n}.id');
+			$id_changes = array_diff($currentIds,$oldIds);
+			if (!empty($id_changes)) {
+			$Model->ShadowModel->set($assocAlias, implode(',',$currentIds));
+			$changeDetected = true;
+			} else {
+			$Model->ShadowModel->set($assocAlias, implode(',',$oldIds));
 			}
-		}
-		unset($this->oldData[$Model->alias]);
-		if (!$changeDetected) {
-			return true;
-		}
+		 		}
+	 		}
+	 		unset($this->oldData[$Model->alias]);
+	 		if (!$changeDetected) {
+	 			return true;
+	 		}
 		$Model->ShadowModel->set('version_created', date('Y-m-d H:i:s'));
 		$Model->ShadowModel->save();
 		$Model->version_id = $Model->ShadowModel->id;
 		if (is_numeric($this->settings[$Model->alias]['limit'])) {
-			$conditions = array('conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id));
+			$conditions = array('conditions'=>array($Model->alias.'.'.$Model->primaryKey => $Model->id));
 			$count = $Model->ShadowModel->find('count', $conditions);
 			if ($count > $this->settings[$Model->alias]['limit']) {
-				$conditions['order'] = $Model->alias . '.version_created ASC, ' . $Model->alias . '.version_id ASC';
-				$oldest = $Model->ShadowModel->find('first', $conditions);
+				$conditions['order'] = $Model->alias.'.version_created ASC, '.$Model->alias.'.version_id ASC';
+				$oldest = $Model->ShadowModel->find('first',$conditions);
 				$Model->ShadowModel->id = null;
 				$Model->ShadowModel->delete($oldest[$Model->alias][$Model->ShadowModel->primaryKey]);
 			}
@@ -899,9 +906,13 @@ class RevisionBehavior extends ModelBehavior {
 		}
 		foreach ($Model->hasAndBelongsToMany as $assocAlias => $a) {
 			if (isset($Model->{$assocAlias}->ShadowModel->_schema[$Model->alias])) {
-				$joins = $Model->{$a['with']}->find('all', array('recursive' => -1, 'conditions' => array($a['foreignKey'] => $Model->
-							id)));
-				$this->deleteUpdates[$Model->alias][$assocAlias] = Set::extract($joins, '/' . $a['with'] . '/' . $a['associationForeignKey']);
+				$joins =  $Model->{$a['with']}->find('all',array(
+					'recursive' => -1,
+					'conditions' => array(
+						$a['foreignKey'] => $Model->id
+					)
+				));
+				$this->deleteUpdates[$Model->alias][$assocAlias] = Set::extract($joins,'/'.$a['with'].'/'.$a['associationForeignKey']);
 			}
 		}
 		return true;
@@ -931,8 +942,9 @@ class RevisionBehavior extends ModelBehavior {
 				$habtm[] = $assocAlias;
 			}
 		}
-		$this->oldData[$Model->alias] = $Model->find('first', array('contain' => $habtm, 'conditions' => array($Model->alias .
-					'.' . $Model->primaryKey => $Model->id)));
+		$this->oldData[$Model->alias] = $Model->find('first', array(
+			 		'contain'=> $habtm,
+			 		'conditions'=>array($Model->alias.'.'.$Model->primaryKey => $Model->id)));
 
 		return true;
 	}
@@ -964,15 +976,15 @@ class RevisionBehavior extends ModelBehavior {
 			$Model->ShadowModel = false;
 			return false;
 		}
-		$useShadowModel = $this->settings[$Model->alias]['model'];
-		if (is_string($useShadowModel) && App::import('model', $useShadowModel)) {
-			$Model->ShadowModel = new $useShadowModel(false, $shadow_table, $dbConfig);
-		} else {
-			$Model->ShadowModel = new Model(false, $shadow_table, $dbConfig);
-		}
-		if ($Model->tablePrefix) {
-			$Model->ShadowModel->tablePrefix = $Model->tablePrefix;
-		}
+	$useShadowModel = $this->settings[$Model->alias]['model'];
+		if (is_string($useShadowModel) && App::import('model',$useShadowModel)) {
+		$Model->ShadowModel = new $useShadowModel(false, $shadow_table, $dbConfig);
+	} else {
+		$Model->ShadowModel = new Model(false, $shadow_table, $dbConfig);
+	}
+	if ($Model->tablePrefix) {
+		$Model->ShadowModel->tablePrefix = $Model->tablePrefix;
+	}
 		$Model->ShadowModel->alias = $Model->alias;
 		$Model->ShadowModel->primaryKey = 'version_id';
 		$Model->ShadowModel->order = 'version_created DESC, version_id DESC';

+ 4 - 4
Model/CodeKey.php

@@ -50,7 +50,7 @@ class CodeKey extends ToolsAppModel {
 
 	/**
 	 * stores new key in DB
-	 * @param string type: neccessary
+	 * @param string type: necessary
 	 * @param string key: optional key, otherwise a key will be generated
 	 * @param mixed user_id: optional (if used, only this user can use this key)
 	 * @param string content: up to 255 characters of content may be added (optional)
@@ -97,8 +97,8 @@ class CodeKey extends ToolsAppModel {
 
 	/**
 	 * usesKey (only once!) - by KEY
-	 * @param string type: neccessary
-	 * @param string key: neccessary
+	 * @param string type: necessary
+	 * @param string key: necessary
 	 * @param mixed user_id: needs to be provided if this key has a user_id stored
 	 * @return ARRAY(content) if successfully used or if already used (used=1), FALSE else
 	 * 2009-05-13 ms
@@ -141,7 +141,7 @@ class CodeKey extends ToolsAppModel {
 
 	/**
 	 * sets Key to "used" (only once!) - directly by ID
-	 * @param id of key to spend: neccessary
+	 * @param id of key to spend: necessary
 	 * @return boolean true on success, false otherwise
 	 * 2009-05-13 ms
 	 */

+ 1 - 1
Model/Qurl.php

@@ -143,7 +143,7 @@ class Qurl extends ToolsAppModel {
 
 	/**
 	 * sets Key to "used" (only once!) - directly by ID
-	 * @param id of key to spend: neccessary
+	 * @param id of key to spend: necessary
 	 * @return boolean true on success, false otherwise
 	 * 2009-05-13 ms
 	 */

+ 38 - 56
Test/Case/Model/Behavior/RevisionBehaviorTest.php

@@ -1,7 +1,9 @@
 <?php
+
 App::uses('RevisionBehavior', 'Tools.Model/Behavior');
+App::uses('MyCakeTestCase', 'Tools.Lib');
 
-class RevisionBehaviorTest extends CakeTestCase {
+class RevisionBehaviorTest extends MyCakeTestCase {
 
 	public $RevisionBehavior;
 
@@ -64,7 +66,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$Post = new RevisionPost();
 
 		$Post->id = 1;
-		$this->assertTrue((bool)$Post->createRevision());
+		$this->assertTrue($Post->createRevision());
 
 		$Post->id = 1;
 		$count = $Post->ShadowModel->find('count', array('conditions' => array('id' => 1)));
@@ -355,7 +357,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 
 		$Post->id = 1;
 		$success = $Post->undo();
-		$this->assertTrue((bool)$success);
+		$this->assertTrue($success);
 
 		$result = $Post->find('first', array('fields' => array(
 				'id',
@@ -405,8 +407,8 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$this->assertEqual($result['Post']['title'], 'Edited Post 2');
 
 		$version_id = $result['Post']['version_id'];
-		$result = $Post->revertTo($version_id);
-		$this->assertTrue((bool)$result);
+
+		$this->assertTrue($Post->RevertTo($version_id));
 
 		$result = $Post->find('first', array('fields' => array(
 				'id',
@@ -563,7 +565,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$data = array('User' => array('id' => 1, 'name' => 'New name'));
 		$success = $User->save($data);
 		$this->assertNoErrors();
-		$this->assertTrue((bool)$success);
+		$this->assertTrue($success);
 	}
 
 
@@ -574,9 +576,8 @@ class RevisionBehaviorTest extends CakeTestCase {
 
 		$data = array('Post' => array('id' => 3, 'title' => 'Edited Post 6'));
 		$Post->save($data);
-		$result = $Post->revertToDate(date('Y-m-d H:i:s', strtotime('yesterday')));
-		$this->assertTrue((bool)$result);
 
+		$this->assertTrue($Post->revertToDate(date('Y-m-d H:i:s', strtotime('yesterday'))));
 		$result = $Post->newest(array('fields' => array(
 				'id',
 				'title',
@@ -603,7 +604,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 				'revision_comment_id' => 1));
 		$Comment->Vote->save($data);
 
-		$this->assertTrue((bool)$Comment->Vote->revertToDate('2008-12-09'));
+		$this->assertTrue($Comment->Vote->revertToDate('2008-12-09'));
 		$Comment->Vote->id = 3;
 		$result = $Comment->Vote->newest(array('fields' => array(
 				'id',
@@ -622,7 +623,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$data = array('Comment' => array('id' => 2, 'title' => 'Edited Comment'));
 		$Comment->save($data);
 
-		$this->assertTrue((bool)$Comment->revertToDate('2008-12-09'));
+		$this->assertTrue($Comment->revertToDate('2008-12-09'));
 
 		$reverted_comments = $Comment->find('all');
 
@@ -656,7 +657,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$this->assertEqual($expected, $result);
 
 		$Article->id = 3;
-		$this->assertTrue((bool)$Article->createRevision());
+		$this->assertTrue($Article->createRevision());
 		$result = $Article->newest(array('fields' => array(
 				'id',
 				'title',
@@ -966,9 +967,8 @@ class RevisionBehaviorTest extends CakeTestCase {
 
 		$result = $Comment->find('first', array('contain' => array('Tag' => array('id', 'title'))));
 		$this->assertEqual(sizeof($result['Tag']), 2);
-		//TODO: assert
-		$this->assertEqual($result['Tag'][0]['title'], 'News');
-		$this->assertEqual($result['Tag'][1]['title'], 'Hard');
+		$this->assertEqual($result['Tag'][0]['title'], 'Hard');
+		$this->assertEqual($result['Tag'][1]['title'], 'News');
 
 		$currentIds = Set::extract($result, 'Tag.{n}.id');
 		$expected = implode(',', $currentIds);
@@ -1035,10 +1035,9 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$Comment->undo();
 		$result = $Comment->find('first', array('recursive' => 1)); //'contain' => array('Tag' => array('id','title'))));
 		$this->assertEqual(sizeof($result['Tag']), 3);
-		//TODO: assert
-		$this->assertEqual($result['Tag'][0]['title'], 'Trick');
+		$this->assertEqual($result['Tag'][0]['title'], 'Fun');
 		$this->assertEqual($result['Tag'][1]['title'], 'Hard');
-		$this->assertEqual($result['Tag'][2]['title'], 'Fun');
+		$this->assertEqual($result['Tag'][2]['title'], 'Trick');
 		$this->assertNoErrors('3 tags : %s');
 	}
 
@@ -1056,9 +1055,9 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$Comment->undo();
 		$result = $Comment->find('first', array('recursive' => 1)); //'contain' => array('Tag' => array('id','title'))));
 		$this->assertEqual(sizeof($result['Tag']), 3);
-		$this->assertEqual($result['Tag'][0]['title'], 'Trick');
+		$this->assertEqual($result['Tag'][0]['title'], 'Fun');
 		$this->assertEqual($result['Tag'][1]['title'], 'Hard');
-		$this->assertEqual($result['Tag'][2]['title'], 'Fun');
+		$this->assertEqual($result['Tag'][2]['title'], 'Trick');
 		$this->assertNoErrors('3 tags : %s');
 	}
 
@@ -1077,9 +1076,9 @@ class RevisionBehaviorTest extends CakeTestCase {
 
 		$result = $Comment->find('first', array('recursive' => 1)); //'contain' => array('Tag' => array('id','title'))));
 		$this->assertEqual(sizeof($result['Tag']), 3);
-		$this->assertEqual($result['Tag'][0]['title'], 'Trick');
+		$this->assertEqual($result['Tag'][0]['title'], 'Fun');
 		$this->assertEqual($result['Tag'][1]['title'], 'Hard');
-		$this->assertEqual($result['Tag'][2]['title'], 'Fun');
+		$this->assertEqual($result['Tag'][2]['title'], 'Trick');
 		$this->assertNoErrors('3 tags : %s');
 	}
 
@@ -1123,12 +1122,10 @@ class RevisionBehaviorTest extends CakeTestCase {
 
 		$comment_one = $Comment->find('first', array('conditions' => array('Comment.id' => 1), 'contain' => 'Tag'));
 		$this->assertEqual($comment_one['Comment']['title'], 'Comment 1');
-		$result = Set::extract($comment_one, 'Tag.{n}.id');
-		//TODO: assert
-		$this->assertEqual($result, array(
-			3,
+		$this->assertEqual(Set::extract($comment_one, 'Tag.{n}.id'), array(
+			1,
 			2,
-			1));
+			3));
 		$Comment->id = 1;
 		$rev_one = $Comment->newest();
 		$this->assertEqual($rev_one['Comment']['title'], 'Comment 1');
@@ -1150,10 +1147,9 @@ class RevisionBehaviorTest extends CakeTestCase {
 
 		$result = $Comment->find('first', array('recursive' => 1));
 		$this->assertEqual(sizeof($result['Tag']), 3);
-		//TODO: assert
-		$this->assertEqual($result['Tag'][0]['title'], 'Trick');
+		$this->assertEqual($result['Tag'][0]['title'], 'Fun');
 		$this->assertEqual($result['Tag'][1]['title'], 'Hard');
-		$this->assertEqual($result['Tag'][2]['title'], 'Fun');
+		$this->assertEqual($result['Tag'][2]['title'], 'Trick');
 		$this->assertNoErrors('3 tags : %s');
 	}
 
@@ -1179,22 +1175,20 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$result = $Comment->find('first', array('conditions' => array('Comment.id' => 2), 'contain' => array('Tag' => array('id',
 						'title'))));
 		$this->assertEqual(sizeof($result['Tag']), 3);
-		//TODO: assert
-		$this->assertEqual($result['Tag'][0]['title'], 'Trick');
-		$this->assertEqual($result['Tag'][1]['title'], 'Hard');
+		$this->assertEqual($result['Tag'][0]['title'], 'Hard');
+		$this->assertEqual($result['Tag'][1]['title'], 'Trick');
 		$this->assertEqual($result['Tag'][2]['title'], 'News');
 
 		// revert Tags on comment logic
 		$Comment->id = 2;
-		$this->assertTrue((bool)$Comment->revertToDate(date('Y-m-d H:i:s', strtotime('yesterday'))),
+		$this->assertTrue($Comment->revertToDate(date('Y-m-d H:i:s', strtotime('yesterday'))),
 			'revertHabtmToDate unsuccessful : %s');
 
 		$result = $Comment->find('first', array('conditions' => array('Comment.id' => 2), 'contain' => array('Tag' => array('id',
 						'title'))));
 		$this->assertEqual(sizeof($result['Tag']), 2);
-		//TODO: assert
-		$this->assertEqual($result['Tag'][0]['title'], 'Trick');
-		$this->assertEqual($result['Tag'][1]['title'], 'Fun');
+		$this->assertEqual($result['Tag'][0]['title'], 'Fun');
+		$this->assertEqual($result['Tag'][1]['title'], 'Trick');
 
 	}
 
@@ -1227,15 +1221,10 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$Comment->Tag->delete(1);
 
 		$result = $Comment->ShadowModel->find('all', array('conditions' => array('version_id' => array(4, 5))));
-		//TODO: assert/fixme
-		debug($result); ob_flush();
 		$this->assertEqual($result[0]['Comment']['Tag'], '3');
 		$this->assertEqual($result[1]['Comment']['Tag'], '2,3');
 	}
 
-	/**
-	 * @expects PHPUNIT_FRAMEWORK_ERROR_WARNING
-	 */
 	function testBadKittyForgotId() {
 		$Comment = new RevisionComment();
 
@@ -1273,9 +1262,6 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$this->assertFalse($Comment->diff(10, 4), 'diff() between two non existing : %s');
 	}
 
-	/**
-	 * @expects PHPUNIT_FRAMEWORK_ERROR_WARNING
-	 */
 	function testMethodsOnNonRevisedModel() {
 		$User = new RevisionUser();
 
@@ -1296,7 +1282,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 		$this->assertError();
 		$this->assertFalse($User->revertTo(2));
 		$this->assertError();
-		$this->assertTrue((bool)$User->revertToDate('1970-01-01'));
+		$this->assertTrue($User->revertToDate('1970-01-01'));
 		$this->assertNoErrors();
 		$this->assertFalse($User->revisions());
 		$this->assertError();
@@ -1352,11 +1338,7 @@ class RevisionBehaviorTest extends CakeTestCase {
 }
 
 
-class RevisionTestModel extends CakeTestModel {
-	public $logableAction;
-}
-
-class RevisionPost extends RevisionTestModel {
+class RevisionPost extends CakeTestModel {
 	public $name = 'RevisionPost';
 	public $alias = 'Post';
 	public $actsAs = array('Revision' => array('limit' => 5));
@@ -1372,7 +1354,7 @@ class RevisionPost extends RevisionTestModel {
 	}
 }
 
-class RevisionArticle extends RevisionTestModel {
+class RevisionArticle extends CakeTestModel {
 	public $name = 'RevisionArticle';
 	public $alias = 'Article';
 	public $actsAs = array('Tree', 'Revision' => array('ignore' => array('title')));
@@ -1393,13 +1375,13 @@ class RevisionArticle extends RevisionTestModel {
 	}
 }
 
-class RevisionUser extends RevisionTestModel {
+class RevisionUser extends CakeTestModel {
 	public $name = 'RevisionUser';
 	public $alias = 'User';
 	public $actsAs = array('Revision');
 }
 
-class RevisionComment extends RevisionTestModel {
+class RevisionComment extends CakeTestModel {
 	public $name = 'RevisionComment';
 	public $alias = 'Comment';
 	public $actsAs = array('Containable', 'Revision');
@@ -1410,20 +1392,20 @@ class RevisionComment extends RevisionTestModel {
 			'dependent' => true));
 }
 
-class RevisionVote extends RevisionTestModel {
+class RevisionVote extends CakeTestModel {
 	public $name = 'RevisionVote';
 	public $alias = 'Vote';
 	public $actsAs = array('Revision');
 }
 
-class RevisionTag extends RevisionTestModel {
+class RevisionTag extends CakeTestModel {
 	public $name = 'RevisionTag';
 	public $alias = 'Tag';
 	public $actsAs = array('Revision');
 	public $hasAndBelongsToMany = array('Comment' => array('className' => 'RevisionComment'));
 }
 
-class CommentsTag extends RevisionTestModel {
+class CommentsTag extends CakeTestModel {
 	public $name = 'CommentsTag';
 	public $useTable = 'revision_comments_revision_tags';
 	public $actsAs = array('Revision');

+ 233 - 236
View/Helper/CommonHelper.php

@@ -2,7 +2,7 @@
 App::uses('AppHelper', 'View/Helper');
 
 /**
- * All site-wide neccessary stuff for the view layer
+ * All site-wide necessary stuff for the view layer
  */
 class CommonHelper extends AppHelper {
 
@@ -12,7 +12,8 @@ class CommonHelper extends AppHelper {
 		'Tools.Jquery' //Used by showDebug
 	);
 
-/* Layout Stuff */
+
+/*** Layout Stuff ***/
 
 	/**
 	 * convinience function for clean ROBOTS allowance
@@ -33,7 +34,7 @@ class CommonHelper extends AppHelper {
 			$content['robots']= array('noindex','nofollow','noarchive');
 		}
 
-		$return = '<meta name="robots" content="'.implode(',',$content['robots']).'" />';
+		$return = '<meta name="robots" content="' . implode(',', $content['robots']) . '" />';
 		return $return;
 	}
 
@@ -41,6 +42,7 @@ class CommonHelper extends AppHelper {
 	 * convinience function 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
 	 * 2009-07-07 ms
 	 */
 	public function metaName($name = null, $content = null) {
@@ -51,10 +53,16 @@ class CommonHelper extends AppHelper {
 		if (!is_array($content)) {
 			$content = (array)$content;
 		}
-		$return = '<meta name="'.$name.'" content="'.implode(', ',$content).'" />';
+		$return = '<meta name="' . $name . '" content="' . implode(', ', $content) . '" />';
 		return $return;
 	}
 
+	/**
+	 * @param string $content
+	 * @param string $language (iso2: de, en-us, ...)
+	 * @param array $additionalOptions
+	 * @return string $htmlMarkup
+	 */
 	public function metaDescription($content, $language = null, $options = array()) {
 		if (!empty($language)) {
 			$options['lang'] = mb_strtolower($language);
@@ -64,6 +72,12 @@ class CommonHelper extends AppHelper {
 		return $this->Html->meta('description', $content, $options);
 	}
 
+	/**
+	 * @param string|array $keywords
+	 * @param string $language (iso2: de, en-us, ...)
+	 * @param bool $escape
+	 * @return string $htmlMarkup
+	 */
 	public function metaKeywords($keywords = null, $language = null, $escape = true) {
 		if ($keywords === null) {
 			$keywords = Configure::read('Config.keywords');
@@ -84,12 +98,14 @@ class CommonHelper extends AppHelper {
 
 	/**
 	 * convinience function for "canonical" SEO links
+	 *
+	 * @return string $htmlMarkup
 	 * 2010-03-03 ms
 	 */
 	public function metaCanonical($url = null, $full = false) {
 		$canonical = $this->Html->url($url, $full);
 		//return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
-		return '<link rel="canonical" href="'.$canonical.'" />';
+		return '<link rel="canonical" href="' . $canonical . '" />';
 	}
 
 	/**
@@ -100,6 +116,7 @@ class CommonHelper extends AppHelper {
 	 * - de
 	 * - de-ch
 	 * etc
+	 * @return string $htmlMarkup
 	 * 2011-12-12 ms
 	 */
 	public function metaAlternate($url, $lang, $full = false) {
@@ -115,8 +132,9 @@ class CommonHelper extends AppHelper {
  			}
  			$countries = (array)$countries;
 	 		foreach ($countries as $country) {
-	 			$l = $language.$country;
-	 			$res[] = $this->Html->meta('alternate', $url, array('rel'=>'alternate', 'hreflang'=>$l, 'type'=>null, 'title'=>null)).PHP_EOL;
+	 			$l = $language . $country;
+	 			$options = array('rel' => 'alternate', 'hreflang' => $l, 'type' => null, 'title' => null);
+	 			$res[] = $this->Html->meta('alternate', $url, $options).PHP_EOL;
 	 		}
 		}
 		return implode('', $res);
@@ -126,6 +144,7 @@ class CommonHelper extends AppHelper {
 	 * convinience function for META Tags
 	 * @param STRING type
 	 * @param STRING content
+	 * @return string $htmlMarkup
 	 * 2008-12-08 ms
 	 */
 	public function metaRss($url = null, $title = null) {
@@ -146,6 +165,7 @@ class CommonHelper extends AppHelper {
 	 * convinience function for META Tags
 	 * @param STRING type
 	 * @param STRING content
+	 * @return string $htmlMarkup
 	 * 2008-12-08 ms
 	 */
 	public function metaEquiv($type = null, $value = null, $escape = true) {
@@ -160,15 +180,15 @@ class CommonHelper extends AppHelper {
 		}
 
 		if ($type == 'language') {
-			return sprintf($tags['meta'],'language',' content="'.$value.'"');
+			return sprintf($tags['meta'], 'language', ' content="'.$value.'"');
 		} elseif ($type == 'pragma') {
-			return sprintf($tags['meta'],'pragma',' content="'.$value.'"');
+			return sprintf($tags['meta'], 'pragma', ' content="'.$value.'"');
 		} elseif ($type == 'expires') {
-			return sprintf($tags['meta'],'expires',' content="'.$value.'"');
+			return sprintf($tags['meta'], 'expires', ' content="'.$value.'"');
 		} elseif ($type == 'cache-control') {
-			return sprintf($tags['meta'],'cache-control',' content="'.$value.'"');
+			return sprintf($tags['meta'], 'cache-control', ' content="'.$value.'"');
 		} elseif ($type == 'refresh') {
-			return sprintf($tags['meta'],'refresh',' content="'.$value.'"');
+			return sprintf($tags['meta'], 'refresh', ' content="'.$value.'"');
 		}
 		return '';
 	}
@@ -178,6 +198,7 @@ class CommonHelper extends AppHelper {
 	 * => x is in webroot/
 	 * => y is in plugins/tools/webroot/
 	 * => z is in plugins/tools/packages/jquery/files/jquery/sub/
+	 * @return string $htmlMarkup
 	 * 2011-03-23 ms
 	 */
 	public function css($files = array(), $rel = null, $options = array()) {
@@ -198,6 +219,7 @@ class CommonHelper extends AppHelper {
 	 * => x is in webroot/
 	 * => y is in plugins/tools/webroot/
 	 * => z is in plugins/tools/packages/jquery/files/jquery/sub/
+	 * @return string $htmlMarkup
 	 * 2011-03-23 ms
 	 */
 	public function script($files = array(), $options = array()) {
@@ -218,6 +240,7 @@ class CommonHelper extends AppHelper {
 	 * IN USAGE
 	 * needs manual adjustment, but still better than the core one!
 	 * @example needs Asset.cssversion => xyz (going up with counter)
+	 * @return string $htmlMarkup
 	 * 2008-12-08 ms
 	 */
 	public function cssDyn($path, $rel = null, $htmlAttributes = array(), $return = true) {
@@ -229,6 +252,7 @@ class CommonHelper extends AppHelper {
 	 * NOT IN USAGE
 	 * but better than the core one!
 	 * @example needs Asset.timestamp => force
+	 * @return string $htmlMarkup
 	 * 2008-12-08 ms
 	 */
 	public function cssAuto($path, $rel = null, $htmlAttributes = array(), $return = true) {
@@ -239,9 +263,15 @@ class CommonHelper extends AppHelper {
 	 	return $url;
 	}
 
-/* Content Stuff */
 
-	public function displayErrors($fields = null) {
+/*** Content Stuff ***/
+
+	/**
+	 * still necessary?
+	 * @param array $fields
+	 * @return string $html
+	 */
+	public function displayErrors($fields = array()) {
 		$res = '';
 		if (!empty($this->validationErrors)) {
 			if ($fields === null) { # catch ALL
@@ -270,15 +300,13 @@ class CommonHelper extends AppHelper {
 		return $res;
 	}
 
-	public function _renderError($error, $escape = true) {
+	protected function _renderError($error, $escape = true) {
 		if ($escape !== false) {
 			$error = h($error);
 		}
 		return '<div class="error-message">'.$error.'</div>';
 	}
 
-
-
 	/**
 	 * Alternates between two or more strings.
 	 *
@@ -308,6 +336,7 @@ class CommonHelper extends AppHelper {
 
 	/**
 	 * check if session works due to allowed cookies
+	 *
 	 * 2009-06-29 ms
 	 */
 	public function sessionCheck() {
@@ -343,7 +372,7 @@ class CommonHelper extends AppHelper {
 		if ((int)$c != 1) {
 			$p = Inflector::pluralize($s);
 		} else {
-		 		$p = null; # no pluralization neccessary
+		 		$p = null; # no pluralization necessary
 		}
 		return $this->sp($s, $p, $c, $autoTranslate);
 	}
@@ -351,6 +380,11 @@ class CommonHelper extends AppHelper {
 	/**
 	 * //TODO: move boostrap
 	 * manual pluralizing a word using the Inflection class
+	 *
+	 * @param string $singular
+	 * @param string $plural
+	 * @param int $count
+	 * @return string $result
 	 * 2009-07-23 ms
 	 */
 	public function sp($s, $p, $c, $autoTranslate = false) {
@@ -367,46 +401,6 @@ class CommonHelper extends AppHelper {
 	}
 
 	/**
-	 * @deprecated
-	 */
-	public function showDebug() {
-		$output = '';
-		$groupout = '';
-		foreach (debugTab::$content as $group => $debug) {
-			if (is_int($group)) {
-				$output .= '<div class="common-debug">';
-				$output .= "<span style=\"cursor:pointer\" onclick=\"$(this).parent().children('pre').slideToggle('fast');\"><strong>" . h($debug['file']) . '</strong>';
-				$output .= ' (line <strong>' . $debug['line'] . '</strong>)</span>';
-				if ($debug['display'])
-					$debug['display'] = 'block';
-				else
-					$debug['display'] = 'none';
-				$output .= "\n<pre style=\"display:" . $debug['display'] . "\" class=\"cake-debug\">\n";
-				$output .= h($debug['debug']);
-				$output .= "\n</pre>\n</div>";
-			}
-		}
-		foreach (debugTab::$groups as $group => $data) {
-			$groupout .= '<div class="common-debug">';
-			$groupout .= "<span style=\"cursor:pointer\" onclick=\"$(this).parent().children('div').slideToggle('fast');\"><strong>" . h($group) . '</strong></span>';
-			foreach ($data as $debug) {
-				$groupout .= "<div style=\"display:none\"><br/><span style=\"cursor:pointer\" onclick=\"$(this).parent().children('pre').slideToggle('fast');\"><strong>" . h($debug['file']) . '</strong></span>';
-				$groupout .= ' (line <strong>' . h($debug['line']) . '</strong>)</span>';
-				if ($debug['display'])
-					$debug['display'] = 'block';
-				else
-					$debug['display'] = 'none';
-				$groupout .= "\n<pre style=\"display:" . $debug['display'] . "\" class=\"cake-debug\">\n";
-				$groupout .= h($debug['debug']);
-				$groupout .= "\n</pre>\n</div>";
-			}
-			$groupout .= "\n</div>";
-		}
-		return $groupout . $output;
-	}
-
-
-	/**
 	 * Show FlashMessages
 	 * @param boolean unsorted true/false [default:FALSE = sorted by priority]
 	 * TODO: export div wrapping method (for static messaging on a page)
@@ -470,95 +464,23 @@ class CommonHelper extends AppHelper {
 
 	/**
 	 * add a message on the fly
+	 *
+	 * @param string $msg
+	 * @param string $class
+	 * @return bool $success
 	 * 2011-05-25 ms
 	 */
 	public function transientFlashMessage($msg, $class = null) {
 		return CommonComponent::transientFlashMessage($msg, $class);
 	}
 
-
-	/**
-	 * SINGLE ROLES function
-	 * currently: isRole('admin'), isRole('user')
-	 * 2009-07-06 ms
-	 */
-	public function isRole($role) {
-		$sessionRole = $this->Session->read('Auth.User.role_id');
-		$roles = array(
-			ROLE_USER => 'user',
-			ROLE_ADMIN => 'admin',
-			ROLE_SUPERADMIN => 'superadmin',
-			ROLE_GUEST => 'guest',
-		);
-		if (!empty($roles[$sessionRole]) && $role = $roles[$sessionRole]) {
-			return true;
-		}
-		return false;
-	}
-
 	/**
-	 * Checks if a role is in the current users session
-	 * @param neccessary 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
-	 */
-	public function roleNames($sessionRoles = null) {
-		$tmp = array();
-
-		if ($sessionRoles === null) {
-			$sessionRoles = $this->Session->read('Auth.User.Role');
-		}
-
-		$roles = Cache::read('User.Role');
-
-		if (empty($roles) || !is_array($roles)) {
-			$Role = ClassRegistry::init('Role');
-			/*
-			if ($Role->useDbConfig == 'test_suite') {
-				return array();
-			}
-			*/
-			$roles = $Role->getActive('list');
-			Cache::write('User.Role', $roles);
-		}
-		//$roleKeys = Set::combine($roles, '/Role/id','/Role/name'); // on find(all)
-		if (!empty($sessionRoles)) {
-			if (is_array($sessionRoles)) {
-
-				foreach ($sessionRoles as $sessionRole) {
-					if (!$sessionRole) {
-					continue;
-					}
-					if (array_key_exists((int)$sessionRole, $roles)) {
-						$tmp[$sessionRole] = $roles[(int)$sessionRole];
-					}
-				}
-			} else {
-				if (array_key_exists($sessionRoles, $roles)) {
-					$tmp[$sessionRoles] = $roles[$sessionRoles];
-				}
-			}
-		}
-
-		return $tmp;
-	}
-
-	/**
-	 * Display Roles separated by Commas
-	 * 2009-07-17 ms
-	 */
-	public function displayRoles($sessionRoles = null, $placeHolder = '---') {
-		$roles = $this->roleNames($sessionRoles);
-		if (!empty($roles)) {
-			return implode(', ',$roles);
-		}
-		return $placeHolder;
-	}
-
-
-	/**
-	 * escape text
+	 * TODO: move into TextExt?
+	 * escape text with some more automagic
+	 *
 	 * @param string $text
-	 * @param options
+	 * @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)
@@ -597,66 +519,6 @@ class CommonHelper extends AppHelper {
 		return $text;
 	}
 
-	/**
-	 * takes int / array(int) and finds the role name to it
-	 * @return array roles
-	 */
-	public function roleNamesTranslated($value) {
-		if (empty($value)) { return array(); }
-		$ret = array();
-		$translate = (array)Configure::read('Role');
-		if (is_array($value)) {
-			foreach ($value as $k => $v) {
-				$ret[$v] = __($translate[$v]);
-			}
-		} else {
-			$ret[$value] = __($translate[$value]);
-		}
-		return $ret;
-	}
-
-	/**
-	 * //TODO: move to TextExt?
-	 * minimizes the given url to a maximum length
-	 * @param string $url the url
-	 * @param int $max the maximum length
-	 * @param options
-	 * - placeholder
-	 * @return string the manipulated url (+ eventuell ...)
-	 */
-	public function minimizeUrl($url = null, $max = null, $options = array()) {
-		// check if there is nothing to do
-		if (empty($url) || mb_strlen($url) <= (int)$max)
-			return (string)$url;
-
-		// http:// has not to be displayed, so
-		if (mb_substr($url,0,7) == 'http://')
-			$url = mb_substr($url,7);
-
-		// cut the parameters
-		if (mb_strpos($url,'/') !== false)
-			$url = strtok($url,'/');
-
-		// return if the url is short enough
-		if (mb_strlen($url) <= (int)$max)
-			return $url;
-
-		// otherwise cut a part in the middle (but only if long enough!!!)
-		# TODO: more dynamically
-
-		$placeholder = CHAR_HELLIP;
-		if (!empty($options['placeholder'])) {
-			$placeholder = $options['placeholder'];
-		}
-
-		$end = mb_substr($url,-5,5);
-		$front = mb_substr($url,0,(int)$max - 8);
-		return $front.$placeholder.$end;
-	}
-
-/** should be in format END **/
-
-
 
 
 	/**
@@ -733,42 +595,7 @@ if ($.browser.msie) {
 	}
 
 
-/**
- * Creates an HTML link.
- *
- * If $url starts with "http://" this is treated as an external link. Else,
- * it is treated as a path to controller/action and parsed with the
- * HtmlHelper::url() method.
- *
- * If the $url is empty, $title is used instead.
- *
- * @param  string  $title The content to be wrapped by <a> tags.
- * @param  mixed   $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
- * @param  array   $htmlAttributes Array of HTML attributes.
- * @param  string  $confirmMessage JavaScript confirmation message.
- * @param  boolean $escapeTitle	Whether or not $title should be HTML escaped.
- * @return string	An <a /> element.
- * // core-hack! $rel = null | !!!!!!!!! Somehow causes trouble with routing functionality of this helper function... careful!
- */
-	public function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $rel = null) {
-		if ($url !== null) {
-			/** core-hack $rel (relative to current position/routing) **/
-			if ($rel === true || !is_array($url)) {
-				// leave it as it is
-			} else {
-				$defaultArray = array('admin'=>false, 'prefix'=>0);
-				$url = array_merge($defaultArray,$url);
-			}
-			/** core-hack END **/
-			return $this->Html->link($title, $url, $htmlAttributes, $confirmMessage,  $escapeTitle);
-		}
-	}
-
-
-
-
-/** Stats **/
-
+/*** Stats ***/
 
 	/**
 	 * print js-visit-stats-link to layout
@@ -824,7 +651,177 @@ piwikTracker.enableLinkTracking();
 	}
 
 
-}
+/*** deprecated ***/
+
+	/**
+	 * SINGLE ROLES function
+	 * currently: isRole('admin'), isRole('user')
+	 *
+	 * @deprecated - use Auth class instead
+	 * 2009-07-06 ms
+	 */
+	public function isRole($role) {
+		$sessionRole = $this->Session->read('Auth.User.role_id');
+		$roles = array(
+			ROLE_USER => 'user',
+			ROLE_ADMIN => 'admin',
+			ROLE_SUPERADMIN => 'superadmin',
+			ROLE_GUEST => 'guest',
+		);
+		if (!empty($roles[$sessionRole]) && $role = $roles[$sessionRole]) {
+			return true;
+		}
+		return false;
+	}
+
+	/**
+	 * 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
+	 * @deprecated - use Auth class instead
+	 */
+	public function roleNames($sessionRoles = null) {
+		$tmp = array();
+
+		if ($sessionRoles === null) {
+			$sessionRoles = $this->Session->read('Auth.User.Role');
+		}
+
+		$roles = Cache::read('User.Role');
+
+		if (empty($roles) || !is_array($roles)) {
+			$Role = ClassRegistry::init('Role');
+			/*
+			if ($Role->useDbConfig == 'test_suite') {
+				return array();
+			}
+			*/
+			$roles = $Role->getActive('list');
+			Cache::write('User.Role', $roles);
+		}
+		//$roleKeys = Set::combine($roles, '/Role/id','/Role/name'); // on find(all)
+		if (!empty($sessionRoles)) {
+			if (is_array($sessionRoles)) {
+
+				foreach ($sessionRoles as $sessionRole) {
+					if (!$sessionRole) {
+					continue;
+					}
+					if (array_key_exists((int)$sessionRole, $roles)) {
+						$tmp[$sessionRole] = $roles[(int)$sessionRole];
+					}
+				}
+			} else {
+				if (array_key_exists($sessionRoles, $roles)) {
+					$tmp[$sessionRoles] = $roles[$sessionRoles];
+				}
+			}
+		}
+
+		return $tmp;
+	}
+
+	/**
+	 * Display Roles separated by Commas
+	 * @deprecated - use Auth class instead
+	 * 2009-07-17 ms
+	 */
+	public function displayRoles($sessionRoles = null, $placeHolder = '---') {
+		$roles = $this->roleNames($sessionRoles);
+		if (!empty($roles)) {
+			return implode(', ',$roles);
+		}
+		return $placeHolder;
+	}
+
+	/**
+	 * takes int / array(int) and finds the role name to it
+	 * @return array roles
+	 */
+	public function roleNamesTranslated($value) {
+		if (empty($value)) { return array(); }
+		$ret = array();
+		$translate = (array)Configure::read('Role');
+		if (is_array($value)) {
+			foreach ($value as $k => $v) {
+				$ret[$v] = __($translate[$v]);
+			}
+		} else {
+			$ret[$value] = __($translate[$value]);
+		}
+		return $ret;
+	}
 
+	/**
+	 * @deprecated
+	 */
+	public function showDebug() {
+		$output = '';
+		$groupout = '';
+		foreach (debugTab::$content as $group => $debug) {
+			if (is_int($group)) {
+				$output .= '<div class="common-debug">';
+				$output .= "<span style=\"cursor:pointer\" onclick=\"$(this).parent().children('pre').slideToggle('fast');\"><strong>" . h($debug['file']) . '</strong>';
+				$output .= ' (line <strong>' . $debug['line'] . '</strong>)</span>';
+				if ($debug['display'])
+					$debug['display'] = 'block';
+				else
+					$debug['display'] = 'none';
+				$output .= "\n<pre style=\"display:" . $debug['display'] . "\" class=\"cake-debug\">\n";
+				$output .= h($debug['debug']);
+				$output .= "\n</pre>\n</div>";
+			}
+		}
+		foreach (debugTab::$groups as $group => $data) {
+			$groupout .= '<div class="common-debug">';
+			$groupout .= "<span style=\"cursor:pointer\" onclick=\"$(this).parent().children('div').slideToggle('fast');\"><strong>" . h($group) . '</strong></span>';
+			foreach ($data as $debug) {
+				$groupout .= "<div style=\"display:none\"><br/><span style=\"cursor:pointer\" onclick=\"$(this).parent().children('pre').slideToggle('fast');\"><strong>" . h($debug['file']) . '</strong></span>';
+				$groupout .= ' (line <strong>' . h($debug['line']) . '</strong>)</span>';
+				if ($debug['display'])
+					$debug['display'] = 'block';
+				else
+					$debug['display'] = 'none';
+				$groupout .= "\n<pre style=\"display:" . $debug['display'] . "\" class=\"cake-debug\">\n";
+				$groupout .= h($debug['debug']);
+				$groupout .= "\n</pre>\n</div>";
+			}
+			$groupout .= "\n</div>";
+		}
+		return $groupout . $output;
+	}
 
+	/**
+	 * Creates an HTML link.
+	 *
+	 * If $url starts with "http://" this is treated as an external link. Else,
+	 * it is treated as a path to controller/action and parsed with the
+	 * HtmlHelper::url() method.
+	 *
+	 * If the $url is empty, $title is used instead.
+	 *
+	 * @param  string  $title The content to be wrapped by <a> tags.
+	 * @param  mixed   $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
+	 * @param  array   $htmlAttributes Array of HTML attributes.
+	 * @param  string  $confirmMessage JavaScript confirmation message.
+	 * @param  boolean $escapeTitle	Whether or not $title should be HTML escaped.
+	 * @return string	An <a /> element.
+	 * @deprecated?
+	 * // core-hack! $rel = null | !!!!!!!!! Somehow causes trouble with routing functionality of this helper function... careful!
+	 */
+	public function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true, $rel = null) {
+		if ($url !== null) {
+			/** core-hack $rel (relative to current position/routing) **/
+			if ($rel === true || !is_array($url)) {
+				// leave it as it is
+			} else {
+				$defaultArray = array('admin'=>false, 'prefix'=>0);
+				$url = array_merge($defaultArray,$url);
+			}
+			/** core-hack END **/
+			return $this->Html->link($title, $url, $htmlAttributes, $confirmMessage,  $escapeTitle);
+		}
+	}
 
+}

+ 1 - 1
View/Helper/FlattrHelper.php

@@ -28,7 +28,7 @@ class FlattrHelper extends AppHelper {
 
 	/**
 	 * display the FlattrButton
-	 * @param mixed $url (unique! neccessary)
+	 * @param mixed $url (unique! necessary)
 	 * @param array $options
 	 * 2010-12-19 ms
 	 */

+ 1 - 1
View/Helper/FormExtHelper.php

@@ -884,7 +884,7 @@ jQuery(\''.$selector.'\').maxlength('.$this->Js->object($settings, array('quoteK
 	/**
 	 * //TODO
 	 * @param jquery: defaults to null = no jquery markup
-	 * - url, data, object (one is neccessary), options
+	 * - url, data, object (one is necessary), options
 	 * 2010-01-27 ms
 	 */
 	public function autoComplete($field = null, $options = array(), $jquery = null) {

+ 1 - 1
View/Helper/FormatHelper.php

@@ -515,7 +515,7 @@ class FormatHelper extends TextHelper {
 	 * Helper Function to Obfuscate Email by inserting a span tag (not more! not very secure on its own...)
 	 * each part of this mail now does not make sense anymore on its own
 	 * (striptags will not work either)
-	 * @param string email: neccessary (and valid - containing one @)
+	 * @param string email: necessary (and valid - containing one @)
 	 * 2009-03-11 ms
 	 */
 	public function encodeEmail($mail) {

+ 39 - 1
View/Helper/TextExtHelper.php

@@ -112,7 +112,7 @@ class TextExtHelper extends TextHelper {
 	 * Helper Function to Obfuscate Email by inserting a span tag (not more! not very secure on its own...)
 	 * each part of this mail now does not make sense anymore on its own
 	 * (striptags will not work either)
-	 * @param string email: neccessary (and valid - containing one @)
+	 * @param string email: necessary (and valid - containing one @)
 	 * @return string $html
 	 * 2009-03-11 ms
 	 */
@@ -291,6 +291,44 @@ class TextExtHelper extends TextHelper {
 	}
 
 	/**
+	 * minimizes the given url to a maximum length
+	 *
+	 * @param string $url the url
+	 * @param int $max the maximum length
+	 * @param array $options
+	 * - placeholder
+	 * @return string the manipulated url (+ eventuell ...)
+	 */
+	public function minimizeUrl($url = null, $max = null, $options = array()) {
+		// check if there is nothing to do
+		if (empty($url) || mb_strlen($url) <= (int)$max) {
+			return (string)$url;
+		}
+		// http:// has not to be displayed, so
+		if (mb_substr($url,0,7) == 'http://') {
+			$url = mb_substr($url, 7);
+		}
+		// cut the parameters
+		if (mb_strpos($url, '/') !== false) {
+			$url = strtok($url, '/');
+		}
+		// return if the url is short enough
+		if (mb_strlen($url) <= (int)$max) {
+			return $url;
+		}
+		// otherwise cut a part in the middle (but only if long enough!!!)
+		# TODO: more dynamically
+		$placeholder = CHAR_HELLIP;
+		if (!empty($options['placeholder'])) {
+			$placeholder = $options['placeholder'];
+		}
+
+		$end = mb_substr($url, -5, 5);
+		$front = mb_substr($url, 0, (int)$max - 8);
+		return $front . $placeholder . $end;
+	}
+
+	/**
 	 * Transforming int values into ordinal numbers (1st, 3rd, etc.)
 	 * @param $num (INT) - the number to be suffixed.
 	 * @param $sup (BOOL) - whether to wrap the suffix in a superscript (<sup>) tag on output.