[wp-cvs] wordpress/wp-includes classes.php, 1.46, 1.47 template-functions-links.php, 1.50, 1.51

Ryan Boren rboren at users.sourceforge.net
Wed Jan 26 22:46:42 GMT 2005


Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11926/wp-includes

Modified Files:
	classes.php template-functions-links.php 
Log Message:
Add link filters for bug 743 (hat tip to morganiq).  More abstraction and flexibility in WP_Rewrite.

Index: template-functions-links.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/template-functions-links.php,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** template-functions-links.php	25 Jan 2005 05:01:54 -0000	1.50
--- template-functions-links.php	26 Jan 2005 22:46:40 -0000	1.51
***************
*** 75,82 ****
  			$idpost->post_name,
  		);
! 		return get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink);
  	} else { // if they're not using the fancy permalink option
  		$permalink = get_settings('home') . '/?p=' . $idpost->ID;
! 		return $permalink;
  	}
  }
--- 75,82 ----
  			$idpost->post_name,
  		);
! 		return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink));
  	} else { // if they're not using the fancy permalink option
  		$permalink = get_settings('home') . '/?p=' . $idpost->ID;
! 		return apply_filters('post_link', $permalink);
  	}
  }
***************
*** 89,105 ****
  	}
  
! 	$permalink = get_settings('permalink_structure');
  
! 	if ('' != $permalink) {
  		$link = get_page_uri($id);
! 		if ($wp_rewrite->using_index_permalinks()) {
! 			$link = 'index.php/' . $link;
! 		}
  		$link = get_settings('home') . "/$link/";
  	} else {
! 		$link = get_settings('home') . "/index.php?page_id=$id";
  	}
  
! 	return $link;
  }
  
--- 89,103 ----
  	}
  
! 	$pagestruct = $wp_rewrite->get_page_permastruct();
  
! 	if ('' != $pagestruct) {
  		$link = get_page_uri($id);
! 		$link = str_replace('%pagename%', $link, $pagestruct);
  		$link = get_settings('home') . "/$link/";
  	} else {
! 		$link = get_settings('home') . "/?page_id=$id";
  	}
  
! 	return apply_filters('page_link', $link);
  }
  
***************
*** 110,116 ****
      if (!empty($yearlink)) {
          $yearlink = str_replace('%year%', $year, $yearlink);
!         return get_settings('home') . trailingslashit($yearlink);
      } else {
!         return get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year;
      }
  }
--- 108,114 ----
      if (!empty($yearlink)) {
          $yearlink = str_replace('%year%', $year, $yearlink);
!         return apply_filters('year_link', get_settings('home') . trailingslashit($yearlink));
      } else {
!         return apply_filters('year_link', get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year);
      }
  }
***************
*** 124,130 ****
          $monthlink = str_replace('%year%', $year, $monthlink);
          $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
!         return get_settings('home') . trailingslashit($monthlink);
      } else {
!         return get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2);
      }
  }
--- 122,128 ----
          $monthlink = str_replace('%year%', $year, $monthlink);
          $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
!         return apply_filters('month_link', get_settings('home') . trailingslashit($monthlink));
      } else {
!         return apply_filters('month_link', get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2));
      }
  }
***************
*** 141,147 ****
          $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
          $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
!         return get_settings('home') . trailingslashit($daylink);
      } else {
!         return get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2);
      }
  }
--- 139,145 ----
          $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
          $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
!         return apply_filters('day_link', get_settings('home') . trailingslashit($daylink));
      } else {
!         return apply_filters('day_link', get_settings('home') .'/'. $querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2));
      }
  }
***************
*** 149,206 ****
  function get_feed_link($feed='rss2') {
  	global $wp_rewrite;
!     $do_perma = 0;
!     $feed_url = get_settings('siteurl');
!     $comment_feed_url = $feed_url;
  
!     $permalink = get_settings('permalink_structure');
!     if ('' != $permalink) {
!         $do_perma = 1;
!         $feed_url = get_settings('home');
!         $index = 'index.php';
!         $prefix = '';
!         if ($wp_rewrite->using_index_permalinks()) {
!             $feed_url .= '/' . $index;
!         }
  
!         $comment_feed_url = $feed_url;
!         $feed_url .= '/feed';
!         $comment_feed_url .= '/comments/feed';
!     }
  
!     switch($feed) {
!         case 'rdf':
!             $output = $feed_url .'/wp-rdf.php';
!             if ($do_perma) {
!                 $output = $feed_url . '/rdf/';
!             }
!             break;
!         case 'rss':
!             $output = $feed_url . '/wp-rss.php';
!             if ($do_perma) {
!                 $output = $feed_url . '/rss/';
!             }
!             break;
!         case 'atom':
!             $output = $feed_url .'/wp-atom.php';
!             if ($do_perma) {
!                 $output = $feed_url . '/atom/';
!             }
!             break;        
!         case 'comments_rss2':
!             $output = $feed_url .'/wp-commentsrss2.php';
!             if ($do_perma) {
!                 $output = $comment_feed_url . '/';
!             }
!             break;
!         case 'rss2':
!         default:
!             $output = $feed_url .'/wp-rss2.php';
!             if ($do_perma) {
!                 $output = $feed_url . '/';
!             }
!             break;
!     }
  
!     return $output;
  }
  
--- 147,175 ----
  function get_feed_link($feed='rss2') {
  	global $wp_rewrite;
! 	$do_perma = 0;
! 	$feed_url = get_settings('siteurl');
! 	$comment_feed_url = $feed_url;
  
! 	$permalink = $wp_rewrite->get_feed_permastruct();
! 	if ('' != $permalink) {
! 		if ( false !== strpos($feed, 'comments_') ) {
! 			$feed = str_replace('comments_', '', $feed);
! 			$permalink = $wp_rewrite->get_comment_feed_permastruct();
! 		}
  
! 		if ( 'rss2' == $feed )
! 			$feed = '';
  
! 		$permalink = str_replace('%feed%', $feed, $permalink);
! 		$output =  get_settings('home') . "/$permalink/";
! 		$output = preg_replace('#/+#', '/', $output);
! 	} else {
! 		if ( false !== strpos($feed, 'comments_') )
! 			$feed = str_replace('comments_', 'comments', $feed);
  
! 		$output = get_settings('siteurl') . "/wp-{$feed}.php";
! 	}
! 
! 	return apply_filters('feed_link', $output);
  }
  

Index: classes.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/classes.php,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** classes.php	25 Jan 2005 00:57:14 -0000	1.46
--- classes.php	26 Jan 2005 22:46:39 -0000	1.47
***************
*** 724,729 ****
--- 724,737 ----
  	var $category_base;
  	var $category_structure;
+ 	var $author_base = 'author';
  	var $author_structure;
  	var $date_structure;
+ 	var $page_structure;
+ 	var $search_base = 'search';
+ 	var $search_structure;
+ 	var $comments_base = 'comments';
+ 	var $feed_base = 'feed';
+ 	var $comments_feed_structure;
+ 	var $feed_structure;
  	var $front;
  	var $root = '';
***************
*** 792,796 ****
  
      // If the index is not in the permalink, we're using mod_rewrite.
!     if (preg_match('#^/*index.php#', $this->permalink_structure)) {
        return true;
      }
--- 800,804 ----
  
      // If the index is not in the permalink, we're using mod_rewrite.
!     if (preg_match('#^/*' . $this->index . '#', $this->permalink_structure)) {
        return true;
      }
***************
*** 822,826 ****
  
  		$rewrite_rules = array();
! 		$page_structure = '/%pagename%';
  		if( is_array( $uris ) )
  			{
--- 830,834 ----
  
  		$rewrite_rules = array();
! 		$page_structure = $this->get_page_permastruct();
  		if( is_array( $uris ) )
  			{
***************
*** 926,934 ****
  		}
  
! 		$this->author_structure = $this->front . 'author/%author%';
  
  		return $this->author_structure;
  	}
  
  	function add_rewrite_tag($tag, $pattern, $query) {
  		// If the tag already exists, replace the existing pattern and query for
--- 934,1002 ----
  		}
  
! 		$this->author_structure = $this->front . $this->author_base . '/%author%';
  
  		return $this->author_structure;
  	}
  
+ 	function get_search_permastruct() {
+ 		if (isset($this->search_structure)) {
+ 			return $this->search_structure;
+ 		}
+ 
+     if (empty($this->permalink_structure)) {
+ 			$this->search_structure = '';
+ 			return false;
+ 		}
+ 
+ 		$this->search_structure = $this->root . $this->search_base . '/%search%';
+ 
+ 		return $this->search_structure;
+ 	}
+ 
+ 	function get_page_permastruct() {
+ 		if (isset($this->page_structure)) {
+ 			return $this->page_structure;
+ 		}
+ 
+     if (empty($this->permalink_structure)) {
+ 			$this->page_structure = '';
+ 			return false;
+ 		}
+ 
+ 		$this->page_structure = $this->root . '%pagename%';
+ 
+ 		return $this->page_structure;
+ 	}
+ 
+ 	function get_feed_permastruct() {
+ 		if (isset($this->feed_structure)) {
+ 			return $this->feed_structure;
+ 		}
+ 
+     if (empty($this->permalink_structure)) {
+ 			$this->feed_structure = '';
+ 			return false;
+ 		}
+ 
+ 		$this->feed_structure = $this->root . $this->feed_base . '/%feed%';
+ 
+ 		return $this->feed_structure;
+ 	}
+ 
+ 	function get_comment_feed_permastruct() {
+ 		if (isset($this->comment_feed_structure)) {
+ 			return $this->comment_feed_structure;
+ 		}
+ 
+     if (empty($this->permalink_structure)) {
+ 			$this->comment_feed_structure = '';
+ 			return false;
+ 		}
+ 
+ 		$this->comment_feed_structure = $this->root . $this->comments_base . '/' . $this->feed_base . '/%feed%';
+ 
+ 		return $this->comment_feed_structure;
+ 	}
+ 
  	function add_rewrite_tag($tag, $pattern, $query) {
  		// If the tag already exists, replace the existing pattern and query for
***************
*** 1069,1077 ****
  
  		// Comments
! 		$comments_rewrite = $this->generate_rewrite_rules($this->root . 'comments',true, true, true);
  		$comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
  
  		// Search
! 		$search_structure = $this->root . "search/%search%";
  		$search_rewrite = $this->generate_rewrite_rules($search_structure);
  		$search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
--- 1137,1145 ----
  
  		// Comments
! 		$comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, true, true, true);
  		$comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
  
  		// Search
! 		$search_structure = $this->get_search_permastruct();
  		$search_rewrite = $this->generate_rewrite_rules($search_structure);
  		$search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
***************
*** 1135,1139 ****
  			}
  
! 			if (strstr($query, 'index.php')) {
  				$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
  			} else {
--- 1203,1207 ----
  			}
  
! 			if (strstr($query, $this->index)) {
  				$rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n";
  			} else {
***************
*** 1159,1163 ****
  		unset($this->category_structure);
  		unset($this->author_structure);
! 		unset($this->date_structure);		
  	}
  
--- 1227,1235 ----
  		unset($this->category_structure);
  		unset($this->author_structure);
! 		unset($this->date_structure);
! 		unset($this->page_structure);
! 		unset($this->search_structure);
! 		unset($this->feed_structure);
! 		unset($this->comment_feed_structure);
  	}
  



More information about the cvs mailing list