Plugin Directory

Changeset 1536371


Ignore:
Timestamp:
11/18/2016 03:31:00 PM (9 years ago)
Author:
loushou
Message:
  • [new] major overhaul on displayed time formats. now they are all options in the admin
  • [new] ability to edit an individual event, change the start/end time, and update the permalink with auto-redirect of old one
  • [tweak] update to better process manually typed in time values when creating and editing events

loushou

Location:
opentickets-community-edition/trunk
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • opentickets-community-edition/trunk/assets/css/admin/base.css

    r1465000 r1536371  
    265265.qsot-mb .image-preview { max-width:100%; }
    266266.qsot-mb .image-preview img { max-width:100%; }
     267.qsot-mb .field .at-time { display:block; margin-left:1.5em; position:relative; width:auto; }
     268.qsot-mb .field .at-time::before { content:"@"; left:-1.5em; line-height:28px; position:absolute; }
    267269
    268270/* licenses */
  • opentickets-community-edition/trunk/assets/js/admin/event-ui.js

    r1458303 r1536371  
    102102
    103103        function normalize_time( str ) {
    104             var matches = str.toLowerCase().match( /^(\d{1,2})(:(\d{1,2})(:(\d{1,2}))?)?([pa]m?)?$/ ),
     104            var matches = str.toLowerCase().match( /^(\d{1,2})(:(\d{1,2})(.?(\d{1,2})?)?)?.?([pa]m?)?$/ ),
    105105                    res = matches
    106106                        ? {
     
    825825    return EventUI;
    826826})(jQuery);
     827
     828// single event edit page
     829( function( $ ) {
     830    $( document ).on( 'change.qsot keyup.qsot', '.single-event-settings input, .single-event-settings select, .single-event-settings textarea', function() {
     831        if ( $( this ).not( '#qsot-update-permalink' ).length ) {
     832            $( '#qsot-update-permalink' ).prop( 'checked', 'checked' );
     833        }
     834    } );
     835} )( jQuery );
  • opentickets-community-edition/trunk/inc/core/calendar.class.php

    r1511879 r1536371  
    598598        $method = get_post_meta( $post->ID, '_calendar_start_method', true );
    599599        $date = get_post_meta( $post->ID, '_calendar_start_manual', true );
     600        $date = ! $date ? date( 'c' ) : $date;
    600601
    601602        // default the settings to 'today' (above)
     
    619620                <label class="screen-reader-text" for="qsot-cal-start-manual"><?php _e( 'Manually entered date', 'opentickets-community-edition' ) ?></label>
    620621                <input size="11" type="text" class="use-datepicker" id="qsot-cal-start-manual-display" name="_calendar_start_manual_display"
    621                         value="<?php echo esc_attr( date( __( 'm-d-Y', 'opentickets-community-edition' ), strtotime( $date ) ) ) ?>"
     622                        value="<?php echo esc_attr( date( QSOT_Date_Formats::php_date_format( 'm-d-Y' ), strtotime( $date ) ) ) ?>"
    622623                        real="#qsot-cal-start-manual" scope="[rel='extra-manual']" frmt="<?php echo esc_attr( __( 'mm-dd-yy', 'opentickets-community-edition' ) ) ?>" />
    623624                <input type="hidden" id="qsot-cal-start-manual" name="_calendar_start_manual" value="<?php echo esc_attr( $date ) ?>" />
  • opentickets-community-edition/trunk/inc/core/post-type.class.php

    r1532350 r1536371  
    5555            // ** I cannot replicate this problem in independent tests, outside wp, but I can reliably get this to happen within.
    5656            add_action( 'save_post', 'qsot_noop', 998 );
     57
     58            // save child events
     59            add_action( 'save_post', array( __CLASS__, 'save_child_event' ), 100000, 3 );
     60            add_action( 'post_updated', array( __CLASS__, 'record_old_slug' ), PHP_INT_MAX, 3 );
    5761
    5862            // action that is used to actually handle the saving of sub-events
     
    12581262
    12591263        // add the date/time to the title
    1260         $date = date( __( 'm/d/Y', 'opentickets-community-edition' ), $start );
    1261         $time = date( __( 'g:ia', 'opentickets-community-edition' ), $start );
     1264        $date = date( QSOT_Date_Formats::php_date_format( 'm/d/Y' ), $start );
     1265        $time = date( QSOT_Date_Formats::php_date_format( 'g:ia' ), $start );
    12621266        $format = '%1$s';
    12631267        if ( $needs['date'] )
     
    13251329        if ( isset( $_POST['qsot-event-title-settings'] ) && wp_verify_nonce( $_POST['qsot-event-title-settings'], 'qsot-event-title' ) )
    13261330            add_action( 'wp_insert_post', array( __CLASS__, 'save_event_title_settings' ), 100, 3 );
     1331    }
     1332
     1333    // handle the saving of an individual child event
     1334    public static function save_child_event( $post_id, $post=null, $updated=false ) {
     1335        static $ran_for = array();
     1336        // only run this function once for a post
     1337        if ( isset( $ran_for[ 'post-' . $post_id ] ) )
     1338            return;
     1339        $ran_for[ 'post-' . $post_id ] = 1;
     1340
     1341        // load the post, just in case it was not sent
     1342        $post = get_post( $post_id );
     1343
     1344        // handle saving of the event date time changes
     1345        if ( isset( $_POST['qsot-single-event-settings'] ) && wp_verify_nonce( $_POST['qsot-single-event-settings'], 'qsot-save-single-event-settings' ) ) {
     1346            $dt = $_POST['qsot-single-event'];
     1347            // if some settings are missing, bail now
     1348            if ( ! isset( $dt['start_date'], $dt['start_time'], $dt['end_date'], $dt['end_time'] ) )
     1349                return;
     1350
     1351            // normalize the time entered, to a usable timestamp
     1352            $start_time = QSOT_Utils::to_24_hour( $dt['start_time'] );
     1353            $end_time = QSOT_Utils::to_24_hour( $dt['end_time'] );
     1354
     1355            // construct date time stamps
     1356            $offset = QSOT_Utils::non_dst_tz_offset();
     1357            $start = preg_replace( '#^(\d{4}-\d{2}-\d{2})(?:T| )(\d{2}:\d{2}:\d{2}).*$#', '\1T\2', $dt['start_date'] . ' ' . $start_time ) . $offset;
     1358            $end = preg_replace( '#^(\d{4}-\d{2}-\d{2})(?:T| )(\d{2}:\d{2}:\d{2}).*$#', '\1T\2', $dt['end_date'] . ' ' . $end_time ) . $offset;
     1359
     1360            // if the times are in the correct format, then save them
     1361            if ( preg_match( '#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+|-)\d{2}:\d{2}$#', $start ) && preg_match( '#^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\+|-)\d{2}:\d{2}$#', $end ) ) {
     1362                update_post_meta( $post_id, '_start', $start );
     1363                update_post_meta( $post_id, '_end', $end );
     1364
     1365                // if we need to update the permalink too, do that now. this is the reason this function has recursion protection
     1366                if ( isset( $_POST['qsot-update-permalink'] ) ) {
     1367                    // update the post_name
     1368                    $post_arr = array(
     1369                        'ID' => $post_id,
     1370                        'post_name' => date( QSOT_Date_Formats::php_date_format( 'Y-m-d_gia' ), QSOT_Utils::local_timestamp( $start ) ),
     1371                    );
     1372                    wp_update_post( $post_arr );
     1373                }
     1374            }
     1375        }
     1376    }
     1377
     1378    // on event update, record the old slug if needed
     1379    public static function record_old_slug( $post_id, $post, $post_before ) {
     1380        // Don't bother if it hasn't changed.
     1381        if ( $post->post_name == $post_before->post_name ) {
     1382            return;
     1383        }
     1384
     1385        // We're only concerned with published, non-hierarchical objects.
     1386        if ( 'qsot-event' !== $post->post_type || ! ( 'publish' === $post->post_status || ( 'attachment' === get_post_type( $post ) && 'inherit' === $post->post_status ) ) ) {
     1387            return;
     1388        }
     1389
     1390        $old_slugs = (array) get_post_meta( $post_id, '_wp_old_slug' );
     1391        $parent = get_post( $post_before->post_parent );
     1392        $old_slug = $parent->post_name . '/' . $post_before->post_name;
     1393        $new_slug = $parent->post_name . '/' . $post->post_name;
     1394
     1395        // If we haven't added this old slug before, add it now.
     1396        if ( ! empty( $post_before->post_name ) && ! in_array( $old_slug, $old_slugs ) ) {
     1397            add_post_meta( $post_id, '_wp_old_slug', $old_slug );
     1398        }
     1399
     1400        // If the new slug was used previously, delete it from the list.
     1401        if ( in_array( $new_slug, $old_slugs ) ) {
     1402            delete_post_meta( $post_id, '_wp_old_slug', $new_slug );
     1403        }
    13271404    }
    13281405
     
    13841461            $tmp = ! is_scalar( $item ) ? $item : @json_decode( stripslashes( $item ) );
    13851462
     1463            // update the timestamps to be non-dst for storage
     1464            $tmp->start = QSOT_Utils::make_non_dst( $tmp->start );
     1465            $tmp->end = QSOT_Utils::make_non_dst( $tmp->end );
     1466
    13861467            // if the settings are a valid set of settings, then continue with this item
    13871468            if ( is_object( $tmp ) ) {
    13881469                // change the title to be the date, which makes for better permalinks
    1389                 $tmp->title = date( _x( 'Y-m-d_gia', 'Permalink date', 'opentickets-community-edition' ), QSOT_Utils::local_timestamp( $tmp->start ) );
     1470                $tmp->title = date( QSOT_Date_Formats::php_date_format( 'Y-m-d_gia' ), QSOT_Utils::local_timestamp( $tmp->start ) );
    13901471                // if the post_id was passed in with the settings, then we know what subevent post to modify with these settings already. therefore we do not need to match it up to an existing
    13911472                // subevent or create a new subevent. lets throw it directly into the update list for usage later
     
    14291510                            'meta' => array( // setup the meta to save
    14301511                                self::$o->{'meta_key.capacity'} => $tmp->capacity, // max occupants
    1431                                 self::$o->{'meta_key.end'} => QSOT_Utils::make_non_dst( $tmp->end ), // end time, for lookup and display purposes later
    1432                                 self::$o->{'meta_key.start'} => QSOT_Utils::make_non_dst( $tmp->start ), // start time for lookup and display purposes later
     1512                                self::$o->{'meta_key.end'} => $tmp->end, // end time, for lookup and display purposes later
     1513                                self::$o->{'meta_key.start'} => $tmp->start, // start time for lookup and display purposes later
    14331514                                self::$o->{'meta_key.purchase_limit'} => $tmp->purchase_limit, // the specific child event purchase limit
    14341515                            ),
     
    15031584                            'meta' => array( // set the meta
    15041585                                self::$o->{'meta_key.capacity'} => $tmp->capacity, // occupant capacity
    1505                                 self::$o->{'meta_key.end'} => QSOT_Utils::make_non_dst( $tmp->end ), // event end date/time for later lookup and display
    1506                                 self::$o->{'meta_key.start'} => QSOT_Utils::make_non_dst( $tmp->start ), // event start data/time for later lookup and display
     1586                                self::$o->{'meta_key.end'} => $tmp->end, // event end date/time for later lookup and display
     1587                                self::$o->{'meta_key.start'} => $tmp->start, // event start data/time for later lookup and display
    15071588                                self::$o->{'meta_key.purchase_limit'} => $tmp->purchase_limit, // the specific child event purchase limit
    15081589                            ),
     
    15461627                        'meta' => array( // set meta
    15471628                            self::$o->{'meta_key.capacity'} => $item->capacity, // occupant copacity
    1548                             self::$o->{'meta_key.end'} => QSOT_Utils::make_non_dst( $item->end ), // end data for lookup and display
    1549                             self::$o->{'meta_key.start'} => QSOT_Utils::make_non_dst( $item->start ), // start date for lookup and display
     1629                            self::$o->{'meta_key.end'} => $item->end, // end data for lookup and display
     1630                            self::$o->{'meta_key.start'} => $item->start, // start date for lookup and display
    15501631                            self::$o->{'meta_key.purchase_limit'} => $tmp->purchase_limit, // the specific child event purchase limit
    15511632                        ),
     
    17381819            );
    17391820        // setup the child event metaboxes
    1740         /*
    17411821        } else if ( is_object( $post ) && 0 != $post->post_parent ) {
    17421822            add_meta_box(
     
    17451825                array( __CLASS__, 'mb_single_event_settings' ),
    17461826                self::$o->core_post_type,
    1747                 'normal',
     1827                'side',
    17481828                'high'
    17491829            );
    1750         */
    17511830        }
    17521831    }
     
    17541833    // metabox for editing a single event's settings
    17551834    public static function mb_single_event_settings( $post, $mb ) {
    1756         // adjust the start and end times for our WP offset setting
    1757         $start_raw = QSOT_Utils::gmt_timestamp( get_post_meta( $post->ID, '_start', true ) );
    1758         $end_raw = QSOT_Utils::gmt_timestamp( get_post_meta( $post->ID, '_end', true ) );
    1759 
    1760         // create the various date parts
    1761         $start = date( 'c', $start_raw );
    1762         $start_time = date( 'H:i:s', $start_raw );
    1763         $end = date( 'c', $end_raw );
    1764         $end_time = date( 'H:i:s', $end_raw );
     1835        // load actual start/end datetime
     1836        $start = get_post_meta( $post->ID, '_start', true );
     1837        $start_c = QSOT_Utils::to_c( $start );
     1838        $end = get_post_meta( $post->ID, '_end', true );
     1839        $end_c = QSOT_Utils::to_c( $end );
     1840
     1841        // get just the date and time portions
     1842        $start_time = date( QSOT_Date_Formats::php_date_format( 'g:ia' ), QSOT_Utils::gmt_timestamp( $start_c, 'from', 'g:ia' ) );
     1843        $end_time = date( QSOT_Date_Formats::php_date_format( 'g:ia' ), QSOT_Utils::gmt_timestamp( $end_c, 'from', 'g:ia' ) );
     1844
     1845        // render the settings box
     1846        ?>
     1847            <div class="qsot-mb single-event-settings">
     1848                <input type="hidden" name="qsot-single-event-settings" value="<?php echo esc_attr( wp_create_nonce( 'qsot-save-single-event-settings' ) ) ?>" />
     1849
     1850                <div class="field">
     1851                    <label for="qsot-single-event-start-date"><?php _e( 'Start Date/time', 'opentickets-community-edition' ) ?></label>
     1852                    <input type="text" class="widefat use-i18n-datepicker" name="qsot-single-event[start_date]" value="<?php echo esc_attr( $start_c ) ?>"
     1853                            data-display-format="<?php echo QSOT_Date_Formats::jquery_date_format( 'mm-dd-yy' ) ?>" role="from" scope=".qsot-mb" />
     1854                    <span class="at-time"><input type="text" class="widefat use-timepicker" name="qsot-single-event[start_time]" value="<?php echo esc_attr( $start_time ) ?>" /></span>
     1855                </div>
     1856
     1857                <div class="field">
     1858                    <label for="qsot-single-event-end-date"><?php _e( 'End Date/time', 'opentickets-community-edition' ) ?></label>
     1859                    <input type="text" class="widefat use-i18n-datepicker" name="qsot-single-event[end_date]" value="<?php echo esc_attr( $end_c ) ?>"
     1860                            data-display-format="<?php echo QSOT_Date_Formats::jquery_date_format( 'mm-dd-yy' ) ?>" role="to" scope=".qsot-mb" />
     1861                    <span class="at-time"><input type="text" class="widefat use-timepicker" name="qsot-single-event[end_time]" value="<?php echo esc_attr( $end_time ) ?>" /></span>
     1862                </div>
     1863
     1864                <div class="field">
     1865                    <label for="qsot-update-permalink"><?php _e( 'Permalink', 'opentickets-community-edition' ) ?></label>
     1866                    <span class="cb-wrap">
     1867                        <input type="checkbox" value="1" name="qsot-update-permalink" id="qsot-update-permalink" />
     1868                        <span class="cb-words"><?php _e( 'Yes, update the permalink upon save.', 'opentickets-community-edition' ) ?></span>
     1869                    </span>
     1870                </div>
     1871            </div>
     1872        <?php
    17651873    }
    17661874
     
    19692077
    19702078    public static function mb_event_date_time_settings($post, $mb) {
    1971         $now = current_time( 'timestamp' );
     2079        $ts = $now = date( 'c' );
     2080        $ts_1_week = date( 'c', strtotime( $ts . ' +1 week' )  );
     2081        $now = QSOT_Utils::local_timestamp( $now, 'from' );
    19722082        $end = strtotime( '+1 hour', $now );
    19732083        $one_week = strtotime( '+1 week', $now );
     
    19862096                                            <input type="text" class="use-i18n-datepicker date-text" name="start-date" scope="td" data-link-with=".repeat-options [role='from']"
    19872097                                                    data-display-format="<?php echo esc_attr( __( 'mm-dd-yy', 'opentickets-community-edition' ) ) ?>"
    1988                                                     value="<?php echo date( __( 'm-d-Y', 'opentickets-community-edition' ), $now ) ?>" title="<?php _e('Start Date','opentickets-community-edition') ?>" role="from" />
     2098                                                    value="<?php echo $ts ?>" title="<?php _e('Start Date','opentickets-community-edition') ?>" role="from" />
    19892099                                            <input type="text" class="time-text" name="start-time" value="<?php echo date(__('h:ia','opentickets-community-edition'), $now) ?>" title="<?php _e('Start Time','opentickets-community-edition') ?>" />
    19902100
     
    19932103                                            <input type="text" class="use-i18n-datepicker date-text" name="end-date" scope="td" data-link-with=".repeat-options [role='from']"
    19942104                                                    data-display-format="<?php echo esc_attr( __( 'mm-dd-yy', 'opentickets-community-edition' ) ) ?>"
    1995                                                     value="<?php echo date( __( 'm-d-Y', 'opentickets-community-edition' ), $end ) ?>" title="<?php _e('End Date','opentickets-community-edition') ?>" role="to" />
     2105                                                    value="<?php echo $ts ?>" title="<?php _e('End Date','opentickets-community-edition') ?>" role="to" />
    19962106                                            <input type="text" class="time-text" name="end-time" value="<?php echo date(__('h:ia','opentickets-community-edition'), $end) ?>" title="<?php _e('End Time','opentickets-community-edition') ?>" />
    19972107
     
    20762186                                                                <input type="text" class="widefat date-text use-i18n-datepicker ends-on" name="repeat-starts" scope=".repeat-options"
    20772187                                                                        data-display-format="<?php echo esc_attr( __( 'mm-dd-yy', 'opentickets-community-edition' ) ) ?>"
    2078                                                                         value="<?php echo esc_attr( date( __( 'm-d-Y', 'opentickets-community-edition' ), $now ) ) ?>" role="from" />
     2188                                                                        value="<?php echo esc_attr( $ts ) ?>" role="from" />
    20792189                                                            </td>
    20802190                                                        </tr>
     
    20912201                                                                        <input type="text" class="widefat date-text use-i18n-datepicker" name="repeat-ends-on" scope=".repeat-options"
    20922202                                                                                data-display-format="<?php echo esc_attr( __( 'mm-dd-yy', 'opentickets-community-edition' ) ) ?>"
    2093                                                                                 value="<?php echo esc_attr( date( __( 'm-d-Y', 'opentickets-community-edition' ), $one_week ) ) ?>" role="to" />
     2203                                                                                value="<?php echo esc_attr( $ts_1_week ) ?>" role="to" />
    20942204                                                                    </li>
    20952205                                                                    <li>
  • opentickets-community-edition/trunk/inc/event-area/general-admission-area-type.class.php

    r1479172 r1536371  
    929929    public function admin_ajax_load_event( $data, $event, $event_area, $order ) {
    930930        // add the html versions of the start and end date
    931         $frmt = __( 'D, F jS, Y h:ia', 'opentickets-community-edition' );
     931        $frmt = QSOT_Date_Formats::php_date_format( 'D, F jS, Y h:ia' );
    932932        $data['_html_date'] = sprintf( '<span class="from">%s</span> - <span class="to">%s</span>', date_i18n( $frmt, QSOT_Utils::local_timestamp( $event->meta->start ) ), date_i18n( $frmt, QSOT_Utils::local_timestamp( $event->meta->end ) ) );
    933933
  • opentickets-community-edition/trunk/inc/event-area/post-type.class.php

    r1529668 r1536371  
    11991199
    12001200                $event_start = get_post_meta( $event->ID, '_start', true );
    1201                 $event_date_time = date_i18n( get_option( 'date_format', __( 'Y-m-d', 'opentickets-commnunity-edition' ) ), QSOT_Utils::local_timestamp( $event_start ) ) . ' '
    1202                         . date_i18n( get_option( 'time_format', __( 'H:i:s', 'opentickets-commnunity-edition' ) ), QSOT_Utils::local_timestamp( $event_start ) );
     1201                $event_date_time = date_i18n( QSOT_Date_Formats::php_date_format( 'Y-m-d' ), QSOT_Utils::local_timestamp( $event_start ) ) . ' '
     1202                        . date_i18n( QSOT_Date_Formats::php_date_format( 'H:i:s' ), QSOT_Utils::local_timestamp( $event_start ) );
    12031203                // add a note explaining what we did
    12041204                $order->add_order_note( apply_filters( 'qsot-removing-cancelled-order-ticket-msg', sprintf(
  • opentickets-community-edition/trunk/inc/sys/admin-settings.php

    r1369465 r1536371  
    3434            $settings[] = include( 'settings/general.php' );
    3535            $settings[] = include( 'settings/frontend.php' );
     36            $settings[] = include( 'settings/dates.php' );
    3637
    3738            // allow adding of other pages if needed
  • opentickets-community-edition/trunk/inc/sys/extensions/settings/licenses.php

    r1314484 r1536371  
    157157                                        <div class="field">
    158158                                            <span class="label"><?php _e( 'Expired On', 'opentickets-community-edition' ) ?></span>:
    159                                             <span class="value"><?php echo date_i18n( get_option( 'date_format', 'F jS, Y' ), $licenses[ $file ]['expires'] ) ?></span>
     159                                            <span class="value"><?php echo date_i18n( get_option( 'date_format', QSOT_Date_Formats::php_date_format( 'F jS, Y' ) ), $licenses[ $file ]['expires'] ) ?></span>
    160160                                        </div>
    161161                                    <?php else: ?>
     
    179179                                        <div class="field">
    180180                                            <span class="label"><?php _e( 'Expires On', 'opentickets-community-edition' ) ?></span>:
    181                                             <span class="value"><?php echo date_i18n( get_option( 'date_format', 'F jS, Y' ), $licenses[ $file ]['expires'] ) ?></span>
     181                                            <span class="value"><?php echo date_i18n( get_option( 'date_format', QSOT_Date_Formats::php_date_format( 'F jS, Y' ) ), $licenses[ $file ]['expires'] ) ?></span>
    182182                                        </div>
    183183                                    <?php endif; ?>
  • opentickets-community-edition/trunk/inc/sys/pages/system-status.page.php

    r1532350 r1536371  
    10421042        }
    10431043
    1044         $subject = '[' . date_i18n( __( 'm-d-Y', 'opentickets-community-edition' ) ) . '] ' . $subject;
     1044        $subject = '[' . date_i18n( QSOT_Date_Formats::php_date_format( 'm-d-Y' ) ) . '] ' . $subject;
    10451045        $purl = @parse_url( site_url() );
    10461046        $headers = array( 'From: Opentickets Background Process <background@' . $purl['host'] . '>' );
  • opentickets-community-edition/trunk/inc/sys/rewrite.php

    r1299061 r1536371  
    2323        // during activation, we need to flush the rewrite rules, because there are a few classes that register spcial rules
    2424        add_action( 'qsot-activate', array( __CLASS__, 'on_activate' ), 1000 );
     25
     26        // handle old event slug lookups
     27        add_action( 'template_redirect', array( __CLASS__, 'old_event_slug_redirect' ), PHP_INT_MAX );
    2528    }
    2629
     
    180183        return $out;
    181184    }
     185
     186    public static function old_event_slug_redirect() {
     187        global $wp_query;
     188
     189        if ( is_404() && '' !== $wp_query->query_vars['name'] && isset( $wp_query->query_vars['qsot-event'] ) && '' !== $wp_query->query_vars['qsot-event'] ) :
     190            global $wpdb;
     191
     192            // Guess the current post_type based on the query vars.
     193            if ( get_query_var( 'post_type' ) ) {
     194                $post_type = get_query_var( 'post_type' );
     195            } elseif ( get_query_var( 'attachment' ) ) {
     196                $post_type = 'attachment';
     197            } elseif ( ! empty( $wp_query->query_vars['pagename'] ) ) {
     198                $post_type = 'page';
     199            } else {
     200                $post_type = 'post';
     201            }
     202
     203            if ( is_array( $post_type ) ) {
     204                if ( count( $post_type ) > 1 )
     205                    return;
     206                $post_type = reset( $post_type );
     207            }
     208
     209            // only redirect event post types
     210            if ( 'qsot-event' !== $post_type )
     211                return;
     212
     213            $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['qsot-event']);
     214
     215            // if year, monthnum, or day have been specified, make our query more precise
     216            // just in case there are multiple identical _wp_old_slug values
     217            if ( '' != $wp_query->query_vars['year'] )
     218                $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", $wp_query->query_vars['year']);
     219            if ( '' != $wp_query->query_vars['monthnum'] )
     220                $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", $wp_query->query_vars['monthnum']);
     221            if ( '' != $wp_query->query_vars['day'] )
     222                $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", $wp_query->query_vars['day']);
     223
     224            $id = (int) $wpdb->get_var($query);
     225
     226            if ( ! $id )
     227                return;
     228
     229            $link = get_permalink( $id );
     230
     231            if ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged'] > 1 ) {
     232                $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . $GLOBALS['wp_query']->query_vars['paged'] );
     233            } elseif( is_embed() ) {
     234                $link = user_trailingslashit( trailingslashit( $link ) . 'embed' );
     235            }
     236
     237            /**
     238             * Filters the old slug redirect URL.
     239             *
     240             * @since 4.4.0
     241             *
     242             * @param string $link The redirect URL.
     243             */
     244            $link = apply_filters( 'old_slug_redirect_url', $link );
     245
     246            if ( ! $link ) {
     247                return;
     248            }
     249
     250            wp_redirect( $link, 301 ); // Permanent redirect
     251            exit;
     252        endif;
     253    }
    182254}
    183255
  • opentickets-community-edition/trunk/inc/sys/settings-page.abstract.php

    r1367916 r1536371  
    2727
    2828        echo '</ul><br class="clear" />';
     29    }
     30
     31    protected function _get_page_settings() { return array(); }
     32
     33    /**
     34     * Get settings array
     35     *
     36     * @return array
     37     */
     38    public function get_page_settings() {
     39        global $current_section;
     40        return apply_filters( 'qsot-get-page-settings', $this->_get_page_settings(), $this->id, $current_section );
    2941    }
    3042
     
    6476        return $fields;
    6577    }
     78
     79    // setup the basic hooks we need for the settings page
     80    protected function _setup_settings_page_hooks() {
     81        add_action( 'qsot_sections_' . $this->id, array( $this, 'output_sections' ) );
     82        add_filter( 'qsot_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
     83        add_action( 'qsot_settings_' . $this->id, array( $this, 'output' ) );
     84        add_action( 'qsot_settings_save_' . $this->id, array( $this, 'save' ) );
     85    }
    6686}
    6787
  • opentickets-community-edition/trunk/inc/sys/settings/frontend.php

    r1367916 r1536371  
    2222        $this->label = __( 'Frontend', 'opentickets-community-edition' );
    2323
    24         add_action( 'qsot_sections_' . $this->id, array( $this, 'output_sections' ) );
    25         add_filter( 'qsot_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
    26         add_action( 'qsot_settings_' . $this->id, array( $this, 'output' ) );
    27         add_action( 'qsot_settings_save_' . $this->id, array( $this, 'save' ) );
     24        $this->_setup_settings_page_hooks();
    2825
    2926        if ( ( $styles = WC_Frontend_Scripts::get_styles() ) && array_key_exists( 'woocommerce-general', $styles ) )
     
    4542
    4643        return $sections;
    47     }
    48 
    49     /**
    50      * Get settings array
    51      *
    52      * @return array
    53      */
    54     public function get_page_settings() {
    55         global $current_section;
    56         return apply_filters( 'qsot-get-page-settings', array(), $this->id, $current_section );
    5744    }
    5845
  • opentickets-community-edition/trunk/inc/sys/utils.php

    r1532350 r1536371  
    250250    }
    251251
     252    // accept a user input value for a time, and convert it to 24 hour time
     253    public static function to_24_hour( $raw_time ) {
     254        // get the various time parts
     255        preg_match( '#^(?P<hour>\d{1,2})(?:[^\dAPMapm]?(?<minute>\d{1,2}))?(?:[^\dAPMapm]?(?<second>\d{1,2}))?(?P<meridiem>[APMapm]+)?$#', $raw_time, $match );
     256
     257        // if we have no matches of at least the hour field, then bail
     258        if ( ! is_array( $match ) || ! isset( $match['hour'] ) )
     259            return '';
     260
     261        $match['hour'] = absint( $match['hour'] );
     262        // update the hour based on meridiem if present
     263        if ( isset( $match['meridiem'] ) ) {
     264            $mer = strtolower( $match['meridiem'] );
     265            // if it is pm and the hour is not 12pm, then add 12 hours
     266            if ( in_array( $mer, array( 'p', 'pm' ) ) && 12 != $match['hour'] )
     267                $match['hour'] = $match['hour'] + 12;
     268            // if it is am and the hour is 12am, make it a 0, for midnight
     269            if ( in_array( $mer, array( 'a', 'am' ) ) && 12 == $match['hour'] )
     270                $match['hour'] = 0;
     271        }
     272
     273        // glue it back up and fill it in
     274        return sprintf(
     275            '%02s:%02s:%02s',
     276            $match['hour'],
     277            isset( $match['minute'] ) ? absint( $match['minute'] ) : 0,
     278            isset( $match['second'] ) ? absint( $match['second'] ) : 0
     279        );
     280    }
     281
    252282    // code to update all the site event start and end times to the same timezone as the SITE, in non-dst, is currently set to
    253283    public static function normalize_event_times() {
     
    303333    }
    304334}
     335
     336// date formatter utils
     337class QSOT_Date_Formats {
     338    // map of php-date format letters to base date-time-segment-type
     339    protected static $php_format_map = array(
     340        // days
     341        'd' => 'd',
     342        'D' => 'd',
     343        'j' => 'd',
     344        'l' => 'd',
     345        'N' => 'd',
     346        'S' => 'd',
     347        'w' => 'd',
     348        'z' => 'd',
     349
     350        // month
     351        'F' => 'm',
     352        'm' => 'm',
     353        'M' => 'm',
     354        'n' => 'm',
     355        't' => 'm',
     356
     357        // Year
     358        'y' => 'Y',
     359        'Y' => 'Y',
     360        'o' => 'Y',
     361
     362        // hour
     363        'g' => 'h',
     364        'G' => 'h',
     365        'h' => 'h',
     366        'H' => 'h',
     367
     368        // minute
     369        'i' => 'i',
     370
     371        // second
     372        's' => 's',
     373
     374        // meridiem
     375        'a' => 'a',
     376        'A' => 'a',
     377
     378        // timezone
     379        'O' => 'z',
     380        'P' => 'z',
     381        'T' => 'z',
     382        'Z' => 'z',
     383
     384        // nothing important
     385        'W' => false,
     386        'B' => false,
     387        'u' => false,
     388        'e' => false,
     389        'I' => false,
     390        'c' => false,
     391        'r' => false,
     392        'U' => false,
     393    );
     394
     395    // list of php-formats used within our plugin that might be customized
     396    public static $php_custom_date_formats = array(
     397        'D, F jS, Y',
     398        'D, F jS, Y h:ia',
     399        'D, F jS, Y \@ g:ia',
     400        'F jS, Y',
     401        'l jS \\o\\f F Y, h:ia',
     402        'Y-m-d_gia',
     403        'Y-m-d',
     404        'm-d-Y',
     405        'm/d/Y',
     406    );
     407    public static $php_custom_time_formats = array(
     408        'g:ia',
     409        'h:ia',
     410        'H:i:s',
     411    );
     412    public static $moment_custom_date_formats = array(
     413        'mm-dd-yy',
     414    );
     415    public static $moment_custom_time_formats = array(
     416    );
     417    public static $jqueryui_custom_date_formats = array(
     418    );
     419    public static $jqueryui_custom_time_formats = array(
     420    );
     421
     422    // report whether this site uses DST or not, according to settings
     423    public static function use_dst() { return get_option( 'qsot-use-dst', 'yes' ) == 'yes'; }
     424
     425    // report date and time format settings
     426    public static function date_format() { return get_option( 'qsot-date-format', 'm-d-Y' ); }
     427    public static function hour_format() { return get_option( 'qsot-hour-format', '12-hour' ); }
     428    public static function is_12_hour() { return get_option( 'qsot-hour-format', '12-hour' ) == '12-hour'; }
     429    public static function is_24_hour() { return get_option( 'qsot-hour-format', '12-hour' ) == '24-hour'; }
     430
     431    // load all custom formats from the db
     432    protected static function _load_custom_formats() {
     433        $formats = array();
     434        foreach ( self::$php_custom_date_formats as $format )
     435            if ( $value = get_option( 'qsot-custom-php-date-format-' . sanitize_title_with_dashes( $format ), '' ) )
     436                $formats[ $format ] = $value;
     437        foreach ( self::$php_custom_time_formats as $format )
     438            if ( $value = get_option( 'qsot-custom-php-date-format-' . sanitize_title_with_dashes( $format ), '' ) )
     439                $formats[ $format ] = $value;
     440        return $formats;
     441    }
     442
     443    // reorder a time format, based on the settings
     444    public static function php_date_format( $format='m-d-Y' ) {
     445        static $conversions = false;
     446        // load all custom formats from db, the first time this function is called
     447        if ( false === $conversions )
     448            $conversions = self::_load_custom_formats();
     449        // only do this conversion once per input format
     450        if ( isset( $conversions[ $format ] ) )
     451            return $conversions[ $format ];
     452
     453        $segment = array();
     454        $last_segment = false;
     455        $i = 0;
     456        $ii = strlen( $format );
     457        // break up the requested format into parts
     458        for ( $i = 0; $i < $ii; $i++ ) {
     459            // if the next char is a back slash, skip it and the next letter
     460            if ( '\\' == $format[ $i ] ) {
     461                if ( $last_segment )
     462                    $segment[ $last_segment ] .= substr( $format, $i, 2 );
     463                $i++;
     464                continue;
     465            }
     466
     467            // if the next letter is not in the php format map, or is irrelevant, then skip it
     468            if ( ! isset( self::$php_format_map[ $format[ $i ] ] ) ) {
     469                if ( $last_segment )
     470                    $segment[ $last_segment ] .= substr( $format, $i, 1 );
     471                continue;
     472            }
     473
     474            // otherwise, add this letter to the relevant segment
     475            $last_segment = self::$php_format_map[ $format[ $i ] ];
     476            if ( ! isset( $segment[ self::$php_format_map[ $format[ $i ] ] ] ) )
     477                $segment[ self::$php_format_map[ $format[ $i ] ] ] = '';
     478            $segment[ self::$php_format_map[ $format[ $i ] ] ] .= $format[ $i ];
     479        }
     480
     481        $date_format_array = explode( '-', self::date_format() );
     482        $date_format = '';
     483        // reorder the date portion of the format, based on the settings
     484        foreach ( $date_format_array as $segment_key )
     485            $date_format .= isset( $segment[ $segment_key ] ) ? $segment[ $segment_key ] : '';
     486
     487        $time_format = '';
     488        $is_24_hour = self::is_24_hour();
     489        // construct the time format
     490        if ( $is_24_hour && isset( $segment['h'] ) )
     491            $time_format .= strtoupper( $segment['h'] );
     492        elseif ( ! $is_24_hour && isset( $segment['h'] ) )
     493            $time_format .= strtolower( $segment['h'] );
     494        if ( isset( $segment['i'] ) )
     495            $time_format .= $segment['i'];
     496        if ( isset( $segment['s'] ) )
     497            $time_format .= $segment['s'];
     498        if ( ! $is_24_hour && isset( $segment['a'] ) )
     499            $time_format .= $segment['a'];
     500        if ( isset( $segment['z'] ) )
     501            $time_format .= $segment['z'];
     502
     503        // glue that shit together, and return
     504        $conversion[ $format ] = trim( $date_format . ' ' . $time_format );
     505        return $conversion[ $format ];
     506    }
     507
     508    // reorder the time format, based on the settings, for a momentjs format
     509    public static function moment_date_format( $format='mm-dd-yy' ) {
     510        return $format;
     511    }
     512
     513    // reorder the time format, based on the settings, for a jquery format
     514    public static function jquery_date_format( $format='mm-dd-yy' ) {
     515        return $format;
     516    }
     517}
  • opentickets-community-edition/trunk/launcher.php

    r1532350 r1536371  
    44 * Plugin URI:  http://opentickets.com/
    55 * Description: Event Management and Online Ticket Sales Platform
    6  * Version:     2.5.3
     6 * Version:     2.6.0
    77 * Author:      Quadshot Software LLC
    88 * Author URI:  http://quadshot.com/
     
    5454            'fctm' => 'fc',
    5555            'always_reserve' => 0,
    56             'version' => '2.5.3',
     56            'version' => '2.6.0',
    5757            'min_wc_version' => '2.6.1',
    5858            'core_post_type' => 'qsot-event',
  • opentickets-community-edition/trunk/readme.txt

    r1532350 r1536371  
    171171
    172172== Changelog ==
     173
     174= 2.6.0 - Nov/18/2016 =
     175* [new] major overhaul on displayed time formats. now they are all options in the admin
     176* [new] ability to edit an individual event, change the start/end time, and update the permalink with auto-redirect of old one
     177* [tweak] update to better process manually typed in time values when creating and editing events
    173178
    174179= 2.5.3 - Nov/11/2016 =
  • opentickets-community-edition/trunk/templates/checkin/already-occupied.php

    r1437825 r1536371  
    2525                            <li class="event"><strong><?php _e( 'Event:', 'opentickets-community-edition' ) ?></strong> <?php echo $ticket->event->post_title ?></li>
    2626                            <li class="start-date"><strong><?php _e( 'Starts:', 'opentickets-community-edition' ) ?></strong> <?php
    27                                 echo date_i18n( get_option( 'date_format', 'F jS, Y' ) . ' ' . get_option( 'time_format', 'g:ia' ), QSOT_Utils::local_timestamp( $ticket->event->meta->start ) )
     27                                echo date_i18n( get_option( 'date_format', QSOT_Date_Formats::php_date_format( 'F jS, Y' ) ) . ' ' . get_option( 'time_format', QSOT_Date_Formats::php_date_format( 'g:ia' ) ), QSOT_Utils::local_timestamp( $ticket->event->meta->start ) )
    2828                            ?></li>
    2929                            <li class="checked"><strong><?php _e( 'Checked-In:', 'opentickets-community-edition' ) ?></strong> <?php echo $index ?></li>
  • opentickets-community-edition/trunk/templates/checkin/occupy-failure.php

    r1437825 r1536371  
    2525                            <li class="event"><strong><?php _e('Event:','opentickets-community-edition') ?></strong> <?php echo $ticket->event->post_title ?></li>
    2626                            <li class="start-date"><strong><?php _e( 'Starts:', 'opentickets-community-edition' ) ?></strong> <?php
    27                                 echo date_i18n( get_option( 'date_format', 'F jS, Y' ) . ' ' . get_option( 'time_format', 'g:ia' ), QSOT_Utils::local_timestamp( $ticket->event->meta->start ) )
     27                                echo date_i18n( get_option( 'date_format', QSOT_Date_Formats::php_date_format( 'F jS, Y' ) ) . ' ' . get_option( 'time_format', QSOT_Date_Formats::php_date_format( 'g:ia' ) ), QSOT_Utils::local_timestamp( $ticket->event->meta->start ) )
    2828                            ?></li>
    2929                            <li class="checked"><strong><?php _e('Checked-In:','opentickets-community-edition') ?></strong> <?php echo $index ?></li>
  • opentickets-community-edition/trunk/templates/checkin/occupy-success.php

    r1437825 r1536371  
    2525                            <li class="event"><strong><?php _e('Event:','opentickets-community-edition') ?></strong> <?php echo $ticket->event->post_title ?></li>
    2626                            <li class="start-date"><strong><?php _e( 'Starts:', 'opentickets-community-edition' ) ?></strong> <?php
    27                                 echo date_i18n( get_option( 'date_format', 'F jS, Y' ) . ' ' . get_option( 'time_format', 'g:ia' ), QSOT_Utils::local_timestamp( $ticket->event->meta->start ) )
     27                                echo date_i18n( get_option( 'date_format', QSOT_Date_Formats::php_date_format( 'F jS, Y' ) ) . ' ' . get_option( 'time_format', QSOT_Date_Formats::php_date_format( 'g:ia' ) ), QSOT_Utils::local_timestamp( $ticket->event->meta->start ) )
    2828                            ?></li>
    2929                            <li class="checked"><strong><?php _e('Checked-In:','opentickets-community-edition') ?></strong> <?php echo $index ?></li>
  • opentickets-community-edition/trunk/templates/tickets/ticket/event-meta.php

    r1437825 r1536371  
    88    <li>
    99        <span class="label"><?php _e( 'Starts:', 'opentickets-community-edition' ) ?></span>
    10         <span class="value"><?php echo date( __( 'D, F jS, Y', 'opentickets-community-edition' ), $start_time ), __( ' @ ', 'opentickets-community-edition' ), date( __( 'g:ia', 'opentickets-community-edition' ), $start_time ) ?></span>
     10        <span class="value"><?php echo date( QSOT_Date_Formats::php_date_format( 'D, F jS, Y \@ g:ia' ), $start_time ) ?></span>
    1111    </li>
    1212    <li>
    1313        <span class="label"><?php _e( 'Ends:', 'opentickets-community-edition' ) ?></span>
    1414        <?php if ( $same_day ): ?>
    15             <span class="value"><?php echo __( ' @ ', 'opentickets-community-edition' ), date( __( 'g:ia', 'opentickets-community-edition' ), $end_time ) ?></span>
     15            <span class="value"><?php echo __( ' @ ', 'opentickets-community-edition' ), date( QSOT_Date_Formats::php_date_format( 'g:ia' ), $end_time ) ?></span>
    1616        <?php else: ?>
    17             <span class="value"><?php echo date( __( 'D, F jS, Y', 'opentickets-community-edition' ), $end_time ), __( ' @ ', 'opentickets-community-edition' ), date( __( 'g:ia', 'opentickets-community-edition' ), $end_time ) ?></span>
     17            <span class="value"><?php echo date( QSOT_Date_Formats::php_date_format( 'D, F jS, Y \@ g:ia' ), $end_time ) ?></span>
    1818        <?php endif; ?>
    1919    </li>
Note: See TracChangeset for help on using the changeset viewer.