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.
 
 
 
 

152 lines
4.8 KiB

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