示例#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 
}
function ttw_saverestore_admin()
{
    /* admin tab for saving and restoring theme */
    $wpdir = wp_upload_dir();
    $ttw_theme_dir = $wpdir['baseurl'] . '/weaver-subthemes/';
    $upload_link = ttw_write_current_theme('current_ttw_subtheme');
    // make a temp copy
    ?>

    <h2>Save/Restore Themes</h2>
    <h4>You can save all the settings from the current theme by:</h4>
    <ol style="font-size: 85%">
    <li>"Save in My Saved Theme" - Saves a copy in server's database. Survives Weaver Theme updates. -or-</li>
   <li>Download current theme settings to a file on your own computer. -or-</li>
   <li>Save settings to a file on your Site's file system (in <?php 
    echo $ttw_theme_dir;
    ?>
.</li></ol>

    <h4>You can restore a saved theme by:</h4>
    <ol style="font-size: 85%">
   <li>Picking "My Saved Theme" from the standard themes list. -or-</li>
   <li>Restoring a theme that you saved in a file on your site (to "My Saved Theme"). -or-</li>
   <li>Uploading a theme from a file saved on your own computer (to "My Saved Theme"). -or-</li>
    <li>Uploading a theme from a web based URL (to "My Saved Theme").</li></ol>
    <hr />
    <h3><span style="color:blue;">Use "My Saved Theme"</span></h3>
    <?php 
    st_show_subtheme_form();
    /* add the picker for subthemes */
    ?>

    <hr />
    <h3><span style="color:blue;">Save Current Theme to File or Download to your computer</span></h3>
     <small><strong>Save</strong> <u>all</u> currently saved options (both Main and Advanced) either by downloading
    to <strong>your computer</strong> or saving a <strong>file</strong> on your Wordpress Site's <em><?php 
    echo $ttw_theme_dir;
    ?>
</em> directory.
    You will be able to restore this theme later using the <strong>Restore Theme</strong> button. Please note: be sure to click
    <em>Save Current Settings</em> first to save any changes you might have made.</small><br /><br />

  <strong>Save as file on this website's server</strong>
 <p>Please provide a name for your file, then click the "Save File" button. <b>Warning:</b> Duplicate names will automatically overwrite existing file without notification.</p>
 <form enctype="multipart/form-data" name='savetheme' method='post'><table cellspacing='10' cellpadding='5'>
    <table>
    <td>Name for saved theme: <input type="text" name="savethemename" size="30" />&nbsp;<small>(Please use a meaningful name - do not provide file extension. Name might be altered to standard form.)</small></td></tr>
	<tr>
	<td><span class='submit'><input name='filesavetheme' type='submit' value='Save File'/></span>&nbsp;&nbsp;
	<small><strong>Save Theme in File</strong> - Theme will be saved in <em><?php 
    echo $ttw_theme_dir;
    ?>
</em> directory on your site server.</small></td>
        </tr>
    </table>
    <?php 
    ttw_nonce_field('filesavetheme');
    ?>
 </form><br />

    <strong>Download to your computer</strong>

 <p>Please <em>right</em>-click <a href="<?php 
    echo "{$upload_link}";
    ?>
"><strong>[* here *]</strong></a> to download the saved theme to your computer. </p>


<hr />

    <h3><span style="color:blue;">Restore Saved Theme from file or URL</span></h3>
    <small>You can restore a previously saved theme file, directly from your Wordpress
     Site's <em><?php 
    echo $ttw_theme_dir;
    ?>
</em> directory, from a file saved on your computer, or by providing an "http" URL address
     of the file (this might be from another site with Weaver themes). Note: after you restore a saved theme,
    it will be loaded into "My Saved Theme". If you've uploaded the theme from your computer or a URL, you might want to also then
    save a local copy on your website server.</small><br /><br />

    <form enctype="multipart/form-data" name='localrestoretheme' method='post'><table cellspacing='10' cellpadding='5'>
    <table>
    <tr><td><strong>Restore from file saved on this website's server</strong></td></tr>
    <tr>
        <td>Select theme file name: <?php 
    ttw_subtheme_list('ttw_restorename');
    ?>
&nbsp;(Restores to "My Saved Theme")</td></tr>
	<tr>
	<td><span class='submit'><input name='restoretheme' type='submit' value='Restore Theme'/></span>&nbsp;&nbsp;
	<small><strong>Restore</strong> a theme you've previously uploaded to your site's <em><?php 
    echo $ttw_theme_dir;
    ?>
</em> directory. Will become current "My Saved Theme".</small></td>
    </tr>
        <tr><td>&nbsp;</td></tr>
    </table>
    <?php 
    ttw_nonce_field('restoretheme');
    ?>
    </form>
    <form enctype="multipart/form-data" action="<?php 
    echo $_SERVER["REQUEST_URI"];
    ?>
" method="POST">
	<table>
            <tr><td><strong>Upload file saved on your computer</strong></td></tr>
		<tr valign="top">
			<td>Select theme file to upload: <input name="uploaded" type="file" />
			<input type="hidden" name="uploadit" value="yes" />&nbsp;(Restores to "My Saved Theme")
                        </td>
		</tr>
                <tr><td><span class='submit'><input name="uploadtheme" type="submit" value="Upload theme" /></span>&nbsp;<small><strong>Upload and Restore</strong> a theme from file on your computer. Will become current "My Saved Theme".</small></td></tr>
                <tr><td>&nbsp;</td></tr>
	</table>
	<?php 
    ttw_nonce_field('uploadtheme');
    ?>
    </form>

    <form enctype="multipart/form-data" name='upload-theme' method='post'><table cellspacing='10' cellpadding='5'>
    <table>
	<tr><td><strong>Restore from a URL</strong></td></tr>
        <tr><td>Enter theme file URL: <input type="text" name="ttw_uploadname" size="60" />&nbsp;(Restores to "My Saved Theme")</td></tr>
	<tr><td><span class='submit'><input name='uploadthemeurl' type='submit' value='Upload Theme from URL'/></span></td></tr>
	<tr><td><small><strong>Upload and Restore</strong> a theme from a web URL address. Will become current "My Saved Theme".</small></td></tr>
    </table>
    <?php 
    ttw_nonce_field('uploadthemeurl');
    ?>
    </form>
    <hr />

    <form enctype="multipart/form-data" name='maintaintheme' method='post'>
    <h3><span style="color:green;">Sub-theme Maintenance</span></h3>
        <?php 
    ttw_subtheme_list('selectName');
    ?>

        <span class='submit'><input name='deletetheme' type='submit' value='Delete Sub-Theme File'/></span>
          <strong>Warning!</strong>This action can't be undone, so be sure you mean to delete a file!
	  <?php 
    ttw_nonce_field('deletetheme');
    ?>
    </form>
    <hr />
<?php 
}