Changeset 654 for plugins/preapproved/trunk/preapproved.plugin.php
- Timestamp:
- 06/29/08 04:45:56 (5 months ago)
- Files:
-
- 1 modified
-
plugins/preapproved/trunk/preapproved.plugin.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins/preapproved/trunk/preapproved.plugin.php
r6 r654 1 1 <?php 2 2 3 /* *3 /* 4 4 * PreApproved Class 5 5 * 6 * This class allows us to auto-approve previously approved commenters6 * This class allows us to auto-approve comments 7 7 * 8 * */8 */ 9 9 10 10 class PreApproved extends Plugin 11 11 { 12 /* *12 /* 13 13 * function info 14 14 * Returns information about this plugin 15 15 * @return array Plugin info array 16 * */16 */ 17 17 function info() 18 18 { … … 22 22 'author' => 'Habari Community', 23 23 'authorurl' => 'http://habariproject.org/', 24 'version' => '1. 1',25 'description' => 'Automatically approve comment ers that have approved comments in the database.',24 'version' => '1.2', 25 'description' => 'Automatically approve comments based on the number of approved comments the commenter has previously made.', 26 26 'license' => 'Apache License 2.0', 27 27 ); 28 28 } 29 30 /* *29 30 /* 31 31 * Register the PreApproved event type with the event log 32 */ 33 public function action_plugin_activation( $file ) { 32 */ 33 public function action_plugin_activation( $file ) 34 { 34 35 if ( realpath( $file ) == __FILE__ ) { 35 36 EventLog::register_type( 'PreApproved' ); 37 if( !(Options::get( 'preapproved__approved_count' ) ) ) { 38 Options::set( 'preapproved__approved_count', 1 ); 39 } 36 40 } 37 41 } 38 39 /* *40 * Unregister the PreApproved event type on deactivation 41 * @todo Should we be doing this?42 */43 public function action_plugin_deactivation( $file ){42 43 /* 44 * Unregister the PreApproved event type on deactivation if it isn't being used 45 */ 46 public function action_plugin_deactivation( $file ) 47 { 44 48 if ( realpath( $file ) == __FILE__ ) { 45 49 EventLog::unregister_type( 'PreApproved' ); 46 50 } 47 51 } 48 49 /** 52 53 public function filter_plugin_config($actions, $plugin_id) 54 { 55 if ($plugin_id == $this->plugin_id()) { 56 $actions[] = _t( 'Configure' ); 57 } 58 return $actions; 59 } 60 61 public function action_plugin_ui($plugin_id, $action) 62 { 63 if ( $plugin_id == $this->plugin_id() ) { 64 switch ($action) { 65 case _t( 'Configure' ): 66 $form= new FormUI( 'preapproved' ); 67 $form->append( 'text', 'approved_count', 'option:preapproved__approved_count', _t( 'Required number of approved comments: ' ) ); 68 $form->approved_count->add_validator( array( $this, 'validate_integer' ) ); 69 $form->append( 'submit', 'save', _t( 'Save' ) ); 70 $form->out(); 71 break; 72 } 73 } 74 } 75 76 /* 50 77 * function act_comment_insert_before 51 78 * This function is executed when the action "comment_insert_before" 52 79 * is invoked from a Comment object. 53 80 * The parent class, Plugin, handles registering the action 54 * and hook name using the name of the function to determine 81 * and hook name using the name of the function to determine coun 55 82 * where it will be applied. 56 83 * You can still register functions as hooks without using … … 58 85 * @param Comment The comment that will be processed before storing it in the database. 59 86 * @return Comment The comment result to store. 60 **/ 61 function action_comment_insert_before ( $comment ) { 87 */ 88 function action_comment_insert_before ( $comment ) 89 { 62 90 // This plugin ignores non-comments 63 if( $comment->type != Comment::COMMENT ) { 64 return $comment; 91 if( $comment->type == Comment::COMMENT ) { 92 if( Comments::get( array( 'email' => $comment->email, 'name' => $comment->name, 93 'url' => $comment->url, 'status' => Comment::STATUS_APPROVED ) )->count >= Options::get( 'preapproved__approved_count' ) ) { 94 $comment->status = Comment::STATUS_APPROVED; 95 EventLog::log( 'Comment by ' . $comment->name . ' automatically approved.', 'info', 'PreApproved', 'Preapproved' ); 96 } 65 97 } 66 67 // <script> is bad, mmmkay? 68 $comment->content = InputFilter::filter( $comment->content ); 98 return $comment; 99 } 69 100 70 if( Comments::get( array( 'email' => $comment->email, 'name' => $comment->name, 71 'url' => $comment->url, 'status' => Comment::STATUS_APPROVED ) )->count ) { 72 $comment->status = Comment::STATUS_APPROVED; 73 EventLog::log( 'Comment by ' . $comment->name . ' automatically approved.', 'info', 'comment', 'preapproved' ); 74 } 75 return; 76 } 77 78 function set_priorities() { 101 function set_priorities() 102 { 79 103 return array( 'action_comment_insert_before' => 10 ); 80 104 } 81 82 /** 83 * Add update beacon support 84 **/ 85 86 function action_update_check() { 87 Update::add( 'PreApproved', '0fa22c74-a0d6-11dc-8314-0800200c9a66', $this->info->version ); 88 } 105 106 /* 107 * Add update beacon support 108 */ 109 function action_update_check() 110 { 111 Update::add( 'PreApproved', '0fa22c74-a0d6-11dc-8314-0800200c9a66', $this->info->version ); 112 } 113 114 /* 115 * A validation function that returns an error if the value passed in is not an integer 116 * 117 * @param string $value A value to test if it is an integer 118 * @param formcontrol $control The control containing the value 119 * @param formui $form The form containing the control 120 * @return array An empty array if the value is an integer or an array with strings describing the errors 121 */ 122 function validate_integer( $value, $control, $form ) 123 { 124 if( !ctype_digit( $value ) ) { 125 return array( _t( 'Please enter a valid positive integer.' ) ); 126 } 127 $val = intval( $value ); 128 if( !is_int( $val ) ) { 129 return array( _t( 'Please enter a valid positive integer.' ) ); 130 } 131 return array(); 132 } 133 89 134 } 90 135 ?>
