/**
 * This actual import of the options from the file to the settings array.
*/
function iced_mocha_import_file()
{
    global $iced_mochas;
    /* Check authorisation */
    $authorised = true;
    // Check nonce
    if (!wp_verify_nonce($_POST['iced_mocha-import'], 'iced_mocha-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=iced_mocha-page', 'iced_mocha-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']) . 'iced_mochas.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['iced_mocha_db'])) {
                        ?>
        <div class="wrap">
        <div id="icon-tools" class="icon32"><br></div>
        <h2><?php 
                        echo __('Import Iced Mocha Options ', 'iced_mocha');
                        ?>
</h2> <?php 
                        $settings = array_merge($iced_mochas, $settings);
                        update_option('iced_mocha_settings', $settings);
                        echo '<div class="updated fade"><p>' . __('Great! The options have been imported!', 'iced_mocha') . '<br />';
                        echo '<a href="themes.php?page=iced_mocha-page">' . __('Go back to the Iced Mocha Theme options page and check them out!', 'iced_mocha') . '<a></p></div>';
                    } else {
                        // else: try to read the settings array
                        echo '<div class="error"><p><strong>' . __('Oops, there\'s a small problem.', 'iced_mocha') . '</strong><br />';
                        echo __('The uploaded file does not contain valid Iced Mocha Theme options. Make sure the file is exported from the Iced Mocha Theme Options page.', 'iced_mocha') . '</p></div>';
                        iced_mocha_import_form();
                    }
                } else {
                    // else: try to read the file
                    echo '<div class="error"><p><strong>' . __('Oops, there\'s a small problem.', 'iced_mocha') . '</strong><br />';
                    echo __('The uploaded file could not be read.', 'iced_mocha') . '</p></div>';
                    iced_mocha_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.', 'iced_mocha') . '</strong><br />';
                echo __('The uploaded file is not supported. Make sure the file was exported from the Iced Mocha Theme page and that it is a text file.', 'iced_mocha') . '</p></div>';
                iced_mocha_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.', 'iced_mocha') . '</p></div>';
            iced_mocha_import_form();
        }
        echo '</div> <!-- end wrap -->';
    } else {
        wp_die(__('ERROR: You are not authorised to perform that operation', 'iced_mocha'));
    }
}
Beispiel #2
0
function iced_mocha_page_fn()
{
    // Load the import form page if the import button has been pressed
    if (isset($_POST['iced_mocha_import'])) {
        iced_mocha_import_form();
        return;
    }
    // Load the import form  page after upload button has been pressed
    if (isset($_POST['iced_mocha_import_confirmed'])) {
        iced_mocha_import_file();
        return;
    }
    // Load the presets  page after presets button has been pressed
    if (isset($_POST['iced_mocha_presets'])) {
        iced_mocha_init_fn();
        iced_mocha_presets();
        return;
    }
    if (!current_user_can('edit_theme_options')) {
        wp_die(__('Sorry, but you do not have sufficient permissions to access this page.', 'iced_mocha'));
    }
    ?>


<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/iced_mocha-logo.png';
    ?>
" /> </div>
	<div id="admin_links">
		<a target="_blank" href="https://github.com/eventespresso/iced-mocha/#iced-mocha-theme">Iced Mocha Theme Homepage</a>
		<a target="_blank" href="http://eventespresso.com/support/forums/">Support</a>
		<a target="_blank" href="http://eventespresso.com">Event Espresso</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('Iced Mocha Theme settings updated successfully.', 'iced_mocha');
        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 Iced Mocha Settings page cannot function without jQuery. </em></div>
<?php 
    global $iced_mochas;
    $iced_mocha_varalert = espresso_theme_maxvarcheck(count($iced_mochas));
    if ($iced_mocha_varalert) {
        ?>
<div id="varlimitalert"> <?php 
        echo $iced_mocha_varalert;
        ?>
 </div><?php 
    }
    ?>
	<div id="main-options">
		<form name="iced_mocha_form" id="iced_mocha_form" action="options.php" method="post" enctype="multipart/form-data">
			<div id="accordion">
				<?php 
    settings_fields('iced_mocha_settings');
    ?>
				<?php 
    do_settings_sections(__FILE__);
    ?>
			</div>
			<div id="submitDiv">
			    <br>
				<input class="button" name="iced_mocha_settings[iced_mocha_submit]" type="submit" id="iced_mocha_sumbit" style="float:right;"   value="<?php 
    _e('Save Changes', 'iced_mocha');
    ?>
" />
				<input class="button" name="iced_mocha_settings[iced_mocha_defaults]" id="iced_mocha_defaults" type="submit" style="float:left;" value="<?php 
    _e('Reset to Defaults', 'iced_mocha');
    ?>
" />
				</div>
		</form>
		<?php 
    $iced_mocha_theme_data = get_transient('iced_mocha_theme_info');
    ?>
		<span id="version">
		Iced Mocha Theme v<?php 
    echo ICED_MOCHA_VERSION;
    ?>
 by <a href="http://eventespresso.com" target="_blank">Event Espresso</a>
		</span>
	</div><!-- main-options -->
</div><!--lefty -->


<div id="righty" ><!-- Right side of page - Coffee, RSS tips and others -->
	<div id="iced_mocha-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>The Iced Mocha theme for WordPress was developed to provide a nice WordPress theme that is fully integrated with Event Espresso 4. Based off of our&nbsp;<a href=\"http://eventespresso.com/wiki/setup-event-espresso-arabica-theme/\">Arabica – Twenty Fourteen</a> child theme, which is included within the Event Espresso 4 plugin files, we were able to provide great looking event lists and registration forms right out of the box.</p>\r\n<p>Much of the Iced Mocha template code is based on the <a href=\"http://wordpress.org/themes/twentyfourteen\" target=\"_blank\">Twenty Fourteen </a>theme, but with a quite a few event specific features sprinkled in. Such as the ability to automatically showcase events in a slider, widget columns, and/or upcoming events right on the home page.</p>";
    ?>
			
		</div><!-- inside -->
	</div><!-- donate -->

    <div id="iced_mocha-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', 'iced_mocha');
    ?>
</h3>
        <div class="panel-wrap inside">
				<form action="" method="post">
                	<?php 
    wp_nonce_field('iced_mocha-export', 'iced_mocha-export');
    ?>
                    <input type="hidden" name="iced_mocha_export" value="true" />
                    <input type="submit" class="button" value="<?php 
    _e('Export Theme options', 'iced_mocha');
    ?>
" />
					<p class="imex-text"><?php 
    _e("It's that easy: a mouse click away - the ability to export your Iced Mocha Theme settings and save them on your computer. Feeling safer? You should!", "iced_mocha");
    ?>
</p>
                </form>
				<br />
                <form action="" method="post">
                    <input type="hidden" name="iced_mocha_import" value="true" />
                    <input type="submit" class="button" value="<?php 
    _e('Import Theme options', 'iced_mocha');
    ?>
" />
					<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.", "iced_mocha");
    ?>
</p>
                </form>
				<br />
			<form action="" method="post">
                    <input type="hidden" name="iced_mocha_presets" value="true" />
                    <input type="submit" class="button" id="presets_button" value="<?php 
    _e('Color Schemes', 'iced_mocha');
    ?>
" />
					<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.", "iced_mocha");
    ?>
</p>
                </form> 

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

    <div id="iced_mocha-news" class="postbox news" >
	 <div title="Click to toggle" class="handlediv"><br /></div>
        		<h3 class="hndle"><?php 
    _e('Iced Mocha Theme Latest News', 'iced_mocha');
    ?>
</h3>
            <div class="panel-wrap inside" style="height:200px;overflow:auto;">
                <?php 
    function return_10($seconds)
    {
        return 10;
    }
    $iced_mocha_news = fetch_feed(array('http://eventespresso.com/blog/feed/'));
    if (!is_wp_error($iced_mocha_news)) {
        $maxitems = $iced_mocha_news->get_item_quantity(10);
        $news_items = $iced_mocha_news->get_items(0, $maxitems);
    }
    ?>
                <ul class="news-list">
                	<?php 
    if ($maxitems == 0) {
        echo '<li>' . __('No news items.', 'iced_mocha') . '</li>';
    } else {
        foreach ($news_items as $news_item) {
            ?>
                    	<li>
                        	<a class="news-header" target="_blank" href='<?php 
            echo esc_url($news_item->get_permalink());
            ?>
'><?php 
            echo esc_html($news_item->get_title());
            ?>
</a><br />
                   <span class="news-item-date"><?php 
            _e('Posted on', 'iced_mocha');
            echo $news_item->get_date(' j F Y, H:i');
            ?>
</span><br />
                            <?php 
            echo iced_mocha_truncate_words(strip_tags($news_item->get_description()), 40, '...');
            ?>
					<br><a class="news-read" target="_blank" href='<?php 
            echo esc_url($news_item->get_permalink());
            ?>
'>Read more &raquo;</a><br />
                        </li>
                    <?php 
        }
    }
    ?>
                </ul>
            </div><!-- inside -->
    </div><!-- news -->


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

<script type="text/javascript">
var reset_confirmation = '<?php 
    echo esc_html(__('Reset Iced Mocha Settings to Defaults?', 'iced_mocha'));
    ?>
';

function startfarb(a,b) {
	jQuery(b).css('display','none');
	jQuery(b).farbtastic(a).addtitle({id: a});

	jQuery(a).click(function() {
			if(jQuery(b).css('display') == 'none')	{
                                        			jQuery(b).parents('div:eq(0)').addClass('ui-accordion-content-overflow');
                                                    jQuery(b).css({'display':'inline-block','position':'absolute',marginLeft:'100px',opacity:0}).animate({opacity:1,marginLeft:'0px'},150);
                                                       }
	});

	jQuery(document).mousedown( function() {
		if(jQuery(b).css('display') != 'none') setTimeout(function () { jQuery(b).css('display','none');},150);
		jQuery(b).animate({opacity:0,marginLeft:'100px'},150, function(){ jQuery(b).parents('div:eq(0)').removeClass('ui-accordion-content-overflow'); });
			// todo: find a better way to remove class after the fade on IEs
	});
}

function tooltip_terain() {
jQuery('#accordion small').parent('div').append('<a class="tooltip"><img src="<?php 
    echo get_template_directory_uri();
    ?>
/images/icon-tooltip.png" /></a>').
	each(function() {
	//jQuery(this).children('a.tooltip').attr('title',jQuery(this).children('small').html() );
	var tooltip_info = jQuery(this).children('small').html();
	jQuery(this).children('.tooltip').tooltip({content : tooltip_info});
     jQuery(this).children('.tooltip').tooltip( "option", "items", "a" );
	//jQuery(this).children('.tooltip').tooltip( "option", "show", "false");
	jQuery(this).children('.tooltip').tooltip( "option", "hide", "false");
	jQuery(this).children('small').remove();
	if (!jQuery(this).hasClass('slmini') && !jQuery(this).hasClass('slidercontent') && !jQuery(this).hasClass('slideDivs')) jQuery(this).addClass('tooltip_div');
	});
}

function coloursel(el){
	var id = "#"+jQuery(el).attr('id');
	jQuery(id+"2").hide();
	var bgcolor = jQuery(id).val();
	if (bgcolor <= "#666666") { jQuery(id).css('color','#ffffff'); } else { jQuery(id).css('color','#000000'); };
	jQuery(id).css('background-color',jQuery(id).val());
}

function vercomp(ver, req) {
    var v = ver.split('.');
    var q = req.split('.');
    for (var i = 0; i < v.length; ++i) {
        if (q.length == i) { return true; } // v is bigger
        if (parseInt(v[i]) == parseInt(q[i])) { continue; } // nothing to do here, move along
        else if (parseInt(v[i]) > parseInt(q[i])) { return true; } // v is bigger
        else { return false; } // q is bigger
    }
    if (v.length != q.length) { return false; } // q is bigger
    return true; // v = q;
}

// farbtastic title addon function
(function($){
        $.fn.extend({
            addtitle: function(options) {
                var defaults = {
                    id: ''
                }
                var options = $.extend(defaults, options);
            return this.each(function() {
                    var o = options;
					var title = jQuery(o.id).attr('title');
                    if (title===undefined) { } else { jQuery(o.id+'2').children('.farbtastic').append('<span class="mytitle">'+title+'</span>'); }
            });
        }
        });
})(jQuery);


jQuery(document).ready(function(){
	//var _jQueryVer = parseFloat('.'+jQuery().jquery.replace(/\./g, ''));  // jQuery version as float, eg: 0.183
	//var _jQueryUIVer = parseFloat('.'+jQuery.ui.version.replace(/\./g, '')); // jQuery UI version as float, eg: 0.192
	//if (_jQueryUIVer >= 0.190) {
	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('#iced_mocha_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>Iced Mocha Theme 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 
}