Show
Ignore:
Timestamp:
06/16/08 23:36:13 (7 months ago)
Author:
dmondark
Message:

plugin:lipsum Reverting to the previous revision. The new additions will need to be implemented differently, it looks like we need to have the post count difference creation.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/Lipsum/trunk/lipsum.plugin.php

    r597 r604  
    3737    { 
    3838        if ( $this->plugin_id() == $plugin_id ){ 
    39             $actions= array( 'Configure','Delete All Posts');        
     39            $actions[]= 'Configure';         
    4040        } 
    4141        return $actions; 
     
    5050    public function action_plugin_ui( $plugin_id, $action ) 
    5151    { 
    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    } 
    7462 
    7563    function action_plugin_activation( $file ) 
     
    9381                $num_posts= 20; 
    9482            } 
    95              
    96             $duration= Options::get( 'lipsum__duration' ); 
    97             if ( ! $duration ) { 
    98                 Options::set( 'lipsum__duration', 3600); 
    99                 $duration= 3600; 
    100             } 
    101              
     83 
    10284            for($z = 0; $z < $num_posts; $z++) { 
    103                 $time = $time - $duration; 
    104                 $this->make_post( $user, $time, $tags ); 
     85                $this->make_post( $user, $time ); 
    10586            } 
    10687 
     
    127108        $num_posts= $form->num_posts->value; 
    128109        $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 
    137111        $current_count= (int) Posts::get( array( 'info' => array( 'lipsum' => true ), 'count' => true ) ); 
    138112 
     
    153127        // otherwise, we need to add some posts 
    154128        else { 
    155     */ 
    156129            $user= User::get_by_name( 'lipsum' ); 
    157130            $time = time() - 160; 
    158131            $count= 0; 
    159132            for ( $i= $current_count + 1; $i <= $num_posts; $i++ ) { 
    160                 $time = $time - $duration; 
    161133                $this->make_post( $user, $time ); 
    162134                $count++; 
    163135            } 
    164136            Session::notice( "Created {$count} sample posts with random comments."); 
    165         //} 
     137        } 
    166138 
    167139        // return the form to redisplay it 
     
    176148     * @param timestamp $time The published timestamp of the new posts 
    177149     */ 
    178     private function make_post( $user, $time, $tags ) 
     150    private function make_post( $user, $time ) 
    179151    { 
    180152        $post = Post::create(array( 
     
    225197    } 
    226198 
    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      
    234199    private function num2word($i) 
    235200    { 
     
    329294    } 
    330295 
    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 
    342297 
    343298}