public static function getTimestampFromReadableDate($dateString, $offsetHours = 0) { // get datetime object from site timezone try { $datetime = new DateTime($dateString, new DateTimeZone(DateUtilities::wp_get_timezone_string())); } catch (Exception $e) { $datetime = new DateTime("2000-01-01", new DateTimeZone(DateUtilities::wp_get_timezone_string())); } // add the offsetHours // $date->add(new DateInterval('P10D')); // $datetime->add( new DateInterval( "PT".$offsetHours."H" ) ); // only PHP 5.3.x + if ($offsetHours > 0) { $datetime->modify('+' . $offsetHours . ' hours'); } // get the unix timestamp (adjusted for the site's timezone already) $timestamp = $datetime->format('U'); return $timestamp; }
<?php /* Should take human readable date strings and turn them into unix timestamps */ require_once "DateUtilities.php"; // find posts that need to take some expiration action global $wpdb; // select all Posts / Pages that have "enable-expiration" set and have expiration date older than right now $querystring = 'SELECT postmetadate.post_id, postmetadate.meta_value FROM ' . $wpdb->postmeta . ' AS postmetadate WHERE postmetadate.meta_key = "_cs-expire-date"'; $result = $wpdb->get_results($querystring); // Act upon the results if (!empty($result)) { // Proceed with the updating process // step through the results foreach ($result as $cur_post) { // do the date munging $unixTimestamp = DateUtilities::getTimestampFromReadableDate($cur_post->meta_value, 0); // update it update_post_meta($cur_post->post_id, '_cs-expire-date', $unixTimestamp, $cur_post->meta_value); } // end foreach } // endif
function handle_shortcode($attributes) { global $post; global $current_user; // Check to see if we have rights to see stuff $min_level = $this->options['min-level']; get_currentuserinfo(); $allcaps = $current_user->allcaps; if (1 != $allcaps[$min_level]) { return; // not authorized to see CS } // else - continue // get the expiration timestamp $timestamp = get_post_meta($post->ID, '_cs-expire-date', true); if (empty($timestamp)) { return false; } else { $expirationdt = DateUtilities::getReadableDateFromTimestamp($timestamp); } $return_string = sprintf(__("Expires: %s", 'contentscheduler'), $expirationdt); return $return_string; }
$auth_id = $post_data['post_author']; // get the author email address $auth_info = get_userdata($auth_id); $auth_email = "Author <" . $auth_info->user_email . ">"; // get the post ID $post_id = $post_data['ID']; // get the post title $post_title = $post_data['post_title']; // get / create the post viewing URL $post_view_url = $post_data['guid']; // get / create the post editing url // $post_edit_url = "Fake Post Editing URL"; // get the post expiration date // $post_expiration_date = ( get_post_meta( $post_data['ID'], '_cs-expire-date', true) ); $post_expiration_date_timestamp = get_post_meta($post_data['ID'], '_cs-expire-date', true); $post_expiration_date = DateUtilities::getReadableDateFromTimestamp($post_expiration_date_timestamp); // pack it up into our array // make a new item array $new_item['ID'] = $post_id; $new_item['post_title'] = $post_title; $new_item['view_url'] = $post_view_url; // $new_item['edit_url'] = $post_edit_url; $new_item['expiration_date'] = $post_expiration_date; if ($notify_whom == 'author' or $notify_whom == 'both') { // add the post to the notification list $notify_list[$auth_email][] = $new_item; } // if we are notifying admin, we can add it to their array if ($notify_whom == 'admin' or $notify_whom == 'both') { // See if the site_admin_email matches the author email. // If it does, the admin is already being notified, so we should not continue