Browse Source

Correct GoogleMapV3Helper regressions and remove 2.3 only features as 2.4 is the current stable branch.

euromark 12 years ago
parent
commit
ebf844fe4d

+ 1 - 1
Lib/RandomLib.php

@@ -315,7 +315,7 @@ class RandomLib {
 		}
 
 		// Make sure alnum strings contain at least one letter and one digit
-		if ($type === 'alnum' and $length > 1) {
+		if ($type === 'alnum' && $length > 1) {
 			if (ctype_alpha($str)) {
 				// Add a random digit
 				$str[mt_rand(0, $length - 1)] = chr(mt_rand(48, 57));

+ 1 - 1
Lib/Utility/NumberLib.php

@@ -312,7 +312,7 @@ class NumberLib extends CakeNumber {
 	 * @return string
 	 */
 	public static function ordinal($number) {
-		if ($number % 100 > 10 and $number % 100 < 14) {
+		if ($number % 100 > 10 && $number % 100 < 14) {
 			return 'th';
 		}
 		switch ($number % 10) {

+ 15 - 0
Lib/Utility/TextLib.php

@@ -69,6 +69,21 @@ class TextLib extends String {
 	}
 
 	/**
+	 * Count chars in a text.
+	 *
+	 * Options:
+	 * - 'whitespace': If whitespace should be counted, as well, defaults to false
+	 *
+	 * @param string $text
+	 * @return integer
+	 */
+	public static function numberOfChars($text, $options = array()) {
+		$text = str_replace(array("\r", "\n", "\t", ' '), '', $text);
+		$count = mb_strlen($text);
+		return $count;
+	}
+
+	/**
 	 * Return an abbreviated string, with characters in the middle of the
 	 * excessively long string replaced by $ending.
 	 *

+ 1 - 1
Lib/ZipLib.php

@@ -210,7 +210,7 @@ class ZipLib {
 		);
 		$errmsg = 'unknown';
 		foreach ($zipFileFunctionsErrors as $constName => $errorMessage) {
-			if (defined($constName) and constant($constName) === $errno) {
+			if (defined($constName) && constant($constName) === $errno) {
 				return 'Zip File Function error: ' . $errorMessage;
 			}
 		}

+ 5 - 5
View/Helper/GoogleMapV3Helper.php

@@ -661,7 +661,7 @@ function geocodeAddress(address) {
 	public function addInfoContent($content) {
 		$this->infoContents[self::$markerCount] = $this->escapeString($content);
 		$event = "
-			gWindowContents" . self::$mapCount . " .push(" . $this->escapeString($content) . ");
+			gWindowContents" . self::$mapCount . ".push(" . $this->escapeString($content) . ");
 			";
 		$this->addCustom($event);
 
@@ -716,13 +716,13 @@ function geocodeAddress(address) {
 
 /*
 var iconImage = new google.maps.MarkerImage('images/' + images[0] + ' .png',
-	new google.maps. size(iconData[images[0]].width, iconData[images[0]].height),
+	new google.maps.Size(iconData[images[0]].width, iconData[images[0]].height),
 	new google.maps.Point(0,0),
 	new google.maps.Point(0, 32)
 );
 
 var iconShadow = new google.maps.MarkerImage('images/' + images[1] + ' .png',
-	new google.maps. size(iconData[images[1]].width, iconData[images[1]].height),
+	new google.maps.Size(iconData[images[1]].width, iconData[images[1]].height),
 	new google.maps.Point(0,0),
 	new google.maps.Point(0, 32)
 );
@@ -805,7 +805,7 @@ var iconShape = {
 		}
 
 		$icon = 'new google.maps.MarkerImage(\'' . $url . '\',
-	new google.maps. size(' . $options['size']['width'] . ', ' . $options['size']['height'] . '),
+	new google.maps.Size(' . $options['size']['width'] . ', ' . $options['size']['height'] . '),
 	new google.maps.Point(' . $options['origin']['width'] . ', ' . $options['origin']['height'] . '),
 	new google.maps.Point(' . $options['anchor']['width'] . ', ' . $options['anchor']['height'] . ')
 )';
@@ -832,7 +832,7 @@ var iconShape = {
 		}
 
 		$windows = "
-			gInfoWindows" . self::$mapCount . " .push( new google.maps.InfoWindow({
+			gInfoWindows" . self::$mapCount . ".push(new google.maps.InfoWindow({
 					position: {$position},
 					content: " . $this->escapeString($options['content']) . ",
 					maxWidth: {$options['maxWidth']},

+ 14 - 0
View/Helper/MyHelper.php

@@ -162,9 +162,16 @@ class MyHelper extends Helper {
 	 * @return string Link
 	 */
 	public function completeLink($title, $url = null, $options = array(), $confirmMessage = false) {
+		// Named are deprecated
 		if (is_array($url)) {
 			$url += $this->params['named'];
 		}
+		if (is_array($url)) {
+			if (!isset($url['?'])) {
+				$url['?'] = array();
+			}
+			$url['?'] += $this->request->query;
+		}
 		return $this->link($title, $url, $options, $confirmMessage);
 	}
 
@@ -175,9 +182,16 @@ class MyHelper extends Helper {
 	 * @return string Link
 	 */
 	public function completeUrl($url = null, $full = false, $escape = true) {
+		// Named are deprecated
 		if (is_array($url)) {
 			$url += $this->params['named'];
 		}
+		if (is_array($url)) {
+			if (!isset($url['?'])) {
+				$url['?'] = array();
+			}
+			$url['?'] += $this->request->query;
+		}
 		return $this->url($url, $options, $escape);
 	}
 

+ 14 - 25
View/Helper/TextExtHelper.php

@@ -5,8 +5,8 @@ App::uses('HtmlHelper', 'View/Helper');
 App::uses('View', 'View');
 
 /**
- * The core text helper is unsecure and outdated in functionality
- * this aims to compensate the deficiencies
+ * The core text helper is unsecure and outdated in functionality.
+ * This aims to compensate the deficiencies.
  *
  * autoLinkEmails
  * - obfuscate (defaults to FALSE right now)
@@ -22,31 +22,20 @@ App::uses('View', 'View');
 class TextExtHelper extends TextHelper {
 
 	/**
-	 * Formats paragraphs around given text for all line breaks
-	 *  <br /> added for single line return
-	 *  <p> added for double line return
+	 * Constructor
 	 *
-	 * @param string $text Text
-	 * @return string The text with proper <p> and <br /> tags
-	 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoParagraph
+	 * ### Settings:
+	 *
+	 * - `engine` Class name to use to replace String functionality.
+	 *            The class needs to be placed in the `Utility` directory.
+	 *
+	 * @param View $View the view object the helper is attached to.
+	 * @param array $settings Settings array Settings array
+	 * @throws CakeException when the engine class could not be found.
 	 */
-	public function autoParagraph($text) {
-		// for cake >= 2.4
-		if (method_exists(get_parent_class(), 'autoParagraph')) {
-			return parent::autoParagraph($text);
-		}
-
-		if (trim($text) !== '') {
-			$text = preg_replace('|<br[^>]*>\s*<br[^>]*>|i', "\n\n", $text . "\n");
-			$text = preg_replace("/\n\n+/", "\n\n", str_replace(array("\r\n", "\r"), "\n", $text));
-			$texts = preg_split('/\n\s*\n/', $text, -1, PREG_SPLIT_NO_EMPTY);
-			$text = '';
-			foreach ($texts as $txt) {
-				$text .= '<p>' . nl2br(trim($txt, "\n")) . "</p>\n";
-			}
-			$text = preg_replace('|<p>\s*</p>|', '', $text);
-		}
-		return $text;
+	public function __construct(View $View, $settings = array()) {
+		$settings = Hash::merge(array('engine' => 'Tools.TextLib'), $settings);
+		parent::__construct($View, $settings);
 	}
 
 	/**