Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * bpModBackend constructor
  *
  * hooks in wordpress backend
  */
 function __construct()
 {
     parent::__construct();
     add_action(is_multisite() ? 'network_admin_menu' : 'admin_menu', array(&$this, 'add_admin_menu'));
     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'));
     }
 }
Exemplo n.º 3
0
 /**
  * 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('contents_table');
     $this->__obj_name = 'bp_moderation_content';
     $this->__id_field = 'content_id';
     $this->__fields_format['item_type'] = '%s';
     $this->__fields_format['item_id'] = '%d';
     $this->__fields_format['item_id2'] = '%d';
     $this->__fields_format['item_author'] = '%d';
     $this->__fields_format['item_url'] = '%s';
     $this->__fields_format['item_date'] = '%s';
     $this->__fields_format['status'] = '%s';
     parent::__construct($id);
 }
 /**
  * Initialize this content type
  *
  * register content type in bp-moderation (needs to be done at every pageload)
  *
  * If this content type needed to place some hooks no matter if it was active or not
  * this would be the right place, instead hooks needed only when it is active
  * are in bpMod_ContentType_BlogPostExample::init()
  *
  * @return bool if successfully initialized
  */
 function bootstrap()
 {
     //check if bpModeration exists, especially the method to register content types that will be used just below
     if (!method_exists('bpModeration', 'register_content_type')) {
         return false;
     }
     // internal slug used by bp-moderation to differentiate between content types (alfanumeric and underscore only)
     $slug = 'blog_post_example';
     // this is how content of this type get called in the backend
     $label = __('Blog post example', 'your-text-domain');
     //callbacks are used when some information/operation is needed, see documentation of each one
     $callbacks = array('info' => array(__CLASS__, 'info'), 'init' => array(__CLASS__, 'init'), 'edit' => array(__CLASS__, 'edit'), 'delete' => array(__CLASS__, 'delete'));
     //bp-moderation can automatically put the flag button in activities generated from this content type, but needs to know what is their activity type
     $activity_types = array('new_blog_post');
     //register this content type in bp-moderation
     return bpModeration::register_content_type($slug, $label, $callbacks, $activity_types);
 }
Exemplo n.º 5
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'));
     }
 }
Exemplo n.º 6
0
 /**
  * Use this function to register a content type not supported by default
  *
  * You must provides some callbacks for the content type to be handled by the plugin:
  * - init : takes no args and returns void, it is called on frontend when this content
  *		 type is active use it to hook around your link generation functions
  * - info : takes id and id2 as args, returns false if no content correspond to those ids,
  *		 otherwise an array in this format:
  *			 author => [the content author ID]
  *			 url	=> [the content permalink]
  *			 date   => [the content generation date, in mysql DATETIME format]
  * - delete : (optional) takes id and id2 as args, takes care of
  *		 deleting specified content; returns true if deleted or if it doesn't exist, false if the content exist but wasn't possible to delete it.
  * - edit : (optional) takes id and id2 as args, returns the url of
  *		 the page where the admin can edit the specified content
  *
  * If the registered content is also present in the activity stream then you should
  * provide an array of activity types that this content can be posted with, the
  * plugin will take care of displaying the flag/unflag link in the activity stream
  * id and secondary id that you provide to the activity component must coincide with those
  * you provide to this plugin
  *
  * @param string $slug internal slug, used to differentiate between content types (alfanumeric and underscore only)
  * @param string $label how this content type is called in the backend
  * @param array $callbacks associative array of callbacks, see function description for mandatory and supported callbacks
  * @param array $activity_types activity types that correspond to this content type
  * @return bool false if passed args are invalid
  */
 function register_content_type($slug, $label, $callbacks, $activity_types = null)
 {
     $_this =& bpModeration::get_istance();
     if (!$slug || !$label || !is_array($callbacks) || !is_callable($callbacks['info'])) {
         return false;
     }
     $callbacks = array_merge(array('init' => false, 'info' => false, 'delete' => false, 'editurl' => false), $callbacks);
     $ct = new stdClass();
     $ct->label = $label;
     $ct->callbacks = $callbacks;
     $_this->content_types[$slug] = $ct;
     if (empty($_this->options['active_types'][$slug])) {
         return true;
     }
     if (is_callable($callbacks['init'])) {
         call_user_func($callbacks['init']);
     }
     foreach ((array) $activity_types as $act_type) {
         $_this->types_map[$act_type] = $slug;
     }
     return true;
 }
Exemplo n.º 7
0
 function __construct()
 {
     parent::__construct();
     add_action('admin_init', array(&$this, 'route_action'));
 }
Exemplo n.º 8
0
 /**
  * Get flag/unflag link
  *
  * static method for getting a reporting link
  *
  * @see bpModFrontend::generate_link for args details
  */
 function get_link($args = '')
 {
     $_this =& bpModeration::get_istance();
     return $_this->generate_link($args);
 }
Exemplo n.º 9
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');
 }