/**
 * @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;
}
Exemplo n.º 2
0
 protected function publishToSoundcloud(array $new_mp3s)
 {
     if (is_null(SC_TOKEN) && is_null(SC_TOKEN_SECRET)) {
         $soundcloud = new Soundcloud(SC_CONSUMER_KEY, SC_CONSUMER_SECRET);
         $token = $soundcloud->get_request_token('http://a.callback.url.com/');
         echo ">> Your SC_TOKEN is : " . $token['oauth_token'] . "\n";
         echo ">> Your SC_TOKEN_SECRET is : " . $token['oauth_token_secret'] . "\n";
         $login = $soundcloud->get_authorize_url($token['oauth_token']);
         echo ">> Please fill in the file, and visit {$login}\n";
         return;
     } else {
         $sc = new Soundcloud(SC_CONSUMER_KEY, SC_CONSUMER_SECRET, SC_TOKEN, SC_TOKEN_SECRET);
         foreach ($new_mp3s as $item) {
             /* @var $item SimplePie_Item */
             /* @var $mp3 SimplePie_Enclosure */
             $mp3 = $item->get_enclosure(0);
             $title = $item->get_title();
             echo "Publishing {$title}...\n";
             $filename = basename($this->getLinkFromItem($item));
             $post_data = array('track[title]' => $item->get_title(), 'track[asset_data]' => $filename, 'track[sharing]' => 'private', 'track[description]' => strip_tags($item->get_description()));
             $sc->upload_track($post_data);
         }
     }
 }
Exemplo n.º 3
0
            $track['release_year'] = $aMatch[1];
            $track['release_month'] = $aMatch[2];
            $track['release_day'] = $aMatch[3];
        }
        if (!empty($_FILES['artwork_data']['name']) && empty($_FILES['artwork_data']['error'])) {
            $track['artwork_data'] = '@' . $_FILES['artwork_data']['tmp_name'];
        }
        $result = $soundcloud->trackUpdate($track);
        if (empty($result['id'])) {
            jsonOutput(null, array('title' => getGS('Save error'), 'text' => getGS('SoundCloud reports an error:') . $soundcloud->error, 'type' => 'error'), null, array(), true);
            exit;
        } else {
            if ($attach) {
                $soundcloudAttach = new Soundcloud((int) $article, (int) $track['id']);
                $soundcloudAttach->delete();
                $soundcloudAttach = new Soundcloud();
                if (!$soundcloudAttach->create((int) $article, (int) $track['id'], $result)) {
                    jsonOutput(null, array('title' => getGS('Attach error'), 'text' => getGS('Error during create attachement'), 'type' => 'error'), null, array(), true);
                    exit;
                }
                $messageTitle = getGS('Save and attach successful');
            } else {
                $messageTitle = getGS('Save successful');
            }
            jsonOutput(null, array('title' => $messageTitle, 'text' => getGS('Track has been updated on SoundCloud'), 'type' => 'success'), null, array('ok' => true), false);
        }
    }
    exit;
}
if ($action == 'search') {
    $trackListParams = array('order' => 'created_at', 'offset' => $offset, 'limit' => $limit);
Exemplo n.º 4
0
            }
            
            .errorMesg {
                font-weight: bold;
                color: #ff0000;
            }
        </style>
    </head>
    <?php 
if ($_POST && $_GET) {
    require_once 'config.php';
    require_once 'api/soundcloud.php';
    require_once 'api/classes/db.inc.php';
    require_once 'api/classes/battle.inc.php';
    require_once 'api/classes/pattern.inc.php';
    $soundcloud = new Soundcloud(SOUNDCLOUD_API_CLIENT_ID, SOUNDCLOUD_API_CLIENT_SECRET, SOUNDCLOUD_API_REDIRECT_URL);
    $accessToken = $soundcloud->accessToken($_GET['code']);
    $title = isset($_POST['title']) ? $_POST['title'] : "";
    $description = isset($_POST['description']) ? $_POST['description'] : "";
    $downloadable = isset($_POST['downloadable']) ? "true" : "false";
    if ($title) {
        $user = '******';
        $sequence = $_SESSION['sequenceArr'];
        $hash = md5($user . $sequence + rand());
        $shareUrl = APP_URL . "?p=" . $hash;
        $options = array("asset_data" => "@" . APP_PATH . $_SESSION['soundcloud_tmp_file'], "title" => $title, "description" => $description . "\n<a href='{$shareUrl}'>{$shareUrl}</a>", "sharing" => "public", "streamable" => "true", "downloadable" => $downloadable);
        //UPLOAD TRACK TO SOUNDCLOUD
        $result = $soundcloud->execute('tracks.json', 'track', 'POST', $options, 'multipart/form-data');
        $permalink = $result->permalink_url;
        //ADD NEWLY UPLOADED TRACK INFO TO DB
        //$tracks = $soundcloud->execute('groups/20839/tracks?format=json', '', 'GET');
Exemplo n.º 5
0
 /**
  * Track search
  */
 private function tracksearch()
 {
     Base::requireLogged();
     $ret = array('status' => 0);
     if (!$_GET['q']) {
         return $ret;
     }
     // Filter search
     $query = Base::searchQuery($_GET['q']);
     if (!$query) {
         return $ret;
     }
     // Get tracks
     $tracks = Track::filter('bySearchQuery', $query)->paginate(-1, 6);
     if ($tracks['num'] <= 6 || $_GET['page'] === '2' && $tracks['num'] <= 12) {
         $query = str_replace('%', ' ', $query);
         $rows = Soundcloud::search($query);
         $rows = array_slice($rows, 0, 6);
         $tracks = array('rows' => $rows);
     }
     $ret['tracks'] = $tracks;
     $ret['status'] = isset($tracks['rows']) && !!$tracks['rows'];
     // // Get favourite tracks
     // $favTracks = $tracks->select('t.*')
     //     ->join('track_fav', 'tf.track_id = t.id', 'tf')
     //     ->where('tf.user_id', LOGGED)
     //     ->where('tf.active', 1)
     //     ->paginate();
     // $ret['fav_tracks'] = $favTracks;
     return $ret;
 }
Exemplo n.º 6
0
});
</script>

<div class="articlebox" title="Soundcloud">

<? if (($f_edit_mode == "edit") && $g_user->hasPermission('plugin_soundcloud_browser')): ?>
    <a id="soundcloud-iframe" custom="yes" class="iframe ui-state-default icon-button right-floated" href="<?php 
echo "/{$ADMIN}/soundcloud/attachement.php?article_id={$f_article_number}";
?>
"><span class="ui-icon ui-icon-plusthick"></span><? putGS('Attach') ?></a>
    <div class="clear"></div>
<? endif ?>


<ul class="block-list">
<? foreach (Soundcloud::getAssignments($f_article_number) as $trackData): ?>
<li id="soundcloud-<?php 
echo $trackData['id'];
?>
">
    <div><a class="text-link" target="soundcloud" href="<?php 
echo $trackData['permalink_url'];
echo $trackData['sharing'] == 'public' ? '' : '/' . $trackData['secret_token'];
?>
"><?php 
echo $trackData['title'];
?>
</a></div>
    <object height="81" width="100%"><param name="movie" value="http://player.soundcloud.com/player.swf?url=<?php 
echo urlencode($trackData['secret_uri']);
?>
Exemplo n.º 7
0
        if (preg_match('!(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)!', $track['release_date'], $aMatch)) {
            $track['release_year'] = $aMatch[1];
            $track['release_month'] = $aMatch[2];
            $track['release_day'] = $aMatch[3];
        }
        $result = $soundcloud->trackUpload($track);
        if (!$result) {
            $showMessage = array('title' => getGS('Upload error'), 'message' => getGS('SoundCloud reports an error:') . ' ' . $soundcloud->error, 'type' => 'error', 'fixed' => 'true');
        } else {
            $showMessage = array('title' => getGS('Upload successful'), 'message' => getGS('Track $1 has been uploaded to SoundCloud. Click to close', $result['id']), 'type' => 'success', 'fixed' => 'true');
            $track = array();
            if ($action == 'attach') {
                $article = Input::Get('article_id', 'string', null);
                $soundcloudAttach = new Soundcloud((int) $article, (int) $track);
                $soundcloudAttach->delete();
                $soundcloudAttach = new Soundcloud();
                if ($soundcloudAttach->create((int) $article, (int) $result['id'], $result)) {
                    $js = 'parent.$.fancybox.reload = true;';
                }
            }
        }
    }
}
$trackListParams = array('order' => 'created_at', 'offset' => 0, 'limit' => $limit);
$trackList = $soundcloud->trackSearch($trackListParams);
$attached = array();
if ($article) {
    $attachments = Soundcloud::getAssignments($article);
    foreach ($attachments as $value) {
        $attached["{$value['id']}"] = $value['id'];
    }
Exemplo n.º 8
0
    if ($outFormat == "mp3") {
        $mimeType = "audio/mpeg";
        $mp3File = $fileDir . $outFileName . ".mp3";
        system('lame -h -b192 --cbr --nogap ' . $outFile . ' ' . $mp3File);
        unlink($outFile);
        $outFile = $mp3File;
    }
    if (!isset($soundcloud)) {
        header('Content-Description: File Transfer');
        header('Content-Type: ' . $mimeType);
        header('Content-Disposition: download; filename="' . $downloadFileName . '"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($outFile));
        ob_clean();
        flush();
        readfile($outFile);
        unlink($outFile);
    } else {
        //If a soundcloud temporary file exists, delete it.
        if (isset($_SESSION['soundcloud_tmp_file']) && is_file($_SESSION['soundcloud_tmp_file'])) {
            unlink($_SESSION['soundcloud_tmp_file']);
        }
        $_SESSION['soundcloud_tmp_file'] = $outFile;
        $_SESSION['sequenceArr'] = $_REQUEST['sequence'];
        $soundcloud = new Soundcloud(SOUNDCLOUD_API_CLIENT_ID, SOUNDCLOUD_API_CLIENT_SECRET, SOUNDCLOUD_API_REDIRECT_URL);
        echo $soundcloud->getAuthorizeUrl() . "&display=popup";
    }
}
Exemplo n.º 9
0
<?php

require_once '../../../config.php';
require_once '../../../api/soundcloud.php';
require_once '../../../api/classes/db.inc.php';
require_once '../../../api/classes/battle.inc.php';
if (isset($_REQUEST['cmd'])) {
    $cmd = $_REQUEST['cmd'];
} else {
    echo "No command specified.";
    return false;
}
if ($cmd == "sync") {
    $soundcloud = new Soundcloud(SOUNDCLOUD_API_CLIENT_ID, SOUNDCLOUD_API_CLIENT_SECRET, SOUNDCLOUD_API_REDIRECT_URL);
    $tracks = $soundcloud->execute('groups/20839/tracks?consumer_key=' . SOUNDCLOUD_API_CLIENT_ID . '&format=json', '', 'GET');
    $battleObj = new Battle();
    $battleObj->syncTracks($tracks);
    echo loadBattle();
} else {
    if ($cmd == "vote" && $_POST) {
        $postArr = $_POST;
        $battleObj = new Battle();
        $battleObj->voteOnTrack($postArr);
        echo loadBattle();
    } else {
        if ($cmd == "load") {
            echo loadBattle();
        } else {
            echo "Invalid command.";
            return false;
        }
Exemplo n.º 10
0
                    $message = 'Success! <a href="' . $response['permalink-url'] . '">Your track</a> has been uploaded!';
                    // Delete the temporary file.
                    unlink(realpath($tmp_file));
                } else {
                    $message = 'Something went wrong while talking to SoundCloud, please try again.';
                }
            } else {
                $message = 'Couldn\'t move file, make sure the temporary path is writable by the server.';
            }
        } else {
            $message = 'SoundCloud support .mp3, .aiff, .wav, .flac, .aac, and .ogg files. Please select a different file.';
        }
    }
} else {
    // This is the first step in the "OAuth dance" where we ask the visitior to authicate himself.
    $soundcloud = new Soundcloud($consumer_key, $consumer_secret);
    $token = $soundcloud->get_request_token($callback_url);
    $_SESSION['oauth_request_token'] = $token['oauth_token'];
    $_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];
    $login = $soundcloud->get_authorize_url($token['oauth_token']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>SoundCloud PHP API Wrapper</title>
    <meta name="author" content="Anton Lindqvist" />
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.7.0/build/reset/reset-min.css" />