Exemplo n.º 1
0
function ttw_do_admin()
{
    /* theme admin page */
    /* This generates the startup script calls, etc, for the admin page */
    global $ttw_optionsList, $ttw_myoptionsList, $ttw_options, $ttw_adminOpts, $ttw_adminOptsDefault, $ttw_optionsListDefault;
    if (!current_user_can('edit_theme_options')) {
        wp_die("No permission to access that page.");
    }
    $ttw_dir = get_template_directory_uri();
    /* PROCESS $_POST VALUES FROM FORM SUBMISSION FIRST */
    /* First, process any actions from the buttons */
    if (ttw_submitted('saveoptions')) {
        // These options are defined in the Main Options form, and should all set
        // the default value when no value is set from the form.
        echo '<div id="message" class="updated fade"><p><strong>' . __("Twenty Ten Weaver main options saved.", TTW_TRANS) . '</strong></p></div>';
        foreach ($ttw_options as $value) {
            /* only reset main options so use $ttw_options */
            $id = $value['id'];
            $type = $value['type'];
            if ($type == 'ctext') {
                if (isset($_POST[$id])) {
                    // do the color part
                    $v = ttw_esc_code($_POST[$id]);
                    ttw_setopt($id, $v);
                } else {
                    ttw_defaultopt($id);
                }
                $css_id = $id . '_css';
                if (isset($_POST[$css_id])) {
                    // do the CSS part
                    $v = ttw_esc_code($_POST[$css_id]);
                    if (strpos($v, '{') === false && strlen($v) > 0) {
                        ttw_setopt($css_id, '{' . $v . '}');
                        // tricky - allows them to add multiple rules, or sub-rules
                    } else {
                        ttw_setopt($css_id, $v);
                    }
                } else {
                    ttw_setopt($css_id, '/* NO OPTION SET*/');
                }
            } else {
                if (isset($_POST[$id])) {
                    $v = ttw_esc_code($_POST[$id]);
                    ttw_setopt($id, $v);
                } else {
                    ttw_defaultopt($id);
                }
            }
        }
        ttw_saveopts();
    }
    if (ttw_submitted('saveadvanced')) {
        echo '<div id="message" class="updated fade"><p><strong>' . __("Twenty Ten Weaver advanced options saved.", TTW_TRANS) . '</strong></p></div>';
        // THEME OPTS - advanced  theme opts - unlike the options from the Main Options form,
        // these options don't have default values, and thus use the ttw_post_xxx functions.
        ttw_post_opt('ttw_head_opts');
        ttw_post_opt('ttw_theme_head_opts');
        ttw_post_opt('ttw_footer_opts');
        ttw_post_opt('ttw_header_insert');
        ttw_post_opt_html('ttw_preheader_insert');
        ttw_post_opt_html('ttw_prefooter_insert');
        ttw_post_opt_html('ttw_postfooter_insert');
        ttw_post_opt_html('ttw_postheader_insert');
        ttw_post_opt_html('ttw_presidebar_insert');
        ttw_post_opt_html('ttw_custom_header_insert');
        ttw_post_opt('ttw_header_frontpage_only');
        ttw_post_opt('ttw_hide_front_preheader');
        ttw_post_opt('ttw_hide_rest_preheader');
        ttw_post_opt('ttw_hide_front_postheader');
        ttw_post_opt('ttw_hide_rest_postheader');
        ttw_post_opt('ttw_hide_front_prefooter');
        ttw_post_opt('ttw_hide_rest_prefooter');
        ttw_post_opt('ttw_hide_front_postfooter');
        ttw_post_opt('ttw_hide_rest_postfooter');
        ttw_post_opt('ttw_hide_front_presidebar');
        ttw_post_opt('ttw_hide_rest_presidebar');
        ttw_post_opt('ttw_hide_custom_header_template_menus');
        ttw_post_opt('ttw_hide_custom_header_template_siteinfo');
        ttw_post_opt('ttw_hide_blank_header');
        ttw_post_opt('ttw_hide_blank_footer');
        // ADMIN OPTS - per site tags - not theme related
        ttw_post_adminopt('ttw_hide_preview');
        ttw_post_adminopt('ttw_hide_theme_thumbs');
        ttw_post_adminopt('ttw_hide_auto_css_rules');
        ttw_post_adminopt('ttw_hide_metainfo');
        ttw_post_adminopt('ttw_metainfo');
        ttw_post_adminopt('ttw_end_opts');
        ttw_post_adminopt('ttw_copyright');
        ttw_post_adminopt('ttw_hide_poweredby');
        ttw_post_adminopt('ttw_force_inline_css');
        ttw_post_adminopt('ttw_hide_IE_warning_css');
        // NOW, save everything
        ttw_saveopts();
    }
    if (ttw_submitted('setsubtheme') || ttw_submitted('setsubtheme2')) {
        /* seems like Mozilla doesn't like 2 sets of select inputs on same page, so we make up 2 ids/names to use */
        if (isset($_POST['setsubtheme'])) {
            $pID = 'ttw_subtheme';
        } else {
            $pID = 'ttw_subtheme2';
        }
        $cur_subtheme = ttw_esc_code($_POST[$pID]);
        /* must have been set to get here */
        if ($cur_subtheme == '') {
            $cur_subtheme = TTW_DEFAULT_THEME;
        }
        /* but just in case */
        /* now, i set all values for theme */
        st_set_subtheme($cur_subtheme);
        $t = ttw_getopt('ttw_subtheme');
        if ($t == '') {
            $t = TTW_DEFAULT_THEME;
        }
        /* did we save a theme? */
        echo '<div id="message" class="updated fade"><p><strong>' . __("Twenty Ten Weaver options reset to sub-theme: ", TTW_TRANS) . $t . '.</strong></p></div>';
    }
    if (ttw_submitted('changethemename')) {
        if (isset($_POST['newthemename'])) {
            $new_name = sanitize_user($_POST['newthemename']);
            ttw_setopt('ttw_themename', $new_name);
            echo '<div id="message" class="updated fade"><p><strong>Theme name changed to ' . $new_name . '</strong></p></div>';
        }
    }
    if (ttw_submitted('savemytheme')) {
        ttw_savemytheme();
        echo '<div id="message" class="updated fade"><p><strong>' . __('All current main and advanced options saved in <em>My Saved Theme</em>.', TTW_TRANS) . '</strong></p></div>';
    }
    if (ttw_submitted('reset_weaver')) {
        // delete everything!
        echo '<div id="message" class="updated fade"><p><strong>All Weaver settings have been reset to the default.</strong></p></div>';
        delete_option('ttw_options');
        delete_option('ttw_myoptions');
        delete_option('ttw_adminoptions');
        $ttw_optionsList = $ttw_optionsListDefault;
        foreach ($ttw_options as $value) {
            ttw_defaultopt($value['id']);
        }
        $ttw_myoptionsList = $ttw_optionsList;
        $ttw_adminOpts = $ttw_adminOptsDefault;
        ttw_saveopts();
        st_set_subtheme(TTW_START_THEME);
    }
    if (ttw_submitted('filesavetheme')) {
        $base = strtolower(sanitize_file_name($_POST['savethemename']));
        $temp_url = ttw_write_current_theme($base);
        if ($temp_url == '') {
            echo '<div id="message" class="updated fade"><p><strong>Invalid name supplied to save theme to file.</strong></p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p><strong>' . __("All current main and advanced options saved in {$temp_url}.", TTW_TRANS) . '</strong></p></div>';
        }
    }
    if (ttw_submitted('uploadtheme') && isset($_POST['uploadit']) && $_POST['uploadit'] == 'yes') {
        ttw_uploadit();
    }
    if (ttw_submitted('uploadthemeurl')) {
        // url method
        $filename = esc_url($_POST['ttw_uploadname']);
        if (ttw_upload_theme($filename)) {
            $t = ttw_getopt('ttw_subtheme');
            if ($t == '') {
                $t = TTW_DEFAULT_THEME;
            }
            /* did we save a theme? */
            echo '<div id="message" class="updated fade"><p><strong>' . __("Twenty Ten Weaver theme options reset to uploaded theme, saved as: ", TTW_TRANS) . $t . '.</strong></p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' . __('INVALID THEME URL PROVIDED - Try Again', TTW_TRANS) . '</em></strong></p></div>';
        }
    }
    if (ttw_submitted('restoretheme')) {
        $wpdir = wp_upload_dir();
        $base = $_POST['ttw_restorename'];
        $valid = validate_file($base);
        // make sure an ok file name
        $fn = $wpdir['basedir'] . '/weaver-subthemes/' . $base;
        if ($valid < 1 && ttw_upload_theme($fn)) {
            $t = ttw_getopt('ttw_subtheme');
            if ($t == '') {
                $t = TTW_DEFAULT_THEME;
            }
            /* did we save a theme? */
            echo '<div id="message" class="updated fade"><p><strong>' . __("Twenty Ten Weaver theme restored from file, saved as: ", TTW_TRANS) . $t . '.</strong></p></div>';
        } else {
            echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' . __('INVALID FILE NAME PROVIDED - Try Again', TTW_TRANS) . '</em></strong></p></div>';
        }
    }
    if (ttw_submitted('deletetheme')) {
        $myFile = $_POST['selectName'];
        $valid = validate_file($myFile);
        if ($valid < 1 && $myFile != "None") {
            $wpdir = wp_upload_dir();
            unlink($wpdir['basedir'] . '/weaver-subthemes/' . $myFile);
            echo '<div style="background-color: rgb(255, 251, 204);" id="message" class="updated fade"><p>File: <strong>' . $myFile . '</strong> has been deleted.</p></div>';
        } else {
            echo '<div style="background-color: rgb(255, 251, 204);" id="message" class="updated fade"><p>File: <strong>' . $myFile . '</strong> invalid file name, not deleted.</p></div>';
        }
    }
    if (ttw_submitted('ttw_save_extension')) {
        /* for theme extensions */
        do_action('ttwx_save_extension');
    }
    ?>
<div style="float:left;"><h3><?php 
    echo TTW_THEMEVERSION;
    ?>
 Options</h3><a name="top_main" id="top_main"></a></div>
<div style="float:right;padding-right:30px;"><small><strong>Like Weaver? Please</strong></small>
<form 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="JUNTAHFM7YGYQ">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div><div style="clear:both;">

<div id="tabwrap">
  <div id="tab-container-1" class='yetii'>
    <ul id="tab-container-1-nav" class='yetii'>
	<li><a href="#tab0"><?php 
    echo __('Weaver Themes', TTW_TRANS);
    ?>
</a></li>
	<li><a href="#tab1"><?php 
    echo __('Main Options', TTW_TRANS);
    ?>
</a></li>
<?php 
    if (ttw_allow_multisite()) {
        ?>
	<li><a href="#tab2"><?php 
        echo __('Advanced Options', TTW_TRANS);
        ?>
</a></li>
	<li><a href="#tab3"><?php 
        echo __('Save/Restore Themes', TTW_TRANS);
        ?>
</a></li>
	<li><a href="#tab4"><?php 
        echo __('Snippets', TTW_TRANS);
        ?>
</a></li>
	<?php 
    }
    ?>
	<li><a href="#tab7"><?php 
    echo __('CSS Help', TTW_TRANS);
    ?>
</a></li>
	<li><a href="#tab5"><?php 
    echo __('Help', TTW_TRANS);
    ?>
</a></li>
	<?php 
    do_action('ttwx_add_extended_tab_title', '<li><a href="#tab6">', '</a></li>');
    ?>
    </ul>

    <div id="tab0" class="tab" >
         <?php 
    ttw_themes_admin();
    ?>
    </div>
    <div id="tab1" class="tab" >
         <?php 
    ttw_options_admin();
    ?>
    </div>
<?php 
    if (ttw_allow_multisite()) {
        ?>
    <div id="tab2" class="tab">
       <?php 
        ttw_advanced_admin();
        ?>
    </div>
    <div id="tab3" class="tab">
       <?php 
        ttw_saverestore_admin();
        ?>
    </div>
    <div id="tab4" class="tab">
       <?php 
        ttw_snippets_admin();
        ?>
    </div>
<?php 
    }
    ?>
    <div id="tab7" class="tab">
       <?php 
    ttw_csshelp_admin();
    ?>
    </div>
    <div id="tab5" class="tab">
       <?php 
    ttw_help_admin();
    ?>
    </div>
    <?php 
    do_action('ttwx_add_extended_tab', '<div id="tab6" class="tab" >', '</div>');
    /* extended option admin tab */
    ?>

  </div>

<?php 
    if (!ttw_getadminopt('ttw_hide_preview')) {
        ?>

<h3>Preview of site. Displays current look <em>after</em> you save options or select sub-theme.</h3>
<iframe id="preview" name="preview" src="<?php 
        echo get_option('siteurl');
        ?>
?temppreview=true" style="width:100%;height:400px;border:1px solid #ccc"></iframe>
<?php 
    } else {
        echo "<h3>Site Preview Disabled</h3>\n";
    }
    ?>
</div>
    <script type="text/javascript">
	var tabber1 = new Yetii({
	id: 'tab-container-1',
	persist: true
	});
</script>
<?php 
}
Exemplo n.º 2
0
function ttw_initopts()
{
    global $ttw_optionsList, $ttw_myoptionsList, $ttw_options, $ttw_adminOpts, $ttw_optionsListDefault;
    $settingsFound = false;
    // any options saved?
    /* first thing, make sure $ttw_optionsList and $ttw_myoptionsList are set to
          good default values
       */
    $ttw_optionsList = $ttw_optionsListDefault;
    foreach ($ttw_options as $value) {
        ttw_defaultopt($value['id']);
        ttw_setmyopt($value['id'], ttw_getopt($value['id']));
    }
    $opts = get_option('ttw_options');
    if ($opts) {
        $settingsFound = true;
        $ttw_optionsList = unserialize($opts);
    }
    $myopts = get_option('ttw_myoptions');
    if (!$myopts) {
        $ttw_myoptionsList = $ttw_optionsList;
    } else {
        $settingsFound = true;
        $ttw_myoptionsList = unserialize($myopts);
    }
    $aopts = get_option('ttw_adminoptions');
    if ($aopts) {
        $settingsFound = true;
        $ttw_adminOpts = unserialize($aopts);
    }
    if ($end = ttw_getopt('ttw_end_opts')) {
        // old version set - 1.3 upgrade compatibility issue here...
        ttw_setadminopt('ttw_end_opts', $end);
        ttw_deleteopt('ttw_end_opts');
        ttw_saveopts();
    }
}
Exemplo n.º 3
0
function ttw_save_serialized_theme($contents)
{
    global $ttw_optionsList;
    if (substr($contents, 0, 10) != "TTW-V01.10") {
        return ttw_file_fail("Wrong theme file version");
    }
    /* simple check for one of ours */
    $restore = array();
    $restore = unserialize(substr($contents, 10));
    if (!$restore) {
        return ttw_file_fail("Unserialize failed");
    }
    foreach ($ttw_optionsList as $key => $val) {
        /* first, clear EVERYTHING in both current and mysaved */
        ttw_deleteopt($key);
        ttw_deletemyopt($key);
    }
    st_set_to_defaults();
    /* now restore defaults - saved will override changes */
    /* now can set the new values from $restore */
    foreach ($restore as $rkey => $rval) {
        if ($rval != '') {
            ttw_setopt($rkey, $rval);
            /* and set both sets of values */
            ttw_setmyopt($rkey, $rval);
        }
    }
    ttw_setopt('ttw_subtheme', "My Saved Theme");
    ttw_saveopts();
    /* and write them to db! */
    return true;
}