Guest User

Show manager

a guest
Oct 24th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Defines the default variables that will be used throughout the plugin
  4.  */
  5. $djwp_defaults = apply_filters('djwp_defaults', array(
  6.     'header_text' => 'On-Air Now',
  7.     'img_width' => 250,
  8.     'img_height' => 250,
  9.     'time_zone' => 'America/Chicago'
  10. ));
  11.  
  12. /**
  13.  * Pull the settings from the DB
  14.  */
  15. $djwp_images = get_option('djwp_images');
  16. $djwp_settings = wp_parse_args(get_option('djwp_settings'), $djwp_defaults);
  17.  
  18. /**
  19.  * The following section registers settings, adds a link to the options page, and a link
  20.  * on the plugin page to "settings"
  21.  */
  22. add_action('admin_init', 'djwp_register_settings');
  23. function djwp_register_settings()
  24. {
  25.     register_setting('djwp_images', 'djwp_images');
  26.     register_setting('djwp_settings', 'djwp_settings');
  27. }
  28.  
  29. add_action('admin_menu', 'add_djwp_menu');
  30. function add_djwp_menu()
  31. {
  32.     add_menu_page('DJ Schedule', 'DJ Schedule', 'manage_options', 'dj-rotator', 'djwp_admin_page');
  33. }
  34.  
  35. function djwp_make_filename_hash($filename)
  36. {
  37.     $info = pathinfo($filename);
  38.     $ext = empty($info['extension']) ? '' : '.' . $info['extension'];
  39.     $name = basename($filename, $ext);
  40.     return md5($name . time()) . $ext;
  41. }
  42.  
  43. /**
  44.  * This function is the code that gets loaded when the settings page gets loaded by the browser.
  45.  * It calls functions that handle image uploads and image settings changes, as well as producing the visible page output.
  46.  */
  47. function djwp_admin_page()
  48. {
  49.     echo '<div class="wrap">';
  50.  
  51.     // If action not set then set it to no value
  52.     if (!isset($_REQUEST['action'])) {
  53.         $_REQUEST['action'] = "";
  54.     }
  55.  
  56.     // handle image upload, if necessary
  57.     if ($_REQUEST['action'] === 'wp_handle_upload') {
  58.         djwp_handle_upload();
  59.     }
  60.  
  61.     // delete an image, if necessary
  62.     if (isset($_REQUEST['delete'])) {
  63.         djwp_delete_upload($_REQUEST['delete']);
  64.     }
  65.  
  66.     // the image management form
  67.     djwp_images_admin();
  68.  
  69.     echo '</div>';
  70. }
  71.  
  72. /**
  73.  * This section handles uploading images, adding the image data to the database, deleting images, and deleting image data from the database.
  74.  */
  75. function djwp_handle_upload()
  76. {
  77.     global $djwp_settings, $djwp_images;
  78.  
  79.     // randomize the file upload name!
  80.     $_FILES['djwp']['name'] = djwp_make_filename_hash($_FILES['djwp']['name']);
  81.  
  82.     // 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.
  83.     $upload = wp_handle_upload($_FILES['djwp'], 0);
  84.  
  85.     //(string) The local path to the uploaded file.
  86.     $localFilePath = $upload['file'];
  87.  
  88.     // (string) The public URL for the uploaded file.
  89.     $publicExternalUrl = $upload['url'];
  90.  
  91.     // (string) The MIME type.
  92.     $memeType = $upload['type'];
  93.  
  94.     // get the image dimensions
  95.     list($width, $height) = getimagesize($localFilePath);
  96.  
  97.     // if the uploaded file is NOT an image
  98.     if (strpos($memeType, 'image') === FALSE) {
  99.         unlink($localFilePath); // delete the file
  100.         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>';
  101.         return;
  102.     }
  103.  
  104.     // if the image doesn't meet the minimum width/height requirements ...
  105.     if ($width < $djwp_settings['img_width'] || $height < $djwp_settings['img_height']) {
  106.         unlink($localFilePath);
  107.         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>';
  108.         return;
  109.     }
  110.  
  111.     // if the image is larger than the width/height requirements, then scale it down.
  112.     if ($width > $djwp_settings['img_width'] || $height > $djwp_settings['img_height']) {
  113.  
  114.         // Resize the image
  115.         $resized = wp_get_image_editor($localFilePath); // Return an implementation that extends WP_Image_Editor
  116.         if (!is_wp_error($resized)) {
  117.             $resized->resize($djwp_settings['img_width'], $djwp_settings['img_height'], true);
  118.             $resized->save($localFilePath);
  119.         }
  120.     }
  121.  
  122.     // use the timestamp as the array key and id
  123.     $time = date('YmdHis');
  124.  
  125.     // add the image data to the array
  126.     $djwp_images[$time] = array(
  127.         'id' => $time,
  128.         'file' => $localFilePath,
  129.         'file_url' => $publicExternalUrl,
  130.         'image_links_to' => '',
  131.  
  132.         'title' => 'Blank',
  133.         'desc' => 'Blank',
  134.  
  135.         'monday' => false,
  136.         'tuesday' => false,
  137.         'wednesday' => false,
  138.         'thursday' => false,
  139.         'friday' => false,
  140.         'saturday' => false,
  141.         'sunday' => false,
  142.  
  143.         'start_time' => '00:00',
  144.         'end_time' => '01:00',
  145.  
  146.         'twitter_page' => '',
  147.         'instagram_page' => '',
  148.         'facebook_page' => '',
  149.         'image_links_to' => ''
  150.     );
  151.  
  152.     // add the image information to the database
  153.     update_option('djwp_images', $djwp_images);
  154. }
  155.  
  156. // delete the image, and removes the image data from the db
  157. function djwp_delete_upload($id)
  158. {
  159.     global $djwp_images;
  160.  
  161.     // if the ID passed to this function is invalid,
  162.     // halt the process, and don't try to delete.
  163.     if (!isset($djwp_images[$id])) {
  164.         return;
  165.     }
  166.  
  167.     // delete the image
  168.     if (file_exists($djwp_images[$id]['file'])) {
  169.         unlink($djwp_images[$id]['file']);
  170.     }
  171.  
  172.     // remove the image data from the db
  173.     unset($djwp_images[$id]);
  174.     update_option('djwp_images', $djwp_images);
  175. }
  176.  
  177. /**
  178.  * Private djwp_multiSort
  179.  *
  180.  * @array() $data
  181.  * @bool $isDate
  182.  * @param $data
  183.  * @param $sortDirection
  184.  * @param $field
  185.  * @param $isDate
  186.  * @return mixed $data
  187.  */
  188. function djwp_multiSort($data, $sortDirection, $field, $isDate)
  189. {
  190.  
  191.     if (empty($data) || !is_array($data) || count($data) < 2) {
  192.         return $data;
  193.     }
  194.  
  195.     $parts = explode("/", $field);
  196.     foreach ($data as $key => $row) {
  197.         $temp = &$row;
  198.         foreach ($parts as $key2) {
  199.             $temp = &$temp[$key2];
  200.         }
  201.         $orderByDate[$key] = ($isDate ? strtotime($temp) : $temp);
  202.     }
  203.     unset($temp);
  204.     unset($parts);
  205.  
  206.     if ($sortDirection == "SORT_DESC") {
  207.         array_multisort($orderByDate, SORT_DESC, $data);
  208.     } else {
  209.         array_multisort($orderByDate, SORT_ASC, $data);
  210.     }
  211.     unset($orderByDate);
  212.     return $data;
  213. }
  214.  
  215. /**
  216.  * Display the DJ image settings on the options page
  217.  */
  218. function djwp_images_admin()
  219. {
  220.     global $djwp_images;
  221.  
  222.     ?>
  223.     <h2><?php _e('DJ Images', 'djwp'); ?></h2>
  224.     <table class="form-table">
  225.         <tr valign="top">
  226.             <th scope="row">Upload a photo</th>
  227.             <td>
  228.                 <form enctype="multipart/form-data" method="post" action="?page=dj-rotator">
  229.                     <input type="hidden" name="post_id" id="post_id" value="0"/>
  230.                     <input type="hidden" name="action" id="action" value="wp_handle_upload"/>
  231.                     <label for="djwp">Select a File: </label>
  232.                     <input type="file" name="djwp" id="djwp"/>
  233.                     <input type="submit" class="button-primary" name="html-upload" value="Upload"/>
  234.                 </form>
  235.             </td>
  236.         </tr>
  237.     </table>
  238.  
  239.     <h2><?php _e('DJ Information', 'djwp'); ?></h2>
  240.     <form class="djform" method="post" action="options.php">
  241.         <?php  settings_fields('djwp_images'); ?>
  242.  
  243.     <table class="widefat" cellspacing="0">
  244.         <thead>
  245.         <tr>
  246.             <th>DJ Image</th>
  247.             <th scope="col">Title / Description</th>
  248.             <th scope="col">Social</th>
  249.             <th scope="col">Days On-Air</th>
  250.             <th scope="col">Times</th>
  251.             <th scope="col">Actions</th>
  252.         </tr>
  253.         </thead>
  254.  
  255.         <tfoot>
  256.         <tr>
  257.             <th scope="col">DJ Image</th>
  258.             <th scope="col">Title / Description</th>
  259.             <th scope="col">Social</th>
  260.             <th scope="col">Days On-Air</th>
  261.             <th scope="col">Times</th>
  262.             <th scope="col">Actions</th>
  263.         </tr>
  264.         </tfoot>
  265.  
  266.         <tbody>
  267.  
  268.             <?php
  269.  
  270.             foreach ($djwp_images as $id => $data) {
  271.  
  272.                 $data_id = isset($data['id']) ? $data['id'] : '';
  273.                 $file = isset($data['file']) ? $data['file'] : '';
  274.                 $file_url = isset($data['file_url']) ? $data['file_url'] : '';
  275.                 $desc = isset($data['desc']) ? $data['desc'] : '';
  276.                 $start_time = isset($data['start_time']) ? $data['start_time'] : '';
  277.                 $end_time = isset($data['end_time']) ? $data['end_time'] : '';
  278.                 $title = isset($data['title']) ? $data['title'] : '';
  279.                 $image_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
  280.  
  281.  
  282.                 $facebook_page = isset($data['facebook_page']) ? $data['facebook_page'] : '';
  283.                 $twitter_page = isset($data['twitter_page']) ? $data['twitter_page'] : '';
  284.                 $instagram_page = isset($data['instagram_page']) ? $data['instagram_page'] : '';
  285.  
  286.  
  287.                 // Days of the week
  288.                 $monday = isset($data['monday']) ? $data['monday'] : '';
  289.                 $tuesday = isset($data['tuesday']) ? $data['tuesday'] : '';
  290.                 $wednesday = isset($data['wednesday']) ? $data['wednesday'] : '';
  291.                 $thursday = isset($data['thursday']) ? $data['thursday'] : '';
  292.                 $friday = isset($data['friday']) ? $data['friday'] : '';
  293.                 $saturday = isset($data['saturday']) ? $data['saturday'] : '';
  294.                 $sunday = isset($data['sunday']) ? $data['sunday'] : '';
  295.  
  296.                 ?>
  297.  
  298.                 <tr>
  299.  
  300.                     <td
  301.  
  302.                     <input type="hidden" name="djwp_images[<?= $id; ?>][id]"
  303.                            value="<?= $data_id ?>"/>
  304.                     <input type="hidden" name="djwp_images[<?= $id; ?>][file]"
  305.                            value="<?= $file ?>"/>
  306.                     <input type="hidden" name="djwp_images[<?= $id; ?>][file_url]"
  307.                            value="<?= $file_url ?>"/>
  308.                     <img src="<?= $file_url ?>" width="100" height="100"/>
  309.                     </td>
  310.  
  311.                     <td>
  312.                         <label>Show title</label><br/>
  313.                         <input type="text" name="djwp_images[<?= $id ?>][title]"
  314.                                value="<?= $title ?>" placeholder="Title"/><br/>
  315.                         <label>Show description</label><br/>
  316.                         <textarea name="djwp_images[<?= $id ?>][desc]" rows="5" cols="20"
  317.                                   class="regular-text"/><?= $desc ?></textarea>
  318.                     </td>
  319.  
  320.                     <td>
  321.                         <input type="text" name="djwp_images[<?= $id ?>][image_links_to]"
  322.                                value="<?= $image_links_to ?>" size="15"
  323.                                placeholder="Show page URL"/><br/>
  324.                         <input type="text" name="djwp_images[<?= $id ?>][twitter_page]"
  325.                                value="<?= $twitter_page ?>" size="15" placeholder="Twitter URL"/><br/>
  326.                         <input type="text" name="djwp_images[<?= $id ?>][facebook_page]"
  327.                                value="<?= $facebook_page ?>" size="15" placeholder="Facebook URL"/><br/>
  328.                         <input type="text" name="djwp_images[<?= $id ?>][instagram_page]"
  329.                                value="<?= $instagram_page ?>" size="15"
  330.                                placeholder="Instagram URL"/>
  331.                     </td>
  332.  
  333.                     <td>
  334.                         <input name="djwp_images[<?= $id ?>][monday]" type="checkbox"
  335.                                value="Mon" <?php checked('Mon', $monday); ?> /> <label
  336.                                 for="djwp_images[monday]">Monday</label><br/>
  337.                         <input name="djwp_images[<?= $id ?>][tuesday]" type="checkbox"
  338.                                value="Tue" <?php checked('Tue', $tuesday); ?> /> <label
  339.                                 for="djwp_images[tuesday]">Tuesday</label><br/>
  340.                         <input name="djwp_images[<?= $id ?>][wednesday]" type="checkbox"
  341.                                value="Wed" <?php checked('Wed', $wednesday); ?> /> <label
  342.                                 for="djwp_images[wednesday]">Wednesday</label><br/>
  343.                         <input name="djwp_images[<?= $id ?>][thursday]" type="checkbox"
  344.                                value="Thu" <?php checked('Thu', $thursday); ?> /> <label
  345.                                 for="djwp_images[thursday]">Thursday</label><br/>
  346.                         <input name="djwp_images[<?= $id ?>][friday]" type="checkbox"
  347.                                value="Fri" <?php checked('Fri', $friday); ?> /> <label
  348.                                 for="djwp_images[friday]">Friday</label><br/>
  349.                         <input name="djwp_images[<?= $id ?>][saturday]" type="checkbox"
  350.                                value="Sat" <?php checked('Sat', $saturday); ?> /> <label
  351.                                 for="djwp_images[saturday]">Saturday</label><br/>
  352.                         <input name="djwp_images[<?= $id ?>][sunday]" type="checkbox"
  353.                                value="Sun" <?php checked('Sun', $sunday); ?> /> <label
  354.                                 for="djwp_images[sunday]">Sunday</label>
  355.                     </td>
  356.  
  357.                     <td>
  358.                         <label>Start Time</label>
  359.                         <input type="text" name="djwp_images[<?= $id ?>][start_time]"
  360.                                value="<?= $start_time ?>" class="small-text"/>
  361.                         <p>
  362.                             <span class="description"><?php _e('24-hour time only <code>15:00</code>', 'djwp'); ?></span>
  363.                         </p>
  364.                         <label>End Time</label>
  365.                         <input type="text" name="djwp_images[<?= $id ?>][end_time]"
  366.                                value="<?= $end_time ?>" class="small-text"/>
  367.                         <p>
  368.                             <span class="description"><?php _e('24-hour time only <code>19:00</code>', 'djwp'); ?></span>
  369.                         </p>
  370.                     </td>
  371.  
  372.                     <td class="column-slug">
  373.                         <a
  374.                                 href="?page=dj-rotator&amp;delete=<?= $id ?>" class="button">Delete</a>
  375.                         <?= submit_button(); ?>
  376.  
  377.                     </td>
  378.                 </tr>
  379.                 <?php
  380.             };
  381.             ?>
  382.  
  383.         </tbody>
  384.     </table>
  385.     </form>
  386.  
  387.     <?php
  388. }
  389.  
  390. /**
  391.  * Generates the DJ image
  392.  */
  393. function djwp_image()
  394. {
  395.     global $djwp_settings, $djwp_images;
  396.  
  397.     // set the timezone
  398.     if (function_exists('date_default_timezone_set')) {
  399.         date_default_timezone_set($djwp_settings['time_zone']);
  400.     }
  401.  
  402.     // get current server time
  403.     $djday = date('D');
  404.     $djnow = date('H:i');
  405.  
  406.     $isDisplayed = false;
  407.  
  408.     $stringBuilder = "";
  409.  
  410.     foreach ((array)$djwp_images as $image => $data) {
  411.  
  412.         // Days of the week
  413.         $monday = isset($data['monday']) ? $data['monday'] : '';
  414.         $tuesday = isset($data['tuesday']) ? $data['tuesday'] : '';
  415.         $wednesday = isset($data['wednesday']) ? $data['wednesday'] : '';
  416.         $thursday = isset($data['thursday']) ? $data['thursday'] : '';
  417.         $friday = isset($data['friday']) ? $data['friday'] : '';
  418.         $saturday = isset($data['saturday']) ? $data['saturday'] : '';
  419.         $sunday = isset($data['sunday']) ? $data['sunday'] : '';
  420.  
  421.         // Times
  422.         $start_time = isset($data['start_time']) ? $data['start_time'] : '';
  423.         $end_time = isset($data['end_time']) ? $data['end_time'] : '';
  424.  
  425.         // Image height settings
  426.         $img_width = isset($djwp_settings['img_width']) ? $djwp_settings['img_width'] : 250;
  427.         $img_height = isset($djwp_settings['img_height']) ? $djwp_settings['img_height'] : 250;
  428.  
  429.         $img_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
  430.         $file_url = isset($data['file_url']) ? $data['file_url'] : '';
  431.         $description = isset($data['desc']) ? $data['desc'] : '';
  432.         $id = isset($data['id']) ? $data['id'] : '';
  433.  
  434.         $start_time_date_obj = DateTime::createFromFormat('H:i', $start_time);
  435.         $end_time_date_obj = DateTime::createFromFormat('H:i', $end_time);
  436.         $now_date_obj = DateTime::createFromFormat('H:i', $djnow);
  437.  
  438.         if ((strcasecmp($djday, $monday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  439.             $isDisplayed = true;
  440.             $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";
  441.         }
  442.  
  443.         if ((strcasecmp($djday, $tuesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  444.             $isDisplayed = true;
  445.             $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";
  446.         }
  447.  
  448.         if ((strcasecmp($djday, $wednesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  449.             $isDisplayed = true;
  450.             $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";
  451.         }
  452.  
  453.         if ((strcasecmp($djday, $thursday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  454.             $isDisplayed = true;
  455.             $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";
  456.         }
  457.  
  458.         if ((strcasecmp($djday, $friday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  459.             $isDisplayed = true;
  460.             $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";
  461.         }
  462.  
  463.         if ((strcasecmp($djday, $saturday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  464.             $isDisplayed = true;
  465.             $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";
  466.         }
  467.  
  468.         if ((strcasecmp($djday, $sunday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  469.             $isDisplayed = true;
  470.             $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";
  471.         }
  472.     }
  473.  
  474.     if ($isDisplayed) {
  475.         echo '<div class="col-md-4 text-center media">';
  476.         echo "$stringBuilder";
  477.         echo '</div>';
  478.     }
  479.  
  480.     if (!$isDisplayed) {
  481.         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>";
  482.     }
  483.  
  484. }
  485.  
  486. function djwp_description()
  487. {
  488.     global $djwp_settings, $djwp_images;
  489.  
  490.     // set the timezone
  491.     if (function_exists('date_default_timezone_set')) {
  492.         date_default_timezone_set($djwp_settings['time_zone']);
  493.     }
  494.  
  495.     // get current server time
  496.     $djday = date('D');
  497.     $djnow = date('H:i');
  498.  
  499.     $i = 0;
  500.     foreach ((array)$djwp_images as $image => $data) {
  501.  
  502.         $i = 0;
  503.  
  504.  
  505.         // Days of the week
  506.         $monday = isset($data['monday']) ? $data['monday'] : '';
  507.         $tuesday = isset($data['tuesday']) ? $data['tuesday'] : '';
  508.         $wednesday = isset($data['wednesday']) ? $data['wednesday'] : '';
  509.         $thursday = isset($data['thursday']) ? $data['thursday'] : '';
  510.         $friday = isset($data['friday']) ? $data['friday'] : '';
  511.         $saturday = isset($data['saturday']) ? $data['saturday'] : '';
  512.         $sunday = isset($data['sunday']) ? $data['sunday'] : '';
  513.  
  514.         // Times
  515.         $start_time = isset($data['start_time']) ? $data['start_time'] : '';
  516.         $end_time = isset($data['end_time']) ? $data['end_time'] : '';
  517.  
  518.         $title = isset($data['title']) ? $data['title'] : '';
  519.         $img_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
  520.         $facebook_page = isset($data['facebook_page']) ? $data['facebook_page'] : '';
  521.         $twitter_page = isset($data['twitter_page']) ? $data['twitter_page'] : '';
  522.         $instagram_page = isset($data['instagram_page']) ? $data['instagram_page'] : '';
  523.  
  524.         $start_time_date_obj = DateTime::createFromFormat('H:i', $start_time);
  525.         $end_time_date_obj = DateTime::createFromFormat('H:i', $end_time);
  526.         $now_date_obj = DateTime::createFromFormat('H:i', $djnow);
  527.  
  528.         if ((strcasecmp($djday, $monday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  529.             echo '<h2>Now Playing: ' . $title . '</h2>';
  530.             $i++;
  531.         }
  532.  
  533.         if ((strcasecmp($djday, $tuesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  534.             echo '<h2>' . $title . '</h2>';
  535.             $i++;
  536.         }
  537.  
  538.         if ((strcasecmp($djday, $wednesday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  539.             echo '<h2>' . $title . '</h2>';
  540.             $i++;
  541.         }
  542.  
  543.         if ((strcasecmp($djday, $thursday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  544.             echo '<h2>' . $title . '</h2>';
  545.             $i++;
  546.         }
  547.  
  548.         if ((strcasecmp($djday, $friday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  549.             echo '<h2>' . $title . '</h2>';
  550.             $i++;
  551.         }
  552.  
  553.         if ((strcasecmp($djday, $saturday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  554.             echo '<h2>' . $title . '</h2>';
  555.             $i++;
  556.         }
  557.  
  558.         if ((strcasecmp($djday, $sunday) == 0) && $now_date_obj >= $start_time_date_obj && $now_date_obj <= $end_time_date_obj) {
  559.             echo '<h2>' . $title . '</h2>';
  560.             $i++;
  561.         }
  562.  
  563.         // Do we need to display the description and or any fb, tw, or instagram links
  564.         if ($i > 0) {
  565.             echo '<p>' . $data['desc'] . '<br />
  566.            <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>';
  567.  
  568.             if ($img_links_to != "" || $facebook_page != "" || $twitter_page != "" || $instagram_page != "") {
  569.                 if ($img_links_to != "") {
  570.                     echo '<a class="btn btn-github mar-right5 mar-left5" href="' . $img_links_to . '" target="_blank"><i class="fa fa-globe"></i></a>';
  571.                 }
  572.                 if ($facebook_page != "") {
  573.                     echo '<a class="btn btn-facebook mar-right5 mar-left5" href="' . $facebook_page . '" target="_blank"><i class="fa fa-facebook"></i></a>';
  574.                 }
  575.                 if ($twitter_page != "") {
  576.                     echo '<a class="btn btn-twitter mar-right5 mar-left5" href="' . $twitter_page . '" target="_blank"><i class="fa fa-twitter"></i></a>';
  577.                 }
  578.                 if ($instagram_page != "") {
  579.                     echo '<a class="btn btn-instagram mar-right5 mar-left5" href="' . $instagram_page . '" target="_blank"><i class="fa fa-camera-retro"></i></a>';
  580.                 }
  581.             }
  582.         }
  583.     }
  584. }
  585.  
  586. function displayShowListItem($data)
  587. {
  588.  
  589.     $desc = isset($data['desc']) ? $data['desc'] : '';
  590.     $img_links_to = isset($data['image_links_to']) ? $data['image_links_to'] : '';
  591.     $facebook_page = isset($data['facebook_page']) ? $data['facebook_page'] : '';
  592.     $twitter_page = isset($data['twitter_page']) ? $data['twitter_page'] : '';
  593.     $instagram_page = isset($data['instagram_page']) ? $data['instagram_page'] : '';
  594.     $title = isset($data['title']) ? $data['title'] : '';
  595.     $start_time = isset($data['start_time']) ? $data['start_time'] : '';
  596.     $end_time = isset($data['end_time']) ? $data['end_time'] : '';
  597.     $file_url = isset($data['file_url']) ? $data['file_url'] : '';
  598.  
  599.     // TODO: fix me?
  600.     echo '<div class="media">';
  601.     echo '<div class="media-left">';
  602.     echo '<img class="media-object img-rounded" src="' . $file_url . '" class="img-rounded" style="max-width:100px; max-height:100px;" alt="Generic placeholder image">';
  603.     echo "</div>";
  604.     echo '<div class="media-body">';
  605.     echo ' <h4 class="media-heading">' . $title . ' (' . date('h:i a', strtotime($start_time)) . ' to ' . date('h:i a', strtotime($end_time)) . ')</h4>';
  606.  
  607.     echo '<p>' . $desc . '</p>';
  608.  
  609.     if ($img_links_to != "" || $facebook_page != "" || $twitter_page != "" || $instagram_page != "") {
  610.         if ($img_links_to != "") {
  611.             echo '<a class="btn btn-default mar-right5 mar-left5" href="' . $img_links_to . '" target="_blank"><i class="fa fa-globe"></i> Website</a>';
  612.         }
  613.         if ($facebook_page != "") {
  614.             echo '<a class="btn btn-facebook mar-right5 mar-left5" href="' . $facebook_page . '" target="_blank"><i class="fa fa-facebook"></i> Facebook</a>';
  615.         }
  616.         if ($twitter_page != "") {
  617.             echo '<a class="btn btn-twitter mar-right5 mar-left5" href="' . $twitter_page . '" target="_blank"><i class="fa fa-twitter"></i> Twitter</a>';
  618.         }
  619.         if ($instagram_page != "") {
  620.             echo '<a class="btn btn-instagram mar-right5 mar-left5" href="' . $instagram_page . '" target="_blank"><i class="fa fa-camera-retro"></i> Instagram</a>';
  621.         }
  622.     }
  623.     echo '</div>';
  624.     echo '</div>';
  625. }
  626.  
  627. /**
  628.  * Generates the DJ list
  629.  */
  630. function djwp_list()
  631. {
  632.     global $djwp_settings, $djwp_images;
  633.  
  634.     // set the timezone
  635.     if (function_exists('date_default_timezone_set')) {
  636.         date_default_timezone_set($djwp_settings['time_zone']);
  637.     }
  638.  
  639.     $days = array(
  640.         'Sunday',
  641.         'Monday',
  642.         'Tuesday',
  643.         'Wednesday',
  644.         'Thursday',
  645.         'Friday',
  646.         'Saturday',
  647.     );
  648.  
  649.     echo '<ul class="nav nav-tabs" role="tablist">';
  650.  
  651.     $count = 0;
  652.     foreach ($days as $day) {
  653.         echo '<li role="presentation" class="' . ($count == 0 ? 'active' : '') . '"><a href="#' . strtolower($day) . '" aria-controls="monday" role="tab" data-toggle="tab">' . $day . '</a></li>';
  654.         $count++;
  655.     }
  656.  
  657.     echo '</ul>';
  658.     echo '<div id="myTabContent" class="tab-content mar-top15">';
  659.  
  660.  
  661.     $newTemp = [];
  662.  
  663.     // For each day, store the schedule event
  664.     foreach ($days as $day) {
  665.         foreach ((array)$djwp_images as $image => $data) {
  666.             $found = isset($data[strtolower($day)]) ? $data[strtolower($day)] : '';
  667.  
  668.             if ($found) {
  669.                 $newTemp[$day][] = $data;
  670.             }
  671.         }
  672.         $dayToSort = isset($newTemp[$day]) ? $newTemp[$day] : '';
  673.         $newTemp[$day] = djwp_multiSort($dayToSort, "SORT_ASC", "start_time", false);
  674.     }
  675.  
  676.     $count2 = 0;
  677.     foreach ($days as $day) {
  678.  
  679.         echo '<div role="tabpanel" class="tab-pane ' . ($count2 == 0 ? 'active' : '') . '" id="' . strtolower($day) . '">';
  680.         $found = 0;
  681.  
  682.         foreach ((array)$newTemp[$day] as $id => $data) {
  683.             if ($data != null) {
  684.                 displayShowListItem($data);
  685.                 $found++;
  686.             }
  687.         }
  688.  
  689.         if ($found == 0) {
  690.             echo "<p>No programming on this day</p>";
  691.         }
  692.  
  693.         echo '</div>';
  694.         $count2++;
  695.     }
  696.     echo '</div>';
  697. }
  698.  
  699. /**
  700.  * Mash it all together and form our primary function (Template Tag & Shortcode)
  701.  *
  702.  */
  703. function djwp($args = array(), $content = null)
  704. {
  705.     global $djwp_settings;
  706.     echo '<div class="row">';
  707.     djwp_image();
  708.     echo '<div class="col-md-6">';
  709.     djwp_description();
  710.     echo '</div>';
  711.     echo '</div>';
  712. }
  713.  
  714. /**
  715.  * Mash it all together and form our primary function (Template Tag & Shortcode)
  716.  *
  717.  */
  718. function djwp_schedule($args = array(), $content = null)
  719. {
  720.     global $djwp_settings;
  721.     djwp_list();
  722. }
  723.  
  724. /**
  725.  * Mash it all together and form our primary function (Sidebar Widget)
  726.  *
  727.  */
  728. function djwp_widget($args = array(), $content = null)
  729. {
  730.     global $djwp_settings;
  731.     djwp_image();
  732.     djwp_description();
  733. }
  734.  
  735. /**
  736.  * Codex keys to use on the site
  737.  */
  738. add_shortcode('djwp', 'djwp_shortcode');
  739. add_shortcode('djwp_schedule', 'djwp_shortcode2');
  740.  
  741. /**
  742.  * Create the shortcode [djwp]
  743.  *
  744.  */
  745. function djwp_shortcode($atts)
  746. {
  747.     ob_start();
  748.     djwp();
  749.     return ob_get_clean();
  750. }
  751.  
  752. function djwp_shortcode2($atts)
  753. {
  754.     ob_start();
  755.     djwp_schedule();
  756.     return ob_get_clean();
  757. }
  758.  
  759. function dj_rotator_register_widgets()
  760. {
  761.     register_widget('DJ_Rotator_Widget');
  762. }
  763.  
  764. add_action('widgets_init', 'dj_rotator_register_widgets');
  765.  
  766. /**
  767.  * Create the Widget
  768.  */
  769. class DJ_Rotator_Widget extends WP_Widget
  770. {
  771.  
  772.     // construct the widget
  773.     public function __construct()
  774.     {
  775.         parent::__construct('dj_rotator_widget', 'DJ Rotator', array('description' => 'Use this widget to place the DJ Rotator in your Sidebar(s)'));
  776.     }
  777.  
  778.     // write the widget
  779.     function widget($args, $instance)
  780.     {
  781.         extract($args);
  782.         $title = apply_filters('widget_title', $instance['title']);
  783.         echo $args['before_widget'];
  784.         if ($title) {
  785.             echo $args['before_title'] . $title . $args['after_title'];
  786.         }
  787.         echo djwp_widget();
  788.         echo $args['after_widget'];
  789.     }
  790.  
  791.     // check for update
  792.     function update($new_instance, $old_instance)
  793.     {
  794.         $instance = $old_instance;
  795.         $instance['title'] = strip_tags($new_instance['title']);
  796.         return $instance;
  797.     }
  798.  
  799.     // build title form
  800.     function form($instance)
  801.     {
  802.         if ($instance) {
  803.             $title = esc_attr($instance['title']);
  804.         } else {
  805.             $title = __('On-Air Now', 'text_domain');
  806.         }
  807.         ?>
  808.         <p>
  809.             <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  810.             <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
  811.                    name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>"/>
  812.         </p>
  813.         <?php
  814.     }
  815. }
Add Comment
Please, Sign In to add comment