Changeset 1047426
- Timestamp:
- 12/17/2014 07:24:35 PM (11 years ago)
- Location:
- content-scheduler/trunk
- Files:
-
- 1 added
- 5 edited
-
content-scheduler-settings.php (modified) (2 diffs)
-
content-scheduler.php (modified) (10 diffs)
-
includes/process-expirations.php (modified) (2 diffs)
-
includes/process-notifications.php (modified) (1 diff)
-
includes/send-notifications.php (modified) (1 diff)
-
includes/update-postmeta-expiration-values.php (added)
Legend:
- Unmodified
- Added
- Removed
-
content-scheduler/trunk/content-scheduler-settings.php
r1047425 r1047426 5 5 exit(); 6 6 } 7 8 define( 'PEK_CONTENT_SCHEDULER_VERSION', '2.0.0' ); 7 9 8 10 if ( !class_exists( "Content_Scheduler_Settings" ) ) { … … 588 590 function draw_plugin_version() 589 591 { 590 $this->options = get_option('ContentScheduler_Options'); 591 echo "<p>$this->options[version]</p>\n"; 592 echo "<p>" . $this->options['version'] . "</p>\n"; 592 593 } // end draw_plugin_version() 593 594 -
content-scheduler/trunk/content-scheduler.php
r1047425 r1047426 185 185 if( is_array( $this->options ) ) 186 186 { 187 // If version is older than 2.0, we need to change the way we store expiration date metadata 188 if( !isset( $this->options['version'] ) || $this->options['version'] < '2.0.0' ) 189 { 190 include 'includes/update-postmeta-expiration-values.php'; 191 } 187 192 // If version newer than 0.9.7, we need to alter the name of our postmeta variables if there are earlier version settings in options 188 193 if( !isset( $this->options['version'] ) || $this->options['version'] < '0.9.7' ) … … 238 243 // We previously used content_scheduler_(blogid) 239 244 // http://codex.wordpress.org/Function_Reference/wp_schedule_event 245 // TODO time() is UTC for right now, and that is okay 240 246 wp_schedule_event( time(), 'contsched_usertime', 'contentscheduler' ); 241 247 // wp_schedule_event( time(), 'hourly', 'content_scheduler_'.$current_blog_id ); … … 393 399 echo "<br />\n<br />\n"; 394 400 // Field for datetime of expiration 395 $datestring = ( get_post_meta( $post->ID, '_cs-expire-date', true) ); 401 // TODO datetime conversion 402 // should be unix timestamp at this point, in UTC 403 // for display, we need to convert this to local time and then format 404 405 // datestring is the original human-readable form 406 // $datestring = ( get_post_meta( $post->ID, '_cs-expire-date', true) ); 407 // timestamp should just be a unix timestamp 408 $timestamp = ( get_post_meta( $post->ID, '_cs-expire-date', true) ); 409 if( !empty( $timestamp ) ) { 410 // we need to convert that into human readable so we can put it into our field 411 $datestring = $this->getReadableDateFromTimestamp( $timestamp ); 412 } else { 413 $datestring = ''; 414 } 396 415 // Should we check for format of the date string? (not doing that presently) 397 416 echo '<label for="cs-expire-date">' . __("Expiration date and hour", 'contentscheduler' ) . '</label><br />'; … … 435 454 // OK, we're authenticated: we need to find and save the data 436 455 // First, let's make sure we'll do date operations in the right timezone for this blog 437 $this->setup_timezone();456 // $this->setup_timezone(); 438 457 // Checkbox for "enable scheduling" 439 458 $enabled = ( empty( $_POST['_cs-enable-schedule'] ) ? 'Disable' : $_POST['_cs-enable-schedule'] ); … … 448 467 } 449 468 // Textbox for "expiration date" 450 $date = $_POST['_cs-expire-date']; 469 $dateString = $_POST['_cs-expire-date']; 470 $offsetHours = 0; 471 // if it is empty then set it to tomorrow 472 // we just want to pass an offset into getTimestampFromReadableDate since that is where our DateTime is made 473 if( empty( $dateString ) ) { 474 // set it to now + 24 hours 475 $offsetHours = 24; 476 } 477 // TODO handle datemath if field reads "default" 451 478 if( strtolower( $date ) == 'default' ) 452 479 { … … 506 533 else 507 534 { 508 // How can we check a myriad of date formats?? 509 // Right now we are mm/dd/yyyy 510 if( ! $this->check_date_format( $date ) ) 511 { 512 // It was not a valid date format 513 // Normally, we would set to '' 514 $date = ''; 515 // For debug, we will set to 'INVALID' 516 // $date = 'INVALID'; 517 } 535 // a. Take human-readable date and time from the field, 536 // b. turn it into a local timestamp 537 // c. turn that into a utc timestamp 538 // d. store it. into $date before saving 539 $date = $this->getTimestampFromReadableDate( $dateString, $offsetHours ); 518 540 } 519 541 // We probably need to store the date differently, … … 758 780 $query = "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = \"_cs-expire-date\" AND post_id=$id"; 759 781 // get the single returned value (can do this better?) 760 $ed = $wpdb->get_var($query); 782 // $ed = $wpdb->get_var($query); 783 $timestamp = $wpdb->get_var($query); 784 if( !empty( $timestamp ) ) { 785 // convert 786 $ed = $this->getReadableDateFromTimestamp( $timestamp ); 787 } else { 788 $ed = "Date misunderstood"; 789 } 761 790 // determine whether expiration is enabled or disabled 762 791 if( get_post_meta( $post->ID, '_cs-enable-schedule', true) != 'Enable' ) … … 801 830 // else - continue 802 831 // get the expiration timestamp 803 $ expirationdt= get_post_meta( $post->ID, '_cs-expire-date', true );804 if ( empty( $ expirationdt) )832 $timestamp = get_post_meta( $post->ID, '_cs-expire-date', true ); 833 if ( empty( $timestamp ) ) 805 834 { 806 835 return false; 807 } 836 } else { 837 $expirationdt = $this->getReadableDateFromTimestamp( $timestamp ); 838 } 839 808 840 // We'll need the following if / when we allow formatting of the timestamp 809 841 /* … … 867 899 // handle timezones 868 900 function setup_timezone() { 901 error_log( __FILE__ . " :: " . __FUNCTION__ . " was called, but we want to stop using it." ); 902 /* 869 903 if ( ! $wp_timezone = get_option( 'timezone_string' ) ) 870 904 { … … 874 908 // Set the default timezone used by Content Scheduler 875 909 date_default_timezone_set( $wp_timezone ); 910 */ 876 911 } 877 } // end ContentScheduler Class 912 913 // TODO: Pull these out into a static class so they can be used in multiple places 914 /* 915 unixTimestamp timestamp NOT adjusted for WordPress local time 916 return something date and time as one string following WP site formatting settings 917 */ 918 function getReadableDateFromTimestamp( $unixTimestamp ) { 919 // get datetime object from unix timestamp 920 $datetime = new DateTime( "@$unixTimestamp", new DateTimeZone( 'UTC' ) ); 921 // set the timezone to the site timezone 922 $datetime->setTimezone( new DateTimeZone( $this->wp_get_timezone_string() ) ); 923 // return the unix timestamp adjusted to reflect the site's timezone 924 // return $timestamp + $datetime->getOffset(); 925 $localTimestamp = $unixTimestamp + $datetime->getOffset(); 926 $dateString = date_i18n( get_option( 'date_format' ), $localTimestamp ); 927 $timeString = date( get_option( 'time_format' ), $localTimestamp ); 928 // put together and return 929 return $dateString . " " . $timeString; 930 } 931 /* 932 dateSTring readalbe date / time string from user input field 933 offsetHours hours to add / remove from dateString-generated DateTime 934 return unit timestamp in UTC time (i.e., not 'local' time) 935 */ 936 function getTimestampFromReadableDate( $dateString, $offsetHours = 0 ) { 937 // get datetime object from site timezone 938 $datetime = new DateTime( $dateString, new DateTimeZone( $this->wp_get_timezone_string() ) ); 939 // add the offsetHours 940 // $date->add(new DateInterval('P10D')); 941 $datetime->add( new DateInterval( "PT".$offsetHours."H" ) ); 942 // get the unix timestamp (adjusted for the site's timezone already) 943 $timestamp = $datetime->format( 'U' ); 944 return $timestamp; 945 } 946 /** 947 * Returns the timezone string for a site, even if it's set to a UTC offset 948 * 949 * Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155 950 * 951 * @return string valid PHP timezone string 952 */ 953 function wp_get_timezone_string() { 954 // if site timezone string exists, return it 955 if ( $timezone = get_option( 'timezone_string' ) ) 956 return $timezone; 957 // get UTC offset, if it isn't set then return UTC 958 if ( 0 === ( $utc_offset = get_option( 'gmt_offset', 0 ) ) ) 959 return 'UTC'; 960 // adjust UTC offset from hours to seconds 961 $utc_offset *= 3600; 962 // attempt to guess the timezone string from the UTC offset 963 if ( $timezone = timezone_name_from_abbr( '', $utc_offset, 0 ) ) { 964 return $timezone; 965 } 966 // last try, guess timezone string manually 967 $is_dst = date( 'I' ); 968 foreach ( timezone_abbreviations_list() as $abbr ) { 969 foreach ( $abbr as $city ) { 970 if ( $city['dst'] == $is_dst && $city['offset'] == $utc_offset ) 971 return $city['timezone_id']; 972 } 973 } 974 // fallback to UTC 975 return 'UTC'; 976 } 977 } // end ContentScheduler Class 878 978 } // End IF Class ContentScheduler 879 979 -
content-scheduler/trunk/includes/process-expirations.php
r1047425 r1047426 2 2 // find posts that need to take some expiration action 3 3 global $wpdb; 4 // $options = get_option('ContentScheduler_Options');5 // tell PHP to use wp-settings timezone6 $this->setup_timezone();7 4 // select all Posts / Pages that have "enable-expiration" set and have expiration date older than right now 8 // 12/8/2010 7:18:08 PM9 // Original has expiration date in results -- differing from process_notifications and causing problems.10 // $querystring = 'SELECT postmetadate.post_id, postmetadate.meta_value AS expiration11 5 $querystring = 'SELECT postmetadate.post_id 12 6 FROM … … 17 11 AND postmetadoit.meta_value = "Enable" 18 12 AND postmetadate.meta_key = "_cs-expire-date" 19 AND postmetadate.meta_value <= "' . date("Y-m-d H:i:s") . '"13 AND postmetadate.meta_value <= "' . time() . '" 20 14 AND postmetadate.post_id = postmetadoit.post_id 21 15 AND postmetadate.post_id = posts.ID -
content-scheduler/trunk/includes/process-notifications.php
r1047425 r1047426 5 5 // get days of notification offset 6 6 $notice_days = $this->options['notify-before']; 7 // setup timezone8 $this->setup_timezone();9 7 // find posts that need to send notifications 8 // this doesn't seem right. unix timestamp plus noticedays in seconds? NO 9 // I would think it would be ... hmm, I don't know 10 // anyway 11 // TODO 12 // dates need to be relavant to unix timestamp (UTC) 13 // AND postmetadate.meta_value <= "' . time() . '" 14 10 15 $notification_timestamp = time() + ($notice_days * 24 * 60 * 60); 11 16 $notification_string = date( "Y-m-d H:i:s", $notification_timestamp ); -
content-scheduler/trunk/includes/send-notifications.php
r1047425 r1047426 68 68 // $post_edit_url = "Fake Post Editing URL"; 69 69 // get the post expiration date 70 $post_expiration_date = ( get_post_meta( $post_data['ID'], '_cs-expire-date', true) ); 70 // $post_expiration_date = ( get_post_meta( $post_data['ID'], '_cs-expire-date', true) ); 71 $post_expiration_date_timestamp = ( get_post_meta( $post_data['ID'], '_cs-expire-date', true) ); 72 $post_expiration_date = $this->getReadableDateFromTimestamp( $post_expiration_date_timestamp ); 73 71 74 // pack it up into our array 72 75 // make a new item array
Note: See TracChangeset
for help on using the changeset viewer.