Merge branch 'saas' of github.com:sourcefabric/Airtime into saas
This commit is contained in:
commit
fd42c67b0b
13 changed files with 225 additions and 76 deletions
|
@ -209,8 +209,12 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
$interval = 'P21D';
|
||||
} elseif ($formData["add_show_repeat_type"] == 5) {
|
||||
$interval = 'P28D';
|
||||
} elseif ($formData["add_show_repeat_type"] == 2) {
|
||||
} elseif ($formData["add_show_repeat_type"] == 2 && $formData["add_show_monthly_repeat_type"] == 2) {
|
||||
$interval = 'P1M';
|
||||
} elseif ($formData["add_show_repeat_type"] == 2 && $formData["add_show_monthly_repeat_type"] == 3) {
|
||||
list($weekNumberOfMonth, $dayOfWeek) =
|
||||
Application_Service_ShowService::getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime($start_time, $showTimezone));
|
||||
}
|
||||
|
||||
/* Check first show
|
||||
|
@ -274,12 +278,26 @@ class Application_Form_AddShowWhen extends Zend_Form_SubForm
|
|||
$this->getElement('add_show_duration')->setErrors(array(_('Cannot schedule overlapping shows')));
|
||||
break 1;
|
||||
} else {
|
||||
$repeatShowStart->setTimezone($showTimezone);
|
||||
$repeatShowEnd->setTimezone($showTimezone);
|
||||
$repeatShowStart->add(new DateInterval($interval));
|
||||
$repeatShowEnd->add(new DateInterval($interval));
|
||||
$repeatShowStart->setTimezone($utc);
|
||||
$repeatShowEnd->setTimezone($utc);
|
||||
if ($formData["add_show_repeat_type"] == 2 && $formData["add_show_monthly_repeat_type"] == 3) {
|
||||
$monthlyWeeklyStart = new DateTime($repeatShowStart->format("Y-m"),
|
||||
new DateTimeZone("UTC"));
|
||||
$monthlyWeeklyStart->add(new DateInterval("P1M"));
|
||||
$repeatShowStart = clone Application_Service_ShowService::getNextMonthlyWeeklyRepeatDate(
|
||||
$monthlyWeeklyStart,
|
||||
$formData["add_show_timezone"],
|
||||
$formData['add_show_start_time'],
|
||||
$weekNumberOfMonth,
|
||||
$dayOfWeek);
|
||||
$repeatShowEnd = clone $repeatShowStart;
|
||||
$repeatShowEnd->add(new DateInterval("PT".$hours."H".$minutes."M"));
|
||||
} else {
|
||||
$repeatShowStart->setTimezone($showTimezone);
|
||||
$repeatShowEnd->setTimezone($showTimezone);
|
||||
$repeatShowStart->add(new DateInterval($interval));
|
||||
$repeatShowEnd->add(new DateInterval($interval));
|
||||
$repeatShowStart->setTimezone($utc);
|
||||
$repeatShowEnd->setTimezone($utc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
private $criteriaOptions;
|
||||
private $stringCriteriaOptions;
|
||||
private $numericCriteriaOptions;
|
||||
private $sortOptions;
|
||||
private $limitOptions;
|
||||
|
||||
/* We need to know if the criteria value will be a string
|
||||
|
@ -122,6 +123,17 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
}
|
||||
return $this->limitOptions;
|
||||
}
|
||||
private function getSortOptions()
|
||||
{
|
||||
if (!isset($this->sortOptions)) {
|
||||
$this->sortOptions = array(
|
||||
"random" => _("random"),
|
||||
"newest" => _("newest"),
|
||||
"oldest" => _("oldest")
|
||||
);
|
||||
}
|
||||
return $this->sortOptions;
|
||||
}
|
||||
|
||||
|
||||
public function init()
|
||||
|
@ -288,6 +300,15 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
}
|
||||
$this->addElement($repeatTracks);
|
||||
|
||||
$sort = new Zend_Form_Element_Select('sp_sort_options');
|
||||
$sort->setAttrib('class', 'sp_input_select')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions($this->getSortOptions());
|
||||
if (isset($storedCrit["sort"])) {
|
||||
$sort->setValue($storedCrit["sort"]["value"]);
|
||||
}
|
||||
$this->addElement($sort);
|
||||
|
||||
$limit = new Zend_Form_Element_Select('sp_limit_options');
|
||||
$limit->setAttrib('class', 'sp_input_select')
|
||||
->setDecorators(array('viewHelper'))
|
||||
|
@ -344,7 +365,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
|
||||
public function preValidation($params)
|
||||
{
|
||||
$data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']);
|
||||
$data = Application_Model_Block::organizeSmartPlaylistCriteria($params['data']);
|
||||
// add elelments that needs to be added
|
||||
// set multioption for modifier according to criteria_field
|
||||
$modRowMap = array();
|
||||
|
|
|
@ -1156,7 +1156,7 @@ SQL;
|
|||
*/
|
||||
public function saveSmartBlockCriteria($p_criteria)
|
||||
{
|
||||
$data = $this->organizeSmartPlyalistCriteria($p_criteria);
|
||||
$data = $this->organizeSmartPlaylistCriteria($p_criteria);
|
||||
// saving dynamic/static flag
|
||||
$blockType = $data['etc']['sp_type'] == 0 ? 'static':'dynamic';
|
||||
$this->saveType($blockType);
|
||||
|
@ -1224,6 +1224,16 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
// insert sort info
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("sort")
|
||||
->setDbModifier("N/A")
|
||||
->setDbValue($p_criteriaData['etc']['sp_sort_options'])
|
||||
->setDbBlockId($this->id)
|
||||
->save();
|
||||
|
||||
|
||||
|
||||
// insert limit info
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("limit")
|
||||
|
@ -1231,7 +1241,8 @@ SQL;
|
|||
->setDbValue($p_criteriaData['etc']['sp_limit_value'])
|
||||
->setDbBlockId($this->id)
|
||||
->save();
|
||||
|
||||
|
||||
|
||||
// insert repeate track option
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("repeat_tracks")
|
||||
|
@ -1352,6 +1363,7 @@ SQL;
|
|||
"isrc_number" => _("ISRC"),
|
||||
"label" => _("Label"),
|
||||
"language" => _("Language"),
|
||||
"utime" => _("Upload Time"),
|
||||
"mtime" => _("Last Modified"),
|
||||
"lptime" => _("Last Played"),
|
||||
"length" => _("Length"),
|
||||
|
@ -1399,6 +1411,8 @@ SQL;
|
|||
"display_modifier"=>_($modifier));
|
||||
} else if($criteria == "repeat_tracks") {
|
||||
$storedCrit["repeat_tracks"] = array("value"=>$value);
|
||||
} else if($criteria == "sort") {
|
||||
$storedCrit["sort"] = array("value"=>$value);
|
||||
} else {
|
||||
$storedCrit["crit"][$criteria][] = array(
|
||||
"criteria"=>$criteria,
|
||||
|
@ -1507,8 +1521,20 @@ SQL;
|
|||
// 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()');
|
||||
}
|
||||
|
||||
}
|
||||
// construct limit restriction
|
||||
$limits = array();
|
||||
|
||||
|
@ -1537,9 +1563,8 @@ SQL;
|
|||
Logging::info($e);
|
||||
}
|
||||
}
|
||||
|
||||
public static function organizeSmartPlyalistCriteria($p_criteria)
|
||||
{
|
||||
public static function organizeSmartPlaylistCriteria($p_criteria)
|
||||
{
|
||||
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra');
|
||||
$output = array();
|
||||
foreach ($p_criteria as $ele) {
|
||||
|
|
|
@ -88,11 +88,19 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable
|
|||
|
||||
public static function deleteStreams($p_ids, $p_userId)
|
||||
{
|
||||
$leftOver = self::streamsNotOwnedByUser($p_ids, $p_userId);
|
||||
if (count($leftOver) == 0) {
|
||||
CcWebstreamQuery::create()->findPKs($p_ids)->delete();
|
||||
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
||||
$user = new Application_Model_User($userInfo->id);
|
||||
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
||||
|
||||
if (!$isAdminOrPM) {
|
||||
$leftOver = self::streamsNotOwnedByUser($p_ids, $p_userId);
|
||||
if (count($leftOver) == 0) {
|
||||
CcWebstreamQuery::create()->findPKs($p_ids)->delete();
|
||||
} else {
|
||||
throw new WebstreamNoPermissionException;
|
||||
}
|
||||
} else {
|
||||
throw new WebstreamNoPermissionException;
|
||||
CcWebstreamQuery::create()->findPKs($p_ids)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
public function init()
|
||||
{
|
||||
$this->view->layout()->disableLayout();
|
||||
// Remove reliance on .phtml files to render requests
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
// Remove reliance on .phtml files to render requests
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
|
@ -83,7 +83,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
public function getAction()
|
||||
{
|
||||
if (!$this->verifyAuth(true, true))
|
||||
{
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -286,11 +286,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
$observed_csrf_token = $token;
|
||||
$expected_csrf_token = $current_namespace->authtoken;
|
||||
|
||||
if($observed_csrf_token == $expected_csrf_token){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return ($observed_csrf_token === $expected_csrf_token);
|
||||
}
|
||||
|
||||
private function verifyAuth($checkApiKey, $checkSession)
|
||||
|
@ -301,7 +297,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
if(!$this->verifyCSRFToken($this->_getParam('csrf_token'))){
|
||||
$resp = $this->getResponse();
|
||||
$resp->setHttpResponseCode(401);
|
||||
$resp->appendBody("ERROR: Token Missmatch.");
|
||||
$resp->appendBody("ERROR: Token Mismatch.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -331,24 +327,13 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
$encodedRequestApiKey = substr($authHeader, strlen("Basic "));
|
||||
$encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":");
|
||||
|
||||
if ($encodedRequestApiKey === $encodedStoredApiKey)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return ($encodedRequestApiKey === $encodedStoredApiKey);
|
||||
}
|
||||
|
||||
private function verifySession()
|
||||
{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ($auth->hasIdentity());
|
||||
|
||||
//Token checking stub code. We'd need to change LoginController.php to generate a token too, but
|
||||
//but luckily all the token code already exists and works.
|
||||
|
@ -458,7 +443,7 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
return $service_user->getCurrentUser()->getDbId();
|
||||
} else {
|
||||
$defaultOwner = CcSubjsQuery::create()
|
||||
->filterByDbType('A')
|
||||
->filterByDbType(array('A', 'S'), Criteria::IN)
|
||||
->orderByDbId()
|
||||
->findOne();
|
||||
if (!$defaultOwner) {
|
||||
|
@ -474,23 +459,21 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Strips out fields from incoming request data that should never be modified
|
||||
* from outside of Airtime
|
||||
* @param array $data
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
private static function removeBlacklistedFieldsFromRequestData($data)
|
||||
{
|
||||
private static function removeBlacklistedFieldsFromRequestData($data) {
|
||||
foreach (self::$blackList as $key) {
|
||||
unset($data[$key]);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
private function removeEmptySubFolders($path)
|
||||
{
|
||||
private function removeEmptySubFolders($path) {
|
||||
exec("find $path -empty -type d -delete");
|
||||
}
|
||||
|
||||
|
|
|
@ -1133,7 +1133,7 @@ SQL;
|
|||
$start = $this->getNextRepeatingPopulateStartDateTime($showDay);
|
||||
|
||||
if (is_null($repeatInterval)&& $repeatType == REPEAT_MONTHLY_WEEKLY) {
|
||||
$repeatInterval = $this->getMonthlyWeeklyRepeatInterval($start, $timezone);
|
||||
$repeatInterval = self::getMonthlyWeeklyRepeatInterval($start, $timezone);
|
||||
}
|
||||
|
||||
//DatePeriod in user's local time
|
||||
|
@ -1236,7 +1236,7 @@ SQL;
|
|||
|
||||
// We will only need this if the repeat type is MONTHLY_WEEKLY
|
||||
list($weekNumberOfMonth, $dayOfWeek) =
|
||||
$this->getMonthlyWeeklyRepeatInterval(
|
||||
self::getMonthlyWeeklyRepeatInterval(
|
||||
new DateTime($first_show, new DateTimeZone($timezone)));
|
||||
|
||||
$this->repeatType = $showDay->getDbRepeatType();
|
||||
|
@ -1296,7 +1296,7 @@ SQL;
|
|||
$monthlyWeeklyStart = new DateTime($utcStartDateTime->format("Y-m"),
|
||||
new DateTimeZone("UTC"));
|
||||
$monthlyWeeklyStart->add(new DateInterval("P1M"));
|
||||
$start = $this->getNextMonthlyWeeklyRepeatDate(
|
||||
$start = self::getNextMonthlyWeeklyRepeatDate(
|
||||
$monthlyWeeklyStart,
|
||||
$timezone,
|
||||
$showDay->getDbStartTime(),
|
||||
|
@ -1318,7 +1318,7 @@ SQL;
|
|||
* @param string $showStart
|
||||
* @param string $timezone user's local timezone
|
||||
*/
|
||||
private function getMonthlyWeeklyRepeatInterval($showStart)
|
||||
public static function getMonthlyWeeklyRepeatInterval($showStart)
|
||||
{
|
||||
$start = clone $showStart;
|
||||
$dayOfMonth = $start->format("j");
|
||||
|
@ -1393,7 +1393,7 @@ SQL;
|
|||
* @param string (i.e. 'first', 'second') $weekNumberOfMonth
|
||||
* @param string (i.e. 'Monday') $dayOfWeek
|
||||
*/
|
||||
private function getNextMonthlyWeeklyRepeatDate(
|
||||
public static function getNextMonthlyWeeklyRepeatDate(
|
||||
$start,
|
||||
$timezone,
|
||||
$startTime,
|
||||
|
|
|
@ -95,7 +95,18 @@
|
|||
<?php endif; ?>
|
||||
<br />
|
||||
</dd>
|
||||
|
||||
<dd id='sp_sort-element'>
|
||||
<span class='sp_text_font'>Sort tracks by</span>
|
||||
<?php echo $this->element->getElement('sp_sort_options') ?>
|
||||
<?php if($this->element->getElement("sp_sort_options")->hasErrors()) : ?>
|
||||
<?php foreach($this->element->getElement("sp_sort_options")->getMessages() as $error): ?>
|
||||
<span class='errors sp-errors'>
|
||||
<?php echo $error; ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<br />
|
||||
</dd>
|
||||
<dd id='sp_limit-element'>
|
||||
<span class='sp_text_font'><?php echo $this->element->getElement('sp_limit_value')->getLabel() ?></span>
|
||||
<?php echo $this->element->getElement('sp_limit_value')?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue