HtmlHelper.php 3.5 KB

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