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
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue