Plugin Directory

Changeset 188938


Ignore:
Timestamp:
01/02/2010 01:02:34 PM (16 years ago)
Author:
jkeyes
Message:

0.9.1 release

Location:
revision-history/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • revision-history/trunk/readme.txt

    r182897 r188938  
    44Tags: revision
    55Requires at least: 2.8.6
    6 Tested up to: 2.8.6
    7 Stable tag: 0.9
     6Tested up to: 2.9
     7Stable tag: 0.9.1
    88
    99Revision History displays the revision history of a post or page, with links
     
    2727By default the revision history is not shown on any posts or pages.
    2828
     29For control over where you place the revision history use the `rh_the_revision` function.
     30It takes optional parameters, before and after.  For example:
     31
     32`<?php rh_the_revision('<h4>', '</h4>'); ?>`
     33
    2934== Installation ==
    3035
     
    4045== Changelog ==
    4146
     47= 0.9.1 =
     48  * Layout uses same markup as standard settings pages.
     49  * Now use the blog date and time format as specified in General Settings.
     50  * Allow a CSS class to be set for the revision string in the post title.
     51  * Added `rh_the_revision` function.
     52
    4253= 0.9 =
    4354  * First version.
  • revision-history/trunk/revision_history.php

    r182905 r188938  
    3434
    3535function check_for_revision($wp) {
     36    $adjust_title = get_option( 'rh_adjust_title' );
     37   
     38    if ( $adjust_title ) {
     39        $title_class = get_option( 'rh_title_class' );
     40        $rev_date = rh_revision_str();
     41
     42        if (valid_revision_id()) {
     43            $revision = $_GET['revision'];
     44            $post = get_post($revision);
     45            if ($post != null) {
     46                # reset posts so the revision is displayed instead of the original
     47                global $posts;
     48                $posts = array($post);
     49            }
     50        }
     51        else {
     52            $post = get_post(get_the_ID());
     53        }
     54
     55        if ($title_class) {
     56            $post->post_title .= "<span class=\"$title_class\">";
     57        }
     58        $post->post_title .= " (Revision: " . $rev_date . ")";
     59        if ($title_class) {
     60            $post->post_title .= "</span>";
     61        }
     62    }
     63}
     64
     65function rh_get_the_revision_post() {
    3666    if (valid_revision_id()) {
    3767        $revision = $_GET['revision'];
    3868        $post = get_post($revision);
    39         if ($post != null) {
    40             # reset posts so the revision is displayed instead of the original
    41             $adjust_title = get_option( 'adjust_title' );
    42             if ( $adjust_title ) {
    43                 $datef = _x( 'j F, Y @ G:i', 'revision date format');
    44                 $rev_date = date_i18n( $datef, strtotime( $post->post_modified_gmt . ' +0000' ) );
    45                 $is_autosave = wp_is_post_autosave($post);
    46                 $post->post_title .= " (Revision: $rev_date)";
    47                 if ( $is_autosave ) {
    48                     $post->post_title .= " [autosave]";
    49                 }
    50             }
    51             global $posts;
    52             $posts = array($post);
    53         }
    54     }
     69    } else {
     70        $post = get_post(get_the_ID());
     71    }
     72    return $post;   
     73}
     74
     75function rh_revision_str($post = null) {
     76    if ($post == null) {
     77        if (valid_revision_id()) {
     78            $post = rh_get_the_revision_post($revision);
     79        }
     80    }
     81    if ($post != null) {
     82        $modified = strtotime($post->post_modified_gmt . ' +0000');
     83        return sprintf('%s at %s', date(get_option('date_format'), $modified), date(get_option('time_format'), $modified));   
     84    } else {
     85        return "Latest";
     86    }
     87}
     88
     89function rh_the_revision($before = '', $after = '') {
     90    echo $before . rh_revision_str() . $after;
    5591}
    5692
     
    65101        $post = get_post($post->post_parent);
    66102    }
    67     $page_name = 'show_page_revisions';
    68     $post_name = 'show_post_revisions';
     103    $page_name = 'rh_show_page_revisions';
     104    $post_name = 'rh_show_post_revisions';
    69105    $page_val = get_option( $page_name );
    70106    $post_val = get_option( $post_name );
     
    86122function list_post_revisions( $post ) {
    87123    if ( $revisions = wp_get_post_revisions( $post->ID ) ) {
    88         $autosave_name = 'show_autosaves';
     124        $autosave_name = 'rh_show_autosaves';
    89125        $show_autosaves = get_option( $autosave_name );
    90126        $revision_id = (valid_revision_id()) ? $revision_id = $_GET['revision'] : $post->ID;
    91         $datef = _x( 'j F, Y @ G:i', 'revision date format');
    92         $current_revision_date = date_i18n( $datef, strtotime( $post->post_modified_gmt . ' +0000' ) );
     127        $current_revision_date = rh_revision_str($post);
    93128        $current_revision_author = get_author_name($post->post_author);
    94129        $current_revision_url = get_permalink($post);
     
    103138                continue;
    104139            }
    105             $date = wp_post_revision_title( $revision, 0 );
     140            $rev_date = rh_revision_str($revision);
    106141            $name = get_author_name( $revision->post_author );
    107142            $query_string = get_query_string($revision);
    108143            $items .= "<li>";
    109144            if ($revision_id == $revision->ID) {
    110                 $items .= "$date by $name (<em>displayed above</em>)";
     145                $items .= "$rev_date by $name (<em>displayed above</em>)";
    111146            } else {
    112                 $items .= "<a href=\"$query_string\">$date</a> by $name";
     147                $items .= "<a href=\"$query_string\">$rev_date</a> by $name";
     148            }
     149            if ($is_autosave) {
     150                $items .= " [autosave]";
    113151            }
    114152            $items .= "</li>";
     
    132170}
    133171
    134 add_option('show_page_revisions', '0');
    135 add_option('show_post_revisions', '0');
    136 add_option('show_autosaves', '0');
    137 add_option('adjust_title', '0');
     172add_option('rh_show_page_revisions', '0');
     173add_option('rh_show_post_revisions', '0');
     174add_option('rh_show_autosaves', '0');
     175add_option('rh_adjust_title', '0');
     176add_option('rh_title_class', 'rh-title');
    138177
    139178// Hook for adding admin menus
     
    148187function add_revision_history_options_page() {
    149188    // variables for the field and option names
    150     $page_name = 'show_page_revisions';
    151     $post_name = 'show_post_revisions';
    152     $autosaves_name = 'show_autosaves';
    153     $adjust_title_name = 'adjust_title';
     189    $page_name = 'rh_show_page_revisions';
     190    $post_name = 'rh_show_post_revisions';
     191    $autosaves_name = 'rh_show_autosaves';
     192    $adjust_title_name = 'rh_adjust_title';
     193    $title_class_name = 'rh_title_class';
    154194    $hidden_field_name = 'submit_hidden';
    155195
     
    159199    $autosaves_val = get_option( $autosaves_name );
    160200    $adjust_title_val = get_option( $adjust_title_name );
     201    $title_class_val = get_option( $title_class_name );
    161202
    162203    // See if the user has posted us some information
     
    168209        $new_autosaves_val = ($_POST[ $autosaves_name ] == "on") ? "1" : "0";
    169210        $new_adjust_title_val = ($_POST[ $adjust_title_name ] == "on") ? "1" : "0";
     211        $new_title_class_val = ($_POST[ $title_class_name ] == "") ? "" : $_POST[ $title_class_name ];
     212
    170213        // save the new values
    171214        if ( $new_page_val != $page_val ) {
     
    184227            update_option( $adjust_title_name, $new_adjust_title_val );
    185228            $adjust_title_val = $new_adjust_title_val;
     229        }
     230        if ( $new_title_class_val != $title_class_val ) {
     231            update_option( $title_class_name, $new_title_class_val );
     232            $title_class_val = $new_title_class_val;
    186233        }
    187234        // Feedback that we've updated the options
     
    192239?>
    193240<div class="wrap">
    194     <?php echo "<h2>" . __( 'Revision History Options', 'mt_trans_domain' ) . "</h2>"; ?>
     241    <?php echo "<h2>" . __( 'Revision History Settings', 'mt_trans_domain' ) . "</h2>"; ?>
    195242
    196243    <form name="show_revision_history" method="post" action="">
    197244        <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
    198         <p>
    199             <input id="show_on_pages" type="checkbox" name="<?php echo $page_name; ?>"
    200                 <?php checked('1', $page_val); ?> />
    201             <label for="show_on_pages"><?php _e("Show revision history on pages.", 'mt_trans_domain' ); ?></label>
    202         </p>
    203         <p>
    204             <input id="show_on_posts" type="checkbox" name="<?php echo $post_name; ?>"
    205                 <?php checked('1', $post_val); ?> />
    206             <label for="show_on_posts"><?php _e("Show revision history on posts.", 'mt_trans_domain' ); ?></label>
    207         </p>
    208         <p>
    209             <input id="show_autosaves" type="checkbox" name="<?php echo $autosaves_name; ?>"
    210                 <?php checked('1', $autosaves_val); ?> />
    211             <label for="show_autosaves"><?php _e("Show autosaves.", 'mt_trans_domain' ); ?></label>
    212         </p>
    213         <p>
    214             <input id="adjust_title" type="checkbox" name="<?php echo $adjust_title_name; ?>"
    215                 <?php checked('1', $adjust_title_val); ?> />
    216             <label for="adjust_title"><?php _e("Show revision date in post title of revisions.", 'mt_trans_domain' ); ?></label>
    217         </p>
     245        <table class="form-table">
     246            <tbody>
     247                <tr valign="top">
     248                    <th scope="row">
     249                        <span>Page revisions</span>
     250                    </th>
     251                    <td>
     252                        <input id="rh_show_on_pages" type="checkbox" name="<?php echo $page_name; ?>"
     253                        <?php checked('1', $page_val); ?> />
     254                        <label for="rh_show_on_pages"><?php _e("Show revision history on pages.", 'mt_trans_domain' ); ?></label>
     255                    </td>
     256                </tr>
     257                <tr valign="top">
     258                    <th scope="row">
     259                        <span>Post revisions</span>
     260                    </th>
     261                    <td>
     262                        <input id="rh_show_on_posts" type="checkbox" name="<?php echo $post_name; ?>"
     263                            <?php checked('1', $post_val); ?> />
     264                        <label for="rh_show_on_posts"><?php _e("Show revision history on posts.", 'mt_trans_domain' ); ?></label>
     265                    </td>
     266                </tr>
     267                <tr valign="top">
     268                    <th scope="row">
     269                        <span>Autosave revisions</span>
     270                    </th>
     271                    <td>
     272                        <input id="rh_show_autosaves" type="checkbox" name="<?php echo $autosaves_name; ?>"
     273                            <?php checked('1', $autosaves_val); ?> />
     274                        <label for="rh_show_autosaves"><?php _e("Show autosaves.", 'mt_trans_domain' ); ?></label>
     275                    </td>
     276                </tr>
     277                <tr valign="top">
     278                    <th scope="row">
     279                        <span>Modify post title</span>
     280                    </th>
     281                    <td>
     282                        <input id="rh_adjust_title" type="checkbox" name="<?php echo $adjust_title_name; ?>"
     283                            <?php checked('1', $adjust_title_val); ?> />
     284                        <label for="rh_adjust_title"><?php _e("Show revision date in post title of revisions.", 'mt_trans_domain' ); ?></label>
     285                        <span class="description">&nbsp;If you need more control use <code>rh_the_revision</code> in your theme.</span>
     286                    </td>
     287                </tr>
     288                <tr valign="top">
     289                    <th scope="row">
     290                        <label for="rh_title_class"><?php _e("Title Class", 'mt_trans_domain' ); ?></label>
     291                    </th>
     292                    <td>
     293                        <input id="rh_title_class" type="text" name="<?php echo $title_class_name; ?>" value="<?php echo $title_class_val; ?>" class="regular-text code"/>
     294                        <span class="description">A child span is added to the post header, with the specified class.</span>
     295                    </td>
     296                </tr>
     297            </tbody>
     298        </table>
    218299        <p class="submit">
    219300            <input type="submit" name="Submit" value="<?php _e('Update Options', 'mt_trans_domain' ) ?>" />
Note: See TracChangeset for help on using the changeset viewer.