function edit_my_calendar_styles()
{
    $dir = plugin_dir_path(__FILE__);
    if (isset($_POST['mc_edit_style'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $my_calendar_style = isset($_POST['style']) ? stripcslashes($_POST['style']) : false;
        $mc_css_file = stripcslashes($_POST['mc_css_file']);
        $stylefile = mc_get_style_path($mc_css_file);
        $wrote_styles = $my_calendar_style !== false ? mc_write_styles($stylefile, $my_calendar_style) : 'disabled';
        if ($wrote_styles == true) {
            // updates from pre version 1.7.0
            delete_option('mc_file_permissions');
            delete_option('mc_style');
        }
        if ($wrote_styles === 'disabled') {
            $message = "<p>" . __("Styles are disabled, and were not edited.", 'my-calendar') . "</p>";
        } else {
            $message = $wrote_styles == true ? '<p>' . __('The stylesheet has been updated.', 'my-calendar') . '</p>' : '<p><strong>' . __('Write Error! Please verify write permissions on the style file.', 'my-calendar') . '</strong></p>';
        }
        $mc_show_css = empty($_POST['mc_show_css']) ? '' : stripcslashes($_POST['mc_show_css']);
        update_option('mc_show_css', $mc_show_css);
        $use_styles = empty($_POST['use_styles']) ? '' : 'true';
        update_option('mc_use_styles', $use_styles);
        if (!empty($_POST['reset_styles'])) {
            $stylefile = mc_get_style_path();
            $styles = mc_default_style();
            $wrote_old_styles = mc_write_styles($stylefile, $styles);
            if ($wrote_old_styles) {
                $message .= "<p>" . __('Stylesheet reset to default.', 'my-calendar') . "</p>";
            }
        }
        $message .= "<p><strong>" . __('Style Settings Saved', 'my-calendar') . ".</strong></p>";
        echo "<div id='message' class='updated fade'>{$message}</div>";
    }
    if (isset($_POST['mc_choose_style'])) {
        $nonce = $_REQUEST['_wpnonce'];
        if (!wp_verify_nonce($nonce, 'my-calendar-nonce')) {
            die("Security check failed");
        }
        $mc_css_file = stripcslashes($_POST['mc_css_file']);
        update_option('mc_css_file', $mc_css_file);
        $message = '<p><strong>' . __('New theme selected.', 'my-calendar') . '</strong></p>';
        echo "<div id='message' class='updated fade'>{$message}</div>";
    }
    $mc_show_css = get_option('mc_show_css');
    $stylefile = mc_get_style_path();
    if ($stylefile) {
        $f = fopen($stylefile, 'r');
        $file = fread($f, filesize($stylefile));
        $my_calendar_style = $file;
        fclose($f);
        $mc_current_style = mc_default_style();
    } else {
        $mc_current_style = '';
        $my_calendar_style = __('Sorry. The file you are looking for doesn\'t appear to exist. Please check your file name and location!', 'my-calendar');
    }
    ?>
	<div class="wrap jd-my-calendar">
	<?php 
    my_calendar_check_db();
    ?>
	<h2><?php 
    _e('My Calendar Styles', 'my-calendar');
    ?>
</h2>
	<div class="postbox-container jcd-wide">
		<div class="metabox-holder">
			<div class="ui-sortable meta-box-sortables">
				<div class="postbox">
					<h3><?php 
    _e('Calendar Style Settings', 'my-calendar');
    ?>
</h3>

					<div class="inside">

						<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-styles");
    ?>
">
							<div><input type="hidden" name="_wpnonce"
							            value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
"/></div>
							<div><input type="hidden" value="true" name="mc_choose_style"/></div>
							<fieldset>
								<p>
									<label
										for="mc_css_file"><?php 
    _e('Select My Calendar Theme', 'my-calendar');
    ?>
</label>
									<select name="mc_css_file" id="mc_css_file"><?php 
    $custom_directory = str_replace('/my-calendar/', '', $dir) . '/my-calendar-custom/styles/';
    $directory = dirname(__FILE__) . '/styles/';
    $files = @my_csslist($custom_directory);
    if (!empty($files)) {
        echo "<optgroup label='" . __('Your Custom Stylesheets', 'my-calendar') . "'>\n";
        foreach ($files as $value) {
            $filepath = mc_get_style_path($value);
            $path = pathinfo($filepath);
            if ($path['extension'] == 'css') {
                $test = "mc_custom_" . $value;
                $selected = get_option('mc_css_file') == $test ? " selected='selected'" : "";
                echo "<option value='" . esc_attr('mc_custom_' . $value) . "'{$selected}>{$value}</option>\n";
            }
        }
        echo "</optgroup>";
    }
    $files = my_csslist($directory);
    echo "<optgroup label='" . __('Installed Stylesheets', 'my-calendar') . "'>\n";
    foreach ($files as $value) {
        $filepath = mc_get_style_path($value);
        $path = pathinfo($filepath);
        if ($path['extension'] == 'css') {
            $selected = get_option('mc_css_file') == $value ? " selected='selected'" : "";
            echo "<option value='" . esc_attr($value) . "'{$selected}>{$value}</option>\n";
        }
    }
    echo "</optgroup>";
    ?>
									</select>
									<input type="submit" name="save" class="button-secondary"
									       value="<?php 
    _e('Choose Style', 'my-calendar');
    ?>
"/>
								</p>
							</fieldset>
						</form>
						<hr/>
						<form method="post" action="<?php 
    echo admin_url("admin.php?page=my-calendar-styles");
    ?>
">
							<div><input type="hidden" name="_wpnonce"
							            value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
"/></div>
							<div><input type="hidden" value="true" name="mc_edit_style"/>
								<input type="hidden" name="mc_css_file"
								       value="<?php 
    esc_attr_e(get_option('mc_css_file'));
    ?>
"/>
							</div>
							<fieldset style="position:relative;">
								<legend><?php 
    _e('CSS Style Options', 'my-calendar');
    ?>
</legend>
								<p>
									<label
										for="mc_show_css"><?php 
    _e('Apply CSS on these pages (comma separated IDs)', 'my-calendar');
    ?>
</label>
									<input type="text" id="mc_show_css" name="mc_show_css"
									       value="<?php 
    esc_attr_e($mc_show_css);
    ?>
"/>
								</p>

								<p>
									<input type="checkbox" id="reset_styles"
									       name="reset_styles" <?php 
    if (mc_is_custom_style(get_option('mc_css_file'))) {
        echo "disabled='disabled'";
    }
    ?>
 /> <label
										for="reset_styles"><?php 
    _e('Restore My Calendar stylesheet', 'my-calendar');
    ?>
</label>
									<input type="checkbox" id="use_styles"
									       name="use_styles" <?php 
    mc_is_checked('mc_use_styles', 'true');
    ?>
 />
									<label
										for="use_styles"><?php 
    _e('Disable My Calendar Stylesheet', 'my-calendar');
    ?>
</label>
								</p>
								<p>						
								<?php 
    if (mc_is_custom_style(get_option('mc_css_file'))) {
        _e('The editor is not available for custom CSS files. You should edit your custom CSS locally, then upload your changes.', 'my-calendar');
    } else {
        ?>
									<label
										for="style"><?php 
        _e('Edit the stylesheet for My Calendar', 'my-calendar');
        ?>
</label><br/><textarea
										class="style-editor" id="style" name="style" rows="30"
										cols="80"<?php 
        if (get_option('mc_use_styles') == 'true') {
            echo "disabled='disabled'";
        }
        ?>
><?php 
        echo $my_calendar_style;
        ?>
</textarea>

								<?php 
    }
    ?>
								</p>
								<p>
									<input type="submit" name="save" class="button-primary button-adjust"
									       value="<?php 
    _e('Save Changes', 'my-calendar');
    ?>
"/>
								</p>
							</fieldset>
						</form>
						<?php 
    $left_string = normalize_whitespace($my_calendar_style);
    $right_string = normalize_whitespace($mc_current_style);
    if ($right_string) {
        // if right string is blank, there is no default
        if (isset($_GET['diff'])) {
            echo '<div class="wrap jd-my-calendar" id="diff">';
            echo wp_text_diff($left_string, $right_string, array('title' => __('Comparing Your Style with latest installed version of My Calendar', 'my-calendar'), 'title_right' => __('Latest (from plugin)', 'my-calendar'), 'title_left' => __('Current (in use)', 'my-calendar')));
            echo '</div>';
        } else {
            if (trim($left_string) != trim($right_string)) {
                echo '<div class="wrap jd-my-calendar">';
                echo '<div class="updated"><p>' . __('There have been updates to the stylesheet.', 'my-calendar') . ' <a href="' . admin_url("admin.php?page=my-calendar-styles&amp;diff#diff") . '">' . __('Compare Your Stylesheet with latest installed version of My Calendar.', 'my-calendar') . '</a></p></div>';
                echo '</div>';
            } else {
                echo '
						<div class="wrap jd-my-calendar">
							<p>' . __('Your stylesheet matches that included with My Calendar.', 'my-calendar') . '</p>
						</div>';
            }
        }
    }
    ?>
					</div>
				</div>
				<p><?php 
    _e('Resetting your stylesheet will set your stylesheet to the version currently distributed with the plug-in.', 'my-calendar');
    ?>
</p>
			</div>
		</div>
	</div>
	<?php 
    mc_show_sidebar();
    ?>
	</div><?php 
}
Ejemplo n.º 2
0
function mc_register_styles()
{
    global $wp_query;
    $stylesheet = mc_get_style_path(get_option('mc_css_file'), 'url');
    wp_register_style('my-calendar-style', $stylesheet);
    $admin_stylesheet = plugins_url('css/mc-admin.css', __FILE__);
    wp_register_style('my-calendar-admin-style', $admin_stylesheet);
    if (current_user_can('mc_manage_events')) {
        wp_enqueue_style('my-calendar-admin-style');
    }
    $this_post = $wp_query->get_queried_object();
    $id = is_object($this_post) && isset($this_post->ID) ? $this_post->ID : false;
    $js_array = get_option('mc_show_js') != '' ? explode(",", get_option('mc_show_js')) : array();
    $css_array = get_option('mc_show_css') != '' ? explode(",", get_option('mc_show_css')) : array();
    // check whether any scripts are actually enabled.
    if (get_option('mc_calendar_javascript') != 1 || get_option('mc_list_javascript') != 1 || get_option('mc_mini_javascript') != 1 || get_option('mc_ajax_javascript') != 1) {
        if (@in_array($id, $js_array) || get_option('mc_show_js') == '') {
            wp_enqueue_script('jquery');
            if (get_option('mc_gmap') == 'true') {
                wp_register_script('gmaps', "//maps.google.com/maps/api/js?sensor=true");
                wp_register_script('gmap3', plugins_url('js/gmap3.min.js', __FILE__), array('jquery'));
                wp_enqueue_script('gmaps');
                wp_enqueue_script('gmap3');
            }
        }
    }
    if (get_option('mc_use_styles') != 'true') {
        if (@in_array($id, $css_array) || get_option('mc_show_css') == '') {
            wp_enqueue_style('my-calendar-style');
        }
    }
    if (mc_is_tablet() && mc_file_exists('mc-tablet.css')) {
        $tablet = mc_get_file('mc-tablet.css');
        wp_register_style('my-calendar-tablet-style', $tablet);
        wp_enqueue_style('my-calendar-tablet-style');
    }
    if (mc_is_mobile() && mc_file_exists('mc-mobile.css')) {
        $mobile = mc_get_file('mc-mobile.css');
        wp_register_style('my-calendar-mobile-style', $mobile);
        wp_enqueue_style('my-calendar-mobile-style');
    }
    if (function_exists('mcs_submissions')) {
        $mcs = plugins_url('/my-calendar-submissions/mcs-styles.css');
        $mcs_ui = plugins_url('/my-calendar-submissions/css/smoothness/jquery-ui-1.8.23.custom.css');
        wp_register_style('my-calendar-submissions-ui-style', $mcs_ui);
        wp_enqueue_style('my-calendar-submissions-ui-style');
        wp_register_style('my-calendar-submissions-style', $mcs);
        wp_enqueue_style('my-calendar-submissions-style');
    }
}
function mc_register_styles()
{
    global $wp_query;
    $stylesheet = apply_filters('mc_registered_stylesheet', mc_get_style_path(get_option('mc_css_file'), 'url'));
    wp_register_style('my-calendar-reset', plugins_url('css/reset.css', __FILE__));
    wp_register_style('my-calendar-style', $stylesheet, array('dashicons', 'my-calendar-reset'));
    $admin_stylesheet = plugins_url('css/mc-admin.css', __FILE__);
    wp_register_style('my-calendar-admin-style', $admin_stylesheet);
    if (current_user_can('mc_manage_events')) {
        wp_enqueue_style('my-calendar-admin-style');
    }
    $this_post = $wp_query->get_queried_object();
    $id = is_object($this_post) && isset($this_post->ID) ? $this_post->ID : false;
    $js_array = get_option('mc_show_js') != '' ? explode(",", get_option('mc_show_js')) : array();
    $css_array = get_option('mc_show_css') != '' ? explode(",", get_option('mc_show_css')) : array();
    // check whether any scripts are actually enabled.
    if (get_option('mc_calendar_javascript') != 1 || get_option('mc_list_javascript') != 1 || get_option('mc_mini_javascript') != 1 || get_option('mc_ajax_javascript') != 1) {
        if (@in_array($id, $js_array) || get_option('mc_show_js') == '' || is_singular('mc-events')) {
            wp_enqueue_script('jquery');
            if (get_option('mc_gmap') == 'true') {
                $api_key = get_option('mc_gmap_api_key');
                if ($api_key) {
                    wp_enqueue_script('gmaps', "https://maps.googleapis.com/maps/api/js?key={$api_key}");
                    wp_enqueue_script('gmap3', plugins_url('js/gmap3.min.js', __FILE__), array('jquery'));
                }
            }
        }
    }
    if (get_option('mc_use_styles') != 'true') {
        if (@in_array($id, $css_array) || get_option('mc_show_css') == '') {
            wp_enqueue_style('my-calendar-style');
        }
    }
    if (mc_is_tablet() && mc_file_exists('mc-tablet.css')) {
        $tablet = mc_get_file('mc-tablet.css');
        wp_register_style('my-calendar-tablet-style', $tablet);
        wp_enqueue_style('my-calendar-tablet-style');
    }
    if (mc_is_mobile() && mc_file_exists('mc-mobile.css')) {
        $mobile = mc_get_file('mc-mobile.css');
        wp_register_style('my-calendar-mobile-style', $mobile);
        wp_enqueue_style('my-calendar-mobile-style');
    }
}