Ejemplo n.º 1
0
 /**
  * bpModBackend constructor
  *
  * hooks in wordpress backend
  */
 function __construct()
 {
     if (version_compare(get_site_option('bp_moderation_db_version'), $this->db_ver, '<')) {
         bpModLoader::load_class('bpModInstaller');
         $installer = new bpModInstaller();
         $installer->install();
     }
     parent::__construct();
     add_action(is_multisite() ? 'network_admin_menu' : 'admin_menu', array(&$this, 'add_admin_menu'));
     add_action('admin_head', array(&$this, 'print_page_icon_style'));
     add_action('rightnow_end', array(&$this, 'rightnow_widget_section'));
     add_action('admin_init', array(&$this, 'register_settings'));
     if (isset($this->options['generate_test_data'])) {
         unset($this->options['generate_test_data']);
         update_site_option('bp_moderation_options', $this->options);
         add_action('admin_init', array(bpModLoader, 'test_data'));
     }
 }
Ejemplo n.º 2
0
<?php

bpModLoader::load_class('bpModAbstractDBobj');
/**
 * Flag Database Object
 *
 * Use this class for get/insert/update/delete single raw from the flags table
 *
 * @see bpModAbstractDBobj
 */
class bpModObjFlag extends bpModAbstractDBobj
{
    /**
     * define proprierties and optionally get row
     *
     * @param bool|int $id id of the row to get from the db
     */
    function __construct($id = false)
    {
        $this->__table = bpModeration::get_property('flags_table');
        $this->__obj_name = 'bp_moderation_flag';
        $this->__id_field = 'flag_id';
        $this->__fields_format['content_id'] = '%d';
        $this->__fields_format['reporter_id'] = '%d';
        $this->__fields_format['date'] = '%s';
        parent::__construct($id);
    }
}
Ejemplo n.º 3
0
 /**
  * why $_istance is an array? Zend 1 engine (php4) can't store a reference in
  * a static var, but can store it as a value of a static array
  */
 function &get_istance($cname = false)
 {
     static $_instance = null;
     if (null === $_instance && $cname) {
         bpModLoader::load_class($cname);
         $ref =& new $cname();
         $_instance = array(&$ref);
     }
     return $_instance[0];
 }
Ejemplo n.º 4
0
 function change_content_status($new_status, $cont_id = null)
 {
     if (!$cont_id && !($cont_id = @$_REQUEST['cont_id'])) {
         return false;
     }
     bpModLoader::load_class('bpModObjContent');
     $cont = new bpModObjContent($cont_id);
     if (!$cont->content_id) {
         return false;
     }
     if ($new_status == $cont->status) {
         return true;
     }
     $old_status = $cont->status;
     $cont->status = $new_status;
     if (!$cont->save()) {
         return false;
     }
     $reporters = $this->get_content_reporters($cont->content_id);
     do_action("bp_moderation_content_{$new_status}", $cont->content_id, $cont, $reporters);
     do_action('bp_moderation_content_status_changed', $cont->content_id, $old_status, $new_status, $cont->item_author, $reporters, $cont);
     return true;
 }
Ejemplo n.º 5
0
 function unflag($type, $id, $id2, $reporter)
 {
     list($cont_id, $flag_id) = $this->check_flag($type, $id, $id2, $reporter);
     if (!$cont_id || !$flag_id) {
         return 'non flagged';
     }
     bpModLoader::load_class('bpModObjFlag');
     $flag = new bpModObjFlag($flag_id);
     if ($flag->delete()) {
         do_action_ref_array('bp_moderation_content_unflagged', array($type, $id, $id2, $reporter, $cont_id, &$flag));
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
<?php

//php4 helper: my little abstraction layer between php4 and php5
bpModLoader::load_class('bpModPHP4helper');
/**
 * Contains vars and methods shared by installer/frontend/backend/actions
 *
 * never create instance of this class directly
 *
 * @author Francesco
 */
class bpModAbstractCore extends bpModPHP4helper
{
    /**
     * BuddyPress Moderation version
     *
     * @var string
     */
    var $plugin_ver = '0.1.5';
    /**
     * database tables & options version
     *
     * needed to check if install/upgrade is needed or not on activation
     *
     * @var int
     */
    var $db_ver = -100;
    /**
     * required version of wordpress
     *
     * @var string
Ejemplo n.º 7
0
 /**
  * Check compatibility and display an error message displayed when trying
  * to activate on non compatible envoriment
  */
 function checkCompatibleOrFail()
 {
     $wpv = $GLOBALS['wp_version'];
     $wpr = $this->min_wp_ver;
     $bpv = @constant('BP_VERSION');
     $bpr = $this->min_bp_ver;
     $failmessage = '';
     if (version_compare($wpv, $wpr, '<')) {
         $failmessage .= sprintf(__('You are using WordPress %s, please upgrade.', 'bp-moderation'), $wpv) . '<br/>';
     }
     if (!$bpv) {
         $failmessage .= __(' Please install <a href="http://buddypress.org/" target="_blank" >Buddypress</a>.', 'bp-moderation') . '<br/>';
     } elseif (version_compare($bpv, $bpr, '<')) {
         $failmessage .= sprintf(__('You are using BuddyPress %s, please upgrade.', 'bp-moderation'), $bpv) . '<br/>';
     }
     if (!$failmessage) {
         return;
     }
     $failmessage = sprintf(__('BuddyPress Moderation require at least WordPress %1$s and BuddyPress %2$s to work.', 'bp-moderation'), $wpr, $bpr) . '<br/>' . $failmessage;
     include_once ABSPATH . 'wp-admin/includes/plugin.php';
     deactivate_plugins(bpModLoader::file());
     die($failmessage);
 }
Ejemplo n.º 8
0
 /**
  * generated random data
  */
 function test_data()
 {
     set_time_limit(0);
     global $wpdb;
     $users = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE ID != 1");
     if (is_multisite()) {
         $wpdb->query("DELETE FROM {$wpdb->signups}");
     }
     foreach ($users as $id) {
         bp_core_delete_account($id);
     }
     $ngu = 2;
     #how much only good users
     $ngbu = 2;
     #how much not only good or only bad users
     $nbu = 2;
     #how much only bad users
     $content_types = array('A', 'B', 'C', 'D');
     $bpmod =& bpModeration::get_istance();
     $statuses = array_keys($bpmod->content_stati);
     $n_contents = 20;
     $flags_per_cont = 20;
     # +/- 30%
     $goodusers = array();
     $badusers = array();
     for ($i = 1; $i <= $ngu + $ngbu + $nbu; $i++) {
         $uid = bp_core_signup_user('user' . $i, 'pass', $i . '@foo.bar', array());
         if (is_multisite()) {
             global $wpdb;
             $key_sql = "SELECT activation_key FROM {$wpdb->signups} WHERE user_email = '" . $i . "@foo.bar'";
             $key = $wpdb->get_var($key_sql);
         } else {
             $key = get_user_meta($uid, 'activation_key');
         }
         $uid = bp_core_activate_signup($key);
         is_multisite() and wp_set_password('pass', $uid);
         if ($i <= $ngu + $ngbu) {
             $goodusers[] = $uid;
         }
         if ($i > $ngu) {
             $badusers[] = $uid;
         }
     }
     bpModLoader::load_class('bpModObjContent');
     bpModLoader::load_class('bpModObjFlag');
     for ($i = 1; $i <= $n_contents; $i++) {
         $badu = $badusers[mt_rand(0, count($badusers) - 1)];
         $cont = new bpModObjContent();
         $cont->item_type = $content_types[mt_rand(0, count($content_types) - 1)];
         $cont->item_id = mt_rand(1, 1000000);
         $cont->item_author = $badu;
         $cont->item_date = gmdate("Y-m-d H:i:s", time() - mt_rand(1000000, 2000000));
         $cont->status = $statuses[mt_rand(0, count($statuses) - 1)];
         $cont->save();
         $flags = mt_rand($flags_per_cont * 0.7, $flags_per_cont * 1.3);
         for ($j = 1; $j <= $flags; $j++) {
             while ($badu == ($goodu = $goodusers[mt_rand(0, count($goodusers) - 1)])) {
             }
             $f = new bpModObjFlag();
             $f->content_id = $cont->content_id;
             $f->reporter_id = $goodu;
             $f->date = gmdate("Y-m-d H:i:s", time() - mt_rand(0, 1000000));
             $f->save();
         }
     }
     update_site_option('bp_moderation_test_data_check', 'success');
 }