HtmlHelper.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * Html Helper class for easy use of HTML widgets.
  19. *
  20. * HtmlHelper encloses all methods needed while working with HTML pages.
  21. *
  22. * @link http://book.cakephp.org/3.0/en/views/helpers/html.html
  23. */
  24. class HtmlHelper extends CoreHtmlHelper {
  25. /**
  26. * Display image tag from blob content.
  27. * Enhancement for HtmlHelper. Defaults to png image
  28. *
  29. * Options:
  30. * - type: png, gif, jpg, ...
  31. *
  32. * @param string $content Data in binary form
  33. * @param array $options Attributes
  34. * @return string HTML image tag
  35. */
  36. public function imageFromBlob($content, array $options = []) {
  37. $options += ['type' => 'png'];
  38. $mimeType = 'image/' . $options['type'];
  39. $text = 'data:' . $mimeType . ';base64,' . base64_encode($content);
  40. return $this->formatTemplate('image', [
  41. 'url' => $text,
  42. 'attrs' => $this->templater()->formatAttributes($options, ['block', 'link'])
  43. ]);
  44. }
  45. /**
  46. * Creates a reset HTML link.
  47. * The prefix and plugin params are resetting to default false.
  48. *
  49. * ### Options
  50. *
  51. * - `escape` Set to false to disable escaping of title and attributes.
  52. * - `escapeTitle` Set to false to disable escaping of title. Takes precedence
  53. * over value of `escape`)
  54. * - `confirm` JavaScript confirmation message.
  55. *
  56. * @param string $title The content to be wrapped by <a> tags.
  57. * @param string|array|null $url URL or array of URL parameters, or
  58. * external URL (starts with http://)
  59. * @param array $options Array of options and HTML attributes.
  60. * @return string An `<a />` element.
  61. */
  62. public function resetLink($title, $url = null, array $options = []) {
  63. if (is_array($url)) {
  64. $url += ['prefix' => false, 'plugin' => false];
  65. }
  66. return parent::link($title, $url, $options);
  67. }
  68. /**
  69. * Keep query string params for pagination/filter for this link,
  70. * e.g. after edit action.
  71. *
  72. * ### Options
  73. *
  74. * - `escape` Set to false to disable escaping of title and attributes.
  75. * - `escapeTitle` Set to false to disable escaping of title. Takes precedence
  76. * over value of `escape`)
  77. * - `confirm` JavaScript confirmation message.
  78. *
  79. * @param string $title The content to be wrapped by <a> tags.
  80. * @param string|array|null $url URL or array of URL parameters, or
  81. * external URL (starts with http://)
  82. * @param array $options Array of options and HTML attributes.
  83. * @return string An `<a />` element.
  84. * @return string Link
  85. */
  86. public function completeLink($title, $url = null, array $options = []) {
  87. if (is_array($url)) {
  88. // Add query strings
  89. if (!isset($url['?'])) {
  90. $url['?'] = [];
  91. }
  92. $url['?'] += $this->request->query;
  93. }
  94. return parent::link($title, $url, $options);
  95. }
  96. /**
  97. * Event listeners.
  98. *
  99. * @return array
  100. */
  101. public function implementedEvents() {
  102. return [];
  103. }
  104. }