136
|
1 |
<?php |
|
2 |
/* |
|
3 |
Plugin Name: AJAX Calendar |
|
4 |
Plugin URI: http://urbangiraffe.com/plugins/ajax-calendar/ |
|
5 |
Description: A version of the WordPress calendar that uses AJAX to allow the user to step through the months without updating the page. Additionally, a click on the 'expand' link shows all the posts within that month, inside the calendar. Caching of content can be enabled to increase speed. |
|
6 |
Version: 2.4.9 |
|
7 |
Author: John Godley |
|
8 |
Author URI: http://urbangiraffe.com |
|
9 |
*/ |
|
10 |
|
|
11 |
include_once (dirname (__FILE__).'/plugin.php'); |
|
12 |
include_once (dirname (__FILE__).'/models/widget.php'); |
|
13 |
|
|
14 |
if (!class_exists ('AJAX_Calendar')) |
|
15 |
{ |
|
16 |
class AJAX_Calendar extends AJAX_Calendar_Plugin |
|
17 |
{ |
|
18 |
function AJAX_Calendar () |
|
19 |
{ |
|
20 |
$this->register_plugin ('ajax-calendar', __FILE__); |
|
21 |
|
|
22 |
if (is_admin ()) |
|
23 |
{ |
|
24 |
$this->add_action ('publish_post', 'cache_remove'); |
|
25 |
$this->add_action ('save_post', 'cache_remove'); |
|
26 |
$this->add_action ('delete_post', 'cache_remove'); |
|
27 |
} |
|
28 |
else |
|
29 |
$this->add_action ('wp_head'); |
|
30 |
|
|
31 |
$this->widget = new AJAX_Calendar_Widget ('AJAX Calendar'); |
|
32 |
} |
|
33 |
|
|
34 |
function show ($categories = '') |
|
35 |
{ |
|
36 |
include_once (dirname (__FILE__).'/models/calendar.php'); |
|
37 |
|
|
38 |
$this->render ('calendar', array ('calendar' => new Calendar ($this->url (), $categories))); |
|
39 |
} |
|
40 |
|
|
41 |
function wp_head () |
|
42 |
{ |
|
43 |
$this->render ('head'); |
|
44 |
} |
|
45 |
|
|
46 |
function cache_remove ($id) |
|
47 |
{ |
|
48 |
$post = wp_get_single_post ($id); |
|
49 |
|
|
50 |
$postmonth = substr ($post->post_date, 5, 2); |
|
51 |
$postyear = substr ($post->post_date, 0, 4); |
|
52 |
$modmonth = substr ($post->post_modified, 5, 2); |
|
53 |
$modyear = substr ($post->post_modified, 0, 4); |
|
54 |
|
|
55 |
// Delete the cache files for the two dates, just in case something has changed |
|
56 |
for ($x = 0; $x < 2; $x++) |
|
57 |
{ |
|
58 |
wp_cache_delete ($postyear."_".$postmonth."_".$x); |
|
59 |
wp_cache_delete ($modyear."_".$modmonth."_".$x); |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
function &get () |
|
64 |
{ |
|
65 |
static $instance; |
|
66 |
|
|
67 |
if (!isset ($instance)) |
|
68 |
{ |
|
69 |
$c = __CLASS__; |
|
70 |
$instance = new $c; |
|
71 |
} |
|
72 |
|
|
73 |
return $instance; |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
function ajax_calendar ($categories = '') |
|
79 |
{ |
|
80 |
$calendar = AJAX_Calendar::get (); |
|
81 |
$calendar->show ($categories); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
|
|
86 |
$ajax_calendar_plugin = AJAX_Calendar::get (); |
|
87 |
|
|
88 |
?> |