/**
  * Settings Page
  * Adds Admin Menu Item via WordPress' "Administration Menus" API. Also hook actions to register options via WordPress' Settings API.
  */
 static function admin_load()
 {
     register_setting(SnS_Admin::OPTION_GROUP, 'SnS_options');
     add_settings_section('global_styles', __('Blog Wide CSS Styles', 'scripts-n-styles'), array(__CLASS__, 'global_styles_section'), SnS_Admin::MENU_SLUG);
     add_settings_section('global_scripts', __('Blog Wide JavaScript', 'scripts-n-styles'), array(__CLASS__, 'global_scripts_section'), SnS_Admin::MENU_SLUG);
     add_settings_field('less', __('<strong>LESS:</strong> ', 'scripts-n-styles'), array(__CLASS__, 'less_fields'), SnS_Admin::MENU_SLUG, 'global_styles', array('label_for' => 'less'));
     add_settings_field('coffee', __('<strong>CoffeeScript:</strong> ', 'scripts-n-styles'), array(__CLASS__, 'coffee_fields'), SnS_Admin::MENU_SLUG, 'global_scripts', array('label_for' => 'coffee'));
     add_settings_field('styles', __('<strong>CSS Styles:</strong> ', 'scripts-n-styles'), array('SnS_Form', 'textarea'), SnS_Admin::MENU_SLUG, 'global_styles', array('label_for' => 'styles', 'setting' => 'SnS_options', 'class' => 'code css', 'wrap_class' => 'style', 'rows' => 5, 'cols' => 40, 'style' => 'min-width: 500px; width:97%;', 'description' => __('<span class="description" style="max-width: 500px; display: inline-block;">The "Styles" will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles')));
     add_settings_field('scripts_in_head', __('<strong>Scripts</strong><br />(for the <code>head</code> element): ', 'scripts-n-styles'), array('SnS_Form', 'textarea'), SnS_Admin::MENU_SLUG, 'global_scripts', array('label_for' => 'scripts_in_head', 'setting' => 'SnS_options', 'class' => 'code js', 'wrap_class' => 'script', 'rows' => 5, 'cols' => 40, 'style' => 'min-width: 500px; width:97%;', 'description' => __('<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts (in head)" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags in the <code>&lt;head></code> element of your html.</span>', 'scripts-n-styles')));
     add_settings_field('scripts', __('<strong>Scripts</strong><br />(end of the <code>body</code> tag):', 'scripts-n-styles'), array('SnS_Form', 'textarea'), SnS_Admin::MENU_SLUG, 'global_scripts', array('label_for' => 'scripts', 'setting' => 'SnS_options', 'class' => 'code js', 'wrap_class' => 'script', 'rows' => 5, 'cols' => 40, 'style' => 'min-width: 500px; width:97%;', 'description' => __('<span class="description" style="max-width: 500px; display: inline-block;">The "Scripts" will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the bottom of the <code>&lt;body></code> element of your html.</span>', 'scripts-n-styles')));
     add_settings_field('enqueue_scripts', __('<strong>Enqueue Scripts</strong>: ', 'scripts-n-styles'), array('SnS_Form', 'select'), SnS_Admin::MENU_SLUG, 'global_scripts', array('label_for' => 'enqueue_scripts', 'setting' => 'SnS_options', 'choices' => Scripts_n_Styles::get_wp_registered(), 'size' => 5, 'style' => 'height: auto;', 'multiple' => true, 'show_current' => __('Currently Enqueued Scripts: ', 'scripts-n-styles')));
     add_filter('sns_options_pre_update_option', array(__CLASS__, 'enqueue_scripts'), 10, 5);
 }
    /**
     * Admin Action: 'add_meta_boxes'
     * Outputs the Meta Box. Only called on callback from add_meta_box() during the add_meta_boxes action.
     * @param unknown_type WordPress Post object.
     */
    static function admin_meta_box($post)
    {
        $registered_handles = Scripts_n_Styles::get_wp_registered();
        $SnS = get_post_meta($post->ID, '_SnS', true);
        $styles = isset($SnS['styles']) ? $SnS['styles'] : array();
        $scripts = isset($SnS['scripts']) ? $SnS['scripts'] : array();
        $position = get_user_option("current_sns_tab");
        if (!in_array($position, array('s0', 's1', 's2', 's3', 's4', 's5'))) {
            $position = 's0';
        }
        wp_nonce_field(Scripts_n_Styles::$file, self::NONCE_NAME);
        ?>
			<ul class="wp-tab-bar">
				<li<?php 
        echo 's0' == $position ? ' class="wp-tab-active"' : '';
        ?>
><a href="#SnS_scripts-tab"><?php 
        _e('Scripts', 'scripts-n-styles');
        ?>
</a></li>
				<li<?php 
        echo 's1' == $position ? ' class="wp-tab-active"' : '';
        ?>
><a href="#SnS_styles-tab"><?php 
        _e('Styles', 'scripts-n-styles');
        ?>
</a></li>
				<li<?php 
        echo 's2' == $position ? ' class="wp-tab-active"' : '';
        ?>
><a href="#SnS_classes_body-tab"><?php 
        _e('Classes', 'scripts-n-styles');
        ?>
</a></li>
				<li<?php 
        echo 's3' == $position ? ' class="wp-tab-active"' : '';
        ?>
><a href="#SnS_enqueue_scripts-tab"><?php 
        _e('Include Scripts', 'scripts-n-styles');
        ?>
</a></li>
				<li<?php 
        echo 's4' == $position ? ' class="wp-tab-active"' : '';
        ?>
><a href="#SnS_shortcodes-tab"><?php 
        _e('Shortcodes', 'scripts-n-styles');
        ?>
</a></li>
				<li<?php 
        echo 's5' == $position ? ' class="wp-tab-active"' : '';
        ?>
 style="display:none"><a href="#SnS_post_styles-tab"><?php 
        _e('Dropdown', 'scripts-n-styles');
        ?>
</a></li>
			</ul>

			<div class="wp-tab-panel" id="SnS_scripts-tab">
				<p><em><?php 
        _e("This code will be included <strong>verbatim</strong> in <code>&lt;script></code> tags at the end of your page's (or post's)", 'scripts-n-styles');
        ?>
 ...</em></p>
				<label for="SnS_scripts_in_head" class="title"><?php 
        _e('<strong>Scripts</strong> (for the <code>head</code> element):', 'scripts-n-styles');
        ?>
 </label>
				<div class="script">
				<textarea class="codemirror js" name="SnS_scripts_in_head" id="SnS_scripts_in_head" rows="5" cols="40" style="width: 98%;"><?php 
        echo isset($scripts['scripts_in_head']) ? esc_textarea($scripts['scripts_in_head']) : '';
        ?>
</textarea>
				</div>
				<p><em>... <code>&lt;/head></code> <?php 
        _e('tag', 'scripts-n-styles');
        ?>
.</em></p>
				<label for="SnS_scripts" class="title"><strong>Scripts</strong>: </label>
				<div class="script">
				<textarea class="codemirror js" name="SnS_scripts" id="SnS_scripts" rows="5" cols="40" style="width: 98%;"><?php 
        echo isset($scripts['scripts']) ? esc_textarea($scripts['scripts']) : '';
        ?>
</textarea>
				</div>
				<p><em>... <code>&lt;/body></code> <?php 
        _e('tag', 'scripts-n-styles');
        ?>
.</em></p>
			</div>

			<div class="wp-tab-panel" id="SnS_styles-tab">
				<label for="SnS_styles" class="title"><?php 
        _e('<strong>Styles</strong>:', 'scripts-n-styles');
        ?>
 </label>
				<div class="style">
				<textarea class="codemirror css" name="SnS_styles" id="SnS_styles" rows="5" cols="40" style="width: 98%;"><?php 
        echo isset($styles['styles']) ? esc_textarea($styles['styles']) : '';
        ?>
</textarea>
				</div>
				<p><em><?php 
        _e('This code will be included <strong>verbatim</strong> in <code>&lt;style></code> tags in the <code>&lt;head></code> tag of your page (or post).', 'scripts-n-styles');
        ?>
</em></p>
			</div>

			<div class="wp-tab-panel" id="SnS_classes_body-tab">
				<strong class="title"><?php 
        _e('Classes', 'scripts-n-styles');
        ?>
</strong>
				<div id="sns-classes">
					<p>
						<label for="SnS_classes_body"><?php 
        _e('<strong>Body Classes</strong>:', 'scripts-n-styles');
        ?>
 </label>
						<input name="SnS_classes_body" id="SnS_classes_body" type="text" class="code" style="width: 99%;"
							value="<?php 
        echo isset($styles['classes_body']) ? esc_attr($styles['classes_body']) : '';
        ?>
" />
					</p>
					<p>
						<label for="SnS_classes_post"><strong>Post Classes</strong>: </label>
						<input name="SnS_classes_post" id="SnS_classes_post" type="text" class="code" style="width: 99%;"
							value="<?php 
        echo isset($styles['classes_post']) ? esc_attr($styles['classes_post']) : '';
        ?>
" />
					</p>
					<p><em><?php 
        _e('These <strong>space separated</strong> class names will be added to the <code>body_class()</code> or <code>post_class()</code> function (provided your theme uses these functions).', 'scripts-n-styles');
        ?>
</em></p>
				</div>
			</div>
				<?php 
        /*
         * Note: Styles Dropdown section only makes sense when Javascript is enabled. (Otherwise, no TinyMCE.)
         */
        ?>
			<div class="wp-tab-panel" id="SnS_post_styles-tab" style="display: none;">
				<strong class="title"><?php 
        _e('Post Styles', 'scripts-n-styles');
        ?>
</strong>
				<div id="mce-dropdown-names">
					<h4><?php 
        _e('The Styles Dropdown', 'scripts-n-styles');
        ?>
</h4>
					<div id="add-mce-dropdown-names">
						<p><?php 
        _e('Add (or update) a class for the "Styles" drop-down:', 'scripts-n-styles');
        ?>
</p>
						<p class="sns-mce-title">
							<label for="SnS_classes_mce_title"><?php 
        _e('Title:', 'scripts-n-styles');
        ?>
</label>
							<input name="SnS_classes_mce_title" id="SnS_classes_mce_title"
								value="" type="text" class="code" style="width: 80px;" />
						</p>
						<p class="sns-mce-type">
							<label for="SnS_classes_mce_type"><?php 
        _e('Type:', 'scripts-n-styles');
        ?>
</label>
							<select name="SnS_classes_mce_type" id="SnS_classes_mce_type" style="width: 80px;">
								<option value="inline"><?php 
        _ex('Inline', 'css type', 'scripts-n-styles');
        ?>
</option>
								<option value="block"><?php 
        _ex('Block', 'css type', 'scripts-n-styles');
        ?>
</option>
								<option value="selector"><?php 
        _ex('Selector:', 'css type', 'scripts-n-styles');
        ?>
</option>
							</select>
						</p>
						<p class="sns-mce-element">
							<label for="SnS_classes_mce_element"><?php 
        _e('Element:', 'scripts-n-styles');
        ?>
</label>
							<input name="SnS_classes_mce_element" id="SnS_classes_mce_element"
								value="" type="text" class="code" style="width: 80px;" />
						</p>
						<p class="sns-mce-classes">
							<label for="SnS_classes_mce_classes"><?php 
        _e('Classes:', 'scripts-n-styles');
        ?>
</label>
							<input name="SnS_classes_mce_classes" id="SnS_classes_mce_classes"
								value="" type="text" class="code" style="width: 80px;" />
						</p>
						<p class="sns-mce-wrapper" style="display: none;">
							<label for="SnS_classes_mce_wrapper"><?php 
        _e('Wrapper:', 'scripts-n-styles');
        ?>
</label>
							<input name="SnS_classes_mce_wrapper" id="SnS_classes_mce_wrapper" type="checkbox" value="true" />
						</p>
					</div>

					<div id="delete-mce-dropdown-names" style="display: none;">
						<p id="instructions-mce-dropdown-names"><?php 
        _e('Classes currently in the dropdown:', 'scripts-n-styles');
        ?>
</p>
					</div>
				</div>
			</div>

			<div class="wp-tab-panel" id="SnS_enqueue_scripts-tab">
				<strong class="title">Include Scripts</strong>
				<select name="SnS_enqueue_scripts[]" id="SnS_enqueue_scripts" size="5" multiple="multiple" style="height: auto; float: left; margin: 6px 10px 8px 0;">
					<?php 
        if (!empty($scripts['enqueue_scripts']) && is_array($scripts['enqueue_scripts'])) {
            foreach ($registered_handles as $value) {
                ?>
							<option value="<?php 
                echo esc_attr($value);
                ?>
"<?php 
                foreach ($scripts['enqueue_scripts'] as $handle) {
                    selected($handle, $value);
                }
                ?>
><?php 
                echo esc_html($value);
                ?>
</option>
						<?php 
            }
        } else {
            foreach ($registered_handles as $value) {
                ?>
							<option value="<?php 
                echo esc_attr($value);
                ?>
"><?php 
                echo esc_html($value);
                ?>
</option>
						<?php 
            }
        }
        ?>
				</select>
				<?php 
        if (!empty($scripts['enqueue_scripts']) && is_array($scripts['enqueue_scripts'])) {
            ?>
					<p><?php 
            _e('Currently Enqueued Scripts:', 'scripts-n-styles');
            ?>
					<?php 
            foreach ($scripts['enqueue_scripts'] as $handle) {
                echo '<code>' . esc_html($handle) . '</code> ';
            }
            ?>
					</p>
				<?php 
        }
        ?>
				<p><em><?php 
        _e('The chosen scripts will be enqueued and placed before your codes if your code is dependant on certain scripts (like jQuery).', 'scripts-n-styles');
        ?>
</em></p>
			</div>

			<div class="wp-tab-panel" id="SnS_shortcodes-tab">
				<strong class="title">Shortcodes</strong>
				<div id="sns-add-shortcode">
					<?php 
        $meta_name = 'SnS_shortcodes';
        $SnS = get_post_meta($post->ID, '_SnS', true);
        $shortcodes = isset($SnS['shortcodes']) ? $SnS['shortcodes'] : array();
        ?>
					<label for="<?php 
        echo $meta_name;
        ?>
">Name: </label>
					<input id="<?php 
        echo $meta_name;
        ?>
" name="<?php 
        echo $meta_name . '[new][name]';
        ?>
" type="text" />
					<textarea id="<?php 
        echo $meta_name;
        ?>
_new" class="codemirror htmlmixed" name="<?php 
        echo $meta_name . '[new][value]';
        ?>
" rows="5" cols="40" style="width: 98%;"></textarea>
				</div>
				<div id="sns-shortcodes">
					<h4>Existing Codes: </h4>
					<div id="sns-shortcodes-wrap">
					<?php 
        if (!empty($shortcodes)) {
            ?>
						<?php 
            foreach ($shortcodes as $key => $value) {
                ?>
							<div class="sns-shortcode widget"><div class="inside">
							<p>[hoops name="<?php 
                echo $key;
                ?>
"]</p>
							<textarea class="codemirror htmlmixed" data-sns-shortcode-key="<?php 
                echo $key;
                ?>
" name="<?php 
                echo $meta_name . '[existing][' . $key . ']';
                ?>
" rows="5" cols="40" style="width: 98%;"><?php 
                echo esc_textarea($value);
                ?>
</textarea>
							</div></div>
						<?php 
            }
            ?>
					<?php 
        }
        ?>
					</div>
				</div>
			</div>
		<?php 
    }
            }
        }
    }
    /**
     * Utility Method: Compares VERSION to stored 'version' value.
     */
    static function upgrade_check()
    {
        $options = get_option('SnS_options');
        if (!isset($options['version']) || version_compare(self::VERSION, $options['version'], '>')) {
            include_once 'includes/class-sns-admin.php';
            SnS_Admin::upgrade();
        }
    }
}
Scripts_n_Styles::init();
class SnS_Widget extends WP_Widget
{
    function __construct()
    {
        $widget_ops = array('classname' => 'sns_widget_text', 'description' => __('Arbitrary text or HTML (including "hoops" shortcodes)', 'scripts-n-styles'));
        $control_ops = array('width' => 400, 'height' => 350);
        parent::__construct('sns_hoops', __('Hoops', 'scripts-n-styles'), $widget_ops, $control_ops);
    }
    function widget($args, $instance)
    {
        global $shortcode_tags;
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        $text = apply_filters('widget_text', empty($instance['text']) ? '' : $instance['text'], $instance);
        echo $before_widget;