VideoPlayer.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ 3Z7H1NpZ9hRn2zzSFfo3651+Q7DygI4OQvosl/dOmQQ=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.10 [rev.7.10.01]
  11. */
  12. /**
  13. * video player
  14. *
  15. * plays either:
  16. * - local files, in which case it will render the video tag
  17. * - remote files (embedded code) in which case it will only return the code to be displayed.
  18. *
  19. * Format Support
  20. * mp4 Please visit http://caniuse.com/#feat=mpeg4 for comprehensive information
  21. * webm Please visit http://caniuse.com/#feat=webm for comprehensive information
  22. * flv All browsers that support Flash (version 10 or later)
  23. * YouTube All browsers since it uses iframe tag
  24. */
  25. namespace Ppb\View\Helper;
  26. use Cube\View\Helper\AbstractHelper,
  27. Cube\Controller\Front,
  28. Ppb\Db\Table\Row\ListingMedia,
  29. Ppb\Service\ListingsMedia as ListingsMediaService;
  30. class VideoPlayer extends AbstractHelper
  31. {
  32. /**
  33. *
  34. * render the video player that will play the video
  35. *
  36. * @param string|\Ppb\Db\Table\Row\ListingMedia $media
  37. *
  38. * @return string
  39. */
  40. public function videoPlayer($media)
  41. {
  42. $video = $player = $videoId = null;
  43. if ($media instanceof ListingMedia) {
  44. if ($media->getData('type') == ListingsMediaService::TYPE_VIDEO) {
  45. $video = $media->getData('value');
  46. $videoId = 'video_' . $media->getData('id');
  47. }
  48. }
  49. else if (is_array($media)) {
  50. if ($media['type'] == ListingsMediaService::TYPE_VIDEO) {
  51. $video = $media['value'];
  52. $videoId = $media['id'];
  53. }
  54. }
  55. else if (is_string($media)) {
  56. $video = $media;
  57. $videoId = 'video_' . md5(uniqid(time()));
  58. }
  59. $video = $this->_decode($video);
  60. $video = $this->getView()->renderHtml($video);
  61. if (strcmp(strip_tags($video), $video) === 0 && !preg_match('#^http(s)?://(.*)+$#i', $video)) {
  62. $baseUrl = Front::getInstance()->getRequest()->getBaseUrl();
  63. /** @var \Cube\View\Helper\Script $scriptHelper */
  64. $scriptHelper = $this->getView()->getHelper('script');
  65. $scriptHelper->addHeaderCode('<link href="' . $baseUrl . '/js/videojs/video-js.min.css" media="screen" rel="stylesheet" type="text/css">')
  66. ->addBodyCode('<script type="text/javascript" src="' . $baseUrl . '/js/videojs/video.min.js"></script>');
  67. $baseUrl = Front::getInstance()->getRequest()->getBaseUrl();
  68. $video = $baseUrl . \Ppb\Utility::URI_DELIMITER
  69. . \Ppb\Utility::getFolder('uploads') . \Ppb\Utility::URI_DELIMITER
  70. . $video;
  71. $player = '
  72. <video id="' . $videoId . '"
  73. class="video-js vjs-default-skin"
  74. controls preload="auto" width="640" height="350">
  75. <source src="' . $video . '" />
  76. </video>';
  77. }
  78. else {
  79. $player = $video;
  80. }
  81. return $player;
  82. }
  83. /**
  84. *
  85. * decode string if encoded
  86. *
  87. * @param $string
  88. *
  89. * @return bool|string
  90. */
  91. protected function _decode($string)
  92. {
  93. $decoded = base64_decode($string);
  94. return (base64_encode($decoded) === $string) ? $decoded : $string;
  95. }
  96. }