versionNotify();
$sss = $this->SourceSwitchStatus();
diff --git a/airtime_mvc/application/logging/Logging.php b/airtime_mvc/application/logging/Logging.php
index 91669647fe..a32aa9410a 100644
--- a/airtime_mvc/application/logging/Logging.php
+++ b/airtime_mvc/application/logging/Logging.php
@@ -38,52 +38,50 @@ public static function toString($p_msg)
return $p_msg;
}
}
+
+ /** @param debugMode Prints the function name, file, and line number. This is slow as it uses debug_backtrace()
+ * so don't use it unless you need it.
+ */
+ private static function getLinePrefix($debugMode=false)
+ {
+ $linePrefix = "";
+
+ if (array_key_exists('SERVER_NAME', $_SERVER)) {
+ $linePrefix .= $_SERVER['SERVER_NAME'] . " ";
+ }
+
+ if ($debugMode) {
+ //debug_backtrace is SLOW so we don't want this invoke unless there was a real error! (hence $debugMode)
+ $bt = debug_backtrace();
+ $caller = $bt[1];
+ $file = basename($caller['file']);
+ $line = $caller['line'];
+ $function = "Unknown function";
+ if (array_key_exists(2, $bt)) {
+ $function = $bt[2]['function'];
+ }
+ $linePrefix .= "[$file:$line - $function()] - ";
+ }
+
+ return $linePrefix;
+ }
public static function info($p_msg)
{
- $bt = debug_backtrace();
-
- $caller = array_shift($bt);
- $file = basename($caller['file']);
- $line = $caller['line'];
-
- $caller = array_shift($bt);
- $function = $caller['function'];
-
$logger = self::getLogger();
- $logger->info("[$file : $function() : line $line] - ".self::toString($p_msg));
+ $logger->info(self::getLinePrefix() . self::toString($p_msg));
}
public static function warn($p_msg)
{
- $bt = debug_backtrace();
-
- $caller = array_shift($bt);
- $file = basename($caller['file']);
- $line = $caller['line'];
-
- $caller = array_shift($bt);
- $function = $caller['function'];
-
$logger = self::getLogger();
- $logger->warn("[$file : $function() : line $line] - "
- . self::toString($p_msg));
+ $logger->warn(self::getLinePrefix() . self::toString($p_msg));
}
public static function error($p_msg)
{
- $bt = debug_backtrace();
-
- $caller = array_shift($bt);
- $file = basename($caller['file']);
- $line = $caller['line'];
-
- $caller = array_shift($bt);
- $function = $caller['function'];
-
$logger = self::getLogger();
- $logger->err("[$file : $function() : line $line] - "
- . self::toString($p_msg));
+ $logger->err(self::getLinePrefix(true) . self::toString($p_msg));
}
public static function debug($p_msg)
@@ -92,17 +90,8 @@ public static function debug($p_msg)
return;
}
- $bt = debug_backtrace();
-
- $caller = array_shift($bt);
- $file = basename($caller['file']);
- $line = $caller['line'];
-
- $caller = array_shift($bt);
- $function = $caller['function'];
-
$logger = self::getLogger();
- $logger->debug("[$file : $function() : line $line] - ".self::toString($p_msg));
+ $logger->debug(self::getLinePrefix(true) . self::toString($p_msg));
}
// kind of like debug but for printing arrays more compactly (skipping
// empty elements
@@ -134,4 +123,49 @@ public static function disablePropelLogging()
Propel::setLogger(null);
}
+ public static function loggingShutdownCallback()
+ {
+ //Catch the types of errors that PHP doesn't normally let us catch and
+ //would otherwise log to the apache log. We route these to our Airtime log to improve the modularity
+ //and reliability of our error logging. (All errors are in one spot!)
+ $err = error_get_last();
+ if (!is_array($err) || !array_key_exists('type', $err)) {
+ return;
+ }
+
+ switch($err['type'])
+ {
+ case E_ERROR:
+ case E_PARSE:
+ case E_CORE_ERROR:
+ case E_CORE_WARNING:
+ case E_COMPILE_ERROR:
+ case E_COMPILE_WARNING:
+ //error_log("Oh noes, a fatal: " . var_export($err, true), 1, 'fatals@example.com');
+ $errorStr = '';
+ if (array_key_exists('message', $err)) {
+ $errorStr .= $err['message'];
+ }
+ if (array_key_exists('file', $err))
+ {
+ $errorStr .= ' at ' .$err['file'];
+ }
+ if (array_key_exists('line', $err))
+ {
+ $errorStr .= ':' . $err['line'];
+ }
+
+ $errorStr .= "\n" . var_export($err, true);
+ Logging::error($errorStr);
+ break;
+ }
+ }
+
+ public static function setupParseErrorLogging()
+ {
+ //Static callback:
+ register_shutdown_function('Logging::loggingShutdownCallback');
+ }
+
}
+
diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php
index 4cb183569a..6a06060b88 100644
--- a/airtime_mvc/application/models/Block.php
+++ b/airtime_mvc/application/models/Block.php
@@ -1517,24 +1517,27 @@ public function getListofFilesMeetCriteria()
$i++;
}
}
-
+
// check if file exists
$qry->add("file_exists", "true", Criteria::EQUAL);
$qry->add("hidden", "false", Criteria::EQUAL);
- if (isset($storedCrit['sort'])) {
- $sortTracks = $storedCrit['sort']['value'];
- }
- if ($sortTracks == 'newest') {
- $qry->addDescendingOrderByColumn('utime');
- }
- else if ($sortTracks == 'oldest') {
- $qry->addAscendingOrderByColumn('utime');
- }
- else {
- $qry->addAscendingOrderByColumn('random()');
- }
+ $sortTracks = 'random';
+ if (isset($storedCrit['sort'])) {
+ $sortTracks = $storedCrit['sort']['value'];
+ }
+ if ($sortTracks == 'newest') {
+ $qry->addDescendingOrderByColumn('utime');
+ }
+ else if ($sortTracks == 'oldest') {
+ $qry->addAscendingOrderByColumn('utime');
+ }
+ else if ($sortTracks == 'random') {
+ $qry->addAscendingOrderByColumn('random()');
+ } else {
+ Logging::warning("Unimplemented sortTracks type in ".__FILE__);
+ }
- }
+ }
// construct limit restriction
$limits = array();
diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php
index 6e65b0c4c2..3f9f145690 100644
--- a/airtime_mvc/application/models/Preference.php
+++ b/airtime_mvc/application/models/Preference.php
@@ -37,8 +37,6 @@ private static function setValue($key, $value, $isUserValue = false)
if ($isUserValue && is_null($userId))
throw new Exception("User id can't be null for a user preference {$key}.");
- Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
-
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = :key";
@@ -589,13 +587,12 @@ public static function GetLocale()
public static function SetStationLogo($imagePath)
{
- if (!empty($imagePath)) {
- $image = @file_get_contents($imagePath);
- $image = base64_encode($image);
- self::setValue("logoImage", $image);
- } else {
- Logging::warn("Attempting to set imagePath to empty string");
+ if (empty($imagePath)) {
+ Logging::info("Removed station logo");
}
+ $image = @file_get_contents($imagePath);
+ $image = base64_encode($image);
+ self::setValue("logoImage", $image);
}
public static function GetStationLogo()
diff --git a/airtime_mvc/application/models/Scheduler.php b/airtime_mvc/application/models/Scheduler.php
index 4208ff5c76..edcf2da10e 100644
--- a/airtime_mvc/application/models/Scheduler.php
+++ b/airtime_mvc/application/models/Scheduler.php
@@ -828,7 +828,8 @@ private function insertAfter($scheduleItems, $mediaItems, $filesToInsert=null, $
"fade_in = '{$file["fadein"]}', ".
"fade_out = '{$file["fadeout"]}', ".
"clip_length = '{$file["cliplength"]}', ".
- "position = {$pos} ".
+ "position = {$pos}, ".
+ "instance_id = {$instanceId} ".
"WHERE id = {$sched["id"]}";
Application_Common_Database::prepareAndExecute(
diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php
index 007e789384..87eee7797f 100644
--- a/airtime_mvc/application/models/Webstream.php
+++ b/airtime_mvc/application/models/Webstream.php
@@ -93,6 +93,7 @@ public static function deleteStreams($p_ids, $p_userId)
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
if (!$isAdminOrPM) {
+ //Make sure the user has ownership of ALL the selected webstreams before
$leftOver = self::streamsNotOwnedByUser($p_ids, $p_userId);
if (count($leftOver) == 0) {
CcWebstreamQuery::create()->findPKs($p_ids)->delete();
@@ -280,13 +281,22 @@ private static function getXspfUrl($url)
private static function getPlsUrl($url)
{
$content = self::getUrlData($url);
- $ini = parse_ini_string($content, true);
- if ($ini !== false && isset($ini["playlist"]) && isset($ini["playlist"]["File1"])) {
- return $ini["playlist"]["File1"];
+ $matches = array();
+ $numStreams = 0; //Number of streams explicitly listed in the PLS.
+
+ if (preg_match("/NumberOfEntries=([0-9]*)/", $content, $matches) !== FALSE) {
+ $numStreams = $matches[1];
}
- throw new Exception(_("Could not parse PLS playlist"));
+ //Find all the stream URLs in the playlist
+ if (preg_match_all("/File[0-9]*=(.*)/", $content, $matches) !== FALSE) {
+ //This array contains all the streams! If we need fallback stream URLs in the future,
+ //they're already in this array...
+ return $matches[1][0];
+ } else {
+ throw new Exception(_("Could not parse PLS playlist"));
+ }
}
private static function getM3uUrl($url)
diff --git a/airtime_mvc/application/services/ShowFormService.php b/airtime_mvc/application/services/ShowFormService.php
index 94cc0068a7..5a17932b29 100644
--- a/airtime_mvc/application/services/ShowFormService.php
+++ b/airtime_mvc/application/services/ShowFormService.php
@@ -402,6 +402,7 @@ public function getNextFutureRepeatShowTime()
->filterByDbShowId($this->ccShow->getDbId())
->filterByDbModifiedInstance(false)
->filterByDbStarts(gmdate("Y-m-d H:i:s"), Criteria::GREATER_THAN)
+ ->orderByDbStarts()
->findOne();
$starts = new DateTime($ccShowInstance->getDbStarts(), new DateTimeZone("UTC"));
diff --git a/airtime_mvc/application/views/scripts/form/preferences.phtml b/airtime_mvc/application/views/scripts/form/preferences.phtml
index afc324126d..53062036af 100644
--- a/airtime_mvc/application/views/scripts/form/preferences.phtml
+++ b/airtime_mvc/application/views/scripts/form/preferences.phtml
@@ -1,7 +1,7 @@