Event List - Version 0.3.0

Version Description

(2012-12-31) =

  • added a widget to show upcoming events in a sidebar
  • added some shortcode attributes to modify the output
  • internal code changes
  • fixed some html issues
  • updated help texts on admin about page
Download this release

Release Info

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

Code changes from version 0.2.2 to 0.3.0

css/admin_about.css ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .el-show-event-options {
2
+ list-style: circle inside;
3
+ }
4
+
5
+ .el-headline {
6
+ margin-top: 2.3em;
7
+ }
8
+
9
+ .el-atts-table {
10
+ border: 1px solid #aaa;
11
+ border-collapse: collapse;
12
+ width: 95%;
13
+ }
14
+ .el-atts-table th {
15
+ border: 1px solid #aaa;
16
+ padding: 3px 4px !important;
17
+ background: #eeeeee;
18
+ }
19
+ .el-atts-table td {
20
+ border: 1px solid #aaa;
21
+ padding: 2px 5px !important;
22
+ vertical-align: top;
23
+ }
24
+
25
+ .el-atts-table-name {
26
+ width: 110px;
27
+ }
28
+
29
+ .el-atts-table-options {
30
+ width: 110px;
31
+ }
32
+
33
+ .el-atts-table-default {
34
+ width: 110px;
35
+ }
css/event-list.css CHANGED
@@ -3,7 +3,7 @@
3
  Event List Layout
4
  ===================
5
 
6
- <ul id="cal">
7
 
8
  <li class="event">
9
  <div class="date">
@@ -15,7 +15,7 @@
15
  <div class="month"></div>
16
  <div class="year"></div>
17
  </div>
18
- <!-- ONLY OUTPUT FOR MULTI-DAY EVENTS -->
19
 
20
  <div class="end-date">
21
  <div class="weekday"></div>
@@ -24,11 +24,11 @@
24
  <div class="year"></div>
25
  </div>
26
  </div>
27
- <div class="info_block">
28
- <h3>[Event Title]</h3>
29
- <span class="time"></span>
30
- [Event Location]
31
- [Event Details]
32
  </div>
33
  </li>
34
 
@@ -46,33 +46,29 @@ a.rss-link {
46
  line-height:16px;
47
  }
48
  */
49
- #eventlist_nav {
50
- font-size: 1.2em;
51
- margin-bottom: 0.3em;
52
- }
53
 
54
- ul#eventlist {
55
  list-style: none;
56
  margin: 1em 0 1.5em 0;
57
  padding: 0;
58
  }
59
 
60
 
61
- #eventlist li.event {
62
  clear: both;
63
  }
64
 
65
- #eventlist .date {
66
  white-space: nowrap;
67
  float: left;
68
  margin-bottom: 1.5em;
69
  }
70
 
71
- #eventlist .multi-date {
72
  background: url(../images/date-separator.png) center no-repeat;
73
  }
74
 
75
- #eventlist .start-date, #eventlist .end-date {
76
  text-align: center;
77
  width: 3.2em;
78
  border-radius: 5px;
@@ -80,53 +76,57 @@ ul#eventlist {
80
  overflow: hidden;
81
  }
82
 
83
- #eventlist .start-date {
84
  float: left;
85
  }
86
 
87
- #eventlist .end-date {
88
  margin-left: 3.8em;
89
  }
90
 
91
- #eventlist .weekday {
92
- font-size: 0.9em;
93
  text-transform: uppercase;
94
  }
95
 
96
- #eventlist .day {
97
  font-size: 1.3em;
98
  font-weight: bold;
99
  line-height: 1em;
100
  margin-bottom: -0.2em;
101
  }
102
 
103
- #eventlist .month {
104
  text-transform: uppercase;
105
- font-size: 0.9em;
106
  line-height: 1em;
107
  padding: 0.4em 0 0.4em 0;
108
  }
109
 
110
- #eventlist .year {
111
  font-size: 0.8em;
112
  line-height: 0.8em;
113
  letter-spacing: 0.1em;
114
  padding-bottom: 0.3em;
115
  }
116
 
117
- #eventlist .info_block {
118
  margin: 0 0 0 7.5em;
119
  }
120
 
121
- #eventlist .info_block h3 {
 
 
 
 
122
  clear: none;
123
  }
124
 
125
- #eventlist .time {
126
  font-weight: bold;
127
  padding-right: 0.8em;
128
  }
129
 
130
- #eventlist .details {
131
  font-size: 0.8em;
132
  }
3
  Event List Layout
4
  ===================
5
 
6
+ <ul class="event-list">
7
 
8
  <li class="event">
9
  <div class="date">
15
  <div class="month"></div>
16
  <div class="year"></div>
17
  </div>
18
+ <!-- ONLY OUTPUT FOR MULTI-DAY EVENTS FINISH -->
19
 
20
  <div class="end-date">
21
  <div class="weekday"></div>
24
  <div class="year"></div>
25
  </div>
26
  </div>
27
+ <div class="event-info">
28
+ <h3 class="event-title"></h3>
29
+ <span class="event-time"></span>
30
+ <span class="event-location"></span>
31
+ <div class="event-details"></div>
32
  </div>
33
  </li>
34
 
46
  line-height:16px;
47
  }
48
  */
 
 
 
 
49
 
50
+ ul.event-list {
51
  list-style: none;
52
  margin: 1em 0 1.5em 0;
53
  padding: 0;
54
  }
55
 
56
 
57
+ li.event {
58
  clear: both;
59
  }
60
 
61
+ .event-date {
62
  white-space: nowrap;
63
  float: left;
64
  margin-bottom: 1.5em;
65
  }
66
 
67
+ .event-list .multi-date {
68
  background: url(../images/date-separator.png) center no-repeat;
69
  }
70
 
71
+ .event-list .start-date, .event-list .end-date {
72
  text-align: center;
73
  width: 3.2em;
74
  border-radius: 5px;
76
  overflow: hidden;
77
  }
78
 
79
+ .event-list .start-date {
80
  float: left;
81
  }
82
 
83
+ .event-list .end-date {
84
  margin-left: 3.8em;
85
  }
86
 
87
+ .event-weekday {
88
+ font-size: 0.8em;
89
  text-transform: uppercase;
90
  }
91
 
92
+ .event-day {
93
  font-size: 1.3em;
94
  font-weight: bold;
95
  line-height: 1em;
96
  margin-bottom: -0.2em;
97
  }
98
 
99
+ .event-month {
100
  text-transform: uppercase;
101
+ font-size: 1.0em;
102
  line-height: 1em;
103
  padding: 0.4em 0 0.4em 0;
104
  }
105
 
106
+ .event-year {
107
  font-size: 0.8em;
108
  line-height: 0.8em;
109
  letter-spacing: 0.1em;
110
  padding-bottom: 0.3em;
111
  }
112
 
113
+ .multi-day {
114
  margin: 0 0 0 7.5em;
115
  }
116
 
117
+ .single-day {
118
+ margin: 0 0 0 3.8em;
119
+ }
120
+
121
+ .event-info h3 {
122
  clear: none;
123
  }
124
 
125
+ .event-time {
126
  font-weight: bold;
127
  padding-right: 0.8em;
128
  }
129
 
130
+ .event-details {
131
  font-size: 0.8em;
132
  }
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.2.2
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
@@ -25,69 +25,72 @@ You can view a copy of the HTML version of the GNU General Public
25
  License at http://www.gnu.org/copyleft/gpl.html
26
  */
27
 
28
- // general definitions
29
  define( 'EL_URL', plugin_dir_url( __FILE__ ) );
30
  define( 'EL_PATH', plugin_dir_path( __FILE__ ) );
31
 
32
 
33
- // ADD HOOKS, ACTIONS AND SHORTCODES:
34
-
35
- // FOR ADMIN AND FRONTPAGE:
36
- // TODO: Check the following hooks
37
- //register_activation_hook( 'php/db.php', array( 'el_db', 'upgrade_check' ) );
38
- //register_activation_hook( 'php/options.php', array( 'el_options', 'upgrade' ) );
39
- add_action( 'plugins_loaded', 'on_el_plugin_loaded' );
40
- // TODO: Add widget
41
- //add_action( 'widgets_init', 'on_el_widgets' );
42
-
43
- // ADMIN PAGE:
44
- if ( is_admin() ) {
45
- add_action( 'admin_menu', 'on_el_admin' ); // add admin pages in admin menu
46
- // add_action( 'admin_init', 'on_el_register_settings' ); // register settings
47
- }
48
-
49
- // FRONT PAGE:
50
- else {
51
- add_shortcode( 'event-list', 'on_el_sc_event_list' ); // add shortcode [event-list]
52
- // Stylesheet for display
53
- add_action('wp_print_styles', 'on_el_styles');
54
- }
55
-
56
- function on_el_plugin_loaded() {
57
- require_once( 'php/db.php' );
58
- el_db::update_check();
59
- }
60
-
61
- function on_el_admin() {
62
- require_once( 'php/admin.php' );
63
- add_menu_page( 'Event List', 'Event List', 'edit_posts', 'el_admin_main', array( 'el_admin', 'show_main' ) );
64
- $page = add_submenu_page( 'el_admin_main', 'Events', 'All Events', 'edit_posts', 'el_admin_main', array( 'el_admin', 'show_main' ) );
65
- add_action( 'admin_print_scripts-'.$page, array( 'el_admin', 'embed_admin_main_scripts' ) );
66
- $page = add_submenu_page( 'el_admin_main', 'Add New Event', 'Add New', 'edit_posts', 'el_admin_new', array( 'el_admin', 'show_new' ) );
67
- add_action( 'admin_print_scripts-'.$page, array( 'el_admin', 'embed_admin_new_scripts' ) );
68
- add_submenu_page( 'el_admin_main', 'Event List Settings', 'Settings', 'manage_options', 'el_admin_settings', array( 'el_admin', 'show_settings' ) );
69
- add_submenu_page( 'el_admin_main', 'About Event List', 'About', 'manage_options', 'el_admin_about', array( 'el_admin', 'show_about' ) );
70
- }
71
- /*
72
- function on_el_register_settings() {
73
- require_once( 'php/options.php' );
74
- el_options::register();
75
- }
76
- */
77
- function on_el_sc_event_list( $atts ) {
78
- require_once( 'php/sc_event-list.php' );
79
- return sc_event_list::show_html( $atts );
80
- }
81
 
82
- function on_el_styles() {
83
- wp_register_style('event-list_css', EL_URL.'css/event-list.css');
84
- wp_enqueue_style( 'event-list_css');
85
- }
 
 
86
 
87
- /*
88
- function on_el_widgets() {
89
- require_once( 'php/event-list_widget.php' );
90
- return register_widget( 'event_list_widget' );
91
- }
92
- */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  ?>
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.3.0
7
  Author: Michael Burtscher
8
  Author URI: http://wordpress.org/extend/plugins/event-list/
9
  License: GPLv2
25
  License at http://www.gnu.org/copyleft/gpl.html
26
  */
27
 
28
+ // GENERAL DEFINITIONS
29
  define( 'EL_URL', plugin_dir_url( __FILE__ ) );
30
  define( 'EL_PATH', plugin_dir_path( __FILE__ ) );
31
 
32
 
33
+ // MAIN PLUGIN CLASS
34
+ class event_list {
35
+ private $shortcode;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ /**
38
+ * Constructor:
39
+ * Initializes the plugin.
40
+ */
41
+ public function __construct() {
42
+ $this->shortcode = NULL;
43
 
44
+ // ALWAYS:
45
+ // Register shortcodes
46
+ add_shortcode( 'event-list', array( &$this, 'shortcode_event_list' ) );
47
+ // Register widgets
48
+ add_action( 'widgets_init', array( &$this, 'widget_init' ) );
49
+
50
+ // ADMIN PAGE:
51
+ if ( is_admin() ) {
52
+ // Include required php-files and initialize required objects
53
+ require_once( 'php/admin.php' );
54
+ $admin = new el_admin();
55
+ // Register actions
56
+ add_action( 'admin_menu', array( &$admin, 'register_pages' ) );
57
+ add_action( 'plugins_loaded', array( &$this, 'db_upgrade_check' ) );
58
+ }
59
+
60
+ // FRONT PAGE:
61
+ else {
62
+ // Register actions
63
+ add_action('wp_print_styles', array( &$this, 'print_styles' ) );
64
+ }
65
+ } // end constructor
66
+
67
+ public function shortcode_event_list( $atts ) {
68
+ if( NULL == $this->shortcode ) {
69
+ require_once( 'php/sc_event-list.php' );
70
+ $this->shortcode = sc_event_list::get_instance();
71
+ }
72
+ return $this->shortcode->show_html( $atts );
73
+ }
74
+
75
+ public function widget_init() {
76
+ // Widget "event-list"
77
+ require_once( 'php/event-list_widget.php' );
78
+ return register_widget( 'event_list_widget' );
79
+ }
80
+
81
+ public function print_styles() {
82
+ wp_register_style('event-list_css', EL_URL.'css/event-list.css');
83
+ wp_enqueue_style( 'event-list_css');
84
+ }
85
+
86
+ public function db_upgrade_check() {
87
+ require_once( 'php/db.php' );
88
+ $db = el_db::get_instance();
89
+ $db->upgrade_check();
90
+ }
91
+ } // end class linkview
92
+
93
+
94
+ // create a class instance
95
+ $event_list = new event_list();
96
  ?>
php/admin.php CHANGED
@@ -1,23 +1,49 @@
1
  <?php
2
  //require_once( EL_PATH.'php/options.php' );
3
  require_once( EL_PATH.'php/db.php' );
 
4
  require_once( EL_PATH.'php/admin_event_table.php' );
5
 
6
  // This class handles all available admin pages
7
  class el_admin {
8
- private static $event_action = false;
9
- private static $event_action_error = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  // show the main admin page as a submenu of "Comments"
12
- public static function show_main() {
13
  if ( !current_user_can( 'edit_posts' ) ) {
14
  wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
15
  }
16
  $action = '';
17
  // is there POST data an event was edited must be updated
18
  if( !empty( $_POST ) ) {
19
- self::$event_action_error = !el_db::update_event( $_POST );
20
- self::$event_action = isset( $_POST['id'] ) ? 'modified' : 'added';
21
  }
22
  // get action
23
  if( isset( $_GET['action'] ) ) {
@@ -25,13 +51,13 @@ class el_admin {
25
  }
26
  // if an event should be edited a different page must be displayed
27
  if( $action === 'edit' ) {
28
- self::show_edit();
29
  return;
30
  }
31
  // delete events if required
32
  if( $action === 'delete' && isset( $_GET['id'] ) ) {
33
- self::$event_action_error = !el_db::delete_events( $_GET['id'] );
34
- self::$event_action = 'deleted';
35
  }
36
  // automatically set order of table to date, if no manual sorting is set
37
  if( !isset( $_GET['orderby'] ) ) {
@@ -44,34 +70,34 @@ class el_admin {
44
  <div class="wrap">
45
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Events <a href="?page=el_admin_new" class="add-new-h2">Add New</a></h2>';
46
  // added messages if required
47
- $out .= self::show_messages();
48
  // list event table
49
- $out .= self::list_events();
50
  $out .= '</div>';
51
  echo $out;
52
  }
53
 
54
- public static function show_new() {
55
  $out = '<div class="wrap">
56
  <div class="wrap nosubsub" style="padding-bottom:15px">
57
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Add New Event</h2>
58
  </div>';
59
- $out .= self::edit_event();
60
  $out .= '</div>';
61
  echo $out;
62
  }
63
 
64
- private static function show_edit() {
65
  $out = '<div class="wrap">
66
  <div class="wrap nosubsub" style="padding-bottom:15px">
67
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Edit Event</h2>
68
  </div>';
69
- $out .= self::edit_event();
70
  $out .= '</div>';
71
  echo $out;
72
  }
73
 
74
- public static function show_settings () {
75
  if (!current_user_can('manage_options')) {
76
  wp_die( __('You do not have sufficient permissions to access this page.') );
77
  }
@@ -137,42 +163,50 @@ class el_admin {
137
  echo $out;
138
  }
139
 
140
- public static function show_about() {
141
  $out = '<div class="wrap">
142
  <div class="wrap nosubsub" style="padding-bottom:15px">
143
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>About Event List</h2>
144
  </div>
145
- <h3>Instructions</h3>
146
- <p>Add your events <a href="admin.php?page=el_admin_main">here</a>.</p>
147
- <p>To show the events on your site just place this short code on any Page or Post:</p>
148
- <pre>[event-list]</pre>';
149
- // <p>The plugin includes a widget to place your events in a sidebar.</p>
150
- $out .= '<p>Be sure to also check out the <a href="admin.php?page=el_admin_settings">settings page</a> to get Event List behaving just the way you want.</p>
 
 
 
151
  </div>';
 
152
  echo $out;
153
  }
154
 
155
- public static function embed_admin_main_scripts() {
156
  // If edit event is selected switch to embed admin_new
157
  if( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) {
158
- self::embed_admin_new_scripts();
159
  }
160
  else {
161
  // Proceed with embedding for admin_main
162
  wp_enqueue_script( 'eventlist_admin_main_js', EL_URL.'js/admin_main.js' );
163
- wp_enqueue_style( 'eventlist_admin_main_css', EL_URL.'css/admin_main.css' );
164
  }
165
  }
166
 
167
- public static function embed_admin_new_scripts() {
168
  wp_print_scripts( 'jquery-ui-datepicker' );
169
  wp_enqueue_script( 'eventlist_admin_new_js', EL_URL.'js/admin_new.js' );
170
- wp_enqueue_style( 'eventlist_admin_new_css', EL_URL.'css/admin_new.css' );
 
 
 
 
171
  }
172
 
173
- private static function list_events() {
174
  // show calendar navigation
175
- $out = el_db::html_calendar_nav();
176
  // set date range of events being displayed
177
  $date_range = 'upcoming';
178
  if( isset( $_GET['ytd'] ) && is_numeric( $_GET['ytd'] ) ) {
@@ -193,12 +227,12 @@ class el_admin {
193
  return $out;
194
  }
195
 
196
- private static function edit_event() {
197
  $date_format = __( 'Y/m/d' ); // similar date format than in list tables (e.g. post, pages, media)
198
  $edit = false;
199
  if( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
200
  // existing event
201
- $event = el_db::get_event( $_GET['id'] );
202
  if( isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) {
203
  // editing of an existing event, if not it would be copy of an existing event
204
  $edit = true;
@@ -214,7 +248,7 @@ class el_admin {
214
 
215
  // Add required data for javascript in a hidden field
216
  $json = json_encode( array( 'el_url' => EL_URL,
217
- 'el_date_format' => self::datepicker_format( $date_format ) ) );
218
  $out = "<input type='hidden' id='json_for_js' value='".$json."' />";
219
  $out .= '<form method="POST" action="?page=el_admin_main">';
220
  if( true === $edit ) {
@@ -260,11 +294,39 @@ class el_admin {
260
  return $out;
261
  }
262
 
263
- private static function show_messages() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  $out = '';
265
  // event added
266
- if( 'added' === self::$event_action ) {
267
- if( false === self::$event_action_error ) {
268
  $out .= '<div id="message" class="updated below-h2"><p><strong>New Event "'.$_POST['title'].'" was added.</strong></p></div>';
269
  }
270
  else {
@@ -272,8 +334,8 @@ class el_admin {
272
  }
273
  }
274
  // event modified
275
- elseif( 'modified' === self::$event_action ) {
276
- if( false === self::$event_action_error ) {
277
  $out .= '<div id="message" class="updated below-h2"><p><strong>Event "'.$_POST['title'].'" (id: '.$_POST['id'].') was modified.</strong></p></div>';
278
  }
279
  else {
@@ -281,13 +343,13 @@ class el_admin {
281
  }
282
  }
283
  // event deleted
284
- elseif( 'deleted' === self::$event_action ) {
285
  $num_deleted = count( explode( ',', $_GET['id'] ) );
286
  $plural = '';
287
  if( $num_deleted > 1 ) {
288
  $plural = 's';
289
  }
290
- if( false === self::$event_action_error ) {
291
  $out .= '<div id="message" class="updated below-h2"><p><strong>'.$num_deleted.' Event'.$plural.' deleted (id'.$plural.': '.$_GET['id'].').</strong></p></div>';
292
  }
293
  else {
@@ -298,13 +360,13 @@ class el_admin {
298
  }
299
 
300
  // TODO: Function "create_tabs" not required yet, can be removed probably
301
- private static function create_tabs( $current = 'general' ) {
302
  $tabs = array( 'general' => 'General settings', 'comment_list' => 'Comment-list settings', 'comment_form' => 'Comment-form settings',
303
  'comment_form_html' => 'Comment-form html code', 'comment_html' => 'Comment html code' );
304
  $out = '<h3 class="nav-tab-wrapper">';
305
  foreach( $tabs as $tab => $name ){
306
  $class = ( $tab == $current ) ? ' nav-tab-active' : '';
307
- $out .= "<a class='nav-tab$class' href='?page=cgb_admin_main&tab=$tab'>$name</a>";
308
  }
309
  $out .= '</h3>';
310
  return $out;
@@ -313,9 +375,9 @@ class el_admin {
313
  // $desc_pos specifies where the descpription will be displayed.
314
  // available options: 'right' ... description will be displayed on the right side of the option (standard value)
315
  // 'newline' ... description will be displayed below the option
316
- private static function show_options( $section, $desc_pos='right' ) {
317
  $out = '';
318
- foreach( self::$options as $oname => $o ) {
319
  if( $o['section'] == $section ) {
320
  $out .= '
321
  <tr valign="top">
@@ -327,13 +389,13 @@ class el_admin {
327
  <td>';
328
  switch( $o['type'] ) {
329
  case 'checkbox':
330
- $out .= cgb_admin::show_checkbox( $oname, self::get( $oname ), $o['caption'] );
331
  break;
332
  case 'text':
333
- $out .= cgb_admin::show_text( $oname, self::get( $oname ) );
334
  break;
335
  case 'textarea':
336
- $out .= cgb_admin::show_textarea( $oname, self::get( $oname ) );
337
  break;
338
  }
339
  $out .= '
@@ -356,7 +418,7 @@ class el_admin {
356
  return $out;
357
  }
358
 
359
- private static function show_checkbox( $name, $value, $caption ) {
360
  $out = '
361
  <label for="'.$name.'">
362
  <input name="'.$name.'" type="checkbox" id="'.$name.'" value="1"';
@@ -369,25 +431,63 @@ class el_admin {
369
  return $out;
370
  }
371
 
372
- private static function show_text( $name, $value ) {
373
  $out = '
374
  <input name="'.$name.'" type="text" id="'.$name.'" value="'.$value.'" />';
375
  return $out;
376
  }
377
 
378
- private static function show_textarea( $name, $value ) {
379
  $out = '
380
  <textarea name="'.$name.'" id="'.$name.'" rows="20" class="large-text code">'.$value.'</textarea>';
381
  return $out;
382
  }
383
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  /**
385
  * Convert a date format to a jQuery UI DatePicker format
386
  *
387
  * @param string $format a date format
388
  * @return string
389
  */
390
- private static function datepicker_format( $format ) {
391
  $chars = array(
392
  // Day
393
  'd' => 'dd', 'j' => 'd', 'l' => 'DD', 'D' => 'D',
1
  <?php
2
  //require_once( EL_PATH.'php/options.php' );
3
  require_once( EL_PATH.'php/db.php' );
4
+ require_once( EL_PATH.'php/sc_event-list.php' );
5
  require_once( EL_PATH.'php/admin_event_table.php' );
6
 
7
  // This class handles all available admin pages
8
  class el_admin {
9
+ private $db;
10
+ private $options;
11
+ private $shortcode;
12
+ private $event_action = false;
13
+ private $event_action_error = false;
14
+
15
+ public function __construct() {
16
+ $this->db = el_db::get_instance();
17
+ //$this->options = &el_options::get_instance();
18
+ $this->shortcode = &sc_event_list::get_instance();
19
+ $this->event_action = null;
20
+ $this->event_action_error = null;
21
+ }
22
+
23
+ /**
24
+ * Add and register all admin pages in the admin menu
25
+ */
26
+ public function register_pages() {
27
+ add_menu_page( 'Event List', 'Event List', 'edit_posts', 'el_admin_main', array( &$this, 'show_main' ) );
28
+ $page = add_submenu_page( 'el_admin_main', 'Events', 'All Events', 'edit_posts', 'el_admin_main', array( &$this, 'show_main' ) );
29
+ add_action( 'admin_print_scripts-'.$page, array( &$this, 'embed_admin_main_scripts' ) );
30
+ $page = add_submenu_page( 'el_admin_main', 'Add New Event', 'Add New', 'edit_posts', 'el_admin_new', array( &$this, 'show_new' ) );
31
+ add_action( 'admin_print_scripts-'.$page, array( &$this, 'embed_admin_new_scripts' ) );
32
+ add_submenu_page( 'el_admin_main', 'Event List Settings', 'Settings', 'manage_options', 'el_admin_settings', array( &$this, 'show_settings' ) );
33
+ $page = add_submenu_page( 'el_admin_main', 'About Event List', 'About', 'manage_options', 'el_admin_about', array( &$this, 'show_about' ) );
34
+ add_action( 'admin_print_scripts-'.$page, array( &$this, 'embed_admin_about_scripts' ) );
35
+ }
36
 
37
  // show the main admin page as a submenu of "Comments"
38
+ public function show_main() {
39
  if ( !current_user_can( 'edit_posts' ) ) {
40
  wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
41
  }
42
  $action = '';
43
  // is there POST data an event was edited must be updated
44
  if( !empty( $_POST ) ) {
45
+ $this->event_action_error = !$this->db->update_event( $_POST );
46
+ $this->event_action = isset( $_POST['id'] ) ? 'modified' : 'added';
47
  }
48
  // get action
49
  if( isset( $_GET['action'] ) ) {
51
  }
52
  // if an event should be edited a different page must be displayed
53
  if( $action === 'edit' ) {
54
+ $this->show_edit();
55
  return;
56
  }
57
  // delete events if required
58
  if( $action === 'delete' && isset( $_GET['id'] ) ) {
59
+ $this->event_action_error = !$this->db->delete_events( $_GET['id'] );
60
+ $this->event_action = 'deleted';
61
  }
62
  // automatically set order of table to date, if no manual sorting is set
63
  if( !isset( $_GET['orderby'] ) ) {
70
  <div class="wrap">
71
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Events <a href="?page=el_admin_new" class="add-new-h2">Add New</a></h2>';
72
  // added messages if required
73
+ $out .= $this->show_messages();
74
  // list event table
75
+ $out .= $this->list_events();
76
  $out .= '</div>';
77
  echo $out;
78
  }
79
 
80
+ public function show_new() {
81
  $out = '<div class="wrap">
82
  <div class="wrap nosubsub" style="padding-bottom:15px">
83
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Add New Event</h2>
84
  </div>';
85
+ $out .= $this->edit_event();
86
  $out .= '</div>';
87
  echo $out;
88
  }
89
 
90
+ private function show_edit() {
91
  $out = '<div class="wrap">
92
  <div class="wrap nosubsub" style="padding-bottom:15px">
93
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>Edit Event</h2>
94
  </div>';
95
+ $out .= $this->edit_event();
96
  $out .= '</div>';
97
  echo $out;
98
  }
99
 
100
+ public function show_settings () {
101
  if (!current_user_can('manage_options')) {
102
  wp_die( __('You do not have sufficient permissions to access this page.') );
103
  }
163
  echo $out;
164
  }
165
 
166
+ public function show_about() {
167
  $out = '<div class="wrap">
168
  <div class="wrap nosubsub" style="padding-bottom:15px">
169
  <div id="icon-edit-pages" class="icon32"><br /></div><h2>About Event List</h2>
170
  </div>
171
+ <h3>Help and Instructions</h3>
172
+ <p>You can manage your events <a href="admin.php?page=el_admin_main">here</a>.</p>
173
+ <p>To show the events on your site you have two possibilities:
174
+ <ul class="el-show-event-options"><li>you can place the <strong>shortcode</strong> <code>[event-list]</code> on any page or post</li>
175
+ <li>you can add the <strong>widget</strong> "Event List" in your sidebars</li></ul>
176
+ The the displayed events and their style can be modified with the available widget settings and the available attributes for the shortcode.<br />
177
+ A list of all available shortcode attributes with their description can be found below.
178
+ </p>
179
+ <p>Be sure to also check the <a href="admin.php?page=el_admin_settings">settings page</a> to get Event List behaving just the way you want.</p>
180
  </div>';
181
+ $out .= $this->html_atts();
182
  echo $out;
183
  }
184
 
185
+ public function embed_admin_main_scripts() {
186
  // If edit event is selected switch to embed admin_new
187
  if( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) {
188
+ $this->embed_admin_new_scripts();
189
  }
190
  else {
191
  // Proceed with embedding for admin_main
192
  wp_enqueue_script( 'eventlist_admin_main_js', EL_URL.'js/admin_main.js' );
193
+ wp_enqueue_style( 'eventlist_admin_main', EL_URL.'css/admin_main.css' );
194
  }
195
  }
196
 
197
+ public function embed_admin_new_scripts() {
198
  wp_print_scripts( 'jquery-ui-datepicker' );
199
  wp_enqueue_script( 'eventlist_admin_new_js', EL_URL.'js/admin_new.js' );
200
+ wp_enqueue_style( 'eventlist_admin_new', EL_URL.'css/admin_new.css' );
201
+ }
202
+
203
+ public function embed_admin_about_scripts() {
204
+ wp_enqueue_style( 'eventlist_admin_about', EL_URL.'css/admin_about.css' );
205
  }
206
 
207
+ private function list_events() {
208
  // show calendar navigation
209
+ $out = $this->show_calendar_nav();
210
  // set date range of events being displayed
211
  $date_range = 'upcoming';
212
  if( isset( $_GET['ytd'] ) && is_numeric( $_GET['ytd'] ) ) {
227
  return $out;
228
  }
229
 
230
+ private function edit_event() {
231
  $date_format = __( 'Y/m/d' ); // similar date format than in list tables (e.g. post, pages, media)
232
  $edit = false;
233
  if( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
234
  // existing event
235
+ $event = $this->db->get_event( $_GET['id'] );
236
  if( isset( $_GET['action'] ) && $_GET['action'] === 'edit' ) {
237
  // editing of an existing event, if not it would be copy of an existing event
238
  $edit = true;
248
 
249
  // Add required data for javascript in a hidden field
250
  $json = json_encode( array( 'el_url' => EL_URL,
251
+ 'el_date_format' => $this->datepicker_format( $date_format ) ) );
252
  $out = "<input type='hidden' id='json_for_js' value='".$json."' />";
253
  $out .= '<form method="POST" action="?page=el_admin_main">';
254
  if( true === $edit ) {
294
  return $out;
295
  }
296
 
297
+ private function show_calendar_nav() {
298
+ $first_year = $this->db->get_event_date( 'first' );
299
+ $last_year = $this->db->get_event_date( 'last' );
300
+
301
+ // Calendar Navigation
302
+ if( true === is_admin() ) {
303
+ $url = "?page=el_admin_main";
304
+ $out = '<ul class="subsubsub">';
305
+ if( isset( $_GET['ytd'] ) || isset( $_GET['event_id'] ) ) {
306
+ $out .= '<li class="upcoming"><a href="'.$url.'">Upcoming</a></li>';
307
+ }
308
+ else {
309
+ $out .= '<li class="upcoming"><a class="current" href="'.$url.'">Upcoming</a></li>';
310
+ }
311
+ for( $year=$last_year; $year>=$first_year; $year-- ) {
312
+ $out .= ' | ';
313
+ if( isset( $_GET['ytd'] ) && $year == $_GET['ytd'] ) {
314
+ $out .= '<li class="year"><a class="current" href="'.$url.'ytd='.$year.'">'.$year.'</a></li>';
315
+ }
316
+ else {
317
+ $out .= '<li class="year"><a href="'.$url.'&amp;ytd='.$year.'">'.$year.'</a></li>';
318
+ }
319
+ }
320
+ $out .= '</ul><br />';
321
+ }
322
+ return $out;
323
+ }
324
+
325
+ private function show_messages() {
326
  $out = '';
327
  // event added
328
+ if( 'added' === $this->event_action ) {
329
+ if( false === $this->event_action_error ) {
330
  $out .= '<div id="message" class="updated below-h2"><p><strong>New Event "'.$_POST['title'].'" was added.</strong></p></div>';
331
  }
332
  else {
334
  }
335
  }
336
  // event modified
337
+ elseif( 'modified' === $this->event_action ) {
338
+ if( false === $this->event_action_error ) {
339
  $out .= '<div id="message" class="updated below-h2"><p><strong>Event "'.$_POST['title'].'" (id: '.$_POST['id'].') was modified.</strong></p></div>';
340
  }
341
  else {
343
  }
344
  }
345
  // event deleted
346
+ elseif( 'deleted' === $this->event_action ) {
347
  $num_deleted = count( explode( ',', $_GET['id'] ) );
348
  $plural = '';
349
  if( $num_deleted > 1 ) {
350
  $plural = 's';
351
  }
352
+ if( false === $this->event_action_error ) {
353
  $out .= '<div id="message" class="updated below-h2"><p><strong>'.$num_deleted.' Event'.$plural.' deleted (id'.$plural.': '.$_GET['id'].').</strong></p></div>';
354
  }
355
  else {
360
  }
361
 
362
  // TODO: Function "create_tabs" not required yet, can be removed probably
363
+ private function create_tabs( $current = 'general' ) {
364
  $tabs = array( 'general' => 'General settings', 'comment_list' => 'Comment-list settings', 'comment_form' => 'Comment-form settings',
365
  'comment_form_html' => 'Comment-form html code', 'comment_html' => 'Comment html code' );
366
  $out = '<h3 class="nav-tab-wrapper">';
367
  foreach( $tabs as $tab => $name ){
368
  $class = ( $tab == $current ) ? ' nav-tab-active' : '';
369
+ $out .= "<a class='nav-tab$class' href='?page=cgb_admin_main&amp;tab=$tab'>$name</a>";
370
  }
371
  $out .= '</h3>';
372
  return $out;
375
  // $desc_pos specifies where the descpription will be displayed.
376
  // available options: 'right' ... description will be displayed on the right side of the option (standard value)
377
  // 'newline' ... description will be displayed below the option
378
+ private function show_options( $section, $desc_pos='right' ) {
379
  $out = '';
380
+ foreach( $this->options as $oname => $o ) {
381
  if( $o['section'] == $section ) {
382
  $out .= '
383
  <tr valign="top">
389
  <td>';
390
  switch( $o['type'] ) {
391
  case 'checkbox':
392
+ $out .= cgb_admin::show_checkbox( $oname, $this->get( $oname ), $o['caption'] );
393
  break;
394
  case 'text':
395
+ $out .= cgb_admin::show_text( $oname, $this->get( $oname ) );
396
  break;
397
  case 'textarea':
398
+ $out .= cgb_admin::show_textarea( $oname, $this->get( $oname ) );
399
  break;
400
  }
401
  $out .= '
418
  return $out;
419
  }
420
 
421
+ private function show_checkbox( $name, $value, $caption ) {
422
  $out = '
423
  <label for="'.$name.'">
424
  <input name="'.$name.'" type="checkbox" id="'.$name.'" value="1"';
431
  return $out;
432
  }
433
 
434
+ private function show_text( $name, $value ) {
435
  $out = '
436
  <input name="'.$name.'" type="text" id="'.$name.'" value="'.$value.'" />';
437
  return $out;
438
  }
439
 
440
+ private function show_textarea( $name, $value ) {
441
  $out = '
442
  <textarea name="'.$name.'" id="'.$name.'" rows="20" class="large-text code">'.$value.'</textarea>';
443
  return $out;
444
  }
445
 
446
+ private function html_atts() {
447
+ $out = '
448
+ <h3 class="el-headline">Available Shortcode Attributes</h3>
449
+ <div>
450
+ You have the possibility to modify the output if you add some of the following attributes to the shortcode.<br />
451
+ You can combine as much attributes as you want. E.g.the shortcode including the attributes "num_events" and "show_nav" would looks like this:
452
+ <p><code>[event-list num_events=10 show_nav=0]</code></p>
453
+ <p>Below you can find a list of all supported attributes with their descriptions and available options:</p>';
454
+ $out .= $this->html_atts_table();
455
+ $out .= '
456
+ </div>';
457
+ return $out;
458
+ }
459
+
460
+ private function html_atts_table() {
461
+ $out = '
462
+ <table class="el-atts-table">
463
+ <tr>
464
+ <th class="el-atts-table-name">Attribute name</th>
465
+ <th class="el-atts-table-options">Value options</th>
466
+ <th class="el-atts-table-default">Default value</th>
467
+ <th class="el-atts-table-desc">Description</th>
468
+ </tr>';
469
+ $atts = $this->shortcode->get_atts();
470
+ foreach( $atts as $aname => $a ) {
471
+ $out .= '
472
+ <tr>
473
+ <td>'.$aname.'</td>
474
+ <td>'.$a['val'].'</td>
475
+ <td>'.$a['std_val'].'</td>
476
+ <td>'.$a['desc'].'</td>
477
+ </tr>';
478
+ }
479
+ $out .= '
480
+ </table>';
481
+ return $out;
482
+ }
483
+
484
  /**
485
  * Convert a date format to a jQuery UI DatePicker format
486
  *
487
  * @param string $format a date format
488
  * @return string
489
  */
490
+ private function datepicker_format( $format ) {
491
  $chars = array(
492
  // Day
493
  'd' => 'dd', 'j' => 'd', 'l' => 'DD', 'D' => 'D',
php/admin_event_table.php CHANGED
@@ -6,7 +6,10 @@ if(!class_exists('WP_List_Table')){
6
  require_once( EL_PATH.'php/db.php' );
7
 
8
  class Admin_Event_Table extends WP_List_Table {
 
 
9
  public function __construct() {
 
10
  global $status, $page;
11
  //Set parent defaults
12
  parent::__construct( array(
@@ -29,7 +32,7 @@ class Admin_Event_Table extends WP_List_Table {
29
  case 'date' :
30
  return $this->format_event_date( $item->start_date, $item->end_date, $item->time );
31
  case 'details' :
32
- return '<span title="'.$item->details.'">'.$this->truncate( 80, $item->details ).'</span>';
33
  case 'pub_user' :
34
  return get_userdata( $item->pub_user )->user_login;
35
  case 'pub_date' :
@@ -50,8 +53,8 @@ class Admin_Event_Table extends WP_List_Table {
50
  protected function column_title($item) {
51
  //Prepare Columns
52
  $actions = array(
53
- 'edit' => '<a href="?page='.$_REQUEST['page'].'&id='.$item->id.'&action=edit">Edit</a>',
54
- 'duplicate' => '<a href="?page=el_admin_new&id='.$item->id.'&action=copy">Duplicate</a>',
55
  'delete' => '<a href="#" onClick="eventlist_deleteEvent('.$item->id.');return false;">Delete</a>'
56
  );
57
 
@@ -139,7 +142,6 @@ class Admin_Event_Table extends WP_List_Table {
139
  * @see $this->prepare_items()
140
  ***************************************************************************/
141
  private function process_bulk_action() {
142
- // TODO: bulk action must be integrated
143
  //Detect when a bulk action is being triggered...
144
  if( 'delete_bulk'===$this->current_action() ) {
145
  // Show confirmation window before deleting
@@ -216,7 +218,7 @@ class Admin_Event_Table extends WP_List_Table {
216
  break;
217
  }
218
  // get and return events in the correct order
219
- return el_db::get_events( $date_range, $sort_array );
220
  }
221
 
222
  /** ************************************************************************
@@ -247,7 +249,6 @@ class Admin_Event_Table extends WP_List_Table {
247
  // similar output than for post or pages
248
  $timestamp = strtotime( $pub_date );
249
  $time_diff = time() - $timestamp;
250
- error_log( "time_diff: ".$time_diff );
251
  if( $time_diff >= 0 && $time_diff < 24*60*60 ) {
252
  $date = sprintf( __( '%s ago' ), human_time_diff( $timestamp ) );
253
  }
6
  require_once( EL_PATH.'php/db.php' );
7
 
8
  class Admin_Event_Table extends WP_List_Table {
9
+ private $db;
10
+
11
  public function __construct() {
12
+ $this->db = el_db::get_instance();
13
  global $status, $page;
14
  //Set parent defaults
15
  parent::__construct( array(
32
  case 'date' :
33
  return $this->format_event_date( $item->start_date, $item->end_date, $item->time );
34
  case 'details' :
35
+ return '<div title="'.$item->details.'">'.$this->truncate( 80, $item->details ).'</div>';
36
  case 'pub_user' :
37
  return get_userdata( $item->pub_user )->user_login;
38
  case 'pub_date' :
53
  protected function column_title($item) {
54
  //Prepare Columns
55
  $actions = array(
56
+ 'edit' => '<a href="?page='.$_REQUEST['page'].'&amp;id='.$item->id.'&amp;action=edit">Edit</a>',
57
+ 'duplicate' => '<a href="?page=el_admin_new&amp;id='.$item->id.'&amp;action=copy">Duplicate</a>',
58
  'delete' => '<a href="#" onClick="eventlist_deleteEvent('.$item->id.');return false;">Delete</a>'
59
  );
60
 
142
  * @see $this->prepare_items()
143
  ***************************************************************************/
144
  private function process_bulk_action() {
 
145
  //Detect when a bulk action is being triggered...
146
  if( 'delete_bulk'===$this->current_action() ) {
147
  // Show confirmation window before deleting
218
  break;
219
  }
220
  // get and return events in the correct order
221
+ return $this->db->get_events( $date_range, 0, $sort_array );
222
  }
223
 
224
  /** ************************************************************************
249
  // similar output than for post or pages
250
  $timestamp = strtotime( $pub_date );
251
  $time_diff = time() - $timestamp;
 
252
  if( $time_diff >= 0 && $time_diff < 24*60*60 ) {
253
  $date = sprintf( __( '%s ago' ), human_time_diff( $timestamp ) );
254
  }
php/db.php CHANGED
@@ -5,12 +5,30 @@
5
  class el_db {
6
  const VERSION = "0.1";
7
  const TABLE_NAME = "event_list";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  // UPDATE DB
10
- public static function update_check() {
11
  // TODO: added version checking
12
  // if( el_options::get( 'el_db_version' ) != self::VERSION) {
13
- $sql = 'CREATE TABLE '.self::table_name().' (
14
  id int(11) NOT NULL AUTO_INCREMENT,
15
  pub_user bigint(20) NOT NULL,
16
  pub_date datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
@@ -31,21 +49,16 @@ class el_db {
31
  // }
32
  }
33
 
34
- public static function table_name() {
35
- global $wpdb;
36
- return $wpdb->prefix.self::TABLE_NAME;
37
- }
38
-
39
- public static function get_events( $date_range='all', $sort_array=array( 'start_date ASC', 'time ASC', 'end_date ASC') ) {
40
  global $wpdb;
41
 
42
  // set date for data base query
43
- if( $date_range === 'all' ) {
44
  // get all events
45
  $range_start = '0000-01-01';
46
  $range_end = '9999-12-31';
47
  }
48
- elseif( $date_range === 'upcoming' ) {
49
  // get only events in the future
50
  $range_start = date( 'Y-m-d' );
51
  $range_end = '9999-12-31';
@@ -54,31 +67,34 @@ class el_db {
54
  $range_start = $date_range.'-01-01';
55
  $range_end = $date_range.'-12-31';
56
  }
57
- $sql = 'SELECT * FROM '.self::table_name().' WHERE (end_date >= "'.$range_start.'" AND start_date <= "'.$range_end.'") ORDER BY '.implode( ', ', $sort_array );
 
 
 
58
  return $wpdb->get_results( $sql );
59
  }
60
 
61
- public static function get_event( $id ) {
62
  global $wpdb;
63
- $sql = 'SELECT * FROM '.self::table_name().' WHERE id = '.$id.' LIMIT 1';
64
  return $wpdb->get_row( $sql );
65
  }
66
 
67
- public static function get_event_date( $event ) {
68
  global $wpdb;
69
  if( $event === 'first' ) {
70
  // first year
71
  $search_date = 'start_date';
72
- $sql = 'SELECT DISTINCT '.$search_date.' FROM '.self::table_name().' WHERE '.$search_date.' != "0000-00-00" ORDER BY '.$search_date.' ASC LIMIT 1';
73
  }
74
  else {
75
  // last year
76
  $search_date = 'end_date';
77
- $sql = 'SELECT DISTINCT '.$search_date.' FROM '.self::table_name().' WHERE '.$search_date.' != "0000-00-00" ORDER BY '.$search_date.' DESC LIMIT 1';
78
  }
79
  $date = $wpdb->get_results($sql, ARRAY_A);
80
  if( !empty( $date ) ) {
81
- $date = self::extract_date( $date[0][$search_date],'Y');
82
  }
83
  else {
84
  $date = date("Y");
@@ -86,7 +102,7 @@ class el_db {
86
  return $date;
87
  }
88
 
89
- public static function update_event( $event_data ) {
90
  global $wpdb;
91
  // prepare and validate sqldata
92
  $sqldata = array();
@@ -97,13 +113,13 @@ class el_db {
97
  //start_date
98
  if( !isset( $event_data['start_date']) ) { return false; }
99
  $start_timestamp = 0;
100
- $sqldata['start_date'] = self::extract_date( $event_data['start_date'], "Y-m-d", $start_timestamp );
101
  if( false === $sqldata['start_date'] ) { return false; }
102
  //end_date
103
  if( !isset( $event_data['end_date']) ) { return false; }
104
  if( isset( $event_data['multiday'] ) && "1" === $event_data['multiday'] ) {
105
  $end_timestamp = 0;
106
- $sqldata['end_date'] = self::extract_date( $event_data['end_date'], "Y-m-d", $end_timestamp );
107
  if( false === $sqldata['end_date'] ) { $sqldata['end_date'] = $sqldata['start_date']; }
108
  elseif( $end_timestamp < $start_timestamp ) { $sqldata['end_date'] = $sqldata['start_date']; }
109
  }
@@ -126,18 +142,18 @@ class el_db {
126
  $sqltypes = array( '%s', '%s', '%s', '%s', '%s', '%s', '%s' );
127
 
128
  if( isset( $event_data['id'] ) ) { // update event
129
- $wpdb->update( self::table_name(), $sqldata, array( 'id' => $event_data['id'] ), $sqltypes );
130
  }
131
  else { // new event
132
- $wpdb->insert( self::table_name(), $sqldata, $sqltypes );
133
  }
134
  return true;
135
  }
136
 
137
- public static function delete_events( $event_ids ) {
138
  global $wpdb;
139
  // sql query
140
- $num_deleted = (int) $wpdb->query( $wpdb->prepare( 'DELETE FROM '.self::table_name().' WHERE id IN ('.$event_ids.')' ) );
141
  if( $num_deleted == count( explode( ',', $event_ids ) ) ) {
142
  return true;
143
  }
@@ -146,7 +162,7 @@ class el_db {
146
  }
147
  }
148
 
149
- public static function extract_date( $datestring, $ret_format, &$ret_timestamp=NULL, &$ret_datearray=NULL ) {
150
  $date_array = date_parse( $datestring );
151
  if( !empty( $date_array['errors']) ) {
152
  return false;
@@ -163,67 +179,5 @@ class el_db {
163
  }
164
  return date( $ret_format, $timestamp );
165
  }
166
-
167
- public static function html_calendar_nav() {
168
- $first_year = self::get_event_date( 'first' );
169
- $last_year = self::get_event_date( 'last' );
170
-
171
- // Calendar Navigation
172
- if( true === is_admin() ) {
173
- $url = "?page=el_admin_main";
174
- $out = '<ul class="subsubsub">';
175
- if( isset( $_GET['ytd'] ) || isset( $_GET['event_id'] ) ) {
176
- $out .= '<li class="upcoming"><a href="'.$url.'">Upcoming</a></li>';
177
- }
178
- else {
179
- $out .= '<li class="upcoming"><a class="current" href="'.$url.'">Upcoming</a></li>';
180
- }
181
- for( $year=$last_year; $year>=$first_year; $year-- ) {
182
- $out .= ' | ';
183
- if( isset( $_GET['ytd'] ) && $year == $_GET['ytd'] ) {
184
- $out .= '<li class="year"><a class="current" href="'.$url.'&ytd='.$year.'">'.$year.'</a></li>';
185
- }
186
- else {
187
- $out .= '<li class="year"><a href="'.$url.'&ytd='.$year.'">'.$year.'</a></li>';
188
- }
189
- }
190
- $out .= '</ul><br />';
191
- }
192
- else {
193
- if( get_option( 'permalink_structure' ) ) {
194
- $url = "?";
195
- }
196
- else {
197
- $existing = "?";
198
- foreach( $_GET as $k => $v ) {
199
- if( $k != "ytd" && $k != "event_id" ) $existing .= $k . "=" . $v . "&";
200
- }
201
- $url = $existing;
202
- }
203
- $out = '<div class="subsubsub">';
204
- if( isset( $_GET['ytd'] ) || isset( $_GET['event_id'] ) ) {
205
- $out .= '<a href="'.$url.'">Upcoming</a>';
206
- }
207
- else {
208
- $out .= '<strong>Upcoming</strong>';
209
- }
210
- for( $year=$last_year; $year>=$first_year; $year-- ) {
211
- $out .= ' | ';
212
- if( isset( $_GET['ytd'] ) && $year == $_GET['ytd'] ) {
213
- $out .= '<strong>'.$year.'</strong>';
214
- }
215
- else {
216
- $out .= '<a href="'.$url.'ytd='.$year.'">'.$year.'</a>';
217
- }
218
- }
219
- $out .= '</div><br />';
220
- }
221
-
222
- // Title (only if event details are viewed)
223
- if( isset( $_GET['event_id'] ) ) {
224
- $out .= '<h2>Event Information:</h2>';
225
- }
226
- return $out;
227
- }
228
  }
229
  ?>
5
  class el_db {
6
  const VERSION = "0.1";
7
  const TABLE_NAME = "event_list";
8
+ private static $instance;
9
+ private $table;
10
+ private $options;
11
+
12
+ public static function &get_instance() {
13
+ // Create class instance if required
14
+ if( !isset( self::$instance ) ) {
15
+ self::$instance = new el_db();
16
+ }
17
+ // Return class instance
18
+ return self::$instance;
19
+ }
20
+
21
+ private function __construct() {
22
+ global $wpdb;
23
+ $this->table = $wpdb->prefix.self::TABLE_NAME;
24
+ //$this->options = &lv_options::get_instance();
25
+ }
26
 
27
  // UPDATE DB
28
+ public function upgrade_check() {
29
  // TODO: added version checking
30
  // if( el_options::get( 'el_db_version' ) != self::VERSION) {
31
+ $sql = 'CREATE TABLE '.$this->table.' (
32
  id int(11) NOT NULL AUTO_INCREMENT,
33
  pub_user bigint(20) NOT NULL,
34
  pub_date datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
49
  // }
50
  }
51
 
52
+ public function get_events( $date_range='all', $num_events=0, $sort_array=array( 'start_date ASC', 'time ASC', 'end_date ASC') ) {
 
 
 
 
 
53
  global $wpdb;
54
 
55
  // set date for data base query
56
+ if( 'all' === $date_range ) {
57
  // get all events
58
  $range_start = '0000-01-01';
59
  $range_end = '9999-12-31';
60
  }
61
+ elseif( 'upcoming' === $date_range ) {
62
  // get only events in the future
63
  $range_start = date( 'Y-m-d' );
64
  $range_end = '9999-12-31';
67
  $range_start = $date_range.'-01-01';
68
  $range_end = $date_range.'-12-31';
69
  }
70
+ $sql = 'SELECT * FROM '.$this->table.' WHERE (end_date >= "'.$range_start.'" AND start_date <= "'.$range_end.'") ORDER BY '.implode( ', ', $sort_array );
71
+ if( 'upcoming' === $date_range && is_numeric($num_events) && 0 < $num_events ) {
72
+ $sql .= ' LIMIT '.$num_events;
73
+ }
74
  return $wpdb->get_results( $sql );
75
  }
76
 
77
+ public function get_event( $id ) {
78
  global $wpdb;
79
+ $sql = 'SELECT * FROM '.$this->table.' WHERE id = '.$id.' LIMIT 1';
80
  return $wpdb->get_row( $sql );
81
  }
82
 
83
+ public function get_event_date( $event ) {
84
  global $wpdb;
85
  if( $event === 'first' ) {
86
  // first year
87
  $search_date = 'start_date';
88
+ $sql = 'SELECT DISTINCT '.$search_date.' FROM '.$this->table.' WHERE '.$search_date.' != "0000-00-00" ORDER BY '.$search_date.' ASC LIMIT 1';
89
  }
90
  else {
91
  // last year
92
  $search_date = 'end_date';
93
+ $sql = 'SELECT DISTINCT '.$search_date.' FROM '.$this->table.' WHERE '.$search_date.' != "0000-00-00" ORDER BY '.$search_date.' DESC LIMIT 1';
94
  }
95
  $date = $wpdb->get_results($sql, ARRAY_A);
96
  if( !empty( $date ) ) {
97
+ $date = $this->extract_date( $date[0][$search_date],'Y');
98
  }
99
  else {
100
  $date = date("Y");
102
  return $date;
103
  }
104
 
105
+ public function update_event( $event_data ) {
106
  global $wpdb;
107
  // prepare and validate sqldata
108
  $sqldata = array();
113
  //start_date
114
  if( !isset( $event_data['start_date']) ) { return false; }
115
  $start_timestamp = 0;
116
+ $sqldata['start_date'] = $this->extract_date( $event_data['start_date'], "Y-m-d", $start_timestamp );
117
  if( false === $sqldata['start_date'] ) { return false; }
118
  //end_date
119
  if( !isset( $event_data['end_date']) ) { return false; }
120
  if( isset( $event_data['multiday'] ) && "1" === $event_data['multiday'] ) {
121
  $end_timestamp = 0;
122
+ $sqldata['end_date'] = $this->extract_date( $event_data['end_date'], "Y-m-d", $end_timestamp );
123
  if( false === $sqldata['end_date'] ) { $sqldata['end_date'] = $sqldata['start_date']; }
124
  elseif( $end_timestamp < $start_timestamp ) { $sqldata['end_date'] = $sqldata['start_date']; }
125
  }
142
  $sqltypes = array( '%s', '%s', '%s', '%s', '%s', '%s', '%s' );
143
 
144
  if( isset( $event_data['id'] ) ) { // update event
145
+ $wpdb->update( $this->table, $sqldata, array( 'id' => $event_data['id'] ), $sqltypes );
146
  }
147
  else { // new event
148
+ $wpdb->insert( $this->table, $sqldata, $sqltypes );
149
  }
150
  return true;
151
  }
152
 
153
+ public function delete_events( $event_ids ) {
154
  global $wpdb;
155
  // sql query
156
+ $num_deleted = (int) $wpdb->query( $wpdb->prepare( 'DELETE FROM '.$this->table.' WHERE id IN ('.$event_ids.')' ) );
157
  if( $num_deleted == count( explode( ',', $event_ids ) ) ) {
158
  return true;
159
  }
162
  }
163
  }
164
 
165
+ public function extract_date( $datestring, $ret_format, &$ret_timestamp=NULL, &$ret_datearray=NULL ) {
166
  $date_array = date_parse( $datestring );
167
  if( !empty( $date_array['errors']) ) {
168
  return false;
179
  }
180
  return date( $ret_format, $timestamp );
181
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
  ?>
php/event-list_widget.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Event List Widget
4
+ */
5
+ class event_list_widget extends WP_Widget {
6
+
7
+ /**
8
+ * Register widget with WordPress.
9
+ */
10
+ public function __construct() {
11
+ parent::__construct(
12
+ 'event_list_widget', // Base ID
13
+ 'Event List', // Name
14
+ array( 'description' => __( 'This widget displays a list of upcoming events.', 'text_domain' ), ) // Args
15
+ );
16
+ }
17
+
18
+ /**
19
+ * Front-end display of widget.
20
+ *
21
+ * @see WP_Widget::widget()
22
+ *
23
+ * @param array $args Widget arguments.
24
+ * @param array $instance Saved values from database.
25
+ */
26
+ public function widget( $args, $instance ) {
27
+ extract( $args );
28
+ $title = apply_filters( 'widget_title', $instance['title'] );
29
+
30
+ echo $before_widget;
31
+ if ( ! empty( $title ) )
32
+ {
33
+ echo $before_title . $title . $after_title;
34
+ }
35
+ echo do_shortcode( '[event-list num_events="'.$instance['num_events'].'" show_nav=0 show_details=0 show_location=0 link_to_event='.$instance['link_to_event'].']' );
36
+ if( 1 == $instance['link_to_page'] ) {
37
+ echo '<div style="clear:both"><a title="'.$instance['link_to_page_caption'].'" href="'.$instance[ 'link_to_page_url'].'">'.$instance['link_to_page_caption'].'</a></div>';
38
+ }
39
+ echo $after_widget;
40
+ extract( $args );
41
+ }
42
+
43
+ /**
44
+ * Sanitize widget form values as they are saved.
45
+ *
46
+ * @see WP_Widget::update()
47
+ *
48
+ * @param array $new_instance Values just sent to be saved.
49
+ * @param array $old_instance Previously saved values from database.
50
+ *
51
+ * @return array Updated safe values to be saved.
52
+ */
53
+ public function update( $new_instance, $old_instance ) {
54
+ $instance = array();
55
+ $instance['title'] = strip_tags( $new_instance['title'] );
56
+ $instance['num_events'] = strip_tags( $new_instance['num_events'] );
57
+ $instance['link_to_event'] = (isset( $new_instance['link_to_event'] ) && 1==$new_instance['link_to_event'] ) ? 1 : 0;
58
+ $instance['link_to_page'] = (isset( $new_instance['link_to_page'] ) && 1==$new_instance['link_to_page'] ) ? 1 : 0;
59
+ $instance['link_to_page_url'] = strip_tags( $new_instance['link_to_page_url'] );
60
+ $instance['link_to_page_caption'] = strip_tags( $new_instance['link_to_page_caption'] );
61
+ return $instance;
62
+ }
63
+
64
+ /**
65
+ * Back-end widget form.
66
+ *
67
+ * @see WP_Widget::form()
68
+ *
69
+ * @param array $instance Previously saved values from database.
70
+ */
71
+ public function form( $instance ) {
72
+ $title = isset( $instance['title'] ) ? $instance['title'] : __( 'New title', 'text_domain' );
73
+ $num_events = isset( $instance['num_events'] ) ? $instance['num_events'] : '3';
74
+ $link_to_event = isset( $instance['link_to_event'] ) ? $instance['link_to_event'] : '1';
75
+ $link_to_page = isset( $instance['link_to_page'] ) ? $instance['link_to_page'] : '';
76
+ $link_to_page_url = isset( $instance['link_to_page_url'] ) ? $instance['link_to_page_url'] : '';
77
+ $link_to_page_caption = isset( $instance['link_to_page_caption'] ) ? $instance['link_to_page_caption'] : __( 'show event-list page', 'text_domain' );
78
+ $link_to_event_checked = 1==$link_to_event ? 'checked = "checked" ' : '';
79
+ $link_to_page_checked = 1==$link_to_page ? 'checked = "checked" ' : '';
80
+ $out = '
81
+ <p>
82
+ <label for="'.$this->get_field_id( 'title' ).'">'.__( 'Title:' ).'</label>
83
+ <input class="widefat" id="'.$this->get_field_id( 'title' ).'" name="'.$this->get_field_name( 'title' ).'" type="text" value="'.esc_attr( $title ).'" />
84
+ </p>
85
+ <p>
86
+ <label for="'.$this->get_field_id( 'num_events' ).'">'.__( 'Number of events:' ).'</label>
87
+ <input style="width:30px" class="widefat" id="'.$this->get_field_id( 'num_events' ).'" name="'.$this->get_field_name( 'num_events' ).'" type="text" value="'.esc_attr( $num_events ).'">
88
+ </p>
89
+ <p>
90
+ <label><input class="widefat" id="'.$this->get_field_id( 'link_to_event' ).'" name="'.$this->get_field_name( 'link_to_event' ).'" type="checkbox" '.$link_to_event_checked.'value="1"> '.__( 'Add links to the single events' ).'</input></label>
91
+ </p>
92
+ <p>
93
+ <label><input class="widefat" id="'.$this->get_field_id( 'link_to_page' ).'" name="'.$this->get_field_name( 'link_to_page' ).'" type="checkbox" '.$link_to_page_checked.'value="1"> '.__( 'Add a link to a page:' ).'</input></label>
94
+ <p>
95
+ <label for="'.$this->get_field_id( 'link_to_page_url' ).'">'.__( 'URL of the linked page:' ).'</label>
96
+ <input class="widefat" id="'.$this->get_field_id( 'link_to_page_url' ).'" name="'.$this->get_field_name( 'link_to_page_url' ).'" type="text" value="'.esc_attr( $link_to_page_url ).'" />
97
+ </p>
98
+ <p>
99
+ <label for="'.$this->get_field_id( 'link_to_page_caption' ).'">'.__( 'Caption for the link:' ).'</label>
100
+ <input class="widefat" id="'.$this->get_field_id( 'link_to_page_caption' ).'" name="'.$this->get_field_name( 'link_to_page_caption' ).'" type="text" value="'.esc_attr( $link_to_page_caption ).'" />
101
+ </p>
102
+ </p>';
103
+ echo $out;
104
+ }
105
+
106
+ }
107
+ ?>
php/sc_event-list.php CHANGED
@@ -3,53 +3,98 @@ require_once( EL_PATH.'php/db.php' );
3
 
4
  // This class handles the shortcode [event-list]
5
  class sc_event_list {
 
 
 
 
6
 
7
- // All available attributes
8
- public static $attr = array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- 'initial_date' => array( 'val' => 'upcoming<br />year e.g. "2012"',
11
- 'std_val' => 'upcoming',
12
- 'desc' => 'This attribute specifies which events are listed after the site is shown. The standard is to show the upcoming events.<br />
13
- Specify a year e.g. "2012" to change this.' )
14
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  // main function to show the rendered HTML output
17
- public static function show_html( $atts ) {
18
  // check attributes
19
  $std_values = array();
20
- foreach( self::$attr as $aname => $attribute ) {
21
  $std_values[$aname] = $attribute['std_val'];
22
  }
23
  $a = shortcode_atts( $std_values, $atts );
24
 
25
  if( isset( $_GET['event_id'] ) ) {
26
- $out = self::html_event_details( $_GET['event_id'] );
27
  }
28
  else {
29
- $out = self::html_events( $a );
30
  }
31
  return $out;
32
  }
33
 
34
- private static function html_event_details( $event_id ) {
35
- $event = el_db::get_event( $event_id );
36
- $out = el_db::html_calendar_nav();
37
- $out .= '<ul id="eventlist">';
38
- $out .= self::html_event( $event );
 
 
39
  $out .= '</ul>';
40
  return $out;
41
  }
42
 
43
- private static function html_events( $a ) {
44
  // specify visible events
45
  if( isset( $_GET['ytd'] ) ) {
46
- $events = el_db::get_events( $_GET['ytd'] );
47
  }
48
- elseif( $a['initial_date'] !== 'upcoming' ) {
49
- $events = el_db::get_events( $a['initial_date'] );
50
  }
51
  else {
52
- $events = el_db::get_events( 'upcoming' );
53
  }
54
  $out = '';
55
  // TODO: add rss feed
@@ -59,7 +104,9 @@ class sc_event_list {
59
  // }
60
 
61
  // generate output
62
- $out .= el_db::html_calendar_nav();
 
 
63
  // TODO: Setting missing
64
  if( empty( $events ) /*&& $mfgigcal_settings['no-events'] == "text"*/ ) {
65
  $out .= "<p>" . 'no event' /*$mfgigcal_settings['message'] */. "</p>";
@@ -77,19 +124,21 @@ class sc_event_list {
77
  }
78
  */
79
  else {
80
- $url = '?';
81
  if( !get_option( 'permalink_structure' ) ) {
82
  foreach( $_GET as $k => $v ) {
83
- if( $k != 'ytd' && $k != 'event_id' ) {
84
- $url .= $k . "=" . $v . "&";
85
  }
86
  }
87
  }
88
 
89
  // set html code
90
- $out .= '<ul id="eventlist">';
 
 
91
  foreach ($events as $event) {
92
- $out .= self::html_event( $event, $url );
93
  }
94
  $out .= '</ul>';
95
  return $out;
@@ -97,11 +146,20 @@ class sc_event_list {
97
  return $out;
98
  }
99
 
100
- private static function html_event( $event, $url=false ) {
101
- $out = '<li class="event">';
102
- $out .= self::html_fulldate( $event->start_date, $event->end_date );
103
- $out .= '<div class="info_block"><h3>';
104
- if( $url ) {
 
 
 
 
 
 
 
 
 
105
  $out .= '<a href="'.$url.'event_id='.$event->id.'">'.$event->title.'</a>';
106
  }
107
  else {
@@ -109,43 +167,98 @@ class sc_event_list {
109
  }
110
  $out .= '</h3>';
111
  if( $event->time != '' ) {
112
- $out .= '<span class="time">'.mysql2date( get_option( 'time_format' ), $event->time ).'</span>';
113
  }
114
- $out .= '<span class="location">'.$event->location.'</span>';
115
- $out .= '<span class="details">'.$event->details.'</span>';
116
- $out .= '</div></li>';
 
 
 
 
 
117
  return $out;
118
  }
119
 
120
- private static function html_fulldate( $start_date, $end_date ) {
121
- $out = '';
 
122
  if( $start_date === $end_date ) {
123
  // one day event
124
- $out .= '<div class="date">';
125
- $out .= '<div class="end-date">';
126
- $out .= self::html_date( $start_date );
 
 
 
 
 
127
  $out .= '</div>';
128
  }
129
  else {
130
  // multi day event
131
- $out .= '<div class="date multi-date">';
132
  $out .= '<div class="start-date">';
133
- $out .= self::html_date( $start_date );
134
  $out .= '</div>';
135
  $out .= '<div class="end-date">';
136
- $out .= self::html_date( $end_date );
137
  $out .= '</div>';
138
  }
139
  $out .= '</div>';
140
  return $out;
141
  }
142
 
143
- private static function html_date( $date ) {
144
- $out = '<div class="weekday">'.mysql2date( 'D', $date ).'</div>';
145
- $out .= '<div class="day">'.mysql2date( 'd', $date ).'</div>';
146
- $out .= '<div class="month">'.mysql2date( 'M', $date ).'</div>';
147
- $out .= '<div class="year">'.mysql2date( 'Y', $date ).'</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  return $out;
149
  }
 
 
 
 
 
 
 
 
 
150
  }
151
  ?>
3
 
4
  // This class handles the shortcode [event-list]
5
  class sc_event_list {
6
+ private static $instance;
7
+ private $db;
8
+ private $options;
9
+ private $atts;
10
 
11
+ public static function &get_instance() {
12
+ // Create class instance if required
13
+ if( !isset( self::$instance ) ) {
14
+ self::$instance = new sc_event_list();
15
+ }
16
+ // Return class instance
17
+ return self::$instance;
18
+ }
19
+
20
+ private function __construct() {
21
+ $this->db = el_db::get_instance();
22
+ //$this->options = &lv_options::get_instance();
23
+
24
+ // All available attributes
25
+ $this->atts = array(
26
+
27
+ 'initial_date' => array( 'val' => 'upcoming<br />year e.g. "2012"',
28
+ 'std_val' => 'upcoming',
29
+ 'desc' => 'This attribute specifies which events are initially shown. The standard is to show the upcoming events.<br />
30
+ Specify a year e.g. "2012" to change this behavior.' ),
31
+
32
+ 'num_events' => array( 'val' => 'number',
33
+ 'std_val' => '0',
34
+ 'desc' => 'This attribute specifies how many events should be displayed if upcoming events is selected.<br />
35
+ 0 is the standard value which means that all events will be displayed.' ),
36
 
37
+ 'show_nav' => array( 'val' => '0..false<br />1..true',
38
+ 'std_val' => '1',
39
+ 'desc' => 'This attribute specifies if the calendar navigation should be displayed.'),
40
+
41
+ 'show_details' => array( 'val' => '0..false<br />1..true',
42
+ 'std_val' => '1',
43
+ 'desc' => 'This attribute specifies if the details are displayed in the event list.'),
44
+
45
+ 'show_location' => array( 'val' => '0..false<br />1..true',
46
+ 'std_val' => '1',
47
+ 'desc' => 'This attribute specifies if the location is displayed in the event list.'),
48
+
49
+ 'link_to_event' => array( 'val' => '0..false<br />1..true',
50
+ 'std_val' => '1',
51
+ 'desc' => 'This attribute specifies if a link to the single event should be added onto the event name in the event list.')
52
+ );
53
+ }
54
+
55
+ public function get_atts() {
56
+ return $this->atts;
57
+ }
58
 
59
  // main function to show the rendered HTML output
60
+ public function show_html( $atts ) {
61
  // check attributes
62
  $std_values = array();
63
+ foreach( $this->atts as $aname => $attribute ) {
64
  $std_values[$aname] = $attribute['std_val'];
65
  }
66
  $a = shortcode_atts( $std_values, $atts );
67
 
68
  if( isset( $_GET['event_id'] ) ) {
69
+ $out = $this->html_event_details( $_GET['event_id'] );
70
  }
71
  else {
72
+ $out = $this->html_events( $a );
73
  }
74
  return $out;
75
  }
76
 
77
+ private function html_event_details( $event_id ) {
78
+ $event = $this->db->get_event( $event_id );
79
+ $out = $this->html_calendar_nav();
80
+ $out .= '
81
+ <h2>Event Information:</h2>
82
+ <ul class="event-list">';
83
+ $out .= $this->html_event( $event );
84
  $out .= '</ul>';
85
  return $out;
86
  }
87
 
88
+ private function html_events( $a ) {
89
  // specify visible events
90
  if( isset( $_GET['ytd'] ) ) {
91
+ $events = $this->db->get_events( $_GET['ytd'] );
92
  }
93
+ elseif( 'upcoming' !== $a['initial_date'] ) {
94
+ $events = $this->db->get_events( $a['initial_date'] );
95
  }
96
  else {
97
+ $events = $this->db->get_events( 'upcoming', $a['num_events'] );
98
  }
99
  $out = '';
100
  // TODO: add rss feed
104
  // }
105
 
106
  // generate output
107
+ if( 0 != $a['show_nav'] ) {
108
+ $out .= $this->html_calendar_nav();
109
+ }
110
  // TODO: Setting missing
111
  if( empty( $events ) /*&& $mfgigcal_settings['no-events'] == "text"*/ ) {
112
  $out .= "<p>" . 'no event' /*$mfgigcal_settings['message'] */. "</p>";
124
  }
125
  */
126
  else {
127
+ $url = get_permalink();
128
  if( !get_option( 'permalink_structure' ) ) {
129
  foreach( $_GET as $k => $v ) {
130
+ if( 'ytd' !== $k && 'event_id' !== $k ) {
131
+ $url .= $k.'='.$v.'&amp;';
132
  }
133
  }
134
  }
135
 
136
  // set html code
137
+ $out .= '
138
+ <ul class="event-list">';
139
+ $single_day_only = $this->is_single_day_only( $events );
140
  foreach ($events as $event) {
141
+ $out .= $this->html_event( $event, $a, $url, $single_day_only );
142
  }
143
  $out .= '</ul>';
144
  return $out;
146
  return $out;
147
  }
148
 
149
+ private function html_event( $event, $a=null, $url=null, $single_day_only=false ) {
150
+ $out = '
151
+ <li class="event">';
152
+ $out .= $this->html_fulldate( $event->start_date, $event->end_date, $single_day_only );
153
+ $out .= '
154
+ <div class="event-info';
155
+ if( $single_day_only ) {
156
+ $out .= ' single-day';
157
+ }
158
+ else {
159
+ $out .= ' multi-day';
160
+ }
161
+ $out .= '"><h3>';
162
+ if( null !== $url && ( null !== $a && 0 != $a['link_to_event'] ) ) {
163
  $out .= '<a href="'.$url.'event_id='.$event->id.'">'.$event->title.'</a>';
164
  }
165
  else {
167
  }
168
  $out .= '</h3>';
169
  if( $event->time != '' ) {
170
+ $out .= '<span class="event-time">'.mysql2date( get_option( 'time_format' ), $event->time ).'</span>';
171
  }
172
+ if( null === $a || 0 != $a['show_location'] ) {
173
+ $out .= '<span class="event-location">'.$event->location.'</span>';
174
+ }
175
+ if( null === $a || 0 != $a['show_details'] ) {
176
+ $out .= '<div class="event-details">'.$event->details.'</div>';
177
+ }
178
+ $out .= '</div>
179
+ </li>';
180
  return $out;
181
  }
182
 
183
+ private function html_fulldate( $start_date, $end_date, $single_day_only=false ) {
184
+ $out = '
185
+ ';
186
  if( $start_date === $end_date ) {
187
  // one day event
188
+ $out .= '<div class="event-date">';
189
+ if( $single_day_only ) {
190
+ $out .= '<div class="start-date">';
191
+ }
192
+ else {
193
+ $out .= '<div class="end-date">';
194
+ }
195
+ $out .= $this->html_date( $start_date );
196
  $out .= '</div>';
197
  }
198
  else {
199
  // multi day event
200
+ $out .= '<div class="event-date multi-date">';
201
  $out .= '<div class="start-date">';
202
+ $out .= $this->html_date( $start_date );
203
  $out .= '</div>';
204
  $out .= '<div class="end-date">';
205
+ $out .= $this->html_date( $end_date );
206
  $out .= '</div>';
207
  }
208
  $out .= '</div>';
209
  return $out;
210
  }
211
 
212
+ private function html_date( $date ) {
213
+ $out = '<div class="event-weekday">'.mysql2date( 'D', $date ).'</div>';
214
+ $out .= '<div class="event-day">'.mysql2date( 'd', $date ).'</div>';
215
+ $out .= '<div class="event-month">'.mysql2date( 'M', $date ).'</div>';
216
+ $out .= '<div class="event-year">'.mysql2date( 'Y', $date ).'</div>';
217
+ return $out;
218
+ }
219
+
220
+ private function html_calendar_nav() {
221
+ $first_year = $this->db->get_event_date( 'first' );
222
+ $last_year = $this->db->get_event_date( 'last' );
223
+
224
+ $url = get_permalink();
225
+ if( !get_option( 'permalink_structure' ) ) {
226
+ foreach( $_GET as $k => $v ) {
227
+ if( 'ytd' !== $k && 'event_id' !== $k ) {
228
+ $url .= $k.'='.$v.'&amp;';
229
+ }
230
+ }
231
+ }
232
+ else {
233
+ $url .= '?';
234
+ }
235
+ $out = '<div class="subsubsub">';
236
+ if( isset( $_GET['ytd'] ) || isset( $_GET['event_id'] ) ) {
237
+ $out .= '<a href="'.$url.'">Upcoming</a>';
238
+ }
239
+ else {
240
+ $out .= '<strong>Upcoming</strong>';
241
+ }
242
+ for( $year=$last_year; $year>=$first_year; $year-- ) {
243
+ $out .= ' | ';
244
+ if( isset( $_GET['ytd'] ) && $year == $_GET['ytd'] ) {
245
+ $out .= '<strong>'.$year.'</strong>';
246
+ }
247
+ else {
248
+ $out .= '<a href="'.$url.'ytd='.$year.'">'.$year.'</a>';
249
+ }
250
+ }
251
+ $out .= '</div><br />';
252
  return $out;
253
  }
254
+
255
+ private function is_single_day_only( &$events ) {
256
+ foreach( $events as $event ) {
257
+ if( $event->start_date !== $event->end_date ) {
258
+ return false;
259
+ }
260
+ }
261
+ return true;
262
+ }
263
  }
264
  ?>
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, admin, attribute, widget, sidebar
5
  Requires at least: 3.3
6
  Tested up to: 3.5
7
- Stable tag: 0.2.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
@@ -14,7 +14,7 @@ Manage your events and show them in a list view on your site.
14
 
15
  == Description ==
16
 
17
- The purpose of this plugin is to to show a list of events with date, time, description, place, etc. on your site by using a shortcode.
18
  There are also admin sites available to access the plugin-settings and to manage the events.
19
 
20
  = Current Features =
@@ -27,6 +27,9 @@ The event list can be placed in any page or post on your Wordpress site. Just in
27
 
28
  ‘[event-list]’
29
 
 
 
 
30
  If you want to follow the development status have a look at the [git-repository on github](https://github.com/mibuthu/wp-event-list "wp-event-list git-repository").
31
 
32
 
@@ -48,11 +51,23 @@ Event List uses the built-in Wordpress WYSIWYG editor. It's exactly the same pro
48
 
49
  == Screenshots ==
50
 
51
- not available yet
 
 
 
 
52
 
53
 
54
  == Changelog ==
55
 
 
 
 
 
 
 
 
 
56
  = 0.2.2 (2012-11-18) =
57
 
58
  * localization of date and time on the frontpage
4
  Tags: event, events, list, listview, calendar, schedule, shortcode, page, category, categories, admin, attribute, widget, sidebar
5
  Requires at least: 3.3
6
  Tested up to: 3.5
7
+ Stable tag: 0.3.0
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
14
 
15
  == Description ==
16
 
17
+ The purpose of this plugin is to to show a list of events with date, time, description, place, etc. on your site by using a shortcode or a widget.
18
  There are also admin sites available to access the plugin-settings and to manage the events.
19
 
20
  = Current Features =
27
 
28
  ‘[event-list]’
29
 
30
+ With the existing attributes it is possible to modify the listed events and their style.
31
+ There is also a widget available to view the upcoming events in a sidebar.
32
+
33
  If you want to follow the development status have a look at the [git-repository on github](https://github.com/mibuthu/wp-event-list "wp-event-list git-repository").
34
 
35
 
51
 
52
  == Screenshots ==
53
 
54
+ 1. Admin page: Main page with the event list table
55
+ 2. Admin page: New event form
56
+ 3. Admin page: About page with help and available attributes list
57
+ 4. Admin page: Widget with the available options
58
+ 5. Example page created with [event-list] shortcode
59
 
60
 
61
  == Changelog ==
62
 
63
+ = 0.3.0 (2012-12-31) =
64
+
65
+ * added a widget to show upcoming events in a sidebar
66
+ * added some shortcode attributes to modify the output
67
+ * internal code changes
68
+ * fixed some html issues
69
+ * updated help texts on admin about page
70
+
71
  = 0.2.2 (2012-11-18) =
72
 
73
  * localization of date and time on the frontpage
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file