CC-2833: Use ClassLoaders for PHP Files

-made MusicDir, Playlist and StoredFile autoload
This commit is contained in:
martin 2011-09-22 12:24:17 -04:00
parent 4e79a88adc
commit 2be0960ed5
22 changed files with 124 additions and 551 deletions

View File

@ -12,9 +12,9 @@ require_once __DIR__."/configs/conf.php";
require_once 'DB.php';
require_once 'Soundcloud.php';
require_once 'MusicDir.php';
require_once 'Playlist.php';
require_once 'StoredFile.php';
//require_once 'MusicDir.php';
//require_once 'Playlist.php';
//require_once 'StoredFile.php';
require_once 'Schedule.php';
require_once 'Preference.php';
require_once 'Shows.php';
@ -37,6 +37,7 @@ $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
date_default_timezone_set(Application_Model_Preference::GetTimezone());
Logging::setLogPath('/var/log/airtime/zendphp.log');
Logging::log("bootstrap");
Zend_Validate::setDefaultNamespaces("Zend");

View File

@ -97,7 +97,7 @@ class ApiController extends Zend_Controller_Action
$filename = $this->_getParam("file");
$file_id = substr($filename, 0, strpos($filename, "."));
if (ctype_alnum($file_id) && strlen($file_id) == 32) {
$media = StoredFile::RecallByGunid($file_id);
$media = Application_Model_StoredFile::RecallByGunid($file_id);
if ($media != null && !PEAR::isError($media)) {
$filepath = $media->getFilePath();
if(is_file($filepath)){
@ -330,9 +330,9 @@ class ApiController extends Zend_Controller_Action
}
$upload_dir = ini_get("upload_tmp_dir");
StoredFile::uploadFile($upload_dir);
Application_Model_StoredFile::uploadFile($upload_dir);
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
StoredFile::copyFileToStor($upload_dir, $fileName);
Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName);
}
public function uploadRecordedAction()
@ -356,7 +356,7 @@ class ApiController extends Zend_Controller_Action
$showCanceled = false;
$file = StoredFile::Recall($file_id);
$file = Application_Model_StoredFile::Recall($file_id);
//$show_instance = $this->_getParam('show_instance');
$show_name = null;
@ -435,9 +435,9 @@ class ApiController extends Zend_Controller_Action
exit;
}
$this->view->stor = MusicDir::getStorDir()->getDirectory();
$this->view->stor = Application_Model_MusicDir::getStorDir()->getDirectory();
$watchedDirs = MusicDir::getWatchedDirs();
$watchedDirs = Application_Model_MusicDir::getWatchedDirs();
$watchedDirsPath = array();
foreach($watchedDirs as $wd){
$watchedDirsPath[] = $wd->getDirectory();
@ -475,10 +475,10 @@ class ApiController extends Zend_Controller_Action
$filepath = $md['MDATA_KEY_FILEPATH'];
$filepath = str_replace("\\", "", $filepath);
$file = StoredFile::RecallByFilepath($filepath);
$file = Application_Model_StoredFile::RecallByFilepath($filepath);
if (is_null($file)) {
$file = StoredFile::Insert($md);
$file = Application_Model_StoredFile::Insert($md);
}
else {
$this->view->error = "File already exists in Airtime.";
@ -488,7 +488,7 @@ class ApiController extends Zend_Controller_Action
else if ($mode == "modify") {
$filepath = $md['MDATA_KEY_FILEPATH'];
$filepath = str_replace("\\", "", $filepath);
$file = StoredFile::RecallByFilepath($filepath);
$file = Application_Model_StoredFile::RecallByFilepath($filepath);
//File is not in database anymore.
if (is_null($file)) {
@ -502,7 +502,7 @@ class ApiController extends Zend_Controller_Action
}
else if ($mode == "moved") {
$md5 = $md['MDATA_KEY_MD5'];
$file = StoredFile::RecallByMd5($md5);
$file = Application_Model_StoredFile::RecallByMd5($md5);
if (is_null($file)) {
$this->view->error = "File doesn't exist in Airtime.";
@ -518,7 +518,7 @@ class ApiController extends Zend_Controller_Action
else if ($mode == "delete") {
$filepath = $md['MDATA_KEY_FILEPATH'];
$filepath = str_replace("\\", "", $filepath);
$file = StoredFile::RecallByFilepath($filepath);
$file = Application_Model_StoredFile::RecallByFilepath($filepath);
if (is_null($file)) {
$this->view->error = "File doesn't exist in Airtime.";
@ -544,7 +544,7 @@ class ApiController extends Zend_Controller_Action
}
$dir_id = $request->getParam('dir_id');
$this->view->files = StoredFile::listAllFiles($dir_id);
$this->view->files = Application_Model_StoredFile::listAllFiles($dir_id);
}
public function listAllWatchedDirsAction() {
@ -561,8 +561,8 @@ class ApiController extends Zend_Controller_Action
$result = array();
$arrWatchedDirs = MusicDir::getWatchedDirs();
$storDir = MusicDir::getStorDir();
$arrWatchedDirs = Application_Model_MusicDir::getWatchedDirs();
$storDir = Application_Model_MusicDir::getStorDir();
$result[$storDir->getId()] = $storDir->getDirectory();
@ -587,7 +587,7 @@ class ApiController extends Zend_Controller_Action
exit;
}
$this->view->msg = MusicDir::addWatchedDir($path);
$this->view->msg = Application_Model_MusicDir::addWatchedDir($path);
}
public function removeWatchedDirAction() {
@ -604,7 +604,7 @@ class ApiController extends Zend_Controller_Action
exit;
}
$this->view->msg = MusicDir::removeWatchedDir($path);
$this->view->msg = Application_Model_MusicDir::removeWatchedDir($path);
}
public function setStorageDirAction() {
@ -621,7 +621,7 @@ class ApiController extends Zend_Controller_Action
exit;
}
$this->view->msg = MusicDir::setStorDir($path);
$this->view->msg = Application_Model_MusicDir::setStorDir($path);
}
public function getStreamSettingAction() {

View File

@ -81,7 +81,7 @@ class LibraryController extends Zend_Controller_Action
$id = $this->_getParam('id');
$file_id = $this->_getParam('id', null);
$file = StoredFile::Recall($file_id);
$file = Application_Model_StoredFile::Recall($file_id);
$url = $file->getRelativeFileUrl($baseUrl).'/api_key/'.$CC_CONFIG["apiKey"][0].'/download/true';
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
@ -132,7 +132,7 @@ class LibraryController extends Zend_Controller_Action
if ($user->isAdmin()) {
if (!is_null($id)) {
$file = StoredFile::Recall($id);
$file = Application_Model_StoredFile::Recall($id);
if (PEAR::isError($file)) {
$this->view->message = $file->getMessage();
@ -163,12 +163,12 @@ class LibraryController extends Zend_Controller_Action
public function contentsAction()
{
$post = $this->getRequest()->getPost();
$datatables = StoredFile::searchFilesForPlaylistBuilder($post);
$datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($post);
//format clip lengh to 1 decimal
foreach($datatables["aaData"] as &$data){
$sec = Playlist::playlistTimeToSeconds($data[5]);
$data[5] = Playlist::secondsToPlaylistTime($sec);
$sec = Application_Model_Playlist::playlistTimeToSeconds($data[5]);
$data[5] = Application_Model_Playlist::secondsToPlaylistTime($sec);
}
die(json_encode($datatables));
@ -180,7 +180,7 @@ class LibraryController extends Zend_Controller_Action
$form = new Application_Form_EditAudioMD();
$file_id = $this->_getParam('id', null);
$file = StoredFile::Recall($file_id);
$file = Application_Model_StoredFile::Recall($file_id);
$form->populate($file->getDbColMetadata());
if ($request->isPost()) {
@ -206,12 +206,12 @@ class LibraryController extends Zend_Controller_Action
$type = $this->_getParam('type');
if($type == "au") {
$file = StoredFile::Recall($id);
$file = Application_Model_StoredFile::Recall($id);
$this->view->type = $type;
$this->view->md = $file->getMetadata();
}
else if($type == "pl") {
$file = Playlist::Recall($id);
$file = Application_Model_Playlist::Recall($id);
$this->view->type = $type;
$this->view->md = $file->getAllPLMetaData();
$this->view->contents = $file->getContents();

View File

@ -33,7 +33,7 @@ class PlaylistController extends Zend_Controller_Action
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
$pl = Application_Model_Playlist::Recall($pl_sess->id);
if($pl === FALSE) {
unset($pl_sess->id);
return;
@ -48,7 +48,7 @@ class PlaylistController extends Zend_Controller_Action
if(isset($pl_sess->id)) {
$pl = Playlist::Recall($pl_sess->id);
$pl = Application_Model_Playlist::Recall($pl_sess->id);
if($pl !== FALSE) {
$this->closePlaylist($pl);
}
@ -56,7 +56,7 @@ class PlaylistController extends Zend_Controller_Action
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$pl = Playlist::Recall($pl_id);
$pl = Application_Model_Playlist::Recall($pl_id);
if($pl === FALSE) {
return FALSE;
}
@ -92,7 +92,7 @@ class PlaylistController extends Zend_Controller_Action
$pl_sess = $this->pl_sess;
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$pl = new Playlist();
$pl = new Application_Model_Playlist();
$pl->create("Untitled Playlist");
$pl->setPLMetaData('dc:creator', $userInfo->login);
@ -285,11 +285,11 @@ class PlaylistController extends Zend_Controller_Action
public function deleteAction()
{
$id = $this->_getParam('id', null);
$pl = Playlist::Recall($id);
$pl = Application_Model_Playlist::Recall($id);
if ($pl !== FALSE) {
Playlist::Delete($id);
Application_Model_Playlist::Delete($id);
$pl_sess = $this->pl_sess;
@ -305,7 +305,7 @@ class PlaylistController extends Zend_Controller_Action
public function deleteActiveAction()
{
$pl = $this->getPlaylist();
Playlist::Delete($pl->getId());
Application_Model_Playlist::Delete($pl->getId());
$pl_sess = $this->pl_sess;
unset($pl_sess->id);

View File

@ -26,7 +26,7 @@ class PluploadController extends Zend_Controller_Action
public function uploadAction()
{
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
StoredFile::uploadFile($upload_dir);
Application_Model_StoredFile::uploadFile($upload_dir);
die('{"jsonrpc" : "2.0"}');
}
@ -34,7 +34,7 @@ class PluploadController extends Zend_Controller_Action
public function copyfileAction(){
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
$filename = $this->_getParam('name');
StoredFile::copyFileToStor($upload_dir, $filename);
Application_Model_StoredFile::copyFileToStor($upload_dir, $filename);
die('{"jsonrpc" : "2.0"}');
}

View File

@ -240,7 +240,7 @@ class PreferenceController extends Zend_Controller_Action
$element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$res = MusicDir::setStorDir($chosen);
$res = Application_Model_MusicDir::setStorDir($chosen);
if($res['code'] != 0){
$watched_dirs_form->populate(array('storageFolder' => $chosen));
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
@ -255,7 +255,7 @@ class PreferenceController extends Zend_Controller_Action
$element = $this->getRequest()->getParam("element");
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$res = MusicDir::addWatchedDir($chosen);
$res = Application_Model_MusicDir::addWatchedDir($chosen);
if($res['code'] != 0){
$watched_dirs_form->populate(array('watchedFolder' => $chosen));
$watched_dirs_form->getElement($element)->setErrors(array($res['error']));
@ -268,7 +268,7 @@ class PreferenceController extends Zend_Controller_Action
{
$chosen = $this->getRequest()->getParam("dir");
$dir = MusicDir::removeWatchedDir($chosen);
$dir = Application_Model_MusicDir::removeWatchedDir($chosen);
$watched_dirs_form = new Application_Form_WatchedDirPreferences();
$this->view->subform = $watched_dirs_form->render();

View File

@ -290,8 +290,8 @@ class ScheduleController extends Zend_Controller_Action
$playlists = $show->searchPlaylistsForShow($post);
foreach( $playlists['aaData'] as &$data){
// calling two functions to format time to 1 decimal place
$sec = Playlist::playlistTimeToSeconds($data[4]);
$data[4] = Playlist::secondsToPlaylistTime($sec);
$sec = Application_Model_Playlist::playlistTimeToSeconds($data[4]);
$data[4] = Application_Model_Playlist::secondsToPlaylistTime($sec);
}
//for datatables
@ -744,7 +744,7 @@ class ScheduleController extends Zend_Controller_Action
$id = $this->_getParam('id');
$file_id = $this->_getParam('id', null);
$file = StoredFile::Recall($file_id);
$file = Application_Model_StoredFile::Recall($file_id);
$url = $file->getFileURL().'/api_key/'.$CC_CONFIG["apiKey"][0].'/download/true';
$menu[] = array('action' => array('type' => 'gourl', 'url' => $url),

View File

@ -2,7 +2,7 @@
class NestedDirectoryException extends Exception { }
class MusicDir {
class Application_Model_MusicDir {
/**
* @holds propel database object
@ -193,7 +193,7 @@ class MusicDir {
{
$dir = CcMusicDirsQuery::create()->findPK($pk);
$mus_dir = new MusicDir($dir);
$mus_dir = new Application_Model_MusicDir($dir);
return $mus_dir;
}
@ -208,7 +208,7 @@ class MusicDir {
return null;
}
else{
$mus_dir = new MusicDir($dir);
$mus_dir = new Application_Model_MusicDir($dir);
return $mus_dir;
}
}
@ -222,7 +222,7 @@ class MusicDir {
->find();
foreach($dirs as $dir) {
$result[] = new MusicDir($dir);
$result[] = new Application_Model_MusicDir($dir);
}
return $result;
@ -234,7 +234,7 @@ class MusicDir {
->filterByType("stor")
->findOne();
$mus_dir = new MusicDir($dir);
$mus_dir = new Application_Model_MusicDir($dir);
return $mus_dir;
}
@ -272,7 +272,7 @@ class MusicDir {
foreach($dirs as $dir) {
$directory = $dir->getDirectory();
if (substr($p_filepath, 0, strlen($directory)) === $directory) {
$mus_dir = new MusicDir($dir);
$mus_dir = new Application_Model_MusicDir($dir);
return $mus_dir;
}
}
@ -282,7 +282,7 @@ class MusicDir {
public static function removeWatchedDir($p_dir){
$p_dir = realpath($p_dir)."/";
$dir = MusicDir::getDirByPath($p_dir);
$dir = Application_Model_MusicDir::getDirByPath($p_dir);
if($dir == NULL){
return array("code"=>1,"error"=>"'$p_dir' doesn't exist in the watched list.");
}else{

View File

@ -9,7 +9,7 @@ define('INDCH', ' ');
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
*/
class Playlist {
class Application_Model_Playlist {
// *** Variable stored in the database ***
@ -162,7 +162,7 @@ class Playlist {
if($pl === NULL)
return FALSE;
$storedPlaylist = new Playlist();
$storedPlaylist = new Application_Model_Playlist();
$storedPlaylist->id = $id;
$storedPlaylist->name = $pl->getDbName();
$storedPlaylist->state = $pl->getDbState();
@ -405,10 +405,10 @@ class Playlist {
foreach ($rows as $row) {
$files[$i] = $row->toArray(BasePeer::TYPE_FIELDNAME, true, true);
// display only upto 1 decimal place by calling secondsToPlaylistTime
$clipSec = Playlist::playlistTimeToSeconds($files[$i]['cliplength']);
$files[$i]['cliplength'] = Playlist::secondsToPlaylistTime($clipSec);
$clipSec = Application_Model_Playlist::playlistTimeToSeconds($files[$i]['cliplength']);
$files[$i]['cliplength'] = Application_Model_Playlist::secondsToPlaylistTime($clipSec);
$offset += $clipSec;
$files[$i]['offset'] = Playlist::secondsToPlaylistTime($offset);
$files[$i]['offset'] = Application_Model_Playlist::secondsToPlaylistTime($offset);
$i++;
}
@ -424,8 +424,8 @@ class Playlist {
return '00:00:00';
// calling two functions to format time to 1 decimal place
$sec = Playlist::playlistTimeToSeconds($res);
$res = Playlist::secondsToPlaylistTime($sec);
$sec = Application_Model_Playlist::playlistTimeToSeconds($res);
$res = Application_Model_Playlist::secondsToPlaylistTime($sec);
return $res;
}
@ -466,7 +466,7 @@ class Playlist {
{
if ($val && $this->isEdited() !== FALSE) {
return PEAR::raiseError(
'Playlist::lock: playlist already locked'
'Application_Model_Playlist::lock: playlist already locked'
);
}
$r = $this->setEditFlag($subjid, $val);
@ -507,7 +507,7 @@ class Playlist {
public function addAudioClip($p_mediaId, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL)
{
//get audio clip.
$media = StoredFile::Recall($p_mediaId);
$media = Application_Model_StoredFile::Recall($p_mediaId);
if (is_null($media) || PEAR::isError($media)) {
return $media;
}
@ -999,430 +999,3 @@ class Playlist {
}
} // class Playlist
/**
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
* @todo Rename this class PlaylistTag
*/
class PlaylistTagExport
{
public static function OutputToSmil(&$pl, $plt, $ind='')
{
$ind2 = $ind.INDCH;
$ind3 = $ind2.INDCH;
$ind4 = $ind3.INDCH;
$res = "";
foreach ($plt['children'] as $ple) {
switch ($ple['elementname']) {
case "playlistElement":
$r = PlaylistElementExport::OutputToSmil($pl, $ple, $ind4);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$res .= $r;
}
break;
case "metadata":
$r = PlaylistMetadataExport::OutputToSmil($pl, $ple, $ind4);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$res .= $r;
}
break;
default:
}
}
$res = "$ind<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
"$ind<smil xmlns=\"http://www.w3.org/2001/SMIL20/Language\">\n".
"$ind2<body>\n".
"$ind3<par>\n".
"$res".
"$ind3</par>\n".
"$ind2</body>\n".
"$ind</smil>\n";
return $res;
}
public static function OutputToM3u(&$pl, $plt, $ind='')
{
$res = "";
foreach ($plt['children'] as $ple) {
switch ($ple['elementname']) {
case"playlistElement":
$r = PlaylistElementExport::OutputToM3u($pl, $ple);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$res .= $r;
}
break;
}
}
$res = "#EXTM3U\n$res";
return $res;
}
public static function OutputToRss(&$pl, $plt, $ind='')
{
$ind2 = $ind.INDCH;
$ind3 = $ind2.INDCH;
$res = "";
foreach ($plt['children'] as $ple) {
switch ($ple['elementname']) {
case "playlistElement":
$r = PlaylistElementExport::OutputToRss($pl, $ple, $ind3);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$res .= $r;
}
break;
case "metadata":
$r = PlaylistMetadataExport::OutputToRss($pl, $ple, $ind3);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$res .= $r;
}
break;
default:
}
}
$res = "$ind<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n".
"$ind<rss version=\"2.0\">\n".
"$ind2<channel>\n".
"$res".
"$ind2</channel>\n".
"$ind</rss>\n";
return $res;
}
}
/**
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
* @todo Rename this class "PlaylistElement"
*/
class PlaylistElementExport {
public static function OutputToSmil(&$pl, $ple, $ind='')
{
$acOrPl = NULL;
$finfo = array('fi'=>0, 'fo'=>0);
$ind2 = $ind.INDCH;
$ind3 = $ind2.INDCH;
$anim = '';
foreach ($ple['children'] as $ac) {
switch ($ac['elementname']) {
case "audioClip":
$r = PlaylistAudioClipExport::OutputToSmil($pl, $ac, $ind2);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$acOrPl = $r;
}
break;
case "playlist":
$gunid = $ac['attrs']['id'];
$pl2 = StoredFile::RecallByGunid($gunid);
if (is_null($pl2) || PEAR::isError($pl2)) {
return $pl2;
}
$r = $pl2->outputToSmil(FALSE);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$acOrPl = $r;
}
break;
case "fadeInfo":
$r = PlaylistFadeInfoExport::OutputToSmil($pl, $ac, $ind2);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$finfo = $r;
}
break;
default:
return PEAR::raiseError(
"PlaylistElementExport::OutputToSmil:".
" unknown tag {$ac['elementname']}"
);
}
}
$beginS = Playlist::playlistTimeToSeconds($ple['attrs']['relativeOffset']);
$playlengthS = Playlist::playlistTimeToSeconds($acOrPl['playlength']);
$fadeOutS = Playlist::playlistTimeToSeconds($finfo['fo']);
$fiBeginS = 0;
$fiEndS = Playlist::playlistTimeToSeconds($finfo['fi']);
$foBeginS = ($playlengthS - $fadeOutS);
$foEndS = Playlist::playlistTimeToSeconds($acOrPl['playlength']);
foreach (array('fi','fo') as $ff) {
if (${$ff."EndS"} - ${$ff."BeginS"} > 0) {
$anim .= "{$ind2}<animate attributeName = \"soundLevel\"\n".
"{$ind3}from = \"".($ff == 'fi' ? 0 : 100)."%\"\n".
"{$ind3}to = \"".($ff == 'fi' ? 100 : 0)."%\"\n".
"{$ind3}calcMode = \"linear\"\n".
"{$ind3}begin = \"{${$ff."BeginS"}}s\"\n".
"{$ind3}end = \"{${$ff."EndS"}}s\"\n".
"{$ind3}fill = \"freeze\"\n".
"{$ind2}/>\n"
;
}
}
$src = $acOrPl['src'];
$str = "$ind<audio src=\"$src\" begin=\"{$beginS}s\"".
($anim ? ">\n$anim$ind</audio>" : " />").
" <!-- {$acOrPl['type']}, {$acOrPl['gunid']}, {$acOrPl['playlength']} -->".
"\n";
return $str;
}
public static function OutputToM3u(&$pl, $ple, $ind='')
{
$acOrPl = NULL;
foreach ($ple['children'] as $ac) {
switch ($ac['elementname']) {
case "audioClip":
$r = PlaylistAudioClipExport::OutputToM3u($pl, $ac);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$acOrPl = $r;
}
break;
case "playlist":
$gunid = $ac['attrs']['id'];
$pl2 = StoredFile::RecallByGunid($gunid);
if (is_null($pl2) || PEAR::isError($pl2)) {
return $pl2;
}
$r = $pl2->outputToM3u(FALSE);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$acOrPl = $r;
}
break;
}
}
if (is_null($acOrPl)) {
return '';
}
$playlength = ceil(Playlist::playlistTimeToSeconds($acOrPl['playlength']));
$title = $acOrPl['title'];
$uri = (isset($acOrPl['uri']) ? $acOrPl['uri'] : '???' );
$res = "#EXTINF: $playlength, $title\n";
$res .= "$uri\n";
return $res;
}
public static function OutputToRss(&$pl, $ple, $ind='')
{
$acOrPl = NULL;
$ind2 = $ind.INDCH;
$anim = '';
foreach ($ple['children'] as $ac) {
switch ($ac['elementname']) {
case "audioClip":
$r = PlaylistAudioClipExport::OutputToRss($pl, $ac, $ind2);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$acOrPl = $r;
}
break;
case "playlist":
$gunid = $ac['attrs']['id'];
$pl2 = StoredFile::RecallByGunid($gunid);
if (is_null($pl2) || PEAR::isError($pl2)) {
return $pl2;
}
$r = $pl2->outputToRss(FALSE);
if (PEAR::isError($r)) {
return $r;
}
if (!is_null($r)) {
$acOrPl = $r;
}
break;
case "fadeInfo":
break;
default:
return PEAR::raiseError(
"PlaylistElementExport::OutputToRss:".
" unknown tag {$ac['elementname']}"
);
}
}
$title = (isset($acOrPl['title']) ? htmlspecialchars($acOrPl['title']) : '' );
$desc = (isset($acOrPl['desc']) ? htmlspecialchars($acOrPl['desc']) : '' );
$link = htmlspecialchars($acOrPl['src']);
$desc = '';
$str = "$ind<item>\n".
"$ind2<title>$title</title>\n".
"$ind2<description>$desc</description>\n".
"$ind2<link>$link</link>\n".
"$ind</item>\n";
return $str;
}
}
/**
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
* @todo Rename this class to PlaylistAudioClip (notice the caps)
*/
class PlaylistAudioClipExport
{
public static function OutputToSmil(&$pl, $plac, $ind='')
{
$gunid = $plac['attrs']['id'];
$ac = StoredFile::RecallByGunid($gunid);
if (is_null($ac) || PEAR::isError($ac)) {
return $ac;
}
$RADext = $ac->getFileExtension();
if (PEAR::isError($RADext)) {
return $RADext;
}
return array(
'type' => 'audioclip',
'gunid' => $gunid,
'src' => AC_URL_RELPATH."$gunid.$RADext",
'playlength' => $plac['attrs']['playlength'],
);
}
public static function OutputToM3u(&$pl, $plac, $ind='')
{
$gunid = $plac['attrs']['id'];
$ac = StoredFile::RecallByGunid($gunid);
if (is_null($ac) || PEAR::isError($ac)) {
return $ac;
}
$RADext = $ac->getFileExtension();
if (PEAR::isError($RADext)) {
return $RADext;
}
return array(
'playlength' => $plac['attrs']['playlength'],
'title' => $plac['attrs']['title'],
'uri' => AC_URL_RELPATH."$gunid.$RADext",
);
}
public static function OutputToRss(&$pl, $plac, $ind='')
{
$id = $plac['attrs']['id'];
$playlist = Playlist::Recall($id);
if (is_null($playlist) || PEAR::isError($playlist)) {
return $playlist;
}
$RADext = $playlist->getFileExtension();
if (PEAR::isError($RADext)) {
return $RADext;
}
$title = $playlist->getName();
$desc = $playlist->getPLMetaData("dc:description");
return array(
'type' => 'audioclip',
'gunid' => $id,
'src' => "http://XXX/YY/$id.$RADext",
'playlength' => $plac['attrs']['playlength'],
'title' => $title,
'desc' => $desc,
);
}
}
/**
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
* @todo Rename this class "PlaylistFadeInfo" (notive the caps)
*/
class PlaylistFadeInfoExport
{
public static function OutputToSmil(&$pl, $plfi, $ind='')
{
$r = array(
'fi'=>$plfi['attrs']['fadeIn'],
'fo'=>$plfi['attrs']['fadeOut'],
);
return $r;
}
public static function OutputToM3u(&$pl, $plfa, $ind='')
{
return '';
}
public static function OutputToRss(&$pl, $plfa, $ind='')
{
return '';
}
}
/**
* @package Airtime
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
* @todo Rename this class to PlaylistMetadata (notice the caps)
*/
class PlaylistMetadataExport
{
public static function OutputToSmil(&$pl, $md, $ind='')
{
return NULL;
}
public static function OutputToM3u(&$pl, $md, $ind='')
{
return NULL;
}
public static function OutputToRss(&$pl, $md, $ind='')
{
return NULL;
}
}

View File

@ -334,8 +334,8 @@ class Application_Model_Preference
}
$outputArray['NUM_OF_USERS'] = User::getUserCount();
$outputArray['NUM_OF_SONGS'] = StoredFile::getFileCount();
$outputArray['NUM_OF_PLAYLISTS'] = Playlist::getPlaylistCount();
$outputArray['NUM_OF_SONGS'] = Application_Model_StoredFile::getFileCount();
$outputArray['NUM_OF_PLAYLISTS'] = Application_Model_Playlist::getPlaylistCount();
$outputArray['NUM_OF_SCHEDULED_PLAYLISTS'] = Schedule::getSchduledPlaylistCount();
$outputArray['NUM_OF_PAST_SHOWS'] = ShowInstance::GetShowInstanceCount(date("Y-m-d H:i:s"));
$outputArray['UNIQUE_ID'] = Application_Model_Preference::GetUniqueId();

View File

@ -6,7 +6,7 @@
* @subpackage StorageServer
* @copyright 2010 Sourcefabric O.P.S.
* @license http://www.gnu.org/licenses/gpl.txt
* @see StoredFile
* @see Application_Model_StoredFile
*/
/* ================== Prefs ================== */
class Prefs {

View File

@ -1,5 +1,4 @@
<?php
require_once("StoredFile.php");
class ScheduleGroup {
@ -49,7 +48,7 @@ class ScheduleGroup {
// Schedule a single audio track
// Load existing track
$track = StoredFile::Recall($p_audioFileId);
$track = Application_Model_StoredFile::Recall($p_audioFileId);
if (is_null($track)) {
return new PEAR_Error("Could not find audio track.");
}
@ -80,7 +79,7 @@ class ScheduleGroup {
// Schedule a whole playlist
// Load existing playlist
$playlist = Playlist::Recall($p_playlistId);
$playlist = Application_Model_Playlist::Recall($p_playlistId);
if (is_null($playlist)) {
return new PEAR_Error("Could not find playlist.");
}
@ -708,7 +707,7 @@ class Schedule {
$medias = array();
foreach ($items as $item)
{
$storedFile = StoredFile::Recall($item["file_id"]);
$storedFile = Application_Model_StoredFile::Recall($item["file_id"]);
$uri = $storedFile->getFileUrl();
$starts = Schedule::AirtimeTimeToPypoTime($item["starts"]);

View File

@ -1370,7 +1370,7 @@ class ShowInstance {
$file_id = $this->_showInstance->getDbRecordedFile();
if(isset($file_id)) {
$file = StoredFile::Recall($file_id);
$file = Application_Model_StoredFile::Recall($file_id);
if (PEAR::isError($file)) {
return null;
@ -1717,7 +1717,7 @@ class ShowInstance {
public function searchPlaylistsForShow($datatables)
{
return StoredFile::searchPlaylistsForSchedule($datatables);
return Application_Model_StoredFile::searchPlaylistsForSchedule($datatables);
}
public function getShowListContent()

View File

@ -61,7 +61,7 @@ class SmilPlaylist {
return $lspl;
}
require_once("Playlist.php");
$pl =& Playlist::create($gb, $plid, "imported_SMIL");
$pl =& Application_Model_Playlist::create($gb, $plid, "imported_SMIL");
if (PEAR::isError($pl)) {
return $pl;
}
@ -220,14 +220,14 @@ class SmilPlaylistAudioElement {
}
}
if ($fadeIn > 0 || $fadeOut > 0) {
$fiGunid = StoredFile::CreateGunid();
$fadeIn = Playlist::secondsToPlaylistTime($fadeIn);
$fadeOut = Playlist::secondsToPlaylistTime($fadeOut);
$fiGunid = Application_Model_StoredFile::CreateGunid();
$fadeIn = Application_Model_Playlist::secondsToPlaylistTime($fadeIn);
$fadeOut = Application_Model_Playlist::secondsToPlaylistTime($fadeOut);
$fInfo = "$ind2<fadeInfo id=\"$fiGunid\" fadeIn=\"$fadeIn\" fadeOut=\"$fadeOut\"/>\n";
} else {
$fInfo = '';
}
$plElGunid = StoredFile::CreateGunid();
$plElGunid = Application_Model_StoredFile::CreateGunid();
$acGunid = $gunid;
$type = 'audioClip';
if (preg_match("|\.([a-zA-Z0-9]+)$|", $uri, $va)) {
@ -244,7 +244,7 @@ class SmilPlaylistAudioElement {
}
//break;
default:
$ac = StoredFile::RecallByGunid($gunid);
$ac = Application_Model_StoredFile::RecallByGunid($gunid);
if (is_null($ac) || PEAR::isError($ac)) {
return $ac;
}
@ -257,10 +257,10 @@ class SmilPlaylistAudioElement {
}
$title = basename($tree->attrs['src']->val);
$offset = Playlist::secondsToPlaylistTime($tree->attrs['begin']->val);
$clipStart = Playlist::secondsToPlaylistTime($tree->attrs['clipStart']->val);
$clipEnd = Playlist::secondsToPlaylistTime($tree->attrs['clipEnd']->val);
$clipLength = Playlist::secondsToPlaylistTime($tree->attrs['clipLength']->val);
$offset = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['begin']->val);
$clipStart = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['clipStart']->val);
$clipEnd = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['clipEnd']->val);
$clipLength = Application_Model_Playlist::secondsToPlaylistTime($tree->attrs['clipLength']->val);
$res = "$ind<playlistElement id=\"$plElGunid\" relativeOffset=\"$offset\" clipStart=\"$clipStart\" clipEnd=\"$clipEnd\" clipLength=\"$clipLength\">\n".
"$ind2<$type id=\"$acGunid\" playlength=\"$playlength\" title=\"$title\"/>\n".
$fInfo.

View File

@ -1,7 +1,7 @@
<?php
/**
* StoredFile class
* Application_Model_StoredFile class
*
* @package Airtime
* @subpackage StorageServer
@ -9,7 +9,7 @@
* @license http://www.gnu.org/licenses/gpl.txt
* @see MetaData
*/
class StoredFile {
class Application_Model_StoredFile {
/**
* @holds propel database object
@ -286,7 +286,7 @@ class StoredFile {
$playlists = array();
if (is_array($ids) && count($ids) > 0) {
foreach ($ids as $id) {
$playlists[] = Playlist::Recall($id);
$playlists[] = Application_Model_Playlist::Recall($id);
}
}
return $playlists;
@ -310,7 +310,7 @@ class StoredFile {
}
}
Playlist::DeleteFileFromAllPlaylists($this->getId());
Application_Model_Playlist::DeleteFileFromAllPlaylists($this->getId());
$this->_file->delete();
if (isset($res)) {
@ -410,7 +410,7 @@ class StoredFile {
*/
public function getFilePath()
{
$music_dir = MusicDir::getDirByPK($this->_file->getDbDirectory());
$music_dir = Application_Model_MusicDir::getDirByPK($this->_file->getDbDirectory());
$filepath = $this->_file->getDbFilepath();
return $music_dir->getDirectory().$filepath;
@ -423,11 +423,11 @@ class StoredFile {
*/
public function setFilePath($p_filepath)
{
$path_info = MusicDir::splitFilePath($p_filepath);
$path_info = Application_Model_MusicDir::splitFilePath($p_filepath);
if (is_null($path_info)) {
return -1;
}
$musicDir = MusicDir::getDirByPath($path_info[0]);
$musicDir = Application_Model_MusicDir::getDirByPath($path_info[0]);
$this->_file->setDbDirectory($musicDir->getId());
$this->_file->setDbFilepath($path_info[1]);
@ -459,7 +459,7 @@ class StoredFile {
$file = new CcFiles();
$file->setDbGunid(md5(uniqid("", true)));
$storedFile = new StoredFile();
$storedFile = new Application_Model_StoredFile();
$storedFile->_file = $file;
if(isset($md['MDATA_KEY_FILEPATH'])) {
@ -490,7 +490,7 @@ class StoredFile {
* global unique id of file
* @param string $p_md5sum
* MD5 sum of the file
* @return StoredFile|NULL
* @return Application_Model_StoredFile|NULL
* Return NULL if the object doesnt exist in the DB.
*/
public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null, $p_filepath=null)
@ -509,12 +509,12 @@ class StoredFile {
->findOne();
}
else if (isset($p_filepath)) {
$path_info = MusicDir::splitFilePath($p_filepath);
$path_info = Application_Model_MusicDir::splitFilePath($p_filepath);
if (is_null($path_info)) {
return null;
}
$music_dir = MusicDir::getDirByPath($path_info[0]);
$music_dir = Application_Model_MusicDir::getDirByPath($path_info[0]);
$file = CcFilesQuery::create()
->filterByDbDirectory($music_dir->getId())
@ -526,7 +526,7 @@ class StoredFile {
}
if (isset($file)) {
$storedFile = new StoredFile();
$storedFile = new Application_Model_StoredFile();
$storedFile->_file = $file;
return $storedFile;
@ -547,34 +547,34 @@ class StoredFile {
*
* @param string $p_gunid
* global unique id of file
* @return StoredFile|NULL
* @return Application_Model_StoredFile|NULL
*/
public static function RecallByGunid($p_gunid)
{
return StoredFile::Recall(null, $p_gunid);
return Application_Model_StoredFile::Recall(null, $p_gunid);
}
/**
* Fetch the StoredFile by looking up the MD5 value.
* Fetch the Application_Model_StoredFile by looking up the MD5 value.
*
* @param string $p_md5sum
* @return StoredFile|NULL
* @return Application_Model_StoredFile|NULL
*/
public static function RecallByMd5($p_md5sum)
{
return StoredFile::Recall(null, null, $p_md5sum);
return Application_Model_StoredFile::Recall(null, null, $p_md5sum);
}
/**
* Fetch the StoredFile by looking up its filepath.
* Fetch the Application_Model_StoredFile by looking up its filepath.
*
* @param string $p_filepath path of file stored in Airtime.
* @return StoredFile|NULL
* @return Application_Model_StoredFile|NULL
*/
public static function RecallByFilepath($p_filepath)
{
return StoredFile::Recall(null, null, null, $p_filepath);
return Application_Model_StoredFile::Recall(null, null, null, $p_filepath);
}
public static function searchFilesForPlaylistBuilder($datatables) {
@ -616,7 +616,7 @@ class StoredFile {
(".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS";
return StoredFile::searchFiles($fromTable, $datatables);
return Application_Model_StoredFile::searchFiles($fromTable, $datatables);
}
@ -626,7 +626,7 @@ class StoredFile {
//$datatables["optWhere"][] = "INTERVAL '{$time_remaining}' > INTERVAL '00:00:00'";
$datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'";
return StoredFile::searchFiles($fromTable, $datatables);
return Application_Model_StoredFile::searchFiles($fromTable, $datatables);
}
public static function searchFiles($fromTable, $data)
@ -801,7 +801,7 @@ class StoredFile {
/*$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName;
$md5 = md5_file($audio_file);
$duplicate = StoredFile::RecallByMd5($md5);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
if ($duplicate) {
if (PEAR::isError($duplicate)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
@ -812,7 +812,7 @@ class StoredFile {
}
}
$storDir = MusicDir::getStorDir();
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
$stor .= "/organize";
@ -827,7 +827,7 @@ class StoredFile {
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName;
Logging::log('copyFileToStor: moving file '.$audio_file);
$md5 = md5_file($audio_file);
$duplicate = StoredFile::RecallByMd5($md5);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
if ($duplicate) {
if (PEAR::isError($duplicate)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
@ -838,7 +838,7 @@ class StoredFile {
}
}
$storDir = MusicDir::getStorDir();
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
$stor .= "/organize";

View File

@ -182,8 +182,8 @@ class Application_Model_Systemstatus
public static function GetDiskInfo(){
/* First lets get all the watched directories. Then we can group them
* into the same paritions by comparing the partition sizes. */
$musicDirs = MusicDir::getWatchedDirs();
$musicDirs[] = MusicDir::getStorDir();
$musicDirs = Application_Model_MusicDir::getWatchedDirs();
$musicDirs[] = Application_Model_MusicDir::getStorDir();
$partions = array();
@ -218,7 +218,7 @@ class Application_Model_Systemstatus
$status[$arr[0]] = $arr[1];
}
$storDir = MusicDir::getStorDir()->getDirectory();
$storDir = Application_Model_MusicDir::getStorDir()->getDirectory();
$freeSpace = disk_free_space($storDir);
$totalSpace = disk_total_space($storDir);

View File

@ -232,7 +232,7 @@ class User {
$username = $auth->getIdentity()->login;
}
$res = StoredFile::searchFiles($fromTable, $datatables_post);
$res = Application_Model_StoredFile::searchFiles($fromTable, $datatables_post);
// mark record which is for the current user
foreach($res['aaData'] as &$record){

View File

@ -12,18 +12,18 @@ class SchedulerExportTests extends PHPUnit_TestCase {
// Add a file
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
$this->storedFile = StoredFile::Insert($values, false);
$this->storedFile = Application_Model_StoredFile::Insert($values, false);
// Add a file
$values = array("filepath" => dirname(__FILE__)."/test10002.mp3");
$this->storedFile2 = StoredFile::Insert($values, false);
$this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
// Clear the schedule table
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
$CC_DBC->query($sql);
// Create a playlist
$playlist = new Playlist();
$playlist = new Application_Model_Playlist();
$playlist->create("Scheduler Unit Test");
$result = $playlist->addAudioClip($this->storedFile->getId());
$result = $playlist->addAudioClip($this->storedFile2->getId());

View File

@ -16,11 +16,11 @@ class SchedulerTests extends PHPUnit_TestCase {
// Add a file
$values = array("filepath" => dirname(__FILE__)."/test10001.mp3");
$this->storedFile = StoredFile::Insert($values, false);
$this->storedFile = Application_Model_StoredFile::Insert($values, false);
// Add a file
$values = array("filepath" => dirname(__FILE__)."/test10002.mp3");
$this->storedFile2 = StoredFile::Insert($values, false);
$this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
// Clear the schedule table
//$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
@ -59,7 +59,7 @@ class SchedulerTests extends PHPUnit_TestCase {
function testAddAndRemovePlaylist() {
// Create a playlist
$playlist = new Playlist();
$playlist = new Application_Model_Playlist();
$playlist->create("Scheduler Unit Test ".uniqid());
$result = $playlist->addAudioClip($this->storedFile->getId());
$result = $playlist->addAudioClip($this->storedFile2->getId());
@ -84,7 +84,7 @@ class SchedulerTests extends PHPUnit_TestCase {
$this->fail("Did not remove item.");
}
Playlist::Delete($playlist->getId());
Application_Model_Playlist::Delete($playlist->getId());
}
function testIsScheduleEmptyInRange() {

View File

@ -43,7 +43,7 @@ class StoredFileTest extends PHPUnit_TestCase {
// Delete any old data from previous tests
$md5 = md5_file($filePath);
$duplicate = StoredFile::RecallByMd5($md5);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
if ($duplicate) {
$duplicate->delete();
}
@ -51,7 +51,7 @@ class StoredFileTest extends PHPUnit_TestCase {
// Test inserting a file by linking
$values = array("filepath" => $filePath,
"dc:description" => "Unit test ".time());
$storedFile = StoredFile::Insert($values, false);
$storedFile = Application_Model_StoredFile::Insert($values, false);
if (PEAR::isError($storedFile)) {
$this->fail("Failed to create StoredFile: ".$storedFile->getMessage());
return;
@ -64,7 +64,7 @@ class StoredFileTest extends PHPUnit_TestCase {
}
// Test loading metadata
$f = new StoredFile();
$f = new Application_Model_StoredFile();
$f->__setGunid($storedFile->getGunid());
$f->loadMetadata();
if (!is_array($md = $f->getMetadata())) {
@ -74,7 +74,7 @@ class StoredFileTest extends PHPUnit_TestCase {
//var_dump($md);
// Check if the length field has been set.
$f2 = StoredFile::RecallByGunid($storedFile->getGunid());
$f2 = Application_Model_StoredFile::RecallByGunid($storedFile->getGunid());
$m2 = $f2->getMetadata();
if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") {
$this->fail("Length not reporting correctly in metadata.");

View File

@ -24,17 +24,17 @@ $CC_DBC->query($sql);
/*
// Create a playlist
$playlist = new Playlist();
$playlist = new Application_Model_Playlist();
$playlist->create("Calendar Load test playlist ".uniqid());
// Add a file
$values = array("filepath" => __DIR__."/test10001.mp3");
$storedFile = StoredFile::Insert($values, false);
$storedFile = Application_Model_StoredFile::Insert($values, false);
$result = $playlist->addAudioClip($storedFile->getId());
// Add a file
$values = array("filepath" => __DIR__."/test10002.mp3");
$storedFile2 = StoredFile::Insert($values, false);
$storedFile2 = Application_Model_StoredFile::Insert($values, false);
$result = $playlist->addAudioClip($storedFile2->getId());
$result = $playlist->addAudioClip($storedFile2->getId());

View File

@ -16,7 +16,7 @@
</ul>
<?php endif; ?>
</dd>
<dd class="block-display selected-item"><strong>Current Storage Folder:</strong><?php $stor = MusicDir::getStorDir(); echo $stor->getDirectory(); ?></dd>
<dd class="block-display selected-item"><strong>Current Storage Folder:</strong><?php $stor = Application_Model_MusicDir::getStorDir(); echo $stor->getDirectory(); ?></dd>
<dt id="watchedFolder-label" class="block-display">
<label class="required" for="watchedFolder"><?php echo $this->element->getElement('watchedFolder')->getLabel() ?></label>
@ -33,7 +33,7 @@
</ul>
<?php endif; ?>
</dd>
<?php $watched_dirs = MusicDir::getWatchedDirs(); ?>
<?php $watched_dirs = Application_Model_MusicDir::getWatchedDirs(); ?>
<?php if (count($watched_dirs) > 0): ?>
<?php foreach($watched_dirs as $watched_dir): ?>