Skip to content

Commit

Permalink
Merge branch '1.3' into 2.0. Had to fix a number of 1.3 -> 2.0
Browse files Browse the repository at this point in the history
differences upon merging.

Conflicts:
	app/config/core.php
	cake/console/templates/skel/config/core.php
	cake/libs/cache/file.php
	cake/libs/cake_session.php
	cake/libs/controller/components/email.php
	cake/libs/i18n.php
	cake/libs/view/pages/home.ctp
	cake/tests/cases/libs/cache/memcache.test.php
	cake/tests/cases/libs/model/model_write.test.php
  • Loading branch information
markstory committed Sep 25, 2010
2 parents 443e523 + a4746c7 commit f21161e
Show file tree
Hide file tree
Showing 26 changed files with 248 additions and 92 deletions.
5 changes: 1 addition & 4 deletions cake/console/libs/tasks/template.php
Expand Up @@ -115,10 +115,7 @@ public function set($one, $two = null) {
if ($data == null) {
return false;
}

foreach ($data as $name => $value) {
$this->templateVars[$name] = $value;
}
$this->templateVars = $data + $this->templateVars;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/cache.php
Expand Up @@ -266,7 +266,7 @@ public static function write($key, $value, $config = 'default') {
}
$key = self::$_engines[$config]->key($key);

if (!$key || is_resource($value) || $settings['duration'] < 1) {
if (!$key || is_resource($value)) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions cake/libs/cache/file.php
Expand Up @@ -299,6 +299,7 @@ protected function _active() {
if ($this->_init && !($dir->isDir() && $dir->isWritable())) {
$this->_init = false;
trigger_error(sprintf(__('%s is not writable'), $this->settings['path']), E_USER_WARNING);
return false;
}
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/controller/components/email.php
Expand Up @@ -790,8 +790,8 @@ function _strip($value, $message = false) {
* @access private
*/
function _mail() {
$header = implode("\n", $this->_header);
$message = implode("\n", $this->_message);
$header = implode("\r\n", $this->_header);
$message = implode("\r\n", $this->_message);
if (is_array($this->to)) {
$to = implode(', ', array_map(array($this, '_formatAddress'), $this->to));
} else {
Expand Down
2 changes: 2 additions & 0 deletions cake/libs/controller/components/request_handler.php
Expand Up @@ -167,6 +167,8 @@ public function startup(&$controller) {
$this->renderAs($controller, $this->ext);
} elseif ($this->request->is('ajax')) {
$this->renderAs($controller, 'ajax');
} elseif (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) {
$this->respondAs('html', array('charset' => Configure::read('App.encoding')));
}

if ($this->requestedWith('xml')) {
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/controller/controller.php
Expand Up @@ -714,7 +714,7 @@ public function set($one, $two = null) {
} else {
$data = array($one => $two);
}
$this->viewVars = array_merge($this->viewVars, $data);
$this->viewVars = $data + $this->viewVars;
}

/**
Expand Down
99 changes: 51 additions & 48 deletions cake/libs/i18n.php
Expand Up @@ -74,13 +74,6 @@ class I18n {
*/
private $__noLocale = false;

/**
* Determine if $__domains cache should be wrote
*
* @var boolean
*/
private $__cache = false;

/**
* Set to true when I18N::__bindTextDomain() is called for the first time.
* If a translation file is found it is set to false again
Expand Down Expand Up @@ -118,7 +111,7 @@ public static function &getInstance() {
*/
public static function translate($singular, $plural = null, $domain = null, $category = 6, $count = null) {
$_this =& I18n::getInstance();

if (strpos($singular, "\r\n") !== false) {
$singular = str_replace("\r\n", "\n", $singular);
}
Expand All @@ -143,15 +136,16 @@ public static function translate($singular, $plural = null, $domain = null, $cat
if (is_null($domain)) {
$domain = 'default';
}
$_this->domain = $domain . '_' . $_this->l10n->locale;

if (empty($_this->__domains)) {
$_this->__domains = Cache::read($_this->domain, '_cake_core_');
$_this->domain = $domain . '_' . $_this->l10n->lang;

if (empty($_this->__domains[$domain][$_this->__lang])) {
$_this->__domains[$domain][$_this->__lang] = Cache::read($_this->domain, '_cake_core_');
}

if (!isset($_this->__domains[$_this->category][$_this->__lang][$domain])) {
if (empty($_this->__domains[$domain][$_this->__lang][$_this->category])) {
$_this->__bindTextDomain($domain);
$_this->__cache = true;
Cache::write($_this->domain, $_this->__domains[$domain][$_this->__lang], '_cake_core_');
}

if ($_this->category == 'LC_TIME') {
Expand All @@ -160,8 +154,8 @@ public static function translate($singular, $plural = null, $domain = null, $cat

if (!isset($count)) {
$plurals = 0;
} elseif (!empty($_this->__domains[$_this->category][$_this->__lang][$domain]["%plural-c"]) && $_this->__noLocale === false) {
$header = $_this->__domains[$_this->category][$_this->__lang][$domain]["%plural-c"];
} elseif (!empty($_this->__domains[$domain][$_this->__lang][$_this->category]["%plural-c"]) && $_this->__noLocale === false) {
$header = $_this->__domains[$domain][$_this->__lang][$_this->category]["%plural-c"];
$plurals = $_this->__pluralGuess($header, $count);
} else {
if ($count != 1) {
Expand All @@ -171,8 +165,8 @@ public static function translate($singular, $plural = null, $domain = null, $cat
}
}

if (!empty($_this->__domains[$_this->category][$_this->__lang][$domain][$singular])) {
if (($trans = $_this->__domains[$_this->category][$_this->__lang][$domain][$singular]) || ($plurals) && ($trans = $_this->__domains[$_this->category][$_this->__lang][$domain][$plural])) {
if (!empty($_this->__domains[$domain][$_this->__lang][$_this->category][$singular])) {
if (($trans = $_this->__domains[$domain][$_this->__lang][$_this->category][$singular]) || ($plurals) && ($trans = $_this->__domains[$domain][$_this->__lang][$_this->category][$plural])) {
if (is_array($trans)) {
if (isset($trans[$plurals])) {
$trans = $trans[$plurals];
Expand All @@ -190,6 +184,26 @@ public static function translate($singular, $plural = null, $domain = null, $cat
return $singular;
}

/**
* Clears the domains internal data array. Useful for testing i18n.
*
* @return void
*/
public static function clear() {
$self =& I18n::getInstance();
$self->__domains = array();
}

/**
* Get the loaded domains cache.
*
* @return array
*/
public static function domains() {
$self =& I18n::getInstance();
return $self->__domains;
}

/**
* Attempts to find the plural form of a string.
*
Expand Down Expand Up @@ -276,12 +290,12 @@ private function __bindTextDomain($domain) {
if (file_exists($fn = "$app.mo")) {
$this->__loadMo($fn, $domain);
$this->__noLocale = false;
$merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain];
$merge[$domain][$this->__lang][$this->category] = $this->__domains[$domain][$this->__lang][$this->category];
$core = null;
} elseif (file_exists($fn = "$app.po") && ($f = fopen($fn, "r"))) {
$this->__loadPo($f, $domain);
$this->__noLocale = false;
$merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain];
$merge[$domain][$this->__lang][$this->category] = $this->__domains[$domain][$this->__lang][$this->category];
$core = null;
}
}
Expand All @@ -302,27 +316,27 @@ private function __bindTextDomain($domain) {
}
}

if (empty($this->__domains[$this->category][$this->__lang][$domain])) {
$this->__domains[$this->category][$this->__lang][$domain] = array();
if (empty($this->__domains[$domain][$this->__lang][$this->category])) {
$this->__domains[$domain][$this->__lang][$this->category] = array();
return $domain;
}

if ($head = $this->__domains[$this->category][$this->__lang][$domain][""]) {
if ($head = $this->__domains[$domain][$this->__lang][$this->category][""]) {
foreach (explode("\n", $head) as $line) {
$header = strtok($line,":");
$line = trim(strtok("\n"));
$this->__domains[$this->category][$this->__lang][$domain]["%po-header"][strtolower($header)] = $line;
$this->__domains[$domain][$this->__lang][$this->category]["%po-header"][strtolower($header)] = $line;
}

if (isset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"]);
$this->__domains[$this->category][$this->__lang][$domain]["%plural-c"] = $switch;
unset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]);
if (isset($this->__domains[$domain][$this->__lang][$this->category]["%po-header"]["plural-forms"])) {
$switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$domain][$this->__lang][$this->category]["%po-header"]["plural-forms"]);
$this->__domains[$domain][$this->__lang][$this->category]["%plural-c"] = $switch;
unset($this->__domains[$domain][$this->__lang][$this->category]["%po-header"]);
}
$this->__domains = Set::pushDiff($this->__domains, $merge);

if (isset($this->__domains[$this->category][$this->__lang][$domain][null])) {
unset($this->__domains[$this->category][$this->__lang][$domain][null]);
if (isset($this->__domains[$domain][$this->__lang][$this->category][null])) {
unset($this->__domains[$domain][$this->__lang][$this->category][null]);
}
}
return $domain;
Expand Down Expand Up @@ -357,10 +371,10 @@ private function __loadMo($file, $domain) {
if (strpos($msgstr, "\000")) {
$msgstr = explode("\000", $msgstr);
}
$this->__domains[$this->category][$this->__lang][$domain][$msgid] = $msgstr;
$this->__domains[$domain][$this->__lang][$this->category][$msgid] = $msgstr;

if (isset($msgid_plural)) {
$this->__domains[$this->category][$this->__lang][$domain][$msgid_plural] =& $this->__domains[$this->category][$this->__lang][$domain][$msgid];
$this->__domains[$domain][$this->__lang][$this->category][$msgid_plural] =& $this->__domains[$domain][$this->__lang][$this->category][$msgid];
}
}
}
Expand Down Expand Up @@ -434,7 +448,7 @@ private function __loadPo($file, $domain) {
} while (!feof($file));
fclose($file);
$merge[""] = $header;
return $this->__domains[$this->category][$this->__lang][$domain] = array_merge($merge ,$translations);
return $this->__domains[$domain][$this->__lang][$this->category] = array_merge($merge ,$translations);
}

/**
Expand Down Expand Up @@ -491,9 +505,9 @@ private function __loadLocaleDefinition($file, $domain = null) {
$value[$i] = $val;
}
if (count($value) == 1) {
$this->__domains[$this->category][$this->__lang][$domain][$currentToken] = array_pop($value);
$this->__domains[$domain][$this->__lang][$this->category][$currentToken] = array_pop($value);
} else {
$this->__domains[$this->category][$this->__lang][$domain][$currentToken] = $value;
$this->__domains[$domain][$this->__lang][$this->category][$currentToken] = $value;
}
}
}
Expand Down Expand Up @@ -535,23 +549,12 @@ private function __parseLiteralValue($string) {
* @param string $domain Domain where format is stored
* @return mixed translated format string if only value or array of translated strings for corresponding format.
*/
private function __translateTime($format, $domain) {
if (!empty($this->__domains['LC_TIME'][$this->__lang][$domain][$format])) {
if (($trans = $this->__domains[$this->category][$this->__lang][$domain][$format])) {
function __translateTime($format, $domain) {
if (!empty($this->__domains[$domain][$this->__lang]['LC_TIME'][$format])) {
if (($trans = $this->__domains[$domain][$this->__lang][$this->category][$format])) {
return $trans;
}
}
return $format;
}

/**
* Object destructor
*
* Write cache file if changes have been made to the $__map or $__paths
*/
function __destruct() {
if ($this->__cache) {
Cache::write($this->domain, array_filter($this->__domains), '_cake_core_');
}
}
}
22 changes: 11 additions & 11 deletions cake/libs/model/datasources/dbo/dbo_postgres.php
Expand Up @@ -299,6 +299,17 @@ function value($data, $column = null, $read = true) {
}

switch($column) {
case 'binary':
$data = pg_escape_bytea($data);
break;
case 'boolean':
if ($data === true || $data === 't' || $data === 'true') {
return 'TRUE';
} elseif ($data === false || $data === 'f' || $data === 'false') {
return 'FALSE';
}
return (!empty($data) ? 'TRUE' : 'FALSE');
break;
case 'float':
if (is_float($data)) {
$data = sprintf('%F', $data);
Expand All @@ -312,17 +323,6 @@ function value($data, $column = null, $read = true) {
if ($data === '') {
return $read ? 'NULL' : 'DEFAULT';
}
case 'binary':
$data = pg_escape_bytea($data);
break;
case 'boolean':
if ($data === true || $data === 't' || $data === 'true') {
return 'TRUE';
} elseif ($data === false || $data === 'f' || $data === 'false') {
return 'FALSE';
}
return (!empty($data) ? 'TRUE' : 'FALSE');
break;
default:
$data = pg_escape_string($data);
break;
Expand Down
21 changes: 8 additions & 13 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -555,6 +555,9 @@ public function name($data) {
)
);
}
if (preg_match('/^[\w-_\s]*[\w-_]+/', $data)) {
return $this->cacheMethod(__FUNCTION__, $cacheKey, $this->startQuote . $data . $this->endQuote);
}
return $this->cacheMethod(__FUNCTION__, $cacheKey, $data);
}

Expand Down Expand Up @@ -1657,8 +1660,10 @@ protected function _matchRecords(&$model, $conditions = null) {
$noJoin = false;
break;
}
$conditions[$field] = $value;
unset($conditions[$originalField]);
if ($field !== $originalField) {
$conditions[$field] = $value;
unset($conditions[$originalField]);
}
}
if ($noJoin === true) {
return $this->conditions($conditions);
Expand Down Expand Up @@ -1979,18 +1984,8 @@ public function fields(&$model, $alias = null, $fields = array(), $quote = true)
if ($comma === false) {
$build = explode('.', $fields[$i]);
if (!Set::numeric($build)) {
$fields[$i] = $this->name($build[0] . '.' . $build[1]);
}
$comma = String::tokenize($fields[$i]);
foreach ($comma as $string) {
if (preg_match('/^[0-9]+\.[0-9]+$/', $string)) {
$value[] = $string;
} else {
$build = explode('.', $string);
$value[] = $this->name(trim($build[0]) . '.' . trim($build[1]));
}
$fields[$i] = $this->name(implode('.', $build));
}
$fields[$i] = implode(', ', $value);
}
}
$fields[$i] = $prepend . $fields[$i];
Expand Down
10 changes: 6 additions & 4 deletions cake/libs/model/model.php
Expand Up @@ -2042,10 +2042,12 @@ public function hasAny($conditions = null) {
* find('all', array(
* 'conditions' => array('name' => 'Thomas Anderson'),
* 'joins' => array(
* 'alias' => 'Thought',
* 'table' => 'thoughts',
* 'type' => 'LEFT',
* 'conditions' => '`Thought`.`person_id` = `Person`.`id`'
* array(
* 'alias' => 'Thought',
* 'table' => 'thoughts',
* 'type' => 'LEFT',
* 'conditions' => '`Thought`.`person_id` = `Person`.`id`'
* )
* )
* ));
* }}}
Expand Down
12 changes: 11 additions & 1 deletion cake/libs/view/pages/home.ctp
Expand Up @@ -71,6 +71,16 @@ endif;
endif;
?>
</p>
<?php
App::import('Core', 'Validation');
if (!Validation::alphaNumeric('cakephp')) {
echo '<p><span class="notice">';
__('PCRE has not been compiled with Unicode support.');
echo '<br/>';
__('Recompile PCRE with Unicode support by adding <code>--enable-unicode-properties</code> when configuring');
echo '</span></p>';
}
?>
<?php
if (isset($filePresent)):
if (!class_exists('ConnectionManager')) {
Expand Down Expand Up @@ -157,4 +167,4 @@ You can also add some CSS styles for your pages at: APP/webroot/css.');
<ul><li><?php echo __('Recommended Software Books'); ?></li></ul></li>
<li><a href="http://www.cafepress.com/cakefoundation"><?php echo __('CakePHP gear'); ?> </a>
<ul><li><?php echo __('Get your own CakePHP gear - Doughnate to Cake'); ?></li></ul></li>
</ul>
</ul>
2 changes: 1 addition & 1 deletion cake/libs/view/view.php
Expand Up @@ -597,7 +597,7 @@ public function set($one, $two = null) {
if ($data == null) {
return false;
}
$this->viewVars = array_merge($this->viewVars, $data);
$this->viewVars = $data + $this->viewVars;
}

/**
Expand Down

0 comments on commit f21161e

Please sign in to comment.