Skip to content

Commit

Permalink
Merge remote branch 'upstream/2.0' into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed Jan 19, 2011
2 parents c712763 + f73c4f3 commit 46d14c5
Show file tree
Hide file tree
Showing 26 changed files with 281 additions and 89 deletions.
27 changes: 19 additions & 8 deletions cake/basics.php
Expand Up @@ -282,7 +282,7 @@ function env($key) {
if (defined('SERVER_IIS') && SERVER_IIS === true) {
return str_replace('\\\\', '\\', env('PATH_TRANSLATED'));
}
break;
break;
case 'DOCUMENT_ROOT':
$name = env('SCRIPT_NAME');
$filename = env('SCRIPT_FILENAME');
Expand All @@ -291,20 +291,31 @@ function env($key) {
$offset = 4;
}
return substr($filename, 0, strlen($filename) - (strlen($name) + $offset));
break;
break;
case 'PHP_SELF':
return str_replace(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
break;
break;
case 'CGI_MODE':
return (PHP_SAPI === 'cgi');
break;
break;
case 'HTTP_BASE':
$host = env('HTTP_HOST');
if (substr_count($host, '.') !== 1) {
return preg_replace('/^([^.])*/i', null, env('HTTP_HOST'));
$parts = explode('.', $host);
$count = count($parts);

if ($count === 1) {
return '.' . $host;
} elseif ($count === 2) {
return '.' . $host;
} elseif ($count === 3) {
$gTLD = array('aero', 'asia', 'biz', 'cat', 'com', 'coop', 'edu', 'gov', 'info', 'int', 'jobs', 'mil', 'mobi', 'museum', 'name', 'net', 'org', 'pro', 'tel', 'travel', 'xxx');
if (in_array($parts[1], $gTLD)) {
return '.' . $host;
}
}
return '.' . $host;
break;
array_shift($parts);
return '.' . implode('.', $parts);
break;
}
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions cake/console/libs/task_collection.php
Expand Up @@ -48,11 +48,10 @@ public function __construct(Shell $Shell) {
*
* @param string $task Task name to load
* @param array $settings Settings for the task.
* @param boolean $enable Whether or not this task should be enabled by default
* @return Task A task object, Either the existing loaded task or a new one.
* @throws MissingTaskFileException, MissingTaskClassException when the task could not be found
*/
public function load($task, $settings = array(), $enable = true) {
public function load($task, $settings = array()) {
list($plugin, $name) = pluginSplit($task, true);

if (isset($this->_loaded[$name])) {
Expand All @@ -72,6 +71,7 @@ public function load($task, $settings = array(), $enable = true) {
$this->_loaded[$name] = new $taskClass(
$this->_Shell->stdout, $this->_Shell->stderr, $this->_Shell->stdin
);
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable === true) {
$this->_enabled[] = $name;
}
Expand Down
2 changes: 1 addition & 1 deletion cake/console/templates/default/classes/fixture.ctp
Expand Up @@ -20,7 +20,7 @@
*/
?>
<?php echo '<?php' . "\n"; ?>
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:m:s') . " : ". time(); ?> */
/* <?php echo $model; ?> Fixture generated on: <?php echo date('Y-m-d H:i:s') . " : ". time(); ?> */
class <?php echo $model; ?>Fixture extends CakeTestFixture {
public $name = '<?php echo $model; ?>';
<?php if ($table): ?>
Expand Down
2 changes: 1 addition & 1 deletion cake/console/templates/default/classes/test.ctp
Expand Up @@ -18,7 +18,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
echo "<?php\n";
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n";
echo "/* ". $className ." Test cases generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n";
?>
App::import('<?php echo $type; ?>', '<?php echo $plugin . $className;?>');

Expand Down
30 changes: 16 additions & 14 deletions cake/libs/cache/memcache.php
Expand Up @@ -33,7 +33,7 @@ class MemcacheEngine extends CacheEngine {
* @var Memcache
* @access private
*/
private $__Memcache = null;
protected $_Memcache = null;

/**
* Settings
Expand Down Expand Up @@ -74,12 +74,12 @@ public function init($settings = array()) {
if (!is_array($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->__Memcache)) {
if (!isset($this->_Memcache)) {
$return = false;
$this->__Memcache = new Memcache();
$this->_Memcache = new Memcache();
foreach ($this->settings['servers'] as $server) {
list($host, $port) = $this->_parseServerString($server);
if ($this->__Memcache->addServer($host, $port)) {
if ($this->_Memcache->addServer($host, $port)) {
$return = true;
}
}
Expand Down Expand Up @@ -116,8 +116,7 @@ function _parseServerString($server) {
/**
* Write data for key into cache. When using memcache as your cache engine
* remember that the Memcache pecl extension does not support cache expiry times greater
* than 30 days in the future. If you wish to create cache entries that do not expire, set the duration
* to `0` in your cache configuration.
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
Expand All @@ -126,7 +125,10 @@ function _parseServerString($server) {
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
return $this->__Memcache->set($key, $value, $this->settings['compress'], $duration);
if ($duration > 30 * DAY) {
$duration = 0;
}
return $this->_Memcache->set($key, $value, $this->settings['compress'], $duration);
}

/**
Expand All @@ -136,7 +138,7 @@ public function write($key, $value, $duration) {
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
*/
public function read($key) {
return $this->__Memcache->get($key);
return $this->_Memcache->get($key);
}

/**
Expand All @@ -154,7 +156,7 @@ public function increment($key, $offset = 1) {
__('Method increment() not implemented for compressed cache in %s', __CLASS__)
);
}
return $this->__Memcache->increment($key, $offset);
return $this->_Memcache->increment($key, $offset);
}

/**
Expand All @@ -172,7 +174,7 @@ public function decrement($key, $offset = 1) {
__('Method decrement() not implemented for compressed cache in %s', __CLASS__)
);
}
return $this->__Memcache->decrement($key, $offset);
return $this->_Memcache->decrement($key, $offset);
}

/**
Expand All @@ -182,7 +184,7 @@ public function decrement($key, $offset = 1) {
* @return boolean True if the value was succesfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->__Memcache->delete($key);
return $this->_Memcache->delete($key);
}

/**
Expand All @@ -191,7 +193,7 @@ public function delete($key) {
* @return boolean True if the cache was succesfully cleared, false otherwise
*/
public function clear($check) {
return $this->__Memcache->flush();
return $this->_Memcache->flush();
}

/**
Expand All @@ -202,8 +204,8 @@ public function clear($check) {
* @return boolean True if memcache server was connected
*/
public function connect($host, $port = 11211) {
if ($this->__Memcache->getServerStatus($host, $port) === 0) {
if ($this->__Memcache->connect($host, $port)) {
if ($this->_Memcache->getServerStatus($host, $port) === 0) {
if ($this->_Memcache->connect($host, $port)) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/component_collection.php
Expand Up @@ -74,7 +74,7 @@ public function getController() {
* @throws MissingComponentFileException, MissingComponentClassException when the component could not be found
*/
public function load($component, $settings = array()) {
if (isset($settings['className'])) {
if (is_array($settings) && isset($settings['className'])) {
$alias = $component;
$component = $settings['className'];
}
Expand Down
5 changes: 4 additions & 1 deletion cake/libs/controller/components/request_handler.php
Expand Up @@ -132,6 +132,7 @@ public function initialize($controller, $settings = array()) {
}
}
}
$this->params = $controller->params;
$this->_set($settings);
}

Expand Down Expand Up @@ -585,7 +586,9 @@ public function respondAs($type, $options = array()) {
}

if ($cType != null) {
$this->response->type($cType);
if (empty($this->request->params['requested'])) {
$this->response->type($cType);
}

if (!empty($options['charset'])) {
$this->response->charset($options['charset']);
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/behavior_collection.php
Expand Up @@ -99,7 +99,7 @@ public function attach($behavior, $config = array()) {
* @throws MissingBehaviorFileException or MissingBehaviorClassException when a behavior could not be found.
*/
public function load($behavior, $config = array()) {
if (isset($config['className'])) {
if (is_array($config) && isset($config['className'])) {
$alias = $behavior;
$behavior = $config['className'];
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/cake_schema.php
Expand Up @@ -365,7 +365,7 @@ public function write($object, $options = array()) {
$out .= "}\n";

$file = new SplFileObject($path . DS . $file, 'w+');
$content = "<?php \n/* {$name} schema generated on: " . date('Y-m-d H:m:s') . " : ". time() . "*/\n{$out}?>";
$content = "<?php \n/* {$name} schema generated on: " . date('Y-m-d H:i:s') . " : ". time() . "*/\n{$out}?>";
if ($file->fwrite($content)) {
return $content;
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/model/db_acl.php
Expand Up @@ -46,7 +46,7 @@ class AclNode extends AppModel {
* @var array
* @access public
*/
public $actsAs = array('Tree' => 'nested');
public $actsAs = array('Tree' => array('nested'));

/**
* Constructor
Expand Down
6 changes: 3 additions & 3 deletions cake/libs/route/cake_route.php
Expand Up @@ -173,7 +173,7 @@ protected function _writeRoute() {

/**
* Checks to see if the given URL can be parsed by this route.
* If the route can be parsed an array of parameters will be returned if not
* If the route can be parsed an array of parameters will be returned; if not
* false will be returned. String urls are parsed if they match a routes regular expression.
*
* @param string $url The url to attempt to parse.
Expand Down Expand Up @@ -245,8 +245,8 @@ public function persistParams($url, $params) {
}

/**
* Attempt to match a url array. If the url matches the route parameters + settings, then
* return a generated string url. If the url doesn't match the route parameters false will be returned.
* Attempt to match a url array. If the url matches the route parameters and settings, then
* return a generated string url. If the url doesn't match the route parameters, false will be returned.
* This method handles the reverse routing or conversion of url arrays into string urls.
*
* @param array $url An array of parameters to check matching with.
Expand Down
19 changes: 12 additions & 7 deletions cake/libs/router.php
Expand Up @@ -221,21 +221,25 @@ public static function getNamedExpressions() {
* Shows connecting a route with custom route parameters as well as providing patterns for those parameters.
* Patterns for routing parameters do not need capturing groups, as one will be added for each route params.
*
* $options offers two 'special' keys. `pass` and `persist` have special meaning in the $options array.
* $options offers three 'special' keys. `pass`, `persist` and `routeClass` have special meaning in the $options array.
*
* `pass` is used to define which of the routed parameters should be shifted into the pass array. Adding a
* parameter to pass will remove it from the regular route array. Ex. `'pass' => array('slug')`
*
* `persist` is used to define which route parameters should be automatically included when generating
* new urls. You can override peristent parameters by redifining them in a url or remove them by
* new urls. You can override persistent parameters by redefining them in a url or remove them by
* setting the parameter to `false`. Ex. `'persist' => array('lang')`
*
* `routeClass` is used to extend and change how individual routes parse requests and handle reverse routing,
* via a custom routing class. Ex. `'routeClass' => 'SlugRoute'`
*
* @param string $route A string describing the template of the route
* @param array $defaults An array describing the default route parameters. These parameters will be used by default
* and can supply routing parameters that are not dynamic. See above.
* @param array $options An array matching the named elements in the route to regular expressions which that
* element should match. Also contains additional parameters such as which routed parameters should be
* shifted into the passed arguments. As well as supplying patterns for routing parameters.
* shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a
* custom routing class.
* @see routes
* @return array Array of routes
* @throws RouterException
Expand Down Expand Up @@ -731,7 +735,7 @@ public static function reload() {
*
* @param $which A zero-based array index representing the route to move. For example,
* if 3 routes have been added, the last route would be 2.
* @return boolean Retuns false if no route exists at the position specified by $which.
* @return boolean Returns false if no route exists at the position specified by $which.
*/
public static function promote($which = null) {
if ($which === null) {
Expand All @@ -752,7 +756,7 @@ public static function promote($which = null) {
* Returns an URL pointing to a combination of controller and action. Param
* $url can be:
*
* - Empty - the method will find address to actuall controller/action.
* - Empty - the method will find address to actual controller/action.
* - '/' - the method will find base URL of application.
* - A combination of controller/action - the method will find url for it.
*
Expand Down Expand Up @@ -1068,7 +1072,7 @@ public static function queryString($q, $extra = array(), $escape = false) {
}

/**
* Reverses a parsed parameter array into a string. Works similarily to Router::url(), but
* Reverses a parsed parameter array into a string. Works similarly to Router::url(), but
* Since parsed URL's contain additional 'pass' and 'named' as well as 'url.url' keys.
* Those keys need to be specially handled in order to reverse a params array into a string url.
*
Expand Down Expand Up @@ -1199,7 +1203,7 @@ public static function extensions() {
}

/**
* Takes an passed params and converts it to args
* Takes a passed params and converts it to args
*
* @param array $params
* @return array Array containing passed and named parameters
Expand Down Expand Up @@ -1263,5 +1267,6 @@ public static function getArgs($args, $options = array()) {
return compact('pass', 'named');
}
}

//Save the initial state
Router::reload();
3 changes: 3 additions & 0 deletions cake/libs/session/database_session.php
Expand Up @@ -106,6 +106,9 @@ public function read($id) {
* @access private
*/
public function write($id, $data) {
if (!$id) {
return false;
}
$expires = time() + (Configure::read('Session.timeout') * 60);
return ClassRegistry::getObject('Session')->save(compact('id', 'data', 'expires'));
}
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/helper_collection.php
Expand Up @@ -57,7 +57,7 @@ public function __construct(View $view) {
* @throws MissingHelperFileException, MissingHelperClassException when the helper could not be found
*/
public function load($helper, $settings = array()) {
if (isset($settings['className'])) {
if (is_array($settings) && isset($settings['className'])) {
$alias = $helper;
$helper = $settings['className'];
}
Expand Down
8 changes: 5 additions & 3 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1001,7 +1001,10 @@ public function checkbox($fieldName, $options = array()) {

if (empty($options['value'])) {
$options['value'] = 1;
} elseif (!empty($value) && $value === $options['value']) {
} elseif (
(!isset($options['checked']) && !empty($value) && $value === $options['value']) ||
!empty($options['checked'])
) {
$options['checked'] = 'checked';
}
if ($options['hiddenField']) {
Expand Down Expand Up @@ -1322,7 +1325,6 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
unset($options['confirm']);
}

$url = $this->url($url);
$formName = uniqid('post_');
$out = $this->create(false, array('url' => $url, 'name' => $formName, 'id' => $formName, 'style' => 'display:none;'));
if (isset($options['data']) && is_array($options['data'])) {
Expand Down Expand Up @@ -2021,7 +2023,7 @@ protected function _name($options = array(), $field = null, $key = 'name') {
return $options;
}

$name = $this->_View->field;
$name = !empty($this->_View->field) ? $this->_View->field : $this->_View->model;
if (!empty($this->_View->fieldSuffix)) {
$name .= '[' . $this->_View->fieldSuffix . ']';
}
Expand Down
3 changes: 2 additions & 1 deletion cake/libs/view/helpers/text.php
Expand Up @@ -180,8 +180,9 @@ private function _linkEmails($matches) {
*/
public function autoLinkEmails($text, $options = array()) {
$this->_linkOptions = $options;
$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
return preg_replace_callback(
'#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)*)/i',
array(&$this, '_linkEmails'),
$text
);
Expand Down

0 comments on commit 46d14c5

Please sign in to comment.