function soundcloud_is_gold_add_user()
{
    if (isset($_POST['request'])) {
        $options = get_option('soundcloud_is_gold_options');
        if (isset($options['soundcloud_is_gold_users'])) {
            $return = 'error';
            //Check if username doesn't exist already and is not blank
            if (!empty($_POST['username']) && !array_key_exists($_POST['username'], $options['soundcloud_is_gold_users'])) {
                $newUsername = str_replace(" ", "-", trim($_POST['username']));
                //Get user info
                $userInfo = get_soundcloud_is_gold_api_response("http://api.soundcloud.com/users/" . $newUsername . ".xml?client_id=9rD2GrGrajkmkw5eYFDp2g");
                if (isset($userInfo) && isset($userInfo['response']->permalink)) {
                    $newUsername = (string) $userInfo['response']->permalink;
                    $newUsernameImg = (string) $userInfo['response']->{'avatar-url'}[0];
                    $return = '<li class="soundcloudIsGoldUserContainer" style="background-image:URL(' . $newUsernameImg . ')">';
                    $return .= '<span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>';
                    $return .= '<div>';
                    $return .= '<input type="hidden" value="' . $newUsername . '" name="soundcloud_is_gold_options[soundcloud_is_gold_users][' . $newUsername . '][0]" />';
                    $return .= '<input type="hidden" value="' . $newUsernameImg . '" name="soundcloud_is_gold_options[soundcloud_is_gold_users][' . $newUsername . '][1]" />';
                    $return .= '<p>' . $newUsername . '</p>';
                    $return .= '</div>';
                    $return .= '</li>';
                    //Tab: extra actions
                    if ($_POST['updateOption'] == '1') {
                        $options['soundcloud_is_gold_users'][$newUsername][0] = $newUsername;
                        $options['soundcloud_is_gold_users'][$newUsername][1] = $newUsernameImg;
                        update_option('soundcloud_is_gold_options', $options);
                    }
                }
            }
            echo $return;
        }
    }
    die;
}
function soundcloud_is_gold_options()
{
    $options = get_option('soundcloud_is_gold_options');
    //printl($options);
    $soundcloudIsGoldActiveUser = isset($options['soundcloud_is_gold_active_user']) ? $options['soundcloud_is_gold_active_user'] : '';
    $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? $options['soundcloud_is_gold_users'] : '';
    $soundcloudIsGoldSettings = isset($options['soundcloud_is_gold_settings']) ? $options['soundcloud_is_gold_settings'] : '';
    $soundcloudIsGoldPlayerType = isset($options['soundcloud_is_gold_playerType']) ? $options['soundcloud_is_gold_playerType'] : '';
    $soundcloudIsGoldPlayerTypeDefault = empty($soundcloudIsGoldPlayerType) ? TRUE : FALSE;
    $soundcloudIsGoldWidthSettings = isset($options['soundcloud_is_gold_width_settings']) ? $options['soundcloud_is_gold_width_settings'] : '';
    $soundcloudIsGoldClasses = isset($options['soundcloud_is_gold_classes']) ? $options['soundcloud_is_gold_classes'] : '';
    $soundcloudIsGoldColor = isset($options['soundcloud_is_gold_color']) ? $options['soundcloud_is_gold_color'] : '';
    $soundcloudIsGoldApiCall = 'http://api.soundcloud.com/users/' . $soundcloudIsGoldActiveUser . '/tracks.xml?limit=1&client_id=9rD2GrGrajkmkw5eYFDp2g';
    $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall);
    if (isset($soundcloudIsGoldApiResponse['response']) && $soundcloudIsGoldApiResponse['response']) {
        foreach ($soundcloudIsGoldApiResponse['response'] as $soundcloudMMLatestTrack) {
            $soundcouldMMId = (string) $soundcloudMMLatestTrack->id;
        }
    }
    $soundcouldMMShortcode = '[soundcloud id=' . $soundcouldMMId . ']';
    ?>
    
    <script type="text/javascript">
	//Set default Soundcloud Is Gold Settings
        <?php 
    get_soundcloud_is_gold_default_settings_for_js();
    ?>
    </script>
    
    <div class="soundcloudMMWrapper soundcloudMMOptions soundcloudMMMainWrapper">
        <div id="soundcloudMMTop" class="darkGreyGradient">
            <a id="soundcloudMMLogo" class="orangeGradient" href="http://www.soundcloud.com" title="visit SoundCloud website"><img src="<?php 
    echo SIG_PLUGIN_DIR;
    ?>
/images/soundcloud-logo-sc.png" width="107" height="71" alt="Soundcloud Logo"/></a>
            <a id="soundcloudMMHeader" class="mediumGreyGradient textShadow" href="http://www.mightymess.com/soundcloud-is-gold-wordpress-plugin" alt="Visit Mighty Mess for more cool stuff">
                <span class="soundcloudMMTitle">SoundCloud is gold <small>by Thomas Michalak</small></span>
                <span class="soundcloudMMUrl">www.mightymess.com/soundcloud-is-gold-wordpress-plugin</span>
            </a>
	    <p id="soundcloudMMVersion">version <?php 
    echo get_soundcloud_is_gold_version($options);
    ?>
</p>
        </div>
        
        <div id="soundcloudMMMain" class="lightBlueGradient">
            <form method="post" action="options.php" id="soundcloudMMMainForm" name="soundcloudMMMainForm" class="">
	    <p class="hidden soundcloudMMId" id="soundcloudMMId-<?php 
    echo $soundcouldMMId;
    ?>
"><?php 
    echo $soundcouldMMId;
    ?>
</p>
            <?php 
    settings_fields('soundcloud_is_gold_options');
    ?>
                <ul id="soundcloudMMSettings">
                    <!-- Username -->
		    <li class="soundcloudMMBox"><label class="optionLabel">User Name</label>
			<?php 
    get_soundcloud_is_gold_username_interface($options, $soundcloudIsGoldUsers);
    ?>
		    </li>
		    <!-- Default Settings -->
                    <li class="soundcloudMMBox"><label class="optionLabel">Default Settings</label>
                        <ul class="subSettings checkboxes">
                            <li><input type="checkbox" <?php 
    echo isset($soundcloudIsGoldSettings[0]) && $soundcloudIsGoldSettings[0] ? 'checked="checked"' : '';
    ?>
 name="soundcloud_is_gold_options[soundcloud_is_gold_settings][0]" value="true" class="soundcloudMMAutoPlay" id="soundcloudMMAutoPlay"/><label for="soundcloudMMAutoPlay">Play Automatically</label></li>
                            <li><input type="checkbox" <?php 
    echo isset($soundcloudIsGoldSettings[1]) && $soundcloudIsGoldSettings[1] ? 'checked="checked"' : '';
    ?>
 name="soundcloud_is_gold_options[soundcloud_is_gold_settings][1]" value="true" class="soundcloudMMShowComments" id="soundcloudMMShowComments"/><label for="soundcloudMMShowComments">Show comments <small>(Standard and Artwork player)</small></label></li>
			    <li><input type="checkbox" <?php 
    echo isset($soundcloudIsGoldSettings[2]) && $soundcloudIsGoldSettings[2] ? 'checked="checked"' : '';
    ?>
 name="soundcloud_is_gold_options[soundcloud_is_gold_settings][2]" value="true" class="soundcloudMMShowArtwork" id="soundcloudMMShowArtwork"/><label for="soundcloudMMShowArtwork">Show Artwork <small>(html5 player)</small></label></li>
                        </ul>
                    </li>
		    <!-- Player Type -->
                    <li class="soundcloudMMBox"><label class="optionLabel">Default Player Type</label>
                        <ul class="subSettings radios">
                            <?php 
    foreach (get_soundcloud_is_gold_player_types() as $type) {
        ?>
                                <li><input name="soundcloud_is_gold_options[soundcloud_is_gold_playerType]" id="<?php 
        echo $type;
        ?>
" class="soundcloudMMPlayerType" type="radio" value="<?php 
        echo $type;
        ?>
" <?php 
        if ($soundcloudIsGoldPlayerTypeDefault && $type == 'Standard') {
            echo 'checked="checked"';
        } else {
            echo $soundcloudIsGoldPlayerType === $type ? 'checked="checked"' : '';
        }
        ?>
 /><label for="<?php 
        echo $type;
        ?>
"><?php 
        echo $type;
        if ($type == 'Artwork') {
            echo ' <small>(not available on free soundcloud account)</small>';
        }
        if ($type == 'html5') {
            echo ' <small>new! (beta)</small>';
        }
        ?>
</label></li>
                            <?php 
    }
    ?>
                        </ul>
                    </li>
		    <!-- Width -->
                    <li class="soundcloudMMBox"><label class="optionLabel">Default Width</label>
                        <ul id="soundcloudMMWidthSetting" class="subSettings texts">
                            <li>
                                <input name="soundcloud_is_gold_options[soundcloud_is_gold_width_settings][type]" <?php 
    echo $soundcloudIsGoldWidthSettings['type'] == "wp" ? 'checked="checked"' : '';
    ?>
 id="soundcloudMMWpWidth" value="wp" type="radio" class="soundcloudMMWpWidth soundcloudMMWidthType radio"/><label for="soundcloudMMWpWidth">Media Width</label>
                                <select class="soundcloudMMInput soundcloudMMWidth" name="soundcloud_is_gold_options[soundcloud_is_gold_width_settings][wp]">
                                <?php 
    foreach (get_soundcloud_is_gold_wordpress_sizes() as $key => $soundcloudIsGoldMediaSize) {
        ?>
                                    <?php 
        //First Time, then Other Times
        if ($soundcloudIsGoldWidthSettings['wp'] == 'medium') {
            $soundcloudIsGoldMediaSelected = $key == $soundcloudIsGoldWidthSettings['wp'] ? 'selected="selected"' : '';
        } else {
            $soundcloudIsGoldMediaSelected = $soundcloudIsGoldMediaSize[0] == $soundcloudIsGoldWidthSettings['wp'] ? 'selected="selected"' : '';
        }
        ?>
                                    <option <?php 
        echo $soundcloudIsGoldMediaSelected;
        ?>
 value="<?php 
        echo $soundcloudIsGoldMediaSize[0];
        ?>
" class="soundcloudMMWpSelectedWidth"><?php 
        echo $key . ': ' . $soundcloudIsGoldMediaSize[0];
        ?>
</option>
                                <?php 
    }
    ?>
                                </select>
                            </li>
                            <li>
                                <input name="soundcloud_is_gold_options[soundcloud_is_gold_width_settings][type]" <?php 
    echo $soundcloudIsGoldWidthSettings['type'] == "custom" ? 'checked="checked"' : '';
    ?>
 id="soundcloudMMCustomWidth" value="custom" type="radio" class="soundcloudMMCustomWidth soundcloudMMWidthType radio"/><label for="soundcloudMMCustomWidth">Custom Width</label>
                                <input name="soundcloud_is_gold_options[soundcloud_is_gold_width_settings][custom]" id="soundcloudMMCustomSelectedWidth" class="soundcloudMMInput soundcloudMMWidth soundcloudMMCustomSelectedWidth" type="text" name="soundcloud_is_gold_options[soundcloudMMCustomSelectedWidth]" value="<?php 
    echo $soundcloudIsGoldWidthSettings['custom'];
    ?>
" />
                            </li>
                        </ul>
                    </li>
		    <!-- Color and Classes -->
                    <li class="soundcloudMMBox"><label class="optionLabel">Extras</label>
                        <ul class="subSettings texts">
                            <li>
                                <label>Color</label>
                                <div class="soundcloudMMColorPickerContainer" id="soundcloudMMColorPickerContainer">
                                    <input type="text" class="soundcloudMMInput soundcloudMMColor" id="soundcloudMMColor" name="soundcloud_is_gold_options[soundcloud_is_gold_color]" value="<?php 
    echo $soundcloudIsGoldColor;
    ?>
" style="background-color:<?php 
    echo $soundcloudIsGoldColor;
    ?>
"/><a href="#" class="soundcloudMMBt soundcloudMMBtSmall inline blue soundcloudMMRounder soundcloudMMResetColor">reset to default</a>
                                    <div id="soundcloudMMColorPicker" class="shadow soundcloudMMColorPicker"><div id="soundcloudMMColorPickerSelect" class="soundcloudMMColorPickerSelect"></div><a id="soundcloudMMColorPickerClose" class="blue soundcloudMMBt soundcloudMMColorPickerClose">done</a></div>
                                </div>
                            </li>
                            <li class="clear">
                                <label>Classes <small>(no commas)</small></label><input class="soundcloudMMInput soundcloudMMClasses" type="text" name="soundcloud_is_gold_options[soundcloud_is_gold_classes]" value="<?php 
    echo $soundcloudIsGoldClasses;
    ?>
" />
                            </li>
                        </ul>
                    </li>
		    <!-- Advance Options -->
		    <!-- <li class="hidden soundcloudMMBox"><label class="optionLabel">Advanced Options</label>
			<?php 
    //soundcloud_is_gold_advanced_options()
    ?>
		    </li> -->
		    <!-- Preview -->
                    <li class="soundcloudMMBox"><label class="optionLabel previewLabel">Live Preview <small>(your latest track)</small></label>
                        <?php 
    if ($soundcloudIsGoldApiResponse['response']) {
        ?>
                        <p class="soundcloudMMEmbed soundcloudMMEmbedOptions" style="text-align:center;">
			    <!-- Soundcloud Preview here -->
			</p>
                        <p class="soundcloudMMLoading soundcloudMMPreviewLoading" style="display:none"></p>
                        <?php 
    } else {
        ?>
                        <!-- Error getting XML -->
                        <div class="soundcloudMMXmlError"><p><?php 
        echo $soundcloudIsGoldApiResponse['error'] ? $soundcloudIsGoldApiResponse['error'] : "Oups! There's been a error while getting the tracks from soundcloud. Please reload the page.";
        ?>
</p></div>
                        <?php 
    }
    ?>
                    </li>
                </ul>
		<!-- Submit -->
                <p id="soundcloudMMSubmit"><input type="submit" name="Submit" value="<?php 
    _e('Save Your SoundCloud Settings');
    ?>
" class="soundcloudMMBt blue"/></p>
	    </form>
        </div>
            <ul id="soundcloudMMExtras" class="lightGreyGradient">
                <li><a href="http://soundcloud.com/t-m" title="TM's music on SoundCloud" class="soundcloudMMBt orangeGradient soundcloudMMRounder">TM on SoundCloud</a></li>
                <li><a href="http://www.mightymess.com" title="Thomas Michalak's Website" class="soundcloudMMBt orangeGradient soundcloudMMRounder">More Mighty Mess</a></li>
                <li><a href="http://wordpress.org/tags/soundcloud-is-gold?forum_id=10" title="Soundcloud is Gold Forum" class="soundcloudMMBt orangeGradient soundcloudMMRounder">Forum</a></li>
                <li>
                <form class="soundcloudMMBtForm" action="https://www.paypal.com/cgi-bin/webscr" method="post">
                        <input type="hidden" name="cmd" value="_s-xclick">
                        <input type="hidden" name="hosted_button_id" value="9VGA6PYQWETGY">
                        <input type="submit" name="submit" value="Donate via PayPal" class="soundcloudMMBt darkGrey soundcloudMMRounder" alt="PayPal - The safer, easier way to pay online.">
                        <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
                    </form>
                </li>
            </ul>
        <p id="disclaimer">SoundCloud and SoundCloud Logo are trademarks of SoundCloud Ltd.</p>
    </div>
    
    <?php 
}