Browse Source

coding standards

euromark 13 years ago
parent
commit
2610ac06c2

+ 2 - 2
Controller/Component/Auth/TinyAuthorize.php

@@ -78,7 +78,7 @@ class TinyAuthorize extends BaseAuthorize {
 		} elseif (isset($user[$this->settings['aclKey']])) {
 		} elseif (isset($user[$this->settings['aclKey']])) {
 			$roles = array($user[$this->settings['aclKey']]);
 			$roles = array($user[$this->settings['aclKey']]);
 		} else {
 		} else {
-			$acl = $this->settings['aclModel'].'/'.$this->settings['aclKey'];
+			$acl = $this->settings['aclModel'] . '/' . $this->settings['aclKey'];
 			trigger_error(__d('dev', 'Missing acl information (%s) in user session', $acl));
 			trigger_error(__d('dev', 'Missing acl information (%s) in user session', $acl));
 			$roles = array();
 			$roles = array();
 		}
 		}
@@ -200,7 +200,7 @@ class TinyAuthorize extends BaseAuthorize {
 						if (!($role = trim($role)) || $role === '*') {
 						if (!($role = trim($role)) || $role === '*') {
 							continue;
 							continue;
 						}
 						}
-						$newRole = Configure::read($this->settings['aclModel'].'.'.strtolower($role));
+						$newRole = Configure::read($this->settings['aclModel'] . '.' . strtolower($role));
 						if (!empty($res[$controllerName][$actionName]) && in_array($newRole, $res[$controllerName][$actionName])) {
 						if (!empty($res[$controllerName][$actionName]) && in_array($newRole, $res[$controllerName][$actionName])) {
 							continue;
 							continue;
 						}
 						}

+ 1 - 1
Lib/GeocodeLib.php

@@ -657,7 +657,7 @@ class GeocodeLib {
 	 * fallbacks: cake and php
 	 * fallbacks: cake and php
 	 * note: expects url with json encoded content
 	 * note: expects url with json encoded content
 	 * @access private
 	 * @access private
-	 **/
+	 */
 	protected function _fetch($url) {
 	protected function _fetch($url) {
 		$this->HttpSocket = new HttpSocketLib($this->use);
 		$this->HttpSocket = new HttpSocketLib($this->use);
 		if ($res = $this->HttpSocket->fetch($url, 'CakePHP Geocode Lib')) {
 		if ($res = $this->HttpSocket->fetch($url, 'CakePHP Geocode Lib')) {

+ 3 - 3
Lib/HazardLib.php

@@ -18,7 +18,7 @@ class HazardLib {
 	 * @return array
 	 * @return array
 	 * @static
 	 * @static
 	 * 2010-07-31 ms
 	 * 2010-07-31 ms
-	 **/
+	 */
 	public function sqlStrings($veryDangerousToo = false) {
 	public function sqlStrings($veryDangerousToo = false) {
 		/*
 		/*
 		$res = array(
 		$res = array(
@@ -47,7 +47,7 @@ class HazardLib {
 	 * @return array
 	 * @return array
 	 * @static
 	 * @static
 	 * 2010-07-31 ms
 	 * 2010-07-31 ms
-	 **/
+	 */
 	public function phpStrings() {
 	public function phpStrings() {
 		$res = array(
 		$res = array(
 			'a:100000000:{}', # serialized objects run the magic _ _wakeup() function when they're unserialized
 			'a:100000000:{}', # serialized objects run the magic _ _wakeup() function when they're unserialized
@@ -62,7 +62,7 @@ class HazardLib {
 	 * @return array
 	 * @return array
 	 * @static
 	 * @static
 	 * 2010-07-31 ms
 	 * 2010-07-31 ms
-	 **/
+	 */
 	public function xssStrings($cache = true) {
 	public function xssStrings($cache = true) {
 		if ($cache) {
 		if ($cache) {
 			$texts = Cache::read('security_lib_texts');
 			$texts = Cache::read('security_lib_texts');

+ 1 - 1
Lib/HttpSocketLib.php

@@ -79,7 +79,7 @@ class HttpSocketLib {
 	 * @param string $url
 	 * @param string $url
 	 * @param array $options
 	 * @param array $options
 	 * @return string Response or false on failure
 	 * @return string Response or false on failure
-	 **/
+	 */
 	public function fetch($url, $options = array()) {
 	public function fetch($url, $options = array()) {
 		if (!is_array($options)) {
 		if (!is_array($options)) {
 			$options = array('agent'=>$options);
 			$options = array('agent'=>$options);

+ 13 - 6
Lib/ImapLib.php

@@ -219,11 +219,17 @@ class ImapLib {
 					}
 					}
 
 
 				}
 				}
-				// Let's add the body
-				$return[$msgNo]['body'] = imap_fetchbody($this->stream, $msgNo, 1);
 
 
 				//lets add attachments
 				//lets add attachments
-				$return[$msgNo]['structure'] = imap_fetchstructure($this->stream, $msgNo);
+				$return[$msgNo]['structure'] = (array)imap_fetchstructure($this->stream, $msgNo);
+				$encodingValue = $return[$msgNo]['structure']['encoding'];
+				if (!empty($return[$msgNo]['structure']['parts'])) {
+					$part = $return[$msgNo]['structure']['parts'][0];
+					$encodingValue = $part->encoding;
+				}
+				// Let's add the body
+				$return[$msgNo]['body'] = $this->_getDecodedValue(imap_fetchbody($this->stream, $msgNo, 1), $encodingValue);
+
 				//debug(imap_fetchstructure($this->stream, $header->Msgno, FT_UID));
 				//debug(imap_fetchstructure($this->stream, $header->Msgno, FT_UID));
 				$return[$msgNo]['attachments'] = $this->attachments($header);
 				$return[$msgNo]['attachments'] = $this->attachments($header);
 			}
 			}
@@ -259,8 +265,8 @@ class ImapLib {
 	 */
 	 */
 	public function attachments($header) {
 	public function attachments($header) {
 		$structure = imap_fetchstructure($this->stream, $header->Msgno);
 		$structure = imap_fetchstructure($this->stream, $header->Msgno);
-		if (!$structure) {
-			return false;
+		if (!$structure || !isset($structure->parts)) {
+			return array();
 		}
 		}
 		$parts = $structure->parts;
 		$parts = $structure->parts;
 		$fpos = 2;
 		$fpos = 2;
@@ -352,7 +358,8 @@ class ImapLib {
 		} elseif ($coding == 4) {
 		} elseif ($coding == 4) {
 			$message = imap_qprint($message);
 			$message = imap_qprint($message);
 		} elseif ($coding == 5) {
 		} elseif ($coding == 5) {
-			$message = imap_base64($message);
+			// plain
+			//$message = imap_base64($message);
 		}
 		}
 		return $message;
 		return $message;
 	}
 	}

+ 1 - 1
Lib/UserAgentLib.php

@@ -130,7 +130,7 @@ class UserAgentLib extends CakeRequest {
 	 * fetches url with curl if available
 	 * fetches url with curl if available
 	 * fallbacks: cake and php
 	 * fallbacks: cake and php
 	 * 2010-09-09 ms
 	 * 2010-09-09 ms
-	 **/
+	 */
 	public function getMobileDevices() {
 	public function getMobileDevices() {
 		$is = array(); //$this->RequestHandler->mobileUA;
 		$is = array(); //$this->RequestHandler->mobileUA;
 		$is = $this->_detectors['mobile']['options'];
 		$is = $this->_detectors['mobile']['options'];

+ 12 - 16
Lib/Utility/TimeLib.php

@@ -1042,7 +1042,6 @@ class TimeLib extends CakeTime {
 	 */
 	 */
 	public static function parseLocalizedDate($date, $format = null, $type = 'start') {
 	public static function parseLocalizedDate($date, $format = null, $type = 'start') {
 		$date = trim($date);
 		$date = trim($date);
-		echo returns($date);
 		$i18n = array(
 		$i18n = array(
 			strtolower(__('Today')) => array('start'=>date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), 'end'=>date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')))),
 			strtolower(__('Today')) => array('start'=>date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), 'end'=>date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')))),
 			strtolower(__('Tomorrow')) => array('start'=>date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))+DAY), 'end'=>date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y'))+DAY)),
 			strtolower(__('Tomorrow')) => array('start'=>date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))+DAY), 'end'=>date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y'))+DAY)),
@@ -1163,7 +1162,7 @@ class TimeLib extends CakeTime {
 		$tmp = $value-$base;
 		$tmp = $value-$base;
 
 
 		$tmp *= 100;
 		$tmp *= 100;
-		$tmp *= 1/60;
+		$tmp *= 1 / 60;
 
 
 		$value = $base+$tmp;
 		$value = $base+$tmp;
 		return $value;
 		return $value;
@@ -1177,12 +1176,12 @@ class TimeLib extends CakeTime {
 	 */
 	 */
 	public static function decimalToStandardTime($value, $pad = null, $decPoint = '.') {
 	public static function decimalToStandardTime($value, $pad = null, $decPoint = '.') {
 		$base = (int)$value;
 		$base = (int)$value;
-		$tmp = $value-$base;
+		$tmp = $value - $base;
 
 
-		$tmp /= 1/60;
+		$tmp /= 1 / 60;
 		$tmp /= 100;
 		$tmp /= 100;
 
 
-		$value = $base+$tmp;
+		$value = $base + $tmp;
 		if ($pad === null) {
 		if ($pad === null) {
 			return $value;
 			return $value;
 		}
 		}
@@ -1245,9 +1244,9 @@ class TimeLib extends CakeTime {
 			$year = $pieces[2];
 			$year = $pieces[2];
 			if (strlen($year) === 2) {
 			if (strlen($year) === 2) {
 				if ($year < 50) {
 				if ($year < 50) {
-					$year = '20'.$year;
+					$year = '20' . $year;
 				} else {
 				} else {
-					$year = '19'.$year;
+					$year = '19' . $year;
 				}
 				}
 			}
 			}
 			$date = mktime(0, 0, 0, $pieces[1], $pieces[0], $year);
 			$date = mktime(0, 0, 0, $pieces[1], $pieces[0], $year);
@@ -1261,7 +1260,6 @@ class TimeLib extends CakeTime {
 		return $date;
 		return $date;
 	}
 	}
 
 
-
 	/**
 	/**
 	 * return strings like 2:30 (later //TODO: or 2:33:99) from seconds etc
 	 * return strings like 2:30 (later //TODO: or 2:33:99) from seconds etc
 	 * @param int: seconds
 	 * @param int: seconds
@@ -1276,12 +1274,12 @@ class TimeLib extends CakeTime {
 
 
 		$minutes = $duration % HOUR;
 		$minutes = $duration % HOUR;
 		$hours = ($duration - $minutes) / HOUR;
 		$hours = ($duration - $minutes) / HOUR;
-		$res = (int)$hours.':'.str_pad(intval($minutes/MINUTE), 2, '0', STR_PAD_LEFT);
+		$res = (int)$hours . ':' . str_pad(intval($minutes/MINUTE), 2, '0', STR_PAD_LEFT);
 		if (strpos($mode, 'SS') !== false) {
 		if (strpos($mode, 'SS') !== false) {
 			//TODO
 			//TODO
 		}
 		}
 		if (!empty($isNegative)) {
 		if (!empty($isNegative)) {
-			$res = '-'.$res;
+			$res = '-' . $res;
 		}
 		}
 		return $res;
 		return $res;
 	}
 	}
@@ -1293,14 +1291,12 @@ class TimeLib extends CakeTime {
 	 * 2011-03-09 ms
 	 * 2011-03-09 ms
 	 */
 	 */
 	public static function buildDefaultTime($duration) {
 	public static function buildDefaultTime($duration) {
-		$minutes = $duration%HOUR;
+		$minutes = $duration % HOUR;
 		$duration = $duration - $minutes;
 		$duration = $duration - $minutes;
-		$hours = ($duration)/HOUR;
-
-		//$duration = $minutes*MINUTE;
+		$hours = $duration / HOUR;
 
 
-		$seconds = $minutes%MINUTE;
-		return self::pad($hours).':'.self::pad($minutes/MINUTE).':'.self::pad($seconds/SECOND);
+		$seconds = $minutes % MINUTE;
+		return self::pad($hours) . ':' . self::pad($minutes / MINUTE) . ':' . self::pad($seconds / SECOND);
 	}
 	}
 
 
 	public static function pad($value, $length = 2) {
 	public static function pad($value, $length = 2) {

+ 1 - 0
Model/Behavior/PasswordableBehavior.php

@@ -1,6 +1,7 @@
 <?php
 <?php
 App::uses('ModelBehavior', 'Model');
 App::uses('ModelBehavior', 'Model');
 App::uses('Router', 'Routing');
 App::uses('Router', 'Routing');
+App::uses('CakeRequest', 'Network');
 App::uses('CakeResponse', 'Network');
 App::uses('CakeResponse', 'Network');
 App::uses('Security', 'Utility');
 App::uses('Security', 'Utility');
 
 

+ 1 - 5
Test/Case/View/Helper/TreeHelperTest.php

@@ -362,11 +362,7 @@ TEXT;
 	<ul>
 	<ul>
 		<li class="active">Two-SubA (active)
 		<li class="active">Two-SubA (active)
 		<ul>
 		<ul>
-			<li>Two-SubA-1
-			<ul>
-				<li>Two-SubA-1-1</li>
-			</ul>
-			</li>
+			<li>Two-SubA-1</li>
 		</ul>
 		</ul>
 		</li>
 		</li>
 		<li>Two-SubB</li>
 		<li>Two-SubB</li>

+ 1 - 1
View/Helper/CommonHelper.php

@@ -526,7 +526,7 @@ if (top!=self) top.location.ref=self.location.href;
 	 * - escape
 	 * - escape
 	 * needs the id element to be a present (div) container in the layout
 	 * needs the id element to be a present (div) container in the layout
 	 * 2009-12-26 ms
 	 * 2009-12-26 ms
-	 **/
+	 */
 	public function browserAlert($id, $message, $options = array()) {
 	public function browserAlert($id, $message, $options = array()) {
 		$engine = 'js';
 		$engine = 'js';
 
 

+ 28 - 28
View/Helper/FormatHelper.php

@@ -1310,41 +1310,41 @@ class FormatHelper extends TextHelper {
 	 * @see http://aidan.dotgeek.org/lib/?file=function.tab2space.php
 	 * @see http://aidan.dotgeek.org/lib/?file=function.tab2space.php
 	 */
 	 */
 	public function tab2space($text, $spaces = 4) {
 	public function tab2space($text, $spaces = 4) {
-	$spaces = str_repeat(" ", $spaces);
-	$text = preg_split("/\r\n|\r|\n/", trim($text));
-	$word_lengths = array();
-	$w_array = array();
-
-	// Store word lengths
-	foreach ($text as $line) {
-		$words = preg_split("/(\t+)/", $line, -1, PREG_SPLIT_DELIM_CAPTURE);
-		foreach (array_keys($words) as $i) {
-			$strlen = strlen($words[$i]);
-			$add = isset($word_lengths[$i]) && ($word_lengths[$i] < $strlen);
-			if ($add || !isset($word_lengths[$i])) {
-				$word_lengths[$i] = $strlen;
+		$spaces = str_repeat(" ", $spaces);
+		$text = preg_split("/\r\n|\r|\n/", trim($text));
+		$word_lengths = array();
+		$w_array = array();
+
+		// Store word lengths
+		foreach ($text as $line) {
+			$words = preg_split("/(\t+)/", $line, -1, PREG_SPLIT_DELIM_CAPTURE);
+			foreach (array_keys($words) as $i) {
+				$strlen = strlen($words[$i]);
+				$add = isset($word_lengths[$i]) && ($word_lengths[$i] < $strlen);
+				if ($add || !isset($word_lengths[$i])) {
+					$word_lengths[$i] = $strlen;
+				}
 			}
 			}
+			$w_array[] = $words;
 		}
 		}
-		$w_array[] = $words;
-	}
 
 
-	// Clear $text
-	$text = '';
+		// Clear $text
+		$text = '';
 
 
-	// Apply padding when appropriate and rebuild the string
-	foreach (array_keys($w_array) as $i) {
-		foreach (array_keys($w_array[$i]) as $ii) {
-			if (preg_match("/^\t+$/", $w_array[$i][$ii])) {
-				$w_array[$i][$ii] = str_pad($w_array[$i][$ii], $word_lengths[$ii], "\t");
-			} else {
-				$w_array[$i][$ii] = str_pad($w_array[$i][$ii], $word_lengths[$ii]);
+		// Apply padding when appropriate and rebuild the string
+		foreach (array_keys($w_array) as $i) {
+			foreach (array_keys($w_array[$i]) as $ii) {
+				if (preg_match("/^\t+$/", $w_array[$i][$ii])) {
+					$w_array[$i][$ii] = str_pad($w_array[$i][$ii], $word_lengths[$ii], "\t");
+				} else {
+					$w_array[$i][$ii] = str_pad($w_array[$i][$ii], $word_lengths[$ii]);
+				}
 			}
 			}
+			$text .= str_replace("\t", $spaces, implode("", $w_array[$i])) . "\n";
 		}
 		}
-		$text .= str_replace("\t", $spaces, implode("", $w_array[$i])) . "\n";
-	}
 
 
-	// Finished
-	return $text;
+		// Finished
+		return $text;
 	}
 	}
 
 
 	/**
 	/**

+ 1 - 1
View/Helper/QrCodeHelper.php

@@ -56,7 +56,7 @@ class QrCodeHelper extends AppHelper {
 	 * - chl: string $text
 	 * - chl: string $text
 	 * - choe: string $outputEncoding
 	 * - choe: string $outputEncoding
 	 * - chs: size (...x...)
 	 * - chs: size (...x...)
-	 **/
+	 */
 	protected $options = array('cht'=>'qr', 'chl'=>'', 'choe'=>'', 'chs'=>'');
 	protected $options = array('cht'=>'qr', 'chl'=>'', 'choe'=>'', 'chs'=>'');
 
 
 	protected $ecLevels = array('H', 'Q', 'M', 'L'); # 30%..7%
 	protected $ecLevels = array('H', 'Q', 'M', 'L'); # 30%..7%

+ 2 - 1
View/Helper/TextExtHelper.php

@@ -277,7 +277,8 @@ class TextExtHelper extends TextHelper {
 	}
 	}
 
 
 	/**
 	/**
-	 * remove http:// or other protocols from the link
+	 * Remove http:// or other protocols from the link
+	 *
 	 * @param string $url
 	 * @param string $url
 	 * @return string $strippedUrl
 	 * @return string $strippedUrl
 	 * 2010-11-07 ms
 	 * 2010-11-07 ms

+ 6 - 4
View/Helper/TreeHelper.php

@@ -74,7 +74,7 @@ class TreeHelper extends AppHelper {
  *	'element' => path to an element to render to get node contents.
  *	'element' => path to an element to render to get node contents.
  *	'callback' => callback to use to get node contents. e.g. array(&$anObject, 'methodName') or 'floatingMethod'
  *	'callback' => callback to use to get node contents. e.g. array(&$anObject, 'methodName') or 'floatingMethod'
  *	'autoPath' => array($left, $right [$classToAdd = 'active']) if set any item in the path will have the class $classToAdd added. MPTT only.
  *	'autoPath' => array($left, $right [$classToAdd = 'active']) if set any item in the path will have the class $classToAdd added. MPTT only.
- *  'hideUnrelated' => if unrelated (not children, not siblings) should be hidden, needs 'treePath'
+ *  'hideUnrelated' => if unrelated (not children, not siblings) should be hidden, needs 'treePath', true/false or array/string for callback
  *  'treePath' => treePath to insert into callback/element
  *  'treePath' => treePath to insert into callback/element
  *	'left' => name of the 'lft' field if not lft. only applies to MPTT data
  *	'left' => name of the 'lft' field if not lft. only applies to MPTT data
  *	'right' => name of the 'rght' field if not lft. only applies to MPTT data
  *	'right' => name of the 'rght' field if not lft. only applies to MPTT data
@@ -154,8 +154,10 @@ class TreeHelper extends AppHelper {
 		$this->_settings['totalNodes'] = count($data);
 		$this->_settings['totalNodes'] = count($data);
 		$keys = array_keys($data);
 		$keys = array_keys($data);
 
 
-		if ($hideUnrelated) {
+		if ($hideUnrelated === true) {
 			$this->_markUnrelatedAsHidden($data, $treePath);
 			$this->_markUnrelatedAsHidden($data, $treePath);
+		} elseif ($hideUnrelated && is_callable($hideUnrelated)) {
+			call_user_func($data, $treePath);
 		}
 		}
 
 
 		foreach ($data as $i => &$result) {
 		foreach ($data as $i => &$result) {
@@ -510,14 +512,14 @@ class TreeHelper extends AppHelper {
 				$subTree[$model]['show'] = 1;
 				$subTree[$model]['show'] = 1;
 				$siblingIsActive = true;
 				$siblingIsActive = true;
 			}
 			}
-			if (!empty($subTree[$model]['show']) || !empty($subTree[$model]['parent_show'])) {
+			if (!empty($subTree[$model]['show'])) { //!empty($subTree[$model]['parent_show']
 				foreach ($subTree['children'] as &$v) {
 				foreach ($subTree['children'] as &$v) {
 					$v[$model]['parent_show'] = 1;
 					$v[$model]['parent_show'] = 1;
 				}
 				}
 			}
 			}
 		}
 		}
 		foreach ($tree as $key => &$subTree) {
 		foreach ($tree as $key => &$subTree) {
-			if (!$siblingIsActive && !isset($subTree[$model]['parent_show'])) {
+			if ($level && !$siblingIsActive && !isset($subTree[$model]['parent_show'])) {
 				$subTree[$model]['hide'] = 1;
 				$subTree[$model]['hide'] = 1;
 			}
 			}
 			$this->_markUnrelatedAsHidden($subTree['children'], $path, $level + 1);
 			$this->_markUnrelatedAsHidden($subTree['children'], $path, $level + 1);