bpModInstaller

BpModInstaller.

Defined (1)

The class is defined in the following location(s).

/classes/bpModInstaller.php  
  1. class bpModInstaller extends bpModAbstractCore 
  2. /** 
  3. * Run on activation 
  4. */ 
  5. function activate() 
  6. #$this->checkCompatibleOrFail(); 
  7.  
  8. /** 
  9. * Run on deactivation 
  10. */ 
  11. function deactivate() 
  12. $opts = get_site_option('bp_moderation_options'); 
  13. if (isset($opts['clean_up']) && 'on' == $opts['clean_up']) { 
  14. $this->clean_up(); 
  15.  
  16. /** 
  17. * Install/upgrade db tables, options... 
  18. */ 
  19. function install() 
  20. /***** CREATE/UPDATE DB *****/ 
  21. global $wpdb; 
  22.  
  23. $charset_collate = ''; 
  24. if (!empty($wpdb->charset)) { 
  25. $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 
  26. if (!empty($wpdb->collate)) { 
  27. $charset_collate .= " COLLATE $wpdb->collate"; 
  28.  
  29. $sql = array(); 
  30. $stati_set = "'" . join("', '", array_keys($this->content_stati)) . "'"; 
  31. $sql[] = "CREATE TABLE {$this->contents_table} ( 
  32. `content_id` BIGINT(20) unsigned NOT NULL auto_increment,  
  33. `item_type` VARCHAR(42) NOT NULL default '',  
  34. `item_id` BIGINT(20) unsigned NOT NULL default 0,  
  35. `item_id2` BIGINT(20) unsigned NOT NULL default 0,  
  36. `item_author` BIGINT(20) unsigned NOT NULL default 0,  
  37. `item_date` DATETIME NOT NULL default '0000-00-00 00:00:00',  
  38. `item_url` VARCHAR(250) NOT NULL default '',  
  39. `status` ENUM($stati_set) NOT NULL default 'new',  
  40. PRIMARY KEY (content_id),  
  41. KEY item_type (item_type),  
  42. KEY item_id (item_id),  
  43. KEY item_id2 (item_id2),  
  44. KEY item_author (item_author),  
  45. KEY item_date (item_date),  
  46. KEY status (status) 
  47. ) {$charset_collate};"; 
  48.  
  49. $sql[] = "CREATE TABLE {$this->flags_table} ( 
  50. `flag_id` BIGINT(20) unsigned NOT NULL auto_increment,  
  51. `content_id` BIGINT(20) unsigned NOT NULL default 0,  
  52. `reporter_id` BIGINT(20) unsigned NOT NULL default 0,  
  53. `date` DATETIME NOT NULL default '0000-00-00 00:00:00',  
  54. PRIMARY KEY (flag_id),  
  55. KEY content_id (content_id),  
  56. KEY reporter_id (reporter_id),  
  57. KEY date (date) 
  58. ) {$charset_collate};"; 
  59.  
  60. require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
  61.  
  62. dbDelta($sql); 
  63. /*** DB OK ***/ 
  64.  
  65. /***** SET/UPDATE OPTIONS *****/ 
  66. $options = get_site_option('bp_moderation_options'); 
  67.  
  68. // if options didn't exist set it as an empty array 
  69. $options or $options = array(); 
  70.  
  71. // activate types if first install, otherwise leave active_types as before 
  72. if (!get_site_option('bp_moderation_db_version')) { 
  73. $options['active_types'] = array_fill_keys(array('status_update', 'activity_comment', 'blog_post', 'blog_comment', 'member', 'group', 'forum_post'), 'on'); 
  74.  
  75. $def_options = array( 
  76. 'unflagged_text' => __('Flag', 'bp-moderation'),  
  77. 'flagged_text' => __('Unflag', 'bp-moderation'),  
  78. 'warning_threshold' => 5,  
  79. 'warning_forward' => get_option('admin_email'),  
  80. 'warning_message' => __(<<< TXT 
  81. Several user reported one of your content as inappropriate. 
  82. You can see the content in the page: %CONTENTURL%. 
  83. You posted this content with the account "%AUTHORNAME%". 
  84.  
  85. A community moderator will soon review and moderate this content if necessary. 
  86. -------------------- 
  87. [%SITENAME%] %SITEURL% 
  88. TXT 
  89. , 'bp-moderation'),  
  90. 'delete_threshold' => 0,  
  91. ); 
  92.  
  93. $options = array_merge($def_options, $options); 
  94.  
  95. update_site_option('bp_moderation_options', $options); 
  96. /*** OPTIONS OK ***/ 
  97.  
  98. update_site_option('bp_moderation_db_version', $this->db_ver); 
  99.  
  100. /** 
  101. * Remove any trace of bp-moderation installation 
  102. */ 
  103. function clean_up() 
  104. delete_site_option('bp_moderation_db_version'); 
  105.  
  106. global $wpdb; 
  107. $wpdb->query("DROP TABLE {$this->contents_table}"); 
  108. $wpdb->query("DROP TABLE {$this->flags_table}"); 
  109.  
  110. delete_site_option('bp_moderation_options'); 
  111.  
  112. /** 
  113. * Check compatibility and display an error message displayed when trying 
  114. * to activate on non compatible envoriment 
  115. */ 
  116. function checkCompatibleOrFail() 
  117. $wpv = $GLOBALS['wp_version']; 
  118. $wpr = $this->min_wp_ver; 
  119. $bpv = @constant('BP_VERSION'); 
  120. $bpr = $this->min_bp_ver; 
  121.  
  122. $failmessage = ''; 
  123.  
  124. if (version_compare($wpv, $wpr, '<')) { 
  125. $failmessage .= sprintf(__('You are using WordPress %s, please upgrade.', 'bp-moderation'), $wpv).'<br/>'; 
  126. if (!$bpv) { 
  127. $failmessage .= __(' Please install <a href="http://buddypress.org/" target="_blank" >Buddypress</a>.', 'bp-moderation').'<br/>'; 
  128. } elseif (version_compare($bpv, $bpr, '<')) { 
  129. $failmessage .= sprintf(__('You are using BuddyPress %s, please upgrade.', 'bp-moderation'), $bpv).'<br/>'; 
  130.  
  131. if (!$failmessage) { 
  132. return; 
  133.  
  134. $failmessage = sprintf(__('BuddyPress Moderation require at least WordPress %1$s and BuddyPress %2$s to work.',  
  135. 'bp-moderation'), $wpr, $bpr) .'<br/>'. $failmessage; 
  136.  
  137. include_once (ABSPATH . 'wp-admin/includes/plugin.php'); 
  138. deactivate_plugins(bpModLoader::file()); 
  139. die($failmessage);