bpModLoader

Loader for bp-moderation.

Defined (1)

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

/bpModLoader.php  
  1. class bpModLoader 
  2. /** 
  3. * hook the plugin in buddypress and in activation/deactivation 
  4. */ 
  5. function __construct() 
  6. $this->basename = plugin_basename(dirname(__FILE__)); 
  7.  
  8. add_action('bp_init', array($this, 'init')); 
  9.  
  10. register_activation_hook(__FILE__, array($this, 'call_activate')); 
  11.  
  12. register_deactivation_hook(__FILE__, array($this, 'call_deactivate')); 
  13.  
  14. /** 
  15. * Load needed class 
  16. */ 
  17. function init() 
  18. if (is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) { 
  19. // if this is an admin page and the current user is not a site admin then the plugin doesn't load at all 
  20. if (!is_super_admin()) { 
  21. return; 
  22.  
  23. if (!empty($_REQUEST['bpmod-action'])) { 
  24. $mainclass = 'bpModBackendActions'; 
  25. } else { 
  26. $mainclass = 'bpModBackend'; 
  27. } else { 
  28. if (!empty($_REQUEST['bpmod-action']) || 'bpmodfrontend' === $_REQUEST['action']) { 
  29. $mainclass = 'bpModActions'; 
  30. } else { 
  31. $mainclass = 'bpModFrontend'; 
  32.  
  33. $this->loadL10n(); 
  34.  
  35. //create an istance of the main class for this situation 
  36. bpModLoader::load_class('bpModeration'); 
  37. $bpMod =& bpModeration::get_istance($mainclass); 
  38.  
  39. //load the default content types 
  40. bpModLoader::load_class('bpModDefaultContentTypes'); 
  41. bpModDefaultContentTypes::init($bpMod); 
  42.  
  43. do_action('bp_moderation_loaded', array(&$this)); 
  44.  
  45. do_action('bp_moderation_init', array(&$bpMod)); 
  46.  
  47. /** 
  48. * Load string translations 
  49. * will load the first translation found from: 
  50. * - wp-content/plugins/bp-moderation-xx_XX.mo 
  51. * - wp-content/plugins/bp-moderation/lang/bp-moderation-xx_XX.mo 
  52. * @return bool if a translation was found and loaded 
  53. */ 
  54. function loadL10n() { 
  55. return load_plugin_textdomain('bp-moderation') 
  56. || load_plugin_textdomain('bp-moderation', false, $this->basename.'/lang'); 
  57.  
  58. private function call_installer($method, $args = array()) 
  59. $this->loadL10n(); 
  60. bpModLoader::load_class('bpModInstaller'); 
  61. $installer = new bpModInstaller(); 
  62. call_user_func_array(array($installer, $method), $args); 
  63.  
  64. /** 
  65. * activation callback 
  66. */ 
  67. function call_activate() 
  68. $this->call_installer('activate', func_get_args()); 
  69.  
  70. /** 
  71. * deactivation callback 
  72. */ 
  73. function call_deactivate() 
  74. $this->call_installer('deactivate', func_get_args()); 
  75.  
  76. /** 
  77. * load a class 
  78. * @param string $cname classname 
  79. */ 
  80. function load_class($cname) 
  81. if (class_exists($cname)) { 
  82. return; 
  83.  
  84. require_once dirname(__FILE__) . '/classes/' . $cname . '.php'; 
  85.  
  86. /** 
  87. * bpModLoader file path 
  88. * @return string this file path 
  89. */ 
  90. static function file() 
  91. return __FILE__; 
  92.  
  93. /** 
  94. * generated random data 
  95. */ 
  96. function test_data() 
  97. set_time_limit(0); 
  98.  
  99. global $wpdb; 
  100. $users = $wpdb->get_col("SELECT ID FROM $wpdb->users WHERE ID != 1"); 
  101.  
  102. if (is_multisite()) { 
  103. $wpdb->query("DELETE FROM $wpdb->signups"); 
  104.  
  105. foreach ($users as $id) 
  106. bp_core_delete_account($id); 
  107.  
  108. $ngu = 2; #how much only good users 
  109. $ngbu = 2; #how much not only good or only bad users 
  110. $nbu = 2; #how much only bad users 
  111. $content_types = array('A', 'B', 'C', 'D'); 
  112.  
  113. $bpmod =& bpModeration::get_istance(); 
  114. $statuses = array_keys($bpmod->content_stati); 
  115. $n_contents = 20; 
  116. $flags_per_cont = 20; # +/- 30% 
  117.  
  118. $goodusers = array(); 
  119. $badusers = array(); 
  120.  
  121. for ($i = 1; $i <= $ngu + $ngbu + $nbu; $i++) { 
  122. $uid = bp_core_signup_user('user' . $i, 'pass', $i . '@foo.bar', array()); 
  123. if (is_multisite()) { 
  124. global $wpdb; 
  125. $key_sql = "SELECT activation_key FROM $wpdb->signups WHERE user_email = '" . $i . "@foo.bar'"; 
  126. $key = $wpdb->get_var($key_sql); 
  127. } else { 
  128. $key = get_user_meta($uid, 'activation_key'); 
  129.  
  130. $uid = bp_core_activate_signup($key); 
  131.  
  132. is_multisite() and 
  133. wp_set_password('pass', $uid); 
  134.  
  135. if ($i <= $ngu + $ngbu) { 
  136. $goodusers[] = $uid; 
  137. if ($i > $ngu) { 
  138. $badusers[] = $uid; 
  139.  
  140. bpModLoader::load_class('bpModObjContent'); 
  141. bpModLoader::load_class('bpModObjFlag'); 
  142.  
  143. for ($i = 1; $i <= $n_contents; $i++) { 
  144. $badu = $badusers[mt_rand(0, count($badusers) - 1)]; 
  145. $cont = new bpModObjContent(); 
  146. $cont->item_type = $content_types[mt_rand(0, count($content_types) - 1)]; 
  147. $cont->item_id = mt_rand(1, 1000000); 
  148. $cont->item_author = $badu; 
  149. $cont->item_date = gmdate("Y-m-d H:i:s", time() - mt_rand(1000000, 2000000)); 
  150. $cont->status = $statuses[mt_rand(0, count($statuses) - 1)]; 
  151. $cont->save(); 
  152.  
  153. $flags = mt_rand($flags_per_cont * 0.7, $flags_per_cont * 1.3); 
  154.  
  155. for ($j = 1; $j <= $flags; $j++) { 
  156. while ($badu == ($goodu = $goodusers[mt_rand(0, count($goodusers) - 1)])) { 
  157.  
  158. $f = new bpModObjFlag(); 
  159. $f->content_id = $cont->content_id; 
  160. $f->reporter_id = $goodu; 
  161. $f->date = gmdate("Y-m-d H:i:s", time() - mt_rand(0, 1000000)); 
  162. $f->save(); 
  163.  
  164.  
  165.  
  166. update_site_option('bp_moderation_test_data_check', 'success'); 
  167.