136
|
1 |
<?php |
|
2 |
/* |
|
3 |
Plugin Name: Event Calendar Widget |
|
4 |
Plugin URI: http://wpcal.firetree.net |
|
5 |
Description: Adds sidebar widgets for Event Calendar and Upcoming Events. Requires the EventCalendar and <a href="http://automattic.com/code/widgets/">Widget</a> plugins (WordPress version 2.1 and earlier). After activating, please visit <a href="themes.php?page=widgets/widgets.php">Sidebar Widgets for WordPress version 2.1 and earlier</a> or <a href="widgets.php">Widgets for WordPress version 2.2 and subsequent</a> to configure and arrange your new widgets. |
|
6 |
Author: Darrell Schulte |
|
7 |
Version: 3.1.4 |
|
8 |
Author URI: http://wpcal.firetree.net |
|
9 |
|
|
10 |
This is a WordPress plugin (http://wordpress.org) and widget |
|
11 |
(http://automattic.com/code/widgets/). |
|
12 |
*/ |
|
13 |
|
|
14 |
/* |
|
15 |
Copyright (c) 2006, Darrell Schulte. $Revision: 285 $ |
|
16 |
|
|
17 |
This program is free software; you can redistribute it and/or |
|
18 |
modify it under the terms of the GNU General Public License |
|
19 |
as published by the Free Software Foundation; either version 2 |
|
20 |
of the License, or (at your option) any later version. |
|
21 |
|
|
22 |
This program is distributed in the hope that it will be useful, |
|
23 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
GNU General Public License for more details. |
|
26 |
|
|
27 |
You should have received a copy of the GNU General Public License |
|
28 |
along with this program; if not, write to the Free Software |
|
29 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
30 |
*/ |
|
31 |
|
|
32 |
function ec3_widget_init() |
|
33 |
{ |
|
34 |
|
|
35 |
if ( !function_exists('register_sidebar_widget') ) |
|
36 |
return; |
|
37 |
|
|
38 |
/** Utility function: Gets the (possibly translated) widget title, given the |
|
39 |
* value of the 'title' option. */ |
|
40 |
function ec3_widget_title($title,$default) |
|
41 |
{ |
|
42 |
if ( empty($title) ) |
|
43 |
return __($default,'ec3'); |
|
44 |
else |
|
45 |
return apply_filters('widget_title',$title); |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
/** Event Calendar widget. */ |
|
50 |
function ec3_widget_cal($args) |
|
51 |
{ |
|
52 |
extract($args); |
|
53 |
$options = get_option('ec3_widget_cal'); |
|
54 |
echo $before_widget . $before_title; |
|
55 |
echo ec3_widget_title($options['title'],'Event Calendar'); |
|
56 |
echo $after_title; |
|
57 |
ec3_get_calendar(); |
|
58 |
echo $after_widget; |
|
59 |
} |
|
60 |
|
|
61 |
function ec3_widget_cal_control() |
|
62 |
{ |
|
63 |
$options = $newoptions = get_option('ec3_widget_cal'); |
|
64 |
if ( $_POST["ec3_cal_submit"] ) |
|
65 |
{ |
|
66 |
$newoptions['title']=strip_tags(stripslashes($_POST["ec3_cal_title"])); |
|
67 |
} |
|
68 |
if ( $options != $newoptions ) |
|
69 |
{ |
|
70 |
$options = $newoptions; |
|
71 |
update_option('ec3_widget_cal', $options); |
|
72 |
} |
|
73 |
$title = ec3_widget_title($options['title'],'Event Calendar'); |
|
74 |
?> |
|
75 |
<p> |
|
76 |
<label for="ec3_cal_title"> |
|
77 |
<?php _e('Title:'); ?> |
|
78 |
<input class="widefat" id="ec3_cal_title" name="ec3_cal_title" |
|
79 |
type="text" value="<?php echo htmlspecialchars($title,ENT_QUOTES); ?>" /> |
|
80 |
</label> |
|
81 |
</p> |
|
82 |
|
|
83 |
<p><a href="options-general.php?page=ec3_admin"> |
|
84 |
<?php _e('Go to Event Calendar Options','ec3') ?>.</a> |
|
85 |
</p> |
|
86 |
|
|
87 |
<input type="hidden" name="ec3_cal_submit" value="1" /> |
|
88 |
<?php |
|
89 |
} |
|
90 |
|
|
91 |
wp_register_sidebar_widget( |
|
92 |
'event-calendar', |
|
93 |
__('Event Calendar','ec3'), |
|
94 |
'ec3_widget_cal', |
|
95 |
array('description' => |
|
96 |
__( 'Display upcoming events in a dynamic calendar.','ec3') |
|
97 |
. ' (Event Calendar '. __('Plugin') .')' ) |
|
98 |
); |
|
99 |
|
|
100 |
register_widget_control( |
|
101 |
array(__('Event Calendar','ec3'),'widgets'), |
|
102 |
'ec3_widget_cal_control' |
|
103 |
); |
|
104 |
|
|
105 |
|
|
106 |
/** Upcoming Events widget. */ |
|
107 |
function ec3_widget_list($args) |
|
108 |
{ |
|
109 |
extract($args); |
|
110 |
$options = get_option('ec3_widget_list'); |
|
111 |
echo $before_widget . $before_title; |
|
112 |
echo ec3_widget_title($options['title'],'Upcoming Events'); |
|
113 |
echo $after_title; |
|
114 |
ec3_get_events( |
|
115 |
$options['limit'], |
|
116 |
EC3_DEFAULT_TEMPLATE_EVENT, |
|
117 |
EC3_DEFAULT_TEMPLATE_DAY, |
|
118 |
get_option('date_format') |
|
119 |
); |
|
120 |
echo $after_widget; |
|
121 |
} |
|
122 |
|
|
123 |
function ec3_widget_list_control() |
|
124 |
{ |
|
125 |
$options = $newoptions = get_option('ec3_widget_list'); |
|
126 |
if ( $_POST["ec3_list_submit"] ) |
|
127 |
{ |
|
128 |
$newoptions['title'] = strip_tags(stripslashes($_POST["ec3_list_title"])); |
|
129 |
$newoptions['limit'] = strip_tags(stripslashes($_POST["ec3_limit"])); |
|
130 |
} |
|
131 |
if ( $options != $newoptions ) |
|
132 |
{ |
|
133 |
$options = $newoptions; |
|
134 |
update_option('ec3_widget_list', $options); |
|
135 |
} |
|
136 |
|
|
137 |
$title = ec3_widget_title($options['title'],'Upcoming Events'); |
|
138 |
$limit = $options['limit']; |
|
139 |
|
|
140 |
$ec3_limit_title = |
|
141 |
__("Examples: '5', '5 days', '5d'. To display recent past events, use a negative number: '-5'."); |
|
142 |
?> |
|
143 |
|
|
144 |
<p> |
|
145 |
<label for="ec3_list_title"> |
|
146 |
<?php _e('Title:'); ?> |
|
147 |
<input class="widefat" id="ec3_list_title" name="ec3_list_title" |
|
148 |
type="text" value="<?php echo htmlspecialchars($title,ENT_QUOTES); ?>" /> |
|
149 |
</label> |
|
150 |
</p> |
|
151 |
<p> |
|
152 |
<label for="ec3_limit" title="<?php echo $ec3_limit_title ?>"> |
|
153 |
<?php _e('Number of events:','ec3'); ?> |
|
154 |
<input class="widefat" style="width: 50px; text-align: center;" |
|
155 |
id="ec3_limit" name="ec3_limit" type="text" |
|
156 |
value="<?php echo $limit? $limit: '5'; ?>" /> |
|
157 |
</label> |
|
158 |
</p> |
|
159 |
|
|
160 |
<p> |
|
161 |
<a href="options-general.php?page=ec3_admin"> |
|
162 |
<?php _e('Go to Event Calendar Options','ec3') ?>.</a> |
|
163 |
</p> |
|
164 |
|
|
165 |
<input type="hidden" name="ec3_list_submit" value="1" /> |
|
166 |
|
|
167 |
<?php |
|
168 |
} |
|
169 |
|
|
170 |
wp_register_sidebar_widget( |
|
171 |
'upcoming-events', |
|
172 |
__('Upcoming Events','ec3'), |
|
173 |
'ec3_widget_list', |
|
174 |
array('description' => |
|
175 |
__('Display upcoming events as a list.','ec3') |
|
176 |
. ' (Event Calendar '. __('Plugin') .')' ) |
|
177 |
); |
|
178 |
|
|
179 |
register_widget_control( |
|
180 |
array(__('Upcoming Events','ec3'),'widgets'), |
|
181 |
'ec3_widget_list_control' |
|
182 |
); |
|
183 |
} |
|
184 |
|
|
185 |
add_action('widgets_init', 'ec3_widget_init'); |
|
186 |
|
|
187 |
|
|
188 |
?> |