#6504: JavascriptHelper::codeBlock, JavascriptHelper::blockEnd
--------------------------+-------------------------------------------------
Reporter: Dremora | Type: Bug
Status: new | Priority: Medium
Milestone: 1.2.x.x | Component: Helpers
Version: 1.2 Final | Severity: Normal
Keywords: | Php_version: PHP 5
Cake_version: |
--------------------------+-------------------------------------------------
JavascriptHelper::codeBlock and JavascriptHelper::blockEnd have several
bugs, for example:
* if codeBlock is called with $script = null and $options['safe'] set to
true;
* if blockEnd is called but codeBlock hasn't been called before.
For example, currently the following code produces wrong output:
{{{
<?php echo $javascript->codeBlock(); ?>
alert('It works');
<?php echo $javascript->blockEnd(); ?>
}}}
The new code for both methods:
{{{
function codeBlock($script = null, $options = array()) {
if (!empty($options) && !is_array($options)) {
$options = array('allowCache' => $options);
} elseif (empty($options)) {
$options = array();
}
$defaultOptions = array('allowCache' => true, 'safe' =>
$this->safe, 'inline' => true);
$options = array_merge($defaultOptions, $options);
$block = ($script !== null && $script !== '');
$cache = $this->_cacheEvents && $this->_cacheAll &&
$options['allowCache'];
$safe = ($options['safe'] || $this->safe);
if (!$block) {
$this->__scriptBuffer = @ob_get_contents();
$this->_blockOptions = $options;
$this->inBlock = true;
@ob_end_clean();
ob_start();
return null;
}
if ($cache) {
$this->_cachedEvents[] = $script;
return null;
}
if ($safe) {
$script = "\n" . '//<![CDATA[' . "\n" . $script .
"\n" . '//]]>' . "\n";
}
if ($options['inline']) {
return sprintf($this->tags['javascriptblock'],
$script);
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript(sprintf($this->tags['javascriptblock'], $script));
}
}
}}}
{{{
function blockEnd() {
if (!isset($this->inBlock) || !$this->inBlock) return;
$script = @ob_get_contents();
@ob_end_clean();
ob_start();
echo $this->__scriptBuffer;
$this->__scriptBuffer = null;
$options = $this->_blockOptions;
$safe = ($options['safe'] || $this->safe);
$this->_blockOptions = array();
$this->inBlock = false;
if (empty($script)) {
return null;
}
if ($this->_cacheEvents && $this->_cacheAll &&
$options['allowCache']) {
$this->_cachedEvents[] = $script;
return null;
}
if ($safe) {
$script = "\n" . '//<![CDATA[' . "\n" . $script .
"\n" . '//]]>' . "\n";
}
if ($options['inline']) {
return sprintf($this->tags['javascriptblock'],
$script);
} else {
$view =& ClassRegistry::getObject('view');
$view->addScript(sprintf($this->tags['javascriptblock'], $script));
}
}
}}}
--
Ticket URL: <https://trac.cakephp.org/ticket/6504>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---