Added public/private/static modifiers to functions. Changing various function names to be more obvious and consistent. Get rid of unneeded data copying ( = = someFunction()).

This commit is contained in:
paul 2006-11-23 06:59:44 +00:00
parent cb921c1b02
commit 37657536be

View file

@ -1,13 +1,11 @@
<? <?
require_once "Playlist.php"; require_once("Playlist.php");
define('INDCH', ' '); define('INDCH', ' ');
define('AC_URL_RELPATH', '../audioClip/'); define('AC_URL_RELPATH', '../audioClip/');
define('PL_URL_RELPATH', '../playlist/'); define('PL_URL_RELPATH', '../playlist/');
/** /**
* LsPlaylist class
*
* Internal playlist format helper. * Internal playlist format helper.
* *
* @author Tomas Hlava <th@red2head.com> * @author Tomas Hlava <th@red2head.com>
@ -23,53 +21,57 @@ define('PL_URL_RELPATH', '../playlist/');
class LsPlaylist extends Playlist class LsPlaylist extends Playlist
{ {
/** /**
* Create instance of LsPlaylist object and recall existing file * Create instance of LsPlaylist object and recall existing file
* by gunid.<br/> * by gunid.
* *
* @param Greenbox $gb, reference to GreenBox object * @param Greenbox $gb
* @param string $gunid, global unique id * @param string $gunid
* @param string $className, optional classname to recall * global unique id
* @return instance of LsPlaylist object * @param string $className
* optional classname to recall
* @return LsPlaylist
*/ */
function &recallByGunid(&$gb, $gunid, $className='LsPlaylist') public static function &recallByGunid(&$gb, $gunid, $className='LsPlaylist')
{ {
return parent::recallByGunid($gb, $gunid, $className); return parent::recallByGunid($gb, $gunid, $className);
} }
/** /**
* Create instance of LsPlaylist object and recall existing file * Create instance of LsPlaylist object and recall existing file
* by access token.<br/> * by access token.
* *
* @param GreenBox $gb, reference to GreenBox object * @param GreenBox $gb
* @param string $token, access token * @param string $token
* @param string $className, optional classname to recall * access token
* @return instance of LsPlaylist object * @param string $className
* optional classname to recall
* @return LsPlaylist
*/ */
function &recallByToken(&$gb, $token, $className='LsPlaylist') public static function &recallByToken(&$gb, $token, $className='LsPlaylist')
{ {
return parent::recallByToken($gb, $token, $className); return parent::recallByToken($gb, $token, $className);
} }
/** /**
* Export playlist as simplified SMIL XML file * Export playlist as simplified SMIL XML file.
* *
* @param boolean $toString * @param boolean $toString
* if false don't real export, * if false don't real export,
* return misc info about playlist only * return misc info about playlist only
* @return string * @return string
* XML string or hasharray with misc info * XML string or hasharray with misc info
*/ */
function output2Smil($toString=TRUE) public function outputToSmil($toString=TRUE)
{ {
$plGunid = $this->gunid; $plGunid = $this->gunid;
$arr = $r = $this->md->genPhpArray(); $arr = $this->md->genPhpArray();
if (PEAR::isError($r)) { if (PEAR::isError($arr)) {
return $r; return $arr;
} }
if ($toString) { if ($toString) {
$r = LsPlaylistTag::output2Smil($this, $arr); $r = LsPlaylistTag::outputToSmil($this, $arr);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -86,21 +88,23 @@ class LsPlaylist extends Playlist
/** /**
* Export playlist as M3U file * Export playlist as M3U file.
* *
* @param toString boolean, if false don't real export, * @param boolean $toString
* return misc info about playlist only * if false don't real export,
* @return M3U string or hasharray with misc info * return misc info about playlist only
* @return string|array
* M3U string or hasharray with misc info
*/ */
function output2m3u($toString=TRUE) public function outputToM3u($toString=TRUE)
{ {
$plGunid = $this->gunid; $plGunid = $this->gunid;
$arr = $r = $this->md->genPhpArray(); $arr = $this->md->genPhpArray();
if (PEAR::isError($r)) { if (PEAR::isError($arr)) {
return $r; return $arr;
} }
if ($toString) { if ($toString) {
$r = LsPlaylistTag::output2m3u($this, $arr); $r = LsPlaylistTag::outputToM3u($this, $arr);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -126,15 +130,15 @@ class LsPlaylist extends Playlist
* @return mixed * @return mixed
* XML string or hasharray with misc info * XML string or hasharray with misc info
*/ */
function output2RSS($toString=TRUE) public function outputToRss($toString=TRUE)
{ {
$plGunid = $this->gunid; $plGunid = $this->gunid;
$arr = $r = $this->md->genPhpArray(); $arr = $this->md->genPhpArray();
if (PEAR::isError($r)) { if (PEAR::isError($arr)) {
return $r; return $arr;
} }
if ($toString) { if ($toString) {
$r = LsPlaylistTag::output2RSS($this, $arr); $r = LsPlaylistTag::outputToRss($this, $arr);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -165,7 +169,7 @@ class LsPlaylist extends Playlist
*/ */
class LsPlaylistTag class LsPlaylistTag
{ {
function output2Smil(&$pl, $plt, $ind='') public function outputToSmil(&$pl, $plt, $ind='')
{ {
$ind2 = $ind.INDCH; $ind2 = $ind.INDCH;
$ind3 = $ind2.INDCH; $ind3 = $ind2.INDCH;
@ -174,7 +178,7 @@ class LsPlaylistTag
foreach ($plt['children'] as $ple) { foreach ($plt['children'] as $ple) {
switch ($ple['elementname']) { switch ($ple['elementname']) {
case"playlistElement": case"playlistElement":
$r = LsPlaylistElement::output2Smil($pl, $ple, $ind4); $r = LsPlaylistElement::outputToSmil($pl, $ple, $ind4);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -183,7 +187,7 @@ class LsPlaylistTag
} }
break; break;
case"metadata": case"metadata":
$r = LsPlaylistMetadata::output2Smil($pl, $ple, $ind4); $r = LsPlaylistMetadata::outputToSmil($pl, $ple, $ind4);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -206,13 +210,13 @@ class LsPlaylistTag
} }
function output2m3u(&$pl, $plt, $ind='') public function outputToM3u(&$pl, $plt, $ind='')
{ {
$res = ""; $res = "";
foreach ($plt['children'] as $ple) { foreach ($plt['children'] as $ple) {
switch ($ple['elementname']) { switch ($ple['elementname']) {
case"playlistElement": case"playlistElement":
$r = LsPlaylistElement::output2m3u($pl, $ple); $r = LsPlaylistElement::outputToM3u($pl, $ple);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -227,7 +231,7 @@ class LsPlaylistTag
} }
function output2RSS(&$pl, $plt, $ind='') public function outputToRss(&$pl, $plt, $ind='')
{ {
$ind2 = $ind.INDCH; $ind2 = $ind.INDCH;
$ind3 = $ind2.INDCH; $ind3 = $ind2.INDCH;
@ -235,7 +239,7 @@ class LsPlaylistTag
foreach ($plt['children'] as $ple) { foreach ($plt['children'] as $ple) {
switch ($ple['elementname']) { switch ($ple['elementname']) {
case"playlistElement": case"playlistElement":
$r = LsPlaylistElement::output2RSS($pl, $ple, $ind3); $r = LsPlaylistElement::outputToRss($pl, $ple, $ind3);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -244,7 +248,7 @@ class LsPlaylistTag
} }
break; break;
case"metadata": case"metadata":
$r = LsPlaylistMetadata::output2RSS($pl, $ple, $ind3); $r = LsPlaylistMetadata::outputToRss($pl, $ple, $ind3);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -279,7 +283,7 @@ class LsPlaylistTag
class LsPlaylistElement { class LsPlaylistElement {
function output2Smil(&$pl, $ple, $ind='') public function outputToSmil(&$pl, $ple, $ind='')
{ {
$acOrPl = NULL; $acOrPl = NULL;
$finfo = array('fi'=>0, 'fo'=>0); $finfo = array('fi'=>0, 'fo'=>0);
@ -289,7 +293,7 @@ class LsPlaylistElement {
foreach ($ple['children'] as $ac) { foreach ($ple['children'] as $ac) {
switch ($ac['elementname']) { switch ($ac['elementname']) {
case "audioClip": case "audioClip":
$r = LsPlaylistAudioClip::output2Smil($pl, $ac, $ind2); $r = LsPlaylistAudioClip::outputToSmil($pl, $ac, $ind2);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -299,11 +303,11 @@ class LsPlaylistElement {
break; break;
case "playlist": case "playlist":
$gunid = $ac['attrs']['id']; $gunid = $ac['attrs']['id'];
$pl2 = $r = LsPlaylist::recallByGunid($pl->gb, $gunid); $pl2 = LsPlaylist::recallByGunid($pl->gb, $gunid);
if (PEAR::isError($r)) { if (PEAR::isError($pl2)) {
return $r; return $pl2;
} }
$r = $pl2->output2Smil(FALSE); $r = $pl2->outputToSmil(FALSE);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -312,7 +316,7 @@ class LsPlaylistElement {
} }
break; break;
case"fadeInfo": case"fadeInfo":
$r = LsPlaylistFadeInfo::output2Smil($pl, $ac, $ind2); $r = LsPlaylistFadeInfo::outputToSmil($pl, $ac, $ind2);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -322,18 +326,18 @@ class LsPlaylistElement {
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
"LsPlaylistElement::output2Smil:". "LsPlaylistElement::outputToSmil:".
" unknown tag {$ac['elementname']}" " unknown tag {$ac['elementname']}"
); );
} }
} }
$beginS = $pl->_plTimeToSecs($ple['attrs']['relativeOffset']); $beginS = Playlist::playlistTimeToSeconds($ple['attrs']['relativeOffset']);
$playlengthS = $pl->_plTimeToSecs($acOrPl['playlength']); $playlengthS = Playlist::playlistTimeToSeconds($acOrPl['playlength']);
$fadeOutS = $pl->_plTimeToSecs($finfo['fo']); $fadeOutS = Playlist::playlistTimeToSeconds($finfo['fo']);
$fiBeginS = 0; $fiBeginS = 0;
$fiEndS = $pl->_plTimeToSecs($finfo['fi']); $fiEndS = Playlist::playlistTimeToSeconds($finfo['fi']);
$foBeginS = ($playlengthS - $fadeOutS); $foBeginS = ($playlengthS - $fadeOutS);
$foEndS = $pl->_plTimeToSecs($acOrPl['playlength']); $foEndS = Playlist::playlistTimeToSeconds($acOrPl['playlength']);
foreach (array('fi','fo') as $ff) { foreach (array('fi','fo') as $ff) {
if (${$ff."EndS"} - ${$ff."BeginS"} > 0) { if (${$ff."EndS"} - ${$ff."BeginS"} > 0) {
$anim .= "{$ind2}<animate attributeName = \"soundLevel\"\n". $anim .= "{$ind2}<animate attributeName = \"soundLevel\"\n".
@ -356,40 +360,40 @@ class LsPlaylistElement {
} }
function output2m3u(&$pl, $ple, $ind='') public function outputToM3u(&$pl, $ple, $ind='')
{ {
$acOrPl = NULL; $acOrPl = NULL;
foreach ($ple['children'] as $ac) { foreach ($ple['children'] as $ac) {
switch ($ac['elementname']) { switch ($ac['elementname']) {
case "audioClip": case "audioClip":
$r = LsPlaylistAudioClip::output2m3u($pl, $ac); $r = LsPlaylistAudioClip::outputToM3u($pl, $ac);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
if (!is_null($r)) { if (!is_null($r)) {
$acOrPl = $r; $acOrPl = $r;
} }
break; break;
case "playlist": case "playlist":
$gunid = $ac['attrs']['id']; $gunid = $ac['attrs']['id'];
$pl2 = $r = LsPlaylist::recallByGunid($pl->gb, $gunid); $pl2 = LsPlaylist::recallByGunid($pl->gb, $gunid);
if (PEAR::isError($r)) { if (PEAR::isError($pl2)) {
return $r; return $pl2;
} }
$r = $pl2->output2m3u(FALSE); $r = $pl2->outputToM3u(FALSE);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
if (!is_null($r)) { if (!is_null($r)) {
$acOrPl = $r; $acOrPl = $r;
} }
break; break;
} }
} }
if (is_null($acOrPl)) { if (is_null($acOrPl)) {
return ''; return '';
} }
$playlength = ceil($pl->_plTimeToSecs($acOrPl['playlength'])); $playlength = ceil(Playlist::playlistTimeToSeconds($acOrPl['playlength']));
$title = $acOrPl['title']; $title = $acOrPl['title'];
$uri = (isset($acOrPl['uri']) ? $acOrPl['uri'] : '???' ); $uri = (isset($acOrPl['uri']) ? $acOrPl['uri'] : '???' );
$res = "#EXTINF: $playlength, $title\n"; $res = "#EXTINF: $playlength, $title\n";
@ -398,7 +402,7 @@ class LsPlaylistElement {
} }
function output2RSS(&$pl, $ple, $ind='') function outputToRss(&$pl, $ple, $ind='')
{ {
$acOrPl = NULL; $acOrPl = NULL;
$ind2 = $ind.INDCH; $ind2 = $ind.INDCH;
@ -406,33 +410,33 @@ class LsPlaylistElement {
foreach ($ple['children'] as $ac) { foreach ($ple['children'] as $ac) {
switch ($ac['elementname']) { switch ($ac['elementname']) {
case "audioClip": case "audioClip":
$r = LsPlaylistAudioClip::output2RSS($pl, $ac, $ind2); $r = LsPlaylistAudioClip::outputToRss($pl, $ac, $ind2);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
if (!is_null($r)) { if (!is_null($r)) {
$acOrPl = $r; $acOrPl = $r;
} }
break; break;
case"playlist": case "playlist":
$gunid = $ac['attrs']['id']; $gunid = $ac['attrs']['id'];
$pl2 = $r = LsPlaylist::recallByGunid($pl->gb, $gunid); $pl2 = LsPlaylist::recallByGunid($pl->gb, $gunid);
if (PEAR::isError($r)) { if (PEAR::isError($pl2)) {
return $r; return $pl2;
} }
$r = $pl2->output2RSS(FALSE); $r = $pl2->outputToRss(FALSE);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
if (!is_null($r)) { if (!is_null($r)) {
$acOrPl = $r; $acOrPl = $r;
} }
break; break;
case"fadeInfo": case"fadeInfo":
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
"LsPlaylistElement::output2RSS:". "LsPlaylistElement::outputToRss:".
" unknown tag {$ac['elementname']}" " unknown tag {$ac['elementname']}"
); );
} }
@ -464,16 +468,16 @@ class LsPlaylistElement {
class LsPlaylistAudioClip class LsPlaylistAudioClip
{ {
function output2Smil(&$pl, $plac, $ind='') public function outputToSmil(&$pl, $plac, $ind='')
{ {
$gunid = $plac['attrs']['id']; $gunid = $plac['attrs']['id'];
$ac = $r = StoredFile::recallByGunid($pl->gb, $gunid); $ac = StoredFile::recallByGunid($pl->gb, $gunid);
if (PEAR::isError($r)) { if (PEAR::isError($ac)) {
return $r; return $ac;
} }
$RADext = $r =$ac->_getExt(); $RADext = $ac->_getExt();
if (PEAR::isError($r)) { if (PEAR::isError($RADext)) {
return $r; return $RADext;
} }
return array( return array(
'type' => 'audioclip', 'type' => 'audioclip',
@ -484,16 +488,16 @@ class LsPlaylistAudioClip
} }
function output2m3u(&$pl, $plac, $ind='') public function outputToM3u(&$pl, $plac, $ind='')
{ {
$gunid = $plac['attrs']['id']; $gunid = $plac['attrs']['id'];
$ac = $r = StoredFile::recallByGunid($pl->gb, $gunid); $ac = StoredFile::recallByGunid($pl->gb, $gunid);
if (PEAR::isError($r)) { if (PEAR::isError($ac)) {
return $r; return $ac;
} }
$RADext = $r =$ac->_getExt(); $RADext = $ac->_getExt();
if (PEAR::isError($r)) { if (PEAR::isError($RADext)) {
return $r; return $RADext;
} }
return array( return array(
'playlength' => $plac['attrs']['playlength'], 'playlength' => $plac['attrs']['playlength'],
@ -503,16 +507,16 @@ class LsPlaylistAudioClip
} }
function output2RSS(&$pl, $plac, $ind='') public function outputToRss(&$pl, $plac, $ind='')
{ {
$gunid = $plac['attrs']['id']; $gunid = $plac['attrs']['id'];
$ac = $r = StoredFile::recallByGunid($pl->gb, $gunid); $ac = StoredFile::recallByGunid($pl->gb, $gunid);
if (PEAR::isError($r)) { if (PEAR::isError($ac)) {
return $r; return $ac;
} }
$RADext = $r =$ac->_getExt(); $RADext = $ac->_getExt();
if (PEAR::isError($r)) { if (PEAR::isError($RADext)) {
return $r; return $RADext;
} }
$title = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:title'); $title = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:title');
$desc = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:description'); $desc = $pl->gb->bsGetMetadataValue($ac->getId(), 'dc:description');
@ -541,7 +545,7 @@ class LsPlaylistAudioClip
class LsPLaylistFadeInfo class LsPLaylistFadeInfo
{ {
function output2Smil(&$pl, $plfi, $ind='') public function outputToSmil(&$pl, $plfi, $ind='')
{ {
$r = array( $r = array(
'fi'=>$plfi['attrs']['fadeIn'], 'fi'=>$plfi['attrs']['fadeIn'],
@ -551,13 +555,13 @@ class LsPLaylistFadeInfo
} }
function output2m3u(&$pl, $plfa, $ind='') public function outputToM3u(&$pl, $plfa, $ind='')
{ {
return ''; return '';
} }
function output2RSS(&$pl, $plfa, $ind='') public function outputToRss(&$pl, $plfa, $ind='')
{ {
return ''; return '';
} }
@ -575,21 +579,21 @@ class LsPLaylistFadeInfo
* @link http://www.campware.org * @link http://www.campware.org
* @todo Rename this class to PlaylistMetadata (notice the caps) * @todo Rename this class to PlaylistMetadata (notice the caps)
*/ */
class LsPLaylistMetadata class LsPlaylistMetadata
{ {
function output2Smil(&$pl, $md, $ind='') public function outputToSmil(&$pl, $md, $ind='')
{ {
return NULL; return NULL;
} }
function output2m3u(&$pl, $md, $ind='') public function outputToM3u(&$pl, $md, $ind='')
{ {
return NULL; return NULL;
} }
function output2RSS(&$pl, $md, $ind='') public function outputToRss(&$pl, $md, $ind='')
{ {
return NULL; return NULL;
} }