function sp_get_themes()
{
    $sf_themes = array();
    $theme_root = untrailingslashit(SPTHEMEBASEDIR);
    $themes_dir = @opendir($theme_root);
    $theme_files = array();
    if ($themes_dir) {
        while (($file = readdir($themes_dir)) !== false) {
            # themes must be in subdir
            if (is_dir($theme_root . '/' . $file)) {
                $themes_subdir = @opendir($theme_root . '/' . $file);
                if ($themes_subdir) {
                    while (($subfile = readdir($themes_subdir)) !== false) {
                        if ($subfile == 'spTheme.txt') {
                            $theme_files[] = "{$file}";
                        }
                    }
                }
            }
        }
    } else {
        return $sf_themes;
    }
    @closedir($themes_dir);
    @closedir($themes_subdir);
    if (empty($theme_files)) {
        return $sf_themes;
    }
    foreach ($theme_files as $theme_file) {
        if (!is_readable("{$theme_root}/{$theme_file}/spTheme.txt")) {
            continue;
        }
        $theme_data = sp_get_theme_data("{$theme_root}/{$theme_file}/spTheme.txt");
        if (empty($theme_data['Name'])) {
            continue;
        }
        $sf_themes[sp_theme_basename($theme_file)] = $theme_data;
    }
    uasort($sf_themes, create_function('$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"]);'));
    return $sf_themes;
}
 function theme_info($theme = null)
 {
     if (empty($theme)) {
         if (!empty($this->result['destination_name'])) {
             $theme = $this->result['destination_name'];
         } else {
             return false;
         }
     }
     return sp_get_theme_data($theme);
 }
function sp_load_plugin_styles($ahahCall = false)
{
    global $spCSSLoaded, $spDevice, $spPaths, $spGlobals;
    if (!sp_get_option('sfwpheadbypass') && $spCSSLoaded) {
        return;
    }
    $curTheme = $spGlobals['theme'];
    $curTheme = apply_filters('sph_theme', $curTheme);
    $vars = '';
    $overlay = '';
    # handle chiild themes
    $parentTheme = !empty($curTheme['parent']) ? sp_get_theme_data(SPTHEMEBASEDIR . $curTheme['parent'] . '/spTheme.txt') : '';
    # handle color overlays
    if (current_theme_supports('sp-theme-child-overlays')) {
        # can use - so might be - a child theme overlay
        $overlay = !empty($curTheme['color']) ? $curTheme['color'] : '';
        if (!empty($parentTheme) && !empty($curTheme['color'])) {
            # must be a child with an overlay selected so...
            # is the overlay in the child theme or not?
            if (file_exists(SPTHEMEBASEDIR . $curTheme['theme'] . '/styles/overlays/' . $curTheme['color'] . '.php')) {
                $theme = $curTheme['theme'];
            } elseif (!empty($curTheme['color'])) {
                $theme = $curTheme['parent'];
            }
        } else {
            $theme = $curTheme['theme'];
        }
    } else {
        # no support for child overlays so do it the old eway
        $overlay = !empty($curTheme['color']) ? $curTheme['color'] : '';
        if (!empty($parentTheme) && !empty($curTheme['color'])) {
            $theme = $curTheme['parent'];
        } else {
            $theme = $curTheme['theme'];
        }
    }
    $vars = !empty($overlay) ? '?overlay=' . esc_attr($overlay) . '&theme=' . esc_attr($theme) : '';
    # add device query var string
    $vars = !empty($vars) ? "{$vars}&device={$spDevice}" : "?device={$spDevice}";
    # set the images path array
    sp_set_image_array($curTheme);
    $spCSSLoaded = true;
    # if called from the AHAH/AJAX init routine then leave now...
    if ($ahahCall) {
        return;
    }
    # handle RTL
    if (is_rtl()) {
        $vars = !empty($vars) ? "{$vars}&rtl=1" : '?rtl=1';
    }
    $reset = is_rtl() ? 'reset.rtl.css' : 'reset,css';
    # enqueue the main theme css
    if (sp_is_plugin_active('user-selection/sp-user-selection-plugin.php')) {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                wp_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            wp_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                wp_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            wp_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        wp_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            wp_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    } else {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                sp_plugin_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            sp_plugin_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                sp_plugin_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            sp_plugin_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        sp_plugin_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            sp_plugin_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    }
    # concat (if needed) and enqueue the plugin css
    do_action('sph_print_plugin_styles');
    $combine_css = sp_get_option('combinecss');
    if ($combine_css) {
        sp_combine_plugin_css_files();
    } else {
        global $sp_plugin_styles;
        if (!empty($sp_plugin_styles)) {
            foreach ($sp_plugin_styles->queue as $handle) {
                wp_enqueue_style($handle, $sp_plugin_styles->registered[$handle]->src);
            }
        }
    }
    do_action('sph_styles_end');
}
function sp_load_plugin_styles()
{
    $curTheme = sp_get_current_sp_theme();
    # get optional color variant to pass to stylesheet
    $curTheme = apply_filters('sph_theme', $curTheme);
    # handle chiild themes
    $parentTheme = !empty($curTheme['parent']) ? sp_get_theme_data(SPTHEMEBASEDIR . $curTheme['parent'] . '/spTheme.txt') : '';
    # handle color overlays
    $vars = !empty($curTheme['color']) ? '?color=' . esc_attr($curTheme['color']) : '';
    # handle RTL
    if (is_rtl()) {
        $vars = !empty($vars) ? "{$vars}&rtl=1" : '?rtl=1';
    }
    $reset = is_rtl() ? 'reset.rtl.css' : 'reset,css';
    # enqueue the main theme css
    if (sp_is_plugin_active('user-selection/sp-user-selection-plugin.php')) {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                wp_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            wp_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                wp_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            wp_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        wp_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            wp_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    } else {
        if (!empty($parentTheme)) {
            $cssTheme = strpos($parentTheme['Stylesheet'], '.css') ? true : false;
            if ($cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/' . $reset)) {
                sp_plugin_enqueue_style('sp-parent-reset', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $reset);
            }
            sp_plugin_enqueue_style('sp-parent', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/' . $parentTheme['Stylesheet'] . $vars);
            if (is_rtl() && $cssTheme && file_exists(SPTHEMEBASEDIR . $curTheme['parent'] . '/styles/rtl.css')) {
                sp_plugin_enqueue_style('sp-parent-rtl', SPTHEMEBASEURL . $curTheme['parent'] . '/styles/rtl.css');
            }
        }
        $cssTheme = strpos(SPTHEMECSS, '.css') ? true : false;
        if ($cssTheme && file_exists(SPTHEMEDIR . $reset)) {
            sp_plugin_enqueue_style('sp-theme-reset', SPTHEMECSSEXTRA . $reset);
        }
        sp_plugin_enqueue_style('sp-theme', SPTHEMECSS . $vars);
        if (is_rtl() && $cssTheme && file_exists(SPTHEMEDIR . 'rtl.css')) {
            sp_plugin_enqueue_style('sp-theme-rtl', SPTHEMECSSEXTRA . 'rtl.css');
        }
    }
    # concat (if needed) and enqueue the plugin css
    do_action('sph_print_plugin_styles');
    $combine_css = sp_get_option('combinecss');
    if ($combine_css) {
        sp_combine_plugin_css_files();
    } else {
        global $sp_plugin_styles;
        if (!empty($sp_plugin_styles)) {
            foreach ($sp_plugin_styles->queue as $handle) {
                wp_enqueue_style($handle, $sp_plugin_styles->registered[$handle]->src);
            }
        }
    }
    do_action('sph_styles_end');
}