Browse Source

Merge branch 'master' into 2.4

Conflicts:
	lib/Cake/Utility/CakeTime.php
	lib/Cake/VERSION.txt
mark_story 12 years ago
parent
commit
26769edd04

+ 1 - 1
app/Controller/PagesController.php

@@ -58,7 +58,7 @@ class PagesController extends AppController {
 
 		$count = count($path);
 		if (!$count) {
-			$this->redirect('/');
+			return $this->redirect('/');
 		}
 		$page = $subpage = $title_for_layout = null;
 

+ 3 - 3
app/View/Layouts/flash.ctp

@@ -23,9 +23,9 @@
 <?php echo $this->Html->charset(); ?>
 <title><?php echo $page_title; ?></title>
 
-<?php if (Configure::read('debug') == 0) { ?>
+<?php if (Configure::read('debug') == 0): ?>
 <meta http-equiv="Refresh" content="<?php echo $pause; ?>;url=<?php echo $url; ?>"/>
-<?php } ?>
+<?php endif; ?>
 <style><!--
 P { text-align:center; font:bold 1.1em sans-serif }
 A { color:#444; text-decoration:none }
@@ -35,4 +35,4 @@ A:HOVER { text-decoration: underline; color:#44E }
 <body>
 <p><a href="<?php echo $url; ?>"><?php echo $message; ?></a></p>
 </body>
-</html>
+</html>

+ 4 - 4
app/View/Layouts/rss/default.ctp

@@ -1,10 +1,10 @@
 <?php
-if (!isset($channel)) {
+if (!isset($channel)):
 	$channel = array();
-}
-if (!isset($channel['title'])) {
+endif;
+if (!isset($channel['title'])):
 	$channel['title'] = $title_for_layout;
-}
+endif;
 
 echo $this->Rss->document(
 	$this->Rss->channel(

+ 6 - 6
app/View/Pages/home.ctp

@@ -101,12 +101,12 @@ if (isset($filePresent)):
 	} catch (Exception $connectionError) {
 		$connected = false;
 		$errorMsg = $connectionError->getMessage();
-		if (method_exists($connectionError, 'getAttributes')) {
+		if (method_exists($connectionError, 'getAttributes')):
 			$attributes = $connectionError->getAttributes();
-			if (isset($errorMsg['message'])) {
+			if (isset($errorMsg['message'])):
 				$errorMsg .= '<br />' . $attributes['message'];
-			}
-		}
+			endif;
+		endif;
 	}
 ?>
 <p>
@@ -127,13 +127,13 @@ if (isset($filePresent)):
 <?php endif; ?>
 <?php
 	App::uses('Validation', 'Utility');
-	if (!Validation::alphaNumeric('cakephp')) {
+	if (!Validation::alphaNumeric('cakephp')):
 		echo '<p><span class="notice">';
 			echo __d('cake_dev', 'PCRE has not been compiled with Unicode support.');
 			echo '<br/>';
 			echo __d('cake_dev', 'Recompile PCRE with Unicode support by adding <code>--enable-unicode-properties</code> when configuring');
 		echo '</span></p>';
-	}
+	endif;
 ?>
 
 <p>

+ 8 - 10
lib/Cake/Console/Templates/default/actions/controller_actions.ctp

@@ -58,13 +58,12 @@
 				$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
 				return $this->redirect(array('action' => 'index'));
 <?php else: ?>
-				$this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
+				return $this->flash(__('<?php echo ucfirst(strtolower($currentModelName)); ?> saved.'), array('action' => 'index'));
 <?php endif; ?>
-			} else {
+			}
 <?php if ($wannaUseSession): ?>
-				$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
+			$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
 <?php endif; ?>
-			}
 		}
 <?php
 	foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
@@ -101,13 +100,12 @@
 				$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> has been saved'));
 				return $this->redirect(array('action' => 'index'));
 <?php else: ?>
-				$this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
+				return $this->flash(__('The <?php echo strtolower($singularHumanName); ?> has been saved.'), array('action' => 'index'));
 <?php endif; ?>
-			} else {
+			}
 <?php if ($wannaUseSession): ?>
-				$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
+			$this->Session->setFlash(__('The <?php echo strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
 <?php endif; ?>
-			}
 		} else {
 			$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
 			$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
@@ -147,13 +145,13 @@
 			$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'));
 			return $this->redirect(array('action' => 'index'));
 <?php else: ?>
-			$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
+			return $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> deleted'), array('action' => 'index'));
 <?php endif; ?>
 		}
 <?php if ($wannaUseSession): ?>
 		$this->Session->setFlash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'));
 <?php else: ?>
-		$this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
+		return $this->flash(__('<?php echo ucfirst(strtolower($singularHumanName)); ?> was not deleted'), array('action' => 'index'));
 <?php endif; ?>
 		return $this->redirect(array('action' => 'index'));
 	}

+ 1 - 1
lib/Cake/Console/Templates/skel/Controller/PagesController.php

@@ -50,7 +50,7 @@ class PagesController extends AppController {
 
 		$count = count($path);
 		if (!$count) {
-			$this->redirect('/');
+			return $this->redirect('/');
 		}
 		$page = $subpage = $title_for_layout = null;
 

+ 2 - 3
lib/Cake/Controller/Scaffold.php

@@ -329,10 +329,9 @@ class Scaffold {
 	protected function _sendMessage($message) {
 		if ($this->_validSession) {
 			$this->controller->Session->setFlash($message);
-			$this->controller->redirect($this->redirect);
-		} else {
-			$this->controller->flash($message, $this->redirect);
+			return $this->controller->redirect($this->redirect);
 		}
+		$this->controller->flash($message, $this->redirect);
 	}
 
 /**

+ 1 - 1
lib/Cake/Model/Datasource/DboSource.php

@@ -313,7 +313,7 @@ class DboSource extends DataSource {
  * Returns a quoted and escaped string of $data for use in an SQL statement.
  *
  * @param string $data String to be prepared for use in an SQL statement
- * @param string $column The column into which this data will be inserted
+ * @param string $column The column datatype into which this data will be inserted.
  * @return string Quoted and escaped data
  */
 	public function value($data, $column = null) {

+ 26 - 0
lib/Cake/Test/Case/Utility/CakeTimeTest.php

@@ -248,6 +248,20 @@ class CakeTimeTest extends CakeTestCase {
 		);
 		$expected = '1 year';
 		$this->assertEquals($expected, $result);
+
+		$result = $this->Time->timeAgoInWords(
+			strtotime('+58 minutes'),
+			array('accuracy' => 'hour')
+		);
+		$expected = 'in about an hour';
+		$this->assertEquals($expected, $result);
+
+		$result = $this->Time->timeAgoInWords(
+			strtotime('+23 hours'),
+			array('accuracy' => 'day')
+		);
+		$expected = 'in about a day';
+		$this->assertEquals($expected, $result);
 	}
 
 /**
@@ -335,6 +349,18 @@ class CakeTimeTest extends CakeTestCase {
 			array('end' => '2 years')
 		);
 		$this->assertEquals('1 year, 1 month, 5 days ago', $result);
+
+		$result = $this->Time->timeAgoInWords(
+			strtotime('-58 minutes'),
+			array('accuracy' => 'hour')
+		);
+		$this->assertEquals('about an hour ago', $result);
+
+		$result = $this->Time->timeAgoInWords(
+			strtotime('-23 hours'),
+			array('accuracy' => 'day')
+		);
+		$this->assertEquals('about a day ago', $result);
 	}
 
 /**

+ 1 - 1
lib/Cake/Test/test_app/Controller/PagesController.php

@@ -59,7 +59,7 @@ class PagesController extends AppController {
 
 		$count = count($path);
 		if (!$count) {
-			$this->redirect('/');
+			return $this->redirect('/');
 		}
 		$page = $subpage = $titleForLayout = null;
 

+ 1 - 1
lib/Cake/Test/test_app/Controller/TestsAppsController.php

@@ -49,7 +49,7 @@ class TestsAppsController extends AppController {
 	}
 
 	public function redirect_to() {
-		$this->redirect('http://cakephp.org');
+		return $this->redirect('http://cakephp.org');
 	}
 
 }

+ 44 - 16
lib/Cake/Utility/CakeTime.php

@@ -858,48 +858,76 @@ class CakeTime {
 			return sprintf($absoluteString, date($format, $inSeconds));
 		}
 
-		$f = $accuracy['second'];
+		$fWord = $accuracy['second'];
 		if ($years > 0) {
-			$f = $accuracy['year'];
+			$fWord = $accuracy['year'];
 		} elseif (abs($months) > 0) {
-			$f = $accuracy['month'];
+			$fWord = $accuracy['month'];
 		} elseif (abs($weeks) > 0) {
-			$f = $accuracy['week'];
+			$fWord = $accuracy['week'];
 		} elseif (abs($days) > 0) {
-			$f = $accuracy['day'];
+			$fWord = $accuracy['day'];
 		} elseif (abs($hours) > 0) {
-			$f = $accuracy['hour'];
+			$fWord = $accuracy['hour'];
 		} elseif (abs($minutes) > 0) {
-			$f = $accuracy['minute'];
+			$fWord = $accuracy['minute'];
 		}
 
-		$f = str_replace(array('year', 'month', 'week', 'day', 'hour', 'minute', 'second'), array(1, 2, 3, 4, 5, 6, 7), $f);
+		$fNum = str_replace(array('year', 'month', 'week', 'day', 'hour', 'minute', 'second'), array(1, 2, 3, 4, 5, 6, 7), $fWord);
 
 		$relativeDate = '';
-		if ($f >= 1 && $years > 0) {
+		if ($fNum >= 1 && $years > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d year', '%d years', $years, $years);
 		}
-		if ($f >= 2 && $months > 0) {
+		if ($fNum >= 2 && $months > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d month', '%d months', $months, $months);
 		}
-		if ($f >= 3 && $weeks > 0) {
+		if ($fNum >= 3 && $weeks > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d week', '%d weeks', $weeks, $weeks);
 		}
-		if ($f >= 4 && $days > 0) {
+		if ($fNum >= 4 && $days > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d day', '%d days', $days, $days);
 		}
-		if ($f >= 5 && $hours > 0) {
+		if ($fNum >= 5 && $hours > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d hour', '%d hours', $hours, $hours);
 		}
-		if ($f >= 6 && $minutes > 0) {
+		if ($fNum >= 6 && $minutes > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d minute', '%d minutes', $minutes, $minutes);
 		}
-		if ($f >= 7 && $seconds > 0) {
+		if ($fNum >= 7 && $seconds > 0) {
 			$relativeDate .= ($relativeDate ? ', ' : '') . __dn('cake', '%d second', '%d seconds', $seconds, $seconds);
 		}
 
+		$aboutAgo = array(
+			'second' => __d('cake', 'about a second ago'),
+			'minute' => __d('cake', 'about a minute ago'),
+			'hour' => __d('cake', 'about an hour ago'),
+			'day' => __d('cake', 'about a day ago'),
+			'week' => __d('cake', 'about a week ago'),
+			'year' => __d('cake', 'about a year ago')
+		);
+
+		$aboutIn = array(
+			'second' => __d('cake', 'in about a second'),
+			'minute' => __d('cake', 'in about a minute'),
+			'hour' => __d('cake', 'in about an hour'),
+			'day' => __d('cake', 'in about a day'),
+			'week' => __d('cake', 'in about a week'),
+			'year' => __d('cake', 'in about a year')
+		);
+
+		// When time has passed
 		if (!$backwards) {
-			return sprintf($relativeString, $relativeDate);
+			if ($relativeDate) {
+				return __d('cake', '%s ago', $relativeDate);
+			}
+
+			return $aboutAgo[$fWord];
+		}
+
+		// When time is to come
+		if (!$relativeDate) {
+			return $aboutIn[$fWord];
 		}
 
 		return $relativeDate;

+ 1 - 1
lib/Cake/Utility/Security.php

@@ -99,7 +99,7 @@ class Security {
  *
  * @param string $string String to hash
  * @param string $type Method to use (sha1/sha256/md5/blowfish)
- * @param mixed $salt If true, automatically appends the application's salt
+ * @param mixed $salt If true, automatically prepends the application's salt
  *     value to $string (Security.salt). If you are using blowfish the salt
  *     must be false or a previously generated salt.
  * @return string Hash