mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-10-30 07:43:59 +01:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
7
lib/Cake/View/Elements/Flash/default.ctp
Normal file
7
lib/Cake/View/Elements/Flash/default.ctp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
$class = 'message';
|
||||
if (!empty($params['class'])) {
|
||||
$class .= ' ' . $params['class'];
|
||||
}
|
||||
?>
|
||||
<div id="<?php echo h($key) ?>Message" class="<?php echo h($class) ?>"><?php echo h($message) ?></div>
|
||||
1
lib/Cake/View/Elements/Flash/error.ctp
Normal file
1
lib/Cake/View/Elements/Flash/error.ctp
Normal file
|
|
@ -0,0 +1 @@
|
|||
<div id="<?php echo h($key) ?>Message" class="message error"><?php echo h($message) ?></div>
|
||||
1
lib/Cake/View/Elements/Flash/success.ctp
Normal file
1
lib/Cake/View/Elements/Flash/success.ctp
Normal file
|
|
@ -0,0 +1 @@
|
|||
<div id="<?php echo h($key) ?>Message" class="message success"><?php echo h($message) ?></div>
|
||||
|
|
@ -2,21 +2,22 @@
|
|||
/**
|
||||
* Prints a stack trace for an exception
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Elements
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Debugger', 'Utility');
|
||||
|
||||
?>
|
||||
<h3>Stack Trace</h3>
|
||||
<ul class="cake-stack-trace">
|
||||
|
|
@ -44,20 +45,20 @@ App::uses('Debugger', 'Utility');
|
|||
if (!empty($stack['args'])):
|
||||
foreach ((array)$stack['args'] as $arg):
|
||||
$args[] = Debugger::getType($arg);
|
||||
$params[] = Debugger::exportVar($arg, 2);
|
||||
$params[] = Debugger::exportVar($arg, 4);
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
$called = isset($stack['class']) ? $stack['class'] . $stack['type'] . $stack['function'] : $stack['function'];
|
||||
|
||||
|
||||
printf(
|
||||
'<a href="#" onclick="traceToggle(event, \'trace-args-%s\')">%s(%s)</a> ',
|
||||
$i,
|
||||
$called,
|
||||
implode(', ', $args)
|
||||
h(implode(', ', $args))
|
||||
);
|
||||
$arguments = sprintf('<div id="trace-args-%s" class="cake-code-dump" style="display: none;"><pre>', $i);
|
||||
$arguments .= implode("\n", $params);
|
||||
$arguments .= h(implode("\n", $params));
|
||||
$arguments .= '</pre></div>';
|
||||
endif;
|
||||
echo $excerpt;
|
||||
|
|
@ -68,7 +69,7 @@ App::uses('Debugger', 'Utility');
|
|||
<script type="text/javascript">
|
||||
function traceToggle(event, id) {
|
||||
var el = document.getElementById(id);
|
||||
el.style.display = (el.style.display == 'block') ? 'none' : 'block';
|
||||
el.style.display = (el.style.display === 'block') ? 'none' : 'block';
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* SQL Dump element. Dumps out SQL log information
|
||||
*
|
||||
* PHP 5
|
||||
* SQL Dump element. Dumps out SQL log information
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Elements
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
if (!class_exists('ConnectionManager') || Configure::read('debug') < 2) {
|
||||
return false;
|
||||
}
|
||||
$noLogs = !isset($logs);
|
||||
$noLogs = !isset($sqlLogs);
|
||||
if ($noLogs):
|
||||
$sources = ConnectionManager::sourceList();
|
||||
|
||||
$logs = array();
|
||||
$sqlLogs = array();
|
||||
foreach ($sources as $source):
|
||||
$db = ConnectionManager::getDataSource($source);
|
||||
if (!method_exists($db, 'getLog')):
|
||||
continue;
|
||||
endif;
|
||||
$logs[$source] = $db->getLog();
|
||||
$sqlLogs[$source] = $db->getLog();
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ($noLogs || isset($_forced_from_dbo_)):
|
||||
foreach ($logs as $source => $logInfo):
|
||||
foreach ($sqlLogs as $source => $logInfo):
|
||||
$text = $logInfo['count'] > 1 ? 'queries' : 'query';
|
||||
printf(
|
||||
'<table class="cake-sql-log" id="cakeSqlLog_%s" summary="Cake SQL Log" cellspacing="0">',
|
||||
|
|
@ -56,19 +56,27 @@ if ($noLogs || isset($_forced_from_dbo_)):
|
|||
}
|
||||
foreach ($i['params'] as $bindKey => $bindVal) {
|
||||
if ($bindType === true) {
|
||||
$bindParam .= h($bindKey) ." => " . h($bindVal) . ", ";
|
||||
$bindParam .= h($bindKey) . " => " . h($bindVal) . ", ";
|
||||
} else {
|
||||
$bindParam .= h($bindVal) . ", ";
|
||||
}
|
||||
}
|
||||
$i['query'] .= " , params[ " . rtrim($bindParam, ', ') . " ]";
|
||||
}
|
||||
echo "<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n";
|
||||
printf('<tr><td>%d</td><td>%s</td><td>%s</td><td style="text-align: right">%d</td><td style="text-align: right">%d</td><td style="text-align: right">%d</td></tr>%s',
|
||||
$k + 1,
|
||||
h($i['query']),
|
||||
$i['error'],
|
||||
$i['affected'],
|
||||
$i['numRows'],
|
||||
$i['took'],
|
||||
"\n"
|
||||
);
|
||||
endforeach;
|
||||
?>
|
||||
</tbody></table>
|
||||
<?php
|
||||
endforeach;
|
||||
else:
|
||||
echo '<p>Encountered unexpected $logs cannot generate SQL log</p>';
|
||||
printf('<p>%s</p>', __d('cake_dev', 'Encountered unexpected %s. Cannot generate SQL log.', '$sqlLogs'));
|
||||
endif;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 2.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Fatal Error'); ?></h2>
|
||||
<p class="error">
|
||||
|
|
@ -33,3 +32,8 @@
|
|||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'fatal_error.ctp'); ?>
|
||||
</p>
|
||||
<?php
|
||||
if (extension_loaded('xdebug')) {
|
||||
xdebug_print_function_stack();
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,35 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Method in %s', $controller); ?></h2> <p class="error">
|
||||
<h2><?php echo __d('cake_dev', 'Missing Method in %s', h($controller)); ?></h2> <p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'The action %1$s is not defined in controller %2$s', '<em>' . $action . '</em>', '<em>' . $controller . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'The action %1$s is not defined in controller %2$s', '<em>' . h($action) . '</em>', '<em>' . h($controller) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Create %1$s%2$s in file: %3$s.', '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', APP_DIR . DS . 'Controller' . DS . $controller . '.php'); ?>
|
||||
<?php echo __d('cake_dev', 'Create %1$s%2$s in file: %3$s.', '<em>' . h($controller) . '::</em>', '<em>' . h($action) . '()</em>', APP_DIR . DS . 'Controller' . DS . h($controller) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $controller; ?> extends AppController {
|
||||
class <?php echo h($controller); ?> extends AppController {
|
||||
|
||||
<strong>
|
||||
public function <?php echo $action; ?>() {
|
||||
public function <?php echo h($action); ?>() {
|
||||
|
||||
}
|
||||
</strong>
|
||||
|
|
@ -39,4 +38,6 @@ class <?php echo $controller; ?> extends AppController {
|
|||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_action.ctp'); ?>
|
||||
</p>
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
@ -1,34 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$pluginDot = empty($plugin) ? null : $plugin . '.';
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Behavior'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . $pluginDot . $class . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . h($pluginDot . $class) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . $class . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'Model' . DS . 'Behavior' . DS . $class . '.php'); ?>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . h($class) . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'Model' . DS . 'Behavior' . DS . h($class) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $class; ?> extends ModelBehavior {
|
||||
class <?php echo h($class); ?> extends ModelBehavior {
|
||||
|
||||
}
|
||||
</pre>
|
||||
|
|
@ -37,4 +36,6 @@ class <?php echo $class; ?> extends ModelBehavior {
|
|||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_behavior.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
@ -1,34 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$pluginDot = empty($plugin) ? null : $plugin . '.';
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Component'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . $pluginDot . $class . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . h($pluginDot . $class) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . $class . '</em>', (empty($plugin) ? APP_DIR : CakePlugin::path($plugin)) . DS . 'Controller' . DS . 'Component' . DS . $class . '.php'); ?>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . h($class) . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'Controller' . DS . 'Component' . DS . h($class) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $class; ?> extends Component {
|
||||
class <?php echo h($class); ?> extends Component {
|
||||
|
||||
}
|
||||
</pre>
|
||||
|
|
@ -37,4 +36,6 @@ class <?php echo $class; ?> extends Component {
|
|||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_component.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,41 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Database Connection'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'A Database connection using "%s" was missing or unable to connect. ', $class); ?>
|
||||
<?php echo __d('cake_dev', 'A Database connection using "%s" was missing or unable to connect.', h($class)); ?>
|
||||
<br />
|
||||
<?php
|
||||
if (isset($message)):
|
||||
echo __d('cake_dev', 'The database server returned this error: %s', $message);
|
||||
echo __d('cake_dev', 'The database server returned this error: %s', h($message));
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php if (!$enabled) : ?>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s driver is NOT enabled', $class); ?>
|
||||
<?php echo __d('cake_dev', '%s driver is NOT enabled', h($class)); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s.', APP_DIR . DS . 'View' . DS . 'Errors' . DS . basename(__FILE__)); ?>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . basename(__FILE__)); ?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
|
|
|
|||
|
|
@ -1,34 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$pluginDot = empty($plugin) ? null : $plugin . '.';
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Controller'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . $pluginDot . $class . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . h($pluginDot . $class) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . $class . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'Controller' . DS . $class . '.php'); ?>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . h($class) . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'Controller' . DS . h($class) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $class . ' extends ' . $plugin; ?>AppController {
|
||||
class <?php echo h($class . ' extends ' . $plugin); ?>AppController {
|
||||
|
||||
}
|
||||
</pre>
|
||||
|
|
@ -37,4 +36,6 @@ class <?php echo $class . ' extends ' . $plugin; ?>AppController {
|
|||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_controller.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Database Connection'); ?></h2>
|
||||
|
|
@ -30,4 +28,6 @@
|
|||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_database.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,30 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$pluginDot = empty($plugin) ? null : $plugin . '.';
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Datasource'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Datasource class %s could not be found.', '<em>' . $pluginDot . $class . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'Datasource class %s could not be found.', '<em>' . h($pluginDot . $class) . '</em>'); ?>
|
||||
<?php if (isset($message)): ?>
|
||||
<?php echo h($message); ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_datasource.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Datasource Configuration'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'The datasource configuration %1$s was not found in database.php.', '<em>' . $config . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'The datasource configuration %1$s was not found in database.php.', '<em>' . h($config) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_datasource_config.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,34 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
$pluginDot = empty($plugin) ? null : $plugin . '.';
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Helper'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . $pluginDot . $class . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', '%s could not be found.', '<em>' . h($pluginDot . $class) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . $class . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'View' . DS . 'Helper' . DS . $class . '.php'); ?>
|
||||
<?php echo __d('cake_dev', 'Create the class %s below in file: %s', '<em>' . h($class) . '</em>', (empty($plugin) ? APP_DIR . DS : CakePlugin::path($plugin)) . 'View' . DS . 'Helper' . DS . h($class) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $class; ?> extends AppHelper {
|
||||
class <?php echo h($class); ?> extends AppHelper {
|
||||
|
||||
}
|
||||
</pre>
|
||||
|
|
@ -37,4 +36,6 @@ class <?php echo $class; ?> extends AppHelper {
|
|||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_helper.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,33 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Layout'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'The layout file %s can not be found or does not exist.', '<em>' . $file . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'The layout file %s can not be found or does not exist.', '<em>' . h($file) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Confirm you have created the file: %s', '<em>' . $file . '</em>'); ?>
|
||||
|
||||
<p>
|
||||
<?php echo __d('cake_dev', 'Confirm you have created the file: %s', h($file)); ?>
|
||||
in one of the following paths:
|
||||
</p>
|
||||
<ul>
|
||||
<?php
|
||||
$paths = $this->_paths($this->plugin);
|
||||
foreach ($paths as $path):
|
||||
if (strpos($path, CORE_PATH) !== false) {
|
||||
continue;
|
||||
}
|
||||
echo sprintf('<li>%s%s</li>', h($path), h($file));
|
||||
endforeach;
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_layout.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,38 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Plugin'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'The application is trying to load a file from the %s plugin', '<em>' . $plugin . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'The application is trying to load a file from the %s plugin', '<em>' . h($plugin) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Make sure your plugin %s is in the ' . APP_DIR . DS . 'Plugin directory and was loaded', $plugin); ?>
|
||||
<?php echo __d('cake_dev', 'Make sure your plugin %s is in the %s directory and was loaded', $plugin, APP_DIR . DS . 'Plugin'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
CakePlugin::load('<?php echo $plugin?>');
|
||||
CakePlugin::load('<?php echo h($plugin); ?>');
|
||||
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Loading all plugins'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you wish to load all plugins at once, use the following line in your ' . APP_DIR . DS . 'Config' . DS . 'bootstrap.php file'); ?>
|
||||
<?php echo __d('cake_dev', 'If you wish to load all plugins at once, use the following line in your %s file', APP_DIR . DS . 'Config' . DS . 'bootstrap.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
CakePlugin::loadAll();
|
||||
|
|
@ -42,4 +40,6 @@ CakePlugin::loadAll();
|
|||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_plugin.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing Database Table'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Table %1$s for model %2$s was not found in datasource %3$s.', '<em>' . $table . '</em>', '<em>' . $class . '</em>', '<em>' . $ds . '</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'Table %1$s for model %2$s was not found in datasource %3$s.', '<em>' . h($table) . '</em>', '<em>' . h($class) . '</em>', '<em>' . h($ds) . '</em>'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_table.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,33 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Missing View'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'The view for %1$s%2$s was not found.', '<em>' . Inflector::camelize($this->request->controller) . 'Controller::</em>', '<em>' . $this->request->action . '()</em>'); ?>
|
||||
<?php echo __d('cake_dev', 'The view for %1$s%2$s was not found.', '<em>' . h(Inflector::camelize($this->request->controller)) . 'Controller::</em>', '<em>' . h($this->request->action) . '()</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'Confirm you have created the file: %s', $file); ?>
|
||||
|
||||
<p>
|
||||
<?php echo __d('cake_dev', 'Confirm you have created the file: %s', h($file)); ?>
|
||||
in one of the following paths:
|
||||
</p>
|
||||
<ul>
|
||||
<?php
|
||||
$paths = $this->_paths($this->plugin);
|
||||
foreach ($paths as $path):
|
||||
if (strpos($path, CORE_PATH) !== false) {
|
||||
continue;
|
||||
}
|
||||
echo sprintf('<li>%s%s</li>', h($path), h($file));
|
||||
endforeach;
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'missing_view.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,38 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Database Error'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo h($error->getMessage()); ?>
|
||||
<?php echo $message; ?>
|
||||
</p>
|
||||
<?php if (!empty($error->queryString)) : ?>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'SQL Query'); ?>: </strong>
|
||||
<?php echo $error->queryString; ?>
|
||||
<?php echo h($error->queryString); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($error->params)) : ?>
|
||||
<strong><?php echo __d('cake_dev', 'SQL Query Params'); ?>: </strong>
|
||||
<?php echo Debugger::dump($error->params); ?>
|
||||
<?php echo Debugger::dump($error->params); ?>
|
||||
<?php endif; ?>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'pdo_error.ctp'); ?>
|
||||
</p>
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Private Method in %s', $controller); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', '%s%s cannot be accessed directly.', '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>'); ?>
|
||||
<?php echo __d('cake_dev', '%s%s cannot be accessed directly.', '<em>' . h($controller) . '::</em>', '<em>' . h($action) . '()</em>'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
|
||||
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s', APP_DIR . DS . 'View' . DS . 'Errors' . DS . 'private_action.ctp'); ?>
|
||||
</p>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
echo $this->element('exception_stack_trace');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo __d('cake_dev', 'Scaffold Error'); ?></h2>
|
||||
|
|
@ -33,4 +31,8 @@ function _scaffoldError() {<br />
|
|||
|
||||
</pre>
|
||||
|
||||
<?php echo $this->element('exception_stack_trace'); ?>
|
||||
<?php
|
||||
if (isset($error) && $error instanceof Exception) {
|
||||
echo $this->element('exception_stack_trace');
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,19 +1,22 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('Router', 'Routing');
|
||||
App::uses('Hash', 'Utility');
|
||||
App::uses('Inflector', 'Utility');
|
||||
|
||||
/**
|
||||
* Abstract base class for all other Helpers in CakePHP.
|
||||
|
|
@ -21,7 +24,14 @@ App::uses('Router', 'Routing');
|
|||
*
|
||||
* @package Cake.View
|
||||
*/
|
||||
class Helper extends Object {
|
||||
class Helper extends CakeObject {
|
||||
|
||||
/**
|
||||
* Settings for this helper.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $settings = array();
|
||||
|
||||
/**
|
||||
* List of helpers used by this helper
|
||||
|
|
@ -96,7 +106,7 @@ class Helper extends Object {
|
|||
|
||||
/**
|
||||
* A list of strings that should be treated as suffixes, or
|
||||
* sub inputs for a parent input. This is used for date/time
|
||||
* sub inputs for a parent input. This is used for date/time
|
||||
* inputs primarily.
|
||||
*
|
||||
* @var array
|
||||
|
|
@ -135,9 +145,48 @@ class Helper extends Object {
|
|||
* @var array
|
||||
*/
|
||||
protected $_minimizedAttributes = array(
|
||||
'compact', 'checked', 'declare', 'readonly', 'disabled', 'selected',
|
||||
'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize',
|
||||
'autoplay', 'controls', 'loop', 'muted'
|
||||
'allowfullscreen',
|
||||
'async',
|
||||
'autofocus',
|
||||
'autoplay',
|
||||
'checked',
|
||||
'compact',
|
||||
'controls',
|
||||
'declare',
|
||||
'default',
|
||||
'defaultchecked',
|
||||
'defaultmuted',
|
||||
'defaultselected',
|
||||
'defer',
|
||||
'disabled',
|
||||
'enabled',
|
||||
'formnovalidate',
|
||||
'hidden',
|
||||
'indeterminate',
|
||||
'inert',
|
||||
'ismap',
|
||||
'itemscope',
|
||||
'loop',
|
||||
'multiple',
|
||||
'muted',
|
||||
'nohref',
|
||||
'noresize',
|
||||
'noshade',
|
||||
'novalidate',
|
||||
'nowrap',
|
||||
'open',
|
||||
'pauseonexit',
|
||||
'readonly',
|
||||
'required',
|
||||
'reversed',
|
||||
'scoped',
|
||||
'seamless',
|
||||
'selected',
|
||||
'sortable',
|
||||
'spellcheck',
|
||||
'truespeed',
|
||||
'typemustmatch',
|
||||
'visible'
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
@ -163,6 +212,9 @@ class Helper extends Object {
|
|||
public function __construct(View $View, $settings = array()) {
|
||||
$this->_View = $View;
|
||||
$this->request = $View->request;
|
||||
if ($settings) {
|
||||
$this->settings = Hash::merge($this->settings, $settings);
|
||||
}
|
||||
if (!empty($this->helpers)) {
|
||||
$this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers);
|
||||
}
|
||||
|
|
@ -184,10 +236,11 @@ class Helper extends Object {
|
|||
*
|
||||
* @param string $name Name of the property being accessed.
|
||||
* @return mixed Helper or property found at $name
|
||||
* @deprecated 3.0.0 Accessing request properties through this method is deprecated and will be removed in 3.0.
|
||||
*/
|
||||
public function __get($name) {
|
||||
if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {
|
||||
$settings = array_merge((array)$this->_helperMap[$name]['settings'], array('enabled' => false));
|
||||
$settings = array('enabled' => false) + (array)$this->_helperMap[$name]['settings'];
|
||||
$this->{$name} = $this->_View->loadHelper($this->_helperMap[$name]['class'], $settings);
|
||||
}
|
||||
if (isset($this->{$name})) {
|
||||
|
|
@ -210,8 +263,9 @@ class Helper extends Object {
|
|||
* Provides backwards compatibility access for setting values to the request object.
|
||||
*
|
||||
* @param string $name Name of the property being accessed.
|
||||
* @param mixed $value
|
||||
* @return mixed Return the $value
|
||||
* @param mixed $value Value to set.
|
||||
* @return void
|
||||
* @deprecated 3.0.0 This method will be removed in 3.0
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
switch ($name) {
|
||||
|
|
@ -219,11 +273,13 @@ class Helper extends Object {
|
|||
case 'here':
|
||||
case 'webroot':
|
||||
case 'data':
|
||||
return $this->request->{$name} = $value;
|
||||
$this->request->{$name} = $value;
|
||||
return;
|
||||
case 'action':
|
||||
return $this->request->params['action'] = $value;
|
||||
$this->request->params['action'] = $value;
|
||||
return;
|
||||
}
|
||||
return $this->{$name} = $value;
|
||||
$this->{$name} = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -232,10 +288,10 @@ class Helper extends Object {
|
|||
* Returns a URL pointing at the provided parameters.
|
||||
*
|
||||
* @param string|array $url Either a relative string url like `/products/view/23` or
|
||||
* an array of url parameters. Using an array for urls will allow you to leverage
|
||||
* an array of URL parameters. Using an array for URLs will allow you to leverage
|
||||
* the reverse routing features of CakePHP.
|
||||
* @param boolean $full If true, the full base URL will be prepended to the result
|
||||
* @return string Full translated URL with base path.
|
||||
* @param bool $full If true, the full base URL will be prepended to the result
|
||||
* @return string Full translated URL with base path.
|
||||
* @link http://book.cakephp.org/2.0/en/views/helpers.html
|
||||
*/
|
||||
public function url($url = null, $full = false) {
|
||||
|
|
@ -279,16 +335,16 @@ class Helper extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate url for given asset file. Depending on options passed provides full url with domain name.
|
||||
* Generate URL for given asset file. Depending on options passed provides full URL with domain name.
|
||||
* Also calls Helper::assetTimestamp() to add timestamp to local files
|
||||
*
|
||||
* @param string|array Path string or url array
|
||||
* @param string|array $path Path string or URL array
|
||||
* @param array $options Options array. Possible keys:
|
||||
* `fullBase` Return full url with domain name
|
||||
* `pathPrefix` Path prefix for relative urls
|
||||
* `fullBase` Return full URL with domain name
|
||||
* `pathPrefix` Path prefix for relative URLs
|
||||
* `ext` Asset extension to append
|
||||
* `plugin` False value will prevent parsing path as a plugin
|
||||
* @return string Generated url
|
||||
* @return string Generated URL
|
||||
*/
|
||||
public function assetUrl($path, $options = array()) {
|
||||
if (is_array($path)) {
|
||||
|
|
@ -303,25 +359,22 @@ class Helper extends Object {
|
|||
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
|
||||
$path = $options['pathPrefix'] . $path;
|
||||
}
|
||||
if (
|
||||
!empty($options['ext']) &&
|
||||
if (!empty($options['ext']) &&
|
||||
strpos($path, '?') === false &&
|
||||
substr($path, -strlen($options['ext'])) !== $options['ext']
|
||||
) {
|
||||
$path .= $options['ext'];
|
||||
}
|
||||
if (preg_match('|^([a-z0-9]+:)?//|', $path)) {
|
||||
return $path;
|
||||
}
|
||||
if (isset($plugin)) {
|
||||
$path = Inflector::underscore($plugin) . '/' . $path;
|
||||
}
|
||||
$path = $this->_encodeUrl($this->assetTimestamp($this->webroot($path)));
|
||||
|
||||
if (!empty($options['fullBase'])) {
|
||||
$base = $this->url('/', true);
|
||||
$len = strlen($this->request->webroot);
|
||||
if ($len) {
|
||||
$base = substr($base, 0, -$len);
|
||||
}
|
||||
$path = $base . $path;
|
||||
$path = rtrim(Router::fullBaseUrl(), '/') . '/' . ltrim($path, '/');
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
|
@ -329,21 +382,20 @@ class Helper extends Object {
|
|||
/**
|
||||
* Encodes a URL for use in HTML attributes.
|
||||
*
|
||||
* @param string $url The url to encode.
|
||||
* @return string The url encoded for both URL & HTML contexts.
|
||||
* @param string $url The URL to encode.
|
||||
* @return string The URL encoded for both URL & HTML contexts.
|
||||
*/
|
||||
protected function _encodeUrl($url) {
|
||||
$path = parse_url($url, PHP_URL_PATH);
|
||||
$encoded = implode('/', array_map(
|
||||
'rawurlencode',
|
||||
explode('/', $path)
|
||||
));
|
||||
$parts = array_map('rawurldecode', explode('/', $path));
|
||||
$parts = array_map('rawurlencode', $parts);
|
||||
$encoded = implode('/', $parts);
|
||||
return h(str_replace($path, $encoded, $url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
|
||||
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force'
|
||||
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp === 'force'
|
||||
* a timestamp will be added.
|
||||
*
|
||||
* @param string $path The file path to timestamp, the path must be inside WWW_ROOT
|
||||
|
|
@ -353,7 +405,11 @@ class Helper extends Object {
|
|||
$stamp = Configure::read('Asset.timestamp');
|
||||
$timestampEnabled = $stamp === 'force' || ($stamp === true && Configure::read('debug') > 0);
|
||||
if ($timestampEnabled && strpos($path, '?') === false) {
|
||||
$filepath = preg_replace('/^' . preg_quote($this->request->webroot, '/') . '/', '', $path);
|
||||
$filepath = preg_replace(
|
||||
'/^' . preg_quote($this->request->webroot, '/') . '/',
|
||||
'',
|
||||
urldecode($path)
|
||||
);
|
||||
$webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
|
||||
if (file_exists($webrootPath)) {
|
||||
//@codingStandardsIgnoreStart
|
||||
|
|
@ -383,12 +439,13 @@ class Helper extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Used to remove harmful tags from content. Removes a number of well known XSS attacks
|
||||
* from content. However, is not guaranteed to remove all possibilities. Escaping
|
||||
* Used to remove harmful tags from content. Removes a number of well known XSS attacks
|
||||
* from content. However, is not guaranteed to remove all possibilities. Escaping
|
||||
* content is the best way to prevent all possible attacks.
|
||||
*
|
||||
* @param string|array $output Either an array of strings to clean or a single string to clean.
|
||||
* @return string|array cleaned content for output
|
||||
* @return string|array|null Cleaned content for output
|
||||
* @deprecated 3.0.0 This method will be removed in 3.0
|
||||
*/
|
||||
public function clean($output) {
|
||||
$this->_reset();
|
||||
|
|
@ -407,22 +464,8 @@ class Helper extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a space-delimited string with items of the $options array. If a
|
||||
* key of $options array happens to be one of:
|
||||
*
|
||||
* - 'compact'
|
||||
* - 'checked'
|
||||
* - 'declare'
|
||||
* - 'readonly'
|
||||
* - 'disabled'
|
||||
* - 'selected'
|
||||
* - 'defer'
|
||||
* - 'ismap'
|
||||
* - 'nohref'
|
||||
* - 'noshade'
|
||||
* - 'nowrap'
|
||||
* - 'multiple'
|
||||
* - 'noresize'
|
||||
* Returns a space-delimited string with items of the $options array. If a key
|
||||
* of $options array happens to be one of those listed in `Helper::$_minimizedAttributes`
|
||||
*
|
||||
* And its value is one of:
|
||||
*
|
||||
|
|
@ -435,7 +478,7 @@ class Helper extends Object {
|
|||
* If the value is not one of these 3, the parameter is not output.
|
||||
*
|
||||
* 'escape' is a special option in that it controls the conversion of
|
||||
* attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.
|
||||
* attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.
|
||||
*
|
||||
* If value for any option key is set to `null` or `false`, that option will be excluded from output.
|
||||
*
|
||||
|
|
@ -444,7 +487,7 @@ class Helper extends Object {
|
|||
* @param string $insertBefore String to be inserted before options.
|
||||
* @param string $insertAfter String to be inserted after options.
|
||||
* @return string Composed attributes.
|
||||
* @deprecated This method will be moved to HtmlHelper in 3.0
|
||||
* @deprecated 3.0.0 This method will be moved to HtmlHelper in 3.0
|
||||
*/
|
||||
protected function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
||||
if (!is_string($options)) {
|
||||
|
|
@ -476,33 +519,51 @@ class Helper extends Object {
|
|||
*
|
||||
* @param string $key The name of the attribute to create
|
||||
* @param string $value The value of the attribute to create.
|
||||
* @param boolean $escape Define if the value must be escaped
|
||||
* @param bool $escape Define if the value must be escaped
|
||||
* @return string The composed attribute.
|
||||
* @deprecated This method will be moved to HtmlHelper in 3.0
|
||||
* @deprecated 3.0.0 This method will be moved to HtmlHelper in 3.0
|
||||
*/
|
||||
protected function _formatAttribute($key, $value, $escape = true) {
|
||||
$attribute = '';
|
||||
if (is_array($value)) {
|
||||
$value = implode(' ' , $value);
|
||||
$value = implode(' ', $value);
|
||||
}
|
||||
|
||||
if (is_numeric($key)) {
|
||||
$attribute = sprintf($this->_minimizedAttributeFormat, $value, $value);
|
||||
} elseif (in_array($key, $this->_minimizedAttributes)) {
|
||||
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
|
||||
$attribute = sprintf($this->_minimizedAttributeFormat, $key, $key);
|
||||
}
|
||||
} else {
|
||||
$attribute = sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
|
||||
return sprintf($this->_minimizedAttributeFormat, $value, $value);
|
||||
}
|
||||
return $attribute;
|
||||
$truthy = array(1, '1', true, 'true', $key);
|
||||
$isMinimized = in_array($key, $this->_minimizedAttributes);
|
||||
if ($isMinimized && in_array($value, $truthy, true)) {
|
||||
return sprintf($this->_minimizedAttributeFormat, $key, $key);
|
||||
}
|
||||
if ($isMinimized) {
|
||||
return '';
|
||||
}
|
||||
return sprintf($this->_attributeFormat, $key, ($escape ? h($value) : $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string to be used as onclick handler for confirm dialogs.
|
||||
*
|
||||
* @param string $message Message to be displayed
|
||||
* @param string $okCode Code to be executed after user chose 'OK'
|
||||
* @param string $cancelCode Code to be executed after user chose 'Cancel', also executed when okCode doesn't return
|
||||
* @param array $options Array of options
|
||||
* @return string onclick JS code
|
||||
*/
|
||||
protected function _confirm($message, $okCode, $cancelCode = '', $options = array()) {
|
||||
$message = json_encode($message);
|
||||
$confirm = "if (confirm({$message})) { {$okCode} } {$cancelCode}";
|
||||
if (isset($options['escape']) && $options['escape'] === false) {
|
||||
$confirm = h($confirm);
|
||||
}
|
||||
return $confirm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this helper's model and field properties to the dot-separated value-pair in $entity.
|
||||
*
|
||||
* @param string $entity A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName"
|
||||
* @param boolean $setScope Sets the view scope to the model specified in $tagValue
|
||||
* @param bool $setScope Sets the view scope to the model specified in $tagValue
|
||||
* @return void
|
||||
*/
|
||||
public function setEntity($entity, $setScope = false) {
|
||||
|
|
@ -520,8 +581,7 @@ class Helper extends Object {
|
|||
$lastPart = isset($parts[$count - 1]) ? $parts[$count - 1] : null;
|
||||
|
||||
// Either 'body' or 'date.month' type inputs.
|
||||
if (
|
||||
($count === 1 && $this->_modelScope && $setScope == false) ||
|
||||
if (($count === 1 && $this->_modelScope && !$setScope) ||
|
||||
(
|
||||
$count === 2 &&
|
||||
in_array($lastPart, $this->_fieldSuffixes) &&
|
||||
|
|
@ -532,9 +592,8 @@ class Helper extends Object {
|
|||
$entity = $this->_modelScope . '.' . $entity;
|
||||
}
|
||||
|
||||
// 0.name, 0.created.month style inputs. Excludes inputs with the modelScope in them.
|
||||
if (
|
||||
$count >= 2 &&
|
||||
// 0.name, 0.created.month style inputs. Excludes inputs with the modelScope in them.
|
||||
if ($count >= 2 &&
|
||||
is_numeric($parts[0]) &&
|
||||
!is_numeric($parts[1]) &&
|
||||
$this->_modelScope &&
|
||||
|
|
@ -547,12 +606,11 @@ class Helper extends Object {
|
|||
|
||||
$isHabtm = (
|
||||
isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
|
||||
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' &&
|
||||
$count == 1
|
||||
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
|
||||
);
|
||||
|
||||
// habtm models are special
|
||||
if ($count == 1 && $isHabtm) {
|
||||
if ($count === 1 && $isHabtm) {
|
||||
$this->_association = $parts[0];
|
||||
$entity = $parts[0] . '.' . $parts[0];
|
||||
} else {
|
||||
|
|
@ -613,7 +671,7 @@ class Helper extends Object {
|
|||
* @param array|string $options Either an array of html attributes to add $id into, or a string
|
||||
* with a view entity path to get a domId for.
|
||||
* @param string $id The name of the 'id' attribute.
|
||||
* @return mixed If $options was an array, an array will be returned with $id set. If a string
|
||||
* @return mixed If $options was an array, an array will be returned with $id set. If a string
|
||||
* was supplied, a string will be returned.
|
||||
*/
|
||||
public function domId($options = null, $id = 'id') {
|
||||
|
|
@ -627,7 +685,7 @@ class Helper extends Object {
|
|||
|
||||
$entity = $this->entity();
|
||||
$model = array_shift($entity);
|
||||
$dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity));
|
||||
$dom = $model . implode('', array_map(array('Inflector', 'camelize'), $entity));
|
||||
|
||||
if (is_array($options) && !array_key_exists($id, $options)) {
|
||||
$options[$id] = $dom;
|
||||
|
|
@ -643,7 +701,7 @@ class Helper extends Object {
|
|||
*
|
||||
* @param array|string $options If an array, should be an array of attributes that $key needs to be added to.
|
||||
* If a string or null, will be used as the View entity.
|
||||
* @param string $field
|
||||
* @param string $field Field name.
|
||||
* @param string $key The name of the attribute to be set, defaults to 'name'
|
||||
* @return mixed If an array was given for $options, an array with $key set will be returned.
|
||||
* If a string was supplied a string will be returned.
|
||||
|
|
@ -667,18 +725,16 @@ class Helper extends Object {
|
|||
switch ($field) {
|
||||
case '_method':
|
||||
$name = $field;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$name = 'data[' . implode('][', $this->entity()) . ']';
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
$options[$key] = $name;
|
||||
return $options;
|
||||
} else {
|
||||
return $name;
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -686,7 +742,7 @@ class Helper extends Object {
|
|||
*
|
||||
* @param array|string $options If an array, should be an array of attributes that $key needs to be added to.
|
||||
* If a string or null, will be used as the View entity.
|
||||
* @param string $field
|
||||
* @param string $field Field name.
|
||||
* @param string $key The name of the attribute to be set, defaults to 'value'
|
||||
* @return mixed If an array was given for $options, an array with $key set will be returned.
|
||||
* If a string was supplied a string will be returned.
|
||||
|
|
@ -734,13 +790,12 @@ class Helper extends Object {
|
|||
if (is_array($options)) {
|
||||
$options[$key] = $result;
|
||||
return $options;
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the defaults for an input tag. Will set the
|
||||
* Sets the defaults for an input tag. Will set the
|
||||
* name, value, and id attributes for an array of html attributes.
|
||||
*
|
||||
* @param string $field The field name to initialize.
|
||||
|
|
@ -762,12 +817,12 @@ class Helper extends Object {
|
|||
* Adds the given class to the element options
|
||||
*
|
||||
* @param array $options Array options/attributes to add a class to
|
||||
* @param string $class The classname being added.
|
||||
* @param string $class The class name being added.
|
||||
* @param string $key the key to use for class.
|
||||
* @return array Array of options with $key set.
|
||||
*/
|
||||
public function addClass($options = array(), $class = null, $key = 'class') {
|
||||
if (isset($options[$key]) && trim($options[$key]) != '') {
|
||||
if (isset($options[$key]) && trim($options[$key])) {
|
||||
$options[$key] .= ' ' . $class;
|
||||
} else {
|
||||
$options[$key] = $class;
|
||||
|
|
@ -782,7 +837,7 @@ class Helper extends Object {
|
|||
*
|
||||
* @param string $str String to be output.
|
||||
* @return string
|
||||
* @deprecated This method will be removed in future versions.
|
||||
* @deprecated 3.0.0 This method will be removed in future versions.
|
||||
*/
|
||||
public function output($str) {
|
||||
return $str;
|
||||
|
|
@ -800,7 +855,7 @@ class Helper extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* After render callback. afterRender is called after the view file is rendered
|
||||
* After render callback. afterRender is called after the view file is rendered
|
||||
* but before the layout has been rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
|
|
@ -812,7 +867,7 @@ class Helper extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Before layout callback. beforeLayout is called before the layout is rendered.
|
||||
* Before layout callback. beforeLayout is called before the layout is rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
*
|
||||
|
|
@ -823,7 +878,7 @@ class Helper extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* After layout callback. afterLayout is called after the layout has rendered.
|
||||
* After layout callback. afterLayout is called after the layout has rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
*
|
||||
|
|
@ -842,7 +897,7 @@ class Helper extends Object {
|
|||
* @param string $viewFile The file about to be rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function beforeRenderFile($viewfile) {
|
||||
public function beforeRenderFile($viewFile) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -855,15 +910,15 @@ class Helper extends Object {
|
|||
* @param string $content The content that was rendered.
|
||||
* @return void
|
||||
*/
|
||||
public function afterRenderFile($viewfile, $content) {
|
||||
public function afterRenderFile($viewFile, $content) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a recordset from a hasAndBelongsToMany association to a list of selected
|
||||
* options for a multiple select element
|
||||
*
|
||||
* @param string|array $data
|
||||
* @param string $key
|
||||
* @param string|array $data Data array or model name.
|
||||
* @param string $key Field name.
|
||||
* @return array
|
||||
*/
|
||||
protected function _selectedArray($data, $key = 'id') {
|
||||
|
|
@ -925,7 +980,7 @@ class Helper extends Object {
|
|||
do {
|
||||
$oldstring = $this->_cleaned;
|
||||
$this->_cleaned = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $this->_cleaned);
|
||||
} while ($oldstring != $this->_cleaned);
|
||||
} while ($oldstring !== $this->_cleaned);
|
||||
$this->_cleaned = str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $this->_cleaned);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* CacheHelper helps create full page view caching.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.0.0.2277
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -25,8 +22,10 @@ App::uses('AppHelper', 'View/Helper');
|
|||
* When using CacheHelper you don't call any of its methods, they are all automatically
|
||||
* called by View, and use the $cacheAction settings set in the controller.
|
||||
*
|
||||
* @package Cake.View.Helper
|
||||
* @package Cake.View.Helper
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html
|
||||
* @deprecated This class will be removed in 3.0. You should use a separate response cache
|
||||
* like Varnish instead.
|
||||
*/
|
||||
class CacheHelper extends AppHelper {
|
||||
|
||||
|
|
@ -49,24 +48,25 @@ class CacheHelper extends AppHelper {
|
|||
/**
|
||||
* Counter used for counting nocache section tags.
|
||||
*
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $_counter = 0;
|
||||
|
||||
/**
|
||||
* Is CacheHelper enabled? should files + output be parsed.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
protected function _enabled() {
|
||||
return (($this->_View->cacheAction != false)) && (Configure::read('Cache.check') === true);
|
||||
return $this->_View->cacheAction && (Configure::read('Cache.check') === true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the view file and stores content for cache file building.
|
||||
*
|
||||
* @param string $viewFile
|
||||
* @return void
|
||||
* @param string $viewFile View file name.
|
||||
* @param string $output The output for the file.
|
||||
* @return string Updated content.
|
||||
*/
|
||||
public function afterRenderFile($viewFile, $output) {
|
||||
if ($this->_enabled()) {
|
||||
|
|
@ -77,7 +77,7 @@ class CacheHelper extends AppHelper {
|
|||
/**
|
||||
* Parses the layout file and stores content for cache file building.
|
||||
*
|
||||
* @param string $layoutFile
|
||||
* @param string $layoutFile Layout file name.
|
||||
* @return void
|
||||
*/
|
||||
public function afterLayout($layoutFile) {
|
||||
|
|
@ -88,7 +88,7 @@ class CacheHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Parse a file + output. Matches nocache tags between the current output and the current file
|
||||
* Parse a file + output. Matches nocache tags between the current output and the current file
|
||||
* stores a reference of the file, so the generated can be swapped back with the file contents when
|
||||
* writing the cache file.
|
||||
*
|
||||
|
|
@ -107,8 +107,9 @@ class CacheHelper extends AppHelper {
|
|||
*
|
||||
* @param string $file File to cache
|
||||
* @param string $out output to cache
|
||||
* @return string view ouput
|
||||
* @return string view output
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html
|
||||
* @throws Exception If debug mode is enabled and writing to cache file fails.
|
||||
*/
|
||||
public function cache($file, $out) {
|
||||
$cacheTime = 0;
|
||||
|
|
@ -120,20 +121,20 @@ class CacheHelper extends AppHelper {
|
|||
$index = null;
|
||||
|
||||
foreach ($keys as $action) {
|
||||
if ($action == $this->request->params['action']) {
|
||||
if ($action === $this->request->params['action']) {
|
||||
$index = $action;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($index) && $this->request->params['action'] == 'index') {
|
||||
if (!isset($index) && $this->request->params['action'] === 'index') {
|
||||
$index = 'index';
|
||||
}
|
||||
|
||||
$options = $cacheAction;
|
||||
if (isset($cacheAction[$index])) {
|
||||
if (is_array($cacheAction[$index])) {
|
||||
$options = array_merge(array('duration' => 0, 'callbacks' => false), $cacheAction[$index]);
|
||||
$options = $cacheAction[$index] + array('duration' => 0, 'callbacks' => false);
|
||||
} else {
|
||||
$cacheTime = $cacheAction[$index];
|
||||
}
|
||||
|
|
@ -148,11 +149,15 @@ class CacheHelper extends AppHelper {
|
|||
$cacheTime = $cacheAction;
|
||||
}
|
||||
|
||||
if ($cacheTime != '' && $cacheTime > 0) {
|
||||
if ($cacheTime && $cacheTime > 0) {
|
||||
$cached = $this->_parseOutput($out);
|
||||
try {
|
||||
$this->_writeFile($cached, $cacheTime, $useCallbacks);
|
||||
} catch (Exception $e) {
|
||||
if (Configure::read('debug')) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$message = __d(
|
||||
'cake_dev',
|
||||
'Unable to write view cache file: "%s" for "%s"',
|
||||
|
|
@ -266,8 +271,9 @@ class CacheHelper extends AppHelper {
|
|||
*
|
||||
* @param string $content view content to write to a cache file.
|
||||
* @param string $timestamp Duration to set for cache file.
|
||||
* @param boolean $useCallbacks
|
||||
* @return boolean success of caching view.
|
||||
* @param bool|null $useCallbacks Whether to include statements in cached file which
|
||||
* run callbacks, otherwise null.
|
||||
* @return bool success of caching view.
|
||||
*/
|
||||
protected function _writeFile($content, $timestamp, $useCallbacks = false) {
|
||||
$now = time();
|
||||
|
|
@ -278,13 +284,17 @@ class CacheHelper extends AppHelper {
|
|||
$cacheTime = strtotime($timestamp, $now);
|
||||
}
|
||||
$path = $this->request->here();
|
||||
if ($path == '/') {
|
||||
if ($path === '/') {
|
||||
$path = 'home';
|
||||
}
|
||||
$prefix = Configure::read('Cache.viewPrefix');
|
||||
if ($prefix) {
|
||||
$path = $prefix . '_' . $path;
|
||||
}
|
||||
$cache = strtolower(Inflector::slug($path));
|
||||
|
||||
if (empty($cache)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$cache = $cache . '.php';
|
||||
$file = '<!--cachetime:' . $cacheTime . '--><?php';
|
||||
|
|
@ -302,7 +312,7 @@ class CacheHelper extends AppHelper {
|
|||
|
||||
$file .= '
|
||||
$request = unserialize(base64_decode(\'' . base64_encode(serialize($this->request)) . '\'));
|
||||
$response = new CakeResponse(array("charset" => Configure::read("App.encoding")));
|
||||
$response->type(\'' . $this->_View->response->type() . '\');
|
||||
$controller = new ' . $this->_View->name . 'Controller($request, $response);
|
||||
$controller->plugin = $this->plugin = \'' . $this->_View->plugin . '\';
|
||||
$controller->helpers = $this->helpers = unserialize(base64_decode(\'' . base64_encode(serialize($this->_View->helpers)) . '\'));
|
||||
|
|
@ -312,7 +322,7 @@ class CacheHelper extends AppHelper {
|
|||
Router::setRequestInfo($controller->request);
|
||||
$this->request = $request;';
|
||||
|
||||
if ($useCallbacks == true) {
|
||||
if ($useCallbacks) {
|
||||
$file .= '
|
||||
$controller->constructClasses();
|
||||
$controller->startupProcess();';
|
||||
|
|
|
|||
95
lib/Cake/View/Helper/FlashHelper.php
Normal file
95
lib/Cake/View/Helper/FlashHelper.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Flash Helper
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 2.7.0-dev
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
App::uses('CakeSession', 'Model/Datasource');
|
||||
|
||||
/**
|
||||
* FlashHelper class to render flash messages.
|
||||
*
|
||||
* After setting messages in your controllers with FlashComponent, you can use
|
||||
* this class to output your flash messages in your views.
|
||||
*
|
||||
* @package Cake.View.Helper
|
||||
*/
|
||||
class FlashHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Used to render the message set in FlashComponent::set()
|
||||
*
|
||||
* In your view: $this->Flash->render('somekey');
|
||||
* Will default to flash if no param is passed
|
||||
*
|
||||
* You can pass additional information into the flash message generation. This allows you
|
||||
* to consolidate all the parameters for a given type of flash message into the view.
|
||||
*
|
||||
* ```
|
||||
* echo $this->Flash->render('flash', array('params' => array('name' => $user['User']['name'])));
|
||||
* ```
|
||||
*
|
||||
* This would pass the current user's name into the flash message, so you could create personalized
|
||||
* messages without the controller needing access to that data.
|
||||
*
|
||||
* Lastly you can choose the element that is used for rendering the flash message. Using
|
||||
* custom elements allows you to fully customize how flash messages are generated.
|
||||
*
|
||||
* ```
|
||||
* echo $this->Flash->render('flash', array('element' => 'my_custom_element'));
|
||||
* ```
|
||||
*
|
||||
* If you want to use an element from a plugin for rendering your flash message
|
||||
* you can use the dot notation for the plugin's element name:
|
||||
*
|
||||
* ```
|
||||
* echo $this->Flash->render('flash', array(
|
||||
* 'element' => 'MyPlugin.my_custom_element',
|
||||
* ));
|
||||
* ```
|
||||
*
|
||||
* @param string $key The [Message.]key you are rendering in the view.
|
||||
* @param array $options Additional options to use for the creation of this flash message.
|
||||
* Supports the 'params', and 'element' keys that are used in the helper.
|
||||
* @return string|null Rendered flash message or null if flash key does not exist
|
||||
* in session.
|
||||
* @throws UnexpectedValueException If value for flash settings key is not an array.
|
||||
*/
|
||||
public function render($key = 'flash', $options = array()) {
|
||||
if (!CakeSession::check("Message.$key")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$flash = CakeSession::read("Message.$key");
|
||||
|
||||
if (!is_array($flash)) {
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'Value for flash setting key "%s" must be an array.',
|
||||
$key
|
||||
));
|
||||
}
|
||||
|
||||
$flash = $options + $flash;
|
||||
CakeSession::delete("Message.$key");
|
||||
$flash['key'] = $key;
|
||||
|
||||
if ($flash['element'] === 'default') {
|
||||
$flash['element'] = 'Flash/default';
|
||||
}
|
||||
|
||||
return $this->_View->element($flash['element'], $flash);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -5,16 +5,17 @@
|
|||
* Simplifies the construction of HTML elements.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 0.9.1
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -46,13 +47,14 @@ class HtmlHelper extends AppHelper {
|
|||
'meta' => '<meta%s/>',
|
||||
'metalink' => '<link href="%s"%s/>',
|
||||
'link' => '<a href="%s"%s>%s</a>',
|
||||
'mailto' => '<a href="mailto:%s" %s>%s</a>',
|
||||
'mailto' => '<a href="mailto:%s"%s>%s</a>',
|
||||
'form' => '<form action="%s"%s>',
|
||||
'formwithoutaction' => '<form%s>',
|
||||
'formend' => '</form>',
|
||||
'input' => '<input name="%s"%s/>',
|
||||
'textarea' => '<textarea name="%s"%s>%s</textarea>',
|
||||
'hidden' => '<input type="hidden" name="%s"%s/>',
|
||||
'checkbox' => '<input type="checkbox" name="%s" %s/>',
|
||||
'checkbox' => '<input type="checkbox" name="%s"%s/>',
|
||||
'checkboxmultiple' => '<input type="checkbox" name="%s[]"%s />',
|
||||
'radio' => '<input type="radio" name="%s" id="%s"%s />%s',
|
||||
'selectstart' => '<select name="%s"%s>',
|
||||
|
|
@ -64,13 +66,13 @@ class HtmlHelper extends AppHelper {
|
|||
'optiongroupend' => '</optgroup>',
|
||||
'checkboxmultiplestart' => '',
|
||||
'checkboxmultipleend' => '',
|
||||
'password' => '<input type="password" name="%s" %s/>',
|
||||
'file' => '<input type="file" name="%s" %s/>',
|
||||
'file_no_model' => '<input type="file" name="%s" %s/>',
|
||||
'submit' => '<input %s/>',
|
||||
'submitimage' => '<input type="image" src="%s" %s/>',
|
||||
'password' => '<input type="password" name="%s"%s/>',
|
||||
'file' => '<input type="file" name="%s"%s/>',
|
||||
'file_no_model' => '<input type="file" name="%s"%s/>',
|
||||
'submit' => '<input%s/>',
|
||||
'submitimage' => '<input type="image" src="%s"%s/>',
|
||||
'button' => '<button%s>%s</button>',
|
||||
'image' => '<img src="%s" %s/>',
|
||||
'image' => '<img src="%s"%s/>',
|
||||
'tableheader' => '<th%s>%s</th>',
|
||||
'tableheaderrow' => '<tr%s>%s</tr>',
|
||||
'tablecell' => '<td%s>%s</td>',
|
||||
|
|
@ -78,6 +80,7 @@ class HtmlHelper extends AppHelper {
|
|||
'block' => '<div%s>%s</div>',
|
||||
'blockstart' => '<div%s>',
|
||||
'blockend' => '</div>',
|
||||
'hiddenblock' => '<div style="display:none;">%s</div>',
|
||||
'tag' => '<%s%s>%s</%s>',
|
||||
'tagstart' => '<%s%s>',
|
||||
'tagend' => '</%s>',
|
||||
|
|
@ -89,15 +92,15 @@ class HtmlHelper extends AppHelper {
|
|||
'fieldsetstart' => '<fieldset><legend>%s</legend>',
|
||||
'fieldsetend' => '</fieldset>',
|
||||
'legend' => '<legend>%s</legend>',
|
||||
'css' => '<link rel="%s" type="text/css" href="%s" %s/>',
|
||||
'css' => '<link rel="%s" type="text/css" href="%s"%s/>',
|
||||
'style' => '<style type="text/css"%s>%s</style>',
|
||||
'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
|
||||
'ul' => '<ul%s>%s</ul>',
|
||||
'ol' => '<ol%s>%s</ol>',
|
||||
'li' => '<li%s>%s</li>',
|
||||
'error' => '<div%s>%s</div>',
|
||||
'javascriptblock' => '<script type="text/javascript"%s>%s</script>',
|
||||
'javascriptstart' => '<script type="text/javascript">',
|
||||
'javascriptblock' => '<script%s>%s</script>',
|
||||
'javascriptstart' => '<script>',
|
||||
'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
|
||||
'javascriptend' => '</script>'
|
||||
);
|
||||
|
|
@ -110,11 +113,11 @@ class HtmlHelper extends AppHelper {
|
|||
protected $_crumbs = array();
|
||||
|
||||
/**
|
||||
* Names of script files that have been included once
|
||||
* Names of script & css files that have been included once
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_includedScripts = array();
|
||||
protected $_includedAssets = array();
|
||||
|
||||
/**
|
||||
* Options for the currently opened script block buffer if any.
|
||||
|
|
@ -159,7 +162,7 @@ class HtmlHelper extends AppHelper {
|
|||
if (is_object($this->_View->response)) {
|
||||
$this->response = $this->_View->response;
|
||||
} else {
|
||||
$this->response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
|
||||
$this->response = new CakeResponse();
|
||||
}
|
||||
if (!empty($settings['configFile'])) {
|
||||
$this->loadConfig($settings['configFile']);
|
||||
|
|
@ -172,12 +175,13 @@ class HtmlHelper extends AppHelper {
|
|||
* @param string $name Text for link
|
||||
* @param string $link URL for link (if empty it won't be a link)
|
||||
* @param string|array $options Link attributes e.g. array('id' => 'selected')
|
||||
* @return void
|
||||
* @return self
|
||||
* @see HtmlHelper::link() for details on $options that can be used.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
|
||||
*/
|
||||
public function addCrumb($name, $link = null, $options = null) {
|
||||
$this->_crumbs[] = array($name, $link, $options);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,7 +199,7 @@ class HtmlHelper extends AppHelper {
|
|||
* - xhtml11: XHTML1.1.
|
||||
*
|
||||
* @param string $type Doctype to use.
|
||||
* @return string Doctype string
|
||||
* @return string|null Doctype string
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::docType
|
||||
*/
|
||||
public function docType($type = 'html5') {
|
||||
|
|
@ -224,7 +228,7 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* - `inline` Whether or not the link element should be output inline. Set to false to
|
||||
* have the meta tag included in `$scripts_for_layout`, and appended to the 'meta' view block.
|
||||
* - `block` Choose a custom block to append the meta tag to. Using this option
|
||||
* - `block` Choose a custom block to append the meta tag to. Using this option
|
||||
* will override the inline option.
|
||||
*
|
||||
* @param string $type The title of the external resource
|
||||
|
|
@ -251,7 +255,7 @@ class HtmlHelper extends AppHelper {
|
|||
);
|
||||
|
||||
if ($type === 'icon' && $url === null) {
|
||||
$types['icon']['link'] = $this->webroot('favicon.ico');
|
||||
$types['icon']['link'] = 'favicon.ico';
|
||||
}
|
||||
|
||||
if (isset($types[$type])) {
|
||||
|
|
@ -268,29 +272,26 @@ class HtmlHelper extends AppHelper {
|
|||
} else {
|
||||
$type = array();
|
||||
}
|
||||
} elseif ($url !== null) {
|
||||
$inline = $url;
|
||||
}
|
||||
$options = array_merge($type, $options);
|
||||
|
||||
$options += $type;
|
||||
$out = null;
|
||||
|
||||
if (isset($options['link'])) {
|
||||
$options['link'] = $this->assetUrl($options['link']);
|
||||
if (isset($options['rel']) && $options['rel'] === 'icon') {
|
||||
$out = sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' '));
|
||||
$out = sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link')));
|
||||
$options['rel'] = 'shortcut icon';
|
||||
} else {
|
||||
$options['link'] = $this->url($options['link'], true);
|
||||
}
|
||||
$out .= sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' '));
|
||||
$out .= sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link')));
|
||||
} else {
|
||||
$out = sprintf($this->_tags['meta'], $this->_parseAttributes($options, array('block', 'type'), ' ', ' '));
|
||||
$out = sprintf($this->_tags['meta'], $this->_parseAttributes($options, array('block', 'type')));
|
||||
}
|
||||
|
||||
if (empty($options['block'])) {
|
||||
return $out;
|
||||
} else {
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -320,12 +321,14 @@ class HtmlHelper extends AppHelper {
|
|||
* ### Options
|
||||
*
|
||||
* - `escape` Set to false to disable escaping of title and attributes.
|
||||
* - `escapeTitle` Set to false to disable escaping of title. (Takes precedence over value of `escape`)
|
||||
* - `confirm` JavaScript confirmation message.
|
||||
*
|
||||
* @param string $title The content to be wrapped by <a> tags.
|
||||
* @param string $title The content to be wrapped by `<a>` tags.
|
||||
* @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
|
||||
* @param array $options Array of HTML attributes.
|
||||
* @param string $confirmMessage JavaScript confirmation message.
|
||||
* @param array $options Array of options and HTML attributes.
|
||||
* @param string $confirmMessage JavaScript confirmation message. This
|
||||
* argument is deprecated as of 2.6. Use `confirm` key in $options instead.
|
||||
* @return string An `<a />` element.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link
|
||||
*/
|
||||
|
|
@ -340,7 +343,10 @@ class HtmlHelper extends AppHelper {
|
|||
$escapeTitle = false;
|
||||
}
|
||||
|
||||
if (isset($options['escape'])) {
|
||||
if (isset($options['escapeTitle'])) {
|
||||
$escapeTitle = $options['escapeTitle'];
|
||||
unset($options['escapeTitle']);
|
||||
} elseif (isset($options['escape'])) {
|
||||
$escapeTitle = $options['escape'];
|
||||
}
|
||||
|
||||
|
|
@ -355,15 +361,14 @@ class HtmlHelper extends AppHelper {
|
|||
unset($options['confirm']);
|
||||
}
|
||||
if ($confirmMessage) {
|
||||
$confirmMessage = str_replace("'", "\'", $confirmMessage);
|
||||
$confirmMessage = str_replace('"', '\"', $confirmMessage);
|
||||
$options['onclick'] = "return confirm('{$confirmMessage}');";
|
||||
} elseif (isset($options['default']) && $options['default'] == false) {
|
||||
$options['onclick'] = $this->_confirm($confirmMessage, 'return true;', 'return false;', $options);
|
||||
} elseif (isset($options['default']) && !$options['default']) {
|
||||
if (isset($options['onclick'])) {
|
||||
$options['onclick'] .= ' event.returnValue = false; return false;';
|
||||
$options['onclick'] .= ' ';
|
||||
} else {
|
||||
$options['onclick'] = 'event.returnValue = false; return false;';
|
||||
$options['onclick'] = '';
|
||||
}
|
||||
$options['onclick'] .= 'event.returnValue = false; return false;';
|
||||
unset($options['default']);
|
||||
}
|
||||
return sprintf($this->_tags['link'], $url, $this->_parseAttributes($options), $title);
|
||||
|
|
@ -384,30 +389,51 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* Add the stylesheet to the `$scripts_for_layout` layout var:
|
||||
*
|
||||
* `$this->Html->css('styles.css', null, array('inline' => false));`
|
||||
* `$this->Html->css('styles.css', array('inline' => false));`
|
||||
*
|
||||
* Add the stylesheet to a custom block:
|
||||
*
|
||||
* `$this->Html->css('styles.css', null, array('block' => 'layoutCss'));`
|
||||
* `$this->Html->css('styles.css', array('block' => 'layoutCss'));`
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `inline` If set to false, the generated tag will be appended to the 'css' block,
|
||||
* and included in the `$scripts_for_layout` layout variable. Defaults to true.
|
||||
* - `block` Set the name of the block link/style tag will be appended to. This overrides the `inline`
|
||||
* option.
|
||||
* - `once` Whether or not the css file should be checked for uniqueness. If true css
|
||||
* files will only be included once, use false to allow the same
|
||||
* css to be included more than once per request.
|
||||
* - `block` Set the name of the block link/style tag will be appended to.
|
||||
* This overrides the `inline` option.
|
||||
* - `plugin` False value will prevent parsing path as a plugin
|
||||
* - `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.
|
||||
* - `fullBase` If true the URL will get a full address for the css file.
|
||||
*
|
||||
* @param string|array $path The name of a CSS style sheet or an array containing names of
|
||||
* CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
|
||||
* of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
|
||||
* @param string $rel Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported.
|
||||
* @param array $options Array of HTML attributes.
|
||||
* @return string CSS <link /> or <style /> tag, depending on the type of link.
|
||||
* @param array $options Array of options and HTML arguments.
|
||||
* @return string CSS `<link />` or `<style />` tag, depending on the type of link.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::css
|
||||
*/
|
||||
public function css($path, $rel = null, $options = array()) {
|
||||
$options += array('block' => null, 'inline' => true);
|
||||
public function css($path, $options = array()) {
|
||||
if (!is_array($options)) {
|
||||
$rel = $options;
|
||||
$options = array();
|
||||
if ($rel) {
|
||||
$options['rel'] = $rel;
|
||||
}
|
||||
if (func_num_args() > 2) {
|
||||
$options = func_get_arg(2) + $options;
|
||||
}
|
||||
unset($rel);
|
||||
}
|
||||
|
||||
$options += array(
|
||||
'block' => null,
|
||||
'inline' => true,
|
||||
'once' => false,
|
||||
'rel' => 'stylesheet'
|
||||
);
|
||||
if (!$options['inline'] && empty($options['block'])) {
|
||||
$options['block'] = __FUNCTION__;
|
||||
}
|
||||
|
|
@ -416,49 +442,60 @@ class HtmlHelper extends AppHelper {
|
|||
if (is_array($path)) {
|
||||
$out = '';
|
||||
foreach ($path as $i) {
|
||||
$out .= "\n\t" . $this->css($i, $rel, $options);
|
||||
$out .= "\n\t" . $this->css($i, $options);
|
||||
}
|
||||
if (empty($options['block'])) {
|
||||
return $out . "\n";
|
||||
}
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($options['once'] && isset($this->_includedAssets[__METHOD__][$path])) {
|
||||
return '';
|
||||
}
|
||||
unset($options['once']);
|
||||
$this->_includedAssets[__METHOD__][$path] = true;
|
||||
|
||||
if (strpos($path, '//') !== false) {
|
||||
$url = $path;
|
||||
} else {
|
||||
$url = $this->assetUrl($path, $options + array('pathPrefix' => CSS_URL, 'ext' => '.css'));
|
||||
$url = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.cssBaseUrl'), 'ext' => '.css'));
|
||||
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
|
||||
|
||||
if (Configure::read('Asset.filter.css')) {
|
||||
$pos = strpos($url, CSS_URL);
|
||||
$pos = strpos($url, Configure::read('App.cssBaseUrl'));
|
||||
if ($pos !== false) {
|
||||
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
|
||||
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(Configure::read('App.cssBaseUrl')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($rel == 'import') {
|
||||
$out = sprintf($this->_tags['style'], $this->_parseAttributes($options, array('inline', 'block'), '', ' '), '@import url(' . $url . ');');
|
||||
if ($options['rel'] === 'import') {
|
||||
$out = sprintf(
|
||||
$this->_tags['style'],
|
||||
$this->_parseAttributes($options, array('rel', 'block')),
|
||||
'@import url(' . $url . ');'
|
||||
);
|
||||
} else {
|
||||
if ($rel == null) {
|
||||
$rel = 'stylesheet';
|
||||
}
|
||||
$out = sprintf($this->_tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline', 'block'), '', ' '));
|
||||
$out = sprintf(
|
||||
$this->_tags['css'],
|
||||
$options['rel'],
|
||||
$url,
|
||||
$this->_parseAttributes($options, array('rel', 'block'))
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($options['block'])) {
|
||||
return $out;
|
||||
} else {
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns one or many `<script>` tags depending on the number of scripts given.
|
||||
*
|
||||
* If the filename is prefixed with "/", the path will be relative to the base path of your
|
||||
* application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
|
||||
*
|
||||
* application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
|
||||
*
|
||||
* ### Usage
|
||||
*
|
||||
|
|
@ -476,20 +513,21 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* Add the script file to a custom block:
|
||||
*
|
||||
* `$this->Html->script('styles.js', null, array('block' => 'bodyScript'));`
|
||||
* `$this->Html->script('styles.js', array('block' => 'bodyScript'));`
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `inline` Whether script should be output inline or into `$scripts_for_layout`. When set to false,
|
||||
* the script tag will be appended to the 'script' view block as well as `$scripts_for_layout`.
|
||||
* - `block` The name of the block you want the script appended to. Leave undefined to output inline.
|
||||
* - `block` The name of the block you want the script appended to. Leave undefined to output inline.
|
||||
* Using this option will override the inline option.
|
||||
* - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be
|
||||
* included once, use false to allow the same script to be included more than once per request.
|
||||
* - `plugin` False value will prevent parsing path as a plugin
|
||||
* - `fullBase` If true the url will get a full address for the script file.
|
||||
*
|
||||
* @param string|array $url String or array of javascript files to include
|
||||
* @param array|boolean $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
|
||||
* @param array|bool $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
|
||||
* @return mixed String of `<script />` tags or null if $inline is false or if $once is true and the file has been
|
||||
* included before.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::script
|
||||
|
|
@ -499,7 +537,7 @@ class HtmlHelper extends AppHelper {
|
|||
list($inline, $options) = array($options, array());
|
||||
$options['inline'] = $inline;
|
||||
}
|
||||
$options = array_merge(array('block' => null, 'inline' => true, 'once' => true), $options);
|
||||
$options += array('block' => null, 'inline' => true, 'once' => true);
|
||||
if (!$options['inline'] && empty($options['block'])) {
|
||||
$options['block'] = __FUNCTION__;
|
||||
}
|
||||
|
|
@ -515,26 +553,26 @@ class HtmlHelper extends AppHelper {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
if ($options['once'] && isset($this->_includedScripts[$url])) {
|
||||
if ($options['once'] && isset($this->_includedAssets[__METHOD__][$url])) {
|
||||
return null;
|
||||
}
|
||||
$this->_includedScripts[$url] = true;
|
||||
$this->_includedAssets[__METHOD__][$url] = true;
|
||||
|
||||
if (strpos($url, '//') === false) {
|
||||
$url = $this->assetUrl($url, $options + array('pathPrefix' => JS_URL, 'ext' => '.js'));
|
||||
$url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));
|
||||
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
|
||||
|
||||
if (Configure::read('Asset.filter.js')) {
|
||||
$url = str_replace(JS_URL, 'cjs/', $url);
|
||||
$url = str_replace(Configure::read('App.jsBaseUrl'), 'cjs/', $url);
|
||||
}
|
||||
}
|
||||
$attributes = $this->_parseAttributes($options, array('block', 'once'), ' ');
|
||||
$attributes = $this->_parseAttributes($options, array('block', 'once'));
|
||||
$out = sprintf($this->_tags['javascriptlink'], $url, $attributes);
|
||||
|
||||
if (empty($options['block'])) {
|
||||
return $out;
|
||||
} else {
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -542,7 +580,7 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `safe` (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
|
||||
* - `safe` (boolean) Whether or not the $script should be wrapped in `<![CDATA[ ]]>`
|
||||
* - `inline` (boolean) Whether or not the $script should be added to
|
||||
* `$scripts_for_layout` / `script` block, or output inline. (Deprecated, use `block` instead)
|
||||
* - `block` Which block you want this script block appended to.
|
||||
|
|
@ -555,23 +593,22 @@ class HtmlHelper extends AppHelper {
|
|||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptBlock
|
||||
*/
|
||||
public function scriptBlock($script, $options = array()) {
|
||||
$options += array('safe' => true, 'inline' => true);
|
||||
$options += array('type' => 'text/javascript', 'safe' => true, 'inline' => true);
|
||||
if ($options['safe']) {
|
||||
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
|
||||
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
|
||||
}
|
||||
if (!$options['inline'] && empty($options['block'])) {
|
||||
$options['block'] = 'script';
|
||||
}
|
||||
unset($options['inline'], $options['safe']);
|
||||
|
||||
$attributes = $this->_parseAttributes($options, array('block'), ' ');
|
||||
$attributes = $this->_parseAttributes($options, array('block'));
|
||||
$out = sprintf($this->_tags['javascriptblock'], $attributes, $script);
|
||||
|
||||
if (empty($options['block'])) {
|
||||
return $out;
|
||||
} else {
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -592,11 +629,10 @@ class HtmlHelper extends AppHelper {
|
|||
$options += array('safe' => true, 'inline' => true);
|
||||
$this->_scriptBlockOptions = $options;
|
||||
ob_start();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* End a Buffered section of Javascript capturing.
|
||||
* End a Buffered section of JavaScript capturing.
|
||||
* Generates a script tag inline or in `$scripts_for_layout` depending on the settings
|
||||
* used when the scriptBlock was started
|
||||
*
|
||||
|
|
@ -615,15 +651,15 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* ### Usage:
|
||||
*
|
||||
* {{{
|
||||
* echo $html->style(array('margin' => '10px', 'padding' => '10px'), true);
|
||||
* ```
|
||||
* echo $this->Html->style(array('margin' => '10px', 'padding' => '10px'), true);
|
||||
*
|
||||
* // creates
|
||||
* 'margin:10px;padding:10px;'
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @param array $data Style data array, keys will be used as property names, values as property values.
|
||||
* @param boolean $oneline Whether or not the style block should be displayed on one line.
|
||||
* @param bool $oneline Whether or not the style block should be displayed on one line.
|
||||
* @return string CSS styling data
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::style
|
||||
*/
|
||||
|
|
@ -636,7 +672,7 @@ class HtmlHelper extends AppHelper {
|
|||
$out[] = $key . ':' . $value . ';';
|
||||
}
|
||||
if ($oneline) {
|
||||
return join(' ', $out);
|
||||
return implode(' ', $out);
|
||||
}
|
||||
return implode("\n", $out);
|
||||
}
|
||||
|
|
@ -652,9 +688,9 @@ class HtmlHelper extends AppHelper {
|
|||
* All other keys will be passed to HtmlHelper::link() as the `$options` parameter.
|
||||
*
|
||||
* @param string $separator Text to separate crumbs.
|
||||
* @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
||||
* @param string|array|bool $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
||||
* also be an array, see above for details.
|
||||
* @return string Composed bread crumbs
|
||||
* @return string|null Composed bread crumbs
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
|
||||
*/
|
||||
public function getCrumbs($separator = '»', $startText = false) {
|
||||
|
|
@ -668,10 +704,9 @@ class HtmlHelper extends AppHelper {
|
|||
$out[] = $crumb[0];
|
||||
}
|
||||
}
|
||||
return join($separator, $out);
|
||||
} else {
|
||||
return null;
|
||||
return implode($separator, $out);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -681,45 +716,62 @@ class HtmlHelper extends AppHelper {
|
|||
* similar to HtmlHelper::getCrumbs(), so it uses options which every
|
||||
* crumb was added with.
|
||||
*
|
||||
* ### Options
|
||||
* - `separator` Separator content to insert in between breadcrumbs, defaults to ''
|
||||
* - `firstClass` Class for wrapper tag on the first breadcrumb, defaults to 'first'
|
||||
* - `lastClass` Class for wrapper tag on current active page, defaults to 'last'
|
||||
*
|
||||
* @param array $options Array of html attributes to apply to the generated list elements.
|
||||
* @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
||||
* @param string|array|bool $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
||||
* also be an array, see `HtmlHelper::getCrumbs` for details.
|
||||
* @return string breadcrumbs html list
|
||||
* @return string|null breadcrumbs html list
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
|
||||
*/
|
||||
public function getCrumbList($options = array(), $startText = false) {
|
||||
$crumbs = $this->_prepareCrumbs($startText);
|
||||
if (!empty($crumbs)) {
|
||||
$result = '';
|
||||
$crumbCount = count($crumbs);
|
||||
$ulOptions = $options;
|
||||
foreach ($crumbs as $which => $crumb) {
|
||||
$options = array();
|
||||
if (empty($crumb[1])) {
|
||||
$elementContent = $crumb[0];
|
||||
} else {
|
||||
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
||||
}
|
||||
if ($which == 0) {
|
||||
$options['class'] = 'first';
|
||||
} elseif ($which == $crumbCount - 1) {
|
||||
$options['class'] = 'last';
|
||||
}
|
||||
$result .= $this->tag('li', $elementContent, $options);
|
||||
}
|
||||
return $this->tag('ul', $result, $ulOptions);
|
||||
} else {
|
||||
$defaults = array('firstClass' => 'first', 'lastClass' => 'last', 'separator' => '', 'escape' => true);
|
||||
$options = (array)$options + $defaults;
|
||||
$firstClass = $options['firstClass'];
|
||||
$lastClass = $options['lastClass'];
|
||||
$separator = $options['separator'];
|
||||
$escape = $options['escape'];
|
||||
unset($options['firstClass'], $options['lastClass'], $options['separator'], $options['escape']);
|
||||
|
||||
$crumbs = $this->_prepareCrumbs($startText, $escape);
|
||||
if (empty($crumbs)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$crumbCount = count($crumbs);
|
||||
$ulOptions = $options;
|
||||
foreach ($crumbs as $which => $crumb) {
|
||||
$options = array();
|
||||
if (empty($crumb[1])) {
|
||||
$elementContent = $crumb[0];
|
||||
} else {
|
||||
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
||||
}
|
||||
if (!$which && $firstClass !== false) {
|
||||
$options['class'] = $firstClass;
|
||||
} elseif ($which == $crumbCount - 1 && $lastClass !== false) {
|
||||
$options['class'] = $lastClass;
|
||||
}
|
||||
if (!empty($separator) && ($crumbCount - $which >= 2)) {
|
||||
$elementContent .= $separator;
|
||||
}
|
||||
$result .= $this->tag('li', $elementContent, $options);
|
||||
}
|
||||
return $this->tag('ul', $result, $ulOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepends startText to crumbs array if set
|
||||
*
|
||||
* @param $startText
|
||||
* @param string $startText Text to prepend
|
||||
* @param bool $escape If the output should be escaped or not
|
||||
* @return array Crumb list including startText (if provided)
|
||||
*/
|
||||
protected function _prepareCrumbs($startText) {
|
||||
protected function _prepareCrumbs($startText, $escape = true) {
|
||||
$crumbs = $this->_crumbs;
|
||||
if ($startText) {
|
||||
if (!is_array($startText)) {
|
||||
|
|
@ -731,7 +783,7 @@ class HtmlHelper extends AppHelper {
|
|||
$startText += array('url' => '/', 'text' => __d('cake', 'Home'));
|
||||
list($url, $text) = array($startText['url'], $startText['text']);
|
||||
unset($startText['url'], $startText['text']);
|
||||
array_unshift($crumbs, array($text, $url, $startText));
|
||||
array_unshift($crumbs, array($text, $url, $startText + array('escape' => $escape)));
|
||||
}
|
||||
return $crumbs;
|
||||
}
|
||||
|
|
@ -745,11 +797,11 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* Create a regular image:
|
||||
*
|
||||
* `echo $html->image('cake_icon.png', array('alt' => 'CakePHP'));`
|
||||
* `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP'));`
|
||||
*
|
||||
* Create an image link:
|
||||
*
|
||||
* `echo $html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
|
||||
* `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
|
|
@ -759,13 +811,13 @@ class HtmlHelper extends AppHelper {
|
|||
* - `plugin` False value will prevent parsing path as a plugin
|
||||
*
|
||||
* @param string $path Path to the image file, relative to the app/webroot/img/ directory.
|
||||
* @param array $options Array of HTML attributes. See above for special options.
|
||||
* @param array $options Array of HTML attributes. See above for special options.
|
||||
* @return string completed img tag
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image
|
||||
*/
|
||||
public function image($path, $options = array()) {
|
||||
$path = $this->assetUrl($path, $options + array('pathPrefix' => IMAGES_URL));
|
||||
$options = array_diff_key($options, array('fullBase' => '', 'pathPrefix' => ''));
|
||||
$path = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.imageBaseUrl')));
|
||||
$options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
|
||||
|
||||
if (!isset($options['alt'])) {
|
||||
$options['alt'] = '';
|
||||
|
|
@ -777,7 +829,7 @@ class HtmlHelper extends AppHelper {
|
|||
unset($options['url']);
|
||||
}
|
||||
|
||||
$image = sprintf($this->_tags['image'], $path, $this->_parseAttributes($options, null, '', ' '));
|
||||
$image = sprintf($this->_tags['image'], $path, $this->_parseAttributes($options));
|
||||
|
||||
if ($url) {
|
||||
return sprintf($this->_tags['link'], $this->url($url), null, $image);
|
||||
|
|
@ -804,7 +856,7 @@ class HtmlHelper extends AppHelper {
|
|||
$out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes(current($arg)), key($arg));
|
||||
}
|
||||
}
|
||||
return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
|
||||
return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), implode(' ', $out));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -813,8 +865,8 @@ class HtmlHelper extends AppHelper {
|
|||
* @param array $data Array of table data
|
||||
* @param array $oddTrOptions HTML options for odd TR elements if true useCount is used
|
||||
* @param array $evenTrOptions HTML options for even TR elements
|
||||
* @param boolean $useCount adds class "column-$i"
|
||||
* @param boolean $continueOddEven If false, will use a non-static $count variable,
|
||||
* @param bool $useCount adds class "column-$i"
|
||||
* @param bool $continueOddEven If false, will use a non-static $count variable,
|
||||
* so that the odd/even count is reset to zero just for that call.
|
||||
* @return string Formatted HTML
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tableCells
|
||||
|
|
@ -850,9 +902,16 @@ class HtmlHelper extends AppHelper {
|
|||
if (is_array($cell)) {
|
||||
$cellOptions = $cell[1];
|
||||
$cell = $cell[0];
|
||||
} elseif ($useCount) {
|
||||
$cellOptions['class'] = 'column-' . ++$i;
|
||||
}
|
||||
|
||||
if ($useCount) {
|
||||
if (isset($cellOptions['class'])) {
|
||||
$cellOptions['class'] .= ' column-' . ++$i;
|
||||
} else {
|
||||
$cellOptions['class'] = 'column-' . ++$i;
|
||||
}
|
||||
}
|
||||
|
||||
$cellsOut[] = sprintf($this->_tags['tablecell'], $this->_parseAttributes($cellOptions), $cell);
|
||||
}
|
||||
$options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
|
||||
|
|
@ -876,19 +935,19 @@ class HtmlHelper extends AppHelper {
|
|||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tag
|
||||
*/
|
||||
public function tag($name, $text = null, $options = array()) {
|
||||
if (is_array($options) && isset($options['escape']) && $options['escape']) {
|
||||
if (empty($name)) {
|
||||
return $text;
|
||||
}
|
||||
if (isset($options['escape']) && $options['escape']) {
|
||||
$text = h($text);
|
||||
unset($options['escape']);
|
||||
}
|
||||
if (!is_array($options)) {
|
||||
$options = array('class' => $options);
|
||||
}
|
||||
if ($text === null) {
|
||||
$tag = 'tagstart';
|
||||
} else {
|
||||
$tag = 'tag';
|
||||
}
|
||||
return sprintf($this->_tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name);
|
||||
return sprintf($this->_tags[$tag], $name, $this->_parseAttributes($options), $text, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -906,7 +965,7 @@ class HtmlHelper extends AppHelper {
|
|||
array_shift($args);
|
||||
foreach ($args as &$arg) {
|
||||
if (is_array($arg)) {
|
||||
$arg = $this->_parseAttributes($arg, null, ' ', '');
|
||||
$arg = $this->_parseAttributes($arg);
|
||||
}
|
||||
}
|
||||
return vsprintf($this->_tags[$tag], $args);
|
||||
|
|
@ -950,15 +1009,14 @@ class HtmlHelper extends AppHelper {
|
|||
if (isset($options['escape'])) {
|
||||
$text = h($text);
|
||||
}
|
||||
if ($class != null && !empty($class)) {
|
||||
if ($class && !empty($class)) {
|
||||
$options['class'] = $class;
|
||||
}
|
||||
$tag = 'para';
|
||||
if ($text === null) {
|
||||
$tag = 'parastart';
|
||||
} else {
|
||||
$tag = 'para';
|
||||
}
|
||||
return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
|
||||
return sprintf($this->_tags[$tag], $this->_parseAttributes($options), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -984,28 +1042,28 @@ class HtmlHelper extends AppHelper {
|
|||
*
|
||||
* Using multiple video files:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* echo $this->Html->media(
|
||||
* array('video.mp4', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")),
|
||||
* array('tag' => 'video', 'autoplay')
|
||||
* );
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* Outputs:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* <video autoplay="autoplay">
|
||||
* <source src="/files/video.mp4" type="video/mp4"/>
|
||||
* <source src="/files/video.ogv" type="video/ogv; codecs='theora, vorbis'"/>
|
||||
* </video>
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `tag` Type of media element to generate, either "audio" or "video".
|
||||
* If tag is not provided it's guessed based on file's mime type.
|
||||
* - `text` Text to include inside the audio/video tag
|
||||
* - `pathPrefix` Path prefix to use for relative urls, defaults to 'files/'
|
||||
* - `pathPrefix` Path prefix to use for relative URLs, defaults to 'files/'
|
||||
* - `fullBase` If provided the src attribute will get a full address including domain name
|
||||
*
|
||||
* @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
|
||||
|
|
@ -1065,15 +1123,15 @@ class HtmlHelper extends AppHelper {
|
|||
}
|
||||
|
||||
if (isset($options['poster'])) {
|
||||
$options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => IMAGES_URL) + $options);
|
||||
$options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => Configure::read('App.imageBaseUrl')) + $options);
|
||||
}
|
||||
$text = $options['text'];
|
||||
|
||||
$options = array_diff_key($options, array(
|
||||
'tag' => '',
|
||||
'fullBase' => '',
|
||||
'pathPrefix' => '',
|
||||
'text' => ''
|
||||
'tag' => null,
|
||||
'fullBase' => null,
|
||||
'pathPrefix' => null,
|
||||
'text' => null
|
||||
));
|
||||
return $this->tag($tag, $text, $options);
|
||||
}
|
||||
|
|
@ -1094,7 +1152,7 @@ class HtmlHelper extends AppHelper {
|
|||
$options = array();
|
||||
}
|
||||
$items = $this->_nestedListItem($list, $options, $itemOptions, $tag);
|
||||
return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $items);
|
||||
return sprintf($this->_tags[$tag], $this->_parseAttributes($options), $items);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1115,12 +1173,12 @@ class HtmlHelper extends AppHelper {
|
|||
if (is_array($item)) {
|
||||
$item = $key . $this->nestedList($item, $options, $itemOptions, $tag);
|
||||
}
|
||||
if (isset($itemOptions['even']) && $index % 2 == 0) {
|
||||
if (isset($itemOptions['even']) && $index % 2 === 0) {
|
||||
$itemOptions['class'] = $itemOptions['even'];
|
||||
} elseif (isset($itemOptions['odd']) && $index % 2 != 0) {
|
||||
} elseif (isset($itemOptions['odd']) && $index % 2 !== 0) {
|
||||
$itemOptions['class'] = $itemOptions['odd'];
|
||||
}
|
||||
$out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item);
|
||||
$out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd')), $item);
|
||||
$index++;
|
||||
}
|
||||
return $out;
|
||||
|
|
@ -1129,18 +1187,18 @@ class HtmlHelper extends AppHelper {
|
|||
/**
|
||||
* Load Html tag configuration.
|
||||
*
|
||||
* Loads a file from APP/Config that contains tag data. By default the file is expected
|
||||
* Loads a file from APP/Config that contains tag data. By default the file is expected
|
||||
* to be compatible with PhpReader:
|
||||
*
|
||||
* `$this->Html->loadConfig('tags.php');`
|
||||
*
|
||||
* tags.php could look like:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $tags = array(
|
||||
* 'meta' => '<meta %s>'
|
||||
* 'meta' => '<meta%s>'
|
||||
* );
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* If you wish to store tag definitions in another format you can give an array
|
||||
* containing the file name, and reader class name:
|
||||
|
|
@ -1194,13 +1252,13 @@ class HtmlHelper extends AppHelper {
|
|||
$readerObj = new $readerClass($path);
|
||||
$configs = $readerObj->read($file);
|
||||
if (isset($configs['tags']) && is_array($configs['tags'])) {
|
||||
$this->_tags = array_merge($this->_tags, $configs['tags']);
|
||||
$this->_tags = $configs['tags'] + $this->_tags;
|
||||
}
|
||||
if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) {
|
||||
$this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']);
|
||||
$this->_minimizedAttributes = $configs['minimizedAttributes'] + $this->_minimizedAttributes;
|
||||
}
|
||||
if (isset($configs['docTypes']) && is_array($configs['docTypes'])) {
|
||||
$this->_docTypes = array_merge($this->_docTypes, $configs['docTypes']);
|
||||
$this->_docTypes = $configs['docTypes'] + $this->_docTypes;
|
||||
}
|
||||
if (isset($configs['attributeFormat'])) {
|
||||
$this->_attributeFormat = $configs['attributeFormat'];
|
||||
|
|
|
|||
|
|
@ -2,25 +2,24 @@
|
|||
/**
|
||||
* jQuery Engine Helper for JsHelper
|
||||
*
|
||||
* Provides jQuery specific Javascript for JsHelper.
|
||||
* Provides jQuery specific JavaScript for JsHelper.
|
||||
*
|
||||
* Implements the JsHelper interface for jQuery. All $options arrays
|
||||
* Implements the JsHelper interface for jQuery. All $options arrays
|
||||
* support all options found in the JsHelper, as well as those in the jQuery
|
||||
* documentation.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -29,9 +28,9 @@ App::uses('JsBaseEngineHelper', 'View/Helper');
|
|||
/**
|
||||
* jQuery Engine Helper for JsHelper
|
||||
*
|
||||
* Provides jQuery specific Javascript for JsHelper.
|
||||
* Provides jQuery specific JavaScript for JsHelper.
|
||||
*
|
||||
* Implements the JsHelper interface for jQuery. All $options arrays
|
||||
* Implements the JsHelper interface for jQuery. All $options arrays
|
||||
* support all options found in the JsHelper, as well as those in the jQuery
|
||||
* documentation.
|
||||
*
|
||||
|
|
@ -146,10 +145,10 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return JqueryEngineHelper instance of $this. Allows chained methods.
|
||||
* @return self
|
||||
*/
|
||||
public function get($selector) {
|
||||
if ($selector == 'window' || $selector == 'document') {
|
||||
if ($selector === 'window' || $selector === 'document') {
|
||||
$this->selection = $this->jQueryObject . '(' . $selector . ')';
|
||||
} else {
|
||||
$this->selection = $this->jQueryObject . '("' . $selector . '")';
|
||||
|
|
@ -166,13 +165,13 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
* - 'stop' - Whether you want the event to stopped. (defaults true)
|
||||
*
|
||||
* @param string $type Type of event to bind to the current dom id
|
||||
* @param string $callback The Javascript function you wish to trigger or the function literal
|
||||
* @param string $callback The JavaScript function you wish to trigger or the function literal
|
||||
* @param array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
*/
|
||||
public function event($type, $callback, $options = array()) {
|
||||
$defaults = array('wrap' => true, 'stop' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
$options += $defaults;
|
||||
|
||||
$function = 'function (event) {%s}';
|
||||
if ($options['wrap'] && $options['stop']) {
|
||||
|
|
@ -189,7 +188,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
* bind a 'traditional event' as `$(document).bind('ready', fn)`
|
||||
* Works in an entirely different fashion than `$(document).ready()`
|
||||
* The first will not run the function when eval()'d as part of a response
|
||||
* The second will. Because of the way that ajax pagination is done
|
||||
* The second will. Because of the way that ajax pagination is done
|
||||
* `$().ready()` is used.
|
||||
*
|
||||
* @param string $functionBody The code to run on domReady
|
||||
|
|
@ -226,7 +225,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
switch ($name) {
|
||||
case 'slideIn':
|
||||
case 'slideOut':
|
||||
$name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
|
||||
$name = ($name === 'slideIn') ? 'slideDown' : 'slideUp';
|
||||
case 'hide':
|
||||
case 'show':
|
||||
case 'fadeIn':
|
||||
|
|
@ -234,7 +233,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
case 'slideDown':
|
||||
case 'slideUp':
|
||||
$effect = ".$name($speed);";
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return $this->selection . $effect;
|
||||
}
|
||||
|
|
@ -244,7 +243,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
*
|
||||
* If the 'update' key is set, success callback will be overridden.
|
||||
*
|
||||
* @param string|array $url
|
||||
* @param string|array $url URL
|
||||
* @param array $options See JsHelper::request() for options.
|
||||
* @return string The completed ajax call.
|
||||
* @see JsBaseEngineHelper::request() for options list.
|
||||
|
|
@ -270,7 +269,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
$options['success'] = $success;
|
||||
unset($options['update']);
|
||||
}
|
||||
$callbacks = array('success', 'error', 'beforeSend', 'complete');
|
||||
$callbacks = array('success', 'error', 'beforeSend', 'complete', 'xhr');
|
||||
if (!empty($options['dataExpression'])) {
|
||||
$callbacks[] = 'data';
|
||||
unset($options['dataExpression']);
|
||||
|
|
@ -339,14 +338,14 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
|
|||
|
||||
/**
|
||||
* Serialize a form attached to $selector. If the current selection is not an input or
|
||||
* form, errors will be created in the Javascript.
|
||||
* form, errors will be created in the JavaScript.
|
||||
*
|
||||
* @param array $options Options for the serialization
|
||||
* @return string completed form serialization script.
|
||||
* @see JsBaseEngineHelper::serializeForm() for option list.
|
||||
*/
|
||||
public function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$options += array('isForm' => false, 'inline' => false);
|
||||
$selector = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selector = $this->selection . '.closest("form")';
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -33,7 +34,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* Collection of option maps. Option maps allow other helpers to use generic names for engine
|
||||
* callbacks and options. Allowing uniform code access for all engine types. Their use is optional
|
||||
* callbacks and options. Allowing uniform code access for all engine types. Their use is optional
|
||||
* for end user use though.
|
||||
*
|
||||
* @var array
|
||||
|
|
@ -56,7 +57,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
protected $_callbackArguments = array();
|
||||
|
||||
/**
|
||||
* Create an `alert()` message in Javascript
|
||||
* Create an `alert()` message in JavaScript
|
||||
*
|
||||
* @param string $message Message you want to alter.
|
||||
* @return string completed alert()
|
||||
|
|
@ -66,11 +67,10 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Redirects to a URL. Creates a window.location modification snippet
|
||||
* that can be used to trigger 'redirects' from Javascript.
|
||||
* Redirects to a URL. Creates a window.location modification snippet
|
||||
* that can be used to trigger 'redirects' from JavaScript.
|
||||
*
|
||||
* @param string|array $url
|
||||
* @param array $options
|
||||
* @param string|array $url URL
|
||||
* @return string completed redirect in javascript
|
||||
*/
|
||||
public function redirect($url = null) {
|
||||
|
|
@ -101,7 +101,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a `prompt()` Javascript function
|
||||
* Create a `prompt()` JavaScript function
|
||||
*
|
||||
* @param string $message Message you want to prompt.
|
||||
* @param string $default Default message
|
||||
|
|
@ -113,7 +113,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* Generates a JavaScript object in JavaScript Object Notation (JSON)
|
||||
* from an array. Will use native JSON encode method if available, and $useNative == true
|
||||
* from an array. Will use native JSON encode method if available, and $useNative == true
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
|
|
@ -128,7 +128,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
$defaultOptions = array(
|
||||
'prefix' => '', 'postfix' => '',
|
||||
);
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
$options += $defaultOptions;
|
||||
|
||||
return $options['prefix'] . json_encode($data) . $options['postfix'];
|
||||
}
|
||||
|
|
@ -137,7 +137,8 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
* Converts a PHP-native variable of any type to a JSON-equivalent representation
|
||||
*
|
||||
* @param mixed $val A PHP variable to be converted to JSON
|
||||
* @param boolean $quoteString If false, leaves string values unquoted
|
||||
* @param bool $quoteString If false, leaves string values unquoted
|
||||
* @param string $key Key name.
|
||||
* @return string a JavaScript-safe/JSON representation of $val
|
||||
*/
|
||||
public function value($val = array(), $quoteString = null, $key = 'value') {
|
||||
|
|
@ -147,25 +148,24 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
switch (true) {
|
||||
case (is_array($val) || is_object($val)):
|
||||
$val = $this->object($val);
|
||||
break;
|
||||
break;
|
||||
case ($val === null):
|
||||
$val = 'null';
|
||||
break;
|
||||
break;
|
||||
case (is_bool($val)):
|
||||
$val = ($val === true) ? 'true' : 'false';
|
||||
break;
|
||||
break;
|
||||
case (is_int($val)):
|
||||
$val = $val;
|
||||
break;
|
||||
break;
|
||||
case (is_float($val)):
|
||||
$val = sprintf("%.11f", $val);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$val = $this->escape($val);
|
||||
if ($quoteString) {
|
||||
$val = '"' . $val . '"';
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Encode a string into JSON. Converts and escapes necessary characters.
|
||||
* Encode a string into JSON. Converts and escapes necessary characters.
|
||||
*
|
||||
* @param string $string The string that needs to be utf8->hex encoded
|
||||
* @return void
|
||||
|
|
@ -285,7 +285,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return JsBaseEngineHelper instance of $this. Allows chained methods.
|
||||
* @return self instance of $this. Allows chained methods.
|
||||
*/
|
||||
abstract public function get($selector);
|
||||
|
||||
|
|
@ -298,7 +298,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
* - `stop` - Whether you want the event to stopped. (defaults to true)
|
||||
*
|
||||
* @param string $type Type of event to bind to the current dom id
|
||||
* @param string $callback The Javascript function you wish to trigger or the function literal
|
||||
* @param string $callback The JavaScript function you wish to trigger or the function literal
|
||||
* @param array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
*/
|
||||
|
|
@ -363,8 +363,8 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
* - `update` - Dom id to update with the content of the request.
|
||||
* - `type` - Data type for response. 'json' and 'html' are supported. Default is html for most libraries.
|
||||
* - `evalScripts` - Whether or not <script> tags should be eval'ed.
|
||||
* - `dataExpression` - Should the `data` key be treated as a callback. Useful for supplying `$options['data']` as
|
||||
* another Javascript expression.
|
||||
* - `dataExpression` - Should the `data` key be treated as a callback. Useful for supplying `$options['data']` as
|
||||
* another JavaScript expression.
|
||||
*
|
||||
* @param string|array $url Array or String URL to target with the request.
|
||||
* @param array $options Array of options. See above for cross library supported options
|
||||
|
|
@ -373,7 +373,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
abstract public function request($url, $options = array());
|
||||
|
||||
/**
|
||||
* Create a draggable element. Works on the currently selected element.
|
||||
* Create a draggable element. Works on the currently selected element.
|
||||
* Additional options may be supported by the library implementation.
|
||||
*
|
||||
* ### Options
|
||||
|
|
@ -437,7 +437,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
abstract public function sortable($options = array());
|
||||
|
||||
/**
|
||||
* Create a slider UI widget. Comprised of a track and knob.
|
||||
* Create a slider UI widget. Comprised of a track and knob.
|
||||
* Additional options may be supported by the library implementation.
|
||||
*
|
||||
* ### Options
|
||||
|
|
@ -476,7 +476,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
abstract public function serializeForm($options = array());
|
||||
|
||||
/**
|
||||
* Parse an options assoc array into an Javascript object literal.
|
||||
* Parse an options assoc array into a JavaScript object literal.
|
||||
* Similar to object() but treats any non-integer value as a string,
|
||||
* does not include `{ }`
|
||||
*
|
||||
|
|
@ -494,7 +494,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
|
|||
$out[] = $key . ':' . $value;
|
||||
}
|
||||
sort($out);
|
||||
return join(', ', $out);
|
||||
return implode(', ', $out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Javascript Generator class file.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc.
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -36,7 +35,7 @@ class JsHelper extends AppHelper {
|
|||
/**
|
||||
* Whether or not you want scripts to be buffered or output.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $bufferScripts = true;
|
||||
|
||||
|
|
@ -81,7 +80,7 @@ class JsHelper extends AppHelper {
|
|||
* Constructor - determines engine helper
|
||||
*
|
||||
* @param View $View the view object the helper is attached to.
|
||||
* @param array $settings Settings array contains name of engine helper.
|
||||
* @param string|array $settings Settings array contains name of engine helper.
|
||||
*/
|
||||
public function __construct(View $View, $settings = array()) {
|
||||
$className = 'Jquery';
|
||||
|
|
@ -91,7 +90,7 @@ class JsHelper extends AppHelper {
|
|||
$className = $settings;
|
||||
}
|
||||
$engineName = $className;
|
||||
list($plugin, $className) = pluginSplit($className);
|
||||
list(, $className) = pluginSplit($className);
|
||||
|
||||
$this->_engineName = $className . 'Engine';
|
||||
$engineClass = $engineName . 'Engine';
|
||||
|
|
@ -158,10 +157,11 @@ class JsHelper extends AppHelper {
|
|||
* See JsBaseEngineHelper::value() for more information on this method.
|
||||
*
|
||||
* @param mixed $val A PHP variable to be converted to JSON
|
||||
* @param boolean $quoteString If false, leaves string values unquoted
|
||||
* @param bool $quoteString If false, leaves string values unquoted
|
||||
* @param string $key Key name.
|
||||
* @return string a JavaScript-safe/JSON representation of $val
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::value
|
||||
**/
|
||||
*/
|
||||
public function value($val = array(), $quoteString = null, $key = 'value') {
|
||||
if ($quoteString === null) {
|
||||
$quoteString = true;
|
||||
|
|
@ -171,8 +171,8 @@ class JsHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* Writes all Javascript generated so far to a code block or
|
||||
* caches them to a file and returns a linked script. If no scripts have been
|
||||
* buffered this method will return null. If the request is an XHR(ajax) request
|
||||
* caches them to a file and returns a linked script. If no scripts have been
|
||||
* buffered this method will return null. If the request is an XHR(ajax) request
|
||||
* onDomReady will be set to false. As the dom is already 'ready'.
|
||||
*
|
||||
* ### Options
|
||||
|
|
@ -195,7 +195,7 @@ class JsHelper extends AppHelper {
|
|||
'onDomReady' => $domReady, 'inline' => true,
|
||||
'cache' => false, 'clear' => true, 'safe' => true
|
||||
);
|
||||
$options = array_merge($defaults, $options);
|
||||
$options += $defaults;
|
||||
$script = implode("\n", $this->getBuffer($options['clear']));
|
||||
|
||||
if (empty($script)) {
|
||||
|
|
@ -210,8 +210,9 @@ class JsHelper extends AppHelper {
|
|||
|
||||
if ($options['cache'] && $options['inline']) {
|
||||
$filename = md5($script);
|
||||
if (file_exists(JS . $filename . '.js')
|
||||
|| cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $script, '+999 days', 'public')
|
||||
$path = WWW_ROOT . Configure::read('App.jsBaseUrl');
|
||||
if (file_exists($path . $filename . '.js')
|
||||
|| cache(str_replace(WWW_ROOT, '', $path) . $filename . '.js', $script, '+999 days', 'public')
|
||||
) {
|
||||
return $this->Html->script($filename);
|
||||
}
|
||||
|
|
@ -228,8 +229,8 @@ class JsHelper extends AppHelper {
|
|||
* Write a script to the buffered scripts.
|
||||
*
|
||||
* @param string $script Script string to add to the buffer.
|
||||
* @param boolean $top If true the script will be added to the top of the
|
||||
* buffered scripts array. If false the bottom.
|
||||
* @param bool $top If true the script will be added to the top of the
|
||||
* buffered scripts array. If false the bottom.
|
||||
* @return void
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::buffer
|
||||
*/
|
||||
|
|
@ -244,7 +245,7 @@ class JsHelper extends AppHelper {
|
|||
/**
|
||||
* Get all the buffered scripts
|
||||
*
|
||||
* @param boolean $clear Whether or not to clear the script caches (default true)
|
||||
* @param bool $clear Whether or not to clear the script caches (default true)
|
||||
* @return array Array of scripts added to the request.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::getBuffer
|
||||
*/
|
||||
|
|
@ -259,9 +260,9 @@ class JsHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generates the object string for variables passed to javascript.
|
||||
* Generates the object string for variables passed to javascript and adds to buffer
|
||||
*
|
||||
* @return string Generated JSON object of all set vars
|
||||
* @return void
|
||||
*/
|
||||
protected function _createVars() {
|
||||
if (!empty($this->_jsVars)) {
|
||||
|
|
@ -271,27 +272,27 @@ class JsHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate an 'Ajax' link. Uses the selected JS engine to create a link
|
||||
* element that is enhanced with Javascript. Options can include
|
||||
* Generate an 'Ajax' link. Uses the selected JS engine to create a link
|
||||
* element that is enhanced with Javascript. Options can include
|
||||
* both those for HtmlHelper::link() and JsBaseEngine::request(), JsBaseEngine::event();
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `confirm` - Generate a confirm() dialog before sending the event.
|
||||
* - `id` - use a custom id.
|
||||
* - `htmlAttributes` - additional non-standard htmlAttributes. Standard attributes are class, id,
|
||||
* - `htmlAttributes` - additional non-standard htmlAttributes. Standard attributes are class, id,
|
||||
* rel, title, escape, onblur and onfocus.
|
||||
* - `buffer` - Disable the buffering and return a script tag in addition to the link.
|
||||
*
|
||||
* @param string $title Title for the link.
|
||||
* @param string|array $url Mixed either a string URL or an cake url array.
|
||||
* @param string|array $url Mixed either a string URL or a CakePHP URL array.
|
||||
* @param array $options Options for both the HTML element and Js::request()
|
||||
* @return string Completed link. If buffering is disabled a script tag will be returned as well.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::link
|
||||
*/
|
||||
public function link($title, $url = null, $options = array()) {
|
||||
if (!isset($options['id'])) {
|
||||
$options['id'] = 'link-' . intval(mt_rand());
|
||||
$options['id'] = 'link-' . (int)mt_rand();
|
||||
}
|
||||
list($options, $htmlOptions) = $this->_getHtmlOptions($options);
|
||||
$out = $this->Html->link($title, $url, $htmlOptions);
|
||||
|
|
@ -318,7 +319,7 @@ class JsHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Pass variables into Javascript. Allows you to set variables that will be
|
||||
* Pass variables into Javascript. Allows you to set variables that will be
|
||||
* output when the buffer is fetched with `JsHelper::getBuffer()` or `JsHelper::writeBuffer()`
|
||||
* The Javascript variable used to output set variables can be controlled with `JsHelper::$setVariable`
|
||||
*
|
||||
|
|
@ -338,7 +339,7 @@ class JsHelper extends AppHelper {
|
|||
} else {
|
||||
$data = array($one => $two);
|
||||
}
|
||||
if ($data == null) {
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
$this->_jsVars = array_merge($this->_jsVars, $data);
|
||||
|
|
@ -346,7 +347,7 @@ class JsHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* Uses the selected JS engine to create a submit input
|
||||
* element that is enhanced with Javascript. Options can include
|
||||
* element that is enhanced with Javascript. Options can include
|
||||
* both those for FormHelper::submit() and JsBaseEngine::request(), JsBaseEngine::event();
|
||||
*
|
||||
* Forms submitting with this method, cannot send files. Files do not transfer over XmlHttpRequest
|
||||
|
|
@ -367,7 +368,7 @@ class JsHelper extends AppHelper {
|
|||
*/
|
||||
public function submit($caption = null, $options = array()) {
|
||||
if (!isset($options['id'])) {
|
||||
$options['id'] = 'submit-' . intval(mt_rand());
|
||||
$options['id'] = 'submit-' . (int)mt_rand();
|
||||
}
|
||||
$formOptions = array('div');
|
||||
list($options, $htmlOptions) = $this->_getHtmlOptions($options, $formOptions);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('JsBaseEngineHelper', 'View/Helper');
|
||||
|
|
@ -18,7 +19,7 @@ App::uses('JsBaseEngineHelper', 'View/Helper');
|
|||
/**
|
||||
* MooTools Engine Helper for JsHelper
|
||||
*
|
||||
* Provides MooTools specific Javascript for JsHelper.
|
||||
* Provides MooTools specific JavaScript for JsHelper.
|
||||
* Assumes that you have the following MooTools packages
|
||||
*
|
||||
* - Remote, Remote.HTML, Remote.JSON
|
||||
|
|
@ -117,11 +118,11 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return MootoolsEngineHelper instance of $this. Allows chained methods.
|
||||
* @return self
|
||||
*/
|
||||
public function get($selector) {
|
||||
$this->_multipleSelection = false;
|
||||
if ($selector == 'window' || $selector == 'document') {
|
||||
if ($selector === 'window' || $selector === 'document') {
|
||||
$this->selection = "$(" . $selector . ")";
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -143,13 +144,13 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
* - 'stop' - Whether you want the event to stopped. (defaults true)
|
||||
*
|
||||
* @param string $type Type of event to bind to the current dom id
|
||||
* @param string $callback The Javascript function you wish to trigger or the function literal
|
||||
* @param string $callback The JavaScript function you wish to trigger or the function literal
|
||||
* @param array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
*/
|
||||
public function event($type, $callback, $options = array()) {
|
||||
$defaults = array('wrap' => true, 'stop' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
$options += $defaults;
|
||||
|
||||
$function = 'function (event) {%s}';
|
||||
if ($options['wrap'] && $options['stop']) {
|
||||
|
|
@ -194,9 +195,9 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
public function effect($name, $options = array()) {
|
||||
$speed = null;
|
||||
if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
|
||||
if ($options['speed'] == 'fast') {
|
||||
if ($options['speed'] === 'fast') {
|
||||
$speed = '"short"';
|
||||
} elseif ($options['speed'] == 'slow') {
|
||||
} elseif ($options['speed'] === 'slow') {
|
||||
$speed = '"long"';
|
||||
}
|
||||
}
|
||||
|
|
@ -204,10 +205,10 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
switch ($name) {
|
||||
case 'hide':
|
||||
$effect = 'setStyle("display", "none")';
|
||||
break;
|
||||
break;
|
||||
case 'show':
|
||||
$effect = 'setStyle("display", "")';
|
||||
break;
|
||||
break;
|
||||
case 'fadeIn':
|
||||
case 'fadeOut':
|
||||
case 'slideIn':
|
||||
|
|
@ -218,19 +219,19 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
$effect .= "set(\"$effectName\", {duration:$speed}).";
|
||||
}
|
||||
$effect .= "$effectName(\"$direction\")";
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return $this->selection . '.' . $effect . ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an new Request.
|
||||
* Create a new Request.
|
||||
*
|
||||
* Requires `Request`. If you wish to use 'update' key you must have ```Request.HTML```
|
||||
* Requires `Request`. If you wish to use 'update' key you must have ```Request.HTML```
|
||||
* if you wish to do Json requests you will need ```JSON``` and ```Request.JSON```.
|
||||
*
|
||||
* @param string|array $url
|
||||
* @param array $options
|
||||
* @param string|array $url URL
|
||||
* @param array $options Options list.
|
||||
* @return string The completed ajax call.
|
||||
*/
|
||||
public function request($url, $options = array()) {
|
||||
|
|
@ -238,7 +239,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
$options = $this->_mapOptions('request', $options);
|
||||
$type = $data = null;
|
||||
if (isset($options['type']) || isset($options['update'])) {
|
||||
if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
if (isset($options['type']) && strtolower($options['type']) === 'json') {
|
||||
$type = '.JSON';
|
||||
}
|
||||
if (isset($options['update'])) {
|
||||
|
|
@ -295,8 +296,8 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
*
|
||||
* Requires the `Drag` and `Drag.Move` plugins from MootoolsMore
|
||||
*
|
||||
* Droppables in Mootools function differently from other libraries. Droppables
|
||||
* are implemented as an extension of Drag. So in addition to making a get() selection for
|
||||
* Droppables in Mootools function differently from other libraries. Droppables
|
||||
* are implemented as an extension of Drag. So in addition to making a get() selection for
|
||||
* the droppable element. You must also provide a selector rule to the draggable element. Furthermore,
|
||||
* Mootools droppables inherit all options from Drag.
|
||||
*
|
||||
|
|
@ -307,7 +308,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
public function drop($options = array()) {
|
||||
if (empty($options['drag'])) {
|
||||
trigger_error(
|
||||
__d('cake_dev', 'MootoolsEngine::drop() requires a "drag" option to properly function'), E_USER_WARNING
|
||||
__d('cake_dev', '%s requires a "drag" option to properly function'), 'MootoolsEngine::drop()', E_USER_WARNING
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -360,7 +361,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
|
|||
* @see JsBaseEngineHelper::serializeForm()
|
||||
*/
|
||||
public function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$options += array('isForm' => false, 'inline' => false);
|
||||
$selection = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selection = '$(' . $this->selection . '.form)';
|
||||
|
|
|
|||
|
|
@ -4,23 +4,23 @@
|
|||
*
|
||||
* Methods to make numbers more readable.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeNumber', 'Utility');
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
App::uses('Hash', 'Utility');
|
||||
|
||||
/**
|
||||
* Number helper library.
|
||||
|
|
@ -66,17 +66,22 @@ class NumberHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* Call methods from CakeNumber utility class
|
||||
*
|
||||
* @param string $method Method to call.
|
||||
* @param array $params Parameters to pass to method.
|
||||
* @return mixed Whatever is returned by called method, or false on failure
|
||||
*/
|
||||
public function __call($method, $params) {
|
||||
return call_user_func_array(array($this->_engine, $method), $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see: CakeNumber::precision()
|
||||
* Formats a number with a level of precision.
|
||||
*
|
||||
* @param float $number A floating point number.
|
||||
* @param integer $precision The precision of the returned number.
|
||||
* @param float $number A floating point number.
|
||||
* @param int $precision The precision of the returned number.
|
||||
* @return float Formatted float.
|
||||
* @see CakeNumber::precision()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::precision
|
||||
*/
|
||||
public function precision($number, $precision = 3) {
|
||||
|
|
@ -84,10 +89,11 @@ class NumberHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see: CakeNumber::toReadableSize()
|
||||
* Returns a formatted-for-humans file size.
|
||||
*
|
||||
* @param integer $size Size in bytes
|
||||
* @param int $size Size in bytes
|
||||
* @return string Human readable size
|
||||
* @see CakeNumber::toReadableSize()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSize
|
||||
*/
|
||||
public function toReadableSize($size) {
|
||||
|
|
@ -95,24 +101,31 @@ class NumberHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see: CakeNumber::toPercentage()
|
||||
* Formats a number into a percentage string.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - `multiply`: Multiply the input value by 100 for decimal percentages.
|
||||
*
|
||||
* @param float $number A floating point number
|
||||
* @param integer $precision The precision of the returned number
|
||||
* @param int $precision The precision of the returned number
|
||||
* @param array $options Options
|
||||
* @return string Percentage string
|
||||
* @see CakeNumber::toPercentage()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toPercentage
|
||||
*/
|
||||
public function toPercentage($number, $precision = 2) {
|
||||
return $this->_engine->toPercentage($number, $precision);
|
||||
public function toPercentage($number, $precision = 2, $options = array()) {
|
||||
return $this->_engine->toPercentage($number, $precision, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see: CakeNumber::format()
|
||||
* Formats a number into a currency format.
|
||||
*
|
||||
* @param float $number A floating point number
|
||||
* @param integer $options if int then places, if string then before, if (,.-) then use it
|
||||
* @param int $options If integer then places, if string then before, if (,.-) then use it
|
||||
* or array with places and before keys
|
||||
* @return string formatted number
|
||||
* @see CakeNumber::format()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::format
|
||||
*/
|
||||
public function format($number, $options = false) {
|
||||
|
|
@ -120,30 +133,53 @@ class NumberHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see: CakeNumber::currency()
|
||||
* Formats a number into a currency format.
|
||||
*
|
||||
* @param float $number
|
||||
* @param float $number Number to format.
|
||||
* @param string $currency Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise
|
||||
* set at least 'before' and 'after' options.
|
||||
* @param array $options
|
||||
* 'USD' is the default currency, use CakeNumber::defaultCurrency() to change this default.
|
||||
* @param array $options Options list.
|
||||
* @return string Number formatted as a currency.
|
||||
* @see CakeNumber::currency()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency
|
||||
*/
|
||||
public function currency($number, $currency = 'USD', $options = array()) {
|
||||
public function currency($number, $currency = null, $options = array()) {
|
||||
return $this->_engine->currency($number, $currency, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see: CakeNumber::addFormat()
|
||||
* Add a currency format to the Number helper. Makes reusing
|
||||
* currency formats easier.
|
||||
*
|
||||
* ``` $this->Number->addFormat('NOK', array('before' => 'Kr. ')); ```
|
||||
*
|
||||
* You can now use `NOK` as a shortform when formatting currency amounts.
|
||||
*
|
||||
* ``` $this->Number->currency($value, 'NOK'); ```
|
||||
*
|
||||
* Added formats are merged with the defaults defined in Cake\Utility\Number::$_currencyDefaults
|
||||
* See Cake\Utility\Number::currency() for more information on the various options and their function.
|
||||
*
|
||||
* @param string $formatName The format name to be used in the future.
|
||||
* @param array $options The array of options for this format.
|
||||
* @return void
|
||||
* @see NumberHelper::currency()
|
||||
* @see CakeNumber::addFormat()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::addFormat
|
||||
*/
|
||||
public function addFormat($formatName, $options) {
|
||||
return $this->_engine->addFormat($formatName, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter/setter for default currency
|
||||
*
|
||||
* @param string $currency The currency to be used in the future.
|
||||
* @return string Currency
|
||||
* @see CakeNumber::defaultCurrency()
|
||||
*/
|
||||
public function defaultCurrency($currency) {
|
||||
return $this->_engine->defaultCurrency($currency);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,17 @@
|
|||
* Generates pagination links
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -38,7 +39,7 @@ class PaginatorHelper extends AppHelper {
|
|||
public $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* The class used for 'Ajax' pagination links. Defaults to JsHelper. You should make sure
|
||||
* The class used for 'Ajax' pagination links. Defaults to JsHelper. You should make sure
|
||||
* that JsHelper is defined as a helper before PaginatorHelper, if you want to customize the JsHelper.
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -63,9 +64,9 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `escape` Defines if the title field for the link should be escaped (default: true).
|
||||
* - `update` DOM id of the element updated with the results of the AJAX call.
|
||||
* If this key isn't specified Paginator will use plain HTML links.
|
||||
* - `paging['paramType']` The type of parameters to use when creating links. Valid options are
|
||||
* 'querystring' and 'named'. See PaginatorComponent::$settings for more information.
|
||||
* - `convertKeys` - A list of keys in url arrays that should be converted to querysting params
|
||||
* - `paging['paramType']` The type of parameters to use when creating links. Valid options are
|
||||
* 'querystring' and 'named'. See PaginatorComponent::$settings for more information.
|
||||
* - `convertKeys` - A list of keys in URL arrays that should be converted to querysting params
|
||||
* if paramType == 'querystring'.
|
||||
*
|
||||
* @var array
|
||||
|
|
@ -78,7 +79,7 @@ class PaginatorHelper extends AppHelper {
|
|||
* Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
|
||||
*
|
||||
* Use `public $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
|
||||
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
|
||||
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
|
||||
* adapter before including PaginatorHelper in your helpers array.
|
||||
*
|
||||
* The chosen custom helper must implement a `link()` method.
|
||||
|
|
@ -94,17 +95,17 @@ class PaginatorHelper extends AppHelper {
|
|||
App::uses($ajaxProvider . 'Helper', 'View/Helper');
|
||||
$classname = $ajaxProvider . 'Helper';
|
||||
if (!class_exists($classname) || !method_exists($classname, 'link')) {
|
||||
throw new CakeException(sprintf(
|
||||
__d('cake_dev', '%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname
|
||||
));
|
||||
throw new CakeException(
|
||||
__d('cake_dev', '%s does not implement a %s method, it is incompatible with %s', $classname, 'link()', 'PaginatorHelper')
|
||||
);
|
||||
}
|
||||
parent::__construct($View, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before render callback. Overridden to merge passed args with url options.
|
||||
* Before render callback. Overridden to merge passed args with URL options.
|
||||
*
|
||||
* @param string $viewFile
|
||||
* @param string $viewFile View file name.
|
||||
* @return void
|
||||
*/
|
||||
public function beforeRender($viewFile) {
|
||||
|
|
@ -118,7 +119,7 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current paging parameters from the resultset for the given model
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return array The array of paging parameters for the paginated resultset.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
|
||||
*/
|
||||
|
|
@ -127,11 +128,34 @@ class PaginatorHelper extends AppHelper {
|
|||
$model = $this->defaultModel();
|
||||
}
|
||||
if (!isset($this->request->params['paging']) || empty($this->request->params['paging'][$model])) {
|
||||
return null;
|
||||
return array(
|
||||
'prevPage' => false,
|
||||
'nextPage' => true,
|
||||
'paramType' => 'named',
|
||||
'pageCount' => 1,
|
||||
'options' => array(),
|
||||
'page' => 1
|
||||
);
|
||||
}
|
||||
return $this->request->params['paging'][$model];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience access to any of the paginator params.
|
||||
*
|
||||
* @param string $key Key of the paginator params array to retrieve.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return mixed Content of the requested param.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
|
||||
*/
|
||||
public function param($key, $model = null) {
|
||||
$params = $this->params($model);
|
||||
if (!isset($params[$key])) {
|
||||
return null;
|
||||
}
|
||||
return $params[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default options for all pagination links
|
||||
*
|
||||
|
|
@ -172,7 +196,7 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current page of the recordset for the given model
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return string The current page number of the recordset.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::current
|
||||
*/
|
||||
|
|
@ -188,9 +212,9 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current key by which the recordset is sorted
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param array $options Options for pagination links. See #options for list of keys.
|
||||
* @return string The name of the key by which the recordset is being sorted, or
|
||||
* @return string|null The name of the key by which the recordset is being sorted, or
|
||||
* null if the results are not currently sorted.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sortKey
|
||||
*/
|
||||
|
|
@ -214,7 +238,7 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current direction the recordset is sorted
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param array $options Options for pagination links. See #options for list of keys.
|
||||
* @return string The direction by which the recordset is being sorted, or
|
||||
* null if the results are not currently sorted.
|
||||
|
|
@ -236,7 +260,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$dir = strtolower(current($params['order']));
|
||||
}
|
||||
|
||||
if ($dir == 'desc') {
|
||||
if ($dir === 'desc') {
|
||||
return 'desc';
|
||||
}
|
||||
return 'asc';
|
||||
|
|
@ -247,9 +271,11 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `url` Allows sending routing parameters such as controllers, actions or passed arguments.
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
* - `disabledTag` Tag to use instead of A tag when there is no previous page
|
||||
*
|
||||
* @param string $title Title for the link. Defaults to '<< Previous'.
|
||||
* @param array $options Options for pagination link. See #options for list of keys.
|
||||
|
|
@ -262,7 +288,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$defaults = array(
|
||||
'rel' => 'prev'
|
||||
);
|
||||
$options = array_merge($defaults, (array)$options);
|
||||
$options = (array)$options + $defaults;
|
||||
return $this->_pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions);
|
||||
}
|
||||
|
||||
|
|
@ -271,34 +297,37 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `url` Allows sending routing parameters such as controllers, actions or passed arguments.
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
* - `disabledTag` Tag to use instead of A tag when there is no next page
|
||||
*
|
||||
* @param string $title Title for the link. Defaults to 'Next >>'.
|
||||
* @param array $options Options for pagination link. See above for list of keys.
|
||||
* @param string $disabledTitle Title when the link is disabled.
|
||||
* @param array $disabledOptions Options for the disabled pagination link. See above for list of keys.
|
||||
* @return string A "next" link or or $disabledTitle text if the link is disabled.
|
||||
* @return string A "next" link or $disabledTitle text if the link is disabled.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::next
|
||||
*/
|
||||
public function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
||||
$defaults = array(
|
||||
'rel' => 'next'
|
||||
);
|
||||
$options = array_merge($defaults, (array)$options);
|
||||
$options = (array)$options + $defaults;
|
||||
return $this->_pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a sorting link. Sets named parameters for the sort and direction. Handles
|
||||
* Generates a sorting link. Sets named parameters for the sort and direction. Handles
|
||||
* direction switching automatically.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true.
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel().
|
||||
* - `direction` The default direction to use when this link isn't active.
|
||||
* - `lock` Lock direction. Will only use the default direction then, defaults to false.
|
||||
*
|
||||
* @param string $key The name of the key that the recordset should be sorted.
|
||||
* @param string $title Title for the link. If $title is null $key will be used
|
||||
|
|
@ -309,17 +338,25 @@ class PaginatorHelper extends AppHelper {
|
|||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sort
|
||||
*/
|
||||
public function sort($key, $title = null, $options = array()) {
|
||||
$options = array_merge(array('url' => array(), 'model' => null), $options);
|
||||
$options += array('url' => array(), 'model' => null);
|
||||
$url = $options['url'];
|
||||
unset($options['url']);
|
||||
|
||||
if (empty($title)) {
|
||||
$title = $key;
|
||||
|
||||
if (strpos($title, '.') !== false) {
|
||||
$title = str_replace('.', ' ', $title);
|
||||
}
|
||||
|
||||
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)));
|
||||
}
|
||||
$dir = isset($options['direction']) ? $options['direction'] : 'asc';
|
||||
$defaultDir = isset($options['direction']) ? strtolower($options['direction']) : 'asc';
|
||||
unset($options['direction']);
|
||||
|
||||
$locked = isset($options['lock']) ? $options['lock'] : false;
|
||||
unset($options['lock']);
|
||||
|
||||
$sortKey = $this->sortKey($options['model']);
|
||||
$defaultModel = $this->defaultModel();
|
||||
$isSorted = (
|
||||
|
|
@ -328,6 +365,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$key === $defaultModel . '.' . $sortKey
|
||||
);
|
||||
|
||||
$dir = $defaultDir;
|
||||
if ($isSorted) {
|
||||
$dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
|
||||
$class = $dir === 'asc' ? 'desc' : 'asc';
|
||||
|
|
@ -336,6 +374,10 @@ class PaginatorHelper extends AppHelper {
|
|||
} else {
|
||||
$options['class'] = $class;
|
||||
}
|
||||
if ($locked) {
|
||||
$dir = $defaultDir;
|
||||
$options['class'] .= ' locked';
|
||||
}
|
||||
}
|
||||
if (is_array($title) && array_key_exists($dir, $title)) {
|
||||
$title = $title[$dir];
|
||||
|
|
@ -350,24 +392,24 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `update` The Id of the DOM element you wish to update. Creates Ajax enabled links
|
||||
* - `update` The Id of the DOM element you wish to update. Creates Ajax enabled links
|
||||
* with the AjaxHelper.
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
*
|
||||
* @param string $title Title for the link.
|
||||
* @param string|array $url Url for the action. See Router::url()
|
||||
* @param string|array $url URL for the action. See Router::url()
|
||||
* @param array $options Options for the link. See #options for list of keys.
|
||||
* @return string A link with pagination parameters.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::link
|
||||
*/
|
||||
public function link($title, $url = array(), $options = array()) {
|
||||
$options = array_merge(array('model' => null, 'escape' => true), $options);
|
||||
$options += array('model' => null, 'escape' => true);
|
||||
$model = $options['model'];
|
||||
unset($options['model']);
|
||||
|
||||
if (!empty($this->options)) {
|
||||
$options = array_merge($this->options, $options);
|
||||
$options += $this->options;
|
||||
}
|
||||
if (isset($options['url'])) {
|
||||
$url = array_merge((array)$options['url'], (array)$url);
|
||||
|
|
@ -385,7 +427,7 @@ class PaginatorHelper extends AppHelper {
|
|||
* Merges passed URL options with current pagination state to generate a pagination URL.
|
||||
*
|
||||
* @param array $options Pagination/URL options array
|
||||
* @param boolean $asArray Return the url as an array, or a URI string
|
||||
* @param bool $asArray Return the URL as an array, or a URI string
|
||||
* @param string $model Which model to paginate on
|
||||
* @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::url
|
||||
|
|
@ -403,7 +445,12 @@ class PaginatorHelper extends AppHelper {
|
|||
$url = array_merge($url, compact('sort', 'direction'));
|
||||
}
|
||||
$url = $this->_convertUrlKeys($url, $paging['paramType']);
|
||||
|
||||
if (!empty($url['page']) && $url['page'] == 1) {
|
||||
$url['page'] = null;
|
||||
}
|
||||
if (!empty($url['?']['page']) && $url['?']['page'] == 1) {
|
||||
unset($url['?']['page']);
|
||||
}
|
||||
if ($asArray) {
|
||||
return $url;
|
||||
}
|
||||
|
|
@ -413,12 +460,12 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Converts the keys being used into the format set by options.paramType
|
||||
*
|
||||
* @param array $url Array of url params to convert
|
||||
* @param string $type
|
||||
* @return array converted url params.
|
||||
* @param array $url Array of URL params to convert
|
||||
* @param string $type Keys type.
|
||||
* @return array converted URL params.
|
||||
*/
|
||||
protected function _convertUrlKeys($url, $type) {
|
||||
if ($type == 'named') {
|
||||
if ($type === 'named') {
|
||||
return $url;
|
||||
}
|
||||
if (!isset($url['?'])) {
|
||||
|
|
@ -436,20 +483,20 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Protected method for generating prev/next links
|
||||
*
|
||||
* @param string $which
|
||||
* @param string $title
|
||||
* @param array $options
|
||||
* @param string $disabledTitle
|
||||
* @param array $disabledOptions
|
||||
* @param string $which Link type: 'Prev', 'Next'.
|
||||
* @param string $title Link title.
|
||||
* @param array $options Options list.
|
||||
* @param string $disabledTitle Disabled link title.
|
||||
* @param array $disabledOptions Disabled link options.
|
||||
* @return string
|
||||
*/
|
||||
protected function _pagingLink($which, $title = null, $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
||||
$check = 'has' . $which;
|
||||
$_defaults = array(
|
||||
'url' => array(), 'step' => 1, 'escape' => true,
|
||||
'model' => null, 'tag' => 'span', 'class' => strtolower($which)
|
||||
'url' => array(), 'step' => 1, 'escape' => true, 'model' => null,
|
||||
'tag' => 'span', 'class' => strtolower($which), 'disabledTag' => null
|
||||
);
|
||||
$options = array_merge($_defaults, (array)$options);
|
||||
$options = (array)$options + $_defaults;
|
||||
$paging = $this->params($options['model']);
|
||||
if (empty($disabledOptions)) {
|
||||
$disabledOptions = $options;
|
||||
|
|
@ -459,30 +506,52 @@ class PaginatorHelper extends AppHelper {
|
|||
if (!empty($disabledTitle) && $disabledTitle !== true) {
|
||||
$title = $disabledTitle;
|
||||
}
|
||||
$options = array_merge($_defaults, (array)$disabledOptions);
|
||||
$options = (array)$disabledOptions + array_intersect_key($options, $_defaults) + $_defaults;
|
||||
} elseif (!$this->{$check}($options['model'])) {
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach (array_keys($_defaults) as $key) {
|
||||
${$key} = $options[$key];
|
||||
unset($options[$key]);
|
||||
}
|
||||
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);
|
||||
|
||||
if ($this->{$check}($model)) {
|
||||
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'model'))), compact('class'));
|
||||
} else {
|
||||
unset($options['rel']);
|
||||
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));
|
||||
$url = array_merge(
|
||||
array('page' => $paging['page'] + ($which === 'Prev' ? $step * -1 : $step)),
|
||||
$url
|
||||
);
|
||||
if ($tag === false) {
|
||||
return $this->link(
|
||||
$title,
|
||||
$url,
|
||||
compact('escape', 'model', 'class') + $options
|
||||
);
|
||||
}
|
||||
$link = $this->link($title, $url, compact('escape', 'model') + $options);
|
||||
return $this->Html->tag($tag, $link, compact('class'));
|
||||
}
|
||||
unset($options['rel']);
|
||||
if (!$tag) {
|
||||
if ($disabledTag) {
|
||||
$tag = $disabledTag;
|
||||
$disabledTag = null;
|
||||
} else {
|
||||
$tag = $_defaults['tag'];
|
||||
}
|
||||
}
|
||||
if ($disabledTag) {
|
||||
$title = $this->Html->tag($disabledTag, $title, compact('escape') + $options);
|
||||
return $this->Html->tag($tag, $title, compact('class'));
|
||||
}
|
||||
return $this->Html->tag($tag, $title, compact('escape', 'class') + $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given result set is not at the first page
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return boolean True if the result set is not at the first page.
|
||||
* @return bool True if the result set is not at the first page.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasPrev
|
||||
*/
|
||||
public function hasPrev($model = null) {
|
||||
|
|
@ -492,8 +561,8 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Returns true if the given result set is not at the last page
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return boolean True if the result set is not at the last page.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return bool True if the result set is not at the last page.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasNext
|
||||
*/
|
||||
public function hasNext($model = null) {
|
||||
|
|
@ -503,9 +572,9 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Returns true if the given result set has the page number given by $page
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param integer $page The page number - if not set defaults to 1.
|
||||
* @return boolean True if the given result set has the specified page number.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param int $page The page number - if not set defaults to 1.
|
||||
* @return bool True if the given result set has the specified page number.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasPage
|
||||
*/
|
||||
public function hasPage($model = null, $page = 1) {
|
||||
|
|
@ -521,27 +590,22 @@ class PaginatorHelper extends AppHelper {
|
|||
* Does $model have $page in its range?
|
||||
*
|
||||
* @param string $model Model name to get parameters for.
|
||||
* @param integer $page Page number you are checking.
|
||||
* @return boolean Whether model has $page
|
||||
* @param int $page Page number you are checking.
|
||||
* @return bool Whether model has $page
|
||||
*/
|
||||
protected function _hasPage($model, $page) {
|
||||
$params = $this->params($model);
|
||||
if (!empty($params)) {
|
||||
if ($params["{$page}Page"] == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return !empty($params) && $params[$page . 'Page'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default model of the paged sets
|
||||
*
|
||||
* @return string Model name or null if the pagination isn't initialized.
|
||||
* @return string|null Model name or null if the pagination isn't initialized.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel
|
||||
*/
|
||||
public function defaultModel() {
|
||||
if ($this->_defaultModel != null) {
|
||||
if ($this->_defaultModel) {
|
||||
return $this->_defaultModel;
|
||||
}
|
||||
if (empty($this->request->params['paging'])) {
|
||||
|
|
@ -558,15 +622,15 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel();
|
||||
* - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
|
||||
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
|
||||
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
|
||||
* the following placeholders `{:page}`, `{:pages}`, `{:current}`, `{:count}`, `{:model}`, `{:start}`, `{:end}` and any
|
||||
* custom content you would like.
|
||||
* - `separator` The separator string to use, default to ' of '
|
||||
*
|
||||
* The `%page%` style placeholders also work, but are deprecated and will be removed in a future version.
|
||||
*
|
||||
* @param array $options Options for the counter string. See #options for list of keys.
|
||||
* @return string Counter string.
|
||||
* @deprecated The %page% style placeholders are deprecated.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::counter
|
||||
*/
|
||||
public function counter($options = array()) {
|
||||
|
|
@ -574,16 +638,14 @@ class PaginatorHelper extends AppHelper {
|
|||
$options = array('format' => $options);
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
array(
|
||||
'model' => $this->defaultModel(),
|
||||
'format' => 'pages',
|
||||
'separator' => __d('cake', ' of ')
|
||||
),
|
||||
$options);
|
||||
$options += array(
|
||||
'model' => $this->defaultModel(),
|
||||
'format' => 'pages',
|
||||
'separator' => __d('cake', ' of ')
|
||||
);
|
||||
|
||||
$paging = $this->params($options['model']);
|
||||
if ($paging['pageCount'] == 0) {
|
||||
if (!$paging['pageCount']) {
|
||||
$paging['pageCount'] = 1;
|
||||
}
|
||||
$start = 0;
|
||||
|
|
@ -602,10 +664,10 @@ class PaginatorHelper extends AppHelper {
|
|||
}
|
||||
$out = $start . $options['separator'][0] . $end . $options['separator'][1];
|
||||
$out .= $paging['count'];
|
||||
break;
|
||||
break;
|
||||
case 'pages':
|
||||
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$map = array(
|
||||
'%page%' => $paging['page'],
|
||||
|
|
@ -622,7 +684,6 @@ class PaginatorHelper extends AppHelper {
|
|||
'{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}', '{:model}'
|
||||
);
|
||||
$out = str_replace($newKeys, array_values($map), $out);
|
||||
break;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
|
@ -644,15 +705,18 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `separator` Separator content defaults to ' | '
|
||||
* - `tag` The tag to wrap links in, defaults to 'span'
|
||||
* - `first` Whether you want first links generated, set to an integer to define the number of 'first'
|
||||
* links to generate.
|
||||
* links to generate. If a string is set a link to the first page will be generated with the value
|
||||
* as the title.
|
||||
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
|
||||
* links to generate.
|
||||
* links to generate. If a string is set a link to the last page will be generated with the value
|
||||
* as the title.
|
||||
* - `ellipsis` Ellipsis content, defaults to '...'
|
||||
* - `class` Class for wrapper tag
|
||||
* - `currentClass` Class for wrapper tag on current active page, defaults to 'current'
|
||||
* - `currentTag` Tag to use for current page number, defaults to null
|
||||
*
|
||||
* @param array $options Options for the numbers, (before, after, model, modulus, separator)
|
||||
* @return string numbers string.
|
||||
* @param array|bool $options Options for the numbers, (before, after, model, modulus, separator)
|
||||
* @return string Numbers string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::numbers
|
||||
*/
|
||||
public function numbers($options = array()) {
|
||||
|
|
@ -664,27 +728,27 @@ class PaginatorHelper extends AppHelper {
|
|||
|
||||
$defaults = array(
|
||||
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
|
||||
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...', 'currentClass' => 'current'
|
||||
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...',
|
||||
'currentClass' => 'current', 'currentTag' => null
|
||||
);
|
||||
$options += $defaults;
|
||||
|
||||
$params = (array)$this->params($options['model']) + array('page' => 1);
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
if (empty($params['pageCount']) || $params['pageCount'] <= 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
extract($options);
|
||||
unset($options['tag'], $options['before'], $options['after'], $options['model'],
|
||||
$options['modulus'], $options['separator'], $options['first'], $options['last'],
|
||||
$options['ellipsis'], $options['class'], $options['currentClass']
|
||||
$options['ellipsis'], $options['class'], $options['currentClass'], $options['currentTag']
|
||||
);
|
||||
|
||||
$out = '';
|
||||
|
||||
if ($modulus && $params['pageCount'] > $modulus) {
|
||||
$half = intval($modulus / 2);
|
||||
$half = (int)($modulus / 2);
|
||||
$end = $params['page'] + $half;
|
||||
|
||||
if ($end > $params['pageCount']) {
|
||||
|
|
@ -696,9 +760,10 @@ class PaginatorHelper extends AppHelper {
|
|||
$end = $params['page'] + ($modulus - $params['page']) + 1;
|
||||
}
|
||||
|
||||
$firstPage = is_int($first) ? $first : 0;
|
||||
if ($first && $start > 1) {
|
||||
$offset = ($start <= (int)$first) ? $start - 1 : $first;
|
||||
if ($offset < $start - 1) {
|
||||
$offset = ($start <= $firstPage) ? $start - 1 : $first;
|
||||
if ($firstPage < $start - 1) {
|
||||
$out .= $this->first($offset, compact('tag', 'separator', 'ellipsis', 'class'));
|
||||
} else {
|
||||
$out .= $this->first($offset, compact('tag', 'separator', 'class', 'ellipsis') + array('after' => $separator));
|
||||
|
|
@ -714,7 +779,11 @@ class PaginatorHelper extends AppHelper {
|
|||
if ($class) {
|
||||
$currentClass .= ' ' . $class;
|
||||
}
|
||||
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
|
||||
if ($currentTag) {
|
||||
$out .= $this->Html->tag($tag, $this->Html->tag($currentTag, $params['page']), array('class' => $currentClass));
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
|
||||
}
|
||||
if ($i != $params['pageCount']) {
|
||||
$out .= $separator;
|
||||
}
|
||||
|
|
@ -731,8 +800,9 @@ class PaginatorHelper extends AppHelper {
|
|||
$out .= $after;
|
||||
|
||||
if ($last && $end < $params['pageCount']) {
|
||||
$offset = ($params['pageCount'] < $end + (int)$last) ? $params['pageCount'] - $end : $last;
|
||||
if ($offset <= $last && $params['pageCount'] - $end > $offset) {
|
||||
$lastPage = is_int($last) ? $last : 0;
|
||||
$offset = ($params['pageCount'] < $end + $lastPage) ? $params['pageCount'] - $end : $last;
|
||||
if ($offset <= $lastPage && $params['pageCount'] - $end > $lastPage) {
|
||||
$out .= $this->last($offset, compact('tag', 'separator', 'ellipsis', 'class'));
|
||||
} else {
|
||||
$out .= $this->last($offset, compact('tag', 'separator', 'class', 'ellipsis') + array('before' => $separator));
|
||||
|
|
@ -747,7 +817,11 @@ class PaginatorHelper extends AppHelper {
|
|||
if ($class) {
|
||||
$currentClass .= ' ' . $class;
|
||||
}
|
||||
$out .= $this->Html->tag($tag, $i, array('class' => $currentClass));
|
||||
if ($currentTag) {
|
||||
$out .= $this->Html->tag($tag, $this->Html->tag($currentTag, $i), array('class' => $currentClass));
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $i, array('class' => $currentClass));
|
||||
}
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
|
||||
}
|
||||
|
|
@ -767,7 +841,7 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* `echo $this->Paginator->first('< first');`
|
||||
*
|
||||
* Creates a single link for the first page. Will output nothing if you are on the first page.
|
||||
* Creates a single link for the first page. Will output nothing if you are on the first page.
|
||||
*
|
||||
* `echo $this->Paginator->first(3);`
|
||||
*
|
||||
|
|
@ -782,36 +856,34 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `separator` Content between the generated links, defaults to ' | '
|
||||
* - `ellipsis` Content for ellipsis, defaults to '...'
|
||||
*
|
||||
* @param string|integer $first if string use as label for the link. If numeric, the number of page links
|
||||
* @param string|int $first if string use as label for the link. If numeric, the number of page links
|
||||
* you want at the beginning of the range.
|
||||
* @param array $options An array of options.
|
||||
* @return string numbers string.
|
||||
* @return string Numbers string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::first
|
||||
*/
|
||||
public function first($first = '<< first', $options = array()) {
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'after' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
),
|
||||
(array)$options);
|
||||
$options = (array)$options + array(
|
||||
'tag' => 'span',
|
||||
'after' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
);
|
||||
|
||||
$params = array_merge(array('page' => 1), (array)$this->params($options['model']));
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
extract($options);
|
||||
unset($options['tag'], $options['after'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
|
||||
|
||||
$out = '';
|
||||
|
||||
if (is_int($first) && $params['page'] >= $first) {
|
||||
if ((is_int($first) || ctype_digit($first)) && $params['page'] >= $first) {
|
||||
if ($after === null) {
|
||||
$after = $ellipsis;
|
||||
}
|
||||
|
|
@ -834,11 +906,11 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* `echo $this->Paginator->last('last >');`
|
||||
*
|
||||
* Creates a single link for the last page. Will output nothing if you are on the last page.
|
||||
* Creates a single link for the last page. Will output nothing if you are on the last page.
|
||||
*
|
||||
* `echo $this->Paginator->last(3);`
|
||||
*
|
||||
* Will create links for the last 3 pages. Once you enter the page range, no output will be created.
|
||||
* Will create links for the last 3 pages. Once you enter the page range, no output will be created.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
|
|
@ -848,37 +920,35 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `separator` Content between the generated links, defaults to ' | '
|
||||
* - `ellipsis` Content for ellipsis, defaults to '...'
|
||||
*
|
||||
* @param string|integer $last if string use as label for the link, if numeric print page numbers
|
||||
* @param string|int $last if string use as label for the link, if numeric print page numbers
|
||||
* @param array $options Array of options
|
||||
* @return string numbers string.
|
||||
* @return string Numbers string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last
|
||||
*/
|
||||
public function last($last = 'last >>', $options = array()) {
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'before' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
),
|
||||
(array)$options);
|
||||
$options = (array)$options + array(
|
||||
'tag' => 'span',
|
||||
'before' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
);
|
||||
|
||||
$params = array_merge(array('page' => 1), (array)$this->params($options['model']));
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
extract($options);
|
||||
unset($options['tag'], $options['before'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
|
||||
|
||||
$out = '';
|
||||
$lower = $params['pageCount'] - $last + 1;
|
||||
$lower = $params['pageCount'] - (int)$last + 1;
|
||||
|
||||
if (is_int($last) && $params['page'] <= $lower) {
|
||||
if ((is_int($last) || ctype_digit($last)) && $params['page'] <= $lower) {
|
||||
if ($before === null) {
|
||||
$before = $ellipsis;
|
||||
}
|
||||
|
|
@ -898,4 +968,51 @@ class PaginatorHelper extends AppHelper {
|
|||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the meta-links for a paginated result set.
|
||||
*
|
||||
* `echo $this->Paginator->meta();`
|
||||
*
|
||||
* Echos the links directly, will output nothing if there is neither a previous nor next page.
|
||||
*
|
||||
* `$this->Paginator->meta(array('block' => true));`
|
||||
*
|
||||
* Will append the output of the meta function to the named block - if true is passed the "meta"
|
||||
* block is used.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
||||
* - `block` The block name to append the output to, or false/absent to return as a string
|
||||
*
|
||||
* @param array $options Array of options.
|
||||
* @return string|null Meta links.
|
||||
*/
|
||||
public function meta($options = array()) {
|
||||
$model = isset($options['model']) ? $options['model'] : null;
|
||||
$params = $this->params($model);
|
||||
$urlOptions = isset($this->options['url']) ? $this->options['url'] : array();
|
||||
$links = array();
|
||||
if ($this->hasPrev()) {
|
||||
$links[] = $this->Html->meta(array(
|
||||
'rel' => 'prev',
|
||||
'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] - 1)), true)
|
||||
));
|
||||
}
|
||||
if ($this->hasNext()) {
|
||||
$links[] = $this->Html->meta(array(
|
||||
'rel' => 'next',
|
||||
'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] + 1)), true)
|
||||
));
|
||||
}
|
||||
$out = implode($links);
|
||||
if (empty($options['block'])) {
|
||||
return $out;
|
||||
}
|
||||
if ($options['block'] === true) {
|
||||
$options['block'] = __FUNCTION__;
|
||||
}
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,21 @@
|
|||
/**
|
||||
* Prototype Engine Helper for JsHelper
|
||||
*
|
||||
* Provides Prototype specific Javascript for JsHelper. Requires at least
|
||||
* Provides Prototype specific JavaScript for JsHelper. Requires at least
|
||||
* Prototype 1.6
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('JsBaseEngineHelper', 'View/Helper');
|
||||
|
|
@ -25,7 +24,7 @@ App::uses('JsBaseEngineHelper', 'View/Helper');
|
|||
/**
|
||||
* Prototype Engine Helper for JsHelper
|
||||
*
|
||||
* Provides Prototype specific Javascript for JsHelper. Requires at least
|
||||
* Provides Prototype specific JavaScript for JsHelper. Requires at least
|
||||
* Prototype 1.6
|
||||
*
|
||||
* @package Cake.View.Helper
|
||||
|
|
@ -35,7 +34,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
/**
|
||||
* Is the current selection a multiple selection? or is it just a single element.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_multiple = false;
|
||||
|
||||
|
|
@ -115,11 +114,11 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return PrototypeEngineHelper instance of $this. Allows chained methods.
|
||||
* @return self
|
||||
*/
|
||||
public function get($selector) {
|
||||
$this->_multiple = false;
|
||||
if ($selector == 'window' || $selector == 'document') {
|
||||
if ($selector === 'window' || $selector === 'document') {
|
||||
$this->selection = "$(" . $selector . ")";
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -141,13 +140,13 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
* - `stop` - Whether you want the event to stopped. (defaults true)
|
||||
*
|
||||
* @param string $type Type of event to bind to the current 946 id
|
||||
* @param string $callback The Javascript function you wish to trigger or the function literal
|
||||
* @param string $callback The JavaScript function you wish to trigger or the function literal
|
||||
* @param array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
*/
|
||||
public function event($type, $callback, $options = array()) {
|
||||
$defaults = array('wrap' => true, 'stop' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
$options += $defaults;
|
||||
|
||||
$function = 'function (event) {%s}';
|
||||
if ($options['wrap'] && $options['stop']) {
|
||||
|
|
@ -195,9 +194,9 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
$effect = '';
|
||||
$optionString = null;
|
||||
if (isset($options['speed'])) {
|
||||
if ($options['speed'] == 'fast') {
|
||||
if ($options['speed'] === 'fast') {
|
||||
$options['duration'] = 0.5;
|
||||
} elseif ($options['speed'] == 'slow') {
|
||||
} elseif ($options['speed'] === 'slow') {
|
||||
$options['duration'] = 2;
|
||||
} else {
|
||||
$options['duration'] = 1;
|
||||
|
|
@ -211,17 +210,17 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
case 'hide':
|
||||
case 'show':
|
||||
$effect = $this->selection . '.' . $name . '();';
|
||||
break;
|
||||
break;
|
||||
case 'slideIn':
|
||||
case 'slideOut':
|
||||
$name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
|
||||
$name = ($name === 'slideIn') ? 'slideDown' : 'slideUp';
|
||||
$effect = 'Effect.' . $name . '(' . $this->selection . $optionString . ');';
|
||||
break;
|
||||
break;
|
||||
case 'fadeIn':
|
||||
case 'fadeOut':
|
||||
$name = ($name == 'fadeIn') ? 'appear' : 'fade';
|
||||
$name = ($name === 'fadeIn') ? 'appear' : 'fade';
|
||||
$effect = $this->selection . '.' . $name . '(' . substr($optionString, 2) . ');';
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return $effect;
|
||||
}
|
||||
|
|
@ -229,8 +228,8 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
/**
|
||||
* Create an Ajax or Ajax.Updater call.
|
||||
*
|
||||
* @param string|array $url
|
||||
* @param array $options
|
||||
* @param string|array $url URL.
|
||||
* @param array $options Options list.
|
||||
* @return string The completed ajax call.
|
||||
*/
|
||||
public function request($url, $options = array()) {
|
||||
|
|
@ -238,7 +237,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
$url = '"' . $url . '"';
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
$type = '.Request';
|
||||
if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
if (isset($options['type']) && strtolower($options['type']) === 'json') {
|
||||
unset($options['type']);
|
||||
}
|
||||
if (isset($options['update'])) {
|
||||
|
|
@ -355,7 +354,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
|
|||
* @see JsBaseEngineHelper::serializeForm()
|
||||
*/
|
||||
public function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$options += array('isForm' => false, 'inline' => false);
|
||||
$selection = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selection = '$(' . $this->selection . '.form)';
|
||||
|
|
|
|||
|
|
@ -5,16 +5,17 @@
|
|||
* Simplifies the output of RSS feeds.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -96,7 +97,7 @@ class RssHelper extends AppHelper {
|
|||
* Returns an RSS document wrapped in `<rss />` tags
|
||||
*
|
||||
* @param array $attrib `<rss />` tag attributes
|
||||
* @param string $content
|
||||
* @param string $content Tag content.
|
||||
* @return string An RSS document
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::document
|
||||
*/
|
||||
|
|
@ -122,12 +123,12 @@ class RssHelper extends AppHelper {
|
|||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::channel
|
||||
*/
|
||||
public function channel($attrib = array(), $elements = array(), $content = null) {
|
||||
if (!isset($elements['title']) && !empty($this->_View->pageTitle)) {
|
||||
$elements['title'] = $this->_View->pageTitle;
|
||||
}
|
||||
if (!isset($elements['link'])) {
|
||||
$elements['link'] = '/';
|
||||
}
|
||||
if (!isset($elements['title'])) {
|
||||
$elements['title'] = '';
|
||||
}
|
||||
if (!isset($elements['description'])) {
|
||||
$elements['description'] = '';
|
||||
}
|
||||
|
|
@ -137,7 +138,7 @@ class RssHelper extends AppHelper {
|
|||
foreach ($elements as $elem => $data) {
|
||||
$attributes = array();
|
||||
if (is_array($data)) {
|
||||
if (strtolower($elem) == 'cloud') {
|
||||
if (strtolower($elem) === 'cloud') {
|
||||
$attributes = $data;
|
||||
$data = array();
|
||||
} elseif (isset($data['attrib']) && is_array($data['attrib'])) {
|
||||
|
|
@ -167,7 +168,7 @@ class RssHelper extends AppHelper {
|
|||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::items
|
||||
*/
|
||||
public function items($items, $callback = null) {
|
||||
if ($callback != null) {
|
||||
if ($callback) {
|
||||
$items = array_map($callback, $items);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +208,7 @@ class RssHelper extends AppHelper {
|
|||
switch ($key) {
|
||||
case 'pubDate' :
|
||||
$val = $this->time($val);
|
||||
break;
|
||||
break;
|
||||
case 'category' :
|
||||
if (is_array($val) && !empty($val[0])) {
|
||||
foreach ($val as $category) {
|
||||
|
|
@ -223,7 +224,7 @@ class RssHelper extends AppHelper {
|
|||
} elseif (is_array($val) && isset($val['domain'])) {
|
||||
$attrib['domain'] = $val['domain'];
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'link':
|
||||
case 'guid':
|
||||
case 'comments':
|
||||
|
|
@ -233,7 +234,7 @@ class RssHelper extends AppHelper {
|
|||
$val = $val['url'];
|
||||
}
|
||||
$val = $this->url($val, true);
|
||||
break;
|
||||
break;
|
||||
case 'source':
|
||||
if (is_array($val) && isset($val['url'])) {
|
||||
$attrib['url'] = $this->url($val['url'], true);
|
||||
|
|
@ -242,7 +243,7 @@ class RssHelper extends AppHelper {
|
|||
$attrib['url'] = $this->url($val[0], true);
|
||||
$val = $val[1];
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'enclosure':
|
||||
if (is_string($val['url']) && is_file(WWW_ROOT . $val['url']) && file_exists(WWW_ROOT . $val['url'])) {
|
||||
if (!isset($val['length']) && strpos($val['url'], '://') === false) {
|
||||
|
|
@ -255,11 +256,11 @@ class RssHelper extends AppHelper {
|
|||
$val['url'] = $this->url($val['url'], true);
|
||||
$attrib = $val;
|
||||
$val = null;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$attrib = $att;
|
||||
}
|
||||
if (!is_null($val) && $escape) {
|
||||
if ($val !== null && $escape) {
|
||||
$val = h($val);
|
||||
}
|
||||
$elements[$key] = $this->elem($key, $attrib, $val);
|
||||
|
|
@ -273,7 +274,7 @@ class RssHelper extends AppHelper {
|
|||
/**
|
||||
* Converts a time in any format to an RSS time
|
||||
*
|
||||
* @param integer|string|DateTime $time
|
||||
* @param int|string|DateTime $time UNIX timestamp or valid time string or DateTime object.
|
||||
* @return string An RSS-formatted timestamp
|
||||
* @see TimeHelper::toRSS
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::time
|
||||
|
|
@ -288,7 +289,7 @@ class RssHelper extends AppHelper {
|
|||
* @param string $name The name of the XML element
|
||||
* @param array $attrib The attributes of the XML element
|
||||
* @param string|array $content XML element content
|
||||
* @param boolean $endTag Whether the end tag of the element should be printed
|
||||
* @param bool $endTag Whether the end tag of the element should be printed
|
||||
* @return string XML
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/rss.html#RssHelper::elem
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Session Helper provides access to the Session in the Views.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.1.7.3328
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
|
@ -31,7 +30,7 @@ App::uses('CakeSession', 'Model/Datasource');
|
|||
class SessionHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Used to read a session values set in a controller for a key or return values for all keys.
|
||||
* Reads a session value for a key or returns values for all keys.
|
||||
*
|
||||
* In your view: `$this->Session->read('Controller.sessKey');`
|
||||
* Calling the method without a param will return all session vars
|
||||
|
|
@ -45,12 +44,24 @@ class SessionHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Used to check is a session key has been set
|
||||
* Reads and deletes a session value for a key.
|
||||
*
|
||||
* In your view: `$this->Session->consume('Controller.sessKey');`
|
||||
*
|
||||
* @param string $name the name of the session key you want to read
|
||||
* @return mixed values from the session vars
|
||||
*/
|
||||
public function consume($name) {
|
||||
return CakeSession::consume($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a session key has been set.
|
||||
*
|
||||
* In your view: `$this->Session->check('Controller.sessKey');`
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @param string $name Session key to check.
|
||||
* @return bool
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::check
|
||||
*/
|
||||
public function check($name) {
|
||||
|
|
@ -63,7 +74,7 @@ class SessionHelper extends AppHelper {
|
|||
* In your view: `$this->Session->error();`
|
||||
*
|
||||
* @return string last error
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#displaying-notifcations-or-flash-messages
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#displaying-notifications-or-flash-messages
|
||||
*/
|
||||
public function error() {
|
||||
return CakeSession::error();
|
||||
|
|
@ -75,20 +86,20 @@ class SessionHelper extends AppHelper {
|
|||
* In your view: $this->Session->flash('somekey');
|
||||
* Will default to flash if no param is passed
|
||||
*
|
||||
* You can pass additional information into the flash message generation. This allows you
|
||||
* You can pass additional information into the flash message generation. This allows you
|
||||
* to consolidate all the parameters for a given type of flash message into the view.
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* echo $this->Session->flash('flash', array('params' => array('class' => 'new-flash')));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* The above would generate a flash message with a custom class name. Using $attrs['params'] you
|
||||
* can pass additional data into the element rendering that will be made available as local variables
|
||||
* when the element is rendered:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* echo $this->Session->flash('flash', array('params' => array('name' => $user['User']['name'])));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* This would pass the current user's name into the flash message, so you could create personalized
|
||||
* messages without the controller needing access to that data.
|
||||
|
|
@ -96,31 +107,33 @@ class SessionHelper extends AppHelper {
|
|||
* Lastly you can choose the element that is rendered when creating the flash message. Using
|
||||
* custom elements allows you to fully customize how flash messages are generated.
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* echo $this->Session->flash('flash', array('element' => 'my_custom_element'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* If you want to use an element from a plugin for rendering your flash message you can do that using the
|
||||
* plugin param:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* echo $this->Session->flash('flash', array(
|
||||
* 'element' => 'my_custom_element',
|
||||
* 'params' => array('plugin' => 'my_plugin')
|
||||
* ));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @param string $key The [Message.]key you are rendering in the view.
|
||||
* @param array $attrs Additional attributes to use for the creation of this flash message.
|
||||
* Supports the 'params', and 'element' keys that are used in the helper.
|
||||
* @return string
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::flash
|
||||
* @deprecated 3.0.0 Since 2.7, use FlashHelper::render() instead.
|
||||
*/
|
||||
public function flash($key = 'flash', $attrs = array()) {
|
||||
$out = false;
|
||||
|
||||
if (CakeSession::check('Message.' . $key)) {
|
||||
$flash = CakeSession::read('Message.' . $key);
|
||||
CakeSession::delete('Message.' . $key);
|
||||
$message = $flash['message'];
|
||||
unset($flash['message']);
|
||||
|
||||
|
|
@ -128,13 +141,13 @@ class SessionHelper extends AppHelper {
|
|||
$flash = array_merge($flash, $attrs);
|
||||
}
|
||||
|
||||
if ($flash['element'] == 'default') {
|
||||
if ($flash['element'] === 'default') {
|
||||
$class = 'message';
|
||||
if (!empty($flash['params']['class'])) {
|
||||
$class = $flash['params']['class'];
|
||||
}
|
||||
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>';
|
||||
} elseif ($flash['element'] == '' || $flash['element'] == null) {
|
||||
} elseif (!$flash['element']) {
|
||||
$out = $message;
|
||||
} else {
|
||||
$options = array();
|
||||
|
|
@ -143,9 +156,9 @@ class SessionHelper extends AppHelper {
|
|||
}
|
||||
$tmpVars = $flash['params'];
|
||||
$tmpVars['message'] = $message;
|
||||
$tmpVars['key'] = $key;
|
||||
$out = $this->_View->element($flash['element'], $tmpVars, $options);
|
||||
}
|
||||
CakeSession::delete('Message.' . $key);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
|
@ -153,7 +166,7 @@ class SessionHelper extends AppHelper {
|
|||
/**
|
||||
* Used to check is a session is valid in a view
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/session.html#SessionHelper::valid
|
||||
*/
|
||||
public function valid() {
|
||||
|
|
|
|||
|
|
@ -4,22 +4,22 @@
|
|||
*
|
||||
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
App::uses('Hash', 'Utility');
|
||||
|
||||
/**
|
||||
* Text helper library.
|
||||
|
|
@ -49,7 +49,9 @@ class TextHelper extends AppHelper {
|
|||
protected $_placeholders = array();
|
||||
|
||||
/**
|
||||
* String utility instance
|
||||
* CakeText utility instance
|
||||
*
|
||||
* @var stdClass
|
||||
*/
|
||||
protected $_engine;
|
||||
|
||||
|
|
@ -58,7 +60,7 @@ class TextHelper extends AppHelper {
|
|||
*
|
||||
* ### Settings:
|
||||
*
|
||||
* - `engine` Class name to use to replace String functionality.
|
||||
* - `engine` Class name to use to replace CakeText functionality.
|
||||
* The class needs to be placed in the `Utility` directory.
|
||||
*
|
||||
* @param View $View the view object the helper is attached to.
|
||||
|
|
@ -66,7 +68,7 @@ class TextHelper extends AppHelper {
|
|||
* @throws CakeException when the engine class could not be found.
|
||||
*/
|
||||
public function __construct(View $View, $settings = array()) {
|
||||
$settings = Hash::merge(array('engine' => 'String'), $settings);
|
||||
$settings = Hash::merge(array('engine' => 'CakeText'), $settings);
|
||||
parent::__construct($View, $settings);
|
||||
list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
|
||||
App::uses($engineClass, $plugin . 'Utility');
|
||||
|
|
@ -78,7 +80,11 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Call methods from String utility class
|
||||
* Call methods from CakeText utility class
|
||||
*
|
||||
* @param string $method Method to call.
|
||||
* @param array $params Parameters to pass to method.
|
||||
* @return mixed Whatever is returned by called method, or false on failure
|
||||
*/
|
||||
public function __call($method, $params) {
|
||||
return call_user_func_array(array($this->_engine, $method), $params);
|
||||
|
|
@ -101,14 +107,14 @@ class TextHelper extends AppHelper {
|
|||
$this->_placeholders = array();
|
||||
$options += array('escape' => true);
|
||||
|
||||
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[a-z0-9.\-:]+(?:/[^\s]*)?)#i';
|
||||
$pattern = '#(?<!href="|src="|">)((?:https?|ftp|nntp)://[\p{L}0-9.\-_:]+(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#i';
|
||||
$text = preg_replace_callback(
|
||||
$pattern,
|
||||
array(&$this, '_insertPlaceHolder'),
|
||||
$text
|
||||
);
|
||||
$text = preg_replace_callback(
|
||||
'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://)www.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
|
||||
'#(?<!href="|">)(?<!\b[[:punct:]])(?<!http://|https://|ftp://|nntp://|//)www\.[^\n\%\ <]+[^<\n\%\,\.\ <](?<!\))#i',
|
||||
array(&$this, '_insertPlaceHolder'),
|
||||
$text
|
||||
);
|
||||
|
|
@ -119,7 +125,7 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Saves the placeholder for a string, for later use. This gets around double
|
||||
* Saves the placeholder for a string, for later use. This gets around double
|
||||
* escaping content in URL's.
|
||||
*
|
||||
* @param array $matches An array of regexp matches.
|
||||
|
|
@ -182,9 +188,9 @@ class TextHelper extends AppHelper {
|
|||
$options += array('escape' => true);
|
||||
$this->_placeholders = array();
|
||||
|
||||
$atom = '[a-z0-9!#$%&\'*+\/=?^_`{|}~-]';
|
||||
$atom = '[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]';
|
||||
$text = preg_replace_callback(
|
||||
'/(' . $atom . '+(?:\.' . $atom . '+)*@[a-z0-9-]+(?:\.[a-z0-9-]+)+)/i',
|
||||
'/(?<=\s|^|\(|\>|\;)(' . $atom . '*(?:\.' . $atom . '+)*@[\p{L}0-9-]+(?:\.[\p{L}0-9-]+)+)/ui',
|
||||
array(&$this, '_insertPlaceholder'),
|
||||
$text
|
||||
);
|
||||
|
|
@ -212,12 +218,14 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see String::highlight()
|
||||
* Highlights a given phrase in a text. You can specify any expression in highlighter that
|
||||
* may include the \1 expression to include the $phrase found.
|
||||
*
|
||||
* @param string $text Text to search the phrase in
|
||||
* @param string $phrase The phrase that will be searched
|
||||
* @param array $options An array of html attributes and options.
|
||||
* @return string The highlighted text
|
||||
* @see CakeText::highlight()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlight
|
||||
*/
|
||||
public function highlight($text, $phrase, $options = array()) {
|
||||
|
|
@ -225,10 +233,34 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see String::stripLinks()
|
||||
* Formats paragraphs around given text for all line breaks
|
||||
* <br /> added for single line return
|
||||
* <p> added for double line return
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips given text of all links (<a href=....)
|
||||
*
|
||||
* @param string $text Text
|
||||
* @return string The text without links
|
||||
* @see CakeText::stripLinks()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::stripLinks
|
||||
*/
|
||||
public function stripLinks($text) {
|
||||
|
|
@ -236,12 +268,22 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see String::truncate()
|
||||
* Truncates text.
|
||||
*
|
||||
* Cuts a string to the length of $length and replaces the last characters
|
||||
* with the ellipsis if the text is longer than length.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `ellipsis` Will be used as Ending and appended to the trimmed string (`ending` is deprecated)
|
||||
* - `exact` If false, $text will not be cut mid-word
|
||||
* - `html` If true, HTML tags would be handled correctly
|
||||
*
|
||||
* @param string $text String to truncate.
|
||||
* @param integer $length Length of returned string, including ellipsis.
|
||||
* @param int $length Length of returned string, including ellipsis.
|
||||
* @param array $options An array of html attributes and options.
|
||||
* @return string Trimmed string.
|
||||
* @see CakeText::truncate()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate
|
||||
*/
|
||||
public function truncate($text, $length = 100, $options = array()) {
|
||||
|
|
@ -249,13 +291,37 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see String::excerpt()
|
||||
* Truncates text starting from the end.
|
||||
*
|
||||
* Cuts a string to the length of $length and replaces the first characters
|
||||
* with the ellipsis if the text is longer than length.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `ellipsis` Will be used as Beginning and prepended to the trimmed string
|
||||
* - `exact` If false, $text will not be cut mid-word
|
||||
*
|
||||
* @param string $text String to truncate.
|
||||
* @param int $length Length of returned string, including ellipsis.
|
||||
* @param array $options An array of html attributes and options.
|
||||
* @return string Trimmed string.
|
||||
* @see CakeText::tail()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::tail
|
||||
*/
|
||||
public function tail($text, $length = 100, $options = array()) {
|
||||
return $this->_engine->tail($text, $length, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts an excerpt from the text surrounding the phrase with a number of characters on each side
|
||||
* determined by radius.
|
||||
*
|
||||
* @param string $text String to search the phrase in
|
||||
* @param string $phrase Phrase that will be searched for
|
||||
* @param integer $radius The amount of characters that will be returned on each side of the founded phrase
|
||||
* @param int $radius The amount of characters that will be returned on each side of the founded phrase
|
||||
* @param string $ending Ending that will be appended
|
||||
* @return string Modified string
|
||||
* @see CakeText::excerpt()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt
|
||||
*/
|
||||
public function excerpt($text, $phrase, $radius = 100, $ending = '...') {
|
||||
|
|
@ -263,15 +329,16 @@ class TextHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see String::toList()
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural language.
|
||||
*
|
||||
* @param array $list The list to be joined
|
||||
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'
|
||||
* @param string $separator The separator used to join all the other items together. Defaults to ', '
|
||||
* @param array $list The list to be joined.
|
||||
* @param string $and The word used to join the last and second last items together with. Defaults to 'and'.
|
||||
* @param string $separator The separator used to join all the other items together. Defaults to ', '.
|
||||
* @return string The glued together string.
|
||||
* @see CakeText::toList()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList
|
||||
*/
|
||||
public function toList($list, $and = 'and', $separator = ', ') {
|
||||
public function toList($list, $and = null, $separator = ', ') {
|
||||
return $this->_engine->toList($list, $and, $separator);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Time Helper class file.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeTime', 'Utility');
|
||||
|
|
@ -34,6 +33,8 @@ class TimeHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* CakeTime instance
|
||||
*
|
||||
* @var CakeTime
|
||||
*/
|
||||
protected $_engine = null;
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ class TimeHelper extends AppHelper {
|
|||
* 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
|
||||
* @param array $settings Settings array
|
||||
* @throws CakeException When the engine class could not be found.
|
||||
*/
|
||||
public function __construct(View $View, $settings = array()) {
|
||||
|
|
@ -66,16 +67,15 @@ class TimeHelper extends AppHelper {
|
|||
*
|
||||
* @param string $name Name of the attribute to set.
|
||||
* @param string $value Value of the attribute to set.
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
switch ($name) {
|
||||
case 'niceFormat':
|
||||
$this->_engine->{$name} = $value;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$this->{$name} = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ class TimeHelper extends AppHelper {
|
|||
* Magic isset check for deprecated attributes.
|
||||
*
|
||||
* @param string $name Name of the attribute to check.
|
||||
* @return boolean
|
||||
* @return bool|null
|
||||
*/
|
||||
public function __isset($name) {
|
||||
if (isset($this->{$name})) {
|
||||
|
|
@ -115,18 +115,24 @@ class TimeHelper extends AppHelper {
|
|||
|
||||
/**
|
||||
* Call methods from CakeTime utility class
|
||||
*
|
||||
* @param string $method Method to call.
|
||||
* @param array $params Parameters to pass to method.
|
||||
* @return mixed Whatever is returned by called method, or false on failure
|
||||
*/
|
||||
public function __call($method, $params) {
|
||||
return call_user_func_array(array($this->_engine, $method), $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::convertSpecifiers()
|
||||
* Converts a string representing the format for the function strftime and returns a
|
||||
* Windows safe and i18n aware format.
|
||||
*
|
||||
* @param string $format Format with specifiers for strftime function.
|
||||
* Accepts the special specifier %S which mimics the modifier S for date()
|
||||
* @param string $time UNIX timestamp
|
||||
* @return string windows safe and date() function compatible format for strftime
|
||||
* @return string Windows safe and date() function compatible format for strftime
|
||||
* @see CakeTime::convertSpecifiers()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function convertSpecifiers($format, $time = null) {
|
||||
|
|
@ -134,11 +140,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::convert()
|
||||
* Converts given time (in server's time zone) to user's local time, given his/her timezone.
|
||||
*
|
||||
* @param string $serverTime UNIX timestamp
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return integer UNIX timestamp
|
||||
* @return int UNIX timestamp
|
||||
* @see CakeTime::convert()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function convert($serverTime, $timezone) {
|
||||
|
|
@ -146,9 +153,10 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::serverOffset()
|
||||
* Returns server's offset
|
||||
*
|
||||
* @return integer Offset
|
||||
* @return int Offset
|
||||
* @see CakeTime::serverOffset()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function serverOffset() {
|
||||
|
|
@ -156,11 +164,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::fromString()
|
||||
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Parsed timestamp
|
||||
* @see CakeTime::fromString()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function fromString($dateString, $timezone = null) {
|
||||
|
|
@ -168,12 +177,13 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::nice()
|
||||
* Returns a nicely formatted date string for given Datetime string.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @param string $format The format to use. If null, `TimeHelper::$niceFormat` is used
|
||||
* @param string $format The format to use. If null, `CakeTime::$niceFormat` is used
|
||||
* @return string Formatted date string
|
||||
* @see CakeTime::nice()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function nice($dateString = null, $timezone = null, $format = null) {
|
||||
|
|
@ -181,11 +191,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::niceShort()
|
||||
* Returns a formatted descriptive date string for given datetime string.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime objectp
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object.
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Described, relative date string
|
||||
* @see CakeTime::niceShort()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function niceShort($dateString = null, $timezone = null) {
|
||||
|
|
@ -193,13 +204,14 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::daysAsSql()
|
||||
* Returns a partial SQL string to search for all records between two dates.
|
||||
*
|
||||
* @param integer|string|DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param integer|string|DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string $fieldName Name of database field to compare with
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Partial SQL string.
|
||||
* @see CakeTime::daysAsSql()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function daysAsSql($begin, $end, $fieldName, $timezone = null) {
|
||||
|
|
@ -207,12 +219,14 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::dayAsSql()
|
||||
* Returns a partial SQL string to search for all records between two times
|
||||
* occurring on the same day.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string $fieldName Name of database field to compare with
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Partial SQL string.
|
||||
* @see CakeTime::dayAsSql()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function dayAsSql($dateString, $fieldName, $timezone = null) {
|
||||
|
|
@ -220,11 +234,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::isToday()
|
||||
* Returns true if given datetime string is today.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string is today
|
||||
* @return bool True if datetime string is today
|
||||
* @see CakeTime::isToday()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function isToday($dateString, $timezone = null) {
|
||||
|
|
@ -232,11 +247,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::isThisWeek()
|
||||
* Returns true if given datetime string is within this week.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string is within current week
|
||||
* @return bool True if datetime string is within current week
|
||||
* @see CakeTime::isThisWeek()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function isThisWeek($dateString, $timezone = null) {
|
||||
|
|
@ -244,11 +260,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::isThisMonth()
|
||||
* Returns true if given datetime string is within this month
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string is within current month
|
||||
* @return bool True if datetime string is within current month
|
||||
* @see CakeTime::isThisMonth()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function isThisMonth($dateString, $timezone = null) {
|
||||
|
|
@ -256,11 +273,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::isThisYear()
|
||||
* Returns true if given datetime string is within current year.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string is within current year
|
||||
* @return bool True if datetime string is within current year
|
||||
* @see CakeTime::isThisYear()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function isThisYear($dateString, $timezone = null) {
|
||||
|
|
@ -268,24 +286,25 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::wasYesterday()
|
||||
* Returns true if given datetime string was yesterday.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string was yesterday
|
||||
* @return bool True if datetime string was yesterday
|
||||
* @see CakeTime::wasYesterday()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*
|
||||
*/
|
||||
public function wasYesterday($dateString, $timezone = null) {
|
||||
return $this->_engine->wasYesterday($dateString, $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::isTomorrow()
|
||||
* Returns true if given datetime string is tomorrow.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean True if datetime string was yesterday
|
||||
* @return bool True if datetime string was yesterday
|
||||
* @see CakeTime::isTomorrow()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function isTomorrow($dateString, $timezone = null) {
|
||||
|
|
@ -293,11 +312,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::toQuarter()
|
||||
* Returns the quarter
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param boolean $range if true returns a range in Y-m-d format
|
||||
* @return mixed 1, 2, 3, or 4 quarter of year or array if $range true
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param bool $range if true returns a range in Y-m-d format
|
||||
* @return int|array 1, 2, 3, or 4 quarter of year or array if $range true
|
||||
* @see CakeTime::toQuarter()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function toQuarter($dateString, $range = false) {
|
||||
|
|
@ -305,11 +325,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::toUnix()
|
||||
* Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return integer Unix timestamp
|
||||
* @return int Unix timestamp
|
||||
* @see CakeTime::toUnix()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function toUnix($dateString, $timezone = null) {
|
||||
|
|
@ -317,11 +338,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::toAtom()
|
||||
* Returns a date formatted for Atom RSS feeds.
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Formatted date string
|
||||
* @see CakeTime::toAtom()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function toAtom($dateString, $timezone = null) {
|
||||
|
|
@ -329,11 +351,12 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::toRSS()
|
||||
* Formats date for RSS feeds
|
||||
*
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Formatted date string
|
||||
* @see CakeTime::toRSS()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function toRSS($dateString, $timezone = null) {
|
||||
|
|
@ -341,25 +364,26 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::timeAgoInWords()
|
||||
* Formats a date into a phrase expressing the relative time.
|
||||
*
|
||||
* ## Addition options
|
||||
*
|
||||
* - `element` - The element to wrap the formatted time in.
|
||||
* Has a few additional options:
|
||||
* - `tag` - The tag to use, defaults to 'span'.
|
||||
* - `class` - The classname to use, defaults to `time-ago-in-words`.
|
||||
* - `class` - The class name to use, defaults to `time-ago-in-words`.
|
||||
* - `title` - Defaults to the $dateTime input.
|
||||
*
|
||||
* @param integer|string|DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param array $options Default format if timestamp is used in $dateString
|
||||
* @return string Relative time string.
|
||||
* @see CakeTime::timeAgoInWords()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function timeAgoInWords($dateTime, $options = array()) {
|
||||
$element = null;
|
||||
|
||||
if (is_array($options) && !empty($options['element'])) {
|
||||
if (!empty($options['element'])) {
|
||||
$element = array(
|
||||
'tag' => 'span',
|
||||
'class' => 'time-ago-in-words',
|
||||
|
|
@ -367,7 +391,7 @@ class TimeHelper extends AppHelper {
|
|||
);
|
||||
|
||||
if (is_array($options['element'])) {
|
||||
$element = array_merge($element, $options['element']);
|
||||
$element = $options['element'] + $element;
|
||||
} else {
|
||||
$element['tag'] = $options['element'];
|
||||
}
|
||||
|
|
@ -388,13 +412,14 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::wasWithinLast()
|
||||
* Returns true if specified datetime was within the interval specified, else false.
|
||||
*
|
||||
* @param string|integer $timeInterval the numeric value with space then time type.
|
||||
* @param string|int $timeInterval the numeric value with space then time type.
|
||||
* Example of valid types: 6 hours, 2 days, 1 minute.
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @see CakeTime::wasWithinLast()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function wasWithinLast($timeInterval, $dateString, $timezone = null) {
|
||||
|
|
@ -402,13 +427,14 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::isWithinLast()
|
||||
* Returns true if specified datetime is within the interval specified, else false.
|
||||
*
|
||||
* @param string|integer $timeInterval the numeric value with space then time type.
|
||||
* @param string|int $timeInterval the numeric value with space then time type.
|
||||
* Example of valid types: 6 hours, 2 days, 1 minute.
|
||||
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* @see CakeTime::isWithinLast()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
||||
*/
|
||||
public function isWithinNext($timeInterval, $dateString, $timezone = null) {
|
||||
|
|
@ -416,10 +442,11 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::gmt()
|
||||
* Returns gmt as a UNIX timestamp.
|
||||
*
|
||||
* @param integer|string|DateTime $string UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @return integer UNIX timestamp
|
||||
* @param int|string|DateTime $string UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @return int UNIX timestamp
|
||||
* @see CakeTime::gmt()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function gmt($string = null) {
|
||||
|
|
@ -427,13 +454,27 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::format()
|
||||
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
* This function also accepts a time string and a format string as first and second parameters.
|
||||
* In that case this function behaves as a wrapper for TimeHelper::i18nFormat()
|
||||
*
|
||||
* @param integer|string|DateTime $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
|
||||
* @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
|
||||
* @param boolean $invalid flag to ignore results of fromString == false
|
||||
* ## Examples
|
||||
*
|
||||
* Create localized & formatted time:
|
||||
*
|
||||
* ```
|
||||
* $this->Time->format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012
|
||||
* $this->Time->format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale
|
||||
* $this->Time->format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A because an invalid date was passed
|
||||
* $this->Time->format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
|
||||
* ```
|
||||
*
|
||||
* @param int|string|DateTime $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
|
||||
* @param int|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
|
||||
* @param bool $invalid flag to ignore results of fromString == false
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Formatted date string
|
||||
* @see CakeTime::format()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function format($format, $date = null, $invalid = false, $timezone = null) {
|
||||
|
|
@ -441,13 +482,15 @@ class TimeHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see CakeTime::i18nFormat()
|
||||
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
* It takes into account the default date format for the current language if a LC_TIME file is used.
|
||||
*
|
||||
* @param integer|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param int|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
|
||||
* @param string $format strftime format string.
|
||||
* @param boolean $invalid flag to ignore results of fromString == false
|
||||
* @param bool $invalid flag to ignore results of fromString == false
|
||||
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
||||
* @return string Formatted and translated date string
|
||||
* @see CakeTime::i18nFormat()
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
||||
*/
|
||||
public function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@
|
|||
* and constructing helper class objects.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View
|
||||
* @since CakePHP(tm) v 2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ObjectCollection', 'Utility');
|
||||
|
|
@ -37,7 +38,7 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param View $view
|
||||
* @param View $view View instance.
|
||||
*/
|
||||
public function __construct(View $view) {
|
||||
$this->_View = $view;
|
||||
|
|
@ -49,7 +50,7 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
* if any
|
||||
*
|
||||
* @param string $helper The helper name to be loaded
|
||||
* @return boolean wheter the helper could be loaded or not
|
||||
* @return bool whether the helper could be loaded or not
|
||||
* @throws MissingHelperException When a helper could not be found.
|
||||
* App helpers are searched, and then plugin helpers.
|
||||
*/
|
||||
|
|
@ -91,19 +92,19 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads/constructs a helper. Will return the instance in the registry if it already exists.
|
||||
* By setting `$enable` to false you can disable callbacks for a helper. Alternatively you
|
||||
* can set `$settings['enabled'] = false` to disable callbacks. This alias is provided so that when
|
||||
* Loads/constructs a helper. Will return the instance in the registry if it already exists.
|
||||
* By setting `$enable` to false you can disable callbacks for a helper. Alternatively you
|
||||
* can set `$settings['enabled'] = false` to disable callbacks. This alias is provided so that when
|
||||
* declaring $helpers arrays you can disable callbacks on helpers.
|
||||
*
|
||||
* You can alias your helper as an existing helper by setting the 'className' key, i.e.,
|
||||
* {{{
|
||||
* ```
|
||||
* public $helpers = array(
|
||||
* 'Html' => array(
|
||||
* 'className' => 'AliasedHtml'
|
||||
* );
|
||||
* );
|
||||
* }}}
|
||||
* ```
|
||||
* All calls to the `Html` helper would use `AliasedHtml` instead.
|
||||
*
|
||||
* @param string $helper Helper name to load
|
||||
|
|
@ -112,7 +113,7 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
* @throws MissingHelperException when the helper could not be found
|
||||
*/
|
||||
public function load($helper, $settings = array()) {
|
||||
if (is_array($settings) && isset($settings['className'])) {
|
||||
if (isset($settings['className'])) {
|
||||
$alias = $helper;
|
||||
$helper = $settings['className'];
|
||||
}
|
||||
|
|
@ -163,7 +164,7 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
|
||||
/**
|
||||
* Trigger a callback method on every object in the collection.
|
||||
* Used to trigger methods on objects in the collection. Will fire the methods in the
|
||||
* Used to trigger methods on objects in the collection. Will fire the methods in the
|
||||
* order they were attached.
|
||||
*
|
||||
* ### Options
|
||||
|
|
@ -172,7 +173,7 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
* Can either be a scalar value, or an array of values to break on. Defaults to `false`.
|
||||
*
|
||||
* - `break` Set to true to enabled breaking. When a trigger is broken, the last returned value
|
||||
* will be returned. If used in combination with `collectReturn` the collected results will be returned.
|
||||
* will be returned. If used in combination with `collectReturn` the collected results will be returned.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* - `collectReturn` Set to true to collect the return of each object into an array.
|
||||
|
|
@ -183,8 +184,7 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
|
|||
* Any non-null value will modify the parameter index indicated.
|
||||
* Defaults to false.
|
||||
*
|
||||
*
|
||||
* @param string $callback|CakeEvent Method to fire on all the objects. Its assumed all the objects implement
|
||||
* @param string|CakeEvent $callback Method to fire on all the objects. Its assumed all the objects implement
|
||||
* the method you are calling. If an instance of CakeEvent is provided, then then Event name will parsed to
|
||||
* get the callback name. This is done by getting the last word after any dot in the event name
|
||||
* (eg. `Model.afterSave` event will trigger the `afterSave` callback)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('View', 'View');
|
||||
|
|
@ -18,7 +19,7 @@ App::uses('View', 'View');
|
|||
*
|
||||
* By setting the '_serialize' key in your controller, you can specify a view variable
|
||||
* that should be serialized to JSON and used as the response for the request.
|
||||
* This allows you to omit views + layouts, if your just need to emit a single view
|
||||
* This allows you to omit views and layouts if you just need to emit a single view
|
||||
* variable as the JSON response.
|
||||
*
|
||||
* In your controller, you could do the following:
|
||||
|
|
@ -28,20 +29,23 @@ App::uses('View', 'View');
|
|||
* When the view is rendered, the `$posts` view variable will be serialized
|
||||
* into JSON.
|
||||
*
|
||||
* You can also define `'_serialize'` as an array. This will create a top level object containing
|
||||
* You can also define `'_serialize'` as an array. This will create a top level object containing
|
||||
* all the named view variables:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $this->set(compact('posts', 'users', 'stuff'));
|
||||
* $this->set('_serialize', array('posts', 'users'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* The above would generate a JSON object that looks like:
|
||||
*
|
||||
* `{"posts": [...], "users": [...]}`
|
||||
*
|
||||
* If you don't use the `_serialize` key, you will need a view. You can use extended
|
||||
* views to provide layout like functionality.
|
||||
* If you don't use the `_serialize` key, you will need a view. You can use extended
|
||||
* views to provide layout-like functionality.
|
||||
*
|
||||
* You can also enable JSONP support by setting parameter `_jsonp` to true or a string to specify
|
||||
* custom query string paramater name which will contain the callback function name.
|
||||
*
|
||||
* @package Cake.View
|
||||
* @since CakePHP(tm) v 2.1.0
|
||||
|
|
@ -49,8 +53,8 @@ App::uses('View', 'View');
|
|||
class JsonView extends View {
|
||||
|
||||
/**
|
||||
* JSON views are always located in the 'json' sub directory for a
|
||||
* controllers views.
|
||||
* JSON views are always located in the 'json' sub directory for
|
||||
* controllers' views.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -59,7 +63,7 @@ class JsonView extends View {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @param Controller $controller Controller instance.
|
||||
*/
|
||||
public function __construct(Controller $controller = null) {
|
||||
parent::__construct($controller);
|
||||
|
|
@ -68,41 +72,104 @@ class JsonView extends View {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip loading helpers if this is a _serialize based view.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadHelpers() {
|
||||
if (isset($this->viewVars['_serialize'])) {
|
||||
return;
|
||||
}
|
||||
parent::loadHelpers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a JSON view.
|
||||
*
|
||||
* Uses the special '_serialize' parameter to convert a set of
|
||||
* view variables into a JSON response. Makes generating simple
|
||||
* JSON responses very easy. You can omit the '_serialize' parameter,
|
||||
* and use a normal view + layout as well.
|
||||
* ### Special parameters
|
||||
* `_serialize` To convert a set of view variables into a JSON response.
|
||||
* Its value can be a string for single variable name or array for multiple names.
|
||||
* You can omit the`_serialize` parameter, and use a normal view + layout as well.
|
||||
* `_jsonp` Enables JSONP support and wraps response in callback function provided in query string.
|
||||
* - Setting it to true enables the default query string parameter "callback".
|
||||
* - Setting it to a string value, uses the provided query string parameter for finding the
|
||||
* JSONP callback name.
|
||||
*
|
||||
* @param string $view The view being rendered.
|
||||
* @param string $layout The layout being rendered.
|
||||
* @return string The rendered view.
|
||||
*/
|
||||
public function render($view = null, $layout = null) {
|
||||
$return = null;
|
||||
if (isset($this->viewVars['_serialize'])) {
|
||||
$serialize = $this->viewVars['_serialize'];
|
||||
if (is_array($serialize)) {
|
||||
$data = array();
|
||||
foreach ($serialize as $key) {
|
||||
$data[$key] = $this->viewVars[$key];
|
||||
$return = $this->_serialize($this->viewVars['_serialize']);
|
||||
} elseif ($view !== false && $this->_getViewFileName($view)) {
|
||||
$return = parent::render($view, false);
|
||||
}
|
||||
|
||||
if (!empty($this->viewVars['_jsonp'])) {
|
||||
$jsonpParam = $this->viewVars['_jsonp'];
|
||||
if ($this->viewVars['_jsonp'] === true) {
|
||||
$jsonpParam = 'callback';
|
||||
}
|
||||
if (isset($this->request->query[$jsonpParam])) {
|
||||
$return = sprintf('%s(%s)', h($this->request->query[$jsonpParam]), $return);
|
||||
$this->response->type('js');
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize view vars
|
||||
*
|
||||
* ### Special parameters
|
||||
* `_jsonOptions` You can set custom options for json_encode() this way,
|
||||
* e.g. `JSON_HEX_TAG | JSON_HEX_APOS`.
|
||||
*
|
||||
* @param array $serialize The viewVars that need to be serialized
|
||||
* @throws CakeException
|
||||
* @return string The serialized data
|
||||
*/
|
||||
protected function _serialize($serialize) {
|
||||
if (is_array($serialize)) {
|
||||
$data = array();
|
||||
foreach ($serialize as $alias => $key) {
|
||||
if (is_numeric($alias)) {
|
||||
$alias = $key;
|
||||
}
|
||||
if (array_key_exists($key, $this->viewVars)) {
|
||||
$data[$alias] = $this->viewVars[$key];
|
||||
}
|
||||
}
|
||||
$data = !empty($data) ? $data : null;
|
||||
} else {
|
||||
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
||||
}
|
||||
|
||||
$jsonOptions = 0;
|
||||
if (isset($this->viewVars['_jsonOptions'])) {
|
||||
if ($this->viewVars['_jsonOptions'] === false) {
|
||||
$jsonOptions = 0;
|
||||
} else {
|
||||
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
||||
$jsonOptions = $this->viewVars['_jsonOptions'];
|
||||
}
|
||||
$content = json_encode($data);
|
||||
$this->Blocks->set('content', $content);
|
||||
return $content;
|
||||
}
|
||||
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
$content = $this->_render($viewFileName);
|
||||
$this->Blocks->set('content', $content);
|
||||
return $content;
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=') && Configure::read('debug')) {
|
||||
$jsonOptions = $jsonOptions | JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
$json = json_encode($data, $jsonOptions);
|
||||
|
||||
if (function_exists('json_last_error') && json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new CakeException(json_last_error_msg());
|
||||
}
|
||||
if ($json === false) {
|
||||
throw new CakeException('Failed to parse JSON');
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,44 +2,41 @@
|
|||
/**
|
||||
* Methods to display or download any type of file
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View
|
||||
* @since CakePHP(tm) v 1.2.0.5714
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('View', 'View');
|
||||
App::uses('CakeRequest', 'Network');
|
||||
|
||||
/**
|
||||
* Media View provides a custom view implementation for sending files to visitors. Its great
|
||||
* Media View provides a custom view implementation for sending files to visitors. Its great
|
||||
* for making the response of a controller action be a file that is saved somewhere on the filesystem.
|
||||
*
|
||||
* An example use comes from the CakePHP internals. MediaView is used to serve plugin and theme assets,
|
||||
* as they are not normally accessible from an application's webroot. Unlike other views, MediaView
|
||||
* as they are not normally accessible from an application's webroot. Unlike other views, MediaView
|
||||
* uses several viewVars that have special meaning:
|
||||
*
|
||||
* - `id` The filename on the server's filesystem, including extension.
|
||||
* - `name` The filename that will be sent to the user, specified without the extension.
|
||||
* - `download` Set to true to set a `Content-Disposition` header. This is ideal for file downloads.
|
||||
* - `extension` The extension of the file being served. This is used to set the mimetype.
|
||||
* If not provided its extracted from filename provided as `id`.
|
||||
* - `download` Set to true to set a `Content-Disposition` header. This is ideal for file downloads.
|
||||
* - `path` The absolute path, including the trailing / on the server's filesystem to `id`.
|
||||
* - `mimeType` The mime type of the file if CakeResponse doesn't know about it.
|
||||
* Must be an associative array with extension as key and mime type as value eg. array('ini' => 'text/plain')
|
||||
*
|
||||
* ### Usage
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* class ExampleController extends AppController {
|
||||
* public function download() {
|
||||
* $this->viewClass = 'Media';
|
||||
|
|
@ -53,190 +50,54 @@ App::uses('CakeRequest', 'Network');
|
|||
* $this->set($params);
|
||||
* }
|
||||
* }
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* @package Cake.View
|
||||
* @deprecated 3.0.0 Deprecated since version 2.3, use CakeResponse::file() instead
|
||||
*/
|
||||
class MediaView extends View {
|
||||
|
||||
/**
|
||||
* Indicates whether response gzip compression was enabled for this class
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_compressionEnabled = false;
|
||||
|
||||
/**
|
||||
* Display or download the given file
|
||||
*
|
||||
* @param string $view Not used
|
||||
* @param string $layout Not used
|
||||
* @return mixed
|
||||
* @throws NotFoundException
|
||||
* @return void
|
||||
*/
|
||||
public function render($view = null, $layout = null) {
|
||||
$name = $download = $extension = $id = $modified = $path = $cache = $mimeType = $compress = null;
|
||||
$name = $extension = $download = $id = $modified = $path = $cache = $mimeType = $compress = null;
|
||||
extract($this->viewVars, EXTR_OVERWRITE);
|
||||
|
||||
if (is_dir($path)) {
|
||||
$path = $path . $id;
|
||||
} else {
|
||||
$path = APP . $path . $id;
|
||||
}
|
||||
|
||||
if (!is_file($path)) {
|
||||
if (Configure::read('debug')) {
|
||||
throw new NotFoundException(sprintf('The requested file %s was not found', $path));
|
||||
}
|
||||
throw new NotFoundException('The requested file was not found');
|
||||
}
|
||||
$path = $path . $id;
|
||||
|
||||
if (is_array($mimeType)) {
|
||||
$this->response->type($mimeType);
|
||||
}
|
||||
|
||||
if (!isset($extension)) {
|
||||
$extension = pathinfo($id, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
if ($this->_isActive()) {
|
||||
$extension = strtolower($extension);
|
||||
//@codingStandardsIgnoreStart
|
||||
$fileSize = @filesize($path);
|
||||
//@codingStandardsIgnoreEnd
|
||||
$handle = fopen($path, 'rb');
|
||||
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
if ($cache) {
|
||||
if (!empty($modified) && !is_numeric($modified)) {
|
||||
$modified = strtotime($modified, time());
|
||||
} else {
|
||||
$modified = time();
|
||||
}
|
||||
if (!$extension || $this->response->type($extension) === false) {
|
||||
$download = true;
|
||||
}
|
||||
|
||||
if ($cache) {
|
||||
$this->response->cache($modified, $cache);
|
||||
} else {
|
||||
$this->response->header(array(
|
||||
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
|
||||
'Expires' => '0',
|
||||
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
|
||||
'Pragma' => 'no-cache'
|
||||
));
|
||||
}
|
||||
|
||||
if ($download) {
|
||||
$agent = env('HTTP_USER_AGENT');
|
||||
|
||||
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
|
||||
$contentType = 'application/octetstream';
|
||||
} elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
|
||||
$contentType = 'application/force-download';
|
||||
}
|
||||
|
||||
if (!empty($contentType)) {
|
||||
$this->response->type($contentType);
|
||||
}
|
||||
if (is_null($name)) {
|
||||
$name = $id;
|
||||
} elseif ($extension) {
|
||||
$name .= '.' . $extension;
|
||||
}
|
||||
$this->response->download($name);
|
||||
$this->response->header(array('Accept-Ranges' => 'bytes'));
|
||||
|
||||
$httpRange = env('HTTP_RANGE');
|
||||
if (isset($httpRange)) {
|
||||
list($toss, $range) = explode('=', $httpRange);
|
||||
|
||||
$size = $fileSize - 1;
|
||||
$length = $fileSize - $range;
|
||||
|
||||
$this->response->header(array(
|
||||
'Content-Length' => $length,
|
||||
'Content-Range' => 'bytes ' . $range . $size . '/' . $fileSize
|
||||
));
|
||||
|
||||
$this->response->statusCode(206);
|
||||
fseek($handle, $range);
|
||||
} else {
|
||||
$this->response->header('Content-Length', $fileSize);
|
||||
}
|
||||
} else {
|
||||
$this->response->header(array(
|
||||
'Content-Length' => $fileSize
|
||||
));
|
||||
}
|
||||
$this->_clearBuffer();
|
||||
if ($compress) {
|
||||
$this->_compressionEnabled = $this->response->compress();
|
||||
}
|
||||
|
||||
$this->response->send();
|
||||
return $this->_sendFile($handle);
|
||||
$this->response->cache($modified, $cache);
|
||||
} else {
|
||||
$this->response->disableCache();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads out a file handle, and echos the content to the client.
|
||||
*
|
||||
* @param resource $handle A file handle or stream
|
||||
* @return void
|
||||
*/
|
||||
protected function _sendFile($handle) {
|
||||
$chunkSize = 8192;
|
||||
$buffer = '';
|
||||
while (!feof($handle)) {
|
||||
if (!$this->_isActive()) {
|
||||
fclose($handle);
|
||||
return false;
|
||||
if ($name !== null) {
|
||||
if (empty($extension)) {
|
||||
$extension = pathinfo($id, PATHINFO_EXTENSION);
|
||||
}
|
||||
set_time_limit(0);
|
||||
$buffer = fread($handle, $chunkSize);
|
||||
echo $buffer;
|
||||
if (!$this->_compressionEnabled) {
|
||||
$this->_flushBuffer();
|
||||
if (!empty($extension)) {
|
||||
$name .= '.' . $extension;
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
$this->response->file($path, compact('name', 'download'));
|
||||
|
||||
/**
|
||||
* Returns true if connection is still active
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isActive() {
|
||||
return connection_status() == 0 && !connection_aborted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the contents of the topmost output buffer and discards them
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _clearBuffer() {
|
||||
//@codingStandardsIgnoreStart
|
||||
return @ob_end_clean();
|
||||
//@codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the contents of the output buffer
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _flushBuffer() {
|
||||
//@codingStandardsIgnoreStart
|
||||
@flush();
|
||||
@ob_flush();
|
||||
//@codingStandardsIgnoreEnd
|
||||
if ($compress) {
|
||||
$this->response->compress();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,29 +4,29 @@
|
|||
*
|
||||
* Automatic forms and actions generation for rapid web application development.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View
|
||||
* @since Cake v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('ThemeView', 'View');
|
||||
App::uses('View', 'View');
|
||||
|
||||
/**
|
||||
* ScaffoldView provides specific view file loading features for scaffolded views.
|
||||
*
|
||||
* @package Cake.View
|
||||
* @package Cake.View
|
||||
* @deprecated 3.0.0 Dynamic scaffolding will be removed and replaced in 3.0
|
||||
*/
|
||||
class ScaffoldView extends ThemeView {
|
||||
class ScaffoldView extends View {
|
||||
|
||||
/**
|
||||
* Override _getViewFileName Appends special scaffolding views in.
|
||||
|
|
@ -51,13 +51,13 @@ class ScaffoldView extends ThemeView {
|
|||
}
|
||||
}
|
||||
|
||||
if ($name === 'add' || $name == 'edit') {
|
||||
if ($name === 'add' || $name === 'edit') {
|
||||
$name = 'form';
|
||||
}
|
||||
|
||||
$scaffoldAction = 'scaffold.' . $name;
|
||||
|
||||
if (!is_null($this->subDir)) {
|
||||
if ($this->subDir !== null) {
|
||||
$subDir = strtolower($this->subDir) . DS;
|
||||
} else {
|
||||
$subDir = null;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Scaffolds
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar; ?> form">
|
||||
|
|
@ -26,20 +24,20 @@
|
|||
<div class="actions">
|
||||
<h3><?php echo __d('cake', 'Actions'); ?></h3>
|
||||
<ul>
|
||||
<?php if ($this->request->action != 'add'): ?>
|
||||
<?php if ($this->request->action !== 'add'): ?>
|
||||
<li><?php echo $this->Form->postLink(
|
||||
__d('cake', 'Delete'),
|
||||
array('action' => 'delete', $this->Form->value($modelClass . '.' . $primaryKey)),
|
||||
null,
|
||||
array(),
|
||||
__d('cake', 'Are you sure you want to delete # %s?', $this->Form->value($modelClass . '.' . $primaryKey)));
|
||||
?></li>
|
||||
<?php endif; ?>
|
||||
<li><?php echo $this->Html->link(__d('cake', 'List') . ' ' . $pluralHumanName, array('action' => 'index')); ?></li>
|
||||
<?php
|
||||
$done = array();
|
||||
foreach ($associations as $_type => $_data) {
|
||||
foreach ($_data as $_alias => $_details) {
|
||||
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
|
||||
foreach ($associations as $_type => $_data):
|
||||
foreach ($_data as $_alias => $_details):
|
||||
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)):
|
||||
echo "\t\t<li>" . $this->Html->link(
|
||||
__d('cake', 'List %s', Inflector::humanize($_details['controller'])),
|
||||
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'index')
|
||||
|
|
@ -49,9 +47,9 @@
|
|||
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'add')
|
||||
) . "</li>\n";
|
||||
$done[] = $_details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Scaffolds
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar; ?> index">
|
||||
|
|
@ -28,21 +26,21 @@
|
|||
<?php
|
||||
foreach (${$pluralVar} as ${$singularVar}):
|
||||
echo '<tr>';
|
||||
foreach ($scaffoldFields as $_field) {
|
||||
foreach ($scaffoldFields as $_field):
|
||||
$isKey = false;
|
||||
if (!empty($associations['belongsTo'])) {
|
||||
foreach ($associations['belongsTo'] as $_alias => $_details) {
|
||||
if ($_field === $_details['foreignKey']) {
|
||||
if (!empty($associations['belongsTo'])):
|
||||
foreach ($associations['belongsTo'] as $_alias => $_details):
|
||||
if ($_field === $_details['foreignKey']):
|
||||
$isKey = true;
|
||||
echo '<td>' . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . '</td>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($isKey !== true) {
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
if ($isKey !== true):
|
||||
echo '<td>' . h(${$singularVar}[$modelClass][$_field]) . '</td>';
|
||||
}
|
||||
}
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
echo '<td class="actions">';
|
||||
echo $this->Html->link(__d('cake', 'View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey]));
|
||||
|
|
@ -50,8 +48,8 @@ foreach (${$pluralVar} as ${$singularVar}):
|
|||
echo ' ' . $this->Form->postLink(
|
||||
__d('cake', 'Delete'),
|
||||
array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]),
|
||||
null,
|
||||
__d('cake', 'Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey]
|
||||
array(),
|
||||
__d('cake', 'Are you sure you want to delete # %s?', ${$singularVar}[$modelClass][$primaryKey])
|
||||
);
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
|
|
@ -69,7 +67,7 @@ endforeach;
|
|||
<?php
|
||||
echo $this->Paginator->prev('< ' . __d('cake', 'previous'), array(), null, array('class' => 'prev disabled'));
|
||||
echo $this->Paginator->numbers(array('separator' => ''));
|
||||
echo $this->Paginator->next(__d('cake', 'next') .' >', array(), null, array('class' => 'next disabled'));
|
||||
echo $this->Paginator->next(__d('cake', 'next') . ' >', array(), null, array('class' => 'next disabled'));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,26 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Scaffolds
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar; ?> view">
|
||||
<h2><?php echo __d('cake', 'View %s', $singularHumanName); ?></h2>
|
||||
<dl>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($scaffoldFields as $_field) {
|
||||
$isKey = false;
|
||||
if (!empty($associations['belongsTo'])) {
|
||||
|
|
@ -51,11 +48,11 @@ foreach ($scaffoldFields as $_field) {
|
|||
<ul>
|
||||
<?php
|
||||
echo "\t\t<li>";
|
||||
echo $this->Html->link(__d('cake', 'Edit %s', $singularHumanName), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey]));
|
||||
echo $this->Html->link(__d('cake', 'Edit %s', $singularHumanName), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey]));
|
||||
echo " </li>\n";
|
||||
|
||||
echo "\t\t<li>";
|
||||
echo $this->Form->postLink(__d('cake', 'Delete %s', $singularHumanName), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __d('cake', 'Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey] . '?');
|
||||
echo $this->Form->postLink(__d('cake', 'Delete %s', $singularHumanName), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), array(), __d('cake', 'Are you sure you want to delete # %s?', ${$singularVar}[$modelClass][$primaryKey]));
|
||||
echo " </li>\n";
|
||||
|
||||
echo "\t\t<li>";
|
||||
|
|
@ -97,12 +94,11 @@ foreach ($associations['hasOne'] as $_alias => $_details): ?>
|
|||
<?php if (!empty(${$singularVar}[$_alias])): ?>
|
||||
<dl>
|
||||
<?php
|
||||
$i = 0;
|
||||
$otherFields = array_keys(${$singularVar}[$_alias]);
|
||||
foreach ($otherFields as $_field) {
|
||||
foreach ($otherFields as $_field):
|
||||
echo "\t\t<dt>" . Inflector::humanize($_field) . "</dt>\n";
|
||||
echo "\t\t<dd>\n\t" . ${$singularVar}[$_alias][$_field] . "\n </dd>\n";
|
||||
}
|
||||
endforeach;
|
||||
?>
|
||||
</dl>
|
||||
<?php endif; ?>
|
||||
|
|
@ -176,8 +172,8 @@ $otherSingularVar = Inflector::variable($_alias);
|
|||
echo $this->Form->postLink(
|
||||
__d('cake', 'Delete'),
|
||||
array('plugin' => $_details['plugin'], 'controller' => $_details['controller'], 'action' => 'delete', ${$otherSingularVar}[$_details['primaryKey']]),
|
||||
null,
|
||||
__d('cake', 'Are you sure you want to delete', true) .' #' . ${$otherSingularVar}[$_details['primaryKey']] . '?'
|
||||
array(),
|
||||
__d('cake', 'Are you sure you want to delete # %s?', ${$otherSingularVar}[$_details['primaryKey']])
|
||||
);
|
||||
echo "\n";
|
||||
echo "\t\t\t</td>\n";
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* A custom view class that is used for themeing
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('View', 'View');
|
||||
|
|
@ -25,7 +24,7 @@ App::uses('View', 'View');
|
|||
* Stub class for 2.1 Compatibility
|
||||
*
|
||||
* @package Cake.View
|
||||
* @deprecated Deprecated since 2.1, use View class instead
|
||||
* @deprecated 3.0.0 Deprecated since 2.1, use View class instead
|
||||
*/
|
||||
class ThemeView extends View {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,18 @@
|
|||
/**
|
||||
* Methods for displaying presentation data in the view.
|
||||
*
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('HelperCollection', 'View');
|
||||
|
|
@ -27,16 +26,16 @@ App::uses('CakeResponse', 'Network');
|
|||
|
||||
/**
|
||||
* View, the V in the MVC triad. View interacts with Helpers and view variables passed
|
||||
* in from the controller to render the results of the controller action. Often this is HTML,
|
||||
* in from the controller to render the results of the controller action. Often this is HTML,
|
||||
* but can also take the form of JSON, XML, PDF's or streaming files.
|
||||
*
|
||||
* CakePHP uses a two-step-view pattern. This means that the view content is rendered first,
|
||||
* and then inserted into the selected layout. This also means you can pass data from the view to the
|
||||
* CakePHP uses a two-step-view pattern. This means that the view content is rendered first,
|
||||
* and then inserted into the selected layout. This also means you can pass data from the view to the
|
||||
* layout using `$this->set()`
|
||||
*
|
||||
* Since 2.1, the base View class also includes support for themes by default. Theme views are regular
|
||||
* view files that can provide unique HTML and static assets. If theme views are not found for the
|
||||
* current view the default app view files will be used. You can set `$this->theme = 'mytheme'`
|
||||
* Since 2.1, the base View class also includes support for themes by default. Theme views are regular
|
||||
* view files that can provide unique HTML and static assets. If theme views are not found for the
|
||||
* current view the default app view files will be used. You can set `$this->theme = 'mytheme'`
|
||||
* in your Controller to use the Themes.
|
||||
*
|
||||
* Example of theme path with `$this->theme = 'SuperHot';` Would be `app/View/Themed/SuperHot/Posts`
|
||||
|
|
@ -54,7 +53,7 @@ App::uses('CakeResponse', 'Network');
|
|||
* @property TimeHelper $Time
|
||||
* @property ViewBlock $Blocks
|
||||
*/
|
||||
class View extends Object {
|
||||
class View extends CakeObject {
|
||||
|
||||
/**
|
||||
* Helpers collection
|
||||
|
|
@ -81,7 +80,7 @@ class View extends Object {
|
|||
/**
|
||||
* Name of the controller.
|
||||
*
|
||||
* @var string Name of controller
|
||||
* @var string
|
||||
*/
|
||||
public $name = null;
|
||||
|
||||
|
|
@ -95,14 +94,14 @@ class View extends Object {
|
|||
/**
|
||||
* An array of names of built-in helpers to include.
|
||||
*
|
||||
* @var mixed A single name as a string or a list of names as an array.
|
||||
* @var mixed
|
||||
*/
|
||||
public $helpers = array('Html');
|
||||
public $helpers = array();
|
||||
|
||||
/**
|
||||
* Path to View.
|
||||
*
|
||||
* @var string Path to View
|
||||
* @var string
|
||||
*/
|
||||
public $viewPath = null;
|
||||
|
||||
|
|
@ -130,27 +129,27 @@ class View extends Object {
|
|||
/**
|
||||
* Path to Layout.
|
||||
*
|
||||
* @var string Path to Layout
|
||||
* @var string
|
||||
*/
|
||||
public $layoutPath = null;
|
||||
|
||||
/**
|
||||
* Turns on or off Cake's conventional mode of applying layout files. On by default.
|
||||
* Turns on or off CakePHP's conventional mode of applying layout files. On by default.
|
||||
* Setting to off means that layouts will not be automatically applied to rendered views.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $autoLayout = true;
|
||||
|
||||
/**
|
||||
* File extension. Defaults to Cake's template ".ctp".
|
||||
* File extension. Defaults to CakePHP's template ".ctp".
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ext = '.ctp';
|
||||
|
||||
/**
|
||||
* Sub-directory for this view file. This is often used for extension based routing.
|
||||
* Sub-directory for this view file. This is often used for extension based routing.
|
||||
* Eg. With an `xml` extension, $subDir would be `xml/`
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -182,7 +181,7 @@ class View extends Object {
|
|||
/**
|
||||
* True when the view has been rendered.
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
public $hasRendered = false;
|
||||
|
||||
|
|
@ -210,8 +209,8 @@ class View extends Object {
|
|||
public $response;
|
||||
|
||||
/**
|
||||
* The Cache configuration View will use to store cached elements. Changing this will change
|
||||
* the default configuration elements are stored under. You can also choose a cache config
|
||||
* The Cache configuration View will use to store cached elements. Changing this will change
|
||||
* the default configuration elements are stored under. You can also choose a cache config
|
||||
* per element.
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -219,6 +218,15 @@ class View extends Object {
|
|||
*/
|
||||
public $elementCache = 'default';
|
||||
|
||||
/**
|
||||
* Element cache settings
|
||||
*
|
||||
* @var array
|
||||
* @see View::_elementCache();
|
||||
* @see View::_renderElement
|
||||
*/
|
||||
public $elementCacheSettings = array();
|
||||
|
||||
/**
|
||||
* List of variables to collect from the associated controller.
|
||||
*
|
||||
|
|
@ -244,11 +252,11 @@ class View extends Object {
|
|||
protected $_paths = array();
|
||||
|
||||
/**
|
||||
* Indicate that helpers have been loaded.
|
||||
* Holds an array of plugin paths.
|
||||
*
|
||||
* @var boolean
|
||||
* @var array
|
||||
*/
|
||||
protected $_helpersLoaded = false;
|
||||
protected $_pathsForPlugin = array();
|
||||
|
||||
/**
|
||||
* The names of views and their parents used with View::extend();
|
||||
|
|
@ -265,7 +273,7 @@ class View extends Object {
|
|||
protected $_current = null;
|
||||
|
||||
/**
|
||||
* Currently rendering an element. Used for finding parent fragments
|
||||
* Currently rendering an element. Used for finding parent fragments
|
||||
* for elements.
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -292,12 +300,29 @@ class View extends Object {
|
|||
/**
|
||||
* Whether the event manager was already configured for this object
|
||||
*
|
||||
* @var boolean
|
||||
* @var bool
|
||||
*/
|
||||
protected $_eventManagerConfigured = false;
|
||||
|
||||
/**
|
||||
* Constant for view file type 'view'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_VIEW = 'view';
|
||||
|
||||
/**
|
||||
* Constant for view file type 'element'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_ELEMENT = 'element';
|
||||
|
||||
/**
|
||||
* Constant for view file type 'layout'
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TYPE_LAYOUT = 'layout';
|
||||
|
||||
/**
|
||||
|
|
@ -322,10 +347,11 @@ class View extends Object {
|
|||
if (is_object($controller) && isset($controller->response)) {
|
||||
$this->response = $controller->response;
|
||||
} else {
|
||||
$this->response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
|
||||
$this->response = new CakeResponse();
|
||||
}
|
||||
$this->Helpers = new HelperCollection($this);
|
||||
$this->Blocks = new ViewBlock();
|
||||
$this->loadHelpers();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
@ -354,96 +380,69 @@ class View extends Object {
|
|||
* data to be used in the element. Elements can be cached improving performance by using the `cache` option.
|
||||
*
|
||||
* @param string $name Name of template file in the/app/View/Elements/ folder,
|
||||
* or `MyPlugin.template` to use the template element from MyPlugin. If the element
|
||||
* or `MyPlugin.template` to use the template element from MyPlugin. If the element
|
||||
* is not found in the plugin, the normal view path cascade will be searched.
|
||||
* @param array $data Array of data to be made available to the rendered view (i.e. the Element)
|
||||
* @param array $options Array of options. Possible keys are:
|
||||
* - `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array
|
||||
* If an array, the following keys can be used:
|
||||
* - `config` - Used to store the cached element in a custom cache configuration.
|
||||
* - `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_`
|
||||
* - `plugin` - Load an element from a specific plugin. This option is deprecated, see below.
|
||||
* - `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_`
|
||||
* - `plugin` - (deprecated!) Load an element from a specific plugin. This option is deprecated, and
|
||||
* will be removed in CakePHP 3.0. Use `Plugin.element_name` instead.
|
||||
* - `callbacks` - Set to true to fire beforeRender and afterRender helper callbacks for this element.
|
||||
* Defaults to false.
|
||||
* - `ignoreMissing` - Used to allow missing elements. Set to true to not trigger notices.
|
||||
* @return string Rendered Element
|
||||
* @deprecated The `$options['plugin']` is deprecated and will be removed in CakePHP 3.0. Use
|
||||
* `Plugin.element_name` instead.
|
||||
*/
|
||||
public function element($name, $data = array(), $options = array()) {
|
||||
$file = $plugin = $key = null;
|
||||
$callbacks = false;
|
||||
$file = $plugin = null;
|
||||
|
||||
if (isset($options['plugin'])) {
|
||||
$name = Inflector::camelize($options['plugin']) . '.' . $name;
|
||||
}
|
||||
|
||||
if (isset($options['callbacks'])) {
|
||||
$callbacks = $options['callbacks'];
|
||||
if (!isset($options['callbacks'])) {
|
||||
$options['callbacks'] = false;
|
||||
}
|
||||
|
||||
if (isset($options['cache'])) {
|
||||
$underscored = null;
|
||||
if ($plugin) {
|
||||
$underscored = Inflector::underscore($plugin);
|
||||
}
|
||||
$keys = array_merge(array($underscored, $name), array_keys($options), array_keys($data));
|
||||
$caching = array(
|
||||
'config' => $this->elementCache,
|
||||
'key' => implode('_', $keys)
|
||||
);
|
||||
if (is_array($options['cache'])) {
|
||||
$defaults = array(
|
||||
'config' => $this->elementCache,
|
||||
'key' => $caching['key']
|
||||
);
|
||||
$caching = array_merge($defaults, $options['cache']);
|
||||
}
|
||||
$key = 'element_' . $caching['key'];
|
||||
$contents = Cache::read($key, $caching['config']);
|
||||
$contents = $this->_elementCache($name, $data, $options);
|
||||
if ($contents !== false) {
|
||||
return $contents;
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->_getElementFilename($name);
|
||||
|
||||
if ($file) {
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
if ($callbacks) {
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($file)));
|
||||
}
|
||||
|
||||
$current = $this->_current;
|
||||
$restore = $this->_currentType;
|
||||
|
||||
$this->_currentType = self::TYPE_ELEMENT;
|
||||
$element = $this->_render($file, array_merge($this->viewVars, $data));
|
||||
|
||||
$this->_currentType = $restore;
|
||||
$this->_current = $current;
|
||||
|
||||
if ($callbacks) {
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
|
||||
}
|
||||
if (isset($options['cache'])) {
|
||||
Cache::write($key, $element, $caching['config']);
|
||||
}
|
||||
return $element;
|
||||
return $this->_renderElement($file, $data, $options);
|
||||
}
|
||||
$file = 'Elements' . DS . $name . $this->ext;
|
||||
|
||||
if (Configure::read('debug') > 0) {
|
||||
return __d('cake_dev', 'Element Not Found: %s', $file);
|
||||
if (empty($options['ignoreMissing'])) {
|
||||
list ($plugin, $name) = pluginSplit($name, true);
|
||||
$name = str_replace('/', DS, $name);
|
||||
$file = $plugin . 'Elements' . DS . $name . $this->ext;
|
||||
trigger_error(__d('cake_dev', 'Element Not Found: %s', $file), E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an element exists
|
||||
*
|
||||
* @param string $name Name of template file in the /app/View/Elements/ folder,
|
||||
* or `MyPlugin.template` to check the template element from MyPlugin. If the element
|
||||
* is not found in the plugin, the normal view path cascade will be searched.
|
||||
* @return bool Success
|
||||
*/
|
||||
public function elementExists($name) {
|
||||
return (bool)$this->_getElementFilename($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders view for given view file and layout.
|
||||
*
|
||||
* Render triggers helper callbacks, which are fired before and after the view are rendered,
|
||||
* as well as before and after the layout. The helper callbacks are called:
|
||||
* as well as before and after the layout. The helper callbacks are called:
|
||||
*
|
||||
* - `beforeRender`
|
||||
* - `afterRender`
|
||||
|
|
@ -452,26 +451,24 @@ class View extends Object {
|
|||
*
|
||||
* If View::$autoRender is false and no `$layout` is provided, the view will be returned bare.
|
||||
*
|
||||
* View and layout names can point to plugin views/layouts. Using the `Plugin.view` syntax
|
||||
* a plugin view/layout can be used instead of the app ones. If the chosen plugin is not found
|
||||
* View and layout names can point to plugin views/layouts. Using the `Plugin.view` syntax
|
||||
* a plugin view/layout can be used instead of the app ones. If the chosen plugin is not found
|
||||
* the view will be located along the regular view path cascade.
|
||||
*
|
||||
* @param string $view Name of view file to use
|
||||
* @param string $layout Layout to use.
|
||||
* @return string Rendered Element
|
||||
* @throws CakeException if there is an error in the view.
|
||||
* @return string|null Rendered content or null if content already rendered and returned earlier.
|
||||
* @triggers View.beforeRender $this, array($viewFileName)
|
||||
* @triggers View.afterRender $this, array($viewFileName)
|
||||
* @throws CakeException If there is an error in the view.
|
||||
*/
|
||||
public function render($view = null, $layout = null) {
|
||||
if ($this->hasRendered) {
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
$this->Blocks->set('content', '');
|
||||
|
||||
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
|
||||
$this->_currentType = self::TYPE_VIEW;
|
||||
$this->_currentType = static::TYPE_VIEW;
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($viewFileName)));
|
||||
$this->Blocks->set('content', $this->_render($viewFileName));
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($viewFileName)));
|
||||
|
|
@ -494,20 +491,23 @@ class View extends Object {
|
|||
* - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control.
|
||||
* - `content_for_layout` - contains rendered view file
|
||||
* - `scripts_for_layout` - Contains content added with addScript() as well as any content in
|
||||
* the 'meta', 'css', and 'script' blocks. They are appended in that order.
|
||||
* the 'meta', 'css', and 'script' blocks. They are appended in that order.
|
||||
*
|
||||
* Deprecated features:
|
||||
*
|
||||
* - `$scripts_for_layout` is deprecated and will be removed in CakePHP 3.0.
|
||||
* Use the block features instead. `meta`, `css` and `script` will be populated
|
||||
* Use the block features instead. `meta`, `css` and `script` will be populated
|
||||
* by the matching methods on HtmlHelper.
|
||||
* - `$title_for_layout` is deprecated and will be removed in CakePHP 3.0
|
||||
* - `$title_for_layout` is deprecated and will be removed in CakePHP 3.0.
|
||||
* Use the `title` block instead.
|
||||
* - `$content_for_layout` is deprecated and will be removed in CakePHP 3.0.
|
||||
* Use the `content` block instead.
|
||||
*
|
||||
* @param string $content Content to render in a view, wrapped by the surrounding layout.
|
||||
* @param string $layout Layout name
|
||||
* @return mixed Rendered output, or false on error
|
||||
* @triggers View.beforeLayout $this, array($layoutFileName)
|
||||
* @triggers View.afterLayout $this, array($layoutFileName)
|
||||
* @throws CakeException if there is an error in the view.
|
||||
*/
|
||||
public function renderLayout($content, $layout = null) {
|
||||
|
|
@ -516,11 +516,10 @@ class View extends Object {
|
|||
return $this->Blocks->get('content');
|
||||
}
|
||||
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
if (empty($content)) {
|
||||
$content = $this->Blocks->get('content');
|
||||
} else {
|
||||
$this->Blocks->set('content', $content);
|
||||
}
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.beforeLayout', $this, array($layoutFileName)));
|
||||
|
||||
|
|
@ -532,11 +531,18 @@ class View extends Object {
|
|||
'scripts_for_layout' => $scripts,
|
||||
));
|
||||
|
||||
if (!isset($this->viewVars['title_for_layout'])) {
|
||||
$this->viewVars['title_for_layout'] = Inflector::humanize($this->viewPath);
|
||||
$title = $this->Blocks->get('title');
|
||||
if ($title === '') {
|
||||
if (isset($this->viewVars['title_for_layout'])) {
|
||||
$title = $this->viewVars['title_for_layout'];
|
||||
} else {
|
||||
$title = Inflector::humanize($this->viewPath);
|
||||
}
|
||||
}
|
||||
$this->viewVars['title_for_layout'] = $title;
|
||||
$this->Blocks->set('title', $title);
|
||||
|
||||
$this->_currentType = self::TYPE_LAYOUT;
|
||||
$this->_currentType = static::TYPE_LAYOUT;
|
||||
$this->Blocks->set('content', $this->_render($layoutFileName));
|
||||
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.afterLayout', $this, array($layoutFileName)));
|
||||
|
|
@ -549,14 +555,16 @@ class View extends Object {
|
|||
*
|
||||
* @param string $filename the cache file to include
|
||||
* @param string $timeStart the page render start time
|
||||
* @return boolean Success of rendering the cached file.
|
||||
* @return bool Success of rendering the cached file.
|
||||
*/
|
||||
public function renderCache($filename, $timeStart) {
|
||||
$response = $this->response;
|
||||
ob_start();
|
||||
include ($filename);
|
||||
include $filename;
|
||||
|
||||
if (Configure::read('debug') > 0 && $this->layout != 'xml') {
|
||||
echo "<!-- Cached Render Time: " . round(microtime(true) - $timeStart, 4) . "s -->";
|
||||
$type = $response->mapType($response->type());
|
||||
if (Configure::read('debug') > 0 && $type === 'html') {
|
||||
echo "<!-- Cached Render Time: " . round(microtime(true) - (int)$timeStart, 4) . "s -->";
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
|
||||
|
|
@ -565,15 +573,10 @@ class View extends Object {
|
|||
//@codingStandardsIgnoreStart
|
||||
@unlink($filename);
|
||||
//@codingStandardsIgnoreEnd
|
||||
unset ($out);
|
||||
unset($out);
|
||||
return false;
|
||||
} else {
|
||||
if ($this->layout === 'xml') {
|
||||
header('Content-type: text/xml');
|
||||
}
|
||||
$commentLength = strlen('<!--cachetime:' . $match['1'] . '-->');
|
||||
return substr($out, $commentLength);
|
||||
}
|
||||
return substr($out, strlen($match[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -591,22 +594,22 @@ class View extends Object {
|
|||
*
|
||||
* @param string $var The view var you want the contents of.
|
||||
* @return mixed The content of the named var if its set, otherwise null.
|
||||
* @deprecated Will be removed in 3.0 Use View::get() instead.
|
||||
* @deprecated 3.0.0 Will be removed in 3.0. Use View::get() instead.
|
||||
*/
|
||||
public function getVar($var) {
|
||||
return $this->get($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the given View variable or a block.
|
||||
* Blocks are checked before view variables.
|
||||
* Returns the contents of the given View variable.
|
||||
*
|
||||
* @param string $var The view var you want the contents of.
|
||||
* @return mixed The content of the named var if its set, otherwise null.
|
||||
* @param mixed $default The default/fallback content of $var.
|
||||
* @return mixed The content of the named var if its set, otherwise $default.
|
||||
*/
|
||||
public function get($var) {
|
||||
public function get($var, $default = null) {
|
||||
if (!isset($this->viewVars[$var])) {
|
||||
return null;
|
||||
return $default;
|
||||
}
|
||||
return $this->viewVars[$var];
|
||||
}
|
||||
|
|
@ -629,35 +632,57 @@ class View extends Object {
|
|||
* @see ViewBlock::start()
|
||||
*/
|
||||
public function start($name) {
|
||||
return $this->Blocks->start($name);
|
||||
$this->Blocks->start($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to an existing or new block. Appending to a new
|
||||
* Start capturing output for a 'block' if it has no content
|
||||
*
|
||||
* @param string $name The name of the block to capture for.
|
||||
* @return void
|
||||
* @see ViewBlock::startIfEmpty()
|
||||
*/
|
||||
public function startIfEmpty($name) {
|
||||
$this->Blocks->startIfEmpty($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to an existing or new block. Appending to a new
|
||||
* block will create the block.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @param string $value The content for the block.
|
||||
* @param mixed $value The content for the block.
|
||||
* @return void
|
||||
* @throws CakeException when you use non-string values.
|
||||
* @see ViewBlock::append()
|
||||
* @see ViewBlock::concat()
|
||||
*/
|
||||
public function append($name, $value = null) {
|
||||
return $this->Blocks->append($name, $value);
|
||||
$this->Blocks->concat($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content for a block. This will overwrite any
|
||||
* Prepend to an existing or new block. Prepending to a new
|
||||
* block will create the block.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @param mixed $value The content for the block.
|
||||
* @return void
|
||||
* @see ViewBlock::concat()
|
||||
*/
|
||||
public function prepend($name, $value = null) {
|
||||
$this->Blocks->concat($name, $value, ViewBlock::PREPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content for a block. This will overwrite any
|
||||
* existing content.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @param string $value The content for the block.
|
||||
* @param mixed $value The content for the block.
|
||||
* @return void
|
||||
* @throws CakeException when you use non-string values.
|
||||
* @see ViewBlock::set()
|
||||
*/
|
||||
public function assign($name, $value) {
|
||||
return $this->Blocks->set($name, $value);
|
||||
$this->Blocks->set($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -665,11 +690,22 @@ class View extends Object {
|
|||
* empty or undefined '' will be returned.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @return The block content or '' if the block does not exist.
|
||||
* @param string $default Default text
|
||||
* @return string default The block content or $default if the block does not exist.
|
||||
* @see ViewBlock::get()
|
||||
*/
|
||||
public function fetch($name) {
|
||||
return $this->Blocks->get($name);
|
||||
public function fetch($name, $default = '') {
|
||||
return $this->Blocks->get($name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block exists
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($name) {
|
||||
return $this->Blocks->exists($name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -679,11 +715,11 @@ class View extends Object {
|
|||
* @see ViewBlock::end()
|
||||
*/
|
||||
public function end() {
|
||||
return $this->Blocks->end();
|
||||
$this->Blocks->end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides view or element extension/inheritance. Views can extends a
|
||||
* Provides view or element extension/inheritance. Views can extends a
|
||||
* parent view and populate blocks in the parent template.
|
||||
*
|
||||
* @param string $name The view or element to 'extend' the current one with.
|
||||
|
|
@ -692,11 +728,11 @@ class View extends Object {
|
|||
* @throws LogicException when you extend an element which doesn't exist
|
||||
*/
|
||||
public function extend($name) {
|
||||
if ($name[0] === '/' || $this->_currentType === self::TYPE_VIEW) {
|
||||
if ($name[0] === '/' || $this->_currentType === static::TYPE_VIEW) {
|
||||
$parent = $this->_getViewFileName($name);
|
||||
} else {
|
||||
switch ($this->_currentType) {
|
||||
case self::TYPE_ELEMENT:
|
||||
case static::TYPE_ELEMENT:
|
||||
$parent = $this->_getElementFileName($name);
|
||||
if (!$parent) {
|
||||
list($plugin, $name) = $this->pluginSplit($name);
|
||||
|
|
@ -709,7 +745,7 @@ class View extends Object {
|
|||
));
|
||||
}
|
||||
break;
|
||||
case self::TYPE_LAYOUT:
|
||||
case static::TYPE_LAYOUT:
|
||||
$parent = $this->_getLayoutFileName($name);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -734,7 +770,7 @@ class View extends Object {
|
|||
* update/replace a script element.
|
||||
* @param string $content The content of the script being added, optional.
|
||||
* @return void
|
||||
* @deprecated Will be removed in 3.0. Supersceeded by blocks functionality.
|
||||
* @deprecated 3.0.0 Will be removed in 3.0. Superseded by blocks functionality.
|
||||
* @see View::start()
|
||||
*/
|
||||
public function addScript($name, $content = null) {
|
||||
|
|
@ -786,12 +822,19 @@ class View extends Object {
|
|||
} else {
|
||||
$data = array($one => $two);
|
||||
}
|
||||
if ($data == null) {
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
$this->viewVars = $data + $this->viewVars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current view type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentType() {
|
||||
return $this->_currentType;
|
||||
}
|
||||
/**
|
||||
* Magic accessor for helpers. Provides access to attributes that were deprecated.
|
||||
*
|
||||
|
|
@ -823,7 +866,7 @@ class View extends Object {
|
|||
* Magic accessor for deprecated attributes.
|
||||
*
|
||||
* @param string $name Name of the attribute to set.
|
||||
* @param string $value Value of the attribute to set.
|
||||
* @param mixed $value Value of the attribute to set.
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
|
|
@ -839,7 +882,7 @@ class View extends Object {
|
|||
* Magic isset check for deprecated attributes.
|
||||
*
|
||||
* @param string $name Name of the attribute to check.
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name) {
|
||||
if (isset($this->{$name})) {
|
||||
|
|
@ -860,10 +903,9 @@ class View extends Object {
|
|||
public function loadHelpers() {
|
||||
$helpers = HelperCollection::normalizeObjectArray($this->helpers);
|
||||
foreach ($helpers as $properties) {
|
||||
list($plugin, $class) = pluginSplit($properties['class']);
|
||||
list(, $class) = pluginSplit($properties['class']);
|
||||
$this->{$class} = $this->Helpers->load($properties['class'], $properties['settings']);
|
||||
}
|
||||
$this->_helpersLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -873,6 +915,8 @@ class View extends Object {
|
|||
* @param string $viewFile Filename of the view
|
||||
* @param array $data Data to include in rendered view. If empty the current View::$viewVars will be used.
|
||||
* @return string Rendered output
|
||||
* @triggers View.beforeRenderFile $this, array($viewFile)
|
||||
* @triggers View.afterRenderFile $this, array($viewFile, $content)
|
||||
* @throws CakeException when a block is left open.
|
||||
*/
|
||||
protected function _render($viewFile, $data = array()) {
|
||||
|
|
@ -882,12 +926,16 @@ class View extends Object {
|
|||
$this->_current = $viewFile;
|
||||
$initialBlocks = count($this->Blocks->unclosed());
|
||||
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRenderFile', $this, array($viewFile)));
|
||||
$eventManager = $this->getEventManager();
|
||||
$beforeEvent = new CakeEvent('View.beforeRenderFile', $this, array($viewFile));
|
||||
|
||||
$eventManager->dispatch($beforeEvent);
|
||||
$content = $this->_evaluate($viewFile, $data);
|
||||
|
||||
$afterEvent = new CakeEvent('View.afterRenderFile', $this, array($viewFile, $content));
|
||||
|
||||
$afterEvent->modParams = 1;
|
||||
$this->getEventManager()->dispatch($afterEvent);
|
||||
$eventManager->dispatch($afterEvent);
|
||||
$content = $afterEvent->data[1];
|
||||
|
||||
if (isset($this->_parents[$viewFile])) {
|
||||
|
|
@ -910,7 +958,7 @@ class View extends Object {
|
|||
/**
|
||||
* Sandbox method to evaluate a template / view script in.
|
||||
*
|
||||
* @param string $viewFn Filename of the view
|
||||
* @param string $viewFile Filename of the view
|
||||
* @param array $dataForView Data to include in rendered view.
|
||||
* If empty the current View::$viewVars will be used.
|
||||
* @return string Rendered output
|
||||
|
|
@ -927,7 +975,7 @@ class View extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads a helper. Delegates to the `HelperCollection::load()` to load the helper
|
||||
* Loads a helper. Delegates to the `HelperCollection::load()` to load the helper
|
||||
*
|
||||
* @param string $helperName Name of the helper to load.
|
||||
* @param array $settings Settings for the helper
|
||||
|
|
@ -950,7 +998,7 @@ class View extends Object {
|
|||
protected function _getViewFileName($name = null) {
|
||||
$subDir = null;
|
||||
|
||||
if (!is_null($this->subDir)) {
|
||||
if ($this->subDir !== null) {
|
||||
$subDir = $this->subDir . DS;
|
||||
}
|
||||
|
||||
|
|
@ -964,9 +1012,6 @@ class View extends Object {
|
|||
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
||||
} elseif (strpos($name, DS) !== false) {
|
||||
if ($name[0] === DS || $name[1] === ':') {
|
||||
if (is_file($name)) {
|
||||
return $name;
|
||||
}
|
||||
$name = trim($name, DS);
|
||||
} elseif ($name[0] === '.') {
|
||||
$name = substr($name, 3);
|
||||
|
|
@ -983,18 +1028,7 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
$defaultPath = $paths[0];
|
||||
|
||||
if ($this->plugin) {
|
||||
$pluginPaths = App::path('plugins');
|
||||
foreach ($paths as $path) {
|
||||
if (strpos($path, $pluginPaths[0]) === 0) {
|
||||
$defaultPath = $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
|
||||
throw new MissingViewException(array('file' => $name . $this->ext));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1003,8 +1037,8 @@ class View extends Object {
|
|||
* It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot
|
||||
*
|
||||
* @param string $name The name you want to plugin split.
|
||||
* @param boolean $fallback If true uses the plugin set in the current CakeRequest when parsed plugin is not loaded
|
||||
* @return array Array with 2 indexes. 0 => plugin name, 1 => filename
|
||||
* @param bool $fallback If true uses the plugin set in the current CakeRequest when parsed plugin is not loaded
|
||||
* @return array Array with 2 indexes. 0 => plugin name, 1 => filename
|
||||
*/
|
||||
public function pluginSplit($name, $fallback = true) {
|
||||
$plugin = null;
|
||||
|
|
@ -1032,7 +1066,7 @@ class View extends Object {
|
|||
}
|
||||
$subDir = null;
|
||||
|
||||
if (!is_null($this->layoutPath)) {
|
||||
if ($this->layoutPath !== null) {
|
||||
$subDir = $this->layoutPath . DS;
|
||||
}
|
||||
list($plugin, $name) = $this->pluginSplit($name);
|
||||
|
|
@ -1047,7 +1081,7 @@ class View extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
throw new MissingLayoutException(array('file' => $paths[0] . $file . $this->ext));
|
||||
throw new MissingLayoutException(array('file' => $file . $this->ext));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1088,12 +1122,17 @@ class View extends Object {
|
|||
* Return all possible paths to find view files in order
|
||||
*
|
||||
* @param string $plugin Optional plugin name to scan for view files.
|
||||
* @param boolean $cached Set to true to force a refresh of view paths.
|
||||
* @param bool $cached Set to false to force a refresh of view paths. Default true.
|
||||
* @return array paths
|
||||
*/
|
||||
protected function _paths($plugin = null, $cached = true) {
|
||||
if ($plugin === null && $cached === true && !empty($this->_paths)) {
|
||||
return $this->_paths;
|
||||
if ($cached === true) {
|
||||
if ($plugin === null && !empty($this->_paths)) {
|
||||
return $this->_paths;
|
||||
}
|
||||
if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
|
||||
return $this->_pathsForPlugin[$plugin];
|
||||
}
|
||||
}
|
||||
$paths = array();
|
||||
$viewPaths = App::path('View');
|
||||
|
|
@ -1125,9 +1164,75 @@ class View extends Object {
|
|||
}
|
||||
$paths = array_merge($paths, $corePaths);
|
||||
if ($plugin !== null) {
|
||||
return $paths;
|
||||
return $this->_pathsForPlugin[$plugin] = $paths;
|
||||
}
|
||||
return $this->_paths = $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an element is cached and returns the cached data if present
|
||||
*
|
||||
* @param string $name Element name
|
||||
* @param string $data Data
|
||||
* @param array $options Element options
|
||||
* @return string|null
|
||||
*/
|
||||
protected function _elementCache($name, $data, $options) {
|
||||
$plugin = null;
|
||||
list($plugin, $name) = $this->pluginSplit($name);
|
||||
|
||||
$underscored = null;
|
||||
if ($plugin) {
|
||||
$underscored = Inflector::underscore($plugin);
|
||||
}
|
||||
$keys = array_merge(array($underscored, $name), array_keys($options), array_keys($data));
|
||||
$this->elementCacheSettings = array(
|
||||
'config' => $this->elementCache,
|
||||
'key' => implode('_', $keys)
|
||||
);
|
||||
if (is_array($options['cache'])) {
|
||||
$defaults = array(
|
||||
'config' => $this->elementCache,
|
||||
'key' => $this->elementCacheSettings['key']
|
||||
);
|
||||
$this->elementCacheSettings = array_merge($defaults, $options['cache']);
|
||||
}
|
||||
$this->elementCacheSettings['key'] = 'element_' . $this->elementCacheSettings['key'];
|
||||
return Cache::read($this->elementCacheSettings['key'], $this->elementCacheSettings['config']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an element and fires the before and afterRender callbacks for it
|
||||
* and writes to the cache if a cache is used
|
||||
*
|
||||
* @param string $file Element file path
|
||||
* @param array $data Data to render
|
||||
* @param array $options Element options
|
||||
* @return string
|
||||
* @triggers View.beforeRender $this, array($file)
|
||||
* @triggers View.afterRender $this, array($file, $element)
|
||||
*/
|
||||
protected function _renderElement($file, $data, $options) {
|
||||
$current = $this->_current;
|
||||
$restore = $this->_currentType;
|
||||
$this->_currentType = static::TYPE_ELEMENT;
|
||||
|
||||
if ($options['callbacks']) {
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($file)));
|
||||
}
|
||||
|
||||
$element = $this->_render($file, array_merge($this->viewVars, $data));
|
||||
|
||||
if ($options['callbacks']) {
|
||||
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
|
||||
}
|
||||
|
||||
$this->_currentType = $restore;
|
||||
$this->_current = $current;
|
||||
|
||||
if (isset($options['cache'])) {
|
||||
Cache::write($this->elementCacheSettings['key'], $element, $this->elementCacheSettings['config']);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* PHP 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @since CakePHP(tm) v2.1
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* ViewBlock implements the concept of Blocks or Slots in the View layer.
|
||||
* Slots or blocks are combined with extending views and layouts to afford slots
|
||||
|
|
@ -24,7 +24,21 @@
|
|||
class ViewBlock {
|
||||
|
||||
/**
|
||||
* Block content. An array of blocks indexed by name.
|
||||
* Append content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const APPEND = 'append';
|
||||
|
||||
/**
|
||||
* Prepend content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PREPEND = 'prepend';
|
||||
|
||||
/**
|
||||
* Block content. An array of blocks indexed by name.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -37,20 +51,53 @@ class ViewBlock {
|
|||
*/
|
||||
protected $_active = array();
|
||||
|
||||
/**
|
||||
* Should the currently captured content be discarded on ViewBlock::end()
|
||||
*
|
||||
* @var bool
|
||||
* @see ViewBlock::end()
|
||||
* @see ViewBlock::startIfEmpty()
|
||||
*/
|
||||
protected $_discardActiveBufferOnEnd = false;
|
||||
|
||||
/**
|
||||
* Start capturing output for a 'block'
|
||||
*
|
||||
* Blocks allow you to create slots or blocks of dynamic content in the layout.
|
||||
* view files can implement some or all of a layout's slots.
|
||||
*
|
||||
* You can end capturing blocks using View::end(). Blocks can be output
|
||||
* You can end capturing blocks using View::end(). Blocks can be output
|
||||
* using View::get();
|
||||
*
|
||||
* @param string $name The name of the block to capture for.
|
||||
* @throws CakeException When starting a block twice
|
||||
* @return void
|
||||
*/
|
||||
public function start($name) {
|
||||
if (in_array($name, $this->_active)) {
|
||||
throw new CakeException(__d('cake', "A view block with the name '%s' is already/still open.", $name));
|
||||
}
|
||||
$this->_active[] = $name;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start capturing output for a 'block' if it is empty
|
||||
*
|
||||
* Blocks allow you to create slots or blocks of dynamic content in the layout.
|
||||
* view files can implement some or all of a layout's slots.
|
||||
*
|
||||
* You can end capturing blocks using View::end(). Blocks can be output
|
||||
* using View::get();
|
||||
*
|
||||
* @param string $name The name of the block to capture for.
|
||||
* @return void
|
||||
*/
|
||||
public function start($name) {
|
||||
$this->_active[] = $name;
|
||||
public function startIfEmpty($name) {
|
||||
if (empty($this->_blocks[$name])) {
|
||||
return $this->start($name);
|
||||
}
|
||||
$this->_discardActiveBufferOnEnd = true;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
|
|
@ -61,6 +108,11 @@ class ViewBlock {
|
|||
* @see ViewBlock::start()
|
||||
*/
|
||||
public function end() {
|
||||
if ($this->_discardActiveBufferOnEnd) {
|
||||
$this->_discardActiveBufferOnEnd = false;
|
||||
ob_end_clean();
|
||||
return;
|
||||
}
|
||||
if (!empty($this->_active)) {
|
||||
$active = end($this->_active);
|
||||
$content = ob_get_clean();
|
||||
|
|
@ -73,7 +125,36 @@ class ViewBlock {
|
|||
}
|
||||
|
||||
/**
|
||||
* Append to an existing or new block. Appending to a new
|
||||
* Concat content to an existing or new block.
|
||||
* Concating to a new block will create the block.
|
||||
*
|
||||
* Calling concat() without a value will create a new capturing
|
||||
* block that needs to be finished with View::end(). The content
|
||||
* of the new capturing context will be added to the existing block context.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @param mixed $value The content for the block
|
||||
* @param string $mode If ViewBlock::APPEND content will be appended to existing content.
|
||||
* If ViewBlock::PREPEND it will be prepended.
|
||||
* @return void
|
||||
*/
|
||||
public function concat($name, $value = null, $mode = ViewBlock::APPEND) {
|
||||
if (isset($value)) {
|
||||
if (!isset($this->_blocks[$name])) {
|
||||
$this->_blocks[$name] = '';
|
||||
}
|
||||
if ($mode === ViewBlock::PREPEND) {
|
||||
$this->_blocks[$name] = $value . $this->_blocks[$name];
|
||||
} else {
|
||||
$this->_blocks[$name] .= $value;
|
||||
}
|
||||
} else {
|
||||
$this->start($name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append to an existing or new block. Appending to a new
|
||||
* block will create the block.
|
||||
*
|
||||
* Calling append() without a value will create a new capturing
|
||||
|
|
@ -83,51 +164,48 @@ class ViewBlock {
|
|||
* @param string $name Name of the block
|
||||
* @param string $value The content for the block.
|
||||
* @return void
|
||||
* @throws CakeException when you use non-string values.
|
||||
* @deprecated 3.0.0 As of 2.3 use ViewBlock::concat() instead.
|
||||
*/
|
||||
public function append($name, $value = null) {
|
||||
if (isset($value)) {
|
||||
if (!is_string($value)) {
|
||||
throw new CakeException(__d('cake_dev', '$value must be a string.'));
|
||||
}
|
||||
if (!isset($this->_blocks[$name])) {
|
||||
$this->_blocks[$name] = '';
|
||||
}
|
||||
$this->_blocks[$name] .= $value;
|
||||
} else {
|
||||
$this->start($name);
|
||||
}
|
||||
$this->concat($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the content for a block. This will overwrite any
|
||||
* Set the content for a block. This will overwrite any
|
||||
* existing content.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @param string $value The content for the block.
|
||||
* @param mixed $value The content for the block.
|
||||
* @return void
|
||||
* @throws CakeException when you use non-string values.
|
||||
*/
|
||||
public function set($name, $value) {
|
||||
if (!is_string($value)) {
|
||||
throw new CakeException(__d('cake_dev', 'Blocks can only contain strings.'));
|
||||
}
|
||||
$this->_blocks[$name] = $value;
|
||||
$this->_blocks[$name] = (string)$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content for a block.
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @return The block content or '' if the block does not exist.
|
||||
* @param string $default Default string
|
||||
* @return string The block content or $default if the block does not exist.
|
||||
*/
|
||||
public function get($name) {
|
||||
public function get($name, $default = '') {
|
||||
if (!isset($this->_blocks[$name])) {
|
||||
return '';
|
||||
return $default;
|
||||
}
|
||||
return $this->_blocks[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block exists
|
||||
*
|
||||
* @param string $name Name of the block
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($name) {
|
||||
return isset($this->_blocks[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of all the existing blocks.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('View', 'View');
|
||||
App::uses('Xml', 'Utility');
|
||||
App::uses('Hash', 'Utility');
|
||||
|
||||
/**
|
||||
* A view class that is used for creating XML responses.
|
||||
|
|
@ -31,19 +33,19 @@ App::uses('Xml', 'Utility');
|
|||
*
|
||||
* **Note** The view variable you specify must be compatible with Xml::fromArray().
|
||||
*
|
||||
* You can also define `'_serialize'` as an array. This will create an additional
|
||||
* You can also define `'_serialize'` as an array. This will create an additional
|
||||
* top level element named `<response>` containing all the named view variables:
|
||||
*
|
||||
* {{{
|
||||
* ```
|
||||
* $this->set(compact('posts', 'users', 'stuff'));
|
||||
* $this->set('_serialize', array('posts', 'users'));
|
||||
* }}}
|
||||
* ```
|
||||
*
|
||||
* The above would generate a XML object that looks like:
|
||||
*
|
||||
* `<response><posts>...</posts><users>...</users></response>`
|
||||
*
|
||||
* If you don't use the `_serialize` key, you will need a view. You can use extended
|
||||
* If you don't use the `_serialize` key, you will need a view. You can use extended
|
||||
* views to provide layout like functionality.
|
||||
*
|
||||
* @package Cake.View
|
||||
|
|
@ -52,7 +54,7 @@ App::uses('Xml', 'Utility');
|
|||
class XmlView extends View {
|
||||
|
||||
/**
|
||||
* The subdirectory. XML views are always in xml.
|
||||
* The subdirectory. XML views are always in xml.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -61,7 +63,7 @@ class XmlView extends View {
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Controller $controller
|
||||
* @param Controller $controller Controller instance.
|
||||
*/
|
||||
public function __construct(Controller $controller = null) {
|
||||
parent::__construct($controller);
|
||||
|
|
@ -71,12 +73,24 @@ class XmlView extends View {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip loading helpers if this is a _serialize based view.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadHelpers() {
|
||||
if (isset($this->viewVars['_serialize'])) {
|
||||
return;
|
||||
}
|
||||
parent::loadHelpers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a XML view.
|
||||
*
|
||||
* Uses the special '_serialize' parameter to convert a set of
|
||||
* view variables into a XML response. Makes generating simple
|
||||
* XML responses very easy. You can omit the '_serialize' parameter,
|
||||
* view variables into a XML response. Makes generating simple
|
||||
* XML responses very easy. You can omit the '_serialize' parameter,
|
||||
* and use a normal view + layout as well.
|
||||
*
|
||||
* @param string $view The view being rendered.
|
||||
|
|
@ -85,29 +99,53 @@ class XmlView extends View {
|
|||
*/
|
||||
public function render($view = null, $layout = null) {
|
||||
if (isset($this->viewVars['_serialize'])) {
|
||||
$serialize = $this->viewVars['_serialize'];
|
||||
if (is_array($serialize)) {
|
||||
$data = array('response' => array());
|
||||
foreach ($serialize as $key) {
|
||||
$data['response'][$key] = $this->viewVars[$key];
|
||||
}
|
||||
} else {
|
||||
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
||||
if (is_array($data) && Set::numeric(array_keys($data))) {
|
||||
$data = array('response' => array($serialize => $data));
|
||||
}
|
||||
}
|
||||
$content = Xml::fromArray($data)->asXML();
|
||||
return $content;
|
||||
return $this->_serialize($this->viewVars['_serialize']);
|
||||
}
|
||||
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
|
||||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
$content = $this->_render($viewFileName);
|
||||
$this->Blocks->set('content', (string)$content);
|
||||
return $content;
|
||||
if ($view !== false && $this->_getViewFileName($view)) {
|
||||
return parent::render($view, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize view vars.
|
||||
*
|
||||
* ### Special parameters
|
||||
* `_xmlOptions` You can set an array of custom options for Xml::fromArray() this way, e.g.
|
||||
* 'format' as 'attributes' instead of 'tags'.
|
||||
*
|
||||
* @param array $serialize The viewVars that need to be serialized.
|
||||
* @return string The serialized data
|
||||
*/
|
||||
protected function _serialize($serialize) {
|
||||
$rootNode = isset($this->viewVars['_rootNode']) ? $this->viewVars['_rootNode'] : 'response';
|
||||
|
||||
if (is_array($serialize)) {
|
||||
$data = array($rootNode => array());
|
||||
foreach ($serialize as $alias => $key) {
|
||||
if (is_numeric($alias)) {
|
||||
$alias = $key;
|
||||
}
|
||||
$data[$rootNode][$alias] = $this->viewVars[$key];
|
||||
}
|
||||
} else {
|
||||
$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
|
||||
if (is_array($data) && Hash::numeric(array_keys($data))) {
|
||||
$data = array($rootNode => array($serialize => $data));
|
||||
}
|
||||
}
|
||||
|
||||
$options = array();
|
||||
if (isset($this->viewVars['_xmlOptions'])) {
|
||||
$options = $this->viewVars['_xmlOptions'];
|
||||
}
|
||||
if (Configure::read('debug')) {
|
||||
$options['pretty'] = true;
|
||||
}
|
||||
|
||||
if (isset($options['return']) && strtolower($options['return']) === 'domdocument') {
|
||||
return Xml::fromArray($data, $options)->saveXML();
|
||||
}
|
||||
return Xml::fromArray($data, $options)->asXML();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue