Changeset 1357
- Timestamp:
- 11/26/08 16:06:49 (6 weeks ago)
- Location:
- plugins/blogroll/trunk
- Files:
-
- 3 added
- 2 modified
-
blogroll.css (added)
-
blogroll.plugin.php (modified) (38 diffs)
-
templates/blogroll.php (modified) (1 diff)
-
templates/tabcontrol_checkboxes.php (added)
-
templates/tabcontrol_radio.php (added)
Legend:
- Unmodified
- Added
- Removed
-
plugins/blogroll/trunk/blogroll.plugin.php
r1300 r1357 15 15 const API_VERSION = 004; 16 16 const CONTENT_TYPE = 'blogroll'; 17 17 18 18 private $relationships = array( 19 19 'external' => 'External', … … 21 21 'bookmark' => 'Bookmark' 22 22 ); 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 ); 25 38 26 39 public function info() … … 36 49 ); 37 50 } 38 51 39 52 /** 40 53 * Run activation routines, and setup default options. … … 57 70 } 58 71 } 59 72 60 73 /** 61 74 * Run deactivation routines. … … 69 82 } 70 83 } 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 72 96 public function action_init() { 73 97 // remove legacy tables and import … … 77 101 $this->add_template( 'blogroll', dirname($this->get_file()) . '/templates/blogroll.php' ); 78 102 $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 81 114 /** 82 * 115 * 83 116 */ 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 * 91 124 */ 92 125 public function filter_plugin_config( $actions, $plugin_id ) … … 98 131 return $actions; 99 132 } 100 133 101 134 /** 102 * 135 * 103 136 */ 104 137 public function action_plugin_ui( $plugin_id, $action ) … … 108 141 case _t( 'Configure', 'blogroll' ): 109 142 $form = new FormUI( 'blogroll' ); 110 143 111 144 // display settings 112 145 $display_wrap = $form->append( 'fieldset', 'display', _t('Display Settings', 'blogroll') ); … … 134 167 _t( 'Order: ', 'blogroll'), $orders 135 168 ); 136 169 137 170 // other settings 138 171 $other_wrap = $form->append( 'fieldset', 'settings', _t('More Settings', 'blogroll') ); … … 141 174 _t( 'Use Weblogs.com to get updates? ', 'blogroll') 142 175 ); 143 176 144 177 $form->append( 'submit', 'save', 'Save' ); 145 178 $form->on_success( array($this, 'formui_submit') ); … … 149 182 } 150 183 } 151 184 152 185 public function formui_submit( FormUI $form ) 153 186 { … … 155 188 $form->save(); 156 189 } 157 190 158 191 public function action_publish_post( Post $post, FormUI $form ) { 159 192 if ( $post->content_type == Post::type(self::CONTENT_TYPE) ) { 160 193 if(isset($form->quick_url) && $form->quick_url->value != '') { 161 194 $data= $this->get_info_from_url($form->quick_url->value); 162 195 163 196 if (!$data) { 164 197 Session::error( _t("Could not find information for {$form->quick_url->value}", 'blogroll') ); … … 173 206 $post->slug= Utils::slugify($data['name']); 174 207 $post->status= Post::status('published'); 175 208 176 209 } 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 187 234 if( $form->content_type->value == Post::type(self::CONTENT_TYPE) ) { 188 235 189 236 if ( !Controller::get_var('id') ) { 190 237 // Quick link button to automagically discover info 191 238 $quicklink_controls= $form->append('tabs', 'quicklink_controls'); 192 239 193 240 $quicklink_tab= $quicklink_controls->append('fieldset', 'quicklink_tab', _t('Quick Link')); 194 241 $quicklink_wrapper= $quicklink_tab->append('wrapper', 'quicklink_wrapper'); 195 242 $quicklink_wrapper->class='container'; 196 243 197 244 $quicklink_wrapper->append('text', 'quick_url', 'null:null', _t('Quick URL'), 'tabcontrol_text'); 198 245 $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>'); 199 246 $quicklink_wrapper->append('submit', 'addquick', _t('Add'), 'admincontrol_submit'); 200 247 201 248 $quicklink_controls->move_before($quicklink_controls, $form); 202 249 } 203 250 204 251 // Remove fields we don't need 205 $form->silos->remove(); 252 if ( $form->silos instanceof FormControl ) { 253 $form->silos->remove(); 254 } 206 255 $form->comments_enabled->remove(); 207 256 $form->newslug->remove(); … … 214 263 $form->url->value = $post->info->url; 215 264 $form->url->move_after($form->title); 216 265 217 266 // Retitle fields 218 267 $form->title->caption= _t('Blog Name'); … … 220 269 $form->content->tabindex= 3; 221 270 $form->tags->tabindex= 4; 222 271 223 272 // Create the extras splitter & fields 224 273 $extras = $form->settings; … … 226 275 $extras->append('text', 'feedurl', 'null:null', _t('Feed URL'), 'tabcontrol_text'); 227 276 $extras->feedurl->value = $post->info->feedurl; 228 277 229 278 $extras->append('text', 'ownername', 'null:null', _t('Owner Name'), 'tabcontrol_text'); 230 279 $extras->ownername->value = $post->info->ownername; 231 280 232 281 $relationships = Plugins::filter( 'blogroll_relationships', $this->relationships ); 233 282 $extras->append('select', 'relationship', 'null:null', _t('Relationship'), $relationships, 'tabcontrol_select'); 234 283 $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 238 336 public static function get_info_from_url( $url ) 239 { 337 { 240 338 $info= array(); 241 339 $data= RemoteRequest::get_contents( $url ); 242 340 $feed= self::get_feed_location( $data, $url ); 243 341 244 342 if ( $feed ) { 245 343 $info['feed']= $feed; … … 277 375 return $info; 278 376 } 279 377 280 378 public static function get_feed_location( $html, $url ) 281 379 { … … 325 423 return false; 326 424 } 327 425 328 426 public function theme_show_blogroll( $theme, $user_params = array() ) 329 427 { 330 428 $theme->blogroll_title = Options::get( 'blogroll__list_title' ); 331 429 332 430 // Build the params array to pass it to the get() method 333 431 $order_by = Options::get( 'blogroll__sort_by' ); 334 432 $direction = Options::get( 'blogroll__direction'); 335 433 336 434 $params = array( 337 435 'limit' => Options::get( 'blogroll__max_links' ), … … 340 438 'content_type' => Post::type(self::CONTENT_TYPE), 341 439 ); 342 440 343 441 $theme->blogs = Posts::get( $params ); 344 442 345 443 return $theme->fetch( 'blogroll' ); 346 444 } 347 445 348 446 public function filter_habminbar( $menu ) 349 447 { … … 367 465 return $rules; 368 466 } 369 467 370 468 public function action_handler_blogroll_opml( array $handler_vars ) 371 469 { 372 470 $opml = new SimpleXMLElement( '<opml version="1.1"></opml>' ); 373 471 374 472 $head = $opml->addChild( 'head' ); 375 473 $head->addChild( 'title', Options::get( 'title' ) ); 376 474 $head->addChild( 'dateCreated', gmdate( 'D, d M Y G:i:s e' ) ); 377 475 378 476 $body = $opml->addChild( 'body' ); 379 477 380 478 $blogs = Posts::get( 381 479 array( … … 385 483 ) 386 484 ); 387 485 388 486 foreach ( $blogs as $blog ) { 389 487 $outline = $body->addChild( 'outline' ); … … 400 498 $opml = Plugins::filter( 'blogroll_opml', $opml, $handler_vars ); 401 499 $opml = $opml->asXML(); 402 500 403 501 ob_clean(); 404 502 header( 'Content-Type: application/opml+xml' ); 405 503 print $opml; 406 504 } 407 505 408 506 public function filter_import_names( $import_names ) 409 507 { 410 508 return array_merge( $import_names, array(_t('BlogRoll OPML file', 'blogroll')) ); 411 509 } 412 510 413 511 /** 414 512 * Plugin filter that supplies the UI for the Blogroll importer … … 427 525 return $stageoutput; 428 526 } 429 527 430 528 $inputs = array(); 431 529 … … 463 561 return $output; 464 562 } 465 563 466 564 private function stage1( array $inputs ) 467 565 { … … 476 574 Session::error($warning); 477 575 } 478 576 479 577 $output = <<< BR_IMPORT_STAGE1 480 578 </form><form method="post" action="" enctype="multipart/form-data"> … … 491 589 </div> 492 590 <input type="hidden" name="stage" value="1"> 493 591 494 592 <div class="item formcontrol" id="apply"><input type="submit" name="import" class="button" value="Import"> 495 593 </div> … … 498 596 return $output; 499 597 } 500 598 501 599 private function stage2( array $inputs ) 502 600 { … … 531 629 return $output; 532 630 } 533 631 534 632 public function action_auth_ajax_blogroll_import_opml( ActionHandler $handler ) 535 633 { … … 537 635 $inputs = array_intersect_key( $_POST, array_flip( $valid_fields ) ); 538 636 extract( $inputs ); 539 637 540 638 if ( ! empty($opml_url) ) { 541 639 $file = RemoteRequest::get_contents( $opml_url ); … … 563 661 } 564 662 } 565 663 566 664 /** 567 665 * Import the <outline> data from simplexml obj. $xml->body. … … 573 671 throw new Exception('Not a valid OPML resource'); 574 672 } 575 673 576 674 $count = 0; 577 675 foreach ( $xml->outline as $outline ) { … … 592 690 ); 593 691 $blog = Post::create($params); 594 692 595 693 foreach($this->info_fields as $field ) { 596 694 if ( isset(${$field}) && ${$field} ) { … … 607 705 return $count; 608 706 } 609 707 610 708 /** 611 709 * Maps standard OPML link attributes to Post fields. … … 641 739 return $valid_atts; 642 740 } 643 741 644 742 /** 645 743 * Grabs update times from weblogs.com … … 701 799 } 702 800 } 703 801 704 802 public function upgrade_pre_004() 705 803 { … … 707 805 DB::register_table('bloginfo'); 708 806 DB::register_table('tag2blog'); 709 807 710 808 if ( ! in_array( DB::table('blogroll'), DB::list_tables() ) ) { 711 809 Options::set( 'blogroll__api_version', self::API_VERSION ); 712 810 return; 713 811 } 714 812 715 813 Post::add_new_type(self::CONTENT_TYPE); 716 814 717 815 $opml = new SimpleXMLElement( '<opml version="1.1"></opml>' ); 718 816 $head = $opml->addChild( 'head' ); … … 720 818 $head->addChild( 'dateCreated', gmdate( 'D, d M Y G:i:s e' ) ); 721 819 $body = $opml->addChild( 'body' ); 722 820 723 821 $blogs = DB::get_results("SELECT * FROM {blogroll}", array()); 724 822 foreach ( $blogs as $blog ) { … … 752 850 EventLog::log( _t('Could Import previous data. please import manually and drop tables.', 'blogroll') ); 753 851 } 754 852 755 853 Options::delete('blogroll__db_version'); 756 854 Options::set( 'blogroll__api_version', self::API_VERSION ); -
plugins/blogroll/trunk/templates/blogroll.php
r1269 r1357 4 4 <ul> 5 5 <?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> 7 7 <?php } } ?> 8 8 </ul> 9 10 9 </div>
