コード例 #1
0
/**
 * @package Newscoop
 * @subpackage Soundcloud plugin
 * @copyright 2011 Sourcefabric o.p.s.
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 */
function smarty_function_assign_soundcloud_tracks($p_params, &$p_smarty)
{
    $gimme = $p_smarty->get_template_vars('gimme');
    $article = empty($p_params['article']) ? $gimme->article->number : $p_params['article'];
    $length = empty($p_params['length']) ? 0 : (int) $p_params['length'];
    $order = empty($p_params['order']) ? 'asc' : $p_params['order'];
    $start = empty($p_params['start']) ? 0 : $p_params['start'];
    $current = empty($p_params['current']) ? 0 : $p_params['current'];
    $search = empty($p_params['search']) ? null : $p_params['search'];
    $api = empty($p_params['api']) ? false : true;
    $set = empty($p_params['set']) ? null : $p_params['set'];
    if (!$api) {
        $tracks = Soundcloud::getAssignments($article, $order, $start, $length);
    } else {
        require_once CS_PATH_PLUGINS . DIR_SEP . 'soundcloud' . DIR_SEP . 'classes' . DIR_SEP . 'soundcloud.api.php';
        $soundcloudAPI = new SoundcloudAPI();
        if ($set) {
            if ($set = $soundcloudAPI->setLoad($set)) {
                $tracks = $set['tracks'];
                if ($order == 'desc') {
                    $tracks = array_reverse($tracks);
                }
                for ($i = 0; $i < $start; $i++) {
                    array_shift($tracks);
                }
                if ($length) {
                    for ($i = sizeof($tracks); $i > $length; $i--) {
                        array_pop($tracks);
                    }
                }
            }
        } else {
            $tracks = $soundcloudAPI->trackSearch(array('order' => 'created_at', 'limit' => $length, 'offest' => $start, 'q' => $search));
        }
    }
    if (!empty($tracks)) {
        $soundcloud = new stdClass();
        $soundcloud->list = false;
        $soundcloud->track = empty($tracks[$current]) ? $tracks[0] : $tracks[$current];
        $soundcloud->total = sizeof($tracks);
        $soundcloud->tracks = $tracks;
        $p_smarty->assign('soundcloud', $soundcloud);
    } else {
        $p_smarty->assign('soundcloud', null);
    }
    return null;
}
コード例 #2
0
ファイル: controller.php プロジェクト: nidzix/Newscoop
$message = array();
$js = null;
$content = null;
$otherParams = array();
$soundcloud = new SoundcloudAPI();
$action = Input::Get('action', 'string', null);
$article = Input::Get('article', 'string', null);
$attachement = Input::Get('attachement', 'string', null) ? true : false;
$track = Input::Get('track', 'string', null);
if ($action == 'addtoset') {
    if (!$g_user->hasPermission('plugin_soundcloud_update')) {
        jsonOutput(null, array('title' => getGS('Error'), 'text' => getGS('You do not have the right to update SoundCloud tracks.'), 'type' => 'error'), null, array(), true);
        exit;
    }
    $set = Input::Get('set', 'string', null);
    if ($setTracks = $soundcloud->setLoad($set)) {
        $tracks = $setTracks['tracks'];
        $tracks[]['id'] = $track;
        $setTracks = array();
        $setTracks['id'] = $set;
        $setTracks['tracks'] = $tracks;
    }
    if (!$setTracks || !($result = $soundcloud->setUpdate($setTracks))) {
        jsonOutput(null, array('title' => getGS('SoundCloud reports an error:'), 'text' => $soundcloud->error, 'type' => 'error'));
    } else {
        jsonOutput(null, array(), null, array('ok' => true));
    }
}
if ($action == 'removefromset') {
    if (!$g_user->hasPermission('plugin_soundcloud_update')) {
        jsonOutput(null, array('title' => getGS('Error'), 'text' => getGS('You do not have the right to update SoundCloud tracks.'), 'type' => 'error'), null, array(), true);