コード例 #1
0
function qt_permalink($qt, $permalink, $post_content, $modified_time, $change_freq, $priority, &$sitemap)
{
    if ($qt["enabled"]) {
        // Get modified time
        if ($modified_time != 0) {
            $modified_time = $sitemap->GetTimestampFromMySql($modified_time);
        }
        // Get a list of languages
        if ($post_content) {
            // Get available languages form post
            $languages = qtrans_getAvailableLanguages($post_content);
        } else {
            // Get all available languages
            $languages = $qt["enabled_languages"];
        }
        // Add an extra permalink url for every non-default qTranslate language
        foreach ($languages as $language) {
            if ($qt["hide_default_language"] == 1 && $qt["default_language"] == $language) {
                $sitemap->AddUrl($permalink, $modified_time, $change_freq, $priority);
            } else {
                $sitemap->AddUrl(qtrans_convertURL($permalink, $language, true), $modified_time, $change_freq, $priority);
            }
        }
    }
}
コード例 #2
0
function qs_service()
{
    global $q_config, $qs_public_key, $qs_error_messages;
    if (!isset($_REQUEST['post'])) {
        echo '<script type="text/javascript">document.location="edit.php";</script>';
        printf(__('To translate a post, please go to the <a href="%s">edit posts overview</a>.', 'qtranslate'), 'edit.php');
        exit;
    }
    $post_id = intval($_REQUEST['post']);
    $translate_from = '';
    if (isset($_REQUEST['source_language']) && qtrans_isEnabled($_REQUEST['source_language'])) {
        $translate_from = $_REQUEST['source_language'];
    }
    if (isset($_REQUEST['target_language']) && qtrans_isEnabled($_REQUEST['target_language'])) {
        $translate_to = $_REQUEST['target_language'];
    }
    if ($translate_to == $translate_from) {
        $translate_to = '';
    }
    $post =& get_post($post_id);
    if (!$post) {
        printf(__('Post with id "%s" not found!', 'qtranslate'), $post_id);
        return;
    }
    $default_service = intval(get_option('qs_default_service'));
    $service_settings = get_option('qs_service_settings');
    // Detect available Languages and possible target languages
    $available_languages = qtrans_getAvailableLanguages($post->post_content);
    if (sizeof($available_languages) == 0) {
        $error = __('The requested Post has no content, no Translation possible.', 'qtranslate');
    }
    // try to guess source and target language
    if (!in_array($translate_from, $available_languages)) {
        $translate_from = '';
    }
    $missing_languages = array_diff($q_config['enabled_languages'], $available_languages);
    if (empty($translate_from) && in_array($q_config['default_language'], $available_languages) && $translate_to != $q_config['default_language']) {
        $translate_from = $q_config['default_language'];
    }
    if (empty($translate_to) && sizeof($missing_languages) == 1) {
        $translate_to = $missing_languages[0];
    }
    if (in_array($translate_to, $available_languages)) {
        $message = __('The Post already has content for the selected target language. If a translation request is send, the current text for the target language will be overwritten.', 'qtranslate');
    }
    if (sizeof($available_languages) == 1) {
        if ($available_languages[0] == $translate_to) {
            $translate_to = '';
        }
        $translate_from = $available_languages[0];
    } elseif ($translate_from == '' && sizeof($available_languages) > 1) {
        $languages = qtrans_getSortedLanguages();
        foreach ($languages as $language) {
            if ($language != $translate_to && in_array($language, $available_languages)) {
                $translate_from = $language;
                break;
            }
        }
    }
    // link to current page with get variables
    $url_link = add_query_arg('post', $post_id);
    if (!empty($translate_to)) {
        $url_link = add_query_arg('target_language', $translate_to, $url_link);
    }
    if (!empty($translate_from)) {
        $url_link = add_query_arg('source_language', $translate_from, $url_link);
    }
    // get correct title and content
    $post_title = qtrans_use($translate_from, $post->post_title);
    $post_content = qtrans_use($translate_from, $post->post_content);
    if (isset($translate_from) && isset($translate_to)) {
        $title = sprintf('Translate &quot;%1$s&quot; from %2$s to %3$s', htmlspecialchars($post_title), $q_config['language_name'][$translate_from], $q_config['language_name'][$translate_to]);
    } elseif (isset($translate_from)) {
        $title = sprintf('Translate &quot;%1$s&quot; from %2$s', htmlspecialchars($post_title), $q_config['language_name'][$translate_from]);
    } else {
        $title = sprintf('Translate &quot;%1$s&quot;', htmlspecialchars($post_title));
    }
    // Check data
    if (isset($_POST['service_id'])) {
        $service_id = intval($_POST['service_id']);
        $default_service = $service_id;
        update_option('qs_default_service', $service_id);
        $order_key = substr(md5(time() . AUTH_KEY), 0, 20);
        $request = array('order_service_id' => $service_id, 'order_url' => get_option('home'), 'order_key' => $order_key, 'order_title' => $post_title, 'order_text' => $post_content, 'order_source_language' => $translate_from, 'order_source_locale' => $q_config['locale'][$translate_from], 'order_target_language' => $translate_to, 'order_target_locale' => $q_config['locale'][$translate_to]);
        // check for additional fields
        if (is_array($service_settings[$service_id])) {
            $request['order_required_field'] = array();
            foreach ($service_settings[$service_id] as $setting => $value) {
                $request['order_required_field'][$setting] = $value;
            }
        }
        $answer = qs_queryQS(QS_INIT_TRANSLATION, $request);
        if (isset($answer['error'])) {
            $error = sprintf(__('An error occured: %s', 'qtranslate'), $qs_error_messages[$answer['error']]);
            if ($answer['message'] != '') {
                $error .= '<br />' . sprintf(__('Additional information: %s', 'qtranslate'), qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($answer['message']));
            }
        }
        if (isset($answer['order_id'])) {
            $orders = get_option('qs_orders');
            if (!is_array($orders)) {
                $orders = array();
            }
            $orders[] = array('post_id' => $post_id, 'service_id' => $service_id, 'source_language' => $translate_from, 'target_language' => $translate_to, 'order' => array('order_key' => $order_key, 'order_id' => $answer['order_id']));
            update_option('qs_orders', $orders);
            if (empty($answer['message'])) {
                $order_completed_message = '';
            } else {
                $order_completed_message = htmlspecialchars($answer['message']);
            }
            qs_UpdateOrder($answer['order_id']);
        }
    }
    if (isset($error)) {
        ?>
<div class="wrap">
<h2><?php 
        _e('qTranslate Services', 'qtranslate');
        ?>
</h2>
<div id="message" class="error fade"><p><?php 
        echo $error;
        ?>
</p></div>
<p><?php 
        printf(__('An serious error occured and qTranslate Services cannot proceed. For help, please visit the <a href="%s">Support Forum</a>', 'qtranslate'), 'http://www.qianqin.de/qtranslate/forum/');
        ?>
</p>
</div>
<?php 
        return;
    }
    if (isset($order_completed_message)) {
        ?>
<div class="wrap">
<h2><?php 
        _e('qTranslate Services', 'qtranslate');
        ?>
</h2>
<div id="message" class="updated fade"><p><?php 
        _e('Order successfully sent.', 'qtranslate');
        ?>
</p></div>
<p><?php 
        _e('Your translation order has been successfully transfered to the selected service.', 'qtranslate');
        ?>
</p>
<?php 
        if (!empty($order_completed_message)) {
            ?>
<p><?php 
            printf(__('The service returned this message: %s', 'qtranslate'), $order_completed_message);
            ?>
</p>
<?php 
        }
        ?>
<p><?php 
        _e('Feel free to choose an action:', 'qtranslate');
        ?>
</p>
<ul>
	<li><a href="<?php 
        echo add_query_arg('target_language', null, $url_link);
        ?>
"><?php 
        _e('Translate this post to another language.', 'qtranslate');
        ?>
</a></li>
	<li><a href="edit.php"><?php 
        _e('Translate a different post.', 'qtranslate');
        ?>
</a></li>
	<li><a href="options-general.php?page=qtranslate#qtranslate_service_settings"><?php 
        _e('View all open orders.', 'qtranslate');
        ?>
</a></li>
	<li><a href="options-general.php?page=qtranslate&qs_cron=true#qtranslate_service_settings"><?php 
        _e('Let qTranslate Services check if any open orders are finished.', 'qtranslate');
        ?>
</a></li>
	<li><a href="<?php 
        echo get_permalink($post_id);
        ?>
 "><?php 
        _e('View this post.', 'qtranslate');
        ?>
</a></li>
</ul>
</div>
<?php 
        return;
    }
    ?>
<div class="wrap">
<h2><?php 
    _e('qTranslate Services', 'qtranslate');
    ?>
</h2>
<?php 
    if (!empty($message)) {
        ?>
<div id="message" class="updated fade"><p><?php 
        echo $message;
        ?>
</p></div>
<?php 
    }
    ?>
<h3><?php 
    echo $title;
    ?>
</h3>
<form action="edit.php?page=qtranslate_services" method="post" id="qtranslate-services-translate">
<p><?php 
    if (sizeof($available_languages) > 1) {
        $available_languages_name = array();
        foreach (array_diff($available_languages, array($translate_from)) as $language) {
            $available_languages_name[] = '<a href="' . add_query_arg('source_language', $language, $url_link) . '">' . $q_config['language_name'][$language] . '</a>';
        }
        $available_languages_names = join(", ", $available_languages_name);
        printf(__('Your article is available in multiple languages. If you do not want to translate from %1$s, you can switch to one of the following languages: %2$s', 'qtranslate'), $q_config['language_name'][$translate_from], $available_languages_names);
    }
    ?>
</p>
<input type="hidden" name="post" value="<?php 
    echo $post_id;
    ?>
"/>
<input type="hidden" name="source_language" value="<?php 
    echo $translate_from;
    ?>
"/>
<?php 
    if (empty($translate_to)) {
        ?>
<p><?php 
        _e('Please choose the language you want to translate to:', 'qtranslate');
        ?>
</p>
<ul>
<?php 
        foreach ($q_config['enabled_languages'] as $language) {
            if ($translate_from == $language) {
                continue;
            }
            ?>
	<li><label><input type="radio" name="target_language" value="<?php 
            echo $language;
            ?>
" /> <?php 
            echo $q_config['language_name'][$language];
            ?>
</li>
<?php 
        }
        ?>
</ul>
	<p class="submit">
		<input type="submit" name="submit" class="button-primary" value="<?php 
        _e('Continue', 'qtranslate');
        ?>
" />
	</p>
<?php 
    } else {
        ?>
<p><?php 
        printf(__('Please review your article and <a href="%s">edit</a> it if needed.', 'qtranslate'), 'post.php?action=edit&post=' . $post_id);
        ?>
</p>
<textarea name="qs_content_preview" id="qs_content_preview" readonly="readonly"><?php 
        echo $post_content;
        ?>
</textarea>
<?php 
        $timestamp = time();
        if ($timestamp != qs_queryQS(QS_VERIFY, $timestamp)) {
            ?>
<p class="error"><?php 
            _e('ERROR: Could not connect to qTranslate Services. Please try again later.', 'qtranslate');
            ?>
</p>
<?php 
            return;
        }
        ?>
<h4><?php 
        _e('Use the following Translation Service:', 'qtranslate');
        ?>
</h4>
<ul>
<?php 
        if ($services = qs_queryQS(QS_GET_SERVICES)) {
            foreach ($services as $service_id => $service) {
                // check if we have data for all required fields
                $requirements_matched = true;
                foreach ($service['service_required_fields'] as $field) {
                    if (!isset($service_settings[$service_id][$field['name']]) || $service_settings[$service_id][$field['name']] == '') {
                        $requirements_matched = false;
                    }
                }
                if (!$requirements_matched) {
                    ?>
<li>
	<label><input type="radio" name="service_id" disabled="disabled" /> <b><?php 
                    echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_name']);
                    ?>
</b> ( <a href="<?php 
                    echo $service['service_url'];
                    ?>
" target="_blank"><?php 
                    _e('Website', 'qtranslate');
                    ?>
</a> )</label>
	<p class="error"><?php 
                    printf(__('Cannot use this service, not all <a href="%s">required fields</a> filled in for this service.', 'qtranslate'), 'options-general.php?page=qtranslate#qs_service_' . $service_id);
                    ?>
</p>
	<p class="service_description"><?php 
                    echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_description']);
                    ?>
</p>
</li>
<?php 
                } else {
                    ?>
<li><label><input type="radio" name="service_id" <?php 
                    if ($default_service == $service['service_id']) {
                        echo 'checked="checked"';
                    }
                    ?>
 value="<?php 
                    echo $service['service_id'];
                    ?>
" /> <b><?php 
                    echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_name']);
                    ?>
</b> ( <a href="<?php 
                    echo $service['service_url'];
                    ?>
" target="_blank"><?php 
                    _e('Website', 'qtranslate');
                    ?>
</a> )</label><p class="service_description"><?php 
                    echo qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($service['service_description']);
                    ?>
</p></li>
<?php 
                }
            }
            ?>
</ul>
<p><?php 
            _e('Your article will be SSL encrypted and securly sent to qTranslate Services, which will forward your text to the chosen Translation Service. Once qTranslate Services receives the translated text, it will automatically appear on your blog.', 'qtranslate');
            ?>
</p>
	<p class="submit">
		<input type="hidden" name="target_language" value="<?php 
            echo $translate_to;
            ?>
"/>
		<input type="submit" name="submit" class="button-primary" value="<?php 
            _e('Request Translation', 'qtranslate');
            ?>
" />
	</p>
<?php 
        }
    }
    ?>
</div>
</form>
<?php 
}
コード例 #3
0
function qtrans_languageColumn($column)
{
    global $q_config, $post;
    if ($column == 'language') {
        $available_languages = qtrans_getAvailableLanguages($post->post_content);
        $missing_languages = array_diff($q_config['enabled_languages'], $available_languages);
        $available_languages_name = array();
        $missing_languages_name = array();
        foreach ($available_languages as $language) {
            $available_languages_name[] = $q_config['language_name'][$language];
        }
        $available_languages_names = join(", ", $available_languages_name);
        echo apply_filters('mqtranslate_available_languages_names', $available_languages_names);
        do_action('mqtranslate_languageColumn', $available_languages, $missing_languages);
    }
    return $column;
}
コード例 #4
0
function qtrans_isAvailableIn($post_id, $language = '')
{
    global $q_config;
    if ($language == '') {
        $language = $q_config['default_language'];
    }
    $post =& get_post($post_id);
    $languages = qtrans_getAvailableLanguages($post->post_content);
    return in_array($language, $languages);
}
コード例 #5
0
 /**
  * Builds the sitemap and writes it into a xml file.
  *
  * @since 3.0
  * @access public
  * @author Arne Brachhold <himself [at] arnebrachhold [dot] de>
  * @return array An array with messages such as failed writes etc.
  */
 function BuildSitemap()
 {
     global $wpdb, $posts, $wp_version;
     $this->Initate();
     if ($this->GetOption("b_memory") != '') {
         @ini_set("memory_limit", $this->GetOption("b_memory"));
     }
     if ($this->GetOption("b_time") != -1) {
         @set_time_limit($this->GetOption("b_time"));
     }
     //This object saves the status information of the script directly to the database
     $status = new GoogleSitemapGeneratorStatus();
     //Other plugins can detect if the building process is active
     $this->_isActive = true;
     //$this->AddElement(new GoogleSitemapGeneratorXmlEntry());
     //Debug mode?
     $debug = $this->GetOption("b_debug");
     if ($this->GetOption("b_xml")) {
         $fileName = $this->GetXmlPath();
         $status->StartXml($this->GetXmlPath(), $this->GetXmlUrl());
         if ($this->IsFileWritable($fileName)) {
             $this->_fileHandle = fopen($fileName, "w");
             if (!$this->_fileHandle) {
                 $status->EndXml(false, "Not openable");
             }
         } else {
             $status->EndXml(false, "not writable");
         }
     }
     //Write gzipped sitemap file
     if ($this->IsGzipEnabled()) {
         $fileName = $this->GetZipPath();
         $status->StartZip($this->GetZipPath(), $this->GetZipUrl());
         if ($this->IsFileWritable($fileName)) {
             $this->_fileZipHandle = gzopen($fileName, "w1");
             if (!$this->_fileZipHandle) {
                 $status->EndZip(false, "Not openable");
             }
         } else {
             $status->EndZip(false, "not writable");
         }
     }
     if (!$this->_fileHandle && !$this->_fileZipHandle) {
         $status->End();
         return;
     }
     //Content of the XML file
     $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>'));
     $styleSheet = $this->GetDefaultStyle() && $this->GetOption('b_style_default') === true ? $this->GetDefaultStyle() : $this->GetOption('b_style');
     if (!empty($styleSheet)) {
         $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<' . '?xml-stylesheet type="text/xsl" href="' . $styleSheet . '"?' . '>'));
     }
     $this->AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"wordpress/" . get_bloginfo('version') . "\""));
     $this->AddElement(new GoogleSitemapGeneratorDebugEntry("sitemap-generator-url=\"http://www.arnebrachhold.de\" sitemap-generator-version=\"" . $this->GetVersion() . "\""));
     $this->AddElement(new GoogleSitemapGeneratorDebugEntry("generated-on=\"" . date(get_option("date_format") . " " . get_option("time_format")) . "\""));
     //All comments as an asso. Array (postID=>commentCount)
     $comments = $this->GetOption("b_prio_provider") != "" ? $this->GetComments() : array();
     //Full number of comments
     $commentCount = count($comments) > 0 ? $this->GetCommentCount($comments) : 0;
     if ($debug && $this->GetOption("b_prio_provider") != "") {
         $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Total comment count: " . $commentCount));
     }
     //Go XML!
     $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'));
     $home = get_bloginfo('url');
     $homePid = 0;
     //[NeoEGM] Moved here for home page support for different languages
     $useQTransLate = function_exists('qtrans_convertURL') && function_exists('qtrans_getAvailableLanguages');
     global $q_config;
     //Add the home page (WITH a slash!)
     if ($this->GetOption("in_home")) {
         if ('page' == get_option('show_on_front') && get_option('page_on_front')) {
             $pageOnFront = get_option('page_on_front');
             $p = get_page($pageOnFront);
             if ($p) {
                 $homePid = $p->ID;
                 $this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
                 //[NeoEGM] Home page support for different languages
                 if ($useQTransLate) {
                     foreach ($q_config['enabled_languages'] as $language) {
                         if ($language != $q_config['default_language']) {
                             $this->AddUrl(qtrans_convertURL(trailingslashit($home), $language, true), $this->GetTimestampFromMySql($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
                         }
                     }
                 }
             }
         } else {
             $this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql(get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
             //[NeoEGM] Home page support for different languages
             if ($useQTransLate) {
                 foreach ($q_config['enabled_languages'] as $language) {
                     if ($language != $q_config['default_language']) {
                         $this->AddUrl(qtrans_convertURL(trailingslashit($home), $language, true), $this->GetTimestampFromMySql(get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home"));
                     }
                 }
             }
         }
     }
     //Add the posts
     if ($this->GetOption("in_posts") || $this->GetOption("in_pages")) {
         if ($debug) {
             $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Postings"));
         }
         //Pre 2.1 compatibility. 2.1 introduced 'future' as post_status so we don't need to check post_date
         $wpCompat = floatval($wp_version) < 2.1;
         //[NeoEGM] Line removed
         //$useQTransLate = false; //function_exists('qtrans_convertURL') && function_exists('qtrans_getEnabledLanguages'); Not really working yet
         $excludes = $this->GetOption('b_exclude');
         //Excluded posts
         $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
             if (is_array($exPosts) && count($exPosts) > 0) {
                 //Merge it with the list of user excluded posts
                 $excludes = array_merge($excludes, $exPosts);
             }
         }
         $contentStmt = '';
         if ($useQTransLate) {
             $contentStmt .= ', post_content ';
         }
         $postPageStmt = '';
         $inSubPages = $this->GetOption('in_posts_sub') === true;
         if ($inSubPages && $this->GetOption('in_posts') === true) {
             $pageDivider = '<!--nextpage-->';
             $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 && $post->ID != $homePid) {
                     $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;
                     }
                     //[NeoEGM] Support for qTranslate either installed or not
                     if ($useQTransLate) {
                         //Add it
                         //[NeoEGM] Add it only if the default language is defined, otherwise only add the defined languages
                         $QTranslateLanguages = qtrans_getAvailableLanguages($post->post_content);
                         if (in_array($q_config['default_language'], $QTranslateLanguages)) {
                             $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);
                         }
                     } else {
                         $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 . '&amp;page=' . ($p + 1);
                             } else {
                                 $subPage = trailingslashit($permalink) . user_trailingslashit($p + 1, '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
                     //[NeoEGM] Moved up the global variable scope line
                     if ($useQTransLate) {
                         foreach ($QTranslateLanguages as $language) {
                             if ($language != $q_config['default_language']) {
                                 $this->AddUrl(qtrans_convertURL($permalink, $language, true), $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("\r\n\t\t\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\t\tc.cat_ID AS ID,\r\n\t\t\t\t\t\t\t\tMAX(p.post_modified_gmt) AS last_mod\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\t`" . $wpdb->categories . "` c,\r\n\t\t\t\t\t\t\t\t`" . $wpdb->post2cat . "` pc,\r\n\t\t\t\t\t\t\t\t`" . $wpdb->posts . "` p\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tpc.category_id = c.cat_ID\r\n\t\t\t\t\t\t\t\tAND p.ID = pc.post_id\r\n\t\t\t\t\t\t\t\tAND p.post_status = 'publish'\r\n\t\t\t\t\t\t\t\tAND p.post_type='post'\r\n\t\t\t\t\t\t\tGROUP\r\n\t\t\t\t\t\t\t\tBY c.cat_id\r\n\t\t\t\t\t\t\t");
             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("\r\n\t\t\t\t\t\tSELECT DISTINCT\r\n\t\t\t\t\t\t\tYEAR(post_date_gmt) AS `year`,\r\n\t\t\t\t\t\t\tMONTH(post_date_gmt) AS `month`,\r\n\t\t\t\t\t\t\tMAX(post_date_gmt) as last_mod,\r\n\t\t\t\t\t\t\tcount(ID) as posts\r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t{$wpdb->posts}\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\tpost_date < '{$now}'\r\n\t\t\t\t\t\t\tAND post_status = 'publish'\r\n\t\t\t\t\t\t\tAND post_type = 'post'\r\n\t\t\t\t\t\t\t" . (floatval($wp_version) < 2.1 ? "AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'" : "") . "\r\n\t\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\t\tYEAR(post_date_gmt),\r\n\t\t\t\t\t\t\tMONTH(post_date_gmt)\r\n\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\tpost_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\r\n\t\t\t\t\t\t\t{$wpdb->users}.ID,\r\n\t\t\t\t\t\t\t{$wpdb->users}.user_nicename,\r\n\t\t\t\t\t\t\tMAX({$wpdb->posts}.post_modified_gmt) AS last_post\r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t{$wpdb->users},\r\n\t\t\t\t\t\t\t{$wpdb->posts}\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t{$wpdb->posts}.post_author = {$wpdb->users}.ID\r\n\t\t\t\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\r\n\t\t\t\t\t\t\tAND {$wpdb->posts}.post_type = 'post'\r\n\t\t\t\t\t\t\tAND {$wpdb->posts}.post_password = ''\r\n\t\t\t\t\t\t\t" . (floatval($wp_version) < 2.1 ? "AND {$wpdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'" : "") . "\r\n\t\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\t\t{$wpdb->users}.ID,\r\n\t\t\t\t\t\t\t{$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("</urlset>"));
     $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;
 }