Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
Martin Konecny 2011-11-23 16:31:29 -05:00
commit 54f6ea6f81
10 changed files with 232 additions and 160 deletions

View File

@ -202,32 +202,6 @@ class ApiController extends Zend_Controller_Action
exit; exit;
} }
} }
public function todayInfoAction()
{
if (Application_Model_Preference::GetAllow3rdPartyApi()){
// disable the view and the layout
$this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$date = new Application_Model_DateHelper;
$utcTimeNow = $date->getUtcTimestamp();
$utctimeEnd = Application_Model_DateHelper::GetDayEndTimestampInUtc();
$result = array("env"=>APPLICATION_ENV,
"schedulerTime"=>gmdate("Y-m-d H:i:s"),
"nextShow"=>Application_Model_Show::GetNextShows($utcTimeNow, 5, $utcTimeEnd));
Application_Model_Show::ConvertToLocalTimeZone($result["nextShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
header("Content-type: text/javascript");
echo $_GET['callback'].'('.json_encode($result).')';
} else {
header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource. ';
exit;
}
}
public function weekInfoAction() public function weekInfoAction()
{ {
@ -397,9 +371,11 @@ class ApiController extends Zend_Controller_Action
} }
$upload_dir = ini_get("upload_tmp_dir"); $upload_dir = ini_get("upload_tmp_dir");
Application_Model_StoredFile::uploadFile($upload_dir); $tempFilePath = Application_Model_StoredFile::uploadFile($upload_dir);
$tempFileName = basename($tempFilePath);
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName); Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
} }
public function uploadRecordedAction() public function uploadRecordedAction()

View File

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

View File

@ -1,4 +1,5 @@
<?php <?php
require_once 'customvalidators/ConditionalNotEmpty.php';
class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
{ {
@ -42,24 +43,40 @@ class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm
//SoundCloud Username //SoundCloud Username
$this->addElement('text', 'SoundCloudUser', array( $this->addElement('text', 'SoundCloudUser', array(
'class' => 'input_text', 'class' => 'input_text',
'label' => 'SoundCloud Email:', 'label' => 'SoundCloud Email',
'required' => false,
'filters' => array('StringTrim'), 'filters' => array('StringTrim'),
'autocomplete' => 'off',
'value' => Application_Model_Preference::GetSoundCloudUser(), 'value' => Application_Model_Preference::GetSoundCloudUser(),
'decorators' => array( 'decorators' => array(
'ViewHelper' 'ViewHelper'
),
// By default, 'allowEmpty' is true. This means that our custom
// validators are going to be skipped if this field is empty,
// which is something we don't want
'allowEmpty' => false,
'validators' => array(
new ConditionalNotEmpty(array('UploadToSoundcloudOption'=>'1'))
) )
)); ));
//SoundCloud Password //SoundCloud Password
$this->addElement('password', 'SoundCloudPassword', array( $this->addElement('password', 'SoundCloudPassword', array(
'class' => 'input_text', 'class' => 'input_text',
'label' => 'SoundCloud Password:', 'label' => 'SoundCloud Password',
'required' => false,
'filters' => array('StringTrim'), 'filters' => array('StringTrim'),
'autocomplete' => 'off',
'value' => Application_Model_Preference::GetSoundCloudPassword(), 'value' => Application_Model_Preference::GetSoundCloudPassword(),
'decorators' => array( 'decorators' => array(
'ViewHelper' 'ViewHelper'
),
// By default, 'allowEmpty' is true. This means that our custom
// validators are going to be skipped if this field is empty,
// which is something we don't want
'allowEmpty' => false,
'validators' => array(
new ConditionalNotEmpty(array('UploadToSoundcloudOption'=>'1'))
) )
)); ));

View File

@ -1,42 +1,42 @@
<?php <?php
class Zend_Filter_ImageSize implements Zend_Filter_Interface { class Zend_Filter_ImageSize implements Zend_Filter_Interface {
public function filter($value) {
public function filter($value) { if (!file_exists($value)) {
if(!file_exists($value)) {
throw new Zend_Filter_Exception('Image does not exist: ' . $value); throw new Zend_Filter_Exception('Image does not exist: ' . $value);
} }
$image = imageCreateFromString(file_get_contents($value)); $image = imageCreateFromString(file_get_contents($value));
if(false === $image) { if (false === $image) {
throw new Zend_Filter_Exception('Can\'t load image: ' . $value); throw new Zend_Filter_Exception('Can\'t load image: ' . $value);
} }
// find ratio to scale down to // find ratio to scale down to
// TODO: pass 600 as parameter in the future // TODO: pass 600 as parameter in the future
$origWidth = imagesx($image); $origWidth = imagesx($image);
$origHeight = imagesy($image); $origHeight = imagesy($image);
$ratio = max($origWidth, $origHeight) / 600; $ratio = max($origWidth, $origHeight) / 600;
if($ratio < 1) {
return; if ($ratio > 1) {
// img too big! create a scaled down image
$newWidth = round($origWidth / $ratio);
$newHeight = round($origHeight / $ratio);
$resized = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
// determine type and store to disk
$explodeResult = explode(".", $value);
$type = strtolower($explodeResult[count($explodeResult) - 1]);
$writeFunc = 'image' . $type;
if ($type == 'jpeg' || $type == 'jpg') {
imagejpeg($resized, $value, 100);
} else {
$writeFunc($resized, $value);
}
} }
// create a scaled down image return $value;
$newWidth = round($origWidth / $ratio); }
$newHeight = round($origHeight / $ratio);
$resized = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight);
// determine type and store to disk
$explodeResult = explode(".", $value);
$type = $explodeResult[count($explodeResult) - 1];
$writeFunc = 'image' . $type;
if($type == 'jpeg' || $type == 'jpg') {
imagejpeg($resized, $value, 100);
} else {
$writeFunc($resized, $value);
}
}
} }
?> ?>

View File

@ -0,0 +1,62 @@
<?php
/**
* Check if a field is empty but only when specific fields have specific values
*/
class ConditionalNotEmpty extends Zend_Validate_Abstract {
const KEY_IS_EMPTY = 'keyIsEmpty';
protected $_messageTemplates = array(
self::KEY_IS_EMPTY => 'Value is required and can\'t be empty'
);
protected $_fieldValues;
/**
* Constructs a new ConditionalNotEmpty validator.
*
* @param array $fieldValues - the names and expected values of the fields we're depending on;
* E.g., if we have a field that should only be validated when two other
* fields PARENT_1 and PARENT_2 have values of '1' and '0' respectively, then
* $fieldValues should contain ('PARENT_1'=>'1', 'PARENT_2'=>'0')
*/
public function __construct($fieldValues)
{
$this->_fieldValues = $fieldValues;
}
/**
* Implements Zend_Validate_Abstract.
* Given names and expected values of the fields we're depending on ($_fieldValues),
* this function returns true if the expected values doesn't match the actual user input,
* or if $value is not empty. Returns false otherwise.
*
* @param String $value - this field's value
* @param array $context - names and values of the rest of the fields in this form
* @return boolean - true if valid; false otherwise
*/
public function isValid($value, $context = null)
{
if ($value != "") {
return true;
}
if (is_array($context)) {
foreach($this->_fieldValues as $fieldName=>$fieldValue) {
if (!isset($context[$fieldName]) || $context[$fieldName] != $fieldValue) {
return true;
}
}
} elseif (is_string($context)) {
if (!isset($context) || $context != $fieldValue) {
return true;
}
}
$this->_error(self::KEY_IS_EMPTY);
return false;
}
}
?>

View File

@ -468,13 +468,13 @@ class Application_Model_Show {
return ""; return "";
} else { } else {
$row = $rows[0]; $row = $rows[0];
$dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"])); $dt = new DateTime($row["first_show"]." ".$row["start_time"], new DateTimeZone($row["timezone"]));
$dt->setTimezone(new DateTimeZone("UTC")); $dt->setTimezone(new DateTimeZone("UTC"));
return $dt->format("Y-m-d"); return $dt->format("Y-m-d");
} }
} }
/** /**
* Get the start time of the current show in UTC timezone. * Get the start time of the current show in UTC timezone.
* *
@ -673,34 +673,34 @@ class Application_Model_Show {
return $days; return $days;
} }
/* Only used for shows that aren't repeating. /* Only used for shows that aren't repeating.
* *
* @return Boolean: true if show has an instance, otherwise false. */ * @return Boolean: true if show has an instance, otherwise false. */
public function hasInstance(){ public function hasInstance(){
return (!is_null($this->getInstance())); return (!is_null($this->getInstance()));
} }
/* Only used for shows that aren't repeating. /* Only used for shows that aren't repeating.
* *
* @return CcShowInstancesQuery: An propel object representing a * @return CcShowInstancesQuery: An propel object representing a
* row in the cc_show_instances table. */ * row in the cc_show_instances table. */
public function getInstance(){ public function getInstance(){
$showInstance = CcShowInstancesQuery::create() $showInstance = CcShowInstancesQuery::create()
->filterByDbShowId($this->getId()) ->filterByDbShowId($this->getId())
->findOne(); ->findOne();
return $showInstance; return $showInstance;
} }
/* Only used for shows that are repeating. Note that this will return /* Only used for shows that are repeating. Note that this will return
* true even for dates that only have a "modified" show instance (does not * true even for dates that only have a "modified" show instance (does not
* check if the "modified_instance" column is set to true). This is intended * check if the "modified_instance" column is set to true). This is intended
* behaviour. * behaviour.
* *
* @param $p_dateTime: Date for which we are checking if instance * @param $p_dateTime: Date for which we are checking if instance
* exists. * exists.
* *
* @return Boolean: true if show has an instance on $p_dateTime, * @return Boolean: true if show has an instance on $p_dateTime,
* otherwise false. */ * otherwise false. */
public function hasInstanceOnDate($p_dateTime){ public function hasInstanceOnDate($p_dateTime){
return (!is_null($this->getInstanceOnDate($p_dateTime))); return (!is_null($this->getInstanceOnDate($p_dateTime)));
@ -710,10 +710,10 @@ class Application_Model_Show {
/* Only used for shows that are repeating. Note that this will return /* Only used for shows that are repeating. Note that this will return
* shows that have been "modified" (does not check if the "modified_instance" * shows that have been "modified" (does not check if the "modified_instance"
* column is set to true). This is intended behaviour. * column is set to true). This is intended behaviour.
* *
* @param $p_dateTime: Date for which we are getting an instance. * @param $p_dateTime: Date for which we are getting an instance.
* *
* @return CcShowInstancesQuery: An propel object representing a * @return CcShowInstancesQuery: An propel object representing a
* row in the cc_show_instances table. */ * row in the cc_show_instances table. */
public function getInstanceOnDate($p_dateTime){ public function getInstanceOnDate($p_dateTime){
global $CC_DBC; global $CC_DBC;
@ -1071,16 +1071,13 @@ class Application_Model_Show {
$timezone = $p_showRow["timezone"]; $timezone = $p_showRow["timezone"];
$start = $first_show." ".$start_time; $start = $first_show." ".$start_time;
$utcStartDateTime = Application_Model_DateHelper::ConvertToUtcDateTime($start, $timezone);
//start & end UTC DateTimes for the show.
list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone);
if ($utcStartDateTime->getTimestamp() < $p_dateTime->getTimestamp()) { if ($utcStartDateTime->getTimestamp() < $p_dateTime->getTimestamp()) {
$utcStart = $utcStartDateTime->format("Y-m-d H:i:s"); $currentUtcTimestamp = gmdate("Y-m-d H:i:s");
$sql = "SELECT timestamp '{$utcStart}' + interval '{$duration}'";
$utcEndDateTime = new DateTime($CC_DBC->GetOne($sql), new DateTimeZone("UTC"));
$date = new Application_Model_DateHelper();
$currentUtcTimestamp = $date->getUtcTimestamp();
$show = new Application_Model_Show($show_id); $show = new Application_Model_Show($show_id);
if ($show->hasInstance()){ if ($show->hasInstance()){
@ -1141,8 +1138,7 @@ class Application_Model_Show {
$record = $p_showRow["record"]; $record = $p_showRow["record"];
$timezone = $p_showRow["timezone"]; $timezone = $p_showRow["timezone"];
$date = new Application_Model_DateHelper(); $currentUtcTimestamp = gmdate("Y-m-d H:i:s");
$currentUtcTimestamp = $date->getUtcTimestamp();
if(isset($next_pop_date)) { if(isset($next_pop_date)) {
$start = $next_pop_date." ".$start_time; $start = $next_pop_date." ".$start_time;
@ -1162,9 +1158,7 @@ class Application_Model_Show {
while($utcStartDateTime->getTimestamp() <= $p_dateTime->getTimestamp() while($utcStartDateTime->getTimestamp() <= $p_dateTime->getTimestamp()
&& (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){ && (is_null($utcLastShowDateTime) || $utcStartDateTime->getTimestamp() < $utcLastShowDateTime->getTimestamp())){
$utcStart = $utcStartDateTime->format("Y-m-d H:i:s"); list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start, $duration, $timezone);
$sql = "SELECT timestamp '{$utcStart}' + interval '{$duration}'";
$utcEndDateTime = new DateTime($CC_DBC->GetOne($sql), new DateTimeZone("UTC"));
if ($show->hasInstanceOnDate($utcStartDateTime)){ if ($show->hasInstanceOnDate($utcStartDateTime)){
$ccShowInstance = $show->getInstanceOnDate($utcStartDateTime); $ccShowInstance = $show->getInstanceOnDate($utcStartDateTime);
@ -1199,25 +1193,25 @@ class Application_Model_Show {
if ($p_interval == 'P1M'){ if ($p_interval == 'P1M'){
/* When adding months, there is a problem if we are on January 31st and add one month with PHP. /* When adding months, there is a problem if we are on January 31st and add one month with PHP.
* What ends up happening is that since February 31st doesn't exist, the date returned is * What ends up happening is that since February 31st doesn't exist, the date returned is
* March 3rd. For now let's ignore the day and assume we are always working with the * March 3rd. For now let's ignore the day and assume we are always working with the
* first of each month, and use PHP to add 1 month to this (this will take care of rolling * first of each month, and use PHP to add 1 month to this (this will take care of rolling
* over the years 2011->2012, etc.). Then let's append the actual day, and use the php * over the years 2011->2012, etc.). Then let's append the actual day, and use the php
* checkdate() function, to see if it is valid. If not, then we'll just skip this month. */ * checkdate() function, to see if it is valid. If not, then we'll just skip this month. */
$startDt = new DateTime($start, new DateTimeZone($timezone)); $startDt = new DateTime($start, new DateTimeZone($timezone));
/* pass in only the year and month (not the day) */ /* pass in only the year and month (not the day) */
$dt = new DateTime($startDt->format("Y-m"), new DateTimeZone($timezone)); $dt = new DateTime($startDt->format("Y-m"), new DateTimeZone($timezone));
/* Keep adding 1 month, until we find the next month that contains the day /* Keep adding 1 month, until we find the next month that contains the day
* we are looking for (31st day for example) */ * we are looking for (31st day for example) */
do { do {
$dt->add(new DateInterval($p_interval)); $dt->add(new DateInterval($p_interval));
} while(!checkdate($dt->format("m"), $startDt->format("d"), $dt->format("Y"))); } while(!checkdate($dt->format("m"), $startDt->format("d"), $dt->format("Y")));
$dt->setDate($dt->format("Y"), $dt->format("m"), $startDt->format("d")); $dt->setDate($dt->format("Y"), $dt->format("m"), $startDt->format("d"));
$start = $dt->format("Y-m-d H:i:s"); $start = $dt->format("Y-m-d H:i:s");
$dt->setTimezone(new DateTimeZone('UTC')); $dt->setTimezone(new DateTimeZone('UTC'));
@ -1236,49 +1230,78 @@ class Application_Model_Show {
Application_Model_Show::setNextPop($start, $show_id, $day); Application_Model_Show::setNextPop($start, $show_id, $day);
} }
/*
* @param $p_start
* timestring format "Y-m-d H:i:s" (not UTC)
* @param $p_duration
* string time interval (h)h:(m)m(:ss)
* @param $p_timezone
* string "Europe/Prague"
* @param $p_offset
* array (days, hours, mins) used for rebroadcast shows.
*
* @return
* array of 2 DateTime objects, start/end time of the show in UTC.
*/
private static function createUTCStartEndDateTime($p_start, $p_duration, $p_timezone=null, $p_offset=null)
{
$timezone = $p_timezone ? $p_timezone : date_default_timezone_get();
$startDateTime = new DateTime($p_start, new DateTimeZone($timezone));
if (isset($p_offset)) {
$startDateTime->add(new DateInterval("P{$p_offset["days"]}DT{$p_offset["hours"]}H{$p_offset["mins"]}M"));
}
//convert time to UTC
$startDateTime->setTimezone(new DateTimeZone('UTC'));
$endDateTime = clone $startDateTime;
$duration = explode(":", $p_duration);
list($hours, $mins) = array_slice($duration, 0, 2);
$endDateTime->add(new DateInterval("PT{$hours}H{$mins}M"));
return array($startDateTime, $endDateTime);
}
/* Create rebroadcast instances for a created show marked for recording /* Create rebroadcast instances for a created show marked for recording
* *
* @param $p_rebroadcasts rows gotten from the db table cc_show_rebroadcasts, tells airtime when to schedule the rebroadcasts. * @param $p_rebroadcasts
* @param $p_currentUtcTimestamp a timestring in format "Y-m-d H:i:s", current UTC time. * rows gotten from the db table cc_show_rebroadcasts, tells airtime when to schedule the rebroadcasts.
* @param $p_showId int of the show it belongs to (from cc_show) * @param $p_currentUtcTimestamp
* @param $p_showInstanceId the instance id of the created recorded show instance * a timestring in format "Y-m-d H:i:s", current UTC time.
* @param $p_showId
* int of the show it belongs to (from cc_show)
* @param $p_showInstanceId
* the instance id of the created recorded show instance
* (from cc_show_instances), used to associate rebroadcasts to this show. * (from cc_show_instances), used to associate rebroadcasts to this show.
* @param $p_startTime a timestring in format "Y-m-d H:i:s" in the timezone, not UTC of the rebroadcasts' parent recorded show. * @param $p_startTime
* @param $p_duration duration of the show in format 1:0 * a timestring in format "Y-m-d H:i:s" in the timezone, not UTC of the rebroadcasts' parent recorded show.
* @param $p_timezone string of user's timezone "Europe/Prague" * @param $p_duration
* string time interval (h)h:(m)m:(ss) length of the show.
* @param $p_timezone
* string of user's timezone "Europe/Prague"
* *
*/ */
private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_startTime, $p_duration, $p_timezone=null){ private static function createRebroadcastInstances($p_rebroadcasts, $p_currentUtcTimestamp, $p_showId, $p_showInstanceId, $p_startTime, $p_duration, $p_timezone=null){
global $CC_DBC;
Logging::log('Count of rebroadcasts '. count($p_rebroadcasts)); //Y-m-d
//use only the date part of the show start time stamp for the offsets to work properly.
$date = explode(" ", $p_startTime);
$start_date = $date[0];
foreach($p_rebroadcasts as $rebroadcast) { foreach($p_rebroadcasts as $rebroadcast) {
//use only the date part of the show start time stamp for the offsets to work properly. $days = explode(" ", $rebroadcast["day_offset"]);
$sql = "SELECT date '{$p_startTime}' + interval '{$rebroadcast["day_offset"]}' + interval '{$rebroadcast["start_time"]}'"; $time = explode(":", $rebroadcast["start_time"]);
$rebroadcast_start_time = $CC_DBC->GetOne($sql); $offset = array("days"=>$days[0], "hours"=>$time[0], "mins"=>$time[1]);
Logging::log('rebroadcast start '.$rebroadcast_start_time);
$sql = "SELECT timestamp '{$rebroadcast_start_time}' + interval '{$p_duration}'"; list($utcStartDateTime, $utcEndDateTime) = Application_Model_Show::createUTCStartEndDateTime($start_date, $p_duration, $p_timezone, $offset);
$rebroadcast_end_time = $CC_DBC->GetOne($sql);
Logging::log('rebroadcast end '.$rebroadcast_end_time);
//convert to UTC, after we have used the defined offsets to calculate rebroadcasts. if ($utcStartDateTime->format("Y-m-d H:i:s") > $p_currentUtcTimestamp){
$utc_rebroadcast_start_time = Application_Model_DateHelper::ConvertToUtcDateTime($rebroadcast_start_time, $p_timezone);
$utc_rebroadcast_end_time = Application_Model_DateHelper::ConvertToUtcDateTime($rebroadcast_end_time, $p_timezone);
Logging::log('UTC rebroadcast start '.$utc_rebroadcast_start_time->format("Y-m-d H:i:s"));
Logging::log('UTC rebroadcast end '.$utc_rebroadcast_end_time->format("Y-m-d H:i:s"));
Logging::log('Current UTC timestamp '.$p_currentUtcTimestamp);
if ($utc_rebroadcast_start_time->format("Y-m-d H:i:s") > $p_currentUtcTimestamp){
Logging::log('Creating rebroadcast show starting at UTC '.$utc_rebroadcast_start_time->format("Y-m-d H:i:s"));
$newRebroadcastInstance = new CcShowInstances(); $newRebroadcastInstance = new CcShowInstances();
$newRebroadcastInstance->setDbShowId($p_showId); $newRebroadcastInstance->setDbShowId($p_showId);
$newRebroadcastInstance->setDbStarts($utc_rebroadcast_start_time->format("Y-m-d H:i:s")); $newRebroadcastInstance->setDbStarts($utcStartDateTime);
$newRebroadcastInstance->setDbEnds($utc_rebroadcast_end_time->format("Y-m-d H:i:s")); $newRebroadcastInstance->setDbEnds($utcEndDateTime);
$newRebroadcastInstance->setDbRecord(0); $newRebroadcastInstance->setDbRecord(0);
$newRebroadcastInstance->setDbRebroadcast(1); $newRebroadcastInstance->setDbRebroadcast(1);
$newRebroadcastInstance->setDbOriginalShow($p_showInstanceId); $newRebroadcastInstance->setDbOriginalShow($p_showInstanceId);
@ -1552,7 +1575,7 @@ class Application_Model_Show {
." AND si.starts >= TIMESTAMP '$timeStart'" ." AND si.starts >= TIMESTAMP '$timeStart'"
." AND si.starts < TIMESTAMP $timeEnd" ." AND si.starts < TIMESTAMP $timeEnd"
." ORDER BY si.starts"; ." ORDER BY si.starts";
// defaults to retrieve all shows within the interval if $limit not set // defaults to retrieve all shows within the interval if $limit not set
if($limit != 0) { if($limit != 0) {
$sql = $sql . " LIMIT $limit"; $sql = $sql . " LIMIT $limit";

View File

@ -809,10 +809,18 @@ class Application_Model_StoredFile {
if (isset($_SERVER["CONTENT_TYPE"])) if (isset($_SERVER["CONTENT_TYPE"]))
$contentType = $_SERVER["CONTENT_TYPE"]; $contentType = $_SERVER["CONTENT_TYPE"];
// create temp file name (CC-3086)
$command = "mktemp --tmpdir=".$p_targetDir;
$tempFilePath= exec($command);
if($tempFilePath == ""){
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Unable to create tmp file."}, "id" : "id"}');
}
if (strpos($contentType, "multipart") !== false) { if (strpos($contentType, "multipart") !== false) {
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
// Open temp file // Open temp file
$out = fopen($p_targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); $out = fopen($tempFilePath, $chunk == 0 ? "wb" : "ab");
if ($out) { if ($out) {
// Read binary input stream and append it to temp file // Read binary input stream and append it to temp file
$in = fopen($_FILES['file']['tmp_name'], "rb"); $in = fopen($_FILES['file']['tmp_name'], "rb");
@ -831,7 +839,7 @@ class Application_Model_StoredFile {
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
} else { } else {
// Open temp file // Open temp file
$out = fopen($p_targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); $out = fopen($tempFilePath, $chunk == 0 ? "wb" : "ab");
if ($out) { if ($out) {
// Read binary input stream and append it to temp file // Read binary input stream and append it to temp file
$in = fopen("php://input", "rb"); $in = fopen("php://input", "rb");
@ -846,34 +854,12 @@ class Application_Model_StoredFile {
} else } else
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
} }
/*$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName; return $tempFilePath;
$md5 = md5_file($audio_file);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
if ($duplicate) {
if (PEAR::isError($duplicate)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
}
if (file_exists($duplicate->getFilePath())) {
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}');
}
}
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
$r = @copy($audio_file, $audio_stor);*/
} }
public static function copyFileToStor($p_targetDir, $fileName){ public static function copyFileToStor($p_targetDir, $fileName, $tempname){
$audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $fileName; $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
Logging::log('copyFileToStor: moving file '.$audio_file); Logging::log('copyFileToStor: moving file '.$audio_file);
$md5 = md5_file($audio_file); $md5 = md5_file($audio_file);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5); $duplicate = Application_Model_StoredFile::RecallByMd5($md5);
@ -895,7 +881,7 @@ class Application_Model_StoredFile {
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName; $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
$r = @copy($audio_file, $audio_stor); $r = @copy($audio_file, $audio_stor);
//$r = @unlink($audio_file); $r = @unlink($audio_file);
} }
public static function getFileCount() public static function getFileCount()

View File

@ -40,7 +40,9 @@
<?php endif; ?> <?php endif; ?>
</dd> </dd>
<dt id="SoundCloudUser-label" class="block-display"> <dt id="SoundCloudUser-label" class="block-display">
<label class="optional" for="SoundCloudUser"><?php echo $this->element->getElement('SoundCloudUser')->getLabel() ?></label> <label class="optional" for="SoundCloudUser"><?php echo $this->element->getElement('SoundCloudUser')->getLabel() ?>
<span class="info-text-small">(Required)</span> :
</label>
</dt> </dt>
<dd id="SoundCloudUser-element" class="block-display"> <dd id="SoundCloudUser-element" class="block-display">
<?php echo $this->element->getElement('SoundCloudUser') ?> <?php echo $this->element->getElement('SoundCloudUser') ?>
@ -53,7 +55,9 @@
<?php endif; ?> <?php endif; ?>
</dd> </dd>
<dt id="SoundCloudPassword-label" class="block-display"> <dt id="SoundCloudPassword-label" class="block-display">
<label class="optional" for="SoundCloudPassword"><?php echo $this->element->getElement('SoundCloudPassword')->getLabel() ?></label> <label class="optional" for="SoundCloudPassword"><?php echo $this->element->getElement('SoundCloudPassword')->getLabel() ?>
<span class="info-text-small">(Required)</span> :
</label>
</dt> </dt>
<dd id="SoundCloudPassword-element" class="block-display"> <dd id="SoundCloudPassword-element" class="block-display">
<?php echo $this->element->getElement('SoundCloudPassword') ?> <?php echo $this->element->getElement('SoundCloudPassword') ?>

View File

@ -16,16 +16,16 @@ $(document).ready(function() {
uploader.bind('FileUploaded', function(up, file, json) { uploader.bind('FileUploaded', function(up, file, json) {
var j = jQuery.parseJSON(json.response); var j = jQuery.parseJSON(json.response);
if(j.error !== undefined) { if(j.error !== undefined) {
var row = $("<tr/>") var row = $("<tr/>")
.append('<td>' + file.name +'</td>') .append('<td>' + file.name +'</td>')
.append('<td>' + j.error.message + '</td>'); .append('<td>' + j.error.message + '</td>');
$("#plupload_error").find("table").append(row); $("#plupload_error").find("table").append(row);
}else{ }else{
$.get('/Plupload/copyfile/format/json/name/'+encodeURIComponent(file.name), function(json){ var tempFileName = j.tempfilepath;
$.get('/Plupload/copyfile/format/json/name/'+encodeURIComponent(file.name)+'/tempname/'+encodeURIComponent(tempFileName), function(json){
var jr = jQuery.parseJSON(json); var jr = jQuery.parseJSON(json);
if(jr.error !== undefined) { if(jr.error !== undefined) {
var row = $("<tr/>") var row = $("<tr/>")

View File

@ -16,7 +16,9 @@
getServerData(); getServerData();
function updateWidget(){ function updateWidget(){
var shows = sd.getNextShows(); var currentShow = sd.getCurrentShow();
var nextShows = sd.getNextShows();
var shows = currentShow.length == 0 ? nextShows : currentShow.concat(nextShows);
tableString = ""; tableString = "";
tableString += "<h3>" + options.text.onAirToday + "</h3>"; tableString += "<h3>" + options.text.onAirToday + "</h3>";
@ -50,7 +52,7 @@
} }
function getServerData(){ function getServerData(){
$.ajax({ url: options.sourceDomain + "api/today-info/", dataType:"jsonp", success:function(data){ $.ajax({ url: options.sourceDomain + "api/live-info/", dataType:"jsonp", success:function(data){
processData(data); processData(data);
}, error:airtimeScheduleJsonpError}); }, error:airtimeScheduleJsonpError});
setTimeout(getServerData, options.updatePeriod*1000); setTimeout(getServerData, options.updatePeriod*1000);