Esempio n. 1
0
 public static function getInstance($sessionID = '')
 {
     if (!self::$instance instanceof GSAPI) {
         self::$instance = new GSAPI($sessionID);
     }
     return self::$instance;
 }
Esempio n. 2
0
 public static function doAuthentication($username, $password)
 {
     if (!$authenticated) {
         $resp = GSAPI::callRemote('startSession');
         $sessionId = $resp['sessionID'];
         GSAPI::setSessionID($sessionId);
         GSAPI::callRemote('authenticate', array('login' => $username, 'password' => $password));
         $authenticated = true;
     }
 }
Esempio n. 3
0
<?php

// JSON backend for getting song links for posts
// Load the API file
if (!class_exists('GSAPI')) {
    require_once "GSAPI.php";
}
if (isset($_POST['songID'])) {
    $gsapi = GSAPI::getInstance();
    print $gsapi->getSongUrl($_POST['songID']);
} else {
    print '';
}
Esempio n. 4
0
<?php

// JSON backend for search
require_once 'GSAPI.php';
// Gets a GSAPI object for API calls
$sessionID = '';
if (!empty($_POST['sessionID'])) {
    $sessionID = $_POST['sessionID'];
}
$gsapi = GSAPI::getInstance($sessionID);
if (isset($_POST['query'])) {
    $limit = 30;
    if (!empty($_POST['limit'])) {
        $limit = $_POST['limit'];
    }
    // Get the list of songs from the API search
    $songs = $gsapi->searchSongs($_POST['query'], $_POST['limit']);
    print "<table id='save-music-choice-search'>";
    if (isset($songs['error'])) {
        // There was an error getting songs
        print "<tr><td>Error Code {$songs['error']}. Please try again.</td></tr>";
    } else {
        // Set up different styles for different wp versions
        $altClass = $_POST['isVersion26'] == 'true' ? 'gsTr26' : 'gsTr27';
        $isSmallBox = $_POST['isSmallBox'] == 1 ? true : false;
        $stringLimit = $_POST['isVersion26'] == 1 ? 73 : 80;
        if (empty($songs)) {
            // No songs were found
            print "<tr class='gsTr1'><td>No Results Found by Grooveshark Plugin</td></tr>";
        } else {
            $index = 0;
Esempio n. 5
0
function grooveshark_options_page()
{
    $gsapi = GSAPI::getInstance();
    $sessionID = $gsapi->getSessionID();
    $errorCodes = array();
    $gs_options = get_option('gs_options');
    $settingsSaved = 0;
    // If the user wants to update the options...
    if (postHasValue('status', 'update') || postHasValue('Submit', 'Enter')) {
        $updateOptions = array();
        /* If a username and password was entered, checks to see if they are valid via the 
           session.loginViaAuthToken method. If they are valid, the userID and token are retrieved and saved. */
        if (isset($_POST['gs-username']) && $_POST['gs-username'] != '' && (isset($_POST['gs-password']) && $_POST['gs-password'] != '')) {
            $userID = 0;
            $username = $_POST['gs-username'];
            $password = $_POST['gs-password'];
            $token = md5($username . md5($password));
            $result = $gsapi->authenticateUser($username, $token);
            if ($result === true) {
                $userID = $gsapi->getUserID();
            } else {
                $errorCodes[] = 'Could not authenticate login information';
                $token = '';
                $username = '';
            }
            $updateOptions += array('userID' => $userID, 'token' => $token, 'username' => $username);
        }
        // Sets the number of songs the user wants to search for. If no number was enter, it just saved the default (30).
        $numberOfSongs = 30;
        if (isset($_POST['numberOfSongs'])) {
            $numberOfSongs = $_POST['numberOfSongs'];
        }
        $updateOptions += array('numberOfSongs' => $numberOfSongs);
        // Sets the display option for comment music
        if (isset($_POST['commentDisplayOption'])) {
            $updateOptions += array('commentDisplayOption' => $_POST['commentDisplayOption']);
        }
        // Set the widget width for comment widgets
        if (isset($_POST['commentWidgetWidth'])) {
            $commentWidgetWidth = $_POST['commentWidgetWidth'];
            if ($commentWidgetWidth < 150) {
                $commentWidgetWidth = 150;
            }
            if ($commentWidgetWidth > 1000) {
                $commentWidgetWidth = 1000;
            }
            $updateOptions += array('commentWidgetWidth' => $commentWidgetWidth);
        }
        if (isset($_POST['commentWidgetHeight'])) {
            $commentWidgetHeight = $_POST['commentWidgetHeight'];
            if ($commentWidgetHeight < 150 && $commentWidgetHeight != 0) {
                $commentWidgetHeight = 150;
            }
            if ($commentWidgetHeight > 1000) {
                $commentWidgetHeight = 1000;
            }
            $updateOptions += array('commentWidgetHeight' => $commentWidgetHeight);
        }
        if (isset($_POST['commentSongLimit'])) {
            $updateOptions += array('commentSongLimit' => $_POST['commentSongLimit']);
        }
        if (isset($_POST['commentDisplayPhrase'])) {
            $updateOptions += array('commentDisplayPhrase' => $_POST['commentDisplayPhrase']);
        }
        if (isset($_POST['commentPlaylistName'])) {
            $updateOptions += array('commentPlaylistName' => $_POST['commentPlaylistName']);
        }
        if (isset($_POST['commentColorScheme'])) {
            $commentColorScheme = $_POST['commentColorScheme'];
            if ($commentColorScheme < 0) {
                $commentColorScheme = 0;
            }
            if ($commentColorScheme > 22) {
                $commentColorScheme = 22;
            }
            $updateOptions += array('commentColorScheme' => $commentColorScheme);
        }
        $gs_options = array_merge($gs_options, $updateOptions);
        // Updates the options and lets the user know the settings were saved.
        update_option('gs_options', $gs_options);
        $settingsSaved = 1;
    }
    if (!postHasValue('Submit', 'Enter')) {
        print "<div class='updated'>";
        if (postHasValue('Status', 'Reset')) {
            // user wants to reset login information, destroy saved token and set userID, username, and user playlists to empty
            $updateArray = array('userID' => 0, 'token' => '', 'username' => '', 'userPlaylists' => array());
            $gs_options = array_merge($gs_options, $updateArray);
            update_option('gs_options', $gs_options);
            print "<p>Login information has been reset.</p>";
        }
        if (postHasValue('gsRssOption', 'Enable')) {
            // user wants to enable Grooveshark RSS
            $gs_options['gsRssOption'] = 1;
            print "<p>Grooveshark RSS Enabled</p>";
        } elseif (postHasValue('gsRssOption', 'Disable')) {
            // user wants to disable Grooveshark RSS
            $gs_options['gsRssOption'] = 0;
            print "<p>Grooveshark RSS Disabled</p>";
        }
        if (postHasValue('sidebarOptions', 'Clear')) {
            $gs_options['sidebarPlaylists'] = array();
            print "<p>Grooveshark Sidebar Cleared</p>";
        }
        if (postHasValue('dashboardOptions', 'Clear')) {
            $gs_options['dashboardPlaylists'] = array();
            print "<p>Grooveshark Dashboard Cleared</p>";
        }
        if (postHasValue('musicComments', 'Enable')) {
            $gs_options['musicComments'] = 1;
            print "<p>Music Comments Enabled</p>";
        } elseif (postHasValue('musicComments', 'Disable')) {
            $gs_options['musicComments'] = 0;
            print "<p>Music Comments Disabled</p>";
        }
        if ($settingsSaved) {
            print "<p>Settings Saved</p>";
        }
        print "</div>";
        update_option('gs_options', $gs_options);
    }
    // Prints all the inputs for the options page. Here, the login information, login reset option, search option, and number of songs can be set.
    print "\n    <form method=\"post\" action=\"\">\n        <div class=\"wrap\">\n            <h2>Grooveshark Plugin Options</h2>\n            <input type=\"hidden\" name=\"status\" value=\"update\">\n            <input type='hidden' name='sessionID' value='{$sessionID}'>\n            <fieldset>";
    print "<table class='form-table'>";
    if (count($errorCodes) > 0) {
        foreach ($errorCodes as $code) {
            print "<tr><td colspan='2'><b>Error Code {$code}. If this problem persists, you can e-mail roberto.sanchez@escapemg.com for support.</b></td></tr>";
        }
    }
    $userID = $gs_options['userID'];
    /* If the login failed, the user is notified. If no login information was saved, 
       then the user is reminded that they can enter their Grooveshark login information. */
    if ($userID == 0) {
        if ($userID == 0 && (isset($username) && $username != '' && (isset($password) && $password != ''))) {
            print "<tr><td colspan='2'><b>There was an error with your login information. Please try again.</b></td></tr>";
        } else {
            print "<tr><td colspan='2'>If you have a <a target='_blank' href='http://www.grooveshark.com'>Grooveshark</a> account, you can input your username and password information to access songs from your favorites list.</td></tr>";
        }
        // Displays the form to enter the login information.
        print "<tr><th><label for='gs-username'>Username: </label></th> <td><input type=\"text\" name=\"gs-username\" id='gs-username'> </td></tr>\n           <tr><th><label for='gs-password'>Password: </label></th> <td><input type=\"password\" name=\"gs-password\" id='gs-password'></td></tr>";
    } else {
        // Displays the form to reset the login information. Also displays an option to allow the user to choose whether
        // plugin-created playlists are attached to their Grooveshark account.
        print "<tr align=\"top\">\n           <th scope=\"row\"><label for='resetSong'>Reset your login information:</label></th>\n           <td class='submit'><input type='submit' name='Submit' value='Enter' style='display: none;' /><input type='submit' name='Status' id='resetSong' value='Reset' />&nbsp; Your login information has been saved. Click this button to reset your login information.</td></tr>";
    }
    $sidebarOption = $gs_options['sidebarPlaylists'];
    if (!empty($sidebarOption)) {
        // Display option to clear sidebar
        print "<tr align='top'>\n               <th scope='row'><label for='sidebarOptions'><input type='submit' name='Submit' value='Enter' style='display: none;' />\n               Clear Sidebar:\n               </label></th>\n               <td class='submit'><input type='submit' name='sidebarOptions' id='sidebarOptions' value='Clear' />&nbsp; Click this button to clear the Grooveshark Sidebar Widget.</td>";
    }
    $dashboardOption = $gs_options['dashboardPlaylists'];
    if (!empty($dashboardOption)) {
        // Display option to clear dashboard
        print "<tr align='top'>\n               <th scope='row'><label for='dashboardOptions'><input type='submit' name='Submit' value='Enter' style='display: none;' />\n               Clear Dashboard:\n               </label></th>\n               <td class='submit'><input type='submit' name='dashboardOptions' id='dashboardOptions' value='Clear' />&nbsp; Click this button to clear the Grooveshark Dashboard Widget.</td>";
    }
    $musicComments = $gs_options['musicComments'];
    print "<tr align='top'>\n           <th scope='row'><label for='musicComments'><input type='submit' name='Submit' value='Enter' style='display: none;' />\n           Allow Music Comments:\n           </label></th>";
    if ($musicComments) {
        print "<td class='submit'><input type='submit' name='musicComments' id='musicComments' value='Disable' />&nbsp; Click this button to disable music in readers' comments.</td>";
    } else {
        print "<td class='submit'><input type='submit' name='musicComments' id='musicComments' value='Enable' />&nbsp; Click this button to allow your blog readers to add music to their comments.</td>";
    }
    print "</tr>";
    if ($musicComments) {
        $commentDisplayOption = $gs_options['commentDisplayOption'];
        $commentWidget = '';
        $commentLink = '';
        if ($commentDisplayOption == 'widget') {
            $commentWidget = 'checked';
        } else {
            $commentLink = 'checked';
        }
        $commentWidgetWidth = $gs_options['commentWidgetWidth'];
        $commentWidgetHeight = $gs_options['commentWidgetHeight'];
        $commentSongLimit = $gs_options['commentSongLimit'];
        $commentDisplayPhrase = $gs_options['commentDisplayPhrase'];
        $commentPlaylistName = $gs_options['commentPlaylistName'];
        $commentColorScheme = $gs_options['commentColorScheme'];
        $colorsArray = array("Default", "Walking on the Sun", "Neon Disaster", "Golf Course", "Creamcicle at the Beach Party", "Toy Boat", "Wine and Chocolate Covered Strawberries", "Japanese Kite", "Eggs and Catsup", "Shark Bait", "Sesame Street", "Robot Food", "Asian Haircut", "Goth Girl", "I Woke Up And My House Was Gone", "Too Drive To Drunk", "She Said She Was 18", "Lemon Party", "Hipster Sneakers", "Blue Moon I Saw You Standing Alone", "Monkey Trouble In Paradise");
        print "<tr align='top'><th scope='row'><label for='commentDisplayOption'>Display Comment Music As:</label></th>\n                   <td><label>Widget &nbsp;<input type='radio' name='commentDisplayOption' value='widget' {$commentWidget} />&nbsp;</label><label> Link &nbsp;<input type='radio' name='commentDisplayOption' value='link' {$commentLink} /></label> &nbsp; Specify whether you want music in comments to be displayed as a link to Grooveshark or as a widget.</td>\n               </tr>";
        if ($commentDisplayOption == 'widget') {
            print "<tr align='top'><th scope='row'><label for='commentWidgetWidth'>Width for Comment Widgets:</label></th>\n                   <td><input type='text' name='commentWidgetWidth' value='{$commentWidgetWidth}' id='commentWidgetWidth'>&nbsp; Specify the width in pixels of widgets embeded in user comments.</td>\n               </tr> \n               <tr align='top'><th scope='row'><label for='commentWidgetHeight'>Height for Comment Widgets:</label></th>\n                   <td><input type='text' name='commentWidgetHeight' value='{$commentWidgetHeight}' id='commentWidgetHeight'>&nbsp; Specify the height in pixels of widgets embeded in user comments <b>(set to 0 for auto-adjustment)</b>.</td>\n               </tr>\n              <tr align='top'><th scope='row'><label for='commentSongLimit'>Comment Song Limit:</label></th>\n                   <td><input type='text' name='commentSongLimit' value='{$commentSongLimit}' id='commentSongLimit'>&nbsp; Specify a limit on how many songs a user may embed as a widget in comments <b>(set to 0 for no limit)</b>.</td>\n               </tr>\n               <tr align='top'><th scope='row'><label for='commentColorScheme'>Color Scheme for Comment Widgets:</label></th>\n                   <td><select type='text' id='commentColorScheme' name='commentColorScheme'>";
            foreach ($colorsArray as $id => $colorOption) {
                print "<option value='{$id}' ";
                if ($id == $commentColorScheme) {
                    print "selected='selected' ";
                }
                print ">{$colorOption}</option>";
            }
            print "&nbsp; Specify the color scheme of widgets embeded in user comments.</td>\n                </tr>";
        } else {
            print "<tr align='top'><th scope='row'><label for='commentDisplayPhrase'>Display Phrase for Comment Music Links:</label></th>\n                   <td><input type='text' name='commentDisplayPhrase' value='{$commentDisplayPhrase}' id='commentDisplayPhrase'>&nbsp; Used in song links. Example: <b>{$commentDisplayPhrase}</b>: {$commentPlaylistName}</td>\n               </tr>\n               <tr align='top'><th scope='row'><label for='commentPlaylistName'>Comment Playlist Names:</label></th>\n                   <td><input type='text' name='commentPlaylistName' value='{$commentPlaylistName}' id='commentPlaylistName'>&nbsp; Used in songs links. Example: {$commentDisplayPhrase}: <b>{$commentPlaylistName}</b></td>\n               </tr>";
        }
    }
    // Finished displaying the form for search options, and displays the form to enter how many songs to search for.
    print "<tr align=\"top\"> <th scope=\"row\"><label for='numberOfSongs'>Number of Results:</label></th>";
    $numberOfSongs = $gs_options['numberOfSongs'];
    print "<td><input type=\"text\" name=\"numberOfSongs\" value=\"{$numberOfSongs}\" id='numberOfSongs'>&nbsp; Specify how many songs or playlists you want the\n           search to return.<input type='submit' name='Submit' value='Enter' style='display: none;' /></td></tr>";
    /*
    // Finished displaying the form for number of results, and displays the form for javascript insertion
    print "<tr align='top'><th scope='row'><label for='javascriptInsertLocation'>Insert Javascript in:</label></th>";
    $javascriptPos = $gs_options['javascriptPos'];
    $jsHead = $javascriptPos == 'head' ? 'checked' : '';
    $jsFoot = $javascriptPos == 'foot' ? 'checked' : '';
    print "<td><label>Header &nbsp;<input type='radio' name='javascriptPosOption' value='head' $jsHead />&nbsp;</label><label> Footer &nbsp;<input type='radio' name='javascriptPosOption' value='foot' $jsFoot /></label> &nbsp; Specify where you want the plugin to insert plugin javascript. Select Footer for faster load time.</td></tr>";
    */
    // Finished displaying the form for javascript insertion, and displays the form for rss
    print "<tr align='top'><th scope='row'><label for='gsRssOption'>Enable Grooveshark RSS:</label></th>";
    $gsRssOption = $gs_options['gsRssOption'];
    if ($gsRssOption) {
        print "<td class='submit'><input type='submit' name='gsRssOption' id='gsRssOption' value='Disable' /> &nbsp; Click this button to disable the Grooveshark RSS feature.</td>";
    } else {
        print "<td class='submit'><input type='submit' name='gsRssOption' id='gsRssOption' value='Enable' /> &nbsp; Grooveshark RSS is disabled by default due to incompatibilities with certain wordpress installations. Click to enable.</td>";
    }
    print "</tr>";
    // Finished displaying all forms, and then ends.
    print "</table><p class='submit'><input type=\"submit\" name=\"Submit\" value=\"Update Options\"></p>\n          </div>\n          </form>";
}
<?php

// JSON backend for getting playlist links for posts
// Load the API file
if (!class_exists('GSAPI')) {
    require_once "GSAPI.php";
}
if (!isset($_POST['username']) && !isset($_POST['token'])) {
    print "You must be logged in to create playlist links. You can log in at the plugin settings page.";
} else {
    if (isset($_POST['sessionID']) && isset($_POST['songIDs'])) {
        $gsapi = GSAPI::getInstance($_POST['sessionID']);
        if ($gsapi->getUserID() == 0) {
            // user not logged in, authenticate
            $gsapi->authenticateUser($_POST['username'], $_POST['token']);
        }
        $playlistName = isset($_POST['playlistName']) ? $_POST['playlistName'] : 'Songs for ' . date('M j');
        $displayPhrase = isset($_POST['displayPhrase']) ? $_POST['displayPhrase'] : 'Grooveshark Playlist';
        $songsArray = explode('::', $_POST['songIDs']);
        if (count($songsArray) < 1) {
            //No songs provided, return nothing
            print 'There was an error getting your songs. Please try again.';
        } else {
            $playlistID = $gsapi->playlistCreate($playlistName, $songsArray);
            if ($playlistID <= 0) {
                if ($playlistID == -1) {
                    $playlistName .= ' ' . date('M j - H:i');
                    $playlistID = $gsapi->playlistCreate($playlistName, $songsArray);
                    if ($playlistID > 0) {
                        $playlistUrl = $gsapi->getPlaylistUrl($playlistID);
                        print "<a href='{$playlistUrl}' target='_blank'>{$displayPhrase}: {$playlistName}</a>";