2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2012-02-27 12:23:22 +01:00
|
|
|
require_once 'formatters/LengthFormatter.php';
|
|
|
|
require_once 'formatters/SamplerateFormatter.php';
|
|
|
|
require_once 'formatters/BitrateFormatter.php';
|
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
class LibraryController extends Zend_Controller_Action
|
|
|
|
{
|
2011-01-05 01:18:44 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
protected $pl_sess = null;
|
2011-02-10 04:37:18 +01:00
|
|
|
protected $search_sess = null;
|
2011-01-05 01:18:44 +01:00
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$ajaxContext = $this->_helper->getHelper('AjaxContext');
|
2011-02-01 21:57:12 +01:00
|
|
|
$ajaxContext->addActionContext('contents', 'json')
|
2011-04-18 18:43:04 +02:00
|
|
|
->addActionContext('delete', 'json')
|
2012-01-08 05:37:37 +01:00
|
|
|
->addActionContext('delete-group', 'json')
|
2011-04-18 18:43:04 +02:00
|
|
|
->addActionContext('context-menu', 'json')
|
2011-02-04 06:15:56 +01:00
|
|
|
->addActionContext('get-file-meta-data', 'html')
|
2011-09-22 17:47:24 +02:00
|
|
|
->addActionContext('upload-file-soundcloud', 'json')
|
2011-09-22 20:01:05 +02:00
|
|
|
->addActionContext('get-upload-to-soundcloud-status', 'json')
|
2011-10-18 16:10:35 +02:00
|
|
|
->addActionContext('set-num-entries', 'json')
|
2010-12-07 20:19:27 +01:00
|
|
|
->initContext();
|
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$this->pl_sess = new Zend_Session_Namespace(UI_PLAYLIST_SESSNAME);
|
|
|
|
$this->search_sess = new Zend_Session_Namespace("search");
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
public function indexAction() {
|
|
|
|
|
|
|
|
$this->_helper->layout->setLayout('library');
|
|
|
|
|
2012-01-17 11:18:17 +01:00
|
|
|
$this->view->headScript()->appendFile($this->view->baseUrl('/js/airtime/library/events/library_playlistbuilder.js'),'text/javascript');
|
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
$this->_helper->actionStack('library', 'library');
|
|
|
|
$this->_helper->actionStack('index', 'playlist');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function libraryAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2012-02-08 22:21:57 +01:00
|
|
|
global $CC_CONFIG;
|
2012-02-09 21:19:21 +01:00
|
|
|
|
2012-02-15 00:39:27 +01:00
|
|
|
$this->_helper->viewRenderer->setResponseSegment('library');
|
|
|
|
|
2011-04-18 17:02:09 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$baseUrl = $request->getBaseUrl();
|
|
|
|
|
2012-02-09 21:19:21 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2012-02-08 22:21:57 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2012-02-22 11:43:37 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2012-02-08 22:21:57 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.TableTools.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
|
|
|
|
2012-02-29 15:47:11 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2012-02-08 22:21:57 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2012-03-01 00:19:59 +01:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/main_library.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
2012-02-08 22:21:57 +01:00
|
|
|
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/media_library.css?'.$CC_CONFIG['airtime_version']);
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']);
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/datatables/css/ColVis.css?'.$CC_CONFIG['airtime_version']);
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/datatables/css/ColReorder.css?'.$CC_CONFIG['airtime_version']);
|
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/TableTools.css?'.$CC_CONFIG['airtime_version']);
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function contextMenuAction()
|
|
|
|
{
|
2012-03-02 23:55:17 +01:00
|
|
|
global $CC_CONFIG;
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
$id = $this->_getParam('id');
|
2011-04-18 18:43:04 +02:00
|
|
|
$type = $this->_getParam('type');
|
2012-02-05 18:19:22 +01:00
|
|
|
//playlist||timeline
|
|
|
|
$screen = $this->_getParam('screen');
|
2011-06-24 22:04:57 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$baseUrl = $request->getBaseUrl();
|
2012-02-08 12:53:46 +01:00
|
|
|
$menu = array();
|
2010-12-22 05:33:58 +01:00
|
|
|
|
2011-07-18 19:48:20 +02:00
|
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
2011-09-23 23:00:55 +02:00
|
|
|
$user = new Application_Model_User($userInfo->id);
|
2011-07-18 19:48:20 +02:00
|
|
|
|
2012-02-02 15:51:15 +01:00
|
|
|
if ($type === "audioclip") {
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-02 15:51:15 +01:00
|
|
|
$file = Application_Model_StoredFile::Recall($id);
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2012-02-24 15:07:04 +01:00
|
|
|
if (isset($this->pl_sess->id) && $screen == "playlist") {
|
|
|
|
$menu["pl_add"] = array("name"=> "Add to Playlist", "icon" => "copy");
|
|
|
|
}
|
2012-03-02 23:55:17 +01:00
|
|
|
//Open a jPlayer window and play the audio clip.
|
|
|
|
$menu["play"] = array("name"=> "Play", "icon" => "big_play");
|
|
|
|
|
2012-02-05 13:56:07 +01:00
|
|
|
$menu["edit"] = array("name"=> "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}");
|
2012-03-02 23:55:17 +01:00
|
|
|
|
|
|
|
if ($user->isAdmin()) {
|
2012-02-05 18:19:22 +01:00
|
|
|
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete");
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
|
|
|
|
2012-03-02 23:55:17 +01:00
|
|
|
$url = $file->getRelativeFileUrl($baseUrl).'/download/true';
|
|
|
|
$menu["download"] = array("name" => "Download", "url" => $url);
|
2011-04-18 18:43:04 +02:00
|
|
|
|
2011-09-29 23:10:17 +02:00
|
|
|
if (Application_Model_Preference::GetUploadToSoundcloudOption()) {
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2012-02-05 13:56:07 +01:00
|
|
|
//create a menu separator
|
|
|
|
$menu["sep1"] = "-----------";
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2012-02-05 13:56:07 +01:00
|
|
|
//create a sub menu for Soundcloud actions.
|
|
|
|
$menu["soundcloud"] = array("name" => "Soundcloud", "icon" => "soundcloud", "items" => array());
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2012-02-02 15:51:15 +01:00
|
|
|
$scid = $file->getSoundCloudId();
|
|
|
|
|
|
|
|
if (!is_null($scid)){
|
2011-11-28 22:20:34 +01:00
|
|
|
$text = "Re-upload to SoundCloud";
|
2011-09-22 17:47:24 +02:00
|
|
|
}
|
2012-02-02 15:51:15 +01:00
|
|
|
else {
|
|
|
|
$text = "Upload to SoundCloud";
|
|
|
|
}
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2012-02-05 13:56:07 +01:00
|
|
|
$menu["soundcloud"]["items"]["upload"] = array("name" => $text, "url" => "/library/upload-file-soundcloud/id/{$id}");
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2012-02-02 15:51:15 +01:00
|
|
|
if ($scid > 0){
|
2012-02-05 13:56:07 +01:00
|
|
|
$url = $file->getSoundCloudLinkToFile();
|
|
|
|
$menu["soundcloud"]["items"]["view"] = array("name" => "View on Soundcloud", "url" => $url);
|
2011-10-22 17:34:04 +02:00
|
|
|
}
|
2011-09-22 17:47:24 +02:00
|
|
|
}
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
2012-02-02 15:51:15 +01:00
|
|
|
else if ($type === "playlist") {
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
if ($this->pl_sess->id !== $id && $screen == "playlist") {
|
2012-02-05 13:56:07 +01:00
|
|
|
$menu["edit"] = array("name"=> "Edit", "icon" => "edit");
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
$menu["del"] = array("name"=> "Delete", "icon" => "delete", "url" => "/library/delete");
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2012-02-05 13:56:07 +01:00
|
|
|
$this->view->items = $menu;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteAction()
|
|
|
|
{
|
2012-02-05 18:19:22 +01:00
|
|
|
//array containing id and type of media to delete.
|
|
|
|
$mediaItems = $this->_getParam('media', null);
|
2011-07-18 19:48:20 +02:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
$user = Application_Model_User::GetCurrentUser();
|
2011-07-18 19:48:20 +02:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
$files = array();
|
|
|
|
$playlists = array();
|
2011-07-18 19:48:20 +02:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
$message = null;
|
2011-07-18 19:48:20 +02:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
foreach ($mediaItems as $media) {
|
2011-07-18 19:48:20 +02:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
if ($media["type"] === "audioclip") {
|
|
|
|
$files[] = intval($media["id"]);
|
|
|
|
}
|
|
|
|
else if ($media["type"] === "playlist") {
|
|
|
|
$playlists[] = intval($media["id"]);
|
2011-05-17 23:30:17 +02:00
|
|
|
}
|
2012-02-05 18:19:22 +01:00
|
|
|
}
|
2011-04-18 18:43:04 +02:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
if (count($playlists)) {
|
|
|
|
Application_Model_Playlist::DeletePlaylists($playlists);
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
2012-01-08 05:37:37 +01:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
if (!$user->isAdmin()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-02-05 18:19:22 +01:00
|
|
|
foreach ($files as $id) {
|
|
|
|
Logging::log("deleting file {$id}");
|
|
|
|
|
|
|
|
$file = Application_Model_StoredFile::Recall($id);
|
|
|
|
|
|
|
|
if (isset($file)) {
|
|
|
|
try {
|
2012-02-06 11:07:10 +01:00
|
|
|
$res = $file->delete(true);
|
2012-02-05 18:19:22 +01:00
|
|
|
}
|
|
|
|
//could throw a scheduled in future exception.
|
|
|
|
catch (Exception $e) {
|
|
|
|
$message = "Could not delete some scheduled files.";
|
2012-01-08 05:37:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 18:19:22 +01:00
|
|
|
|
|
|
|
if (isset($message)) {
|
|
|
|
$this->view->message = $message;
|
|
|
|
}
|
2012-01-08 05:37:37 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
|
|
|
public function contentsAction()
|
|
|
|
{
|
2012-01-27 21:06:04 +01:00
|
|
|
$params = $this->getRequest()->getParams();
|
|
|
|
$datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($params);
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-02-05 19:48:23 +01:00
|
|
|
//TODO move this to the datatables row callback.
|
|
|
|
foreach ($datatables["aaData"] as &$data) {
|
|
|
|
|
|
|
|
if ($data['ftype'] == 'audioclip'){
|
2012-01-11 16:41:58 +01:00
|
|
|
$file = Application_Model_StoredFile::Recall($data['id']);
|
2011-09-22 17:47:24 +02:00
|
|
|
$scid = $file->getSoundCloudId();
|
2012-02-05 19:48:23 +01:00
|
|
|
|
|
|
|
if ($scid == "-2"){
|
|
|
|
$data['track_title'] .= '<span class="small-icon progress"/>';
|
|
|
|
}
|
|
|
|
else if ($scid == "-3"){
|
|
|
|
$data['track_title'] .= '<span class="small-icon sc-error"/>';
|
|
|
|
}
|
|
|
|
else if (!is_null($scid)){
|
|
|
|
$data['track_title'] .= '<span class="small-icon soundcloud"/>';
|
2011-09-22 17:47:24 +02:00
|
|
|
}
|
|
|
|
}
|
2011-06-24 21:51:21 +02:00
|
|
|
}
|
2010-12-22 05:33:58 +01:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
die(json_encode($datatables));
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
public function editFileMdAction()
|
2010-12-07 20:19:27 +01:00
|
|
|
{
|
2010-12-30 23:26:44 +01:00
|
|
|
$request = $this->getRequest();
|
2011-05-17 23:30:17 +02:00
|
|
|
$form = new Application_Form_EditAudioMD();
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-02-24 17:06:19 +01:00
|
|
|
$file_id = $this->_getParam('id', null);
|
2011-09-22 18:24:17 +02:00
|
|
|
$file = Application_Model_StoredFile::Recall($file_id);
|
2011-08-30 22:50:46 +02:00
|
|
|
$form->populate($file->getDbColMetadata());
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
if ($request->isPost()) {
|
2011-05-17 23:30:17 +02:00
|
|
|
if ($form->isValid($request->getPost())) {
|
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$formdata = $form->getValues();
|
2011-06-09 11:50:03 +02:00
|
|
|
$file->setDbColMetadata($formdata);
|
2010-12-30 23:26:44 +01:00
|
|
|
|
2011-06-15 14:20:14 +02:00
|
|
|
$data = $file->getMetadata();
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-10-03 20:10:47 +02:00
|
|
|
// set MDATA_KEY_FILEPATH
|
|
|
|
$data['MDATA_KEY_FILEPATH'] = $file->getFilePath();
|
|
|
|
Logging::log($data['MDATA_KEY_FILEPATH']);
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::SendMessageToMediaMonitor("md_update", $data);
|
2011-05-05 16:55:14 +02:00
|
|
|
|
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$this->_helper->redirector('index');
|
2010-12-30 23:26:44 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-24 17:06:19 +01:00
|
|
|
|
2010-12-30 23:26:44 +01:00
|
|
|
$this->view->form = $form;
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
2011-02-04 06:15:56 +01:00
|
|
|
|
|
|
|
public function getFileMetaDataAction()
|
|
|
|
{
|
2011-02-04 07:28:55 +01:00
|
|
|
$id = $this->_getParam('id');
|
|
|
|
$type = $this->_getParam('type');
|
2011-02-04 06:15:56 +01:00
|
|
|
|
2012-02-06 11:59:20 +01:00
|
|
|
try {
|
|
|
|
if ($type == "audioclip") {
|
|
|
|
$file = Application_Model_StoredFile::Recall($id);
|
|
|
|
$this->view->type = $type;
|
2012-02-27 12:23:22 +01:00
|
|
|
$md = $file->getMetadata();
|
|
|
|
|
|
|
|
$formatter = new SamplerateFormatter($md["MDATA_KEY_SAMPLERATE"]);
|
|
|
|
$md["MDATA_KEY_SAMPLERATE"] = $formatter->format();
|
|
|
|
|
|
|
|
$formatter = new BitrateFormatter($md["MDATA_KEY_BITRATE"]);
|
|
|
|
$md["MDATA_KEY_BITRATE"] = $formatter->format();
|
|
|
|
|
|
|
|
$formatter = new LengthFormatter($md["MDATA_KEY_DURATION"]);
|
|
|
|
$md["MDATA_KEY_DURATION"] = $formatter->format();
|
|
|
|
|
|
|
|
$this->view->md = $md;
|
|
|
|
|
2012-02-06 11:59:20 +01:00
|
|
|
}
|
|
|
|
else if ($type == "playlist") {
|
|
|
|
|
|
|
|
$file = new Application_Model_Playlist($id);
|
|
|
|
$this->view->type = $type;
|
2012-02-27 12:23:22 +01:00
|
|
|
$md = $file->getAllPLMetaData();
|
|
|
|
|
|
|
|
$formatter = new LengthFormatter($md["dcterms:extent"]);
|
|
|
|
$md["dcterms:extent"] = $formatter->format();
|
|
|
|
|
|
|
|
$this->view->md = $md;
|
2012-02-06 11:59:20 +01:00
|
|
|
$this->view->contents = $file->getContents();
|
|
|
|
}
|
2011-02-04 06:15:56 +01:00
|
|
|
}
|
2012-02-06 11:59:20 +01:00
|
|
|
catch (Exception $e) {
|
|
|
|
Logging::log($e->getMessage());
|
2011-02-04 06:15:56 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-09-22 17:47:24 +02:00
|
|
|
public function uploadFileSoundcloudAction(){
|
|
|
|
$id = $this->_getParam('id');
|
|
|
|
$res = exec("/usr/lib/airtime/utils/soundcloud-uploader $id > /dev/null &");
|
|
|
|
// we should die with ui info
|
|
|
|
die();
|
|
|
|
}
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-09-22 20:01:05 +02:00
|
|
|
public function getUploadToSoundcloudStatusAction(){
|
2011-09-22 17:47:24 +02:00
|
|
|
$id = $this->_getParam('id');
|
|
|
|
$type = $this->_getParam('type');
|
2012-02-05 18:19:22 +01:00
|
|
|
|
|
|
|
if ($type == "show") {
|
2011-09-23 16:54:20 +02:00
|
|
|
$show_instance = new Application_Model_ShowInstance($id);
|
2011-09-22 17:47:24 +02:00
|
|
|
$this->view->sc_id = $show_instance->getSoundCloudFileId();
|
|
|
|
$file = $show_instance->getRecordedFile();
|
|
|
|
$this->view->error_code = $file->getSoundCloudErrorCode();
|
|
|
|
$this->view->error_msg = $file->getSoundCloudErrorMsg();
|
2012-02-05 18:19:22 +01:00
|
|
|
}
|
|
|
|
else if ($type == "file") {
|
2011-09-22 20:01:05 +02:00
|
|
|
$file = Application_Model_StoredFile::Recall($id);
|
2011-09-22 17:47:24 +02:00
|
|
|
$this->view->sc_id = $file->getSoundCloudId();
|
|
|
|
$this->view->error_code = $file->getSoundCloudErrorCode();
|
|
|
|
$this->view->error_msg = $file->getSoundCloudErrorMsg();
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|