/**
 * This actual import of the options from the file to the settings array.
*/
function tempera_import_file()
{
    global $temperas;
    /* Check authorisation */
    $authorised = true;
    // Check nonce
    if (!wp_verify_nonce($_POST['tempera-import'], 'tempera-import')) {
        $authorised = false;
    }
    // Check permissions
    if (!current_user_can('edit_theme_options')) {
        $authorised = false;
    }
    // If the user is authorised, import the theme's options to the database
    if ($authorised) {
        ?>
        <?php 
        // make sure there is an import file uploaded
        if (isset($_FILES["import"]["size"]) && $_FILES["import"]["size"] > 0) {
            $form_fields = array('import');
            $method = '';
            $url = wp_nonce_url('themes.php?page=tempera-page', 'tempera-import');
            // Get file writing credentials
            if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $form_fields))) {
                return true;
            }
            if (!WP_Filesystem($creds)) {
                // our credentials were no good, ask the user for them again
                request_filesystem_credentials($url, $method, true, false, $form_fields);
                return true;
            }
            // Write the file if credentials are good
            $upload_dir = wp_upload_dir();
            $filename = trailingslashit($upload_dir['path']) . 'temperas.txt';
            // by this point, the $wp_filesystem global should be working, so let's use it to create a file
            global $wp_filesystem;
            if (!$wp_filesystem->move($_FILES['import']['tmp_name'], $filename, true)) {
                echo 'Error saving file!';
                return;
            }
            $file = $_FILES['import'];
            if ($file['type'] == 'text/plain') {
                $data = $wp_filesystem->get_contents($filename);
                // try to read the file
                if ($data !== FALSE) {
                    $settings = json_decode($data, true);
                    // try to read the settings array
                    if (isset($settings['tempera_db'])) {
                        ?>
        <div class="wrap">
        <div id="icon-tools" class="icon32"><br></div>
        <h2><?php 
                        echo __('Import Tempera Theme Options ', 'tempera');
                        ?>
</h2> <?php 
                        $settings = array_merge($temperas, $settings);
                        update_option('tempera_settings', $settings);
                        echo '<div class="updated fade"><p>' . __('Great! The options have been imported!', 'tempera') . '<br />';
                        echo '<a href="themes.php?page=tempera-page">' . __('Go back to the Tempera options page and check them out!', 'tempera') . '<a></p></div>';
                    } else {
                        // else: try to read the settings array
                        echo '<div class="error"><p><strong>' . __('Oops, there\'s a small problem.', 'tempera') . '</strong><br />';
                        echo __('The uploaded file does not contain valid Tempera options. Make sure the file is exported from the Tempera Options page.', 'tempera') . '</p></div>';
                        tempera_import_form();
                    }
                } else {
                    // else: try to read the file
                    echo '<div class="error"><p><strong>' . __('Oops, there\'s a small problem.', 'tempera') . '</strong><br />';
                    echo __('The uploaded file could not be read.', 'tempera') . '</p></div>';
                    tempera_import_form();
                }
            } else {
                // else: make sure the file uploaded was a plain text file
                echo '<div class="error"><p><strong>' . __('Oops, there\'s a small problem.', 'tempera') . '</strong><br />';
                echo __('The uploaded file is not supported. Make sure the file was exported from the Tempera page and that it is a text file.', 'tempera') . '</p></div>';
                tempera_import_form();
            }
            // Delete the file after we're done
            $wp_filesystem->delete($filename);
        } else {
            // else: make sure there is an import file uploaded
            echo '<div class="error"><p>' . __('Oops! The file is empty or there was no file. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.', 'tempera') . '</p></div>';
            tempera_import_form();
        }
        echo '</div> <!-- end wrap -->';
    } else {
        wp_die(__('ERROR: You are not authorised to perform that operation', 'tempera'));
    }
}
示例#2
0
function tempera_page_fn()
{
    // Load the import form page if the import button has been pressed
    if (isset($_POST['tempera_import'])) {
        tempera_import_form();
        return;
    }
    // Load the import form  page after upload button has been pressed
    if (isset($_POST['tempera_import_confirmed'])) {
        tempera_import_file();
        return;
    }
    // Load the presets  page after presets button has been pressed
    if (isset($_POST['tempera_presets'])) {
        tempera_init_fn();
        tempera_presets();
        return;
    }
    if (!current_user_can('edit_theme_options')) {
        wp_die(__('Sorry, but you do not have sufficient permissions to access this page.', 'tempera'));
    }
    ?>


<div class="wrap"><!-- Admin wrap page -->

<div id="lefty"><!-- Left side of page - the options area -->
<div>
	<div id="admin_header"><img src="<?php 
    echo get_template_directory_uri() . '/admin/images/tempera-logo.png';
    ?>
" /> </div>
	<div id="admin_links">
		<a target="_blank" href="http://www.cryoutcreations.eu/tempera">Tempera Homepage</a>
		<a target="_blank" href="http://www.cryoutcreations.eu/forum">Support</a>
		<a target="_blank" href="http://www.cryoutcreations.eu">Cryout Creations</a>
	</div>
	<div style="clear: both;"></div>
</div>
<?php 
    if (isset($_GET['settings-updated'])) {
        echo "<div class='updated fade' style='clear:left;'><p>";
        echo _e('Tempera settings updated successfully.', 'tempera');
        echo "</p></div>";
    }
    ?>
<div id="jsAlert" class=""><b>Checking jQuery functionality...</b><br/><em>If this message remains visible after the page has loaded then there is a problem with your WordPress jQuery library. This can have several causes, including incompatible plugins.
The Tempera Settings page cannot function without jQuery. </em></div>
<?php 
    global $temperas;
    $tempera_varalert = cryout_maxvarcheck(count($temperas));
    if ($tempera_varalert) {
        ?>
<div id="varlimitalert"> <?php 
        echo $tempera_varalert;
        ?>
 </div><?php 
    }
    ?>
	<div id="main-options">
		<form name="tempera_form" id="tempera_form" action="options.php" method="post" enctype="multipart/form-data">
			<div id="accordion">
				<?php 
    settings_fields('tempera_settings');
    ?>
				<?php 
    do_settings_sections(__FILE__);
    ?>
			</div>
			<div id="submitDiv">
			    <br>
				<input class="button" name="tempera_settings[tempera_submit]" type="submit" id="tempera_sumbit" style="float:right;"   value="<?php 
    _e('Save Changes', 'tempera');
    ?>
" />
				<input class="button" name="tempera_settings[tempera_defaults]" id="tempera_defaults" type="submit" style="float:left;" value="<?php 
    _e('Reset to Defaults', 'tempera');
    ?>
" />
				</div>
		</form>
		<?php 
    $tempera_theme_data = get_transient('tempera_theme_info');
    ?>
		<span id="version">
		Tempera v<?php 
    echo TEMPERA_VERSION;
    ?>
 by <a href="http://www.cryoutcreations.eu" target="_blank">Cryout Creations</a>
		</span>
	</div><!-- main-options -->
</div><!--lefty -->


<div id="righty" ><!-- Right side of page - Coffee, RSS tips and others -->
	<div id="tempera-donate" class="postbox donate">
	 <div title="Click to toggle" class="handlediv"><br /></div>
		<h3 class="hndle"> Coffee Break </h3>
		<div class="inside"><?php 
    echo "<p>While looking at Tempera you will notice what may appear as colors. You'll see them within images, in links and menus, defining borders and backgrounds, as part of animations, hover effects and more.  </p>\n<p>But don't let that fool you, those are not colors. What you're actually seeing is a complex mix of coffee and our own blood - you'd be surprised to see how many hues we can get by mixing those two. But as of late we've been feeling pretty dizzy and light headed and it's not from the lack of blood (we are secretly vampires).</p>\n<p>What's causing the dizziness is the limited amount of coffee. Every morning we have to make one very tough decision: either use coffee to make colors for Tempera or drink it and stay awake to develop Tempera. It's a choice we'd rather not make so...</p>";
    ?>
			<div style="display:block;float:none;margin:0 auto;text-align:center;">
				<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
					<input type="hidden" name="cmd" value="_donations">
					<input type="hidden" name="business" value="KYL26KAN4PJC8">
					<input type="hidden" name="item_name" value="Cryout Creations / Tempera Theme donation">
					<input type="hidden" name="currency_code" value="EUR">
					<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_SM.gif:NonHosted">
					<input type="image" src="<?php 
    echo get_template_directory_uri() . '/admin/images/coffee.png';
    ?>
" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
					<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
				</form>			
			</div>
			
			<p>Or socially smother, caress and embrace us:</p>
			<div style="display:table;float:none;margin:0 auto;">
				<div id="fb-root"></div><div class="fb-like" data-href="https://www.facebook.com/CryoutCreations" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div>
				<a href="https://twitter.com/cryoutcreations" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @cryoutcreations</a>
				<script src="https://apis.google.com/js/platform.js" async defer></script> <div class="g-plusone" data-href="https://plus.google.com/+CryoutcreationsEuCR2"  data-size="medium" data-annotation="none"></div>
			</div>
			
		</div><!-- inside -->
	</div><!-- donate -->

    <div id="tempera-export" class="postbox export non-essential-option" style="overflow:hidden;">
            <div title="Click to toggle" class="handlediv"><br /></div>
           	<h3 class="hndle"><?php 
    _e('Import/Export Settings', 'tempera');
    ?>
</h3>
        <div class="panel-wrap inside">
				<form action="" method="post">
                	<?php 
    wp_nonce_field('tempera-export', 'tempera-export');
    ?>
                    <input type="hidden" name="tempera_export" value="true" />
                    <input type="submit" class="button" value="<?php 
    _e('Export Theme options', 'tempera');
    ?>
" />
					<p class="imex-text"><?php 
    _e("It's that easy: a mouse click away - the ability to export your Tempera settings and save them on your computer. Feeling safer? You should!", "tempera");
    ?>
</p>
                </form>
				<br />
                <form action="" method="post">
                    <input type="hidden" name="tempera_import" value="true" />
                    <input type="submit" class="button" value="<?php 
    _e('Import Theme options', 'tempera');
    ?>
" />
					<p class="imex-text"><?php 
    _e("Without the import, the export would just be a fool's exercise. Make sure you have the exported file ready and see you after the mouse click.", "tempera");
    ?>
</p>
                </form>
				<br />
				<form action="" method="post">
                    <input type="hidden" name="tempera_presets" value="true" />
                    <input type="submit" class="button" id="presets_button" value="<?php 
    _e('Color Schemes', 'tempera');
    ?>
" />
					<p class="imex-text"><?php 
    _e("A collection of preset color schemes to use as the starting point for your site. Just load one up and see your blog in a different light.", "tempera");
    ?>
</p>
                </form>

		</div><!-- inside -->
	</div><!-- export -->

    <div id="tempera-news" class="postbox news" >
	 <div title="Click to toggle" class="handlediv"><br /></div>
        		<h3 class="hndle"><?php 
    _e('Tempera Latest News', 'tempera');
    ?>
</h3>
            <div class="panel-wrap inside" style="height:200px;overflow:auto;">
             
            </div><!-- inside -->
    </div><!-- news -->


</div><!--  righty -->
</div><!--  wrap -->

<script type="text/javascript">
var reset_confirmation = '<?php 
    echo esc_html(__('Reset Tempera Settings to Defaults?', 'tempera'));
    ?>
';
var tempera_help_icon = '<?php 
    echo get_template_directory_uri();
    ?>
/images/icon-tooltip.png';

jQuery(document).ready(function(){
	if (vercomp(jQuery.ui.version,"1.9.0")) {
		tooltip_terain();
		jQuery('.colorthingy').each(function(){
			id = "#"+jQuery(this).attr('id');
			startfarb(id,id+'2');
		});
	} else {
		jQuery("#main-options").addClass('oldwp');
		setTimeout(function(){jQuery('#tempera_slideType').trigger('click')},1000);
		jQuery('.colorthingy').each(function(){
			id = "#"+jQuery(this).attr('id');
			jQuery(this).on('keyup',function(){coloursel(this)});
			coloursel(this);
		});
		/* warn about the old partially unsupported version */
		jQuery("#jsAlert").after("<div class='updated fade' style='clear:left; font-size: 16px;'><p>Tempera has detected you are running an older version of Wordpress (jQuery) and will be running in compatibility mode. Some features may not work correctly. Consider updating your Wordpress to the latest version.</p></div>");
	}
});
jQuery('#jsAlert').hide();
</script>

<?php 
}