VideoMedium.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 VideoMedium extends Medium
  10. {
  11. use StaticResizeTrait;
  12. /**
  13. * Parsedown element for source display mode
  14. *
  15. * @param array $attributes
  16. * @param bool $reset
  17. * @return array
  18. */
  19. protected function sourceParsedownElement(array $attributes, $reset = true)
  20. {
  21. $location = $this->url($reset);
  22. return [
  23. 'name' => 'video',
  24. 'text' => '<source src="' . $location . '">Your browser does not support the video tag.',
  25. 'attributes' => $attributes
  26. ];
  27. }
  28. /**
  29. * Allows to set or remove the HTML5 default controls
  30. *
  31. * @param bool $display
  32. * @return $this
  33. */
  34. public function controls($display = true)
  35. {
  36. if($display) {
  37. $this->attributes['controls'] = true;
  38. } else {
  39. unset($this->attributes['controls']);
  40. }
  41. return $this;
  42. }
  43. /**
  44. * Allows to set the video's poster image
  45. *
  46. * @param string $urlImage
  47. * @return $this
  48. */
  49. public function poster($urlImage)
  50. {
  51. $this->attributes['poster'] = $urlImage;
  52. return $this;
  53. }
  54. /**
  55. * Allows to set the loop attribute
  56. *
  57. * @param bool $status
  58. * @return $this
  59. */
  60. public function loop($status = false)
  61. {
  62. if($status) {
  63. $this->attributes['loop'] = true;
  64. } else {
  65. unset($this->attributes['loop']);
  66. }
  67. return $this;
  68. }
  69. /**
  70. * Allows to set the autoplay attribute
  71. *
  72. * @param bool $status
  73. * @return $this
  74. */
  75. public function autoplay($status = false)
  76. {
  77. if ($status) {
  78. $this->attributes['autoplay'] = '';
  79. } else {
  80. unset($this->attributes['autoplay']);
  81. }
  82. return $this;
  83. }
  84. /**
  85. * Allows ability to set the preload option
  86. *
  87. * @param null $status
  88. * @return $this
  89. */
  90. public function preload($status = null)
  91. {
  92. if ($status) {
  93. $this->attributes['preload'] = $status;
  94. } else {
  95. unset($this->attributes['preload']);
  96. }
  97. return $this;
  98. }
  99. /**
  100. * Allows to set the playsinline attribute
  101. *
  102. * @param bool $status
  103. * @return $this
  104. */
  105. public function playsinline($status = false)
  106. {
  107. if($status) {
  108. $this->attributes['playsinline'] = true;
  109. } else {
  110. unset($this->attributes['playsinline']);
  111. }
  112. return $this;
  113. }
  114. /**
  115. * Allows to set the muted attribute
  116. *
  117. * @param bool $status
  118. * @return $this
  119. */
  120. public function muted($status = false)
  121. {
  122. if($status) {
  123. $this->attributes['muted'] = true;
  124. } else {
  125. unset($this->attributes['muted']);
  126. }
  127. return $this;
  128. }
  129. /**
  130. * Reset medium.
  131. *
  132. * @return $this
  133. */
  134. public function reset()
  135. {
  136. parent::reset();
  137. $this->attributes['controls'] = true;
  138. return $this;
  139. }
  140. }