2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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')
|
|
|
|
->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
|
|
|
}
|
|
|
|
|
|
|
|
public function indexAction()
|
|
|
|
{
|
2011-04-18 17:02:09 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$baseUrl = $request->getBaseUrl();
|
|
|
|
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/contextmenu/jjmenu.js','text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/js/jquery.dataTables.js','text/javascript');
|
2011-04-27 21:14:24 +02:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.pluginAPI.js','text/javascript');
|
2011-06-17 20:41:57 +02:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.fnSetFilteringDelay.js','text/javascript');
|
2011-04-18 17:02:09 +02:00
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/library.js','text/javascript');
|
|
|
|
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/library/advancedsearch.js','text/javascript');
|
|
|
|
|
2011-05-17 23:30:17 +02:00
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/media_library.css');
|
2011-04-18 18:43:04 +02:00
|
|
|
$this->view->headLink()->appendStylesheet($baseUrl.'/css/contextmenu.css');
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$this->_helper->layout->setLayout('library');
|
2011-02-01 21:57:12 +01:00
|
|
|
$this->_helper->viewRenderer->setResponseSegment('library');
|
2011-02-10 04:37:18 +01:00
|
|
|
|
|
|
|
$form = new Application_Form_AdvancedSearch();
|
|
|
|
$form->addGroup(1, 1);
|
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$this->search_sess->next_group = 2;
|
|
|
|
$this->search_sess->next_row[1] = 2;
|
|
|
|
$this->view->form = $form;
|
2011-02-10 04:37:18 +01:00
|
|
|
$this->view->md = $this->search_sess->md;
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$this->_helper->actionStack('index', 'playlist');
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function contextMenuAction()
|
|
|
|
{
|
2011-05-04 22:07:29 +02: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');
|
2011-06-24 22:04:57 +02:00
|
|
|
$request = $this->getRequest();
|
|
|
|
$baseUrl = $request->getBaseUrl();
|
2010-12-22 05:33:58 +01:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$params = '/format/json/id/#id#/type/#type#';
|
|
|
|
|
|
|
|
$paramsPop = str_replace('#id#', $id, $params);
|
|
|
|
$paramsPop = str_replace('#type#', $type, $paramsPop);
|
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
|
|
|
|
2010-12-07 20:19:27 +01:00
|
|
|
$pl_sess = $this->pl_sess;
|
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
if($type === "au") {
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
if(isset($pl_sess->id)) {
|
2011-07-18 19:48:20 +02:00
|
|
|
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Playlist/add-item'.$params, 'callback' => 'window["setSPLContent"]'),
|
2011-04-18 18:43:04 +02:00
|
|
|
'title' => 'Add to Playlist');
|
|
|
|
}
|
|
|
|
|
2011-05-17 23:30:17 +02:00
|
|
|
$menu[] = array('action' => array('type' => 'gourl', 'url' => '/Library/edit-file-md/id/#id#'),
|
2011-04-18 18:43:04 +02:00
|
|
|
'title' => 'Edit Metadata');
|
|
|
|
|
2011-05-04 22:07:29 +02:00
|
|
|
// added for downlaod
|
|
|
|
$id = $this->_getParam('id');
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2011-05-04 22:07:29 +02:00
|
|
|
$file_id = $this->_getParam('id', null);
|
2011-09-22 18:24:17 +02:00
|
|
|
$file = Application_Model_StoredFile::Recall($file_id);
|
2011-05-17 23:30:17 +02:00
|
|
|
|
2011-10-14 00:12:33 +02:00
|
|
|
$url = $file->getRelativeFileUrl($baseUrl).'/download/true';
|
2011-05-04 22:07:29 +02:00
|
|
|
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
|
|
|
|
'title' => 'Download');
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-09-29 23:10:17 +02:00
|
|
|
if (Application_Model_Preference::GetUploadToSoundcloudOption()) {
|
2011-11-28 22:20:34 +01:00
|
|
|
$text = "Upload to SoundCloud";
|
2011-09-22 17:47:24 +02:00
|
|
|
if(!is_null($file->getSoundCloudId())){
|
2011-11-28 22:20:34 +01:00
|
|
|
$text = "Re-upload to SoundCloud";
|
2011-09-22 17:47:24 +02:00
|
|
|
}
|
|
|
|
$menu[] = array('action' => array('type' => 'ajax', 'url' => '/Library/upload-file-soundcloud/id/#id#',
|
2011-09-22 18:15:03 +02:00
|
|
|
'callback'=>"window['addProgressIcon']('$file_id')"),'title' => $text);
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-10-22 17:34:04 +02:00
|
|
|
$scid = $file->getSoundCloudId();
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-10-22 17:34:04 +02:00
|
|
|
if($scid > 0){
|
|
|
|
$link_to_file = $file->getSoundCloudLinkToFile();
|
2011-11-29 16:20:09 +01:00
|
|
|
$menu[] = array('action' => array('type' => 'fn',
|
2011-10-22 17:34:04 +02:00
|
|
|
'callback' => "window['openFileOnSoundCloud']('$link_to_file')"),
|
|
|
|
'title' => 'View on SoundCloud');
|
|
|
|
}
|
2011-09-22 17:47:24 +02:00
|
|
|
}
|
2011-07-18 19:48:20 +02:00
|
|
|
|
|
|
|
if ($user->isAdmin()) {
|
|
|
|
$menu[] = array('action' => array('type' => 'fn',
|
|
|
|
'callback' => "window['confirmDeleteAudioClip']('$paramsPop')"),
|
|
|
|
'title' => 'Delete');
|
|
|
|
}
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
|
|
|
else if($type === "pl") {
|
|
|
|
|
|
|
|
if(!isset($pl_sess->id) || $pl_sess->id !== $id) {
|
2011-05-17 23:30:17 +02:00
|
|
|
$menu[] = array('action' =>
|
|
|
|
array('type' => 'ajax',
|
|
|
|
'url' => '/Playlist/edit'.$params,
|
|
|
|
'callback' => 'window["openDiffSPL"]'),
|
2011-04-18 18:43:04 +02:00
|
|
|
'title' => 'Edit');
|
|
|
|
}
|
|
|
|
else if(isset($pl_sess->id) && $pl_sess->id === $id) {
|
2011-05-17 23:30:17 +02:00
|
|
|
$menu[] = array('action' =>
|
|
|
|
array('type' => 'ajax',
|
|
|
|
'url' => '/Playlist/close'.$params,
|
|
|
|
'callback' => 'window["noOpenPL"]'),
|
2011-04-18 18:43:04 +02:00
|
|
|
'title' => 'Close');
|
|
|
|
}
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
$menu[] = array('action' => array('type' => 'fn',
|
2011-05-17 23:30:17 +02:00
|
|
|
'callback' => "window['confirmDeletePlaylist']('$paramsPop')"),
|
2011-04-18 18:43:04 +02:00
|
|
|
'title' => 'Delete');
|
|
|
|
|
|
|
|
}
|
2010-12-30 00:43:17 +01:00
|
|
|
|
2011-04-18 18:43:04 +02:00
|
|
|
//returns format jjmenu is looking for.
|
|
|
|
die(json_encode($menu));
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteAction()
|
|
|
|
{
|
|
|
|
$id = $this->_getParam('id');
|
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
|
|
|
|
|
|
|
if ($user->isAdmin()) {
|
|
|
|
|
|
|
|
if (!is_null($id)) {
|
2011-09-22 18:24:17 +02:00
|
|
|
$file = Application_Model_StoredFile::Recall($id);
|
2011-07-18 19:48:20 +02:00
|
|
|
|
|
|
|
if (PEAR::isError($file)) {
|
|
|
|
$this->view->message = $file->getMessage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(is_null($file)) {
|
|
|
|
$this->view->message = "file doesn't exist";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$res = $file->delete();
|
|
|
|
|
|
|
|
if (PEAR::isError($res)) {
|
|
|
|
$this->view->message = $res->getMessage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2011-07-19 11:00:32 +02:00
|
|
|
$res = settype($res, "integer");
|
2011-07-18 19:48:20 +02:00
|
|
|
$data = array("filepath" => $file->getFilePath(), "delete" => $res);
|
2011-09-26 21:19:04 +02:00
|
|
|
Application_Model_RabbitMq::SendMessageToMediaMonitor("file_delete", $data);
|
2011-07-18 19:48:20 +02:00
|
|
|
}
|
2011-05-17 23:30:17 +02:00
|
|
|
}
|
2011-04-18 18:43:04 +02:00
|
|
|
|
2011-07-18 19:48:20 +02:00
|
|
|
$this->view->id = $id;
|
2011-04-18 18:43:04 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function contentsAction()
|
|
|
|
{
|
2011-05-17 23:30:17 +02:00
|
|
|
$post = $this->getRequest()->getPost();
|
2012-01-04 18:47:27 +01:00
|
|
|
Logging::log(print_r($post, true));
|
2011-09-22 18:24:17 +02:00
|
|
|
$datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($post);
|
2011-07-18 15:28:17 +02:00
|
|
|
|
2011-06-24 21:51:21 +02:00
|
|
|
//format clip lengh to 1 decimal
|
|
|
|
foreach($datatables["aaData"] as &$data){
|
2011-09-22 17:47:24 +02:00
|
|
|
if($data[6] == 'audioclip'){
|
2011-09-22 20:01:05 +02:00
|
|
|
$file = Application_Model_StoredFile::Recall($data[0]);
|
2011-09-22 17:47:24 +02:00
|
|
|
$scid = $file->getSoundCloudId();
|
|
|
|
if($scid == "-2"){
|
|
|
|
$data[1] .= '<span id="'.$data[0].'" class="small-icon progress"></span>';
|
|
|
|
}else if($scid == "-3"){
|
|
|
|
$data[1] .= '<span id="'.$data[0].'" class="small-icon sc-error"></span>';
|
|
|
|
}else if(!is_null($scid)){
|
|
|
|
$data[1] .= '<span id="'.$data[0].'" class="small-icon soundcloud"></span>';
|
|
|
|
}
|
|
|
|
}
|
2011-09-22 18:24:17 +02:00
|
|
|
$sec = Application_Model_Playlist::playlistTimeToSeconds($data[5]);
|
|
|
|
$data[5] = Application_Model_Playlist::secondsToPlaylistTime($sec);
|
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
|
|
|
|
2011-02-04 07:28:55 +01:00
|
|
|
if($type == "au") {
|
2011-09-22 18:24:17 +02:00
|
|
|
$file = Application_Model_StoredFile::Recall($id);
|
2011-02-04 07:28:55 +01:00
|
|
|
$this->view->type = $type;
|
2011-06-24 10:40:31 +02:00
|
|
|
$this->view->md = $file->getMetadata();
|
2011-02-04 06:15:56 +01:00
|
|
|
}
|
2011-02-04 07:28:55 +01:00
|
|
|
else if($type == "pl") {
|
2011-09-22 18:24:17 +02:00
|
|
|
$file = Application_Model_Playlist::Recall($id);
|
2011-02-04 07:28:55 +01:00
|
|
|
$this->view->type = $type;
|
2011-02-04 06:15:56 +01:00
|
|
|
$this->view->md = $file->getAllPLMetaData();
|
|
|
|
$this->view->contents = $file->getContents();
|
|
|
|
}
|
2011-05-17 23:30:17 +02:00
|
|
|
|
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');
|
|
|
|
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();
|
|
|
|
}else{
|
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();
|
|
|
|
}
|
|
|
|
}
|
2011-11-29 16:20:09 +01:00
|
|
|
|
2011-10-18 16:10:35 +02:00
|
|
|
/**
|
|
|
|
* Stores the number of entries user chose to show in the Library
|
|
|
|
* to the pref db
|
|
|
|
*/
|
|
|
|
public function setNumEntriesAction() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$numEntries = $request->getParam('numEntries');
|
|
|
|
Application_Model_Preference::SetLibraryNumEntries($numEntries);
|
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|