HtmlHelper.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 0.9.1
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Tools\View\Helper;
  16. use Cake\View\Helper\HtmlHelper as CoreHtmlHelper;
  17. /**
  18. * Overwrite
  19. *
  20. * @property \Cake\View\Helper\UrlHelper $Url
  21. */
  22. class HtmlHelper extends CoreHtmlHelper {
  23. /**
  24. * Display image tag from blob content.
  25. * Enhancement for HtmlHelper. Defaults to png image
  26. *
  27. * Options:
  28. * - type: png, gif, jpg, ...
  29. *
  30. * @param string $content Data in binary form
  31. * @param array $options Attributes
  32. * @return string HTML image tag
  33. */
  34. public function imageFromBlob($content, array $options = []) {
  35. $options += ['type' => 'png'];
  36. $mimeType = 'image/' . $options['type'];
  37. $text = 'data:' . $mimeType . ';base64,' . base64_encode($content);
  38. return $this->formatTemplate('image', [
  39. 'url' => $text,
  40. 'attrs' => $this->templater()->formatAttributes($options, ['block', 'link'])
  41. ]);
  42. }
  43. /**
  44. * Creates a reset HTML link.
  45. * The prefix and plugin params are resetting to default false.
  46. *
  47. * ### Options
  48. *
  49. * - `escape` Set to false to disable escaping of title and attributes.
  50. * - `escapeTitle` Set to false to disable escaping of title. Takes precedence
  51. * over value of `escape`)
  52. * - `confirm` JavaScript confirmation message.
  53. *
  54. * @param string $title The content to be wrapped by <a> tags.
  55. * @param string|array|null $url URL or array of URL parameters, or
  56. * external URL (starts with http://)
  57. * @param array $options Array of options and HTML attributes.
  58. * @return string An `<a />` element.
  59. */
  60. public function linkReset($title, $url = null, array $options = []) {
  61. if (is_array($url)) {
  62. $url += ['prefix' => false, 'plugin' => false];
  63. }
  64. return parent::link($title, $url, $options);
  65. }
  66. /**
  67. * Keep query string params for pagination/filter for this link,
  68. * e.g. after edit action.
  69. *
  70. * ### Options
  71. *
  72. * - `escape` Set to false to disable escaping of title and attributes.
  73. * - `escapeTitle` Set to false to disable escaping of title. Takes precedence
  74. * over value of `escape`)
  75. * - `confirm` JavaScript confirmation message.
  76. *
  77. * @param string $title The content to be wrapped by <a> tags.
  78. * @param string|array|null $url URL or array of URL parameters, or
  79. * external URL (starts with http://)
  80. * @param array $options Array of options and HTML attributes.
  81. * @return string An `<a />` element.
  82. * @return string Link
  83. */
  84. public function linkComplete($title, $url = null, array $options = []) {
  85. if (is_array($url)) {
  86. // Add query strings
  87. if (!isset($url['?'])) {
  88. $url['?'] = [];
  89. }
  90. $url['?'] += $this->_View->getRequest()->getQuery();
  91. }
  92. return parent::link($title, $url, $options);
  93. }
  94. /**
  95. * Event listeners.
  96. *
  97. * @return array
  98. */
  99. public function implementedEvents() {
  100. return [];
  101. }
  102. }