/** * Actually adds the meta box */ function expirationdate_meta_box($post) { // Get default month $expirationdatets = get_post_meta($post->ID, '_expiration-date', true); $firstsave = get_post_meta($post->ID, '_expiration-date-status', true); $default = ''; $expireType = ''; $defaults = get_option('expirationdateDefaults' . ucfirst($post->post_type)); if (empty($expirationdatets)) { $default = get_option('expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT); if ($default == 'null') { $defaultmonth = date_i18n('m'); $defaultday = date_i18n('d'); $defaulthour = date_i18n('H'); $defaultyear = date_i18n('Y'); $defaultminute = date_i18n('i'); } elseif ($default == 'custom') { $custom = get_option('expirationdateDefaultDateCustom'); if ($custom === false) { $ts = time(); } else { $tz = get_option('timezone_string'); if ($tz) { date_default_timezone_set($tz); } $ts = time() + (strtotime($custom) - time()); if ($tz) { date_default_timezone_set('UTC'); } } $defaultmonth = get_date_from_gmt(gmdate('Y-m-d H:i:s', $ts), 'm'); $defaultday = get_date_from_gmt(gmdate('Y-m-d H:i:s', $ts), 'd'); $defaultyear = get_date_from_gmt(gmdate('Y-m-d H:i:s', $ts), 'Y'); $defaulthour = get_date_from_gmt(gmdate('Y-m-d H:i:s', $ts), 'H'); $defaultminute = get_date_from_gmt(gmdate('Y-m-d H:i:s', $ts), 'i'); } $enabled = ''; $disabled = ' disabled="disabled"'; $categories = get_option('expirationdateCategoryDefaults'); if (isset($defaults['expireType'])) { $expireType = $defaults['expireType']; } if (isset($defaults['autoEnable']) && $firstsave !== 'saved' && ($defaults['autoEnable'] === true || $defaults['autoEnable'] == 1)) { $enabled = ' checked="checked"'; $disabled = ''; } } else { $defaultmonth = get_date_from_gmt(gmdate('Y-m-d H:i:s', $expirationdatets), 'm'); $defaultday = get_date_from_gmt(gmdate('Y-m-d H:i:s', $expirationdatets), 'd'); $defaultyear = get_date_from_gmt(gmdate('Y-m-d H:i:s', $expirationdatets), 'Y'); $defaulthour = get_date_from_gmt(gmdate('Y-m-d H:i:s', $expirationdatets), 'H'); $defaultminute = get_date_from_gmt(gmdate('Y-m-d H:i:s', $expirationdatets), 'i'); $enabled = ' checked="checked"'; $disabled = ''; $opts = get_post_meta($post->ID, '_expiration-date-options', true); if (isset($opts['expireType'])) { $expireType = $opts['expireType']; } $categories = isset($opts['category']) ? $opts['category'] : false; } $rv = array(); $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"' . $enabled . ' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />'; $rv[] = '<label for="enable-expirationdate">' . __('Enable Post Expiration', 'post-expirator') . '</label></p>'; if ($default == 'publish') { $rv[] = '<em>' . __('The published date/time will be used as the expiration value', 'post-expirator') . '</em><br/>'; } else { $rv[] = '<table><tr>'; $rv[] = '<th style="text-align: left;">' . __('Year', 'post-expirator') . '</th>'; $rv[] = '<th style="text-align: left;">' . __('Month', 'post-expirator') . '</th>'; $rv[] = '<th style="text-align: left;">' . __('Day', 'post-expirator') . '</th>'; $rv[] = '</tr><tr>'; $rv[] = '<td>'; $rv[] = '<select name="expirationdate_year" id="expirationdate_year"' . $disabled . '>'; $currentyear = date('Y'); if ($defaultyear < $currentyear) { $currentyear = $defaultyear; } for ($i = $currentyear; $i < $currentyear + 8; $i++) { if ($i == $defaultyear) { $selected = ' selected="selected"'; } else { $selected = ''; } $rv[] = '<option' . $selected . '>' . $i . '</option>'; } $rv[] = '</select>'; $rv[] = '</td><td>'; $rv[] = '<select name="expirationdate_month" id="expirationdate_month"' . $disabled . '>'; for ($i = 1; $i <= 12; $i++) { if ($defaultmonth == date_i18n('m', mktime(0, 0, 0, $i, 1, date_i18n('Y')))) { $selected = ' selected="selected"'; } else { $selected = ''; } $rv[] = '<option value="' . date_i18n('m', mktime(0, 0, 0, $i, 1, date_i18n('Y'))) . '"' . $selected . '>' . date_i18n('F', mktime(0, 0, 0, $i, 1, date_i18n('Y'))) . '</option>'; } $rv[] = '</select>'; $rv[] = '</td><td>'; $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="' . $defaultday . '" size="2"' . $disabled . ' />,'; $rv[] = '</td></tr><tr>'; $rv[] = '<th style="text-align: left;"></th>'; $rv[] = '<th style="text-align: left;">' . __('Hour', 'post-expirator') . '(' . date_i18n('T', mktime(0, 0, 0, $i, 1, date_i18n('Y'))) . ')</th>'; $rv[] = '<th style="text-align: left;">' . __('Minute', 'post-expirator') . '</th>'; $rv[] = '</tr><tr>'; $rv[] = '<td>@</td><td>'; $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"' . $disabled . '>'; for ($i = 1; $i <= 24; $i++) { if ($defaulthour == date_i18n('H', mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y')))) { $selected = ' selected="selected"'; } else { $selected = ''; } $rv[] = '<option value="' . date_i18n('H', mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))) . '"' . $selected . '>' . date_i18n('H', mktime($i, 0, 0, date_i18n('n'), date_i18n('j'), date_i18n('Y'))) . '</option>'; } $rv[] = '</select></td><td>'; $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="' . $defaultminute . '" size="2"' . $disabled . ' />'; $rv[] = '</td></tr></table>'; } $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />'; echo implode("\n", $rv); echo '<br/>' . __('How to expire', 'post-expirator') . ': '; echo _postExpiratorExpireType(array('type' => $post->post_type, 'name' => 'expirationdate_expiretype', 'selected' => $expireType, 'disabled' => $disabled, 'onchange' => 'expirationdate_toggle_category(this)')); echo '<br/>'; if ($post->post_type != 'page') { if (isset($expireType) && ($expireType == 'category' || $expireType == 'category-add' || $expireType == 'category-remove')) { $catdisplay = 'block'; } else { $catdisplay = 'none'; } echo '<div id="expired-category-selection" style="display: ' . $catdisplay . '">'; echo '<br/>' . __('Expiration Categories', 'post-expirator') . ':<br/>'; echo '<div class="wp-tab-panel" id="post-expirator-cat-list">'; echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">'; $walker = new Walker_PostExpirator_Category_Checklist(); if (!empty($disabled)) { $walker->setDisabled(); } $taxonomies = get_object_taxonomies($post->post_type, 'object'); $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true)); if (sizeof($taxonomies) == 0) { echo '<p>' . __('You must assign a heirarchical taxonomy to this post type to use this feature.', 'post-expirator') . '</p>'; } elseif (sizeof($taxonomies) > 1 && !isset($defaults['taxonomy'])) { echo '<p>' . __('More than 1 heirachical taxonomy detected. You must assign a default taxonomy on the settings screen.', 'post-expirator') . '</p>'; } else { $keys = array_keys($taxonomies); $taxonomy = isset($defaults['taxonomy']) ? $defaults['taxonomy'] : $keys[0]; wp_terms_checklist(0, array('taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false)); echo '<input type="hidden" name="taxonomy-heirarchical" value="' . $taxonomy . '" />'; } echo '</ul>'; echo '</div>'; if (isset($taxonomy)) { echo '<p class="post-expirator-taxonomy-name">' . __('Taxonomy Name', 'post-expirator') . ': ' . $taxonomy . '</p>'; } echo '</div>'; } echo '<div id="expirationdate_ajax_result"></div>'; }
/** * Actually adds the meta box */ function expirationdate_meta_box($post) { // Get default month postExpiratorTimezoneSetup(); $expirationdatets = get_post_meta($post->ID, 'expiration-date', true); $default = ''; if (empty($expirationdatets)) { $default = get_option('expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT); if ($default == 'null') { $defaultmonth = date('F'); $defaultday = date('d'); $defaulthour = date('H'); $defaultyear = date('Y'); $defaultminute = date('i'); } elseif ($default == 'custom') { $custom = get_option('expirationdateDefaultDateCustom'); if ($custom === false) { $ts = time(); } else { $ts = strtotime($custom); } $defaultmonth = date('F', $ts); $defaultday = date('d', $ts); $defaulthour = date('H', $ts); $defaultyear = date('Y', $ts); $defaultminute = date('i', $ts); } $enabled = ''; $disabled = ' disabled="disabled"'; $categories = get_option('expirationdateCategoryDefaults'); } else { $defaultmonth = date('F', $expirationdatets); $defaultday = date('d', $expirationdatets); $defaultyear = date('Y', $expirationdatets); $defaulthour = date('H', $expirationdatets); $defaultminute = date('i', $expirationdatets); $enabled = ' checked="checked"'; $disabled = ''; $categories = get_post_meta($post->ID, '_expiration-date-category', true); } $rv = array(); $rv[] = '<p><input type="checkbox" name="enable-expirationdate" id="enable-expirationdate" value="checked"' . $enabled . ' onclick="expirationdate_ajax_add_meta(\'enable-expirationdate\')" />'; $rv[] = '<label for="enable-expirationdate">' . __('Enable Post Expiration', 'post-expirator') . '</label></p>'; if ($default == 'publish') { $rv[] = '<em>' . __('The published date/time will be used as the expiration value', 'post-expirator') . '</em><br/>'; } else { $rv[] = '<table><tr>'; $rv[] = '<th style="text-align: left;">' . __('Year', 'post-expirator') . '</th>'; $rv[] = '<th style="text-align: left;">' . __('Month', 'post-expirator') . '</th>'; $rv[] = '<th style="text-align: left;">' . __('Day', 'post-expirator') . '</th>'; $rv[] = '</tr><tr>'; $rv[] = '<td>'; $rv[] = '<select name="expirationdate_year" id="expirationdate_year"' . $disabled . '>'; $currentyear = date('Y'); if ($defaultyear < $currentyear) { $currentyear = $defaultyear; } for ($i = $currentyear; $i < $currentyear + 8; $i++) { if ($i == $defaultyear) { $selected = ' selected="selected"'; } else { $selected = ''; } $rv[] = '<option' . $selected . '>' . $i . '</option>'; } $rv[] = '</select>'; $rv[] = '</td><td>'; $rv[] = '<select name="expirationdate_month" id="expirationdate_month"' . $disabled . '>'; for ($i = 1; $i <= 12; $i++) { if ($defaultmonth == date('F', mktime(0, 0, 0, $i, 1, date("Y")))) { $selected = ' selected="selected"'; } else { $selected = ''; } $rv[] = '<option value="' . date('m', mktime(0, 0, 0, $i, 1, date("Y"))) . '"' . $selected . '>' . date_i18n('F', mktime(0, 0, 0, $i, 1, date("Y"))) . '</option>'; } $rv[] = '</select>'; $rv[] = '</td><td>'; $rv[] = '<input type="text" id="expirationdate_day" name="expirationdate_day" value="' . $defaultday . '" size="2"' . $disabled . ' />,'; $rv[] = '</td></tr><tr>'; $rv[] = '<th style="text-align: left;"></th>'; $rv[] = '<th style="text-align: left;">' . __('Hour', 'post-expirator') . '(' . date('T', mktime(0, 0, 0, $i, 1, date("Y"))) . ')</th>'; $rv[] = '<th style="text-align: left;">' . __('Minute', 'post-expirator') . '</th>'; $rv[] = '</tr><tr>'; $rv[] = '<td>@</td><td>'; $rv[] = '<select name="expirationdate_hour" id="expirationdate_hour"' . $disabled . '>'; for ($i = 1; $i <= 24; $i++) { if ($defaulthour == date('H', mktime($i, 0, 0, date("n"), date("j"), date("Y")))) { $selected = ' selected="selected"'; } else { $selected = ''; } $rv[] = '<option value="' . date('H', mktime($i, 0, 0, date("n"), date("j"), date("Y"))) . '"' . $selected . '>' . date_i18n('H', mktime($i, 0, 0, date("n"), date("j"), date("Y"))) . '</option>'; } $rv[] = '</select></td><td>'; $rv[] = '<input type="text" id="expirationdate_minute" name="expirationdate_minute" value="' . $defaultminute . '" size="2"' . $disabled . ' />'; $rv[] = '</td></tr></table>'; } $rv[] = '<input type="hidden" name="expirationdate_formcheck" value="true" />'; echo implode("\n", $rv); $catEnabled = get_option('expirationdateCategory'); if ($post->post_type != 'page' && ($catEnabled === false || $catEnabled == 1)) { $args = array('hide_empty' => 0, 'orderby' => 'name', 'hierarchical' => 0); echo '<br/>' . __('Expiration Categories', 'post-expirator') . ':<br/>'; echo '<div class="wp-tab-panel" id="post-expirator-cat-list">'; echo '<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">'; $walker = new Walker_PostExpirator_Category_Checklist(); if (!empty($disabled)) { $walker->setDisabled(); } wp_terms_checklist(0, array('taxonomy' => 'category', 'walker' => $walker, 'selected_cats' => $categories, 'checked_ontop' => false)); echo '</ul>'; echo '</div>'; echo '<p class="howto">' . __('Setting an expiration category will change the category at expiration time, and override the default post action', 'post-expirator') . '.</p>'; } echo '<div id="expirationdate_ajax_result"></div>'; }