Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Add The Slide options box to the post CRUD page
- *
- * @author Eric Lubow <elubow@simplereach.com>
- * @param None
- * @return None
- */
- function srslide_post_meta_box()
- {
- if (function_exists('add_meta_box')) {
- add_meta_box('srslide',__('The Slide', 'srslide'), 'srslide_meta','post');
- add_meta_box('srslide',__('The Slide', 'srslide'), 'srslide_meta','page');
- }
- }
- /**
- * The code for The Slide options box on the post CRUD page
- *
- * @author Eric Lubow <elubow@simplereach.com>
- * @param None
- * @return None
- */
- function srslide_meta()
- {
- global $post;
- $post_id = $post;
- if (is_object($post_id)) {
- $post_id = $post_id->ID;
- }
- wp_register_style('srslide.css', SRSLIDE_PLUGIN_URL . 'srslide.css');
- wp_enqueue_style('srslide.css');
- wp_nonce_field( plugin_basename(__FILE__), 'srslide_noncename' );
- $title = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_srslide_title', true)));
- $article_icon = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_srslide_article_icon', true)));
- $tags = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_srslide_tags', true)));
- $disable_slide_on_post = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_srslide_disable_on_post', true)));
- if ($post_end_date = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_srslide_post_end_date', true)))) {
- $end_date_pattern = '/(\d+)\-(\d+)\-(\d+)\s+(\d+):(\d+):(\d+)/';
- if (preg_match($end_date_pattern,$post_end_date,$matches)) {
- $post_end_year = $matches[1];
- $post_end_month = $matches[2];
- $post_end_day = $matches[3];
- $post_end_hour = $matches[4];
- $post_end_minute = $matches[5];
- $post_end_meridian = 1;
- if ($post_end_hour > 12) {
- $post_end_hour -= 12;
- $post_end_meridian = 2;
- }
- }
- }
- ?>
- <div id="srslide_meta_box">
- <input value='srslide_edit' type='hidden' name='srslide_edit' />
- <table>
- <tr>
- <th><?php print __('Title:', 'srslide') ?></th>
- <td><input value="<?php echo $title ?>" type="text" name="srslide_title" size="60" /></td>
- </tr>
- <tr>
- <th scope="row"><?php print __('Article Icon URL:', 'srslide') ?></th>
- <td><input value="<?php echo $article_icon ?>" type="text" name="srslide_article_icon" size="60" /></td>
- </tr>
- <tr>
- <th scope="row"><?php print __('Tags:', 'srslide') ?></th>
- <td><input value="<?php echo $tags ?>" type="text" name="srslide_tags" size="60" /></td>
- </tr>
- <tr>
- <th scope="row"><?php print __('End Date:', 'srslide') ?></th>
- <td>
- <select name="srslide_post_end_month" id="srslide_post_end_month" value="">
- <?php
- $month_list = array('0' => '-----', '01' => 'January', '02' => 'February',
- '03' => 'March', '04' => 'April', '05' => 'May',
- '06' => 'June', '07' => 'July', '08' => 'August',
- '09' => 'September', '10' => 'October', '11' => 'November',
- '12' => 'December');
- foreach ($month_list as $k=>$v) {
- echo "\t\t\t\t".'<option value="'.$k.'"';
- if ($k == $post_end_month) {
- echo ' selected >';
- }
- else {
- echo '>';
- }
- echo $v.'</option>'."\n";
- }
- ?>
- </select>
- <select name="srslide_post_end_day" id="srslide_post_end_day" value="">
- <option value='0'>------</option>
- <?php
- for ($i=1; $i <= 31; $i++) {
- $j = sprintf("%02d",$i);
- echo "\t\t\t\t".'<option value="'.$j.'"';
- if ($i == $post_end_day) {
- echo ' selected';
- }
- echo '>'.$j.'</option>'."\n";
- }
- ?>
- </select>
- <select name="srslide_post_end_year" id="srslide_post_end_year" value="">
- <?php
- $year = (int) date("Y");
- $maxyear = $year + 5;
- for ($i = $year;$i < $maxyear;$i++) {
- echo "\t\t\t\t".'<option value="'.$i.'"';
- if ($i == $post_end_year) {
- echo ' selected';
- }
- echo '>'.$i.'</option>'."\n";
- }
- ?>
- </select>
- <select name="srslide_post_end_hour" id="srslide_post_end_hour" value="">
- <?php
- for ($i = 1;$i < 13;$i++) {
- echo "\t\t\t\t".'<option value="'.$i.'"';
- if ($i == $post_end_hour) {
- echo ' selected';
- }
- echo '>'.$i.'</option>'."\n";
- }
- ?>
- </select>
- <select name="srslide_post_end_minute" id="srslide_post_end_minute" value="">
- <?php
- for ($i = 0;$i < 60;$i++) {
- $j = sprintf("%02d",$i);
- echo "\t\t\t\t".'<option value="'.$j.'"';
- if ($i == $post_end_minute) {
- echo ' selected';
- }
- echo '>'.$j.'</option>'."\n";
- }
- ?>
- </select>
- <input type="radio" name="srslide_post_end_meridian" value="1" <?php echo ($post_end_meridian != 2) ? 'Checked' : ''; ?>> AM
- <input type="radio" name="srslide_post_end_meridian" value="2" <?php echo ($post_end_meridian == 2) ? 'Checked' : ''; ?>> PM
- </td>
- </tr>
- <tr>
- <th scope="row"><?php print __('Disable Slide on post:', 'srslide') ?></th>
- <td><input name="srslide_disable_on_post" id="srslide_disable_on_post" type="checkbox" <?php if ($disable_slide_on_post) echo 'checked="1"'; ?> /></td>
- </tr>
- </table>
- </div>
- <?php
- }
- /**
- * Save the post meta data for The Slide
- *
- * @author Eric Lubow <elubow@simplereach.com>
- * @param Integer Post ID
- * @return None
- */
- function srslide_post_save_data($post_id)
- {
- // Ignore if auto-saving
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $post_id;
- }
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- $srslide_noncename = (!empty($_POST['srslide_noncename'])) ? $_POST['srslide_noncename'] : '';
- if (!wp_verify_nonce($srslide_noncename, plugin_basename(__FILE__))) {
- return $post_id;
- }
- // Check permissions
- $post_type = (!empty($_POST['post_type'])) ? $_POST['post_type'] : '';
- if ('page' == $post_type) {
- if (!current_user_can( 'edit_page', $post_id ))
- return $post_id;
- } else {
- if (!current_user_can( 'edit_post', $post_id ))
- return $post_id;
- }
- // OK, we're auth'd, time to make the donuts
- global $post;
- $id = $post;
- if (is_object($id)) {
- $id = $post->ID;
- }
- $disable_slide_on_post = (!empty($_POST['srslide_disable_on_post'])) ? $_POST['srslide_disable_on_post'] : '';
- $title = (!empty($_POST['srslide_title'])) ? $_POST['srslide_title'] : '';
- $tags = (!empty($_POST['srslide_tags'])) ? $_POST['srslide_tags'] : '';
- $icon = (!empty($_POST['srslide_article_icon'])) ? $_POST['srslide_article_icon'] : '';
- $post_end_month = (!empty($_POST['srslide_post_end_month'])) ? $_POST['srslide_post_end_month'] : '';
- $post_end_day = (!empty($_POST['srslide_post_end_day'])) ? $_POST['srslide_post_end_day'] : '';
- $post_end_year = (!empty($_POST['srslide_post_end_year'])) ? $_POST['srslide_post_end_year'] : '';
- $post_end_hour = (!empty($_POST['srslide_post_end_hour'])) ? $_POST['srslide_post_end_hour'] : '';
- $post_end_minute = (!empty($_POST['srslide_post_end_minute'])) ? $_POST['srslide_post_end_minute'] : '';
- $post_end_meridian = (!empty($_POST['srslide_post_end_meridian'])) ? $_POST['srslide_post_end_meridian'] : '';
- // Clear everything out first to start with a clean slate
- delete_post_meta($id, '_srslide_title');
- delete_post_meta($id, '_srslide_tags');
- delete_post_meta($id, '_srslide_article_icon');
- delete_post_meta($id, '_srslide_disable_on_post');
- delete_post_meta($id, '_srslide_post_end_date');
- // Ignore if the slide should be hidden
- add_post_meta($id, '_srslide_disable_on_post', !empty($disable_slide_on_post));
- // if(isset($disable_slide_on_post) && !empty($disable_slide_on_post)) {
- // add_post_meta($id, '_srslide_disable_on_post', true);
- // // We don't just return here because we want to save the data anyway
- // // SimpleReach will index this post even though The Slide is disabled
- // } else {
- // // Add this anyway to ensure we show the slide
- // add_post_meta($id, '_srslide_disable_on_post', false);
- // }
- // Set to post title if the field is empty
- if (empty($title) && ($post->post_status == 'publish')) {
- if (!empty($_POST['post_title'])) {
- add_post_meta($id, '_srslide_title', $_POST['post_title']);
- }
- } else {
- add_post_meta($id, '_srslide_title', $title);
- }
- // Set to post tags if the field is empty
- if (empty($tags) && ($post->post_status == 'publish')) {
- $tagset = array();
- foreach (wp_get_post_tags($id) as $tag) {
- $tagset[] = $tag->name;
- }
- add_post_meta($id, '_srslide_tags', join(",", $tagset));
- } else {
- add_post_meta($id, '_srslide_tags', $tags);
- }
- if (empty($icon) && ($post->post_status == 'publish')) {
- $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
- if ($thumbnail_id) {
- list($img, $h, $w) = wp_get_attachment_image_src($thumbnail_id);
- add_post_meta($id, '_srslide_article_icon', $img);
- }
- } else {
- add_post_meta($id, '_srslide_article_icon', $icon);
- }
- if (($post_end_month > 0) && ($post_end_day > 0)) {
- if (checkdate($post_end_month,$post_end_day,$post_end_year)) {
- if ($post_end_meridian == 2) {
- $post_end_hour += 12;
- }
- $post_end_date = sprintf("%04d-%02d-%02d %02d:%02d:00",$post_end_year,$post_end_month,$post_end_day,$post_end_hour,$post_end_minute);
- add_post_meta($id,'_srslide_post_end_date',$post_end_date);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement