a grand renaming so that the most significant portion of the name comes first
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.elements.email.html
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php
|
||||
$content = explode("\n", $content);
|
||||
|
||||
foreach ($content as $line):
|
||||
echo '<p> ' . $line . '</p>';
|
||||
endforeach;
|
||||
?>
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.elements.email.text
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php echo $content; ?>
|
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* SQL Dump element. Dumps out SQL log information
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.elements
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (!class_exists('ConnectionManager') || Configure::read('debug') < 2) {
|
||||
return false;
|
||||
}
|
||||
$noLogs = !isset($logs);
|
||||
if ($noLogs):
|
||||
$sources = ConnectionManager::sourceList();
|
||||
|
||||
$logs = array();
|
||||
foreach ($sources as $source):
|
||||
$db =& ConnectionManager::getDataSource($source);
|
||||
if (!$db->isInterfaceSupported('getLog')):
|
||||
continue;
|
||||
endif;
|
||||
$logs[$source] = $db->getLog();
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ($noLogs || isset($_forced_from_dbo_)):
|
||||
foreach ($logs as $source => $logInfo):
|
||||
$text = $logInfo['count'] > 1 ? 'queries' : 'query';
|
||||
printf(
|
||||
'<table class="cake-sql-log" id="cakeSqlLog_%s" summary="Cake SQL Log" cellspacing="0" border = "0">',
|
||||
preg_replace('/[^A-Za-z0-9_]/', '_', uniqid(time(), true))
|
||||
);
|
||||
printf('<caption>(%s) %s %s took %s ms</caption>', $source, $logInfo['count'], $text, $logInfo['time']);
|
||||
?>
|
||||
<thead>
|
||||
<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($logInfo['log'] as $k => $i) :
|
||||
echo "<tr><td>" . ($k + 1) . "</td><td>" . h($i['query']) . "</td><td>{$i['error']}</td><td style = \"text-align: right\">{$i['affected']}</td><td style = \"text-align: right\">{$i['numRows']}</td><td style = \"text-align: right\">{$i['took']}</td></tr>\n";
|
||||
endforeach;
|
||||
?>
|
||||
</tbody></table>
|
||||
<?php
|
||||
endforeach;
|
||||
else:
|
||||
echo '<p>Encountered unexpected $logs cannot generate SQL log</p>';
|
||||
endif;
|
||||
?>
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo $name; ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The requested address %s was not found on this server.', true), "<strong>'{$message}'</strong>"); ?>
|
||||
</p>
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php echo $name; ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('An Internal Error Has Occurred.', true), "<strong>'{$message}'</strong>"); ?>
|
||||
</p>
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php printf(__('Missing Method in %s', true), $controller); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The action %1$s is not defined in controller %2$s', true), '<em>' . $action . '</em>', '<em>' . $controller . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create %1$s%2$s in file: %3$s.', true), '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $controller;?> extends AppController {
|
||||
|
||||
var $name = '<?php echo $controllerName;?>';
|
||||
|
||||
<strong>
|
||||
function <?php echo $action;?>() {
|
||||
|
||||
}
|
||||
</strong>
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_action.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Behavior Class'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The behavior class <em>%s</em> can not be found or does not exist.', true), $behaviorClass); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class below in file: %s', true), APP_DIR . DS . 'models' . DS . 'behaviors' . DS . $file); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $behaviorClass;?> extends ModelBehavior {
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_behavior_class.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Behavior File'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The Behavior file %s can not be found or does not exist.', true), APP_DIR . DS . 'models' . DS . 'behaviors' . DS . $file); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class below in file: %s', true), APP_DIR . DS . 'models' . DS . 'behaviors' . DS . $file); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $behaviorClass;?> extends ModelBehavior {
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_behavior_file.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Component Class'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Component class %1$s in %2$s was not found.', true), '<em>' . $component . 'Component</em>', '<em>' . $controller . 'Controller</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class %s in file: %s', true), '<em>' . $component . 'Component</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $component;?>Component extends Object {<br />
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_component_class.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Component File'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php __('The component file was not found.'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class %s in file: %s', true), '<em>' . $component . 'Component</em>', APP_DIR . DS . 'controllers' . DS . 'components' . DS . $file); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $component;?>Component extends Object {<br />
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_component_file.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Database Connection'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('%s requires a database connection', true), $model); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Confirm you have created the file : %s.', true), APP_DIR . DS . 'config' . DS . 'database.php'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s.', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . basename(__FILE__)); ?>
|
||||
</p>
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Controller'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('%s could not be found.', true), '<em>' . $controller . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class %s below in file: %s', true), '<em>' . $controller . '</em>', APP_DIR . DS . 'controllers' . DS . Inflector::underscore($controller) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $controller;?> extends AppController {
|
||||
|
||||
var $name = '<?php echo $controllerName;?>';
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_controller.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Helper Class'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The helper class <em>%s</em> can not be found or does not exist.', true), $helperClass); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class below in file: %s', true), APP_DIR . DS . 'views' . DS . 'helpers' . DS . $file); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $helperClass;?> extends AppHelper {
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_helper_class.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Helper File'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The helper file %s can not be found or does not exist.', true), APP_DIR . DS . 'views' . DS . 'helpers' . DS . $file); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class below in file: %s', true), APP_DIR . DS . 'views' . DS . 'helpers' . DS . $file); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $helperClass;?> extends AppHelper {
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_helper_file.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Layout'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The layout file %s can not be found or does not exist.', true), '<em>' . $file . '</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Confirm you have created the file: %s', true), '<em>' . $file . '</em>'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_layout.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Model'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('<em>%s</em> could not be found.', true), $model); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Create the class %s in file: %s', true), '<em>' . $model . '</em>', APP_DIR . DS . 'models' . DS . Inflector::underscore($model) . '.php'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
class <?php echo $model;?> extends AppModel {
|
||||
|
||||
var $name = '<?php echo $model;?>';
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_model.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Database Connection'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php __('Scaffold requires a database connection'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Confirm you have created the file: %s', true), APP_DIR . DS . 'config' . DS . 'database.php'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_scaffolddb.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing Database Table'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Database table %1$s for model %2$s was not found.', true), '<em>' . $table . '</em>', '<em>' . $model . '</em>'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_table.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Missing View'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('The view for %1$s%2$s was not found.', true), '<em>' . $controller . 'Controller::</em>', '<em>' . $action . '()</em>'); ?>
|
||||
</p>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('Confirm you have created the file: %s', true), $file); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'missing_view.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php printf(__('Private Method in %s', true), $controller); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php printf(__('%s%s cannot be accessed directly.', true), '<em>' . $controller . '::</em>', '<em>' . $action . '()</em>'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'private_action.ctp'); ?>
|
||||
</p>
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.errors
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<h2><?php __('Scaffold Error'); ?></h2>
|
||||
<p class="error">
|
||||
<strong><?php __('Error'); ?>: </strong>
|
||||
<?php __('Method _scaffoldError in was not found in the controller'); ?>
|
||||
</p>
|
||||
<p class="notice">
|
||||
<strong><?php __('Notice'); ?>: </strong>
|
||||
<?php printf(__('If you want to customize this error message, create %s', true), APP_DIR . DS . 'views' . DS . 'errors' . DS . 'scaffold_error.ctp'); ?>
|
||||
</p>
|
||||
<pre>
|
||||
<?php
|
||||
function _scaffoldError() {<br />
|
||||
|
||||
}
|
||||
?>
|
||||
</pre>
|
912
php-practice/web-cake/html/cake/libs/view/helper.php
Normal file
912
php-practice/web-cake/html/cake/libs/view/helper.php
Normal file
@@ -0,0 +1,912 @@
|
||||
<?php
|
||||
/**
|
||||
* Backend for helpers.
|
||||
*
|
||||
* Internal methods for the Helpers.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Included libs
|
||||
*/
|
||||
App::import('Core', 'Overloadable');
|
||||
|
||||
/**
|
||||
* Abstract base class for all other Helpers in CakePHP.
|
||||
* Provides common methods and features.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
*/
|
||||
class Helper extends Overloadable {
|
||||
|
||||
/**
|
||||
* List of helpers used by this helper
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $helpers = null;
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $base = null;
|
||||
|
||||
/**
|
||||
* Webroot path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $webroot = null;
|
||||
|
||||
/**
|
||||
* The current theme name if any.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $theme = null;
|
||||
|
||||
/**
|
||||
* URL to current action.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $here = null;
|
||||
|
||||
/**
|
||||
* Parameter array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $params = array();
|
||||
|
||||
/**
|
||||
* Current action.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $action = null;
|
||||
|
||||
/**
|
||||
* Plugin path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $plugin = null;
|
||||
|
||||
/**
|
||||
* POST data for models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $data = null;
|
||||
|
||||
/**
|
||||
* List of named arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $namedArgs = null;
|
||||
|
||||
/**
|
||||
* URL argument separator character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $argSeparator = null;
|
||||
|
||||
/**
|
||||
* Contains model validation errors of form post-backs
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $validationErrors = null;
|
||||
|
||||
/**
|
||||
* Holds tag templates.
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $tags = array();
|
||||
|
||||
/**
|
||||
* Holds the content to be cleaned.
|
||||
*
|
||||
* @access private
|
||||
* @var mixed
|
||||
*/
|
||||
var $__tainted = null;
|
||||
|
||||
/**
|
||||
* Holds the cleaned content.
|
||||
*
|
||||
* @access private
|
||||
* @var mixed
|
||||
*/
|
||||
var $__cleaned = null;
|
||||
|
||||
/**
|
||||
* Default overload methods
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
function get__($name) {}
|
||||
function set__($name, $value) {}
|
||||
function call__($method, $params) {
|
||||
trigger_error(sprintf(__('Method %1$s::%2$s does not exist', true), get_class($this), $method), E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses tag templates into $this->tags.
|
||||
*
|
||||
* @param $name file name inside app/config to load.
|
||||
* @return array merged tags from config/$name.php
|
||||
* @access public
|
||||
*/
|
||||
function loadConfig($name = 'tags') {
|
||||
if (file_exists(CONFIGS . $name .'.php')) {
|
||||
require(CONFIGS . $name .'.php');
|
||||
if (isset($tags)) {
|
||||
$this->tags = array_merge($this->tags, $tags);
|
||||
}
|
||||
}
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds URL for specified action.
|
||||
*
|
||||
* Returns a URL pointing at the provided parameters.
|
||||
*
|
||||
* @param mixed $url Either a relative string url like `/products/view/23` or
|
||||
* an array of url parameters. Using an array for urls will allow you to leverage
|
||||
* the reverse routing features of CakePHP.
|
||||
* @param boolean $full If true, the full base URL will be prepended to the result
|
||||
* @return string Full translated URL with base path.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1448/url
|
||||
*/
|
||||
function url($url = null, $full = false) {
|
||||
return h(Router::url($url, $full));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file exists when theme is used, if no file is found default location is returned
|
||||
*
|
||||
* @param string $file The file to create a webroot path to.
|
||||
* @return string Web accessible path to file.
|
||||
* @access public
|
||||
*/
|
||||
function webroot($file) {
|
||||
$asset = explode('?', $file);
|
||||
$asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
|
||||
$webPath = "{$this->webroot}" . $asset[0];
|
||||
$file = $asset[0];
|
||||
|
||||
if (!empty($this->theme)) {
|
||||
$file = trim($file, '/');
|
||||
$theme = $this->theme . '/';
|
||||
|
||||
if (DS === '\\') {
|
||||
$file = str_replace('/', '\\', $file);
|
||||
}
|
||||
|
||||
if (file_exists(Configure::read('App.www_root') . 'theme' . DS . $this->theme . DS . $file)) {
|
||||
$webPath = "{$this->webroot}theme/" . $theme . $asset[0];
|
||||
} else {
|
||||
$viewPaths = App::path('views');
|
||||
|
||||
foreach ($viewPaths as $viewPath) {
|
||||
$path = $viewPath . 'themed'. DS . $this->theme . DS . 'webroot' . DS . $file;
|
||||
|
||||
if (file_exists($path)) {
|
||||
$webPath = "{$this->webroot}theme/" . $theme . $asset[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strpos($webPath, '//') !== false) {
|
||||
return str_replace('//', '/', $webPath . $asset[1]);
|
||||
}
|
||||
return $webPath . $asset[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a timestamp to a file based resource based on the value of `Asset.timestamp` in
|
||||
* Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp == 'force'
|
||||
* a timestamp will be added.
|
||||
*
|
||||
* @param string $path The file path to timestamp, the path must be inside WWW_ROOT
|
||||
* @return string Path with a timestamp added, or not.
|
||||
* @access public
|
||||
*/
|
||||
function assetTimestamp($path) {
|
||||
$timestampEnabled = (
|
||||
(Configure::read('Asset.timestamp') === true && Configure::read() > 0) ||
|
||||
Configure::read('Asset.timestamp') === 'force'
|
||||
);
|
||||
if (strpos($path, '?') === false && $timestampEnabled) {
|
||||
$filepath = preg_replace('/^' . preg_quote($this->webroot, '/') . '/', '', $path);
|
||||
$webrootPath = WWW_ROOT . str_replace('/', DS, $filepath);
|
||||
if (file_exists($webrootPath)) {
|
||||
return $path . '?' . @filemtime($webrootPath);
|
||||
}
|
||||
$segments = explode('/', ltrim($filepath, '/'));
|
||||
if ($segments[0] === 'theme') {
|
||||
$theme = $segments[1];
|
||||
unset($segments[0], $segments[1]);
|
||||
$themePath = App::themePath($theme) . 'webroot' . DS . implode(DS, $segments);
|
||||
return $path . '?' . @filemtime($themePath);
|
||||
} else {
|
||||
$plugin = $segments[0];
|
||||
unset($segments[0]);
|
||||
$pluginPath = App::pluginPath($plugin) . 'webroot' . DS . implode(DS, $segments);
|
||||
return $path . '?' . @filemtime($pluginPath);
|
||||
}
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to remove harmful tags from content. Removes a number of well known XSS attacks
|
||||
* from content. However, is not guaranteed to remove all possiblities. Escaping
|
||||
* content is the best way to prevent all possible attacks.
|
||||
*
|
||||
* @param mixed $output Either an array of strings to clean or a single string to clean.
|
||||
* @return cleaned content for output
|
||||
* @access public
|
||||
*/
|
||||
function clean($output) {
|
||||
$this->__reset();
|
||||
if (empty($output)) {
|
||||
return null;
|
||||
}
|
||||
if (is_array($output)) {
|
||||
foreach ($output as $key => $value) {
|
||||
$return[$key] = $this->clean($value);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
$this->__tainted = $output;
|
||||
$this->__clean();
|
||||
return $this->__cleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a space-delimited string with items of the $options array. If a
|
||||
* key of $options array happens to be one of:
|
||||
*
|
||||
* - 'compact'
|
||||
* - 'checked'
|
||||
* - 'declare'
|
||||
* - 'readonly'
|
||||
* - 'disabled'
|
||||
* - 'selected'
|
||||
* - 'defer'
|
||||
* - 'ismap'
|
||||
* - 'nohref'
|
||||
* - 'noshade'
|
||||
* - 'nowrap'
|
||||
* - 'multiple'
|
||||
* - 'noresize'
|
||||
*
|
||||
* And its value is one of:
|
||||
*
|
||||
* - '1' (string)
|
||||
* - 1 (integer)
|
||||
* - true (boolean)
|
||||
* - 'true' (string)
|
||||
*
|
||||
* Then the value will be reset to be identical with key's name.
|
||||
* If the value is not one of these 3, the parameter is not output.
|
||||
*
|
||||
* 'escape' is a special option in that it controls the conversion of
|
||||
* attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.
|
||||
*
|
||||
* If value for any option key is set to `null` or `false`, that option will be excluded from output.
|
||||
*
|
||||
* @param array $options Array of options.
|
||||
* @param array $exclude Array of options to be excluded, the options here will not be part of the return.
|
||||
* @param string $insertBefore String to be inserted before options.
|
||||
* @param string $insertAfter String to be inserted after options.
|
||||
* @return string Composed attributes.
|
||||
* @access public
|
||||
*/
|
||||
function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $insertAfter = null) {
|
||||
if (is_array($options)) {
|
||||
$options = array_merge(array('escape' => true), $options);
|
||||
|
||||
if (!is_array($exclude)) {
|
||||
$exclude = array();
|
||||
}
|
||||
$keys = array_diff(array_keys($options), array_merge($exclude, array('escape')));
|
||||
$values = array_intersect_key(array_values($options), $keys);
|
||||
$escape = $options['escape'];
|
||||
$attributes = array();
|
||||
|
||||
foreach ($keys as $index => $key) {
|
||||
if ($values[$index] !== false && $values[$index] !== null) {
|
||||
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
|
||||
}
|
||||
}
|
||||
$out = implode(' ', $attributes);
|
||||
} else {
|
||||
$out = $options;
|
||||
}
|
||||
return $out ? $insertBefore . $out . $insertAfter : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an individual attribute, and returns the string value of the composed attribute.
|
||||
* Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
|
||||
*
|
||||
* @param string $key The name of the attribute to create
|
||||
* @param string $value The value of the attribute to create.
|
||||
* @return string The composed attribute.
|
||||
* @access private
|
||||
*/
|
||||
function __formatAttribute($key, $value, $escape = true) {
|
||||
$attribute = '';
|
||||
$attributeFormat = '%s="%s"';
|
||||
$minimizedAttributes = array('compact', 'checked', 'declare', 'readonly', 'disabled',
|
||||
'selected', 'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize');
|
||||
if (is_array($value)) {
|
||||
$value = '';
|
||||
}
|
||||
|
||||
if (in_array($key, $minimizedAttributes)) {
|
||||
if ($value === 1 || $value === true || $value === 'true' || $value === '1' || $value == $key) {
|
||||
$attribute = sprintf($attributeFormat, $key, $key);
|
||||
}
|
||||
} else {
|
||||
$attribute = sprintf($attributeFormat, $key, ($escape ? h($value) : $value));
|
||||
}
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this helper's model and field properties to the dot-separated value-pair in $entity.
|
||||
*
|
||||
* @param mixed $entity A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName"
|
||||
* @param boolean $setScope Sets the view scope to the model specified in $tagValue
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function setEntity($entity, $setScope = false) {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
|
||||
if ($setScope) {
|
||||
$view->modelScope = false;
|
||||
} elseif (!empty($view->entityPath) && $view->entityPath == $entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($entity === null) {
|
||||
$view->model = null;
|
||||
$view->association = null;
|
||||
$view->modelId = null;
|
||||
$view->modelScope = false;
|
||||
$view->entityPath = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$view->entityPath = $entity;
|
||||
$model = $view->model;
|
||||
$sameScope = $hasField = false;
|
||||
$parts = array_values(Set::filter(explode('.', $entity), true));
|
||||
|
||||
if (empty($parts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = count($parts);
|
||||
if ($count === 1) {
|
||||
$sameScope = true;
|
||||
} else {
|
||||
if (is_numeric($parts[0])) {
|
||||
$sameScope = true;
|
||||
}
|
||||
$reverse = array_reverse($parts);
|
||||
$field = array_shift($reverse);
|
||||
while(!empty($reverse)) {
|
||||
$subject = array_shift($reverse);
|
||||
if (is_numeric($subject)) {
|
||||
continue;
|
||||
}
|
||||
if (ClassRegistry::isKeySet($subject)) {
|
||||
$model = $subject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ClassRegistry::isKeySet($model)) {
|
||||
$ModelObj =& ClassRegistry::getObject($model);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (
|
||||
is_a($ModelObj, 'Model') &&
|
||||
($ModelObj->hasField($parts[$i]) ||
|
||||
array_key_exists($parts[$i], $ModelObj->validate))
|
||||
) {
|
||||
$hasField = $i;
|
||||
if ($hasField === 0 || ($hasField === 1 && is_numeric($parts[0]))) {
|
||||
$sameScope = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($sameScope === true && in_array($parts[0], array_keys($ModelObj->hasAndBelongsToMany))) {
|
||||
$sameScope = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$view->association && $parts[0] == $view->field && $view->field != $view->model) {
|
||||
array_unshift($parts, $model);
|
||||
$hasField = true;
|
||||
}
|
||||
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null;
|
||||
|
||||
switch (count($parts)) {
|
||||
case 1:
|
||||
if ($view->modelScope === false) {
|
||||
$view->model = $parts[0];
|
||||
} else {
|
||||
$view->field = $parts[0];
|
||||
if ($sameScope === false) {
|
||||
$view->association = $parts[0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if ($view->modelScope === false) {
|
||||
list($view->model, $view->field) = $parts;
|
||||
} elseif ($sameScope === true && $hasField === 0) {
|
||||
list($view->field, $view->fieldSuffix) = $parts;
|
||||
} elseif ($sameScope === true && $hasField === 1) {
|
||||
list($view->modelId, $view->field) = $parts;
|
||||
} else {
|
||||
list($view->association, $view->field) = $parts;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if ($sameScope === true && $hasField === 1) {
|
||||
list($view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
||||
} elseif ($hasField === 2) {
|
||||
list($view->association, $view->modelId, $view->field) = $parts;
|
||||
} else {
|
||||
list($view->association, $view->field, $view->fieldSuffix) = $parts;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if ($parts[0] === $view->model) {
|
||||
list($view->model, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
||||
} else {
|
||||
list($view->association, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$reverse = array_reverse($parts);
|
||||
|
||||
if ($hasField) {
|
||||
$view->field = $field;
|
||||
if (!is_numeric($reverse[1]) && $reverse[1] != $model) {
|
||||
$view->field = $reverse[1];
|
||||
$view->fieldSuffix = $field;
|
||||
}
|
||||
}
|
||||
if (is_numeric($parts[0])) {
|
||||
$view->modelId = $parts[0];
|
||||
} elseif ($view->model == $parts[0] && is_numeric($parts[1])) {
|
||||
$view->modelId = $parts[1];
|
||||
}
|
||||
$view->association = $model;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($view->model) || empty($view->model)) {
|
||||
$view->model = $view->association;
|
||||
$view->association = null;
|
||||
} elseif ($view->model === $view->association) {
|
||||
$view->association = null;
|
||||
}
|
||||
|
||||
if ($setScope) {
|
||||
$view->modelScope = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently-used model of the rendering context.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function model() {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
if (!empty($view->association)) {
|
||||
return $view->association;
|
||||
} else {
|
||||
return $view->model;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the currently-used model of the rendering context.
|
||||
*
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function modelID() {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
return $view->modelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently-used model field of the rendering context.
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function field() {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
return $view->field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if given FORM field has no errors. Otherwise it returns the constant set in
|
||||
* the array Model->validationErrors.
|
||||
*
|
||||
* @param string $model Model name as a string
|
||||
* @param string $field Fieldname as a string
|
||||
* @param integer $modelID Unique index identifying this record within the form
|
||||
* @return boolean True on errors.
|
||||
*/
|
||||
function tagIsInvalid($model = null, $field = null, $modelID = null) {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$errors = $this->validationErrors;
|
||||
$entity = $view->entity();
|
||||
if (!empty($entity)) {
|
||||
return Set::extract($errors, join('.', $entity));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a DOM ID for the selected element, if one is not set.
|
||||
* Uses the current View::entity() settings to generate a CamelCased id attribute.
|
||||
*
|
||||
* @param mixed $options Either an array of html attributes to add $id into, or a string
|
||||
* with a view entity path to get a domId for.
|
||||
* @param string $id The name of the 'id' attribute.
|
||||
* @return mixed If $options was an array, an array will be returned with $id set. If a string
|
||||
* was supplied, a string will be returned.
|
||||
* @todo Refactor this method to not have as many input/output options.
|
||||
*/
|
||||
function domId($options = null, $id = 'id') {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
|
||||
if (is_array($options) && array_key_exists($id, $options) && $options[$id] === null) {
|
||||
unset($options[$id]);
|
||||
return $options;
|
||||
} elseif (!is_array($options) && $options !== null) {
|
||||
$this->setEntity($options);
|
||||
return $this->domId();
|
||||
}
|
||||
|
||||
$entity = $view->entity();
|
||||
$model = array_shift($entity);
|
||||
$dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity));
|
||||
|
||||
if (is_array($options) && !array_key_exists($id, $options)) {
|
||||
$options[$id] = $dom;
|
||||
} elseif ($options === null) {
|
||||
return $dom;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the input field name for the current tag. Creates input name attributes
|
||||
* using CakePHP's data[Model][field] formatting.
|
||||
*
|
||||
* @param mixed $options If an array, should be an array of attributes that $key needs to be added to.
|
||||
* If a string or null, will be used as the View entity.
|
||||
* @param string $field
|
||||
* @param string $key The name of the attribute to be set, defaults to 'name'
|
||||
* @return mixed If an array was given for $options, an array with $key set will be returned.
|
||||
* If a string was supplied a string will be returned.
|
||||
* @access protected
|
||||
* @todo Refactor this method to not have as many input/output options.
|
||||
*/
|
||||
function _name($options = array(), $field = null, $key = 'name') {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
if ($options === null) {
|
||||
$options = array();
|
||||
} elseif (is_string($options)) {
|
||||
$field = $options;
|
||||
$options = 0;
|
||||
}
|
||||
|
||||
if (!empty($field)) {
|
||||
$this->setEntity($field);
|
||||
}
|
||||
|
||||
if (is_array($options) && array_key_exists($key, $options)) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
switch ($field) {
|
||||
case '_method':
|
||||
$name = $field;
|
||||
break;
|
||||
default:
|
||||
$name = 'data[' . implode('][', $view->entity()) . ']';
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
$options[$key] = $name;
|
||||
return $options;
|
||||
} else {
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data for the current tag
|
||||
*
|
||||
* @param mixed $options If an array, should be an array of attributes that $key needs to be added to.
|
||||
* If a string or null, will be used as the View entity.
|
||||
* @param string $field
|
||||
* @param string $key The name of the attribute to be set, defaults to 'value'
|
||||
* @return mixed If an array was given for $options, an array with $key set will be returned.
|
||||
* If a string was supplied a string will be returned.
|
||||
* @access public
|
||||
* @todo Refactor this method to not have as many input/output options.
|
||||
*/
|
||||
function value($options = array(), $field = null, $key = 'value') {
|
||||
if ($options === null) {
|
||||
$options = array();
|
||||
} elseif (is_string($options)) {
|
||||
$field = $options;
|
||||
$options = 0;
|
||||
}
|
||||
|
||||
if (is_array($options) && isset($options[$key])) {
|
||||
return $options;
|
||||
}
|
||||
|
||||
if (!empty($field)) {
|
||||
$this->setEntity($field);
|
||||
}
|
||||
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$result = null;
|
||||
|
||||
$entity = $view->entity();
|
||||
if (!empty($this->data) && !empty($entity)) {
|
||||
$result = Set::extract($this->data, join('.', $entity));
|
||||
}
|
||||
|
||||
$habtmKey = $this->field();
|
||||
if (empty($result) && isset($this->data[$habtmKey][$habtmKey])) {
|
||||
$result = $this->data[$habtmKey][$habtmKey];
|
||||
} elseif (empty($result) && isset($this->data[$habtmKey]) && is_array($this->data[$habtmKey])) {
|
||||
if (ClassRegistry::isKeySet($habtmKey)) {
|
||||
$model =& ClassRegistry::getObject($habtmKey);
|
||||
$result = $this->__selectedArray($this->data[$habtmKey], $model->primaryKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($result)) {
|
||||
if (array_key_exists($view->fieldSuffix, $result)) {
|
||||
$result = $result[$view->fieldSuffix];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
if ($result === null && isset($options['default'])) {
|
||||
$result = $options['default'];
|
||||
}
|
||||
unset($options['default']);
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
$options[$key] = $result;
|
||||
return $options;
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the defaults for an input tag. Will set the
|
||||
* name, value, and id attributes for an array of html attributes. Will also
|
||||
* add a 'form-error' class if the field contains validation errors.
|
||||
*
|
||||
* @param string $field The field name to initialize.
|
||||
* @param array $options Array of options to use while initializing an input field.
|
||||
* @return array Array options for the form input.
|
||||
* @access protected
|
||||
*/
|
||||
function _initInputField($field, $options = array()) {
|
||||
if ($field !== null) {
|
||||
$this->setEntity($field);
|
||||
}
|
||||
$options = (array)$options;
|
||||
$options = $this->_name($options);
|
||||
$options = $this->value($options);
|
||||
$options = $this->domId($options);
|
||||
if ($this->tagIsInvalid()) {
|
||||
$options = $this->addClass($options, 'form-error');
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given class to the element options
|
||||
*
|
||||
* @param array $options Array options/attributes to add a class to
|
||||
* @param string $class The classname being added.
|
||||
* @param string $key the key to use for class.
|
||||
* @return array Array of options with $key set.
|
||||
* @access public
|
||||
*/
|
||||
function addClass($options = array(), $class = null, $key = 'class') {
|
||||
if (isset($options[$key]) && trim($options[$key]) != '') {
|
||||
$options[$key] .= ' ' . $class;
|
||||
} else {
|
||||
$options[$key] = $class;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string generated by a helper method
|
||||
*
|
||||
* This method can be overridden in subclasses to do generalized output post-processing
|
||||
*
|
||||
* @param string $str String to be output.
|
||||
* @return string
|
||||
* @deprecated This method will be removed in future versions.
|
||||
*/
|
||||
function output($str) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Before render callback. beforeRender is called before the view file is rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function beforeRender() {
|
||||
}
|
||||
|
||||
/**
|
||||
* After render callback. afterRender is called after the view file is rendered
|
||||
* but before the layout has been rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function afterRender() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Before layout callback. beforeLayout is called before the layout is rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function beforeLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* After layout callback. afterLayout is called after the layout has rendered.
|
||||
*
|
||||
* Overridden in subclasses.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function afterLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a recordset from a hasAndBelongsToMany association to a list of selected
|
||||
* options for a multiple select element
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param string $key
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
function __selectedArray($data, $key = 'id') {
|
||||
if (!is_array($data)) {
|
||||
$model = $data;
|
||||
if (!empty($this->data[$model][$model])) {
|
||||
return $this->data[$model][$model];
|
||||
}
|
||||
if (!empty($this->data[$model])) {
|
||||
$data = $this->data[$model];
|
||||
}
|
||||
}
|
||||
$array = array();
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $var) {
|
||||
$array[$var[$key]] = $var[$key];
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the vars used by Helper::clean() to null
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __reset() {
|
||||
$this->__tainted = null;
|
||||
$this->__cleaned = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes harmful content from output
|
||||
*
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __clean() {
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$this->__cleaned = stripslashes($this->__tainted);
|
||||
} else {
|
||||
$this->__cleaned = $this->__tainted;
|
||||
}
|
||||
|
||||
$this->__cleaned = str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u', "$1;", $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#(&\#x*)([0-9A-F]+);*#iu', "$1$2;", $this->__cleaned);
|
||||
$this->__cleaned = html_entity_decode($this->__cleaned, ENT_COMPAT, "UTF-8");
|
||||
$this->__cleaned = preg_replace('#(<[^>]+[\x00-\x20\"\'\/])(on|xmlns)[^>]*>#iUu', "$1>", $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*)[\\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2nojavascript...', $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=([\'\"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2novbscript...', $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=*([\'\"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#iUu','$1=$2nomozbinding...', $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#([a-z]*)[\x00-\x20]*=([\'\"]*)[\x00-\x20]*data[\x00-\x20]*:#Uu', '$1=$2nodata...', $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*expression[\x00-\x20]*\([^>]*>#iU', "$1>", $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*behaviour[\x00-\x20]*\([^>]*>#iU', "$1>", $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#(<[^>]+)style[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*).*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*>#iUu', "$1>", $this->__cleaned);
|
||||
$this->__cleaned = preg_replace('#</*\w+:\w[^>]*>#i', "", $this->__cleaned);
|
||||
do {
|
||||
$oldstring = $this->__cleaned;
|
||||
$this->__cleaned = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $this->__cleaned);
|
||||
} while ($oldstring != $this->__cleaned);
|
||||
$this->__cleaned = str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $this->__cleaned);
|
||||
}
|
||||
}
|
1036
php-practice/web-cake/html/cake/libs/view/helpers/ajax.php
Normal file
1036
php-practice/web-cake/html/cake/libs/view/helpers/ajax.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Application level View Helper
|
||||
*
|
||||
* This file is application-wide helper file. You can put all
|
||||
* application-wide helper-related methods here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
* @since CakePHP(tm) v 0.2.9
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('View', 'Helper', false);
|
||||
|
||||
/**
|
||||
* This is a placeholder class.
|
||||
* Create the same file in app/app_helper.php
|
||||
*
|
||||
* Add your application-wide methods in the class below, your helpers
|
||||
* will inherit them.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
*/
|
||||
class AppHelper extends Helper {
|
||||
}
|
261
php-practice/web-cake/html/cake/libs/view/helpers/cache.php
Normal file
261
php-practice/web-cake/html/cake/libs/view/helpers/cache.php
Normal file
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
/**
|
||||
* CacheHelper helps create full page view caching.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.0.0.2277
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* CacheHelper helps create full page view caching.
|
||||
*
|
||||
* 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
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1376/Cache
|
||||
*/
|
||||
class CacheHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Array of strings replaced in cached views.
|
||||
* The strings are found between <cake:nocache><cake:nocache> in views
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__replace = array();
|
||||
|
||||
/**
|
||||
* Array of string that are replace with there var replace above.
|
||||
* The strings are any content inside <cake:nocache><cake:nocache> and includes the tags in views
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__match = array();
|
||||
|
||||
/**
|
||||
* cache action time
|
||||
*
|
||||
* @var object
|
||||
* @access public
|
||||
*/
|
||||
var $cacheAction;
|
||||
|
||||
/**
|
||||
* Main method used to cache a view
|
||||
*
|
||||
* @param string $file File to cache
|
||||
* @param string $out output to cache
|
||||
* @param boolean $cache Whether or not a cache file should be written.
|
||||
* @return string view ouput
|
||||
*/
|
||||
function cache($file, $out, $cache = false) {
|
||||
$cacheTime = 0;
|
||||
$useCallbacks = false;
|
||||
if (is_array($this->cacheAction)) {
|
||||
$keys = array_keys($this->cacheAction);
|
||||
$index = null;
|
||||
|
||||
foreach ($keys as $action) {
|
||||
if ($action == $this->params['action']) {
|
||||
$index = $action;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($index) && $this->action == 'index') {
|
||||
$index = 'index';
|
||||
}
|
||||
|
||||
$options = $this->cacheAction;
|
||||
if (isset($this->cacheAction[$index])) {
|
||||
if (is_array($this->cacheAction[$index])) {
|
||||
$options = array_merge(array('duration' => 0, 'callbacks' => false), $this->cacheAction[$index]);
|
||||
} else {
|
||||
$cacheTime = $this->cacheAction[$index];
|
||||
}
|
||||
}
|
||||
if (isset($options['duration'])) {
|
||||
$cacheTime = $options['duration'];
|
||||
}
|
||||
if (isset($options['callbacks'])) {
|
||||
$useCallbacks = $options['callbacks'];
|
||||
}
|
||||
} else {
|
||||
$cacheTime = $this->cacheAction;
|
||||
}
|
||||
|
||||
if ($cacheTime != '' && $cacheTime > 0) {
|
||||
$this->__parseFile($file, $out);
|
||||
if ($cache === true) {
|
||||
$cached = $this->__parseOutput($out);
|
||||
$this->__writeFile($cached, $cacheTime, $useCallbacks);
|
||||
}
|
||||
return $out;
|
||||
} else {
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse file searching for no cache tags
|
||||
*
|
||||
* @param string $file The filename that needs to be parsed.
|
||||
* @param string $cache The cached content
|
||||
* @access private
|
||||
*/
|
||||
function __parseFile($file, $cache) {
|
||||
if (is_file($file)) {
|
||||
$file = file_get_contents($file);
|
||||
} elseif ($file = fileExistsInPath($file)) {
|
||||
$file = file_get_contents($file);
|
||||
}
|
||||
preg_match_all('/(<cake:nocache>(?<=<cake:nocache>)[\\s\\S]*?(?=<\/cake:nocache>)<\/cake:nocache>)/i', $cache, $outputResult, PREG_PATTERN_ORDER);
|
||||
preg_match_all('/(?<=<cake:nocache>)([\\s\\S]*?)(?=<\/cake:nocache>)/i', $file, $fileResult, PREG_PATTERN_ORDER);
|
||||
$fileResult = $fileResult[0];
|
||||
$outputResult = $outputResult[0];
|
||||
|
||||
if (!empty($this->__replace)) {
|
||||
foreach ($outputResult as $i => $element) {
|
||||
$index = array_search($element, $this->__match);
|
||||
if ($index !== false) {
|
||||
unset($outputResult[$i]);
|
||||
}
|
||||
}
|
||||
$outputResult = array_values($outputResult);
|
||||
}
|
||||
|
||||
if (!empty($fileResult)) {
|
||||
$i = 0;
|
||||
foreach ($fileResult as $cacheBlock) {
|
||||
if (isset($outputResult[$i])) {
|
||||
$this->__replace[] = $cacheBlock;
|
||||
$this->__match[] = $outputResult[$i];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the output and replace cache tags
|
||||
*
|
||||
* @param string $cache Output to replace content in.
|
||||
* @return string with all replacements made to <cake:nocache><cake:nocache>
|
||||
* @access private
|
||||
*/
|
||||
function __parseOutput($cache) {
|
||||
$count = 0;
|
||||
if (!empty($this->__match)) {
|
||||
foreach ($this->__match as $found) {
|
||||
$original = $cache;
|
||||
$length = strlen($found);
|
||||
$position = 0;
|
||||
|
||||
for ($i = 1; $i <= 1; $i++) {
|
||||
$position = strpos($cache, $found, $position);
|
||||
|
||||
if ($position !== false) {
|
||||
$cache = substr($original, 0, $position);
|
||||
$cache .= $this->__replace[$count];
|
||||
$cache .= substr($original, $position + $length);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a cached version of the file
|
||||
*
|
||||
* @param string $content view content to write to a cache file.
|
||||
* @param sting $timestamp Duration to set for cache file.
|
||||
* @return boolean success of caching view.
|
||||
* @access private
|
||||
*/
|
||||
function __writeFile($content, $timestamp, $useCallbacks = false) {
|
||||
$now = time();
|
||||
|
||||
if (is_numeric($timestamp)) {
|
||||
$cacheTime = $now + $timestamp;
|
||||
} else {
|
||||
$cacheTime = strtotime($timestamp, $now);
|
||||
}
|
||||
$path = $this->here;
|
||||
if ($this->here == '/') {
|
||||
$path = 'home';
|
||||
}
|
||||
$cache = strtolower(Inflector::slug($path));
|
||||
|
||||
if (empty($cache)) {
|
||||
return;
|
||||
}
|
||||
$cache = $cache . '.php';
|
||||
$file = '<!--cachetime:' . $cacheTime . '--><?php';
|
||||
|
||||
if (empty($this->plugin)) {
|
||||
$file .= '
|
||||
App::import(\'Controller\', \'' . $this->controllerName. '\');
|
||||
';
|
||||
} else {
|
||||
$file .= '
|
||||
App::import(\'Controller\', \'' . $this->plugin . '.' . $this->controllerName. '\');
|
||||
';
|
||||
}
|
||||
|
||||
$file .= '$controller =& new ' . $this->controllerName . 'Controller();
|
||||
$controller->plugin = $this->plugin = \''.$this->plugin.'\';
|
||||
$controller->helpers = $this->helpers = unserialize(\'' . serialize($this->helpers) . '\');
|
||||
$controller->base = $this->base = \'' . $this->base . '\';
|
||||
$controller->layout = $this->layout = \'' . $this->layout. '\';
|
||||
$controller->webroot = $this->webroot = \'' . $this->webroot . '\';
|
||||
$controller->here = $this->here = \'' . $this->here . '\';
|
||||
$controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\'));
|
||||
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
|
||||
$controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\'));
|
||||
$controller->theme = $this->theme = \'' . $this->theme . '\';
|
||||
Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));';
|
||||
|
||||
if ($useCallbacks == true) {
|
||||
$file .= '
|
||||
$controller->constructClasses();
|
||||
$controller->Component->initialize($controller);
|
||||
$controller->beforeFilter();
|
||||
$controller->Component->startup($controller);';
|
||||
}
|
||||
|
||||
$file .= '
|
||||
$loadedHelpers = array();
|
||||
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
|
||||
foreach (array_keys($loadedHelpers) as $helper) {
|
||||
$camelBackedHelper = Inflector::variable($helper);
|
||||
${$camelBackedHelper} =& $loadedHelpers[$helper];
|
||||
$this->loaded[$camelBackedHelper] =& ${$camelBackedHelper};
|
||||
$this->{$helper} =& $loadedHelpers[$helper];
|
||||
}
|
||||
?>';
|
||||
$content = preg_replace("/(<\\?xml)/", "<?php echo '$1';?>",$content);
|
||||
$file .= $content;
|
||||
return cache('views' . DS . $cache, $file, $timestamp);
|
||||
}
|
||||
}
|
2197
php-practice/web-cake/html/cake/libs/view/helpers/form.php
Normal file
2197
php-practice/web-cake/html/cake/libs/view/helpers/form.php
Normal file
File diff suppressed because it is too large
Load Diff
835
php-practice/web-cake/html/cake/libs/view/helpers/html.php
Normal file
835
php-practice/web-cake/html/cake/libs/view/helpers/html.php
Normal file
@@ -0,0 +1,835 @@
|
||||
<?php
|
||||
/**
|
||||
* Html Helper class file.
|
||||
*
|
||||
* Simplifies the construction of HTML elements.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 0.9.1
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
/**
|
||||
* Html Helper class for easy use of HTML widgets.
|
||||
*
|
||||
* HtmlHelper encloses all methods needed while working with HTML pages.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1434/HTML
|
||||
*/
|
||||
class HtmlHelper extends AppHelper {
|
||||
/**
|
||||
* html tags used by this helper.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tags = array(
|
||||
'meta' => '<meta%s/>',
|
||||
'metalink' => '<link href="%s"%s/>',
|
||||
'link' => '<a href="%s"%s>%s</a>',
|
||||
'mailto' => '<a href="mailto:%s" %s>%s</a>',
|
||||
'form' => '<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/>',
|
||||
'checkboxmultiple' => '<input type="checkbox" name="%s[]"%s />',
|
||||
'radio' => '<input type="radio" name="%s" id="%s" %s />%s',
|
||||
'selectstart' => '<select name="%s"%s>',
|
||||
'selectmultiplestart' => '<select name="%s[]"%s>',
|
||||
'selectempty' => '<option value=""%s> </option>',
|
||||
'selectoption' => '<option value="%s"%s>%s</option>',
|
||||
'selectend' => '</select>',
|
||||
'optiongroup' => '<optgroup label="%s"%s>',
|
||||
'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/>',
|
||||
'button' => '<button type="%s"%s>%s</button>',
|
||||
'image' => '<img src="%s" %s/>',
|
||||
'tableheader' => '<th%s>%s</th>',
|
||||
'tableheaderrow' => '<tr%s>%s</tr>',
|
||||
'tablecell' => '<td%s>%s</td>',
|
||||
'tablerow' => '<tr%s>%s</tr>',
|
||||
'block' => '<div%s>%s</div>',
|
||||
'blockstart' => '<div%s>',
|
||||
'blockend' => '</div>',
|
||||
'tag' => '<%s%s>%s</%s>',
|
||||
'tagstart' => '<%s%s>',
|
||||
'tagend' => '</%s>',
|
||||
'para' => '<p%s>%s</p>',
|
||||
'parastart' => '<p%s>',
|
||||
'label' => '<label for="%s"%s>%s</label>',
|
||||
'fieldset' => '<fieldset%s>%s</fieldset>',
|
||||
'fieldsetstart' => '<fieldset><legend>%s</legend>',
|
||||
'fieldsetend' => '</fieldset>',
|
||||
'legend' => '<legend>%s</legend>',
|
||||
'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">',
|
||||
'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
|
||||
'javascriptend' => '</script>'
|
||||
);
|
||||
|
||||
/**
|
||||
* Breadcrumbs.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_crumbs = array();
|
||||
|
||||
/**
|
||||
* Names of script files that have been included once
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__includedScripts = array();
|
||||
/**
|
||||
* Options for the currently opened script block buffer if any.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_scriptBlockOptions = array();
|
||||
/**
|
||||
* Document type definitions
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__docTypes = array(
|
||||
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
|
||||
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
|
||||
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
|
||||
'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
|
||||
'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
|
||||
'xhtml-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
|
||||
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
|
||||
);
|
||||
|
||||
/**
|
||||
* Adds a link to the breadcrumbs array.
|
||||
*
|
||||
* @param string $name Text for link
|
||||
* @param string $link URL for link (if empty it won't be a link)
|
||||
* @param mixed $options Link attributes e.g. array('id'=>'selected')
|
||||
* @return void
|
||||
* @see HtmlHelper::link() for details on $options that can be used.
|
||||
* @access public
|
||||
*/
|
||||
function addCrumb($name, $link = null, $options = null) {
|
||||
$this->_crumbs[] = array($name, $link, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a doctype string.
|
||||
*
|
||||
* Possible doctypes:
|
||||
*
|
||||
* - html4-strict: HTML4 Strict.
|
||||
* - html4-trans: HTML4 Transitional.
|
||||
* - html4-frame: HTML4 Frameset.
|
||||
* - xhtml-strict: XHTML1 Strict.
|
||||
* - xhtml-trans: XHTML1 Transitional.
|
||||
* - xhtml-frame: XHTML1 Frameset.
|
||||
* - xhtml11: XHTML1.1.
|
||||
*
|
||||
* @param string $type Doctype to use.
|
||||
* @return string Doctype string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1439/docType
|
||||
*/
|
||||
function docType($type = 'xhtml-strict') {
|
||||
if (isset($this->__docTypes[$type])) {
|
||||
return $this->__docTypes[$type];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link to an external resource and handles basic meta tags
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `inline` Whether or not the link element should be output inline, or in scripts_for_layout.
|
||||
*
|
||||
* @param string $type The title of the external resource
|
||||
* @param mixed $url The address of the external resource or string for content attribute
|
||||
* @param array $options Other attributes for the generated tag. If the type attribute is html,
|
||||
* rss, atom, or icon, the mime-type is returned.
|
||||
* @return string A completed `<link />` element.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1438/meta
|
||||
*/
|
||||
function meta($type, $url = null, $options = array()) {
|
||||
$inline = isset($options['inline']) ? $options['inline'] : true;
|
||||
unset($options['inline']);
|
||||
|
||||
if (!is_array($type)) {
|
||||
$types = array(
|
||||
'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $url),
|
||||
'atom' => array('type' => 'application/atom+xml', 'title' => $type, 'link' => $url),
|
||||
'icon' => array('type' => 'image/x-icon', 'rel' => 'icon', 'link' => $url),
|
||||
'keywords' => array('name' => 'keywords', 'content' => $url),
|
||||
'description' => array('name' => 'description', 'content' => $url),
|
||||
);
|
||||
|
||||
if ($type === 'icon' && $url === null) {
|
||||
$types['icon']['link'] = $this->webroot('favicon.ico');
|
||||
}
|
||||
|
||||
if (isset($types[$type])) {
|
||||
$type = $types[$type];
|
||||
} elseif (!isset($options['type']) && $url !== null) {
|
||||
if (is_array($url) && isset($url['ext'])) {
|
||||
$type = $types[$url['ext']];
|
||||
} else {
|
||||
$type = $types['rss'];
|
||||
}
|
||||
} elseif (isset($options['type']) && isset($types[$options['type']])) {
|
||||
$type = $types[$options['type']];
|
||||
unset($options['type']);
|
||||
} else {
|
||||
$type = array();
|
||||
}
|
||||
} elseif ($url !== null) {
|
||||
$inline = $url;
|
||||
}
|
||||
$options = array_merge($type, $options);
|
||||
$out = null;
|
||||
|
||||
if (isset($options['link'])) {
|
||||
if (isset($options['rel']) && $options['rel'] === 'icon') {
|
||||
$out = sprintf($this->tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
|
||||
$options['rel'] = 'shortcut icon';
|
||||
} else {
|
||||
$options['link'] = $this->url($options['link'], true);
|
||||
}
|
||||
$out .= sprintf($this->tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
|
||||
} else {
|
||||
$out = sprintf($this->tags['meta'], $this->_parseAttributes($options, array('type'), ' ', ' '));
|
||||
}
|
||||
|
||||
if ($inline) {
|
||||
return $out;
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->addScript($out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a charset META-tag.
|
||||
*
|
||||
* @param string $charset The character set to be used in the meta tag. If empty,
|
||||
* The App.encoding value will be used. Example: "utf-8".
|
||||
* @return string A meta tag containing the specified character set.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1436/charset
|
||||
*/
|
||||
function charset($charset = null) {
|
||||
if (empty($charset)) {
|
||||
$charset = strtolower(Configure::read('App.encoding'));
|
||||
}
|
||||
return sprintf($this->tags['charset'], (!empty($charset) ? $charset : 'utf-8'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an HTML link.
|
||||
*
|
||||
* If $url starts with "http://" this is treated as an external link. Else,
|
||||
* it is treated as a path to controller/action and parsed with the
|
||||
* HtmlHelper::url() method.
|
||||
*
|
||||
* If the $url is empty, $title is used instead.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `escape` Set to false to disable escaping of title and attributes.
|
||||
*
|
||||
* @param string $title The content to be wrapped by <a> tags.
|
||||
* @param mixed $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.
|
||||
* @return string An `<a />` element.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1442/link
|
||||
*/
|
||||
function link($title, $url = null, $options = array(), $confirmMessage = false) {
|
||||
$escapeTitle = true;
|
||||
if ($url !== null) {
|
||||
$url = $this->url($url);
|
||||
} else {
|
||||
$url = $this->url($title);
|
||||
$title = $url;
|
||||
$escapeTitle = false;
|
||||
}
|
||||
|
||||
if (isset($options['escape'])) {
|
||||
$escapeTitle = $options['escape'];
|
||||
}
|
||||
|
||||
if ($escapeTitle === true) {
|
||||
$title = h($title);
|
||||
} elseif (is_string($escapeTitle)) {
|
||||
$title = htmlentities($title, ENT_QUOTES, $escapeTitle);
|
||||
}
|
||||
|
||||
if (!empty($options['confirm'])) {
|
||||
$confirmMessage = $options['confirm'];
|
||||
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) {
|
||||
if (isset($options['onclick'])) {
|
||||
$options['onclick'] .= ' event.returnValue = false; return false;';
|
||||
} else {
|
||||
$options['onclick'] = 'event.returnValue = false; return false;';
|
||||
}
|
||||
unset($options['default']);
|
||||
}
|
||||
return sprintf($this->tags['link'], $url, $this->_parseAttributes($options), $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a link element for CSS stylesheets.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `inline` If set to false, the generated tag appears in the head tag of the layout. Defaults to true
|
||||
*
|
||||
* @param mixed $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.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1437/css
|
||||
*/
|
||||
function css($path, $rel = null, $options = array()) {
|
||||
$options += array('inline' => true);
|
||||
if (is_array($path)) {
|
||||
$out = '';
|
||||
foreach ($path as $i) {
|
||||
$out .= "\n\t" . $this->css($i, $rel, $options);
|
||||
}
|
||||
if ($options['inline']) {
|
||||
return $out . "\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($path, '://') !== false) {
|
||||
$url = $path;
|
||||
} else {
|
||||
if ($path[0] !== '/') {
|
||||
$path = CSS_URL . $path;
|
||||
}
|
||||
|
||||
if (strpos($path, '?') === false) {
|
||||
if (substr($path, -4) !== '.css') {
|
||||
$path .= '.css';
|
||||
}
|
||||
}
|
||||
$url = $this->assetTimestamp($this->webroot($path));
|
||||
|
||||
if (Configure::read('Asset.filter.css')) {
|
||||
$pos = strpos($url, CSS_URL);
|
||||
if ($pos !== false) {
|
||||
$url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(CSS_URL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($rel == 'import') {
|
||||
$out = sprintf($this->tags['style'], $this->_parseAttributes($options, array('inline'), '', ' '), '@import url(' . $url . ');');
|
||||
} else {
|
||||
if ($rel == null) {
|
||||
$rel = 'stylesheet';
|
||||
}
|
||||
$out = sprintf($this->tags['css'], $rel, $url, $this->_parseAttributes($options, array('inline'), '', ' '));
|
||||
}
|
||||
|
||||
if ($options['inline']) {
|
||||
return $out;
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->addScript($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.
|
||||
*
|
||||
* Can include one or many Javascript files.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `inline` - Whether script should be output inline or into scripts_for_layout.
|
||||
* - `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.
|
||||
*
|
||||
* @param mixed $url String or array of javascript files to include
|
||||
* @param mixed $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.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1589/script
|
||||
*/
|
||||
function script($url, $options = array()) {
|
||||
if (is_bool($options)) {
|
||||
list($inline, $options) = array($options, array());
|
||||
$options['inline'] = $inline;
|
||||
}
|
||||
$options = array_merge(array('inline' => true, 'once' => true), $options);
|
||||
if (is_array($url)) {
|
||||
$out = '';
|
||||
foreach ($url as $i) {
|
||||
$out .= "\n\t" . $this->script($i, $options);
|
||||
}
|
||||
if ($options['inline']) {
|
||||
return $out . "\n";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if ($options['once'] && isset($this->__includedScripts[$url])) {
|
||||
return null;
|
||||
}
|
||||
$this->__includedScripts[$url] = true;
|
||||
|
||||
if (strpos($url, '://') === false) {
|
||||
if ($url[0] !== '/') {
|
||||
$url = JS_URL . $url;
|
||||
}
|
||||
if (strpos($url, '?') === false && substr($url, -3) !== '.js') {
|
||||
$url .= '.js';
|
||||
}
|
||||
$url = $this->assetTimestamp($this->webroot($url));
|
||||
|
||||
if (Configure::read('Asset.filter.js')) {
|
||||
$url = str_replace(JS_URL, 'cjs/', $url);
|
||||
}
|
||||
}
|
||||
$attributes = $this->_parseAttributes($options, array('inline', 'once'), ' ');
|
||||
$out = sprintf($this->tags['javascriptlink'], $url, $attributes);
|
||||
|
||||
if ($options['inline']) {
|
||||
return $out;
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->addScript($out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap $script in a script tag.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `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 or output inline
|
||||
*
|
||||
* @param string $script The script to wrap
|
||||
* @param array $options The options to use.
|
||||
* @return mixed string or null depending on the value of `$options['inline']`
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1604/scriptBlock
|
||||
*/
|
||||
function scriptBlock($script, $options = array()) {
|
||||
$options += array('safe' => true, 'inline' => true);
|
||||
if ($options['safe']) {
|
||||
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
|
||||
}
|
||||
$inline = $options['inline'];
|
||||
unset($options['inline'], $options['safe']);
|
||||
$attributes = $this->_parseAttributes($options, ' ', ' ');
|
||||
if ($inline) {
|
||||
return sprintf($this->tags['javascriptblock'], $attributes, $script);
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->addScript(sprintf($this->tags['javascriptblock'], $attributes, $script));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a script block that captures output until HtmlHelper::scriptEnd()
|
||||
* is called. This capturing block will capture all output between the methods
|
||||
* and create a scriptBlock from it.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `safe` Whether the code block should contain a CDATA
|
||||
* - `inline` Should the generated script tag be output inline or in `$scripts_for_layout`
|
||||
*
|
||||
* @param array $options Options for the code block.
|
||||
* @return void
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1605/scriptStart
|
||||
*/
|
||||
function scriptStart($options = array()) {
|
||||
$options += array('safe' => true, 'inline' => true);
|
||||
$this->_scriptBlockOptions = $options;
|
||||
ob_start();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return mixed depending on the settings of scriptStart() either a script tag or null
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1606/scriptEnd
|
||||
*/
|
||||
function scriptEnd() {
|
||||
$buffer = ob_get_clean();
|
||||
$options = $this->_scriptBlockOptions;
|
||||
$this->_scriptBlockOptions = array();
|
||||
return $this->scriptBlock($buffer, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds CSS style data from an array of CSS properties
|
||||
*
|
||||
* ### Usage:
|
||||
*
|
||||
* {{{
|
||||
* echo $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.
|
||||
* @return string CSS styling data
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1440/style
|
||||
*/
|
||||
function style($data, $oneline = true) {
|
||||
if (!is_array($data)) {
|
||||
return $data;
|
||||
}
|
||||
$out = array();
|
||||
foreach ($data as $key=> $value) {
|
||||
$out[] = $key.':'.$value.';';
|
||||
}
|
||||
if ($oneline) {
|
||||
return join(' ', $out);
|
||||
}
|
||||
return implode("\n", $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the breadcrumb trail as a sequence of »-separated links.
|
||||
*
|
||||
* @param string $separator Text to separate crumbs.
|
||||
* @param string $startText This will be the first crumb, if false it defaults to first crumb in array
|
||||
* @return string Composed bread crumbs
|
||||
* @access public
|
||||
*/
|
||||
function getCrumbs($separator = '»', $startText = false) {
|
||||
if (!empty($this->_crumbs)) {
|
||||
$out = array();
|
||||
if ($startText) {
|
||||
$out[] = $this->link($startText, '/');
|
||||
}
|
||||
|
||||
foreach ($this->_crumbs as $crumb) {
|
||||
if (!empty($crumb[1])) {
|
||||
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
||||
} else {
|
||||
$out[] = $crumb[0];
|
||||
}
|
||||
}
|
||||
return join($separator, $out);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
|
||||
* generated with the link pointed at `$options['url']`. This method will set an empty
|
||||
* alt attribute if one is not supplied.
|
||||
*
|
||||
* ### Usage
|
||||
*
|
||||
* Create a regular image:
|
||||
*
|
||||
* `echo $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'));`
|
||||
*
|
||||
* @param string $path Path to the image file, relative to the app/webroot/img/ directory.
|
||||
* @param array $options Array of HTML attributes.
|
||||
* @return string completed img tag
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1441/image
|
||||
*/
|
||||
function image($path, $options = array()) {
|
||||
if (is_array($path)) {
|
||||
$path = $this->url($path);
|
||||
} elseif (strpos($path, '://') === false) {
|
||||
if ($path[0] !== '/') {
|
||||
$path = IMAGES_URL . $path;
|
||||
}
|
||||
$path = $this->assetTimestamp($this->webroot($path));
|
||||
}
|
||||
|
||||
if (!isset($options['alt'])) {
|
||||
$options['alt'] = '';
|
||||
}
|
||||
|
||||
$url = false;
|
||||
if (!empty($options['url'])) {
|
||||
$url = $options['url'];
|
||||
unset($options['url']);
|
||||
}
|
||||
|
||||
$image = sprintf($this->tags['image'], $path, $this->_parseAttributes($options, null, '', ' '));
|
||||
|
||||
if ($url) {
|
||||
return sprintf($this->tags['link'], $this->url($url), null, $image);
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a row of formatted and named TABLE headers.
|
||||
*
|
||||
* @param array $names Array of tablenames.
|
||||
* @param array $trOptions HTML options for TR elements.
|
||||
* @param array $thOptions HTML options for TH elements.
|
||||
* @return string Completed table headers
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1446/tableHeaders
|
||||
*/
|
||||
function tableHeaders($names, $trOptions = null, $thOptions = null) {
|
||||
$out = array();
|
||||
foreach ($names as $arg) {
|
||||
$out[] = sprintf($this->tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
|
||||
}
|
||||
return sprintf($this->tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted string of table rows (TR's with TD's in them).
|
||||
*
|
||||
* @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 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
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1447/tableCells
|
||||
*/
|
||||
function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true) {
|
||||
if (empty($data[0]) || !is_array($data[0])) {
|
||||
$data = array($data);
|
||||
}
|
||||
|
||||
if ($oddTrOptions === true) {
|
||||
$useCount = true;
|
||||
$oddTrOptions = null;
|
||||
}
|
||||
|
||||
if ($evenTrOptions === false) {
|
||||
$continueOddEven = false;
|
||||
$evenTrOptions = null;
|
||||
}
|
||||
|
||||
if ($continueOddEven) {
|
||||
static $count = 0;
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
|
||||
foreach ($data as $line) {
|
||||
$count++;
|
||||
$cellsOut = array();
|
||||
$i = 0;
|
||||
foreach ($line as $cell) {
|
||||
$cellOptions = array();
|
||||
|
||||
if (is_array($cell)) {
|
||||
$cellOptions = $cell[1];
|
||||
$cell = $cell[0];
|
||||
} elseif ($useCount) {
|
||||
$cellOptions['class'] = 'column-' . ++$i;
|
||||
}
|
||||
$cellsOut[] = sprintf($this->tags['tablecell'], $this->_parseAttributes($cellOptions), $cell);
|
||||
}
|
||||
$options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
|
||||
$out[] = sprintf($this->tags['tablerow'], $options, implode(' ', $cellsOut));
|
||||
}
|
||||
return implode("\n", $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted block tag, i.e DIV, SPAN, P.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `escape` Whether or not the contents should be html_entity escaped.
|
||||
*
|
||||
* @param string $name Tag name.
|
||||
* @param string $text String content that will appear inside the div element.
|
||||
* If null, only a start tag will be printed
|
||||
* @param array $options Additional HTML attributes of the DIV tag, see above.
|
||||
* @return string The formatted tag element
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1443/tag
|
||||
*/
|
||||
function tag($name, $text = null, $options = array()) {
|
||||
if (is_array($options) && 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted DIV tag for HTML FORMs.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `escape` Whether or not the contents should be html_entity escaped.
|
||||
*
|
||||
* @param string $class CSS class name of the div element.
|
||||
* @param string $text String content that will appear inside the div element.
|
||||
* If null, only a start tag will be printed
|
||||
* @param array $options Additional HTML attributes of the DIV tag
|
||||
* @return string The formatted DIV element
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1444/div
|
||||
*/
|
||||
function div($class = null, $text = null, $options = array()) {
|
||||
if (!empty($class)) {
|
||||
$options['class'] = $class;
|
||||
}
|
||||
return $this->tag('div', $text, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted P tag.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `escape` Whether or not the contents should be html_entity escaped.
|
||||
*
|
||||
* @param string $class CSS class name of the p element.
|
||||
* @param string $text String content that will appear inside the p element.
|
||||
* @param array $options Additional HTML attributes of the P tag
|
||||
* @return string The formatted P element
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1445/para
|
||||
*/
|
||||
function para($class, $text, $options = array()) {
|
||||
if (isset($options['escape'])) {
|
||||
$text = h($text);
|
||||
}
|
||||
if ($class != null && !empty($class)) {
|
||||
$options['class'] = $class;
|
||||
}
|
||||
if ($text === null) {
|
||||
$tag = 'parastart';
|
||||
} else {
|
||||
$tag = 'para';
|
||||
}
|
||||
return sprintf($this->tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a nested list (UL/OL) out of an associative array.
|
||||
*
|
||||
* @param array $list Set of elements to list
|
||||
* @param array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
|
||||
* @param array $itemOptions Additional HTML attributes of the list item (LI) tag
|
||||
* @param string $tag Type of list tag to use (ol/ul)
|
||||
* @return string The nested list
|
||||
* @access public
|
||||
*/
|
||||
function nestedList($list, $options = array(), $itemOptions = array(), $tag = 'ul') {
|
||||
if (is_string($options)) {
|
||||
$tag = $options;
|
||||
$options = array();
|
||||
}
|
||||
$items = $this->__nestedListItem($list, $options, $itemOptions, $tag);
|
||||
return sprintf($this->tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal function to build a nested list (UL/OL) out of an associative array.
|
||||
*
|
||||
* @param array $list Set of elements to list
|
||||
* @param array $options Additional HTML attributes of the list (ol/ul) tag
|
||||
* @param array $itemOptions Additional HTML attributes of the list item (LI) tag
|
||||
* @param string $tag Type of list tag to use (ol/ul)
|
||||
* @return string The nested list element
|
||||
* @access private
|
||||
* @see HtmlHelper::nestedList()
|
||||
*/
|
||||
function __nestedListItem($items, $options, $itemOptions, $tag) {
|
||||
$out = '';
|
||||
|
||||
$index = 1;
|
||||
foreach ($items as $key => $item) {
|
||||
if (is_array($item)) {
|
||||
$item = $key . $this->nestedList($item, $options, $itemOptions, $tag);
|
||||
}
|
||||
if (isset($itemOptions['even']) && $index % 2 == 0) {
|
||||
$itemOptions['class'] = $itemOptions['even'];
|
||||
} else if (isset($itemOptions['odd']) && $index % 2 != 0) {
|
||||
$itemOptions['class'] = $itemOptions['odd'];
|
||||
}
|
||||
$out .= sprintf($this->tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item);
|
||||
$index++;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
721
php-practice/web-cake/html/cake/libs/view/helpers/javascript.php
Normal file
721
php-practice/web-cake/html/cake/libs/view/helpers/javascript.php
Normal file
@@ -0,0 +1,721 @@
|
||||
<?php
|
||||
/**
|
||||
* Javascript Helper class file.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Javascript Helper class for easy use of JavaScript.
|
||||
*
|
||||
* JavascriptHelper encloses all methods needed while working with JavaScript.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1450/Javascript
|
||||
*/
|
||||
class JavascriptHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Determines whether native JSON extension is used for encoding. Set by object constructor.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $useNative = false;
|
||||
|
||||
/**
|
||||
* If true, automatically writes events to the end of a script or to an external JavaScript file
|
||||
* at the end of page execution
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $enabled = true;
|
||||
|
||||
/**
|
||||
* Indicates whether <script /> blocks should be written 'safely,' i.e. wrapped in CDATA blocks
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $safe = false;
|
||||
|
||||
/**
|
||||
* HTML tags used by this helper.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $tags = array(
|
||||
'javascriptstart' => '<script type="text/javascript">',
|
||||
'javascriptend' => '</script>',
|
||||
'javascriptblock' => '<script type="text/javascript">%s</script>',
|
||||
'javascriptlink' => '<script type="text/javascript" src="%s"></script>'
|
||||
);
|
||||
|
||||
/**
|
||||
* Holds options passed to codeBlock(), saved for when block is dumped to output
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
* @see JavascriptHelper::codeBlock()
|
||||
*/
|
||||
var $_blockOptions = array();
|
||||
|
||||
/**
|
||||
* Caches events written by event() for output at the end of page execution
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
* @see JavascriptHelper::event()
|
||||
*/
|
||||
var $_cachedEvents = array();
|
||||
|
||||
/**
|
||||
* Indicates whether generated events should be cached for later output (can be written at the
|
||||
* end of the page, in the <head />, or to an external file).
|
||||
*
|
||||
* @var boolean
|
||||
* @access protected
|
||||
* @see JavascriptHelper::event()
|
||||
* @see JavascriptHelper::writeEvents()
|
||||
*/
|
||||
var $_cacheEvents = false;
|
||||
|
||||
/**
|
||||
* Indicates whether cached events should be written to an external file
|
||||
*
|
||||
* @var boolean
|
||||
* @access protected
|
||||
* @see JavascriptHelper::event()
|
||||
* @see JavascriptHelper::writeEvents()
|
||||
*/
|
||||
var $_cacheToFile = false;
|
||||
|
||||
/**
|
||||
* Indicates whether *all* generated JavaScript should be cached for later output
|
||||
*
|
||||
* @var boolean
|
||||
* @access protected
|
||||
* @see JavascriptHelper::codeBlock()
|
||||
* @see JavascriptHelper::blockEnd()
|
||||
*/
|
||||
var $_cacheAll = false;
|
||||
|
||||
/**
|
||||
* Contains event rules attached with CSS selectors. Used with the event:Selectors JavaScript
|
||||
* library.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
* @see JavascriptHelper::event()
|
||||
* @link http://alternateidea.com/event-selectors/
|
||||
*/
|
||||
var $_rules = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $__scriptBuffer = null;
|
||||
|
||||
/**
|
||||
* Constructor. Checks for presence of native PHP JSON extension to use for object encoding
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct($options = array()) {
|
||||
if (!empty($options)) {
|
||||
foreach ($options as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
$key = $val;
|
||||
$val = true;
|
||||
}
|
||||
switch ($key) {
|
||||
case 'cache':
|
||||
|
||||
break;
|
||||
case 'safe':
|
||||
$this->safe = $val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->useNative = function_exists('json_encode');
|
||||
return parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JavaScript script tag.
|
||||
*
|
||||
* Options:
|
||||
*
|
||||
* - allowCache: boolean, designates whether this block is cacheable using the
|
||||
* current cache settings.
|
||||
* - safe: boolean, whether this block should be wrapped in CDATA tags. Defaults
|
||||
* to helper's object configuration.
|
||||
* - inline: whether the block should be printed inline, or written
|
||||
* to cached for later output (i.e. $scripts_for_layout).
|
||||
*
|
||||
* @param string $script The JavaScript to be wrapped in SCRIPT tags.
|
||||
* @param array $options Set of options:
|
||||
* @return string The full SCRIPT element, with the JavaScript inside it, or null,
|
||||
* if 'inline' is set to false.
|
||||
*/
|
||||
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' => true, 'inline' => true);
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
|
||||
if (empty($script)) {
|
||||
$this->__scriptBuffer = @ob_get_contents();
|
||||
$this->_blockOptions = $options;
|
||||
$this->inBlock = true;
|
||||
@ob_end_clean();
|
||||
ob_start();
|
||||
return null;
|
||||
}
|
||||
if ($this->_cacheEvents && $this->_cacheAll && $options['allowCache']) {
|
||||
$this->_cachedEvents[] = $script;
|
||||
return null;
|
||||
}
|
||||
if ($options['safe'] || $this->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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends a block of cached JavaScript code
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
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;
|
||||
$this->_blockOptions = array();
|
||||
$this->inBlock = false;
|
||||
|
||||
if (empty($script)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->codeBlock($script, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JavaScript include tag (SCRIPT element). 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.
|
||||
*
|
||||
* @param mixed $url String URL to JavaScript file, or an array of URLs.
|
||||
* @param boolean $inline If true, the <script /> tag will be printed inline,
|
||||
* otherwise it will be printed in the <head />, using $scripts_for_layout
|
||||
* @see JS_URL
|
||||
* @return string
|
||||
*/
|
||||
function link($url, $inline = true) {
|
||||
if (is_array($url)) {
|
||||
$out = '';
|
||||
foreach ($url as $i) {
|
||||
$out .= "\n\t" . $this->link($i, $inline);
|
||||
}
|
||||
if ($inline) {
|
||||
return $out . "\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($url, '://') === false) {
|
||||
if ($url[0] !== '/') {
|
||||
$url = JS_URL . $url;
|
||||
}
|
||||
if (strpos($url, '?') === false) {
|
||||
if (substr($url, -3) !== '.js') {
|
||||
$url .= '.js';
|
||||
}
|
||||
}
|
||||
$url = $this->assetTimestamp($this->webroot($url));
|
||||
|
||||
if (Configure::read('Asset.filter.js')) {
|
||||
$pos = strpos($url, JS_URL);
|
||||
if ($pos !== false) {
|
||||
$url = substr($url, 0, $pos) . 'cjs/' . substr($url, $pos + strlen(JS_URL));
|
||||
}
|
||||
}
|
||||
}
|
||||
$out = sprintf($this->tags['javascriptlink'], $url);
|
||||
|
||||
if ($inline) {
|
||||
return $out;
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->addScript($out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape carriage returns and single and double quotes for JavaScript segments.
|
||||
*
|
||||
* @param string $script string that might have javascript elements
|
||||
* @return string escaped string
|
||||
*/
|
||||
function escapeScript($script) {
|
||||
$script = str_replace(array("\r\n", "\n", "\r"), '\n', $script);
|
||||
$script = str_replace(array('"', "'"), array('\"', "\\'"), $script);
|
||||
return $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string to be JavaScript friendly.
|
||||
*
|
||||
* List of escaped ellements:
|
||||
* + "\r\n" => '\n'
|
||||
* + "\r" => '\n'
|
||||
* + "\n" => '\n'
|
||||
* + '"' => '\"'
|
||||
* + "'" => "\\'"
|
||||
*
|
||||
* @param string $script String that needs to get escaped.
|
||||
* @return string Escaped string.
|
||||
*/
|
||||
function escapeString($string) {
|
||||
App::import('Core', 'Multibyte');
|
||||
$escape = array("\r\n" => "\n", "\r" => "\n");
|
||||
$string = str_replace(array_keys($escape), array_values($escape), $string);
|
||||
return $this->_utf8ToHex($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a string into JSON. Converts and escapes necessary characters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function _utf8ToHex($string) {
|
||||
$length = strlen($string);
|
||||
$return = '';
|
||||
for ($i = 0; $i < $length; ++$i) {
|
||||
$ord = ord($string{$i});
|
||||
switch (true) {
|
||||
case $ord == 0x08:
|
||||
$return .= '\b';
|
||||
break;
|
||||
case $ord == 0x09:
|
||||
$return .= '\t';
|
||||
break;
|
||||
case $ord == 0x0A:
|
||||
$return .= '\n';
|
||||
break;
|
||||
case $ord == 0x0C:
|
||||
$return .= '\f';
|
||||
break;
|
||||
case $ord == 0x0D:
|
||||
$return .= '\r';
|
||||
break;
|
||||
case $ord == 0x22:
|
||||
case $ord == 0x2F:
|
||||
case $ord == 0x5C:
|
||||
case $ord == 0x27:
|
||||
$return .= '\\' . $string{$i};
|
||||
break;
|
||||
case (($ord >= 0x20) && ($ord <= 0x7F)):
|
||||
$return .= $string{$i};
|
||||
break;
|
||||
case (($ord & 0xE0) == 0xC0):
|
||||
if ($i + 1 >= $length) {
|
||||
$i += 1;
|
||||
$return .= '?';
|
||||
break;
|
||||
}
|
||||
$charbits = $string{$i} . $string{$i + 1};
|
||||
$char = Multibyte::utf8($charbits);
|
||||
$return .= sprintf('\u%04s', dechex($char[0]));
|
||||
$i += 1;
|
||||
break;
|
||||
case (($ord & 0xF0) == 0xE0):
|
||||
if ($i + 2 >= $length) {
|
||||
$i += 2;
|
||||
$return .= '?';
|
||||
break;
|
||||
}
|
||||
$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2};
|
||||
$char = Multibyte::utf8($charbits);
|
||||
$return .= sprintf('\u%04s', dechex($char[0]));
|
||||
$i += 2;
|
||||
break;
|
||||
case (($ord & 0xF8) == 0xF0):
|
||||
if ($i + 3 >= $length) {
|
||||
$i += 3;
|
||||
$return .= '?';
|
||||
break;
|
||||
}
|
||||
$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3};
|
||||
$char = Multibyte::utf8($charbits);
|
||||
$return .= sprintf('\u%04s', dechex($char[0]));
|
||||
$i += 3;
|
||||
break;
|
||||
case (($ord & 0xFC) == 0xF8):
|
||||
if ($i + 4 >= $length) {
|
||||
$i += 4;
|
||||
$return .= '?';
|
||||
break;
|
||||
}
|
||||
$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4};
|
||||
$char = Multibyte::utf8($charbits);
|
||||
$return .= sprintf('\u%04s', dechex($char[0]));
|
||||
$i += 4;
|
||||
break;
|
||||
case (($ord & 0xFE) == 0xFC):
|
||||
if ($i + 5 >= $length) {
|
||||
$i += 5;
|
||||
$return .= '?';
|
||||
break;
|
||||
}
|
||||
$charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4} . $string{$i + 5};
|
||||
$char = Multibyte::utf8($charbits);
|
||||
$return .= sprintf('\u%04s', dechex($char[0]));
|
||||
$i += 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach an event to an element. Used with the Prototype library.
|
||||
*
|
||||
* @param string $object Object to be observed
|
||||
* @param string $event event to observe
|
||||
* @param string $observer function to call
|
||||
* @param array $options Set options: useCapture, allowCache, safe
|
||||
* @return boolean true on success
|
||||
*/
|
||||
function event($object, $event, $observer = null, $options = array()) {
|
||||
if (!empty($options) && !is_array($options)) {
|
||||
$options = array('useCapture' => $options);
|
||||
} else if (empty($options)) {
|
||||
$options = array();
|
||||
}
|
||||
|
||||
$defaultOptions = array('useCapture' => false);
|
||||
$options = array_merge($defaultOptions, $options);
|
||||
|
||||
if ($options['useCapture'] == true) {
|
||||
$options['useCapture'] = 'true';
|
||||
} else {
|
||||
$options['useCapture'] = 'false';
|
||||
}
|
||||
$isObject = (
|
||||
strpos($object, 'window') !== false || strpos($object, 'document') !== false ||
|
||||
strpos($object, '$(') !== false || strpos($object, '"') !== false ||
|
||||
strpos($object, '\'') !== false
|
||||
);
|
||||
|
||||
if ($isObject) {
|
||||
$b = "Event.observe({$object}, '{$event}', function(event) { {$observer} }, ";
|
||||
$b .= "{$options['useCapture']});";
|
||||
} elseif ($object[0] == '\'') {
|
||||
$b = "Event.observe(" . substr($object, 1) . ", '{$event}', function(event) { ";
|
||||
$b .= "{$observer} }, {$options['useCapture']});";
|
||||
} else {
|
||||
$chars = array('#', ' ', ', ', '.', ':');
|
||||
$found = false;
|
||||
foreach ($chars as $char) {
|
||||
if (strpos($object, $char) !== false) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
$this->_rules[$object] = $event;
|
||||
} else {
|
||||
$b = "Event.observe(\$('{$object}'), '{$event}', function(event) { ";
|
||||
$b .= "{$observer} }, {$options['useCapture']});";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($b) && !empty($b)) {
|
||||
if ($this->_cacheEvents === true) {
|
||||
$this->_cachedEvents[] = $b;
|
||||
return;
|
||||
} else {
|
||||
return $this->codeBlock($b, array_diff_key($options, $defaultOptions));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache JavaScript events created with event()
|
||||
*
|
||||
* @param boolean $file If true, code will be written to a file
|
||||
* @param boolean $all If true, all code written with JavascriptHelper will be sent to a file
|
||||
* @return null
|
||||
*/
|
||||
function cacheEvents($file = false, $all = false) {
|
||||
$this->_cacheEvents = true;
|
||||
$this->_cacheToFile = $file;
|
||||
$this->_cacheAll = $all;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets (and clears) the current JavaScript event cache
|
||||
*
|
||||
* @param boolean $clear
|
||||
* @return string
|
||||
*/
|
||||
function getCache($clear = true) {
|
||||
$out = '';
|
||||
$rules = array();
|
||||
|
||||
if (!empty($this->_rules)) {
|
||||
foreach ($this->_rules as $sel => $event) {
|
||||
$rules[] = "\t'{$sel}': function(element, event) {\n\t\t{$event}\n\t}";
|
||||
}
|
||||
}
|
||||
$data = implode("\n", $this->_cachedEvents);
|
||||
|
||||
if (!empty($rules)) {
|
||||
$data .= "\nvar Rules = {\n" . implode(",\n\n", $rules) . "\n}";
|
||||
$data .= "\nEventSelectors.start(Rules);\n";
|
||||
}
|
||||
if ($clear) {
|
||||
$this->_rules = array();
|
||||
$this->_cacheEvents = false;
|
||||
$this->_cachedEvents = array();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write cached JavaScript events
|
||||
*
|
||||
* @param boolean $inline If true, returns JavaScript event code. Otherwise it is added to the
|
||||
* output of $scripts_for_layout in the layout.
|
||||
* @param array $options Set options for codeBlock
|
||||
* @return string
|
||||
*/
|
||||
function writeEvents($inline = true, $options = array()) {
|
||||
$out = '';
|
||||
$rules = array();
|
||||
|
||||
if (!$this->_cacheEvents) {
|
||||
return;
|
||||
}
|
||||
$data = $this->getCache();
|
||||
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_cacheToFile) {
|
||||
$filename = md5($data);
|
||||
if (!file_exists(JS . $filename . '.js')) {
|
||||
cache(str_replace(WWW_ROOT, '', JS) . $filename . '.js', $data, '+999 days', 'public');
|
||||
}
|
||||
$out = $this->link($filename);
|
||||
} else {
|
||||
$out = $this->codeBlock("\n" . $data . "\n", $options);
|
||||
}
|
||||
|
||||
if ($inline) {
|
||||
return $out;
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$view->addScript($out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the Prototype Javascript library (and anything else) inside a single script tag.
|
||||
*
|
||||
* Note: The recommended approach is to copy the contents of
|
||||
* javascripts into your application's
|
||||
* public/javascripts/ directory, and use @see javascriptIncludeTag() to
|
||||
* create remote script links.
|
||||
*
|
||||
* @param string $script Script file to include
|
||||
* @param array $options Set options for codeBlock
|
||||
* @return string script with all javascript in/javascripts folder
|
||||
*/
|
||||
function includeScript($script = "", $options = array()) {
|
||||
if ($script == "") {
|
||||
$files = scandir(JS);
|
||||
$javascript = '';
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (substr($file, -3) == '.js') {
|
||||
$javascript .= file_get_contents(JS . "{$file}") . "\n\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$javascript = file_get_contents(JS . "$script.js") . "\n\n";
|
||||
}
|
||||
return $this->codeBlock("\n\n" . $javascript, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a JavaScript object in JavaScript Object Notation (JSON)
|
||||
* from an array
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - block - Wraps the return value in a script tag if true. Default is false
|
||||
* - prefix - Prepends the string to the returned data. Default is ''
|
||||
* - postfix - Appends the string to the returned data. Default is ''
|
||||
* - stringKeys - A list of array keys to be treated as a string.
|
||||
* - quoteKeys - If false treats $stringKeys as a list of keys **not** to be quoted. Default is true.
|
||||
* - q - The type of quote to use. Default is '"'. This option only affects the keys, not the values.
|
||||
*
|
||||
* @param array $data Data to be converted
|
||||
* @param array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q
|
||||
* @return string A JSON code block
|
||||
*/
|
||||
function object($data = array(), $options = array()) {
|
||||
if (!empty($options) && !is_array($options)) {
|
||||
$options = array('block' => $options);
|
||||
} else if (empty($options)) {
|
||||
$options = array();
|
||||
}
|
||||
|
||||
$defaultOptions = array(
|
||||
'block' => false, 'prefix' => '', 'postfix' => '',
|
||||
'stringKeys' => array(), 'quoteKeys' => true, 'q' => '"'
|
||||
);
|
||||
$options = array_merge($defaultOptions, $options, array_filter(compact(array_keys($defaultOptions))));
|
||||
|
||||
if (is_object($data)) {
|
||||
$data = get_object_vars($data);
|
||||
}
|
||||
|
||||
$out = $keys = array();
|
||||
$numeric = true;
|
||||
|
||||
if ($this->useNative) {
|
||||
$rt = json_encode($data);
|
||||
} else {
|
||||
if (is_null($data)) {
|
||||
return 'null';
|
||||
}
|
||||
if (is_bool($data)) {
|
||||
return $data ? 'true' : 'false';
|
||||
}
|
||||
|
||||
if (is_array($data)) {
|
||||
$keys = array_keys($data);
|
||||
}
|
||||
|
||||
if (!empty($keys)) {
|
||||
$numeric = (array_values($keys) === array_keys(array_values($keys)));
|
||||
}
|
||||
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_array($val) || is_object($val)) {
|
||||
$val = $this->object(
|
||||
$val,
|
||||
array_merge($options, array('block' => false, 'prefix' => '', 'postfix' => ''))
|
||||
);
|
||||
} else {
|
||||
$quoteStrings = (
|
||||
!count($options['stringKeys']) ||
|
||||
($options['quoteKeys'] && in_array($key, $options['stringKeys'], true)) ||
|
||||
(!$options['quoteKeys'] && !in_array($key, $options['stringKeys'], true))
|
||||
);
|
||||
$val = $this->value($val, $quoteStrings);
|
||||
}
|
||||
if (!$numeric) {
|
||||
$val = $options['q'] . $this->value($key, false) . $options['q'] . ':' . $val;
|
||||
}
|
||||
$out[] = $val;
|
||||
}
|
||||
|
||||
if (!$numeric) {
|
||||
$rt = '{' . implode(',', $out) . '}';
|
||||
} else {
|
||||
$rt = '[' . implode(',', $out) . ']';
|
||||
}
|
||||
}
|
||||
$rt = $options['prefix'] . $rt . $options['postfix'];
|
||||
|
||||
if ($options['block']) {
|
||||
$rt = $this->codeBlock($rt, array_diff_key($options, $defaultOptions));
|
||||
}
|
||||
|
||||
return $rt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $quoteStrings If false, leaves string values unquoted
|
||||
* @return string a JavaScript-safe/JSON representation of $val
|
||||
*/
|
||||
function value($val, $quoteStrings = true) {
|
||||
switch (true) {
|
||||
case (is_array($val) || is_object($val)):
|
||||
$val = $this->object($val);
|
||||
break;
|
||||
case ($val === null):
|
||||
$val = 'null';
|
||||
break;
|
||||
case (is_bool($val)):
|
||||
$val = !empty($val) ? 'true' : 'false';
|
||||
break;
|
||||
case (is_int($val)):
|
||||
$val = $val;
|
||||
break;
|
||||
case (is_float($val)):
|
||||
$val = sprintf("%.11f", $val);
|
||||
break;
|
||||
default:
|
||||
$val = $this->escapeString($val);
|
||||
if ($quoteStrings) {
|
||||
$val = '"' . $val . '"';
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* AfterRender callback. Writes any cached events to the view, or to a temp file.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
function afterRender() {
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
echo $this->writeEvents(true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
/**
|
||||
* jQuery Engine Helper for JsHelper
|
||||
*
|
||||
* Provides jQuery specific Javascript for JsHelper.
|
||||
*
|
||||
* 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 versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
||||
* @link http://cakephp.org CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.view.helpers
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Helper', 'Js');
|
||||
|
||||
class JqueryEngineHelper extends JsBaseEngineHelper {
|
||||
/**
|
||||
* Option mappings for jQuery
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_optionMap = array(
|
||||
'request' => array(
|
||||
'type' => 'dataType',
|
||||
'before' => 'beforeSend',
|
||||
'method' => 'type',
|
||||
),
|
||||
'sortable' => array(
|
||||
'complete' => 'stop',
|
||||
),
|
||||
'drag' => array(
|
||||
'snapGrid' => 'grid',
|
||||
'container' => 'containment',
|
||||
),
|
||||
'drop' => array(
|
||||
'leave' => 'out',
|
||||
'hover' => 'over'
|
||||
),
|
||||
'slider' => array(
|
||||
'complete' => 'stop',
|
||||
'direction' => 'orientation'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Callback arguments lists
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
var $_callbackArguments = array(
|
||||
'slider' => array(
|
||||
'start' => 'event, ui',
|
||||
'slide' => 'event, ui',
|
||||
'change' => 'event, ui',
|
||||
'stop' => 'event, ui'
|
||||
),
|
||||
'sortable' => array(
|
||||
'start' => 'event, ui',
|
||||
'sort' => 'event, ui',
|
||||
'change' => 'event, ui',
|
||||
'beforeStop' => 'event, ui',
|
||||
'stop' => 'event, ui',
|
||||
'update' => 'event, ui',
|
||||
'receive' => 'event, ui',
|
||||
'remove' => 'event, ui',
|
||||
'over' => 'event, ui',
|
||||
'out' => 'event, ui',
|
||||
'activate' => 'event, ui',
|
||||
'deactivate' => 'event, ui'
|
||||
),
|
||||
'drag' => array(
|
||||
'start' => 'event, ui',
|
||||
'drag' => 'event, ui',
|
||||
'stop' => 'event, ui',
|
||||
),
|
||||
'drop' => array(
|
||||
'activate' => 'event, ui',
|
||||
'deactivate' => 'event, ui',
|
||||
'over' => 'event, ui',
|
||||
'out' => 'event, ui',
|
||||
'drop' => 'event, ui'
|
||||
),
|
||||
'request' => array(
|
||||
'beforeSend' => 'XMLHttpRequest',
|
||||
'error' => 'XMLHttpRequest, textStatus, errorThrown',
|
||||
'success' => 'data, textStatus',
|
||||
'complete' => 'XMLHttpRequest, textStatus',
|
||||
'xhr' => ''
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The variable name of the jQuery Object, useful
|
||||
* when jQuery is put into noConflict() mode.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $jQueryObject = '$';
|
||||
|
||||
/**
|
||||
* Helper function to wrap repetitive simple method templating.
|
||||
*
|
||||
* @param string $method The method name being generated.
|
||||
* @param string $template The method template
|
||||
* @param string $selection the selection to apply
|
||||
* @param string $options Array of options for method
|
||||
* @param string $callbacks Array of callback / special options.
|
||||
* @return string Composed method string
|
||||
* @access public
|
||||
*/
|
||||
function _methodTemplate($method, $template, $options, $extraSafeKeys = array()) {
|
||||
$options = $this->_mapOptions($method, $options);
|
||||
$options = $this->_prepareCallbacks($method, $options);
|
||||
$callbacks = array_keys($this->_callbackArguments[$method]);
|
||||
if (!empty($extraSafeKeys)) {
|
||||
$callbacks = array_merge($callbacks, $extraSafeKeys);
|
||||
}
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
return sprintf($template, $this->selection, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return object instance of $this. Allows chained methods.
|
||||
* @access public
|
||||
*/
|
||||
function get($selector) {
|
||||
if ($selector == 'window' || $selector == 'document') {
|
||||
$this->selection = $this->jQueryObject . '(' . $selector .')';
|
||||
} else {
|
||||
$this->selection = $this->jQueryObject . '("' . $selector . '")';
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the script cache. Operates on the currently selected elements.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults true)
|
||||
* - '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 array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
* @access public
|
||||
*/
|
||||
function event($type, $callback, $options = array()) {
|
||||
$defaults = array('wrap' => true, 'stop' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
|
||||
$function = 'function (event) {%s}';
|
||||
if ($options['wrap'] && $options['stop']) {
|
||||
$callback .= "\nreturn false;";
|
||||
}
|
||||
if ($options['wrap']) {
|
||||
$callback = sprintf($function, $callback);
|
||||
}
|
||||
return sprintf('%s.bind("%s", %s);', $this->selection, $type, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a domReady event. For jQuery. This method does not
|
||||
* 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
|
||||
* `$().ready()` is used.
|
||||
*
|
||||
* @param string $functionBody The code to run on domReady
|
||||
* @return string completed domReady method
|
||||
* @access public
|
||||
*/
|
||||
function domReady($functionBody) {
|
||||
return $this->jQueryObject . '(document).ready(function () {' . $functionBody . '});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an iteration over the current selection result.
|
||||
*
|
||||
* @param string $method The method you want to apply to the selection
|
||||
* @param string $callback The function body you wish to apply during the iteration.
|
||||
* @return string completed iteration
|
||||
* @access public
|
||||
*/
|
||||
function each($callback) {
|
||||
return $this->selection . '.each(function () {' . $callback . '});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger an Effect.
|
||||
*
|
||||
* @param string $name The name of the effect to trigger.
|
||||
* @param array $options Array of options for the effect.
|
||||
* @return string completed string with effect.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::effect()
|
||||
*/
|
||||
function effect($name, $options = array()) {
|
||||
$speed = null;
|
||||
if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
|
||||
$speed = $this->value($options['speed']);
|
||||
}
|
||||
$effect = '';
|
||||
switch ($name) {
|
||||
case 'slideIn':
|
||||
case 'slideOut':
|
||||
$name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
|
||||
case 'hide':
|
||||
case 'show':
|
||||
case 'fadeIn':
|
||||
case 'fadeOut':
|
||||
case 'slideDown':
|
||||
case 'slideUp':
|
||||
$effect = ".$name($speed);";
|
||||
break;
|
||||
}
|
||||
return $this->selection . $effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an $.ajax() call.
|
||||
*
|
||||
* If the 'update' key is set, success callback will be overridden.
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param array $options See JsHelper::request() for options.
|
||||
* @return string The completed ajax call.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::request() for options list.
|
||||
*/
|
||||
function request($url, $options = array()) {
|
||||
$url = $this->url($url);
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
if (isset($options['data']) && is_array($options['data'])) {
|
||||
$options['data'] = $this->_toQuerystring($options['data']);
|
||||
}
|
||||
$options['url'] = $url;
|
||||
if (isset($options['update'])) {
|
||||
$wrapCallbacks = isset($options['wrapCallbacks']) ? $options['wrapCallbacks'] : true;
|
||||
$success = '';
|
||||
if(isset($options['success']) AND !empty($options['success'])) {
|
||||
$success .= $options['success'];
|
||||
}
|
||||
$success .= $this->jQueryObject . '("' . $options['update'] . '").html(data);';
|
||||
if (!$wrapCallbacks) {
|
||||
$success = 'function (data, textStatus) {' . $success . '}';
|
||||
}
|
||||
$options['dataType'] = 'html';
|
||||
$options['success'] = $success;
|
||||
unset($options['update']);
|
||||
}
|
||||
$callbacks = array('success', 'error', 'beforeSend', 'complete');
|
||||
if (isset($options['dataExpression'])) {
|
||||
$callbacks[] = 'data';
|
||||
unset($options['dataExpression']);
|
||||
}
|
||||
$options = $this->_prepareCallbacks('request', $options);
|
||||
$options = $this->_parseOptions($options, $callbacks);
|
||||
return $this->jQueryObject . '.ajax({' . $options .'});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sortable element.
|
||||
*
|
||||
* Requires both Ui.Core and Ui.Sortables to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the sortable.
|
||||
* @return string Completed sortable script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::sortable() for options list.
|
||||
*/
|
||||
function sortable($options = array()) {
|
||||
$template = '%s.sortable({%s});';
|
||||
return $this->_methodTemplate('sortable', $template, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Draggable element
|
||||
*
|
||||
* Requires both Ui.Core and Ui.Draggable to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the draggable element.
|
||||
* @return string Completed Draggable script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::drag() for options list.
|
||||
*/
|
||||
function drag($options = array()) {
|
||||
$template = '%s.draggable({%s});';
|
||||
return $this->_methodTemplate('drag', $template, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Droppable element
|
||||
*
|
||||
* Requires both Ui.Core and Ui.Droppable to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the droppable element.
|
||||
* @return string Completed Droppable script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::drop() for options list.
|
||||
*/
|
||||
function drop($options = array()) {
|
||||
$template = '%s.droppable({%s});';
|
||||
return $this->_methodTemplate('drop', $template, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Slider element
|
||||
*
|
||||
* Requires both Ui.Core and Ui.Slider to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the droppable element.
|
||||
* @return string Completed Slider script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::slider() for options list.
|
||||
*/
|
||||
function slider($options = array()) {
|
||||
$callbacks = array('start', 'change', 'slide', 'stop');
|
||||
$template = '%s.slider({%s});';
|
||||
return $this->_methodTemplate('slider', $template, $options, $callbacks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a form attached to $selector. If the current selection is not an input or
|
||||
* form, errors will be created in the Javascript.
|
||||
*
|
||||
* @param array $options Options for the serialization
|
||||
* @return string completed form serialization script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::serializeForm() for option list.
|
||||
*/
|
||||
function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$selector = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selector = $this->selection . '.closest("form")';
|
||||
}
|
||||
$method = '.serialize()';
|
||||
if (!$options['inline']) {
|
||||
$method .= ';';
|
||||
}
|
||||
return $selector . $method;
|
||||
}
|
||||
}
|
1128
php-practice/web-cake/html/cake/libs/view/helpers/js.php
Normal file
1128
php-practice/web-cake/html/cake/libs/view/helpers/js.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
/**
|
||||
* MooTools Engine Helper for JsHelper
|
||||
*
|
||||
* Provides MooTools specific Javascript for JsHelper.
|
||||
* Assumes that you have the following MooTools packages
|
||||
*
|
||||
* - Remote, Remote.HTML, Remote.JSON
|
||||
* - Fx, Fx.Tween, Fx.Morph
|
||||
* - Selectors, DomReady,
|
||||
* - Drag, Drag.Move
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Helper', 'Js');
|
||||
|
||||
class MootoolsEngineHelper extends JsBaseEngineHelper {
|
||||
/**
|
||||
* Option mappings for MooTools
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_optionMap = array(
|
||||
'request' => array(
|
||||
'complete' => 'onComplete',
|
||||
'success' => 'onSuccess',
|
||||
'before' => 'onRequest',
|
||||
'error' => 'onFailure'
|
||||
),
|
||||
'sortable' => array(
|
||||
'distance' => 'snap',
|
||||
'containment' => 'constrain',
|
||||
'sort' => 'onSort',
|
||||
'complete' => 'onComplete',
|
||||
'start' => 'onStart',
|
||||
),
|
||||
'drag' => array(
|
||||
'snapGrid' => 'snap',
|
||||
'start' => 'onStart',
|
||||
'drag' => 'onDrag',
|
||||
'stop' => 'onComplete',
|
||||
),
|
||||
'drop' => array(
|
||||
'drop' => 'onDrop',
|
||||
'hover' => 'onEnter',
|
||||
'leave' => 'onLeave',
|
||||
),
|
||||
'slider' => array(
|
||||
'complete' => 'onComplete',
|
||||
'change' => 'onChange',
|
||||
'direction' => 'mode',
|
||||
'step' => 'steps'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Contains a list of callback names -> default arguments.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_callbackArguments = array(
|
||||
'slider' => array(
|
||||
'onTick' => 'position',
|
||||
'onChange' => 'step',
|
||||
'onComplete' => 'event'
|
||||
),
|
||||
'request' => array(
|
||||
'onRequest' => '',
|
||||
'onComplete' => '',
|
||||
'onCancel' => '',
|
||||
'onSuccess' => 'responseText, responseXML',
|
||||
'onFailure' => 'xhr',
|
||||
'onException' => 'headerName, value',
|
||||
),
|
||||
'drag' => array(
|
||||
'onBeforeStart' => 'element',
|
||||
'onStart' => 'element',
|
||||
'onSnap' => 'element',
|
||||
'onDrag' => 'element, event',
|
||||
'onComplete' => 'element, event',
|
||||
'onCancel' => 'element',
|
||||
),
|
||||
'drop' => array(
|
||||
'onBeforeStart' => 'element',
|
||||
'onStart' => 'element',
|
||||
'onSnap' => 'element',
|
||||
'onDrag' => 'element, event',
|
||||
'onComplete' => 'element, event',
|
||||
'onCancel' => 'element',
|
||||
'onDrop' => 'element, droppable, event',
|
||||
'onLeave' => 'element, droppable',
|
||||
'onEnter' => 'element, droppable',
|
||||
),
|
||||
'sortable' => array(
|
||||
'onStart' => 'element, clone',
|
||||
'onSort' => 'element, clone',
|
||||
'onComplete' => 'element',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return object instance of $this. Allows chained methods.
|
||||
*/
|
||||
function get($selector) {
|
||||
$this->_multipleSelection = false;
|
||||
if ($selector == 'window' || $selector == 'document') {
|
||||
$this->selection = "$(" . $selector .")";
|
||||
return $this;
|
||||
}
|
||||
if (preg_match('/^#[^\s.]+$/', $selector)) {
|
||||
$this->selection = '$("' . substr($selector, 1) . '")';
|
||||
return $this;
|
||||
}
|
||||
$this->_multipleSelection = true;
|
||||
$this->selection = '$$("' . $selector . '")';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the script cache. Operates on the currently selected elements.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults true)
|
||||
* - '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 array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
*/
|
||||
function event($type, $callback, $options = array()) {
|
||||
$defaults = array('wrap' => true, 'stop' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
|
||||
$function = 'function (event) {%s}';
|
||||
if ($options['wrap'] && $options['stop']) {
|
||||
$callback = "event.stop();\n" . $callback;
|
||||
}
|
||||
if ($options['wrap']) {
|
||||
$callback = sprintf($function, $callback);
|
||||
}
|
||||
$out = $this->selection . ".addEvent(\"{$type}\", $callback);";
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a domReady event. This is a special event in many libraries
|
||||
*
|
||||
* @param string $functionBody The code to run on domReady
|
||||
* @return string completed domReady method
|
||||
*/
|
||||
function domReady($functionBody) {
|
||||
$this->selection = 'window';
|
||||
return $this->event('domready', $functionBody, array('stop' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an iteration over the current selection result.
|
||||
*
|
||||
* @param string $method The method you want to apply to the selection
|
||||
* @param string $callback The function body you wish to apply during the iteration.
|
||||
* @return string completed iteration
|
||||
*/
|
||||
function each($callback) {
|
||||
return $this->selection . '.each(function (item, index) {' . $callback . '});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger an Effect.
|
||||
*
|
||||
* @param string $name The name of the effect to trigger.
|
||||
* @param array $options Array of options for the effect.
|
||||
* @return string completed string with effect.
|
||||
* @see JsBaseEngineHelper::effect()
|
||||
*/
|
||||
function effect($name, $options = array()) {
|
||||
$speed = null;
|
||||
if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
|
||||
if ($options['speed'] == 'fast') {
|
||||
$speed = '"short"';
|
||||
} elseif ($options['speed'] == 'slow') {
|
||||
$speed = '"long"';
|
||||
}
|
||||
}
|
||||
$effect = '';
|
||||
switch ($name) {
|
||||
case 'hide':
|
||||
$effect = 'setStyle("display", "none")';
|
||||
break;
|
||||
case 'show':
|
||||
$effect = 'setStyle("display", "")';
|
||||
break;
|
||||
case 'fadeIn':
|
||||
case 'fadeOut':
|
||||
case 'slideIn':
|
||||
case 'slideOut':
|
||||
list($effectName, $direction) = preg_split('/([A-Z][a-z]+)/', $name, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$direction = strtolower($direction);
|
||||
if ($speed) {
|
||||
$effect .= "set(\"$effectName\", {duration:$speed}).";
|
||||
}
|
||||
$effect .= "$effectName(\"$direction\")";
|
||||
break;
|
||||
}
|
||||
return $this->selection . '.' . $effect . ';';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an new Request.
|
||||
*
|
||||
* 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 mixed $url
|
||||
* @param array $options
|
||||
* @return string The completed ajax call.
|
||||
*/
|
||||
function request($url, $options = array()) {
|
||||
$url = $this->url($url);
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
$type = $data = null;
|
||||
if (isset($options['type']) || isset($options['update'])) {
|
||||
if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
$type = '.JSON';
|
||||
}
|
||||
if (isset($options['update'])) {
|
||||
$options['update'] = str_replace('#', '', $options['update']);
|
||||
$type = '.HTML';
|
||||
}
|
||||
unset($options['type']);
|
||||
}
|
||||
if (!empty($options['data'])) {
|
||||
$data = $options['data'];
|
||||
unset($options['data']);
|
||||
}
|
||||
$options['url'] = $url;
|
||||
$options = $this->_prepareCallbacks('request', $options);
|
||||
if (isset($options['dataExpression'])) {
|
||||
$callbacks[] = 'data';
|
||||
unset($options['dataExpression']);
|
||||
} elseif (!empty($data)) {
|
||||
$data = $this->object($data);
|
||||
}
|
||||
$options = $this->_parseOptions($options, array_keys($this->_callbackArguments['request']));
|
||||
return "var jsRequest = new Request$type({{$options}}).send($data);";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sortable element.
|
||||
*
|
||||
* Requires the `Sortables` plugin from MootoolsMore
|
||||
*
|
||||
* @param array $options Array of options for the sortable.
|
||||
* @return string Completed sortable script.
|
||||
* @see JsBaseEngineHelper::sortable() for options list.
|
||||
*/
|
||||
function sortable($options = array()) {
|
||||
$options = $this->_processOptions('sortable', $options);
|
||||
return 'var jsSortable = new Sortables(' . $this->selection . ', {' . $options . '});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Draggable element.
|
||||
*
|
||||
* Requires the `Drag` plugin from MootoolsMore
|
||||
*
|
||||
* @param array $options Array of options for the draggable.
|
||||
* @return string Completed draggable script.
|
||||
* @see JsHelper::drag() for options list.
|
||||
*/
|
||||
function drag($options = array()) {
|
||||
$options = $this->_processOptions('drag', $options);
|
||||
return $this->selection . '.makeDraggable({' . $options . '});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Droppable element.
|
||||
*
|
||||
* 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 addtion 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.
|
||||
*
|
||||
* @param array $options Array of options for the droppable.
|
||||
* @return string Completed droppable script.
|
||||
* @see JsBaseEngineHelper::drop() for options list.
|
||||
*/
|
||||
function drop($options = array()) {
|
||||
if (empty($options['drag'])) {
|
||||
trigger_error(
|
||||
__('MootoolsEngine::drop() requires a "drag" option to properly function', true), E_USER_WARNING
|
||||
);
|
||||
return false;
|
||||
}
|
||||
$options['droppables'] = $this->selection;
|
||||
|
||||
$this->get($options['drag']);
|
||||
unset($options['drag']);
|
||||
|
||||
$options = $this->_mapOptions('drag', $this->_mapOptions('drop', $options));
|
||||
$options = $this->_prepareCallbacks('drop', $options);
|
||||
$safe = array_merge(array_keys($this->_callbackArguments['drop']), array('droppables'));
|
||||
$optionString = $this->_parseOptions($options, $safe);
|
||||
$out = $this->selection . '.makeDraggable({' . $optionString . '});';
|
||||
$this->selection = $options['droppables'];
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a slider control
|
||||
*
|
||||
* Requires `Slider` from MootoolsMore
|
||||
*
|
||||
* @param array $options Array of options for the slider.
|
||||
* @return string Completed slider script.
|
||||
* @see JsBaseEngineHelper::slider() for options list.
|
||||
*/
|
||||
function slider($options = array()) {
|
||||
$slider = $this->selection;
|
||||
$this->get($options['handle']);
|
||||
unset($options['handle']);
|
||||
|
||||
if (isset($options['min']) && isset($options['max'])) {
|
||||
$options['range'] = array($options['min'], $options['max']);
|
||||
unset($options['min'], $options['max']);
|
||||
}
|
||||
$optionString = $this->_processOptions('slider', $options);
|
||||
if (!empty($optionString)) {
|
||||
$optionString = ', {' . $optionString . '}';
|
||||
}
|
||||
$out = 'var jsSlider = new Slider(' . $slider . ', ' . $this->selection . $optionString . ');';
|
||||
$this->selection = $slider;
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the form attached to $selector.
|
||||
*
|
||||
* @param array $options Array of options.
|
||||
* @return string Completed serializeForm() snippet
|
||||
* @see JsBaseEngineHelper::serializeForm()
|
||||
*/
|
||||
function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$selection = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selection = '$(' . $this->selection . '.form)';
|
||||
}
|
||||
$method = '.toQueryString()';
|
||||
if (!$options['inline']) {
|
||||
$method .= ';';
|
||||
}
|
||||
return $selection . $method;
|
||||
}
|
||||
}
|
257
php-practice/web-cake/html/cake/libs/view/helpers/number.php
Normal file
257
php-practice/web-cake/html/cake/libs/view/helpers/number.php
Normal file
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
/**
|
||||
* Number Helper.
|
||||
*
|
||||
* Methods to make numbers more readable.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Number helper library.
|
||||
*
|
||||
* Methods to make numbers more readable.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1452/Number
|
||||
*/
|
||||
class NumberHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Currencies supported by the helper. You can add additional currency formats
|
||||
* with NumberHelper::addFormat
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_currencies = array(
|
||||
'USD' => array(
|
||||
'before' => '$', 'after' => 'c', 'zero' => 0, 'places' => 2, 'thousands' => ',',
|
||||
'decimals' => '.', 'negative' => '()', 'escape' => true
|
||||
),
|
||||
'GBP' => array(
|
||||
'before'=>'£', 'after' => 'p', 'zero' => 0, 'places' => 2, 'thousands' => ',',
|
||||
'decimals' => '.', 'negative' => '()','escape' => false
|
||||
),
|
||||
'EUR' => array(
|
||||
'before'=>'€', 'after' => false, 'zero' => 0, 'places' => 2, 'thousands' => '.',
|
||||
'decimals' => ',', 'negative' => '()', 'escape' => false
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Default options for currency formats
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_currencyDefaults = array(
|
||||
'before'=>'', 'after' => '', 'zero' => '0', 'places' => 2, 'thousands' => ',',
|
||||
'decimals' => '.','negative' => '()', 'escape' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Formats a number with a level of precision.
|
||||
*
|
||||
* @param float $number A floating point number.
|
||||
* @param integer $precision The precision of the returned number.
|
||||
* @return float Formatted float.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1454/precision
|
||||
*/
|
||||
function precision($number, $precision = 3) {
|
||||
return sprintf("%01.{$precision}f", $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted-for-humans file size.
|
||||
*
|
||||
* @param integer $length Size in bytes
|
||||
* @return string Human readable size
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1456/toReadableSize
|
||||
*/
|
||||
function toReadableSize($size) {
|
||||
switch (true) {
|
||||
case $size < 1024:
|
||||
return sprintf(__n('%d Byte', '%d Bytes', $size, true), $size);
|
||||
case round($size / 1024) < 1024:
|
||||
return sprintf(__('%d KB', true), $this->precision($size / 1024, 0));
|
||||
case round($size / 1024 / 1024, 2) < 1024:
|
||||
return sprintf(__('%.2f MB', true), $this->precision($size / 1024 / 1024, 2));
|
||||
case round($size / 1024 / 1024 / 1024, 2) < 1024:
|
||||
return sprintf(__('%.2f GB', true), $this->precision($size / 1024 / 1024 / 1024, 2));
|
||||
default:
|
||||
return sprintf(__('%.2f TB', true), $this->precision($size / 1024 / 1024 / 1024 / 1024, 2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number into a percentage string.
|
||||
*
|
||||
* @param float $number A floating point number
|
||||
* @param integer $precision The precision of the returned number
|
||||
* @return string Percentage string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1455/toPercentage
|
||||
*/
|
||||
function toPercentage($number, $precision = 2) {
|
||||
return $this->precision($number, $precision) . '%';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* or array with places and before keys
|
||||
* @return string formatted number
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1457/format
|
||||
*/
|
||||
function format($number, $options = false) {
|
||||
$places = 0;
|
||||
if (is_int($options)) {
|
||||
$places = $options;
|
||||
}
|
||||
|
||||
$separators = array(',', '.', '-', ':');
|
||||
|
||||
$before = $after = null;
|
||||
if (is_string($options) && !in_array($options, $separators)) {
|
||||
$before = $options;
|
||||
}
|
||||
$thousands = ',';
|
||||
if (!is_array($options) && in_array($options, $separators)) {
|
||||
$thousands = $options;
|
||||
}
|
||||
$decimals = '.';
|
||||
if (!is_array($options) && in_array($options, $separators)) {
|
||||
$decimals = $options;
|
||||
}
|
||||
|
||||
$escape = true;
|
||||
if (is_array($options)) {
|
||||
$options = array_merge(array('before'=>'$', 'places' => 2, 'thousands' => ',', 'decimals' => '.'), $options);
|
||||
extract($options);
|
||||
}
|
||||
|
||||
$out = $before . number_format($number, $places, $decimals, $thousands) . $after;
|
||||
|
||||
if ($escape) {
|
||||
return h($out);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number into a currency format.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `before` - The currency symbol to place before whole numbers ie. '$'
|
||||
* - `after` - The currency symbol to place after decimal numbers ie. 'c'. Set to boolean false to
|
||||
* use no decimal symbol. eg. 0.35 => $0.35.
|
||||
* - `zero` - The text to use for zero values, can be a string or a number. ie. 0, 'Free!'
|
||||
* - `places` - Number of decimal places to use. ie. 2
|
||||
* - `thousands` - Thousands separator ie. ','
|
||||
* - `decimals` - Decimal separator symbol ie. '.'
|
||||
* - `negative` - Symbol for negative numbers. If equal to '()', the number will be wrapped with ( and )
|
||||
* - `escape` - Should the output be htmlentity escaped? Defaults to true
|
||||
*
|
||||
* @param float $number
|
||||
* @param string $currency Shortcut to default options. Valid values are 'USD', 'EUR', 'GBP', otherwise
|
||||
* set at least 'before' and 'after' options.
|
||||
* @param array $options
|
||||
* @return string Number formatted as a currency.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1453/currency
|
||||
*/
|
||||
function currency($number, $currency = 'USD', $options = array()) {
|
||||
$default = $this->_currencyDefaults;
|
||||
|
||||
if (isset($this->_currencies[$currency])) {
|
||||
$default = $this->_currencies[$currency];
|
||||
} elseif (is_string($currency)) {
|
||||
$options['before'] = $currency;
|
||||
}
|
||||
|
||||
$options = array_merge($default, $options);
|
||||
|
||||
$result = null;
|
||||
|
||||
if ($number == 0 ) {
|
||||
if ($options['zero'] !== 0 ) {
|
||||
return $options['zero'];
|
||||
}
|
||||
$options['after'] = null;
|
||||
} elseif ($number < 1 && $number > -1 ) {
|
||||
if ($options['after'] !== false) {
|
||||
$multiply = intval('1' . str_pad('', $options['places'], '0'));
|
||||
$number = $number * $multiply;
|
||||
$options['before'] = null;
|
||||
$options['places'] = null;
|
||||
}
|
||||
} elseif (empty($options['before'])) {
|
||||
$options['before'] = null;
|
||||
} else {
|
||||
$options['after'] = null;
|
||||
}
|
||||
|
||||
$abs = abs($number);
|
||||
$result = $this->format($abs, $options);
|
||||
|
||||
if ($number < 0 ) {
|
||||
if ($options['negative'] == '()') {
|
||||
$result = '(' . $result .')';
|
||||
} else {
|
||||
$result = $options['negative'] . $result;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a currency format to the Number helper. Makes reusing
|
||||
* currency formats easier.
|
||||
*
|
||||
* {{{ $number->addFormat('NOK', array('before' => 'Kr. ')); }}}
|
||||
*
|
||||
* You can now use `NOK` as a shortform when formatting currency amounts.
|
||||
*
|
||||
* {{{ $number->currency($value, 'NOK'); }}}
|
||||
*
|
||||
* Added formats are merged with the following defaults.
|
||||
*
|
||||
* {{{
|
||||
* array(
|
||||
* 'before' => '$', 'after' => 'c', 'zero' => 0, 'places' => 2, 'thousands' => ',',
|
||||
* 'decimals' => '.', 'negative' => '()', 'escape' => true
|
||||
* )
|
||||
* }}}
|
||||
*
|
||||
* @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()
|
||||
* @access public
|
||||
*/
|
||||
function addFormat($formatName, $options) {
|
||||
$this->_currencies[$formatName] = $options + $this->_currencyDefaults;
|
||||
}
|
||||
|
||||
}
|
813
php-practice/web-cake/html/cake/libs/view/helpers/paginator.php
Normal file
813
php-practice/web-cake/html/cake/libs/view/helpers/paginator.php
Normal file
@@ -0,0 +1,813 @@
|
||||
<?php
|
||||
/**
|
||||
* Pagination Helper class file.
|
||||
*
|
||||
* Generates pagination links
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pagination Helper class for easy generation of pagination links.
|
||||
*
|
||||
* PaginationHelper encloses all methods needed when working with pagination.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1458/Paginator
|
||||
*/
|
||||
class PaginatorHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Helper dependencies
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* Holds the default model for paged recordsets
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $__defaultModel = null;
|
||||
|
||||
/**
|
||||
* The class used for 'Ajax' pagination links.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_ajaxHelperClass = 'Js';
|
||||
|
||||
/**
|
||||
* Holds the default options for pagination links
|
||||
*
|
||||
* The values that may be specified are:
|
||||
*
|
||||
* - `$options['format']` Format of the counter. Supported formats are 'range' and 'pages'
|
||||
* and custom (default). In the default mode the supplied string is parsed and constants are replaced
|
||||
* by their actual values.
|
||||
* Constants: %page%, %pages%, %current%, %count%, %start%, %end% .
|
||||
* - `$options['separator']` The separator of the actual page and number of pages (default: ' of ').
|
||||
* - `$options['url']` Url of the action. See Router::url()
|
||||
* - `$options['url']['sort']` the key that the recordset is sorted.
|
||||
* - `$options['url']['direction']` Direction of the sorting (default: 'asc').
|
||||
* - `$options['url']['page']` Page # to display.
|
||||
* - `$options['model']` The name of the model.
|
||||
* - `$options['escape']` Defines if the title field for the link should be escaped (default: true).
|
||||
* - `$options['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.
|
||||
* - `$options['indicator']` DOM id of the element that will be shown when doing AJAX requests. **Only supported by
|
||||
* AjaxHelper**
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $options = array();
|
||||
|
||||
/**
|
||||
* Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
|
||||
*
|
||||
* Use `var $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
|
||||
* adapter before including PaginatorHelper in your helpers array.
|
||||
*
|
||||
* The chosen custom helper must implement a `link()` method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct($config = array()) {
|
||||
$ajaxProvider = isset($config['ajax']) ? $config['ajax'] : 'Js';
|
||||
$this->helpers[] = $ajaxProvider;
|
||||
$this->_ajaxHelperClass = $ajaxProvider;
|
||||
|
||||
App::import('Helper', $ajaxProvider);
|
||||
$classname = $ajaxProvider . 'Helper';
|
||||
if (!is_callable(array($classname, 'link'))) {
|
||||
trigger_error(sprintf(__('%s does not implement a link() method, it is incompatible with PaginatorHelper', true), $classname), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Before render callback. Overridden to merge passed args with url options.
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function beforeRender() {
|
||||
$this->options['url'] = array_merge($this->params['pass'], $this->params['named']);
|
||||
|
||||
parent::beforeRender();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return array The array of paging parameters for the paginated resultset.
|
||||
* @access public
|
||||
*/
|
||||
function params($model = null) {
|
||||
if (empty($model)) {
|
||||
$model = $this->defaultModel();
|
||||
}
|
||||
if (!isset($this->params['paging']) || empty($this->params['paging'][$model])) {
|
||||
return null;
|
||||
}
|
||||
return $this->params['paging'][$model];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default options for all pagination links
|
||||
*
|
||||
* @param mixed $options Default options for pagination links. If a string is supplied - it
|
||||
* is used as the DOM id element to update. See PaginatorHelper::$options for list of keys.
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function options($options = array()) {
|
||||
if (is_string($options)) {
|
||||
$options = array('update' => $options);
|
||||
}
|
||||
|
||||
if (!empty($options['paging'])) {
|
||||
if (!isset($this->params['paging'])) {
|
||||
$this->params['paging'] = array();
|
||||
}
|
||||
$this->params['paging'] = array_merge($this->params['paging'], $options['paging']);
|
||||
unset($options['paging']);
|
||||
}
|
||||
$model = $this->defaultModel();
|
||||
|
||||
if (!empty($options[$model])) {
|
||||
if (!isset($this->params['paging'][$model])) {
|
||||
$this->params['paging'][$model] = array();
|
||||
}
|
||||
$this->params['paging'][$model] = array_merge(
|
||||
$this->params['paging'][$model], $options[$model]
|
||||
);
|
||||
unset($options[$model]);
|
||||
}
|
||||
$this->options = array_filter(array_merge($this->options, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current page of the recordset for the given model
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return string The current page number of the recordset.
|
||||
* @access public
|
||||
*/
|
||||
function current($model = null) {
|
||||
$params = $this->params($model);
|
||||
|
||||
if (isset($params['page'])) {
|
||||
return $params['page'];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current key by which the recordset is sorted
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param mixed $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
|
||||
* null if the results are not currently sorted.
|
||||
* @access public
|
||||
*/
|
||||
function sortKey($model = null, $options = array()) {
|
||||
if (empty($options)) {
|
||||
$params = $this->params($model);
|
||||
$options = array_merge($params['defaults'], $params['options']);
|
||||
}
|
||||
|
||||
if (isset($options['sort']) && !empty($options['sort'])) {
|
||||
return $options['sort'];
|
||||
} elseif (isset($options['order']) && is_array($options['order'])) {
|
||||
return key($options['order']);
|
||||
} elseif (isset($options['order']) && is_string($options['order'])) {
|
||||
return $options['order'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current direction the recordset is sorted
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param mixed $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.
|
||||
* @access public
|
||||
*/
|
||||
function sortDir($model = null, $options = array()) {
|
||||
$dir = null;
|
||||
|
||||
if (empty($options)) {
|
||||
$params = $this->params($model);
|
||||
$options = array_merge($params['defaults'], $params['options']);
|
||||
}
|
||||
|
||||
if (isset($options['direction'])) {
|
||||
$dir = strtolower($options['direction']);
|
||||
} elseif (isset($options['order']) && is_array($options['order'])) {
|
||||
$dir = strtolower(current($options['order']));
|
||||
}
|
||||
|
||||
if ($dir == 'desc') {
|
||||
return 'desc';
|
||||
}
|
||||
return 'asc';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a "previous" link for a set of paged records
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `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. Defaults to '<< Previous'.
|
||||
* @param mixed $options Options for pagination link. See #options for list of keys.
|
||||
* @param string $disabledTitle Title when the link is disabled.
|
||||
* @param mixed $disabledOptions Options for the disabled pagination link. See #options for list of keys.
|
||||
* @return string A "previous" link or $disabledTitle text if the link is disabled.
|
||||
* @access public
|
||||
*/
|
||||
function prev($title = '<< Previous', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
||||
return $this->__pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a "next" link for a set of paged records
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `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. Defaults to 'Next >>'.
|
||||
* @param mixed $options Options for pagination link. See above for list of keys.
|
||||
* @param string $disabledTitle Title when the link is disabled.
|
||||
* @param mixed $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.
|
||||
* @access public
|
||||
*/
|
||||
function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
||||
return $this->__pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*
|
||||
* @param string $title Title for the link.
|
||||
* @param string $key The name of the key that the recordset should be sorted. If $key is null
|
||||
* $title will be used for the key, and a title will be generated by inflection.
|
||||
* @param array $options Options for sorting link. See above for list of keys.
|
||||
* @return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified
|
||||
* key the returned link will sort by 'desc'.
|
||||
* @access public
|
||||
*/
|
||||
function sort($title, $key = null, $options = array()) {
|
||||
$options = array_merge(array('url' => array(), 'model' => null), $options);
|
||||
$url = $options['url'];
|
||||
unset($options['url']);
|
||||
|
||||
if (empty($key)) {
|
||||
$key = $title;
|
||||
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)), true);
|
||||
}
|
||||
$dir = isset($options['direction']) ? $options['direction'] : 'asc';
|
||||
unset($options['direction']);
|
||||
|
||||
$sortKey = $this->sortKey($options['model']);
|
||||
$defaultModel = $this->defaultModel();
|
||||
$isSorted = (
|
||||
$sortKey === $key ||
|
||||
$sortKey === $defaultModel . '.' . $key ||
|
||||
$key === $defaultModel . '.' . $sortKey
|
||||
);
|
||||
|
||||
if ($isSorted) {
|
||||
$dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
|
||||
$class = $dir === 'asc' ? 'desc' : 'asc';
|
||||
if (!empty($options['class'])) {
|
||||
$options['class'] .= ' ' . $class;
|
||||
} else {
|
||||
$options['class'] = $class;
|
||||
}
|
||||
}
|
||||
if (is_array($title) && array_key_exists($dir, $title)) {
|
||||
$title = $title[$dir];
|
||||
}
|
||||
|
||||
$url = array_merge(array('sort' => $key, 'direction' => $dir), $url, array('order' => null));
|
||||
return $this->link($title, $url, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a plain or Ajax link with pagination parameters
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `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 mixed $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.
|
||||
* @access public
|
||||
*/
|
||||
function link($title, $url = array(), $options = array()) {
|
||||
$options = array_merge(array('model' => null, 'escape' => true), $options);
|
||||
$model = $options['model'];
|
||||
unset($options['model']);
|
||||
|
||||
if (!empty($this->options)) {
|
||||
$options = array_merge($this->options, $options);
|
||||
}
|
||||
if (isset($options['url'])) {
|
||||
$url = array_merge((array)$options['url'], (array)$url);
|
||||
unset($options['url']);
|
||||
}
|
||||
$url = $this->url($url, true, $model);
|
||||
|
||||
$obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html';
|
||||
$url = array_merge(array('page' => $this->current($model)), $url);
|
||||
$url = array_merge(Set::filter($url, true), array_intersect_key($url, array('plugin' => true)));
|
||||
return $this->{$obj}->link($title, $url, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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)
|
||||
* @access public
|
||||
*/
|
||||
function url($options = array(), $asArray = false, $model = null) {
|
||||
$paging = $this->params($model);
|
||||
$url = array_merge(array_filter(Set::diff(array_merge(
|
||||
$paging['defaults'], $paging['options']), $paging['defaults'])), $options
|
||||
);
|
||||
|
||||
if (isset($url['order'])) {
|
||||
$sort = $direction = null;
|
||||
if (is_array($url['order'])) {
|
||||
list($sort, $direction) = array($this->sortKey($model, $url), current($url['order']));
|
||||
}
|
||||
unset($url['order']);
|
||||
$url = array_merge($url, compact('sort', 'direction'));
|
||||
}
|
||||
|
||||
if ($asArray) {
|
||||
return $url;
|
||||
}
|
||||
return parent::url($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protected method for generating prev/next links
|
||||
*
|
||||
* @access 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)
|
||||
);
|
||||
$options = array_merge($_defaults, (array)$options);
|
||||
$paging = $this->params($options['model']);
|
||||
if (empty($disabledOptions)) {
|
||||
$disabledOptions = $options;
|
||||
}
|
||||
|
||||
if (!$this->{$check}($options['model']) && (!empty($disabledTitle) || !empty($disabledOptions))) {
|
||||
if (!empty($disabledTitle) && $disabledTitle !== true) {
|
||||
$title = $disabledTitle;
|
||||
}
|
||||
$options = array_merge($_defaults, (array)$disabledOptions);
|
||||
} elseif (!$this->{$check}($options['model'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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', 'class'))));
|
||||
} else {
|
||||
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @access public
|
||||
*/
|
||||
function hasPrev($model = null) {
|
||||
return $this->__hasPage($model, 'prev');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @access public
|
||||
*/
|
||||
function hasNext($model = null) {
|
||||
return $this->__hasPage($model, 'next');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $page The page number - if not set defaults to 1.
|
||||
* @return boolean True if the given result set has the specified page number.
|
||||
* @access public
|
||||
*/
|
||||
function hasPage($model = null, $page = 1) {
|
||||
if (is_numeric($model)) {
|
||||
$page = $model;
|
||||
$model = null;
|
||||
}
|
||||
$paging = $this->params($model);
|
||||
return $page <= $paging['pageCount'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @access protected
|
||||
*/
|
||||
function __hasPage($model, $page) {
|
||||
$params = $this->params($model);
|
||||
if (!empty($params)) {
|
||||
if ($params["{$page}Page"] == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default model of the paged sets
|
||||
*
|
||||
* @return string Model name or null if the pagination isn't initialized.
|
||||
* @access public
|
||||
*/
|
||||
function defaultModel() {
|
||||
if ($this->__defaultModel != null) {
|
||||
return $this->__defaultModel;
|
||||
}
|
||||
if (empty($this->params['paging'])) {
|
||||
return null;
|
||||
}
|
||||
list($this->__defaultModel) = array_keys($this->params['paging']);
|
||||
return $this->__defaultModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a counter string for the paged result set
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `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
|
||||
* the following placeholders `%page%`, `%pages%`, `%current%`, `%count%`, `%start%`, `%end%` and any
|
||||
* custom content you would like.
|
||||
* - `separator` The separator string to use, default to ' of '
|
||||
*
|
||||
* @param mixed $options Options for the counter string. See #options for list of keys.
|
||||
* @return string Counter string.
|
||||
* @access public
|
||||
*/
|
||||
function counter($options = array()) {
|
||||
if (is_string($options)) {
|
||||
$options = array('format' => $options);
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
array(
|
||||
'model' => $this->defaultModel(),
|
||||
'format' => 'pages',
|
||||
'separator' => __(' of ', true)
|
||||
),
|
||||
$options);
|
||||
|
||||
$paging = $this->params($options['model']);
|
||||
if ($paging['pageCount'] == 0) {
|
||||
$paging['pageCount'] = 1;
|
||||
}
|
||||
$start = 0;
|
||||
if ($paging['count'] >= 1) {
|
||||
$start = (($paging['page'] - 1) * $paging['options']['limit']) + 1;
|
||||
}
|
||||
$end = $start + $paging['options']['limit'] - 1;
|
||||
if ($paging['count'] < $end) {
|
||||
$end = $paging['count'];
|
||||
}
|
||||
|
||||
switch ($options['format']) {
|
||||
case 'range':
|
||||
if (!is_array($options['separator'])) {
|
||||
$options['separator'] = array(' - ', $options['separator']);
|
||||
}
|
||||
$out = $start . $options['separator'][0] . $end . $options['separator'][1];
|
||||
$out .= $paging['count'];
|
||||
break;
|
||||
case 'pages':
|
||||
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
|
||||
break;
|
||||
default:
|
||||
$map = array(
|
||||
'%page%' => $paging['page'],
|
||||
'%pages%' => $paging['pageCount'],
|
||||
'%current%' => $paging['current'],
|
||||
'%count%' => $paging['count'],
|
||||
'%start%' => $start,
|
||||
'%end%' => $end
|
||||
);
|
||||
$out = str_replace(array_keys($map), array_values($map), $options['format']);
|
||||
|
||||
$newKeys = array(
|
||||
'{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}'
|
||||
);
|
||||
$out = str_replace($newKeys, array_values($map), $out);
|
||||
break;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of numbers for the paged result set
|
||||
* uses a modulus to decide how many numbers to show on each side of the current page (default: 8)
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `before` Content to be inserted before the numbers
|
||||
* - `after` Content to be inserted after the numbers
|
||||
* - `model` Model to create numbers for, defaults to PaginatorHelper::defaultModel()
|
||||
* - `modulus` how many numbers to include on either side of the current page, defaults to 8.
|
||||
* - `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
|
||||
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
|
||||
* links to generate
|
||||
*
|
||||
* @param mixed $options Options for the numbers, (before, after, model, modulus, separator)
|
||||
* @return string numbers string.
|
||||
* @access public
|
||||
*/
|
||||
function numbers($options = array()) {
|
||||
if ($options === true) {
|
||||
$options = array(
|
||||
'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'
|
||||
);
|
||||
}
|
||||
|
||||
$defaults = array(
|
||||
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(),
|
||||
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null,
|
||||
);
|
||||
$options += $defaults;
|
||||
|
||||
$params = (array)$this->params($options['model']) + array('page'=> 1);
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
extract($options);
|
||||
unset($options['tag'], $options['before'], $options['after'], $options['model'],
|
||||
$options['modulus'], $options['separator'], $options['first'], $options['last']);
|
||||
|
||||
$out = '';
|
||||
|
||||
if ($modulus && $params['pageCount'] > $modulus) {
|
||||
$half = intval($modulus / 2);
|
||||
$end = $params['page'] + $half;
|
||||
|
||||
if ($end > $params['pageCount']) {
|
||||
$end = $params['pageCount'];
|
||||
}
|
||||
$start = $params['page'] - ($modulus - ($end - $params['page']));
|
||||
if ($start <= 1) {
|
||||
$start = 1;
|
||||
$end = $params['page'] + ($modulus - $params['page']) + 1;
|
||||
}
|
||||
|
||||
if ($first && $start > 1) {
|
||||
$offset = ($start <= (int)$first) ? $start - 1 : $first;
|
||||
if ($offset < $start - 1) {
|
||||
$out .= $this->first($offset, array('tag' => $tag, 'separator' => $separator));
|
||||
} else {
|
||||
$out .= $this->first($offset, array('tag' => $tag, 'after' => $separator, 'separator' => $separator));
|
||||
}
|
||||
}
|
||||
|
||||
$out .= $before;
|
||||
|
||||
for ($i = $start; $i < $params['page']; $i++) {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
|
||||
. $separator;
|
||||
}
|
||||
|
||||
$out .= $this->Html->tag($tag, $params['page'], array('class' => 'current'));
|
||||
if ($i != $params['pageCount']) {
|
||||
$out .= $separator;
|
||||
}
|
||||
|
||||
$start = $params['page'] + 1;
|
||||
for ($i = $start; $i < $end; $i++) {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
|
||||
. $separator;
|
||||
}
|
||||
|
||||
if ($end != $params['page']) {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $end), $options));
|
||||
}
|
||||
|
||||
$out .= $after;
|
||||
|
||||
if ($last && $end < $params['pageCount']) {
|
||||
$offset = ($params['pageCount'] < $end + (int)$last) ? $params['pageCount'] - $end : $last;
|
||||
if ($offset <= $last && $params['pageCount'] - $end > $offset) {
|
||||
$out .= $this->last($offset, array('tag' => $tag, 'separator' => $separator));
|
||||
} else {
|
||||
$out .= $this->last($offset, array('tag' => $tag, 'before' => $separator, 'separator' => $separator));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$out .= $before;
|
||||
|
||||
for ($i = 1; $i <= $params['pageCount']; $i++) {
|
||||
if ($i == $params['page']) {
|
||||
$out .= $this->Html->tag($tag, $i, array('class' => 'current'));
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
|
||||
}
|
||||
if ($i != $params['pageCount']) {
|
||||
$out .= $separator;
|
||||
}
|
||||
}
|
||||
|
||||
$out .= $after;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a first or set of numbers for the first pages
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `before` Content to insert before the link/tag
|
||||
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
||||
* - `separator` Content between the generated links, defaults to ' | '
|
||||
*
|
||||
* @param mixed $first if string use as label for the link, if numeric print page numbers
|
||||
* @param mixed $options
|
||||
* @return string numbers string.
|
||||
* @access public
|
||||
*/
|
||||
function first($first = '<< first', $options = array()) {
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'after'=> null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
),
|
||||
(array)$options);
|
||||
|
||||
$params = array_merge(array('page'=> 1), (array)$this->params($options['model']));
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
}
|
||||
extract($options);
|
||||
unset($options['tag'], $options['after'], $options['model'], $options['separator']);
|
||||
|
||||
$out = '';
|
||||
|
||||
if (is_int($first) && $params['page'] > $first) {
|
||||
if ($after === null) {
|
||||
$after = '...';
|
||||
}
|
||||
for ($i = 1; $i <= $first; $i++) {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
|
||||
if ($i != $first) {
|
||||
$out .= $separator;
|
||||
}
|
||||
}
|
||||
$out .= $after;
|
||||
} elseif ($params['page'] > 1) {
|
||||
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options))
|
||||
. $after;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a last or set of numbers for the last pages
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `before` Content to insert before the link/tag
|
||||
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
||||
* - `separator` Content between the generated links, defaults to ' | '
|
||||
*
|
||||
* @param mixed $last if string use as label for the link, if numeric print page numbers
|
||||
* @param mixed $options Array of options
|
||||
* @return string numbers string.
|
||||
* @access public
|
||||
*/
|
||||
function last($last = 'last >>', $options = array()) {
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'before'=> null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
),
|
||||
(array)$options);
|
||||
|
||||
$params = array_merge(array('page'=> 1), (array)$this->params($options['model']));
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
extract($options);
|
||||
unset($options['tag'], $options['before'], $options['model'], $options['separator']);
|
||||
|
||||
$out = '';
|
||||
$lower = $params['pageCount'] - $last + 1;
|
||||
|
||||
if (is_int($last) && $params['page'] < $lower) {
|
||||
if ($before === null) {
|
||||
$before = '...';
|
||||
}
|
||||
for ($i = $lower; $i <= $params['pageCount']; $i++) {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options));
|
||||
if ($i != $params['pageCount']) {
|
||||
$out .= $separator;
|
||||
}
|
||||
}
|
||||
$out = $before . $out;
|
||||
} elseif ($params['page'] < $params['pageCount']) {
|
||||
$out = $before . $this->Html->tag(
|
||||
$tag, $this->link($last, array('page' => $params['pageCount']), $options
|
||||
));
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
/**
|
||||
* Prototype Engine Helper for JsHelper
|
||||
*
|
||||
* Provides Prototype specific Javascript for JsHelper. Requires at least
|
||||
* Prototype 1.6
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Helper', 'Js');
|
||||
|
||||
class PrototypeEngineHelper extends JsBaseEngineHelper {
|
||||
/**
|
||||
* Is the current selection a multiple selection? or is it just a single element.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $_multiple = false;
|
||||
|
||||
/**
|
||||
* Option mappings for Prototype
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_optionMap = array(
|
||||
'request' => array(
|
||||
'async' => 'asynchronous',
|
||||
'data' => 'parameters',
|
||||
'before' => 'onCreate',
|
||||
'success' => 'onSuccess',
|
||||
'complete' => 'onComplete',
|
||||
'error' => 'onFailure'
|
||||
),
|
||||
'sortable' => array(
|
||||
'start' => 'onStart',
|
||||
'sort' => 'onChange',
|
||||
'complete' => 'onUpdate',
|
||||
'distance' => 'snap',
|
||||
),
|
||||
'drag' => array(
|
||||
'snapGrid' => 'snap',
|
||||
'container' => 'constraint',
|
||||
'stop' => 'onEnd',
|
||||
'start' => 'onStart',
|
||||
'drag' => 'onDrag',
|
||||
),
|
||||
'drop' => array(
|
||||
'hover' => 'onHover',
|
||||
'drop' => 'onDrop',
|
||||
'hoverClass' => 'hoverclass',
|
||||
),
|
||||
'slider' => array(
|
||||
'direction' => 'axis',
|
||||
'change' => 'onSlide',
|
||||
'complete' => 'onChange',
|
||||
'value' => 'sliderValue',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Contains a list of callback names -> default arguments.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_callbackArguments = array(
|
||||
'slider' => array(
|
||||
'onSlide' => 'value',
|
||||
'onChange' => 'value',
|
||||
),
|
||||
'drag' => array(
|
||||
'onStart' => 'event',
|
||||
'onDrag' => 'event',
|
||||
'change' => 'draggable',
|
||||
'onEnd' => 'event',
|
||||
),
|
||||
'drop' => array(
|
||||
'onHover' => 'draggable, droppable, event',
|
||||
'onDrop' => 'draggable, droppable, event',
|
||||
),
|
||||
'request' => array(
|
||||
'onCreate' => 'transport',
|
||||
'onComplete' => 'transport',
|
||||
'onFailure' => 'response, jsonHeader',
|
||||
'onRequest' => 'transport',
|
||||
'onSuccess' => 'response, jsonHeader'
|
||||
),
|
||||
'sortable' => array(
|
||||
'onStart' => 'element',
|
||||
'onChange' => 'element',
|
||||
'onUpdate' => 'element',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Create javascript selector for a CSS rule
|
||||
*
|
||||
* @param string $selector The selector that is targeted
|
||||
* @return object instance of $this. Allows chained methods.
|
||||
*/
|
||||
function get($selector) {
|
||||
$this->_multiple = false;
|
||||
if ($selector == 'window' || $selector == 'document') {
|
||||
$this->selection = "$(" . $selector .")";
|
||||
return $this;
|
||||
}
|
||||
if (preg_match('/^#[^\s.]+$/', $selector)) {
|
||||
$this->selection = '$("' . substr($selector, 1) . '")';
|
||||
return $this;
|
||||
}
|
||||
$this->_multiple = true;
|
||||
$this->selection = '$$("' . $selector . '")';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the script cache. Operates on the currently selected elements.
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `wrap` - Whether you want the callback wrapped in an anonymous function. (defaults true)
|
||||
* - `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 array $options Options for the event.
|
||||
* @return string completed event handler
|
||||
*/
|
||||
function event($type, $callback, $options = array()) {
|
||||
$defaults = array('wrap' => true, 'stop' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
|
||||
$function = 'function (event) {%s}';
|
||||
if ($options['wrap'] && $options['stop']) {
|
||||
$callback = "event.stop();\n" . $callback;
|
||||
}
|
||||
if ($options['wrap']) {
|
||||
$callback = sprintf($function, $callback);
|
||||
}
|
||||
$out = $this->selection . ".observe(\"{$type}\", $callback);";
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a domReady event. This is a special event in many libraries
|
||||
*
|
||||
* @param string $functionBody The code to run on domReady
|
||||
* @return string completed domReady method
|
||||
* @access public
|
||||
*/
|
||||
function domReady($functionBody) {
|
||||
$this->selection = 'document';
|
||||
return $this->event('dom:loaded', $functionBody, array('stop' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an iteration over the current selection result.
|
||||
*
|
||||
* @param string $method The method you want to apply to the selection
|
||||
* @param string $callback The function body you wish to apply during the iteration.
|
||||
* @return string completed iteration
|
||||
* @access public
|
||||
*/
|
||||
function each($callback) {
|
||||
return $this->selection . '.each(function (item, index) {' . $callback . '});';
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger an Effect.
|
||||
*
|
||||
* ### Note: Effects require Scriptaculous to be loaded.
|
||||
*
|
||||
* @param string $name The name of the effect to trigger.
|
||||
* @param array $options Array of options for the effect.
|
||||
* @return string completed string with effect.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::effect()
|
||||
*/
|
||||
function effect($name, $options = array()) {
|
||||
$effect = '';
|
||||
$optionString = null;
|
||||
if (isset($options['speed'])) {
|
||||
if ($options['speed'] == 'fast') {
|
||||
$options['duration'] = 0.5;
|
||||
} elseif ($options['speed'] == 'slow') {
|
||||
$options['duration'] = 2;
|
||||
} else {
|
||||
$options['duration'] = 1;
|
||||
}
|
||||
unset($options['speed']);
|
||||
}
|
||||
if (!empty($options)) {
|
||||
$optionString = ', {' . $this->_parseOptions($options) . '}';
|
||||
}
|
||||
switch ($name) {
|
||||
case 'hide':
|
||||
case 'show':
|
||||
$effect = $this->selection . '.' . $name . '();';
|
||||
break;
|
||||
case 'slideIn':
|
||||
case 'slideOut':
|
||||
$name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
|
||||
$effect = 'Effect.' . $name . '(' . $this->selection . $optionString . ');';
|
||||
break;
|
||||
case 'fadeIn':
|
||||
case 'fadeOut':
|
||||
$name = ($name == 'fadeIn') ? 'appear' : 'fade';
|
||||
$effect = $this->selection . '.' . $name .'(' . substr($optionString, 2) . ');';
|
||||
break;
|
||||
}
|
||||
return $effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an Ajax or Ajax.Updater call.
|
||||
*
|
||||
* @param mixed $url
|
||||
* @param array $options
|
||||
* @return string The completed ajax call.
|
||||
* @access public
|
||||
*/
|
||||
function request($url, $options = array()) {
|
||||
$url = '"'. $this->url($url) . '"';
|
||||
$options = $this->_mapOptions('request', $options);
|
||||
$type = '.Request';
|
||||
$data = null;
|
||||
if (isset($options['type']) && strtolower($options['type']) == 'json') {
|
||||
unset($options['type']);
|
||||
}
|
||||
if (isset($options['update'])) {
|
||||
$url = '"' . str_replace('#', '', $options['update']) . '", ' . $url;
|
||||
$type = '.Updater';
|
||||
unset($options['update'], $options['type']);
|
||||
}
|
||||
$safe = array_keys($this->_callbackArguments['request']);
|
||||
$options = $this->_prepareCallbacks('request', $options, $safe);
|
||||
if (isset($options['dataExpression'])) {
|
||||
$safe[] = 'parameters';
|
||||
unset($options['dataExpression']);
|
||||
}
|
||||
$options = $this->_parseOptions($options, $safe);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return "var jsRequest = new Ajax$type($url$options);";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sortable element.
|
||||
*
|
||||
* #### Note: Requires scriptaculous to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the sortable.
|
||||
* @return string Completed sortable script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::sortable() for options list.
|
||||
*/
|
||||
function sortable($options = array()) {
|
||||
$options = $this->_processOptions('sortable', $options);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return 'var jsSortable = Sortable.create(' . $this->selection . $options . ');';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Draggable element.
|
||||
*
|
||||
* #### Note: Requires scriptaculous to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the draggable.
|
||||
* @return string Completed draggable script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::draggable() for options list.
|
||||
*/
|
||||
function drag($options = array()) {
|
||||
$options = $this->_processOptions('drag', $options);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
if ($this->_multiple) {
|
||||
return $this->each('new Draggable(item' . $options . ');');
|
||||
}
|
||||
return 'var jsDrag = new Draggable(' . $this->selection . $options . ');';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Droppable element.
|
||||
*
|
||||
* #### Note: Requires scriptaculous to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the droppable.
|
||||
* @return string Completed droppable script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::droppable() for options list.
|
||||
*/
|
||||
function drop($options = array()) {
|
||||
$options = $this->_processOptions('drop', $options);
|
||||
if (!empty($options)) {
|
||||
$options = ', {' . $options . '}';
|
||||
}
|
||||
return 'Droppables.add(' . $this->selection . $options . ');';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a slider control widget.
|
||||
*
|
||||
* ### Note: Requires scriptaculous to be loaded.
|
||||
*
|
||||
* @param array $options Array of options for the slider.
|
||||
* @return string Completed slider script.
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::slider() for options list.
|
||||
*/
|
||||
function slider($options = array()) {
|
||||
$slider = $this->selection;
|
||||
$this->get($options['handle']);
|
||||
unset($options['handle']);
|
||||
|
||||
if (isset($options['min']) && isset($options['max'])) {
|
||||
$options['range'] = array($options['min'], $options['max']);
|
||||
unset($options['min'], $options['max']);
|
||||
}
|
||||
$optionString = $this->_processOptions('slider', $options);
|
||||
if (!empty($optionString)) {
|
||||
$optionString = ', {' . $optionString . '}';
|
||||
}
|
||||
$out = 'var jsSlider = new Control.Slider(' . $this->selection . ', ' . $slider . $optionString . ');';
|
||||
$this->selection = $slider;
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the form attached to $selector.
|
||||
*
|
||||
* @param array $options Array of options.
|
||||
* @return string Completed serializeForm() snippet
|
||||
* @access public
|
||||
* @see JsBaseEngineHelper::serializeForm()
|
||||
*/
|
||||
function serializeForm($options = array()) {
|
||||
$options = array_merge(array('isForm' => false, 'inline' => false), $options);
|
||||
$selection = $this->selection;
|
||||
if (!$options['isForm']) {
|
||||
$selection = '$(' . $this->selection . '.form)';
|
||||
}
|
||||
$method = '.serialize()';
|
||||
if (!$options['inline']) {
|
||||
$method .= ';';
|
||||
}
|
||||
return $selection . $method;
|
||||
}
|
||||
}
|
292
php-practice/web-cake/html/cake/libs/view/helpers/rss.php
Normal file
292
php-practice/web-cake/html/cake/libs/view/helpers/rss.php
Normal file
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
/**
|
||||
* RSS Helper class file.
|
||||
*
|
||||
* Simplifies the output of RSS feeds.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Helper', 'Xml');
|
||||
|
||||
/**
|
||||
* XML Helper class for easy output of XML structures.
|
||||
*
|
||||
* XmlHelper encloses all methods needed while working with XML documents.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1460/RSS
|
||||
*/
|
||||
class RssHelper extends XmlHelper {
|
||||
|
||||
/**
|
||||
* Helpers used by RSS Helper
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $helpers = array('Time');
|
||||
|
||||
/**
|
||||
* Base URL
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $base = null;
|
||||
|
||||
/**
|
||||
* URL to current action.
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $here = null;
|
||||
|
||||
/**
|
||||
* Parameter array.
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $params = array();
|
||||
|
||||
/**
|
||||
* Current action.
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $action = null;
|
||||
|
||||
/**
|
||||
* POSTed model data
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $data = null;
|
||||
|
||||
/**
|
||||
* Name of the current model
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $model = null;
|
||||
|
||||
/**
|
||||
* Name of the current field
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $field = null;
|
||||
|
||||
/**
|
||||
* Default spec version of generated RSS
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $version = '2.0';
|
||||
|
||||
/**
|
||||
* Returns an RSS document wrapped in `<rss />` tags
|
||||
*
|
||||
* @param array $attrib `<rss />` tag attributes
|
||||
* @return string An RSS document
|
||||
* @access public
|
||||
*/
|
||||
function document($attrib = array(), $content = null) {
|
||||
if ($content === null) {
|
||||
$content = $attrib;
|
||||
$attrib = array();
|
||||
}
|
||||
if (!isset($attrib['version']) || empty($attrib['version'])) {
|
||||
$attrib['version'] = $this->version;
|
||||
}
|
||||
|
||||
return $this->elem('rss', $attrib, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an RSS `<channel />` element
|
||||
*
|
||||
* @param array $attrib `<channel />` tag attributes
|
||||
* @param mixed $elements Named array elements which are converted to tags
|
||||
* @param mixed $content Content (`<item />`'s belonging to this channel
|
||||
* @return string An RSS `<channel />`
|
||||
* @access public
|
||||
*/
|
||||
function channel($attrib = array(), $elements = array(), $content = null) {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
|
||||
if (!isset($elements['title']) && !empty($view->pageTitle)) {
|
||||
$elements['title'] = $view->pageTitle;
|
||||
}
|
||||
if (!isset($elements['link'])) {
|
||||
$elements['link'] = '/';
|
||||
}
|
||||
if (!isset($elements['description'])) {
|
||||
$elements['description'] = '';
|
||||
}
|
||||
$elements['link'] = $this->url($elements['link'], true);
|
||||
|
||||
$elems = '';
|
||||
foreach ($elements as $elem => $data) {
|
||||
$attributes = array();
|
||||
if (is_array($data)) {
|
||||
if (strtolower($elem) == 'cloud') {
|
||||
$attributes = $data;
|
||||
$data = array();
|
||||
} elseif (isset($data['attrib']) && is_array($data['attrib'])) {
|
||||
$attributes = $data['attrib'];
|
||||
unset($data['attrib']);
|
||||
} else {
|
||||
$innerElements = '';
|
||||
foreach ($data as $subElement => $value) {
|
||||
$innerElements .= $this->elem($subElement, array(), $value);
|
||||
}
|
||||
$data = $innerElements;
|
||||
}
|
||||
}
|
||||
$elems .= $this->elem($elem, $attributes, $data);
|
||||
}
|
||||
return $this->elem('channel', $attrib, $elems . $content, !($content === null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an array of data using an optional callback, and maps it to a set
|
||||
* of `<item />` tags
|
||||
*
|
||||
* @param array $items The list of items to be mapped
|
||||
* @param mixed $callback A string function name, or array containing an object
|
||||
* and a string method name
|
||||
* @return string A set of RSS `<item />` elements
|
||||
* @access public
|
||||
*/
|
||||
function items($items, $callback = null) {
|
||||
if ($callback != null) {
|
||||
$items = array_map($callback, $items);
|
||||
}
|
||||
|
||||
$out = '';
|
||||
$c = count($items);
|
||||
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
$out .= $this->item(array(), $items[$i]);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array into an `<item />` element and its contents
|
||||
*
|
||||
* @param array $attrib The attributes of the `<item />` element
|
||||
* @param array $elements The list of elements contained in this `<item />`
|
||||
* @return string An RSS `<item />` element
|
||||
* @access public
|
||||
*/
|
||||
function item($att = array(), $elements = array()) {
|
||||
$content = null;
|
||||
|
||||
if (isset($elements['link']) && !isset($elements['guid'])) {
|
||||
$elements['guid'] = $elements['link'];
|
||||
}
|
||||
|
||||
foreach ($elements as $key => $val) {
|
||||
$attrib = array();
|
||||
|
||||
$escape = true;
|
||||
if (is_array($val) && isset($val['convertEntities'])) {
|
||||
$escape = $val['convertEntities'];
|
||||
unset($val['convertEntities']);
|
||||
}
|
||||
|
||||
switch ($key) {
|
||||
case 'pubDate' :
|
||||
$val = $this->time($val);
|
||||
break;
|
||||
case 'category' :
|
||||
if (is_array($val) && !empty($val[0])) {
|
||||
foreach ($val as $category) {
|
||||
$attrib = array();
|
||||
if (isset($category['domain'])) {
|
||||
$attrib['domain'] = $category['domain'];
|
||||
unset($category['domain']);
|
||||
}
|
||||
$categories[] = $this->elem($key, $attrib, $category);
|
||||
}
|
||||
$elements[$key] = implode('', $categories);
|
||||
continue 2;
|
||||
} else if (is_array($val) && isset($val['domain'])) {
|
||||
$attrib['domain'] = $val['domain'];
|
||||
}
|
||||
break;
|
||||
case 'link':
|
||||
case 'guid':
|
||||
case 'comments':
|
||||
if (is_array($val) && isset($val['url'])) {
|
||||
$attrib = $val;
|
||||
unset($attrib['url']);
|
||||
$val = $val['url'];
|
||||
}
|
||||
$val = $this->url($val, true);
|
||||
break;
|
||||
case 'source':
|
||||
if (is_array($val) && isset($val['url'])) {
|
||||
$attrib['url'] = $this->url($val['url'], true);
|
||||
$val = $val['title'];
|
||||
} elseif (is_array($val)) {
|
||||
$attrib['url'] = $this->url($val[0], true);
|
||||
$val = $val[1];
|
||||
}
|
||||
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) {
|
||||
$val['length'] = sprintf("%u", filesize(WWW_ROOT . $val['url']));
|
||||
}
|
||||
if (!isset($val['type']) && function_exists('mime_content_type')) {
|
||||
$val['type'] = mime_content_type(WWW_ROOT . $val['url']);
|
||||
}
|
||||
}
|
||||
$val['url'] = $this->url($val['url'], true);
|
||||
$attrib = $val;
|
||||
$val = null;
|
||||
break;
|
||||
}
|
||||
if (!is_null($val) && $escape) {
|
||||
$val = h($val);
|
||||
}
|
||||
$elements[$key] = $this->elem($key, $attrib, $val);
|
||||
}
|
||||
if (!empty($elements)) {
|
||||
$content = implode('', $elements);
|
||||
}
|
||||
return $this->elem('item', $att, $content, !($content === null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a time in any format to an RSS time
|
||||
*
|
||||
* @param mixed $time
|
||||
* @return string An RSS-formatted timestamp
|
||||
* @see TimeHelper::toRSS
|
||||
*/
|
||||
function time($time) {
|
||||
return $this->Time->toRSS($time);
|
||||
}
|
||||
}
|
201
php-practice/web-cake/html/cake/libs/view/helpers/session.php
Normal file
201
php-practice/web-cake/html/cake/libs/view/helpers/session.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* Session Helper provides access to the Session in the Views.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.1.7.3328
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (!class_exists('cakesession')) {
|
||||
require LIBS . 'cake_session.php';
|
||||
}
|
||||
/**
|
||||
* Session Helper.
|
||||
*
|
||||
* Session reading from the view.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1465/Session
|
||||
*/
|
||||
class SessionHelper extends CakeSession {
|
||||
|
||||
/**
|
||||
* List of helpers used by this helper
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $helpers = array();
|
||||
|
||||
/**
|
||||
* Used to determine if methods implementation is used, or bypassed
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $__active = true;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $base
|
||||
*/
|
||||
function __construct($base = null) {
|
||||
if (Configure::read('Session.start') === true) {
|
||||
parent::__construct($base, false);
|
||||
$this->start();
|
||||
$this->__active = true;
|
||||
} else {
|
||||
$this->__active = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn sessions on if 'Session.start' is set to false in core.php
|
||||
*
|
||||
* @param string $base
|
||||
* @access public
|
||||
*/
|
||||
function activate($base = null) {
|
||||
$this->__active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to read a session values set in a controller for a key or return values for all keys.
|
||||
*
|
||||
* In your view: `$session->read('Controller.sessKey');`
|
||||
* Calling the method without a param will return all session vars
|
||||
*
|
||||
* @param string $name the name of the session key you want to read
|
||||
* @return values from the session vars
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1466/Methods
|
||||
*/
|
||||
function read($name = null) {
|
||||
if ($this->__active === true && $this->__start()) {
|
||||
return parent::read($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check is a session key has been set
|
||||
*
|
||||
* In your view: `$session->check('Controller.sessKey');`
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1466/Methods
|
||||
*/
|
||||
function check($name) {
|
||||
if ($this->__active === true && $this->__start()) {
|
||||
return parent::check($name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last error encountered in a session
|
||||
*
|
||||
* In your view: `$session->error();`
|
||||
*
|
||||
* @return string last error
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1466/Methods
|
||||
*/
|
||||
function error() {
|
||||
if ($this->__active === true && $this->__start()) {
|
||||
return parent::error();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to render the message set in Controller::Session::setFlash()
|
||||
*
|
||||
* In your view: $session->flash('somekey');
|
||||
* Will default to flash if no param is passed
|
||||
*
|
||||
* @param string $key The [Message.]key you are rendering in the view.
|
||||
* @return boolean|string Will return the value if $key is set, or false if not set.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1466/Methods
|
||||
* @link http://book.cakephp.org/view/1467/flash
|
||||
*/
|
||||
function flash($key = 'flash') {
|
||||
$out = false;
|
||||
|
||||
if ($this->__active === true && $this->__start()) {
|
||||
if (parent::check('Message.' . $key)) {
|
||||
$flash = parent::read('Message.' . $key);
|
||||
|
||||
if ($flash['element'] == 'default') {
|
||||
if (!empty($flash['params']['class'])) {
|
||||
$class = $flash['params']['class'];
|
||||
} else {
|
||||
$class = 'message';
|
||||
}
|
||||
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $flash['message'] . '</div>';
|
||||
} elseif ($flash['element'] == '' || $flash['element'] == null) {
|
||||
$out = $flash['message'];
|
||||
} else {
|
||||
$view =& ClassRegistry::getObject('view');
|
||||
$tmpVars = $flash['params'];
|
||||
$tmpVars['message'] = $flash['message'];
|
||||
$out = $view->element($flash['element'], $tmpVars);
|
||||
}
|
||||
parent::delete('Message.' . $key);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check is a session is valid in a view
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function valid() {
|
||||
if ($this->__active === true && $this->__start()) {
|
||||
return parent::valid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override CakeSession::write().
|
||||
* This method should not be used in a view
|
||||
*
|
||||
* @return boolean
|
||||
* @access public
|
||||
*/
|
||||
function write() {
|
||||
trigger_error(__('You can not write to a Session from the view', true), E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if Session has been started
|
||||
* and attempt to start it if not
|
||||
*
|
||||
* @return boolean true if Session is already started, false if
|
||||
* Session could not be started
|
||||
* @access private
|
||||
*/
|
||||
function __start() {
|
||||
if (!$this->started()) {
|
||||
return $this->start();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
336
php-practice/web-cake/html/cake/libs/view/helpers/text.php
Normal file
336
php-practice/web-cake/html/cake/libs/view/helpers/text.php
Normal file
@@ -0,0 +1,336 @@
|
||||
<?php
|
||||
/**
|
||||
* Text Helper
|
||||
*
|
||||
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Included libraries.
|
||||
*
|
||||
*/
|
||||
if (!class_exists('HtmlHelper')) {
|
||||
App::import('Helper', 'Html');
|
||||
}
|
||||
if (!class_exists('Multibyte')) {
|
||||
App::import('Core', 'Multibyte');
|
||||
}
|
||||
|
||||
/**
|
||||
* Text helper library.
|
||||
*
|
||||
* Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1469/Text
|
||||
*/
|
||||
class TextHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `format` The piece of html with that the phrase will be highlighted
|
||||
* - `html` If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
|
||||
*
|
||||
* @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
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#highlight-1622
|
||||
*/
|
||||
function highlight($text, $phrase, $options = array()) {
|
||||
if (empty($phrase)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$default = array(
|
||||
'format' => '<span class="highlight">\1</span>',
|
||||
'html' => false
|
||||
);
|
||||
$options = array_merge($default, $options);
|
||||
extract($options);
|
||||
|
||||
if (is_array($phrase)) {
|
||||
$replace = array();
|
||||
$with = array();
|
||||
|
||||
foreach ($phrase as $key => $segment) {
|
||||
$segment = "($segment)";
|
||||
if ($html) {
|
||||
$segment = "(?![^<]+>)$segment(?![^<]+>)";
|
||||
}
|
||||
|
||||
$with[] = (is_array($format)) ? $format[$key] : $format;
|
||||
$replace[] = "|$segment|iu";
|
||||
}
|
||||
|
||||
return preg_replace($replace, $with, $text);
|
||||
} else {
|
||||
$phrase = "($phrase)";
|
||||
if ($html) {
|
||||
$phrase = "(?![^<]+>)$phrase(?![^<]+>)";
|
||||
}
|
||||
|
||||
return preg_replace("|$phrase|iu", $format, $text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips given text of all links (<a href=....)
|
||||
*
|
||||
* @param string $text Text
|
||||
* @return string The text without links
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#stripLinks-1623
|
||||
*/
|
||||
function stripLinks($text) {
|
||||
return preg_replace('|<a\s+[^>]+>|im', '', preg_replace('|<\/a>|im', '', $text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds links (<a href=....) to a given text, by finding text that begins with
|
||||
* strings like http:// and ftp://.
|
||||
*
|
||||
* @param string $text Text to add links to
|
||||
* @param array $options Array of HTML options.
|
||||
* @return string The text with links
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#autoLinkUrls-1619
|
||||
*/
|
||||
function autoLinkUrls($text, $htmlOptions = array()) {
|
||||
$options = var_export($htmlOptions, true);
|
||||
$text = preg_replace_callback('#(?<!href="|">)((?:https?|ftp|nntp)://[^\s<>()]+)#i', create_function('$matches',
|
||||
'$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], $matches[0],' . $options . ');'), $text);
|
||||
|
||||
return preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\.[^\n\%\ <]+[^<\n\%\,\.\ <])(?<!\))#i',
|
||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "http://" . $matches[0],' . $options . ');'), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds email links (<a href="mailto:....) to a given text.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $options Array of HTML options.
|
||||
* @return string The text with links
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#autoLinkEmails-1618
|
||||
*/
|
||||
function autoLinkEmails($text, $options = array()) {
|
||||
$linkOptions = 'array(';
|
||||
foreach ($options as $option => $value) {
|
||||
$value = var_export($value, true);
|
||||
$linkOptions .= "'$option' => $value, ";
|
||||
}
|
||||
$linkOptions .= ')';
|
||||
|
||||
return preg_replace_callback('#([_A-Za-z0-9+-]+(?:\.[_A-Za-z0-9+-]+)*@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*)#',
|
||||
create_function('$matches', '$Html = new HtmlHelper(); $Html->tags = $Html->loadConfig(); return $Html->link($matches[0], "mailto:" . $matches[0],' . $linkOptions . ');'), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all links and email adresses to HTML links.
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param array $options Array of HTML options.
|
||||
* @return string The text with links
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#autoLink-1620
|
||||
*/
|
||||
function autoLink($text, $options = array()) {
|
||||
return $this->autoLinkEmails($this->autoLinkUrls($text, $options), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates text.
|
||||
*
|
||||
* Cuts a string to the length of $length and replaces the last characters
|
||||
* with the ending if the text is longer than length.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `ending` Will be used as Ending and appended to the trimmed string
|
||||
* - `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 array $options An array of html attributes and options.
|
||||
* @return string Trimmed string.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#truncate-1625
|
||||
*/
|
||||
function truncate($text, $length = 100, $options = array()) {
|
||||
$default = array(
|
||||
'ending' => '...', 'exact' => true, 'html' => false
|
||||
);
|
||||
$options = array_merge($default, $options);
|
||||
extract($options);
|
||||
|
||||
if ($html) {
|
||||
if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
|
||||
return $text;
|
||||
}
|
||||
$totalLength = mb_strlen(strip_tags($ending));
|
||||
$openTags = array();
|
||||
$truncate = '';
|
||||
|
||||
preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER);
|
||||
foreach ($tags as $tag) {
|
||||
if (!preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) {
|
||||
if (preg_match('/<[\w]+[^>]*>/s', $tag[0])) {
|
||||
array_unshift($openTags, $tag[2]);
|
||||
} else if (preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag)) {
|
||||
$pos = array_search($closeTag[1], $openTags);
|
||||
if ($pos !== false) {
|
||||
array_splice($openTags, $pos, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
$truncate .= $tag[1];
|
||||
|
||||
$contentLength = mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3]));
|
||||
if ($contentLength + $totalLength > $length) {
|
||||
$left = $length - $totalLength;
|
||||
$entitiesLength = 0;
|
||||
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE)) {
|
||||
foreach ($entities[0] as $entity) {
|
||||
if ($entity[1] + 1 - $entitiesLength <= $left) {
|
||||
$left--;
|
||||
$entitiesLength += mb_strlen($entity[0]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$truncate .= mb_substr($tag[3], 0 , $left + $entitiesLength);
|
||||
break;
|
||||
} else {
|
||||
$truncate .= $tag[3];
|
||||
$totalLength += $contentLength;
|
||||
}
|
||||
if ($totalLength >= $length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mb_strlen($text) <= $length) {
|
||||
return $text;
|
||||
} else {
|
||||
$truncate = mb_substr($text, 0, $length - mb_strlen($ending));
|
||||
}
|
||||
}
|
||||
if (!$exact) {
|
||||
$spacepos = mb_strrpos($truncate, ' ');
|
||||
if (isset($spacepos)) {
|
||||
if ($html) {
|
||||
$bits = mb_substr($truncate, $spacepos);
|
||||
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
|
||||
if (!empty($droppedTags)) {
|
||||
foreach ($droppedTags as $closingTag) {
|
||||
if (!in_array($closingTag[1], $openTags)) {
|
||||
array_unshift($openTags, $closingTag[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$truncate = mb_substr($truncate, 0, $spacepos);
|
||||
}
|
||||
}
|
||||
$truncate .= $ending;
|
||||
|
||||
if ($html) {
|
||||
foreach ($openTags as $tag) {
|
||||
$truncate .= '</'.$tag.'>';
|
||||
}
|
||||
}
|
||||
|
||||
return $truncate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 string $ending Ending that will be appended
|
||||
* @return string Modified string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#excerpt-1621
|
||||
*/
|
||||
function excerpt($text, $phrase, $radius = 100, $ending = '...') {
|
||||
if (empty($text) or empty($phrase)) {
|
||||
return $this->truncate($text, $radius * 2, array('ending' => $ending));
|
||||
}
|
||||
|
||||
$phraseLen = mb_strlen($phrase);
|
||||
if ($radius < $phraseLen) {
|
||||
$radius = $phraseLen;
|
||||
}
|
||||
|
||||
$pos = mb_strpos(mb_strtolower($text), mb_strtolower($phrase));
|
||||
|
||||
$startPos = 0;
|
||||
if ($pos > $radius) {
|
||||
$startPos = $pos - $radius;
|
||||
}
|
||||
|
||||
$textLen = mb_strlen($text);
|
||||
|
||||
$endPos = $pos + $phraseLen + $radius;
|
||||
if ($endPos >= $textLen) {
|
||||
$endPos = $textLen;
|
||||
}
|
||||
|
||||
$excerpt = mb_substr($text, $startPos, $endPos - $startPos);
|
||||
if ($startPos != 0) {
|
||||
$excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
|
||||
}
|
||||
|
||||
if ($endPos != $textLen) {
|
||||
$excerpt = substr_replace($excerpt, $ending, -$phraseLen);
|
||||
}
|
||||
|
||||
return $excerpt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural English
|
||||
*
|
||||
* @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 othe other items together. Defaults to ', '
|
||||
* @return string The glued together string.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1469/Text#toList-1624
|
||||
*/
|
||||
function toList($list, $and = 'and', $separator = ', ') {
|
||||
if (count($list) > 1) {
|
||||
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
|
||||
} else {
|
||||
return array_pop($list);
|
||||
}
|
||||
}
|
||||
}
|
735
php-practice/web-cake/html/cake/libs/view/helpers/time.php
Normal file
735
php-practice/web-cake/html/cake/libs/view/helpers/time.php
Normal file
@@ -0,0 +1,735 @@
|
||||
<?php
|
||||
/**
|
||||
* Time Helper class file.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Time Helper class for easy use of time data.
|
||||
*
|
||||
* Manipulation of time data.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1470/Time
|
||||
*/
|
||||
class TimeHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* 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 th modifier S for date()
|
||||
* @param string UNIX timestamp
|
||||
* @return string windows safe and date() function compatible format for strftime
|
||||
* @access public
|
||||
*/
|
||||
function convertSpecifiers($format, $time = null) {
|
||||
if (!$time) {
|
||||
$time = time();
|
||||
}
|
||||
$this->__time = $time;
|
||||
return preg_replace_callback('/\%(\w+)/', array($this, '__translateSpecifier'), $format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to translate a matched specifier element from a regular expresion into
|
||||
* a windows safe and i18n aware specifier
|
||||
*
|
||||
* @param array $specifier match from regular expression
|
||||
* @return string converted element
|
||||
* @access private
|
||||
*/
|
||||
function __translateSpecifier($specifier) {
|
||||
switch ($specifier[1]) {
|
||||
case 'a':
|
||||
$abday = __c('abday', 5, true);
|
||||
if (is_array($abday)) {
|
||||
return $abday[date('w', $this->__time)];
|
||||
}
|
||||
break;
|
||||
case 'A':
|
||||
$day = __c('day',5,true);
|
||||
if (is_array($day)) {
|
||||
return $day[date('w', $this->__time)];
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
$format = __c('d_t_fmt',5,true);
|
||||
if ($format != 'd_t_fmt') {
|
||||
return $this->convertSpecifiers($format, $this->__time);
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
return sprintf("%02d", date('Y', $this->__time) / 100);
|
||||
case 'D':
|
||||
return '%m/%d/%y';
|
||||
case 'eS' :
|
||||
return date('jS', $this->__time);
|
||||
case 'b':
|
||||
case 'h':
|
||||
$months = __c('abmon', 5, true);
|
||||
if (is_array($months)) {
|
||||
return $months[date('n', $this->__time) -1];
|
||||
}
|
||||
return '%b';
|
||||
case 'B':
|
||||
$months = __c('mon',5,true);
|
||||
if (is_array($months)) {
|
||||
return $months[date('n', $this->__time) -1];
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
return "\n";
|
||||
case 'p':
|
||||
case 'P':
|
||||
$default = array('am' => 0, 'pm' => 1);
|
||||
$meridiem = $default[date('a',$this->__time)];
|
||||
$format = __c('am_pm', 5, true);
|
||||
if (is_array($format)) {
|
||||
$meridiem = $format[$meridiem];
|
||||
return ($specifier[1] == 'P') ? strtolower($meridiem) : strtoupper($meridiem);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
$complete = __c('t_fmt_ampm', 5, true);
|
||||
if ($complete != 't_fmt_ampm') {
|
||||
return str_replace('%p',$this->__translateSpecifier(array('%p', 'p')),$complete);
|
||||
}
|
||||
break;
|
||||
case 'R':
|
||||
return date('H:i', $this->__time);
|
||||
case 't':
|
||||
return "\t";
|
||||
case 'T':
|
||||
return '%H:%M:%S';
|
||||
case 'u':
|
||||
return ($weekDay = date('w', $this->__time)) ? $weekDay : 7;
|
||||
case 'x':
|
||||
$format = __c('d_fmt', 5, true);
|
||||
if ($format != 'd_fmt') {
|
||||
return $this->convertSpecifiers($format, $this->__time);
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
$format = __c('t_fmt',5,true);
|
||||
if ($format != 't_fmt') {
|
||||
return $this->convertSpecifiers($format, $this->__time);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $specifier[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts given time (in server's time zone) to user's local time, given his/her offset from GMT.
|
||||
*
|
||||
* @param string $serverTime UNIX timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string UNIX timestamp
|
||||
* @access public
|
||||
*/
|
||||
function convert($serverTime, $userOffset) {
|
||||
$serverOffset = $this->serverOffset();
|
||||
$gmtTime = $serverTime - $serverOffset;
|
||||
$userTime = $gmtTime + $userOffset * (60*60);
|
||||
return $userTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns server's offset from GMT in seconds.
|
||||
*
|
||||
* @return int Offset
|
||||
* @access public
|
||||
*/
|
||||
function serverOffset() {
|
||||
return date('Z', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
*
|
||||
* @param string $dateString Datetime string
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Parsed timestamp
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function fromString($dateString, $userOffset = null) {
|
||||
if (empty($dateString)) {
|
||||
return false;
|
||||
}
|
||||
if (is_integer($dateString) || is_numeric($dateString)) {
|
||||
$date = intval($dateString);
|
||||
} else {
|
||||
$date = strtotime($dateString);
|
||||
}
|
||||
if ($userOffset !== null) {
|
||||
return $this->convert($date, $userOffset);
|
||||
}
|
||||
if ($date === -1) {
|
||||
return false;
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a nicely formatted date string for given Datetime string.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Formatted date string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function nice($dateString = null, $userOffset = null) {
|
||||
if ($dateString != null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
} else {
|
||||
$date = time();
|
||||
}
|
||||
$format = $this->convertSpecifiers('%a, %b %eS %Y, %H:%M', $date);
|
||||
return strftime($format, $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted descriptive date string for given datetime string.
|
||||
*
|
||||
* If the given date is today, the returned string could be "Today, 16:54".
|
||||
* If the given date was yesterday, the returned string could be "Yesterday, 16:54".
|
||||
* If $dateString's year is the current year, the returned string does not
|
||||
* include mention of the year.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Described, relative date string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function niceShort($dateString = null, $userOffset = null) {
|
||||
$date = $dateString ? $this->fromString($dateString, $userOffset) : time();
|
||||
|
||||
$y = $this->isThisYear($date) ? '' : ' %Y';
|
||||
|
||||
if ($this->isToday($date)) {
|
||||
$ret = sprintf(__('Today, %s',true), strftime("%H:%M", $date));
|
||||
} elseif ($this->wasYesterday($date)) {
|
||||
$ret = sprintf(__('Yesterday, %s',true), strftime("%H:%M", $date));
|
||||
} else {
|
||||
$format = $this->convertSpecifiers("%b %eS{$y}, %H:%M", $date);
|
||||
$ret = strftime($format, $date);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a partial SQL string to search for all records between two dates.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param string $end Datetime string or Unix timestamp
|
||||
* @param string $fieldName Name of database field to compare with
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Partial SQL string.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function daysAsSql($begin, $end, $fieldName, $userOffset = null) {
|
||||
$begin = $this->fromString($begin, $userOffset);
|
||||
$end = $this->fromString($end, $userOffset);
|
||||
$begin = date('Y-m-d', $begin) . ' 00:00:00';
|
||||
$end = date('Y-m-d', $end) . ' 23:59:59';
|
||||
|
||||
return "($fieldName >= '$begin') AND ($fieldName <= '$end')";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a partial SQL string to search for all records between two times
|
||||
* occurring on the same day.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param string $fieldName Name of database field to compare with
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Partial SQL string.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function dayAsSql($dateString, $fieldName, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return $this->daysAsSql($dateString, $dateString, $fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is today.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return boolean True if datetime string is today
|
||||
* @access public
|
||||
*/
|
||||
function isToday($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date('Y-m-d', $date) == date('Y-m-d', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is within this week
|
||||
* @param string $dateString
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return boolean True if datetime string is within current week
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1472/Testing-Time
|
||||
*/
|
||||
function isThisWeek($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date('W Y', $date) == date('W Y', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is within this month
|
||||
* @param string $dateString
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return boolean True if datetime string is within current month
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1472/Testing-Time
|
||||
*/
|
||||
function isThisMonth($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString);
|
||||
return date('m Y',$date) == date('m Y', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is within current year.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @return boolean True if datetime string is within current year
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1472/Testing-Time
|
||||
*/
|
||||
function isThisYear($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date('Y', $date) == date('Y', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string was yesterday.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return boolean True if datetime string was yesterday
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1472/Testing-Time
|
||||
*
|
||||
*/
|
||||
function wasYesterday($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if given datetime string is tomorrow.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return boolean True if datetime string was yesterday
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1472/Testing-Time
|
||||
*/
|
||||
function isTomorrow($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date('Y-m-d', $date) == date('Y-m-d', strtotime('tomorrow'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the quarter
|
||||
*
|
||||
* @param string $dateString
|
||||
* @param boolean $range if true returns a range in Y-m-d format
|
||||
* @return boolean True if datetime string is within current week
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function toQuarter($dateString, $range = false) {
|
||||
$time = $this->fromString($dateString);
|
||||
$date = ceil(date('m', $time) / 3);
|
||||
|
||||
if ($range === true) {
|
||||
$range = 'Y-m-d';
|
||||
}
|
||||
|
||||
if ($range !== false) {
|
||||
$year = date('Y', $time);
|
||||
|
||||
switch ($date) {
|
||||
case 1:
|
||||
$date = array($year.'-01-01', $year.'-03-31');
|
||||
break;
|
||||
case 2:
|
||||
$date = array($year.'-04-01', $year.'-06-30');
|
||||
break;
|
||||
case 3:
|
||||
$date = array($year.'-07-01', $year.'-09-30');
|
||||
break;
|
||||
case 4:
|
||||
$date = array($year.'-10-01', $year.'-12-31');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
|
||||
*
|
||||
* @param string $dateString Datetime string to be represented as a Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return integer Unix timestamp
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function toUnix($dateString, $userOffset = null) {
|
||||
return $this->fromString($dateString, $userOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a date formatted for Atom RSS feeds.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Formatted date string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function toAtom($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date('Y-m-d\TH:i:s\Z', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats date for RSS feeds
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Formatted date string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function toRSS($dateString, $userOffset = null) {
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
return date("r", $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns either a relative date or a formatted date depending
|
||||
* on the difference between the current time and given datetime.
|
||||
* $datetime should be in a <i>strtotime</i> - parsable format, like MySQL's datetime datatype.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `format` => a fall back format if the relative time is longer than the duration specified by end
|
||||
* - `end` => The end of relative time telling
|
||||
* - `userOffset` => Users offset from GMT (in hours)
|
||||
*
|
||||
* Relative dates look something like this:
|
||||
* 3 weeks, 4 days ago
|
||||
* 15 seconds ago
|
||||
*
|
||||
* Default date formatting is d/m/yy e.g: on 18/2/09
|
||||
*
|
||||
* The returned string includes 'ago' or 'on' and assumes you'll properly add a word
|
||||
* like 'Posted ' before the function output.
|
||||
*
|
||||
* @param string $dateString Datetime string or Unix timestamp
|
||||
* @param array $options Default format if timestamp is used in $dateString
|
||||
* @return string Relative time string.
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function timeAgoInWords($dateTime, $options = array()) {
|
||||
$userOffset = null;
|
||||
if (is_array($options) && isset($options['userOffset'])) {
|
||||
$userOffset = $options['userOffset'];
|
||||
}
|
||||
$now = time();
|
||||
if (!is_null($userOffset)) {
|
||||
$now = $this->convert(time(), $userOffset);
|
||||
}
|
||||
$inSeconds = $this->fromString($dateTime, $userOffset);
|
||||
$backwards = ($inSeconds > $now);
|
||||
|
||||
$format = 'j/n/y';
|
||||
$end = '+1 month';
|
||||
|
||||
if (is_array($options)) {
|
||||
if (isset($options['format'])) {
|
||||
$format = $options['format'];
|
||||
unset($options['format']);
|
||||
}
|
||||
if (isset($options['end'])) {
|
||||
$end = $options['end'];
|
||||
unset($options['end']);
|
||||
}
|
||||
} else {
|
||||
$format = $options;
|
||||
}
|
||||
|
||||
if ($backwards) {
|
||||
$futureTime = $inSeconds;
|
||||
$pastTime = $now;
|
||||
} else {
|
||||
$futureTime = $now;
|
||||
$pastTime = $inSeconds;
|
||||
}
|
||||
$diff = $futureTime - $pastTime;
|
||||
|
||||
// If more than a week, then take into account the length of months
|
||||
if ($diff >= 604800) {
|
||||
$current = array();
|
||||
$date = array();
|
||||
|
||||
list($future['H'], $future['i'], $future['s'], $future['d'], $future['m'], $future['Y']) = explode('/', date('H/i/s/d/m/Y', $futureTime));
|
||||
|
||||
list($past['H'], $past['i'], $past['s'], $past['d'], $past['m'], $past['Y']) = explode('/', date('H/i/s/d/m/Y', $pastTime));
|
||||
$years = $months = $weeks = $days = $hours = $minutes = $seconds = 0;
|
||||
|
||||
if ($future['Y'] == $past['Y'] && $future['m'] == $past['m']) {
|
||||
$months = 0;
|
||||
$years = 0;
|
||||
} else {
|
||||
if ($future['Y'] == $past['Y']) {
|
||||
$months = $future['m'] - $past['m'];
|
||||
} else {
|
||||
$years = $future['Y'] - $past['Y'];
|
||||
$months = $future['m'] + ((12 * $years) - $past['m']);
|
||||
|
||||
if ($months >= 12) {
|
||||
$years = floor($months / 12);
|
||||
$months = $months - ($years * 12);
|
||||
}
|
||||
|
||||
if ($future['m'] < $past['m'] && $future['Y'] - $past['Y'] == 1) {
|
||||
$years --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($future['d'] >= $past['d']) {
|
||||
$days = $future['d'] - $past['d'];
|
||||
} else {
|
||||
$daysInPastMonth = date('t', $pastTime);
|
||||
$daysInFutureMonth = date('t', mktime(0, 0, 0, $future['m'] - 1, 1, $future['Y']));
|
||||
|
||||
if (!$backwards) {
|
||||
$days = ($daysInPastMonth - $past['d']) + $future['d'];
|
||||
} else {
|
||||
$days = ($daysInFutureMonth - $past['d']) + $future['d'];
|
||||
}
|
||||
|
||||
if ($future['m'] != $past['m']) {
|
||||
$months --;
|
||||
}
|
||||
}
|
||||
|
||||
if ($months == 0 && $years >= 1 && $diff < ($years * 31536000)) {
|
||||
$months = 11;
|
||||
$years --;
|
||||
}
|
||||
|
||||
if ($months >= 12) {
|
||||
$years = $years + 1;
|
||||
$months = $months - 12;
|
||||
}
|
||||
|
||||
if ($days >= 7) {
|
||||
$weeks = floor($days / 7);
|
||||
$days = $days - ($weeks * 7);
|
||||
}
|
||||
} else {
|
||||
$years = $months = $weeks = 0;
|
||||
$days = floor($diff / 86400);
|
||||
|
||||
$diff = $diff - ($days * 86400);
|
||||
|
||||
$hours = floor($diff / 3600);
|
||||
$diff = $diff - ($hours * 3600);
|
||||
|
||||
$minutes = floor($diff / 60);
|
||||
$diff = $diff - ($minutes * 60);
|
||||
$seconds = $diff;
|
||||
}
|
||||
$relativeDate = '';
|
||||
$diff = $futureTime - $pastTime;
|
||||
|
||||
if ($diff > abs($now - $this->fromString($end))) {
|
||||
$relativeDate = sprintf(__('on %s',true), date($format, $inSeconds));
|
||||
} else {
|
||||
if ($years > 0) {
|
||||
// years and months and days
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $years . ' ' . __n('year', 'years', $years, true);
|
||||
$relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . $months . ' ' . __n('month', 'months', $months, true) : '';
|
||||
$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true) : '';
|
||||
$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
|
||||
} elseif (abs($months) > 0) {
|
||||
// months, weeks and days
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $months . ' ' . __n('month', 'months', $months, true);
|
||||
$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true) : '';
|
||||
$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
|
||||
} elseif (abs($weeks) > 0) {
|
||||
// weeks and days
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true);
|
||||
$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
|
||||
} elseif (abs($days) > 0) {
|
||||
// days and hours
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true);
|
||||
$relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . $hours . ' ' . __n('hour', 'hours', $hours, true) : '';
|
||||
} elseif (abs($hours) > 0) {
|
||||
// hours and minutes
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $hours . ' ' . __n('hour', 'hours', $hours, true);
|
||||
$relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . $minutes . ' ' . __n('minute', 'minutes', $minutes, true) : '';
|
||||
} elseif (abs($minutes) > 0) {
|
||||
// minutes only
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $minutes . ' ' . __n('minute', 'minutes', $minutes, true);
|
||||
} else {
|
||||
// seconds only
|
||||
$relativeDate .= ($relativeDate ? ', ' : '') . $seconds . ' ' . __n('second', 'seconds', $seconds, true);
|
||||
}
|
||||
|
||||
if (!$backwards) {
|
||||
$relativeDate = sprintf(__('%s ago', true), $relativeDate);
|
||||
}
|
||||
}
|
||||
return $relativeDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for timeAgoInWords
|
||||
*
|
||||
* @param mixed $dateTime Datetime string (strtotime-compatible) or Unix timestamp
|
||||
* @param mixed $options Default format string, if timestamp is used in $dateTime, or an array of options to be passed
|
||||
* on to timeAgoInWords().
|
||||
* @return string Relative time string.
|
||||
* @see TimeHelper::timeAgoInWords
|
||||
* @access public
|
||||
* @deprecated This method alias will be removed in future versions.
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function relativeTime($dateTime, $options = array()) {
|
||||
return $this->timeAgoInWords($dateTime, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if specified datetime was within the interval specified, else false.
|
||||
*
|
||||
* @param mixed $timeInterval the numeric value with space then time type.
|
||||
* Example of valid types: 6 hours, 2 days, 1 minute.
|
||||
* @param mixed $dateString the datestring or unix timestamp to compare
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return bool
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1472/Testing-Time
|
||||
*/
|
||||
function wasWithinLast($timeInterval, $dateString, $userOffset = null) {
|
||||
$tmp = str_replace(' ', '', $timeInterval);
|
||||
if (is_numeric($tmp)) {
|
||||
$timeInterval = $tmp . ' ' . __('days', true);
|
||||
}
|
||||
|
||||
$date = $this->fromString($dateString, $userOffset);
|
||||
$interval = $this->fromString('-'.$timeInterval);
|
||||
|
||||
if ($date >= $interval && $date <= time()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns gmt, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
*
|
||||
* @param string $dateString Datetime string
|
||||
* @return string Formatted date string
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1471/Formatting
|
||||
*/
|
||||
function gmt($string = null) {
|
||||
if ($string != null) {
|
||||
$string = $this->fromString($string);
|
||||
} else {
|
||||
$string = time();
|
||||
}
|
||||
$string = $this->fromString($string);
|
||||
$hour = intval(date("G", $string));
|
||||
$minute = intval(date("i", $string));
|
||||
$second = intval(date("s", $string));
|
||||
$month = intval(date("n", $string));
|
||||
$day = intval(date("j", $string));
|
||||
$year = intval(date("Y", $string));
|
||||
|
||||
return gmmktime($hour, $minute, $second, $month, $day, $year);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 string $format date format string (or a DateTime string)
|
||||
* @param string $dateString Datetime string (or a date format string)
|
||||
* @param boolean $invalid flag to ignore results of fromString == false
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Formatted date string
|
||||
* @access public
|
||||
*/
|
||||
function format($format, $date = null, $invalid = false, $userOffset = null) {
|
||||
$time = $this->fromString($date, $userOffset);
|
||||
$_time = $this->fromString($format, $userOffset);
|
||||
|
||||
if (is_numeric($_time) && $time === false) {
|
||||
$format = $date;
|
||||
return $this->i18nFormat($_time, $format, $invalid, $userOffset);
|
||||
}
|
||||
if ($time === false && $invalid !== false) {
|
||||
return $invalid;
|
||||
}
|
||||
return date($format, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
|
||||
* It take in account the default date format for the current language if a LC_TIME file is used.
|
||||
*
|
||||
* @param string $dateString Datetime string
|
||||
* @param string $format strftime format string.
|
||||
* @param boolean $invalid flag to ignore results of fromString == false
|
||||
* @param int $userOffset User's offset from GMT (in hours)
|
||||
* @return string Formatted and translated date string @access public
|
||||
* @access public
|
||||
*/
|
||||
function i18nFormat($date, $format = null, $invalid = false, $userOffset = null) {
|
||||
$date = $this->fromString($date, $userOffset);
|
||||
if ($date === false && $invalid !== false) {
|
||||
return $invalid;
|
||||
}
|
||||
if (empty($format)) {
|
||||
$format = '%x';
|
||||
}
|
||||
$format = $this->convertSpecifiers($format, $date);
|
||||
return strftime($format, $date);
|
||||
}
|
||||
}
|
174
php-practice/web-cake/html/cake/libs/view/helpers/xml.php
Normal file
174
php-practice/web-cake/html/cake/libs/view/helpers/xml.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
/**
|
||||
* XML Helper class file.
|
||||
*
|
||||
* Simplifies the output of XML documents.
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @since CakePHP(tm) v 1.2
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('Core', array('Xml', 'Set'));
|
||||
|
||||
/**
|
||||
* XML Helper class for easy output of XML structures.
|
||||
*
|
||||
* XmlHelper encloses all methods needed while working with XML documents.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.helpers
|
||||
* @link http://book.cakephp.org/view/1473/XML
|
||||
*/
|
||||
class XmlHelper extends AppHelper {
|
||||
|
||||
/**
|
||||
* Default document encoding
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $encoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->Xml =& new Xml();
|
||||
$this->Xml->options(array('verifyNs' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an XML document header
|
||||
*
|
||||
* @param array $attrib Header tag attributes
|
||||
* @return string XML header
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1476/header
|
||||
*/
|
||||
function header($attrib = array()) {
|
||||
if (Configure::read('App.encoding') !== null) {
|
||||
$this->encoding = Configure::read('App.encoding');
|
||||
}
|
||||
|
||||
if (is_array($attrib)) {
|
||||
$attrib = array_merge(array('encoding' => $this->encoding), $attrib);
|
||||
}
|
||||
if (is_string($attrib) && strpos($attrib, 'xml') !== 0) {
|
||||
$attrib = 'xml ' . $attrib;
|
||||
}
|
||||
|
||||
return $this->Xml->header($attrib);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a namespace to any documents generated
|
||||
*
|
||||
* @param string $name The namespace name
|
||||
* @param string $url The namespace URI; can be empty if in the default namespace map
|
||||
* @return boolean False if no URL is specified, and the namespace does not exist
|
||||
* default namespace map, otherwise true
|
||||
* @deprecated
|
||||
* @see Xml::addNs()
|
||||
*/
|
||||
function addNs($name, $url = null) {
|
||||
return $this->Xml->addNamespace($name, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a namespace added in addNs()
|
||||
*
|
||||
* @param string $name The namespace name or URI
|
||||
* @deprecated
|
||||
* @see Xml::removeNs()
|
||||
* @access public
|
||||
*/
|
||||
function removeNs($name) {
|
||||
return $this->Xml->removeGlobalNamespace($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an XML element
|
||||
*
|
||||
* @param string $name The name of the XML element
|
||||
* @param array $attrib The attributes of the XML element
|
||||
* @param mixed $content XML element content
|
||||
* @param boolean $endTag Whether the end tag of the element should be printed
|
||||
* @return string XML
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1475/elem
|
||||
*/
|
||||
function elem($name, $attrib = array(), $content = null, $endTag = true) {
|
||||
$namespace = null;
|
||||
if (isset($attrib['namespace'])) {
|
||||
$namespace = $attrib['namespace'];
|
||||
unset($attrib['namespace']);
|
||||
}
|
||||
$cdata = false;
|
||||
if (is_array($content) && isset($content['cdata'])) {
|
||||
$cdata = true;
|
||||
unset($content['cdata']);
|
||||
}
|
||||
if (is_array($content) && array_key_exists('value', $content)) {
|
||||
$content = $content['value'];
|
||||
}
|
||||
$children = array();
|
||||
if (is_array($content)) {
|
||||
$children = $content;
|
||||
$content = null;
|
||||
}
|
||||
|
||||
$elem =& $this->Xml->createElement($name, $content, $attrib, $namespace);
|
||||
foreach ($children as $child) {
|
||||
$elem->createElement($child);
|
||||
}
|
||||
$out = $elem->toString(array('cdata' => $cdata, 'leaveOpen' => !$endTag));
|
||||
|
||||
if (!$endTag) {
|
||||
$this->Xml =& $elem;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create closing tag for current element
|
||||
*
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function closeElem() {
|
||||
$name = $this->Xml->name();
|
||||
if ($parent =& $this->Xml->parent()) {
|
||||
$this->Xml =& $parent;
|
||||
}
|
||||
return '</' . $name . '>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes a model resultset into XML
|
||||
*
|
||||
* @param mixed $data The content to be converted to XML
|
||||
* @param array $options The data formatting options. For a list of valid options, see
|
||||
* Xml::__construct().
|
||||
* @return string A copy of $data in XML format
|
||||
* @see Xml::__construct()
|
||||
* @access public
|
||||
* @link http://book.cakephp.org/view/1474/serialize
|
||||
*/
|
||||
function serialize($data, $options = array()) {
|
||||
$options += array('attributes' => false, 'format' => 'attributes');
|
||||
$data =& new Xml($data, $options);
|
||||
return $data->toString($options + array('header' => false));
|
||||
}
|
||||
}
|
20
php-practice/web-cake/html/cake/libs/view/layouts/ajax.ctp
Normal file
20
php-practice/web-cake/html/cake/libs/view/layouts/ajax.ctp
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php echo $content_for_layout; ?>
|
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<?php echo $this->Html->charset(); ?>
|
||||
<title>
|
||||
<?php __('CakePHP: the rapid development php framework:'); ?>
|
||||
<?php echo $title_for_layout; ?>
|
||||
</title>
|
||||
<?php
|
||||
echo $this->Html->meta('icon');
|
||||
|
||||
echo $this->Html->css('cake.generic');
|
||||
|
||||
echo $scripts_for_layout;
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="header">
|
||||
<h1><?php echo $this->Html->link(__('CakePHP: the rapid development php framework', true), 'http://cakephp.org'); ?></h1>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
<?php echo $this->Session->flash(); ?>
|
||||
|
||||
<?php echo $content_for_layout; ?>
|
||||
|
||||
</div>
|
||||
<div id="footer">
|
||||
<?php echo $this->Html->link(
|
||||
$this->Html->image('cake.power.gif', array('alt'=> __('CakePHP: the rapid development php framework', true), 'border' => '0')),
|
||||
'http://www.cakephp.org/',
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo $this->element('sql_dump'); ?>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts.email.html
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo $title_for_layout;?></title>
|
||||
</head>
|
||||
<body>
|
||||
<?php echo $content_for_layout;?>
|
||||
|
||||
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts.email.text
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<?php echo $content_for_layout;?>
|
||||
|
||||
This email was sent using the CakePHP Framework, http://cakephp.org.
|
38
php-practice/web-cake/html/cake/libs/view/layouts/flash.ctp
Normal file
38
php-practice/web-cake/html/cake/libs/view/layouts/flash.ctp
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<?php echo $this->Html->charset(); ?>
|
||||
<title><?php echo $page_title; ?></title>
|
||||
|
||||
<?php if (Configure::read() == 0) { ?>
|
||||
<meta http-equiv="Refresh" content="<?php echo $pause; ?>;url=<?php echo $url; ?>"/>
|
||||
<?php } ?>
|
||||
<style><!--
|
||||
P { text-align:center; font:bold 1.1em sans-serif }
|
||||
A { color:#444; text-decoration:none }
|
||||
A:HOVER { text-decoration: underline; color:#44E }
|
||||
--></style>
|
||||
</head>
|
||||
<body>
|
||||
<p><a href="<?php echo $url; ?>"><?php echo $message; ?></a></p>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,2 @@
|
||||
<?php echo $scripts_for_layout; ?>
|
||||
<script type="text/javascript"><?php echo $content_for_layout; ?></script>
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
echo $this->Rss->header();
|
||||
|
||||
if (!isset($channel)) {
|
||||
$channel = array();
|
||||
}
|
||||
if (!isset($channel['title'])) {
|
||||
$channel['title'] = $title_for_layout;
|
||||
}
|
||||
|
||||
echo $this->Rss->document(
|
||||
$this->Rss->channel(
|
||||
array(), $channel, $content_for_layout
|
||||
)
|
||||
);
|
||||
?>
|
@@ -0,0 +1,2 @@
|
||||
<?php echo $this->Xml->header(); ?>
|
||||
<?php echo $content_for_layout; ?>
|
285
php-practice/web-cake/html/cake/libs/view/media.php
Normal file
285
php-practice/web-cake/html/cake/libs/view/media.php
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/**
|
||||
* Methods to display or download any type of file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
* @since CakePHP(tm) v 1.2.0.5714
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
App::import('View', 'View', false);
|
||||
|
||||
class MediaView extends View {
|
||||
|
||||
/**
|
||||
* Holds known mime type mappings
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $mimeType = array(
|
||||
'ai' => 'application/postscript', 'bcpio' => 'application/x-bcpio', 'bin' => 'application/octet-stream',
|
||||
'ccad' => 'application/clariscad', 'cdf' => 'application/x-netcdf', 'class' => 'application/octet-stream',
|
||||
'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', 'csh' => 'application/x-csh',
|
||||
'csv' => 'application/csv', 'dcr' => 'application/x-director', 'dir' => 'application/x-director',
|
||||
'dms' => 'application/octet-stream', 'doc' => 'application/msword', 'drw' => 'application/drafting',
|
||||
'dvi' => 'application/x-dvi', 'dwg' => 'application/acad', 'dxf' => 'application/dxf',
|
||||
'dxr' => 'application/x-director', 'eot' => 'application/vnd.ms-fontobject', 'eps' => 'application/postscript',
|
||||
'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset',
|
||||
'flv' => 'video/x-flv', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip',
|
||||
'bz2' => 'application/x-bzip', '7z' => 'application/x-7z-compressed', 'hdf' => 'application/x-hdf',
|
||||
'hqx' => 'application/mac-binhex40', 'ico' => 'image/vnd.microsoft.icon', 'ips' => 'application/x-ipscript',
|
||||
'ipx' => 'application/x-ipix', 'js' => 'application/x-javascript', 'latex' => 'application/x-latex',
|
||||
'lha' => 'application/octet-stream', 'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream',
|
||||
'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif',
|
||||
'ms' => 'application/x-troff-ms', 'nc' => 'application/x-netcdf', 'oda' => 'application/oda',
|
||||
'otf' => 'font/otf', 'pdf' => 'application/pdf',
|
||||
'pgn' => 'application/x-chess-pgn', 'pot' => 'application/mspowerpoint', 'pps' => 'application/mspowerpoint',
|
||||
'ppt' => 'application/mspowerpoint', 'ppz' => 'application/mspowerpoint', 'pre' => 'application/x-freelance',
|
||||
'prt' => 'application/pro_eng', 'ps' => 'application/postscript', 'roff' => 'application/x-troff',
|
||||
'scm' => 'application/x-lotusscreencam', 'set' => 'application/set', 'sh' => 'application/x-sh',
|
||||
'shar' => 'application/x-shar', 'sit' => 'application/x-stuffit', 'skd' => 'application/x-koan',
|
||||
'skm' => 'application/x-koan', 'skp' => 'application/x-koan', 'skt' => 'application/x-koan',
|
||||
'smi' => 'application/smil', 'smil' => 'application/smil', 'sol' => 'application/solids',
|
||||
'spl' => 'application/x-futuresplash', 'src' => 'application/x-wais-source', 'step' => 'application/STEP',
|
||||
'stl' => 'application/SLA', 'stp' => 'application/STEP', 'sv4cpio' => 'application/x-sv4cpio',
|
||||
'sv4crc' => 'application/x-sv4crc', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml',
|
||||
'swf' => 'application/x-shockwave-flash', 't' => 'application/x-troff',
|
||||
'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex',
|
||||
'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tr' => 'application/x-troff',
|
||||
'tsp' => 'application/dsptype', 'ttf' => 'font/ttf',
|
||||
'unv' => 'application/i-deas', 'ustar' => 'application/x-ustar',
|
||||
'vcd' => 'application/x-cdlink', 'vda' => 'application/vda', 'xlc' => 'application/vnd.ms-excel',
|
||||
'xll' => 'application/vnd.ms-excel', 'xlm' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-excel',
|
||||
'xlw' => 'application/vnd.ms-excel', 'zip' => 'application/zip', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff',
|
||||
'aiff' => 'audio/x-aiff', 'au' => 'audio/basic', 'kar' => 'audio/midi', 'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mpga' => 'audio/mpeg',
|
||||
'ra' => 'audio/x-realaudio', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin', 'snd' => 'audio/basic', 'tsi' => 'audio/TSP-audio', 'wav' => 'audio/x-wav',
|
||||
'asc' => 'text/plain', 'c' => 'text/plain', 'cc' => 'text/plain', 'css' => 'text/css', 'etx' => 'text/x-setext',
|
||||
'f' => 'text/plain', 'f90' => 'text/plain', 'h' => 'text/plain', 'hh' => 'text/plain', 'htm' => 'text/html',
|
||||
'html' => 'text/html', 'm' => 'text/plain', 'rtf' => 'text/rtf', 'rtx' => 'text/richtext', 'sgm' => 'text/sgml',
|
||||
'sgml' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'tpl' => 'text/template', 'txt' => 'text/plain',
|
||||
'xml' => 'text/xml', 'avi' => 'video/x-msvideo', 'fli' => 'video/x-fli', 'mov' => 'video/quicktime',
|
||||
'movie' => 'video/x-sgi-movie', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime', 'viv' => 'video/vnd.vivo', 'vivo' => 'video/vnd.vivo', 'gif' => 'image/gif',
|
||||
'ief' => 'image/ief', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg',
|
||||
'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'png' => 'image/png',
|
||||
'pnm' => 'image/x-portable-anymap', 'ppm' => 'image/x-portable-pixmap', 'ras' => 'image/cmu-raster',
|
||||
'rgb' => 'image/x-rgb', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'xbm' => 'image/x-xbitmap',
|
||||
'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'ice' => 'x-conference/x-cooltalk',
|
||||
'iges' => 'model/iges', 'igs' => 'model/iges', 'mesh' => 'model/mesh', 'msh' => 'model/mesh',
|
||||
'silo' => 'model/mesh', 'vrml' => 'model/vrml', 'wrl' => 'model/vrml',
|
||||
'mime' => 'www/mime', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-pdb');
|
||||
|
||||
/**
|
||||
* Holds headers sent to browser before rendering media
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_headers = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $controller
|
||||
*/
|
||||
function __construct(&$controller) {
|
||||
parent::__construct($controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display or download the given file
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function render() {
|
||||
$name = $download = $extension = $id = $modified = $path = $size = $cache = $mimeType = null;
|
||||
extract($this->viewVars, EXTR_OVERWRITE);
|
||||
|
||||
if ($size) {
|
||||
$id = $id . '_' . $size;
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
$path = $path . $id;
|
||||
} else {
|
||||
$path = APP . $path . $id;
|
||||
}
|
||||
|
||||
if (!file_exists($path)) {
|
||||
header('Content-Type: text/html');
|
||||
$this->cakeError('error404');
|
||||
}
|
||||
|
||||
if (is_null($name)) {
|
||||
$name = $id;
|
||||
}
|
||||
|
||||
if (is_array($mimeType)) {
|
||||
$this->mimeType = array_merge($this->mimeType, $mimeType);
|
||||
}
|
||||
|
||||
if (isset($extension) && isset($this->mimeType[$extension]) && connection_status() == 0) {
|
||||
$chunkSize = 8192;
|
||||
$buffer = '';
|
||||
$fileSize = @filesize($path);
|
||||
$handle = fopen($path, 'rb');
|
||||
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
if (!empty($modified)) {
|
||||
$modified = gmdate('D, d M Y H:i:s', strtotime($modified, time())) . ' GMT';
|
||||
} else {
|
||||
$modified = gmdate('D, d M Y H:i:s') . ' GMT';
|
||||
}
|
||||
|
||||
if ($download) {
|
||||
$contentTypes = array('application/octet-stream');
|
||||
$agent = env('HTTP_USER_AGENT');
|
||||
|
||||
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) {
|
||||
$contentTypes[0] = 'application/octetstream';
|
||||
} else if (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
|
||||
$contentTypes[0] = 'application/force-download';
|
||||
array_merge($contentTypes, array(
|
||||
'application/octet-stream',
|
||||
'application/download'
|
||||
));
|
||||
}
|
||||
foreach($contentTypes as $contentType) {
|
||||
$this->_header('Content-Type: ' . $contentType);
|
||||
}
|
||||
$this->_header(array(
|
||||
'Content-Disposition: attachment; filename="' . $name . '.' . $extension . '";',
|
||||
'Expires: 0',
|
||||
'Accept-Ranges: bytes',
|
||||
'Cache-Control: private' => false,
|
||||
'Pragma: private'));
|
||||
|
||||
$httpRange = env('HTTP_RANGE');
|
||||
if (isset($httpRange)) {
|
||||
list($toss, $range) = explode('=', $httpRange);
|
||||
|
||||
$size = $fileSize - 1;
|
||||
$length = $fileSize - $range;
|
||||
|
||||
$this->_header(array(
|
||||
'HTTP/1.1 206 Partial Content',
|
||||
'Content-Length: ' . $length,
|
||||
'Content-Range: bytes ' . $range . $size . '/' . $fileSize));
|
||||
|
||||
fseek($handle, $range);
|
||||
} else {
|
||||
$this->_header('Content-Length: ' . $fileSize);
|
||||
}
|
||||
} else {
|
||||
$this->_header('Date: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
|
||||
if ($cache) {
|
||||
if (!is_numeric($cache)) {
|
||||
$cache = strtotime($cache) - time();
|
||||
}
|
||||
$this->_header(array(
|
||||
'Cache-Control: max-age=' . $cache,
|
||||
'Expires: ' . gmdate('D, d M Y H:i:s', time() + $cache) . ' GMT',
|
||||
'Pragma: cache'));
|
||||
} else {
|
||||
$this->_header(array(
|
||||
'Cache-Control: must-revalidate, post-check=0, pre-check=0',
|
||||
'Pragma: no-cache'));
|
||||
}
|
||||
$this->_header(array(
|
||||
'Last-Modified: ' . $modified,
|
||||
'Content-Type: ' . $this->mimeType[$extension],
|
||||
'Content-Length: ' . $fileSize));
|
||||
}
|
||||
$this->_output();
|
||||
$this->_clearBuffer();
|
||||
|
||||
while (!feof($handle)) {
|
||||
if (!$this->_isActive()) {
|
||||
fclose($handle);
|
||||
return false;
|
||||
}
|
||||
set_time_limit(0);
|
||||
$buffer = fread($handle, $chunkSize);
|
||||
echo $buffer;
|
||||
$this->_flushBuffer();
|
||||
}
|
||||
fclose($handle);
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set headers
|
||||
* @param mixed $header
|
||||
* @param boolean $boolean
|
||||
* @access protected
|
||||
*/
|
||||
function _header($header, $boolean = true) {
|
||||
if (is_array($header)) {
|
||||
foreach ($header as $string => $boolean) {
|
||||
if (is_numeric($string)) {
|
||||
$this->_headers[] = array($boolean => true);
|
||||
} else {
|
||||
$this->_headers[] = array($string => $boolean);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
$this->_headers[] = array($header => $boolean);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to output headers
|
||||
* @access protected
|
||||
*/
|
||||
function _output() {
|
||||
foreach ($this->_headers as $key => $value) {
|
||||
$header = key($value);
|
||||
header($header, $value[$header]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if connection is still active
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function _isActive() {
|
||||
return connection_status() == 0 && !connection_aborted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the contents of the topmost output buffer and discards them
|
||||
* @return boolean
|
||||
* @access protected
|
||||
*/
|
||||
function _clearBuffer() {
|
||||
return @ob_end_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the contents of the output buffer
|
||||
* @access protected
|
||||
*/
|
||||
function _flushBuffer() {
|
||||
@flush();
|
||||
@ob_flush();
|
||||
}
|
||||
}
|
170
php-practice/web-cake/html/cake/libs/view/pages/home.ctp
Normal file
170
php-practice/web-cake/html/cake/libs/view/pages/home.ctp
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.pages
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
if (Configure::read() == 0):
|
||||
$this->cakeError('error404');
|
||||
endif;
|
||||
?>
|
||||
<h2><?php echo sprintf(__('Release Notes for CakePHP %s.', true), Configure::version()); ?></h2>
|
||||
<a href="http://cakephp.org/changelogs/1.3.6"><?php __('Read the changelog'); ?> </a>
|
||||
<?php
|
||||
if (Configure::read() > 0):
|
||||
Debugger::checkSecurityKeys();
|
||||
endif;
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if (is_writable(TMP)):
|
||||
echo '<span class="notice success">';
|
||||
__('Your tmp directory is writable.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
__('Your tmp directory is NOT writable.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
$settings = Cache::settings();
|
||||
if (!empty($settings)):
|
||||
echo '<span class="notice success">';
|
||||
printf(__('The %s is being used for caching. To change the config edit APP/config/core.php ', true), '<em>'. $settings['engine'] . 'Engine</em>');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
__('Your cache is NOT working. Please check the settings in APP/config/core.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
$filePresent = null;
|
||||
if (file_exists(CONFIGS.'database.php')):
|
||||
echo '<span class="notice success">';
|
||||
__('Your database configuration file is present.');
|
||||
$filePresent = true;
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
__('Your database configuration file is NOT present.');
|
||||
echo '<br/>';
|
||||
__('Rename config/database.php.default to config/database.php');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
App::import('Core', 'Validation');
|
||||
if (!Validation::alphaNumeric('cakephp')) {
|
||||
echo '<p><span class="notice">';
|
||||
__('PCRE has not been compiled with Unicode support.');
|
||||
echo '<br/>';
|
||||
__('Recompile PCRE with Unicode support by adding <code>--enable-unicode-properties</code> when configuring');
|
||||
echo '</span></p>';
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if (isset($filePresent)):
|
||||
if (!class_exists('ConnectionManager')) {
|
||||
require LIBS . 'model' . DS . 'connection_manager.php';
|
||||
}
|
||||
$db = ConnectionManager::getInstance();
|
||||
@$connected = $db->getDataSource('default');
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
if ($connected->isConnected()):
|
||||
echo '<span class="notice success">';
|
||||
__('Cake is able to connect to the database.');
|
||||
echo '</span>';
|
||||
else:
|
||||
echo '<span class="notice">';
|
||||
__('Cake is NOT able to connect to the database.');
|
||||
echo '</span>';
|
||||
endif;
|
||||
?>
|
||||
</p>
|
||||
<?php endif;?>
|
||||
<h3><?php __('Editing this Page'); ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
__('To change the content of this page, create: APP/views/pages/home.ctp.<br />
|
||||
To change its layout, create: APP/views/layouts/default.ctp.<br />
|
||||
You can also add some CSS styles for your pages at: APP/webroot/css.');
|
||||
?>
|
||||
</p>
|
||||
|
||||
<h3><?php __('Getting Started'); ?></h3>
|
||||
<p>
|
||||
<?php
|
||||
echo $this->Html->link(
|
||||
sprintf('<strong>%s</strong> %s', __('New', true), __('CakePHP 1.3 Docs', true)),
|
||||
'http://book.cakephp.org/view/875/x1-3-Collection',
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<?php
|
||||
echo $this->Html->link(
|
||||
__('The 15 min Blog Tutorial', true),
|
||||
'http://book.cakephp.org/view/1528/Blog',
|
||||
array('target' => '_blank', 'escape' => false)
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<h3><?php __('More about Cake'); ?></h3>
|
||||
<p>
|
||||
<?php __('CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Active Record, Association Data Mapping, Front Controller and MVC.'); ?>
|
||||
</p>
|
||||
<p>
|
||||
<?php __('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.'); ?>
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://cakefoundation.org/"><?php __('Cake Software Foundation'); ?> </a>
|
||||
<ul><li><?php __('Promoting development related to CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://www.cakephp.org"><?php __('CakePHP'); ?> </a>
|
||||
<ul><li><?php __('The Rapid Development Framework'); ?></li></ul></li>
|
||||
<li><a href="http://book.cakephp.org"><?php __('CakePHP Documentation'); ?> </a>
|
||||
<ul><li><?php __('Your Rapid Development Cookbook'); ?></li></ul></li>
|
||||
<li><a href="http://api.cakephp.org"><?php __('CakePHP API'); ?> </a>
|
||||
<ul><li><?php __('Quick Reference'); ?></li></ul></li>
|
||||
<li><a href="http://bakery.cakephp.org"><?php __('The Bakery'); ?> </a>
|
||||
<ul><li><?php __('Everything CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://live.cakephp.org"><?php __('The Show'); ?> </a>
|
||||
<ul><li><?php __('The Show is a live and archived internet radio broadcast CakePHP-related topics and answer questions live via IRC, Skype, and telephone.'); ?></li></ul></li>
|
||||
<li><a href="http://groups.google.com/group/cake-php"><?php __('CakePHP Google Group'); ?> </a>
|
||||
<ul><li><?php __('Community mailing list'); ?></li></ul></li>
|
||||
<li><a href="irc://irc.freenode.net/cakephp">irc.freenode.net #cakephp</a>
|
||||
<ul><li><?php __('Live chat about CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://github.com/cakephp/"><?php __('CakePHP Code'); ?> </a>
|
||||
<ul><li><?php __('For the Development of CakePHP Git repository, Downloads'); ?></li></ul></li>
|
||||
<li><a href="http://cakephp.lighthouseapp.com/"><?php __('CakePHP Lighthouse'); ?> </a>
|
||||
<ul><li><?php __('CakePHP Tickets, Wiki pages, Roadmap'); ?></li></ul></li>
|
||||
<li><a href="http://www.cakeforge.org"><?php __('CakeForge'); ?> </a>
|
||||
<ul><li><?php __('Open Development for CakePHP'); ?></li></ul></li>
|
||||
<li><a href="http://astore.amazon.com/cakesoftwaref-20/"><?php __('Book Store'); ?> </a>
|
||||
<ul><li><?php __('Recommended Software Books'); ?></li></ul></li>
|
||||
<li><a href="http://www.cafepress.com/cakefoundation"><?php __('CakePHP gear'); ?> </a>
|
||||
<ul><li><?php __('Get your own CakePHP gear - Doughnate to Cake'); ?></li></ul></li>
|
||||
</ul>
|
47
php-practice/web-cake/html/cake/libs/view/scaffolds/edit.ctp
Normal file
47
php-practice/web-cake/html/cake/libs/view/scaffolds/edit.ctp
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.scaffolds
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar;?> form">
|
||||
<?php
|
||||
echo $this->Form->create();
|
||||
echo $this->Form->inputs($scaffoldFields, array('created', 'modified', 'updated'));
|
||||
echo $this->Form->end(__('Submit', true));
|
||||
?>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<h3><?php __('Actions'); ?></h3>
|
||||
<ul>
|
||||
<?php if ($this->action != 'add'):?>
|
||||
<li><?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $this->Form->value($modelClass.'.'.$primaryKey)), null, __('Are you sure you want to delete', true).' #' . $this->Form->value($modelClass.'.'.$primaryKey)); ?></li>
|
||||
<?php endif;?>
|
||||
<li><?php echo $this->Html->link(__('List', true).' '.$pluralHumanName, array('action' => 'index'));?></li>
|
||||
<?php
|
||||
$done = array();
|
||||
foreach ($associations as $_type => $_data) {
|
||||
foreach ($_data as $_alias => $_details) {
|
||||
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
|
||||
echo "\t\t<li>" . $this->Html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' =>'index')) . "</li>\n";
|
||||
echo "\t\t<li>" . $this->Html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' =>'add')) . "</li>\n";
|
||||
$done[] = $_details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.console.libs.templates.views
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar;?> index">
|
||||
<h2><?php echo $pluralHumanName;?></h2>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<?php foreach ($scaffoldFields as $_field):?>
|
||||
<th><?php echo $this->Paginator->sort($_field);?></th>
|
||||
<?php endforeach;?>
|
||||
<th><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach (${$pluralVar} as ${$singularVar}):
|
||||
$class = null;
|
||||
if ($i++ % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
echo "\n";
|
||||
echo "\t<tr{$class}>\n";
|
||||
foreach ($scaffoldFields as $_field) {
|
||||
$isKey = false;
|
||||
if (!empty($associations['belongsTo'])) {
|
||||
foreach ($associations['belongsTo'] as $_alias => $_details) {
|
||||
if ($_field === $_details['foreignKey']) {
|
||||
$isKey = true;
|
||||
echo "\t\t<td>\n\t\t\t" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t</td>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($isKey !== true) {
|
||||
echo "\t\t<td>\n\t\t\t" . ${$singularVar}[$modelClass][$_field] . " \n\t\t</td>\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\t\t<td class=\"actions\">\n";
|
||||
echo "\t\t\t" . $this->Html->link(__('View', true), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey])) . "\n";
|
||||
echo "\t\t\t" . $this->Html->link(__('Edit', true), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])) . "\n";
|
||||
echo "\t\t\t" . $this->Html->link(__('Delete', true), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __('Are you sure you want to delete', true).' #' . ${$singularVar}[$modelClass][$primaryKey]) . "\n";
|
||||
echo "\t\t</td>\n";
|
||||
echo "\t</tr>\n";
|
||||
|
||||
endforeach;
|
||||
echo "\n";
|
||||
?>
|
||||
</table>
|
||||
<p><?php
|
||||
echo $this->Paginator->counter(array(
|
||||
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
|
||||
));
|
||||
?></p>
|
||||
<div class="paging">
|
||||
<?php echo "\t" . $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled')) . "\n";?>
|
||||
| <?php echo $this->Paginator->numbers() . "\n"?>
|
||||
<?php echo "\t ". $this->Paginator->next(__('next', true) .' >>', array(), null, array('class' => 'disabled')) . "\n";?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<h3><?php __('Actions'); ?></h3>
|
||||
<ul>
|
||||
<li><?php echo $this->Html->link(sprintf(__('New %s', true), $singularHumanName), array('action' => 'add')); ?></li>
|
||||
<?php
|
||||
$done = array();
|
||||
foreach ($associations as $_type => $_data) {
|
||||
foreach ($_data as $_alias => $_details) {
|
||||
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
|
||||
echo "\t\t<li>" . $this->Html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>\n";
|
||||
echo "\t\t<li>" . $this->Html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>\n";
|
||||
$done[] = $_details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
159
php-practice/web-cake/html/cake/libs/view/scaffolds/view.ctp
Normal file
159
php-practice/web-cake/html/cake/libs/view/scaffolds/view.ctp
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.scaffolds
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
?>
|
||||
<div class="<?php echo $pluralVar;?> view">
|
||||
<h2><?php printf(__("View %s", true), $singularHumanName); ?></h2>
|
||||
<dl>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($scaffoldFields as $_field) {
|
||||
$class = null;
|
||||
if ($i++ % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
$isKey = false;
|
||||
if (!empty($associations['belongsTo'])) {
|
||||
foreach ($associations['belongsTo'] as $_alias => $_details) {
|
||||
if ($_field === $_details['foreignKey']) {
|
||||
$isKey = true;
|
||||
echo "\t\t<dt{$class}>" . Inflector::humanize($_alias) . "</dt>\n";
|
||||
echo "\t\t<dd{$class}>\n\t\t\t" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t </dd>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($isKey !== true) {
|
||||
echo "\t\t<dt{$class}>" . Inflector::humanize($_field) . "</dt>\n";
|
||||
echo "\t\t<dd{$class}>\n\t\t\t{${$singularVar}[$modelClass][$_field]}\n \t\t</dd>\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<h3><?php __('Actions'); ?></h3>
|
||||
<ul>
|
||||
<?php
|
||||
echo "\t\t<li>" .$this->Html->link(sprintf(__('Edit %s', true), $singularHumanName), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])). " </li>\n";
|
||||
echo "\t\t<li>" .$this->Html->link(sprintf(__('Delete %s', true), $singularHumanName), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __('Are you sure you want to delete', true).' #' . ${$singularVar}[$modelClass][$primaryKey] . '?'). " </li>\n";
|
||||
echo "\t\t<li>" .$this->Html->link(sprintf(__('List %s', true), $pluralHumanName), array('action' => 'index')). " </li>\n";
|
||||
echo "\t\t<li>" .$this->Html->link(sprintf(__('New %s', true), $singularHumanName), array('action' => 'add')). " </li>\n";
|
||||
|
||||
$done = array();
|
||||
foreach ($associations as $_type => $_data) {
|
||||
foreach ($_data as $_alias => $_details) {
|
||||
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
|
||||
echo "\t\t<li>" . $this->Html->link(sprintf(__('List %s', true), Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>\n";
|
||||
echo "\t\t<li>" . $this->Html->link(sprintf(__('New %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>\n";
|
||||
$done[] = $_details['controller'];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
if (!empty($associations['hasOne'])) :
|
||||
foreach ($associations['hasOne'] as $_alias => $_details): ?>
|
||||
<div class="related">
|
||||
<h3><?php printf(__("Related %s", true), Inflector::humanize($_details['controller'])); ?></h3>
|
||||
<?php if (!empty(${$singularVar}[$_alias])):?>
|
||||
<dl>
|
||||
<?php
|
||||
$i = 0;
|
||||
$otherFields = array_keys(${$singularVar}[$_alias]);
|
||||
foreach ($otherFields as $_field) {
|
||||
$class = null;
|
||||
if ($i++ % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
echo "\t\t<dt{$class}>" . Inflector::humanize($_field) . "</dt>\n";
|
||||
echo "\t\t<dd{$class}>\n\t" . ${$singularVar}[$_alias][$_field] . "\n </dd>\n";
|
||||
}
|
||||
?>
|
||||
</dl>
|
||||
<?php endif; ?>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $this->Html->link(sprintf(__('Edit %s', true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'edit', ${$singularVar}[$_alias][$_details['primaryKey']]))."</li>\n";?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if (empty($associations['hasMany'])) {
|
||||
$associations['hasMany'] = array();
|
||||
}
|
||||
if (empty($associations['hasAndBelongsToMany'])) {
|
||||
$associations['hasAndBelongsToMany'] = array();
|
||||
}
|
||||
$relations = array_merge($associations['hasMany'], $associations['hasAndBelongsToMany']);
|
||||
$i = 0;
|
||||
foreach ($relations as $_alias => $_details):
|
||||
$otherSingularVar = Inflector::variable($_alias);
|
||||
?>
|
||||
<div class="related">
|
||||
<h3><?php printf(__("Related %s", true), Inflector::humanize($_details['controller'])); ?></h3>
|
||||
<?php if (!empty(${$singularVar}[$_alias])):?>
|
||||
<table cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<?php
|
||||
$otherFields = array_keys(${$singularVar}[$_alias][0]);
|
||||
if (isset($_details['with'])) {
|
||||
$index = array_search($_details['with'], $otherFields);
|
||||
unset($otherFields[$index]);
|
||||
}
|
||||
foreach ($otherFields as $_field) {
|
||||
echo "\t\t<th>" . Inflector::humanize($_field) . "</th>\n";
|
||||
}
|
||||
?>
|
||||
<th class="actions">Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach (${$singularVar}[$_alias] as ${$otherSingularVar}):
|
||||
$class = null;
|
||||
if ($i++ % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
echo "\t\t<tr{$class}>\n";
|
||||
|
||||
foreach ($otherFields as $_field) {
|
||||
echo "\t\t\t<td>" . ${$otherSingularVar}[$_field] . "</td>\n";
|
||||
}
|
||||
|
||||
echo "\t\t\t<td class=\"actions\">\n";
|
||||
echo "\t\t\t\t" . $this->Html->link(__('View', true), array('controller' => $_details['controller'], 'action' => 'view', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
|
||||
echo "\t\t\t\t" . $this->Html->link(__('Edit', true), array('controller' => $_details['controller'], 'action' => 'edit', ${$otherSingularVar}[$_details['primaryKey']])). "\n";
|
||||
echo "\t\t\t\t" . $this->Html->link(__('Delete', true), array('controller' => $_details['controller'], 'action' => 'delete', ${$otherSingularVar}[$_details['primaryKey']]), null, __('Are you sure you want to delete', true).' #' . ${$otherSingularVar}[$_details['primaryKey']] . '?'). "\n";
|
||||
echo "\t\t\t</td>\n";
|
||||
echo "\t\t</tr>\n";
|
||||
endforeach;
|
||||
?>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $this->Html->link(sprintf(__("New %s", true), Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add'));?> </li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach;?>
|
74
php-practice/web-cake/html/cake/libs/view/theme.php
Normal file
74
php-practice/web-cake/html/cake/libs/view/theme.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* A custom view class that is used for themeing
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Theme view class
|
||||
*
|
||||
* Allows the creation of multiple themes to be used in an app. Theme views are regular view files
|
||||
* that can provide unique HTML and static assets. If theme views are not found for the current view
|
||||
* the default app view files will be used. You can set `$this->theme` and `$this->view = 'Theme'`
|
||||
* in your Controller to use the ThemeView.
|
||||
*
|
||||
* Example of theme path with `$this->theme = 'super_hot';` Would be `app/views/themed/super_hot/posts`
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
*/
|
||||
class ThemeView extends View {
|
||||
/**
|
||||
* Constructor for ThemeView sets $this->theme.
|
||||
*
|
||||
* @param Controller $controller Controller object to be rendered.
|
||||
* @param boolean $register Should the view be registered in the registry.
|
||||
*/
|
||||
function __construct(&$controller, $register = true) {
|
||||
parent::__construct($controller, $register);
|
||||
$this->theme =& $controller->theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all possible paths to find view files in order
|
||||
*
|
||||
* @param string $plugin The name of the plugin views are being found for.
|
||||
* @param boolean $cached Set to true to force dir scan.
|
||||
* @return array paths
|
||||
* @access protected
|
||||
* @todo Make theme path building respect $cached parameter.
|
||||
*/
|
||||
function _paths($plugin = null, $cached = true) {
|
||||
$paths = parent::_paths($plugin, $cached);
|
||||
$themePaths = array();
|
||||
|
||||
if (!empty($this->theme)) {
|
||||
$count = count($paths);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (strpos($paths[$i], DS . 'plugins' . DS) === false
|
||||
&& strpos($paths[$i], DS . 'libs' . DS . 'view') === false) {
|
||||
if ($plugin) {
|
||||
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS . 'plugins' . DS . $plugin . DS;
|
||||
}
|
||||
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS;
|
||||
}
|
||||
}
|
||||
$paths = array_merge($themePaths, $paths);
|
||||
}
|
||||
return $paths;
|
||||
}
|
||||
}
|
971
php-practice/web-cake/html/cake/libs/view/view.php
Normal file
971
php-practice/web-cake/html/cake/libs/view/view.php
Normal file
@@ -0,0 +1,971 @@
|
||||
<?php
|
||||
/**
|
||||
* Methods for displaying presentation data in the view.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Included libraries.
|
||||
*/
|
||||
App::import('Core', 'ClassRegistry');
|
||||
App::import('View', 'Helper', false);
|
||||
|
||||
/**
|
||||
* View, the V in the MVC triad.
|
||||
*
|
||||
* Class holding methods for displaying presentation data.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view
|
||||
*/
|
||||
class View extends Object {
|
||||
|
||||
/**
|
||||
* Path parts for creating links in views.
|
||||
*
|
||||
* @var string Base URL
|
||||
* @access public
|
||||
*/
|
||||
var $base = null;
|
||||
|
||||
/**
|
||||
* Stores the current URL (for links etc.)
|
||||
*
|
||||
* @var string Current URL
|
||||
*/
|
||||
var $here = null;
|
||||
|
||||
/**
|
||||
* Name of the plugin.
|
||||
*
|
||||
* @link http://manual.cakephp.org/chapter/plugins
|
||||
* @var string
|
||||
*/
|
||||
var $plugin = null;
|
||||
|
||||
/**
|
||||
* Name of the controller.
|
||||
*
|
||||
* @var string Name of controller
|
||||
* @access public
|
||||
*/
|
||||
var $name = null;
|
||||
|
||||
/**
|
||||
* Action to be performed.
|
||||
*
|
||||
* @var string Name of action
|
||||
* @access public
|
||||
*/
|
||||
var $action = null;
|
||||
|
||||
/**
|
||||
* Array of parameter data
|
||||
*
|
||||
* @var array Parameter data
|
||||
*/
|
||||
var $params = array();
|
||||
|
||||
/**
|
||||
* Current passed params
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
var $passedArgs = array();
|
||||
|
||||
/**
|
||||
* Array of data
|
||||
*
|
||||
* @var array Parameter data
|
||||
*/
|
||||
var $data = array();
|
||||
|
||||
/**
|
||||
* An array of names of built-in helpers to include.
|
||||
*
|
||||
* @var mixed A single name as a string or a list of names as an array.
|
||||
* @access public
|
||||
*/
|
||||
var $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* Path to View.
|
||||
*
|
||||
* @var string Path to View
|
||||
*/
|
||||
var $viewPath = null;
|
||||
|
||||
/**
|
||||
* Variables for the view
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $viewVars = array();
|
||||
|
||||
/**
|
||||
* Name of layout to use with this View.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $layout = 'default';
|
||||
|
||||
/**
|
||||
* Path to Layout.
|
||||
*
|
||||
* @var string Path to Layout
|
||||
*/
|
||||
var $layoutPath = null;
|
||||
|
||||
/**
|
||||
* Turns on or off Cake's conventional mode of rendering views. On by default.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $autoRender = true;
|
||||
|
||||
/**
|
||||
* Turns on or off Cake's conventional mode of finding layout files. On by default.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $autoLayout = true;
|
||||
|
||||
/**
|
||||
* File extension. Defaults to Cake's template ".ctp".
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $ext = '.ctp';
|
||||
|
||||
/**
|
||||
* Sub-directory for this view file.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $subDir = null;
|
||||
|
||||
/**
|
||||
* Theme name.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $theme = null;
|
||||
|
||||
/**
|
||||
* Used to define methods a controller that will be cached.
|
||||
*
|
||||
* @see Controller::$cacheAction
|
||||
* @var mixed
|
||||
* @access public
|
||||
*/
|
||||
var $cacheAction = false;
|
||||
|
||||
/**
|
||||
* holds current errors for the model validation
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $validationErrors = array();
|
||||
|
||||
/**
|
||||
* True when the view has been rendered.
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $hasRendered = false;
|
||||
|
||||
/**
|
||||
* Array of loaded view helpers.
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $loaded = array();
|
||||
|
||||
/**
|
||||
* True if in scope of model-specific region
|
||||
*
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $modelScope = false;
|
||||
|
||||
/**
|
||||
* Name of current model this view context is attached to
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $model = null;
|
||||
|
||||
/**
|
||||
* Name of association model this view context is attached to
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $association = null;
|
||||
|
||||
/**
|
||||
* Name of current model field this view context is attached to
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $field = null;
|
||||
|
||||
/**
|
||||
* Suffix of current field this view context is attached to
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $fieldSuffix = null;
|
||||
|
||||
/**
|
||||
* The current model ID this view context is attached to
|
||||
*
|
||||
* @var mixed
|
||||
* @access public
|
||||
*/
|
||||
var $modelId = null;
|
||||
|
||||
/**
|
||||
* List of generated DOM UUIDs
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $uuids = array();
|
||||
|
||||
/**
|
||||
* Holds View output.
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $output = false;
|
||||
|
||||
/**
|
||||
* List of variables to collect from the associated controller
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $__passedVars = array(
|
||||
'viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot',
|
||||
'helpers', 'here', 'layout', 'name', 'layoutPath', 'viewPath',
|
||||
'params', 'data', 'plugin', 'passedArgs', 'cacheAction'
|
||||
);
|
||||
|
||||
/**
|
||||
* Scripts (and/or other <head /> tags) for the layout
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__scripts = array();
|
||||
|
||||
/**
|
||||
* Holds an array of paths.
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__paths = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Controller $controller A controller object to pull View::__passedArgs from.
|
||||
* @param boolean $register Should the View instance be registered in the ClassRegistry
|
||||
* @return View
|
||||
*/
|
||||
function __construct(&$controller, $register = true) {
|
||||
if (is_object($controller)) {
|
||||
$count = count($this->__passedVars);
|
||||
for ($j = 0; $j < $count; $j++) {
|
||||
$var = $this->__passedVars[$j];
|
||||
$this->{$var} = $controller->{$var};
|
||||
}
|
||||
}
|
||||
parent::__construct();
|
||||
|
||||
if ($register) {
|
||||
ClassRegistry::addObject('view', $this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
|
||||
*
|
||||
* This realizes the concept of Elements, (or "partial layouts")
|
||||
* and the $params array is used to send data to be used in the
|
||||
* Element. Elements can be cached through use of the cache key.
|
||||
*
|
||||
* ### Special params
|
||||
*
|
||||
* - `cache` - enable caching for this element accepts boolean or strtotime compatible string.
|
||||
* Can also be an array. If `cache` is an array,
|
||||
* `time` is used to specify duration of cache.
|
||||
* `key` can be used to create unique cache files.
|
||||
* - `plugin` - Load an element from a specific plugin.
|
||||
*
|
||||
* @param string $name Name of template file in the/app/views/elements/ folder
|
||||
* @param array $params Array of data to be made available to the for rendered
|
||||
* view (i.e. the Element)
|
||||
* @return string Rendered Element
|
||||
* @access public
|
||||
*/
|
||||
function element($name, $params = array(), $loadHelpers = false) {
|
||||
$file = $plugin = $key = null;
|
||||
|
||||
if (isset($params['plugin'])) {
|
||||
$plugin = $params['plugin'];
|
||||
}
|
||||
|
||||
if (isset($this->plugin) && !$plugin) {
|
||||
$plugin = $this->plugin;
|
||||
}
|
||||
|
||||
if (isset($params['cache'])) {
|
||||
$expires = '+1 day';
|
||||
|
||||
if (is_array($params['cache'])) {
|
||||
$expires = $params['cache']['time'];
|
||||
$key = Inflector::slug($params['cache']['key']);
|
||||
} elseif ($params['cache'] !== true) {
|
||||
$expires = $params['cache'];
|
||||
$key = implode('_', array_keys($params));
|
||||
}
|
||||
|
||||
if ($expires) {
|
||||
$cacheFile = 'element_' . $key . '_' . $plugin . Inflector::slug($name);
|
||||
$cache = cache('views' . DS . $cacheFile, null, $expires);
|
||||
|
||||
if (is_string($cache)) {
|
||||
return $cache;
|
||||
}
|
||||
}
|
||||
}
|
||||
$paths = $this->_paths($plugin);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
|
||||
$file = $path . 'elements' . DS . $name . $this->ext;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_file($file)) {
|
||||
$params = array_merge_recursive($params, $this->loaded);
|
||||
$element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
||||
if (isset($params['cache']) && isset($cacheFile) && isset($expires)) {
|
||||
cache('views' . DS . $cacheFile, $element, $expires);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
$file = $paths[0] . 'elements' . DS . $name . $this->ext;
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
return "Not Found: " . $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders view for given action and layout. If $file is given, that is used
|
||||
* for a view filename (e.g. customFunkyView.ctp).
|
||||
*
|
||||
* @param string $action Name of action to render for
|
||||
* @param string $layout Layout to use
|
||||
* @param string $file Custom filename for view
|
||||
* @return string Rendered Element
|
||||
* @access public
|
||||
*/
|
||||
function render($action = null, $layout = null, $file = null) {
|
||||
if ($this->hasRendered) {
|
||||
return true;
|
||||
}
|
||||
$out = null;
|
||||
|
||||
if ($file != null) {
|
||||
$action = $file;
|
||||
}
|
||||
|
||||
if ($action !== false && $viewFileName = $this->_getViewFileName($action)) {
|
||||
$out = $this->_render($viewFileName, $this->viewVars);
|
||||
}
|
||||
|
||||
if ($layout === null) {
|
||||
$layout = $this->layout;
|
||||
}
|
||||
|
||||
if ($out !== false) {
|
||||
if ($layout && $this->autoLayout) {
|
||||
$out = $this->renderLayout($out, $layout);
|
||||
$isCached = (
|
||||
isset($this->loaded['cache']) ||
|
||||
Configure::read('Cache.check') === true
|
||||
);
|
||||
|
||||
if ($isCached) {
|
||||
$replace = array('<cake:nocache>', '</cake:nocache>');
|
||||
$out = str_replace($replace, '', $out);
|
||||
}
|
||||
}
|
||||
$this->hasRendered = true;
|
||||
} else {
|
||||
$out = $this->_render($viewFileName, $this->viewVars);
|
||||
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>", true), $viewFileName, $out), E_USER_ERROR);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a layout. Returns output from _render(). Returns false on error.
|
||||
* Several variables are created for use in layout.
|
||||
*
|
||||
* - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control.
|
||||
* - `content_for_layout` - contains rendered view file
|
||||
* - `scripts_for_layout` - contains scripts added to header
|
||||
*
|
||||
* @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
|
||||
* @return mixed Rendered output, or false on error
|
||||
* @access public
|
||||
*/
|
||||
function renderLayout($content_for_layout, $layout = null) {
|
||||
$layoutFileName = $this->_getLayoutFileName($layout);
|
||||
if (empty($layoutFileName)) {
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
$dataForLayout = array_merge($this->viewVars, array(
|
||||
'content_for_layout' => $content_for_layout,
|
||||
'scripts_for_layout' => implode("\n\t", $this->__scripts),
|
||||
));
|
||||
|
||||
if (!isset($dataForLayout['title_for_layout'])) {
|
||||
$dataForLayout['title_for_layout'] = Inflector::humanize($this->viewPath);
|
||||
}
|
||||
|
||||
if (empty($this->loaded) && !empty($this->helpers)) {
|
||||
$loadHelpers = true;
|
||||
} else {
|
||||
$loadHelpers = false;
|
||||
$dataForLayout = array_merge($dataForLayout, $this->loaded);
|
||||
}
|
||||
|
||||
$this->_triggerHelpers('beforeLayout');
|
||||
$this->output = $this->_render($layoutFileName, $dataForLayout, $loadHelpers, true);
|
||||
|
||||
if ($this->output === false) {
|
||||
$this->output = $this->_render($layoutFileName, $data_for_layout);
|
||||
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>", true), $layoutFileName, $this->output), E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_triggerHelpers('afterLayout');
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a callback on all loaded Helpers. All helpers must implement this method,
|
||||
* it is not checked before being called. You can add additional helper callbacks in AppHelper.
|
||||
*
|
||||
* @param string $callback name of callback fire.
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
function _triggerHelpers($callback) {
|
||||
if (empty($this->loaded)) {
|
||||
return false;
|
||||
}
|
||||
$helpers = array_keys($this->loaded);
|
||||
foreach ($helpers as $helperName) {
|
||||
$helper =& $this->loaded[$helperName];
|
||||
if (is_object($helper)) {
|
||||
if (is_subclass_of($helper, 'Helper')) {
|
||||
$helper->{$callback}();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render cached view. Works in concert with CacheHelper and Dispatcher to
|
||||
* render cached view files.
|
||||
*
|
||||
* @param string $filename the cache file to include
|
||||
* @param string $timeStart the page render start time
|
||||
* @return boolean Success of rendering the cached file.
|
||||
* @access public
|
||||
*/
|
||||
function renderCache($filename, $timeStart) {
|
||||
ob_start();
|
||||
include ($filename);
|
||||
|
||||
if (Configure::read() > 0 && $this->layout != 'xml') {
|
||||
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
|
||||
}
|
||||
$out = ob_get_clean();
|
||||
|
||||
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) {
|
||||
if (time() >= $match['1']) {
|
||||
@unlink($filename);
|
||||
unset ($out);
|
||||
return false;
|
||||
} else {
|
||||
if ($this->layout === 'xml') {
|
||||
header('Content-type: text/xml');
|
||||
}
|
||||
$commentLength = strlen('<!--cachetime:' . $match['1'] . '-->');
|
||||
echo substr($out, $commentLength);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of variables available in the current View context
|
||||
*
|
||||
* @return array Array of the set view variable names.
|
||||
* @access public
|
||||
*/
|
||||
function getVars() {
|
||||
return array_keys($this->viewVars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the given View variable(s)
|
||||
*
|
||||
* @param string $var The view var you want the contents of.
|
||||
* @return mixed The content of the named var if its set, otherwise null.
|
||||
* @access public
|
||||
*/
|
||||
function getVar($var) {
|
||||
if (!isset($this->viewVars[$var])) {
|
||||
return null;
|
||||
} else {
|
||||
return $this->viewVars[$var];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a script block or other element to be inserted in $scripts_for_layout in
|
||||
* the `<head />` of a document layout
|
||||
*
|
||||
* @param string $name Either the key name for the script, or the script content. Name can be used to
|
||||
* update/replace a script element.
|
||||
* @param string $content The content of the script being added, optional.
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function addScript($name, $content = null) {
|
||||
if (empty($content)) {
|
||||
if (!in_array($name, array_values($this->__scripts))) {
|
||||
$this->__scripts[] = $name;
|
||||
}
|
||||
} else {
|
||||
$this->__scripts[$name] = $content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique, non-random DOM ID for an object, based on the object type and the target URL.
|
||||
*
|
||||
* @param string $object Type of object, i.e. 'form' or 'link'
|
||||
* @param string $url The object's target URL
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function uuid($object, $url) {
|
||||
$c = 1;
|
||||
$url = Router::url($url);
|
||||
$hash = $object . substr(md5($object . $url), 0, 10);
|
||||
while (in_array($hash, $this->uuids)) {
|
||||
$hash = $object . substr(md5($object . $url . $c), 0, 10);
|
||||
$c++;
|
||||
}
|
||||
$this->uuids[] = $hash;
|
||||
return $hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity reference of the current context as an array of identity parts
|
||||
*
|
||||
* @return array An array containing the identity elements of an entity
|
||||
* @access public
|
||||
*/
|
||||
function entity() {
|
||||
$assoc = ($this->association) ? $this->association : $this->model;
|
||||
if (!empty($this->entityPath)) {
|
||||
$path = explode('.', $this->entityPath);
|
||||
$count = count($path);
|
||||
if (
|
||||
($count == 1 && !empty($this->association)) ||
|
||||
($count == 1 && $this->model != $this->entityPath) ||
|
||||
($count == 1 && empty($this->association) && !empty($this->field)) ||
|
||||
($count == 2 && !empty($this->fieldSuffix)) ||
|
||||
is_numeric($path[0]) && !empty($assoc)
|
||||
) {
|
||||
array_unshift($path, $assoc);
|
||||
}
|
||||
return Set::filter($path);
|
||||
}
|
||||
return array_values(Set::filter(
|
||||
array($assoc, $this->modelId, $this->field, $this->fieldSuffix)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a template or element to set a variable that will be available in
|
||||
* a layout or other element. Analagous to Controller::set.
|
||||
*
|
||||
* @param mixed $one A string or an array of data.
|
||||
* @param mixed $two Value in case $one is a string (which then works as the key).
|
||||
* Unused if $one is an associative array, otherwise serves as the values to $one's keys.
|
||||
* @return void
|
||||
* @access public
|
||||
*/
|
||||
function set($one, $two = null) {
|
||||
$data = null;
|
||||
if (is_array($one)) {
|
||||
if (is_array($two)) {
|
||||
$data = array_combine($one, $two);
|
||||
} else {
|
||||
$data = $one;
|
||||
}
|
||||
} else {
|
||||
$data = array($one => $two);
|
||||
}
|
||||
if ($data == null) {
|
||||
return false;
|
||||
}
|
||||
$this->viewVars = $data + $this->viewVars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error page to the user. Uses layouts/error.ctp to render the page.
|
||||
*
|
||||
* @param integer $code HTTP Error code (for instance: 404)
|
||||
* @param string $name Name of the error (for instance: Not Found)
|
||||
* @param string $message Error message as a web page
|
||||
* @access public
|
||||
*/
|
||||
function error($code, $name, $message) {
|
||||
header ("HTTP/1.1 {$code} {$name}");
|
||||
print ($this->_render(
|
||||
$this->_getLayoutFileName('error'),
|
||||
array('code' => $code, 'name' => $name, 'message' => $message)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders and returns output for given view filename with its
|
||||
* array of data.
|
||||
*
|
||||
* @param string $___viewFn Filename of the view
|
||||
* @param array $___dataForView Data to include in rendered view
|
||||
* @param boolean $loadHelpers Boolean to indicate that helpers should be loaded.
|
||||
* @param boolean $cached Whether or not to trigger the creation of a cache file.
|
||||
* @return string Rendered output
|
||||
* @access protected
|
||||
*/
|
||||
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
|
||||
$loadedHelpers = array();
|
||||
|
||||
if ($this->helpers != false && $loadHelpers === true) {
|
||||
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
|
||||
$helpers = array_keys($loadedHelpers);
|
||||
$helperNames = array_map(array('Inflector', 'variable'), $helpers);
|
||||
|
||||
for ($i = count($helpers) - 1; $i >= 0; $i--) {
|
||||
$name = $helperNames[$i];
|
||||
$helper =& $loadedHelpers[$helpers[$i]];
|
||||
|
||||
if (!isset($___dataForView[$name])) {
|
||||
${$name} =& $helper;
|
||||
}
|
||||
$this->loaded[$helperNames[$i]] =& $helper;
|
||||
$this->{$helpers[$i]} =& $helper;
|
||||
}
|
||||
$this->_triggerHelpers('beforeRender');
|
||||
unset($name, $loadedHelpers, $helpers, $i, $helperNames, $helper);
|
||||
}
|
||||
|
||||
extract($___dataForView, EXTR_SKIP);
|
||||
ob_start();
|
||||
|
||||
if (Configure::read() > 0) {
|
||||
include ($___viewFn);
|
||||
} else {
|
||||
@include ($___viewFn);
|
||||
}
|
||||
|
||||
if ($loadHelpers === true) {
|
||||
$this->_triggerHelpers('afterRender');
|
||||
}
|
||||
|
||||
$out = ob_get_clean();
|
||||
$caching = (
|
||||
isset($this->loaded['cache']) &&
|
||||
(($this->cacheAction != false)) && (Configure::read('Cache.check') === true)
|
||||
);
|
||||
|
||||
if ($caching) {
|
||||
if (is_a($this->loaded['cache'], 'CacheHelper')) {
|
||||
$cache =& $this->loaded['cache'];
|
||||
$cache->base = $this->base;
|
||||
$cache->here = $this->here;
|
||||
$cache->helpers = $this->helpers;
|
||||
$cache->action = $this->action;
|
||||
$cache->controllerName = $this->name;
|
||||
$cache->layout = $this->layout;
|
||||
$cache->cacheAction = $this->cacheAction;
|
||||
$cache->cache($___viewFn, $out, $cached);
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads helpers, with their dependencies.
|
||||
*
|
||||
* @param array $loaded List of helpers that are already loaded.
|
||||
* @param array $helpers List of helpers to load.
|
||||
* @param string $parent holds name of helper, if loaded helper has helpers
|
||||
* @return array Array containing the loaded helpers.
|
||||
* @access protected
|
||||
*/
|
||||
function &_loadHelpers(&$loaded, $helpers, $parent = null) {
|
||||
foreach ($helpers as $i => $helper) {
|
||||
$options = array();
|
||||
|
||||
if (!is_int($i)) {
|
||||
$options = $helper;
|
||||
$helper = $i;
|
||||
}
|
||||
list($plugin, $helper) = pluginSplit($helper, true, $this->plugin);
|
||||
$helperCn = $helper . 'Helper';
|
||||
|
||||
if (!isset($loaded[$helper])) {
|
||||
if (!class_exists($helperCn)) {
|
||||
$isLoaded = false;
|
||||
if (!is_null($plugin)) {
|
||||
$isLoaded = App::import('Helper', $plugin . $helper);
|
||||
}
|
||||
if (!$isLoaded) {
|
||||
if (!App::import('Helper', $helper)) {
|
||||
$this->cakeError('missingHelperFile', array(array(
|
||||
'helper' => $helper,
|
||||
'file' => Inflector::underscore($helper) . '.php',
|
||||
'base' => $this->base
|
||||
)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!class_exists($helperCn)) {
|
||||
$this->cakeError('missingHelperClass', array(array(
|
||||
'helper' => $helper,
|
||||
'file' => Inflector::underscore($helper) . '.php',
|
||||
'base' => $this->base
|
||||
)));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$loaded[$helper] =& new $helperCn($options);
|
||||
$vars = array('base', 'webroot', 'here', 'params', 'action', 'data', 'theme', 'plugin');
|
||||
$c = count($vars);
|
||||
|
||||
for ($j = 0; $j < $c; $j++) {
|
||||
$loaded[$helper]->{$vars[$j]} = $this->{$vars[$j]};
|
||||
}
|
||||
|
||||
if (!empty($this->validationErrors)) {
|
||||
$loaded[$helper]->validationErrors = $this->validationErrors;
|
||||
}
|
||||
if (is_array($loaded[$helper]->helpers) && !empty($loaded[$helper]->helpers)) {
|
||||
$loaded =& $this->_loadHelpers($loaded, $loaded[$helper]->helpers, $helper);
|
||||
}
|
||||
}
|
||||
if (isset($loaded[$parent])) {
|
||||
$loaded[$parent]->{$helper} =& $loaded[$helper];
|
||||
}
|
||||
}
|
||||
return $loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filename of given action's template file (.ctp) as a string.
|
||||
* CamelCased action names will be under_scored! This means that you can have
|
||||
* LongActionNames that refer to long_action_names.ctp views.
|
||||
*
|
||||
* @param string $name Controller action to find template filename for
|
||||
* @return string Template filename
|
||||
* @access protected
|
||||
*/
|
||||
function _getViewFileName($name = null) {
|
||||
$subDir = null;
|
||||
|
||||
if (!is_null($this->subDir)) {
|
||||
$subDir = $this->subDir . DS;
|
||||
}
|
||||
|
||||
if ($name === null) {
|
||||
$name = $this->action;
|
||||
}
|
||||
$name = str_replace('/', DS, $name);
|
||||
|
||||
if (strpos($name, DS) === false && $name[0] !== '.') {
|
||||
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
||||
} elseif (strpos($name, DS) !== false) {
|
||||
if ($name{0} === DS || $name{1} === ':') {
|
||||
if (is_file($name)) {
|
||||
return $name;
|
||||
}
|
||||
$name = trim($name, DS);
|
||||
} else if ($name[0] === '.') {
|
||||
$name = substr($name, 3);
|
||||
} else {
|
||||
$name = $this->viewPath . DS . $subDir . $name;
|
||||
}
|
||||
}
|
||||
$paths = $this->_paths(Inflector::underscore($this->plugin));
|
||||
|
||||
$exts = array($this->ext);
|
||||
if ($this->ext !== '.ctp') {
|
||||
array_push($exts, '.ctp');
|
||||
}
|
||||
foreach ($exts as $ext) {
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path . $name . $ext)) {
|
||||
return $path . $name . $ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
$defaultPath = $paths[0];
|
||||
|
||||
if ($this->plugin) {
|
||||
$pluginPaths = App::path('plugins');
|
||||
foreach ($paths as $path) {
|
||||
if (strpos($path, $pluginPaths[0]) === 0) {
|
||||
$defaultPath = $path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_missingView($defaultPath . $name . $this->ext, 'missingView');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns layout filename for this template as a string.
|
||||
*
|
||||
* @param string $name The name of the layout to find.
|
||||
* @return string Filename for layout file (.ctp).
|
||||
* @access protected
|
||||
*/
|
||||
function _getLayoutFileName($name = null) {
|
||||
if ($name === null) {
|
||||
$name = $this->layout;
|
||||
}
|
||||
$subDir = null;
|
||||
|
||||
if (!is_null($this->layoutPath)) {
|
||||
$subDir = $this->layoutPath . DS;
|
||||
}
|
||||
$paths = $this->_paths(Inflector::underscore($this->plugin));
|
||||
$file = 'layouts' . DS . $subDir . $name;
|
||||
|
||||
$exts = array($this->ext);
|
||||
if ($this->ext !== '.ctp') {
|
||||
array_push($exts, '.ctp');
|
||||
}
|
||||
foreach ($exts as $ext) {
|
||||
foreach ($paths as $path) {
|
||||
if (file_exists($path . $file . $ext)) {
|
||||
return $path . $file . $ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a misssing view error message
|
||||
*
|
||||
* @param string $viewFileName the filename that should exist
|
||||
* @return false
|
||||
* @access protected
|
||||
*/
|
||||
function _missingView($file, $error = 'missingView') {
|
||||
if ($error === 'missingView') {
|
||||
$this->cakeError('missingView', array(
|
||||
'className' => $this->name,
|
||||
'action' => $this->action,
|
||||
'file' => $file,
|
||||
'base' => $this->base
|
||||
));
|
||||
return false;
|
||||
} elseif ($error === 'missingLayout') {
|
||||
$this->cakeError('missingLayout', array(
|
||||
'layout' => $this->layout,
|
||||
'file' => $file,
|
||||
'base' => $this->base
|
||||
));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all possible paths to find view files in order
|
||||
*
|
||||
* @param string $plugin Optional plugin name to scan for view files.
|
||||
* @param boolean $cached Set to true to force a refresh of view paths.
|
||||
* @return array paths
|
||||
* @access protected
|
||||
*/
|
||||
function _paths($plugin = null, $cached = true) {
|
||||
if ($plugin === null && $cached === true && !empty($this->__paths)) {
|
||||
return $this->__paths;
|
||||
}
|
||||
$paths = array();
|
||||
$viewPaths = App::path('views');
|
||||
$corePaths = array_flip(App::core('views'));
|
||||
|
||||
if (!empty($plugin)) {
|
||||
$count = count($viewPaths);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (!isset($corePaths[$viewPaths[$i]])) {
|
||||
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
|
||||
}
|
||||
}
|
||||
$paths[] = App::pluginPath($plugin) . 'views' . DS;
|
||||
}
|
||||
$this->__paths = array_merge($paths, $viewPaths);
|
||||
return $this->__paths;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user