]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/post.php
Wordpress 2.0.2-scripts
[autoinstalls/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();
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=true';
52         }
53
54         if ( 'static' == $_POST['post_status'] )
55                 $location = "page-new.php?saved=true";
56
57         if ( isset($_POST['save']) )
58                 $location = "post.php?action=edit&post=$post_ID";
59
60         header("Location: $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 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         check_admin_referer();
91
92         $post_id = (int) $_POST['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         check_admin_referer();
109         
110         $post_ID = edit_post();
111
112         if ($_POST['save']) {
113                 $location = $_SERVER['HTTP_REFERER'];
114         } elseif ($_POST['updatemeta']) {
115                 $location = $_SERVER['HTTP_REFERER'] . '&message=2#postcustom';
116         } elseif ($_POST['deletemeta']) {
117                 $location = $_SERVER['HTTP_REFERER'] . '&message=3#postcustom';
118         } elseif (isset($_POST['referredby']) && $_POST['referredby'] != $_SERVER['HTTP_REFERER']) {
119                 $location = $_POST['referredby'];
120                 if ( $_POST['referredby'] == 'redo' )
121                         $location = get_permalink( $post_ID );
122         } elseif ($action == 'editattachment') {
123                 $location = 'attachments.php';
124         } else {
125                 $location = 'post.php';
126         }
127         header ('Location: ' . $location); // Send user on their way while we keep working
128
129         exit();
130         break;
131
132 case 'delete':
133         check_admin_referer();
134
135         $post_id = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
136
137         $post = & get_post($post_id);
138         
139         if ( !current_user_can('edit_post', $post_id) ) 
140                 die( __('You are not allowed to delete this post.') );
141
142         if ( $post->post_status == 'attachment' ) {
143                 if ( ! wp_delete_attachment($post_id) )
144                         die( __('Error in deleting...') );
145         } else {
146                 if ( !wp_delete_post($post_id) ) 
147                         die( __('Error in deleting...') );
148         }
149
150         $sendback = $_SERVER['HTTP_REFERER'];
151         if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
152         elseif (strstr($sendback, 'attachments.php')) $sendback = get_settings('siteurl') .'/wp-admin/attachments.php';
153         $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
154         header ('Location: ' . $sendback);
155         break;
156
157 case 'editcomment':
158         $title = __('Edit Comment');
159         $parent_file = 'edit.php';
160         require_once ('admin-header.php');
161
162         get_currentuserinfo();
163
164         $comment = (int) $_GET['comment'];
165
166         if ( ! $comment = get_comment($comment) )
167                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
168
169         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
170                 die( __('You are not allowed to edit comments on this post.') );
171
172         $comment = get_comment_to_edit($comment);
173
174         include('edit-form-comment.php');
175
176         break;
177
178 case 'confirmdeletecomment':
179
180         require_once('./admin-header.php');
181
182         $comment = (int) $_GET['comment'];
183         $p = (int) $_GET['p'];
184
185         if ( ! $comment = get_comment($comment) )
186                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
187
188         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
189                 die( __('You are not allowed to delete comments on this post.') );
190
191         echo "<div class='wrap'>\n";
192         echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
193         echo "<table border='0'>\n";
194         echo "<tr><td>" . __('Author:') . "</td><td>$comment->comment_author</td></tr>\n";
195         echo "<tr><td>" . __('E-mail:') . "</td><td>$comment->comment_author_email</td></tr>\n";
196         echo "<tr><td>". __('URL:') . "</td><td>$comment->comment_author_url</td></tr>\n";
197         echo "<tr><td>". __('Comment:') . "</td><td>$comment->comment_content</td></tr>\n";
198         echo "</table>\n";
199         echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
200
201         echo "<form action='".get_settings('siteurl')."/wp-admin/post.php' method='get'>\n";
202         echo "<input type='hidden' name='action' value='deletecomment' />\n";
203         echo "<input type='hidden' name='p' value='$p' />\n";
204         echo "<input type='hidden' name='comment' value='{$comment->comment_ID}' />\n";
205         echo "<input type='hidden' name='noredir' value='1' />\n";
206         echo "<input type='submit' value='" . __('Yes') . "' />";
207         echo "&nbsp;&nbsp;";
208         echo "<input type='button' value='" . __('No') . "' onclick=\"self.location='". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&amp;c=1#comments';\" />\n";
209         echo "</form>\n";
210         echo "</div>\n";
211
212         break;
213
214 case 'deletecomment':
215
216         check_admin_referer();
217
218         $comment = (int) $_GET['comment'];
219         $p = (int) $_GET['p'];
220         if (isset($_GET['noredir'])) {
221                 $noredir = true;
222         } else {
223                 $noredir = false;
224         }
225
226         $postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
227
228         if ( ! $comment = get_comment($comment) )
229                          die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
230
231         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
232                 die( __('You are not allowed to edit comments on this post.') );
233
234         wp_set_comment_status($comment->comment_ID, "delete");
235         do_action('delete_comment', $comment->comment_ID);
236
237         if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
238                 header('Location: ' . $_SERVER['HTTP_REFERER']);
239         } else {
240                 header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
241         }
242
243         break;
244
245 case 'unapprovecomment':
246
247         check_admin_referer();
248
249         $comment = (int) $_GET['comment'];
250         $p = (int) $_GET['p'];
251         if (isset($_GET['noredir'])) {
252                 $noredir = true;
253         } else {
254                 $noredir = false;
255         }
256
257         if ( ! $comment = get_comment($comment) )
258                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
259
260         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
261                 die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
262
263         wp_set_comment_status($comment->comment_ID, "hold");
264
265         if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
266                 header('Location: ' . $_SERVER['HTTP_REFERER']);
267         } else {
268                 header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
269         }
270
271         break;
272
273 case 'mailapprovecomment':
274
275         $comment = (int) $_GET['comment'];
276
277         if ( ! $comment = get_comment($comment) )
278                          die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
279
280         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
281                 die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
282
283         if ('1' != $comment->comment_approved) {
284                 wp_set_comment_status($comment->comment_ID, 'approve');
285                 if (true == get_option('comments_notify'))
286                         wp_notify_postauthor($comment->comment_ID);
287         }
288
289         header('Location: ' . get_option('siteurl') . '/wp-admin/moderation.php?approved=1');
290
291         break;
292
293 case 'approvecomment':
294
295         $comment = (int) $_GET['comment'];
296         $p = (int) $_GET['p'];
297         if (isset($_GET['noredir'])) {
298                 $noredir = true;
299         } else {
300                 $noredir = false;
301         }
302
303         if ( ! $comment = get_comment($comment) )
304                 die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
305
306         if ( !current_user_can('edit_post', $comment->comment_post_ID) )        
307                 die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
308
309         wp_set_comment_status($comment->comment_ID, "approve");
310         if (get_settings("comments_notify") == true) {
311                 wp_notify_postauthor($comment->comment_ID);
312         }
313
314
315         if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) {
316                 header('Location: ' . $_SERVER['HTTP_REFERER']);
317         } else {
318                 header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
319         }
320
321         break;
322
323 case 'editedcomment':
324
325         edit_comment();
326
327         $referredby = $_POST['referredby'];
328         if (!empty($referredby)) {
329                 header('Location: ' . $referredby);
330         } else {
331                 header ("Location: edit.php?p=$comment_post_ID&c=1#comments");
332         }
333
334         break;
335
336 default:
337         $title = __('Create New Post');
338         require_once ('./admin-header.php');
339 ?>
340 <?php if ( isset($_GET['posted']) ) : ?>
341 <div id="message" class="updated fade"><p><?php printf(__('Post saved. <a href="%s">View site &raquo;</a>'), get_bloginfo('home') . '/'); ?></p></div>
342 <?php endif; ?>
343 <?php
344         if ( current_user_can('edit_posts') ) {
345                 $action = 'post';
346                 get_currentuserinfo();
347                 if ( $drafts = get_users_drafts( $user_ID ) ) {
348                         ?>
349                         <div class="wrap">
350                         <p><strong><?php _e('Your Drafts:') ?></strong>
351                         <?php
352                         $num_drafts = count($drafts);
353                         if ( $num_drafts > 15 ) $num_drafts = 15;
354                         for ( $i = 0; $i < $num_drafts; $i++ ) {
355                                 $draft = $drafts[$i];
356                                 if ( 0 != $i )
357                                         echo ', ';
358                                 $draft->post_title = stripslashes($draft->post_title);
359                                 if ( empty($draft->post_title) )
360                                         $draft->post_title = sprintf(__('Post # %s'), $draft->ID);
361                                 echo "<a href='post.php?action=edit&amp;post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
362                         }
363                         ?>
364                         <?php if ( 15 < count($drafts) ) { ?>
365                         , <a href="edit.php"><?php echo sprintf(__('and %s more'), (count($drafts) - 15) ); ?> &raquo;</a>
366                         <?php } ?>
367                         .</p>
368                         </div>
369                         <?php
370                 }
371
372                 $post = get_default_post_to_edit();
373
374                 include('edit-form-advanced.php');
375 ?>
376 <div class="wrap">
377 <?php echo '<h3>'.__('WordPress bookmarklet').'</h3>
378 <p>'.__('Right click on the following link and choose "Add to favorites" to create a posting shortcut.').'</p>'; ?>
379 <p>
380
381 <?php
382 if ($is_NS4 || $is_gecko) {
383 ?>
384 <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> 
385 <?php
386 } else if ($is_winIE) {
387 ?>
388 <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>
389 <script type="text/javascript">
390 <!--
391 function oneclickbookmarklet(blah) {
392 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");
393 }
394 // -->
395 </script>
396 <br />
397 <br />
398 <?php _e('One-click bookmarklet:') ?><br />
399 <a href="javascript:oneclickbookmarklet(0);"><?php _e('click here') ?></a> 
400 <?php
401 } else if ($is_opera) {
402 ?>
403 <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> 
404 <?php
405 } else if ($is_macIE) {
406 ?>
407 <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> 
408 <?php
409 }
410 ?>
411 </p>
412 </div>
413 <?php
414 } else {
415 ?>
416 <div class="wrap">
417 <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 />
418 You can also <a href="mailto:%s?subject=Promotion?">e-mail the admin</a> to ask for a promotion.<br />
419 When you&#8217;re promoted, just reload this page and you&#8217;ll be able to blog. :)'), get_settings('admin_email')); ?>
420 </p>
421 </div>
422 <?php
423 }
424
425         break;
426 } // end switch
427 /* </Edit> */
428 include('admin-footer.php');
429 ?>