BxDolPlayer.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Standard Player view.
  11. * @see BxDolPlayer::attachPlayer
  12. */
  13. define('BX_PLAYER_STANDARD', 1);
  14. /**
  15. * Mini Player view. If not supported by player, standard view is used.
  16. * @see BxDolPlayer::attachPlayer
  17. */
  18. define('BX_PLAYER_MINI', 3);
  19. /**
  20. * Player view in embed. If not supported by player, standard view is used.
  21. * @see BxDolPlayer::attachPlayer
  22. */
  23. define('BX_PLAYER_EMBED', 2);
  24. /**
  25. * Audio/Video player integration.
  26. *
  27. * Site owner can choose which audio/video can be user on the site.
  28. *
  29. * Default player is stored in 'sys_player_default' setting option.
  30. *
  31. * @section player_create Creating the Editor object:
  32. *
  33. *
  34. * Add record to 'sys_objects_player' table:
  35. *
  36. * - object: name of the object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing;
  37. * - title: title of the player, displayed in the studio.
  38. * - skin: player skin, if player suports custom/multiple skins.
  39. * - override_class_name: user defined class name which is derived from one of base player classes.
  40. * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
  41. *
  42. *
  43. * @section example Example of usage
  44. *
  45. * Display player
  46. *
  47. * @code
  48. *
  49. * $oPlayer = BxDolPlayer::getObjectInstance(); // get default player object instance
  50. * if ($oPlayer) // check if player is available for using
  51. * echo $oPlayer->getCodeVideo (BX_PLAYER_STANDARD, array(
  52. * 'poster' => $sUrlPoster, // optional, but very
  53. * 'mp4' => $sUrlMP4, // or array of files,
  54. * for example: array('sd' => $sUrl480, 'hd' => $sUrl720)
  55. * 'webm' => $sUrlWebM, // optional, mp4 format is enough for all moders browsers
  56. * 'attrs' => $aAttrs, // optional, not supported by all player implementations
  57. * 'styles' => 'width:100%; height:auto;', // optional, not supported by all
  58. * players implementations
  59. * )); // output HTML player implementation
  60. * @endcode
  61. *
  62. */
  63. class BxDolPlayer extends BxDolFactory implements iBxDolFactoryObject
  64. {
  65. protected $_sObject;
  66. protected $_aObject;
  67. protected $_aConfCustom = array();
  68. protected $_sSkin;
  69. protected $_aSkins;
  70. protected $_aSizes = array(
  71. 'sd' => 480,
  72. 'hd' => 720,
  73. );
  74. protected function __construct($aObject)
  75. {
  76. parent::__construct();
  77. $this->_sObject = $aObject['object'];
  78. $this->_aObject = $aObject;
  79. $this->_sSkin = !empty($aObject['skin']) ? $aObject['skin']: '';
  80. $this->_aSkins = array();
  81. }
  82. /**
  83. * Get player object instance by object name
  84. * @param $sObject object name
  85. * @return object instance or false on error
  86. */
  87. static public function getObjectInstance($sObject = false, $oTemplate = false)
  88. {
  89. if (!$sObject)
  90. $sObject = getParam('sys_player_default');
  91. if (isset($GLOBALS['bxDolClasses']['BxDolPlayer!'.$sObject]))
  92. return $GLOBALS['bxDolClasses']['BxDolPlayer!'.$sObject];
  93. $aObject = BxDolPlayerQuery::getPlayerObject($sObject);
  94. if (!$aObject || !is_array($aObject))
  95. return false;
  96. if (empty($aObject['override_class_name']))
  97. return false;
  98. $sClass = $aObject['override_class_name'];
  99. if (!empty($aObject['override_class_file']))
  100. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  101. $o = new $sClass($aObject, $oTemplate);
  102. return ($GLOBALS['bxDolClasses']['BxDolPlayer!'.$sObject] = $o);
  103. }
  104. /**
  105. * Get object name
  106. */
  107. public function getObjectName ()
  108. {
  109. return $this->_sObject;
  110. }
  111. /**
  112. * Set custom player configuration options
  113. */
  114. public function setCustomConf ($a)
  115. {
  116. $this->_aConfCustom = $a;
  117. }
  118. /**
  119. * Set size for default resolutions: 'sd' and 'hd'
  120. */
  121. public function setVideoSize ($sName, $iSize)
  122. {
  123. if (isset($this->_aSizes[$sName]))
  124. $this->_aSizes[$sName] = $iSize;
  125. }
  126. /**
  127. * Get a list of available skins.
  128. */
  129. public function getSkins($bFullInfo = false)
  130. {
  131. if($bFullInfo)
  132. return $this->_aSkins;
  133. $aResults = array();
  134. foreach($this->_aSkins as $aSkin)
  135. $aResults[] = array('key' => $aSkin['name'], 'value' => _t($aSkin['title']));
  136. return $aResults;
  137. }
  138. public function setSkin($sSkin)
  139. {
  140. if(!in_array($sSkin, array_keys($this->_aSkins)))
  141. return;
  142. $this->_sSkin = $sSkin;
  143. }
  144. /**
  145. * Get player HTML code
  146. * @param $iViewMode - player view mode: BX_PLAYER_STANDARD, BX_PLAYER_MINI, BX_PLAYER_EMBED
  147. * @param $aParams - player params: mp3, ogg, attrs, styles - See usage example.
  148. * @param $bDynamicMode - is AJAX mode or not, the HTML with player is loaded dynamically.
  149. */
  150. public function getCodeAudio ($iViewMode, $aParams, $bDynamicMode = false)
  151. {
  152. // override this function in particular player class
  153. }
  154. /**
  155. * Get player HTML code
  156. * @param $iViewMode - player view mode: BX_PLAYER_STANDARD, BX_PLAYER_MINI, BX_PLAYER_EMBED
  157. * @param $aParams - player params: poster, mp4, webm, attrs, styles - See usage example.
  158. * @param $bDynamicMode - is AJAX mode or not, the HTML with player is loaded dynamically.
  159. */
  160. public function getCodeVideo ($iViewMode, $aParams, $bDynamicMode = false)
  161. {
  162. // override this function in particular player class
  163. }
  164. /**
  165. * Add css/js files which are needed for player display and functionality.
  166. */
  167. protected function _addJsCss ($bDynamicMode = false)
  168. {
  169. // override this function in particular player class
  170. }
  171. /**
  172. * Replace provided markers string.
  173. * @param $s - string to replace markers in
  174. * @param $a - markers array
  175. * @return string with replaces markers
  176. */
  177. protected function _replaceMarkers ($s, $a)
  178. {
  179. if (empty($s) || empty($a) || !is_array($a))
  180. return $s;
  181. return bx_replace_markers($s, $a);
  182. }
  183. }
  184. /** @} */