web/wp-content/plugins/google-sitemap-generator/sitemap-core.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
--- a/web/wp-content/plugins/google-sitemap-generator/sitemap-core.php	Thu Sep 16 15:45:36 2010 +0000
+++ b/web/wp-content/plugins/google-sitemap-generator/sitemap-core.php	Mon Nov 19 18:26:13 2012 +0100
@@ -1,7 +1,7 @@
 <?php
 /*
  
- $Id: sitemap-core.php 175664 2009-11-20 21:21:09Z arnee $
+ $Id: sitemap-core.php 583237 2012-08-08 21:06:12Z arnee $
 
 */
 
@@ -22,7 +22,7 @@
 		
 		$exists = get_option("sm_status");
 		
-		if($exists === false) add_option("sm_status","","Status","no");
+		if($exists === false) add_option("sm_status","",null,"no");
 		
 		$this->Save();
 	}
@@ -36,7 +36,7 @@
 	 * 
 	 * @return GoogleSitemapGeneratorStatus
 	 */
-	function Load() {
+	function &Load() {
 		$status = @get_option("sm_status");
 		if(is_a($status,"GoogleSitemapGeneratorStatus")) return $status;
 		else return null;
@@ -188,56 +188,6 @@
 		return round($this->_googleEndTime - $this->_googleStartTime,2);
 	}
 	
-	var $_usedYahoo = false;
-	var $_yahooUrl = '';
-	var $_yahooSuccess = false;
-	var $_yahooStartTime = 0;
-	var $_yahooEndTime = 0;
-	
-	function StartYahooPing($url) {
-		$this->_yahooUrl = $url;
-		$this->_usedYahoo = true;
-		$this->_yahooStartTime = $this->GetMicrotimeFloat();
-		
-		$this->Save();
-	}
-	
-	function EndYahooPing($success) {
-		$this->_yahooEndTime = $this->GetMicrotimeFloat();
-		$this->_yahooSuccess = $success;
-		
-		$this->Save();
-	}
-	
-	function GetYahooTime() {
-		return round($this->_yahooEndTime - $this->_yahooStartTime,2);
-	}
-	
-	var $_usedAsk = false;
-	var $_askUrl = '';
-	var $_askSuccess = false;
-	var $_askStartTime = 0;
-	var $_askEndTime = 0;
-	
-	function StartAskPing($url) {
-		$this->_usedAsk = true;
-		$this->_askUrl = $url;
-		$this->_askStartTime = $this->GetMicrotimeFloat();
-		
-		$this->Save();
-	}
-	
-	function EndAskPing($success) {
-		$this->_askEndTime = $this->GetMicrotimeFloat();
-		$this->_askSuccess = $success;
-		
-		$this->Save();
-	}
-	
-	function GetAskTime() {
-		return round($this->_askEndTime - $this->_askStartTime,2);
-	}
-	
 	var $_usedMsn = false;
 	var $_msnUrl = '';
 	var $_msnSuccess = false;
@@ -746,7 +696,7 @@
 	/**
 	 * @var Version of the generator in SVN
 	*/
-	var $_svnVersion = '$Id: sitemap-core.php 175664 2009-11-20 21:21:09Z arnee $';
+	var $_svnVersion = '$Id: sitemap-core.php 583237 2012-08-08 21:06:12Z arnee $';
 	
 	/**
 	 * @var array The unserialized array with the stored options
@@ -831,7 +781,7 @@
 			//function to detect if you are on an admin page. So we have to copy
 			//the get_home_path function in our own...
 			$home = get_option( 'home' );
-			if ( $home != '' && $home != get_option( 'siteurl' ) ) {
+			if ( $home != '' && $home != get_option( 'url' ) ) {
 				$home_path = parse_url( $home );
 				$home_path = $home_path['path'];
 				$root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
@@ -910,9 +860,6 @@
 		$this->_options["sm_b_xml"]=true;					//Create a .xml file
 		$this->_options["sm_b_gzip"]=true;					//Create a gzipped .xml file(.gz) file
 		$this->_options["sm_b_ping"]=true;					//Auto ping Google
-		$this->_options["sm_b_pingyahoo"]=false;			//Auto ping YAHOO
-		$this->_options["sm_b_yahookey"]='';				//YAHOO Application Key
-		$this->_options["sm_b_pingask"]=true;				//Auto ping Ask.com
 		$this->_options["sm_b_pingmsn"]=true;				//Auto ping MSN
 		$this->_options["sm_b_manual_enabled"]=false;		//Allow manual creation of the sitemap via GET request
 		$this->_options["sm_b_auto_enabled"]=true;			//Rebuild sitemap when content is changed
@@ -940,6 +887,7 @@
 		$this->_options["sm_in_auth"]=false;				//Include author pages
 		$this->_options["sm_in_tags"]=false;				//Include tag pages
 		$this->_options["sm_in_tax"]=array();				//Include additional taxonomies
+		$this->_options["sm_in_customtypes"]=array();		//Include custom post types
 		$this->_options["sm_in_lastmod"]=true;				//Include the last modification date
 
 		$this->_options["sm_cf_home"]="daily";				//Change frequency of the homepage
@@ -1159,6 +1107,18 @@
 	function IsTaxonomySupported() {
 		return (function_exists("get_taxonomy") && function_exists("get_terms"));
 	}
+
+	/**
+	 * Returns if this version of WordPress supports custom post types
+	 *
+	 * @since 3.2.5
+	 * @access private
+	 * @author Lee Willis
+	 * @return true if supported
+	 */
+	function IsCustomPostTypesSupported() {
+		return (function_exists("get_post_types") && function_exists("register_post_type"));
+	}
 	
 	/**
 	 * Returns the list of custom taxonies. These are basically all taxonomies without categories and post tags
@@ -1168,7 +1128,21 @@
 	 */
 	function GetCustomTaxonomies() {
 		$taxonomies = get_object_taxonomies('post');
-		return array_diff($taxonomies,array("category","post_tag"));
+		return array_diff($taxonomies,array("category","post_tag","post_format"));
+	}
+
+	/**
+	 * Returns the list of custom post types. These are all custome post types except post, page and attachment
+	 * 
+	 * @since 3.2.5
+	 * @author Lee Willis
+	 * @return array Array of custom post types as per get_post_types
+	 */
+	function GetCustomPostTypes() {
+		$post_types = get_post_types(array("public"=>1));
+
+		$post_types = array_diff($post_types,array("post","page","attachment"));
+		return $post_types;
 	}
 	
 	/**
@@ -1333,7 +1307,7 @@
 		} else {
 			delete_option("sm_cpages");
 			//Add the option, Note the autoload=false because when the autoload happens, our class GoogleSitemapGeneratorPage doesn't exist
-			add_option("sm_cpages",$this->_pages,"Storage for custom pages of the sitemap plugin","no");
+			add_option("sm_cpages",$this->_pages,null,"no");
 			return true;
 		}
 	}
@@ -1353,7 +1327,7 @@
 		if(!$forceAuto && $this->GetOption("b_location_mode")=="manual") {
 			return $this->GetOption("b_fileurl_manual");
 		} else {
-			return trailingslashit(get_bloginfo('siteurl')). $this->GetOption("b_filename");
+			return trailingslashit(get_bloginfo('url')). $this->GetOption("b_filename");
 		}
 	}
 
@@ -1699,16 +1673,25 @@
 			
 			$useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not really working yet
 			
-			$excludes = $this->GetOption('b_exclude'); //Excluded posts
+			$excludes = $this->GetOption('b_exclude'); //Excluded posts and pages (user enetered ID)
 			
 			$exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats
 			
 			if($exclCats && count($exclCats)>0 && $this->IsTaxonomySupported()) {
 				
-				$exPosts = get_objects_in_term($exclCats,"category"); // Get all posts in excl. cats
+				$excludedCatPosts = get_objects_in_term($exclCats,"category"); // Get all posts in excl. cats. Unforttunately this also gives us pages, revisions and so on...
+				
+				//Remove the pages, revisions etc from the exclude by category list, because they are always in the uncategorized one.
+				if(count($excludedCatPosts)>0) {
+					$exclPages = $wpdb->get_col("SELECT ID FROM `" . $wpdb->posts . "` WHERE post_type!='post' AND ID IN ('" . implode("','",$excludedCatPosts) . "')");
 				
-				if(is_array($exPosts) && count($exPosts) > 0) { //Merge it with the list of user excluded posts
-					$excludes = array_merge($excludes, $exPosts);
+					$exclPages = array_map('intval', $exclPages);
+					
+					//Remove the pages from the exlusion list before
+					if(count($exclPages)>0)	$excludedCatPosts = array_diff($excludedCatPosts, $exclPages);
+					
+					//Merge the category exclusion list with the users one
+					if(count($excludedCatPosts)>0) $excludes = array_merge($excludes, $excludedCatPosts);
 				}
 			}
 			
@@ -1735,7 +1718,15 @@
 				//WP < 2.1: posts are post_status = publish
 				//WP >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future'
 				if($wpCompat) $where.="(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')";
-				else $where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) ";
+				else if ($this->IsCustomPostTypesSupported() && count($this->GetOption('in_customtypes'))>0) {
+					$where.=" (post_status = 'publish' AND (post_type in ('','post'";
+					foreach ($this->GetOption('in_customtypes') as $customType) {
+						$where.= ",'$customType'";
+					}
+					$where .= "))) ";
+				} else {
+					$where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) ";
+				}
 			}
 			
 			if($this->GetOption('in_pages')) {
@@ -2038,7 +2029,7 @@
 				//We retrieve only users with published and not password protected posts (and not pages)
 				//WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt
 				$sql = "SELECT DISTINCT
-							p.ID,
+							u.ID,
 							u.user_nicename,
 							MAX(p.post_modified_gmt) AS last_post
 						FROM
@@ -2128,7 +2119,7 @@
 				$termInfo = $wpdb->get_results($sql);
 				
 				foreach($termInfo AS $term) {
-					$this->AddUrl(get_term_link($term,$term->_taxonomy),$term->_mod_date ,$this->GetOption("cf_tags"),$this->GetOption("pr_tags"));
+					$this->AddUrl(get_term_link($term->slug,$term->_taxonomy),$term->_mod_date ,$this->GetOption("cf_tags"),$this->GetOption("pr_tags"));
 				}
 			}
 
@@ -2187,41 +2178,14 @@
 			}
 		}
 				
-		//Ping Ask.com
-		if($this->GetOption("b_pingask") && !empty($pingUrl)) {
-			$sPingUrl="http://submissions.ask.com/ping?sitemap=" . urlencode($pingUrl);
-			$status->StartAskPing($sPingUrl);
-			$pingres=$this->RemoteOpen($sPingUrl);
-									  
-			if($pingres==NULL || $pingres===false || strpos($pingres,"successfully received and added")===false) { //Ask.com returns 200 OK even if there was an error, so we need to check the content.
-				$status->EndAskPing(false,$this->_lastError);
-				trigger_error("Failed to ping Ask.com: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE);
-			} else {
-				$status->EndAskPing(true);
-			}
-		}
-		
-		//Ping YAHOO
-		if($this->GetOption("b_pingyahoo")===true && $this->GetOption("b_yahookey")!="" && !empty($pingUrl)) {
-			$sPingUrl="http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=" . $this->GetOption("b_yahookey") . "&url=" . urlencode($pingUrl);
-			$status->StartYahooPing($sPingUrl);
-			$pingres=$this->RemoteOpen($sPingUrl);
-
-			if($pingres==NULL || $pingres===false || strpos(strtolower($pingres),"success")===false) {
-				trigger_error("Failed to ping YAHOO: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE);
-				$status->EndYahooPing(false,$this->_lastError);
-			} else {
-				$status->EndYahooPing(true);
-			}
-		}
 		
 		//Ping Bing
 		if($this->GetOption("b_pingmsn") && !empty($pingUrl)) {
 			$sPingUrl="http://www.bing.com/webmaster/ping.aspx?siteMap=" . urlencode($pingUrl);
 			$status->StartMsnPing($sPingUrl);
 			$pingres=$this->RemoteOpen($sPingUrl);
-									  
-			if($pingres==NULL || $pingres===false || strpos($pingres,"Thanks for submitting your sitemap")===false) {
+			//Bing returns ip/country-based success messages, so there is no way to check the content. Rely on HTTP 500 only then...
+			if($pingres==NULL || $pingres===false || strpos($pingres," ")===false) {
 				trigger_error("Failed to ping Bing: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE);
 				$status->EndMsnPing(false,$this->_lastError);
 			} else {
@@ -2254,7 +2218,7 @@
 		
 		$service = !empty($_GET["sm_ping_service"])?$_GET["sm_ping_service"]:null;
 		
-		$status = GoogleSitemapGeneratorStatus::Load();
+		$status = &GoogleSitemapGeneratorStatus::Load();
 		
 		if(!$status) die("No build status yet. Build the sitemap first.");
 		
@@ -2264,15 +2228,9 @@
 			case "google":
 				$url = $status->_googleUrl;
 				break;
-			case "yahoo":
-				$url = $status->_yahooUrl;
-				break;
 			case "msn":
 				$url = $status->_msnUrl;
-				break;
-			case "ask":
-				$url = $status->_askUrl;
-				break;			
+				break;		
 		}
 		
 		if(empty($url)) die("Invalid ping url");
@@ -2505,9 +2463,9 @@
 	 * @return int The time in seconds
 	 */
 	function GetTimestampFromMySql($mysqlDateTime) {
-		list($date, $hours) = split(' ', $mysqlDateTime);
-		list($year,$month,$day) = split('-',$date);
-		list($hour,$min,$sec) = split(':',$hours);
+		list($date, $hours) = explode(' ', $mysqlDateTime);
+		list($year,$month,$day) = explode('-',$date);
+		list($hour,$min,$sec) = explode(':',$hours);
 		return mktime(intval($hour), intval($min), intval($sec), intval($month), intval($day), intval($year));
 	}
 	
@@ -2529,9 +2487,16 @@
 	 * @return string The full url
 	 */
 	function GetBackLink() {
+		global $wp_version;
+		$url = '';
 		//admin_url was added in WP 2.6.0
-		if(function_exists("admin_url")) return admin_url("options-general.php?page=" .  GoogleSitemapGeneratorLoader::GetBaseName());
-		else return $_SERVER['PHP_SELF'] . "?page=" .  GoogleSitemapGeneratorLoader::GetBaseName();
+		if(function_exists("admin_url")) $url = admin_url("options-general.php?page=" .  GoogleSitemapGeneratorLoader::GetBaseName());
+		else $url = $_SERVER['PHP_SELF'] . "?page=" .  GoogleSitemapGeneratorLoader::GetBaseName();
+		
+		//Some browser cache the page... great! So lets add some no caching params depending on the WP and plugin version
+		$url.='&sm_wpv=' . $wp_version . '&sm_pv=' . GoogleSitemapGeneratorLoader::GetVersion();
+		
+		return $url;
 	}
 	
 	/**