User-agent: * Disallow: , $exPosts); } } $contentStmt = ''; if($useQTransLate) { $contentStmt.=', post_content '; } $postPageStmt = ''; $inSubPages = ($this->GetOption('in_posts_sub')===true); if($inSubPages && $this->GetOption('in_posts')===true) { $pageDivider=''; $postPageStmt = ", (character_length(`post_content`) - character_length(REPLACE(`post_content`, '$pageDivider', ''))) / " . strlen($pageDivider) . " as postPages"; } $sql="SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` $postPageStmt $contentStmt FROM `" . $wpdb->posts . "` WHERE "; $where = '('; if($this->GetOption('in_posts')) { //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 = '')) "; } if($this->GetOption('in_pages')) { if($this->GetOption('in_posts')) { $where.=" OR "; } if($wpCompat) { //WP < 2.1: posts have post_status = published, pages have post_status = static $where.=" post_status='static' "; } else { //WP >= 2.1: posts have post_type = 'post' and pages have post_type = 'page'. Both must be published. $where.=" (post_status = 'publish' AND post_type = 'page') "; } } $where.=") "; if(is_array($excludes) && count($excludes)>0) { $where.=" AND ID NOT IN ('" . implode("','",$excludes) . "')"; } $where.=" AND post_password='' ORDER BY post_modified DESC"; $sql .= $where; if($this->GetOption("b_max_posts")>0) { $sql.=" LIMIT 0," . $this->GetOption("b_max_posts"); } $postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE ". $where,0,0)); //Create a new connection because we are using mysql_unbuffered_query and don't want to disturb the WP connection //Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :( $con = $postRes = null; //In 2.2, a bug which prevented additional DB connections was fixed if(floatval($wp_version) < 2.2) { $this->SetOption("b_safemode",true); } if($this->GetOption("b_safemode")===true) { $postRes = mysql_query($sql,$wpdb->dbh); if(!$postRes) { trigger_error("MySQL query failed: " . mysql_error(),E_USER_NOTICE); //E_NOTE will be displayed on our debug mode return; } } else { $con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD,true); if(!$con) { trigger_error("MySQL Connection failed: " . mysql_error(),E_USER_NOTICE); return; } if(!mysql_select_db(DB_NAME,$con)) { trigger_error("MySQL DB Select failed: " . mysql_error(),E_USER_NOTICE); return; } $postRes = mysql_unbuffered_query($sql,$con); if(!$postRes) { trigger_error("MySQL unbuffered query failed: " . mysql_error(),E_USER_NOTICE); return; } } if($postRes) { //#type $prioProvider GoogleSitemapGeneratorPrioProviderBase $prioProvider=NULL; if($this->GetOption("b_prio_provider") != '') { $providerClass=$this->GetOption('b_prio_provider'); $prioProvider = new $providerClass($commentCount,$postCount); } //$posts is used by Alex King's Popularity Contest plugin //if($posts == null || !is_array($posts)) { // $posts = &$postRes; //} $z = 1; $zz = 1; //Default priorities $default_prio_posts = $this->GetOption('pr_posts'); $default_prio_pages = $this->GetOption('pr_pages'); //Change frequencies $cf_pages = $this->GetOption('cf_pages'); $cf_posts = $this->GetOption('cf_posts'); $minPrio=$this->GetOption('pr_posts_min'); //Cycle through all posts and add them while($post = mysql_fetch_object($postRes)) { //Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later. $cache = array(&$post); update_post_cache($cache); //Set the current working post for other plugins which depend on "the loop" $GLOBALS['post'] = &$post; $permalink = get_permalink($post->ID); if($permalink != $home) { $isPage = false; if($wpCompat) { $isPage = ($post->post_status == 'static'); } else { $isPage = ($post->post_type == 'page'); } //Default Priority if auto calc is disabled $prio = 0; if($isPage) { //Priority for static pages $prio = $default_prio_pages; } else { //Priority for normal posts $prio = $default_prio_posts; } //If priority calc. is enabled, calculate (but only for posts, not pages)! if($prioProvider !== null && !$isPage) { //Comment count for this post $cmtcnt = (isset($comments[$post->ID])?$comments[$post->ID]:0); $prio = $prioProvider->GetPostPriority($post->ID, $cmtcnt, $post); if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points')); } if(!$isPage && $minPrio>0 && $prio<$minPrio) { $prio = $minPrio; } //Add it $this->AddUrl($permalink,$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio); if($inSubPages) { $subPage = ''; for($p =1; $p<=$post->postPages; $p++) { if(get_option('permalink_structure') == '') { $subPage = $permalink . '&page=' . $p; } else { $subPage = trailingslashit($permalink) . user_trailingslashit($p, 'single_paged'); } $this->AddUrl($subPage,$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio); } } // Multilingual Support with qTranslate, thanks to Qian Qin if($useQTransLate) { global $q_config; foreach(qtrans_getEnabledLanguages($post->post_content) as $language) { if($language!=$q_config['default_language']) { $this->AddUrl(qtrans_convertURL($permalink,$language),$this->GetTimestampFromMySql(($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt)),($isPage?$cf_pages:$cf_posts),$prio); } } } } //Update the status every 100 posts and at the end. //If the script breaks because of memory or time limit, //we have a "last reponded" value which can be compared to the server settings if($zz==100 || $z == $postCount) { $status->SaveStep($z); $zz=0; } else $zz++; $z++; //Clean cache because it's incomplete if(version_compare($wp_version,"2.5",">=")) { //WP 2.5 makes a mysql query for every clean_post_cache to clear the child cache //so I've copied the function here until a patch arrives... wp_cache_delete($post->ID, 'posts'); wp_cache_delete($post->ID, 'post_meta'); clean_object_term_cache($post->ID, 'post'); } else { clean_post_cache($post->ID); } } unset($postRes); unset($prioProvider); if($this->GetOption("b_safemode")!==true && $con) mysql_close($con); } if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Postings")); } //Add the cats if($this->GetOption("in_cats")) { if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Cats")); $exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats if($exclCats == null) $exclCats=array(); if(!$this->IsTaxonomySupported()) { $catsRes=$wpdb->get_results(" SELECT c.cat_ID AS ID, MAX(p.post_modified_gmt) AS last_mod FROM `" . $wpdb->categories . "` c, `" . $wpdb->post2cat . "` pc, `" . $wpdb->posts . "` p WHERE pc.category_id = c.cat_ID AND p.ID = pc.post_id AND p.post_status = 'publish' AND p.post_type='post' GROUP BY c.cat_id "); if($catsRes) { foreach($catsRes as $cat) { if($cat && $cat->ID && $cat->ID>0 && !in_array($cat->ID, $exclCats)) { if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Cat-ID:" . $cat->ID)); $this->AddUrl(get_category_link($cat->ID),$this->GetTimestampFromMySql($cat->last_mod),$this->GetOption("cf_cats"),$this->GetOption("pr_cats")); } } } } else { $cats = get_terms("category",array("hide_empty"=>true,"hierarchical"=>false)); if($cats && is_array($cats) && count($cats)>0) { foreach($cats AS $cat) { if(!in_array($cat->term_id, $exclCats)) $this->AddUrl(get_category_link($cat->term_id),0,$this->GetOption("cf_cats"),$this->GetOption("pr_cats")); } } } if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Cats")); } //Add the archives if($this->GetOption("in_arch")) { if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Archive")); $now = current_time('mysql'); //WP2.1 introduced post_status='future', for earlier WP versions we need to check the post_date_gmt $arcresults = $wpdb->get_results(" SELECT DISTINCT YEAR(post_date_gmt) AS `year`, MONTH(post_date_gmt) AS `month`, MAX(post_date_gmt) as last_mod, count(ID) as posts FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' AND post_type = 'post' " . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . " GROUP BY YEAR(post_date_gmt), MONTH(post_date_gmt) ORDER BY post_date_gmt DESC"); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); $changeFreq=""; //Archive is the current one if($arcresult->month==date("n") && $arcresult->year==date("Y")) { $changeFreq=$this->GetOption("cf_arch_curr"); } else { // Archive is older $changeFreq=$this->GetOption("cf_arch_old"); } $this->AddUrl($url,$this->GetTimestampFromMySql($arcresult->last_mod),$changeFreq,$this->GetOption("pr_arch")); } } if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Archive")); } //Add the author pages if($this->GetOption("in_auth")) { if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Author pages")); $linkFunc = null; //get_author_link is deprecated in WP 2.1, try to use get_author_posts_url first. if(function_exists('get_author_posts_url')) { $linkFunc = 'get_author_posts_url'; } else if(function_exists('get_author_link')) { $linkFunc = 'get_author_link'; } //Who knows what happens in later WP versions, so check again if it worked if($linkFunc !== null) { //Unfortunately there is no API function to get all authors, so we have to do it the dirty way... //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 {$wpdb->users}.ID, {$wpdb->users}.user_nicename, MAX({$wpdb->posts}.post_modified_gmt) AS last_post FROM {$wpdb->users}, {$wpdb->posts} WHERE {$wpdb->posts}.post_author = {$wpdb->users}.ID AND {$wpdb->posts}.post_status = 'publish' AND {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_password = '' " . (floatval($wp_version) < 2.1?"AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'":"") . " GROUP BY {$wpdb->users}.ID, {$wpdb->users}.user_nicename"; $authors = $wpdb->get_results($sql); if($authors && is_array($authors)) { foreach($authors as $author) { if($debug) if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Author-ID:" . $author->ID)); $url = ($linkFunc=='get_author_posts_url'?get_author_posts_url($author->ID,$author->user_nicename):get_author_link(false,$author->ID,$author->user_nicename)); $this->AddUrl($url,$this->GetTimestampFromMySql($author->last_post),$this->GetOption("cf_auth"),$this->GetOption("pr_auth")); } } } else { //Too bad, no author pages for you :( if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: No valid author link function found")); } if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Author pages")); } //Add tag pages if($this->GetOption("in_tags") && $this->IsTaxonomySupported()) { if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Tags")); $tags = get_terms("post_tag",array("hide_empty"=>true,"hierarchical"=>false)); if($tags && is_array($tags) && count($tags)>0) { foreach($tags AS $tag) { $this->AddUrl(get_tag_link($tag->term_id),0,$this->GetOption("cf_tags"),$this->GetOption("pr_tags")); } } if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Tags")); } //Add the custom pages if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Custom Pages")); if($this->_pages && is_array($this->_pages) && count($this->_pages)>0) { //#type $page GoogleSitemapGeneratorPage foreach($this->_pages AS $page) { $this->AddUrl($page->GetUrl(),$page->getLastMod(),$page->getChangeFreq(),$page->getPriority()); } } if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Custom Pages")); if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start additional URLs")); do_action("sm_buildmap"); if($debug) $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End additional URLs")); $this->AddElement(new GoogleSitemapGeneratorXmlEntry("")); $pingUrl=''; if($this->GetOption("b_xml")) { if($this->_fileHandle && fclose($this->_fileHandle)) { $this->_fileHandle = null; $status->EndXml(true); $pingUrl=$this->GetXmlUrl(); } else $status->EndXml(false,"Could not close the sitemap file."); } if($this->IsGzipEnabled()) { if($this->_fileZipHandle && fclose($this->_fileZipHandle)) { $this->_fileZipHandle = null; $status->EndZip(true); $pingUrl=$this->GetZipUrl(); } else $status->EndZip(false,"Could not close the zipped sitemap file"); } //Ping Google if($this->GetOption("b_ping") && !empty($pingUrl)) { $sPingUrl="http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl); $status->StartGooglePing($sPingUrl); $pingres=$this->RemoteOpen($sPingUrl); if($pingres==NULL || $pingres===false) { $status->EndGooglePing(false,$this->_lastError); trigger_error("Failed to ping Google: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE); } else { $status->EndGooglePing(true); } } //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) { trigger_error("Failed to ping Bing: " . htmlspecialchars(strip_tags($pingres)),E_USER_NOTICE); $status->EndMsnPing(false,$this->_lastError); } else { $status->EndMsnPing(true); } } $status->End(); $this->_isActive = false; //done... return $status; } function RemoteOpen($url,$method = 'get', $postData = null, $timeout = 10) { global $wp_version; //Before WP 2.7, wp_remote_fopen was quite crappy so Snoopy was favoured. if(floatval($wp_version) < 2.7) { if(!file_exists(ABSPATH . 'wp-includes/class-snoopy.php')) { trigger_error('Snoopy Web Request failed: Snoopy not found.',E_USER_NOTICE); return false; //Hoah? } require_once( ABSPATH . 'wp-includes/class-snoopy.php'); $s = new Snoopy(); $s->read_timeout = $timeout; if($method == 'get') { $s->fetch($url); } else { $s->submit($url,$postData); } if($s->status != "200") trigger_error('Snoopy Web Request failed: Status: ' . $s->status . "; Content: " . htmlspecialchars($s->results),E_USER_NOTICE); return $s->results; } else { $options = array(); $options['timeout'] = $timeout; if($method == 'get') { $response = wp_remote_get( $url, $options ); } else { $response = wp_remote_post($url, array_merge($options,array('body'=>$postData))); } if ( is_wp_error( $response ) ) { $errs = $response->get_error_messages(); $errs = htmlspecialchars(implode('; ', $errs)); trigger_error('WP HTTP API Web Request failed: ' . $errs,E_USER_NOTICE); return false; } return $response['body']; } return false; } /** * Tracks the last error (gets called by PHP) * * @since 3.0 * @access private * @author Arne Brachhold */ function TrackError($log_level, $log_text, $error_file, $error_line) { $this->_lastError = $log_text; } /** * Echos option fields for an select field containing the valid change frequencies * * @since 3.0 * @access private * @author Arne Brachhold * @param $currentVal The value which should be selected * @return all valid change frequencies as html option fields */ function HtmlGetFreqNames($currentVal) { foreach($this->_freqNames AS $k=>$v) { echo ""; } } /** * Echos option fields for an select field containing the valid priorities (0- 1.0) * * @since 3.0 * @access private * @author Arne Brachhold * @param $currentVal string The value which should be selected * @return 0.0 - 1.0 as html option fields */ function HtmlGetPriorityValues($currentVal) { $currentVal=(float) $currentVal; for($i=0.0; $i<=1.0; $i+=0.1) { $v = number_format($i,1,".",""); $t = number_format_i18n($i,1); echo ""; } } /** * Returns the checked attribute if the given values match * * @since 3.0 * @access private * @author Arne Brachhold * @param $val string The current value * @param $equals string The value to match * @return The checked attribute if the given values match, an empty string if not */ function HtmlGetChecked($val,$equals) { if($val==$equals) return $this->HtmlGetAttribute("checked"); else return ""; } /** * Returns the selected attribute if the given values match * * @since 3.0 * @access private * @author Arne Brachhold * @param $val string The current value * @param $equals string The value to match * @return The selected attribute if the given values match, an empty string if not */ function HtmlGetSelected($val,$equals) { if($val==$equals) return $this->HtmlGetAttribute("selected"); else return ""; } /** * Returns an formatted attribute. If the value is NULL, the name will be used. * * @since 3.0 * @access private * @author Arne Brachhold * @param $attr string The attribute name * @param $value string The attribute value * @return The formatted attribute */ function HtmlGetAttribute($attr,$value=NULL) { if($value==NULL) $value=$attr; return " " . $attr . "=\"" . $value . "\" "; } /** * Returns an array with GoogleSitemapGeneratorPage objects which is generated from POST values * * @since 3.0 * @see GoogleSitemapGeneratorPage * @access private * @author Arne Brachhold * @return array An array with GoogleSitemapGeneratorPage objects */ function HtmlApplyPages() { // Array with all page URLs $pages_ur=(!isset($_POST["sm_pages_ur"]) || !is_array($_POST["sm_pages_ur"])?array():$_POST["sm_pages_ur"]); //Array with all priorities $pages_pr=(!isset($_POST["sm_pages_pr"]) || !is_array($_POST["sm_pages_pr"])?array():$_POST["sm_pages_pr"]); //Array with all change frequencies $pages_cf=(!isset($_POST["sm_pages_cf"]) || !is_array($_POST["sm_pages_cf"])?array():$_POST["sm_pages_cf"]); //Array with all lastmods $pages_lm=(!isset($_POST["sm_pages_lm"]) || !is_array($_POST["sm_pages_lm"])?array():$_POST["sm_pages_lm"]); //Array where the new pages are stored $pages=array(); //Loop through all defined pages and set their properties into an object if(isset($_POST["sm_pages_mark"]) && is_array($_POST["sm_pages_mark"])) { for($i=0; $iSetUrl($pages_ur[$i]); $p->SetProprity($pages_pr[$i]); $p->SetChangeFreq($pages_cf[$i]); //Try to parse last modified, if -1 (note ===) automatic will be used (0) $lm=(!empty($pages_lm[$i])?strtotime($pages_lm[$i],time()):-1); if($lm===-1) $p->setLastMod(0); else $p->setLastMod($lm); //Add it to the array array_push($pages,$p); } } return $pages; } function GetTimestampFromMySql($mysqlDateTime) { list($date, $hours) = split(' ', $mysqlDateTime); list($year,$month,$day) = split('-',$date); list($hour,$min,$sec) = split(':',$hours); return mktime($hour, $min, $sec, $month, $day, $year); } function GetRedirectLink($redir) { return trailingslashit("http://www.arnebrachhold.de/redir/" . $redir); } function GetBackLink() { $page = basename(__FILE__); if(isset($_GET['page']) && !empty($_GET['page'])) { $page = preg_replace('[^a-zA-Z0-9\.\_\-]','',$_GET['page']); } if(function_exists("admin_url")) return admin_url(basename($_SERVER["PHP_SELF"])) . "?page=" . $page; else return $_SERVER['PHP_SELF'] . "?page=" . $page; } function HtmlShowOptionsPage() { $ui = $this->GetUI(); if($ui) { $ui->HtmlShowOptionsPage(); return true; } return false; } var $_ui = null; function GetUI() { global $wp_version; if($this->_ui === null) { $className='GoogleSitemapGeneratorUI'; $fileName='sitemap-ui.php'; if(!class_exists($className)) { $path = trailingslashit(dirname(__FILE__)); if(!file_exists( $path . $fileName)) return false; require_once($path. $fileName); } $this->_ui = new $className($this); } return $this->_ui; } function HtmlShowHelp() { } } Sitemap: http://freeadultwebcamslive.com/sitemap.xml.gz