AudiopreviewController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. class AudiopreviewController extends Zend_Controller_Action
  3. {
  4. public function init()
  5. {
  6. $ajaxContext = $this->_helper->getHelper('AjaxContext');
  7. $ajaxContext->addActionContext('show-preview', 'json')
  8. ->addActionContext('audio-preview', 'json')
  9. ->addActionContext('get-show', 'json')
  10. ->addActionContext('playlist-preview', 'json')
  11. ->addActionContext('get-playlist', 'json')
  12. ->initContext();
  13. }
  14. /**
  15. * Simply sets up the view to play the required audio track.
  16. * Gets the parameters from the request and sets them to the view.
  17. */
  18. public function audioPreviewAction()
  19. {
  20. $CC_CONFIG = Config::getConfig();
  21. $audioFileID = $this->_getParam('audioFileID');
  22. $audioFileArtist = $this->_getParam('audioFileArtist');
  23. $audioFileTitle = $this->_getParam('audioFileTitle');
  24. $type = $this->_getParam('type');
  25. $baseUrl = Application_Common_OsPath::getBaseDir();
  26. $this->view->headScript()->appendFile(
  27. $baseUrl.'js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],
  28. 'text/javascript');
  29. $this->view->headScript()->appendFile(
  30. $baseUrl.'js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],
  31. 'text/javascript');
  32. $this->view->headLink()->appendStylesheet(
  33. $baseUrl.'js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
  34. $this->_helper->layout->setLayout('audioPlayer');
  35. $logo = Application_Model_Preference::GetStationLogo();
  36. if ($logo) {
  37. $this->view->logo = "data:image/png;base64,$logo";
  38. } else {
  39. $this->view->logo = $baseUrl."css/images/airtime_logo_jp.png";
  40. }
  41. if ($type == "audioclip") {
  42. $uri = $baseUrl."api/get-media/file/".$audioFileID;
  43. $media = Application_Model_StoredFile::RecallById($audioFileID);
  44. $mime = $media->getPropelOrm()->getDbMime();
  45. } elseif ($type == "stream") {
  46. $webstream = CcWebstreamQuery::create()->findPk($audioFileID);
  47. $uri = $webstream->getDbUrl();
  48. $mime = $webstream->getDbMime();
  49. } else {
  50. throw new Exception("Unknown type for audio preview!.Type=$type");
  51. }
  52. $this->view->uri = $uri;
  53. $this->view->mime = $mime;
  54. $this->view->audioFileID = $audioFileID;
  55. // We need to decode artist and title because it gets
  56. // encoded twice in js
  57. $this->view->audioFileArtist = htmlspecialchars(urldecode($audioFileArtist));
  58. $this->view->audioFileTitle = htmlspecialchars(urldecode($audioFileTitle));
  59. $this->view->type = $type;
  60. $this->_helper->viewRenderer->setRender('audio-preview');
  61. }
  62. /**
  63. * Simply sets up the view to play the required playlist track.
  64. * Gets the parameters from the request and sets them to the view.
  65. */
  66. public function playlistPreviewAction()
  67. {
  68. $CC_CONFIG = Config::getConfig();
  69. $playlistIndex = $this->_getParam('playlistIndex');
  70. $playlistID = $this->_getParam('playlistID');
  71. $baseUrl = Application_Common_OsPath::getBaseDir();
  72. $this->view->headScript()->appendFile($baseUrl.'js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  73. $this->view->headScript()->appendFile($baseUrl.'js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  74. $this->view->headLink()->appendStylesheet($baseUrl.'js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
  75. $this->_helper->layout->setLayout('audioPlayer');
  76. $logo = Application_Model_Preference::GetStationLogo();
  77. if ($logo) {
  78. $this->view->logo = "data:image/png;base64,$logo";
  79. } else {
  80. $this->view->logo = $baseUrl."css/images/airtime_logo_jp.png";
  81. }
  82. $this->view->playlistIndex= $playlistIndex;
  83. $this->view->playlistID = $playlistID;
  84. $this->_helper->viewRenderer->setRender('audio-preview');
  85. }
  86. public function blockPreviewAction()
  87. {
  88. $CC_CONFIG = Config::getConfig();
  89. $blockIndex = $this->_getParam('blockIndex');
  90. $blockId = $this->_getParam('blockId');
  91. $baseUrl = Application_Common_OsPath::getBaseDir();
  92. $this->view->headScript()->appendFile($baseUrl.'js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  93. $this->view->headScript()->appendFile($baseUrl.'js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  94. $this->view->headLink()->appendStylesheet($baseUrl.'js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
  95. $this->_helper->layout->setLayout('audioPlayer');
  96. $logo = Application_Model_Preference::GetStationLogo();
  97. if ($logo) {
  98. $this->view->logo = "data:image/png;base64,$logo";
  99. } else {
  100. $this->view->logo = $baseUrl."css/images/airtime_logo_jp.png";
  101. }
  102. $this->view->blockIndex= $blockIndex;
  103. $this->view->blockId = $blockId;
  104. $this->_helper->viewRenderer->setRender('audio-preview');
  105. }
  106. public function getBlockAction()
  107. {
  108. // disable the view and the layout
  109. $this->view->layout()->disableLayout();
  110. $this->_helper->viewRenderer->setNoRender(true);
  111. $blockId = $this->_getParam('blockId');
  112. if (!isset($blockId)) {
  113. return;
  114. }
  115. $bl = new Application_Model_Block($blockId);
  116. $result = array();
  117. foreach ($bl->getContents(true) as $ele) {
  118. $result[] = $this->createElementMap($ele);
  119. }
  120. $this->_helper->json($result);
  121. }
  122. /**
  123. *Function will load and return the contents of the requested playlist.
  124. */
  125. public function getPlaylistAction()
  126. {
  127. // disable the view and the layout
  128. $this->view->layout()->disableLayout();
  129. $this->_helper->viewRenderer->setNoRender(true);
  130. $playlistID = $this->_getParam('playlistID');
  131. if (!isset($playlistID)) {
  132. return;
  133. }
  134. $pl = new Application_Model_Playlist($playlistID);
  135. $result = Array();
  136. foreach ($pl->getContents(true) as $ele) {
  137. if ($ele['type'] == 2) {
  138. // if element is a block expand and add
  139. $bl = new Application_Model_Block($ele['item_id']);
  140. if ($bl->isStatic()) {
  141. foreach ($bl->getContents(true) as $track) {
  142. $result[] = $this->createElementMap($track);
  143. }
  144. }
  145. } else {
  146. $result[] = $this->createElementMap($ele);
  147. }
  148. }
  149. $this->_helper->json($result);
  150. }
  151. private function createElementMap($track)
  152. {
  153. $baseUrl = Application_Common_OsPath::getBaseDir();
  154. $elementMap = array( 'element_title' => isset($track['track_title'])?$track['track_title']:"",
  155. 'element_artist' => isset($track['artist_name'])?$track['artist_name']:"",
  156. 'element_id' => isset($track['id'])?$track['id']:"",
  157. 'element_position' => isset($track['position'])?$track['position']:"",
  158. 'mime' => isset($track['mime'])?$track['mime']:""
  159. );
  160. /* If the track type is static we know it must be
  161. * a track because static blocks can only contain
  162. * tracks
  163. */
  164. if ($track['type'] == 'static') {
  165. $track['type'] = 0;
  166. }
  167. $elementMap['type'] = $track['type'];
  168. if ($track['type'] == 0) {
  169. $mime = $track['mime'];
  170. //type is file
  171. if (strtolower($mime) === 'audio/mp3') {
  172. $elementMap['element_mp3'] = $track['item_id'];
  173. } elseif (strtolower($mime) === 'audio/ogg') {
  174. $elementMap['element_oga'] = $track['item_id'];
  175. } elseif (strtolower($mime) === 'audio/vorbis') {
  176. $elementMap['element_oga'] = $track['item_id'];
  177. } elseif (strtolower($mime) === 'audio/mp4') {
  178. $elementMap['element_m4a'] = $track['item_id'];
  179. } elseif (strtolower($mime) === 'audio/wav') {
  180. $elementMap['element_wav'] = $track['item_id'];
  181. } elseif (strtolower($mime) === 'audio/x-wav') {
  182. $elementMap['element_wav'] = $track['item_id'];
  183. } elseif (strtolower($mime) === 'audio/x-flac') {
  184. $elementMap['element_flac'] = $track['item_id'];
  185. } else {
  186. throw new Exception("Unknown file type: $mime");
  187. }
  188. $elementMap['uri'] = $baseUrl."api/get-media/file/".$track['item_id'];
  189. } else {
  190. $elementMap['uri'] = $track['path'];
  191. }
  192. return $elementMap;
  193. }
  194. /**
  195. * Simply sets up the view to play the required show track.
  196. * Gets the parameters from the request and sets them to the view.
  197. */
  198. public function showPreviewAction()
  199. {
  200. $CC_CONFIG = Config::getConfig();
  201. $showID = $this->_getParam('showID');
  202. $showIndex = $this->_getParam('showIndex');
  203. $baseUrl = Application_Common_OsPath::getBaseDir();
  204. $this->view->headScript()->appendFile($baseUrl.'js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  205. $this->view->headScript()->appendFile($baseUrl.'js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  206. $this->view->headLink()->appendStylesheet($baseUrl.'js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
  207. $this->_helper->layout->setLayout('audioPlayer');
  208. $logo = Application_Model_Preference::GetStationLogo();
  209. if ($logo) {
  210. $this->view->logo = "data:image/png;base64,$logo";
  211. } else {
  212. $this->view->logo = $baseUrl."css/images/airtime_logo_jp.png";
  213. }
  214. $this->view->showID = $showID;
  215. $this->view->showIndex = $showIndex;
  216. $this->_helper->viewRenderer->setRender('audio-preview');
  217. }
  218. /**
  219. *Function will load and return the contents of the requested show.
  220. */
  221. public function getShowAction()
  222. {
  223. $baseUrl = Application_Common_OsPath::getBaseDir();
  224. // disable the view and the layout
  225. $this->view->layout()->disableLayout();
  226. $this->_helper->viewRenderer->setNoRender(true);
  227. $showID = $this->_getParam('showID');
  228. if (!isset($showID)) {
  229. return;
  230. }
  231. $showInstance = new Application_Model_ShowInstance($showID);
  232. $result = array();
  233. $position = 0;
  234. foreach ($showInstance->getShowListContent() as $track) {
  235. $elementMap = array(
  236. 'element_title' => isset($track['track_title']) ? $track['track_title'] : "",
  237. 'element_artist' => isset($track['creator']) ? $track['creator'] : "",
  238. 'element_position' => $position,
  239. 'element_id' => ++$position,
  240. 'mime' => isset($track['mime'])?$track['mime']:""
  241. );
  242. $elementMap['type'] = $track['type'];
  243. if ($track['type'] == 0) {
  244. $mime = $track['mime'];
  245. if (strtolower($mime) === 'audio/mp3') {
  246. $elementMap['element_mp3'] = $track['item_id'];
  247. } elseif (strtolower($mime) === 'audio/ogg') {
  248. $elementMap['element_oga'] = $track['item_id'];
  249. } elseif (strtolower($mime) === 'audio/vorbis') {
  250. $elementMap['element_oga'] = $track['item_id'];
  251. } elseif (strtolower($mime) === 'audio/mp4') {
  252. $elementMap['element_m4a'] = $track['item_id'];
  253. } elseif (strtolower($mime) === 'audio/wav') {
  254. $elementMap['element_wav'] = $track['item_id'];
  255. } elseif (strtolower($mime) === 'audio/x-wav') {
  256. $elementMap['element_wav'] = $track['item_id'];
  257. } elseif (strtolower($mime) === 'audio/x-flac') {
  258. $elementMap['element_flac'] = $track['item_id'];
  259. } else {
  260. throw new Exception("Unknown file type: $mime");
  261. }
  262. $elementMap['uri'] = $baseUrl."api/get-media/file/".$track['item_id'];
  263. } else {
  264. $elementMap['uri'] = $track['filepath'];
  265. }
  266. $result[] = $elementMap;
  267. }
  268. $this->_helper->json($result);
  269. }
  270. }