Browse Source

fixes and cleanup

euromark 12 years ago
parent
commit
6be9d3d19e

+ 3 - 3
Lib/Utility/Utility.php

@@ -35,17 +35,17 @@ class Utility {
 		if ($safe === null) {
 			$safe = false;
 		}
-		if (!$safe && env('HTTP_X_FORWARDED_FOR') != null) {
+		if (!$safe && env('HTTP_X_FORWARDED_FOR')) {
 			$ipaddr = preg_replace('/(?:,.*)/', '', env('HTTP_X_FORWARDED_FOR'));
 		} else {
-			if (env('HTTP_CLIENT_IP') != null) {
+			if (env('HTTP_CLIENT_IP')) {
 				$ipaddr = env('HTTP_CLIENT_IP');
 			} else {
 				$ipaddr = env('REMOTE_ADDR');
 			}
 		}
 
-		if (env('HTTP_CLIENTADDRESS') != null) {
+		if (env('HTTP_CLIENTADDRESS')) {
 			$tmpipaddr = env('HTTP_CLIENTADDRESS');
 
 			if (!empty($tmpipaddr)) {

+ 1 - 1
Model/Behavior/LogableBehavior.php

@@ -151,7 +151,7 @@ class LogableBehavior extends ModelBehavior {
 		$defaults = array(
 			 $this->settings[$Model->alias]['classField'] => null,
 			 'action' => null,
-			 'order' => $this->Log->alias . 'id DESC',
+			 'order' => $this->Log->alias . '.id DESC',
 			 $this->settings[$Model->alias]['userKey'] => null,
 			 'conditions' => array(),
 			 $this->settings[$Model->alias]['foreignKey'] => null,

+ 3 - 3
Model/Token.php

@@ -109,11 +109,11 @@ class Token extends ToolsAppModel {
 		if (empty($type) || empty($key)) {
 			return false;
 		}
-		$conditions = array('conditions'=>array($this->alias.'.key'=>$key, $this->alias.'.type'=>$type));
+		$options = array('conditions' => array($this->alias.'.key' => $key, $this->alias.'.type' => $type));
 		if (!empty($uid)) {
-			$conditions['conditions'][$this->alias.'.user_id'] = $uid;
+			$options['conditions'][$this->alias.'.user_id'] = $uid;
 		}
-		$res = $this->find('first', $conditions);
+		$res = $this->find('first', $options);
 		if (empty($res)) {
 			return false;
 		}

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

@@ -22,7 +22,7 @@ class CommonHelperTest extends MyCakeTestCase {
 	public function testMetaCanonical() {
 		$is = $this->Common->metaCanonical('/some/url/param1');
 		$this->out(h($is));
-		$this->assertEquals('<link rel="canonical" href="'.$this->Common->url('/some/url/param1').'" />', trim($is));
+		$this->assertEquals('<link href="'.$this->Common->url('/some/url/param1', true).'" rel="canonical" />', trim($is));
 	}
 
 	/**

+ 1 - 22
Test/Case/View/Helper/FormatHelperTest.php

@@ -7,17 +7,9 @@ App::uses('View', 'View');
 
 /**
  * Datetime Test Case
- *
- * @package cake.tests
- * @subpackage cake.tests.cases.libs.view.helpers
  */
 class FormatHelperTest extends MyCakeTestCase {
-	/**
-	* setUp method
 
-	* @access public
-	* @return void
-	*/
 	public function setUp() {
 		parent::setUp();
 
@@ -25,7 +17,6 @@ class FormatHelperTest extends MyCakeTestCase {
 		$this->Format->Html = new HtmlHelper(new View(null));
 	}
 
-
 	/**
 	 * 2009-08-30 ms
 	 */
@@ -43,7 +34,6 @@ class FormatHelperTest extends MyCakeTestCase {
 		}
 	}
 
-
 	/**
 	 * 2009-08-30 ms
 	 */
@@ -60,7 +50,6 @@ class FormatHelperTest extends MyCakeTestCase {
 		}
 	}
 
-
 	/**
 	 * 2009-08-30 ms
 	 */
@@ -164,8 +153,6 @@ class FormatHelperTest extends MyCakeTestCase {
 
 	}
 
-
-
 	/**
 	 * 2009-08-30 ms
 	 */
@@ -183,10 +170,8 @@ class FormatHelperTest extends MyCakeTestCase {
 			//debug('\''.h($value).'\' becomes \''.h($res).'\'', null, false);
 			$this->assertEquals($expected === null ? $value : $expected, $res);
 		}
-
 	}
 
-
 /**
  * 2009-03-11 ms
  */
@@ -234,7 +219,6 @@ class FormatHelperTest extends MyCakeTestCase {
 
 	}
 
-
 	public function testArray2table() {
 		//echo '<h2>'.__FUNCTION__.'</h2>';
 		$array = array(
@@ -258,15 +242,10 @@ class FormatHelperTest extends MyCakeTestCase {
 		//echo $is;
 	}
 
-/**
- * tearDown method
- *
- * @access public
- * @return void
- */
 	public function tearDown() {
 		parent::tearDown();
 
 		unset($this->Format);
 	}
+
 }

+ 5 - 25
View/Helper/CommonHelper.php

@@ -66,7 +66,7 @@ class CommonHelper extends AppHelper {
 		if (!empty($language)) {
 			$options['lang'] = mb_strtolower($language);
 		} elseif ($language !== false) {
-			$options['lang'] = Configure::read('Config.locale'); // DEFAULT_LANGUAGE
+			$options['lang'] = Configure::read('Config.locale');
 		}
 		return $this->Html->meta('description', $content, $options);
 	}
@@ -92,7 +92,7 @@ class CommonHelper extends AppHelper {
 		if (!empty($language)) {
 			$options['lang'] = mb_strtolower($language);
 		} elseif ($language !== false) {
-			$options['lang'] = Configure::read('Config.locale'); // DEFAULT_LANGUAGE
+			$options['lang'] = Configure::read('Config.locale');
 		}
 		return $this->Html->meta('keywords', $keywords, $options);
 	}
@@ -107,8 +107,7 @@ class CommonHelper extends AppHelper {
 	 */
 	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 $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
 	}
 
 	/**
@@ -280,14 +279,6 @@ class CommonHelper extends AppHelper {
 					}
 				}
 			}
-
-			/*
-			if (!empty($catched)) {
-				foreach ($catched as $c) {
-
-				}
-			}
-			*/
 		}
 		return $res;
 	}
@@ -308,7 +299,7 @@ class CommonHelper extends AppHelper {
 	 *
 	 * Note that using multiple iterations of different strings may produce
 	 * unexpected results.
-	 * TODO: move to booststrap!!!
+	 * TODO: move to booststrap/lib!!!
 	 *
 	 * @param string strings to alternate between
 	 * @return string
@@ -521,7 +512,7 @@ class CommonHelper extends AppHelper {
 	}
 
 	/**
-	 * prevents site being opened/included by others/websites inside frames
+	 * Prevents site being opened/included by others/websites inside frames
 	 * 2009-01-08 ms
 	 */
 	public function framebuster() {
@@ -568,11 +559,6 @@ jQuery(document).ready(function() {
 });
 */
 ');
-/*
-if ($.browser.msie) {
-	var version = $.browser.version.substring(0,1);
-}
-*/
 	}
 
 	/**
@@ -691,15 +677,9 @@ piwikTracker.enableLinkTracking();
 
 		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)) {
 

+ 10 - 4
View/Helper/FormExtHelper.php

@@ -441,7 +441,7 @@ class FormExtHelper extends FormHelper {
 
 		$options = parent::_initInputField($field, $options);
 
-		if (!empty($options['value']) && $normalize) {
+		if (!empty($options['value']) && is_string($options['value']) && $normalize) {
 			$options['value'] = str_replace(array("\t", "\r\n", "\n"), ' ', $options['value']);
 		}
 		//Configure::write('Validation.autoRequire', $autoRequire);
@@ -494,7 +494,13 @@ class FormExtHelper extends FormHelper {
 		}
 	}
 
-
+	/**
+	 * FormExtHelper::dateTimeExt()
+	 *
+	 * @param mixed $field
+	 * @param mixed $options
+	 * @return
+	 */
 	public function dateTimeExt($field, $options = array()) {
 		$res = array();
 		if (!isset($options['separator'])) {
@@ -614,8 +620,8 @@ class FormExtHelper extends FormHelper {
 
 		$defaultOptions = array(
 			'empty' => false,
-			'minYear' => date('Y')-10,
-			'maxYear' => date('Y')+10
+			'minYear' => date('Y') - 10,
+			'maxYear' => date('Y') + 10
 		);
 		$defaultOptions = array_merge($defaultOptions, (array)Configure::read('Form.date'));
 

+ 51 - 75
View/Helper/FormatHelper.php

@@ -1,8 +1,6 @@
 <?php
 App::uses('TextHelper', 'View/Helper');
 
-App::import('Helper', 'Text');
-
 /**
  * Format helper with basic html snippets
  *
@@ -317,11 +315,11 @@ class FormatHelper extends TextHelper {
 	 * @param options array ('class'=>'','width/height'=>'','onclick=>'') etc
 	 * 2008-12-28 ms
 	 */
-	public function icon($type, $t=null, $a=null, $translate=null, $options=array()) {
+	public function icon($type, $t = null, $a = null, $translate = null, $options = array()) {
 		$html='';
 
 		# title
-		if (isset($t) && $t===false) {
+		if (isset($t) && $t === false) {
 			$title='';
 		} elseif (empty($t)) {
 
@@ -354,7 +352,7 @@ class FormatHelper extends TextHelper {
 			$alt = '';
 		}
 
-		$default_options=array('title'=>$title,'alt'=>$alt,'class'=>'icon');
+		$default_options=array('title'=>$title, 'alt'=>$alt, 'class'=>'icon');
 		//$new_options['onclick']=$options['onclick'];
 		$new_options= array_merge($default_options, $options);
 
@@ -431,13 +429,13 @@ class FormatHelper extends TextHelper {
 
 			$text = '';
 			for ($i=0;$i<$min;$i++) {
-				$attributes = array('alt'=>'#','class'=>'full');
+				$attributes = array('alt'=>'#', 'class'=>'full');
 				if (!empty($options['title'])) { $attributes['title'] = ($i+1).'/'.$max; } # ?
 				$text.= $this->Html->image('icons/star_icon2.gif', $attributes);
 
 			}
 			for ($i=$min;$i<$max;$i++) {
-				$attributes = array('alt'=>'-','class'=>'empty');
+				$attributes = array('alt'=>'-', 'class'=>'empty');
 				if (!empty($options['title'])) { $attributes['title'] = ($i+1).'/'.$max; } # ?
 				if ($steps == 0.5 && $current == $i+0.5) {
 					$text.= $this->Html->image('icons/star_icon2_half.gif', $attributes);
@@ -449,15 +447,15 @@ class FormatHelper extends TextHelper {
 			$attributes = array('class'=>'starBar');
 			$attributes = array_merge($attributes, $attr);
 			if (empty($attributes['title']) && empty($options['title'])) {
-				$attributes['title'] = ($current).' '.__('of').' '.$max;
+				$attributes['title'] = ($current) . ' ' . __('of') . ' ' . $max;
 			}
 
 			$res = $this->Html->tag('span', $text, $attributes);
 			//$res='<span title="ss" class="starBar">'.$text.'</span>';
 		} else {
 			if ($max > 3) {
-				for ($i=0;$i<$max-3;$i++) {
-					$res .='-';
+				for ($i = 0; $i < $max - 3; $i++) {
+					$res .= '-';
 				}
 			}
 		}
@@ -488,7 +486,7 @@ class FormatHelper extends TextHelper {
 
 		$language_change = __('Language').': ';
 
-		$languages=array();
+		$languages = array();
 		foreach ($langs as $lang) {
 			$languages[$lang] = $supportedLangs[$lang];
 		}
@@ -508,19 +506,13 @@ class FormatHelper extends TextHelper {
 		}
 
 		$language_change .= '</span>'; //.__('(Translation not complete yet)');
-				//<a href="http://localhost/c/telapp/img/1.php" onclick="return hs.htmlExpand(this, { contentId: 'highslide-help', objectType: 'ajax', preserveContent: true } ); return false;">s</a>
-
-	return $language_change;
+		return $language_change;
 	}
 
-
-
-	/**
-	 * It is still believed that encoding will stop spam-bots being able to find your email address. Nevertheless, encoded email address harvester are on the way
- (http://www.dreamweaverfever.com/experiments/spam/).
- 	 */
-
 	/**
+	 * It is still believed that encoding will stop spam-bots being able to find your email address.
+	 * Nevertheless, encoded email address harvester are on the way (http://www.dreamweaverfever.com/experiments/spam/).
+ 	 *
 	 * //TODO: move to TextExt?
 	 * 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
@@ -530,7 +522,7 @@ class FormatHelper extends TextHelper {
 	 */
 	public function encodeEmail($mail) {
 		list($mail1, $mail2) = explode('@', $mail);
-		$encMail = $this->encodeText($mail1).'<span>@</span>'.$this->encodeText($mail2);
+		$encMail = $this->encodeText($mail1) . '<span>@</span>' . $this->encodeText($mail2);
 		return $encMail;
 	}
 
@@ -544,7 +536,7 @@ class FormatHelper extends TextHelper {
 	 * @return save string with js generated link around email (and non js fallback)
 	 * 2009-04-20 ms
 	 */
-	public function encodeEmailUrl($mail, $text=null, $params=array(), $attr = array()) {
+	public function encodeEmailUrl($mail, $text = null, $params = array(), $attr = array()) {
 		if (empty($class)) { $class='email';}
 
 		$defaults = array(
@@ -559,37 +551,30 @@ class FormatHelper extends TextHelper {
 
 		$encMail = 'mailto:'.$mail;
 
-
 		// additionally there could be a span tag in between: email<span syle="display:none"></span>@web.de
-
-
-		//$encmail = '&#109;a&#105;&#108;t&#111;&#58;'.$encMail;
 		$querystring = '';
 		foreach ($params as $key=>$val) {
 			if ($querystring) {
-				$querystring .= "&$key=".rawurlencode($val);
+				$querystring .= "&$key=" . rawurlencode($val);
 			} else {
-				$querystring = "?$key=".rawurlencode($val);
+				$querystring = "?$key=" . rawurlencode($val);
 			}
 		}
 
 		$attr = array_merge($defaults, $attr);
 
+		$xmail = $this->Html->link('', $encMail . $querystring, $attr);
+		$xmail1 = mb_substr($xmail, 0, count($xmail) - 5);
+		$xmail2 = mb_substr($xmail, -4, 4);
 
-	$xmail = $this->Html->link('', $encMail.$querystring, $attr);
-	$xmail1 = mb_substr($xmail, 0, count($xmail)-5);
-	$xmail2 = mb_substr($xmail, -4, 4);
-	//pr (h($xmail1));
-	//pr (h($xmail2));
-
-	$len = mb_strlen($xmail1);
-	$i=0;
-	while ($i<$len) {
-		$c = mt_rand(2,6);
-		$par[] = (mb_substr($xmail1, $i, $c));
-		$i += $c;
-	}
-	$join = implode('\'+ \'', $par);
+		$len = mb_strlen($xmail1);
+		$i=0;
+		while ($i < $len) {
+			$c = mt_rand(2, 6);
+			$par[] = (mb_substr($xmail1, $i, $c));
+			$i += $c;
+		}
+		$join = implode('\'+ \'', $par);
 
 		return '<script language=javascript><!--
 	document.write(\''.$join.'\');
@@ -598,12 +583,8 @@ class FormatHelper extends TextHelper {
 	<script language=javascript><!--
 	document.write(\''.$xmail2.'\');
 	//--></script>';
-
-
-		//return '<a class="'.$class.'" title="'.$title.'" href="'.$encmail.$querystring.'">'.$encText.'</a>';
 	}
 
-
 	/**
 	 * //TODO: move to TextExt?
 	 * Encodes Piece of Text (without usage of JS!) to avoid spam bots to get it
@@ -658,9 +639,6 @@ class FormatHelper extends TextHelper {
 		return $light;
 	}
 
-
-
-
 	/**
 	 * get url of a png img of a website (16x16 pixel)
 	 * 2011-02-15 ms
@@ -736,7 +714,6 @@ class FormatHelper extends TextHelper {
 			$folder = WWW_ROOT.'img'.DS.'content'.DS.'imagick';
 		}
 
-
 		$file = sha1($text.serialize($options)).'.'.($options['inline'] || !empty($options['background']) ? 'png' : 'gif');
 		if (!file_exists($folder)) {
 			mkdir($folder, 0755);
@@ -758,9 +735,6 @@ class FormatHelper extends TextHelper {
 		return $out;
 	}
 
-
-
-
 	/**
 	 * 2009-12-24 ms
 	 */
@@ -771,13 +745,12 @@ class FormatHelper extends TextHelper {
 		return $this->Html->tag('span', $text, $options);
 	}
 
-
 	/**
 	 * display communication action depending on the current rule/right
 	 * 2009-10-14 ms
 	 */
 	public function action($s) {
-
+		//TODO
 	}
 
 	/**
@@ -813,7 +786,6 @@ class FormatHelper extends TextHelper {
 		return $currentCount;
 	}
 
-
 	/**
 	 * @param float progress
 	 * @param array options:
@@ -841,7 +813,7 @@ class FormatHelper extends TextHelper {
 
 		$params = Router::queryString($options, array(), true);
 
-		App::import('Helper', 'Tools.Numeric');
+		App::uses('NumericHelper', 'Tools.View/Helper');
 		$this->Numeric = new NumericHelper(new View(null));
 
 		$htmlDefaults = array('title' => $this->Numeric->format($percent, $options['decimals']) . ' ' . __('Percent'), 'class' => 'help');
@@ -855,7 +827,6 @@ class FormatHelper extends TextHelper {
 			$htmlOptions['class'] . '" alt="' . $htmlOptions['title'] . '" />';
 	}
 
-
 	public function tip($type, $file, $title, $icon) {
 		return $this->cIcon($icon, $title, null, null, array('class' => 'tip' . ucfirst($type) . ' hand', 'rel' => $file));
 	}
@@ -894,8 +865,6 @@ class FormatHelper extends TextHelper {
 	 * 2009-09-10 ms
 	 */
 	public function image($id, $options = array(), $attr = array()) {
-
-
 		if (!empty($options['h'])) {
 			$attr['height'] = $options['h'];
 		}
@@ -916,7 +885,6 @@ class FormatHelper extends TextHelper {
 		return $urlArray;
 	}
 
-
 	/**
 	 * album image
 	 * 2009-09-10 ms
@@ -952,7 +920,6 @@ class FormatHelper extends TextHelper {
 			$options);
 	}
 
-
 	public function albumImageTexts($image, $options = array()) {
 		$display = array(
 			'title' => true,
@@ -1012,7 +979,6 @@ class FormatHelper extends TextHelper {
 		return $res;
 	}
 
-
 	/**
 	 * takes username + userId and forms a profile link out of it
 	 * if username is empty, return "deleted" text without link
@@ -1061,7 +1027,13 @@ class FormatHelper extends TextHelper {
 
 	}
 
-
+	/**
+	 * FormatHelper::languageFlag()
+	 *
+	 * @param mixed $iso2
+	 * @param mixed $options
+	 * @return string
+	 */
 	public function languageFlag($iso2, $options = array()) {
 		$flag = '';
 
@@ -1072,7 +1044,13 @@ class FormatHelper extends TextHelper {
 		return $flag;
 	}
 
-
+	/**
+	 * FormatHelper::countryAndProvince()
+	 *
+	 * @param mixed $array
+	 * @param mixed $options
+	 * @return string
+	 */
 	public function countryAndProvince($array, $options = array()) {
 		$res = '<span class="help" title="%s">%s</span>';
 
@@ -1098,7 +1076,6 @@ class FormatHelper extends TextHelper {
 		return $res;
 	}
 
-
 	//deprecated?
 	public function avatar($setting, $uid, $email = null, $options = array()) {
 
@@ -1117,7 +1094,6 @@ class FormatHelper extends TextHelper {
 		}
 	}
 
-
 	/**
 	 * display traffic light for status etc
 	 * 2008-12-28 ms
@@ -1142,7 +1118,13 @@ class FormatHelper extends TextHelper {
 		return $this->Html->image('icons/status_light_' . $icon . '.gif', $options);
 	}
 
-
+	/**
+	 * FormatHelper::onlineIcon()
+	 *
+	 * @param mixed $modified
+	 * @param mixed $options
+	 * @return string
+	 */
 	public function onlineIcon($modified = null, $options = array()) {
 		# from low (off) to high (on)
 		$icons = array('healthbar0.gif', 'healthbar1.gif', 'healthbar1b.gif', 'healthbar2.gif', 'healthbar3.gif', 'healthbar4.gif', 'healthbar5.gif');
@@ -1310,7 +1292,6 @@ class FormatHelper extends TextHelper {
 		return $text;
 	}
 
-
 	/**
 	 *
 	 * Inspired by the tab2space function found at:
@@ -1390,7 +1371,6 @@ class FormatHelper extends TextHelper {
 		return trim($str);
 	}
 
-
 	/**
 	 * Translate a result array into a HTML table
 	 *
@@ -1460,9 +1440,6 @@ class FormatHelper extends TextHelper {
 		return $table;
 	}
 
-
-
-
 	public $icons = array(
 		'up' => array(
 			'pic'=>ICON_UP,
@@ -1577,7 +1554,6 @@ class FormatHelper extends TextHelper {
 
 }
 
-
 # default icons
 
 if (!defined('ICON_UP')) {

+ 4 - 4
View/Helper/MyHelper.php

@@ -30,11 +30,11 @@ class MyHelper extends Helper {
 				$helper = $config;
 				$config = array();
 			}
-			list($plugin, $helperName) = pluginSplit($helper);
+			list($plugin, $helperName) = pluginSplit($helper, true);
 			if (isset($this->{$helperName})) {
 				continue;
 			}
-			App::import('Helper', $helper);
+			App::uses($helperName . 'Helper', $plugin . 'View/Helper');
 			$helperFullName = $helperName.'Helper';
 			$this->{$helperName} = new $helperFullName($this->_View, (array)$config);
 
@@ -188,7 +188,7 @@ class MyHelper extends Helper {
 	public function defaultLink($title, $url = null, $options = array(), $confirmMessage = false) {
 		if ($this->linkDefaults === null) {
 			if (!class_exists('CommonComponent')) {
-				App::import('Component', 'Tools.Common');
+				App::uses('CommonComponent', 'Tools.Controller/Component');
 			}
 			$this->linkDefaults = CommonComponent::defaultUrlParams();
 		}
@@ -219,7 +219,7 @@ class MyHelper extends Helper {
 	public function defaultUrl($url = null, $full = false) {
 		if ($this->linkDefaults === null) {
 			if (!class_exists('CommonComponent')) {
-				App::import('Component', 'Tools.Common');
+				App::uses('CommonComponent', 'Tools.Controller/Component');
 			}
 			$this->linkDefaults = CommonComponent::defaultUrlParams();
 		}