/** * Sanitize the settings before saving * * @since 1.0.0 */ public function sanitize_podcasting_settings($input) { $new_input = array(); if (isset($input['soundcloud_client_id'])) { $new_input['soundcloud_client_id'] = sanitize_text_field($input['soundcloud_client_id']); } if (isset($input['soundcloud_client_secret'])) { $new_input['soundcloud_client_secret'] = sanitize_text_field($input['soundcloud_client_secret']); } if (isset($input['soundcloud_redirect_uri'])) { $new_input['soundcloud_redirect_uri'] = sanitize_text_field($input['soundcloud_redirect_uri']); } if (isset($input['soundcloud_user_id'])) { $new_input['soundcloud_user_id'] = absint($input['soundcloud_user_id']); } if (isset($input['soundcloud_access_code'])) { require_once plugin_dir_path(__FILE__) . '../public/assets/php-soundcloud-master/Services/Soundcloud.php'; $options = get_option('hbi_soundcloud_podcasts_settings'); $client = new Services_Soundcloud($options['soundcloud_client_id'], $options['soundcloud_client_secret'], $options['soundcloud_redirect_uri']); try { $new_input['soundcloud_access_token'] = $client->accessToken($input['soundcloud_access_code']); } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { exit($e->getMessage()); } } return $new_input; }
protected function completeAuthToken() { $api = new Services_Soundcloud($this->userid, $this->secret, $this->getRedirectUri()); $token = $api->accessToken($this->authcode); $this->authtoken = $token['access_token']; debug_event('soundcloud_catalog', 'SoundCloud authentication token generated for userid ' . $this->userid . '.', 1); $sql = 'UPDATE `catalog_soundcloud` SET `authtoken` = ? WHERE `catalog_id` = ?'; Dba::write($sql, array($this->authtoken, $this->catalog_id)); }
function wp_scu_authenticate() { //get soundcloud options $sc_options = get_option('soundcloud_settings'); if ($sc_options) { $sc_id = $sc_options['sc_client_id']; $sc_secret = $sc_options['sc_client_secret']; $sc_token = $sc_options['sc_client_access_token']; $sc_redirect_uri = $sc_options['sc_redirect_uri']; } $soundcloud = new Services_Soundcloud($sc_id, $sc_secret, $sc_redirect_uri); if (!$sc_token) { $params = array('scope' => 'non-expiring'); $authorizeUrl = $soundcloud->getAuthorizeUrl($params); echo '<br /><a id="scu_connect_url" style="border-style:solid; padding:5px; border-color:orange;" href="' . $authorizeUrl . '">Click Here To Connect To SoundCloud</a>'; try { //TODO: tighten up code - use isset to check if "code" param below exists $post_data = array(); $curl_opts = array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false); $accessToken = $soundcloud->accessToken($_GET['code'], $post_data, $curl_opts); echo scu_jquery_snippet(); } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { //exit($e->getMessage()); echo '<div style="color:red;"><p><strong>SoundCloud Ultimate Error: Could not process the request - Error code (' . $e->getHttpCode() . ').</strong></p></div>'; return; } //var_dump($accessToken); //store the token in tyhe options $sc_redirect_uri = site_url() . '/wp-admin/admin.php?page=wpshq_scu_plugin_options'; $param = array('sc_client_id' => $sc_id, 'sc_client_secret' => $sc_secret, 'sc_client_access_token' => $accessToken['access_token'], 'sc_redirect_uri' => $sc_redirect_uri); update_option('soundcloud_settings', $param); //store the results in WP options table $soundcloud->setAccessToken($accessToken['access_token']); } else { if ($sc_token) { $soundcloud->setAccessToken($sc_token); } } }
$authorizeUrl = $soundcloud->getAuthorizeUrl(); ?> <a class="login"href="<?php echo $authorizeUrl; ?> ">Connect to Souncloud</a> <?php try { // if(!isset($_SESSION['token'])) // { // print_r($_SESSION); $accessToken = $soundcloud->accessToken($_GET['code']); // $_SESSION['token'] = $accessToken['access_token']; // } // else // { // print_r($_SESSION); // $soundcloud->setAccessToken($_SESSION['token']); // print_r($accessToken); // } echo '<pre>'; } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { exit($e->getMessage()); } try { $me = json_decode($soundcloud->get('me'), true); print_r($me);
require 'Soundcloud.php'; // credentials for new instance of services soundcloud require 'credScUser.php'; //create new instance $scUser = new Services_Soundcloud(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); //get oauth code $authorizeUrl = $scUser->getAuthorizeUrl(); echo "<pre>"; echo "<a href='{$authorizeUrl}'> Connect with SoundCloud</a><br>"; //set session to token returned from array try { //check if SESSION is set to access token returned from sc. will only work if code is returned in URL if (!isset($_SESSION['token'])) { /*Obtain 'code' in order to request a access token. input this into function. * returns array which includes access token*/ $accessToken = $scUser->accessToken($_GET['code']); //set SESSION to access token(from accesstoken array) $_SESSION['token'] = $accessToken['access_token']; } else { /*set our classes accesstoken property to the session data(set after following initial connect to soundcloud link) this will happen on refresh of page */ $scUser->setAccessToken($_SESSION['token']); } } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { exit($e->getMessage()); } //run search $username = '******'; $tracksSearchQ = json_decode($scUser->get('tracks', array('q' => $username)), true); //print_r($tracksSearchQ);
function sc_render_manager_page() { require_once plugin_dir_path(__FILE__) . 'includes/Services/Soundcloud.php'; require_once plugin_dir_path(__FILE__) . 'includes/class/pagination.class.php'; $options = get_option('sc_options'); $client = new Services_Soundcloud($options['client_id'], $options['client_secret'], $options['callback_url']); // Error message if app settings are not filled in. if ($options['client_id'] == "Your client ID goes here" || $options['client_secret'] == "Your client secret goes here" || $options['callback_url'] == "Your callback url goes here") { echo '<div class="error fade"><p>Warning: One or more of the required fields have not been set. Please insure that your cliend ID, client secret, and callback url are defined <a href="' . admin_url('options-general.php?page=soundcloud/soundcloud.php') . '">HERE</a>.</br>Soundcloud functionality will not be available until these fields are set.</p></div></br>'; } // SoundCloud login/logout if (isset($_GET['code']) || get_option('soundcloud_access_token')) { echo '<a href="' . admin_url('admin.php?page=soundcloud-disconnect') . '" class="soundcloud-icon"><img src="' . plugins_url() . '/soundcloud/includes/images/btn-disconnect-l.png" alt="Disconnect"/></a>'; try { $client = new Services_Soundcloud($options['client_id'], $options['client_secret'], $options['callback_url']); if (isset($_GET['code'])) { $accessToken = $client->accessToken($_GET['code']); update_option('soundcloud_access_token', $accessToken['access_token']); update_option('soundcloud_refresh_token', $accessToken['refresh_token']); update_option('soundcloud_token_expiration', time() + $accessToken['expires_in']); } else { if (get_option('soundcloud_access_token')) { // refresh token code deprecated due to non-expiring tokens /*if (time() > get_option('soundcloud_token_expiration')) { $client->setAccessToken(get_option('soundcloud_access_token')); // refresh access token $accessToken = $client->accessTokenRefresh(get_option('soundcloud_refresh_token')); //$client->setAccessToken($accessToken['access_token']); update_option('soundcloud_access_token', $accessToken['access_token']); update_option('soundcloud_refresh_token', $accessToken['refresh_token']); update_option('soundcloud_token_expiration', time() + $accessToken['expires_in']); } else {*/ $client->setAccessToken(get_option('soundcloud_access_token')); //} } } } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { var_dump($e->getMessage()); exit; } } else { echo '<a href="' . $client->getAuthorizeUrl(array('scope' => 'non-expiring')) . '" class="soundcloud-icon"><img src="' . plugins_url() . '/soundcloud/includes/images/btn-connect-sc-l.png" alt="Connect with Soundcloud"/></a>'; } // tab switching if (isset($_GET['tab'])) { sc_admin_tabs($_GET['tab']); $tab = $_GET['tab']; } else { sc_admin_tabs('user'); $tab = 'user'; } if (get_option('soundcloud_access_token')) { try { $me = json_decode($client->get('me'), true); } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { var_dump($e->getMessage()); exit; } echo '<h3>Logged in as: ' . $me['username'] . '</h3>'; } else { echo '<h3>Not logged in.</h3>'; } switch ($tab) { case 'user': try { $me = json_decode($client->get('me'), true); ?> <form action="" method="post"> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="username">Username:</label></th> <td><input type="text" name="username" value="<?php echo $me['username']; ?> " size="30" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="permalink">Permalink:</label></th> <td><input type="text" name="permalink" value="<?php echo $me['permalink']; ?> " size="30" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="description">Description:</label></th> <td><input type="text" name="description" value="<?php echo $me['description']; ?> " size="30" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="website">Website:</label></th> <td><input type="text" name="website" value="<?php echo $me['website']; ?> " size="30" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="website_title">Website Name:</label></th> <td><input type="text" name="website_title" value="<?php echo $me['website_title']; ?> " size="30" class="regular-text code"></td> </tr> </table> <p class="submit"><input type="submit" value="Update Account" class="button-primary"></p> </form> <?php if (isset($_POST['username']) || isset($_POST['permalink']) || isset($_POST['description']) || isset($_POST['website']) || isset($_POST['website_title'])) { $response = json_decode($client->put('me', array('user[username]' => $_POST['username'], 'user[permalink]' => $_POST['permalink'], 'user[description]' => $_POST['description'], 'user[website]' => strlen($_POST['website']) ? $_POST['website'] : null, 'user[website_title]' => strlen($_POST['website_title']) ? $_POST['website_title'] : null))); } } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { var_dump($e->getMessage()); exit; } break; case 'upload': ?> <form action="" enctype="multipart/form-data" method="post" id ="add_track"> <table class="form-table"> <tr valign="top"> <th scope="row"><label for="track_title">Track title:</label></th> <td><input type="text" name="track_title" size="30" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="track_file">Please specify a track:</label></th> <td><input type="file" name="track_file" id="track_file" size="40" accept="audio/*" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="track_art">Please specify track artwork:</label></th> <td><input type="file" name="track_art" id="track_art" size="40" accept="image/*" class="regular-text code"></td> </tr> <tr valign="top"> <th scope="row"><label for="tag">Track tags:</label></th> <td><input type="text" name="tag" id="tag" size="30"><input type="button" id="add_tag" name="add_tag" class="button" value="Add Tag" /> <br><ul id="tags"></ul></td> </tr> <tr valign="top"> <th scope="row"><label for="sharing">Track privacy:</label></th> <td><select name="sharing"> <option value="public">Public</option> <option value="private">Private</option> </select></td> </tr> </table> <p class="submit"><input type="submit" value="Upload" class="button-primary"></p> </form> <?php try { $tmp_file = '/tmp/' . stripslashes($_FILES['track_file']['name']); $tmp_art_file = '/tmp/' . stripslashes($_FILES['track_art']['name']); if (move_uploaded_file($_FILES['track_file']['tmp_name'], $tmp_file) && move_uploaded_file($_FILES['track_art']['tmp_name'], $tmp_art_file)) { // upload audio file $track = json_decode($client->post('tracks', array('track[title]' => $_POST['track_title'], 'track[asset_data]' => '@' . $tmp_file, 'track[artwork_data]' => '@' . $tmp_art_file, 'track[tags]' => strlen($_POST['tags']) ? $_POST['tags'] : null, 'track[sharing]' => $_POST['sharing']))); unlink(realpath($tmp_file)); unlink(realpath($tmp_art_file)); } } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { var_dump($e->getMessage()); exit; } break; case 'tracks': try { echo '</br>'; $page_size = 5; // Pagination code $p = new pagination(); $p->items($me['track_count']); $p->limit($page_size); // Limit entries per page $p->target("admin.php?page=soundcloud-manager&tab=tracks"); $p->currentPage($_GET[$p->paging]); // Gets and validates the current page $p->calculate(); // Calculates what to show $p->parameterName('paging'); $p->adjacents(1); //No. of page away from the current page if (!isset($_GET['paging'])) { $p->page = 1; } else { $p->page = $_GET['paging']; } if ($p->page == 1) { // get first page of tracks $tracks = json_decode($client->get('users/' . $me['id'] . '/tracks', array('order' => 'created_at', 'limit' => $page_size))); } else { // get additional pages of tracks $tracks = json_decode($client->get('users/' . $me['id'] . '/tracks', array('order' => 'created_at', 'limit' => $page_size, 'offset' => $page_size * $page))); } ?> <div class="tablenav"> <div class='tablenav-pages'> <?php echo $p->show(); ?> </div> </div> <?php foreach ($tracks as $track) { $client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => 1)); $embed_info = json_decode($client->get('oembed', array('url' => $track->permalink_url))); // render the html for the player widget echo $embed_info->html . '</br></br>'; } } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { var_dump($e->getMessage()); exit; } break; } }