Changeset 188938
- Timestamp:
- 01/02/2010 01:02:34 PM (16 years ago)
- Location:
- revision-history/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
revision_history.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
revision-history/trunk/readme.txt
r182897 r188938 4 4 Tags: revision 5 5 Requires at least: 2.8.6 6 Tested up to: 2. 8.67 Stable tag: 0.9 6 Tested up to: 2.9 7 Stable tag: 0.9.1 8 8 9 9 Revision History displays the revision history of a post or page, with links … … 27 27 By default the revision history is not shown on any posts or pages. 28 28 29 For control over where you place the revision history use the `rh_the_revision` function. 30 It takes optional parameters, before and after. For example: 31 32 `<?php rh_the_revision('<h4>', '</h4>'); ?>` 33 29 34 == Installation == 30 35 … … 40 45 == Changelog == 41 46 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 42 53 = 0.9 = 43 54 * First version. -
revision-history/trunk/revision_history.php
r182905 r188938 34 34 35 35 function 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 65 function rh_get_the_revision_post() { 36 66 if (valid_revision_id()) { 37 67 $revision = $_GET['revision']; 38 68 $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 75 function 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 89 function rh_the_revision($before = '', $after = '') { 90 echo $before . rh_revision_str() . $after; 55 91 } 56 92 … … 65 101 $post = get_post($post->post_parent); 66 102 } 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'; 69 105 $page_val = get_option( $page_name ); 70 106 $post_val = get_option( $post_name ); … … 86 122 function list_post_revisions( $post ) { 87 123 if ( $revisions = wp_get_post_revisions( $post->ID ) ) { 88 $autosave_name = ' show_autosaves';124 $autosave_name = 'rh_show_autosaves'; 89 125 $show_autosaves = get_option( $autosave_name ); 90 126 $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); 93 128 $current_revision_author = get_author_name($post->post_author); 94 129 $current_revision_url = get_permalink($post); … … 103 138 continue; 104 139 } 105 $date = wp_post_revision_title( $revision, 0);140 $rev_date = rh_revision_str($revision); 106 141 $name = get_author_name( $revision->post_author ); 107 142 $query_string = get_query_string($revision); 108 143 $items .= "<li>"; 109 144 if ($revision_id == $revision->ID) { 110 $items .= "$ date by $name (<em>displayed above</em>)";145 $items .= "$rev_date by $name (<em>displayed above</em>)"; 111 146 } 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]"; 113 151 } 114 152 $items .= "</li>"; … … 132 170 } 133 171 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'); 172 add_option('rh_show_page_revisions', '0'); 173 add_option('rh_show_post_revisions', '0'); 174 add_option('rh_show_autosaves', '0'); 175 add_option('rh_adjust_title', '0'); 176 add_option('rh_title_class', 'rh-title'); 138 177 139 178 // Hook for adding admin menus … … 148 187 function add_revision_history_options_page() { 149 188 // 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'; 154 194 $hidden_field_name = 'submit_hidden'; 155 195 … … 159 199 $autosaves_val = get_option( $autosaves_name ); 160 200 $adjust_title_val = get_option( $adjust_title_name ); 201 $title_class_val = get_option( $title_class_name ); 161 202 162 203 // See if the user has posted us some information … … 168 209 $new_autosaves_val = ($_POST[ $autosaves_name ] == "on") ? "1" : "0"; 169 210 $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 170 213 // save the new values 171 214 if ( $new_page_val != $page_val ) { … … 184 227 update_option( $adjust_title_name, $new_adjust_title_val ); 185 228 $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; 186 233 } 187 234 // Feedback that we've updated the options … … 192 239 ?> 193 240 <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>"; ?> 195 242 196 243 <form name="show_revision_history" method="post" action=""> 197 244 <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"> 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> 218 299 <p class="submit"> 219 300 <input type="submit" name="Submit" value="<?php _e('Update Options', 'mt_trans_domain' ) ?>" />
Note: See TracChangeset
for help on using the changeset viewer.