bpModeration

Contains vars and methods shared by frontend/backend/actions but not installer.

Defined (1)

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

/classes/bpModeration.php  
  1. class bpModeration extends bpModAbstractCore 
  2.  
  3. /** 
  4. * Full URL to the plugin 
  5. * @var string 
  6. */ 
  7. var $plugin_url; 
  8.  
  9. /** 
  10. * Contains supported content types and info about them 
  11. * @var array 
  12. */ 
  13. var $content_types = array(); 
  14.  
  15. /** 
  16. * Maps activities 'type' to corresponding 'item_type' used in this plugin 
  17. * @var array 
  18. */ 
  19. var $types_map = array(); 
  20.  
  21. /** 
  22. * contains stored options for this plugin 
  23. * @var array 
  24. */ 
  25. var $options; 
  26.  
  27. function __construct() 
  28. parent::__construct(); 
  29.  
  30. $this->plugin_url = plugins_url('', bpModLoader::file()); 
  31.  
  32. $this->options = get_site_option('bp_moderation_options'); 
  33.  
  34. /** 
  35. * function to easily create nonces that depends on multiple parameters 
  36. * pass as many parameters needed to identify an action 
  37. * @return <string> the generated nonce or false on failure 
  38. */ 
  39. function create_nonce() 
  40. $args = func_get_args(); 
  41. if (!$key = call_user_func_array(array(__CLASS__, '_nonce_key'), $args)) { 
  42. return $key; 
  43.  
  44. return wp_create_nonce($key); 
  45.  
  46. /** 
  47. * function to easily verify nonces created with create_nonce method of this class 
  48. * pass same parameters passed to create_nonce 
  49. * the nonce must be in _wpnonce in get or post request 
  50. * @return <boolean> true if parameters and nonce are valid 
  51. */ 
  52. function verify_nonce() 
  53. $args = func_get_args(); 
  54. if (!$key = call_user_func_array(array(__CLASS__, '_nonce_key'), $args)) { 
  55. return $key; 
  56.  
  57. $nonce = $_REQUEST['_wpnonce']; 
  58.  
  59. return wp_verify_nonce($nonce, $key); 
  60.  
  61. /** 
  62. * internal method used by create_nonce and verify_nonce 
  63. * @return <string> the nonce 'action' that depends on given parameters 
  64. */ 
  65. function _nonce_key() 
  66. if (0 == func_num_args()) { 
  67. return false; 
  68.  
  69. $args = func_get_args(); 
  70.  
  71. $key = join('_', $args); 
  72.  
  73. return 'bp_moderation_' . $key; 
  74.  
  75. /** 
  76. * why $_istance is an array? Zend 1 engine (php4) can't store a reference in 
  77. * a static var, but can store it as a value of a static array 
  78. */ 
  79. function &get_istance($cname = false) 
  80. static $_instance = null; 
  81.  
  82. if (null === $_instance && $cname) { 
  83.  
  84. bpModLoader::load_class($cname); 
  85. $ref = & new $cname; 
  86.  
  87. $_instance = array(&$ref); 
  88.  
  89. return $_instance[0]; 
  90.  
  91. /** 
  92. * for getting proprierties from outside a bpModeration child 
  93. */ 
  94. function get_property($name) 
  95. $_this = & bpModeration::get_istance(); 
  96.  
  97. if (isset($_this->$name)) { 
  98. return $_this->$name; 
  99. else 
  100. return null; 
  101.  
  102. /** 
  103. * for getting options from outside a bpModeration child 
  104. */ 
  105. function get_option($name) 
  106. $_this = & bpModeration::get_istance(); 
  107.  
  108. if (isset($_this->options[$name])) { 
  109. return $_this->options[$name]; 
  110. else 
  111. return null; 
  112.  
  113. /** 
  114. * Use this function to register a content type not supported by default 
  115. * You must provides some callbacks for the content type to be handled by the plugin: 
  116. * - init : takes no args and returns void, it is called on frontend when this content 
  117. * type is active use it to hook around your link generation functions 
  118. * - info : takes id and id2 as args, returns false if no content correspond to those ids,  
  119. * otherwise an array in this format: 
  120. * author => [the content author ID] 
  121. * url => [the content permalink] 
  122. * date => [the content generation date, in mysql DATETIME format] 
  123. * - delete : (optional) takes id and id2 as args, takes care of 
  124. * 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. 
  125. * - edit : (optional) takes id and id2 as args, returns the url of 
  126. * the page where the admin can edit the specified content 
  127. * If the registered content is also present in the activity stream then you should 
  128. * provide an array of activity types that this content can be posted with, the 
  129. * plugin will take care of displaying the flag/unflag link in the activity stream 
  130. * id and secondary id that you provide to the activity component must coincide with those 
  131. * you provide to this plugin 
  132. * @param string $slug internal slug, used to differentiate between content types (alfanumeric and underscore only) 
  133. * @param string $label how this content type is called in the backend 
  134. * @param array $callbacks associative array of callbacks, see function description for mandatory and supported callbacks 
  135. * @param array $activity_types activity types that correspond to this content type 
  136. * @return bool false if passed args are invalid 
  137. */ 
  138. function register_content_type($slug, $label, $callbacks, $activity_types = null) 
  139. $_this = & bpModeration::get_istance(); 
  140.  
  141. if (!$slug || !$label || !is_array($callbacks) || !is_callable($callbacks['info'])) { 
  142. return false; 
  143.  
  144. $callbacks = array_merge( 
  145. array('init' => false, 'info' => false, 'delete' => false, 'editurl' => false), $callbacks 
  146. ); 
  147.  
  148. $ct = new stdClass(); 
  149. $ct->label = $label; 
  150. $ct->callbacks = $callbacks; 
  151.  
  152. $_this->content_types[$slug] = $ct; 
  153.  
  154. if (empty($_this->options['active_types'][$slug])) { 
  155. return true; 
  156.  
  157. if (is_callable($callbacks['init'])) { 
  158. call_user_func($callbacks['init']); 
  159.  
  160. foreach ((array)$activity_types as $act_type) 
  161. $_this->types_map[$act_type] = $slug; 
  162.  
  163. return true; 
  164.