PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/2.0.5/wp-admin/post.php

#
PHP | 437 lines | 341 code | 90 blank | 6 comment | 91 complexity | d4ae2c0a11009743a57aadc862bf82a9 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. require_once('admin.php');
  3. $wpvarstoreset = array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder' );
  4. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  5. $wpvar = $wpvarstoreset[$i];
  6. if (!isset($$wpvar)) {
  7. if (empty($_POST["$wpvar"])) {
  8. if (empty($_GET["$wpvar"])) {
  9. $$wpvar = '';
  10. } else {
  11. $$wpvar = $_GET["$wpvar"];
  12. }
  13. } else {
  14. $$wpvar = $_POST["$wpvar"];
  15. }
  16. }
  17. }
  18. if (isset($_POST['deletepost'])) {
  19. $action = "delete";
  20. }
  21. // Fix submenu highlighting for pages.
  22. if ( isset($_REQUEST['post']) && 'static' == get_post_status($_REQUEST['post']) )
  23. $submenu_file = 'page-new.php';
  24. $editing = true;
  25. switch($action) {
  26. case 'post':
  27. check_admin_referer('add-post');
  28. $post_ID = write_post();
  29. // Redirect.
  30. if (!empty($_POST['mode'])) {
  31. switch($_POST['mode']) {
  32. case 'bookmarklet':
  33. $location = $_POST['referredby'];
  34. break;
  35. case 'sidebar':
  36. $location = 'sidebar.php?a=b';
  37. break;
  38. default:
  39. $location = 'post.php';
  40. break;
  41. }
  42. } else {
  43. $location = "post.php?posted=$post_ID";
  44. }
  45. if ( 'static' == $_POST['post_status'] )
  46. $location = "page-new.php?saved=$post_ID";
  47. if ( isset($_POST['save']) )
  48. $location = "post.php?action=edit&post=$post_ID";
  49. wp_redirect($location);
  50. exit();
  51. break;
  52. case 'edit':
  53. $title = __('Edit');
  54. require_once('admin-header.php');
  55. $post_ID = $p = (int) $_GET['post'];
  56. if ( !current_user_can('edit_post', $post_ID) )
  57. die ( __('You are not allowed to edit this post.') );
  58. $post = get_post_to_edit($post_ID);
  59. if ($post->post_status == 'static')
  60. include('edit-page-form.php');
  61. else
  62. include('edit-form-advanced.php');
  63. ?>
  64. <div id='preview' class='wrap'>
  65. <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>
  66. <iframe src="<?php echo wp_specialchars(apply_filters('preview_post_link', add_query_arg('preview', 'true', get_permalink($post->ID)))); ?>" width="100%" height="600" ></iframe>
  67. </div>
  68. <?php
  69. break;
  70. case 'editattachment':
  71. $post_id = (int) $_POST['post_ID'];
  72. check_admin_referer('update-attachment_' . $post_id);
  73. // Don't let these be changed
  74. unset($_POST['guid']);
  75. $_POST['post_status'] = 'attachment';
  76. // Update the thumbnail filename
  77. $oldmeta = $newmeta = get_post_meta($post_id, '_wp_attachment_metadata', true);
  78. $newmeta['thumb'] = $_POST['thumb'];
  79. if ( '' !== $oldmeta )
  80. update_post_meta($post_id, '_wp_attachment_metadata', $newmeta, $oldmeta);
  81. else
  82. add_post_meta($post_id, '_wp_attachment_metadata', $newmeta);
  83. case 'editpost':
  84. $post_ID = (int) $_POST['post_ID'];
  85. check_admin_referer('update-post_' . $post_ID);
  86. $post_ID = edit_post();
  87. $referredby = '';
  88. if ( !empty($_POST['referredby']) )
  89. $referredby = preg_replace('|https?://[^/]+|i', '', $_POST['referredby']);
  90. $referer = preg_replace('|https?://[^/]+|i', '', wp_get_referer());
  91. if ($_POST['save']) {
  92. $location = wp_get_referer();
  93. } elseif ($_POST['updatemeta']) {
  94. $location = wp_get_referer() . '&message=2#postcustom';
  95. } elseif ($_POST['deletemeta']) {
  96. $location = wp_get_referer() . '&message=3#postcustom';
  97. } elseif (!empty($referredby) && $referredby != $referer) {
  98. $location = $_POST['referredby'];
  99. if ( $_POST['referredby'] == 'redo' )
  100. $location = get_permalink( $post_ID );
  101. } elseif ($action == 'editattachment') {
  102. $location = 'attachments.php';
  103. } else {
  104. $location = 'post.php';
  105. }
  106. wp_redirect($location); // Send user on their way while we keep working
  107. exit();
  108. break;
  109. case 'delete':
  110. $post_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']);
  111. check_admin_referer('delete-post_' . $post_id);
  112. $post = & get_post($post_id);
  113. if ( !current_user_can('edit_post', $post_id) )
  114. die( __('You are not allowed to delete this post.') );
  115. if ( $post->post_status == 'attachment' ) {
  116. if ( ! wp_delete_attachment($post_id) )
  117. die( __('Error in deleting...') );
  118. } else {
  119. if ( !wp_delete_post($post_id) )
  120. die( __('Error in deleting...') );
  121. }
  122. $sendback = wp_get_referer();
  123. if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post.php';
  124. elseif (strstr($sendback, 'attachments.php')) $sendback = get_settings('siteurl') .'/wp-admin/attachments.php';
  125. $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback);
  126. wp_redirect($sendback);
  127. break;
  128. case 'editcomment':
  129. $title = __('Edit Comment');
  130. $parent_file = 'edit.php';
  131. require_once ('admin-header.php');
  132. get_currentuserinfo();
  133. $comment = (int) $_GET['comment'];
  134. if ( ! $comment = get_comment($comment) )
  135. die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'javascript:history.go(-1)'));
  136. if ( !current_user_can('edit_post', $comment->comment_post_ID) )
  137. die( __('You are not allowed to edit comments on this post.') );
  138. $comment = get_comment_to_edit($comment);
  139. include('edit-form-comment.php');
  140. break;
  141. case 'confirmdeletecomment':
  142. require_once('./admin-header.php');
  143. $comment = (int) $_GET['comment'];
  144. $p = (int) $_GET['p'];
  145. if ( ! $comment = get_comment($comment) )
  146. die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  147. if ( !current_user_can('edit_post', $comment->comment_post_ID) )
  148. die( __('You are not allowed to delete comments on this post.') );
  149. echo "<div class='wrap'>\n";
  150. echo "<p>" . __('<strong>Caution:</strong> You are about to delete the following comment:') . "</p>\n";
  151. echo "<table border='0'>\n";
  152. echo "<tr><td>" . __('Author:') . "</td><td>$comment->comment_author</td></tr>\n";
  153. echo "<tr><td>" . __('E-mail:') . "</td><td>$comment->comment_author_email</td></tr>\n";
  154. echo "<tr><td>". __('URL:') . "</td><td>$comment->comment_author_url</td></tr>\n";
  155. echo "<tr><td>". __('Comment:') . "</td><td>$comment->comment_content</td></tr>\n";
  156. echo "</table>\n";
  157. echo "<p>" . __('Are you sure you want to do that?') . "</p>\n";
  158. echo "<form action='".get_settings('siteurl')."/wp-admin/post.php' method='get'>\n";
  159. echo "<input type='hidden' name='action' value='deletecomment' />\n";
  160. echo "<input type='hidden' name='p' value='$p' />\n";
  161. echo "<input type='hidden' name='comment' value='{$comment->comment_ID}' />\n";
  162. echo "<input type='hidden' name='noredir' value='1' />\n";
  163. wp_nonce_field('delete-comment_' . $comment->comment_ID);
  164. echo "<input type='submit' value='" . __('Yes') . "' />";
  165. echo "&nbsp;&nbsp;";
  166. echo "<input type='button' value='" . __('No') . "' onclick=\"self.location='". get_settings('siteurl') ."/wp-admin/edit.php?p=$p&amp;c=1#comments';\" />\n";
  167. echo "</form>\n";
  168. echo "</div>\n";
  169. break;
  170. case 'deletecomment':
  171. $comment = (int) $_GET['comment'];
  172. check_admin_referer('delete-comment_' . $comment);
  173. $p = (int) $_GET['p'];
  174. if (isset($_GET['noredir'])) {
  175. $noredir = true;
  176. } else {
  177. $noredir = false;
  178. }
  179. $postdata = get_post($p) or die(sprintf(__('Oops, no post with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  180. if ( ! $comment = get_comment($comment) )
  181. die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'post.php'));
  182. if ( !current_user_can('edit_post', $comment->comment_post_ID) )
  183. die( __('You are not allowed to edit comments on this post.') );
  184. wp_set_comment_status($comment->comment_ID, "delete");
  185. do_action('delete_comment', $comment->comment_ID);
  186. if ((wp_get_referer() != "") && (false == $noredir)) {
  187. wp_redirect(wp_get_referer());
  188. } else {
  189. wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  190. }
  191. break;
  192. case 'unapprovecomment':
  193. $comment = (int) $_GET['comment'];
  194. check_admin_referer('unapprove-comment_' . $comment);
  195. $p = (int) $_GET['p'];
  196. if (isset($_GET['noredir'])) {
  197. $noredir = true;
  198. } else {
  199. $noredir = false;
  200. }
  201. if ( ! $comment = get_comment($comment) )
  202. die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  203. if ( !current_user_can('edit_post', $comment->comment_post_ID) )
  204. die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') );
  205. wp_set_comment_status($comment->comment_ID, "hold");
  206. if ((wp_get_referer() != "") && (false == $noredir)) {
  207. wp_redirect(wp_get_referer());
  208. } else {
  209. wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  210. }
  211. break;
  212. case 'mailapprovecomment':
  213. $comment = (int) $_GET['comment'];
  214. check_admin_referer('approve-comment_' . $comment);
  215. if ( ! $comment = get_comment($comment) )
  216. die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  217. if ( !current_user_can('edit_post', $comment->comment_post_ID) )
  218. die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
  219. if ('1' != $comment->comment_approved) {
  220. wp_set_comment_status($comment->comment_ID, 'approve');
  221. if (true == get_option('comments_notify'))
  222. wp_notify_postauthor($comment->comment_ID);
  223. }
  224. wp_redirect(get_option('siteurl') . '/wp-admin/moderation.php?approved=1');
  225. break;
  226. case 'approvecomment':
  227. $comment = (int) $_GET['comment'];
  228. check_admin_referer('approve-comment_' . $comment);
  229. $p = (int) $_GET['p'];
  230. if (isset($_GET['noredir'])) {
  231. $noredir = true;
  232. } else {
  233. $noredir = false;
  234. }
  235. if ( ! $comment = get_comment($comment) )
  236. die(sprintf(__('Oops, no comment with this ID. <a href="%s">Go back</a>!'), 'edit.php'));
  237. if ( !current_user_can('edit_post', $comment->comment_post_ID) )
  238. die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') );
  239. wp_set_comment_status($comment->comment_ID, "approve");
  240. if (get_settings("comments_notify") == true) {
  241. wp_notify_postauthor($comment->comment_ID);
  242. }
  243. if ((wp_get_referer() != "") && (false == $noredir)) {
  244. wp_redirect(wp_get_referer());
  245. } else {
  246. wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments');
  247. }
  248. break;
  249. case 'editedcomment':
  250. $comment_ID = (int) $_POST['comment_ID'];
  251. $comment_post_ID = (int) $_POST['comment_post_ID'];
  252. check_admin_referer('update-comment_' . $comment_ID);
  253. edit_comment();
  254. $location = ( empty($_POST['referredby']) ? "edit.php?p=$comment_post_ID&c=1" : $_POST['referredby'] ) . '#comment-' . $comment_ID;
  255. $location = apply_filters('comment_edit_redirect', $location, $comment_ID);
  256. wp_redirect($location);
  257. break;
  258. default:
  259. $title = __('Create New Post');
  260. require_once ('./admin-header.php');
  261. ?>
  262. <?php if ( isset($_GET['posted']) ) : ?>
  263. <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>
  264. <?php endif; ?>
  265. <?php
  266. if ( current_user_can('edit_posts') ) {
  267. $action = 'post';
  268. get_currentuserinfo();
  269. if ( $drafts = get_users_drafts( $user_ID ) ) {
  270. ?>
  271. <div class="wrap">
  272. <p><strong><?php _e('Your Drafts:') ?></strong>
  273. <?php
  274. $num_drafts = count($drafts);
  275. if ( $num_drafts > 15 ) $num_drafts = 15;
  276. for ( $i = 0; $i < $num_drafts; $i++ ) {
  277. $draft = $drafts[$i];
  278. if ( 0 != $i )
  279. echo ', ';
  280. $draft->post_title = stripslashes($draft->post_title);
  281. if ( empty($draft->post_title) )
  282. $draft->post_title = sprintf(__('Post # %s'), $draft->ID);
  283. echo "<a href='post.php?action=edit&amp;post=$draft->ID' title='" . __('Edit this draft') . "'>$draft->post_title</a>";
  284. }
  285. ?>
  286. <?php if ( 15 < count($drafts) ) { ?>
  287. , <a href="edit.php"><?php echo sprintf(__('and %s more'), (count($drafts) - 15) ); ?> &raquo;</a>
  288. <?php } ?>
  289. .</p>
  290. </div>
  291. <?php
  292. }
  293. $post = get_default_post_to_edit();
  294. include('edit-form-advanced.php');
  295. ?>
  296. <div id="wp-bookmarklet" class="wrap">
  297. <?php echo '<h3>'.__('WordPress bookmarklet').'</h3>
  298. <p>'.__('Right click on the following link and choose "Add to favorites" to create a posting shortcut.').'</p>'; ?>
  299. <p>
  300. <?php
  301. if ($is_NS4 || $is_gecko) {
  302. ?>
  303. <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>
  304. <?php
  305. } else if ($is_winIE) {
  306. ?>
  307. <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>
  308. <script type="text/javascript">
  309. <!--
  310. function oneclickbookmarklet(blah) {
  311. 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");
  312. }
  313. // -->
  314. </script>
  315. <br />
  316. <br />
  317. <?php _e('One-click bookmarklet:') ?><br />
  318. <a href="javascript:oneclickbookmarklet(0);"><?php _e('click here') ?></a>
  319. <?php
  320. } else if ($is_opera) {
  321. ?>
  322. <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>
  323. <?php
  324. } else if ($is_macIE) {
  325. ?>
  326. <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>
  327. <?php
  328. }
  329. ?>
  330. </p>
  331. </div>
  332. <?php
  333. } else {
  334. ?>
  335. <div class="wrap">
  336. <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 />
  337. You can also <a href="mailto:%s?subject=Promotion?">e-mail the admin</a> to ask for a promotion.<br />
  338. When you&#8217;re promoted, just reload this page and you&#8217;ll be able to blog. :)'), get_settings('admin_email')); ?>
  339. </p>
  340. </div>
  341. <?php
  342. }
  343. break;
  344. } // end switch
  345. /* </Edit> */
  346. include('admin-footer.php');
  347. ?>