Event List - Version 0.6.3

Version Description

(2014-02-09) = * added options to allow html tags in event time and location * fixed date check for PHP version 5.2 * fixed edit view after adding a new event * strip slashes in event time field * fixed url to event-list css file * only load event-list css if required

Download this release

Release Info

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

Code changes from version 0.6.2 to 0.6.3

admin/includes/admin-new.php CHANGED
@@ -13,6 +13,8 @@ class EL_Admin_New {
13
  private $db;
14
  private $options;
15
  private $categories;
 
 
16
 
17
  public static function &get_instance() {
18
  // Create class instance if required
@@ -27,6 +29,8 @@ class EL_Admin_New {
27
  $this->db = &EL_Db::get_instance();
28
  $this->options = &EL_Options::get_instance();
29
  $this->categories = &EL_Categories::get_instance();
 
 
30
  }
31
 
32
  public function show_new() {
@@ -49,23 +53,17 @@ class EL_Admin_New {
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
 
 
 
 
55
  $event = $this->db->get_event($_GET['id']);
56
- if(isset($_GET['action']) && $_GET['action'] === 'edit') {
57
- // editing of an existing event, if not it would be copy of an existing event
58
- $edit = true;
59
- }
60
  $start_date = strtotime($event->start_date);
61
  $end_date = strtotime($event->end_date);
62
  }
63
- else {
64
- //new event
65
- $start_date = current_time('timestamp')+86400; // next day (86400 seconds = 1*24*60*60 = 1 day);
66
- $end_date = $start_date;
67
- }
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)));
@@ -81,14 +79,14 @@ class EL_Admin_New {
81
  <div id="poststuff">
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">
@@ -148,8 +146,7 @@ class EL_Admin_New {
148
  }
149
 
150
  public function render_publish_metabox() {
151
- $edit = (isset($_GET['id']) && is_numeric($_GET['id']) && isset($_GET['action']) && 'edit' === $_GET['action']) ? true : false;
152
- $button_text = $edit ? __('Update') : __('Publish');
153
  $out = '<div class="submitbox">
154
  <div id="delete-action"><a href="?page=el_admin_main" class="submitdelete deletion">'.__('Cancel').'</a></div>
155
  <div id="publishing-action"><input type="submit" class="button button-primary button-large" name="publish" value="'.$button_text.'" id="publish"></div>
13
  private $db;
14
  private $options;
15
  private $categories;
16
+ private $is_new;
17
+ private $is_duplicate;
18
 
19
  public static function &get_instance() {
20
  // Create class instance if required
29
  $this->db = &EL_Db::get_instance();
30
  $this->options = &EL_Options::get_instance();
31
  $this->categories = &EL_Categories::get_instance();
32
+ $this->is_new = !(isset($_GET['action']) && ('edit' === $_GET['action'] || 'added' === $_GET['action'] || 'modified' === $_GET['action']));
33
+ $this->is_duplicate = $this->is_new && isset($_GET['id']) && is_numeric($_GET['id']);
34
  }
35
 
36
  public function show_new() {
53
 
54
  public function edit_event() {
55
  $dateformat = $this->get_event_dateformat();
56
+ if($this->is_new && !$this->is_duplicate) {
57
+ // set next day as date
58
+ $start_date = current_time('timestamp')+86400; // next day (86400 seconds = 1*24*60*60 = 1 day);
59
+ $end_date = $start_date;
60
+ }
61
+ else {
62
+ // set event data and existing date
63
  $event = $this->db->get_event($_GET['id']);
 
 
 
 
64
  $start_date = strtotime($event->start_date);
65
  $end_date = strtotime($event->end_date);
66
  }
 
 
 
 
 
 
67
  // Add required data for javascript in a hidden field
68
  $json = json_encode(array('el_url' => EL_URL,
69
  'el_date_format' => $this->datepicker_format($dateformat)));
79
  <div id="poststuff">
80
  <div id="post-body" class="metabox-holder columns-2">
81
  <div id="post-body-content">';
82
+ if($this->is_new) {
83
  $out .= '
84
+ <input type="hidden" name="action" value="new" />';
 
85
  }
86
  else {
87
  $out .= '
88
+ <input type="hidden" name="action" value="edited" />
89
+ <input type="hidden" name="id" value="'.$_GET['id'].'" />';
90
  }
91
  $out .= '
92
  <table class="form-table">
146
  }
147
 
148
  public function render_publish_metabox() {
149
+ $button_text = $this->is_new ? __('Publish') : __('Update');
 
150
  $out = '<div class="submitbox">
151
  <div id="delete-action"><a href="?page=el_admin_main" class="submitdelete deletion">'.__('Cancel').'</a></div>
152
  <div id="publishing-action"><input type="submit" class="button button-primary button-large" name="publish" value="'.$button_text.'" id="publish"></div>
admin/includes/event_table.php CHANGED
@@ -45,7 +45,7 @@ class EL_Event_Table extends WP_List_Table {
45
  case 'date' :
46
  return $this->format_event_date($item->start_date, $item->end_date, $item->time);
47
  case 'details' :
48
- return '<div>'.$this->db->truncate(80, $item->details).'</div>';
49
  case 'pub_user' :
50
  return get_userdata($item->pub_user)->user_login;
51
  case 'pub_date' :
@@ -289,7 +289,7 @@ class EL_Event_Table extends WP_List_Table {
289
  $start_time = mysql2date( get_option( 'time_format' ), $start_time );
290
  }
291
  $out .= '<br />
292
- <span class="time">'.$start_time.'</span>';
293
  }
294
  $out .= '</span>';
295
  return $out;
45
  case 'date' :
46
  return $this->format_event_date($item->start_date, $item->end_date, $item->time);
47
  case 'details' :
48
+ return '<div>'.$this->db->truncate($item->details, 80).'</div>';
49
  case 'pub_user' :
50
  return get_userdata($item->pub_user)->user_login;
51
  case 'pub_date' :
289
  $start_time = mysql2date( get_option( 'time_format' ), $start_time );
290
  }
291
  $out .= '<br />
292
+ <span class="time">'.esc_html($start_time).'</span>';
293
  }
294
  $out .= '</span>';
295
  return $out;
event-list.php CHANGED
@@ -3,13 +3,13 @@
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
10
 
11
  A plugin for the blogging MySQL/PHP-based WordPress.
12
- Copyright 2012-2013 Michael Burtscher
13
 
14
  This program is free software; you can redistribute it and/or
15
  modify it under the terms of the GNUs General Public License
@@ -87,8 +87,11 @@ class Event_List {
87
  }
88
 
89
  public function print_styles() {
90
- wp_register_style('event-list_css', EL_URL.'/includes/css/event-list.css');
91
- wp_enqueue_style( 'event-list_css');
 
 
 
92
  }
93
  } // end class linkview
94
 
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.3
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
10
 
11
  A plugin for the blogging MySQL/PHP-based WordPress.
12
+ Copyright 2012-2014 Michael Burtscher
13
 
14
  This program is free software; you can redistribute it and/or
15
  modify it under the terms of the GNUs General Public License
87
  }
88
 
89
  public function print_styles() {
90
+ global $post;
91
+ if(is_active_widget(null, null, 'event_list_widget') || strstr($post->post_content, '[event-list]')) {
92
+ wp_register_style('event-list', EL_URL.'includes/css/event-list.css');
93
+ wp_enqueue_style( 'event-list');
94
+ }
95
  }
96
  } // end class linkview
97
 
includes/db.php CHANGED
@@ -122,7 +122,7 @@ class EL_Db {
122
  }
123
  //time
124
  if( !isset( $event_data['time'] ) ) { $sqldata['time'] = ''; }
125
- else { $sqldata['time'] = $event_data['time']; }
126
  //title
127
  if( !isset( $event_data['title'] ) || $event_data['title'] === '' ) { return false; }
128
  $sqldata['title'] = stripslashes( $event_data['title'] );
@@ -205,7 +205,7 @@ class EL_Db {
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
  }
@@ -276,30 +276,41 @@ class EL_Db {
276
  return $sql_filter_string;
277
  }
278
 
279
- /** ************************************************************************
280
  * Function to truncate and shorten text
281
  *
282
- * @param int $max_length The length to which the text should be shortened
283
  * @param string $html The html code which should be shortened
284
- ***************************************************************************/
285
- public function truncate( $max_length, $html ) {
286
- if( $max_length > 0 && strlen( $html ) > $max_length ) {
 
 
 
 
 
 
 
 
 
 
 
 
287
  $printedLength = 0;
288
  $position = 0;
289
  $tags = array();
290
  $out = '';
291
- while ($printedLength < $max_length && preg_match('{</?([a-z]+)[^>]*>|&#?[a-zA-Z0-9]+;}', $html, $match, PREG_OFFSET_CAPTURE, $position)) {
292
  list($tag, $tagPosition) = $match[0];
293
  // Print text leading up to the tag
294
  $str = substr($html, $position, $tagPosition - $position);
295
- if ($printedLength + strlen($str) > $max_length) {
296
- $out .= substr($str, 0, $max_length - $printedLength);
297
- $printedLength = $max_length;
298
  break;
299
  }
300
  $out .= $str;
301
  $printedLength += strlen($str);
302
- if ($tag[0] == '&') {
303
  // Handle the entity
304
  $out .= $tag;
305
  $printedLength++;
@@ -307,14 +318,13 @@ class EL_Db {
307
  else {
308
  // Handle the tag
309
  $tagName = $match[1][0];
310
- if ($tag[1] == '/')
311
- {
312
  // This is a closing tag
313
  $openingTag = array_pop($tags);
314
  assert($openingTag == $tagName); // check that tags are properly nested
315
  $out .= $tag;
316
  }
317
- else if ($tag[strlen($tag) - 2] == '/') {
318
  // Self-closing tag
319
  $out .= $tag;
320
  }
@@ -328,22 +338,30 @@ class EL_Db {
328
  $position = $tagPosition + strlen($tag);
329
  }
330
  // Print any remaining text
331
- if ($printedLength < $max_length && $position < strlen($html)) {
332
- $out .= substr($html, $position, $max_length - $printedLength);
333
  }
334
  // Print "..." if the html is not complete
335
- if( strlen( $html) != $position ) {
336
- $out .= ' ...';
337
  }
338
  // Close any open tags.
339
- while (!empty($tags)) {
340
  $out .= '</'.array_pop($tags).'>';
341
  }
342
  return $out;
343
  }
344
- else {
345
- return $html;
346
- }
 
 
 
 
 
 
 
 
347
  }
348
  }
349
  ?>
122
  }
123
  //time
124
  if( !isset( $event_data['time'] ) ) { $sqldata['time'] = ''; }
125
+ else { $sqldata['time'] = stripslashes($event_data['time']); }
126
  //title
127
  if( !isset( $event_data['title'] ) || $event_data['title'] === '' ) { return false; }
128
  $sqldata['title'] = stripslashes( $event_data['title'] );
205
  }
206
 
207
  private function validate_sql_date($datestring) {
208
+ $d = date_create_from_format('Y-m-d', $datestring);
209
  if($d && $d->format('Y-m-d') == $datestring) {
210
  return $datestring;
211
  }
276
  return $sql_filter_string;
277
  }
278
 
279
+ /** ************************************************************************************************************
280
  * Function to truncate and shorten text
281
  *
 
282
  * @param string $html The html code which should be shortened
283
+ * @param int $length The length to which the text should be shortened
284
+ * @param bool skip If this value is true the truncate will be skipped (nothing will be done)
285
+ * @param bool perserve_tags Specifies if html tags should be preserved or if only the text should be shortened
286
+ ***************************************************************************************************************/
287
+ public function truncate($html, $length, $skip=false, $preserve_tags=true) {
288
+ if(0 >= $length || strlen($html) <= $length || $skip) {
289
+ // do nothing
290
+ return $html;
291
+ }
292
+ elseif(!$preserve_tags) {
293
+ // only shorten text
294
+ return substr($html, 0, $length);
295
+ }
296
+ else {
297
+ // truncate with preserving html tags
298
  $printedLength = 0;
299
  $position = 0;
300
  $tags = array();
301
  $out = '';
302
+ while($printedLength < $length && preg_match('{</?([a-z]+)[^>]*>|&#?[a-zA-Z0-9]+;}', $html, $match, PREG_OFFSET_CAPTURE, $position)) {
303
  list($tag, $tagPosition) = $match[0];
304
  // Print text leading up to the tag
305
  $str = substr($html, $position, $tagPosition - $position);
306
+ if($printedLength + strlen($str) > $length) {
307
+ $out .= substr($str, 0, $length - $printedLength);
308
+ $printedLength = $length;
309
  break;
310
  }
311
  $out .= $str;
312
  $printedLength += strlen($str);
313
+ if($tag[0] == '&') {
314
  // Handle the entity
315
  $out .= $tag;
316
  $printedLength++;
318
  else {
319
  // Handle the tag
320
  $tagName = $match[1][0];
321
+ if($tag[1] == '/') {
 
322
  // This is a closing tag
323
  $openingTag = array_pop($tags);
324
  assert($openingTag == $tagName); // check that tags are properly nested
325
  $out .= $tag;
326
  }
327
+ else if($tag[strlen($tag) - 2] == '/') {
328
  // Self-closing tag
329
  $out .= $tag;
330
  }
338
  $position = $tagPosition + strlen($tag);
339
  }
340
  // Print any remaining text
341
+ if($printedLength < $length && $position < strlen($html)) {
342
+ $out .= substr($html, $position, $length - $printedLength);
343
  }
344
  // Print "..." if the html is not complete
345
+ if(strlen($html) != $position) {
346
+ $out .= ' &hellip;';
347
  }
348
  // Close any open tags.
349
+ while(!empty($tags)) {
350
  $out .= '</'.array_pop($tags).'>';
351
  }
352
  return $out;
353
  }
354
+ }
355
+ }
356
+
357
+ /* create date_create_from_format (DateTime::createFromFormat) alternative for PHP 5.2
358
+ *
359
+ * This function is only a small implementation of this function with reduced functionality to handle sql dates (format: 2014-01-31)
360
+ */
361
+ if(!function_exists("date_create_from_format")) {
362
+ function date_create_from_format($dformat, $dvalue) {
363
+ $d = new DateTime($dvalue);
364
+ return $d;
365
  }
366
  }
367
  ?>
includes/options.php CHANGED
@@ -61,6 +61,20 @@ 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_edit_dateformat' => array('section' => 'admin',
65
  'type' => 'text',
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_html_tags_in_time' => array('section' => 'general',
65
+ 'type' => 'checkbox',
66
+ 'std_val' => '',
67
+ 'label' => __('HTML tags'),
68
+ 'caption' => __('Allow HTML tags in event time field'),
69
+ 'desc' => __('This option specifies if HTML tags are allowed in the event start time field.')),
70
+
71
+ 'el_html_tags_in_loc' => array('section' => 'general',
72
+ 'type' => 'checkbox',
73
+ 'std_val' => '',
74
+ 'label' => '', // only one label for all html tags settings
75
+ 'caption' => __('Allow HTML tags in event location field'),
76
+ 'desc' => __('This option specifies if HTML tags are allowed in the event location field.')),
77
+
78
  'el_edit_dateformat' => array('section' => 'admin',
79
  'type' => 'text',
80
  'std_val' => '',
includes/sc_event-list.php CHANGED
@@ -296,9 +296,9 @@ class SC_Event_List {
296
 
297
  private function html_event( &$event, &$a, $single_day_only=false ) {
298
  static $last_event_startdate=null, $last_event_enddate=null;
299
- $max_length = is_numeric( $a['event_id'] ) ? 0 : 999999;
300
  $out = '
301
  <li class="event">';
 
302
  if( '1' !== $this->options->get( 'el_date_once_per_day' ) || $last_event_startdate !== $event->start_date || $last_event_enddate !== $event->end_date ) {
303
  $out .= $this->html_fulldate( $event->start_date, $event->end_date, $single_day_only );
304
  }
@@ -311,10 +311,9 @@ class SC_Event_List {
311
  $out .= ' multi-day';
312
  }
313
  $out .= '">';
314
-
315
  $out .= '<div class="event-title"><h3>';
316
-
317
- $title = esc_attr($this->db->truncate(min($max_length, $a['title_length']), $event->title));
318
  if( $this->is_visible( $a['link_to_event'] ) ) {
319
  $out .= '<a href="'.esc_html(add_query_arg('event_id'.$a['sc_id_for_url'], $event->id, $this->get_url($a))).'">'.$title.'</a>';
320
  }
@@ -322,22 +321,34 @@ class SC_Event_List {
322
  $out .= $title;
323
  }
324
  $out .= '</h3></div>';
325
- if( $event->time != '' && $this->is_visible( $a['show_starttime'] ) ) {
 
326
  // set time format if a known format is available, else only show the text
327
- $date_array = date_parse( $event->time );
328
- if( empty( $date_array['errors']) && is_numeric( $date_array['hour'] ) && is_numeric( $date_array['minute'] ) ) {
329
- $event->time = mysql2date( get_option( 'time_format' ), $event->time );
 
 
 
 
330
  }
331
- $out .= '<span class="event-time">'.esc_attr($event->time).'</span>';
332
  }
333
- if( $this->is_visible( $a['show_location'] ) ) {
334
- $out .= '<span class="event-location">'.esc_attr($this->db->truncate(min($max_length, $a['location_length']), $event->location)).'</span>';
 
 
 
 
 
 
 
335
  }
336
  if( $this->is_visible( $a['show_cat'] ) ) {
337
  $out .= '<div class="event-cat">'.esc_attr($this->categories->get_category_string($event->categories)).'</div>';
338
  }
339
  if( $this->is_visible( $a['show_details'] ) ) {
340
- $out .= '<div class="event-details">'.$this->db->truncate( min( $max_length, $a['details_length'] ), do_shortcode( $event->details ) ).'</div>';
341
  }
342
  $out .= '</div>
343
  </li>';
296
 
297
  private function html_event( &$event, &$a, $single_day_only=false ) {
298
  static $last_event_startdate=null, $last_event_enddate=null;
 
299
  $out = '
300
  <li class="event">';
301
+ // event date
302
  if( '1' !== $this->options->get( 'el_date_once_per_day' ) || $last_event_startdate !== $event->start_date || $last_event_enddate !== $event->end_date ) {
303
  $out .= $this->html_fulldate( $event->start_date, $event->end_date, $single_day_only );
304
  }
311
  $out .= ' multi-day';
312
  }
313
  $out .= '">';
314
+ // event title
315
  $out .= '<div class="event-title"><h3>';
316
+ $title = esc_attr($this->db->truncate($event->title, $a['title_length'], $this->single_event));
 
317
  if( $this->is_visible( $a['link_to_event'] ) ) {
318
  $out .= '<a href="'.esc_html(add_query_arg('event_id'.$a['sc_id_for_url'], $event->id, $this->get_url($a))).'">'.$title.'</a>';
319
  }
321
  $out .= $title;
322
  }
323
  $out .= '</h3></div>';
324
+ // event time
325
+ if('' != $event->time && $this->is_visible($a['show_starttime'])) {
326
  // set time format if a known format is available, else only show the text
327
+ $date_array = date_parse($event->time);
328
+ $time = $event->time;
329
+ if(empty($date_array['errors']) && is_numeric($date_array['hour']) && is_numeric($date_array['minute'])) {
330
+ $time = mysql2date(get_option('time_format'), $event->time);
331
+ }
332
+ if('' == $this->options->get('el_html_tags_in_time')) {
333
+ $time = esc_attr($time);
334
  }
335
+ $out .= '<span class="event-time">'.$time.'</span>';
336
  }
337
+ // event location
338
+ if('' != $event->location && $this->is_visible($a['show_location'])) {
339
+ if('' == $this->options->get('el_html_tags_in_loc')) {
340
+ $location = esc_attr($this->db->truncate($event->location, $a['location_length'], $this->single_event, false));
341
+ }
342
+ else {
343
+ $location = $this->db->truncate($event->location, $a['location_length'], $this->single_event);
344
+ }
345
+ $out .= '<span class="event-location">'.$location.'</span>';
346
  }
347
  if( $this->is_visible( $a['show_cat'] ) ) {
348
  $out .= '<div class="event-cat">'.esc_attr($this->categories->get_category_string($event->categories)).'</div>';
349
  }
350
  if( $this->is_visible( $a['show_details'] ) ) {
351
+ $out .= '<div class="event-details">'.$this->db->truncate(do_shortcode($event->details), $a['details_length'], $this->single_event).'</div>';
352
  }
353
  $out .= '</div>
354
  </li>';
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
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,6 +71,14 @@ Another possibility would be to call the wordpress function "do_shortcode()".
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
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.3
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.3 (2014-02-09) =
75
+ * added options to allow html tags in event time and location
76
+ * fixed date check for PHP version 5.2
77
+ * fixed edit view after adding a new event
78
+ * strip slashes in event time field
79
+ * fixed url to event-list css file
80
+ * only load event-list css if required
81
+
82
  = 0.6.2 (2014-02-01) =
83
  * complete rewrite of date handling in new/edit event form and date validation
84
  * added option to change date format in event new/edit form