|
1 <?php |
|
2 /** |
|
3 * Plugin Name: Gigs Calendar |
|
4 * Plugin URI: http://blogsforbands.com |
|
5 * Description: A calendar to let musicians and other performing artists share their performance dates with their adoring public. |
|
6 * Author: Dan Coulter |
|
7 * Version: 0.4.7 |
|
8 * Author URI: http://dancoulter.com |
|
9 */ |
|
10 |
|
11 /** |
|
12 * Copyright 2008 Dan Coulter (dan@blogsforbands.com) |
|
13 * |
|
14 * This program is free software; you can redistribute it and/or modify |
|
15 * it under the terms of the GNU General Public License as published by |
|
16 * the Free Software Foundation; either version 2 of the License, or |
|
17 * (at your option) any later version. |
|
18 * |
|
19 * This program is distributed in the hope that it will be useful, |
|
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 * GNU General Public License for more details. |
|
23 * |
|
24 * You can get a copy of this license here: http://www.gnu.org/licenses/ |
|
25 * And a human readable copy here: http://creativecommons.org/licenses/GPL/2.0/ |
|
26 */ |
|
27 |
|
28 $include_folder = dirname(__FILE__); |
|
29 require_once $include_folder . '/version.php'; |
|
30 require_once $include_folder . '/gigs-classes.php'; |
|
31 $gcd = 'gigs-calendar'; // Domain for Internationalization |
|
32 |
|
33 if ( defined('ABSPATH') ) : |
|
34 class dtc_gigs { |
|
35 var $cache = array(); |
|
36 |
|
37 function add_admin_page() { |
|
38 global $gcd, $wp_version; |
|
39 $options = get_option('gigs-calendar'); |
|
40 $admin_location = 'add_object_page'; |
|
41 if ( $wp_version < 2.7 ) $admin_location = 'add_management_page'; |
|
42 else $admin_location = 'add_object_page'; |
|
43 $admin_location( |
|
44 __('Gigs Calendar', $gcd), |
|
45 __('Gigs Calendar', $gcd), |
|
46 (isset($options['user_level']) ? $options['user_level'] : 'level_7'), |
|
47 'gigs', |
|
48 array("dtc_gigs", "generate_admin_page") |
|
49 ); |
|
50 } |
|
51 |
|
52 function admin_css() { |
|
53 global $wp_version; |
|
54 $options = get_option('gigs-calendar'); |
|
55 $folder = dtc_gigs::get_url(); |
|
56 ?> |
|
57 <link type="text/css" rel="stylesheet" href="<?php echo $folder; ?>js/jquery.tooltip.css" /> |
|
58 <link type="text/css" rel="stylesheet" href="<?php echo $folder; ?>js/ui.datepicker.css" /> |
|
59 <link type="text/css" rel="stylesheet" href="<?php echo $folder; ?>gigs-calendar-admin.css" /> |
|
60 <?php |
|
61 if ( (float) $wp_version >= 2.5 ) { |
|
62 ?><link type="text/css" rel="stylesheet" href="<?php echo $folder; ?>gigs-calendar-admin-wp2.5.css" /><?php |
|
63 } |
|
64 } |
|
65 |
|
66 function display_css() { |
|
67 $options = get_option('gigs-calendar'); |
|
68 $folder = dtc_gigs::get_url() . 'templates/'; |
|
69 |
|
70 if ( is_file(dirname(__FILE__) . '/templates/' . $options['template'] . '/style.css') ) { |
|
71 ?> |
|
72 <link type="text/css" rel="stylesheet" href="<?php echo $folder . $options['template']; ?>/style.css" /> |
|
73 <?php |
|
74 } elseif ( is_file(ABSPATH . 'wp-content/gigs-templates/' . $options['template'] . '/style.css') ) { |
|
75 ?> |
|
76 <link type="text/css" rel="stylesheet" href="<?php echo get_bloginfo('wpurl') . '/wp-content/gigs-templates/' . $options['template']; ?>/style.css" /> |
|
77 <?php |
|
78 } else { |
|
79 ?> |
|
80 <link type="text/css" rel="stylesheet" href="<?php echo $folder; ?>basic/style.css" /> |
|
81 <?php |
|
82 } |
|
83 } |
|
84 |
|
85 function generate_admin_page() { |
|
86 global $gcd; |
|
87 $options = get_option('gigs-calendar'); |
|
88 if ( $options !== false && !current_user_can($options['user_level']) ) { |
|
89 //exit; // Stupid non-fix. |
|
90 } |
|
91 get_currentuserinfo(); |
|
92 global $userdata; |
|
93 |
|
94 if ( isset($_GET['ladyhawke']) ) { |
|
95 update_option("gig_db_version", $_GET['ladyhawke']); |
|
96 dtc_gigs::upgrade(); |
|
97 } |
|
98 |
|
99 $folder = dtc_gigs::get_url(); |
|
100 $pages = array( |
|
101 'gigs' => __('Gigs', $gcd), |
|
102 'archive' => __('Archive', $gcd), |
|
103 'venues' => __('Venues', $gcd), |
|
104 'tours' => __('Tours', $gcd), |
|
105 'settings' => __('Settings', $gcd), |
|
106 'feedback' => __('Feedback/Bugs', $gcd), |
|
107 'credits' => __('Credits', $gcd), |
|
108 ); |
|
109 |
|
110 foreach ( $pages as $key => $name ) { |
|
111 $pages[$key] = array('name'=>$name, 'key'=>$key, 'url'=>$folder . $key . '.ajax.php'); |
|
112 } |
|
113 |
|
114 if ( $options['admin-only-settings'] && !current_user_can('administrator') ) { |
|
115 unset($pages['settings']); |
|
116 } |
|
117 |
|
118 $pages = apply_filters('gigCal_pages', $pages); |
|
119 ?> |
|
120 <script type="text/javascript"> |
|
121 var pages = { |
|
122 <?php |
|
123 $first = true; |
|
124 foreach ( $pages as $page ) { |
|
125 echo ( $first ? '' : ',' ) . $page['key'] . ' : {key:"' . $page['key'] . '", name:"' . $page['name'] . '", url:"' . $page['url'] . '"}'; |
|
126 $first = false; |
|
127 } |
|
128 ?> |
|
129 }; |
|
130 var ajaxTarget = "<?php echo $folder; ?>"; |
|
131 var nonce = "<?php echo wp_create_nonce('gigs-calendar'); ?>"; |
|
132 var pageTarget = ""; |
|
133 </script> |
|
134 <div class="wrap"> |
|
135 <h2><?php _e('Gigs Calendar', $gcd) ?></h2> |
|
136 <ul id="gigs-menu"> |
|
137 <?php if ( !$options || (empty($options['parent']) && $options['calendar-position'] != 'custom') ) : ?> |
|
138 <li id="settings-tab"><?php _e('Settings', $gcd) ?></li> |
|
139 <li id="feedback-tab"><?php _e('Feedback/Bugs', $gcd) ?></li> |
|
140 <li id="credits-tab"><?php _e('Credits', $gcd) ?></li> |
|
141 <?php else: ?> |
|
142 <?php foreach ( $pages as $page ) : ?> |
|
143 <li id="<?php echo $page['key']; ?>-tab"><?php echo $page['name']; ?></li> |
|
144 <?php endforeach; ?> |
|
145 <?php endif; ?> |
|
146 </ul> |
|
147 <div id="gigs-wrapper" class="wrap"> |
|
148 <div id="loading"> |
|
149 <?php _e('Loading...', $gcd) ?><br /> |
|
150 <img src="<?php echo $folder; ?>images/ajax-loader.gif" alt="" /> |
|
151 </div> |
|
152 <?php foreach ( $pages as $page ) : ?> |
|
153 <div id="<?php echo $page['key']; ?>" class="gigs-page"></div> |
|
154 <?php endforeach; ?> |
|
155 </div> |
|
156 </div> |
|
157 <script type="text/javascript"> |
|
158 jQuery(document).ready(function(){ |
|
159 gigs_page_load(jQuery("#gigs-menu li").eq(0).attr("id").split("-")[0]); |
|
160 }); |
|
161 |
|
162 jQuery("#gigs-menu li").click(function(){ |
|
163 gigs_page_load(this.id.split("-")[0]); |
|
164 }); |
|
165 |
|
166 gigs_page_load = function(page, query) { |
|
167 if ( query == undefined ) query = ""; |
|
168 else query = "?" + query; |
|
169 |
|
170 try{pageDestroy();}catch(e){}; |
|
171 jQuery("#loading").show(); |
|
172 jQuery(".gigs-page:visible").hide(); |
|
173 jQuery("#gigs-menu li.selected").removeClass("selected"); |
|
174 jQuery("#" + page + "-tab").addClass("selected"); |
|
175 pageTarget = pages[page].url; |
|
176 jQuery("#" + page).load(pageTarget + query, { |
|
177 action:"load", |
|
178 "page":page, |
|
179 "nonce":nonce |
|
180 }, function(rsp1,rsp2,rsp3){ |
|
181 jQuery("#loading").hide(); |
|
182 jQuery(".gigs-page:visible").hide(); |
|
183 jQuery("#" + page).show(); |
|
184 }); |
|
185 } |
|
186 |
|
187 resetTableColors = function(table) { |
|
188 rows = jQuery(table).find("tbody tr"); |
|
189 for ( i = 0; i < rows.length; i++ ) { |
|
190 if ( Math.floor(i/2) % 2 ) { |
|
191 rows.eq(i).removeClass("alternate"); |
|
192 } else { |
|
193 rows.eq(i).addClass("alternate"); |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 </script> |
|
199 <?php |
|
200 } |
|
201 |
|
202 function get_url() { |
|
203 return ( defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? str_replace("http://", "https://", get_bloginfo('wpurl')) : get_bloginfo('wpurl')) . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/'; |
|
204 } |
|
205 |
|
206 function get_path() { |
|
207 return dirname(__FILE__); |
|
208 } |
|
209 |
|
210 function display($in){ |
|
211 global $wpdb, $post, $include_folder, $gcd; |
|
212 $options = get_option("gigs-calendar"); |
|
213 require_once 'gigs-classes.php'; |
|
214 $out = ''; |
|
215 $is_archive = false; |
|
216 $tpath = dirname(__FILE__) . '/templates/'. $options['template']; |
|
217 |
|
218 $is_parent = !empty($options['parent']) && is_page($options['parent']); |
|
219 $is_archive = !empty($options['archive']) && is_page($options['archive']); |
|
220 |
|
221 if ( ($is_parent || $is_archive) && $options['calendar-position'] != 'custom' ) { |
|
222 ob_start(); |
|
223 if ( $is_parent ) { |
|
224 if ( $options['tours-display'] ) { |
|
225 $t = new tour(); |
|
226 $tours = $t->sortTours(); |
|
227 foreach ( $tours as $tour ) { |
|
228 dtc_gigs::generateList(array( |
|
229 'caption'=> $is_archive ? __('Upcoming shows', $gcd) : '', |
|
230 'dateFormat' => 'short', |
|
231 'tour' => $tour, |
|
232 )); |
|
233 } |
|
234 dtc_gigs::generateList(array( |
|
235 'caption'=> '<div class="title">' . __('Other shows', $gcd) . '</div>', |
|
236 'dateFormat' => 'short', |
|
237 'tour' => -1, |
|
238 )); |
|
239 } else { |
|
240 dtc_gigs::generateList(array( |
|
241 'caption'=> $is_archive ? __('Upcoming shows', $gcd) : '', |
|
242 'dateFormat' => 'short', |
|
243 )); |
|
244 } |
|
245 } |
|
246 if ( !empty($options['archive']) && is_page($options['archive']) ) { |
|
247 if ( $options['tours-display'] ) { |
|
248 $t = new tour(); |
|
249 $tours = $t->sortTours(); |
|
250 foreach ( $tours as $tour ) { |
|
251 dtc_gigs::generateList(array( |
|
252 'upcoming'=>false, |
|
253 'caption'=> $is_archive ? __('Upcoming shows', $gcd) : '', |
|
254 'dateFormat' => 'short', |
|
255 'tour' => $tour, |
|
256 )); |
|
257 } |
|
258 dtc_gigs::generateList(array( |
|
259 'upcoming'=>false, |
|
260 'caption'=> '<div class="title">' . __('Other shows', $gcd) . '</div>', |
|
261 'dateFormat' => 'short', |
|
262 'tour' => -1, |
|
263 )); |
|
264 } else { |
|
265 dtc_gigs::generateList(array( |
|
266 'upcoming'=>false, |
|
267 'caption'=> $is_parent ? __('Past show archive', $gcd) : '', |
|
268 'dateFormat' => 'archive', |
|
269 )); |
|
270 } |
|
271 } |
|
272 |
|
273 dtcGigs::loadTemplate('rss'); |
|
274 dtcGigs::loadTemplate('attribution'); |
|
275 $out = ob_get_clean(); |
|
276 if ( $options['calendar-position'] == 'bottom' ) { |
|
277 $out = '<div>' . $in . '</div>' . $out; |
|
278 } else { |
|
279 $out .= '<div>' . $in . '</div>'; |
|
280 } |
|
281 } else { |
|
282 $g = new gig(); |
|
283 if ( $g->getByPostID($post->ID) ) { |
|
284 $data = array( |
|
285 'g' => $g, |
|
286 'v' => $g->getVenue(), |
|
287 'p' => $g->getPerformances(), |
|
288 'image_folder' => dtc_gigs::get_url() . 'images/', |
|
289 'tags' => $g->getTags(), |
|
290 'tags_slugs' => $g->getTags(true), |
|
291 'custom' => $g->getCustom(), |
|
292 ); |
|
293 ob_start(); |
|
294 dtcGigs::loadTemplate('gig-post', null, $data); |
|
295 $out = ob_get_clean(); |
|
296 |
|
297 $out = '<div>' . $in . '</div>' . $out; |
|
298 } else { |
|
299 $out = $in; |
|
300 } |
|
301 } |
|
302 if ( preg_match_all('~\[gig-cal ?(.*?)\]~', $out, $matches) ) { |
|
303 $matches[0] = array_unique($matches[0]); |
|
304 foreach ( $matches[0] as $key => $match ) { |
|
305 $args = array(); |
|
306 parse_str(str_replace(' ', '&', $matches[1][$key]), $args); |
|
307 $args['upcoming'] = (strpos($matches[1][$key], 'archive') !== FALSE) ? false : true; |
|
308 $args['return'] = true; |
|
309 $out = str_replace($match, dtc_gigs::generateList($args), $out); |
|
310 } |
|
311 } |
|
312 return $out; |
|
313 } |
|
314 |
|
315 function upgrade() { |
|
316 global $wpdb; |
|
317 |
|
318 if ( isset($wpdb->charset) && !empty($wpdb->charset) ) { |
|
319 $charset = ' DEFAULT CHARSET=' . $wpdb->charset; |
|
320 } elseif ( defined(DB_CHARSET) && DB_CHARSET != '' ) { |
|
321 $charset = ' DEFAULT CHARSET=' . DB_CHARSET; |
|
322 } else { |
|
323 $charset = ''; |
|
324 } |
|
325 |
|
326 $queries = array( |
|
327 array( // 1 |
|
328 ' |
|
329 CREATE TABLE IF NOT EXISTS `' . TABLE_VENUES . '` ( |
|
330 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , |
|
331 `name` VARCHAR( 255 ) NOT NULL , |
|
332 `address` TEXT NOT NULL , |
|
333 `city` VARCHAR( 255 ) NOT NULL , |
|
334 `state` VARCHAR( 255 ) NOT NULL , |
|
335 `country` VARCHAR( 255 ) NOT NULL , |
|
336 `postalCode` VARCHAR( 255 ) NOT NULL , |
|
337 `contact` VARCHAR( 255 ) NOT NULL , |
|
338 `phone` VARCHAR( 255 ) NOT NULL , |
|
339 `email` VARCHAR( 255 ) NOT NULL , |
|
340 `link` VARCHAR( 255 ) NOT NULL , |
|
341 `notes` TEXT NOT NULL , |
|
342 `private` TINYINT NOT NULL , |
|
343 `apiID` INT UNSIGNED NOT NULL , |
|
344 `deleted` TINYINT NOT NULL |
|
345 ) ' . $charset . ' |
|
346 ', ' |
|
347 CREATE TABLE IF NOT EXISTS `' . TABLE_GIGS . '` ( |
|
348 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , |
|
349 `venueID` INT UNSIGNED NOT NULL , |
|
350 `date` DATE NOT NULL , |
|
351 `notes` TEXT NOT NULL, |
|
352 `postID` BIGINT UNSIGNED NOT NULL |
|
353 ) ' . $charset . ' |
|
354 ', ' |
|
355 CREATE TABLE IF NOT EXISTS `' . TABLE_PERFORMANCES . '` ( |
|
356 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , |
|
357 `gigID` INT UNSIGNED NOT NULL , |
|
358 `time` TIME NULL , |
|
359 `link` VARCHAR( 255 ) NOT NULL , |
|
360 `shortNotes` VARCHAR( 255 ) NOT NULL , |
|
361 `ages` VARCHAR( 255 ) NOT NULL |
|
362 ) ' . $charset . ' |
|
363 ' |
|
364 ), array( // 2 |
|
365 'ALTER TABLE `' . TABLE_VENUES . '` ADD `customMap` VARCHAR( 255 ) NOT NULL', |
|
366 'ALTER TABLE `' . TABLE_GIGS . '` ADD `eventName` VARCHAR( 255 ) NOT NULL', |
|
367 ), array( // 3 |
|
368 ' |
|
369 CREATE TABLE `' . TABLE_TOURS . '` ( |
|
370 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , |
|
371 `name` VARCHAR( 255 ) NOT NULL , |
|
372 `notes` MEDIUMTEXT NOT NULL , |
|
373 `pos` INT UNSIGNED NOT NULL |
|
374 ) ' . $charset . ' |
|
375 ', ' |
|
376 ALTER TABLE `' . TABLE_GIGS . '` ADD `tour_id` INT UNSIGNED NULL |
|
377 ', |
|
378 ), |
|
379 |
|
380 |
|
381 |
|
382 ); |
|
383 for ( $i = (int) get_option('gig_db_version'); $i < (int) DTC_GIGS_DB_VERSION; $i++) { |
|
384 if ( isset($queries[$i]) ) { |
|
385 foreach ( $queries[$i] as $q ) { |
|
386 $wpdb->query($q); |
|
387 } |
|
388 } |
|
389 } |
|
390 |
|
391 if ( count($wpdb->get_results('show tables like "' . GIGS_DB_PREFIX . 'gigs_%"')) != 4 ) { |
|
392 update_option("gig_db_version", -1); |
|
393 } else { |
|
394 update_option("gig_db_version", (int) DTC_GIGS_DB_VERSION); |
|
395 } |
|
396 } |
|
397 |
|
398 |
|
399 function hide_posts($where) { |
|
400 $o = get_option('gigs-calendar'); |
|
401 if ( 0 < (int) get_option('gig_db_version') && $o['post-filtering'] ) { |
|
402 global $wp_the_query; |
|
403 global $wp_query; |
|
404 global $wp_actions; |
|
405 global $wpdb; |
|
406 if ( in_array('get_sidebar', $wp_actions) ) { |
|
407 $where .= ' AND ID NOT IN (SELECT postID FROM ' . TABLE_GIGS . ')'; |
|
408 } elseif ( (is_single() || (function_exists('is_tag') && is_tag())) ) { |
|
409 return $where; |
|
410 } elseif ( (!is_category() || $wp_the_query->query_vars['cat'] != $o['category']) || defined('gigs-query-mod')) { |
|
411 $where .= ' AND ID NOT IN (SELECT postID FROM ' . TABLE_GIGS . ')'; |
|
412 } |
|
413 } |
|
414 return $where; |
|
415 } |
|
416 |
|
417 function hide_archives($where) { |
|
418 $o = get_option('gigs-calendar'); |
|
419 if ( $o['post-filtering'] ) { |
|
420 global $wpdb; |
|
421 return $where . ' AND ID NOT IN (SELECT postID FROM ' . TABLE_GIGS . ')'; |
|
422 } |
|
423 } |
|
424 |
|
425 |
|
426 function post_nav($where) { |
|
427 $o = get_option('gigs-calendar'); |
|
428 if ( 0 < (int) get_option('gig_db_version') && $o['post-filtering'] ) { |
|
429 global $wp_the_query, $include_folder, $wpdb, $wp_version; |
|
430 |
|
431 include_once 'gigs-classes.php'; |
|
432 |
|
433 $wtq = $wp_the_query; |
|
434 $g = new gig(); |
|
435 |
|
436 $table = ''; // This will let me support versions < 2.3 |
|
437 if ( (float) $wp_version >= 2.3 ) { |
|
438 $table = 'p.'; |
|
439 } |
|
440 |
|
441 if ( $wtq->is_single && $wpdb->get_var('SELECT COUNT(*) FROM ' . TABLE_GIGS . ' WHERE postID = ' . $wtq->post->ID) ) { // Is a gig |
|
442 $where .= ' AND ' . $table . 'ID IN (SELECT postID FROM ' . TABLE_GIGS . ')'; |
|
443 } else { |
|
444 $where .= ' AND ' . $table . 'ID NOT IN (SELECT postID FROM ' . TABLE_GIGS . ')'; |
|
445 } |
|
446 } |
|
447 return $where; |
|
448 } |
|
449 |
|
450 function widget_upcoming($args) { |
|
451 extract($args); |
|
452 $o = get_option('gigs-calendar'); |
|
453 if ( !isset($o['widget']['upcoming']) ) $o['widget']['upcoming'] = array(); |
|
454 ?> |
|
455 <?php echo $before_widget; ?> |
|
456 <?php echo $before_title . $o['widget']['upcoming']['title'] . $after_title; ?> |
|
457 <?php |
|
458 dtc_gigs::generateList(array_merge( |
|
459 array( |
|
460 'upcoming'=>true, |
|
461 'limit'=>$o['widget']['upcoming']['length'], |
|
462 'template'=>'upcoming-widget', |
|
463 ), |
|
464 $o['widget']['upcoming'] |
|
465 )); |
|
466 ?> |
|
467 <?php echo $after_widget; ?> |
|
468 <?php |
|
469 } |
|
470 |
|
471 function widget_upcoming_control() { |
|
472 global $gcd; |
|
473 $o = get_option('gigs-calendar'); |
|
474 if ( !isset($o['widget']['upcoming']) ) { |
|
475 $o['widget']['upcoming'] = array(); |
|
476 $o['widget']['upcoming']['title'] = __('Upcoming Gigs', $gcd); |
|
477 $o['widget']['upcoming']['length'] = 5; |
|
478 $o['widget']['upcoming']['dateFormat'] = 'M j'; |
|
479 $o['widget']['upcoming']['dateFormatYear'] = 'M j, Y'; |
|
480 $o['widget']['upcoming']['link'] = array(); |
|
481 $o['widget']['upcoming']['link'][] = 'city'; |
|
482 $o['widget']['upcoming']['link'][] = 'none'; |
|
483 } |
|
484 |
|
485 if ( isset($_POST['gigs_length']) ) { |
|
486 $o['widget']['upcoming']['title'] = isset($_POST['gigs_title']) ? $_POST['gigs_title'] : $o['widget']['upcoming']['title']; |
|
487 $o['widget']['upcoming']['length'] = !empty($_POST['gigs_length']) ? $_POST['gigs_length'] : 5; |
|
488 $o['widget']['upcoming']['dateFormat'] = !empty($_POST['gigs_dateFormat']) ? $_POST['gigs_dateFormat'] : 'M j'; |
|
489 $o['widget']['upcoming']['dateFormatYear'] = !empty($_POST['gigs_dateFormatYear']) ? $_POST['gigs_dateFormatYear'] : 'M j, Y'; |
|
490 $o['widget']['upcoming']['link'] = array(); |
|
491 $o['widget']['upcoming']['link'][] = $_POST['gig-firstLinkField']; |
|
492 $o['widget']['upcoming']['link'][] = $_POST['gig-secondLinkField']; |
|
493 update_option('gigs-calendar', $o); |
|
494 } |
|
495 |
|
496 $linkFields = array( |
|
497 'city' => 'City', |
|
498 'country' => 'Country', |
|
499 'venue' => 'Venue', |
|
500 'eventName' => 'Event Name', |
|
501 ); |
|
502 |
|
503 ?> |
|
504 <p> |
|
505 <label> |
|
506 <?php _e('Widget title:', $gcd) ?> |
|
507 <input type="text" size="20" name="gigs_title" value="<?php echo $o['widget']['upcoming']['title']; ?>" /> |
|
508 </label> |
|
509 </p> |
|
510 <p> |
|
511 <label> |
|
512 <?php _e('Number of gigs to show on the sidebar:', $gcd) ?> |
|
513 <input type="text" size="5" name="gigs_length" value="<?php echo $o['widget']['upcoming']['length']; ?>" /> |
|
514 </label> |
|
515 </p> |
|
516 <p> |
|
517 <?php _e('Note: All date formats use the PHP <a href="http://php.net/date">date()</a> function syntax', $gcd) ?> |
|
518 </p> |
|
519 <p> |
|
520 <label> |
|
521 <?php _e('Date format for dates in the current year:', $gcd) ?> |
|
522 <input type="text" size="5" name="gigs_dateFormat" value="<?php echo $o['widget']['upcoming']['dateFormat']; ?>" /> |
|
523 </label> |
|
524 </p> |
|
525 <p> |
|
526 <label> |
|
527 <?php _e('Date format for dates in a future year:', $gcd) ?> |
|
528 <input type="text" size="5" name="gigs_dateFormatYear" value="<?php echo $o['widget']['upcoming']['dateFormatYear']; ?>" /> |
|
529 </label> |
|
530 </p> |
|
531 <p> |
|
532 <label> |
|
533 <?php _e('First piece of data in the link:', $gcd) ?> |
|
534 <select name="gig-firstLinkField"> |
|
535 <?php foreach ( $linkFields as $key => $value ) : ?> |
|
536 <option value="<?php echo $key ?>" <?php if ($key == $o['widget']['upcoming']['link'][0]) echo 'selected="selected"' ?>><?php echo $value ?></option> |
|
537 <?php endforeach; ?> |
|
538 </select> |
|
539 </label> |
|
540 </p> |
|
541 <p> |
|
542 <label> |
|
543 <?php _e('Second piece of data in the link:', $gcd) ?> |
|
544 <select name="gig-secondLinkField"> |
|
545 <option value="none"><?php _e('None', $gcd) ?></option> |
|
546 <?php foreach ( $linkFields as $key => $value ) : ?> |
|
547 <option value="<?php echo $key ?>" <?php if ($key == $o['widget']['upcoming']['link'][1]) echo 'selected="selected"' ?>><?php echo $value ?></option> |
|
548 <?php endforeach; ?> |
|
549 </select> |
|
550 </label> |
|
551 </p> |
|
552 <?php |
|
553 } |
|
554 |
|
555 function widget_next($args) { |
|
556 extract($args); |
|
557 $o = get_option('gigs-calendar'); |
|
558 if ( !isset($o['widget']['next']) ) $o['widget']['next'] = array('title'=>__('Next Gig', $gcd)); |
|
559 ?> |
|
560 <?php echo $before_widget; ?> |
|
561 <?php echo $before_title . $o['widget']['next']['title'] . $after_title; ?> |
|
562 <?php |
|
563 dtc_gigs::generateList(array( |
|
564 'upcoming'=>true, |
|
565 'limit'=>1, |
|
566 'template'=>'next-widget', |
|
567 )); |
|
568 ?> |
|
569 <?php echo $after_widget; ?> |
|
570 <?php |
|
571 } |
|
572 |
|
573 function widget_next_control() { |
|
574 global $gcd; |
|
575 $o = get_option('gigs-calendar'); |
|
576 |
|
577 $defaults = array( |
|
578 'title' => __('Next Gig', $gcd), |
|
579 ); |
|
580 |
|
581 if ( !isset($o['widget']['next']) ) { |
|
582 $o['widget']['next'] = array(); |
|
583 } |
|
584 |
|
585 $o['widget']['next'] = array_merge($defaults, $o['widget']['next']); |
|
586 |
|
587 if ( isset($_POST['gigs_next_title']) ) { |
|
588 $o['widget']['next']['title'] = !empty($_POST['gigs_next_title']) ? $_POST['gigs_next_title'] : $defaults['title']; |
|
589 print_r($o['widget']); |
|
590 update_option('gigs-calendar', $o); |
|
591 } |
|
592 |
|
593 ?> |
|
594 <p> |
|
595 <label> |
|
596 <?php _e('Widget title:', $gcd) ?> |
|
597 <input type="text" size="20" name="gigs_next_title" value="<?php echo $o['widget']['next']['title']; ?>" /> |
|
598 </label> |
|
599 </p> |
|
600 <?php |
|
601 } |
|
602 |
|
603 function init() { |
|
604 global $gcd; |
|
605 load_plugin_textdomain($gcd, 'wp-content/plugins/gigs-calendar/i18n'); |
|
606 if ( function_exists('register_sidebar_widget') ) { |
|
607 register_sidebar_widget('Upcoming Gigs', array('dtc_gigs', 'widget_upcoming')); |
|
608 register_widget_control('Upcoming Gigs', array('dtc_gigs', 'widget_upcoming_control'), 360, 273); |
|
609 |
|
610 register_sidebar_widget('Next Gig', array('dtc_gigs', 'widget_next')); |
|
611 register_widget_control('Next Gig', array('dtc_gigs', 'widget_next_control'), 360, 273); |
|
612 } |
|
613 } |
|
614 |
|
615 function generateList($args = false) { |
|
616 ob_start(); |
|
617 global $wpdb, $post, $include_folder, $gcd; |
|
618 $options = get_option("gigs-calendar"); |
|
619 require_once 'gigs-classes.php'; |
|
620 $tpath = dirname(__FILE__) . '/templates/'; |
|
621 |
|
622 $folder = dtc_gigs::get_url(); |
|
623 |
|
624 $defaults = array( |
|
625 'upcoming' => true, |
|
626 'limit' => false, |
|
627 'tour' => false, |
|
628 'template' => 'gigs-list', |
|
629 'dateFormat' => ($args['upcoming'] === false ? 'archive' : 'short'), |
|
630 'force' => false, |
|
631 'year' => null, |
|
632 'month' => null, |
|
633 'caption' => null, |
|
634 ); |
|
635 |
|
636 |
|
637 $args = is_array($args) ? array_merge($defaults, $args) : $defaults; |
|
638 extract($args); |
|
639 |
|
640 $listFields = array( |
|
641 'city' => __('City', $gcd), |
|
642 'country' => __('Country', $gcd), |
|
643 'venue' => __('Venue', $gcd), |
|
644 'eventName' => __('Event', $gcd), |
|
645 'date' => __('Date', $gcd), |
|
646 'time' => __('Time', $gcd), |
|
647 'shortNotes' => __('Notes', $gcd), |
|
648 'tickets' => __('Tickets', $gcd), |
|
649 'map' => __('Map', $gcd), |
|
650 ); |
|
651 |
|
652 $show_fields = $options['gigs-table-show']; |
|
653 if ( !$upcoming && in_array( 'tickets', $show_fields ) ) { |
|
654 unset( $show_fields[array_search('tickets', $show_fields)] ); |
|
655 } |
|
656 |
|
657 $gig_ids = array(); |
|
658 if ( is_null($year) && is_null($month) ) { |
|
659 $gigs = $wpdb->get_results(' |
|
660 SELECT |
|
661 *, |
|
662 g.notes as gigNotes, |
|
663 v.notes as venueNotes, |
|
664 g.id as gigID, |
|
665 v.link as venueLink |
|
666 FROM |
|
667 `' . TABLE_GIGS . '` AS g |
|
668 LEFT JOIN |
|
669 `' . TABLE_VENUES . '` AS v ON ( g.venueID = v.id ) |
|
670 WHERE |
|
671 `date` ' . ($upcoming ? '>=' : '<=') . ' CURDATE() |
|
672 ' . (($tour && $tour != -1) ? ' AND tour_id = ' . (int) $tour : '') . ' |
|
673 ' . ($tour == -1 ? ' AND tour_id is null' : '') . ' |
|
674 ORDER BY |
|
675 `date` ' . ($upcoming ? 'ASC' : 'DESC') . ' |
|
676 ' . ( !empty($limit) ? ' LIMIT ' . $limit : '' ) . ' |
|
677 |
|
678 '); |
|
679 } else { |
|
680 $gigs = $wpdb->get_results(' |
|
681 SELECT |
|
682 *, |
|
683 g.notes as gigNotes, |
|
684 v.notes as venueNotes, |
|
685 g.id as gigID, |
|
686 v.link as venueLink |
|
687 FROM |
|
688 `' . TABLE_GIGS . '` AS g |
|
689 LEFT JOIN |
|
690 `' . TABLE_VENUES . '` AS v ON ( g.venueID = v.id ) |
|
691 WHERE |
|
692 1=1 |
|
693 ' . ( !is_null($year) ? 'AND YEAR(`date`) = ' . (int) $year : '' ) . ' |
|
694 ' . ( !is_null($month) ? 'AND MONTH(`date`) = ' . (int) $month : '' ) . ' |
|
695 ' . (($tour && $tour != -1) ? ' AND tour_id = ' . (int) $tour : '') . ' |
|
696 ' . ($tour == -1 ? ' AND tour_id is null' : '') . ' |
|
697 ORDER BY |
|
698 `date` ' . ($upcoming ? 'ASC' : 'DESC') . ' |
|
699 ' . ( !empty($limit) ? ' LIMIT ' . $limit : '' ) . ' |
|
700 |
|
701 '); |
|
702 } |
|
703 |
|
704 if ( $tour !== false && $tour !== "false" ) { |
|
705 if ( !count($gigs) && !$options['tours-empty'] && !$force ) { |
|
706 return ''; |
|
707 } |
|
708 if ( $t != -1 && empty($caption) ) { |
|
709 $t = new tour($tour); |
|
710 $caption = '<div class="name">' . $t->name . '</div><div class="notes">' . $t->notes . '</div>'; |
|
711 } |
|
712 } |
|
713 |
|
714 |
|
715 $performances = $wpdb->get_results(' |
|
716 SELECT |
|
717 p.* |
|
718 FROM |
|
719 `' . TABLE_GIGS . '` AS g |
|
720 LEFT JOIN |
|
721 `' . TABLE_PERFORMANCES . '` AS p ON ( g.id = p.gigID ) |
|
722 ORDER BY |
|
723 `time` ASC |
|
724 '); |
|
725 |
|
726 foreach ( $gigs as $key => $g ) { |
|
727 if ( empty($g->venueID) ) { |
|
728 $g->mapLink = false; |
|
729 } else { |
|
730 $g->mapLink = dtcGigs::mapLink($g); |
|
731 } |
|
732 $g->cityState = $g->city . ( empty($g->state) ? '' : ', ' . $g->state ); |
|
733 $g->cityStateCountry = $g->city . ( empty($g->state) ? '' : ', ' . $g->state ) . ( empty($g->country) ? '' : ', ' . $g->country ); |
|
734 $g->cityCountry = $g->city . ( empty($g->country) ? '' : ', ' . $g->country ); |
|
735 $g->permalink = get_permalink($g->postID); |
|
736 $g->shortDate = dtcGigs::dateFormat($g->date, 'short'); |
|
737 $g->longDate = dtcGigs::dateFormat($g->date, 'long'); |
|
738 $g->archiveDate = dtcGigs::dateFormat($g->date, 'archive'); |
|
739 $g->mysqlDate = $g->date; |
|
740 $g->date = dtcGigs::dateFormat($g->date, $dateFormat); |
|
741 $g->id = $g->gigID; |
|
742 $g->id = $g->gigID; |
|
743 $g->performances = array(); |
|
744 $g->tags_slugs = array(); |
|
745 $g->tags = function_exists('wp_get_post_tags') ? wp_get_post_tags($g->postID) : array(); |
|
746 $gig_ids[$g->gigID] = $key; |
|
747 foreach ( $g->tags as $tagkey => $tag ) { |
|
748 $g->tags[$tagkey] = $tag->name; |
|
749 $g->tags_slugs[$tagkey] = 'gc-' . $tag->slug; |
|
750 } |
|
751 $g->custom = get_post_custom($g->postID); |
|
752 $gigs[$key] = $g; |
|
753 } |
|
754 |
|
755 foreach ( $performances as $p ) { |
|
756 $p->time_12h = dtcGigs::timeFormat($p->time, '12h'); |
|
757 $p->time_24h = dtcGigs::timeFormat($p->time, '24h'); |
|
758 $p->time = dtcGigs::timeFormat($p->time); |
|
759 |
|
760 if ( isset($gigs[$gig_ids[$p->gigID]]) ) { |
|
761 $gigs[$gig_ids[$p->gigID]]->performances[] = $p; |
|
762 } |
|
763 } |
|
764 |
|
765 if ( is_file(dirname(__FILE__) . '/templates/' . $options['template'] . '/' . $template . '.php') ) { |
|
766 include(dirname(__FILE__) . '/templates/' . $options['template'] . '/' . $template . '.php'); |
|
767 } elseif ( is_file(ABSPATH . 'wp-content/gigs-templates/' . $options['template'] . '/' . $template . '.php') ) { |
|
768 include(ABSPATH . 'wp-content/gigs-templates/' . $options['template'] . '/' . $template . '.php'); |
|
769 } else { |
|
770 include(dirname(__FILE__) . '/templates/' . 'basic/' . $template . '.php'); |
|
771 } |
|
772 $result = ob_get_clean(); |
|
773 if ( $return ) return $result; |
|
774 else echo $result; |
|
775 } |
|
776 |
|
777 function upcomingList($args = array()) { |
|
778 // This method has been depriciated. Stop using it! |
|
779 global $include_folder; |
|
780 $o = get_option('gigs-calendar'); |
|
781 $defaults = array( |
|
782 "length" => 5, |
|
783 "dateFormat" => 'M j', |
|
784 'dateFormatYear' => 'M j, Y', |
|
785 'link' => array('city'), |
|
786 'return' => false, |
|
787 ); |
|
788 |
|
789 |
|
790 $args = array_merge($defaults, $args); |
|
791 |
|
792 include_once 'gigs-classes.php'; |
|
793 $g = new gig(); |
|
794 $g->search('`date` >= CURDATE()', '`date` ASC'); |
|
795 |
|
796 $count = 0; |
|
797 if ( $g->_count ) : |
|
798 |
|
799 ?> |
|
800 <ul class="gigs"> |
|
801 <?php while ( $g->fetch() ) : |
|
802 $v = $g->getVenue(); |
|
803 $p = $g->getPerformances(); |
|
804 $link = array(); |
|
805 foreach ( $args['link'] as $f ) { |
|
806 switch ( $f ) { |
|
807 case 'city': |
|
808 $link[] = $v->getCity(); |
|
809 break; |
|
810 case 'venue': |
|
811 $link[] = $v->name; |
|
812 break; |
|
813 case 'eventName': |
|
814 $link[] = $g->eventName; |
|
815 break; |
|
816 } |
|
817 } |
|
818 $link = array_unique($link); |
|
819 foreach ( $link as $key => $value ) { |
|
820 if ( empty($value) ) unset($link[$key]); |
|
821 } |
|
822 ?> |
|
823 |
|
824 <li class="<?php echo implode(' ', $g->getTags(true)); ?>"><?php echo date((date('Y') == date('Y', strtotime($g->date))) ? $args['dateFormat'] : $args['dateFormatYear'], strtotime($g->date . ' ' . $p->time)) ?>: <a href="<?php echo $g->getPermalink(); ?>"> |
|
825 <?php echo implode(' - ', $link) ?> |
|
826 </a></li> |
|
827 <?php if ( ++$count >= $args['length'] ) break; endwhile; ?> |
|
828 </ul> |
|
829 <?php |
|
830 else : |
|
831 ?> |
|
832 <div class="no-gigs"><?php echo $o['no-upcoming']; ?></div> |
|
833 <?php |
|
834 endif; |
|
835 } |
|
836 |
|
837 function test($posts) { |
|
838 global $wp_query; |
|
839 |
|
840 //print_r($wp_query); |
|
841 |
|
842 return $posts; |
|
843 } |
|
844 |
|
845 function setup_future_hook() { |
|
846 $o = get_option('gigs-calendar'); |
|
847 if ( $o['post-filtering'] ) { |
|
848 remove_action('future_post', '_future_post_hook'); |
|
849 add_action('future_post', array('dtc_gigs', 'publish_future_post_now')); |
|
850 } |
|
851 } |
|
852 |
|
853 function publish_future_post_now($id, $post = null) { |
|
854 global $wpdb; |
|
855 if ( $wpdb->get_var('SELECT COUNT(*) FROM ' . TABLE_GIGS . ' WHERE postID = ' . (int) $id ) ) { |
|
856 wp_publish_post($id); |
|
857 } else { |
|
858 _future_post_hook($id, $post); |
|
859 } |
|
860 } |
|
861 } |
|
862 |
|
863 |
|
864 |
|
865 add_action('init', array('dtc_gigs', 'setup_future_hook')); |
|
866 add_action('admin_menu', array('dtc_gigs', 'add_admin_page')); |
|
867 |
|
868 //add_filter('the_posts', array('dtc_gigs', 'test')); |
|
869 |
|
870 if ( 4.1 <= mysql_get_server_info() ) { |
|
871 add_filter('posts_where', array('dtc_gigs', 'hide_posts')); |
|
872 add_filter('get_next_post_where', array('dtc_gigs', 'post_nav')); |
|
873 add_filter('get_previous_post_where', array('dtc_gigs', 'post_nav')); |
|
874 add_filter('getarchives_where', array('dtc_gigs', 'hide_archives')); |
|
875 } else { |
|
876 |
|
877 } |
|
878 |
|
879 add_filter('the_content', array('dtc_gigs', 'display')); |
|
880 |
|
881 add_action('plugins_loaded', array('dtc_gigs', 'init')); |
|
882 |
|
883 |
|
884 if ( $_GET['page'] == 'gigs' ) : |
|
885 // If not WP > 2.6, we'll need to include some custom scripts. |
|
886 $folder = dtc_gigs::get_url(); |
|
887 if ( (float) $wp_version < 2.6 ) { |
|
888 wp_deregister_script('jquery'); |
|
889 wp_deregister_script('interface'); |
|
890 wp_deregister_script('jquery-form'); |
|
891 wp_enqueue_script('jquery', $folder . 'js/jquery.js', array(), '1.2.6'); |
|
892 wp_enqueue_script('jquery-form', $folder . 'js/jquery.form.js', array(), '2.02'); |
|
893 wp_enqueue_script('jquery-ui-core', $folder . 'js/ui.core.js', array(), '1.5'); |
|
894 wp_enqueue_script('jquery-ui-sortable', $folder . 'js/ui.sortable.js', array(), '1.5'); |
|
895 } else { |
|
896 wp_enqueue_script('jquery'); |
|
897 wp_enqueue_script('jquery-form'); |
|
898 wp_enqueue_script('jquery-ui-core'); |
|
899 wp_enqueue_script('jquery-ui-sortable'); |
|
900 } |
|
901 wp_enqueue_script('jquery-ui-datepicker', $folder . 'js/ui.datepicker.min.js', array(), '1.5'); |
|
902 wp_enqueue_script('jquery-tooltip', $folder . 'js/jquery.tooltip.min.js', array(), '1.2'); |
|
903 |
|
904 add_action('admin_head', array('dtc_gigs', 'admin_css')); |
|
905 |
|
906 if ( get_option('gig_db_version') != DTC_GIGS_DB_VERSION ) { |
|
907 dtc_gigs::upgrade(); |
|
908 } |
|
909 |
|
910 endif; |
|
911 |
|
912 add_action('wp_head', array('dtc_gigs', 'display_css')); |
|
913 else: |
|
914 require_once $include_folder . '/ajaxSetup.php'; |
|
915 endif; |
|
916 |
|
917 ?> |