]> scripts.mit.edu Git - autoinstallsdev/wordpress.git/blob - wp-admin/post.php
Wordpress 2.0.11-scripts
[autoinstallsdev/wordpress.git] / wp-admin / post.php
1 <?php
2 require_once('admin.php');
3
4 $wpvarstoreset = array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder' );
5
6 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
7         $wpvar = $wpvarstoreset[$i];
8         if (!isset($$wpvar)) {
9                 if (empty($_POST["$wpvar"])) {
10                         if (empty($_GET["$wpvar"])) {
11                                 $$wpvar = '';
12                         } else {
13                         $$wpvar = $_GET["$wpvar"];
14                         }
15                 } else {
16                         $$wpvar = $_POST["$wpvar"];
17                 }
18         }
19 }
20
21 if (isset($_POST['deletepost'])) {
22 $action = "delete";
23 }
24
25 // Fix submenu highlighting for pages.
26 if ( isset($_REQUEST['post']) && 'static' == get_post_status($_REQUEST['post']) )
27         $submenu_file = 'page-new.php';
28
29 $editing = true;
30
31 switch($action) {
32 case 'post':
33         check_admin_referer('add-post');
34         
35         $post_ID = write_post();
36
37         // Redirect.
38         if (!empty($_POST['mode'])) {
39         switch($_POST['mode']) {
40                 case 'bookmarklet':
41                         $location = $_POST['referredby'];
42                         break;
43                 case 'sidebar':
44                         $location = 'sidebar.php?a=b';
45                         break;
46                 default:
47                         $location = 'post.php';
48                         break;
49                 }
50         } else {
51                 $location = "post.php?posted=$post_ID";
52         }
53
54         if ( 'static' == $_POST['post_status'] )
55                 $location = "page-new.php?saved=$post_ID";
56
57         if ( isset($_POST['save']) )
58                 $location = "post.php?action=edit&post=$post_ID";
59
60         wp_redirect($location);
61         exit();
62         break;
63
64 case 'edit':
65         $title = __('Edit');
66
67         require_once('admin-header.php');
68
69         $post_ID = $p = (int) $_GET['post'];
70
71         if ( !current_user_can('edit_post', $post_ID) )
72                 die ( __('You are not allowed to edit this post.') );
73
74         $post = get_post_to_edit($post_ID);
75         
76         if ($post->post_status == 'static')
77                 include('edit-page-form.php');
78         else
79                 include('edit-form-advanced.php');
80
81         ?>
82         <div id='preview' class='wrap'>
83         <h2 id="preview-post"><?php _e('Post Preview (updated when post is saved)'); ?> <small class="quickjump"><a href="#write-post"><?php _e('edit &uarr;'); ?></a></small></h2>
84                 <iframe src="<?php echo clean_url(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID)))); ?>" width="100%" height="600" ></iframe>
85         </div>
86         <?php
87         break;
88
89 case 'editattachment':
90         $post_id = (int) $_POST['post_ID'];
91
92         check_admin_referer('update-attachment_' . $post_id);
93
94         // Don't let these be changed
95         unset($_POST['guid']);
96         $_POST['post_status'] = 'attachment';
97
98         // Update the thumbnail filename
99         $oldmeta = $newmeta = get_post_meta($post_id, '_wp_attachment_metadata', true);
100         $newmeta['thumb'] = $_POST['thumb'];
101
102         if ( '' !== $oldmeta )
103                 update_post_meta($post_id, '_wp_attachment_metadata', $newmeta, $oldmeta);
104         else
105                 add_post_meta($post_id, '_wp_attachment_metadata', $newmeta);
106
107 case 'editpost':
108         $post_ID = (int) $_POST['post_ID'];
109         check_admin_referer('update-post_' . $post_ID);
110         
111         $post_ID = edit_post();
112
113         $referredby = '';
114         if ( !empty($_POST['referredby']) )
115                 $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
116         $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
117         
118         if ($_POST['save']) {
119                 $location = wp_get_referer();
120         } elseif ($_POST['updatemeta']) {
121                 $location = wp_get_referer() . '&message=2#postcustom';
122         } elseif ($_POST['deletemeta']) {
123                 $location = wp_get_referer() . '&message=3#postcustom';
124         } elseif (!empty($referredby) && $referredby != $referer) {
125                 $location = $_POST['referredby'];
126                 if ( $_POST['referredby'] == 'redo' )
127                         $location = get_permalink( $post_ID );
128         } elseif ($action == 'editattachment') {
129                 $location = 'attachments.php';
130         } else {
131                 $location = 'post.php';
132         }
133
134         wp_redirect($location); // Send user on their way while we keep working
135
136         exit();
137         break;
138
139 case 'delete':
140         $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
141
142         $post = & get_post($post_id);
143         if ( 'static' == $post->post_status )
144                 check_admin_referer('delete-page_' . $post_id);
145         else
146                 check_admin_referer('delete-post_' . $post_id);
147
148         if ( !current_user_can('edit_post', $post_id) ) 
149                 die( __('You are not allowed to delete this post.') );
150
151         if ( $post->post_status == 'attachment' ) {
152                 if ( ! wp_delete_attachment($post_id) )
153                         die( __('Error in deleting...') );
154         } else {
155                 if ( !wp_delete_post($post_id) ) 
156                         die( __('Error in deleting...') );
157         }
158
159         $sendback = wp_get_referer();
160         if ( 'static' == $post->post_status )
161                 $sendback = get_option('siteurl') . '/wp-admin/edit-pages.php';
162         elseif ( strstr($sendback, 'post.php') )
163                 $sendback = get_option('siteurl') .'/wp-admin/post.php';
164         elseif ( strstr($sendback, 'attachments.php') )
165                 $sendback = get_option('siteurl') .'/wp-admin/attachments.php';
166         wp_redirect($sendback);
167         break;
168
169 case 'editcomment':
170         $title = __('Edit Comment');
171         $parent_file = 'edit.php';
172         require_once ('admin-header.php');
173
174         get_currentuserinfo();
175
176         $comment = (int) $_GET['comment'];
177
178         if ( ! $comment = get_comment($comment) )
179                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
180
181         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
182                 die( __('You are not allowed to edit comments on this post.') );
183
184         $comment = get_comment_to_edit($comment);
185
186         include('edit-form-comment.php');
187
188         break;
189
190 case 'confirmdeletecomment':
191
192         require_once('./admin-header.php');
193
194         $comment = (int) $_GET['comment'];
195         $p = (int) $_GET['p'];
196
197         if ( ! $comment = get_comment_to_edit($comment) )
198                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
199
200         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
201                 die( __('You are not allowed to delete comments on this post.') );
202
203         echo "<div class='wrap'>\n";
204         echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
205         echo "<table border='0'>\n";
206         echo "<tr><td>" . __('Author:') . "</td><td>$comment->comment_author</td></tr>\n";
207         echo "<tr><td>" . __('E-mail:') . "</td><td>$comment->comment_author_email</td></tr>\n";
208         echo "<tr><td>". __('URL:') . "</td><td>$comment->comment_author_url</td></tr>\n";
209         echo "<tr><td>". __('Comment:') . "</td><td>$comment->comment_content</td></tr>\n";
210         echo "</table>\n";
211         echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
212
213         echo "<form action='".get_settings('siteurl')."/wp-admin/post.php' method='get'>\n";
214         echo "<input type='hidden' name='action' value='deletecomment' />\n";
215         echo "<input type='hidden' name='p' value='$p' />\n";
216         echo "<input type='hidden' name='comment' value='{$comment->comment_ID}' />\n";
217         echo "<input type='hidden' name='noredir' value='1' />\n";
218         wp_nonce_field('delete-comment_' .  $comment->comment_ID);
219         echo "<input type='submit' value='" . __('Yes') . "' />";
220         echo "&nbsp;&nbsp;";
221         echo "<input type='button' value='" . __('No') . "' onclick=\"self.location='". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&amp;c=1#comments';\" />\n";
222         echo "</form>\n";
223         echo "</div>\n";
224
225         break;
226
227 case 'deletecomment':
228         $comment = (int) $_GET['comment'];
229         check_admin_referer('delete-comment_' . $comment);
230
231         $p = (int) $_GET['p'];
232         if (isset($_GET['noredir'])) {
233                 $noredir = true;
234         } else {
235                 $noredir = false;
236         }
237
238         $postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
239
240         if ( ! $comment = get_comment($comment) )
241                          die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
242
243         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
244                 die( __('You are not allowed to edit comments on this post.') );
245
246         wp_set_comment_status($comment->comment_ID, "delete");
247         do_action('delete_comment', $comment->comment_ID);
248
249         if ((wp_get_referer() != "") && (false == $noredir)) {
250                 wp_redirect(wp_get_referer());
251         } else {
252                 wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
253         }
254
255         break;
256
257 case 'unapprovecomment':
258         $comment = (int) $_GET['comment'];
259         check_admin_referer('unapprove-comment_' . $comment);
260
261         $p = (int) $_GET['p'];
262         if (isset($_GET['noredir'])) {
263                 $noredir = true;
264         } else {
265                 $noredir = false;
266         }
267
268         if ( ! $comment = get_comment($comment) )
269                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
270
271         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
272                 die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
273
274         wp_set_comment_status($comment->comment_ID, "hold");
275
276         if ((wp_get_referer() != "") && (false == $noredir)) {
277                 wp_redirect(wp_get_referer());
278         } else {
279                 wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
280         }
281
282         break;
283
284 case 'mailapprovecomment':
285         $comment = (int) $_GET['comment'];
286         check_admin_referer('approve-comment_' . $comment);
287
288         if ( ! $comment = get_comment($comment) )
289                          die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
290
291         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
292                 die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
293
294         if ('1' != $comment->comment_approved) {
295                 wp_set_comment_status($comment->comment_ID, 'approve');
296                 if (true == get_option('comments_notify'))
297                         wp_notify_postauthor($comment->comment_ID);
298         }
299
300         wp_redirect(get_option('siteurl') . '/wp-admin/moderation.php?approved=1');
301
302         break;
303
304 case 'approvecomment':
305         $comment = (int) $_GET['comment'];
306         check_admin_referer('approve-comment_' . $comment);
307
308         $p = (int) $_GET['p'];
309         if (isset($_GET['noredir'])) {
310                 $noredir = true;
311         } else {
312                 $noredir = false;
313         }
314
315         if ( ! $comment = get_comment($comment) )
316                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
317
318         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
319                 die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
320
321         wp_set_comment_status($comment->comment_ID, "approve");
322         if (get_settings("comments_notify") == true) {
323                 wp_notify_postauthor($comment->comment_ID);
324         }
325
326
327         if ((wp_get_referer() != "") && (false == $noredir)) {
328                 wp_redirect(wp_get_referer());
329         } else {
330                 wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
331         }
332
333         break;
334
335 case 'editedcomment':
336
337         $comment_ID = (int) $_POST['comment_ID'];
338         $comment_post_ID = (int)  $_POST['comment_post_ID'];
339
340         check_admin_referer('update-comment_' . $comment_ID);
341
342         edit_comment();
343
344         $location = ( empty($_POST['referredby']) ? "edit.php?p=$comment_post_ID&c=1" : $_POST['referredby'] ) . '#comment-' . $comment_ID;
345         $location = apply_filters('comment_edit_redirect', $location, $comment_ID);
346         wp_redirect($location);
347         exit();
348         break;
349
350 default:
351         $title = __('Create New Post');
352         require_once ('./admin-header.php');
353 ?>
354 <?php if ( isset($_GET['posted']) ) : ?>
355 <div id="message" class="updated fade"><p><strong><?php _e('Post saved.'); ?></strong> <a href="<?php echo get_permalink( $_GET['posted'] ); ?>"><?php _e('View post'); ?> &raquo;</a></p></div>
356 <?php endif; ?>
357 <?php
358         if ( current_user_can('edit_posts') ) {
359                 $action = 'post';
360                 get_currentuserinfo();
361                 if ( $drafts = get_users_drafts( $user_ID ) ) {
362                         ?>
363                         <div class="wrap">
364                         <p><strong><?php _e('Your Drafts:') ?></strong>
365                         <?php
366                         $num_drafts = count($drafts);
367                         if ( $num_drafts > 15 ) $num_drafts = 15;
368                         for ( $i = 0; $i < $num_drafts; $i++ ) {
369                                 $draft = $drafts[$i];
370                                 if ( 0 != $i )
371                                         echo ', ';
372                                 $draft->post_title = stripslashes($draft->post_title);
373                                 if ( empty($draft->post_title) )
374                                         $draft->post_title = sprintf(__('Post # %s'), $draft->ID);
375                                 echo "<a href='post.php?action=edit&amp;post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
376                         }
377                         ?>
378                         <?php if ( 15 < count($drafts) ) { ?>
379                         , <a href="edit.php"><?php echo sprintf(__('and %s more'), (count($drafts) - 15) ); ?> &raquo;</a>
380                         <?php } ?>
381                         .</p>
382                         </div>
383                         <?php
384                 }
385
386                 $post = get_default_post_to_edit();
387
388                 include('edit-form-advanced.php');
389 ?>
390 <div id="wp-bookmarklet" class="wrap">
391 <?php echo '<h3>'.__('WordPress bookmarklet').'</h3>
392 <p>'.__('Right click on the following link and choose "Add to favorites" to create a posting shortcut.').'</p>'; ?>
393 <p>
394
395 <?php
396 if ($is_NS4 || $is_gecko) {
397 ?>
398 <a href="javascript:if(navigator.userAgent.indexOf('Safari') >= 0){Q=getSelection();}else{Q=document.selection?document.selection.createRange().text:document.getSelection();}location.href='<?php echo get_settings('siteurl') ?>/wp-admin/post.php?text='+encodeURIComponent(Q)+'&amp;popupurl='+encodeURIComponent(location.href)+'&amp;popuptitle='+encodeURIComponent(document.title);"><?php printf(__('Press It - %s'), wp_specialchars(get_settings('blogname'))); ?></a> 
399 <?php
400 } else if ($is_winIE) {
401 ?>
402 <a href="javascript:Q='';if(top.frames.length==0)Q=document.selection.createRange().text;location.href='<?php echo get_settings('siteurl') ?>/wp-admin/post.php?text='+encodeURIComponent(Q)+'&amp;popupurl='+encodeURIComponent(location.href)+'&amp;popuptitle='+encodeURIComponent(document.title);"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a>
403 <script type="text/javascript">
404 <!--
405 function oneclickbookmarklet(blah) {
406 window.open ("profile.php?action=IErightclick", "oneclickbookmarklet", "width=500, height=450, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, screenX=120, left=120, screenY=120, top=120");
407 }
408 // -->
409 </script>
410 <br />
411 <br />
412 <?php _e('One-click bookmarklet:') ?><br />
413 <a href="javascript:oneclickbookmarklet(0);"><?php _e('click here') ?></a> 
414 <?php
415 } else if ($is_opera) {
416 ?>
417 <a href="javascript:location.href='<?php echo get_settings('siteurl'); ?>/wp-admin/post.php?popupurl='+escape(location.href)+'&popuptitle='+escape(document.title);"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
418 <?php
419 } else if ($is_macIE) {
420 ?>
421 <a href="javascript:Q='';location.href='<?php echo get_settings('siteurl'); ?>/wp-admin/bookmarklet.php?text='+escape(document.getSelection())+'&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title);"><?php printf(__('Press it - %s'), get_settings('blogname')); ?></a> 
422 <?php
423 }
424 ?>
425 </p>
426 </div>
427 <?php
428 } else {
429 ?>
430 <div class="wrap">
431 <p><?php printf(__('Since you&#8217;re a newcomer, you&#8217;ll have to wait for an admin to raise your level to 1, in order to be authorized to post.<br />
432 You can also <a href="mailto:%s?subject=Promotion?">e-mail the admin</a> to ask for a promotion.<br />
433 When you&#8217;re promoted, just reload this page and you&#8217;ll be able to blog. :)'), get_settings('admin_email')); ?>
434 </p>
435 </div>
436 <?php
437 }
438
439         break;
440 } // end switch
441 /* </Edit> */
442 include('admin-footer.php');
443 ?>