Event List - Version 0.6.2

Version Description

(2014-02-01) = * complete rewrite of date handling in new/edit event form and date validation * added option to change date format in event new/edit form * fixed a css issue in the filterbar hlist when list-style-image is used in the theme * some css fixes in admin settings page * some html output code style fixes

Download this release

Release Info

Developer mibuthu
Plugin Icon 128x128 Event List
Version 0.6.2
Comparing to
See all releases

Code changes from version 0.6.1 to 0.6.2

admin/admin.php CHANGED
@@ -58,7 +58,7 @@ class EL_Admin {
58
 
59
  // Settings subpage
60
  $page = add_submenu_page('el_admin_main', 'Event List Settings', 'Settings', 'manage_options', 'el_admin_settings', array(&$this, 'show_settings_page'));
61
- //add_action('admin_print_scripts-'.$page, array(&$this, 'embed_settings_scripts'));
62
 
63
  // About subpage
64
  $page = add_submenu_page('el_admin_main', 'About Event List', 'About', 'edit_posts', 'el_admin_about', array(&$this, 'show_about_page'));
@@ -116,12 +116,12 @@ class EL_Admin {
116
  require_once(EL_PATH.'admin/includes/admin-settings.php');
117
  EL_Admin_Settings::get_instance()->show_settings();
118
  }
119
- /*
120
  public function embed_settings_scripts() {
121
  require_once(EL_PATH.'admin/includes/admin-settings.php');
122
  EL_Admin_Settings::get_instance()->embed_settings_scripts();
123
  }
124
- */
125
  public function show_about_page() {
126
  require_once(EL_PATH.'admin/includes/admin-about.php');
127
  EL_Admin_About::get_instance()->show_about();
58
 
59
  // Settings subpage
60
  $page = add_submenu_page('el_admin_main', 'Event List Settings', 'Settings', 'manage_options', 'el_admin_settings', array(&$this, 'show_settings_page'));
61
+ add_action('admin_print_scripts-'.$page, array(&$this, 'embed_settings_scripts'));
62
 
63
  // About subpage
64
  $page = add_submenu_page('el_admin_main', 'About Event List', 'About', 'edit_posts', 'el_admin_about', array(&$this, 'show_about_page'));
116
  require_once(EL_PATH.'admin/includes/admin-settings.php');
117
  EL_Admin_Settings::get_instance()->show_settings();
118
  }
119
+
120
  public function embed_settings_scripts() {
121
  require_once(EL_PATH.'admin/includes/admin-settings.php');
122
  EL_Admin_Settings::get_instance()->embed_settings_scripts();
123
  }
124
+
125
  public function show_about_page() {
126
  require_once(EL_PATH.'admin/includes/admin-about.php');
127
  EL_Admin_About::get_instance()->show_about();
admin/css/admin_new.css CHANGED
@@ -5,7 +5,7 @@
5
  }
6
 
7
  #start_date, #end_date, #time {
8
- width: 110px;
9
  }
10
 
11
  img.ui-datepicker-trigger {
@@ -19,4 +19,4 @@ p.note {
19
 
20
  div#postbox-container-1 {
21
  width: 260px !important;
22
- }
5
  }
6
 
7
  #start_date, #end_date, #time {
8
+ width: 125px;
9
  }
10
 
11
  img.ui-datepicker-trigger {
19
 
20
  div#postbox-container-1 {
21
  width: 260px !important;
22
+ }
admin/css/admin_settings.css ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ .el-settings {
2
+ padding: 0 10px;
3
+ }
4
+
5
+ .form-table th, .form-table td {
6
+ vertical-align: top;
7
+ padding: 15px 10px 15px 0;
8
+ };
admin/includes/admin-main.php CHANGED
@@ -35,13 +35,13 @@ class EL_Admin_Main {
35
  // real actions (redirect when finished)
36
  case 'new':
37
  if(!empty($_POST)) {
38
- $id = $this->db->update_event($_POST, __('Y/m/d'));
39
  $error = !$id;
40
  $this->redirect('added', $error, array('title' => urlencode($_POST['title']), 'id' => $id));
41
  }
42
  case 'edited':
43
  if(!empty($_POST)) {
44
- $error = !$this->db->update_event($_POST, __('Y/m/d'));
45
  $this->redirect('modified', $error, array('title' => urlencode($_POST['title']), 'id' => $_POST['id']));
46
  }
47
  break;
@@ -188,6 +188,18 @@ class EL_Admin_Main {
188
  <div id="message" class="error below-h2"><p><strong>'.$text.'</strong></p></div>';
189
  }
190
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  private function redirect($action=false, $error=false, $query_args=array()) {
192
  $url = remove_query_arg(array('noheader', 'action', 'action2', 'filter', '_wpnonce', '_wp_http_referer'), $_SERVER['REQUEST_URI']);
193
  if($action) {
35
  // real actions (redirect when finished)
36
  case 'new':
37
  if(!empty($_POST)) {
38
+ $id = $this->update_event($_POST);
39
  $error = !$id;
40
  $this->redirect('added', $error, array('title' => urlencode($_POST['title']), 'id' => $id));
41
  }
42
  case 'edited':
43
  if(!empty($_POST)) {
44
+ $error = !$this->update_event($_POST);
45
  $this->redirect('modified', $error, array('title' => urlencode($_POST['title']), 'id' => $_POST['id']));
46
  }
47
  break;
188
  <div id="message" class="error below-h2"><p><strong>'.$text.'</strong></p></div>';
189
  }
190
 
191
+ private function update_event() {
192
+ $eventdata = $_POST;
193
+ // provide correct sql start- and end-date
194
+ if(isset($eventdata['sql_start_date']) && '' != $eventdata['sql_start_date']) {
195
+ $eventdata['start_date'] = $eventdata['sql_start_date'];
196
+ }
197
+ if(isset($eventdata['sql_end_date']) && '' != $eventdata['sql_end_date']) {
198
+ $eventdata['end_date'] = $eventdata['sql_end_date'];
199
+ }
200
+ return $this->db->update_event($eventdata);
201
+ }
202
+
203
  private function redirect($action=false, $error=false, $query_args=array()) {
204
  $url = remove_query_arg(array('noheader', 'action', 'action2', 'filter', '_wpnonce', '_wp_http_referer'), $_SERVER['REQUEST_URI']);
205
  if($action) {
admin/includes/admin-new.php CHANGED
@@ -4,12 +4,14 @@ if(!defined('ABSPATH')) {
4
  }
5
 
6
  require_once(EL_PATH.'includes/db.php');
 
7
  require_once(EL_PATH.'includes/categories.php');
8
 
9
  // This class handles all data for the admin new event page
10
  class EL_Admin_New {
11
  private static $instance;
12
  private $db;
 
13
  private $categories;
14
 
15
  public static function &get_instance() {
@@ -23,6 +25,7 @@ class EL_Admin_New {
23
 
24
  private function __construct() {
25
  $this->db = &EL_Db::get_instance();
 
26
  $this->categories = &EL_Categories::get_instance();
27
  }
28
 
@@ -45,6 +48,7 @@ class EL_Admin_New {
45
  }
46
 
47
  public function edit_event() {
 
48
  $edit = false;
49
  if(isset($_GET['id']) && is_numeric($_GET['id'])) {
50
  // existing event
@@ -64,7 +68,7 @@ class EL_Admin_New {
64
 
65
  // Add required data for javascript in a hidden field
66
  $json = json_encode(array('el_url' => EL_URL,
67
- 'el_date_format' => $this->datepicker_format(__('Y/m/d'))));
68
  $out = '
69
  <form method="POST" action="'.add_query_arg('noheader', 'true', '?page=el_admin_main').'">';
70
  $out .= "
@@ -78,34 +82,40 @@ class EL_Admin_New {
78
  <div id="post-body" class="metabox-holder columns-2">
79
  <div id="post-body-content">';
80
  if(true === $edit) {
81
- $out .= '<input type="hidden" name="action" value="edited" />';
82
- $out .= '<input type="hidden" name="id" value="'.$_GET['id'].'" />';
 
83
  }
84
  else {
85
- $out .= '<input type="hidden" name="action" value="new" />';
 
86
  }
87
- $out .= '<table class="form-table">
88
- <tr>
89
- <th><label>Event Title (required)</label></th>
90
- <td><input type="text" class="text form-required" name="title" id="title" value="'.str_replace('"', '&quot;', isset($event->title) ? $event->title : '').'" /></td>
91
- </tr>
92
- <tr>
93
- <th><label>Event Date (required)</label></th>
94
- <td><input type="text" class="text datepicker form-required" name="start_date" id="start_date" value="'.date_i18n(__('Y/m/d'), $start_date).'" />
95
- <span id="end_date_area"> - <input type="text" class="text datepicker" name="end_date" id="end_date" value="'.date_i18n(__('Y/m/d'), $end_date).'" /></span>
96
- <label><input type="checkbox" name="multiday" id="multiday" value="1" /> Multi-Day Event</label></td>
97
- </tr>
98
- <tr>
99
- <th><label>Event Time</label></th>
100
- <td><input type="text" class="text" name="time" id="time" value="'.str_replace('"', '&quot;', isset($event->time) ? $event->time : '').'" /></td>
101
- </tr>
102
- <tr>
103
- <th><label>Event Location</label></th>
104
- <td><input type="text" class="text" name="location" id="location" value="'.str_replace('"', '&quot;', isset($event->location) ? $event->location : '').'" /></td>
105
- </tr>
106
- <tr>
107
- <th><label>Event Details</label></th>
108
- <td>';
 
 
 
 
109
  $editor_settings = array('media_buttons' => true,
110
  'wpautop' => false,
111
  'textarea_rows' => 20);
@@ -113,9 +123,10 @@ class EL_Admin_New {
113
  wp_editor(isset($event->details) ? $event->details : '', 'details', $editor_settings);
114
  $out .= ob_get_contents();
115
  ob_end_clean();
116
- $out .= '<p class="note">NOTE: In the text editor, use RETURN to start a new paragraph - use SHIFT-RETURN to start a new line.</p></td>
117
- </tr>
118
- </table>';
 
119
  $out .= '
120
  </div>
121
  <div id="postbox-container-1" class="postbox-container">
@@ -205,6 +216,15 @@ class EL_Admin_New {
205
  echo $out;
206
  }
207
 
 
 
 
 
 
 
 
 
 
208
  /**
209
  * Convert a date format to a jQuery UI DatePicker format
210
  *
4
  }
5
 
6
  require_once(EL_PATH.'includes/db.php');
7
+ require_once(EL_PATH.'includes/options.php');
8
  require_once(EL_PATH.'includes/categories.php');
9
 
10
  // This class handles all data for the admin new event page
11
  class EL_Admin_New {
12
  private static $instance;
13
  private $db;
14
+ private $options;
15
  private $categories;
16
 
17
  public static function &get_instance() {
25
 
26
  private function __construct() {
27
  $this->db = &EL_Db::get_instance();
28
+ $this->options = &EL_Options::get_instance();
29
  $this->categories = &EL_Categories::get_instance();
30
  }
31
 
48
  }
49
 
50
  public function edit_event() {
51
+ $dateformat = $this->get_event_dateformat();
52
  $edit = false;
53
  if(isset($_GET['id']) && is_numeric($_GET['id'])) {
54
  // existing event
68
 
69
  // Add required data for javascript in a hidden field
70
  $json = json_encode(array('el_url' => EL_URL,
71
+ 'el_date_format' => $this->datepicker_format($dateformat)));
72
  $out = '
73
  <form method="POST" action="'.add_query_arg('noheader', 'true', '?page=el_admin_main').'">';
74
  $out .= "
82
  <div id="post-body" class="metabox-holder columns-2">
83
  <div id="post-body-content">';
84
  if(true === $edit) {
85
+ $out .= '
86
+ <input type="hidden" name="action" value="edited" />
87
+ <input type="hidden" name="id" value="'.$_GET['id'].'" />';
88
  }
89
  else {
90
+ $out .= '
91
+ <input type="hidden" name="action" value="new" />';
92
  }
93
+ $out .= '
94
+ <table class="form-table">
95
+ <tr>
96
+ <th><label>Event Title (required)</label></th>
97
+ <td><input type="text" class="text form-required" name="title" id="title" value="'.str_replace('"', '&quot;', isset($event->title) ? $event->title : '').'" /></td>
98
+ </tr>
99
+ <tr>
100
+ <th><label>Event Date (required)</label></th>
101
+ <td><input type="text" class="text datepicker form-required" name="start_date" id="start_date" value="'.date('Y-m-d', $start_date).'" />
102
+ <span id="end_date_area"> - <input type="text" class="text datepicker" name="end_date" id="end_date" value="'.date('Y-m-d', $end_date).'" /></span>
103
+ <label><input type="checkbox" name="multiday" id="multiday" value="1" /> Multi-Day Event</label>
104
+ <input type="hidden" id="sql_start_date" name="sql_start_date" value="" />
105
+ <input type="hidden" id="sql_end_date" name="sql_end_date" value="" />
106
+ </td>
107
+ </tr>
108
+ <tr>
109
+ <th><label>Event Time</label></th>
110
+ <td><input type="text" class="text" name="time" id="time" value="'.str_replace('"', '&quot;', isset($event->time) ? $event->time : '').'" /></td>
111
+ </tr>
112
+ <tr>
113
+ <th><label>Event Location</label></th>
114
+ <td><input type="text" class="text" name="location" id="location" value="'.str_replace('"', '&quot;', isset($event->location) ? $event->location : '').'" /></td>
115
+ </tr>
116
+ <tr>
117
+ <th><label>Event Details</label></th>
118
+ <td>';
119
  $editor_settings = array('media_buttons' => true,
120
  'wpautop' => false,
121
  'textarea_rows' => 20);
123
  wp_editor(isset($event->details) ? $event->details : '', 'details', $editor_settings);
124
  $out .= ob_get_contents();
125
  ob_end_clean();
126
+ $out .= '
127
+ <p class="note">NOTE: In the text editor, use RETURN to start a new paragraph - use SHIFT-RETURN to start a new line.</p></td>
128
+ </tr>
129
+ </table>';
130
  $out .= '
131
  </div>
132
  <div id="postbox-container-1" class="postbox-container">
216
  echo $out;
217
  }
218
 
219
+ private function get_event_dateformat() {
220
+ if('' == $this->options->get('el_edit_dateformat')) {
221
+ return __('Y/m/d');
222
+ }
223
+ else {
224
+ return $this->options->get('el_edit_dateformat');
225
+ }
226
+ }
227
+
228
  /**
229
  * Convert a date format to a jQuery UI DatePicker format
230
  *
admin/includes/admin-settings.php CHANGED
@@ -38,7 +38,8 @@ class EL_Admin_Settings {
38
  }
39
 
40
  // normal output
41
- $out.= '<div class="wrap">
 
42
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Event List Settings</h2>';
43
  if(!isset($_GET['tab'])) {
44
  $_GET['tab'] = 'general';
@@ -58,6 +59,7 @@ class EL_Admin_Settings {
58
  */
59
  private function show_tabs($current = 'category') {
60
  $tabs = array('general' => 'General',
 
61
  'feed' => 'Feed Settings');
62
  $out = '<h3 class="nav-tab-wrapper">';
63
  foreach($tabs as $tab => $name){
@@ -77,12 +79,12 @@ class EL_Admin_Settings {
77
  $out .= ob_get_contents();
78
  ob_end_clean();
79
  $out .= '
80
- <div style="padding:0 10px">
81
  <table class="form-table">';
82
  foreach($this->options->options as $oname => $o) {
83
  if($o['section'] == $section) {
84
  $out .= '
85
- <tr style="vertical-align:top;">
86
  <th>';
87
  if($o['label'] != '') {
88
  $out .= '<label for="'.$oname.'">'.$o['label'].':</label>';
@@ -120,5 +122,9 @@ class EL_Admin_Settings {
120
  </form>';
121
  return $out;
122
  }
 
 
 
 
123
  }
124
  ?>
38
  }
39
 
40
  // normal output
41
+ $out.= '
42
+ <div class="wrap">
43
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Event List Settings</h2>';
44
  if(!isset($_GET['tab'])) {
45
  $_GET['tab'] = 'general';
59
  */
60
  private function show_tabs($current = 'category') {
61
  $tabs = array('general' => 'General',
62
+ 'admin' => 'Admin Page Settings',
63
  'feed' => 'Feed Settings');
64
  $out = '<h3 class="nav-tab-wrapper">';
65
  foreach($tabs as $tab => $name){
79
  $out .= ob_get_contents();
80
  ob_end_clean();
81
  $out .= '
82
+ <div class="el-settings">
83
  <table class="form-table">';
84
  foreach($this->options->options as $oname => $o) {
85
  if($o['section'] == $section) {
86
  $out .= '
87
+ <tr>
88
  <th>';
89
  if($o['label'] != '') {
90
  $out .= '<label for="'.$oname.'">'.$o['label'].':</label>';
122
  </form>';
123
  return $out;
124
  }
125
+
126
+ public function embed_settings_scripts() {
127
+ wp_enqueue_style('eventlist_admin_settings', EL_URL.'admin/css/admin_settings.css');
128
+ }
129
  }
130
  ?>
admin/js/admin_new.js CHANGED
@@ -25,7 +25,10 @@ jQuery(document).ready(function($) {
25
  buttonImage: conf.el_url + "admin/images/calendar-icon.png",
26
  buttonImageOnly: true,
27
  constrainInput: true,
 
 
28
  onClose: function(selectedDate) {
 
29
  minDate = $.datepicker.parseDate( conf.el_date_format, selectedDate );
30
  minDate.setDate(minDate.getDate()+1);
31
  $("#end_date").datepicker("option", "minDate", minDate);
@@ -40,7 +43,9 @@ jQuery(document).ready(function($) {
40
  showOn: "both",
41
  buttonImage: conf.el_url + "admin/images/calendar-icon.png",
42
  buttonImageOnly: true,
43
- constrainInput: true
 
 
44
  });
45
 
46
  // Toogle end_date visibility and insert the correct date
@@ -54,8 +59,11 @@ jQuery(document).ready(function($) {
54
  }
55
  else {
56
  $("#end_date_area").fadeOut();
57
- $("#end_date").datepicker("option", "minDate", null);
58
  }
59
  $("#end_date").datepicker("setDate", enddate);
60
  });
 
 
 
 
61
  });
25
  buttonImage: conf.el_url + "admin/images/calendar-icon.png",
26
  buttonImageOnly: true,
27
  constrainInput: true,
28
+ altField: "#sql_start_date",
29
+ altFormat: "yy-mm-dd",
30
  onClose: function(selectedDate) {
31
+ // set minDate for end_date picker
32
  minDate = $.datepicker.parseDate( conf.el_date_format, selectedDate );
33
  minDate.setDate(minDate.getDate()+1);
34
  $("#end_date").datepicker("option", "minDate", minDate);
43
  showOn: "both",
44
  buttonImage: conf.el_url + "admin/images/calendar-icon.png",
45
  buttonImageOnly: true,
46
+ constrainInput: true,
47
+ altField: "#sql_end_date",
48
+ altFormat: "yy-mm-dd"
49
  });
50
 
51
  // Toogle end_date visibility and insert the correct date
59
  }
60
  else {
61
  $("#end_date_area").fadeOut();
 
62
  }
63
  $("#end_date").datepicker("setDate", enddate);
64
  });
65
+
66
+ // Initialize Dates
67
+ $("#start_date").datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $("#start_date").val()));
68
+ $("#end_date").datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $("#end_date").val()));
69
  });
event-list.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Event List
4
  Plugin URI: http://wordpress.org/extend/plugins/event-list/
5
  Description: Manage your events and show them in a list view on your site.
6
- Version: 0.6.1
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
3
  Plugin Name: Event List
4
  Plugin URI: http://wordpress.org/extend/plugins/event-list/
5
  Description: Manage your events and show them in a list view on your site.
6
+ Version: 0.6.2
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
includes/css/event-list.css CHANGED
@@ -116,7 +116,7 @@ div.filterbar select.dropdown, div.filterbar ul.hlist, div.filterbar a.link {
116
 
117
  div.filterbar ul.hlist li {
118
  float: left;
119
- list-style-type: none;
120
  margin: 0;
121
  }
122
 
116
 
117
  div.filterbar ul.hlist li {
118
  float: left;
119
+ list-style: none;
120
  margin: 0;
121
  }
122
 
includes/db.php CHANGED
@@ -81,12 +81,12 @@ class EL_Db {
81
  }
82
  $date = $wpdb->get_results($sql, ARRAY_A);
83
  if( !empty( $date ) ) {
84
- $date = $this->extract_date( $date[0][$search_date],'Y');
85
  }
86
  else {
87
- $date = date('Y', current_time('timestamp'));
88
  }
89
- return $date;
90
  }
91
 
92
  public function get_num_events() {
@@ -95,7 +95,7 @@ class EL_Db {
95
  return $wpdb->get_var($sql);
96
  }
97
 
98
- public function update_event( $event_data, $dateformat=NULL ) {
99
  global $wpdb;
100
  // prepare and validate sqldata
101
  $sqldata = array();
@@ -107,17 +107,15 @@ class EL_Db {
107
  $sqldata['pub_date'] = isset($event_data['pub_date']) ? $event_data['pub_date'] : date("Y-m-d H:i:s", current_time('timestamp'));
108
  }
109
  //start_date
110
- if( !isset( $event_data['start_date']) ) { return false; }
111
- $start_timestamp = 0;
112
- $sqldata['start_date'] = $this->extract_date( $event_data['start_date'], "Y-m-d", $dateformat, $start_timestamp );
113
- if( false === $sqldata['start_date'] ) { return false; }
114
  //end_date
115
- if( !isset( $event_data['end_date']) ) { return false; }
116
- if( isset( $event_data['multiday'] ) && "1" === $event_data['multiday'] ) {
117
- $end_timestamp = 0;
118
- $sqldata['end_date'] = $this->extract_date( $event_data['end_date'], "Y-m-d", $dateformat, $end_timestamp );
119
- if( false === $sqldata['end_date'] ) { $sqldata['end_date'] = $sqldata['start_date']; }
120
- elseif( $end_timestamp < $start_timestamp ) { $sqldata['end_date'] = $sqldata['start_date']; }
121
  }
122
  else {
123
  $sqldata['end_date'] = $sqldata['start_date'];
@@ -206,27 +204,12 @@ class EL_Db {
206
  return $wpdb->get_var( $sql );
207
  }
208
 
209
- private function extract_date( $datestring, $ret_format, $dateformat=NULL, &$ret_timestamp=NULL, &$ret_datearray=NULL ) {
210
- if( NULL === $dateformat ) {
211
- $date_array = date_parse( $datestring );
 
212
  }
213
- else {
214
- $date_array = date_parse_from_format( $dateformat, $datestring );
215
- }
216
- if( !empty( $date_array['errors']) ) {
217
- return false;
218
- }
219
- if( false === checkdate( $date_array['month'], $date_array['day'], $date_array['year'] ) ) {
220
- return false;
221
- }
222
- $timestamp = mktime( 0, 0, 0, $date_array['month'], $date_array['day'], $date_array['year'] );
223
- if( isset( $ret_timestamp ) ) {
224
- $ret_timestamp = $timestamp;
225
- }
226
- if( isset( $ret_datearray ) ) {
227
- $ret_datearray = $date_array;
228
- }
229
- return date( $ret_format, $timestamp );
230
  }
231
 
232
  private function get_sql_filter_string($date_filter=null, $cat_filter=null) {
@@ -363,75 +346,4 @@ class EL_Db {
363
  }
364
  }
365
  }
366
-
367
-
368
- // Define "date_parse_from_format" (This is required for php versions < 5.3)
369
- if(!function_exists('date_parse_from_format')){
370
- function date_parse_from_format($format, $date) {
371
- // reverse engineer date formats
372
- $keys = array(
373
- 'Y' => array('year', '\d{4}'), // A full numeric representation of a year, 4 digits
374
- 'y' => array('year', '\d{2}'), // A two digit representation of a year
375
- 'm' => array('month', '\d{2}'), // Numeric representation of a month, with leading zeros
376
- 'n' => array('month', '\d{1,2}'), // Numeric representation of a month, without leading zeros
377
- 'M' => array('month', '[A-Z][a-z]{3}'), // A short textual representation of a month, three letters
378
- 'F' => array('month', '[A-Z][a-z]{2,8}'), // A full textual representation of a month, such as January or March
379
- 'd' => array('day', '\d{2}'), // Day of the month, 2 digits with leading zeros
380
- 'j' => array('day', '\d{1,2}'), // Day of the month without leading zeros
381
- 'D' => array('day', '[A-Z][a-z]{2}'), // A textual representation of a day, three letters
382
- 'l' => array('day', '[A-Z][a-z]{6,9}'), // A full textual representation of the day of the week
383
- 'u' => array('hour', '\d{1,6}'), // Microsecondes
384
- 'h' => array('hour', '\d{2}'), // 12-hour format of an hour with leading zeros
385
- 'H' => array('hour', '\d{2}'), // 24-hour format of an hour with leading zeros
386
- 'g' => array('hour', '\d{1,2}'), // 12-hour format of an hour without leading zeros
387
- 'G' => array('hour', '\d{1,2}'), // 24-hour format of an hour without leading zeros
388
- 'i' => array('minute', '\d{2}'), // Minutes with leading zeros
389
- 's' => array('second', '\d{2}') // Seconds, with leading zeros
390
- );
391
- // convert format string to regex
392
- $regex = '';
393
- $chars = str_split($format);
394
- foreach($chars as $n => $char) {
395
- $lastChar = isset($chars[$n-1]) ? $chars[$n-1] : '';
396
- $skipCurrent = '\\' == $lastChar;
397
- if(!$skipCurrent && isset($keys[$char])) {
398
- $regex .= '(?P<'.$keys[$char][0].'>'.$keys[$char][1].')';
399
- }
400
- else if('\\' == $char) {
401
- $regex .= $char;
402
- }
403
- else {
404
- $regex .= preg_quote($char);
405
- }
406
- }
407
- // create array
408
- $dt = array();
409
- $dt['error_count'] = 0;
410
- $dt['errors'] = array();
411
- // now try to match it
412
- if(preg_match('#^'.$regex.'$#', $date, $dt)){
413
- foreach($dt as $k => $v) {
414
- if(is_int($k)){
415
- unset($dt[$k]);
416
- }
417
- }
418
- if(!checkdate($dt['month'], $dt['day'], $dt['year'])) {
419
- $dt['error_count'] = 1;
420
- $dt['errors'][] = 'ERROR';
421
- }
422
- }
423
- else {
424
- $dt['error_count'] = 1;
425
- $dt['errors'][] = 'ERROR';
426
- }
427
- $dt['fraction'] = '';
428
- $dt['warning_count'] = 0;
429
- $dt['warnings'] = array();
430
- $dt['is_localtime'] = 0;
431
- $dt['zone_type'] = 0;
432
- $dt['zone'] = 0;
433
- $dt['is_dst'] = '';
434
- return $dt;
435
- }
436
- }
437
  ?>
81
  }
82
  $date = $wpdb->get_results($sql, ARRAY_A);
83
  if( !empty( $date ) ) {
84
+ $datestring = substr($date[0][$search_date], 0, 4);
85
  }
86
  else {
87
+ $datestring = date('Y', current_time('timestamp'));
88
  }
89
+ return $datestring;
90
  }
91
 
92
  public function get_num_events() {
95
  return $wpdb->get_var($sql);
96
  }
97
 
98
+ public function update_event($event_data) {
99
  global $wpdb;
100
  // prepare and validate sqldata
101
  $sqldata = array();
107
  $sqldata['pub_date'] = isset($event_data['pub_date']) ? $event_data['pub_date'] : date("Y-m-d H:i:s", current_time('timestamp'));
108
  }
109
  //start_date
110
+ if(!isset( $event_data['start_date'])) { return false; }
111
+ $sqldata['start_date'] = $this->validate_sql_date($event_data['start_date']);
112
+ if(false === $sqldata['start_date']) { return false; }
 
113
  //end_date
114
+ if(isset($event_data['multiday']) && "1" === $event_data['multiday']) {
115
+ if(!isset($event_data['end_date'])) { $sqldata['end_date'] = $sqldata['start_date']; }
116
+ $sqldata['end_date'] = $this->validate_sql_date($event_data['end_date']);
117
+ if(false === $sqldata['end_date']) { $sqldata['end_date'] = $sqldata['start_date']; }
118
+ elseif(new DateTime($sqldata['end_date']) < new DateTime($sqldata['start_date'])) { $sqldata['end_date'] = $sqldata['start_date']; }
 
119
  }
120
  else {
121
  $sqldata['end_date'] = $sqldata['start_date'];
204
  return $wpdb->get_var( $sql );
205
  }
206
 
207
+ private function validate_sql_date($datestring) {
208
+ $d = DateTime::createFromFormat('Y-m-d', $datestring);
209
+ if($d && $d->format('Y-m-d') == $datestring) {
210
+ return $datestring;
211
  }
212
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
214
 
215
  private function get_sql_filter_string($date_filter=null, $cat_filter=null) {
346
  }
347
  }
348
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  ?>
includes/options.php CHANGED
@@ -61,6 +61,15 @@ class EL_Options {
61
  'desc' => __('With this option you can display the date only once per day if multiple events are available on the same day.<br />
62
  If this option is enabled the events are ordered in a different way (end date before start time) to allow using the same date for as much events as possible.')),
63
 
 
 
 
 
 
 
 
 
 
64
  'el_enable_feed' => array('section' => 'feed',
65
  'type' => 'checkbox',
66
  'std_val' => '',
61
  'desc' => __('With this option you can display the date only once per day if multiple events are available on the same day.<br />
62
  If this option is enabled the events are ordered in a different way (end date before start time) to allow using the same date for as much events as possible.')),
63
 
64
+ 'el_edit_dateformat' => array('section' => 'admin',
65
+ 'type' => 'text',
66
+ 'std_val' => '',
67
+ 'label' => __('Date format in edit form'),
68
+ 'caption' => __('Specific date format in new/edit event form'),
69
+ 'desc' => __('This option sets a specific date format for the event date fields in the new/edit event form.<br />
70
+ The standard is an empty string to use the wordpress standard setting.<br />
71
+ All available options to specify the format can be found <a href="http://php.net/manual/en/function.date.php" target="_blank">here</a>')),
72
+
73
  'el_enable_feed' => array('section' => 'feed',
74
  'type' => 'checkbox',
75
  'std_val' => '',
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mibuthu
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W54LNZMWF9KW2
4
  Tags: event, events, list, listview, calendar, schedule, shortcode, page, category, categories, filter, admin, attribute, widget, sidebar, feed, rss
5
  Requires at least: 3.3
6
- Tested up to: 3.8
7
- Stable tag: 0.6.1
8
  Plugin URI: http://wordpress.org/extend/plugins/event-list
9
  Licence: GPLv2
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -71,7 +71,14 @@ Another possibility would be to call the wordpress function "do_shortcode()".
71
 
72
  == Changelog ==
73
 
74
- = 0.6.1 (2013-01-03) =
 
 
 
 
 
 
 
75
  * fixed redirect issue in admin event table
76
  * fixed a bug in filterbar javascript
77
  * fixed a problem with wrong format of deatails in admin event table
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W54LNZMWF9KW2
4
  Tags: event, events, list, listview, calendar, schedule, shortcode, page, category, categories, filter, admin, attribute, widget, sidebar, feed, rss
5
  Requires at least: 3.3
6
+ Tested up to: 3.8.1
7
+ Stable tag: 0.6.2
8
  Plugin URI: http://wordpress.org/extend/plugins/event-list
9
  Licence: GPLv2
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
71
 
72
  == Changelog ==
73
 
74
+ = 0.6.2 (2014-02-01) =
75
+ * complete rewrite of date handling in new/edit event form and date validation
76
+ * added option to change date format in event new/edit form
77
+ * fixed a css issue in the filterbar hlist when list-style-image is used in the theme
78
+ * some css fixes in admin settings page
79
+ * some html output code style fixes
80
+
81
+ = 0.6.1 (2014-01-03) =
82
  * fixed redirect issue in admin event table
83
  * fixed a bug in filterbar javascript
84
  * fixed a problem with wrong format of deatails in admin event table