ThumbnailImageMedium.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @package Grav\Common\Page
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Page\Medium;
  9. class ThumbnailImageMedium extends ImageMedium
  10. {
  11. /**
  12. * @var Medium
  13. */
  14. public $parent = null;
  15. /**
  16. * @var bool
  17. */
  18. public $linked = false;
  19. /**
  20. * Return srcset string for this Medium and its alternatives.
  21. *
  22. * @param bool $reset
  23. * @return string
  24. */
  25. public function srcset($reset = true)
  26. {
  27. return '';
  28. }
  29. /**
  30. * Get an element (is array) that can be rendered by the Parsedown engine
  31. *
  32. * @param string $title
  33. * @param string $alt
  34. * @param string $class
  35. * @param string $id
  36. * @param bool $reset
  37. * @return array
  38. */
  39. public function parsedownElement($title = null, $alt = null, $class = null, $id = null, $reset = true)
  40. {
  41. return $this->bubble('parsedownElement', [$title, $alt, $class, $id, $reset]);
  42. }
  43. /**
  44. * Return HTML markup from the medium.
  45. *
  46. * @param string $title
  47. * @param string $alt
  48. * @param string $class
  49. * @param string $id
  50. * @param bool $reset
  51. * @return string
  52. */
  53. public function html($title = null, $alt = null, $class = null, $id = null, $reset = true)
  54. {
  55. return $this->bubble('html', [$title, $alt, $class, $id, $reset]);
  56. }
  57. /**
  58. * Switch display mode.
  59. *
  60. * @param string $mode
  61. *
  62. * @return $this
  63. */
  64. public function display($mode = 'source')
  65. {
  66. return $this->bubble('display', [$mode], false);
  67. }
  68. /**
  69. * Switch thumbnail.
  70. *
  71. * @param string $type
  72. *
  73. * @return $this
  74. */
  75. public function thumbnail($type = 'auto')
  76. {
  77. $this->bubble('thumbnail', [$type], false);
  78. return $this->bubble('getThumbnail', [], false);
  79. }
  80. /**
  81. * Turn the current Medium into a Link
  82. *
  83. * @param bool $reset
  84. * @param array $attributes
  85. * @return Link
  86. */
  87. public function link($reset = true, array $attributes = [])
  88. {
  89. return $this->bubble('link', [$reset, $attributes], false);
  90. }
  91. /**
  92. * Turn the current Medium into a Link with lightbox enabled
  93. *
  94. * @param int $width
  95. * @param int $height
  96. * @param bool $reset
  97. * @return Link
  98. */
  99. public function lightbox($width = null, $height = null, $reset = true)
  100. {
  101. return $this->bubble('lightbox', [$width, $height, $reset], false);
  102. }
  103. /**
  104. * Bubble a function call up to either the superclass function or the parent Medium instance
  105. *
  106. * @param string $method
  107. * @param array $arguments
  108. * @param bool $testLinked
  109. * @return Medium
  110. */
  111. protected function bubble($method, array $arguments = [], $testLinked = true)
  112. {
  113. if (!$testLinked || $this->linked) {
  114. return $this->parent ? call_user_func_array(array($this->parent, $method), $arguments) : $this;
  115. }
  116. return call_user_func_array(array($this, 'parent::' . $method), $arguments);
  117. }
  118. }