Plugin to allow visitor contributions to WordPress posts, wiki style.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

editor.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. $post=null;
  3. if(!empty($_POST)){
  4. global $wpdb;
  5. $wpdb->show_errors();
  6. $table_name = $wpdb->prefix . 'visitors_edits';
  7. $post_id=$_POST["post_id"];
  8. $visitor_name=$_POST["visitor_name"];
  9. $visitor_email=$_POST["visitor_email"];
  10. $visitor_comment=$_POST["visitor_comment"];
  11. $edit_content=$_POST["edit_content"];
  12. $post = get_post($post_id);
  13. //Check if changed
  14. if(md5($post->post_content)!==md5(stripcslashes($edit_content))){
  15. $wpdb->insert($table_name,[
  16. "edit_time"=>date('Y-m-d H:i:s'),
  17. "visitor_name"=>$visitor_name,
  18. "visitor_email"=>$visitor_email,
  19. "visitor_comment"=>$visitor_comment,
  20. "edit_content"=>$edit_content,
  21. "post_id"=>$post_id,
  22. "post_content"=>$post->post_content
  23. ]);
  24. require "mail.php";
  25. $options=get_option( "visitors_edits_options", [
  26. "admin_email"=>"",
  27. "notify_admin"=>null,
  28. "visitor_notif_message"=>"Your suggestion was submitted.",
  29. "admin_notif_message"=>"A new suggestion was submitted."
  30. ]);
  31. $mail = [
  32. "post_title"=>$post->post_title,
  33. "post_url"=>get_permalink($post_id),
  34. "visitor_name"=>$visitor_name,
  35. "visitor_comment"=>$visitor_comment,
  36. "visitor_email"=>$visitor_email,
  37. "edit_time"=>date('m/d/Y')." at ".date('h:i a'),
  38. "blog_title" => get_bloginfo("name"),
  39. "visitor_notif_message"=>$options["visitor_notif_message"],
  40. "admin_notif_message"=>$options["admin_notif_message"]
  41. ];
  42. $visitor_submitionMail=new visitors_edits_EMAIL($mail,"visitor_submition");
  43. $visitor_submitionMail->send($visitor_email);
  44. if($options["notify_admin"]!=null){
  45. $admin_email=$options["admin_email"];
  46. $admin_submitionMail=new visitors_edits_EMAIL($mail,"admin_submition");
  47. $admin_submitionMail->send($admin_email);
  48. }
  49. }
  50. }else{
  51. global $wp;
  52. global $post;
  53. $post = get_posts([
  54. "name"=> $wp->query_vars['visitors_edits_post_name'],
  55. 'post_type' => 'post',
  56. 'post_status' => 'publish',
  57. 'numberposts' => 1
  58. ]);
  59. $post=$post[0];
  60. if($post->post_name!=$wp->query_vars['visitors_edits_post_name']){
  61. header("Location:".get_site_url());
  62. }
  63. }
  64. ?>
  65. <!DOCTYPE html>
  66. <html xmlns="http://www.w1.org/1998/xhtml" xml:lang="en" lang="en">
  67. <head>
  68. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  69. <link rel="stylesheet" type="text/css" href="<?php echo plugins_url( '/../css/grid.css',__FILE__ );?>">
  70. <link rel="stylesheet" type="text/css" href="<?php echo plugins_url( '/../css/editor.css',__FILE__ );?>">
  71. <script src="<?php echo visitors_edits::scriptUrl('jquery');?>"></script>
  72. <title>Submit an edit</title>
  73. </head>
  74. <body <?php if(!empty($_POST)){echo 'class="grey"';} ?>>
  75. <?php
  76. if(!empty($_POST)){
  77. confirmSubmit("Edit Submitted!","Thanks for your contribution you will be notified once the edit reviewed.");
  78. }else{
  79. showForm();
  80. }
  81. ?>
  82. </body>
  83. </html>
  84. <?php
  85. function showForm(){
  86. global $post;
  87. ?>
  88. <div class="header">
  89. <div class="header-title">Submit a contribution</div>
  90. <p class="header-content">
  91. <a href="<?php echo get_permalink($post->ID) ?>">Original post : <?php echo $post->post_title; ?>.</a>
  92. </p>
  93. </div>
  94. <form action="" method="POST" class="editor_form row" id="editor_form" onsubmit="return validateEdit.run()">
  95. <div class="submit_fields col-12 col-l-4">
  96. <ul class="submit_fields_error" id="submit_fields_error">
  97. </ul>
  98. <label for="name">Name</label>
  99. <input class="text_field" type="text" name="visitor_name" placeholder="Name" id="name">
  100. <label for="email">Email</label>
  101. <input class="text_field" type="email" name="visitor_email" placeholder="Email" id="email">
  102. <label for="comment">Description</label>
  103. <textarea class="area_field" type="text" name="visitor_comment" value=" " id="comment">
  104. </textarea>
  105. <input type="hidden" name="post_id" value="<?php echo $post->ID;?>">
  106. <input type="hidden" name="post_url" value="<?php echo get_permalink($post->ID);?>">
  107. <input type="submit" class="btn" value="Submit for review">
  108. </div>
  109. <div class="editor_field col-12 col-l-8">
  110. <?php
  111. wp_editor($post->post_content,"edit_content",[
  112. "media_buttons"=>false,
  113. "quicktags"=>false,
  114. "textarea_name"=>"edit_content",
  115. "tinymce"=>[
  116. "mode" => "textareas",
  117. "theme" => "modern"
  118. ]
  119. ]);
  120. _WP_Editors::enqueue_scripts();
  121. print_footer_scripts();
  122. _WP_Editors::editor_js();
  123. ?>
  124. </div>
  125. <div class="cb"></div>
  126. </form>
  127. <script src="<?php echo visitors_edits::scriptUrl('editor');?>"></script>
  128. <?php
  129. }
  130. function confirmSubmit($title,$message){
  131. ?>
  132. <div class="submit_success col-10 col-l-6 col-center">
  133. <strong class="alert_title">
  134. <?php echo $title;?>
  135. </strong>
  136. <p class="alert_content">
  137. <?php echo $message;?>
  138. </p>
  139. <p class="alert_footer">
  140. <a href="<?php echo $_POST['post_url']?>">Click here to continue back to the post</a>
  141. </p>
  142. </div>
  143. </div>
  144. <?php
  145. }
  146. ?>