root/trunk/admin.inc.php

Revision 3, 43.9 KB (checked in by jonathan, 3 years ago)

Initial import -- WPListCal 1.2.2

Line 
1<?php
2/*
3WPListCal Admin functions
4
5Permission is hereby granted, free of charge, to any person or organization
6obtaining a copy of the software and accompanying documentation covered by
7this license (the "Software") to use, reproduce, display, distribute,
8execute, and transmit the Software, and to prepare derivative works of the
9Software, and to permit third-parties to whom the Software is furnished to
10do so, all subject to the following:
11
12The copyright notices in the Software and this entire statement, including
13the above license grant and author attributions, this restriction, and the
14following disclaimer, must be included in all copies of the Software, in
15whole or in part, and all derivative works of the Software, unless such
16copies or derivative works are solely in the form of machine-executable
17object code generated by a source language processor.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26*/
27
28if(wplc_is_wplc_page()) {
29        add_action( 'admin_head', 'wplc_editor_init' );
30        function wplc_editor_init() {
31                wp_admin_css('thickbox');
32                wp_print_scripts('editor');
33                add_thickbox();
34                wp_print_scripts('media-upload');
35                wp_print_scripts('jquery');
36                wp_print_scripts('jquery-ui-core');
37                wp_print_scripts('jquery-ui-tabs');
38                if(function_exists('wp_tiny_mce')) wp_tiny_mce();
39        }
40}
41
42function wplc_show_event_form($event=array(), $message=null, $export=false) {
43        wplc_setup();
44        global $wplc_domain;
45       
46        wplc_upgrade_if_needed();
47       
48        $editing = count($event) != 0;
49       
50        $use_24hr_time = get_option("wplc_use_24hr_time");
51        if(!is_bool($use_24hr_time)) {
52                $use_24hr_time = $use_24hr_time == "true";
53        }
54
55        // Prep event times
56        $d = $event['event_start_time'];
57        if(empty($d))
58                $d = wplc_time();
59        $date['event_start_month'] = date('n', $d);
60        $date['event_start_day'] = date('j', $d);
61        $date['event_start_year'] = date('Y', $d);
62        if($use_24hr_time)
63                $date['event_start_hour'] = date('G', $d);
64        else
65                $date['event_start_hour'] = date('g', $d);
66        $date['event_start_minute'] = date('i', $d);
67        if(!$use_24hr_time)
68                $date['event_start_ampm'] = date('A', $d);
69       
70        $d = $event['event_end_time'];
71        if(empty($d))
72                $d = wplc_time() + 3600;
73        $date['event_end_month'] = date('n', $d);
74        $date['event_end_day'] = date('j', $d);
75        $date['event_end_year'] = date('Y', $d);
76        if($use_24hr_time)
77                $date['event_end_hour'] = date('G', $d);
78        else
79                $date['event_end_hour'] = date('g', $d);
80        $date['event_end_minute'] = date('i', $d);
81        if(!$use_24hr_time)
82                $date['event_end_ampm'] = date('A', $d);
83               
84        get_currentuserinfo();
85        global $user_ID;
86       
87        if($editing) {
88                $time_format = "M j, Y @ ";
89               
90                if($use_24hr_time) {
91                        $time_format .= "G:i";
92                }
93                else {
94                        $time_format .= "g:ia";
95                }
96               
97                if($event['event_create_time'] == '0') {
98                        $create_time = __("N/A", $wplc_domain);
99                }
100                else {
101                        $create_time = date($time_format, $event['event_create_time']);
102                }
103                if($event['event_modified_time'] == '0') {
104                        $modified_time = __("N/A", $wplc_domain);
105                }
106                else {
107                        $modified_time = date($time_format, $event['event_modified_time']);
108                }
109               
110                if($event['event_author'] == null) {
111                        $author = __("N/A", $wplc_domain);
112                }
113                else {
114                        $author = $event['event_author'];
115                }
116        }
117       
118        if(!is_null($message)) {
119        ?>
120                <div id="message" class="updated fade">
121                        <p>
122                                <?php echo $message; ?>
123                        </p>
124                </div>
125        <?php
126        }
127        ?>
128        <div class="wrap">
129                <h2><?php echo $editing ? __("Edit Event", $wplc_domain) : __("Add New Event", $wplc_domain); ?></h2>
130                <form name="event" id="event" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
131                        <input type="hidden" id="user-id" name="user_ID" value="<?php echo (int) $user_ID ?>" />
132                        <div id="poststuff">
133                                <div style="position:relative;" class="has-right-sidebar">
134                                        <div class="inner-sidebar">
135                                                <div class="postbox" id="submitdiv">
136                                                        <h3 class="wplc_plaincursor">
137                                                                <span><?php _e('Publish', $wplc_domain); ?></span>
138                                                        </h3>
139                                                        <div class="inside">
140                                                                <div class="submitbox">
141                                                                        <div id="minor-publishing">
142                                                                                <?php if($editing) { ?>
143                                                                                        <div class="misc-pub-section">
144                                                                                                <label class="wplc_baseline"><?php _e("Author:", $wplc_domain); ?></label>
145                                                                                                <b><?php echo $author; ?></b>
146                                                                                        </div>
147                                                                                        <div class="misc-pub-section">
148                                                                                                <label class="wplc_baseline"><?php _e("Published on:", $wplc_domain); ?></label>
149                                                                                                <b><?php echo $create_time; ?></b>
150                                                                                        </div>
151                                                                                        <?php if($create_time != $modified_time) { ?>
152                                                                                                <div class="misc-pub-section">
153                                                                                                        <label class="wplc_baseline"><?php _e("Modified on:", $wplc_domain); ?></label>
154                                                                                                        <b><?php echo $modified_time; ?></b>
155                                                                                                </div>
156                                                                                        <?php } ?>
157                                                                                        <div class="misc-pub-section misc-pub-section-last">
158                                                                                                <?php
159                                                                                                if($editing) {
160                                                                                                        $dellink = "admin.php?page=wplc-edit&op=delete&id=".$event['id'];
161                                                                                                        $dellink = (function_exists('wp_nonce_url')) ? wp_nonce_url($dellink, 'wplc-delete-event') : $dellink;
162                                                                                                        echo "<a class='submitdelete' href='".$dellink."' onclick=\"if(confirm('".__('You are about to delete this event \\\''.stripslashes($event['event_name']).'\\\'\n \\\'Cancel\\\' to stop, \\\'OK\\\' to delete.', $wplc_domain)."')) { return true; } return false;\">".__("Delete Event", $wplc_domain)."</a>";
163                                                                                                        ?> |
164                                                                                                        <a class='wplc_link' href="admin.php?page=wplc-edit&amp;op=editexport&amp;id=<?php echo $event['id']; ?>"><?php _e("Export", $wplc_domain); ?></a>
165                                                                                                        <?php
166                                                                                                }
167                                                                                                ?>
168                                                                                        </div>
169                                                                                <?php }
170                                                                                else {
171                                                                                        echo "&nbsp;";
172                                                                                } ?>
173                                                                        </div>
174                                                                        <div id="major-publishing-actions">
175                                                                                <div id="delete-action">
176                                                                                        <input type="submit" name="saveandnew" id="save-new-post" value="<?php _e('Save and new', $wplc_domain); ?>" tabindex="16" class="button" />
177                                                                                </div>
178                                                                                <div id="publishing-action">
179                                                                                        <input type="submit" name="save" id="save-post" value="<?php _e('Save', $wplc_domain); ?>" tabindex="17" class="button-primary" />
180                                                                                </div>
181                                                                                <div class="clear"></div>
182                                                                        </div>
183                                                                </div>
184                                                        </div>
185                                                </div>
186                                        </div>
187                                <div id="post-body" class="has-sidebar">
188                                        <div id="post-body-content" class="has-sidebar-content">
189                                                <input type="hidden" name="action" value="submitted" />
190                                                <?php
191                                                if($editing) {
192                                                ?>
193                                                        <input type="hidden" name="id" value="<?php echo $event['id']; ?>" />
194                                                <?php
195                                                }
196                                                ?>
197                                                <div id="titlediv-noformat" class="postbox">
198                                                        <h3 class="wplc_plaincursor"><?php _e('Title', $wplc_domain); ?></h3>
199                                                        <div id="titlewrap-noformat" class="inside">
200                                                                <label class="hidden" for="title-noformat">Title</label>
201                                                                <input type="text" name="event_name" size="30" tabindex="1" value="<?php echo stripslashes(stripslashes($event['event_name'])); ?>" id="title-noformat" />
202                                                        </div>
203                                                </div>
204                                               
205                                                <div id="locdiv" class="postbox">
206                                                        <h3 class="wplc_plaincursor"><?php _e('Location', $wplc_domain); ?></h3>
207                                                        <div id="locwrap" class="inside">
208                                                                <label class="hidden" for="location">Location</label>
209                                                                <input type="text" name="event_loc" size="30" tabindex="2" value="<?php echo stripslashes(stripslashes($event['event_loc'])); ?>" id="location" />
210                                                        </div>
211                                                </div>
212                                       
213                                                <div id="linkdiv" class="postbox">
214                                                        <h3 class="wplc_plaincursor"><?php _e('Link', $wplc_domain); ?></h3>
215                                                        <div id="linkwrap" class="inside">
216                                                                <label class="hidden" for="link">Link</label>
217                                                                <input type="text" name="event_link" size="30" tabindex="2" value="<?php echo stripslashes(stripslashes($event['event_link'])); ?>" id="link" />
218                                                        </div>
219                                                </div>
220
221                                                <div id="startdiv" class="postbox">
222                                                        <h3 class="wplc_plaincursor"><?php _e('Date/Time', $wplc_domain); ?></h3>
223                                                        <div id="startwrap" class="inside">
224                                                                <div style="clear:both;float:none;">
225                                                                        <label class="wplc_date_label">Start:</label>
226                                                                        <div class="wplc_date_body">
227                                                                                <?php
228                                                                                        $s[$date['event_start_month']] = " selected='selected'";
229                                                                                ?>
230                                                                                <select name="start-month" id="start-month" onchange="wplc_matchValue('start-month', 'end-month', true);" tabindex="3">
231                                                                                        <option value="1"<?php echo $s['1']; ?>><?php _e('Jan', $wplc_domain); ?></option>
232                                                                                        <option value="2"<?php echo $s['2']; ?>><?php _e('Feb', $wplc_domain); ?></option>
233                                                                                        <option value="3"<?php echo $s['3']; ?>><?php _e('Mar', $wplc_domain); ?></option>
234                                                                                        <option value="4"<?php echo $s['4']; ?>><?php _e('Apr', $wplc_domain); ?></option>
235                                                                                        <option value="5"<?php echo $s['5']; ?>><?php _e('May', $wplc_domain); ?></option>
236                                                                                        <option value="6"<?php echo $s['6']; ?>><?php _e('Jun', $wplc_domain); ?></option>
237                                                                                        <option value="7"<?php echo $s['7']; ?>><?php _e('Jul', $wplc_domain); ?></option>
238                                                                                        <option value="8"<?php echo $s['8']; ?>><?php _e('Aug', $wplc_domain); ?></option>
239                                                                                        <option value="9"<?php echo $s['9']; ?>><?php _e('Sep', $wplc_domain); ?></option>
240                                                                                        <option value="10"<?php echo $s['10']; ?>><?php _e('Oct', $wplc_domain); ?></option>
241                                                                                        <option value="11"<?php echo $s['11']; ?>><?php _e('Nov', $wplc_domain); ?></option>
242                                                                                        <option value="12"<?php echo $s['12']; ?>><?php _e('Dec', $wplc_domain); ?></option>
243                                                                                </select>
244                                                                                <input type="text" name="start-day" id="start-day" size="2" maxlength="2" value="<?php echo $date['event_start_day']; ?>" tabindex="4" onblur="wplc_matchValue('start-day', 'end-day', false);" />
245                                                                                <input type="text" name="start-year" id="start-year" size="4" maxlength="4" value="<?php echo $date['event_start_year']; ?>" tabindex="5" onblur="wplc_matchValue('start-year', 'end-year', false);" />
246                                                                                <span id="start-time-cont"<?php echo $event['event_allday']==1 ? " style='visibility:hidden;'" : ""; ?>>
247                                                                                        @ <input type="text" name="start-hour" id="start-hour" size="2" maxlength="2" value="<?php echo $date['event_start_hour']; ?>" tabindex="6" onblur="wplc_matchValue('start-hour', 'end-hour', false);" />
248                                                                                        : <input type="text" name="start-minute" id="start-minute" size="2" maxlength="2" value="<?php echo $date['event_start_minute']; ?>" tabindex="7" onblur="wplc_matchValue('start-minute', 'end-minute', false);" />
249                                                                                        <?php
250                                                                                                if(!$use_24hr_time) {
251                                                                                                        $s[$date['event_start_ampm']] = " selected='selected'";
252                                                                                        ?>
253                                                                                        <select name="start-ampm" id="start-ampm" tabindex="8" onchange="wplc_matchValue('start-ampm', 'end-ampm', true);">
254                                                                                                <option value="AM"<?php echo $s['AM']; ?>>AM</option>
255                                                                                                <option value="PM"<?php echo $s['PM']; ?>>PM</option>
256                                                                                        </select>
257                                                                                </span>
258                                                                                <?php
259                                                                                        }
260                                                                                ?>
261                                                                        </div>
262                                                                </div>
263                                                                <div style="padding-top:15px;clear:both;float:none;">
264                                                                        <label class="wplc_date_label">End:</label>
265                                                                        <div class="wplc_date_body">
266                                                                                <?php
267                                                                                        unset($s);
268                                                                                        $s[$date['event_end_month']] = " selected='selected'";
269                                                                                ?>
270                                                                                <select name="end-month" tabindex="9" id="end-month" onfocus="editable = true;" onblur="editable = false;" onchange="fieldsDirty = editable ? true : fieldsDirty;">
271                                                                                        <option value="1"<?php echo $s['1']; ?>><?php _e('Jan', $wplc_domain); ?></option>
272                                                                                        <option value="2"<?php echo $s['2']; ?>><?php _e('Feb', $wplc_domain); ?></option>
273                                                                                        <option value="3"<?php echo $s['3']; ?>><?php _e('Mar', $wplc_domain); ?></option>
274                                                                                        <option value="4"<?php echo $s['4']; ?>><?php _e('Apr', $wplc_domain); ?></option>
275                                                                                        <option value="5"<?php echo $s['5']; ?>><?php _e('May', $wplc_domain); ?></option>
276                                                                                        <option value="6"<?php echo $s['6']; ?>><?php _e('Jun', $wplc_domain); ?></option>
277                                                                                        <option value="7"<?php echo $s['7']; ?>><?php _e('Jul', $wplc_domain); ?></option>
278                                                                                        <option value="8"<?php echo $s['8']; ?>><?php _e('Aug', $wplc_domain); ?></option>
279                                                                                        <option value="9"<?php echo $s['9']; ?>><?php _e('Sep', $wplc_domain); ?></option>
280                                                                                        <option value="10"<?php echo $s['10']; ?>><?php _e('Oct', $wplc_domain); ?></option>
281                                                                                        <option value="11"<?php echo $s['11']; ?>><?php _e('Nov', $wplc_domain); ?></option>
282                                                                                        <option value="12"<?php echo $s['12']; ?>><?php _e('Dec', $wplc_domain); ?></option>
283                                                                                </select>
284                                                                                <input type="text" name="end-day" id="end-day" size="2" maxlength="2" value="<?php echo $date['event_end_day']; ?>" tabindex="10" onfocus="editable = true;" onblur="editable = false;" onchange="fieldsDirty = editable ? true : fieldsDirty;" />
285                                                                                <input type="text" name="end-year" id="end-year" size="4" maxlength="4" value="<?php echo $date['event_end_year']; ?>" tabindex="11" onfocus="editable = true;" onblur="editable = false;" onchange="fieldsDirty = editable ? true : fieldsDirty;" />
286                                                                                <span id="end-time-cont"<?php echo $event['event_allday']==1 ? " style='visibility:hidden;'" : ""; ?>>
287                                                                                        @ <input type="text" name="end-hour" id="end-hour" size="2" maxlength="2" value="<?php echo $date['event_end_hour']; ?>" tabindex="12" onfocus="editable = true;" onblur="editable = false;" onchange="fieldsDirty = editable ? true : fieldsDirty;" />
288                                                                                        : <input type="text" name="end-minute" id="end-minute" size="2" maxlength="2" value="<?php echo $date['event_end_minute']; ?>" tabindex="13" onfocus="editable = true;" onblur="editable = false;" onchange="fieldsDirty = editable ? true : fieldsDirty;" />
289                                                                                        <?php
290                                                                                                if(!$use_24hr_time) {
291                                                                                                        $s[$date['event_end_ampm']] = " selected='selected'";
292                                                                                        ?>
293                                                                                        <select name="end-ampm" id="end-ampm" tabindex="14" onfocus="editable = true;" onblur="editable = false;" onchange="fieldsDirty = editable ? true : fieldsDirty;">
294                                                                                                <option value="AM"<?php echo $s['AM']; ?>>AM</option>
295                                                                                                <option value="PM"<?php echo $s['PM']; ?>>PM</option>
296                                                                                        </select>
297                                                                                </span>
298                                                                                <?php
299                                                                                        }
300                                                                                ?>
301                                                                        </div>
302                                                                </div>
303                                                                <div style="clear:both;">
304                                                                        &nbsp;
305                                                                </div>
306                                                        </div>
307                                                </div>
308       
309                                                <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
310                                                        <?php
311                                                        the_editor(stripslashes(stripslashes($event['event_desc'])) /*content*/, "content" /*id*/, "end-ampm" /*prev_id*/, true /*media_buttons*/, 15 /*tab_index*/);
312                                                        ?>
313                                                </div>
314                                        </div>
315                                </div>
316                        </div>
317                </form>
318        </div>
319        <script type="text/javascript" charset="utf-8">
320        //<![CDATA[
321        try{document.getElementById("title-noformat").focus();} catch(e) {}
322        //]]>
323        </script>
324        <?php
325       
326        if($export) {
327                wplc_export_events($event['id']);
328        }
329}
330
331function wplc_process_event($postvars) {
332        wplc_setup();
333        global $wplc_domain, $wpdb, $current_user;
334        get_currentuserinfo();
335
336        $gobacktoeditform = !empty($postvars['save']);
337
338        $name = addslashes($postvars['event_name']);
339        $location = addslashes($postvars['event_loc']);
340        $link = addslashes($postvars['event_link']);
341        $description = addslashes($postvars['content']);
342       
343        $tbl_name = $wpdb->escape(get_option("wplc_tbl_name"));
344       
345        $allday = $postvars['event_allday'] == 1;
346        if($allday) {
347                $start_time = "0:00";
348                $end_time = "23:59";
349        }
350        else {
351                $start_time = addslashes($postvars['start-hour']).":".
352                addslashes($postvars['start-minute']).
353                $postvars['start-ampm'];
354               
355                $end_time = addslashes($postvars['end-hour']).":".
356                addslashes($postvars['end-minute']).
357                $postvars['end-ampm'];
358        }
359
360        // Get timestamps from date/time info
361        $startstr = addslashes($postvars['start-year'])."-".
362                                $postvars['start-month']."-".
363                                addslashes($postvars['start-day'])." ".
364                                $start_time;
365        $endstr = addslashes($postvars['end-year'])."-".
366                                $postvars['end-month']."-".
367                                addslashes($postvars['end-day'])." ".
368                                $end_time;
369        $start = strtotime($startstr);
370        $end = strtotime($endstr);
371       
372        $author = $current_user->ID;
373        $create_mod_time = wplc_time();
374
375        // Validation & Error Handling
376        // If name is empty, just refresh the post page
377        if(empty($name)) {
378                wplc_show_event_form();
379                return;
380        }
381        // If start time is invalid, use NOW
382        if($start === -1 || $start === false)
383                $start = wplc_time();
384        // If end time is invalid, use start
385        if($end === -1 || $end === false)
386                $end = $start;
387        // If end is before start time, set end to start
388        if($end < $start)
389                $end = $start;
390       
391        // Add data to db
392        if(empty($postvars['id'])) {
393                $insert = "INSERT INTO ".$tbl_name.
394                                  " (event_name, event_link, event_loc, event_desc, event_start_time, event_end_time, event_allday, event_author, event_create_time, event_modified_time) ".
395                                  "VALUES('".$wpdb->escape($name)."',
396                                                  '".$wpdb->escape($link)."',
397                                                  '".$wpdb->escape($location)."',
398                                                  '".$wpdb->escape($description)."',
399                                                  '".$wpdb->escape($start)."',
400                                                  '".$wpdb->escape($end)."',
401                                                  ".$wpdb->escape($allday ? '1' : '0').",
402                                                  '".$wpdb->escape($author)."',
403                                                  '".$wpdb->escape($create_mod_time)."',
404                                                  '".$wpdb->escape($create_mod_time)."');";
405                $results = $wpdb->query($insert);
406        }
407        else {
408                $update = "UPDATE ".$tbl_name.
409                                  " SET event_name='".$wpdb->escape($name)."',".
410                                  "event_link='".$wpdb->escape($link)."',".
411                                  "event_loc='".$wpdb->escape($location)."',".
412                                  "event_desc='".$wpdb->escape($description)."',".
413                                  "event_start_time='".$wpdb->escape($start)."',".
414                                  "event_end_time='".$wpdb->escape($end)."',".
415                                  "event_allday=".$wpdb->escape($allday ? '1' : '0').",".
416                                  "event_modified_time='".$wpdb->escape($create_mod_time)."' ".
417                                  "WHERE id=".$wpdb->escape($postvars['id']);
418                $results = $wpdb->query($update);
419        }
420       
421        $msg = empty($postvars['id']) ? __("Event Added", $wplc_domain) : __("Event Updated", $wplc_domain);
422       
423        if($gobacktoeditform) {
424                $id = empty($postvars['id']) ? $wpdb->insert_id : $postvars['id'];
425                $sql = "SELECT e.*, u.display_name as event_author FROM ".$wpdb->escape(get_option("wplc_tbl_name"))." e LEFT JOIN ".$wpdb->users." u ON e.event_author = u.ID WHERE e.id=".$wpdb->escape($id);
426                $event = $wpdb->get_results($sql, ARRAY_A);
427
428                // Show edit form
429                wplc_show_event_form($event[0], $msg);
430        }
431        else {
432                wplc_show_event_form(array(), $msg);
433        }
434}
435
436function wplc_show_admin_write_page() {
437        wplc_setup();
438        global $wplc_domain;
439
440        $action = $_POST['action'];
441        if($action == "submitted") {
442                wplc_process_event($_POST);
443        }
444        else
445                wplc_show_event_form();
446}
447
448add_action('admin_menu', 'wplc_add_admin_pages');
449function wplc_add_admin_pages() {
450        wplc_setup();
451        global $wplc_domain, $wplc_dir, $wplc_plugin;
452       
453        add_object_page(__("Events"), __("Events"), 2, $wplc_plugin, "wplc_show_admin_write_page", $wplc_dir."/icon.gif");
454       
455        add_submenu_page($wplc_plugin, __("Add New Event", $wplc_domain), __("Add New", $wplc_domain), "edit_posts", $wplc_plugin, "wplc_show_admin_write_page");
456        add_submenu_page($wplc_plugin, __("Edit Events", $wplc_domain), __("Edit", $wplc_domain), "edit_posts", "wplc-edit", "wplc_show_admin_manage_page");
457        // Import not ready for release
458        //add_submenu_page($wplc_plugin, __("Import Events", $wplc_domain), __("Import", $wplc_domain), "import", "wplc-import", "wplc_show_import_page");
459        add_submenu_page($wplc_plugin, __("Export Events", $wplc_domain), __("Export", $wplc_domain), "read", "wplc-export", "wplc_show_export_page");
460        add_submenu_page($wplc_plugin, __("Cleanup Events", $wplc_domain), __("Cleanup", $wplc_domain), "delete_posts", "wplc-cleanup", "wplc_show_admin_cleanup_page");
461        add_options_page(__("WPListCal Settings", $wplc_domain), __("WPListCal", $wplc_domain), "manage_options", "wplc-options", "wplc_show_admin_options_page");
462}
463
464add_filter("favorite_actions", "wplc_favorite_actions_filter");
465function wplc_favorite_actions_filter($actions) {
466        global $wplc_plugin, $wplc_domain;
467        wplc_setup();
468       
469        $actions['admin.php?page='.$wplc_plugin] = array(__("New Event", $wplc_domain), "edit_posts");
470        return $actions;
471}
472
473add_action("right_now_table_end", "wplc_activity_box");
474function wplc_activity_box() {
475        global $wpdb;
476        $tbl_name = get_option("wplc_tbl_name");
477        $sql = "SELECT COUNT(*) FROM $tbl_name";
478        $num = $wpdb->get_var($wpdb->escape($sql));
479        $num = number_format_i18n($num);
480        ?>
481        <tr>
482                <td class="first b b-events"><a href="admin.php?page=wplc-edit"><?php echo $num; ?></a></td>
483                <td class="t events"><?php echo __ngettext( 'Event', 'Events', $num ); ?></td>
484                <td class="b">&nbsp;</td>
485                <td class="t last">&nbsp;</td>
486        </tr>
487        <?php
488}
489
490add_filter("plugin_action_links_$wplc_plugin", 'wplc_actlinks' ); 
491function wplc_actlinks($links) { 
492        global $wplc_plugin;
493        // Add a link to this plugin's settings page
494        $settings_link = '<a href="options-general.php?page=wplc-options">Settings</a>'; 
495        array_unshift( $links, $settings_link ); 
496        return $links; 
497}
498
499add_action("wp_ajax_wplc_delete_event", "wplc_delete_event");
500function wplc_delete_event($id=null) {
501        wplc_setup();
502        global $wplc_domain, $wpdb;
503       
504        if($id == null)
505                $id = $wpdb->escape($_POST['id']);
506               
507        $tbl_name = $wpdb->escape(get_option("wplc_tbl_name"));
508       
509        $sql = "DELETE FROM ".$tbl_name." WHERE id=".$id;
510        $wpdb->query($sql);
511}
512
513function wplc_show_admin_manage_page() {
514        wplc_setup();
515        global $wplc_domain, $wpdb, $wplc_plugin;
516       
517        wplc_upgrade_if_needed();
518       
519        if($_POST['action'] == "delete") {
520                wplc_delete_event($_POST['id']);
521                return;
522        }
523       
524        if(($_GET['op'] == 'edit' || $_GET['op'] == 'editexport') && isset($_GET['id'])) {
525                wplc_show_admin_edit_page($_GET['id'], $_GET['op'] == 'editexport');
526                return;
527        }
528       
529        if($_GET['op'] == 'delete') {
530                if(function_exists('wp_nonce_url')) {
531                        check_admin_referer('wplc-delete-event');
532                }
533               
534                wplc_delete_event($_GET['id']);
535               
536                // Set message
537                $message = __("Event deleted", $wplc_domain);
538        }
539       
540        // op == export on bottom of function
541
542        $itemsperpage = get_option("wplc_manage_items_per_page");
543        $page = $_GET['wplc_pg'];
544        if(isset($page)) {
545                $offset = $itemsperpage * ($page-1);
546        }
547        else {
548                $offset = 0;
549                $page = 1;
550        }
551       
552        $use_24hr_time = get_option("wplc_use_24hr_time");
553        if(!is_bool($use_24hr_time)) {
554                $use_24hr_time = $use_24hr_time == "true";
555        }
556       
557        // Check how many events there are
558        $sql = "SELECT ID FROM ".$wpdb->escape(get_option("wplc_tbl_name"));
559        $wpdb->query($sql);
560        $totalevents = $wpdb->num_rows;
561       
562
563        // Get events for this page
564        $sql = "SELECT id, event_name, event_loc, event_start_time, event_end_time, event_allday"
565                 ." FROM ".$wpdb->escape(get_option("wplc_tbl_name"))
566                 ." ORDER BY event_start_time DESC, event_end_time DESC"
567                 ." LIMIT ".$wpdb->escape($offset).", ".$wpdb->escape($itemsperpage);
568                $wpdb->show_errors();
569        $events = $wpdb->get_results($sql, ARRAY_A);
570       
571        if($use_24hr_time)
572                $dateformat = 'D, M j, Y @ G:i';
573        else
574                $dateformat = 'D, M j, Y @ g:ia';
575       
576        $allday_format = "D, M j";
577       
578        $delmsg = __("You are about to delete the event \'%s\'. \\n\'OK\' to delete, \'Cancel\' to stop.", $wplc_domain);
579       
580        if(!is_null($message)) {
581        ?>
582                <div id="message" class="updated fade">
583                        <p>
584                                <?php echo $message; ?>
585                        </p>
586                </div>
587        <?php
588        }
589        ?>
590       
591        <div class="wrap">
592                <h2><?php _e("Edit Events", $wplc_domain); ?></h2>
593                <div class="tablenav">
594                        <div class="tablenav-pages">
595                                <span class="displaying-num"><?php _e(sprintf("Displaying %d-%d of %d", $offset+1, $offset+count($events), $totalevents), $wplc_domain); ?></span>
596                                <?php
597                                if($offset + $itemsperpage < $totalevents) {
598                                        echo "<a href='admin.php?wplc_pg=".($page+1)."&amp;page=wplc-edit' class='prev page-numbers'>";
599                                        _e("&laquo; Previous Events", $wplc_domain);
600                                        echo "</a>";
601                                        $prevshown = true;
602                                }
603                                if($page > 1) {
604                                        if($prevshown)
605                                                echo " | ";
606                                        echo "<a href='admin.php?wplc_pg=".($page-1)."&amp;page=wplc-edit' class='next page-numbers'>";
607                                        _e("Next Events &raquo;", $wplc_domain);
608                                        echo "</a>";
609                                }
610                                ?>
611                        </div>
612                        <div class="alignleft">
613                                <a href="admin.php?page=<?php echo $wplc_plugin; ?>"><?php _e('Add New Event &raquo;', $wplc_domain); ?></a>
614                        </div>
615                </div>
616                <table class="widefat">
617                        <thead>
618                                <tr>
619                                        <th scope="col" style="text-align:center;"><span class="hidden"><?php _e("ID", $wplc_domain); ?></span></th>
620                                        <th scope="col"><?php _e("Event Name", $wplc_domain); ?></th>
621                                        <th scope="col"><?php _e("Location", $wplc_domain); ?></th>
622                                        <th scope="col"><?php _e("Start Date/Time", $wplc_domain); ?></th>
623                                        <th scope="col"><?php _e("End Date/Time", $wplc_domain); ?></th>
624                                </tr>
625                        </thead>
626                        <tbody>
627
628                        <?php
629                        for($i=0; $i<count($events); $i++) {
630                                $class = $i % 2 == 0 ? " class='alternate'" : "";
631                                $useformat = $events[$i]['event_allday'] == 1 ? $allday_format : $dateformat;
632                                $start = date($useformat, $events[$i]['event_start_time']);
633                                $end = date($useformat, $events[$i]['event_end_time']);
634                        ?>
635
636                                <tr id="event-<?php echo $events[$i]['id']; ?>" <?php echo $class; ?>>
637                                        <th scope="row" style="text-align:center;" class="check-column"><?php echo $events[$i]['id']; ?></th>
638                                        <td><a href="admin.php?id=<?php echo $events[$i]['id']; ?>&amp;page=wplc-edit&amp;op=edit" class="row-title"><?php echo stripslashes(stripslashes($events[$i]['event_name'])); ?></a>
639                                                <div class="row-actions"><a href="admin.php?id=<?php echo $events[$i]['id']; ?>&amp;page=wplc-edit&amp;op=edit" class="edit"><?php _e("Edit", $wplc_domain); ?></a> | <a href="javascript:;" onclick="wplcDeleteEvent(<?php echo $events[$i]['id']; ?>, '<?php echo sprintf($delmsg, $events[$i]['event_name']); ?>');" class="submitdelete"><?php _e("Delete", $wplc_domain); ?></a> | <a href="admin.php?page=wplc-edit&amp;op=export&amp;id=<?php echo $events[$i]['id']; ?>"><?php _e("Export", $wplc_domain); ?></a></div>
640                                        </td>
641                                        <td><?php echo stripslashes(stripslashes($events[$i]['event_loc'])); ?></td>
642                                        <td><?php echo $start; ?></td>
643                                        <td><?php echo $end; ?></td>
644                                </tr>
645
646                        <?php
647                        }
648                        ?>
649       
650                        </tbody>
651                        <tfoot>
652                                <tr>
653                                        <th scope="col" style="text-align:center;"><span class="hidden"><?php _e("ID", $wplc_domain); ?></span></th>
654                                        <th scope="col"><?php _e("Event Name", $wplc_domain); ?></th>
655                                        <th scope="col"><?php _e("Location", $wplc_domain); ?></th>
656                                        <th scope="col"><?php _e("Start Date/Time", $wplc_domain); ?></th>
657                                        <th scope="col"><?php _e("End Date/Time", $wplc_domain); ?></th>
658                                </tr>
659                        </tfoot>                       
660                </table>
661                <div class="tablenav">
662                        <div class="tablenav-pages">
663                                <span class="displaying-num"><?php _e(sprintf("Displaying %d-%d of %d", $offset+1, $offset+count($events), $totalevents), $wplc_domain); ?></span>
664                                <?php
665                                if($offset + $itemsperpage < $totalevents) {
666                                        echo "<a href='admin.php?wplc_pg=".($page+1)."&amp;page=wplc-edit' class='prev page-numbers'>";
667                                        _e("&laquo; Previous Events", $wplc_domain);
668                                        echo "</a>";
669                                        $prevshown = true;
670                                }
671                                if($page > 1) {
672                                        if($prevshown)
673                                                echo " | ";
674                                        echo "<a href='admin.php?wplc_pg=".($page-1)."&amp;page=wplc-edit' class='next page-numbers'>";
675                                        _e("Next Events &raquo;", $wplc_domain);
676                                        echo "</a>";
677                                }
678                                ?>
679                        </div>
680                        <div class="alignleft" style="margin-top:6px;">
681                                <a href="admin.php?page=<?php echo $wplc_plugin; ?>"><?php _e('Add New Event &raquo;', $wplc_domain); ?></a>
682                        </div>
683                </div>
684                <br class="clear" />
685        </div>
686        <?php
687       
688        if($_GET['op'] == "export") {
689                if(!empty($_GET['id'])) {
690                        wplc_export_events($_GET['id']);
691                }
692        }
693}
694
695function wplc_show_admin_edit_page($id, $export=false) {
696        wplc_setup();
697        global $wplc_domain, $wpdb;
698
699        $action = $_POST['action'];
700        if($action == "submitted") {
701                wplc_process_event($_POST);
702        }
703        else {
704                // Lookup event data for $id
705                $sql = "SELECT e.*, u.display_name as event_author FROM ".$wpdb->escape(get_option("wplc_tbl_name"))." e LEFT JOIN  ".$wpdb->users." u ON e.event_author = u.ID WHERE e.id=".$wpdb->escape($id);
706                $event = $wpdb->get_results($sql, ARRAY_A);
707
708                // Show edit form
709                wplc_show_event_form($event[0], null, $export);
710        }
711}
712
713function wplc_show_import_page() {
714        // Not ready for release
715        return;
716       
717        wplc_setup();
718        global $wplc_domain;
719       
720        $msgerr = false;       
721        if(isset($_POST['submit'])) {
722                if($_FILES['wplc_import_file']['type'] == "text/calendar") {
723                        $dir = get_option("wplc_upload_dir");
724
725                        if(empty($dir) || empty($url)) {
726                                wplc_init_upload_dir_settings();
727                                $dir = get_option("wplc_upload_dir");
728                        }
729                       
730                        $uploadfile = $dir.basename($_FILES['wplc_import_file']['name']);
731                        if(move_uploaded_file($_FILES['wplc_import_file']['tmp_name'], $uploadfile)) {
732                                if(wplc_import_events($uploadfile)) {
733                                        $msgerr = true;
734                                        $message = __("Events successfully imported", $wplc_domain);
735                                        $class = "updated";
736                                }
737                                else {
738                                        $msgerr = true;
739                                        $message = __("Error: iCalendar file was not parsable", $wplc_domain);
740                                        $class = "error";
741                                }
742                        }
743                        else {
744                                $msgerr = true;
745                                $message = __("Error: Upload failed", $wplc_domain);
746                                $class = "error";
747                        }
748                }
749                else {
750                        $msgerr = true;
751                        $message = __("Error: Invalid file type uploaded. Please upload an iCalendar file. Type: ".$_FILES['wplc_import_file']['type'], $wplc_domain);
752                        $class = "error";
753                }
754        }
755       
756        if($msgerr) {
757        ?>
758        <div id="message" class="<?php echo $class; ?>">
759                <p>
760                        <?php echo $message; ?>
761                </p>
762        </div>
763        <?php   
764        }
765       
766        ?>
767        <div class="wrap">
768                <h2><?php _e("Import Events", $wplc_domain); ?></h2>
769                <p>
770                        <?php _e("WPListCal can import events from iCalendar files saved from programs like Apple iCal, Microsoft Outlook, and Mozilla Sunbird. Choose an iCalendar (.ics) file using the selector below and press &quot;Import&quot; to add all the events in the file to your WPListCal calendar.", $wplc_domain); ?>
771                </p>
772                <p>
773                        <?php _e("Events will maintain the creation timestamp from the file, but the author will be listed as the account you are currently logged in as. The modified time will be changed to the current time.", $wplc_domain); ?>
774                </p>
775                <form method="post" action="admin.php?page=wplc-import" enctype="multipart/form-data">
776                        <p>
777                                <label for="wplc_import_file"><?php _e("iCalendar File:", $wplc_domain); ?></label>
778                                <input type="file" name="wplc_import_file" id="wplc_import_file" />
779                        </p>
780                        <p>
781                                <input type="submit" class="button-primary" name="submit" value="<?php _e('Import', $wplc_domain); ?>" />
782                        </p>
783                </form>
784        <?php
785}
786
787function wplc_show_export_page() {
788        wplc_setup();
789        global $wplc_domain;
790       
791        ?>
792        <div class="wrap">
793                <h2><?php _e("Export Events", $wplc_domain); ?></h2>
794                <p>
795                        <?php printf(__("WPListCal can save your events in the standard iCalendar format. Events are stored in the timezone that your blog is set to use. All events are exported at once, past and future. If you'd like to export a single event, go to the %smanage events%s page and click &quot;Export&quot; near the event you want to export.", $wplc_domain), "<a href='admin.php?page=wplc-edit'>", "</a>"); ?>
796                </p>
797                <h3><a href="admin.php?page=wplc-export&amp;op=export"><?php _e("Export events &raquo;", $wplc_domain); ?></a></h3>
798        </div>
799        <?php
800       
801        if($_GET['op'] == "export") {
802                wplc_export_events();
803        }
804}
805
806function wplc_show_admin_cleanup_page() {
807        wplc_setup();
808        global $wplc_domain;
809       
810        if($_GET['op'] == "cleanup") {
811                $num = wplc_cleanup_events();
812                if($num > 0) {
813                        $message = sprintf(__("%d old ".($num == 1 ? "event" : "events")." deleted.", $wplc_domain), $num);
814                        $class = "updated";
815                }
816                elseif($num == 0) {
817                        $message = __("No old events to delete.", $wplc_domain);
818                        $class = "updated";
819                }
820                else {
821                        $message = __("Error: Event cleanup failed.", $wplc_domain);
822                        $class = "error";
823                }
824                ?>
825                <div id="message" class="<?php echo $class; ?>">
826                        <p>
827                                <?php echo $message; ?>
828                        </p>
829                </div>
830                <?php
831        }
832        ?>
833        <div class="wrap">
834                <h2><?php _e("Cleanup Events", $wplc_domain); ?></h2>
835                <p>
836                        <?php _e("Have a bunch of old events sitting around? Click below to delete all events that have ended already. Note that this operation CANNOT be undone.", $wplc_domain); ?>
837                </p>
838                <h3><a href="admin.php?page=wplc-cleanup&amp;op=cleanup" onclick="return confirm('<?php _e("Are you sure you want to delete all past events?", $wplc_domain); ?>');"><?php _e("Cleanup events &raquo;", $wplc_domain); ?></a></h3>
839        </div>
840        <?php
841}
842
843function wplc_cleanup_events() {
844        global $wpdb;
845       
846        $sql = "DELETE FROM ".$wpdb->escape(get_option("wplc_tbl_name"))." WHERE event_end_time < ".wplc_time();
847        $result = $wpdb->query($sql);
848       
849        if($result === false)
850                return -1;
851        return $result;
852}
853
854function wplc_show_admin_options_page() {
855        wplc_setup();
856        global $wplc_domain;
857       
858        $use_24hr_time = get_option("wplc_use_24hr_time");
859        if(!is_bool($use_24hr_time)) {
860                $use_24hr_time = $use_24hr_time == "true";
861        }
862       
863        $open_links_in_new_window = get_option("wplc_open_links_in_new_window");
864        if(!is_bool($open_links_in_new_window)) {
865                $open_links_in_new_window = $open_links_in_new_window == "true";
866        }
867       
868        $hide_same_date = get_option("wplc_hide_same_date");
869        if(!is_bool($hide_same_date)) {
870                $hide_same_date = $hide_same_date == "true";
871        }
872       
873        $nofollow_links = get_option("wplc_nofollow_links");
874        if(!is_bool($nofollow_links)) {
875                $nofollow_links = $nofollow_links == "true";
876        }
877        ?>
878       
879        <div class="wrap">
880                <form method="post" action="options.php">
881                        <?php wp_nonce_field('update-options'); ?>
882                        <h2><?php _e("WPListCal Options", $wplc_domain); ?></h2>
883                        <table class="form-table">
884                                <tr valign="top" id="displaymode">
885                                        <th scope="row"><?php _e("Display Mode:", $wplc_domain); ?></th>
886                                        <td>
887                                                <input type="radio" name="wplc_display_mode" value="list" id="wplc_display_mode_list" onclick="wplc_changeDisabled('wplc_event_format', false);"<?php echo get_option('wplc_display_mode') == 'list' ? "checked='checked'" : ""; ?> />
888                                                        <label for="wplc_display_mode_list"><?php _e("Show events in an unordered list <em>(Default)</em>", $wplc_domain); ?></label>
889                                                <br />
890                                                <fieldset style="margin-left: 25px;border:none;">
891                                                        <legend style="float:left; margin-top:2px;"><?php _e("Event Format", $wplc_domain); ?> <a href="javascript:;" title="<?php _e("The following variables are available:", $wplc_domain); ?> %NAME%, %LINK%, %LINKEDNAME%, %LOCATION%, %DESCRIPTION%, %START%, %END%, and %AUTHOR%.
892                                                               
893Put words into curly brackets to make them dependent on the first variable in the bracketed statement. Use '^' to escape brackets or to stop a variable from being the dependent variable for a statement." style="cursor:help;">?</a>:</legend>
894                                                        <div>
895                                                                <textarea name="wplc_event_format" id="wplc_event_format" style="width:350px; height:50px;" class="large-text code"<?php echo get_option('wplc_display_mode') == 'list' ? "" : "disabled='disabled'"; ?>><?php echo htmlentities(get_option('wplc_event_format')); ?></textarea>
896                                                        </div>
897                                                </fieldset>
898                                                <input type="radio" name="wplc_display_mode" value="table" id="wplc_display_mode_table" onclick="wplc_changeDisabled('wplc_event_format', true);"<?php echo get_option('wplc_display_mode') == 'table' ? "checked='checked'" : ""; ?> />
899                                                        <label for="wplc_display_mode_table"><?php _e("Show events in a table", $wplc_domain); ?></label>
900                                        </td>
901                                </tr>
902                                <tr valign="top" id="dateformat">
903                                        <th scope="row"><?php _e("Date/Time Format:", $wplc_domain); ?></th>
904                                        <td>
905                                                <input type="text" name="wplc_date_format" value="<?php echo get_option('wplc_date_format'); ?>" class="regular-text" />
906                                                <span class="setting-description"><a href="http://codex.wordpress.org/Formatting_Date_and_Time"><?php _e("Documentation on date formatting", $wplc_domain); ?></a>. <?php _e("Click &quot;Save Changes&quot; to update sample output.", $wplc_domain); ?></span>
907                                                <br />
908                                                <strong><?php _e("Output:", $wplc_domain); ?></strong> <?php echo date(get_option('wplc_date_format'), wplc_time()); ?>
909                                        </td>
910                                </tr>
911                                <tr valign="top" id="24hr_time">
912                                        <th scope="row"><?php _e("12/24 Hour Time:", $wplc_domain); ?></th>
913                                        <td>
914                                                <input type="radio" name="wplc_use_24hr_time" id="wplc_use_24hr_time0" value="false"<?php echo $use_24hr_time ? '' : ' checked=\'checked\''; ?> />
915                                                <label for="wplc_use_24hr_time0"><?php _e("Use 12 hour time (e.g. 1:35pm)", $wplc_domain); ?></label>
916                                                <br />
917                                                <input type="radio" name="wplc_use_24hr_time" id="wplc_use_24hr_time1" value="true"<?php echo $use_24hr_time ? ' checked=\'checked\'' : ''; ?> />
918                                                <label for="wplc_use_24hr_time1"><?php _e("Use 24 hour time (e.g. 13:35)", $wplc_domain); ?></label>
919                                                <br />
920                                                <span class="setting-description"><?php _e("What time-style to use in the admin area (does not affect what is displayed on your site)", $wplc_domain); ?></span>
921                                        </td>
922                                </tr>
923                                <tr valign="top" id="hide_same_date">
924                                        <th scope="row"><?php _e("End Date Options:", $wplc_domain); ?></th>
925                                        <td>
926                                                <input type="radio" name="wplc_hide_same_date" value="true" id="wplc_hide_same_date_true" onclick="wplc_changeDisabled('wplc_date2_time_format', false);"<?php echo $hide_same_date ? "checked='checked'" : ""; ?> />
927                                                        <label for="wplc_hide_same_date_true"><?php _e("If event starts and ends on the same day, use the time format below for the end date <em>(Default)</em>", $wplc_domain); ?></label>
928                                                <br />
929                                                <fieldset style="margin-left: 25px;border:none;">
930                                                        <legend style="float:left; margin-top:2px;"><?php _e("End Date Format", $wplc_domain); ?>:</legend>
931                                                        <div>
932                                                                <input type="text" name="wplc_date2_time_format" id="wplc_date2_time_format" value="<?php echo get_option('wplc_date2_time_format'); ?>"<?php echo $hide_same_date ? "" : "disabled='disabled'"; ?> class="small-text" />
933                                                                <strong><?php _e("Output:", $wplc_domain); ?></strong> <?php echo date(get_option('wplc_date2_time_format'), wplc_time()); ?>
934                                                        </div>
935                                                </fieldset>
936                                                <input type="radio" name="wplc_hide_same_date" value="false" id="wplc_hide_same_date_false" onclick="wplc_changeDisabled('wplc_date2_time_format', true);"<?php echo $hide_same_date ? "" : "checked='checked'"; ?> />
937                                                        <label for="wplc_hide_same_date_false"><?php _e("Use the same format for both start and end dates", $wplc_domain); ?></label>
938                                        </td>
939                                </tr>
940                                <tr valign="top" id="maxevents">
941                                        <th scope="row"><?php _e("Maximum Displayed Events:", $wplc_domain); ?></th>
942                                        <td>
943                                                <input type="text" name="wplc_max_events" size="4" value="<?php echo get_option('wplc_max_events'); ?>" class="small-text" />
944                                                <span class="setting-description"><?php _e("How many events to display in the event list, -1 for no limit", $wplc_domain); ?></span>
945                                        </td>
946                                </tr>
947                                <tr valign="top" id="advancenotice">
948                                        <th scope="row"><?php _e("Maximum Advanced Notice:", $wplc_domain); ?></th>
949                                        <td>
950                                                <input type="text" name="wplc_advance_days" size="4" value="<?php echo get_option('wplc_advance_days'); ?>" class="small-text" />
951                                                <span class="setting-description"><?php _e("How many days in advance to display events, -1 for no limit", $wplc_domain); ?></span>
952                                        </td>
953                                </tr>
954                                <tr valign="top" id="showpastevents">
955                                        <th scope="row"><?php _e("Past Events:", $wplc_domain); ?></th>
956                                        <td>
957                                                <input type="radio" name="wplc_show_past_events" value="false" id="wplc_show_past_events_false"<?php echo get_option('wplc_show_past_events') != 'true' ? "checked='checked'" : ""; ?> />
958                                                        <label for="wplc_show_past_events_false"><?php _e("Only show current and future events", $wplc_domain); ?></label>
959                                                <br />
960                                                <input type="radio" name="wplc_show_past_events" value="true" id="wplc_show_past_events_true"<?php echo get_option('wplc_show_past_events') == 'true' ? "checked='checked'" : ""; ?> />
961                                                        <label for="wplc_show_past_events_true"><?php _e("Show all events, even if they have already occurred", $wplc_domain); ?></label>
962                                        </td>
963                                </tr>
964                                <tr valign="top" id="eventorder">
965                                        <th scope="row"><?php _e("Event Order:", $wplc_domain); ?></th>
966                                        <td>
967                                                <input type="radio" name="wplc_event_order" value="asc" id="wplc_event_order_asc"<?php echo get_option('wplc_event_order') == 'asc' ? "checked='checked'" : ""; ?> />
968                                                        <label for="wplc_event_order_asc"><?php _e("Show the closest event first", $wplc_domain); ?></label>
969                                                <br />
970                                                <input type="radio" name="wplc_event_order" value="desc" id="wplc_event_order_desc"<?php echo get_option('wplc_event_order') == 'desc' ? "checked='checked'" : ""; ?> />
971                                                        <label for="wplc_event_order_desc"><?php _e("Show the furthest event first", $wplc_domain); ?></label>
972                                        </td>
973                                </tr>
974                                <tr valign="top" id="no_events_msg">
975                                        <th scope="row"><?php _e("No Events Message:", $wplc_domain); ?></th>
976                                        <td>
977                                                <input type="text" name="wplc_no_events_msg" size="30" value="<?php echo get_option('wplc_no_events_msg'); ?>" class="regular-text" />
978                                                <span class="setting-description"><?php _e("Message to show if there are no events, leave blank for none", $wplc_domain); ?></span>
979                                        </td>
980                                </tr>
981                                <tr valign="top" id="adminperpage">
982                                        <th scope="row"><?php _e("Admin Items Per Page:", $wplc_domain); ?></th>
983                                        <td>
984                                                <input type="text" name="wplc_manage_items_per_page" size="4" value="<?php echo get_option('wplc_manage_items_per_page'); ?>" class="small-text" />
985                                                <span class="setting-description"><?php _e("How many events to display per page on the Manage Events admin page", $wplc_domain); ?></span>
986                                        </td>
987                                </tr>
988                                <tr valign="top" id="open_links_in_new_window">
989                                        <th scope="row"><?php _e("Event Link Target:", $wplc_domain); ?></th>
990                                        <td>
991                                                <input type="radio" name="wplc_open_links_in_new_window" id="wplc_open_links_in_new_window0" value="false"<?php echo $open_links_in_new_window ? '' : ' checked=\'checked\''; ?> />
992                                                <label for="wplc_open_links_in_new_window0"><?php _e("Open links in the current window", $wplc_domain); ?></label>
993                                                <br />
994                                                <input type="radio" name="wplc_open_links_in_new_window" id="wplc_open_links_in_new_window1" value="true"<?php echo $open_links_in_new_window ? ' checked=\'checked\'' : ''; ?> />
995                                                <label for="wplc_open_links_in_new_window1"><?php _e("Open links in a new window", $wplc_domain); ?></label>
996                                        </td>
997                                </tr>
998                                <tr valign="top" id="nofollow_links">
999                                        <th scope="row"><?php _e("Link No Follow:", $wplc_domain); ?></th>
1000                                        <td>
1001                                                <input type="checkbox" name="wplc_nofollow_links" id="wplc_nofollow_links" value="true"<?php echo $nofollow_links ? ' checked=\'checked\'' : ''; ?> />
1002                                                <label for="wplc_nofollow_links"><?php _e("Set rel=&quot;nofollow&quot; on links", $wplc_domain); ?></label>
1003                                        </td>
1004                                </tr>
1005                        </table>
1006                        <input type="hidden" name="action" value="update" />
1007                        <input type="hidden" name="page_options" value="wplc_display_mode,wplc_event_format,wplc_date_format,wplc_use_24hr_time,wplc_hide_same_date,wplc_date2_time_format,wplc_max_events,wplc_advance_days,wplc_show_past_events,wplc_no_events_msg,wplc_manage_items_per_page,wplc_open_links_in_new_window,wplc_nofollow_links" />
1008                        <p class="submit"><input type="submit" name="Submit" value="<?php _e("Save Changes", $wplc_domain); ?>" class="button-primary" /></p>
1009                </form>
1010        </div>
1011       
1012        <?php
1013}
1014
1015function wplc_widget_init() {
1016        if (!function_exists('register_sidebar_widget') || !function_exists('register_widget_control'))
1017                return;
1018               
1019        function wplc_widget($args) {
1020                extract($args);
1021               
1022                $widget_title = get_option("wplc_widget_title");
1023               
1024                echo $before_widget;
1025                echo $before_title . $widget_title . $after_title;
1026                echo wplc_show_events();
1027                echo $after_widget;
1028        }
1029       
1030        function wplc_widget_control() {
1031                global $wplc_domain;
1032                wplc_setup();
1033               
1034                $wplc_widget_title = get_option("wplc_widget_title");
1035               
1036                if($_POST['wplc_submit'] == "1") {
1037                        $wplc_widget_new_title = strip_tags(stripslashes($_POST['wplc_widget_title']));
1038                        if($wplc_widget_title != $wplc_widget_new_title) {
1039                                $wplc_widget_title = $wplc_widget_new_title;
1040                                update_option("wplc_widget_title", $wplc_widget_title);
1041                        }
1042                }
1043               
1044                $wplc_widget_title = htmlspecialchars($wplc_widget_title, ENT_QUOTES);
1045               
1046                ?>
1047                <div>
1048                        <label for="wplc_widget_title"><?php _e("Widget Title:", $wplc_domain); ?></label><input type="text" id="wplc_widget_title" name="wplc_widget_title" value="<?php echo $wplc_widget_title; ?>" />
1049                        <input type="hidden" name="wplc_submit" id="wplc_submit" value="1" />
1050                </div>
1051                <?php
1052        }
1053       
1054        register_sidebar_widget("WPListCal", "wplc_widget");
1055        register_widget_control("WPListCal", "wplc_widget_control");
1056}
1057
1058add_action("plugins_loaded", "wplc_widget_init");
1059?>
Note: See TracBrowser for help on using the browser.