Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Defines the default variables that will be used throughout the plugin
- */
- $djwp_defaults = apply_filters('djwp_defaults', array(
- 'header_text' => 'On-Air Now',
- 'img_width' => 250,
- 'img_height' => 250,
- 'time_zone' => 'America/Chicago'
- ));
- /**
- * Pull the settings from the DB
- */
- $djwp_images = get_option('djwp_images');
- $djwp_settings = wp_parse_args(get_option('djwp_settings'), $djwp_defaults);
- /**
- * The following section registers settings, adds a link to the options page, and a link
- * on the plugin page to "settings"
- */
- add_action('admin_init', 'djwp_register_settings');
- function djwp_register_settings()
- {
- register_setting('djwp_images', 'djwp_images');
- register_setting('djwp_settings', 'djwp_settings');
- }
- add_action('admin_menu', 'add_djwp_menu');
- function add_djwp_menu()
- {
- add_menu_page('DJ Schedule', 'DJ Schedule', 'manage_options', 'dj-rotator', 'djwp_admin_page');
- }
- function djwp_make_filename_hash($filename)
- {
- $info = pathinfo($filename);
- $ext = empty($info['extension']) ? '' : '.' . $info['extension'];
- $name = basename($filename, $ext);
- return md5($name . time()) . $ext;
- }
- /**
- * This function is the code that gets loaded when the settings page gets loaded by the browser.
- * It calls functions that handle image uploads and image settings changes, as well as producing the visible page output.
- */
- function djwp_admin_page()
- {
- echo '<div class="wrap">';
- // If action not set then set it to no value
- if (!isset($_REQUEST['action'])) {
- $_REQUEST['action'] = "";
- }
- // handle image upload, if necessary
- if ($_REQUEST['action'] === 'wp_handle_upload') {
- djwp_handle_upload();
- }
- // delete an image, if necessary
- if (isset($_REQUEST['delete'])) {
- djwp_delete_upload($_REQUEST['delete']);
- }
- // the image management form
- djwp_images_admin();
- echo '</div>';
- }
- /**
- * This section handles uploading images, adding the image data to the database, deleting images, and deleting image data from the database.
- */
- function djwp_handle_upload()
- {
- global $djwp_settings, $djwp_images;
- // randomize the file upload name!
- $_FILES['djwp']['name'] = djwp_make_filename_hash($_FILES['djwp']['name']);
- // Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, and moving the file to the appropriate directory within the uploads directory.
- $upload = wp_handle_upload($_FILES['djwp'], 0);
- //(string) The local path to the uploaded file.
- $localFilePath = $upload['file'];
- // (string) The public URL for the uploaded file.
- $publicExternalUrl = $upload['url'];
- // (string) The MIME type.
- $memeType = $upload['type'];
- // get the image dimensions
- list($width, $height) = getimagesize($localFilePath);
- // if the uploaded file is NOT an image
- if (strpos($memeType, 'image') === FALSE) {
- unlink($localFilePath); // delete the file
- echo '<div class="error" id="message"><p>Sorry, but the file you uploaded does not seem to be a valid image. Please try again.</p></div>';
- return;
- }
- // if the image doesn't meet the minimum width/height requirements ...
- if ($width < $djwp_settings['img_width'] || $height < $djwp_settings['img_height']) {
- unlink($localFilePath);
- echo '<div class="error" id="message"><p>Sorry, but this image does not meet the minimum height/width requirements. Please upload another image</p></div>';
- return;
- }
- // if the image is larger than the width/height requirements, then scale it down.
- if ($width > $djwp_settings['img_width'] || $height > $djwp_settings['img_height']) {
- // Resize the image
- $resized = wp_get_image_editor($localFilePath); // Return an implementation that extends WP_Image_Editor
- if (!is_wp_error($resized)) {
- $resized->resize($djwp_settings['img_width'], $djwp_settings['img_height'], true);
- $resized->save($localFilePath);
- }
- }
- // use the timestamp as the array key and id
- $time = date('YmdHis');
- // add the image data to the array
- $djwp_images[$time] = array(
- 'id' => $time,
- 'file' => $localFilePath,
- 'file_url' => $publicExternalUrl,
- 'image_links_to' => '',
- 'title' => 'Blank',
- 'desc' => 'Blank',
- 'monday' => false,
- 'tuesday' => false,
- 'wednesday' => false,
- 'thursday' => false,
- 'friday' => false,
- 'saturday' => false,
- 'sunday' => false,
- 'start_time' => '00:00',
- 'end_time' => '01:00',
- 'twitter_page' => '',
- 'instagram_page' => '',
- 'facebook_page' => '',
- 'image_links_to' => ''
- );
- // add the image information to the database
- update_option('djwp_images', $djwp_images);
- }
- // delete the image, and removes the image data from the db
- function djwp_delete_upload($id)
- {
- global $djwp_images;
- // if the ID passed to this function is invalid,
- // halt the process, and don't try to delete.
- if (!isset($djwp_images[$id])) {
- return;
- }
- // delete the image
- if (file_exists($djwp_images[$id]['file'])) {
- unlink($djwp_images[$id]['file']);
- }
- // remove the image data from the db
- unset($djwp_images[$id]);
- update_option('djwp_images', $djwp_images);
- }
- /**
- * Private djwp_multiSort
- *
- * @array() $data
- * @bool $isDate
- * @param $data
- * @param $sortDirection
- * @param $field
- * @param $isDate
- * @return mixed $data
- */
- function djwp_multiSort($data, $sortDirection, $field, $isDate)
- {
- if (empty($data) || !is_array($data) || count($data) < 2) {
- return $data;
- }
- $parts = explode("/", $field);
- foreach ($data as $key => $row) {
- $temp = &$row;
- foreach ($parts as $key2) {
- $temp = &$temp[$key2];
- }
- $orderByDate[$key] = ($isDate ? strtotime($temp) : $temp);
- }
- unset($temp);
- unset($parts);
- if ($sortDirection == "SORT_DESC") {
- array_multisort($orderByDate, SORT_DESC, $data);
- } else {
- array_multisort($orderByDate, SORT_ASC, $data);
- }
- unset($orderByDate);
- return $data;
- }
- /**
- * Display the DJ image settings on the options page
- */
- function djwp_images_admin()
- {
- global $djwp_images;
- ?>
- <h2><?php _e('DJ Images', 'djwp'); ?></h2>
- <table class="form-table">
- <tr valign="top">
- <th scope="row">Upload a photo</th>
- <td>
- <form enctype="multipart/form-data" method="post" action="?page=dj-rotator">
- <input type="hidden" name="post_id" id="post_id" value="0"/>
- <input type="hidden" name="action" id="action" value="wp_handle_upload"/>
- <label for="djwp">Select a File: </label>
- <input type="file" name="djwp" id="djwp"/>
- <input type="submit" class="button-primary" name="html-upload" value="Upload"/>
- </form>
- </td>
- </tr>
- </table>
- <h2><?php _e('DJ Information', 'djwp'); ?></h2>
- <form class="djform" method="post" action="options.php">
- <?php settings_fields('djwp_images'); ?>
- <table class="widefat" cellspacing="0">
- <thead>
- <tr>
- <th>DJ Image</th>
- <th scope="col">Title / Description</th>
- <th scope="col">Social</th>
- <th scope="col">Days On-Air</th>
- <th scope="col">Times</th>
- <th scope="col">Actions</th>
- </tr>
- </thead>
- <tfoot>
- <tr>
- <th scope="col">DJ Image</th>
- <th scope="col">Title / Description</th>
- <th scope="col">Social</th>
- <th scope="col">Days On-Air</th>
- <th scope="col">Times</th>
- <th scope="col">Actions</th>
- </tr>
- </tfoot>
- <tbody>
- <?php
- foreach ($djwp_images as $id => $data) {
- $data_id = isset($data['id']) ? $data['id'] : '';
- $file = isset($data['file']) ? $data['file'] : '';
- $file_url = isset($data['file_url']) ? $data['file_url'] : '';
- $desc = isset($data['desc']) ? $data['desc'] : '';
- $start_time = isset($data['start_time']) ? $data['start_time'] : '';
- $end_time = isset($data['end_time']) ? $data['end_time'] : '';
- $title = isset($data['title']) ? $data['title'] : '';
- $image_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
- $facebook_page = isset($data['facebook_page']) ? $data['facebook_page'] : '';
- $twitter_page = isset($data['twitter_page']) ? $data['twitter_page'] : '';
- $instagram_page = isset($data['instagram_page']) ? $data['instagram_page'] : '';
- // Days of the week
- $monday = isset($data['monday']) ? $data['monday'] : '';
- $tuesday = isset($data['tuesday']) ? $data['tuesday'] : '';
- $wednesday = isset($data['wednesday']) ? $data['wednesday'] : '';
- $thursday = isset($data['thursday']) ? $data['thursday'] : '';
- $friday = isset($data['friday']) ? $data['friday'] : '';
- $saturday = isset($data['saturday']) ? $data['saturday'] : '';
- $sunday = isset($data['sunday']) ? $data['sunday'] : '';
- ?>
- <tr>
- <td
- <input type="hidden" name="djwp_images[<?= $id; ?>][id]"
- value="<?= $data_id ?>"/>
- <input type="hidden" name="djwp_images[<?= $id; ?>][file]"
- value="<?= $file ?>"/>
- <input type="hidden" name="djwp_images[<?= $id; ?>][file_url]"
- value="<?= $file_url ?>"/>
- <img src="<?= $file_url ?>" width="100" height="100"/>
- </td>
- <td>
- <label>Show title</label><br/>
- <input type="text" name="djwp_images[<?= $id ?>][title]"
- value="<?= $title ?>" placeholder="Title"/><br/>
- <label>Show description</label><br/>
- <textarea name="djwp_images[<?= $id ?>][desc]" rows="5" cols="20"
- class="regular-text"/><?= $desc ?></textarea>
- </td>
- <td>
- <input type="text" name="djwp_images[<?= $id ?>][image_links_to]"
- value="<?= $image_links_to ?>" size="15"
- placeholder="Show page URL"/><br/>
- <input type="text" name="djwp_images[<?= $id ?>][twitter_page]"
- value="<?= $twitter_page ?>" size="15" placeholder="Twitter URL"/><br/>
- <input type="text" name="djwp_images[<?= $id ?>][facebook_page]"
- value="<?= $facebook_page ?>" size="15" placeholder="Facebook URL"/><br/>
- <input type="text" name="djwp_images[<?= $id ?>][instagram_page]"
- value="<?= $instagram_page ?>" size="15"
- placeholder="Instagram URL"/>
- </td>
- <td>
- <input name="djwp_images[<?= $id ?>][monday]" type="checkbox"
- value="Mon" <?php checked('Mon', $monday); ?> /> <label
- for="djwp_images[monday]">Monday</label><br/>
- <input name="djwp_images[<?= $id ?>][tuesday]" type="checkbox"
- value="Tue" <?php checked('Tue', $tuesday); ?> /> <label
- for="djwp_images[tuesday]">Tuesday</label><br/>
- <input name="djwp_images[<?= $id ?>][wednesday]" type="checkbox"
- value="Wed" <?php checked('Wed', $wednesday); ?> /> <label
- for="djwp_images[wednesday]">Wednesday</label><br/>
- <input name="djwp_images[<?= $id ?>][thursday]" type="checkbox"
- value="Thu" <?php checked('Thu', $thursday); ?> /> <label
- for="djwp_images[thursday]">Thursday</label><br/>
- <input name="djwp_images[<?= $id ?>][friday]" type="checkbox"
- value="Fri" <?php checked('Fri', $friday); ?> /> <label
- for="djwp_images[friday]">Friday</label><br/>
- <input name="djwp_images[<?= $id ?>][saturday]" type="checkbox"
- value="Sat" <?php checked('Sat', $saturday); ?> /> <label
- for="djwp_images[saturday]">Saturday</label><br/>
- <input name="djwp_images[<?= $id ?>][sunday]" type="checkbox"
- value="Sun" <?php checked('Sun', $sunday); ?> /> <label
- for="djwp_images[sunday]">Sunday</label>
- </td>
- <td>
- <label>Start Time</label>
- <input type="text" name="djwp_images[<?= $id ?>][start_time]"
- value="<?= $start_time ?>" class="small-text"/>
- <p>
- <span class="description"><?php _e('24-hour time only <code>15:00</code>', 'djwp'); ?></span>
- </p>
- <label>End Time</label>
- <input type="text" name="djwp_images[<?= $id ?>][end_time]"
- value="<?= $end_time ?>" class="small-text"/>
- <p>
- <span class="description"><?php _e('24-hour time only <code>19:00</code>', 'djwp'); ?></span>
- </p>
- </td>
- <td class="column-slug">
- <a
- href="?page=dj-rotator&delete=<?= $id ?>" class="button">Delete</a>
- <?= submit_button(); ?>
- </td>
- </tr>
- <?php
- };
- ?>
- </tbody>
- </table>
- </form>
- <?php
- }
- /**
- * Generates the DJ image
- */
- function djwp_image()
- {
- global $djwp_settings, $djwp_images;
- // set the timezone
- if (function_exists('date_default_timezone_set')) {
- date_default_timezone_set($djwp_settings['time_zone']);
- }
- // get current server time
- $djday = date('D');
- $djnow = date('H:i');
- $isDisplayed = false;
- $stringBuilder = "";
- foreach ((array)$djwp_images as $image => $data) {
- // Days of the week
- $monday = isset($data['monday']) ? $data['monday'] : '';
- $tuesday = isset($data['tuesday']) ? $data['tuesday'] : '';
- $wednesday = isset($data['wednesday']) ? $data['wednesday'] : '';
- $thursday = isset($data['thursday']) ? $data['thursday'] : '';
- $friday = isset($data['friday']) ? $data['friday'] : '';
- $saturday = isset($data['saturday']) ? $data['saturday'] : '';
- $sunday = isset($data['sunday']) ? $data['sunday'] : '';
- // Times
- $start_time = isset($data['start_time']) ? $data['start_time'] : '';
- $end_time = isset($data['end_time']) ? $data['end_time'] : '';
- // Image height settings
- $img_width = isset($djwp_settings['img_width']) ? $djwp_settings['img_width'] : 250;
- $img_height = isset($djwp_settings['img_height']) ? $djwp_settings['img_height'] : 250;
- $img_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
- $file_url = isset($data['file_url']) ? $data['file_url'] : '';
- $description = isset($data['desc']) ? $data['desc'] : '';
- $id = isset($data['id']) ? $data['id'] : '';
- $start_time_date_obj = DateTime::createFromFormat('H:i', $start_time);
- $end_time_date_obj = DateTime::createFromFormat('H:i', $end_time);
- $now_date_obj = DateTime::createFromFormat('H:i', $djnow);
- if ((strcasecmp($djday, $monday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- if ((strcasecmp($djday, $tuesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- if ((strcasecmp($djday, $wednesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- if ((strcasecmp($djday, $thursday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- if ((strcasecmp($djday, $friday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- if ((strcasecmp($djday, $saturday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- if ((strcasecmp($djday, $sunday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- $isDisplayed = true;
- $stringBuilder = '<a href="' . $img_links_to . '" target="_blank"><span class="media-object"><img style="margin: 0 auto;" class="img-circle img-responsive ' . $id . '" src="' . $file_url . '" width="' . $img_width . '" height="' . $img_height . '" alt="' . $description . '" title="' . $description . '" /></span></a>' . "\n";
- }
- }
- if ($isDisplayed) {
- echo '<div class="col-md-4 text-center media">';
- echo "$stringBuilder";
- echo '</div>';
- }
- if (!$isDisplayed) {
- echo "<div class=\"align-center well well-sm\" style=\"color:#CCC; background-color: rgba(51, 51, 51, 0.8); border-color:#444;\">Currently no shows in progress, <a href=\"/programming\">view our scheduled programming</a></div>";
- }
- }
- function djwp_description()
- {
- global $djwp_settings, $djwp_images;
- // set the timezone
- if (function_exists('date_default_timezone_set')) {
- date_default_timezone_set($djwp_settings['time_zone']);
- }
- // get current server time
- $djday = date('D');
- $djnow = date('H:i');
- $i = 0;
- foreach ((array)$djwp_images as $image => $data) {
- $i = 0;
- // Days of the week
- $monday = isset($data['monday']) ? $data['monday'] : '';
- $tuesday = isset($data['tuesday']) ? $data['tuesday'] : '';
- $wednesday = isset($data['wednesday']) ? $data['wednesday'] : '';
- $thursday = isset($data['thursday']) ? $data['thursday'] : '';
- $friday = isset($data['friday']) ? $data['friday'] : '';
- $saturday = isset($data['saturday']) ? $data['saturday'] : '';
- $sunday = isset($data['sunday']) ? $data['sunday'] : '';
- // Times
- $start_time = isset($data['start_time']) ? $data['start_time'] : '';
- $end_time = isset($data['end_time']) ? $data['end_time'] : '';
- $title = isset($data['title']) ? $data['title'] : '';
- $img_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
- $facebook_page = isset($data['facebook_page']) ? $data['facebook_page'] : '';
- $twitter_page = isset($data['twitter_page']) ? $data['twitter_page'] : '';
- $instagram_page = isset($data['instagram_page']) ? $data['instagram_page'] : '';
- $start_time_date_obj = DateTime::createFromFormat('H:i', $start_time);
- $end_time_date_obj = DateTime::createFromFormat('H:i', $end_time);
- $now_date_obj = DateTime::createFromFormat('H:i', $djnow);
- if ((strcasecmp($djday, $monday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>Now Playing: ' . $title . '</h2>';
- $i++;
- }
- if ((strcasecmp($djday, $tuesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>' . $title . '</h2>';
- $i++;
- }
- if ((strcasecmp($djday, $wednesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>' . $title . '</h2>';
- $i++;
- }
- if ((strcasecmp($djday, $thursday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>' . $title . '</h2>';
- $i++;
- }
- if ((strcasecmp($djday, $friday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>' . $title . '</h2>';
- $i++;
- }
- if ((strcasecmp($djday, $saturday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>' . $title . '</h2>';
- $i++;
- }
- if ((strcasecmp($djday, $sunday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
- echo '<h2>' . $title . '</h2>';
- $i++;
- }
- // Do we need to display the description and or any fb, tw, or instagram links
- if ($i > 0) {
- echo '<p>' . $data['desc'] . '<br />
- <a class="btn btn-default mar-top5" href="https://radiowave.io/s/KSWZ?autoPlay=true" target="_blank"><i class="fa fa-headphones"></i> Listen Live</a></p>';
- if ($img_links_to != "" || $facebook_page != "" || $twitter_page != "" || $instagram_page != "") {
- if ($img_links_to != "") {
- echo '<a class="btn btn-github mar-right5 mar-left5" href="' . $img_links_to . '" target="_blank"><i class="fa fa-globe"></i></a>';
- }
- if ($facebook_page != "") {
- echo '<a class="btn btn-facebook mar-right5 mar-left5" href="' . $facebook_page . '" target="_blank"><i class="fa fa-facebook"></i></a>';
- }
- if ($twitter_page != "") {
- echo '<a class="btn btn-twitter mar-right5 mar-left5" href="' . $twitter_page . '" target="_blank"><i class="fa fa-twitter"></i></a>';
- }
- if ($instagram_page != "") {
- echo '<a class="btn btn-instagram mar-right5 mar-left5" href="' . $instagram_page . '" target="_blank"><i class="fa fa-camera-retro"></i></a>';
- }
- }
- }
- }
- }
- function displayShowListItem($data)
- {
- $desc = isset($data['desc']) ? $data['desc'] : '';
- $img_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
- $facebook_page = isset($data['facebook_page']) ? $data['facebook_page'] : '';
- $twitter_page = isset($data['twitter_page']) ? $data['twitter_page'] : '';
- $instagram_page = isset($data['instagram_page']) ? $data['instagram_page'] : '';
- $title = isset($data['title']) ? $data['title'] : '';
- $start_time = isset($data['start_time']) ? $data['start_time'] : '';
- $end_time = isset($data['end_time']) ? $data['end_time'] : '';
- $file_url = isset($data['file_url']) ? $data['file_url'] : '';
- // TODO: fix me?
- echo '<div class="media">';
- echo '<div class="media-left">';
- echo '<img class="media-object img-rounded" src="' . $file_url . '" class="img-rounded" style="max-width:100px; max-height:100px;" alt="Generic placeholder image">';
- echo "</div>";
- echo '<div class="media-body">';
- echo ' <h4 class="media-heading">' . $title . ' (' . date('h:i a', strtotime($start_time)) . ' to ' . date('h:i a', strtotime($end_time)) . ')</h4>';
- echo '<p>' . $desc . '</p>';
- if ($img_links_to != "" || $facebook_page != "" || $twitter_page != "" || $instagram_page != "") {
- if ($img_links_to != "") {
- echo '<a class="btn btn-default mar-right5 mar-left5" href="' . $img_links_to . '" target="_blank"><i class="fa fa-globe"></i> Website</a>';
- }
- if ($facebook_page != "") {
- echo '<a class="btn btn-facebook mar-right5 mar-left5" href="' . $facebook_page . '" target="_blank"><i class="fa fa-facebook"></i> Facebook</a>';
- }
- if ($twitter_page != "") {
- echo '<a class="btn btn-twitter mar-right5 mar-left5" href="' . $twitter_page . '" target="_blank"><i class="fa fa-twitter"></i> Twitter</a>';
- }
- if ($instagram_page != "") {
- echo '<a class="btn btn-instagram mar-right5 mar-left5" href="' . $instagram_page . '" target="_blank"><i class="fa fa-camera-retro"></i> Instagram</a>';
- }
- }
- echo '</div>';
- echo '</div>';
- }
- /**
- * Generates the DJ list
- */
- function djwp_list()
- {
- global $djwp_settings, $djwp_images;
- // set the timezone
- if (function_exists('date_default_timezone_set')) {
- date_default_timezone_set($djwp_settings['time_zone']);
- }
- $days = array(
- 'Sunday',
- 'Monday',
- 'Tuesday',
- 'Wednesday',
- 'Thursday',
- 'Friday',
- 'Saturday',
- );
- echo '<ul class="nav nav-tabs" role="tablist">';
- $count = 0;
- foreach ($days as $day) {
- echo '<li role="presentation" class="' . ($count == 0 ? 'active' : '') . '"><a href="#' . strtolower($day) . '" aria-controls="monday" role="tab" data-toggle="tab">' . $day . '</a></li>';
- $count++;
- }
- echo '</ul>';
- echo '<div id="myTabContent" class="tab-content mar-top15">';
- $newTemp = [];
- // For each day, store the schedule event
- foreach ($days as $day) {
- foreach ((array)$djwp_images as $image => $data) {
- $found = isset($data[strtolower($day)]) ? $data[strtolower($day)] : '';
- if ($found) {
- $newTemp[$day][] = $data;
- }
- }
- $dayToSort = isset($newTemp[$day]) ? $newTemp[$day] : '';
- $newTemp[$day] = djwp_multiSort($dayToSort, "SORT_ASC", "start_time", false);
- }
- $count2 = 0;
- foreach ($days as $day) {
- echo '<div role="tabpanel" class="tab-pane ' . ($count2 == 0 ? 'active' : '') . '" id="' . strtolower($day) . '">';
- $found = 0;
- foreach ((array)$newTemp[$day] as $id => $data) {
- if ($data != null) {
- displayShowListItem($data);
- $found++;
- }
- }
- if ($found == 0) {
- echo "<p>No programming on this day</p>";
- }
- echo '</div>';
- $count2++;
- }
- echo '</div>';
- }
- /**
- * Mash it all together and form our primary function (Template Tag & Shortcode)
- *
- */
- function djwp($args = array(), $content = null)
- {
- global $djwp_settings;
- echo '<div class="row">';
- djwp_image();
- echo '<div class="col-md-6">';
- djwp_description();
- echo '</div>';
- echo '</div>';
- }
- /**
- * Mash it all together and form our primary function (Template Tag & Shortcode)
- *
- */
- function djwp_schedule($args = array(), $content = null)
- {
- global $djwp_settings;
- djwp_list();
- }
- /**
- * Mash it all together and form our primary function (Sidebar Widget)
- *
- */
- function djwp_widget($args = array(), $content = null)
- {
- global $djwp_settings;
- djwp_image();
- djwp_description();
- }
- /**
- * Codex keys to use on the site
- */
- add_shortcode('djwp', 'djwp_shortcode');
- add_shortcode('djwp_schedule', 'djwp_shortcode2');
- /**
- * Create the shortcode [djwp]
- *
- */
- function djwp_shortcode($atts)
- {
- ob_start();
- djwp();
- return ob_get_clean();
- }
- function djwp_shortcode2($atts)
- {
- ob_start();
- djwp_schedule();
- return ob_get_clean();
- }
- function dj_rotator_register_widgets()
- {
- register_widget('DJ_Rotator_Widget');
- }
- add_action('widgets_init', 'dj_rotator_register_widgets');
- /**
- * Create the Widget
- */
- class DJ_Rotator_Widget extends WP_Widget
- {
- // construct the widget
- public function __construct()
- {
- parent::__construct('dj_rotator_widget', 'DJ Rotator', array('description' => 'Use this widget to place the DJ Rotator in your Sidebar(s)'));
- }
- // write the widget
- function widget($args, $instance)
- {
- extract($args);
- $title = apply_filters('widget_title', $instance['title']);
- echo $args['before_widget'];
- if ($title) {
- echo $args['before_title'] . $title . $args['after_title'];
- }
- echo djwp_widget();
- echo $args['after_widget'];
- }
- // check for update
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- return $instance;
- }
- // build title form
- function form($instance)
- {
- if ($instance) {
- $title = esc_attr($instance['title']);
- } else {
- $title = __('On-Air Now', 'text_domain');
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
- name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>"/>
- </p>
- <?php
- }
- }
Add Comment
Please, Sign In to add comment