Plugin Directory

Changeset 677215


Ignore:
Timestamp:
03/06/2013 11:03:15 PM (13 years ago)
Author:
mattyribbo
Message:

1.1b1 - Added 'Unscheduled Item' functionality. Allows an unscheduled item to be created, which can then be enabled at any time and override a scheduled item.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • riotschedule/trunk/riotschedule.php

    r666051 r677215  
    44 * Plugin URI: http://www.mattyribbo.co.uk/riotschedule
    55 * Description: Plugin to display weekly schedule for TV/Radio
    6  * Version: 1.0b3
     6 * Version: 1.1b1
    77 * Author: Matt Ribbins
    88 * Author URI: http://www.mattyribbo.co.uk
     
    2828 */
    2929 
    30 $version = "1.0b3";
     30$version = "1.1b1";
    3131
    3232
     
    120120    $genoptions['includestylescript'] = "";
    121121    $genoptions['frontpagestylescript'] = false;
    122     $genoptions['version'] = "1.0";
     122    $genoptions['version'] = "1.1";
    123123    return $genoptions;
    124124}
     
    301301    <table>
    302302                    <tr>
     303                        <td>Show Type</td>
     304                        <td>
     305                        <select style='width: 150px' name="type">
     306                            <option value='1' <?php selected( 1, $itemexist->type );?>>Scheduled Item</option>
     307                            <option value='2' <?php selected( 2, $itemexist->type );?>>Unscheduled Item</option>
     308                        </select>
     309                        </td>
     310                    </tr>
     311                    <?php if ( $itemexist->type == 2 ) { ?>
     312                    <tr>
     313                        <td>Enable Unscheduled Item</td>
     314                        <td><input type="checkbox" <?php checked ( $itemexist->enabled ); ?> name="enabled" value="enabled" /></td>
     315                    </tr>
     316                    <?php } ?>
     317                    <tr>
    303318                    <td>Short Description (One line)</td>
    304                     <td><textarea name="description" style='width: 150px;' rows="2"><?php if ($itemexist) { echo htmlspecialchars(stripslashes($itemexist->description)); }?></textarea>
     319                    <td><textarea name="description" style='width: 150px;' rows="5"><?php if ($itemexist) { echo htmlspecialchars(stripslashes($itemexist->description)); }?></textarea>
    305320                    </td>
    306321                    </tr>
     
    435450                              'scheduleid' => $_POST['schedule'],
    436451                              'pid' => $schedule_id,
    437                               'enabled' => '1'
     452                              'enabled' => 0,
     453                              'type' => $_POST['type']
    438454                             );
    439 
     455            // Force enable. Scheduled items are always enabled. Unscheduled items are disabled by default
     456            if($newitem['type'] == '1') {
     457                $newitem['enabled'] = '1';
     458            }
     459            if( $newitem['type'] == '2' ) {
     460
     461                if ( isset ( $_POST['enabled'] ) ) {
     462                    $newitem['enabled'] = '1' ;
     463                } else {
     464                    $newitem['enabled'] = '0';
     465                }
     466            }
     467           
    440468            // Search for matching PID in our database
    441469            $endtime = $newitem['starttime'] + $newitem['duration'];
     
    450478            if ( $update ) {
    451479                // We're updating a current record.
    452                 //$item_row = $wpdb->get_row("SELECT * from " . $wpdb->prefix . "rs_items where pid = " . $schedule_id);
    453480                $wpdb->update( $wpdb->prefix . 'rs_items', $newitem, array( 'pid' => $schedule_id ));
    454481                //echo '<div id="message" class="updated fade"><p><strong>Updated Scheduled Item</strong></div>';
     
    464491           
    465492        } else {
    466             // Seems we're just re-enabling this scheduled item
    467             $wpdb->update( $wpdb->prefix . 'rs_items', array( 'enabled' => true ), array( 'pid' => $schedule_id ));
     493            // Seems we're just re-enabling this scheduled item or updating the item
     494            if ( $newitem['type'] == '1' ) {
     495                $wpdb->update( $wpdb->prefix . 'rs_items', array( 'enabled' => true ), array( 'pid' => $schedule_id ));
     496            }
    468497        }
    469498    }
     
    526555            echo $before_title . $title . $after_title;
    527556
    528         //fetch results
     557        // Fetch results
    529558        global $wpdb;
    530559       
    531         $schedule_query = 'SELECT * from ' . $wpdb->prefix . 'rs_items WHERE day = ' . $today . ' AND scheduleid = ' . $schedule_id . ' ORDER by starttime ASC LIMIT 0, ' . $max_items;
     560        $schedule_query = 'SELECT * from ' . $wpdb->prefix . 'rs_items WHERE day = ' . $today . ' AND scheduleid = ' . $schedule_id . ' AND type = 1 AND enabled = 1 ORDER by starttime ASC LIMIT 0, ' . $max_items;
    532561       
    533562        $schedule_items = $wpdb->get_results( $schedule_query );
     
    695724        'offset' => '0',
    696725        'display' => 'name',
    697         'default_message' => 'Non-stop Music 24/7'
     726        'default_message' => 'Non-stop Music 24/7',
     727        'schedule' => '1'
    698728    ), $atts ) );
    699729   
     
    713743    if($mode == 'now') {
    714744        // Find the most recent show
    715         $sqlitems = "SELECT * FROM ".$wpdb->prefix."rs_items WHERE day = '".$wsc_day."' AND starttime  <= '".$wsc_hour."' ORDER BY starttime DESC LIMIT 0,1";
     745        $sqlitems = "SELECT * FROM " . $wpdb->prefix . "rs_items WHERE day = '" . $wsc_day . "' AND starttime  <= '" . $wsc_hour . "' AND enabled = 1 AND scheduleid = " . $schedule . " ORDER BY starttime DESC, type DESC LIMIT 0,1";
    716746        $items = $wpdb->get_row($sqlitems,ARRAY_A);
    717747        // Check that there is a show that has happened or is happening
     
    725755            // Look at yesterday, could be an overlapping show
    726756        }
     757
    727758    }
    728759   
     
    730761    if($mode == 'next') {
    731762        // Find the next item after the current hour
    732         $sqlitems = "SELECT * FROM ".$wpdb->prefix."rs_items WHERE day = '".$wsc_day."' AND starttime > '".$wsc_hour."' ORDER BY starttime ASC LIMIT 0,1";
     763        $sqlitems = "SELECT * FROM ".$wpdb->prefix."rs_items WHERE day = '".$wsc_day."' AND starttime > '".$wsc_hour."' AND enabled = 1 AND AND scheduleid = " . $schedule . " ORDER BY starttime ASC, type DESC LIMIT 0,1";
    733764        $items = $wpdb->get_row($sqlitems,ARRAY_A);
    734765        // If items found, that is the next show. If no items found, check next day up until 1pm!
     
    802833    $show_next['time'] = rs_now_next_func(array("mode" => "next", "display" => "time"));
    803834    echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<rss version=\"0.92\">\n";
    804     echo "<channel>\n<title>Hub Now and Next</title>\n<description>Shows the Now and Next shows on Hub Radio in a RSS format</description>\n";
     835    echo "<channel>\n<title>" . get_bloginfo("name") . " Now and Next</title>\n<description>Shows the Now and Next shows on " . get_bloginfo("name") . "</description>\n";
    805836    echo "<link>http://www.hubradio.co.uk</link>\n";
    806837    echo "<item><guid>http://www.hubradio.co.uk/?now</guid><title>".strip_tags($show_now['name'])." - ".strip_tags($show_now['time'])."</title><description>".strip_tags($show_now['name'])."</description></item\n>";
     
    830861        'thumb_height' => 100,
    831862        'thumb_width' => 100,
    832         'block_name_desc' => 0
     863        'block_name_desc' => 0,
     864        'type' => 1
    833865    ), $atts));
    834866   
     
    843875                      ' AND starttime >= ' . $period_start .
    844876                      ' AND starttime < ' . $period_end .
    845                       ' ORDER by starttime ASC LIMIT 0, ' . $max_items;
     877                      ' AND type = ' . $type .
     878                      ' ORDER by starttime ASC, type DESC LIMIT 0, ' . $max_items;
    846879
    847880    $schedule_items = $wpdb->get_results( $schedule_query );
     
    930963                      'rs_items WHERE pid = ' . $pid . 
    931964                      ' AND enabled = 1' .
    932                       ' ORDER by starttime ASC LIMIT 0, 1';
     965                      ' ORDER by starttime ASC, type DESC LIMIT 0, 1';
    933966
    934967    $schedule_items = $wpdb->get_results( $schedule_query );
     
    10081041        'thumbnail' => 0,
    10091042        'thumb_height' => 100,
    1010         'thumb_width' => 100
     1043        'thumb_width' => 100,
     1044        'type' => 1
    10111045    ), $atts));
    10121046   
     
    10231057   
    10241058    foreach ( $postslist as $post ) :  setup_postdata( $post );
    1025             //Fetch the RiotSchedule specific results
     1059        //Fetch the RiotSchedule specific results
    10261060        $schedule_query = 'SELECT * from ' . $wpdb->prefix .
    1027                           'rs_items WHERE pid = ' . $post->ID .             
     1061                          'rs_items WHERE pid = ' . $post->ID .
     1062                          ' AND type = ' . $type .         
    10281063                          ' LIMIT 0, 1';
    10291064        $schedule_item = $wpdb->get_row( $schedule_query );
    1030        
    1031        
    1032         $output .= '<li class="riotschedule-fulllist-item">';
    1033 
    1034         $output .= '<a href=' . get_permalink() . '>';
    1035 
    1036         $output .= '<div class="riotschedule-fulllist-thumb">';
    1037         $output .= get_the_post_thumbnail();           
    1038         $output .= '</div>';
    1039 
    1040         $output .= '<div class="riotschedule-fulllist-title">';
    1041         $output .= get_the_title();
    1042         $output .= '</div>';
    1043        
    1044         $output .= '<div class="riotschedule-fulllist-time">';
    1045         $output .= rs_get_day_string( $schedule_item->day ) . ' ' . rs_get_time_string( $schedule_item->starttime );
    1046         $output .= '</div>';
    1047        
    1048         $output .= '<div class="riotschedule-fulllist-desc">';
    1049         $output .= $schedule_item->description;
    1050         $output .= '</div>';
    1051 
    1052         $output .= '</a>';
    1053 
    1054         $output .= '</li>';     
     1065        if($schedule_item) {
     1066            $output .= '<li class="riotschedule-fulllist-item">';
     1067   
     1068            $output .= '<a href=' . get_permalink() . '>';
     1069   
     1070            $output .= '<div class="riotschedule-fulllist-thumb">';
     1071            $output .= get_the_post_thumbnail();           
     1072            $output .= '</div>';
     1073   
     1074            $output .= '<div class="riotschedule-fulllist-title">';
     1075            $output .= get_the_title();
     1076            $output .= '</div>';
     1077           
     1078            $output .= '<div class="riotschedule-fulllist-time">';
     1079            $output .= rs_get_day_string( $schedule_item->day ) . ' ' . rs_get_time_string( $schedule_item->starttime );
     1080            $output .= '</div>';
     1081           
     1082            $output .= '<div class="riotschedule-fulllist-desc">';
     1083            $output .= $schedule_item->description;
     1084            $output .= '</div>';
     1085   
     1086            $output .= '</a>';
     1087   
     1088            $output .= '</li>';
     1089        }
    10551090    endforeach;
    10561091
     
    12231258    }
    12241259
    1225     $sqldays = "SELECT * from " .  $wpdb->prefix . "rs_days where scheduleid = " . $scheduleid;
     1260    $sqldays = "SELECT * from " .  $wpdb->prefix . "rs_days WHERE scheduleid = " . $scheduleid . "AND enabled = 1 AND scheduleid = " . $scheduleid;
    12261261   
    12271262    if ($daylist != "")
     
    12591294                $output .= "</tr>\n";
    12601295
    1261             $sqlitems = "SELECT *, i.name as itemname, c.name as categoryname, c.id as catid FROM " . $wpdb->prefix . "rs_items i, " . $wpdb->prefix . "rs_categories c WHERE day = " . $day->id . " AND i.scheduleid = " . $scheduleid . " AND i.category = c.id AND i.starttime >= " . $starttime . " AND i.starttime < " . $endtime . " ORDER by starttime";
     1296            $sqlitems = "SELECT *, i.name as itemname, c.name as categoryname, c.id as catid FROM " . $wpdb->prefix . "rs_items i, " . $wpdb->prefix . "rs_categories c WHERE day = " . $day->id . " AND i.scheduleid = " . $scheduleid . " AND i.category = c.id AND i.starttime >= " . $starttime . " AND i.starttime < " . $endtime . " AND i.enabled = 1 AND i.scheduleid = '" . $scheduleid . "' ORDER by starttime";
    12621297
    12631298            $items = $wpdb->get_results($sqlitems);
     
    25182553    $genoptions = get_option("RiotScheduleGeneral");
    25192554   
    2520     if ($genoptions == false) {
     2555    if ( $genoptions == false ) {
    25212556        $genoptions = rs_return_default_genoptions($genoptions);
    25222557        update_option( 'RiotScheduleGeneral', $genoptions );
    25232558    }
     2559    if ( $genoptions['version'] === "2.7" ) {
     2560        // Port from Weekly Schedule may have put this false version number in. Revert back to 1.0
     2561        $genoptions['version'] = "1.0";
     2562        update_option( 'RiotScheduleGeneral', $genoptions );
     2563    }
     2564   
     2565    if ( $genoptions['version'] === "1.0" ) {
     2566        // Add type to scheduled item (introduced 1.1)
     2567        $result = $wpdb->query("ALTER TABLE `$wpdb->rs_items` ADD COLUMN `type` INT(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `enabled`;");
     2568       
     2569        $genoptions['version'] = "1.1";
     2570        update_option( 'RiotScheduleGeneral', $genoptions );
     2571    }
    25242572}
    25252573
Note: See TracChangeset for help on using the changeset viewer.