WordPress.org

Plugin Directory

Changeset 340396


Ignore:
Timestamp:
02/03/11 18:49:13 (3 years ago)
Author:
goldenapples
Message:
 
Location:
external-events-calendar/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • external-events-calendar/trunk/gad-events-calendar.php

    r278380 r340396  
    55Description: Adds the ability to display links of time-stamped events as a calendar. 
    66Author: Nathaniel Taintor 
    7 Version: 0.3.1 
     7Version: 0.4.0 
    88Author URI: http://goldenapplesdesign.com 
    99*/ 
    1010 
    1111global $wpdb; 
    12 define("EXTEVTCAL_PLUGIN_DIR", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) ))); 
    13 define("EXTEVTCAL_PLUGIN_PATH", path_join(WP_PLUGIN_DIR, basename( dirname( __FILE__ ) ))); 
    14 define("EXTEVTCAL_TABLE",$wpdb->prefix.'linkmeta'); 
    15  
    16 register_activation_hook(__FILE__,'extevtcal_install'); 
    17  
    18 function extevtcal_install() { 
     12define( "EXTEVTCAL_PLUGIN_DIR", path_join( WP_PLUGIN_URL, basename( dirname( __FILE__ ) ) ) ); 
     13define( "EXTEVTCAL_PLUGIN_PATH", path_join( WP_PLUGIN_DIR, basename( dirname( __FILE__ ) ) ) ); 
     14define( "EXTEVTCAL_TABLE", $wpdb->prefix . 'linkmeta' ); 
     15 
     16register_activation_hook( __FILE__, 'extevtcal_install' ); 
     17 
     18function extevtcal_install( ) { 
    1919    global $wp_version; 
    20     if (version_compare($wp_version, "2.9", "<")) { 
    21         deactivate_plugins(basename(__FILE__)); 
    22         wp_die("This plugin requires Wordpress version 2.9 or higher."); 
    23     } 
    24      
    25     if (!is_term('Events Calendar')) wp_insert_term('Events Calendar','link_category'); 
     20    if (version_compare( $wp_version, "2.9", "<" )) { 
     21        deactivate_plugins( basename( __FILE__ ) ); 
     22        wp_die( "This plugin requires WordPress version 2.9 or higher." ); 
     23    } 
     24 
     25    if (!term_exists( 'Events Calendar' )) wp_insert_term( 'Events Calendar', 'link_category' ); 
    2626 
    2727    // create linkmeta table if it doesn't exist 
    2828    global $wpdb; 
    29     if ($wpdb->get_var("SHOW TABLES LIKE '".EXTEVTCAL_TABLE."'") != EXTEVTCAL_TABLE) { 
    30         $sql = "CREATE TABLE `".EXTEVTCAL_TABLE."` ( 
     29    if ($wpdb->get_var( "SHOW TABLES LIKE '" . EXTEVTCAL_TABLE . "'" ) != EXTEVTCAL_TABLE) { 
     30        $sql = "CREATE TABLE `" . EXTEVTCAL_TABLE . "` ( 
    3131                `meta_id` BIGINT( 20 ) NOT NULL AUTO_INCREMENT , 
    3232                `link_id` BIGINT( 20 ) NOT NULL , 
     
    3636                UNIQUE ( `meta_id` ) 
    3737                )"; 
    38         require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
    39         dbDelta($sql); 
    40         update_option('extevtcal_db_version','0.1'); 
    41         if (!get_option('extevtcal_date_formatting')) update_option('extevtcal_date_formatting','builtin'); 
    42         if (!get_option('extevtcal_link_position')) update_option('extevtcal_link_position','title_only'); 
    43         if (!get_option('extevtcal_use_css')) update_option('extevtcal_link_position',true); 
    44     } 
    45 } 
    46  
     38        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 
     39        dbDelta( $sql ); 
     40        update_option( 'extevtcal_db_version', '0.1' ); 
     41        if (!get_option( 'extevtcal_date_formatting' )) update_option( 'extevtcal_date_formatting', 'builtin' ); 
     42        if (!get_option( 'extevtcal_link_position' )) update_option( 'extevtcal_link_position', 'title_only' ); 
     43        if (!get_option( 'extevtcal_use_css' )) update_option( 'extevtcal_use_css', true ); 
     44        if (!get_option( 'extevtcal_currentday_behavior' )) update_option( 'extevtcal_currentday_behavior', 'default' ); 
     45    } 
     46} 
    4747 
    4848/** 
    49 * Defining some get and update meta functions.  
    50 * These function similarly to get_post_meta and update_post_meta 
    51 * 
    52 * @package external-events-calendar 
    53 * @since 0.1 
    54 * 
    55 * @param int    $link   The ID of the link to check 
    56 * @param string $key    The name of the key to check 
    57 * @param string $value  The value to update $key for on $link 
    58 */ 
    59 function get_link_meta($link,$key) { 
    60     if ( !$link = absint($link) ) return false; 
     49 * Defining some get and update meta functions. 
     50 * These function similarly to get_post_meta and update_post_meta 
     51 * 
     52 * @package external-events-calendar 
     53 * @since 0.1 
     54 * 
     55 * @param int       $link   The ID of the link to check 
     56 * @param string    $key    The name of the key to check 
     57 * @param string    $value  The value to update $key for on $link 
     58 */ 
     59function get_link_meta( $link, $key ) { 
     60    if (!$link = absint( $link )) return false; 
    6161    global $wpdb; 
    62     $table_name = $wpdb->prefix.'linkmeta'; 
    63     $linkmeta = $wpdb->get_var( "SELECT meta_value FROM `".$table_name."` WHERE `link_id` = '".$link."' AND `meta_key` = '".$key."'" ); 
     62    $linkmeta = $wpdb->get_var( "SELECT meta_value FROM `".EXTEVTCAL_TABLE."` WHERE `link_id` = '$link' AND `meta_key` = '$key'" ); 
    6463    return $linkmeta; 
    6564} 
    6665 
    67 function update_link_meta($link,$key,$value) { 
     66function update_link_meta( $link, $key, $value ) { 
    6867    global $wpdb; 
    69     $table_name = $wpdb->prefix.'linkmeta'; 
    70     $exists = $wpdb->get_results( "SELECT meta_key,meta_value FROM `".$table_name."` WHERE `link_id` = '".$link."' AND `meta_key` = '".$key."'" ); 
    71     if (!$exists) $wpdb->insert( $table_name, array ('link_id'=>$link,'meta_key'=>$key,'meta_value'=>$value), array('%d','%s','%s') ); 
    72     else $wpdb->update( $table_name, array ('meta_value'=>$value), array('link_id'=>$link,'meta_key'=>$key),array('%s'),array('%d','%s') ); 
     68    $exists = $wpdb->get_results( "SELECT meta_key,meta_value FROM `".EXTEVTCAL_TABLE."` WHERE `link_id` = '$link' AND `meta_key` = '$key'" ); 
     69    if (!$exists) $wpdb->insert( EXTEVTCAL_TABLE, array('link_id' => $link, 'meta_key' => $key, 'meta_value' => $value), array('%d', '%s', '%s') ); 
     70    else $wpdb->update( EXTEVTCAL_TABLE, array('meta_value' => $value), array('link_id' => $link, 'meta_key' => $key), array('%s'), array('%d', '%s') ); 
     71} 
     72 
     73function dateformat( ) { 
     74    if (get_option( 'extevtcal_date_formatting' ) == 'WP_setting') 
     75        $dateformat = get_option( 'date_format' ); 
     76    elseif (get_option( 'extevtcal_date_formatting' ) == 'WP_setting_time') 
     77        $dateformat = get_option( 'links_updated_date_format' ); 
     78    elseif (get_option( 'extevtcal_date_formatting' ) != 'builtin') 
     79        $dateformat = get_option( 'extevtcal_date_customformat' ); 
     80    else $dateformat = false; 
     81    return $dateformat; 
    7382} 
    7483 
    7584/** 
    76 * Sorts an array of events by date.  
    77 * Used in admin page and widget output 
    78 * 
    79 * @package external-events-calendar 
    80 * @since 0.3 
    81 * 
    82 * @param array      $eventslist     Array of links returned by wp_get_bookmarks or get_objects_in_term 
    83 * @param ASC|DEC    $sortorder      Sort events current to future, or future to current 
    84 * @param bool       $showpastevents Whether or not to include past events in returned array 
    85 */ 
    86 function sortListings($eventslist, $sortorder='DEC', $showpastevents=true) { 
     85 * Sorts an array of events by date. 
     86 * Used in admin page and widget output 
     87 * 
     88 * @package external-events-calendar 
     89 * @since 0.3 
     90 * 
     91 * @param array     $eventslist     Array of links returned by wp_get_bookmarks or get_objects_in_term 
     92 * @param ASC|DEC   $sortorder      Sort events current to future, or future to current 
     93 * @param string    $showevents     Whether or not to include past events in returned array. 
     94 *                                  Possible values: false / 'upcomingonly' | true / 'allevents' | 'pastonly' 
     95 */ 
     96function sortListings( $eventslist, $sortorder = 'DESC', $showevents = 'allevents' ) { 
    8797    $sortarray = array(); 
    8898    $eventlisting = array(); 
     99    $behavior = get_option('extevtcal_currentday_behavior'); 
     100    if ( $behavior == 'today' ) 
     101        $currenttime = strtotime( 'yesterday 11:59pm' ); 
     102    elseif ( $behavior == 'thisweek' ) { 
     103        $days = array( 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' ); 
     104        $currenttime = strtotime( 'last '.$days[get_option('start_of_week')].', 12:00am' ); 
     105    } else $currenttime = time( ); 
    89106    foreach ($eventslist as $link) { 
    90         $location = get_link_meta($link,'extevt_location'); 
    91         $startdate = get_link_meta($link,'extevt_start_date'); 
    92         $enddate = get_link_meta($link,'extevt_end_date'); 
    93         $sortnumber = strtotime($startdate); 
    94         if ($showpastevents || ($sortnumber > time() ) ) { 
    95             array_push($sortarray, $sortnumber); 
    96             array_push($eventlisting, array( 
    97                 'id'=>$link, 
    98                 'location'=>$location, 
    99                 'startdate'=>$startdate, 
    100                 'enddate'=>$enddate)); 
    101         } 
    102     } 
    103     if ($sortorder=='DEC') array_multisort($sortarray,SORT_DESC,SORT_NUMERIC,$eventlisting); 
    104     else array_multisort($sortarray,$eventlisting); 
     107        $location = get_link_meta( $link, 'extevt_location' ); 
     108        $startdate = get_link_meta( $link, 'extevt_start_date' ); 
     109        $enddate = get_link_meta( $link, 'extevt_end_date' ); 
     110        $sortnumber = strtotime( $startdate ); 
     111        if ( ( ( $showevents != 'pastonly' ) && ( 
     112                ( ( $showevents == 'allevents' ) || ( $showevents === true ) || ( $sortnumber > $currenttime ) ) 
     113                || ( ( $behavior == 'enddate' ) && !empty( $enddate ) && ( strtotime( $enddate ) > $currenttime ) ) ) ) 
     114                || ( ( $showevents == 'pastonly') && ( $sortnumber < time() ) ) ) { 
     115            array_push( $sortarray, $sortnumber ); 
     116            array_push( $eventlisting, array( 
     117                'id' => $link, 
     118                'sortnumber' => $sortnumber, 
     119                'location' => $location, 
     120                'startdate' => $startdate, 
     121                'enddate' => $enddate) ); 
     122        } 
     123    } 
     124    if ($sortorder == 'DESC') array_multisort( $sortarray, SORT_DESC, SORT_NUMERIC, $eventlisting ); 
     125    else array_multisort( $sortarray, $eventlisting ); 
    105126    return $eventlisting; 
    106127} 
    107128 
    108129/** 
    109 * Displays date listings as a range.  
    110 * Used in admin page and widget output 
    111 * 
    112 * @package external-events-calendar 
    113 * @since 0.3 
    114 * 
    115 * @param string         $startdate      Start date of event 
    116 * @param string         $senddate       End date of event 
    117 * @param bool|string    $customformat   False (use dates as entered)|Date format string to reformat dates 
    118 */ 
    119 function processDateListing( $startdate='', $enddate='', $customformat=false) { 
     130 * Displays date listings as a range. 
     131 * Used in admin page and widget output 
     132 * 
     133 * @package external-events-calendar 
     134 * @since 0.3 
     135 * 
     136 * @param string            $startdate      Start date of event 
     137 * @param string            $senddate       End date of event 
     138 * @param bool|string       $customformat   False (use dates as entered)|Date format string to reformat dates 
     139 */ 
     140function processDateListing( $startdate = '', $enddate = '', $customformat = false ) { 
    120141    if (!$enddate) { // single date only 
    121         if ($customformat) $startdate = date_i18n( __($customformat),strtotime($startdate)); 
    122         return $startdate;  
     142        if ($customformat) $startdate = date_i18n( __( $customformat ), strtotime( $startdate ) ); 
     143        return $startdate; 
    123144    } else { 
    124         $enddatearray=getdate(strtotime($enddate)); 
    125         $startdatearray=getdate(strtotime($startdate)); 
    126         $difference = array_diff($startdatearray,$enddatearray); 
     145        $enddatearray = getdate( strtotime( $enddate ) ); 
     146        $startdatearray = getdate( strtotime( $startdate ) ); 
     147        $difference = array_diff( $startdatearray, $enddatearray ); 
    127148        if ($customformat) { 
    128             $startdate = date_i18n( __($customformat),strtotime($startdate)); 
    129             $enddate = date_i18n( __($customformat),strtotime($enddate)); 
    130         } 
    131     } 
    132     if (!$difference['mon'] && !$difference['year'] && !$difference['mday'] &&  
    133             ($difference['hours'] || $difference['minutes'])) { 
     149            $startdate = date_i18n( __( $customformat ), strtotime( $startdate ) ); 
     150            $enddate = date_i18n( __( $customformat ), strtotime( $enddate ) ); 
     151        } 
     152    } 
     153    if (!isset( $difference['mon'] ) && !isset( $difference['year'] ) && !isset( $difference['mday'] ) && 
     154            ( isset( $difference['hours'] ) || isset( $difference['minutes'] ) )) { 
    134155        // same day, range should reflect time only 
    135         if (preg_match('/(?<=[^a-zA-Z0-9])('.$startdatearray['hours'].$startdatearray['minutes'].')(?=[^a-zA-Z0-9])/',$startdate)) { 
     156        if (preg_match( '/(?<=[^a-zA-Z0-9])(' . $startdatearray['hours'] . $startdatearray['minutes'] . ')(?=[^a-zA-Z0-9])/', $startdate )) { 
    136157            //simplest possibility; military time 
    137             return preg_replace('/(?<=[^a-zA-Z0-9])('.$difference['hours'].$difference['minutes'].')(?=[^a-zA-Z0-9])/', 
    138                 '$1&ndash;'.$enddatearray['hours'].$enddatearray['minutes'],$startdate); 
    139         } elseif (preg_match('/(?<=[^a-zA-Z0-9])('.date('g:i',mktime($startdatearray['hours'],$startdatearray['minutes'])).')(?=[^a-zA-Z0-9])/',$startdate)) { 
     158            return preg_replace( '/(?<=[^a-zA-Z0-9])(' . $difference['hours'] . $difference['minutes'] . ')(?=[^a-zA-Z0-9])/', 
     159                    '$1&ndash;' . $enddatearray['hours'] . $enddatearray['minutes'], $startdate ); 
     160        } elseif (preg_match( '/(?<=[^a-zA-Z0-9])(' . date( 'g:i', mktime( $startdatearray['hours'], $startdatearray['minutes'] ) ) . ')(?=[^a-zA-Z0-9])/', $startdate )) { 
    140161            //g:ia format 
    141             return preg_replace('/(?<=[^a-zA-Z0-9])('.date('g:i',mktime($startdatearray['hours'],$startdatearray['minutes'])).')(?=[^a-zA-Z0-9])/','$1&ndash;'.date('g:i',mktime($enddatearray['hours'],$enddatearray['minutes'])),$startdate); 
    142         } 
    143     } elseif (!$difference['mon'] && !$difference['year'] && $difference['mday']) { 
     162            return preg_replace( '/(?<=[^a-zA-Z0-9])(' . date( 'g:i', mktime( $startdatearray['hours'], $startdatearray['minutes'] ) ) . ')(?=[^a-zA-Z0-9])/', '$1&ndash;' . date( 'g:i', mktime( $enddatearray['hours'], $enddatearray['minutes'] ) ), $startdate ); 
     163        } 
     164    } elseif (!isset( $difference['mon'] ) && !isset( $difference['year'] ) && isset( $difference['mday'] )) { 
    144165        // no difference in month or year; find day and append endash & enddate 
    145         if (preg_match('/(?<=[^a-zA-Z0-9])('.$difference['mday'].')(?=[^a-zA-Z0-9])/',$startdate)) { 
    146             return preg_replace('/(?<=[^a-zA-Z0-9])('.$difference['mday'].')(?=[^a-zA-Z0-9])/','$1&ndash;'.$enddatearray['mday'], 
    147                 $startdate); 
    148         } 
    149     } elseif (!$difference['year'] && $difference['mon'] && $difference['mday']) { 
     166        if (preg_match( '/(?<=[^a-zA-Z0-9])(' . $difference['mday'] . ')(?=[^a-zA-Z0-9])/', $startdate )) { 
     167            return preg_replace( '/(?<=[^a-zA-Z0-9])(' . $difference['mday'] . ')(?=[^a-zA-Z0-9])/', '$1&ndash;' . $enddatearray['mday'], 
     168                $startdate ); 
     169        } 
     170    } elseif (!isset( $difference['year'] ) && isset( $difference['mon'] ) && isset( $difference['mday'] )) { 
    150171        // no difference in year, add end month and date 
    151         if (preg_match('/(?<![a-zA-Z0-9+])('.$difference['mday'].')([^a-zA-Z0-9]+)('.$difference['month'].')(?=[^a-zA-Z0-9])/', 
    152                     $startdate)) { 
     172        if (preg_match( '/(?<![a-zA-Z0-9+])(' . $difference['mday'] . ')([^a-zA-Z0-9]+)(' . $difference['month'] . ')(?=[^a-zA-Z0-9])/', 
     173            $startdate )) { 
    153174            // j F format: 
    154             return preg_replace('/(?<![a-zA-Z0-9+])('.$difference['mday'].')([^a-zA-Z0-9]+)('.$difference['month'].')(?=[^a-zA-Z0-9])/', 
    155                                 '$1$2$3&ndash;'.$enddatearray['mday'].'$2'.$enddatearray['month'],$startdate); 
    156         } elseif (preg_match('/(?<![a-zA-Z0-9+])('.$difference['month'].')([^a-zA-Z0-9+])('.$difference['mday'].')(?=[^a-zA-Z0-9])/', 
    157                                 $startdate)) { 
     175            return preg_replace( '/(?<![a-zA-Z0-9+])(' . $difference['mday'] . ')([^a-zA-Z0-9]+)(' . $difference['month'] . ')(?=[^a-zA-Z0-9])/', 
     176                    '$1$2$3&ndash;' . $enddatearray['mday'] . '$2' . $enddatearray['month'], $startdate ); 
     177        } elseif (preg_match( '/(?<![a-zA-Z0-9+])(' . $difference['month'] . ')([^a-zA-Z0-9+])(' . $difference['mday'] . ')(?=[^a-zA-Z0-9])/', 
     178            $startdate )) { 
    158179            // F j format: 
    159             return preg_replace('/(?<![a-zA-Z0-9+])('.$difference['month'].')([^a-zA-Z0-9+])('.$difference['mday'].')(?=[^a-zA-Z0-9])/', 
    160                                 '$1$2$3&ndash;'.$enddatearray['month'].' '.$enddatearray['mday'],$startdate); 
    161         } elseif (preg_match('/(?<![a-zA-Z0-9+])('.$difference['mday'].')([^a-zA-Z0-9]+)('.substr($difference['month'],0,3). 
    162                                 ')([^a-zA-Z0-9]+)/',$startdate)) { 
     180            return preg_replace( '/(?<![a-zA-Z0-9+])(' . $difference['month'] . ')([^a-zA-Z0-9+])(' . $difference['mday'] . ')(?=[^a-zA-Z0-9])/', 
     181                    '$1$2$3&ndash;' . $enddatearray['month'] . ' ' . $enddatearray['mday'], $startdate ); 
     182        } elseif (preg_match( '/(?<![a-zA-Z0-9+])(' . $difference['mday'] . ')([^a-zA-Z0-9]+)(' . substr( $difference['month'], 0, 3 ) . 
     183                ')([^a-zA-Z0-9]+)/', $startdate )) { 
    163184            // j M format: 
    164             return preg_replace('/(?<![a-zA-Z0-9+])('.$difference['mday'].')([^a-zA-Z0-9]+)('.substr($difference['month'],0,3). 
    165                                 ')(?=[^a-zA-Z0-9])/','$1$2$3&ndash;'.$enddatearray['mday'].' '.substr($enddatearray['month'],0,3), 
    166                                 $startdate); 
    167         } elseif (preg_match('/(?<![a-zA-Z0-9+])('.substr($difference['month'],0,3).')([^a-zA-Z0-9]+)('. 
    168                                 $difference['mday'].')(?=[^a-zA-Z0-9])/',$startdate)) { 
     185            return preg_replace( '/(?<![a-zA-Z0-9+])(' . $difference['mday'] . ')([^a-zA-Z0-9]+)(' . substr( $difference['month'], 0, 3 ) . 
     186                    ')(?=[^a-zA-Z0-9])/', '$1$2$3&ndash;' . $enddatearray['mday'] . ' ' . substr( $enddatearray['month'], 0, 3 ), 
     187                $startdate ); 
     188        } elseif (preg_match( '/(?<![a-zA-Z0-9+])(' . substr( $difference['month'], 0, 3 ) . ')([^a-zA-Z0-9]+)(' . 
     189                $difference['mday'] . ')(?=[^a-zA-Z0-9])/', $startdate )) { 
    169190            // M j format: 
    170             return preg_replace('/(?<![a-zA-Z0-9+])('.substr($difference['month'],0,3).')([^a-zA-Z0-9]+)('.$difference['mday']. 
    171                                 ')(?=[^a-zA-Z0-9])/','$1$2$3&ndash;'.substr($enddatearray['month'],0,3).' '.$enddatearray['mday'], 
    172                                 $startdate); 
    173         }  
    174     }  
     191            return preg_replace( '/(?<![a-zA-Z0-9+])(' . substr( $difference['month'], 0, 3 ) . ')([^a-zA-Z0-9]+)(' . $difference['mday'] . 
     192                    ')(?=[^a-zA-Z0-9])/', '$1$2$3&ndash;' . substr( $enddatearray['month'], 0, 3 ) . ' ' . $enddatearray['mday'], 
     193                $startdate ); 
     194        } 
     195    } 
    175196    // if all fields are different, or we can't parse date format 
    176     return $startdate.' &ndash; '.$enddate; 
    177 } 
    178  
    179 add_action('admin_init','add_extevtcal_metabox'); 
    180 add_action('edit_link','save_extevtcal_metabox'); 
    181 add_action('add_link','save_extevtcal_metabox'); 
    182 add_action('admin_menu','add_extevtcal_submenu_pages'); 
    183  
    184 function add_extevtcal_submenu_pages() { 
    185     add_links_page(__('Manage Event Listings','extevtcal_plugin'),__('Events Calendar','extevtcal_plugin'),'manage_links','extevtcal_manage_events','extevtcal_manage_events'); 
    186     add_options_page(__('Events Calendar Options','extevtcal_plugin'),__('Events Calendar','extevtcal_plugin'),'manage_options','extevtcal_settings_page','extevtcal_settings_page'); 
    187     add_action('admin_init','register_extevtcal_settings'); 
    188 } 
    189  
    190 function add_extevtcal_metabox() { 
    191     add_meta_box('extevtcal_metabox',__('Event Information','extevtcal_plugin'),'extevtcal_metabox','link','normal','high'); 
    192 }  
    193  
    194 function register_extevtcal_settings() { 
     197    return $startdate . ' &ndash; ' . $enddate; 
     198} 
     199 
     200add_action( 'admin_init', 'add_extevtcal_metabox' ); 
     201add_action( 'edit_link', 'save_extevtcal_metabox' ); 
     202add_action( 'add_link', 'save_extevtcal_metabox' ); 
     203add_action( 'admin_menu', 'add_extevtcal_submenu_pages' ); 
     204add_action( 'widgets_init', 'extevtcal_register_widgets' ); 
     205add_action( 'admin_head-link-add.php', 'check_extevtcal_category' ); 
     206 
     207function check_extevtcal_category() { 
     208    if (!isset($_GET['type']) || ($_GET['type'] != 'external-event')) 
     209        return; 
     210    ?> 
     211    <script type="text/javascript"> 
     212        jQuery(document).ready(function() { 
     213            jQuery("#in-link-category-<?php echo term_exists('Events Calendar'); ?>").attr('checked',"checked"); 
     214        }); 
     215    </script> 
     216    <?php 
     217} 
     218 
     219function add_extevtcal_submenu_pages( ) { 
     220    add_links_page( __( 'Manage Event Listings', 'extevtcal_plugin' ), __( 'Events Calendar', 'extevtcal_plugin' ), 'manage_links', 'extevtcal_manage_events', 'extevtcal_manage_events' ); 
     221    add_options_page( __( 'Events Calendar Options', 'extevtcal_plugin' ), __( 'Events Calendar', 'extevtcal_plugin' ), 'manage_options', 'extevtcal_settings_page', 'extevtcal_settings_page' ); 
     222    add_action( 'admin_init', 'register_extevtcal_settings' ); 
     223} 
     224 
     225function add_extevtcal_metabox( ) { 
     226    add_meta_box( 'extevtcal_metabox', __( 'Event Information', 'extevtcal_plugin' ), 'extevtcal_metabox', 'link', 'normal', 'high' ); 
     227} 
     228 
     229function register_extevtcal_settings( ) { 
    195230    register_setting( 'extevtcal-settings', 'extevtcal_date_formatting' ); 
     231    register_setting( 'extevtcal-settings', 'extevtcal_date_customformat' ); 
    196232    register_setting( 'extevtcal-settings', 'extevtcal_link_position' ); 
    197233    register_setting( 'extevtcal-settings', 'extevtcal_use_css' ); 
    198 } 
    199  
    200 function extevtcal_settings_page() { ?> 
    201     <div class="wrap"><div id="icon-options-general" class="icon32"></div> 
    202     <h2><?php _e('Events Calendar Options','extevtcal_plugin'); ?></h2> 
    203      
    204     <form method="POST" action="options.php"> 
    205     <?php settings_fields('extevtcal-settings');  
    206             $setting_date_formatting = get_option('extevtcal_date_formatting');  
    207             $setting_link_position = get_option('extevtcal_link_position'); 
    208             $setting_use_css = get_option('extevtcal_use_css'); 
    209                 //dummy values to demonstrate date formats 
    210                 date_default_timezone_set(get_option('timezone_string')); 
    211                 $today = date('F j, Y g:ia'); 
    212                 $later = date('F j, Y g:ia',time()+1014400); ?> 
    213         <table class="form-table"> 
    214             <tr valign="top"><th scope="row"><?php _e('Date format to use:','extevtcal_plugin'); ?></th> 
    215             <td><table cellpadding="0" cellspacing="0"><tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_date_formatting" value="builtin" <?php  
    216                 if ($setting_date_formatting == "builtin") echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php  
    217                 echo __('Use dates/times as entered (may not work well with non-US English date formats)','extevtcal_plugin').'<br /><em>'; 
    218                 echo __('Example','extevtcal_plugin').': '.processDateListing($today,$later,false); ?></em></td></tr> 
    219                 <tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_date_formatting" value="WP_setting" <?php  
    220                 if ($setting_date_formatting == "WP_setting") echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php 
    221                 echo __('Use localized WordPress date format setting','extevtcal_plugin').'<br /><em>'; 
    222                 echo __('Example','extevtcal_plugin').': '.processDateListing($today,$later,get_option('date_format')).'<br />'; ?></em></td></tr> 
    223                 <tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_date_formatting" value="WP_setting_time" <?php  
    224                 if ($setting_date_formatting == "WP_setting_time") echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php 
    225                 echo __('Use localized WordPress date format setting with time','extevtcal_plugin').'<br /><em>'; 
    226                 echo __('Example','extevtcal_plugin').': '.processDateListing($today,$later,get_option('links_updated_date_format')).'<br />'; ?></em></td></tr></table></td> 
    227             </tr> 
    228             <tr valign="top"><th scope="row"><?php _e('Wrap link around:','extevtcal_plugin'); ?></th> 
    229             <td><table cellpadding="0" cellspacing="0"><tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_link_position" value="title_only" <?php if ($setting_link_position == "title_only") echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php  
    230                 echo __('Wrap link around title only (standard)','extevtcal_plugin'); ?></td></tr> 
    231                 <tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_link_position" value="entire_li" <?php if ($setting_link_position == "entire_li") echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php  
    232                 echo __('Wrap link around entire &lt;li&gt; (for block hover effects)','extevtcal_plugin'); ?></td></tr></table></td></tr> 
    233             <tr valign="top"><th scope="row"><?php _e('Use default CSS styling:','extevtcal_plugin'); ?></th> 
    234             <td><table cellpadding="0" cellspacing="0"><tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_use_css" value="1" <?php if ($setting_use_css == true) echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php  
    235                 printf(__('Include (see %s for styles defined)','extevtcal_plugin'),'<a href="'.EXTEVTCAL_PLUGIN_DIR.'/gad-events-calendar.css">'.EXTEVTCAL_PLUGIN_DIR.'/gad-events-calendar.css</a>'); ?></td></tr> 
    236                 <tr valign="top"><td style="padding-top:3px;"><input type="radio" name="extevtcal_use_css" value="0" <?php if ($setting_use_css != true) echo 'checked="checked" '; ?>/></td><td style="margin:0;padding:0;"><?php  
    237                 echo __('Do not include default css styles (Note: make sure to define your own)','extevtcal_plugin'); ?></td></tr></table></td></tr>           
    238                  
    239                 </table> 
    240                 <p class="submit"> 
    241                 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> 
    242                 </p> 
    243  
    244                 </form> 
    245     </div><?php  
    246 } 
    247  
    248 function extevtcal_manage_events() { 
    249     echo '<div class="wrap"><div id="icon-link-manager" class="icon32"></div><h2>'.__('Manage Event Listings','extevtcal_plugin'); 
    250     echo ' <a class="button add-new-h2" href="link-add.php">'.__('Add new','extevtcal_plugin').'</a></h2>'; 
    251     include(EXTEVTCAL_PLUGIN_PATH.'/pagination.class.php'); 
    252     $ext_events = get_objects_in_term( is_term('Events Calendar'),'link_category'); 
    253     $items = count($ext_events);  
    254     $eventslist = sortListings($ext_events); 
    255     if($items > 0) {             
    256             $p = new pagination; 
    257             $p->items($items); 
    258             $p->limit(20); // Limit entries per page 
    259             $p->target("link-manager.php?page=extevtcal_manage_events"); 
    260             $p->currentPage($_GET[$p->paging]); // Gets and validates the current page 
    261             $p->calculate(); // Calculates what to show 
    262             $p->parameterName('paging'); 
    263             $p->adjacents(1); //No. of page away from the current page 
    264      
    265             if(!isset($_GET['paging'])) { 
    266                 $p->page = 1; 
    267             } else { 
    268                 $p->page = $_GET['paging']; 
    269             } 
    270      
    271             //Array slice for paging 
    272             $eventslist = array_slice($eventslist,($p->page - 1) * $p->limit,$p->limit); 
    273             ?> 
    274             <div class="tablenav"> 
    275                 <div class='tablenav-pages'> 
    276                     <?php echo $p->show();  // Echo out the list of paging. ?> 
    277                 </div> 
    278             </div><?php 
     234    register_setting( 'extevtcal-settings', 'extevtcal_currentday_behavior' ); 
     235} 
     236 
     237function extevtcal_settings_page( ) { 
     238    include( 'admin.options.php'); 
     239} 
     240 
     241function extevtcal_manage_events( ) { 
     242    echo '<div class="wrap"><div id="icon-link-manager" class="icon32"></div><h2>' . __( 'Manage Event Listings', 'extevtcal_plugin' ); 
     243    echo ' <a class="button add-new-h2" href="link-add.php?type=external-event">' . __( 'Add new', 'extevtcal_plugin' ) . '</a></h2>'; 
     244    include( EXTEVTCAL_PLUGIN_PATH . '/pagination.class.php' ); 
     245    $ext_events = get_objects_in_term( term_exists( 'Events Calendar' ), 'link_category' ); 
     246    $items = count( $ext_events ); 
     247    $eventslist = sortListings( $ext_events ); 
     248    $page = isset( $_GET['page'] ) ? $_GET['page'] : 1; 
     249    if ($items > 0) { 
     250        $p = new pagination; 
     251        $p->items( $items ); 
     252        $p->limit( 20 ); // Limit entries per page 
     253        $p->target( "link-manager.php?page=extevtcal_manage_events" ); 
     254        $p->currentPage( $page ); // Gets and validates the current page 
     255        $p->calculate( ); // Calculates what to show 
     256        $p->parameterName( 'paging' ); 
     257        $p->adjacents( 1 ); //No. of page away from the current page 
     258 
     259        if (!isset( $_GET['paging'] )) { 
     260            $p->page = 1; 
     261        } else { 
     262            $p->page = $_GET['paging']; 
     263        } 
     264 
     265        //Array slice for paging 
     266        $eventslist = array_slice( $eventslist, ( $p->page - 1 ) * $p->limit, $p->limit ); 
     267        ?> 
     268        <div class="tablenav"> 
     269            <div class='tablenav-pages'> 
     270            <?php echo $p->show( );  // Echo out the list of paging. ?> 
     271            </div> 
     272        </div><?php 
     273 
    279274    } else { 
    280         _e("No Event Listings Found",'extevtcal_plugin'); 
     275        _e( "No Event Listings Found", 'extevtcal_plugin' ); 
    281276    } ?> 
    282     <p><em><?php _e('Please note: if you add a link for a new event, you will still have to set the category to "Events Calendar" in order for it to show up in this list.','extevtcal_plugin'); ?></em></p> 
     277    <p> 
     278        <em><?php _e( 'Please note: if you add a link for a new event, you will still have to set the category to "Events Calendar" in order for it to show up in this list.', 'extevtcal_plugin' ); ?></em> 
     279    </p> 
    283280    <table class="widefat"> 
    284   <?php if (get_option('extevtcal_date_formatting') == 'WP_setting') $dateformat = get_option('date_format'); 
    285         elseif (get_option('extevtcal_date_formatting') == 'WP_setting_time') $dateformat = get_option('links_updated_date_format'); 
    286         elseif (get_option('extevtcal_date_formatting') != 'builtin') $dateformat = get_option('extevtcal_date_formatting'); 
     281    <?php $dateformat = dateformat( ); 
    287282    echo ' 
    288         <thead><tr><th scope="col">'.__('Event Name','extevtcal_plugin').'</th><th scope="col">'.__('Date','extevtcal_plugin').'</th><th scope="col">'.__('Link','extevtcal_plugin').'</th><th scope="col">'.__('Location / Description','extevtcal_plugin').'</th></tr></thead><tbody>';  
    289         foreach ($eventslist as $event) { 
    290             $link = get_bookmark($event['id']); 
    291         echo '<tr><td ><strong><a href="link.php?action=edit&link_id='.$event['id'].'">'; 
    292         echo apply_filters('the_title',stripslashes($link->link_name)).'</a></strong>'; 
    293         echo '<div class="row-actions"><span class="edit"><a href="link.php?action=edit&link_id='.$event['id'].'">Edit</a> | </span>'; 
    294         echo '<span class="trash"><a class="submitdelete" href="' . wp_nonce_url("link.php?action=delete&amp;link_id=".$event['id'], 'delete-bookmark_' . $event['id']); 
    295         echo '" onclick="if ( confirm(\'' . esc_js(sprintf( __("You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete."), $link->link_name )) . '\') ) { return true;}return false;">' . __('Delete') . '</a></span></div></td>'; 
    296         echo '<td>'.processDateListing($event['startdate'],$event['enddate'],$dateformat).'</td>'; 
    297         echo '<td><a href="'.$link->link_url.'" target="_blank">'.str_replace('http://','',$link->link_url).'</a></td>'; 
    298         echo '<td>'.$event['location'].'<br><em>'.apply_filters('the_excerpt',stripslashes($link->link_description)).'</em></td></tr>'; 
    299         }  
    300         echo '</tbody> 
    301         <tfoot><tr><th scope="col">'.__('Event Name','extevtcal_plugin').'</th><th scope="col">'.__('Date','extevtcal_plugin').'</th><th scope="col">'.__('Link','extevtcal_plugin').'</th><th scope="col">'.__('Location / Description','extevtcal_plugin').'</th></tr></tfoot></table>'; ?> 
    302     </div> 
    303 <?php } 
    304  
    305  
    306  function extevtcal_metabox() { 
    307     $link = $_GET['link_id']; 
    308     $location = get_link_meta($link,'extevt_location'); 
    309     $startdate = get_link_meta($link,'extevt_start_date'); 
    310     $enddate = get_link_meta($link,'extevt_end_date'); 
     283        <thead><tr><th scope="col">' . __( 'Event Name', 'extevtcal_plugin' ) . '</th><th scope="col">' . __( 'Date', 'extevtcal_plugin' ) . '</th><th scope="col">' . __( 'Link', 'extevtcal_plugin' ) . '</th><th scope="col">' . __( 'Location / Description', 'extevtcal_plugin' ) . '</th></tr></thead><tbody>'; 
     284    foreach ($eventslist as $event) { 
     285        $link = get_bookmark( $event['id'] ); 
     286        echo '<tr><td ><strong><a href="'.get_edit_bookmark_link( $event['id'] ). '">'; 
     287        echo apply_filters( 'the_title', stripslashes( $link->link_name ) ) . '</a></strong>'; 
     288        echo '<div class="row-actions"><span class="edit"><a href="link.php?action=edit&link_id=' . $event['id'] . '">Edit</a> | </span>'; 
     289        echo '<span class="trash"><a class="submitdelete" href="' . wp_nonce_url( "link.php?action=delete&amp;link_id=" . $event['id'], 'delete-bookmark_' . $event['id'] ); 
     290        echo '" onclick="if ( confirm(\'' . esc_js( sprintf( __( "You are about to delete this link '%s'\n  'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ) . '\') ) { return true;}return false;">' . __( 'Delete' ) . '</a></span></div></td>'; 
     291        echo '<td>' . processDateListing( $event['startdate'], $event['enddate'], $dateformat ) . '</td>'; 
     292        echo '<td><a href="' . $link->link_url . '" target="_blank">' . str_replace( 'http://', '', $link->link_url ) . '</a></td>'; 
     293        echo '<td>' . $event['location'] . '<br><em>' . apply_filters( 'the_excerpt', stripslashes( $link->link_description ) ) . '</em></td></tr>'; 
     294    } 
     295    echo '</tbody> 
     296        <tfoot><tr><th scope="col">' . __( 'Event Name', 'extevtcal_plugin' ) . '</th><th scope="col">' . __( 'Date', 'extevtcal_plugin' ) . '</th><th scope="col">' . __( 'Link', 'extevtcal_plugin' ) . '</th><th scope="col">' . __( 'Location / Description', 'extevtcal_plugin' ) . '</th></tr></tfoot>'; ?> 
     297    </table> 
     298    </div> 
     299    <?php 
     300 
     301} 
     302 
     303 
     304function extevtcal_metabox( ) { 
     305    $link = (isset( $_GET['link_id'])) ? $_GET['link_id'] : false; 
     306    $location = get_link_meta( $link, 'extevt_location' ); 
     307    $startdate = get_link_meta( $link, 'extevt_start_date' ); 
     308    $enddate = get_link_meta( $link, 'extevt_end_date' ); 
    311309    echo '<table class="form-table"><tbody>'; 
    312     echo '<tr class="form-field"><th scope="row">' . __('Location', 'extevtcal_plugin' ) . '</th> '; 
    313     echo '<td><input type="text" name="extevtcal_location" value="'.$location.'" size="80" /></td></tr>'; 
    314     echo '<tr class="form-field"><th scope="row">' . __('Start Date', 'extevtcal_plugin' ) . '</th> '; 
    315     echo '<td><input type="text" name="extevtcal_startdate" value="'.$startdate.'" size="80" /></td></tr>'; 
    316     echo '<tr class="form-field"><th scope="row">' . __('End Date (optional)', 'extevtcal_plugin' ) . '</th> '; 
    317     echo '<td><input type="text" name="extevtcal_enddate" value="'.$enddate.'" size="80" /></td></tr></tbody></table>'; 
    318     echo '<p><em>'.__('Note: if you are having problems with your events displaying properly, enter dates in a simple format like MM/DD/YYYY.', 'extevtcal_plugin' ).'</em></p>'; 
    319      
    320 }  
    321  
    322     function save_extevtcal_metabox($link) { 
    323         update_link_meta($link,'extevt_location',$_POST['extevtcal_location']); 
    324         update_link_meta($link,'extevt_start_date',$_POST['extevtcal_startdate']); 
    325         update_link_meta($link,'extevt_end_date',$_POST['extevtcal_enddate']); 
    326     } 
     310    echo '<tr class="form-field"><th scope="row">' . __( 'Location', 'extevtcal_plugin' ) . '</th> '; 
     311    echo '<td><input type="text" name="extevtcal_location" value="' . $location . '" size="80" /></td></tr>'; 
     312    echo '<tr class="form-field"><th scope="row">' . __( 'Start Date', 'extevtcal_plugin' ) . '</th> '; 
     313    echo '<td><input type="text" name="extevtcal_startdate" value="' . $startdate . '" size="80" /></td></tr>'; 
     314    echo '<tr class="form-field"><th scope="row">' . __( 'End Date (optional)', 'extevtcal_plugin' ) . '</th> '; 
     315    echo '<td><input type="text" name="extevtcal_enddate" value="' . $enddate . '" size="80" /></td></tr></tbody></table>'; 
     316    echo '<p><em>' . __( 'Note: if you are having problems with your events displaying properly, enter dates in a simple format like MM/DD/YYYY.', 'extevtcal_plugin' ) . '</em></p>'; 
     317 
     318} 
     319 
     320function save_extevtcal_metabox( $link ) { 
     321    update_link_meta( $link, 'extevt_location', $_POST['extevtcal_location'] ); 
     322    update_link_meta( $link, 'extevt_start_date', $_POST['extevtcal_startdate'] ); 
     323    update_link_meta( $link, 'extevt_end_date', $_POST['extevtcal_enddate'] ); 
     324} 
    327325 
    328326// a very minimal stylesheet for widget - either modify this stylesheet or just delete it and define these styles in your own css 
    329 add_action('wp_print_styles','extevtcal_load_stylesheet'); 
    330  
    331 function extevtcal_load_stylesheet() { 
    332     if (get_option('extevtcal_use_css')==true) wp_enqueue_style('gad-events-calendar',EXTEVTCAL_PLUGIN_DIR.'/gad-events-calendar.css'); 
     327add_action( 'wp_print_styles', 'extevtcal_load_stylesheet' ); 
     328 
     329function extevtcal_load_stylesheet( ) { 
     330    if (get_option( 'extevtcal_use_css' ) == true) { 
     331        // check first in theme directory, then in plugins/gad-events-custom/. 
     332        // If stylesheet not found in either of those locations, include the one in this folder. 
     333        if ( file_exists( get_stylesheet_directory() . '/gad-events-calendar.css' ) ) 
     334            $custom_css_file = get_stylesheet_directory_uri() . '/gad-events-calendar.css'; 
     335        elseif ( file_exists( WP_PLUGIN_DIR . '/gad-events-custom/gad-events-calendar.css' )) 
     336            $custom_css_file = WP_PLUGIN_URL . '/gad-events-custom/gad-events-calendar.css'; 
     337        else 
     338            $custom_css_file = EXTEVTCAL_PLUGIN_DIR . '/gad-events-calendar.css'; 
     339        wp_enqueue_style( 'gad-events-calendar', $custom_css_file ); 
     340    } 
    333341} 
    334342 
    335343//register shortcode to display events on pages/posts 
    336 add_shortcode('eventslisting','eventslisting'); 
    337  
    338 function eventslisting($atts) { 
    339     $instance = shortcode_atts( array ( 
    340         'display_title'=>__('Upcoming Events','extevtcal_plugin'), 
    341         'link_category'=>is_term('Events Calendar'), 
    342         'show_past_events'=>false, 
    343         'show_descriptions'=>true, 
    344         'show_images'=>false, 
    345         'orderby'=>'ASC', 
    346         'limit'=>false ), $atts ); 
    347     $category_id = is_term('Events Calendar'); 
    348     $eventslist = get_objects_in_term( $category_id,'link_category'); 
    349     $eventlisting = sortListings($eventslist, $instance['orderby'], $instance['show_past_events']); 
    350     if ($instance['limit']) $eventlisting = array_slice($eventlisting,0,$instance['limit']); 
    351     $link_position = get_option('extevtcal_link_position'); 
    352     echo '<div class="div_extevtcal_div"><h2>'.apply_filters('the_title',$display_title ).'</h2>'; 
    353     extevtcal_showlist($eventlisting,$instance,$link_position); 
    354     echo '</div>'; 
    355                  
    356      
    357 } 
    358  
    359 function extevtcal_showlist($eventlisting,$instance,$link_position) { 
    360             echo '<ul>'; 
    361             foreach ($eventlisting as $event) { 
    362                 $link = get_link($event['id']); 
    363                 $link_before_title = array('<a href="'.$link->link_url.'" rel="'.$link->link_rel.'" target="'.$link->link_target.'">','</a>'); 
    364                 $link_before_li = array('',''); 
    365                 if ($link_position == 'entire_li') { 
    366                     $link_before_li = $link_before_title; 
    367                     $link_before_title = array('',''); 
    368                 } 
    369                 echo $link_before_li[0].'<li>'; 
    370                 if ($instance['show_images'] && $link->link_image) echo '<img src="'.$link->link_image.'" class="link-image" >'; 
    371                 echo '<h4>'.$link_before_title[0].$link->link_name.$link_before_title[1].'</h4>'; 
    372                 if ($event['location']) echo '<span class="event-location">'.$event['location'].'</span>'; 
    373                 if ($instance['show_descriptions'] && $link->link_description) { 
    374                     echo '<span class="event-description">'.$link->link_description.'</span>'; 
    375                 } 
    376                 echo '<span class="event-date">'.processDateListing($event['startdate'],$event['enddate'],$dateformat).'</span></li>'.$link_before_li[1]; 
    377             } 
    378             echo '</ul>'; 
     344add_shortcode( 'eventslisting', 'eventslisting' ); 
     345 
     346function eventslisting( $atts ) { 
     347    if ( isset( $atts['show_events'] ) ) 
     348        $atts['show_past_events'] = $atts['show_events']; 
     349    $instance = shortcode_atts( array( 
     350        'display_title' => false, 
     351        'link_category' => term_exists( 'Events Calendar' ), 
     352        'show_past_events' => 'upcomingonly', 
     353        'show_descriptions' => true, 
     354        'show_images' => false, 
     355        'orderby' => 'ASC', 
     356        'limit' => false), $atts ); 
     357    $category_id = $instance['link_category']; 
     358    $eventslist = get_objects_in_term( $category_id, 'link_category' ); 
     359    $eventlisting = sortListings( $eventslist, $instance['orderby'], $instance['show_past_events'] ); 
     360    $tmp = ''; 
     361    if ($instance['limit']) $eventlisting = array_slice( $eventlisting, 0, $instance['limit'] ); 
     362    $link_position = get_option( 'extevtcal_link_position' ); 
     363    $tmp .= '<div class="div_extevtcal_div">'; 
     364    if (!empty( $instance['display_title'] )) $tmp .= '<h2>' . apply_filters( 'the_title', $instance['display_title'] ) . '</h2>'; 
     365    $tmp .= extevtcal_showlist( $eventlisting, $instance, $link_position, false ); 
     366    $tmp .= '</div>'; 
     367    return $tmp; 
     368} 
     369 
     370function extevtcal_showlist( $eventlisting, $instance, $link_position, $echo = true ) { 
     371    $tmp = '<ul>'; 
     372    foreach ($eventlisting as $event) { 
     373        $link = get_bookmark( $event['id'] ); 
     374        $link_before_title = array('<a href="' . $link->link_url . '" rel="' . $link->link_rel . '" target="' . $link->link_target . '">', '</a>'); 
     375        $link_before_li = array('', ''); 
     376        if ($link_position == 'entire_li') { 
     377            $link_before_li = $link_before_title; 
     378            $link_before_title = array('', ''); 
     379        } 
     380        $tmp .= $link_before_li[0] . '<li>'; 
     381        if ($instance['show_images'] && $link->link_image) $tmp .= '<img src="' . $link->link_image . '" class="link-image" >'; 
     382        $tmp .= '<h4>' . $link_before_title[0] . $link->link_name . $link_before_title[1] . '</h4>'; 
     383        if ($event['location']) $tmp .= '<span class="event-location">' . $event['location'] . '</span>'; 
     384        if ($instance['show_descriptions'] && $link->link_description) { 
     385            $tmp .= '<span class="event-description">' . $link->link_description . '</span>'; 
     386        } 
     387        $tmp .= '<span class="event-date">' . processDateListing( $event['startdate'], $event['enddate'], dateformat( ) ) . '</span></li>' . $link_before_li[1]; 
     388    } 
     389    $tmp .= '</ul>'; 
     390    if ($echo) echo $tmp; 
     391    else return $tmp; 
    379392} 
    380393 
    381394//register the widget form and widget display 
    382 add_action('widgets_init','extevtcal_register_widgets'); 
    383  
    384 function extevtcal_register_widgets() { 
     395function extevtcal_register_widgets( ) { 
    385396    register_widget( 'extevtcal_widget' ); 
    386397} 
    387398 
    388399class extevtcal_widget extends WP_Widget { 
    389      
    390     function extevtcal_widget() { 
    391         $widget_ops = array('classname'=>'extevtcal_widget', 
    392                             'description'=>__('Widget to display upcoming events from the "Upcoming Events" link category','extevtcal_plugin') ); 
    393         $this->WP_Widget('extevtcal_widget', __('External Events Calendar','extevtcal_plugin') ); 
    394     } 
    395      
    396     function form($instance) { 
    397         $defaults = array('display_title'=>__('Upcoming Events','extevtcal_plugin'), 
    398                             'link_category'=>is_term('Events Calendar'), 
    399                             'show_past_events'=>false, 
    400                             'show_descriptions'=>true, 
    401                             'show_images'=>false, 
    402                             'orderby'=>'ASC'); 
     400 
     401    function extevtcal_widget( ) { 
     402        $widget_ops = array('classname' => 'extevtcal_widget', 
     403            'description' => __( 'Widget to display upcoming events from the "Upcoming Events" link category', 'extevtcal_plugin' )); 
     404        $this->WP_Widget( 'extevtcal_widget', __( 'External Events Calendar', 'extevtcal_plugin' ) ); 
     405    } 
     406 
     407    function form( $instance ) { 
     408        $defaults = array('display_title' => __( 'Upcoming Events', 'extevtcal_plugin' ), 
     409            'link_category' => term_exists( 'Events Calendar' ), 
     410            'show_past_events' => "upcoming", 
     411            'show_descriptions' => true, 
     412            'show_images' => false, 
     413            'orderby' => 'ASC', 
     414            'limit' => false ); 
    403415        $instance = wp_parse_args( (array) $instance, $defaults ); 
    404             $displaytitle=strip_tags($instance['display_title']); 
    405             $showpastevents=strip_tags($instance['show_past_events']); 
    406             $showdescriptions=strip_tags($instance['show_descriptions']); 
    407             $showimages=strip_tags($instance['show_images']); 
    408             $orderby=strip_tags($instance['orderby']); 
    409             $limit = strip_tags($instance['limit']); 
     416        $displaytitle = strip_tags( $instance['display_title'] ); 
     417        $showpastevents = strip_tags( $instance['show_past_events'] ); 
     418        $showdescriptions = strip_tags( $instance['show_descriptions'] ); 
     419        $showimages = strip_tags( $instance['show_images'] ); 
     420        $orderby = strip_tags( $instance['orderby'] ); 
     421        $limit = strip_tags( $instance['limit'] ); 
    410422        ?> 
    411         <p><?php _e('Title','extevtcal_plugin') ?>: <input class="widefat" name="<?php echo $this->get_field_name('display_title'); ?>" type="text" value="<?php echo esc_attr($displaytitle); ?>"  /></p> 
    412         <p><input class="checkbox" name="<?php echo $this->get_field_name('show_past_events'); ?>" type="checkbox" <?php if ($showpastevents) echo 'checked="checked"'; ?>  /> <?php _e('Show Past events?','extevtcal_plugin') ?></p> 
    413         <p><input class="checkbox" name="<?php echo $this->get_field_name('show_descriptions'); ?>" type="checkbox" <?php if ($showdescriptions) echo 'checked="checked"'; ?>  /> <?php _e('Show Descriptions?','extevtcal_plugin') ?></p> 
    414         <p><input class="checkbox" name="<?php echo $this->get_field_name('show_images'); ?>" type="checkbox" <?php if ($showimages) echo 'checked="checked"'; ?>  /> <?php _e('Show Images?','extevtcal_plugin') ?></p> 
    415         <p><?php _e('Order Events by:','extevtcal_plugin') ?></p> 
    416         <p><input class="radio" name="<?php echo $this->get_field_name('orderby'); ?>" type="radio" value="ASC" <?php if ($orderby != 'DEC') echo 'checked="checked"'; ?>  /><?php _e('Current to future (default)','extevtcal_plugin'); ?></p> 
    417         <p><input class="radio" name="<?php echo $this->get_field_name('orderby'); ?>" type="radio" value="DEC" <?php if ($orderby == 'DEC') echo 'checked="checked"'; ?>  /><?php _e('Future to current','extevtcal_plugin'); ?></p> 
    418         <p><?php _e('Max Number of listings to show','extevtcal_plugin') ?>: <input class="widefat" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo esc_attr($limit); ?>"  /></p> 
    419         <?php 
    420     } 
    421      
    422     function update($new_instance, $old_instance) { 
     423        <p><?php _e( 'Title', 'extevtcal_plugin' ) ?>: 
     424            <input class="widefat" 
     425                   name="<?php echo $this->get_field_name( 'display_title' ); ?>" 
     426                   type="text" 
     427                   value="<?php echo esc_attr( $displaytitle ); ?>"/></p> 
     428        <h4><?php _e( 'Listings to Show', 'extevtcal_plugin' ); ?>:</h4> 
     429        <p><input class="radio" 
     430                  name="<?php echo $this->get_field_name( 'show_past_events' ); ?>" 
     431                  type="radio" 
     432                  value="upcomingonly" <?php checked( empty( $showpastevents ) || ( $showpastevents == 'upcomingonly' ) ); ?>  /> <?php _e( 'Upcoming Only (default)', 'extevtcal_plugin' ) ?> 
     433            <br/> 
     434            <input class="radio" 
     435                   name="<?php echo $this->get_field_name( 'show_past_events' ); ?>" 
     436                   type="radio" 
     437                   value="allevents" <?php checked( ( $showpastevents == 'allevents' ) || ( 1 === $showpastevents ), true ); ?>  /> <?php _e( 'All Events', 'extevtcal_plugin' ) ?> 
     438            <br/> 
     439            <input class="radio" 
     440                   name="<?php echo $this->get_field_name( 'show_past_events' ); ?>" 
     441                   type="radio" 
     442                   value="pastonly" <?php checked( $showpastevents == 'pastonly' ); ?>  /> <?php _e( 'Past Events Only', 'extevtcal_plugin' ) ?> 
     443        </p> 
     444        <p><input class="checkbox" 
     445                  name="<?php echo $this->get_field_name( 'show_descriptions' ); ?>" value="1" 
     446                  type="checkbox" <?php checked( $showdescriptions, 1 ); ?>  /> <?php _e( 'Show Descriptions?', 'extevtcal_plugin' ) ?> 
     447        </p> 
     448        <p><input class="checkbox" 
     449                  name="<?php echo $this->get_field_name( 'show_images' ); ?>" value="1" 
     450                  type="checkbox" <?php checked( $showimages, 1 ); ?>  /> <?php _e( 'Show Images?', 'extevtcal_plugin' ) ?> 
     451        </p> 
     452        <h4><?php _e( 'Order Events by:', 'extevtcal_plugin' ) ?></h4> 
     453        <p><input class="radio" 
     454                  name="<?php echo $this->get_field_name( 'orderby' ); ?>" 
     455                  type="radio" 
     456                  value="ASC" <?php checked( $orderby != 'DEC', true ); ?>  /><?php _e( 'Current to future (default)', 'extevtcal_plugin' ); ?> 
     457            <br/> 
     458            <input class="radio" 
     459                   name="<?php echo $this->get_field_name( 'orderby' ); ?>" 
     460                   type="radio" 
     461                   value="DESC" <?php checked( ($orderby == 'DESC') || ($orderby == 'DEC') ); ?>  /><?php _e( 'Future to current', 'extevtcal_plugin' ); ?> 
     462        </p> 
     463        <p><?php _e( 'Max Number of listings to show', 'extevtcal_plugin' ) ?>: 
     464            <input class="widefat" 
     465                   name="<?php echo $this->get_field_name( 'limit' ); ?>" 
     466                   type="text" 
     467                   value="<?php echo esc_attr( $limit ); ?>"/> 
     468        </p> 
     469        <?php 
     470 
     471    } 
     472 
     473    function update( $new_instance, $old_instance ) { 
    423474        $instance = $old_instance; 
    424         $instance['display_title'] = strip_tags($new_instance['display_title']); 
    425         $instance['show_past_events'] = strip_tags($new_instance['show_past_events']); 
    426         $instance['show_descriptions'] = strip_tags($new_instance['show_descriptions']); 
    427         $instance['show_images'] = strip_tags($new_instance['show_images']); 
    428         $instance['orderby'] = strip_tags($new_instance['orderby']); 
    429         $instance['limit'] = strip_tags($new_instance['limit']); 
     475        $instance['display_title'] = strip_tags( $new_instance['display_title'] ); 
     476        $instance['show_past_events'] = strip_tags( $new_instance['show_past_events'] ); 
     477        $instance['show_descriptions'] = strip_tags( $new_instance['show_descriptions'] ); 
     478        $instance['show_images'] = strip_tags( $new_instance['show_images'] ); 
     479        $instance['orderby'] = strip_tags( $new_instance['orderby'] ); 
     480        $instance['limit'] = strip_tags( $new_instance['limit'] ); 
    430481        return $instance; 
    431482    } 
    432      
    433     function widget($args, $instance) { 
    434         extract($args); 
    435         $title = apply_filters('widget_title', $instance['display_title']); 
    436         $category_id = is_term('Events Calendar'); 
    437         $eventslist = get_objects_in_term( $category_id,'link_category'); 
    438         $eventlisting = sortListings($eventslist, $instance['orderby'], $instance['show_past_events']); 
    439         $link_position = get_option('extevtcal_link_position'); 
    440         if (get_option('extevtcal_date_formatting') == 'WP_setting') $dateformat = get_option('date_format'); 
    441         elseif (get_option('extevtcal_date_formatting') == 'WP_setting_time') $dateformat = get_option('links_updated_date_format'); 
    442         elseif (get_option('extevtcal_date_formatting') != 'builtin') $dateformat = get_option('extevtcal_date_formatting'); 
    443         if ($instance['limit']) $eventlisting = array_slice($eventlisting,0,$instance['limit']); 
     483 
     484    function widget( $args, $instance ) { 
     485        extract( $args ); 
     486        $title = apply_filters( 'widget_title', $instance['display_title'] ); 
     487        $category_id = term_exists( 'Events Calendar' ); 
     488        $eventslist = get_objects_in_term( $category_id, 'link_category' ); 
     489        $eventlisting = sortListings( $eventslist, $instance['orderby'], $instance['show_past_events'] ); 
     490        $link_position = get_option( 'extevtcal_link_position' ); 
     491        if ($instance['limit']) $eventlisting = array_slice( $eventlisting, 0, $instance['limit'] ); 
    444492        if ($eventlisting) { 
    445             echo $before_widget.$before_title . $title . $after_title; 
    446             extevtcal_showlist($eventlisting,$instance,$link_position); 
     493            echo $before_widget . $before_title . $title . $after_title; 
     494            extevtcal_showlist( $eventlisting, $instance, $link_position ); 
    447495            echo $after_widget; 
    448496        } 
    449497    } 
    450          
    451          
     498 
     499 
    452500} 
    453501 
  • external-events-calendar/trunk/readme.txt

    r278380 r340396  
    44Tags: calendar, links, widget, events calendar, upcoming events 
    55Requires at least: 2.9.1 
    6 Tested up to: 3.0.1 
    7 Stable tag: 0.3.1 
     6Tested up to: 3.1RC3 
     7Stable tag: 0.4 
    88 
    99This plugin adds a basic "upcoming events" calendar of links to Wordpress. 
     
    29291. Add links to the "Events Calendar" category, and give them a "Location" (optional) and Start and End "Date" 
    30301. View and manage all your events in the "Events Calendar" page under the 'Links' menu  
    31 1. Use the "External Events Calendar" widget in any widgetized area in your site 
     311. Use the "External Events Calendar" widget in any widgetized area in your site, or 
     321. Use the shortcode `[eventslisting]` in a post or page (see the FAQ for parameters that can be passed). 
    3233 
    3334== Frequently Asked Questions == 
     
    4344If you are having problems having your dates be ordered properly, it is most likely because the `strtotime()` function is not able to recognize or parse your input. Try entering your dates in a simple format like MM/DD/YYYY and using the WordPress date format settings to display them. 
    4445 
     46= Can I have more than one category of Events? Can I use the widget twice, pulling from a different listing of events in each case? = 
     47 
     48Yes, you can add an additional link category and use it to store events. If the category you create has an id of `11`, for example, you can pull events from your own category using the shortcode `[eventslisting link_category=11]`. At the moment, the widget will only pull from the default "Events Calendar" link category. If you create your own category, you will have to manage it yourself - the "Events Calendar" submenu page under "Links" will only show events in the default category. 
     49 
    4550= Can I override the default CSS? = 
    4651 
    47 As of version 3.0, you have the option to include or not include the default CSS styling. Take a look at the css file provided to see the class names that need to be styled. If you define those in the `style.css` of your main theme, you can safely disable the default CSS, while will make your page loads a wee bit quicker. 
     52As of version 0.3, you have the option to include or not include the default CSS styling. Take a look at the css file provided to see the class names that need to be styled. If you define those in the `style.css` of your main theme, you can safely disable the default CSS, while will make your page loads a wee bit quicker. 
     53 
     54As of version 0.4, you can also copy the existing `gad-events-calendar.css` file to your theme directory and edit it there, OR create a new directory under `/wp-content/plugins` called `gad-events-custom` and copy the stylesheet there. This can help protect your style changes in case of updating the plugin in the future. 
     55 
     56= What options does the shortcode `[eventslisting]` take? 
     57 
     58You can pass any of the same options to the shortcode that you can select in the widget. Here is the syntax for each of the options: 
     59 
     60* `display_title` (false|string)  The title, if any, to show before the list of events. Will be wrapped in an `<h2>` tag if present. 
     61* `show_past_events` (true|false) Present for backwards compatability. Use `show_events` instead. 
     62* `show_events` ("upcomingonly"|"allevents"|"pastonly") Pretty much what it implies. Defaults to "upcomingonly". 
     63* `show_descriptions` (true|false) Whether or not to show descriptions in the list of events. Defaults to true. 
     64* `show_images` (true|false) Whether or not to show link images, if present, in the list of events. Defaults to false. 
     65* `orderby` (ASC|DESC) ASC: Order events current to future, or past to future. DESC: Order events future to current (or past). Defaults to ASC. 
     66* `limit` (int) If present, the maximum number of events to show in the listing. 
     67* `link_category` (int) A different category to pull events from, other than the default "Events Calendar" category. 
     68 
     69So for example, if you want to include the five events farthest in the future in a post, this would be the shortcode to use: `[eventslisting display_title="Planning Ahead" orderby=DESC limit=5]` 
     70 
    4871 
    4972== Screenshots == 
     
    5376 
    5477== Changelog == 
     78 
     79= 0.4 = 
     80 
     81New features and bugfixes 2/4/11 
     82 
     83* Added "past only" option, to show only past events. 
     84* New options for behavior of current date (can choose to have upcoming events drop off the calendar when the start date is past, when the end date is past, or to include all events from the current day, or week). This addresses a bug which was reported where events which weren't given a time would drop off of the calendar on the day they were scheduled. 
     85* Fixed bug within shortcode that would always display at the top of post content. 
     86* Added custom date formatting option using any PHP date format string. 
     87* Removed deprecated functions 
    5588 
    5689= 0.3.1 = 
Note: See TracChangeset for help on using the changeset viewer.