From f4a86d96c616c3c965fc47b08a4681c7faa7724e Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 5 Mar 2011 21:58:36 -0500 Subject: [PATCH 1/6] -fix for missing GreenBox.php file --- install/airtime-install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/airtime-install.php b/install/airtime-install.php index 700b88d5d..885c2d36a 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -18,7 +18,7 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) { createAPIKey(); require_once(dirname(__FILE__).'/../application/configs/conf.php'); -require_once(dirname(__FILE__).'/../application/models/GreenBox.php'); +//require_once(dirname(__FILE__).'/../application/models/GreenBox.php'); require_once(dirname(__FILE__).'/installInit.php'); From e16dd6c486eb9f0baf16c66e296ec3076e73d230 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 6 Mar 2011 00:08:02 -0500 Subject: [PATCH 2/6] early implementation of CC-1962 --- .../controllers/ScheduleController.php | 6 +-- application/models/Schedule.php | 43 ++++++++++++++++--- application/models/Shows.php | 23 +++++++--- application/models/StoredFile.php | 2 +- .../schedule/schedule-show-dialog.phtml | 1 + public/js/airtime/schedule/schedule.js | 9 ++++ public/js/playlist/nowplayingdatagrid.js | 2 +- pypo/scripts/lib.liq | 12 ++++-- 8 files changed, 78 insertions(+), 20 deletions(-) diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index 2a071ec78..e589f7fe9 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -188,7 +188,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->showContent = $show->getShowContent(); $this->view->timeFilled = $show->getTimeScheduled(); - $this->view->percentFilled = $show->getPercentScheduledInRange(); + $this->view->percentFilled = $show->getPercentScheduled(); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); unset($this->view->showContent); @@ -237,7 +237,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->showContent = $show->getShowContent(); $this->view->timeFilled = $show->getTimeScheduled(); - $this->view->percentFilled = $show->getPercentScheduledInRange(); + $this->view->percentFilled = $show->getPercentScheduled(); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); unset($this->view->showContent); } @@ -268,7 +268,7 @@ class ScheduleController extends Zend_Controller_Action $this->view->timeFilled = $show->getTimeScheduled(); $this->view->showName = $show->getName(); $this->view->showLength = $show->getShowLength(); - $this->view->percentFilled = $show->getPercentScheduledInRange(); + $this->view->percentFilled = $show->getPercentScheduled(); $this->view->s_wday = $dateInfo_s['weekday']; $this->view->s_month = $dateInfo_s['month']; diff --git a/application/models/Schedule.php b/application/models/Schedule.php index f515327e1..ad8d24d3a 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -278,12 +278,11 @@ class Schedule { return ($count == '0'); } - public static function getTimeUnScheduledInRange($s_datetime, $e_datetime) { + public static function getTimeUnScheduledInRange($instance_id, $s_datetime, $e_datetime) { global $CC_CONFIG, $CC_DBC; - $sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." - WHERE (starts >= '{$s_datetime}') - AND (ends <= '{$e_datetime}')"; + $sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]" + ." WHERE instance_id = $instance_id"; $time = $CC_DBC->GetOne($sql); @@ -313,6 +312,20 @@ class Schedule { return $res; } + + public static function GetTotalShowTime($instance_id) { + global $CC_CONFIG, $CC_DBC; + + $sql = "SELECT SUM(clip_length) FROM $CC_CONFIG[scheduleTable]" + ." WHERE instance_id = $instance_id"; + + $res = $CC_DBC->GetOne($sql); + + if(is_null($res)) + return 0; + + return $res; + } public static function getPercentScheduledInRange($s_datetime, $e_datetime) { @@ -337,6 +350,25 @@ class Schedule { return $percent; } + public static function GetPercentScheduled($instance_id, $s_datetime, $e_datetime){ + $time = Schedule::GetTotalShowTime($instance_id); + + $s_epoch = strtotime($s_datetime); + $e_epoch = strtotime($e_datetime); + + $con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME); + $sql = "SELECT EXTRACT(EPOCH FROM INTERVAL '{$time}')"; + $r = $con->query($sql); + $i_epoch = $r->fetchColumn(0); + + $percent = ceil(($i_epoch / ($e_epoch - $s_epoch)) * 100); + + if ($percent > 100) + $percent = 100; + + return $percent; + } + /** * Return TRUE if file is going to be played in the future. @@ -490,7 +522,8 @@ class Schedule { ." WHERE st.playlist_id = pt.id" ." AND st.file_id = ft.id" ." AND st.instance_id = si.id" - ." AND si.show_id = show.id"; + ." AND si.show_id = show.id" + ." AND st.starts < si.ends"; if ($timePeriod < 0){ $sql .= " AND st.ends < TIMESTAMP '$timeStamp'" diff --git a/application/models/Shows.php b/application/models/Shows.php index 12fa1411b..993c5e84f 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -456,6 +456,10 @@ class ShowInstance { return $showInstance->getDbShowId(); } + public function getShowInstanceId() { + return $this->_instanceId; + } + public function getName() { $show = CcShowQuery::create()->findPK($this->getShowId()); return $show->getDbName(); @@ -635,11 +639,8 @@ class ShowInstance { } public function getTimeScheduled() { - - $start_timestamp = $this->getShowStart(); - $end_timestamp = $this->getShowEnd(); - - $time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp); + $instance_id = $this->getShowInstanceId(); + $time = Schedule::GetTotalShowTime($instance_id); return $time; } @@ -648,8 +649,9 @@ class ShowInstance { $start_timestamp = $this->getShowStart(); $end_timestamp = $this->getShowEnd(); + $instance_id = $this->getShowInstanceId(); - $time = Schedule::getTimeUnScheduledInRange($start_timestamp, $end_timestamp); + $time = Schedule::getTimeUnScheduledInRange($instance_id, $start_timestamp, $end_timestamp); return $time; } @@ -662,6 +664,14 @@ class ShowInstance { return Schedule::getPercentScheduledInRange($start_timestamp, $end_timestamp); } + public function getPercentScheduled(){ + $start_timestamp = $this->getShowStart(); + $end_timestamp = $this->getShowEnd(); + $instance_id = $this->getShowInstanceId(); + + return Schedule::GetPercentScheduled($instance_id, $start_timestamp, $end_timestamp); + } + public function getShowLength(){ global $CC_DBC; @@ -794,6 +804,7 @@ class Show_DAL{ ." WHERE ((si.starts < TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends > TIMESTAMP '$timeNow' - INTERVAL '$start seconds')" ." OR (si.starts > TIMESTAMP '$timeNow' - INTERVAL '$start seconds' AND si.ends < TIMESTAMP '$timeNow' + INTERVAL '$end seconds')" ." OR (si.starts < TIMESTAMP '$timeNow' + INTERVAL '$end seconds' AND si.ends > TIMESTAMP '$timeNow' + INTERVAL '$end seconds'))" + ." AND (st.starts < si.ends)" ." ORDER BY st.starts"; return $CC_DBC->GetAll($sql); diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index 72e96dbea..95f7f51ae 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -1671,7 +1671,7 @@ class StoredFile { $fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id"; - $datatables["optWhere"][] = "plt.length <= INTERVAL '{$p_length}'"; + $datatables["optWhere"][] = "INTERVAL '{$p_length}' > INTERVAL '00:00:00'"; $datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'"; return StoredFile::searchFiles($fromTable, $datatables); diff --git a/application/views/scripts/schedule/schedule-show-dialog.phtml b/application/views/scripts/schedule/schedule-show-dialog.phtml index c10038bfd..c0a28a984 100644 --- a/application/views/scripts/schedule/schedule-show-dialog.phtml +++ b/application/views/scripts/schedule/schedule-show-dialog.phtml @@ -28,6 +28,7 @@
showLength; ?> +
diff --git a/public/js/airtime/schedule/schedule.js b/public/js/airtime/schedule/schedule.js index 99e5fadf1..5fb842593 100644 --- a/public/js/airtime/schedule/schedule.js +++ b/public/js/airtime/schedule/schedule.js @@ -22,6 +22,15 @@ function setScheduleDialogHtml(json) { $("#show_time_filled").empty().append(json.timeFilled); $("#show_progressbar").progressbar( "value" , json.percentFilled ); + + var showFilled = $("#show_time_filled").text().split('.')[0]; + var showLength = $("#show_length").text(); + + if (showFilled > showLength){ + $("#show_time_warning").text("Shows longer than their scheduled time will be cut off by a following show."); + } else { + $("#show_time_warning").empty(); + } } function setScheduleDialogEvents(dialog) { diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index 97313278c..b1ca520be 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -60,7 +60,7 @@ var columns = [{"sTitle": "type", "bVisible":false}, {"sTitle":"Album"}, {"sTitle":"Playlist"}, {"sTitle":"Show"}, - {"sTitle":"instance_id", "bVisible":true}]; + {"sTitle":"instance_id", "bVisible":false}]; function getDateString(){ var date0 = $("#datepicker").datepicker("getDate"); diff --git a/pypo/scripts/lib.liq b/pypo/scripts/lib.liq index 68fd55459..384287056 100644 --- a/pypo/scripts/lib.liq +++ b/pypo/scripts/lib.liq @@ -39,10 +39,14 @@ end # by default def add_skip_command(s) # A command to skip - def skip(_) - source.skip(s) - "Done!" - end + def skip(_) + l = list.hd(server.execute("queue.queue")) + l = string.split(separator=" ",l) + list.iter(fun (rid) -> ignore(server.execute(queue.ignore #{rid}")), l) + + source.skip(s) + "Done!" + end # Register the command: server.register(namespace="source", usage="skip", From c2903c4198349bb510c274d7ac9b2fcf08f098e2 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 6 Mar 2011 00:16:31 -0500 Subject: [PATCH 3/6] -updated now playing view to show only only currently playing item. --- application/models/Nowplaying.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/models/Nowplaying.php b/application/models/Nowplaying.php index 563dada04..5602945f6 100644 --- a/application/models/Nowplaying.php +++ b/application/models/Nowplaying.php @@ -75,7 +75,8 @@ class Application_Model_Nowplaying $type = "b"; } else if (strtotime($item['item_ends']) < strtotime($timeNow)){ $type = "p"; - } else if (strtotime($item['item_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['item_ends'])){ + } else if (strtotime($item['item_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['item_ends']) + && strtotime($item['show_starts']) < strtotime($timeNow) && strtotime($timeNow) < strtotime($item['show_ends'])){ $type = "c"; } else { $type = "n"; From 95a4694b5acbba43cc8bf428660317c4236b2c07 Mon Sep 17 00:00:00 2001 From: "paul.baranowski" Date: Sun, 6 Mar 2011 11:05:12 -0500 Subject: [PATCH 4/6] Created a new Metadata class to hold static functions which parse audio file metadata. This got rid of the "camp_" prefixes on the function names. --- .../controllers/PluploadController.php | 4 +- application/models/StoredFile.php | 520 +++++++++--------- application/models/tests/StoredFileTests.php | 2 +- 3 files changed, 255 insertions(+), 271 deletions(-) diff --git a/application/controllers/PluploadController.php b/application/controllers/PluploadController.php index 830590487..c9f6967c0 100644 --- a/application/controllers/PluploadController.php +++ b/application/controllers/PluploadController.php @@ -124,7 +124,7 @@ class PluploadController extends Zend_Controller_Action } } - $metadata = camp_get_audio_metadata($audio_file); + $metadata = Metadata::LoadFromFile($audio_file); if (PEAR::isError($metadata)) { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $metadata->getMessage() + '}}'); @@ -160,7 +160,7 @@ class PluploadController extends Zend_Controller_Action } public function pluploadAction() - { + { $this->view->headScript()->appendFile('/js/plupload/plupload.full.min.js','text/javascript'); $this->view->headScript()->appendFile('/js/plupload/jquery.plupload.queue.min.js','text/javascript'); $this->view->headScript()->appendFile('/js/airtime/library/plupload.js','text/javascript'); diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index 72e96dbea..a93217cae 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -52,261 +52,263 @@ $g_metadata_xml_to_db_mapping = array( "dc:contributor" => "contributor", "dc:language" => "language"); -/** - * Track numbers in metadata tags can come in many formats: - * "1 of 20", "1/20", "20/1". This function parses the track - * number and gets the real number so that we can sort by it - * in the database. - * - * @param string $p_trackNumber - * @return int - */ -function camp_parse_track_number($p_trackNumber) -{ - $num = trim($p_trackNumber); - if (!is_numeric($num)) { - $matches = preg_match("/\s*([0-9]+)([^0-9]*)([0-9]*)\s*/", $num, $results); - $trackNum = 0; - foreach ($results as $result) { - if (is_numeric($result)) { - if ($trackNum == 0) { - $trackNum = $result; - } elseif ($result < $trackNum) { - $trackNum = $result; - } - } - } - } else { - $trackNum = $num; - } - return $trackNum; -} +class Metadata { - -/** - * Add data to the global array $mdata, also sets global variables - * $titleHaveSet and $titleKey. - * - * Converts the given string ($val) into UTF-8. - * - * @param array $p_mdata - * The array to add the metadata to. - * @param string $p_key - * Metadata key. - * @param string $p_val - * Metadata value. - * @param string $p_inputEncoding - * Encoding type of the input value. - */ -function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859-1') -{ - if (!is_null($p_val)) { - $data = $p_val; - $outputEncoding = 'UTF-8'; - //if (function_exists('iconv') && ($p_inputEncoding != $outputEncoding) ) { - if (function_exists('iconv') && is_string($p_val)) { - $newData = @iconv($p_inputEncoding, $outputEncoding, $data); - if ($newData === FALSE) { - echo "Warning: convert $key data to unicode failed\n"; - } elseif ($newData != $data) { - echo "Converted string: '$data' (".gettype($data).") -> '$newData' (".gettype($newData).").\n"; - $data = $newData; - } - } - $p_mdata[$p_key] = trim($data); - } -} - - -/** - * Return an array with the given audio file's ID3 tags. The keys in the - * array can be: - *
- * 		dc:format ("mime type")
- * 		dcterms:extent ("duration")
- * 		dc:title
- * 		dc:creator ("artist")
- * 		dc:source ("album")
- *      dc:type ("genre")
- * 		ls:bitrate
- * 		ls:encoded_by
- * 		ls:track_num
- * 		ls:channels
- * 		ls:year
- * 		ls:filename
- * 
- * - * @param string $p_filename - * @param boolean $p_testonly - * For diagnostic and debugging purposes - setting this to TRUE - * will print out the values found in the file and the ones assigned - * to the return array. - * @return array|PEAR_Error - */ -function camp_get_audio_metadata($p_filename, $p_testonly = false) -{ - $getID3 = new getID3(); - $infoFromFile = $getID3->analyze($p_filename); - if (PEAR::isError($infoFromFile)) { - return $infoFromFile; - } - if (isset($infoFromFile['error'])) { - return new PEAR_Error(array_pop($infoFromFile['error'])); - } - if (!$infoFromFile['bitrate']) { - return new PEAR_Error("File given is not an audio file."); - } - - if ($p_testonly) { - print_r($infoFromFile); - } - $titleKey = 'dc:title'; - $flds = array( - 'dc:format' => array( - array('path'=>"['mime_type']", 'ignoreEnc'=>TRUE), - ), - 'ls:bitrate' => array( - array('path'=>"['bitrate']", 'ignoreEnc'=>TRUE), - array('path'=>"['audio']['bitrate']", 'ignoreEnc'=>TRUE), - ), - 'ls:samplerate' => array( - array('path'=>"['audio']['sample_rate']", 'ignoreEnc'=>TRUE), - ), - 'ls:encoder' => array( - array('path'=>"['audio']['codec']", 'ignoreEnc'=>TRUE), - ), - 'dcterms:extent'=> array( - array('path'=>"['playtime_seconds']", 'ignoreEnc'=>TRUE), - ), - 'ls:composer'=> array( - array('path'=>"['id3v2']['comments']['composer']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - array('path'=>"['id3v2']['TCOM'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['id3v2']['composer']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - array('path'=>"['ogg']['comments']['composer']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['composer']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'dc:description'=> array( - array('path'=>"['id3v1']['comments']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['comments']['comments']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - array('path'=>"['id3v2']['COMM'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['id3v2']['comments']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - array('path'=>"['ogg']['comments']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'dc:type'=> array( - array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'dc:title' => array( - array('path'=>"['id3v2']['comments']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TIT2'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TT2'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v1']", 'dataPath'=>"['title']", 'encPath'=>"['encoding']"), - array('path'=>"['ogg']['comments']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'dc:creator' => array( - array('path'=>"['id3v2']['comments']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TPE1'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TP1'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v1']", 'dataPath'=>"['artist']", 'encPath'=>"['encoding']"), - array('path'=>"['ogg']['comments']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'dc:source' => array( - array('path'=>"['id3v2']['comments']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TALB'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TAL'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['ogg']['comments']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'ls:encoded_by' => array( - array('path'=>"['id3v2']['TENC'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TEN'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['ogg']['comments']['encoded-by']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['encoded-by']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'ls:track_num' => array( - array('path'=>"['id3v2']['TRCK'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['id3v2']['TRK'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - array('path'=>"['ogg']['comments']['tracknumber']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['tracknumber']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - // 'ls:genre' => array( - // array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), - // array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), - // array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), - // array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - // array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - // ), - 'ls:channels' => array( - array('path'=>"['audio']['channels']", 'ignoreEnc'=>TRUE), - ), - 'ls:year' => array( - array('path'=>"['comments']['date']"), - array('path'=>"['ogg']['comments']['date']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - array('path'=>"['tags']['vorbiscomment']['date']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), - ), - 'ls:filename' => array( - array('path'=>"['filename']"), - ), - ); - $mdata = array(); - if (isset($infoFromFile['audio'])) { - $mdata['audio'] = $infoFromFile['audio']; - } - if (isset($infoFromFile['playtime_seconds'])) { - $mdata['playtime_seconds'] = $infoFromFile['playtime_seconds']; - } - - $titleHaveSet = FALSE; - foreach ($flds as $key => $getid3keys) { - foreach ($getid3keys as $getid3key) { - $path = $getid3key["path"]; - $ignoreEnc = isset($getid3key["ignoreEnc"])? - $getid3key["ignoreEnc"]:FALSE; - $dataPath = isset($getid3key["dataPath"])?$getid3key["dataPath"]:""; - $encPath = isset($getid3key["encPath"])?$getid3key["encPath"]:""; - $enc = "UTF-8"; - - $tagElement = "\$infoFromFile$path$dataPath"; - eval("\$tagExists = isset($tagElement);"); - if ($tagExists) { - //echo "ignore encoding: ".($ignoreEnc?"yes":"no")."\n"; - //echo "tag exists\n"; - //echo "encode path: $encPath\n"; - eval("\$data = $tagElement;"); - if (!$ignoreEnc && $encPath != "") { - $encodedElement = "\$infoFromFile$path$encPath"; - eval("\$encodedElementExists = isset($encodedElement);"); - if ($encodedElementExists) { - eval("\$enc = $encodedElement;"); + /** + * Track numbers in metadata tags can come in many formats: + * "1 of 20", "1/20", "20/1". This function parses the track + * number and gets the real number so that we can sort by it + * in the database. + * + * @param string $p_trackNumber + * @return int + */ + public static function ParseTrackNumber($p_trackNumber) + { + $num = trim($p_trackNumber); + if (!is_numeric($num)) { + $matches = preg_match("/\s*([0-9]+)([^0-9]*)([0-9]*)\s*/", $num, $results); + $trackNum = 0; + foreach ($results as $result) { + if (is_numeric($result)) { + if ($trackNum == 0) { + $trackNum = $result; + } elseif ($result < $trackNum) { + $trackNum = $result; } } - - // Special case handling for track number - if ($key == "ls:track_num") { - $data = camp_parse_track_number($data); - } - camp_add_metadata($mdata, $key, $data, $enc); - if ($key == $titleKey) { - $titleHaveSet = TRUE; - } - break; } + } else { + $trackNum = $num; + } + return $trackNum; + } + + + /** + * Add data to the array $p_mdata. + * + * Converts the given string ($val) into UTF-8. + * + * @param array $p_mdata + * The array to add the metadata to. + * @param string $p_key + * Metadata key. + * @param string $p_val + * Metadata value. + * @param string $p_inputEncoding + * Encoding type of the input value. + */ + public static function AddToArray(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859-1') + { + if (!is_null($p_val)) { + $data = $p_val; + $outputEncoding = 'UTF-8'; + //if (function_exists('iconv') && ($p_inputEncoding != $outputEncoding) ) { + if (function_exists('iconv') && is_string($p_val)) { + $newData = @iconv($p_inputEncoding, $outputEncoding, $data); + if ($newData === FALSE) { + echo "Warning: convert $key data to unicode failed\n"; + } elseif ($newData != $data) { + echo "Converted string: '$data' (".gettype($data).") -> '$newData' (".gettype($newData).").\n"; + $data = $newData; + } + } + $p_mdata[$p_key] = trim($data); } } - if ($p_testonly) { - var_dump($mdata); - } - if (!$titleHaveSet || trim($mdata[$titleKey]) == '') { - camp_add_metadata($mdata, $titleKey, basename($p_filename)); + + /** + * Return an array with the given audio file's ID3 tags. The keys in the + * array can be: + *
+     * 		dc:format ("mime type")
+     * 		dcterms:extent ("duration")
+     * 		dc:title
+     * 		dc:creator ("artist")
+     * 		dc:source ("album")
+     *      dc:type ("genre")
+     * 		ls:bitrate
+     * 		ls:encoded_by
+     * 		ls:track_num
+     * 		ls:channels
+     * 		ls:year
+     * 		ls:filename
+     * 
+ * + * @param string $p_filename + * @param boolean $p_testonly + * For diagnostic and debugging purposes - setting this to TRUE + * will print out the values found in the file and the ones assigned + * to the return array. + * @return array|PEAR_Error + */ + public static function LoadFromFile($p_filename, $p_testonly = false) + { + $getID3 = new getID3(); + $infoFromFile = $getID3->analyze($p_filename); + if (PEAR::isError($infoFromFile)) { + return $infoFromFile; + } + if (isset($infoFromFile['error'])) { + return new PEAR_Error(array_pop($infoFromFile['error'])); + } + if (!$infoFromFile['bitrate']) { + return new PEAR_Error("File given is not an audio file."); + } + + if ($p_testonly) { + print_r($infoFromFile); + } + $titleKey = 'dc:title'; + $flds = array( + 'dc:format' => array( + array('path'=>"['mime_type']", 'ignoreEnc'=>TRUE), + ), + 'ls:bitrate' => array( + array('path'=>"['bitrate']", 'ignoreEnc'=>TRUE), + array('path'=>"['audio']['bitrate']", 'ignoreEnc'=>TRUE), + ), + 'ls:samplerate' => array( + array('path'=>"['audio']['sample_rate']", 'ignoreEnc'=>TRUE), + ), + 'ls:encoder' => array( + array('path'=>"['audio']['codec']", 'ignoreEnc'=>TRUE), + ), + 'dcterms:extent'=> array( + array('path'=>"['playtime_seconds']", 'ignoreEnc'=>TRUE), + ), + 'ls:composer'=> array( + array('path'=>"['id3v2']['comments']['composer']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['id3v2']['TCOM'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['id3v2']['composer']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['ogg']['comments']['composer']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['composer']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:description'=> array( + array('path'=>"['id3v1']['comments']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['comments']['comments']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['id3v2']['COMM'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['id3v2']['comments']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['ogg']['comments']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['comment']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:type'=> array( + array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:title' => array( + array('path'=>"['id3v2']['comments']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TIT2'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TT2'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v1']", 'dataPath'=>"['title']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['title']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:creator' => array( + array('path'=>"['id3v2']['comments']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TPE1'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TP1'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v1']", 'dataPath'=>"['artist']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['artist']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'dc:source' => array( + array('path'=>"['id3v2']['comments']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TALB'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TAL'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['album']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'ls:encoded_by' => array( + array('path'=>"['id3v2']['TENC'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TEN'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['encoded-by']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['encoded-by']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'ls:track_num' => array( + array('path'=>"['id3v2']['TRCK'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['id3v2']['TRK'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + array('path'=>"['ogg']['comments']['tracknumber']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['tracknumber']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + // 'ls:genre' => array( + // array('path'=>"['id3v1']", 'dataPath'=>"['genre']", 'encPath'=>"['encoding']"), + // array('path'=>"['id3v2']['TCON'][0]", 'dataPath'=>"['data']", 'encPath'=>"['encoding']"), + // array('path'=>"['id3v2']['comments']['content_type']", 'dataPath'=>"[0]", 'ignoreEnc'=>TRUE), + // array('path'=>"['ogg']['comments']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + // array('path'=>"['tags']['vorbiscomment']['genre']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + // ), + 'ls:channels' => array( + array('path'=>"['audio']['channels']", 'ignoreEnc'=>TRUE), + ), + 'ls:year' => array( + array('path'=>"['comments']['date']"), + array('path'=>"['ogg']['comments']['date']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + array('path'=>"['tags']['vorbiscomment']['date']", 'dataPath'=>"[0]", 'encPath'=>"['encoding']"), + ), + 'ls:filename' => array( + array('path'=>"['filename']"), + ), + ); + $mdata = array(); + if (isset($infoFromFile['audio'])) { + $mdata['audio'] = $infoFromFile['audio']; + } + if (isset($infoFromFile['playtime_seconds'])) { + $mdata['playtime_seconds'] = $infoFromFile['playtime_seconds']; + } + + $titleHaveSet = FALSE; + foreach ($flds as $key => $getid3keys) { + foreach ($getid3keys as $getid3key) { + $path = $getid3key["path"]; + $ignoreEnc = isset($getid3key["ignoreEnc"])? + $getid3key["ignoreEnc"]:FALSE; + $dataPath = isset($getid3key["dataPath"])?$getid3key["dataPath"]:""; + $encPath = isset($getid3key["encPath"])?$getid3key["encPath"]:""; + $enc = "UTF-8"; + + $tagElement = "\$infoFromFile$path$dataPath"; + eval("\$tagExists = isset($tagElement);"); + if ($tagExists) { + //echo "ignore encoding: ".($ignoreEnc?"yes":"no")."\n"; + //echo "tag exists\n"; + //echo "encode path: $encPath\n"; + eval("\$data = $tagElement;"); + if (!$ignoreEnc && $encPath != "") { + $encodedElement = "\$infoFromFile$path$encPath"; + eval("\$encodedElementExists = isset($encodedElement);"); + if ($encodedElementExists) { + eval("\$enc = $encodedElement;"); + } + } + + // Special case handling for track number + if ($key == "ls:track_num") { + $data = Metadata::ParseTrackNumber($data); + } + Metadata::AddToArray($mdata, $key, $data, $enc); + if ($key == $titleKey) { + $titleHaveSet = TRUE; + } + break; + } + } + } + if ($p_testonly) { + var_dump($mdata); + } + + if (!$titleHaveSet || trim($mdata[$titleKey]) == '') { + Metadata::AddToArray($mdata, $titleKey, basename($p_filename)); + } + return $mdata; } - return $mdata; } @@ -316,7 +318,7 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false) * Airtime file storage support class.
* Represents one virtual file in storage. Virtual file has up to two parts: *
    - *
  • metadata in database - represented by MetaData class
  • + *
  • metadata in database
  • *
  • binary media data in real file
  • *
* @@ -607,7 +609,7 @@ class StoredFile { if (isset($p_values["metadata"])) { $metadata = $p_values['metadata']; } else { - $metadata = camp_get_audio_metadata($p_values["filepath"]); + $metadata = Metadata::LoadFromFile($p_values["filepath"]); } $storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $p_values["filepath"]; @@ -906,24 +908,6 @@ class StoredFile { } - /** - * Analyze file with getid3 module.
- * Obtain some metadata stored in media file.
- * This method should be used for prefilling metadata input form. - * - * @return array - * hierarchical hasharray with information about media file - */ - public function analyzeFile() - { - if (!$this->exists) { - return FALSE; - } - $ia = camp_get_audio_metadata($this->filepath); - return $ia; - } - - /** * Create instance of StoredFile object and make copy of existing file * @@ -1511,7 +1495,7 @@ class StoredFile { */ public function getMime() { - $a = $this->analyzeFile(); + $a = Metadata::LoadFromFile($this->filepath); if (PEAR::isError($a)) { return $a; } diff --git a/application/models/tests/StoredFileTests.php b/application/models/tests/StoredFileTests.php index 7061e2b5f..8ee3bea13 100644 --- a/application/models/tests/StoredFileTests.php +++ b/application/models/tests/StoredFileTests.php @@ -20,7 +20,7 @@ class StoredFileTest extends PHPUnit_TestCase { function testGetAudioMetadata() { $filePath = dirname(__FILE__)."/ex1.mp3"; - $metadata = camp_get_audio_metadata($filePath); + $metadata = Metadata::LoadFromFile($filePath); if (PEAR::isError($metadata)) { $this->fail($metadata->getMessage()); return; From e6c6365591711120827e6d6ef95b51eaec19fb2e Mon Sep 17 00:00:00 2001 From: "paul.baranowski" Date: Sun, 6 Mar 2011 11:35:10 -0500 Subject: [PATCH 5/6] Got rid of global variable $g_metadata_xml_to_db_mapping, put the mapping inside of the Metadata class. --- application/models/BasicStor.php | 3 +- application/models/StoredFile.php | 200 +++++++++--------------------- 2 files changed, 61 insertions(+), 142 deletions(-) diff --git a/application/models/BasicStor.php b/application/models/BasicStor.php index e9a93ca04..6bc484131 100644 --- a/application/models/BasicStor.php +++ b/application/models/BasicStor.php @@ -443,11 +443,10 @@ class BasicStor { //"dc:creator" => "artist_name", //dc:description - global $g_metadata_xml_to_db_mapping; $plSelect = "SELECT "; $fileSelect = "SELECT "; $_SESSION["br"] = ""; - foreach ($g_metadata_xml_to_db_mapping as $key => $val){ + foreach (Metadata::GetMapMetadataXmlToDb() as $key => $val){ $_SESSION["br"] .= "key: ".$key." value:".$val.", "; if($key === "dc:title"){ $plSelect .= "name AS ".$val.", "; diff --git a/application/models/StoredFile.php b/application/models/StoredFile.php index 8db111b01..69e1b2ddb 100644 --- a/application/models/StoredFile.php +++ b/application/models/StoredFile.php @@ -4,56 +4,59 @@ require_once(dirname(__FILE__)."/../../library/getid3/var/getid3.php"); require_once("BasicStor.php"); require_once("Schedule.php"); -global $g_metadata_xml_to_db_mapping; -$g_metadata_xml_to_db_mapping = array( - "ls:type" => "ftype", - "dc:format" => "format", - "ls:bitrate" => "bit_rate", - "ls:samplerate" => "sample_rate", - "dcterms:extent" => "length", - "dc:title" => "track_title", - "dc:description" => "comments", - "dc:type" => "genre", - "dc:creator" => "artist_name", - "dc:source" => "album_title", - "ls:channels" => "channels", - "ls:filename" => "name", - "ls:year" => "year", - "ls:url" => "url", - "ls:track_num" => "track_number", - "ls:mood" => "mood", - "ls:bpm" => "bpm", - "ls:disc_num" => "disc_number", - "ls:rating" => "rating", - "ls:encoded_by" => "encoded_by", - "dc:publisher" => "label", - "ls:composer" => "composer", - "ls:encoder" => "encoder", - "ls:crc" => "checksum", - "ls:lyrics" => "lyrics", - "ls:orchestra" => "orchestra", - "ls:conductor" => "conductor", - "ls:lyricist" => "lyricist", - "ls:originallyricist" => "original_lyricist", - "ls:radiostationname" => "radio_station_name", - "ls:audiofileinfourl" => "info_url", - "ls:artisturl" => "artist_url", - "ls:audiosourceurl" => "audio_source_url", - "ls:radiostationurl" => "radio_station_url", - "ls:buycdurl" => "buy_this_url", - "ls:isrcnumber" => "isrc_number", - "ls:catalognumber" => "catalog_number", - "ls:originalartist" => "original_artist", - "dc:rights" => "copyright", - "dcterms:temporal" => "report_datetime", - "dcterms:spatial" => "report_location", - "dcterms:entity" => "report_organization", - "dc:subject" => "subject", - "dc:contributor" => "contributor", - "dc:language" => "language"); - class Metadata { + private static $MAP_METADATA_XML_TO_DB = array( + "ls:type" => "ftype", + "dc:format" => "format", + "ls:bitrate" => "bit_rate", + "ls:samplerate" => "sample_rate", + "dcterms:extent" => "length", + "dc:title" => "track_title", + "dc:description" => "comments", + "dc:type" => "genre", + "dc:creator" => "artist_name", + "dc:source" => "album_title", + "ls:channels" => "channels", + "ls:filename" => "name", + "ls:year" => "year", + "ls:url" => "url", + "ls:track_num" => "track_number", + "ls:mood" => "mood", + "ls:bpm" => "bpm", + "ls:disc_num" => "disc_number", + "ls:rating" => "rating", + "ls:encoded_by" => "encoded_by", + "dc:publisher" => "label", + "ls:composer" => "composer", + "ls:encoder" => "encoder", + "ls:crc" => "checksum", + "ls:lyrics" => "lyrics", + "ls:orchestra" => "orchestra", + "ls:conductor" => "conductor", + "ls:lyricist" => "lyricist", + "ls:originallyricist" => "original_lyricist", + "ls:radiostationname" => "radio_station_name", + "ls:audiofileinfourl" => "info_url", + "ls:artisturl" => "artist_url", + "ls:audiosourceurl" => "audio_source_url", + "ls:radiostationurl" => "radio_station_url", + "ls:buycdurl" => "buy_this_url", + "ls:isrcnumber" => "isrc_number", + "ls:catalognumber" => "catalog_number", + "ls:originalartist" => "original_artist", + "dc:rights" => "copyright", + "dcterms:temporal" => "report_datetime", + "dcterms:spatial" => "report_location", + "dcterms:entity" => "report_organization", + "dc:subject" => "subject", + "dc:contributor" => "contributor", + "dc:language" => "language"); + + public static function GetMapMetadataXmlToDb() { + return Metadata::$MAP_METADATA_XML_TO_DB; + } + /** * Track numbers in metadata tags can come in many formats: * "1 of 20", "1/20", "20/1". This function parses the track @@ -458,9 +461,9 @@ class StoredFile { */ public static function xmlCategoryToDbColumn($p_category) { - global $g_metadata_xml_to_db_mapping; - if (array_key_exists($p_category, $g_metadata_xml_to_db_mapping)) { - return $g_metadata_xml_to_db_mapping[$p_category]; + $map = Metadata::GetMapMetadataXmlToDb(); + if (array_key_exists($p_category, $map)) { + return $map[$p_category]; } return null; } @@ -474,8 +477,7 @@ class StoredFile { */ public static function dbColumnToXmlCatagory($p_dbColumn) { - global $g_metadata_xml_to_db_mapping; - $str = array_search($p_dbColumn, $g_metadata_xml_to_db_mapping); + $str = array_search($p_dbColumn, Metadata::GetMapMetadataXmlToDb()); // make return value consistent with xmlCategoryToDbColumn() if ($str === FALSE) { $str = null; @@ -1605,13 +1607,13 @@ class StoredFile { return $CC_CONFIG['accessDir']."/$p_token.$p_ext"; } - public static function searchFilesForPlaylistBuilder($datatables) { - global $CC_CONFIG, $g_metadata_xml_to_db_mapping; + public static function searchFilesForPlaylistBuilder($datatables) { + global $CC_CONFIG; $plSelect = "SELECT "; $fileSelect = "SELECT "; - foreach ($g_metadata_xml_to_db_mapping as $key => $val){ + foreach (Metadata::GetMapMetadataXmlToDb() as $key => $val){ if($key === "dc:title"){ $plSelect .= "name AS ".$val.", "; @@ -1651,16 +1653,15 @@ class StoredFile { } + public static function searchPlaylistsForSchedule($p_length, $datatables) { - $fromTable = "cc_playlist AS pl LEFT JOIN cc_playlisttimes AS plt USING(id) LEFT JOIN cc_subjs AS sub ON pl.editedby = sub.id"; - $datatables["optWhere"][] = "INTERVAL '{$p_length}' > INTERVAL '00:00:00'"; $datatables["optWhere"][] = "plt.length > INTERVAL '00:00:00'"; - return StoredFile::searchFiles($fromTable, $datatables); } + public static function searchFiles($fromTable, $data) { global $CC_CONFIG, $CC_DBC; @@ -1678,16 +1679,12 @@ class StoredFile { // Where clause if(isset($data["optWhere"])) { - $where[] = join(" AND ", $data["optWhere"]); } if(isset($searchTerms)) { - $searchCols = array(); - for($i=0; $i<$data["iColumns"]; $i++) { - if($data["bSearchable_".$i] == "true") { $searchCols[] = $columnsDisplayed[$i]; } @@ -1696,7 +1693,6 @@ class StoredFile { $outerCond = array(); foreach($searchTerms as $term) { - $innerCond = array(); foreach($searchCols as $col) { @@ -1722,12 +1718,9 @@ class StoredFile { $CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED); if(isset($where)) { - $where = join(" AND ", $where); - $sql = $selectorCount." FROM ".$fromTable." WHERE ".$where; $totalDisplayRows = $CC_DBC->getOne($sql); - $sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby." OFFSET ".$data["iDisplayStart"]." LIMIT ".$data["iDisplayLength"]; } else { @@ -1746,79 +1739,6 @@ class StoredFile { } return array("sEcho" => intval($data["sEcho"]), "iTotalDisplayRecords" => $totalDisplayRows, "iTotalRecords" => $totalRows, "aaData" => $results); - - - - - /* - - $match = array( - "0" => "ILIKE", - "1" => "=", - "2" => "<", - "3" => "<=", - "4" => ">", - "5" => ">=", - "6" => "!=", - ); - - $or_cond = array(); - $inner = $quick ? 'OR':'AND'; - $outer = $quick ? 'AND':'OR'; - foreach (array_keys($md) as $group) { - - if(strpos($group, 'group') === false) { - continue; - } - - $and_cond = array(); - foreach (array_keys($md[$group]) as $row) { - - $string = $g_metadata_xml_to_db_mapping[$md[$group][$row]["metadata"]]; - - $string = $string ." ".$match[$md[$group][$row]["match"]]; - - if ($md[$group][$row]["match"] === "0") - $string = $string." '%". $md[$group][$row]["search"]."%'"; - else - $string = $string." '". $md[$group][$row]["search"]."'"; - - $and_cond[] = $string; - } - - if(count($and_cond) > 0) { - $or_cond[] = "(".join(" ".$inner." ", $and_cond).")"; - } - } - - if(count($or_cond) > 0) { - $where = " WHERE ". join(" ".$outer." ", $or_cond); - $sql = $sql . $where; - } - - if($count) { - return $CC_DBC->getOne($sql); - } - - if(!is_null($order)) { - $ob = " ORDER BY ".$g_metadata_xml_to_db_mapping[$order["category"]]." ".$order["order"].", id "; - $sql = $sql . $ob; - } - else{ - $ob = " ORDER BY artist_name asc, id"; - $sql = $sql . $ob; - } - - if(!is_null($page) && !is_null($limit)) { - $offset = $page * $limit - ($limit); - $paginate = " LIMIT ".$limit. " OFFSET " .$offset; - $sql = $sql . $paginate; - } - //echo var_dump($md); - //echo $sql; - */ - - //return $CC_DBC->getAll($sql); } } From 75167bb5768454ed05b26b691ed7f4f2a793aa99 Mon Sep 17 00:00:00 2001 From: martin Date: Sun, 6 Mar 2011 15:18:40 -0500 Subject: [PATCH 6/6] -syntax error fix for liquidsoap + other small changes --- install/airtime-install.php | 5 ++--- pypo/scripts/lib.liq | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/install/airtime-install.php b/install/airtime-install.php index 885c2d36a..68913f554 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -18,7 +18,6 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) { createAPIKey(); require_once(dirname(__FILE__).'/../application/configs/conf.php'); -//require_once(dirname(__FILE__).'/../application/models/GreenBox.php'); require_once(dirname(__FILE__).'/installInit.php'); @@ -36,8 +35,8 @@ function rand_string($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') function createAPIKey(){ $api_key = rand_string(); - updateINIKeyValues('../build/airtime.conf', 'api_key', $api_key); - updateINIKeyValues('../pypo/config.cfg', 'api_key', "'$api_key'"); + updateINIKeyValues(__DIR__.'/../build/airtime.conf', 'api_key', $api_key); + updateINIKeyValues(__DIR__.'/../pypo/config.cfg', 'api_key', "'$api_key'"); } function checkIfRoot(){ diff --git a/pypo/scripts/lib.liq b/pypo/scripts/lib.liq index 384287056..2dc107c14 100644 --- a/pypo/scripts/lib.liq +++ b/pypo/scripts/lib.liq @@ -42,7 +42,7 @@ def add_skip_command(s) def skip(_) l = list.hd(server.execute("queue.queue")) l = string.split(separator=" ",l) - list.iter(fun (rid) -> ignore(server.execute(queue.ignore #{rid}")), l) + list.iter(fun (rid) -> ignore(server.execute("queue.ignore #{rid}")), l) source.skip(s) "Done!"