Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
denise 2012-08-09 17:24:00 -04:00
commit f75cf5ffe2
12 changed files with 159 additions and 110 deletions

View file

@ -24,15 +24,22 @@ class AudiopreviewController extends Zend_Controller_Action
$audioFileID = $this->_getParam('audioFileID');
$audioFileArtist = $this->_getParam('audioFileArtist');
$audioFileTitle = $this->_getParam('audioFileTitle');
$type = $this->_getParam('type');
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
$baseDir = dirname($_SERVER['SCRIPT_FILENAME']);
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headLink()->appendStylesheet($baseUrl.'/js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
$this->view->headScript()->appendFile(
$baseUrl.'/js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],
'text/javascript');
$this->view->headScript()->appendFile(
$baseUrl.'/js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],
'text/javascript');
$this->view->headLink()->appendStylesheet(
$baseUrl.'/js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
$this->_helper->layout->setLayout('audioPlayer');
$logo = Application_Model_Preference::GetStationLogo();
@ -41,6 +48,17 @@ class AudiopreviewController extends Zend_Controller_Action
} else {
$this->view->logo = "$baseUrl/css/images/airtime_logo_jp.png";
}
if ($type == "audioclip") {
$uri = "/api/get-media/file/".$audioFileID;
} else if ($type == "stream") {
$webstream = CcWebstreamQuery::create()->findPk($audioFileID);
$uri = $webstream->getDbUrl();
} else {
throw new Exception("Unknown type for audio preview!");
}
$this->view->uri = $uri;
$this->view->audioFileID = $audioFileID;
$this->view->audioFileArtist = $audioFileArtist;
$this->view->audioFileTitle = $audioFileTitle;
@ -83,49 +101,49 @@ class AudiopreviewController extends Zend_Controller_Action
public function blockPreviewAction()
{
global $CC_CONFIG;
$blockIndex = $this->_getParam('blockIndex');
$blockId = $this->_getParam('blockId');
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
$baseDir = dirname($_SERVER['SCRIPT_FILENAME']);
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headLink()->appendStylesheet($baseUrl.'/js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
$this->_helper->layout->setLayout('audioPlayer');
$logo = Application_Model_Preference::GetStationLogo();
if ($logo) {
$this->view->logo = "data:image/png;base64,$logo";
} else {
$this->view->logo = "$baseUrl/css/images/airtime_logo_jp.png";
}
$this->view->blockIndex= $blockIndex;
$this->view->blockId = $blockId;
global $CC_CONFIG;
$blockIndex = $this->_getParam('blockIndex');
$blockId = $this->_getParam('blockId');
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
$baseDir = dirname($_SERVER['SCRIPT_FILENAME']);
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/audiopreview/preview_jplayer.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/jplayer/jplayer.playlist.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headLink()->appendStylesheet($baseUrl.'/js/jplayer/skin/jplayer.airtime.audio.preview.css?'.$CC_CONFIG['airtime_version']);
$this->_helper->layout->setLayout('audioPlayer');
$logo = Application_Model_Preference::GetStationLogo();
if ($logo) {
$this->view->logo = "data:image/png;base64,$logo";
} else {
$this->view->logo = "$baseUrl/css/images/airtime_logo_jp.png";
}
$this->view->blockIndex= $blockIndex;
$this->view->blockId = $blockId;
$this->_helper->viewRenderer->setRender('audio-preview');
}
public function getBlockAction()
{
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$blockId = $this->_getParam('blockId');
if (!isset($blockId)) {
return;
}
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$blockId = $this->_getParam('blockId');
if (!isset($blockId)) {
return;
}
$bl = new Application_Model_Block($blockId);
$result = array();
$result = array();
foreach ($bl->getContents(true) as $ele) {
$result[] = $this->createElementMap($ele);
}
}
$this->_helper->json($result);
}
/**
@ -155,26 +173,40 @@ class AudiopreviewController extends Zend_Controller_Action
$result[] = $this->createElementMap($track);
}
}
}else{
} else {
$result[] = $this->createElementMap($ele);
}
}
$this->_helper->json($result);
}
function createElementMap($track){
$elementMap = array( 'element_title' => isset($track['track_title'])?$track['track_title']:"",
'element_artist' => isset($track['artist_name'])?$track['artist_name']:"",
'element_id' => isset($track['id'])?$track['id']:"",
'element_position' => isset($track['position'])?$track['position']:"",
);
$fileExtension = pathinfo($track['path'], PATHINFO_EXTENSION);
if (strtolower($fileExtension) === 'mp3') {
$elementMap['element_mp3'] = $track['item_id'];
} else if (strtolower($fileExtension) === 'ogg') {
$elementMap['element_oga'] = $track['item_id'];
} else {
//the media was neither mp3 or ogg
private function createElementMap($track)
{
$elementMap = array( 'element_title' => isset($track['track_title'])?$track['track_title']:"",
'element_artist' => isset($track['artist_name'])?$track['artist_name']:"",
'element_id' => isset($track['id'])?$track['id']:"",
'element_position' => isset($track['position'])?$track['position']:"",
);
$elementMap['type'] = $track['type'];
if ($track['type'] == 0) {
$fileExtension = pathinfo($track['path'], PATHINFO_EXTENSION);
//type is file
//TODO: use MIME type for this
if (strtolower($fileExtension) === 'mp3') {
$elementMap['element_mp3'] = $track['item_id'];
} else if (strtolower($fileExtension) === 'ogg') {
$elementMap['element_oga'] = $track['item_id'];
} else {
//the media was neither mp3 or ogg
throw new Exception("Unknown file type");
}
$elementMap['uri'] = "/api/get-media/file/".$track['item_id'];
} else {
$elementMap['uri'] = $track['path'];
}
return $elementMap;
}

View file

@ -59,7 +59,7 @@ class LibraryController extends Zend_Controller_Action
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
if ($this->obj_sess->type === "playlist") {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
} else {
} else if ($this->obj_sess->type === "block") {
$menu["pl_add"] = array("name"=> "Add to Smart Playlist", "icon" => "add-playlist", "icon" => "copy");
}
}
@ -101,8 +101,6 @@ class LibraryController extends Zend_Controller_Action
if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
if ($this->obj_sess->type === "playlist") {
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
} else {
$menu["pl_add"] = array("name"=> "Add to Smart Playlist", "icon" => "add-playlist", "icon" => "copy");
}
}
}
@ -181,7 +179,7 @@ class LibraryController extends Zend_Controller_Action
try {
Application_Model_Block::deleteBlocks($blocks, $user->getId());
} catch (Exception $e) {
//TODO: warn user that not all blocks could be deleted.
//TODO: warn user that not all blocks could be deleted.
}
try {

View file

@ -153,8 +153,8 @@ class PlaylistController extends Zend_Controller_Action
Logging::log("{$e->getMessage()}");
}
private function playlistDenied($obj) {
$this->view->error = "You cannot add playlists to smart playlists.";
private function wrongTypeToBlock($obj) {
$this->view->error = "You can only add tracks to smart playlists.";
$this->createFullResponse($obj);
}
@ -315,13 +315,15 @@ class PlaylistController extends Zend_Controller_Action
// if the dest is a block object
//check if any items are playlists
foreach($ids as $id) {
if (is_array($id) && isset($id[1]) && $id[1] == 'playlist') {
throw new Exception('playlist to block');
if (is_array($id) && isset($id[1])) {
if ($id[1] != 'audioclip') {
throw new WrongTypeToBlockException;
}
}
}
$obj->addAudioClips($ids, $afterItem, $addType);
} else {
throw new Exception('track to dynamic');
throw new BlockDynamicException;
}
$this->createUpdateResponse($obj);
}
@ -331,14 +333,14 @@ class PlaylistController extends Zend_Controller_Action
catch (PlaylistNotFoundException $e) {
$this->playlistNotFound($obj_type);
}
catch (WrongTypeToBlockException $e) {
$this->wrongTypeToBlock($obj);
}
catch (BlockDynamicException $e) {
$this->blockDynamic($obj);
}
catch (Exception $e) {
if ($e->getMessage() == 'playlist to block') {
$this->playlistDenied($obj);
} else if ($e->getMessage() == 'track to dynamic') {
$this->blockDynamic($obj);
} else {
$this->playlistUnknownError($e);
}
$this->playlistUnknownError($e);
}
}
@ -606,5 +608,6 @@ class PlaylistController extends Zend_Controller_Action
}
die(json_encode($out));
}
}
class WrongTypeToBlockException extends Exception {}
class BlockDynamicException extends Exception {}