Changeset 492853
- Timestamp:
- 01/20/2012 11:11:27 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ipb-comments-for-wordpress/trunk/class.ipbcomments.php
r490272 r492853 6 6 7 7 class WP_IPBComments { 8 9 public $ttl = 180; // cache values will expire every 3 minutes or 180 seconds10 8 11 9 public $crosspost_edits = false; // don't change this yet … … 49 47 'manage_options', // capability required to use this menu option 50 48 'ipb-comments', // slug to refer to this menu item 51 array($this,'show_options_page') // optional callback function49 array($this,'show_options_page') // optional callback function 52 50 ); 53 51 … … 60 58 function register_comments() { 61 59 60 // where to put the link + link text 62 61 switch ( $this->options['ipb_custom_link_filter'] ) { 63 62 64 63 case 'before_comments': 64 add_filter( 'comments_array', array($this,'show_link_text') ); 65 break; 66 65 67 case 'after_comments': 66 add_ filter( 'comments_array', array($this,'show_link_text') );68 add_action( 'comment_form_before', array($this,'show_link_text') ); 67 69 break; 68 70 … … 71 73 add_filter( 'the_content', array($this,'show_link_text') ); 72 74 break; 73 74 default:75 76 75 } 77 76 … … 177 176 'topic_id' => intval($topicData['tid']), // forum topic id 178 177 'replies' => array(), // last X replies in topic 179 'ttl' => $this->ttl, // time to live for cached replies180 178 'timestamp' => time() // current timestamp of this update 181 179 ) ); … … 193 191 194 192 /** 195 * get the last 5replies for IPB topic_id193 * get the last X replies for IPB topic_id 196 194 */ 197 195 function get_replies( $topic_id ) { … … 226 224 $registry->init(); 227 225 226 // build the select statement, skip the original post, we just want the replies 228 227 $registry->DB()->build( array( 'select' => 'author_name,post_date,post', 229 228 'from' => 'posts', 230 229 'where' => 'topic_id = '.intval($topic_id), 231 'order' => 'post_date DESC',232 'limit' => array( 0,$this->options['ipb_field_show_comments'])230 'order' => 'post_date', 231 'limit' => array(1,$this->options['ipb_field_show_comments']) 233 232 ) 234 233 ); … … 253 252 } 254 253 255 return $replies; 254 // return the comments in reverse chronological order 255 return array_reverse($replies); 256 256 } 257 257 … … 369 369 370 370 <li> 371 <label for="ttl">Cache TTL:</label> 372 <input type="text" size="3" name="ipb_comments_options[ipb_field_ttl]" 373 value="<?php echo $this->options['ipb_field_ttl']; ?>" /> 374 <em>180 (seconds to cache the forum replies)</em> 375 </li> 376 377 <li> 371 378 <label for="member_id">Member ID:</label> 372 379 <input type="text" size="5" name="ipb_comments_options[ipb_field_member_id]" … … 473 480 $topic_link_text = $this->options['ipb_field_link_text_wp']; 474 481 475 $link = sprintf( '<p class="ipb_discussion"><a href="%s">%s</a></p>', $topic_link, $topic_link_text );482 $link_text = sprintf( '<p class="ipb_discussion"><a href="%s">%s</a></p>', $topic_link, $topic_link_text ); 476 483 477 484 // add it to the content/comments … … 479 486 480 487 case 'before_comments': 488 case 'after_comments': 489 echo $this->get_forum_comments(); 490 echo $link_text; 491 return $content; 492 481 493 case 'before_content': 482 return $link.$content; 483 484 case 'after_comments': 494 return $this->get_forum_comments() . $link_text . $content; 495 485 496 case 'after_content': 486 return $content .$link;487 488 default: 497 return $content . $this->get_forum_comments() . $link_text; 498 499 default: 489 500 return $content; 490 501 } … … 500 511 */ 501 512 502 function show_forum_comments ( $comments) {503 513 function get_forum_comments () { 514 504 515 if ( ! is_single() ) return $comments; 505 516 … … 522 533 $meta = get_post_meta($post_ID,'forum_topic_meta'); 523 534 extract($meta[0]); 524 535 525 536 /** 526 537 * check if cache has expired using timestamp and ttl against current time() … … 529 540 $t = time(); 530 541 531 if ( empty($meta) OR ($t - $timestamp > $ttl) OR empty($replies) ) { 542 $update_cache = (empty($meta) OR empty($replies) OR ($t - $timestamp > intval($this->options['ipb_field_ttl']))); 543 544 if ( $update_cache ) { 532 545 533 546 $replies = $this->get_replies($topic_id); … … 568 581 * Show our forum comments just above our post comments 569 582 */ 583 ob_start(); 570 584 ?> 571 585 <div id="ipb_comments"> 572 586 <p class="ipb_discussion"><a href="<?php echo $topic_link; ?>"><?php echo $this->topic_text; ?></a></p> 573 <h4>Most recent comments:</h4>587 <h4>Most recent forum comments:</h4> 574 588 <ul> 575 589 <?php echo $reply_content; ?> … … 578 592 <?php 579 593 580 return $comments;594 return ob_get_clean(); 581 595 } 582 596
Note: See TracChangeset
for help on using the changeset viewer.