Guest User

Nudnik

a guest
Oct 25th, 2007
551
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. Plugin Name: RS Event
  5. Plugin URI: http://www.sargant.com/blog/wordpress-plugins/rs-event/
  6. Description: Adds an "RS Event" panel to the posting sidebar, allowing for a date to be set for the post and then displayed in the blog sidebar.
  7. Author: Robert Sargant
  8. Version: 0.9.4
  9. Edited: Nudnik
  10. Author URI: http://www.sargant.com/
  11. */
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. /*** INPUT CONTROLS *******************************************************/
  20.  
  21.  
  22.  
  23. /*** Add the RS Event controls to the posting sidebar */
  24.  
  25. add_action('dbx_post_sidebar', 'rs_event_sidebar_controls');
  26.  
  27.  
  28.  
  29. /*** Manipulate RS Event data when modifying posts */
  30.  
  31. add_action('edit_post', 'rs_event_save');
  32.  
  33. add_action('save_post', 'rs_event_save');
  34.  
  35. add_action('publish_post', 'rs_event_save');
  36.  
  37. add_action('delete_post', 'rs_event_delete');
  38.  
  39.  
  40.  
  41. /*** These defaults are used all over the place */
  42.  
  43.  
  44.  
  45. $rs_event_defaults = array
  46.  
  47. (
  48.  
  49.     "title"          => "Upcoming Events",
  50.  
  51.     "timespan"      => 365,
  52.  
  53.     "history"        => 0,
  54.  
  55.     "date_format"    => "F j",
  56.  
  57.     "time_format"    => "g:i a",
  58.     "time_separator" => "@ ", //New: This puts the characters between the date and time- trailing space recommended!
  59.  
  60.     "event_html"        => "%DATE% %TIME%: <a href='%URL%'>%TITLE%</a>",
  61.  
  62.     "max_events"        => 0,
  63.  
  64.     "group_by_date" => 0,
  65.  
  66.     "no_events_msg" => "No upcoming events.",
  67.  
  68.     "sort_order"        => "ASC",
  69.  
  70.     "category"      => 0,
  71.  
  72. );
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. /*** ADMIN CONTROLS *******************************************************/
  81.  
  82.  
  83.  
  84. /*** Inserts some drop-down menus as an extra posting sidebar panel. */
  85.  
  86. function rs_event_sidebar_controls()
  87.  
  88. {
  89.  
  90.     /*** If there are existing post details, get values to autofill the form */
  91.  
  92.     if(isset($_REQUEST['post']))
  93.  
  94.     {
  95.  
  96.         $event_timestamp = get_post_meta($_REQUEST['post'], "rs_event");
  97.         $event_timestamp = $event_timestamp[0];
  98.        
  99.  
  100.         if($event_timestamp)
  101.  
  102.         {
  103.             $has_time = 1; //check for trailing "n," meaning no time set
  104.             if ($event_timestamp{strlen($event_timestamp)-1} == 'n')
  105.             {
  106.             $has_time = 0;
  107.             }
  108.             settype($event_timestamp, "integer"); //remove "n"
  109.  
  110.         list($year, $month, $day, $hour, $minute) = explode(" ", gmdate("Y n j G i", $event_timestamp));
  111.  
  112.         // Cast as int to get rid of the zero
  113.  
  114.         $hour = (int)$hour;
  115.  
  116.         $minute = (int)$minute;
  117.         $ampm = 1;
  118.        
  119.         if ($hour = 0) { //change 24 hour clock to 12 hour standard
  120.             $hour = 12;
  121.             $ampm = 1;
  122.             }
  123.         elseif ($hour > 12) {
  124.             $hour = ($hour - 12);
  125.             $ampm = 2;
  126.         }
  127.        
  128.         if ($has_time == 0) { //if no time, ensure none gets pre-selected!
  129.             $hour = 99;
  130.             $minute = 99;
  131.             }
  132.  
  133.  
  134.         }
  135.  
  136.     }
  137.  
  138.    
  139.     else     {
  140.  
  141.     $year = date("Y"); //preselect current year
  142.     }
  143.  
  144.  
  145.  
  146.     ?>
  147. <fieldset id="rs_event_dbx" class="dbx-box">
  148.     <h3 class="dbx-handle">Event Date Info</h3>
  149.     <div class="dbx-content">
  150.         <!-- Print current date, for user-friendliness -->
  151.         <span style="color:#999;font-size:.85em;">Today is <?php echo date("F j"); ?></span>
  152.         <br />
  153.        
  154.  
  155.         <?php _e('Date:') ?>
  156.         <br />
  157.         <select name="rs_event_month" style="width: 6em;">
  158.             <option value=""><?php _e('Month') ?></option>
  159.             <option value="">----</option>
  160.  
  161.             <?php foreach(array( 1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec") as $id => $m) { ?>
  162.  
  163.                
  164.  
  165.                 <?php if($id == $month) { ?>
  166.             <option selected="selected" value="<?php echo $id ?>"><?php _e($m) ?></option>
  167.  
  168.                 <?php } else { ?>
  169.             <option value="<?php echo $id ?>"><?php _e($m) ?></option>
  170.  
  171.                 <?php } ?>
  172.  
  173.                
  174.  
  175.             <?php } ?>
  176.         </select>
  177.         <select name="rs_event_day" style="width: 4.5em">
  178.             <option value=""><?php _e('Day') ?></option>
  179.             <option value="">----</option>
  180.  
  181.             <?php for($d = 1; $d <= 31; $d++) { ?>
  182.  
  183.                
  184.  
  185.                 <?php if($d == $day) { ?>
  186.             <option selected="selected" value="<?php echo $d ?>"><?php echo $d ?></option>
  187.  
  188.                 <?php } else { ?>
  189.             <option value="<?php echo $d ?>"><?php echo $d ?></option>
  190.  
  191.                 <?php } ?>
  192.  
  193.              
  194.  
  195.             <?php } ?>
  196.         </select>
  197.         <br />
  198.         <select name="rs_event_year" style="width: 7em;">
  199.             <?php for($y = date("Y")-1; $y <= date("Y")+3; $y++) { ?>
  200.  
  201.                 <?php if($y == $year) { ?>
  202.             <option selected="selected" value="<?php echo $y ?>"><?php echo $y ?></option>
  203.  
  204.                 <?php } else { ?>
  205.             <option value="<?php echo $y ?>"><?php echo $y ?></option>
  206.  
  207.                 <?php } ?>
  208.  
  209.             <?php } ?>
  210.         </select>
  211.         <br />
  212.         <br />
  213.  
  214.        
  215.  
  216.     <?php _e('Time: (Optional)') ?>
  217.         <br />
  218.         <select name="rs_event_hour" style="width: 3.5em;">
  219.                 <option value="notime"><?php _e('Hr') ?></option>
  220.                 <option value="notime">----</option>
  221.                 <?php
  222.  
  223.             for($h = 0; $h < 12; $h++)
  224.         {
  225.             $h_display = ($h + 1);
  226.             $select_me = "";
  227.            
  228.             if($h === $hour)
  229.             {
  230.                 $select_me = "selected=\"selected\"";
  231.             }
  232.                 ?>
  233.             <option <?php echo $select_me ?> value="<?php echo $h ?>"><?php echo $h_display ?></option>
  234.                 <?php
  235.                
  236.         }
  237.             ?>
  238.         </select>
  239.         :
  240.         <select name="rs_event_minute" style="width: 4em;">
  241.             <option value=""><?php _e('Min') ?></option>
  242.             <option value="">----</option>
  243.  
  244.             <?php for($mi = 0; $mi <= 55; $mi = $mi + 5) { ?>
  245.  
  246.                
  247.  
  248.                 <?php if($mi === $minute) { ?>
  249.             <option selected="selected" value="<?php echo $mi ?>"><?php echo str_pad($mi, 2, "0", STR_PAD_LEFT) ?></option>
  250.  
  251.                 <?php } else { ?>
  252.             <option value="<?php echo $mi ?>"><?php echo str_pad($mi, 2, "0", STR_PAD_LEFT) ?></option>
  253.  
  254.                 <?php } ?>
  255.  
  256.              
  257.  
  258.             <?php } ?>
  259.         </select>
  260.         <select name="rs_event_ampm" style="width: 4em">
  261.         <?php
  262.         $switchie = 1; //put in AM/PM values
  263.         while ($switchie < 3)
  264.         {
  265.             echo "<option ";
  266.             if ($switchie == $ampm) {
  267.             echo "selected=\"selected\" ";
  268.             }
  269.             echo "value=\"{$switchie}\">";
  270.             if ($switchie == 1) {
  271.             echo "AM";
  272.             } else {
  273.             echo "PM";
  274.             }
  275.             echo "</option>";
  276.             $switchie++;
  277.         }
  278.         ?>
  279.         </select>
  280.         <br />
  281.         <br />
  282.  
  283.        
  284.  
  285.         <?php if($event_timestamp) {?>
  286.         <label for="rs-event-delete" class="selectit"><input id="rs-event-delete" type="checkbox" name="rs_event_delete" value="1" /> Delete Event</label>
  287.  
  288.            
  289.  
  290.         <?php }
  291.         ?>
  292.     </div>
  293. </fieldset>
  294.  
  295.    
  296.  
  297.     <?php
  298. }
  299.  
  300.  
  301.  
  302. function rs_event_save($id)
  303.  
  304. {
  305.  
  306.     if(!isset($id)) { $id = $_REQUEST['post_ID']; }
  307.  
  308.    
  309.  
  310.     if($_REQUEST['rs_event_delete'])
  311.  
  312.     {
  313.  
  314.         delete_post_meta($id, "rs_event");
  315.  
  316.         return true;
  317.  
  318.     }
  319.  
  320.     elseif($_REQUEST['rs_event_year'] && $_REQUEST['rs_event_month'] && $_REQUEST['rs_event_day'])
  321.  
  322.     {
  323.         if ($_REQUEST['rs_event_hour'] == "notime") {
  324.             $pad_char = "n";
  325.             $_REQUEST['rs_event_hour'] = 0;
  326.             $_REQUEST['rs_event_minute'] = 0;
  327.             }
  328.  
  329.         $hour    = ($_REQUEST['rs_event_hour']) ? $_REQUEST['rs_event_hour'] : 0;
  330.  
  331.         $minute = ($_REQUEST['rs_event_hour']) ? $_REQUEST['rs_event_minute'] : 0;
  332.        
  333.  
  334.         /*** gmmktime stops PHP from interfering with local timezone settings */
  335.  
  336.         $ts = gmmktime($hour, $minute, 0, $_REQUEST['rs_event_month'], $_REQUEST['rs_event_day'], $_REQUEST['rs_event_year']);
  337.         $ts .= "$pad_char";
  338.  
  339.        
  340.  
  341.         delete_post_meta($id, "rs_event");
  342.  
  343.         add_post_meta($id, "rs_event", $ts);
  344.  
  345.         return true;
  346.  
  347.     }
  348.  
  349. }
  350.  
  351.  
  352.  
  353. /*** New in 0.6.2 - delete the event when the parent post is deleted */
  354.  
  355. function rs_event_delete($id)
  356.  
  357. {
  358.  
  359.     if(!isset($id)) { $id = $_REQUEST['post_ID']; }
  360.  
  361.    
  362.  
  363.     delete_post_meta($id, "rs_event");
  364.  
  365.     return true;
  366.  
  367. }
  368.  
  369.  
  370.  
  371.  
  372.  
  373. /*** OUTPUT DISPLAY CONTROLS **********************************************/
  374.  
  375.  
  376.  
  377.  
  378.  
  379. function rs_event_list($args = array())
  380.  
  381. {
  382.  
  383.     global $wpdb, $rs_event_defaults;
  384.  
  385.    
  386.  
  387.     /*** 0.9 - Use array_walk instead (cleaner) */
  388.  
  389.     $values = $rs_event_defaults;
  390.  
  391.     $callback = create_function('&$v, $k, $a', '$v = isset($a[$k]) ? $a[$k] : $v;');
  392.  
  393.     array_walk($values, $callback, $args);
  394.  
  395.     extract($values);
  396.  
  397.    
  398.  
  399.     $lower_time = time() - ($history    * 24 * 60 * 60);
  400.  
  401.     $upper_time = time() + ($timespan * 24 * 60 * 60);
  402.  
  403.    
  404.     //This section has been modified for 2.3
  405.  
  406.     $where_category_clause = (0 == $category) ? '' : 'AND cats.term_taxonomy_id = '.$wpdb->escape(stripslashes($category));
  407.  
  408.    
  409.  
  410.     /*** Modified in 0.6.3 - only select published posts ***/
  411.  
  412.     /*** 0.9 - don't show postdated posts, grab excerpt, DISTINCT modifier if no category restriction ***/
  413.     //This section has been modified for 2.3
  414.  
  415.   $query_string = "
  416.  
  417.     SELECT DISTINCT
  418.  
  419.    meta.meta_value as `date`,
  420.  
  421.    post.post_title as `title`,
  422.  
  423.    post.post_content as `fulltext`,
  424.  
  425.    post.ID as id,
  426.  
  427.    post.post_excerpt as `excerpt`
  428.  
  429.  FROM
  430.  
  431.    {$wpdb->postmeta} as meta,
  432.  
  433.    {$wpdb->posts} as post,
  434.  
  435.    {$wpdb->term_relationships} as cats
  436.  
  437.  WHERE
  438.  
  439.    meta.post_id = post.ID
  440.  
  441.  AND
  442.  
  443.    post.ID = cats.object_id
  444.  
  445.  AND
  446.  
  447.    meta.meta_key = 'rs_event'
  448.  
  449.  AND
  450.  
  451.    post.post_date <= '".current_time('mysql')."'
  452.  
  453.  AND
  454.  
  455.    meta.meta_value >= {$lower_time}
  456.  
  457.  AND
  458.  
  459.    meta.meta_value <= {$upper_time}
  460.  
  461.  AND
  462.  
  463.    post.post_status = 'publish'
  464.  
  465.  {$where_category_clause}
  466.  
  467.  ORDER BY
  468.  
  469.    meta.meta_value {$sort_order}";
  470.  
  471.    
  472.  
  473.     /*** 0.5.1 - Allow event limiting */
  474.  
  475.     if($max_events != 0) { $query_string .= " LIMIT {$max_events}"; }
  476.  
  477.    
  478.  
  479.     /*** Get a list of the events from our query string */
  480.  
  481.     $event_list = $wpdb->get_results($query_string);
  482.  
  483.    
  484.  
  485.     /*** Items for outputting will be placed here for imploding later */
  486.  
  487.     $output_array = array();
  488.  
  489.    
  490.  
  491.     /*** If the query has returned an array, do stuff */
  492.  
  493.     if(is_array($event_list))
  494.  
  495.     {
  496.  
  497.         /*** To store previous dates if we have $group_by_date turned on */
  498.  
  499.         $previous_date = false;
  500.  
  501.        
  502.  
  503.         /*** Loop through each event */
  504.  
  505.         foreach($event_list as $event)
  506.  
  507.         {
  508.  
  509.         /*** Format the date/time/HTML now */
  510.             $show_time = 1; //check if there's a time, set variable
  511.             if (strlen($event->date) == 11) {
  512.             $show_time = 0;
  513.             settype($event->date, "integer");
  514.             }
  515.  
  516.         $output_date = gmdate_i18n($date_format, $event->date);
  517.         $output_time = gmdate_i18n($time_format, $event->date);
  518.  
  519.        
  520.  
  521.         /***
  522.  
  523.             Fake an excerpt if it doesn't exist
  524.  
  525.             Nicked from WP 2.0.3 functions-formatting.php line 721 (stupid globals)
  526.  
  527.         */
  528.  
  529.         if('' == $event->excerpt)
  530.  
  531.         {
  532.  
  533.                 $event->excerpt = $event->fulltext;
  534.  
  535.                 $event->excerpt = apply_filters('the_content', $event->excerpt);
  536.  
  537.                 $event->excerpt = str_replace(']]>', ']]&gt;', $event->excerpt);
  538.  
  539.                 $event->excerpt = strip_tags($event->excerpt);
  540.  
  541.                 $excerpt_length = 55;
  542.  
  543.                 $words = explode(' ', $event->excerpt, $excerpt_length + 1);
  544.  
  545.                 if (count($words) > $excerpt_length)
  546.  
  547.             {
  548.  
  549.                     array_pop($words);
  550.  
  551.                     array_push($words, '[...]');
  552.  
  553.                     $event->excerpt = implode(' ', $words);
  554.  
  555.                 }
  556.  
  557.         }
  558.  
  559.        
  560.  
  561.         /*** Tidy these up into keys/values and add filters */
  562.  
  563.         $replacements = array
  564.  
  565.         (
  566.  
  567.             '%URL%' => get_permalink($event->id),
  568.  
  569.             '%DATE%' => apply_filters('the_date', $output_date),
  570.  
  571.             '%TIME%' => apply_filters('the_time', $output_time),
  572.  
  573.             '%TITLE%' => apply_filters('the_title', $event->title),
  574.  
  575.             '%FULLTEXT%' => apply_filters('the_content', $event->fulltext),
  576.  
  577.             '%EXCERPT%' => apply_filters('the_excerpt', $event->excerpt),
  578.  
  579.         );
  580.  
  581.        
  582.         $replacements['%TIME%'] = $values['time_separator'] . $replacements['%TIME%']; //prepend the time separator to the time output
  583.        
  584.         if ($show_time == 0) { //if there's no time, don't show anything
  585.         $replacements['%TIME%'] = "";
  586.         }
  587.  
  588.         $output_html = str_replace(array_keys($replacements), array_values($replacements), $event_html);
  589.  
  590.                
  591.  
  592.         /*** If we are not grouping by date, output as a list item now. */
  593.  
  594.         if($group_by_date == false) { $output_array[] = $output_html; }
  595.  
  596.        
  597.  
  598.         /*** If we are grouping by date */
  599.  
  600.         else
  601.  
  602.         {
  603.  
  604.             /*** If this is a new date, create a new element in the array */
  605.  
  606.             if($output_date != $previous_date)
  607.  
  608.             {
  609.  
  610.                 $output_array[] = "$output_date<br />";
  611.  
  612.                 $previous_date = $output_date;
  613.  
  614.             }
  615.  
  616.            
  617.  
  618.             /*** Append the event's HTML onto the last item in the list */
  619.  
  620.             $output_array[count($output_array)-1] .= "$output_html<br />";
  621.  
  622.            
  623.  
  624.         }
  625.  
  626.         }
  627.  
  628.     }
  629.  
  630.     /*** If no array returned, say nothing */
  631.  
  632.     else { $output_array[] = $no_events_msg; }
  633.  
  634.    
  635.  
  636.     /*** Now output the array */
  637.  
  638.     echo "<ul><li>".implode("</li><li>", $output_array)."</li></ul>";
  639.  
  640.    
  641.  
  642. } // end rs_event_list
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650. /*** WIDGET FUNCTIONS *****************************************************/
  651.  
  652.  
  653.  
  654. function widget_rs_event_init()
  655.  
  656. {
  657.  
  658.     if (!function_exists('register_sidebar_widget')) { return; }
  659.  
  660.    
  661.  
  662.     function widget_rs_event($args)
  663.  
  664.     {
  665.  
  666.         global $rs_event_defaults;
  667.  
  668.         extract($args);
  669.  
  670.         $options = get_option('widget_rs_event');
  671.         $title = $options['title'];
  672.  
  673.        
  674.  
  675.         echo $before_widget . $before_title . $title . $after_title;
  676.  
  677.        
  678.  
  679.         foreach($rs_event_defaults as $key => $value)
  680.  
  681.         {
  682.  
  683.             if(!$options[$key]) { $options[$key] = $value; }
  684.  
  685.         }
  686.  
  687.        
  688.         rs_event_list($options);
  689.         echo $after_widget;
  690.  
  691.     }
  692.  
  693.    
  694.  
  695.     register_sidebar_widget('RS Event', 'widget_rs_event');
  696.  
  697.    
  698.  
  699.    
  700.  
  701.    
  702.  
  703.     function widget_rs_event_control()
  704.  
  705.     {
  706.  
  707.         global $rs_event_defaults;
  708.         $options = get_option('widget_rs_event');
  709.  
  710.        
  711.  
  712.         foreach($rs_event_defaults as $key => $value)
  713.  
  714.         {
  715.  
  716.             if(!$options[$key]) { $options[$key] = $value; }
  717.  
  718.         }
  719.  
  720.        
  721.         if($_POST['rs_event_submit'])
  722.  
  723.         {
  724.  
  725.             $callback = create_function('&$v,$k', '$v = stripslashes($_POST["rs_event_".$k]); if($k != "event_html" && $k != "no_events_msg"){$v = strip_tags($v);}');
  726.  
  727.             array_walk($options, $callback);
  728.             update_option('widget_rs_event', $options);
  729.         }
  730.  
  731.        
  732.  
  733.         $callback = create_function('&$v,$k', '$v = htmlspecialchars($v, ENT_QUOTES);');
  734.  
  735.         array_walk($options, $callback);
  736.  
  737.         extract($options);
  738.        
  739.  
  740.         ?>
  741. <script type="text/javascript">
  742.     function insert_tag(value) {rs_event_insert_at_cursor(document.getElementById("rs_event_event_html"), '%'+value+'%');}
  743.     function rs_event_insert_at_cursor(f,v) { if(document.selection){f.focus();sel=document.selection.createRange();sel.text=v;}else if (f.selectionStart||f.selectionStart=="0"){var startPos=f.selectionStart;var endPos = f.selectionEnd;f.value = f.value.substring(0, startPos)+v+f.value.substring(endPos, f.value.length);} else {f.value+=v;}}
  744. </script>
  745. <fieldset style="float: left; width: 340px">
  746.     <legend style="font-weight: bold">Output Options</legend>
  747.     <p style="text-align:right">
  748.         <label for="rs_event_title">Title:</label>
  749.         <input style="width: 200px;" id="rs_event_title" name="rs_event_title" type="text" value="<?php echo $title ?>" />
  750.     </p>
  751.     <p style="text-align:right">
  752.         <label for="rs_event_event_html">Output HTML:</label>
  753.         <input style="width: 200px" id="rs_event_event_html" name="rs_event_event_html" type="text" value="<?php echo $event_html ?>" />
  754.     </p>
  755.     <p style="text-align:right">
  756.         <small>
  757.             Insert:
  758.             <a href="javascript:insert_tag('URL')"><code>URL</code></a>,
  759.             <a href="javascript:insert_tag('TITLE')"><code>TITLE</code></a>,
  760.             <a href="javascript:insert_tag('DATE')"><code>DATE</code></a>,
  761.             <a href="javascript:insert_tag('TIME')"><code>TIME</code></a>,
  762.             <a href="javascript:insert_tag('FULLTEXT')"><code>FULLTEXT</code></a>,
  763.             <a href="javascript:insert_tag('EXCERPT')"><code>EXCERPT</code></a>
  764.         </small>
  765.     </p>
  766.     <p style="text-align:right">
  767.         <label for="rs_event_no_events_msg">"No events" message:</label>
  768.         <input style="width: 150px" id="rs_event_no_events_msg" name="rs_event_no_events_msg" type="text" value="<?php echo $no_events_msg ?>" />
  769.     </p>
  770.     <p style="text-align:right;">
  771.         "Group by date" formatting?
  772.         <label for="rs_event_group_by_date_true">
  773.             <input type="radio" name="rs_event_group_by_date" id="rs_event_group_by_date_true" value="1" <?php echo ($group_by_date?'checked="checked"':'') ?> /> Yes
  774.         </label>
  775.         <label for="rs_event_group_by_date_false">
  776.             <input type="radio" name="rs_event_group_by_date" id="rs_event_group_by_date_false" value="0" <?php echo (!$group_by_date?'checked="checked"':'') ?> /> No
  777.         </label>
  778.     </p>
  779.     <p style="text-align:right">
  780.         <label for="rs_event_date_format">Date Formatting:</label>
  781.         <input style="width: 70px;" id="rs_event_date_format" name="rs_event_date_format" type="text" value="<?php echo $date_format ?>" />
  782.     </p>
  783.     <p style="text-align:right">
  784.         <label for="rs_event_time_format">Time Formatting:</label>
  785.         <input style="width: 70px;" id="rs_event_time_format" name="rs_event_time_format" type="text" value="<?php echo $time_format ?>" />
  786.     </p>
  787.     <p style="text-align:right">
  788.         <a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on time and date formatting</a>
  789.     </p>
  790. </fieldset>
  791. <fieldset style="float: right; width: 340px">
  792.     <legend style="font-weight: bold">Selection Options</legend>
  793.     <p style="text-align:right">
  794.         <label for="rs_event_timespan">Timespan:</label>
  795.         <input style="width: 40px; text-align: right" id="rs_event_timespan" name="rs_event_timespan" type="text" value="<?php echo $timespan ?>" /> days
  796.     </p>
  797.     <p style="text-align:right;">
  798.         <label for="rs_event_history">History:</label>
  799.         <input style="width: 40px; text-align: right" id="rs_event_history" name="rs_event_history" type="text" value="<?php echo $history ?>" /> days
  800.     </p>
  801.     <p style="text-align:right">
  802.         <label for="rs_event_max_events">Show up to (0 for all): </label>
  803.         <input style="width: 40px; text-align: right" id="rs_event_max_events" name="rs_event_max_events" type="text" value="<?php echo $max_events ?>" /> events
  804.     </p>
  805.     <p style="text-align:right">
  806.         Sort Order:
  807.         <label for="rs_event_sort_order_asc">
  808.             <input type="radio" name="rs_event_sort_order" id="rs_event_sort_order_asc" value="ASC" <?php echo ("ASC" == $sort_order) ?'checked="checked"':'' ?> /> Ascending
  809.         </label>
  810.         <label for="rs_event_sort_order_desc">
  811.             <input type="radio" name="rs_event_sort_order" id="rs_event_sort_order_desc" value="DESC" <?php echo ("DESC" == $sort_order) ?'checked="checked"':'' ?> /> Descending
  812.         </label>
  813.     </p>
  814. </fieldset>
  815. <input type="hidden" id="rs_event_submit" name="rs_event_submit" value="1" />
  816.  
  817.        
  818.  
  819.         <?php
  820.     }
  821.  
  822.    
  823.  
  824.     register_widget_control('RS Event', 'widget_rs_event_control', 700, 350);
  825.  
  826. }
  827.  
  828.  
  829.  
  830. add_action('plugins_loaded', 'widget_rs_event_init');
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838. /*** The standard date_i18n uses machine timezones - BAD! *****************/
  839.  
  840.  
  841.  
  842. function gmdate_i18n($dateformatstring, $unixtimestamp)
  843.  
  844. {
  845.  
  846.     global $month, $weekday, $month_abbrev, $weekday_abbrev;
  847.  
  848.     $i = $unixtimestamp;
  849.     if ((!empty($month)) && (!empty($weekday)))
  850.  
  851.     {
  852.  
  853.         $datemonth = $month[date('m', $i)];
  854.  
  855.         $datemonth_abbrev = $month_abbrev[$datemonth];
  856.  
  857.         $dateweekday = $weekday[date('w', $i)];
  858.  
  859.         $dateweekday_abbrev = $weekday_abbrev[$dateweekday];
  860.  
  861.         $dateformatstring = ' '.$dateformatstring;
  862.  
  863.         $dateformatstring = preg_replace("/([^\\\])D/", "\${1}".backslashit($dateweekday_abbrev), $dateformatstring);
  864.  
  865.         $dateformatstring = preg_replace("/([^\\\])F/", "\${1}".backslashit($datemonth), $dateformatstring);
  866.  
  867.         $dateformatstring = preg_replace("/([^\\\])l/", "\${1}".backslashit($dateweekday), $dateformatstring);
  868.  
  869.         $dateformatstring = preg_replace("/([^\\\])M/", "\${1}".backslashit($datemonth_abbrev), $dateformatstring);
  870.  
  871.         $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
  872.  
  873.     }
  874.  
  875.     $j = @gmdate($dateformatstring, $i);
  876.  
  877.     return $j;
  878.  
  879. }
  880.  
  881.  
  882.  
  883. ?>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×