Plugin to allow visitor contributions to WordPress posts, wiki style.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

136 Zeilen
4.6KB

  1. <?php
  2. /*
  3. Plugin Name: Visitors contributions
  4. Plugin URI: http://codecanyon.net/user/Leavy
  5. Description: A wordpress plugin that gives your visitors the possiblity to develop your website content by submiting new versions to your articles.
  6. Version: 1.11
  7. Author: Leavy
  8. Author URI: http://codecanyon.net/user/Leavy
  9. */
  10. class visitors_edits{
  11. public function __construct() {
  12. register_activation_hook( __FILE__, array($this,'install'));
  13. add_action( 'admin_menu', array( $this, 'admin_pages' ) );
  14. add_filter('the_content', array($this,'contentFilter'));
  15. add_filter( 'query_vars', array($this,'query_vars') );
  16. add_action( 'init',array($this,'init'));
  17. add_action( 'parse_request',array($this,'parse_request'));
  18. add_filter( 'mce_buttons', array($this,'tinymce_btns') );
  19. add_filter( 'mce_external_plugins', array($this,'tinymce_scripts') );
  20. add_action('admin_head', array($this,'admin_head') );
  21. add_action('admin_init', array($this,'admin_init') );
  22. }
  23. public function admin_pages() {
  24. add_menu_page('Visitors Contributions | Pending reviews','Visitors contributions','read','visitors_edits_main',array($this , 'main'),plugins_url("img/contribute.png",__FILE__),87);
  25. add_submenu_page(null,"Visitors Contributions | Review","Review a contribution","read",'visitors_edits_approve',array($this,'approve'));
  26. add_submenu_page("visitors_edits_main","Visitors Contributions | Settings","Settings","read",'visitors_edits_settings',array($this,'settings'));
  27. }
  28. public function admin_head(){
  29. if(isset($_GET["page"]) && ($_GET["page"]==="visitors_edits_approve" || $_GET["page"]==="visitors_edits_main" || $_GET["page"]==="visitors_edits_settings")){
  30. ?>
  31. <link rel="stylesheet" type="text/css" href="<?php echo plugins_url( '/css/app.css',__FILE__ );?>">
  32. <?php
  33. }
  34. }
  35. public function admin_init(){
  36. add_editor_style(plugins_url( './css/tinymce.css',__FILE__ ));
  37. }
  38. public function main(){
  39. require "inc/main.php";
  40. }
  41. public function approve(){
  42. require 'inc/approve.php';
  43. }
  44. public function settings(){
  45. require 'inc/settings.php';
  46. }
  47. public function contentFilter($content){
  48. if(is_single()) {
  49. $options=get_option( "visitors_edits_options", [
  50. "propose_edit_link"=>"<p><a href='#post_link#'>Propose an edit</a></p>"
  51. ]);
  52. global $post;
  53. $new_content = str_replace("#post_link#", get_site_url().'/'.$post->post_name.'/suggestions', stripcslashes($options["propose_edit_link"]));
  54. $content .= $new_content;
  55. }
  56. return $content;
  57. }
  58. public function install(){
  59. //General Settings
  60. delete_option("visitors_edits_options");
  61. //Database Settings
  62. global $wpdb;
  63. $wpdb->show_errors();
  64. $charset_collate = $wpdb->get_charset_collate();
  65. $table_name = $wpdb->prefix . 'visitors_edits';
  66. $sql = "CREATE TABLE $table_name (
  67. edit_id bigint(20) NOT NULL AUTO_INCREMENT,
  68. edit_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
  69. visitor_name text DEFAULT '',
  70. visitor_email text DEFAULT '',
  71. visitor_comment longtext DEFAULT '',
  72. edit_content longtext DEFAULT '',
  73. post_id bigint(20),
  74. post_content longtext DEFAULT '',
  75. UNIQUE KEY (edit_id)
  76. ) $charset_collate;";
  77. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  78. dbDelta( $sql );
  79. flush_rewrite_rules(true);
  80. }
  81. public function query_vars($query_vars){
  82. $query_vars[] = 'visitors_edits_post_name';
  83. return $query_vars;
  84. }
  85. public function init(){
  86. add_rewrite_rule(
  87. '(.*)?/suggestions/?$',
  88. 'index.php?visitors_edits_post_name=$matches[1]',
  89. 'top'
  90. );
  91. }
  92. public function parse_request($request){
  93. if( isset( $request->query_vars['visitors_edits_post_name'] ) ):
  94. include( plugin_dir_path(__FILE__) . "/inc/editor.php" );
  95. exit();
  96. endif;
  97. return $request;
  98. }
  99. public function tinymce_btns($buttons){
  100. if(isset($_GET["page"]) && $_GET["page"]==="visitors_edits_approve"){
  101. array_push($buttons,'|','visitors_edits_approve','visitors_edits_reject','visitors_edits_clean');
  102. }
  103. return $buttons;
  104. }
  105. public function tinymce_scripts($plugin_array){
  106. $plugin_array['visitors_edits'] = plugins_url( 'js/approve.js',__FILE__ );
  107. return $plugin_array;
  108. }
  109. static function scriptUrl($script){
  110. return plugins_url( 'js/'.$script.'.js',__FILE__);
  111. }
  112. }
  113. new visitors_edits();
  114. use Caxy\HtmlDiff\HtmlDiff;
  115. use PHPHtmlParser\Dom;
  116. function visitors_editsDIFF($oldHtml,$newHtml){
  117. require "vendor/autoload.php";
  118. $htmlDiff = new HtmlDiff($oldHtml, $newHtml);
  119. $htmlDiff->getConfig()->setGroupDiffs(false);
  120. return $htmlDiff->build();
  121. }
  122. function visitors_editsDOM(){
  123. return new Dom;
  124. }
  125. ?>