Changeset 604 for plugins/Lipsum/trunk/lipsum.plugin.php
- Timestamp:
- 06/16/08 23:36:13 (7 months ago)
- Files:
-
- 1 modified
-
plugins/Lipsum/trunk/lipsum.plugin.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
plugins/Lipsum/trunk/lipsum.plugin.php
r597 r604 37 37 { 38 38 if ( $this->plugin_id() == $plugin_id ){ 39 $actions = array( 'Configure','Delete All Posts');39 $actions[]= 'Configure'; 40 40 } 41 41 return $actions; … … 50 50 public function action_plugin_ui( $plugin_id, $action ) 51 51 { 52 if ( $this->plugin_id()==$plugin_id ) 53 { 54 switch ($action){ 55 case 'Configure': 56 $form= new FormUI( strtolower(get_class( $this ) ) ); 57 $form->append( 'text', 'num_posts', 'option:lipsum__num_posts', _t('Number of posts to add: ') ); 58 //$form->num_posts->add_validator( 'validate_required' ); 59 $form->append( 'text', 'duration', 'option:lipsum__duration', _t('Duration between posts (in seconds): ') ); 60 //$form->duration->add_validator( 'validate_required' ); 61 $form->append( 'text', 'min_tags', 'option:lipsum__min_tags', _t('Minimum tags per post: ') ); 62 $form->append( 'text', 'max_tags', 'option:lipsum__max_tags', _t('Maximum tags per post: ') ); 63 $form->append( 'submit', 'add', _t( 'Add Posts' ) ); 64 $form->on_success( array( $this, 'update_num_posts' ) ); 65 $form->out(); 66 break; 67 68 case 'Delete All Posts': 69 $this->delete_all(); 70 break; 71 } 72 } 73 } 52 if ( $this->plugin_id()==$plugin_id && $action=='Configure' ) 53 { 54 $form= new FormUI( strtolower(get_class( $this ) ) ); 55 $form->append( 'text', 'num_posts', 'option:lipsum__num_posts', _t('Number of posts to create:'), '20'); 56 $form->num_posts->add_validator( 'validate_required' ); 57 $form->append( 'submit', 'save', _t( 'Save' ) ); 58 $form->on_success( array( $this, 'update_num_posts' ) ); 59 $form->out(); 60 } 61 } 74 62 75 63 function action_plugin_activation( $file ) … … 93 81 $num_posts= 20; 94 82 } 95 96 $duration= Options::get( 'lipsum__duration' ); 97 if ( ! $duration ) { 98 Options::set( 'lipsum__duration', 3600); 99 $duration= 3600; 100 } 101 83 102 84 for($z = 0; $z < $num_posts; $z++) { 103 $time = $time - $duration; 104 $this->make_post( $user, $time, $tags ); 85 $this->make_post( $user, $time ); 105 86 } 106 87 … … 127 108 $num_posts= $form->num_posts->value; 128 109 $num_posts= is_numeric($num_posts) ? (int) $num_posts : 20; 129 $duration= $form->duration->value; 130 $duration= is_numeric($duration) ? (int) $duration : 3600; 131 $min_tags= $form->min_tags->value; 132 $min_tags= is_numeric($min_tags) ? (int) $min_tags : 1; 133 $min_tags= $form->min_tags->value; 134 $max_tags= is_numeric($max_tags) ? (int) $max_tags : 5; 135 136 /* 110 137 111 $current_count= (int) Posts::get( array( 'info' => array( 'lipsum' => true ), 'count' => true ) ); 138 112 … … 153 127 // otherwise, we need to add some posts 154 128 else { 155 */156 129 $user= User::get_by_name( 'lipsum' ); 157 130 $time = time() - 160; 158 131 $count= 0; 159 132 for ( $i= $current_count + 1; $i <= $num_posts; $i++ ) { 160 $time = $time - $duration;161 133 $this->make_post( $user, $time ); 162 134 $count++; 163 135 } 164 136 Session::notice( "Created {$count} sample posts with random comments."); 165 //}137 } 166 138 167 139 // return the form to redisplay it … … 176 148 * @param timestamp $time The published timestamp of the new posts 177 149 */ 178 private function make_post( $user, $time , $tags)150 private function make_post( $user, $time ) 179 151 { 180 152 $post = Post::create(array( … … 225 197 } 226 198 227 private function random_tags($min, $max)228 {229 $thetags = array('lipsum','met','erat','ipsum','non','dignissim','egestas','metus','quis','iaculis','porttitor','malesuada','vel');230 231 }232 233 234 199 private function num2word($i) 235 200 { … … 329 294 } 330 295 331 private function delete_all() 332 { 333 set_time_limit(0); 334 $posts = Posts::get(array('info'=>array('lipsum' => true), 'nolimit'=>true)); 335 $count = 0; 336 foreach($posts as $post) { 337 $post->delete(); 338 $count++; 339 } 340 Session::notice("Removed {$count} sample posts and their comments."); 341 } 296 342 297 343 298 }
