Changeset 1357 for plugins

Show
Ignore:
Timestamp:
11/26/08 16:06:49 (6 weeks ago)
Author:
bcse
Message:

Plugin: Blogroll: Add XFN annotations, see #89.

Location:
plugins/blogroll/trunk
Files:
3 added
2 modified

Legend:

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

    r1300 r1357  
    1515    const API_VERSION = 004; 
    1616    const CONTENT_TYPE = 'blogroll'; 
    17      
     17 
    1818    private $relationships = array( 
    1919        'external' => 'External', 
     
    2121        'bookmark' => 'Bookmark' 
    2222    ); 
    23      
    24     private $info_fields = array( 'feedurl', 'ownername', 'relationship', 'url' ); 
     23 
     24    private $info_fields = array( 
     25        'feedurl', 
     26        'ownername', 
     27        'relationship', 
     28        'relationships', 
     29        'url', 
     30        'xfn_identity', 
     31        'xfn_friendship', 
     32        'xfn_physical', 
     33        'xfn_professional', 
     34        'xfn_geographical', 
     35        'xfn_family', 
     36        'xfn_romantic' 
     37    ); 
    2538 
    2639    public function info() 
     
    3649        ); 
    3750    } 
    38      
     51 
    3952    /** 
    4053     * Run activation routines, and setup default options. 
     
    5770        } 
    5871    } 
    59      
     72 
    6073    /** 
    6174     * Run deactivation routines. 
     
    6982        } 
    7083    } 
    71      
     84 
     85    public function filter_post_type_display($type, $foruse) 
     86    { 
     87        $names = array( 
     88            self::CONTENT_TYPE => array( 
     89                'singular' => _t( 'Link', self::CONTENT_TYPE ), 
     90                'plural' => _t( 'Links', self::CONTENT_TYPE ), 
     91            ) 
     92        ); 
     93        return isset($names[$type][$foruse]) ? $names[$type][$foruse] : $type; 
     94    } 
     95 
    7296    public function action_init() { 
    7397        // remove legacy tables and import 
     
    77101        $this->add_template( 'blogroll', dirname($this->get_file()) . '/templates/blogroll.php' ); 
    78102        $this->add_template( 'formcontrol_opml_file', dirname($this->get_file()) . '/templates/formcontrol_file.php' ); 
    79     } 
    80      
     103        $this->add_template( 'blogroll__tabcontrol_checkboxes', dirname($this->get_file()) . '/templates/tabcontrol_checkboxes.php' ); 
     104        $this->add_template( 'blogroll__tabcontrol_radio', dirname($this->get_file()) . '/templates/tabcontrol_radio.php' ); 
     105    } 
     106 
     107    public function action_admin_header( $theme ) 
     108    { 
     109        if ( 'publish' == $theme->page && $theme->form->content_type->value == Post::type(self::CONTENT_TYPE) ) { 
     110            Stack::add( 'admin_stylesheet', array( $this->get_url() . '/blogroll.css', 'screen' ), 'blogroll' ); 
     111        } 
     112    } 
     113 
    81114    /** 
    82      *  
     115     * 
    83116     */ 
    84     public function action_update_check() 
    85     { 
    86         Update::add( 'blogroll', '0420cf10-db83-11dc-95ff-0800200c9a66',  $this->info->version ); 
    87     } 
    88      
    89     /** 
    90      *  
     117    public function action_update_check() 
     118    { 
     119        Update::add( 'blogroll', '0420cf10-db83-11dc-95ff-0800200c9a66',  $this->info->version ); 
     120    } 
     121 
     122    /** 
     123     * 
    91124     */ 
    92125    public function filter_plugin_config( $actions, $plugin_id ) 
     
    98131        return $actions; 
    99132    } 
    100      
     133 
    101134    /** 
    102      *  
     135     * 
    103136     */ 
    104137    public function action_plugin_ui( $plugin_id, $action ) 
     
    108141                case _t( 'Configure', 'blogroll' ): 
    109142                    $form = new FormUI( 'blogroll' ); 
    110                      
     143 
    111144                    // display settings 
    112145                    $display_wrap = $form->append( 'fieldset', 'display', _t('Display Settings', 'blogroll') ); 
     
    134167                        _t( 'Order: ', 'blogroll'), $orders 
    135168                    ); 
    136                      
     169 
    137170                    // other settings 
    138171                    $other_wrap = $form->append( 'fieldset', 'settings', _t('More Settings', 'blogroll') ); 
     
    141174                        _t( 'Use Weblogs.com to get updates? ', 'blogroll') 
    142175                    ); 
    143                      
     176 
    144177                    $form->append( 'submit', 'save', 'Save' ); 
    145178                    $form->on_success( array($this, 'formui_submit') ); 
     
    149182        } 
    150183    } 
    151      
     184 
    152185    public function formui_submit( FormUI $form ) 
    153186    { 
     
    155188        $form->save(); 
    156189    } 
    157      
     190 
    158191    public function action_publish_post( Post $post, FormUI $form ) { 
    159192        if ( $post->content_type == Post::type(self::CONTENT_TYPE) ) { 
    160193            if(isset($form->quick_url) && $form->quick_url->value != '') { 
    161194                $data= $this->get_info_from_url($form->quick_url->value); 
    162                  
     195 
    163196                if (!$data) { 
    164197                    Session::error( _t("Could not find information for {$form->quick_url->value}", 'blogroll') ); 
     
    173206                $post->slug= Utils::slugify($data['name']); 
    174207                $post->status= Post::status('published'); 
    175                  
     208 
    176209            } else { 
    177                 $post->info->url= $form->url->value; 
    178                 $post->info->feedurl= $form->feedurl->value; 
    179                 $post->info->ownername= $form->ownername->value; 
    180                 $post->info->relationship= $form->relationship->value; 
    181             } 
    182         } 
    183     } 
    184      
    185     public function action_form_publish( FormUI $form, Post $post) {     
    186          
     210                $relationships = array(); 
     211                $relationships[] = $form->relationship->value; 
     212                if ( count($form->xfn_identity->value) > 0 ) { 
     213                    $relationships = array_merge($form->xfn_identity->value, $relationships); 
     214                } else { 
     215                    $relationships[] = $form->xfn_friendship->value; 
     216                    $relationships = array_merge($form->xfn_physical->value, $relationships); 
     217                    $relationships = array_merge($form->xfn_professional->value, $relationships); 
     218                    $relationships[] = $form->xfn_geographical->value; 
     219                    $relationships[] = $form->xfn_family->value; 
     220                    $relationships = array_merge($form->xfn_romantic->value, $relationships); 
     221                } 
     222                $relationships = str_replace( ' null:null', '', implode(' ', $relationships) ); 
     223 
     224                foreach ($this->info_fields as $field_name) { 
     225                    $post->info->$field_name= $form->$field_name->value; 
     226                } 
     227                $post->info->relationships = $relationships; 
     228            } 
     229        } 
     230    } 
     231 
     232    public function action_form_publish( FormUI $form, Post $post) { 
     233 
    187234        if( $form->content_type->value == Post::type(self::CONTENT_TYPE) ) { 
    188          
     235 
    189236            if ( !Controller::get_var('id') ) { 
    190237                // Quick link button to automagically discover info 
    191238                $quicklink_controls= $form->append('tabs', 'quicklink_controls'); 
    192                  
     239 
    193240                $quicklink_tab= $quicklink_controls->append('fieldset', 'quicklink_tab', _t('Quick Link')); 
    194241                $quicklink_wrapper= $quicklink_tab->append('wrapper', 'quicklink_wrapper'); 
    195242                $quicklink_wrapper->class='container'; 
    196                  
     243 
    197244                $quicklink_wrapper->append('text', 'quick_url', 'null:null', _t('Quick URL'), 'tabcontrol_text'); 
    198245                $quicklink_wrapper->append('static', 'quick_url_info', '<p class="column span-15">Enter a url or feed url and other information will be automatically discovered.</p>'); 
    199246                $quicklink_wrapper->append('submit', 'addquick', _t('Add'), 'admincontrol_submit'); 
    200                  
     247 
    201248                $quicklink_controls->move_before($quicklink_controls, $form); 
    202249            } 
    203              
     250 
    204251            // Remove fields we don't need 
    205             $form->silos->remove(); 
     252            if ( $form->silos instanceof FormControl ) { 
     253                $form->silos->remove(); 
     254            } 
    206255            $form->comments_enabled->remove(); 
    207256            $form->newslug->remove(); 
     
    214263            $form->url->value = $post->info->url; 
    215264            $form->url->move_after($form->title); 
    216              
     265 
    217266            // Retitle fields 
    218267            $form->title->caption= _t('Blog Name'); 
     
    220269            $form->content->tabindex= 3; 
    221270            $form->tags->tabindex= 4; 
    222              
     271 
    223272            // Create the extras splitter & fields 
    224273            $extras = $form->settings; 
     
    226275            $extras->append('text', 'feedurl', 'null:null', _t('Feed URL'), 'tabcontrol_text'); 
    227276            $extras->feedurl->value = $post->info->feedurl; 
    228              
     277 
    229278            $extras->append('text', 'ownername', 'null:null', _t('Owner Name'), 'tabcontrol_text'); 
    230279            $extras->ownername->value = $post->info->ownername; 
    231              
     280 
    232281            $relationships = Plugins::filter( 'blogroll_relationships', $this->relationships ); 
    233282            $extras->append('select', 'relationship', 'null:null', _t('Relationship'), $relationships, 'tabcontrol_select'); 
    234283            $extras->relationship->value = $post->info->relationship; 
    235         } 
    236     } 
    237      
     284 
     285            // Create the XFN Selector 
     286            $xfnselector = $form->publish_controls->append('fieldset', 'xfnselector', _t('XFN')); 
     287 
     288            $xfnselector->append('checkboxes', 'xfn_identity', 'null:null', _t('Identity'), array('me' => _t('Another web address of mine')), 'blogroll__tabcontrol_checkboxes'); 
     289            $xfnselector->xfn_identity->value = $post->info->xfn_identity; 
     290 
     291            $xfnselector->append('radio', 'xfn_friendship', 'null:null', _t('Friendship'), array( 
     292                'contact' => _t('Contact'), 
     293                'acquaintance' => _t('Acquaintance'), 
     294                'friend' => _t('Friend'), 
     295                'null:null' => _t('None') 
     296            ), 'blogroll__tabcontrol_radio'); 
     297            $xfnselector->xfn_friendship->value = $post->info->xfn_friendship; 
     298 
     299            $xfnselector->append('checkboxes', 'xfn_physical', 'null:null', _t('Physical'), array('met' => _t('Met')), 'blogroll__tabcontrol_checkboxes'); 
     300            $xfnselector->xfn_physical->value = $post->info->xfn_physical; 
     301 
     302            $xfnselector->append('checkboxes', 'xfn_professional', 'null:null', _t('Professional'), array( 
     303                'co-worker' => _t('Co-worker'), 
     304                'colleague' => _t('Colleague'), 
     305            ), 'blogroll__tabcontrol_checkboxes'); 
     306            $xfnselector->xfn_professional->value = $post->info->xfn_professional; 
     307 
     308            $xfnselector->append('radio', 'xfn_geographical', 'null:null', _t('Geographical'), array( 
     309                'co-resident' => _t('Co-resident'), 
     310                'neighbor' => _t('Neighbor'), 
     311                'null:null' => _t('None') 
     312            ), 'blogroll__tabcontrol_radio'); 
     313            $xfnselector->xfn_geographical->value = $post->info->xfn_geographical; 
     314 
     315            $xfnselector->append('radio', 'xfn_family', 'null:null', _t('Family'), array( 
     316                'child' => _t('Child'), 
     317                'parent' => _t('Parent'), 
     318                'sibling' => _t('Sibling'), 
     319                'spouse' => _t('Spouse'), 
     320                'kin' => _t('Kin'), 
     321                'null:null' => _t('None') 
     322            ), 'blogroll__tabcontrol_radio'); 
     323            $xfnselector->xfn_family->value = $post->info->xfn_family; 
     324 
     325            $xfnselector->append('checkboxes', 'xfn_romantic', 'null:null', _t('Romantic'), array( 
     326                'muse' => _t('Muse'), 
     327                'crush' => _t('Crush'), 
     328                'date' => _t('Date'), 
     329                'sweetheart' => _t('Sweetheart') 
     330            ), 'blogroll__tabcontrol_checkboxes'); 
     331            $xfnselector->xfn_romantic->value = $post->info->xfn_romantic; 
     332 
     333        } 
     334    } 
     335 
    238336    public static function get_info_from_url( $url ) 
    239     {        
     337    { 
    240338        $info= array(); 
    241339        $data= RemoteRequest::get_contents( $url ); 
    242340        $feed= self::get_feed_location( $data, $url ); 
    243          
     341 
    244342        if ( $feed ) { 
    245343            $info['feed']= $feed; 
     
    277375        return $info; 
    278376    } 
    279      
     377 
    280378    public static function get_feed_location( $html, $url ) 
    281379    { 
     
    325423        return false; 
    326424    } 
    327      
     425 
    328426    public function theme_show_blogroll( $theme, $user_params = array() ) 
    329427    { 
    330428        $theme->blogroll_title = Options::get( 'blogroll__list_title' ); 
    331          
     429 
    332430        // Build the params array to pass it to the get() method 
    333431        $order_by = Options::get( 'blogroll__sort_by' ); 
    334432        $direction = Options::get( 'blogroll__direction'); 
    335          
     433 
    336434        $params = array( 
    337435            'limit' => Options::get( 'blogroll__max_links' ), 
     
    340438            'content_type' => Post::type(self::CONTENT_TYPE), 
    341439        ); 
    342          
     440 
    343441        $theme->blogs = Posts::get( $params ); 
    344          
     442 
    345443        return $theme->fetch( 'blogroll' ); 
    346444    } 
    347      
     445 
    348446    public function filter_habminbar( $menu ) 
    349447    { 
     
    367465        return $rules; 
    368466    } 
    369      
     467 
    370468    public function action_handler_blogroll_opml( array $handler_vars ) 
    371469    { 
    372470        $opml = new SimpleXMLElement( '<opml version="1.1"></opml>' ); 
    373          
     471 
    374472        $head = $opml->addChild( 'head' ); 
    375473        $head->addChild( 'title', Options::get( 'title' ) ); 
    376474        $head->addChild( 'dateCreated', gmdate( 'D, d M Y G:i:s e' ) ); 
    377          
     475 
    378476        $body = $opml->addChild( 'body' ); 
    379          
     477 
    380478        $blogs = Posts::get( 
    381479            array( 
     
    385483            ) 
    386484        ); 
    387          
     485 
    388486        foreach ( $blogs as $blog ) { 
    389487            $outline = $body->addChild( 'outline' ); 
     
    400498        $opml = Plugins::filter( 'blogroll_opml', $opml, $handler_vars ); 
    401499        $opml = $opml->asXML(); 
    402          
     500 
    403501        ob_clean(); 
    404502        header( 'Content-Type: application/opml+xml' ); 
    405503        print $opml; 
    406504    } 
    407      
     505 
    408506    public function filter_import_names( $import_names ) 
    409507    { 
    410508        return array_merge( $import_names, array(_t('BlogRoll OPML file', 'blogroll')) ); 
    411509    } 
    412      
     510 
    413511    /** 
    414512     * Plugin filter that supplies the UI for the Blogroll importer 
     
    427525            return $stageoutput; 
    428526        } 
    429          
     527 
    430528        $inputs = array(); 
    431529 
     
    463561        return $output; 
    464562    } 
    465      
     563 
    466564    private function stage1( array $inputs ) 
    467565    { 
     
    476574            Session::error($warning); 
    477575        } 
    478          
     576 
    479577        $output = <<< BR_IMPORT_STAGE1 
    480578            </form><form method="post" action="" enctype="multipart/form-data"> 
     
    491589            </div> 
    492590            <input type="hidden" name="stage" value="1"> 
    493              
     591 
    494592            <div class="item formcontrol"  id="apply"><input type="submit" name="import" class="button" value="Import"> 
    495593            </div> 
     
    498596        return $output; 
    499597    } 
    500      
     598 
    501599    private function stage2( array $inputs ) 
    502600    { 
     
    531629        return $output; 
    532630    } 
    533      
     631 
    534632    public function action_auth_ajax_blogroll_import_opml( ActionHandler $handler ) 
    535633    { 
     
    537635        $inputs = array_intersect_key( $_POST, array_flip( $valid_fields ) ); 
    538636        extract( $inputs ); 
    539          
     637 
    540638        if ( ! empty($opml_url) ) { 
    541639            $file = RemoteRequest::get_contents( $opml_url ); 
     
    563661        } 
    564662    } 
    565      
     663 
    566664    /** 
    567665     * Import the <outline> data from simplexml obj. $xml->body. 
     
    573671            throw new Exception('Not a valid OPML resource'); 
    574672        } 
    575          
     673 
    576674        $count = 0; 
    577675        foreach ( $xml->outline as $outline ) { 
     
    592690                ); 
    593691                $blog = Post::create($params); 
    594                  
     692 
    595693                foreach($this->info_fields as $field ) { 
    596694                    if ( isset(${$field}) && ${$field} ) { 
     
    607705        return $count; 
    608706    } 
    609      
     707 
    610708    /** 
    611709     * Maps standard OPML link attributes to Post fields. 
     
    641739        return $valid_atts; 
    642740    } 
    643      
     741 
    644742    /** 
    645743     * Grabs update times from weblogs.com 
     
    701799        } 
    702800    } 
    703      
     801 
    704802    public function upgrade_pre_004() 
    705803    { 
     
    707805        DB::register_table('bloginfo'); 
    708806        DB::register_table('tag2blog'); 
    709          
     807 
    710808        if ( ! in_array( DB::table('blogroll'), DB::list_tables() ) ) { 
    711809            Options::set( 'blogroll__api_version', self::API_VERSION ); 
    712810            return; 
    713811        } 
    714          
     812 
    715813        Post::add_new_type(self::CONTENT_TYPE); 
    716          
     814 
    717815        $opml = new SimpleXMLElement( '<opml version="1.1"></opml>' ); 
    718816        $head = $opml->addChild( 'head' ); 
     
    720818        $head->addChild( 'dateCreated', gmdate( 'D, d M Y G:i:s e' ) ); 
    721819        $body = $opml->addChild( 'body' ); 
    722          
     820 
    723821        $blogs = DB::get_results("SELECT * FROM {blogroll}", array()); 
    724822        foreach ( $blogs as $blog ) { 
     
    752850            EventLog::log( _t('Could Import previous data. please import manually and drop tables.', 'blogroll') ); 
    753851        } 
    754          
     852 
    755853        Options::delete('blogroll__db_version'); 
    756854        Options::set( 'blogroll__api_version', self::API_VERSION ); 
  • plugins/blogroll/trunk/templates/blogroll.php

    r1269 r1357  
    44    <ul> 
    55    <?php if ( ! empty( $blogs ) ) { foreach( $blogs as $blog ) { ?> 
    6         <li><a href="<?php echo $blog->info->url; ?>"><?php echo $blog->title; ?></a></li> 
     6        <li class="vcard"><a href="<?php echo $blog->info->url; ?>" class="url" title="<?php echo $blog->content; ?>" rel="<?php echo $blog->info->relationships; ?>"><?php echo $blog->title; ?></a></li> 
    77    <?php } } ?> 
    88    </ul> 
    9      
    109</div>