Changeset 19556
- Timestamp:
- 09/22/2007 12:27:16 PM (19 years ago)
- File:
-
- 1 edited
-
google-sitemap-generator/trunk/sitemap.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
google-sitemap-generator/trunk/sitemap.php
r17826 r19556 33 33 Plugin URI: http://www.arnebrachhold.de/redir/sitemap-home/ 34 34 Description: This plugin will generate a sitemaps.org compatible sitemap of your WordPress blog which is supported by Ask.com, Google, MSN Search and YAHOO. <a href="options-general.php?page=sitemap.php">Configuration Page</a> 35 Version: 3.0b1 035 Version: 3.0b11 36 36 Author: Arne Brachhold 37 37 Author URI: http://www.arnebrachhold.de/ … … 159 159 Repaired GET building 160 160 Added more info on debug mode 161 2007-09-04 3.0b11 Changed mysql queries to unbuffered queries 162 Uses MUCH less memory 163 Fixed really stupid bug with search engine pings 164 Option to set how many posts will be included 161 165 162 166 … … 1062 1066 * @var Version of the generator 1063 1067 */ 1064 var $_version = "3.0b1 0";1068 var $_version = "3.0b11"; 1065 1069 1066 1070 /** … … 1118 1122 */ 1119 1123 var $_isActive = false; 1124 1125 /** 1126 * @var object The file handle which is used to write the sitemap file 1127 */ 1128 var $_fileHandle = null; 1129 1130 /** 1131 * @var object The file handle which is used to write the zipped sitemap file 1132 */ 1133 var $_fileZipHandle = null; 1120 1134 1121 1135 /** … … 1244 1258 $this->_options["sm_b_memory"] = ''; //Set Memory Limit (e.g. 16M) 1245 1259 $this->_options["sm_b_time"] = -1; //Set time limit in seconds, 0 for unlimited, -1 for disabled 1260 $this->_options["sm_b_max_posts"] = -1; //Maximum number of posts, <= 0 for all 1246 1261 $this->_options["sm_b_style"] = $this->GetDefaultStyle(); //Include a stylesheet in the XML 1247 1262 $this->_options["sm_b_robots"] = false; //Modify or create robots.txt file in blog root which contains the sitemap location … … 1442 1457 */ 1443 1458 function IsGzipEnabled() { 1444 return ($this->GetOption("b_gzip")===true && function_exists("gz encode"));1459 return ($this->GetOption("b_gzip")===true && function_exists("gzwrite")); 1445 1460 } 1446 1461 … … 1809 1824 if(empty($page)) return; 1810 1825 1811 $this->_content[] = $page; 1826 $s = $page->Render(); 1827 1828 if($this->_fileZipHandle && $this->IsGzipEnabled()) { 1829 gzwrite($this->_fileZipHandle,$s); 1830 } 1831 1832 if($this->_fileHandle && $this->GetOption("b_xml")) { 1833 fwrite($this->_fileHandle,$s); 1834 } 1812 1835 } 1813 1836 … … 1906 1929 $debug=$this->GetOption("b_debug"); 1907 1930 1931 1932 if($this->GetOption("b_xml")) { 1933 $fileName = $this->GetXmlPath(); 1934 $status->StartXml($this->GetXmlPath(),$this->GetXmlUrl()); 1935 1936 if($this->IsFileWritable($fileName)) { 1937 1938 $this->_fileHandle = fopen($fileName,"w"); 1939 if(!$this->_fileHandle) $status->EndXml(false,"Not openable"); 1940 1941 } else $status->EndXml(false,"not writable"); 1942 } 1943 1944 //Write gzipped sitemap file 1945 if($this->IsGzipEnabled()) { 1946 $fileName = $this->GetZipPath(); 1947 $status->StartZip($this->GetZipPath(),$this->GetZipUrl()); 1948 1949 if($this->IsFileWritable($fileName)) { 1950 1951 $this->_fileZipHandle = gzopen($fileName,"w1"); 1952 if(!$this->_fileZipHandle) $status->EndZip(false,"Not openable"); 1953 1954 } else $status->EndZip(false,"not writable"); 1955 } 1956 1957 if(!$this->_fileHandle && !$this->_fileZipHandle) { 1958 $status->End(); 1959 return; 1960 } 1961 1962 1908 1963 //Content of the XML file 1909 1964 $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>')); … … 1947 2002 $wpCompat = (floatval($wp_version) < 2.1); 1948 2003 1949 $sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` FROM `" . $wpdb->posts . "` WHERE ("; 2004 $sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` FROM `" . $wpdb->posts . "` WHERE "; 2005 2006 $where = '('; 1950 2007 1951 2008 if($this->GetOption('in_posts')) { 1952 2009 //WP < 2.1: posts are post_status = publish 1953 2010 //WP >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future' 1954 if($wpCompat) $ sql.="(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')";1955 else $ sql.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) ";2011 if($wpCompat) $where.="(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')"; 2012 else $where.=" (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) "; 1956 2013 } 1957 2014 1958 2015 if($this->GetOption('in_pages')) { 1959 2016 if($this->GetOption('in_posts')) { 1960 $ sql.=" OR ";2017 $where.=" OR "; 1961 2018 } 1962 2019 if($wpCompat) { 1963 2020 //WP < 2.1: posts have post_status = published, pages have post_status = static 1964 $ sql.=" post_status='static' ";2021 $where.=" post_status='static' "; 1965 2022 } else { 1966 2023 //WP >= 2.1: posts have post_type = 'post' and pages have post_type = 'page'. Both must be published. 1967 $ sql.=" (post_status = 'publish' AND post_type = 'page') ";2024 $where.=" (post_status = 'publish' AND post_type = 'page') "; 1968 2025 } 1969 2026 } 1970 2027 1971 $sql.=") "; 1972 1973 $sql.=" AND post_password='' ORDER BY post_modified DESC"; 2028 $where.=") "; 2029 2030 $where.=" AND post_password='' ORDER BY post_modified DESC"; 2031 2032 $sql .= $where; 2033 2034 if($this->GetOption("sm_b_max_posts")>0) { 2035 $sql.=" LIMIT 0," . $this->GetOption("sm_b_max_posts"); 2036 } 2037 2038 $postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE ". $where,0,0)); 2039 1974 2040 1975 2041 //Retrieve all posts and static pages (if enabled) 1976 $postRes=$wpdb->get_results($sql); 2042 2043 $con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,true); 2044 mysql_select_db(DB_NAME,$con); 2045 2046 $postRes = mysql_unbuffered_query($sql,$con); 1977 2047 1978 2048 if($postRes) { 1979 1980 //Count of all posts1981 $postCount=count($postRes);1982 2049 1983 2050 //#type $prioProvider GoogleSitemapGeneratorPrioProviderBase … … 1990 2057 1991 2058 //$posts is used by Alex King's Popularity Contest plugin 1992 if($posts == null || !is_array($posts)) {1993 $posts = &$postRes;1994 }2059 //if($posts == null || !is_array($posts)) { 2060 // $posts = &$postRes; 2061 //} 1995 2062 1996 2063 $z = 1; … … 2007 2074 $minPrio=$this->GetOption('pr_posts_min'); 2008 2075 2009 //Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later.2010 update_post_cache($postRes);2011 2076 2012 2077 //Cycle through all posts and add them 2013 foreach($postRes as $post) { 2078 while($post = mysql_fetch_object($postRes)) { 2079 2080 //Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later. 2081 $cache = array(&$post); 2082 update_post_cache($cache); 2014 2083 2015 2084 $permalink = get_permalink($post->ID); … … 2071 2140 unset($prioProvider); 2072 2141 2142 mysql_close($con); 2073 2143 } 2074 2144 if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Postings")); … … 2241 2311 $this->AddElement(new GoogleSitemapGeneratorXmlEntry("</urlset>")); 2242 2312 2243 $s=''; 2244 $c = count($this->_content); 2245 for($i =0; $i<$c; $i++) { 2246 $s.=$this->_content[$i]->Render() . "\n"; 2247 } 2248 2249 $hasChanged = true; 2250 2251 $xmlHasChanged = true; 2252 $zipHasChanged = true; 2253 2254 if($this->GetOption("b_xml") && is_readable($this->GetXmlPath())) { 2255 $current = file_get_contents($this->GetXmlPath()); 2256 $current = $this->RemoveSitemapComment($current); 2257 $new = $this->RemoveSitemapComment($s); 2258 if($new == $current) $xmlHasChanged = false; 2259 } 2260 2261 if($this->IsGzipEnabled() && is_readable($this->GetZipPath())) { 2262 $current = file_get_contents("compress.zlib://" . $this->GetZipPath()); 2263 $current = $this->RemoveSitemapComment($current); 2264 $new = $this->RemoveSitemapComment($s); 2265 if($new == $current) $zipHasChanged = false; 2266 } 2267 2268 $hasChanged = ($zipHasChanged || $xmlHasChanged); 2269 2270 if(!$hasChanged) { 2271 $status->End(false); 2272 } else { 2273 $pingUrl=''; 2274 2275 //Write normal sitemap file 2276 if($xmlHasChanged && $this->GetOption("b_xml")) { 2277 $fileName = $this->GetXmlPath(); 2278 $status->StartXml($this->GetXmlPath(),$this->GetXmlUrl()); 2279 if($this->IsFileWritable($fileName)) { 2280 if(file_put_contents($fileName,$s)) { 2281 $pingUrl=$this->GetXmlUrl(); 2282 $status->EndXml(true); 2283 } else { 2284 $status->EndXml(false,$this->_lastError); 2285 } 2286 } else $status->EndXml(false,"nt writable"); 2313 2314 $pingUrl=''; 2315 2316 if($this->GetOption("b_xml")) { 2317 if($this->_fileHandle && fclose($this->_fileHandle)) { 2318 $this->_fileHandle = null; 2319 $status->EndXml(true); 2320 $pingUrl=$this->GetXmlUrl(); 2321 } else $status->EndXml(false,"Could not close the sitemap file."); 2322 } 2323 2324 if($this->IsGzipEnabled()) { 2325 if($this->_fileZipHandle && fclose($this->_fileZipHandle)) { 2326 $this->_fileZipHandle = null; 2327 $status->EndZip(true); 2328 $pingUrl=$this->GetZipUrl(); 2329 } else $status->EndZip(false,"Could not close the zipped sitemap file"); 2330 } 2331 2332 //Ping Google 2333 if($this->GetOption("b_ping") && !empty($pingUrl)) { 2334 $status->StartGooglePing(); 2335 $sPingUrl="http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl); 2336 $pingres=wp_remote_fopen($sPingUrl); 2337 2338 if($pingres==NULL || $pingres===false) { 2339 $status->EndGooglePing(false,$this->_lastError); 2340 } else { 2341 $status->EndGooglePing(true); 2287 2342 } 2288 2289 //Write gzipped sitemap file 2290 if($zipHasChanged && $this->IsGzipEnabled()) { 2291 $fileName = $this->GetZipPath(); 2292 $status->StartZip($this->GetZipPath(),$this->GetZipUrl()); 2293 if($this->IsFileWritable($fileName)) { 2294 //Gzip Level 1 is OK and very fast. 2295 if(file_put_contents($fileName,gzencode($s,1))) { 2296 $pingUrl=$this->GetZipUrl(); 2297 $status->EndZip(true); 2298 } else { 2299 $status->EndZip(false,$this->_lastError); 2300 } 2301 } else $status->EndZip(false,"nt writable"); 2343 } 2344 2345 //Ping Ask.com 2346 if($this->GetOption("b_pingask") && !empty($pingUrl)) { 2347 $status->StartAskPing(); 2348 $sPingUrl="http://submissions.ask.com/ping?sitemap=" . urlencode($pingUrl); 2349 $pingres=wp_remote_fopen($sPingUrl); 2350 2351 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. 2352 $status->EndAskPing(false,$this->_lastError); 2353 } else { 2354 $status->EndAskPing(true); 2302 2355 } 2303 2304 //Ping Google 2305 if($this->GetOption("b_ping") && !empty($pingUrl)) { 2306 $status->StartGooglePing(); 2307 $pingUrl="http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl); 2308 $pingres=@wp_remote_fopen($pingUrl); 2309 2310 if($pingres==NULL || $pingres===false) { 2311 $status->EndGooglePing(false,$this->_lastError); 2312 } else { 2313 $status->EndGooglePing(true); 2314 } 2315 } 2316 2317 //Ping Ask.com 2318 if($this->GetOption("b_pingask") && !empty($pingUrl)) { 2319 $status->StartAskPing(); 2320 $pingUrl="http://submissions.ask.com/ping?sitemap=" . urlencode($pingUrl); 2321 $pingres=@wp_remote_fopen($pingUrl); 2322 2323 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. 2324 $status->EndAskPing(false,$this->_lastError); 2325 } else { 2326 $status->EndAskPing(true); 2327 } 2328 } 2329 2330 //Ping YAHOO 2331 if($this->GetOption("sm_b_pingyahoo")===true && !empty($pingUrl)) { 2332 $status->StartYahooPing(); 2333 $pingUrl="http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=" . urlencode($pingUrl); 2334 $pingres=@wp_remote_fopen($pingUrl); 2335 2336 if($pingres==NULL || $pingres===false || strpos(strtolower($pingres),"success")===false) { 2337 $status->EndYahooPing(false,$this->_lastError); 2338 } else { 2339 $status->EndYahooPing(true); 2340 } 2356 } 2357 2358 //Ping YAHOO 2359 if($this->GetOption("sm_b_pingyahoo")===true && !empty($pingUrl)) { 2360 $status->StartYahooPing(); 2361 $sPingUrl="http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=" . urlencode($pingUrl); 2362 $pingres=wp_remote_fopen($sPingUrl); 2363 2364 if($pingres==NULL || $pingres===false || strpos(strtolower($pingres),"success")===false) { 2365 $status->EndYahooPing(false,$this->_lastError); 2366 } else { 2367 $status->EndYahooPing(true); 2341 2368 } 2342 2343 $status->End(); 2344 } 2369 } 2370 2371 $status->End(); 2372 2345 2373 2346 2374 $this->_isActive = false; … … 2569 2597 } 2570 2598 2571 $oldErr = @error_reporting(E_ALL);2572 $oldIni = @ini_set("display_errors",1);2599 $oldErr = error_reporting(E_ALL); 2600 $oldIni = ini_set("display_errors",1); 2573 2601 2574 2602 echo '<div class="wrap">'; … … 2579 2607 echo '<p>WordPress ' . $GLOBALS['wp_version'] . ' with ' . ' DB ' . $GLOBALS['wp_db_version'] . ' on PHP ' . phpversion() . '</p>'; 2580 2608 echo '<p>Plugin version: ' . $this->_version . ' (' . $this->_svnVersion . ')'; 2581 echo '<h4>Extensions</h4>';2582 echo "<pre>";2583 print_r(get_loaded_extensions());2584 echo "</pre>";2585 2609 echo '<h4>Environment</h4>'; 2586 2610 echo "<pre>"; … … 2608 2632 $status = $this->BuildSitemap(); 2609 2633 echo '</div>'; 2634 echo '<h3>MySQL Queries</h3>'; 2635 if(defined('SAVEQUERIES') && SAVEQUERIES) { 2636 echo '<pre>'; 2637 var_dump($GLOBALS['wpdb']->queries); 2638 echo '</pre>'; 2639 2640 $total = 0; 2641 foreach($GLOBALS['wpdb']->queries as $q) { 2642 $total+=$q[1]; 2643 } 2644 echo '<h4>Total Query Time</h4>'; 2645 echo '<pre>' . count($GLOBALS['wpdb']->queries) . ' queries in ' . round($total,2) . ' seconds.</pre>'; 2646 } else { 2647 echo '<p>Please edit wp-db.inc.php in wp-includes and set SAVEQUERIES to true if you want to see the queries.</p>'; 2648 } 2610 2649 echo "<h3>Build Process Results</h3>"; 2611 2650 echo "<pre>"; … … 2644 2683 if($tmp=="auto" || $tmp="manual") $this->_options[$k]=$tmp; 2645 2684 else $this->_options[$k]="auto"; 2646 } else if($k == "sm_b_time" ) {2685 } else if($k == "sm_b_time" || $k=="sm_b_max_posts") { 2647 2686 if($_POST[$k]=='') $_POST[$k] = -1; 2648 2687 $this->_options[$k] = intval($_POST[$k]); … … 3048 3087 <b><?php _e('Advanced options:','sitemap'); ?></b> <a href="<?php echo $this->GetRedirectLink('sitemap-help-options-adv'); ?>"><?php _e('Learn more','sitemap'); ?></a> 3049 3088 <ul> 3089 <li> 3090 <label for="sm_b_max_posts"><?php _e('Limit the number of posts in the sitemap:', 'sitemap') ?> <input type="text" name="sm_b_max_posts" id="sm_b_max_posts" style="width:40px;" value="<?php echo ($this->GetOption("sm_b_max_posts")<=0?"":$this->GetOption("sm_b_max_posts")); ?>" /></label> (<?php echo __('Newer posts will be included first', 'sitemap'); ?>) 3091 </li> 3050 3092 <li> 3051 3093 <label for="sm_b_memory"><?php _e('Try to increase the memory limit to:', 'sitemap') ?> <input type="text" name="sm_b_memory" id="sm_b_memory" style="width:40px;" value="<?php echo $this->GetOption("sm_b_memory"); ?>" /></label> (<?php echo htmlspecialchars(__('e.g. "4M", "16M"', 'sitemap')); ?>) … … 3538 3580 3539 3581 3582 3583 3540 3584 //Check if ABSPATH and WPINC is defined, this is done in wp-settings.php 3541 3585 //If not defined, we can't guarante that all required functions are available.
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)