]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/template.php
Wordpress 2.3.2
[autoinstalls/wordpress.git] / wp-admin / includes / template.php
1 <?php
2
3 //
4 // Big Mess
5 //
6
7 // Dandy new recursive multiple category stuff.
8 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
9         if ( !$categories )
10                 $categories = get_categories( 'hide_empty=0' );
11
12         $children = _get_term_hierarchy('category');
13
14         if ( $categories ) {
15                 ob_start();
16                 foreach ( $categories as $category ) {
17                         if ( $category->parent == $parent) {
18                                 echo "\t" . _cat_row( $category, $level );
19                                 if ( isset($children[$category->term_id]) )
20                                         cat_rows( $category->term_id, $level +1, $categories );
21                         }
22                 }
23                 $output = ob_get_contents();
24                 ob_end_clean();
25
26                 $output = apply_filters('cat_rows', $output);
27
28                 echo $output;
29         } else {
30                 return false;
31         }
32 }
33
34 function _cat_row( $category, $level, $name_override = false ) {
35         global $class;
36
37         $pad = str_repeat( '&#8212; ', $level );
38         if ( current_user_can( 'manage_categories' ) ) {
39                 $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
40                 $default_cat_id = (int) get_option( 'default_category' );
41                 $default_link_cat_id = (int) get_option( 'default_link_category' );
42
43                 if ( $category->term_id != $default_cat_id )
44                         $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&amp;cat_ID=$category->term_id", 'delete-category_' . $category->term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>";
45                 else
46                         $edit .= "<td style='text-align:center'>".__( "Default" );
47         } else
48                 $edit = '';
49
50         $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
51
52         $category->count = number_format_i18n( $category->count );
53         $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
54         $output = "<tr id='cat-$category->term_id'$class>
55                 <th scope='row' style='text-align: center'>$category->term_id</th>
56                 <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
57                 <td>$category->description</td>
58                 <td align='center'>$posts_count</td>
59                 <td>$edit</td>\n\t</tr>\n";
60
61         return apply_filters('cat_row', $output);
62 }
63
64 function checked( $checked, $current) {
65         if ( $checked == $current)
66                 echo ' checked="checked"';
67 }
68
69 // TODO: Remove?
70 function documentation_link( $for ) {
71         return;
72 }
73
74 function selected( $selected, $current) {
75         if ( $selected == $current)
76                 echo ' selected="selected"';
77 }
78
79 //
80 // Nasty Category Stuff
81 //
82
83 function sort_cats( $cat1, $cat2 ) {
84         if ( $cat1['checked'] || $cat2['checked'] )
85                 return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1;
86         else
87                 return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] );
88 }
89
90 function get_nested_categories( $default = 0, $parent = 0 ) {
91         global $post_ID, $mode, $wpdb, $checked_categories;
92
93         if ( empty($checked_categories) ) {
94                 if ( $post_ID ) {
95                         $checked_categories = wp_get_post_categories($post_ID);
96
97                         if ( count( $checked_categories ) == 0 ) {
98                                 // No selected categories, strange
99                         $checked_categories[] = $default;
100                         }
101                 } else {
102                         $checked_categories[] = $default;
103                 }
104         }
105
106         $cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
107
108         $result = array ();
109         if ( is_array( $cats ) ) {
110                 foreach ( $cats as $cat) {
111                         $result[$cat]['children'] = get_nested_categories( $default, $cat);
112                         $result[$cat]['cat_ID'] = $cat;
113                         $result[$cat]['checked'] = in_array( $cat, $checked_categories );
114                         $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
115                 }
116         }
117
118         $result = apply_filters('get_nested_categories', $result);
119         usort( $result, 'sort_cats' );
120
121         return $result;
122 }
123
124 function write_nested_categories( $categories ) {
125         foreach ( $categories as $category ) {
126                 echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label></li>";
127
128                 if ( $category['children'] ) {
129                         echo "<ul>\n";
130                         write_nested_categories( $category['children'] );
131                         echo "</ul>\n";
132                 }
133         }
134 }
135
136 function dropdown_categories( $default = 0 ) {
137         write_nested_categories( get_nested_categories( $default) );
138 }
139
140 function dropdown_link_categories( $default = 0 ) {
141         global $link_id;
142
143         if ( $link_id ) {
144                 $checked_categories = wp_get_link_cats($link_id);
145
146                 if ( count( $checked_categories ) == 0 ) {
147                         // No selected categories, strange
148                         $checked_categories[] = $default;
149                 }
150         } else {
151                 $checked_categories[] = $default;
152         }
153
154         $categories = get_terms('link_category', 'orderby=count&hide_empty=0');
155
156         if ( empty($categories) )
157                 return;
158
159         foreach ( $categories as $category ) {
160                 $cat_id = $category->term_id;
161                 $name = wp_specialchars( apply_filters('the_category', $category->name));
162                 $checked = in_array( $cat_id, $checked_categories );
163                 echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
164         }
165 }
166
167 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) {
168         global $wpdb, $class, $post;
169
170         if (!$pages )
171                 $pages = get_pages( 'sort_column=menu_order' );
172
173         if (! $pages )
174                 return false;
175
176         foreach ( $pages as $post) {
177                 setup_postdata( $post);
178                 if ( $hierarchy && ($post->post_parent != $parent) )
179                         continue;
180
181                 $post->post_title = wp_specialchars( $post->post_title );
182                 $pad = str_repeat( '&#8212; ', $level );
183                 $id = (int) $post->ID;
184                 $class = ('alternate' == $class ) ? '' : 'alternate';
185 ?>
186   <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
187     <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th>
188     <td>
189       <?php echo $pad; ?><?php the_title() ?>
190     </td>
191     <td><?php the_author() ?></td>
192     <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td>
193         <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e( 'View' ); ?></a></td>
194     <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
195     <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
196   </tr>
197
198 <?php
199                 if ( $hierarchy ) page_rows( $id, $level + 1, $pages );
200         }
201 }
202
203 function user_row( $user_object, $style = '' ) {
204         if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
205                 $user_object = new WP_User( (int) $user_object );
206         $email = $user_object->user_email;
207         $url = $user_object->user_url;
208         $short_url = str_replace( 'http://', '', $url );
209         $short_url = str_replace( 'www.', '', $short_url );
210         if ('/' == substr( $short_url, -1 ))
211                 $short_url = substr( $short_url, 0, -1 );
212         if ( strlen( $short_url ) > 35 )
213                 $short_url =  substr( $short_url, 0, 32 ).'...';
214         $numposts = get_usernumposts( $user_object->ID );
215         $r = "<tr id='user-$user_object->ID'$style>
216                 <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
217                 <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
218                 <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
219                 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
220                 <td><a href='$url' title='website: $url'>$short_url</a></td>";
221         $r .= "\n\t\t<td align='center'>";
222         if ( $numposts > 0 ) {
223                 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
224                 $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts);
225                 $r .= '</a>';
226         }
227         $r .= "</td>\n\t\t<td>";
228         if ( current_user_can( 'edit_user', $user_object->ID ) ) {
229                 $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" );
230                 $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>";
231         }
232         $r .= "</td>\n\t</tr>";
233         return $r;
234 }
235
236 function _wp_get_comment_list( $s = false, $start, $num ) {
237         global $wpdb;
238
239         $start = abs( (int) $start );
240         $num = (int) $num;
241
242         if ( $s ) {
243                 $s = $wpdb->escape($s);
244                 $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
245                         (comment_author LIKE '%$s%' OR
246                         comment_author_email LIKE '%$s%' OR
247                         comment_author_url LIKE ('%$s%') OR
248                         comment_author_IP LIKE ('%$s%') OR
249                         comment_content LIKE ('%$s%') ) AND
250                         comment_approved != 'spam'
251                         ORDER BY comment_date DESC LIMIT $start, $num");
252         } else {
253                 $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" );
254         }
255
256         update_comment_cache($comments);
257
258         $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
259
260         return array($comments, $total);
261 }
262
263 function _wp_comment_list_item( $id, $alt = 0 ) {
264         global $authordata, $comment, $wpdb;
265         $id = (int) $id;
266         $comment =& get_comment( $id );
267         $class = '';
268         $post = get_post($comment->comment_post_ID);
269         $authordata = get_userdata($post->post_author);
270         $comment_status = wp_get_comment_status($comment->comment_ID);
271         if ( 'unapproved' == $comment_status )
272                 $class .= ' unapproved';
273         if ( $alt % 2 )
274                 $class .= ' alternate';
275         echo "<li id='comment-$comment->comment_ID' class='$class'>";
276 ?>
277 <p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
278
279 <?php comment_text() ?>
280
281 <p><?php comment_date(__('M j, g:i A'));  ?> &#8212; [
282 <?php
283 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
284         echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" .  __('Edit') . '</a>';
285         echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
286         if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
287                 echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
288                 echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
289         }
290         echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author))  . "', theCommentList );\">" . __('Spam') . "</a> ";
291 }
292 $post = get_post($comment->comment_post_ID, OBJECT, 'display');
293 $post_title = wp_specialchars( $post->post_title, 'double' );
294 $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
295 ?>
296  ] &#8212; <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
297                 </li>
298 <?php
299 }
300
301 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
302         global $wpdb;
303         if (!$categories )
304                 $categories = get_categories( 'hide_empty=0' );
305
306         if ( $categories ) {
307                 foreach ( $categories as $category ) {
308                         if ( $currentcat != $category->term_id && $parent == $category->parent) {
309                                 $pad = str_repeat( '&#8211; ', $level );
310                                 $category->name = wp_specialchars( $category->name );
311                                 echo "\n\t<option value='$category->term_id'";
312                                 if ( $currentparent == $category->term_id )
313                                         echo " selected='selected'";
314                                 echo ">$pad$category->name</option>";
315                                 wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
316                         }
317                 }
318         } else {
319                 return false;
320         }
321 }
322
323 function list_meta( $meta ) {
324         global $post_ID;
325         // Exit if no meta
326         if (!$meta ) {
327                 echo '<tbody id="the-list"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS
328                 return;
329         }
330         $count = 0;
331 ?>
332         <thead>
333         <tr>
334                 <th><?php _e( 'Key' ) ?></th>
335                 <th><?php _e( 'Value' ) ?></th>
336                 <th colspan='2'><?php _e( 'Action' ) ?></th>
337         </tr>
338         </thead>
339 <?php
340         $r ="\n\t<tbody id='the-list'>";
341         foreach ( $meta as $entry ) {
342                 ++ $count;
343                 if ( $count % 2 )
344                         $style = 'alternate';
345                 else
346                         $style = '';
347                 if ('_' == $entry['meta_key'] { 0 } )
348                         $style .= ' hidden';
349
350                 if ( is_serialized( $entry['meta_value'] ) ) {
351                         if ( is_serialized_string( $entry['meta_value'] ) ) {
352                                 // this is a serialized string, so we should display it
353                                 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
354                         } else {
355                                 // this is a serialized array/object so we should NOT display it
356                                 --$count;
357                                 continue;
358                         }
359                 }
360
361                 $key_js = js_escape( $entry['meta_key'] );
362                 $entry['meta_key']   = attribute_escape($entry['meta_key']);
363                 $entry['meta_value'] = attribute_escape($entry['meta_value']);
364                 $entry['meta_id'] = (int) $entry['meta_id'];
365                 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
366                 $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
367                 $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
368                 $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".attribute_escape(__( 'Update' ))."' /><br />";
369                 $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
370                 $r .= js_escape(sprintf( __("You are about to delete the '%s' custom field on this post.\n'OK' to delete, 'Cancel' to stop." ), $key_js ) );
371                 $r .= "' );\" class='deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' /></td>";
372                 $r .= "\n\t</tr>";
373         }
374         echo $r;
375         echo "\n\t</tbody>";
376 }
377
378 function meta_form() {
379         global $wpdb;
380         $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
381         $keys = $wpdb->get_col( "
382                 SELECT meta_key
383                 FROM $wpdb->postmeta
384                 WHERE meta_key NOT LIKE '\_%'
385                 GROUP BY meta_key
386                 ORDER BY meta_id DESC
387                 LIMIT $limit" );
388         if ( $keys )
389                 natcasesort($keys);
390 ?>
391 <h3><?php _e( 'Add a new custom field:' ) ?></h3>
392 <table id="newmeta" cellspacing="3" cellpadding="3">
393         <tr>
394 <th colspan="2"><?php _e( 'Key' ) ?></th>
395 <th><?php _e( 'Value' ) ?></th>
396 </tr>
397         <tr valign="top">
398                 <td align="right" width="18%">
399 <?php if ( $keys ) : ?>
400 <select id="metakeyselect" name="metakeyselect" tabindex="7">
401 <option value="#NONE#"><?php _e( '- Select -' ); ?></option>
402 <?php
403
404         foreach ( $keys as $key ) {
405                 $key = attribute_escape( $key );
406                 echo "\n\t<option value='$key'>$key</option>";
407         }
408 ?>
409 </select> <?php _e( 'or' ); ?>
410 <?php endif; ?>
411 </td>
412 <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
413                 <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
414         </tr>
415
416 </table>
417 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field &raquo;' ) ?>" /></p>
418 <?php
419
420 }
421
422 function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
423         global $wp_locale, $post, $comment;
424
425         if ( $for_post )
426                 $edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
427         
428         $tab_index_attribute = '';
429         if ( (int) $tab_index > 0 )
430                 $tab_index_attribute = " tabindex=\"$tab_index\"";
431
432         echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
433
434         $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
435         $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
436         $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
437         $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
438         $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
439         $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
440         $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
441         $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
442
443         echo "<select name=\"mm\" onchange=\"edit_date.checked=true\"$tab_index_attribute>\n";
444         for ( $i = 1; $i < 13; $i = $i +1 ) {
445                 echo "\t\t\t<option value=\"$i\"";
446                 if ( $i == $mm )
447                         echo ' selected="selected"';
448                 echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
449         }
450 ?>
451 </select>
452 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> />
453 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> /> @
454 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> /> :
455 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> />
456 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
457 <?php
458         if ( $edit ) {
459                 printf( _c( 'Existing timestamp: %1$s %2$s, %3$s @ %4$s:%5$s|1: month, 2: month string, 3: full year, 4: hours, 5: minutes' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn );
460         }
461 ?>
462 </fieldset>
463         <?php
464
465 }
466
467 function page_template_dropdown( $default = '' ) {
468         $templates = get_page_templates();
469         ksort( $templates );
470         foreach (array_keys( $templates ) as $template )
471                 : if ( $default == $templates[$template] )
472                         $selected = " selected='selected'";
473                 else
474                         $selected = '';
475         echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
476         endforeach;
477 }
478
479 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
480         global $wpdb, $post_ID;
481         $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" );
482
483         if ( $items ) {
484                 foreach ( $items as $item ) {
485                         // A page cannot be its own parent.
486                         if (!empty ( $post_ID ) ) {
487                                 if ( $item->ID == $post_ID ) {
488                                         continue;
489                                 }
490                         }
491                         $pad = str_repeat( '&nbsp;', $level * 3 );
492                         if ( $item->ID == $default)
493                                 $current = ' selected="selected"';
494                         else
495                                 $current = '';
496
497                         echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";
498                         parent_dropdown( $default, $item->ID, $level +1 );
499                 }
500         } else {
501                 return false;
502         }
503 }
504
505 function browse_happy() {
506         $getit = __( 'WordPress recommends a better browser' );
507         echo '
508                 <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p>
509                 ';
510 }
511
512 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
513         add_action( 'admin_footer', 'browse_happy' );
514
515 function the_attachment_links( $id = false ) {
516         $id = (int) $id;
517         $post = & get_post( $id );
518
519         if ( $post->post_type != 'attachment' )
520                 return false;
521
522         $icon = get_attachment_icon( $post->ID );
523         $attachment_data = wp_get_attachment_metadata( $id );
524         $thumb = isset( $attachment_data['thumb'] );
525 ?>
526 <form id="the-attachment-links">
527 <table>
528         <col />
529         <col class="widefat" />
530         <tr>
531                 <th scope="row"><?php _e( 'URL' ) ?></th>
532                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
533         </tr>
534 <?php if ( $icon ) : ?>
535         <tr>
536                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
537                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
538         </tr>
539         <tr>
540                 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
541                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
542         </tr>
543 <?php else : ?>
544         <tr>
545                 <th scope="row"><?php _e( 'Link to file' ) ?></th>
546                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() );  ?></a></textarea></td>
547         </tr>
548         <tr>
549                 <th scope="row"><?php _e( 'Link to page' ) ?></th>
550                 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
551         </tr>
552 <?php endif; ?>
553 </table>
554 </form>
555 <?php
556 }
557
558 function wp_dropdown_roles( $default = false ) {
559         global $wp_roles;
560         $r = '';
561         foreach( $wp_roles->role_names as $role => $name )
562                 if ( $default == $role ) // Make default first in list
563                         $p = "\n\t<option selected='selected' value='$role'>$name</option>";
564                 else
565                         $r .= "\n\t<option value='$role'>$name</option>";
566         echo $p . $r;
567 }
568
569 function wp_convert_hr_to_bytes( $size ) {
570         $size = strtolower($size);
571         $bytes = (int) $size;
572         if ( strpos($size, 'k') !== false )
573                 $bytes = intval($size) * 1024;
574         elseif ( strpos($size, 'm') !== false )
575                 $bytes = intval($size) * 1024 * 1024;
576         elseif ( strpos($size, 'g') !== false )
577                 $bytes = intval($size) * 1024 * 1024 * 1024;
578         return $bytes;
579 }
580
581 function wp_convert_bytes_to_hr( $bytes ) {
582         $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
583         $log = log( $bytes, 1024 );
584         $power = (int) $log;
585         $size = pow(1024, $log - $power);
586         return $size . $units[$power];
587 }
588
589 function wp_import_upload_form( $action ) {
590         $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
591         $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
592         $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
593         $size = wp_convert_bytes_to_hr( $bytes );
594 ?>
595 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>">
596 <p>
597 <?php wp_nonce_field('import-upload'); ?>
598 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
599 <input type="file" id="upload" name="import" size="25" />
600 <input type="hidden" name="action" value="save" />
601 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
602 </p>
603 <p class="submit">
604 <input type="submit" value="<?php _e( 'Upload file and import &raquo;' ); ?>" />
605 </p>
606 </form>
607 <?php
608 }
609
610 function wp_remember_old_slug() {
611         global $post;
612         $name = attribute_escape($post->post_name); // just in case
613         if ( strlen($name) )
614                 echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
615 }
616
617 ?>