예제 #1
0
function my_calendar_wp_head()
{
    global $wpdb, $wp_query;
    $mcdb = $wpdb;
    $array = array();
    if (get_option('mc_use_styles') != 'true') {
        $this_post = $wp_query->get_queried_object();
        $id = is_object($this_post) && isset($this_post->ID) ? $this_post->ID : false;
        $array = get_option('mc_show_css') != '' ? explode(",", get_option('mc_show_css')) : $array;
        if (@in_array($id, $array) || get_option('mc_show_css') == '') {
            // generate category colors
            $category_styles = $inv = $type = $alt = '';
            $categories = $mcdb->get_results("SELECT * FROM " . MY_CALENDAR_CATEGORIES_TABLE . " ORDER BY category_id ASC");
            foreach ($categories as $category) {
                $class = "mc_" . sanitize_title($category->category_name);
                $hex = strpos($category->category_color, '#') !== 0 ? '#' : '';
                $color = $hex . $category->category_color;
                if ($color != '#') {
                    $hcolor = mc_shift_color($category->category_color);
                    if (get_option('mc_apply_color') == 'font') {
                        $type = 'color';
                        $alt = 'background';
                    } else {
                        if (get_option('mc_apply_color') == 'background') {
                            $type = 'background';
                            $alt = 'color';
                        }
                    }
                    if (get_option('mc_inverse_color') == 'true') {
                        $inverse = mc_inverse_color($color);
                        $inv = "{$alt}: {$inverse};";
                    }
                    if (get_option('mc_apply_color') == 'font' || get_option('mc_apply_color') == 'background') {
                        // always an anchor as of 1.11.0, apply also to title
                        $category_styles .= "\n.mc-main .{$class} .event-title, .mc-main .{$class} .event-title a { {$type}: {$color}; {$inv} }";
                        $category_styles .= "\n.mc-main .{$class} .event-title a:hover, .mc-main .{$class} .event-title a:focus { {$type}: {$hcolor};}";
                    }
                }
            }
            $all_styles = "\n<style type=\"text/css\">\n<!--\n.mcjs .mc-main .details, .mcjs .mc-main .calendar-events { display: none; }\n/* Styles by My Calendar - Joseph C Dolson http://www.joedolson.com/ */\n{$category_styles}\n.mc-event-visible {\ndisplay: block!important;\n}\n-->\n</style>";
            echo $all_styles;
        }
    }
}
function mc_manage_categories()
{
    global $wpdb;
    $mcdb = $wpdb;
    ?>
	<h2><?php 
    _e('Manage Categories', 'my-calendar');
    ?>
</h2><?php 
    $co = !isset($_GET['co']) ? 1 : (int) $_GET['co'];
    switch ($co) {
        case 1:
            $cat_order = 'category_id';
            break;
        case 2:
            $cat_order = 'category_name';
            break;
        default:
            $cat_order = 'category_id';
    }
    // We pull the categories from the database
    $categories = $mcdb->get_results("SELECT * FROM " . my_calendar_categories_table() . " ORDER BY {$cat_order} ASC");
    if (!empty($categories)) {
        ?>
		<table class="widefat page fixed mc-categories" id="my-calendar-admin-table">
		<thead>
		<tr>
			<th scope="col"><?php 
        echo $co == 2 ? "<a href='" . admin_url("admin.php?page=my-calendar-categories&amp;co=1") . "'>" : '';
        _e('ID', 'my-calendar');
        echo $co == 2 ? '</a>' : '';
        ?>
</th>
			<th scope="col"><?php 
        echo $co == 1 ? "<a href='" . admin_url("admin.php?page=my-calendar-categories&amp;co=2") . "'>" : '';
        _e('Category Name', 'my-calendar');
        echo $co == 1 ? '</a>' : '';
        ?>
</th>
			<th scope="col"><?php 
        _e('Color/Icon', 'my-calendar');
        ?>
</th>
			<th scope="col"><?php 
        _e('Private', 'my-calendar');
        ?>
</th>
			<th scope="col"><?php 
        _e('Edit', 'my-calendar');
        ?>
</th>
			<th scope="col"><?php 
        _e('Delete', 'my-calendar');
        ?>
</th>
		</tr>
		</thead>
		<?php 
        $class = '';
        foreach ($categories as $cat) {
            $class = $class == 'alternate' ? '' : 'alternate';
            $icon_src = mc_file_exists($cat->category_icon) ? mc_get_file($cat->category_icon, 'url') : plugins_url('my-calendar/images/icons/' . $cat->category_icon);
            $background = strpos($cat->category_color, '#') !== 0 ? '#' : '' . $cat->category_color;
            $foreground = mc_inverse_color($background);
            ?>
		<tr class="<?php 
            echo $class;
            ?>
">
			<th scope="row"><?php 
            echo $cat->category_id;
            ?>
</th>
			<td><?php 
            echo stripslashes($cat->category_name);
            if ($cat->category_id == get_option('mc_default_category')) {
                echo ' ' . __('(Default)');
            }
            if ($cat->category_id == get_option('mc_skip_holidays_category')) {
                echo ' ' . __('(Holiday)');
            }
            ?>
</td>
			<td style="background-color:<?php 
            echo $background;
            ?>
;color: <?php 
            echo $foreground;
            ?>
"><img src="<?php 
            echo $icon_src;
            ?>
" alt=""/> <?php 
            echo $background;
            ?>
</td>
			<td><?php 
            echo $cat->category_private == 1 ? __('Yes', 'my-calendar') : __('No', 'my-calendar');
            ?>
</td>
			<td><a
				href="<?php 
            echo admin_url("admin.php?page=my-calendar-categories&amp;mode=edit&amp;category_id={$cat->category_id}");
            ?>
"
				class='edit'><?php 
            _e('Edit', 'my-calendar');
            ?>
</a></td><?php 
            if ($cat->category_id == 1) {
                echo '<td>' . __('N/A', 'my-calendar') . '</td>';
            } else {
                ?>
				<td><a
					href="<?php 
                echo admin_url("admin.php?page=my-calendar-categories&amp;mode=delete&amp;category_id={$cat->category_id}");
                ?>
"
					class="delete"
					onclick="return confirm('<?php 
                _e('Are you sure you want to delete this category?', 'my-calendar');
                ?>
')"><?php 
                _e('Delete', 'my-calendar');
                ?>
</a>
				</td><?php 
            }
            ?>
			</tr><?php 
        }
        ?>
		</table><?php 
    } else {
        echo '<p>' . __('There are no categories in the database - or something has gone wrong!', 'my-calendar') . '</p>';
    }
}