/Vendor/pear-pear.cakephp.org/CakePHP/Cake/View/Helper/HtmlHelper.php

https://bitbucket.org/daveschwan/ronin-group · PHP · 1248 lines · 628 code · 76 blank · 544 comment · 132 complexity · b1f937bbc456e58dc4c78fad9fe7b09b MD5 · raw file

  1. <?php
  2. /**
  3. * Html Helper class file.
  4. *
  5. * Simplifies the construction of HTML elements.
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @package Cake.View.Helper
  17. * @since CakePHP(tm) v 0.9.1
  18. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  19. */
  20. App::uses('AppHelper', 'View/Helper');
  21. App::uses('CakeResponse', 'Network');
  22. /**
  23. * Html Helper class for easy use of HTML widgets.
  24. *
  25. * HtmlHelper encloses all methods needed while working with HTML pages.
  26. *
  27. * @package Cake.View.Helper
  28. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html
  29. */
  30. class HtmlHelper extends AppHelper {
  31. /**
  32. * Reference to the Response object
  33. *
  34. * @var CakeResponse
  35. */
  36. public $response;
  37. /**
  38. * html tags used by this helper.
  39. *
  40. * @var array
  41. */
  42. protected $_tags = array(
  43. 'meta' => '<meta%s/>',
  44. 'metalink' => '<link href="%s"%s/>',
  45. 'link' => '<a href="%s"%s>%s</a>',
  46. 'mailto' => '<a href="mailto:%s" %s>%s</a>',
  47. 'form' => '<form action="%s"%s>',
  48. 'formend' => '</form>',
  49. 'input' => '<input name="%s"%s/>',
  50. 'textarea' => '<textarea name="%s"%s>%s</textarea>',
  51. 'hidden' => '<input type="hidden" name="%s"%s/>',
  52. 'checkbox' => '<input type="checkbox" name="%s" %s/>',
  53. 'checkboxmultiple' => '<input type="checkbox" name="%s[]"%s />',
  54. 'radio' => '<input type="radio" name="%s" id="%s"%s />%s',
  55. 'selectstart' => '<select name="%s"%s>',
  56. 'selectmultiplestart' => '<select name="%s[]"%s>',
  57. 'selectempty' => '<option value=""%s>&nbsp;</option>',
  58. 'selectoption' => '<option value="%s"%s>%s</option>',
  59. 'selectend' => '</select>',
  60. 'optiongroup' => '<optgroup label="%s"%s>',
  61. 'optiongroupend' => '</optgroup>',
  62. 'checkboxmultiplestart' => '',
  63. 'checkboxmultipleend' => '',
  64. 'password' => '<input type="password" name="%s" %s/>',
  65. 'file' => '<input type="file" name="%s" %s/>',
  66. 'file_no_model' => '<input type="file" name="%s" %s/>',
  67. 'submit' => '<input %s/>',
  68. 'submitimage' => '<input type="image" src="%s" %s/>',
  69. 'button' => '<button%s>%s</button>',
  70. 'image' => '<img src="%s" %s/>',
  71. 'tableheader' => '<th%s>%s</th>',
  72. 'tableheaderrow' => '<tr%s>%s</tr>',
  73. 'tablecell' => '<td%s>%s</td>',
  74. 'tablerow' => '<tr%s>%s</tr>',
  75. 'block' => '<div%s>%s</div>',
  76. 'blockstart' => '<div%s>',
  77. 'blockend' => '</div>',
  78. 'hiddenblock' => '<div style="display:none;">%s</div>',
  79. 'tag' => '<%s%s>%s</%s>',
  80. 'tagstart' => '<%s%s>',
  81. 'tagend' => '</%s>',
  82. 'tagselfclosing' => '<%s%s/>',
  83. 'para' => '<p%s>%s</p>',
  84. 'parastart' => '<p%s>',
  85. 'label' => '<label for="%s"%s>%s</label>',
  86. 'fieldset' => '<fieldset%s>%s</fieldset>',
  87. 'fieldsetstart' => '<fieldset><legend>%s</legend>',
  88. 'fieldsetend' => '</fieldset>',
  89. 'legend' => '<legend>%s</legend>',
  90. 'css' => '<link rel="%s" type="text/css" href="%s" %s/>',
  91. 'style' => '<style type="text/css"%s>%s</style>',
  92. 'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
  93. 'ul' => '<ul%s>%s</ul>',
  94. 'ol' => '<ol%s>%s</ol>',
  95. 'li' => '<li%s>%s</li>',
  96. 'error' => '<div%s>%s</div>',
  97. 'javascriptblock' => '<script%s>%s</script>',
  98. 'javascriptstart' => '<script>',
  99. 'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
  100. 'javascriptend' => '</script>'
  101. );
  102. /**
  103. * Breadcrumbs.
  104. *
  105. * @var array
  106. */
  107. protected $_crumbs = array();
  108. /**
  109. * Names of script files that have been included once
  110. *
  111. * @var array
  112. */
  113. protected $_includedScripts = array();
  114. /**
  115. * Options for the currently opened script block buffer if any.
  116. *
  117. * @var array
  118. */
  119. protected $_scriptBlockOptions = array();
  120. /**
  121. * Document type definitions
  122. *
  123. * @var array
  124. */
  125. protected $_docTypes = array(
  126. 'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
  127. 'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
  128. 'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
  129. 'html5' => '<!DOCTYPE html>',
  130. 'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
  131. 'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
  132. 'xhtml-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
  133. 'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
  134. );
  135. /**
  136. * Constructor
  137. *
  138. * ### Settings
  139. *
  140. * - `configFile` A file containing an array of tags you wish to redefine.
  141. *
  142. * ### Customizing tag sets
  143. *
  144. * Using the `configFile` option you can redefine the tag HtmlHelper will use.
  145. * The file named should be compatible with HtmlHelper::loadConfig().
  146. *
  147. * @param View $View The View this helper is being attached to.
  148. * @param array $settings Configuration settings for the helper.
  149. */
  150. public function __construct(View $View, $settings = array()) {
  151. parent::__construct($View, $settings);
  152. if (is_object($this->_View->response)) {
  153. $this->response = $this->_View->response;
  154. } else {
  155. $this->response = new CakeResponse();
  156. }
  157. if (!empty($settings['configFile'])) {
  158. $this->loadConfig($settings['configFile']);
  159. }
  160. }
  161. /**
  162. * Adds a link to the breadcrumbs array.
  163. *
  164. * @param string $name Text for link
  165. * @param string $link URL for link (if empty it won't be a link)
  166. * @param string|array $options Link attributes e.g. array('id' => 'selected')
  167. * @return void
  168. * @see HtmlHelper::link() for details on $options that can be used.
  169. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
  170. */
  171. public function addCrumb($name, $link = null, $options = null) {
  172. $this->_crumbs[] = array($name, $link, $options);
  173. }
  174. /**
  175. * Returns a doctype string.
  176. *
  177. * Possible doctypes:
  178. *
  179. * - html4-strict: HTML4 Strict.
  180. * - html4-trans: HTML4 Transitional.
  181. * - html4-frame: HTML4 Frameset.
  182. * - html5: HTML5. Default value.
  183. * - xhtml-strict: XHTML1 Strict.
  184. * - xhtml-trans: XHTML1 Transitional.
  185. * - xhtml-frame: XHTML1 Frameset.
  186. * - xhtml11: XHTML1.1.
  187. *
  188. * @param string $type Doctype to use.
  189. * @return string Doctype string
  190. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::docType
  191. */
  192. public function docType($type = 'html5') {
  193. if (isset($this->_docTypes[$type])) {
  194. return $this->_docTypes[$type];
  195. }
  196. return null;
  197. }
  198. /**
  199. * Creates a link to an external resource and handles basic meta tags
  200. *
  201. * Create a meta tag that is output inline:
  202. *
  203. * `$this->Html->meta('icon', 'favicon.ico');
  204. *
  205. * Append the meta tag to `$scripts_for_layout`:
  206. *
  207. * `$this->Html->meta('description', 'A great page', array('inline' => false));`
  208. *
  209. * Append the meta tag to custom view block:
  210. *
  211. * `$this->Html->meta('description', 'A great page', array('block' => 'metaTags'));`
  212. *
  213. * ### Options
  214. *
  215. * - `inline` Whether or not the link element should be output inline. Set to false to
  216. * have the meta tag included in `$scripts_for_layout`, and appended to the 'meta' view block.
  217. * - `block` Choose a custom block to append the meta tag to. Using this option
  218. * will override the inline option.
  219. *
  220. * @param string $type The title of the external resource
  221. * @param string|array $url The address of the external resource or string for content attribute
  222. * @param array $options Other attributes for the generated tag. If the type attribute is html,
  223. * rss, atom, or icon, the mime-type is returned.
  224. * @return string A completed `<link />` element.
  225. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::meta
  226. */
  227. public function meta($type, $url = null, $options = array()) {
  228. $options += array('inline' => true, 'block' => null);
  229. if (!$options['inline'] && empty($options['block'])) {
  230. $options['block'] = __FUNCTION__;
  231. }
  232. unset($options['inline']);
  233. if (!is_array($type)) {
  234. $types = array(
  235. 'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $url),
  236. 'atom' => array('type' => 'application/atom+xml', 'title' => $type, 'link' => $url),
  237. 'icon' => array('type' => 'image/x-icon', 'rel' => 'icon', 'link' => $url),
  238. 'keywords' => array('name' => 'keywords', 'content' => $url),
  239. 'description' => array('name' => 'description', 'content' => $url),
  240. );
  241. if ($type === 'icon' && $url === null) {
  242. $types['icon']['link'] = 'favicon.ico';
  243. }
  244. if (isset($types[$type])) {
  245. $type = $types[$type];
  246. } elseif (!isset($options['type']) && $url !== null) {
  247. if (is_array($url) && isset($url['ext'])) {
  248. $type = $types[$url['ext']];
  249. } else {
  250. $type = $types['rss'];
  251. }
  252. } elseif (isset($options['type']) && isset($types[$options['type']])) {
  253. $type = $types[$options['type']];
  254. unset($options['type']);
  255. } else {
  256. $type = array();
  257. }
  258. }
  259. $options = array_merge($type, $options);
  260. $out = null;
  261. if (isset($options['link'])) {
  262. $options['link'] = $this->assetUrl($options['link']);
  263. if (isset($options['rel']) && $options['rel'] === 'icon') {
  264. $out = sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' '));
  265. $options['rel'] = 'shortcut icon';
  266. }
  267. $out .= sprintf($this->_tags['metalink'], $options['link'], $this->_parseAttributes($options, array('block', 'link'), ' ', ' '));
  268. } else {
  269. $out = sprintf($this->_tags['meta'], $this->_parseAttributes($options, array('block', 'type'), ' ', ' '));
  270. }
  271. if (empty($options['block'])) {
  272. return $out;
  273. }
  274. $this->_View->append($options['block'], $out);
  275. }
  276. /**
  277. * Returns a charset META-tag.
  278. *
  279. * @param string $charset The character set to be used in the meta tag. If empty,
  280. * The App.encoding value will be used. Example: "utf-8".
  281. * @return string A meta tag containing the specified character set.
  282. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::charset
  283. */
  284. public function charset($charset = null) {
  285. if (empty($charset)) {
  286. $charset = strtolower(Configure::read('App.encoding'));
  287. }
  288. return sprintf($this->_tags['charset'], (!empty($charset) ? $charset : 'utf-8'));
  289. }
  290. /**
  291. * Creates an HTML link.
  292. *
  293. * If $url starts with "http://" this is treated as an external link. Else,
  294. * it is treated as a path to controller/action and parsed with the
  295. * HtmlHelper::url() method.
  296. *
  297. * If the $url is empty, $title is used instead.
  298. *
  299. * ### Options
  300. *
  301. * - `escape` Set to false to disable escaping of title and attributes.
  302. * - `escapeTitle` Set to false to disable escaping of title. (Takes precedence over value of `escape`)
  303. * - `confirm` JavaScript confirmation message.
  304. *
  305. * @param string $title The content to be wrapped by <a> tags.
  306. * @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
  307. * @param array $options Array of options and HTML attributes.
  308. * @param string $confirmMessage JavaScript confirmation message.
  309. * @return string An `<a />` element.
  310. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link
  311. */
  312. public function link($title, $url = null, $options = array(), $confirmMessage = false) {
  313. $escapeTitle = true;
  314. if ($url !== null) {
  315. $url = $this->url($url);
  316. } else {
  317. $url = $this->url($title);
  318. $title = htmlspecialchars_decode($url, ENT_QUOTES);
  319. $title = h(urldecode($title));
  320. $escapeTitle = false;
  321. }
  322. if (isset($options['escapeTitle'])) {
  323. $escapeTitle = $options['escapeTitle'];
  324. unset($options['escapeTitle']);
  325. } elseif (isset($options['escape'])) {
  326. $escapeTitle = $options['escape'];
  327. }
  328. if ($escapeTitle === true) {
  329. $title = h($title);
  330. } elseif (is_string($escapeTitle)) {
  331. $title = htmlentities($title, ENT_QUOTES, $escapeTitle);
  332. }
  333. if (!empty($options['confirm'])) {
  334. $confirmMessage = $options['confirm'];
  335. unset($options['confirm']);
  336. }
  337. if ($confirmMessage) {
  338. $options['onclick'] = $this->_confirm($confirmMessage, 'return true;', 'return false;', $options);
  339. } elseif (isset($options['default']) && !$options['default']) {
  340. if (isset($options['onclick'])) {
  341. $options['onclick'] .= ' ';
  342. } else {
  343. $options['onclick'] = '';
  344. }
  345. $options['onclick'] .= 'event.returnValue = false; return false;';
  346. unset($options['default']);
  347. }
  348. return sprintf($this->_tags['link'], $url, $this->_parseAttributes($options), $title);
  349. }
  350. /**
  351. * Creates a link element for CSS stylesheets.
  352. *
  353. * ### Usage
  354. *
  355. * Include one CSS file:
  356. *
  357. * `echo $this->Html->css('styles.css');`
  358. *
  359. * Include multiple CSS files:
  360. *
  361. * `echo $this->Html->css(array('one.css', 'two.css'));`
  362. *
  363. * Add the stylesheet to the `$scripts_for_layout` layout var:
  364. *
  365. * `$this->Html->css('styles.css', array('inline' => false));`
  366. *
  367. * Add the stylesheet to a custom block:
  368. *
  369. * `$this->Html->css('styles.css', array('block' => 'layoutCss'));`
  370. *
  371. * ### Options
  372. *
  373. * - `inline` If set to false, the generated tag will be appended to the 'css' block,
  374. * and included in the `$scripts_for_layout` layout variable. Defaults to true.
  375. * - `block` Set the name of the block link/style tag will be appended to.
  376. * This overrides the `inline` option.
  377. * - `plugin` False value will prevent parsing path as a plugin
  378. * - `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.
  379. * - `fullBase` If true the URL will get a full address for the css file.
  380. *
  381. * @param string|array $path The name of a CSS style sheet or an array containing names of
  382. * CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
  383. * of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
  384. * @param array $options Array of options and HTML arguments.
  385. * @return string CSS <link /> or <style /> tag, depending on the type of link.
  386. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::css
  387. */
  388. public function css($path, $options = array()) {
  389. if (!is_array($options)) {
  390. $rel = $options;
  391. $options = array();
  392. if ($rel) {
  393. $options['rel'] = $rel;
  394. }
  395. if (func_num_args() > 2) {
  396. $options = func_get_arg(2) + $options;
  397. }
  398. unset($rel);
  399. }
  400. $options += array('block' => null, 'inline' => true, 'rel' => 'stylesheet');
  401. if (!$options['inline'] && empty($options['block'])) {
  402. $options['block'] = __FUNCTION__;
  403. }
  404. unset($options['inline']);
  405. if (is_array($path)) {
  406. $out = '';
  407. foreach ($path as $i) {
  408. $out .= "\n\t" . $this->css($i, $options);
  409. }
  410. if (empty($options['block'])) {
  411. return $out . "\n";
  412. }
  413. return;
  414. }
  415. if (strpos($path, '//') !== false) {
  416. $url = $path;
  417. } else {
  418. $url = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.cssBaseUrl'), 'ext' => '.css'));
  419. $options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
  420. if (Configure::read('Asset.filter.css')) {
  421. $pos = strpos($url, Configure::read('App.cssBaseUrl'));
  422. if ($pos !== false) {
  423. $url = substr($url, 0, $pos) . 'ccss/' . substr($url, $pos + strlen(Configure::read('App.cssBaseUrl')));
  424. }
  425. }
  426. }
  427. if ($options['rel'] == 'import') {
  428. $out = sprintf(
  429. $this->_tags['style'],
  430. $this->_parseAttributes($options, array('rel', 'block'), '', ' '),
  431. '@import url(' . $url . ');'
  432. );
  433. } else {
  434. $out = sprintf(
  435. $this->_tags['css'],
  436. $options['rel'],
  437. $url,
  438. $this->_parseAttributes($options, array('rel', 'block'), '', ' ')
  439. );
  440. }
  441. if (empty($options['block'])) {
  442. return $out;
  443. }
  444. $this->_View->append($options['block'], $out);
  445. }
  446. /**
  447. * Returns one or many `<script>` tags depending on the number of scripts given.
  448. *
  449. * If the filename is prefixed with "/", the path will be relative to the base path of your
  450. * application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
  451. *
  452. *
  453. * ### Usage
  454. *
  455. * Include one script file:
  456. *
  457. * `echo $this->Html->script('styles.js');`
  458. *
  459. * Include multiple script files:
  460. *
  461. * `echo $this->Html->script(array('one.js', 'two.js'));`
  462. *
  463. * Add the script file to the `$scripts_for_layout` layout var:
  464. *
  465. * `$this->Html->script('styles.js', array('inline' => false));`
  466. *
  467. * Add the script file to a custom block:
  468. *
  469. * `$this->Html->script('styles.js', null, array('block' => 'bodyScript'));`
  470. *
  471. * ### Options
  472. *
  473. * - `inline` Whether script should be output inline or into `$scripts_for_layout`. When set to false,
  474. * the script tag will be appended to the 'script' view block as well as `$scripts_for_layout`.
  475. * - `block` The name of the block you want the script appended to. Leave undefined to output inline.
  476. * Using this option will override the inline option.
  477. * - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be
  478. * included once, use false to allow the same script to be included more than once per request.
  479. * - `plugin` False value will prevent parsing path as a plugin
  480. * - `fullBase` If true the url will get a full address for the script file.
  481. *
  482. * @param string|array $url String or array of javascript files to include
  483. * @param array|boolean $options Array of options, and html attributes see above. If boolean sets $options['inline'] = value
  484. * @return mixed String of `<script />` tags or null if $inline is false or if $once is true and the file has been
  485. * included before.
  486. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::script
  487. */
  488. public function script($url, $options = array()) {
  489. if (is_bool($options)) {
  490. list($inline, $options) = array($options, array());
  491. $options['inline'] = $inline;
  492. }
  493. $options = array_merge(array('block' => null, 'inline' => true, 'once' => true), $options);
  494. if (!$options['inline'] && empty($options['block'])) {
  495. $options['block'] = __FUNCTION__;
  496. }
  497. unset($options['inline']);
  498. if (is_array($url)) {
  499. $out = '';
  500. foreach ($url as $i) {
  501. $out .= "\n\t" . $this->script($i, $options);
  502. }
  503. if (empty($options['block'])) {
  504. return $out . "\n";
  505. }
  506. return null;
  507. }
  508. if ($options['once'] && isset($this->_includedScripts[$url])) {
  509. return null;
  510. }
  511. $this->_includedScripts[$url] = true;
  512. if (strpos($url, '//') === false) {
  513. $url = $this->assetUrl($url, $options + array('pathPrefix' => Configure::read('App.jsBaseUrl'), 'ext' => '.js'));
  514. $options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
  515. if (Configure::read('Asset.filter.js')) {
  516. $url = str_replace(Configure::read('App.jsBaseUrl'), 'cjs/', $url);
  517. }
  518. }
  519. $attributes = $this->_parseAttributes($options, array('block', 'once'), ' ');
  520. $out = sprintf($this->_tags['javascriptlink'], $url, $attributes);
  521. if (empty($options['block'])) {
  522. return $out;
  523. }
  524. $this->_View->append($options['block'], $out);
  525. }
  526. /**
  527. * Wrap $script in a script tag.
  528. *
  529. * ### Options
  530. *
  531. * - `safe` (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
  532. * - `inline` (boolean) Whether or not the $script should be added to
  533. * `$scripts_for_layout` / `script` block, or output inline. (Deprecated, use `block` instead)
  534. * - `block` Which block you want this script block appended to.
  535. * Defaults to `script`.
  536. *
  537. * @param string $script The script to wrap
  538. * @param array $options The options to use. Options not listed above will be
  539. * treated as HTML attributes.
  540. * @return mixed string or null depending on the value of `$options['block']`
  541. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptBlock
  542. */
  543. public function scriptBlock($script, $options = array()) {
  544. $options += array('type' => 'text/javascript', 'safe' => true, 'inline' => true);
  545. if ($options['safe']) {
  546. $script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
  547. }
  548. if (!$options['inline'] && empty($options['block'])) {
  549. $options['block'] = 'script';
  550. }
  551. unset($options['inline'], $options['safe']);
  552. $attributes = $this->_parseAttributes($options, array('block'), ' ');
  553. $out = sprintf($this->_tags['javascriptblock'], $attributes, $script);
  554. if (empty($options['block'])) {
  555. return $out;
  556. }
  557. $this->_View->append($options['block'], $out);
  558. }
  559. /**
  560. * Begin a script block that captures output until HtmlHelper::scriptEnd()
  561. * is called. This capturing block will capture all output between the methods
  562. * and create a scriptBlock from it.
  563. *
  564. * ### Options
  565. *
  566. * - `safe` Whether the code block should contain a CDATA
  567. * - `inline` Should the generated script tag be output inline or in `$scripts_for_layout`
  568. *
  569. * @param array $options Options for the code block.
  570. * @return void
  571. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptStart
  572. */
  573. public function scriptStart($options = array()) {
  574. $options += array('safe' => true, 'inline' => true);
  575. $this->_scriptBlockOptions = $options;
  576. ob_start();
  577. return null;
  578. }
  579. /**
  580. * End a Buffered section of JavaScript capturing.
  581. * Generates a script tag inline or in `$scripts_for_layout` depending on the settings
  582. * used when the scriptBlock was started
  583. *
  584. * @return mixed depending on the settings of scriptStart() either a script tag or null
  585. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptEnd
  586. */
  587. public function scriptEnd() {
  588. $buffer = ob_get_clean();
  589. $options = $this->_scriptBlockOptions;
  590. $this->_scriptBlockOptions = array();
  591. return $this->scriptBlock($buffer, $options);
  592. }
  593. /**
  594. * Builds CSS style data from an array of CSS properties
  595. *
  596. * ### Usage:
  597. *
  598. * {{{
  599. * echo $this->Html->style(array('margin' => '10px', 'padding' => '10px'), true);
  600. *
  601. * // creates
  602. * 'margin:10px;padding:10px;'
  603. * }}}
  604. *
  605. * @param array $data Style data array, keys will be used as property names, values as property values.
  606. * @param boolean $oneline Whether or not the style block should be displayed on one line.
  607. * @return string CSS styling data
  608. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::style
  609. */
  610. public function style($data, $oneline = true) {
  611. if (!is_array($data)) {
  612. return $data;
  613. }
  614. $out = array();
  615. foreach ($data as $key => $value) {
  616. $out[] = $key . ':' . $value . ';';
  617. }
  618. if ($oneline) {
  619. return implode(' ', $out);
  620. }
  621. return implode("\n", $out);
  622. }
  623. /**
  624. * Returns the breadcrumb trail as a sequence of &raquo;-separated links.
  625. *
  626. * If `$startText` is an array, the accepted keys are:
  627. *
  628. * - `text` Define the text/content for the link.
  629. * - `url` Define the target of the created link.
  630. *
  631. * All other keys will be passed to HtmlHelper::link() as the `$options` parameter.
  632. *
  633. * @param string $separator Text to separate crumbs.
  634. * @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can
  635. * also be an array, see above for details.
  636. * @return string Composed bread crumbs
  637. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
  638. */
  639. public function getCrumbs($separator = '&raquo;', $startText = false) {
  640. $crumbs = $this->_prepareCrumbs($startText);
  641. if (!empty($crumbs)) {
  642. $out = array();
  643. foreach ($crumbs as $crumb) {
  644. if (!empty($crumb[1])) {
  645. $out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
  646. } else {
  647. $out[] = $crumb[0];
  648. }
  649. }
  650. return implode($separator, $out);
  651. }
  652. return null;
  653. }
  654. /**
  655. * Returns breadcrumbs as a (x)html list
  656. *
  657. * This method uses HtmlHelper::tag() to generate list and its elements. Works
  658. * similar to HtmlHelper::getCrumbs(), so it uses options which every
  659. * crumb was added with.
  660. *
  661. * ### Options
  662. * - `separator` Separator content to insert in between breadcrumbs, defaults to ''
  663. * - `firstClass` Class for wrapper tag on the first breadcrumb, defaults to 'first'
  664. * - `lastClass` Class for wrapper tag on current active page, defaults to 'last'
  665. *
  666. * @param array $options Array of html attributes to apply to the generated list elements.
  667. * @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can
  668. * also be an array, see `HtmlHelper::getCrumbs` for details.
  669. * @return string breadcrumbs html list
  670. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
  671. */
  672. public function getCrumbList($options = array(), $startText = false) {
  673. $defaults = array('firstClass' => 'first', 'lastClass' => 'last', 'separator' => '');
  674. $options = array_merge($defaults, (array)$options);
  675. $firstClass = $options['firstClass'];
  676. $lastClass = $options['lastClass'];
  677. $separator = $options['separator'];
  678. unset($options['firstClass'], $options['lastClass'], $options['separator']);
  679. $crumbs = $this->_prepareCrumbs($startText);
  680. if (empty($crumbs)) {
  681. return null;
  682. }
  683. $result = '';
  684. $crumbCount = count($crumbs);
  685. $ulOptions = $options;
  686. foreach ($crumbs as $which => $crumb) {
  687. $options = array();
  688. if (empty($crumb[1])) {
  689. $elementContent = $crumb[0];
  690. } else {
  691. $elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
  692. }
  693. if (!$which && $firstClass !== false) {
  694. $options['class'] = $firstClass;
  695. } elseif ($which == $crumbCount - 1 && $lastClass !== false) {
  696. $options['class'] = $lastClass;
  697. }
  698. if (!empty($separator) && ($crumbCount - $which >= 2)) {
  699. $elementContent .= $separator;
  700. }
  701. $result .= $this->tag('li', $elementContent, $options);
  702. }
  703. return $this->tag('ul', $result, $ulOptions);
  704. }
  705. /**
  706. * Prepends startText to crumbs array if set
  707. *
  708. * @param string $startText Text to prepend
  709. * @return array Crumb list including startText (if provided)
  710. */
  711. protected function _prepareCrumbs($startText) {
  712. $crumbs = $this->_crumbs;
  713. if ($startText) {
  714. if (!is_array($startText)) {
  715. $startText = array(
  716. 'url' => '/',
  717. 'text' => $startText
  718. );
  719. }
  720. $startText += array('url' => '/', 'text' => __d('cake', 'Home'));
  721. list($url, $text) = array($startText['url'], $startText['text']);
  722. unset($startText['url'], $startText['text']);
  723. array_unshift($crumbs, array($text, $url, $startText));
  724. }
  725. return $crumbs;
  726. }
  727. /**
  728. * Creates a formatted IMG element.
  729. *
  730. * This method will set an empty alt attribute if one is not supplied.
  731. *
  732. * ### Usage:
  733. *
  734. * Create a regular image:
  735. *
  736. * `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP'));`
  737. *
  738. * Create an image link:
  739. *
  740. * `echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));`
  741. *
  742. * ### Options:
  743. *
  744. * - `url` If provided an image link will be generated and the link will point at
  745. * `$options['url']`.
  746. * - `fullBase` If true the src attribute will get a full address for the image file.
  747. * - `plugin` False value will prevent parsing path as a plugin
  748. *
  749. * @param string $path Path to the image file, relative to the app/webroot/img/ directory.
  750. * @param array $options Array of HTML attributes. See above for special options.
  751. * @return string completed img tag
  752. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image
  753. */
  754. public function image($path, $options = array()) {
  755. $path = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.imageBaseUrl')));
  756. $options = array_diff_key($options, array('fullBase' => null, 'pathPrefix' => null));
  757. if (!isset($options['alt'])) {
  758. $options['alt'] = '';
  759. }
  760. $url = false;
  761. if (!empty($options['url'])) {
  762. $url = $options['url'];
  763. unset($options['url']);
  764. }
  765. $image = sprintf($this->_tags['image'], $path, $this->_parseAttributes($options, null, '', ' '));
  766. if ($url) {
  767. return sprintf($this->_tags['link'], $this->url($url), null, $image);
  768. }
  769. return $image;
  770. }
  771. /**
  772. * Returns a row of formatted and named TABLE headers.
  773. *
  774. * @param array $names Array of tablenames. Each tablename also can be a key that points to an array with a set
  775. * of attributes to its specific tag
  776. * @param array $trOptions HTML options for TR elements.
  777. * @param array $thOptions HTML options for TH elements.
  778. * @return string Completed table headers
  779. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tableHeaders
  780. */
  781. public function tableHeaders($names, $trOptions = null, $thOptions = null) {
  782. $out = array();
  783. foreach ($names as $arg) {
  784. if (!is_array($arg)) {
  785. $out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
  786. } else {
  787. $out[] = sprintf($this->_tags['tableheader'], $this->_parseAttributes(current($arg)), key($arg));
  788. }
  789. }
  790. return sprintf($this->_tags['tablerow'], $this->_parseAttributes($trOptions), implode(' ', $out));
  791. }
  792. /**
  793. * Returns a formatted string of table rows (TR's with TD's in them).
  794. *
  795. * @param array $data Array of table data
  796. * @param array $oddTrOptions HTML options for odd TR elements if true useCount is used
  797. * @param array $evenTrOptions HTML options for even TR elements
  798. * @param boolean $useCount adds class "column-$i"
  799. * @param boolean $continueOddEven If false, will use a non-static $count variable,
  800. * so that the odd/even count is reset to zero just for that call.
  801. * @return string Formatted HTML
  802. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tableCells
  803. */
  804. public function tableCells($data, $oddTrOptions = null, $evenTrOptions = null, $useCount = false, $continueOddEven = true) {
  805. if (empty($data[0]) || !is_array($data[0])) {
  806. $data = array($data);
  807. }
  808. if ($oddTrOptions === true) {
  809. $useCount = true;
  810. $oddTrOptions = null;
  811. }
  812. if ($evenTrOptions === false) {
  813. $continueOddEven = false;
  814. $evenTrOptions = null;
  815. }
  816. if ($continueOddEven) {
  817. static $count = 0;
  818. } else {
  819. $count = 0;
  820. }
  821. foreach ($data as $line) {
  822. $count++;
  823. $cellsOut = array();
  824. $i = 0;
  825. foreach ($line as $cell) {
  826. $cellOptions = array();
  827. if (is_array($cell)) {
  828. $cellOptions = $cell[1];
  829. $cell = $cell[0];
  830. } elseif ($useCount) {
  831. $cellOptions['class'] = 'column-' . ++$i;
  832. }
  833. $cellsOut[] = sprintf($this->_tags['tablecell'], $this->_parseAttributes($cellOptions), $cell);
  834. }
  835. $options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
  836. $out[] = sprintf($this->_tags['tablerow'], $options, implode(' ', $cellsOut));
  837. }
  838. return implode("\n", $out);
  839. }
  840. /**
  841. * Returns a formatted block tag, i.e DIV, SPAN, P.
  842. *
  843. * ### Options
  844. *
  845. * - `escape` Whether or not the contents should be html_entity escaped.
  846. *
  847. * @param string $name Tag name.
  848. * @param string $text String content that will appear inside the div element.
  849. * If null, only a start tag will be printed
  850. * @param array $options Additional HTML attributes of the DIV tag, see above.
  851. * @return string The formatted tag element
  852. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tag
  853. */
  854. public function tag($name, $text = null, $options = array()) {
  855. if (empty($name)) {
  856. return $text;
  857. }
  858. if (isset($options['escape']) && $options['escape']) {
  859. $text = h($text);
  860. unset($options['escape']);
  861. }
  862. if ($text === null) {
  863. $tag = 'tagstart';
  864. } else {
  865. $tag = 'tag';
  866. }
  867. return sprintf($this->_tags[$tag], $name, $this->_parseAttributes($options, null, ' ', ''), $text, $name);
  868. }
  869. /**
  870. * Returns a formatted existent block of $tags
  871. *
  872. * @param string $tag Tag name
  873. * @return string Formatted block
  874. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::useTag
  875. */
  876. public function useTag($tag) {
  877. if (!isset($this->_tags[$tag])) {
  878. return '';
  879. }
  880. $args = func_get_args();
  881. array_shift($args);
  882. foreach ($args as &$arg) {
  883. if (is_array($arg)) {
  884. $arg = $this->_parseAttributes($arg, null, ' ', '');
  885. }
  886. }
  887. return vsprintf($this->_tags[$tag], $args);
  888. }
  889. /**
  890. * Returns a formatted DIV tag for HTML FORMs.
  891. *
  892. * ### Options
  893. *
  894. * - `escape` Whether or not the contents should be html_entity escaped.
  895. *
  896. * @param string $class CSS class name of the div element.
  897. * @param string $text String content that will appear inside the div element.
  898. * If null, only a start tag will be printed
  899. * @param array $options Additional HTML attributes of the DIV tag
  900. * @return string The formatted DIV element
  901. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::div
  902. */
  903. public function div($class = null, $text = null, $options = array()) {
  904. if (!empty($class)) {
  905. $options['class'] = $class;
  906. }
  907. return $this->tag('div', $text, $options);
  908. }
  909. /**
  910. * Returns a formatted P tag.
  911. *
  912. * ### Options
  913. *
  914. * - `escape` Whether or not the contents should be html_entity escaped.
  915. *
  916. * @param string $class CSS class name of the p element.
  917. * @param string $text String content that will appear inside the p element.
  918. * @param array $options Additional HTML attributes of the P tag
  919. * @return string The formatted P element
  920. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::para
  921. */
  922. public function para($class, $text, $options = array()) {
  923. if (isset($options['escape'])) {
  924. $text = h($text);
  925. }
  926. if ($class && !empty($class)) {
  927. $options['class'] = $class;
  928. }
  929. $tag = 'para';
  930. if ($text === null) {
  931. $tag = 'parastart';
  932. }
  933. return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $text);
  934. }
  935. /**
  936. * Returns an audio/video element
  937. *
  938. * ### Usage
  939. *
  940. * Using an audio file:
  941. *
  942. * `echo $this->Html->media('audio.mp3', array('fullBase' => true));`
  943. *
  944. * Outputs:
  945. *
  946. * `<video src="http://www.somehost.com/files/audio.mp3">Fallback text</video>`
  947. *
  948. * Using a video file:
  949. *
  950. * `echo $this->Html->media('video.mp4', array('text' => 'Fallback text'));`
  951. *
  952. * Outputs:
  953. *
  954. * `<video src="/files/video.mp4">Fallback text</video>`
  955. *
  956. * Using multiple video files:
  957. *
  958. * {{{
  959. * echo $this->Html->media(
  960. * array('video.mp4', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")),
  961. * array('tag' => 'video', 'autoplay')
  962. * );
  963. * }}}
  964. *
  965. * Outputs:
  966. *
  967. * {{{
  968. * <video autoplay="autoplay">
  969. * <source src="/files/video.mp4" type="video/mp4"/>
  970. * <source src="/files/video.ogv" type="video/ogv; codecs='theora, vorbis'"/>
  971. * </video>
  972. * }}}
  973. *
  974. * ### Options
  975. *
  976. * - `tag` Type of media element to generate, either "audio" or "video".
  977. * If tag is not provided it's guessed based on file's mime type.
  978. * - `text` Text to include inside the audio/video tag
  979. * - `pathPrefix` Path prefix to use for relative URLs, defaults to 'files/'
  980. * - `fullBase` If provided the src attribute will get a full address including domain name
  981. *
  982. * @param string|array $path Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
  983. * Or an array where each item itself can be a path string or an associate array containing keys `src` and `type`
  984. * @param array $options Array of HTML attributes, and special options above.
  985. * @return string Generated media element
  986. */
  987. public function media($path, $options = array()) {
  988. $options += array(
  989. 'tag' => null,
  990. 'pathPrefix' => 'files/',
  991. 'text' => ''
  992. );
  993. if (!empty($options['tag'])) {
  994. $tag = $options['tag'];
  995. } else {
  996. $tag = null;
  997. }
  998. if (is_array($path)) {
  999. $sourceTags = '';
  1000. foreach ($path as &$source) {
  1001. if (is_string($source)) {
  1002. $source = array(
  1003. 'src' => $source,
  1004. );
  1005. }
  1006. if (!isset($source['type'])) {
  1007. $ext = pathinfo($source['src'], PATHINFO_EXTENSION);
  1008. $source['type'] = $this->response->getMimeType($ext);
  1009. }
  1010. $source['src'] = $this->assetUrl($source['src'], $options);
  1011. $sourceTags .= $this->useTag('tagselfclosing', 'source', $source);
  1012. }
  1013. unset($source);
  1014. $options['text'] = $sourceTags . $options['text'];
  1015. unset($options['fullBase']);
  1016. } else {
  1017. if (empty($path) && !empty($options['src'])) {
  1018. $path = $options['src'];
  1019. }
  1020. $options['src'] = $this->assetUrl($path, $options);
  1021. }
  1022. if ($tag === null) {
  1023. if (is_array($path)) {
  1024. $mimeType = $path[0]['type'];
  1025. } else {
  1026. $mimeType = $this->response->getMimeType(pathinfo($path, PATHINFO_EXTENSION));
  1027. }
  1028. if (preg_match('#^video/#', $mimeType)) {
  1029. $tag = 'video';
  1030. } else {
  1031. $tag = 'audio';
  1032. }
  1033. }
  1034. if (isset($options['poster'])) {
  1035. $options['poster'] = $this->assetUrl($options['poster'], array('pathPrefix' => Configure::read('App.imageBaseUrl')) + $options);
  1036. }
  1037. $text = $options['text'];
  1038. $options = array_diff_key($options, array(
  1039. 'tag' => null,
  1040. 'fullBase' => null,
  1041. 'pathPrefix' => null,
  1042. 'text' => null
  1043. ));
  1044. return $this->tag($tag, $text, $options);
  1045. }
  1046. /**
  1047. * Build a nested list (UL/OL) out of an associative array.
  1048. *
  1049. * @param array $list Set of elements to list
  1050. * @param array $options Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
  1051. * @param array $itemOptions Additional HTML attributes of the list item (LI) tag
  1052. * @param string $tag Type of list tag to use (ol/ul)
  1053. * @return string The nested list
  1054. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::nestedList
  1055. */
  1056. public function nestedList($list, $options = array(), $itemOptions = array(), $tag = 'ul') {
  1057. if (is_string($options)) {
  1058. $tag = $options;
  1059. $options = array();
  1060. }
  1061. $items = $this->_nestedListItem($list, $options, $itemOptions, $tag);
  1062. return sprintf($this->_tags[$tag], $this->_parseAttributes($options, null, ' ', ''), $items);
  1063. }
  1064. /**
  1065. * Internal function to build a nested list (UL/OL) out of an associative array.
  1066. *
  1067. * @param array $items Set of elements to list
  1068. * @param array $options Additional HTML attributes of the list (ol/ul) tag
  1069. * @param array $itemOptions Additional HTML attributes of the list item (LI) tag
  1070. * @param string $tag Type of list tag to use (ol/ul)
  1071. * @return string The nested list element
  1072. * @see HtmlHelper::nestedList()
  1073. */
  1074. protected function _nestedListItem($items, $options, $itemOptions, $tag) {
  1075. $out = '';
  1076. $index = 1;
  1077. foreach ($items as $key => $item) {
  1078. if (is_array($item)) {
  1079. $item = $key . $this->nestedList($item, $options, $itemOptions, $tag);
  1080. }
  1081. if (isset($itemOptions['even']) && $index % 2 === 0) {
  1082. $itemOptions['class'] = $itemOptions['even'];
  1083. } elseif (isset($itemOptions['odd']) && $index % 2 !== 0) {
  1084. $itemOptions['class'] = $itemOptions['odd'];
  1085. }
  1086. $out .= sprintf($this->_tags['li'], $this->_parseAttributes($itemOptions, array('even', 'odd'), ' ', ''), $item);
  1087. $index++;
  1088. }
  1089. return $out;
  1090. }
  1091. /**
  1092. * Load Html tag configuration.
  1093. *
  1094. * Loads a file from APP/Config that contains tag data. By default the file is expected
  1095. * to be compatible with PhpReader:
  1096. *
  1097. * `$this->Html->loadConfig('tags.php');`
  1098. *
  1099. * tags.php could look like:
  1100. *
  1101. * {{{
  1102. * $tags = array(
  1103. * 'meta' => '<meta %s>'
  1104. * );
  1105. * }}}
  1106. *
  1107. * If you wish to store tag definitions in another format you can give an array
  1108. * containing the file name, and reader class name:
  1109. *
  1110. * `$this->Html->loadConfig(array('tags.ini', 'ini'));`
  1111. *
  1112. * Its expected that the `tags` index will exist from any configuration file that is read.
  1113. * You can also specify the path to read the configuration file from, if APP/Config is not
  1114. * where the file is.
  1115. *
  1116. * `$this->Html->loadConfig('tags.php', APP . 'Lib' . DS);`
  1117. *
  1118. * Configuration files can define the following sections:
  1119. *
  1120. * - `tags` The tags to replace.
  1121. * - `minimizedAttributes` The attributes that are represented like `disabled="disabled"`
  1122. * - `docTypes` Additional doctypes to use.
  1123. * - `attributeFormat` Format for long attributes e.g. `'%s="%s"'`
  1124. * - `minimizedAttributeFormat` Format for minimized attributes e.g. `'%s="%s"'`
  1125. *
  1126. * @param string|array $configFile String with the config file (load using PhpReader) or an array with file and reader name
  1127. * @param string $path Path with config file
  1128. * @return mixed False to error or loaded configs
  1129. * @throws ConfigureException
  1130. * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#changing-the-tags-output-by-htmlhelper
  1131. */
  1132. public function loadConfig($configFile, $path = null) {
  1133. if (!$path) {
  1134. $path = APP . 'Config' . DS;
  1135. }
  1136. $file = null;
  1137. $reader = 'php';
  1138. if (!is_array($configFile)) {
  1139. $file = $configFile;
  1140. } elseif (isset($configFile[0])) {
  1141. $file = $configFile[0];
  1142. if (isset($configFile[1])) {
  1143. $reader = $configFile[1];
  1144. }
  1145. } else {
  1146. throw new ConfigureException(__d('cake_dev', 'Cannot load the configuration file. Wrong "configFile" configuration.'));
  1147. }
  1148. $readerClass = Inflector::camelize($reader) . 'Reader';
  1149. App::uses($readerClass, 'Configure');
  1150. if (!class_exists($readerClass)) {
  1151. throw new ConfigureException(__d('cake_dev', 'Cannot load the configuration file. Unknown reader.'));
  1152. }
  1153. $readerObj = new $readerClass($path);
  1154. $configs = $readerObj->read($file);
  1155. if (isset($configs['tags']) && is_array($configs['tags'])) {
  1156. $this->_tags = array_merge($this->_tags, $configs['tags']);
  1157. }
  1158. if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) {
  1159. $this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']);
  1160. }
  1161. if (isset($configs['docTypes']) && is_array($configs['docTypes'])) {
  1162. $this->_docTypes = array_merge($this->_docTypes, $configs['docTypes']);
  1163. }
  1164. if (isset($configs['attributeFormat'])) {
  1165. $this->_attributeFormat = $configs['attributeFormat'];
  1166. }
  1167. if (isset($configs['minimizedAttributeFormat'])) {
  1168. $this->_minimizedAttributeFormat = $configs['minimizedAttributeFormat'];
  1169. }
  1170. return $configs;
  1171. }
  1172. }