Merge branch 'saas-dev-publishing' of https://github.com/sourcefabric/Airtime into saas-dev-publishing

This commit is contained in:
drigato 2015-09-15 14:07:59 -04:00
commit 73d154ba17
23 changed files with 492 additions and 338 deletions

View file

@ -31,6 +31,7 @@ require_once "Auth.php";
require_once "interface/OAuth2.php";
require_once "TaskManager.php";
require_once "UsabilityHints.php";
require_once "MediaType.php";
require_once __DIR__.'/models/formatters/LengthFormatter.php';
require_once __DIR__.'/services/CeleryService.php';
require_once __DIR__.'/services/SoundcloudService.php';

View file

@ -36,6 +36,8 @@ set_include_path(implode(PATH_SEPARATOR, array(
)));
set_include_path(APPLICATION_PATH . 'common' . PATH_SEPARATOR . get_include_path());
set_include_path(APPLICATION_PATH . 'common/enum' . PATH_SEPARATOR . get_include_path());
set_include_path(APPLICATION_PATH . 'common/interface' . PATH_SEPARATOR . get_include_path());
//Propel classes.
set_include_path(APPLICATION_PATH . 'models' . PATH_SEPARATOR . get_include_path());

View file

@ -0,0 +1,47 @@
<?php
/**
* Basic enumeration implementation; from http://stackoverflow.com/questions/254514/php-and-enumerations
*
* Class Enum
*/
abstract class Enum {
const __default = NULL;
private static $constCacheArray = NULL;
private function __construct() {}
private static function getConstants() {
if (self::$constCacheArray == NULL) {
self::$constCacheArray = [];
}
$calledClass = get_called_class();
if (!array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new ReflectionClass($calledClass);
self::$constCacheArray[$calledClass] = $reflect->getConstants();
}
return self::$constCacheArray[$calledClass];
}
public static function isValidName($name, $strict = false) {
$constants = self::getConstants();
if ($strict) {
return array_key_exists($name, $constants);
}
$keys = array_map('strtolower', array_keys($constants));
return in_array(strtolower($name), $keys);
}
public static function isValidValue($value) {
$values = array_values(self::getConstants());
return in_array($value, $values, $strict = true);
}
public static function getDefault() {
return static::__default;
}
}

View file

@ -0,0 +1,14 @@
<?php
require_once "Enum.php";
final class MediaType extends Enum {
const __default = self::FILE;
const FILE = 1;
const PLAYLIST = 2;
const BLOCK = 3;
const WEBSTREAM = 4;
const PODCAST = 5;
}

View file

@ -77,6 +77,19 @@ abstract class ThirdPartyController extends Zend_Controller_Action {
$this->_service->upload($id);
}
/**
* Download the file with the given id from a third-party service
*
* @return void
*
* @throws Zend_Controller_Response_Exception thrown if download fails for any reason
*/
public function downloadAction() {
$request = $this->getRequest();
$id = $request->getParam('id');
$this->_service->download($id);
}
/**
* Delete the file with the given id from a third-party service
*

View file

@ -66,22 +66,21 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
<a href="#"><?php echo _("Webstream") ?></a>
</li>
</ul>
<a href="/Plupload">
<a href="/plupload">
<button id="add_media_btn" class="btn btn-small dashboard-btn btn-new">
<span><?php echo _("Upload") ?></span>
</button>
</a>
</div>
<div class="media_type_selector top-link" data-selection-id="1">
<a href="/showbuilder#"><i class='icon-home icon-white'></i><?php echo _("Dashboard") ?></a></div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="1">
<a href="/showbuilder#tracks"><i class='icon-music icon-white'></i><?php echo _("Tracks") ?></a></div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="2">
<a href="/showbuilder#playlists"><i class='icon-list icon-white'></i><?php echo _("Playlists") ?></a></div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="3">
<a href="/showbuilder#smart-blocks"><i class='icon-time icon-white'></i><?php echo _("Smart Blocks") ?></a></div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="4">
<a href="/showbuilder#webstreams"><i class='icon-random icon-white'></i><?php echo _("Webstreams") ?></a></div>
<div class="media_type_selector top-link" data-selection-id="<?php echo MediaType::getDefault(); ?>">
<a href="/showbuilder#">
<i class='icon-home icon-white'></i>
<?php echo _("Dashboard") ?>
</a>
</div>
<?php $subnavPrefix = "/showbuilder"; require_once APPLICATION_PATH . "views/scripts/partialviews/dashboard-sub-nav.php"; ?>
<hr style="margin-left: 5px; margin-right: 5px">
<div id="nav">
<?php echo $this->navigation()->menu(); ?>
@ -90,7 +89,6 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
<?php
$partitions = Application_Model_Systemstatus::GetDiskInfo();
$status = new StdClass;
$partitions = $partitions;
$disk = $partitions[0];
$used = $disk->totalSpace-$disk->totalFreeSpace;
$total = $disk->totalSpace;

View file

@ -806,21 +806,17 @@ SQL;
$unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS";
//choose which table we need to select data from.
// TODO : use constants instead of numbers -- RG
switch ($type) {
case 0:
$fromTable = $unionTable;
break;
case 1:
case MediaType::FILE:
$fromTable = $fileTable." AS File"; //need an alias for the table if it's standalone.
break;
case 2:
case MediaType::PLAYLIST:
$fromTable = $plTable." AS Playlist"; //need an alias for the table if it's standalone.
break;
case 3:
case MediaType::BLOCK:
$fromTable = $blTable." AS Block"; //need an alias for the table if it's standalone.
break;
case 4:
case MediaType::WEBSTREAM:
$fromTable = $streamTable." AS StreamTable"; //need an alias for the table if it's standalone.
break;
default:

View file

@ -77,8 +77,7 @@ class CeleryService {
$c = self::_setupCeleryExchange($config, self::$_CELERY_RESULTS_EXCHANGE, $queue);
$message = $c->getAsyncResultMessage($task->getDbName(), $task->getDbTaskId());
// If the message isn't ready yet (Celery hasn't finished the task),
// only throw an exception if the message has timed out.
// If the message isn't ready yet (Celery hasn't finished the task), throw an exception.
if ($message == FALSE) {
if (self::_checkMessageTimeout($task)) {
// If the task times out, mark it as failed. We don't want to remove the

View file

@ -19,6 +19,7 @@ class SoundcloudService extends ThirdPartyCeleryService implements OAuth2 {
*/
protected static $_SERVICE_NAME = SOUNDCLOUD_SERVICE_NAME; // SoundCloud service name constant from constants.php
// TODO: Make these constants
/**
* @var string exchange name for SoundCloud tasks
*/
@ -29,6 +30,11 @@ class SoundcloudService extends ThirdPartyCeleryService implements OAuth2 {
*/
protected static $_CELERY_UPLOAD_TASK_NAME = 'soundcloud-upload';
/**
* @var string celery task name for third party uploads
*/
protected static $_CELERY_DOWNLOAD_TASK_NAME = 'soundcloud-download';
/**
* @var string celery task name for third party deletions
*/

View file

@ -14,6 +14,11 @@ abstract class ThirdPartyCeleryService extends ThirdPartyService {
*/
protected static $_CELERY_UPLOAD_TASK_NAME;
/**
* @var string celery task name for third-party uploads
*/
protected static $_CELERY_DOWNLOAD_TASK_NAME;
/**
* @var string celery task name for third-party deletion
*/
@ -41,6 +46,31 @@ abstract class ThirdPartyCeleryService extends ThirdPartyService {
}
}
/**
* Given a SoundCloud track identifier, download a track from SoundCloud.
*
* If no track identifier is given, download all tracks for the currently
* authenticated SoundCloud user.
*
* @param int|null $trackId a SoundCloud track identifier
*/
public function download($trackId = null) {
$namespace = new Zend_Session_Namespace('csrf_namespace');
$csrfToken = $namespace->authtoken;
$data = array(
'callback_url' => 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . '/media/post>csrf_token=' . $csrfToken,
'token' => $this->_accessToken,
'track_id' => $trackId
);
try {
CeleryService::sendCeleryMessage(static::$_CELERY_DOWNLOAD_TASK_NAME,
static::$_CELERY_EXCHANGE_NAME,
$data);
} catch (Exception $e) {
Logging::info("Invalid request: " . $e->getMessage());
}
}
/**
* Delete the file with the given identifier from a third-party service
*
@ -52,7 +82,7 @@ abstract class ThirdPartyCeleryService extends ThirdPartyService {
public function delete($fileId) {
$serviceId = $this->getServiceId($fileId);
if ($serviceId == 0) {
throw new ServiceNotFoundException("No service found for file with ID $fileId");
throw new ServiceNotFoundException("No service ID found for file with ID $fileId");
}
$data = array(
'token' => $this->_accessToken,

View file

@ -124,6 +124,13 @@ abstract class ThirdPartyService {
*/
abstract function upload($fileId);
/**
* Download the file with the given identifier from a third-party service
*
* @param int $trackId the third-party service track identifier
*/
abstract function download($trackId);
/**
* Delete the file with the given identifier from a third-party service
*

View file

@ -0,0 +1,30 @@
<div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::FILE ?>">
<a href="<?php echo $subnavPrefix; ?>#tracks">
<i class='icon-music icon-white'></i>
<span class="selector-name"><?php echo _("Tracks") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::PLAYLIST ?>">
<a href="<?php echo $subnavPrefix; ?>#playlists">
<i class='icon-list icon-white'></i>
<span class="selector-name"><?php echo _("Playlists") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::BLOCK ?>">
<a href="<?php echo $subnavPrefix; ?>#smart-blocks">
<i class='icon-time icon-white'></i>
<span class="selector-name"><?php echo _("Smart Blocks") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::WEBSTREAM ?>">
<a href="<?php echo $subnavPrefix; ?>#webstreams">
<i class='icon-random icon-white'></i>
<span class="selector-name"><?php echo _("Webstreams") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="<?php echo MediaType::PODCAST ?>">
<a href="<?php echo $subnavPrefix; ?>#podcasts">
<i class='icon-headphones icon-white'></i>
<span class="selector-name"><?php echo _("Podcasts") ?></span>
</a>
</div>

View file

@ -1,30 +1,7 @@
<div><!-- jQuery UI changes the styling on the outermost div; use a blank div so as not to break the .wrapper styling-->
<div class="wrapper">
<div id="media_selector_wrapper">
<div class="media_type_selector dashboard_sub_nav" data-selection-id="1">
<a href="#tracks">
<i class='icon-music icon-white'></i>
<span class="selector-name"><?php echo _("Tracks") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="2">
<a href="#playlists">
<i class='icon-list icon-white'></i>
<span class="selector-name"><?php echo _("Playlists") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="3">
<a href="#smart-blocks">
<i class='icon-time icon-white'></i>
<span class="selector-name"><?php echo _("Smart Blocks") ?></span>
</a>
</div>
<div class="media_type_selector dashboard_sub_nav" data-selection-id="4">
<a href="#webstreams">
<i class='icon-random icon-white'></i>
<span class="selector-name"><?php echo _("Webstreams") ?></span>
</a>
</div>
<?php $subnavPrefix = ""; require_once APPLICATION_PATH . "views/scripts/partialviews/dashboard-sub-nav.php"; ?>
</div>
<?php echo $this->csrf ?>

View file

@ -15,6 +15,7 @@
</div>
<div class="outer-datatable-wrapper">
<table id="library_display" cellpadding="0" cellspacing="0" class="datatable"></table>
<table id="podcast_table" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>
</div>