Changeset 639

Show
Ignore:
Timestamp:
2008-06-25 05:47:56 (2 months ago)
Author:
michaeltwofish
Message:

Fixes to the SQLite schema.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/blogroll/trunk/blogroll.plugin.php

    r521 r639  
    22/* 
    33 * Blogroll Plugin 
    4  * Usage: <?php $theme->show_blogroll(); ?>  
    5  * A sample blogroll.php template is included with the plugin.  This can be copied to your  
     4 * Usage: <?php $theme->show_blogroll(); ?> 
     5 * A sample blogroll.php template is included with the plugin.  This can be copied to your 
    66 * active theme and modified to fit your preference. 
    77 * 
     
    2020    const VERSION= '0.5-beta'; 
    2121    const DB_VERSION= 003; 
    22      
     22 
    2323    public function info() 
    2424    { 
    2525        return array( 
    26         'name' => 'Blogroll', 
    27         'version' => self::VERSION, 
    28         'url' => 'http://wiki.habariproject.org/en/plugins/blogroll', 
    29         'author' => 'Habari Community', 
    30         'authorurl' => 'http://habariproject.org/', 
    31         'license' => 'Apache License 2.0', 
    32         'description' => 'Displays a blogroll on your blog' 
     26            'name' => 'Blogroll', 
     27            'version' => self::VERSION, 
     28            'url' => 'http://wiki.habariproject.org/en/plugins/blogroll', 
     29            'author' => 'Habari Community', 
     30            'authorurl' => 'http://habariproject.org/', 
     31            'license' => 'Apache License 2.0', 
     32            'description' => 'Displays a blogroll on your blog' 
    3333        ); 
    3434    } 
    35      
     35 
    3636    public function action_plugin_activation( $file ) 
    3737    { 
     
    4040            DB::register_table( 'bloginfo' ); 
    4141            DB::register_table( 'tag2blog' ); 
    42              
     42 
    4343            if ( ! CronTab::get_cronjob( 'blogroll:update' ) ) { 
    4444                CronTab::add_hourly_cron( 'blogroll:update', 'blogroll_update_cron', 'Updates the blog updated timestamp from weblogs.com' ); 
    4545            } 
    46              
     46 
    4747            Options::set( 'blogroll__db_version', self::DB_VERSION ); 
    4848            Options::set( 'blogroll__use_updated', true ); 
     
    5151            Options::set( 'blogroll__direction', 'ASC' ); 
    5252            Options::set( 'blogroll__list_title', 'Blogroll' ); 
    53              
     53 
    5454            if ( $this->install_db_tables() ) { 
    5555                Session::notice( _t( 'Created the Blogroll database tables.', 'blogroll' ) ); 
     
    6060        } 
    6161    } 
    62      
     62 
    6363    public function action_plugin_deactivation( $file ) 
    6464    { 
     
    6868        } 
    6969    } 
    70      
     70 
    7171    public function install_db_tables() 
    7272    { 
     
    107107                updated VARCHAR(12) NOT NULL, 
    108108                rel VARCHAR(255) NOT NULL, 
    109                 description TEXT, 
     109                description TEXT 
    110110                ); 
    111111                CREATE TABLE " . DB::table('bloginfo') . " ( 
     
    119119                tag_id INTEGER UNSIGNED NOT NULL, 
    120120                blog_id INTEGER UNSIGNED NOT NULL, 
    121                 PRIMARY KEY (tag_id, post_id) 
     121                PRIMARY KEY (tag_id, blog_id) 
    122122                ); 
    123123                CREATE INDEX IF NOT EXISTS tag2blog_blog_id ON " . DB::table('tag2blog') . "(blog_id);"; 
     
    126126        return DB::dbdelta( $schema ); 
    127127    } 
    128      
     128 
    129129    public function action_update_check() 
    130130    { 
    131131        Update::add( 'blogroll', '0420cf10-db83-11dc-95ff-0800200c9a66',  $this->info->version ); 
    132132    } 
    133      
     133 
    134134    public function action_init() 
    135135    { 
     
    137137        DB::register_table( 'bloginfo' ); 
    138138        DB::register_table( 'tag2blog' ); 
    139          
     139 
    140140        if ( Options::get( 'blogroll__db_version' ) && self::DB_VERSION > Options::get( 'blogroll__db_version' ) ) { 
    141141            $this->install_db_tables(); 
     
    144144        } 
    145145    } 
    146      
     146 
    147147    public function filter_plugin_config( $actions, $plugin_id ) 
    148148    { 
    149          
     149 
    150150        if ( $this->plugin_id() == $plugin_id ){ 
    151151            $actions[]= _t( 'Configure', 'blogroll' ); 
     
    153153        return $actions; 
    154154    } 
    155      
     155 
    156156    public function action_plugin_ui( $plugin_id, $action ) 
    157157    { 
     
    160160                case _t( 'Configure', 'blogroll' ): 
    161161                    $form= new FormUI( 'blogroll' ); 
    162                      
     162 
    163163                    $title= $form->append( 'text', 'list_title', 'option:blogroll__list_title', _t( 'List title: ', 'blogroll' ) ); 
    164                      
     164 
    165165                    $max= $form->append( 'text', 'max_links', 'option:blogroll__max_links', _t( 'Max. displayed links: ', 'blogroll') ); 
    166                      
    167                     $sort_bys= array_merge(  
     166 
     167                    $sort_bys= array_merge( 
    168168                        array_combine( array_keys( Blog::default_fields() ), array_map( 'ucwords', array_keys( Blog::default_fields() ) ) ), 
    169169                        array( 'random' => _t('Randomly', 'blogroll') ) 
    170170                        ); 
    171171                    $sortby= $form->append( 'select', 'sort_by', 'option:blogroll__sort_by', _t( 'Sort By: ', 'blogroll'), $sort_bys ); 
    172                      
     172 
    173173                    $orders= array( 'ASC' => _t('Ascending' ,'blogroll'), 'DESC' => _t('Descending' ,'blogroll') ); 
    174174                    $order= $form->append( 'select', 'direction', 'option:blogroll__direction', _t( 'Order: ', 'blogroll'), $orders ); 
    175                      
     175 
    176176                    $update= $form->append( 'checkbox', 'use_update', 'option:blogroll__use_update', _t( 'Use Weblogs.com to get updates? ', 'blogroll') ); 
    177                      
     177 
    178178                    $form->append( 'submit', 'save', 'Save' ); 
    179179                    $form->out(); 
     
    182182        } 
    183183    } 
    184      
     184 
    185185    public function filter_adminhandler_post_loadplugins_main_menu( $menus ) 
    186186    { 
     
    189189        return $menus; 
    190190    } 
    191      
     191 
    192192    public function action_admin_theme_post_blogroll_manage( $handler, $theme ) 
    193193    { 
    194194        extract( $handler->handler_vars ); 
    195          
     195 
    196196        if ( isset( $change ) && isset( $blog_ids ) ) { 
    197197            $count= count( $blog_ids ); 
    198198            $blog_ids= (array) $blog_ids; 
    199              
     199 
    200200            switch ( $change ) { 
    201201                case 'delete': 
     
    238238            } 
    239239        } 
    240          
     240 
    241241        Utils::redirect( URL::get( 'admin', 'page=blogroll_manage' ) ); 
    242242        exit; 
    243243    } 
    244      
     244 
    245245    public function action_admin_theme_post_blogroll_publish( $handler, $theme ) 
    246246    { 
    247247        $params= array_intersect_key( $handler->handler_vars, array_flip( array('name', 'url', 'feed', 'description', 'owner', 'tags') ) ); 
    248248        extract( $handler->handler_vars ); 
    249          
     249 
    250250        if ( !empty( $quick_link ) ) { 
    251251            $link= $quick_link; 
     
    265265            } 
    266266        } 
    267          
     267 
    268268        if ( ( empty( $params['name'] ) || empty( $params['url'] ) ) ) { 
    269269            Session::error( _t('Blog Name and URL are required feilds.', 'blogroll') ); 
     
    292292            } 
    293293        } 
    294          
     294 
    295295        if ( !empty( $quick_link ) && !empty( $redirect_to ) ) { 
    296296            $msg= sprintf( _t('Successfully added blog %s. Now going back.', 'blogroll'), htmlspecialchars( $blog->name ) ); 
     
    300300            exit; 
    301301        } 
    302          
     302 
    303303        Utils::redirect( URL::get( 'admin', 'page=blogroll_publish' ) ); 
    304304        exit; 
    305305    } 
    306      
     306 
    307307    public function action_admin_theme_get_blogroll_manage( $handler, $theme ) 
    308308    { 
    309309        Stack::add( 'admin_stylesheet', array( $this->get_url() . '/templates/blogroll.css', 'screen' ) ); 
    310310        $theme->feed_icon= $this->get_url() . '/templates/feed.png'; 
    311          
     311 
    312312        $theme->display( 'blogroll_manage' ); 
    313313        exit; 
    314314    } 
    315      
     315 
    316316    public function action_admin_theme_get_blogroll_publish( $handler, $theme ) 
    317317    { 
    318318        Stack::add( 'admin_stylesheet', array( $this->get_url() . '/templates/blogroll.css', 'screen' ) ); 
    319319        extract(  $handler->handler_vars ); 
    320          
     320 
    321321        if ( !empty( $quick_link_bookmarklet ) ) { 
    322322            Session::add_to_set( 'last_form_data', array('quick_link'=>$quick_link_bookmarklet, 'redirect_to'=>$quick_link_bookmarklet), 'post' ); 
     
    324324            exit; 
    325325        } 
    326          
     326 
    327327        if ( !empty( $id ) ) { 
    328328            $blog= Blog::get( $id ); 
     
    336336            $theme->$key= $value; 
    337337        } 
    338          
     338 
    339339        $theme->relationships= Plugins::filter( 'blogroll_relationships', array('external'=>'External', 'nofollow'=>'Nofollow', 'bookmark'=>'Bookmark') ); 
    340340        $controls= array( 
     
    346346        exit; 
    347347    } 
    348      
     348 
    349349    public function filter_available_templates( $templates, $class ) { 
    350350        $templates= array_merge( $templates, array('blogroll_manage','blogroll_publish','blogroll','blogroll_publish_extras') ); 
    351351        return $templates; 
    352352    } 
    353      
     353 
    354354    public function filter_include_template_file( $template_path, $template_name, $class ) 
    355355    { 
     
    368368        return $template_path; 
    369369    } 
    370      
     370 
    371371    public function theme_show_blogroll( $theme, $user_params= array() ) 
    372372    { 
    373373        $theme->blogroll_title= Options::get( 'blogroll__list_title' ); 
    374          
     374 
    375375        // Build the params array to pass it to the get() method 
    376376        $order_by= Options::get( 'blogroll__sort_by' ); 
    377377        $direction= Options::get( 'blogroll__direction'); 
    378          
     378 
    379379        $params= array( 
    380380            'limit' => Options::get( 'blogroll__max_links' ), 
    381381            'order_by' => $order_by . ' ' . $direction, 
    382             ); 
    383              
     382        ); 
     383 
    384384        $theme->blogs= Blogs::get( $params ); 
    385          
     385 
    386386        return $theme->fetch( 'blogroll' ); 
    387387    } 
    388      
     388 
    389389    public function filter_blogroll_update_cron( $success ) 
    390390    { 
     
    419419        } 
    420420    } 
    421      
     421 
    422422    public function filter_habminbar( $menu ) 
    423423    { 
     
    425425        return $menu; 
    426426    } 
    427      
     427 
    428428    public function filter_rewrite_rules( $rules ) 
    429429    { 
     
    441441        return $rules; 
    442442    } 
    443      
     443 
    444444    private function import_opml( SimpleXMLElement $xml ) 
    445445    { 
     
    459459        return $count; 
    460460    } 
    461      
     461 
    462462    private function map_opml_atts( $atts ) 
    463463    {