PluginProbe
Jock On Air Now (JOAN) / 5.1
Jock On Air Now (JOAN) v5.1
4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 5.0 5.1 5.2.0 5.3.0 5.4.0 5.5.0 5.5.1 5.5.2 5.5.3 5.5.4 5.5.6 5.5.7 5.5.8 5.5.9 5.6 5.6.1 5.6.2 5.6.3 5.6.4 All 77 releases
joan / joan.php

joan.php in Jock On Air Now (JOAN) 5.1, at joan.php

608 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Jock On Air Now
4 Plugin URI: https://gandenterprisesinc.com/jock-on-air-now/
5 Description: JOAN allows you to create, manage and display your station's programming schedule quite easily. After install use the widget to display the current show/Jock on air, display full station schedule by inserting the included shortcode into posts or pages. Create a new page, name it schedule or whatever you like place the schedule shortcode on it, add to your menu to display your full schedule.
6 Author: G n D Enterprises, Inc.
7 Version: 5.1
8 Author URI: https://www.gandenterprisesinc.com
9
10 Get Joan Premium
11
12 *Priority Support
13 *Schedule Import
14 *Multi-site support
15 *Easily ‘duplicate’ show schedules (Repeating shows)
16 *Set a shows’ status
17 *Weekly, Biweekly or Monthly Schedule
18 *Edit existing show time
19 *Custom CSS field
20
21 Premium Support and more. <a href="https://gandenterprisesinc.com/pricing/"</a>
22
23 */
24
25 if (!defined('ABSPATH')) {
26 exit("Sorry, you are not allowed to access this page directly.");
27 }
28
29 /* Set constant for plugin directory */
30 define( 'SS3_URL', WP_PLUGIN_URL.'/joan' );
31
32 $joan_db_version = "3.1.1";
33
34 if (!isset($wpdb))
35 $wpdb = $GLOBALS['wpdb'];
36
37 $joanTable = $wpdb->prefix . "WPJoan";
38
39 $tz = get_option('timezone_string');
40 date_default_timezone_set($tz);
41
42 //Installation
43 function joan_install () {
44 global $wpdb;
45 global $joan_db_version;
46 global $joanTable;
47
48 $joanTable = $wpdb->prefix . "WPJoan";
49
50 if($wpdb->get_var("show tables like '$joanTable'") != $joanTable) {
51
52 $sql = "CREATE TABLE " . $joanTable . " (
53 id int(9) NOT NULL AUTO_INCREMENT,
54 dayOfTheWeek text NOT NULL,
55 startTime int(11) NOT NULL,
56 endTime int(11) NOT NULL,
57 startClock text not null,
58 endClock text not null,
59 showName text NOT NULL,
60 linkURL text NOT null,
61 imageURL text not null,
62 UNIQUE KEY id (id)
63 );";
64
65 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
66 dbDelta($sql);
67
68 add_option("joan_db_version", $joan_db_version);
69 }
70 }
71
72 register_activation_hook(__FILE__,'joan_install');
73
74 //Register and create the Widget
75
76 class JoanWidget extends WP_Widget {
77
78 /**
79 * Declares the JoanWidget class.
80 *
81 */
82 function __construct(){
83 $widget_ops = array('classname' => 'joan_widget', 'description' => __( "Display your schedule with style.") );
84 $control_ops = array('width' => 300, 'height' => 300);
85 parent::__construct( 'Joan', __( 'Joan', 'joan' ), $widget_ops, $control_ops );
86 }
87
88 /**
89 * Displays the Widget
90 *
91 */
92 function widget($args, $instance){
93
94 extract($args);
95 $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title']);
96
97 # Before the widget
98 echo $before_widget;
99
100 # The title
101 if ( $title )
102 echo $before_title . $title . $after_title;
103
104 # Make the Joan widget
105 echo showme_joan();
106
107 # After the widget
108 echo $after_widget;
109 }
110
111 /**
112 * Saves the widgets settings.
113 *
114 */
115 function update($new_instance, $old_instance){
116 $instance = $old_instance;
117 $instance['title'] = strip_tags(stripslashes($new_instance['title']));
118 $instance['lineOne'] = strip_tags(stripslashes($new_instance['lineOne']));
119 $instance['lineTwo'] = strip_tags(stripslashes($new_instance['lineTwo']));
120
121 return $instance;
122 }
123
124 /**
125 * Creates the edit form for the widget.
126 *
127 */
128 function form($instance){
129 //Defaults
130 $instance = wp_parse_args( (array) $instance, array('title'=>'On Air Now') );
131
132 $title = htmlspecialchars($instance['title']);
133
134 # Output the options
135 echo '<p style="text-align:right;"><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input style="width: 250px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';
136 }
137 } //End of widget
138
139
140 function JoanInit() {
141 register_widget('JoanWidget');
142 }
143 add_action('widgets_init', 'JoanInit');
144
145
146 //==== OPTIONS ====
147 add_option('joan_upcoming', 'yes');
148 add_option('joan_use_images', 'yes');
149 add_option('joan_shutitdown', 'no');
150 add_option('off_air_message', 'We are currently off the air.');
151 add_option('joan_css', '');
152 add_option('joan_shutitdown', 'no');
153
154
155 //==== SHORTCODES ====
156
157 function joan_schedule_handler($atts, $content=null, $code=""){
158
159 if (!isset($wpdb)) $wpdb = $GLOBALS['wpdb'];
160 global $wpdb;
161 global $joanTable;
162
163 //Get the current schedule, divided into days
164 $daysOfTheWeek = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
165
166 $schedule = array();
167
168 $output = '';
169
170 foreach ($daysOfTheWeek as $day) {
171 if (!isset($wpdb)) $wpdb = $GLOBALS['wpdb'];
172 //Add this day's shows HTML to the $output array
173 $showsForThisDay = $wpdb->get_results( $wpdb->prepare ( "SELECT * FROM $joanTable WHERE dayOfTheWeek = %s ORDER BY startTime", $day ));
174
175 //Check to make sure this day has shows before saving the header
176 if ($showsForThisDay){
177 $output .= '<h2>'.$day.'</h2>';
178 $output .= '<ul class="joan-schedule">';
179 foreach ($showsForThisDay as $show){
180 $showName = $show->showName;
181 $startClock = $show->startClock;
182 $endClock = $show->endClock;
183 $linkURL = $show->linkURL;
184
185 if ($linkURL){
186 $showName = '<a href="'.$linkURL.'">'.$showName.'</a>';
187 }
188
189 $output .= '<li><strong>'.$startClock.'</strong> - <strong>'.$endClock.'</strong>: '.$showName.'</li>';
190
191 }
192 $output .= '</ul>';
193 }
194 }
195 return $output;
196 }
197
198 add_shortcode('joan-schedule', 'joan_schedule_handler');
199
200 //Henry custom stuff
201 function joan_schedule_today($atts, $content=null, $code=""){
202
203 global $wpdb;
204 global $joanTable;
205
206 //Get the current schedule, divided into days
207 $daysOfTheWeek = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
208
209 $today = date('l');
210
211 $schedule = array();
212
213 $output = '';
214
215 foreach ($daysOfTheWeek as $day) {
216 //Add this day's shows HTML to the $output array
217 $showsForThisDay = $wpdb->get_results( $wpdb->prepare ( "SELECT * FROM $joanTable WHERE dayOfTheWeek = %s ORDER BY startTime", $day ));
218
219 if ($day == $today) {
220
221 //Check to make sure this day has shows before saving the header
222 if ($showsForThisDay){
223 $output .= '<h2 class="widget-title">What\'s On Today - '.$today.'</h2>';
224 $output .= '<ul class="joan-schedule">';
225 foreach ($showsForThisDay as $show){
226 $showName = $show->showName;
227 $startClock = $show->startClock;
228 $endClock = $show->endClock;
229 $linkURL = $show->linkURL;
230 if ($linkURL){
231 $showName = '<a href="'.$linkURL.'">'.$showName.'</a>';
232 }
233 $output .= '<li><span class="show-time">'.$startClock./*' - '.$endClock.*/':</span> <span class="show-name">'.$showName.'</span></li>';
234 }
235 $output .= '</ul>';
236 }
237 }
238 }
239 return $output;
240 }
241
242 add_shortcode('schedule-today', 'joan_schedule_today');
243
244 //End Henry custom stuff
245
246 function showme_joan(){
247
248 $output = '<style>'.get_option('joan_css', '').'</style>';
249 $output .= '<div class="joan-now-playing"></div>';
250 return $output;
251
252 }
253
254 add_shortcode('joan-now-playing', 'showme_joan');
255
256
257 if ( is_admin() ){ // admin actions
258 add_action('admin_menu', 'joan_plugin_menu');
259 }
260
261
262 function joan_image_upload_scripts() {
263 wp_enqueue_script('media-upload');
264 wp_enqueue_script('thickbox');
265 wp_enqueue_script('my-upload');
266 }
267
268 function joan_image_upload_styles() {
269 wp_enqueue_style('thickbox');
270 }
271
272 if (isset($_GET['page']) && $_GET['page'] == 'joan_settings') {
273 add_action('admin_print_scripts', 'joan_image_upload_scripts');
274 add_action('admin_print_styles', 'joan_image_upload_styles');
275 }
276
277 //==== ADMIN OPTIONS AND SCHEDULE PAGE ====
278
279 function joan_plugin_menu() {
280 global $pagenow;
281 // Add a new submenu under Options:
282 add_menu_page('JOAN', 'Jock On Air Now', 'activate_plugins', 'joan_settings', 'joan_options_page');
283
284 // Modified by PHP Stack
285 if ($pagenow == 'admin.php' && isset($_GET['page'])) {
286 if ($_GET['page'] == 'joan_settings') {
287 wp_enqueue_style( "joan-admin", plugins_url('admin.css', __FILE__) );
288 wp_enqueue_script( "joan-admin", plugins_url('admin.js', __FILE__), array('jquery'), '1.0.0', true );
289 }
290 }
291 }
292
293 function joan_options_page(){
294 if (!isset($wpdb)) $wpdb = $GLOBALS['wpdb'];
295 global $wpdb;
296 global $joanTable;
297 //Check to see if the user is upgrading from an old Joan database
298
299 if (isset($_POST['upgrade-database'])){
300 if (check_admin_referer('upgrade_joan_database', 'upgrade_joan_database_field')){
301
302 if ($wpdb->get_var("show tables like '$joanTable'") != $joanTable){
303 $sql = "CREATE TABLE " . $joanTable . " (
304 id int(9) NOT NULL AUTO_INCREMENT,
305 dayOfTheWeek text NOT NULL,
306 startTime int(11) NOT NULL,
307 endTime int(11) NOT NULL,
308 startClock text not null,
309 endClock text not null,
310 showName text NOT NULL,
311 linkURL text NOT null,
312 imageURL text not null,
313 UNIQUE KEY id (id)
314 );";
315
316 $wpdb->query($sql);
317 }
318
319 $joanOldTable = $wpdb->prefix.'joan';
320
321 $oldJoanShows = $wpdb->get_results($wpdb->prepare("SELECT id, showstart, showend, showname, linkUrl, imageUrl FROM $joanOldTable WHERE id != %d", -1));
322 if ($oldJoanShows){
323 foreach ($oldJoanShows as $show){
324 $showname = $show->showname;
325 $startTime = $show->showstart;
326 $endTime = $show->showend;
327 $startDay = date('l', $startTime);
328 $startClock = date('g:i a', ($startTime));
329 $endClock = date('g:i a', ($endTime));
330 $linkURL = $show->linkUrl;
331 if ($linkURL == 'No link specified.'){
332 $linkURL = '';
333 }
334 $imageURL = $show->imageUrl;
335
336 //Insert the new show into the New Joan Databse
337 $wpdb->query( $wpdb->prepare("INSERT INTO $joanTable (dayOfTheWeek, startTime,endTime,startClock, endClock, showName, imageURL, linkURL) VALUES (%s, %d, %d , %s, %s, %s, %s, %s)", $startDay, $startTime, $endTime, $startClock, $endClock, $showname, $imageURL, $linkURL ) );
338 }
339 }
340 }
341 //Remove the old Joan table if the new table has been created
342 if($wpdb->get_var("show tables like '$joanTable'") == $joanTable) {
343 $wpdb->query("DROP TABLE $joanOldTable");
344 }
345 }
346
347 // echo '<script type="text/javascript" src="'.SS3_URL.'/admin.js" ></script>';
348
349 ?>
350 <div class="wrap">
351 <div class="joan-message-window">Message goes here.</div>
352 <h1>Jock On Air Now</h1>
353 <p><em>Let your listeners know when their favorite jock/show is on or about to come on.</em><br /><small>by <a href='http://www.gandenterprisesinc.com' target='_blank'>G and D Enterprises, Inc.</a></small></p>
354
355 <?php
356 //Check to see if Joan 2.0 is installed
357 $table_name = $wpdb->prefix . "joan";
358 if($wpdb->get_var("show tables like '$table_name'") == $table_name) {
359 ?>
360 <div class="error">
361 <form method="post" action="">
362 <p><strong>Previous version of Joan detected.</strong> Be sure to back up your database before performing this upgrade. <input type="submit" class="button-primary" value="Upgrade my Joan Database" /></p>
363 <input type="hidden" name="upgrade-database" value=' ' />
364 <?php wp_nonce_field('upgrade_joan_database', 'upgrade_joan_database_field'); ?>
365 </form>
366 </div>
367 <?php
368 }
369
370 ?>
371
372 <input type="hidden" class="script-src" readonly="readonly" value="<?= $_SERVER['PHP_SELF']; ?>?page=joan_settings" />
373 <?php wp_nonce_field('delete_joan_entry', 'delete_entries_nonce_field'); ?>
374
375 <ul class="tab-navigation">
376 <li class="joan-scheudle">Schedule</li>
377 <li class="joan-options">Options</li>
378 <li class="shut-it-down" style="border:none;">Suspend</li>
379 </ul>
380 <div class="joan-tabs">
381
382 <div class="tab-container" id="joan-schedule">
383
384 <h2>Schedule: Add New Shows To Schedule or Edit Existing Show Schedule</h2>
385
386
387 <div class="add-new-entry">
388
389 <form id="add-joan-entry" method="post" action="<?php echo get_admin_url()?>admin-ajax.php">
390 <input type='hidden' name='action' value='show-time-curd' />
391 <div class="set-joan-show-deets">
392 <div class="show-time-container">
393 <h3>Show Start</h3>
394 <label for="start">
395 <select class="startDay" name="sday">
396 <option value="Sunday">Sunday</option>
397 <option value="Monday">Monday</option>
398 <option value="Tuesday">Tuesday</option>
399 <option value="Wednesday">Wednesday</option>
400 <option value="Thursday">Thursday</option>
401 <option value="Friday">Friday</option>
402 <option value="Saturday">Saturday</option>
403 </select>
404 </label>
405
406 <label for="starttime">
407 <input id="starttime" class="text" name="startTime" size="5" maxlength="5" type="text" value="00:00" /></label>
408 </div>
409 <div class="show-time-container">
410 <h3>Show End</h3>
411 <label for="endday">
412 <select class="endDay" name="eday">
413 <option value="Sunday">Sunday</option>
414 <option value="Monday">Monday</option>
415 <option value="Tuesday">Tuesday</option>
416 <option value="Wednesday">Wednesday</option>
417 <option value="Thursday">Thursday</option>
418 <option value="Friday">Friday</option>
419 <option value="Saturday">Saturday</option>
420 </select>
421 </label>
422
423 <label for="endtime">
424 <input id="endtime" class="text" name="endTime" size="5" maxlength="5" type="text" value="00:00" /></label>
425 </div>
426 <div class="clr"></div>
427 <p><strong>Be sure to use 24 hour time format (01:00 = 1 AM, 13:00 = 1 PM)</strong></p>
428 <p>Also, make sure your <a href="/wp-admin/options-general.php">timezone <strong>city</strong></a> is set appropriately.(Select the city name the best matches your local time(Not the UTC)<br/>
429 <small><em>Current timezone: <?php if (get_option('timezone_string') == '') { echo '<strong style="color:red;">Set your <a href="options-general.php">timezone</a> city now.</strong></em></small></p>'; } else { echo get_option('timezone_string'); ?></em></small></p>
430
431 </div>
432 <div class="set-joan-show-deets">
433 <label for="showname"><h3>Show Details</h3></label>
434 <p>Name: <br/>
435 <input id="showname" type="text" name="showname" class="show-detail" />
436 </p>
437
438 <p>Link URL (optional):<br />
439 <label for="linkUrl">
440
441 <input type="text" name="linkUrl" placeholder="No URL specified." class="show-detail" />
442
443 </p>
444
445 <p id="primary-image"></p>
446 <p><input class="image-url" type="hidden" name="imageUrl" data-target-field-name="new show" value=""/></p>
447 <p><input type="button" class="upload-image button" data-target-field="new show" value="Upload Image" /></p>
448 <img src="" style="display:none;" data-target-field-name="new show" />
449 <p><a id="remove-primary-image" href="#"><small>Remove Image</small></a></p>
450
451
452 <input type="submit" class="button-primary" style="cursor: pointer;" value="Add Show" />
453 <input type="hidden" name="crud-action" value="create" />
454 <?php wp_nonce_field('add_joan_entry', 'joan_nonce_field'); ?>
455
456 <?php } ?>
457
458 </div>
459 </form>
460
461 <div class="clr"></div>
462
463 </div>
464
465 <h3>Current Schedule</h3>
466
467 <p>Edit Schedule: <a href="#" class="display-toggle full-display">Expanded</a> | <a href="#" class="display-toggle simple-display">Retract</a></p>
468
469 <form method="post" action="<?php echo get_admin_url()?>admin-ajax.php" class="joan-update-shows">
470 <input type='hidden' name='action' value='show-time-curd' />
471 <div class="joan-schedule loading">
472 <div class="sunday-container"><h2>Sunday</h2></div><!-- end this day of the week -->
473 <div class="monday-container"><h2>Monday</h2></div><!-- end this day of the week -->
474 <div class="tuesday-container"><h2>Tuesday</h2></div><!-- end this day of the week -->
475 <div class="wednesday-container"><h2>Wednesday</h2></div><!-- end this day of the week -->
476 <div class="thursday-container"><h2>Thursday</h2></div><!-- end this day of the week -->
477 <div class="friday-container"><h2>Friday</h2></div><!-- end this day of the week -->
478 <div class="saturday-container"><h2>Saturday</h2></div><!-- end this day of the week -->
479 </div>
480 <input type="hidden" name="crud-action" value="update" />
481 <?php wp_nonce_field('save_joan_entries', 'joan_entries_nonce_field'); ?>
482
483 </form>
484
485 <p>Edit Schedule: <a href="#" class="display-toggle full-display">Expanded</a> | <a href="#" class="display-toggle simple-display">Retract</a></p>
486
487
488 </div>
489
490 <div class="tab-container" id="joan-options">
491 <form method="post" action="">
492 <h2>Select Options Below</h2>
493 <?php
494
495 //Save posted options
496
497 if (isset($_POST['joan_options'])){
498
499
500 update_option('joan_upcoming', $_POST['joan_options']['showUpcoming']);
501 update_option('joan_use_images', $_POST['joan_options']['imagesOn']);
502 update_option('off_air_message', htmlentities(stripslashes($_POST['joan_options']['offAirMessage'])));
503 update_option('joan_css', htmlentities(stripslashes($_POST['joan_options']['joanCSS'])));
504
505 } else if (isset($_POST['shut-it-down'])) {
506 update_option('joan_shutitdown', $_POST['shut-it-down']);
507 }
508
509 //Set options variables
510 $showUpcoming = get_option('joan_upcoming');
511 $imagesOn = get_option('joan_use_images');
512 $shutItDown = get_option('joan_shutitdown');
513 $offAirMessage = get_option('off_air_message');
514 $joanCSS = get_option('joan_css');
515 $shutItDown = get_option('joan_shutitdown');
516
517 ?>
518
519 <h3>Display Images</h3>
520 <form id="option" method="post" action="">
521 <p>Show accompanying images with joans?</p>
522 <label><input type="radio"<?php if($imagesOn == 'yes') { ?> checked="checked"<?php } ?> name="joan_options[imagesOn]" value="yes" /> : Yes</label><br/>
523 <label><input type="radio"<?php if($imagesOn == 'no') { ?> checked="checked"<?php } ?> name="joan_options[imagesOn]" value="no" /> : No</label><br/>
524
525
526 <h3>Upcoming Timeslot</h3>
527
528 <p>Show the name/time of the next timeslot?</p>
529 <label><input type="radio"<?php if($showUpcoming == 'yes') { ?> checked="checked"<?php } ?> name="joan_options[showUpcoming]" value="yes" /> : Yes</label><br/>
530 <label><input type="radio"<?php if($showUpcoming == 'no') { ?> checked="checked"<?php } ?> name="joan_options[showUpcoming]" value="no" /> : No</label><br/>
531
532
533 <h3>Off Air Message</h3>
534 <label>Message:<br /><input type="text" id="off-air-message" value="<?= $offAirMessage; ?>" name="joan_options[offAirMessage]" size="40" /></label>
535
536
537 <p class="submit">
538 <input type="submit" class="button-primary" value="Save Changes" />
539 </p>
540
541 <h2>Display Shortcodes</h2>
542 <h3>[joan-schedule]</h3>
543 <p>Display a list of the times and names of your events, broken down weekly, example:</p>
544 <div style="margin-left:30px;">
545 <h4>Mondays</h4>
546 <ul>
547 <li><strong>5:00 am - 10:00 am</strong> - Morning Ride</li>
548 <li><strong>10:00 am - 12:00 pm</strong> - The Vibe with MarkD</li>
549 </ul>
550 <h4>Saturdays</h4>
551 <ul>
552 <li><strong>10:00 am - 1:00 am</strong> - Drive Time</li>
553 <li><strong>1:00 pm - 4:00 pm</strong> - Kool Jamz</li>
554 </ul>
555 </div>
556 <h3>[joan-now-playing]</h3>
557 <p>Display the Current Show/jock widget.</p>
558 <h3>[schedule-today]</h3>
559 <p>Automatically display your schedule for each day of the week.</p>
560
561 <div class="clr"></div>
562
563
564 </div>
565
566 <div class="tab-container" id="joan-shut-it-down">
567
568 <h2>Temporarily Suspend schedule</h2>
569
570 <form method="post" action="">
571 <p>You can temporarily take down your schedule for any reason, during schedule updates, public holidays or station off-air periods etc.</p>
572 <label><input type="radio"<?php if($shutItDown == 'yes') { ?> checked="checked"<?php } ?> name="shut-it-down" value="yes" /> : Suspend Schedule.</label><br/>
573 <label><input type="radio"<?php if($shutItDown == 'no') { ?> checked="checked"<?php } ?> name="shut-it-down" value="no" /> : Show Current On Air Schedule (Default). </label><br/>
574
575 <p class="submit">
576 <input type="submit" class="button-primary" value="Save changes" />
577 </p>
578 </form>
579
580 </div>
581
582 </div><!-- end the joan tabs -->
583
584 </div>
585
586 <?php
587
588 }
589
590 function joan_header_scripts(){
591
592
593 echo '<script>crudScriptURL = "'.get_admin_url().'admin-ajax.php"</script>';
594 wp_enqueue_script( "joan-front", plugins_url('joan.js', __FILE__), array(), '1.0.0', true );
595
596
597 }
598
599 add_action("wp_head","joan_header_scripts");
600 add_action('wp_ajax_show-time-curd', '_handle_form_action');
601 add_action('wp_ajax_nopriv_show-time-curd', '_handle_form_action');
602
603 function _handle_form_action(){
604
605 include( plugin_dir_path( __FILE__ ) . 'crud.php' );
606
607 die(); // this is required to return a proper result
608 }