/**
 * Google XML Sitemap
 *
 * @author Cor van Noorloos
 * @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
 * @link https://github.com/corvannoorloos/google-xml-sitemap
 *
 * @wordpress
 * HiddenPlugin Name: Google XML Sitemap
 * Plugin URI: https://github.com/corvannoorloos/google-xml-sitemap
 * Description: Sitemaps are a way to tell Google about pages on your site we might not otherwise discover. In its simplest terms, a XML Sitemap—usually called Sitemap, with a capital S—is a list of the pages on your website. Creating and submitting a Sitemap helps make sure that Google knows about all the pages on your site, including URLs that may not be discoverable by Google's normal crawling process.
 * Author: Cor van Noorloos
 * Version: 0.1.1
 * Author URI: http://corvannoorloos.com/
 * (Bookt) The original file has been modified to output specific entries from BAPI seo data
 */
function google_sitemap()
{
    if (!preg_match('/sitemap\\.xml$/', $_SERVER['REQUEST_URI'])) {
        return;
    }
    global $wpdb;
    $posts = $wpdb->get_results("SELECT ID, post_title, post_modified_gmt\r\n\t\tFROM {$wpdb->posts}\r\n\t\tWHERE post_status = 'publish'\r\n\t\tAND post_type <> 'nav_menu_item'\r\n\t\tAND post_name <> 'hello-world'\r\n\t\tAND post_password = ''\r\n\t\tORDER BY post_type DESC, post_modified DESC\r\n\t\tLIMIT 50000");
    header("HTTP/1.1 200 OK");
    header('X-Robots-Tag: noindex, follow', true);
    header('Content-Type: text/xml');
    echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?>' . "\n";
    echo '<!-- generator="' . home_url('/') . '" -->' . "\n";
    $xml = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 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">' . "\n";
    $xml .= "\t<url>" . "\n";
    $xml .= "\t\t<loc>" . home_url('/') . "</loc>\n";
    $xml .= "\t\t<lastmod>" . mysql2date('Y-m-d\\TH:i:s+00:00', get_lastpostmodified('GMT'), false) . "</lastmod>\n";
    $xml .= "\t\t<changefreq>" . 'daily' . "</changefreq>\n";
    $xml .= "\t\t<priority>" . '1' . "</priority>\n";
    $xml .= "\t</url>" . "\n";
    foreach ($posts as $post) {
        if ($post->ID == get_option('page_on_front')) {
            continue;
        }
        if (!empty($post->post_title)) {
            // prevent outputing detail screens which can be determined by seeing if the post has a meta bapikey
            $bapikey = get_post_meta($post->ID, "bapikey", true);
            if (empty($bapikey)) {
                $xml .= "\t<url>\n";
                $xml .= "\t\t<loc>" . get_permalink($post->ID) . "</loc>\n";
                $xml .= "\t\t<lastmod>" . mysql2date('Y-m-d\\TH:i:s+00:00', $post->post_modified_gmt, false) . "</lastmod>\n";
                $xml .= "\t\t<changefreq>" . 'weekly' . "</changefreq>\n";
                $xml .= "\t\t<priority>" . '0.8' . "</priority>\n";
                $xml .= "\t</url>\n";
            }
        }
    }
    // now output the pages from bapi seo data
    global $bapisync;
    global $bapi_all_options;
    foreach ($bapisync->seodata as $seo) {
        if (!empty($seo["entity"]) && !empty($seo["pkid"])) {
            $turl = BAPISync::cleanurl($seo["DetailURL"]);
            $xml .= "\t<url>\n";
            $xml .= "\t\t<loc>" . $bapi_all_options['bapi_site_cdn_domain'] . $turl . "</loc>\n";
            $xml .= "\t\t<lastmod>" . mysql2date('Y-m-d\\TH:i:s+00:00', $seo["ModifiedOn"]["LongDateTime"], false) . "</lastmod>\n";
            $xml .= "\t\t<changefreq>" . 'weekly' . "</changefreq>\n";
            $xml .= "\t\t<priority>" . '0.8' . "</priority>\n";
            $xml .= "\t</url>\n";
        }
    }
    $xml .= '</urlset>';
    echo "{$xml}";
    exit;
}
Ejemplo n.º 2
0
 /**
  * Loop on each syncable entities present in $_default_entity_diff_meth_ids, call the diff method associated and do the sync on each entity 
  * In case of error (return false), error information can be found in $this->_errors array.
  * 
  * @return bool
  */
 public function sync_entities()
 {
     if (!is_string($this->_api_key) || !strlen($this->_api_key)) {
         $this->log_error(0, 'Invalid API key');
         return false;
     }
     $success_log = array();
     foreach ($this->_entity_diff_meth_ids as $entity => $options) {
         // In case of error propagate, the error, don't update the diff_id and continue with the next entity
         // Call the diff method to get the changed entity's ids
         if (!is_array($ids_to_update = $this->get_entity_diff($entity, array($options['diff_method_name'] => $options['diff_id']), $new_diff_id))) {
             $this->log_error(1, 'Unable to process diff method', array('entity' => $entity, $options['diff_method_name'] => $options['diff_id'], 'url' => $this->url, 'cron_endpoint' => BAPI_CRON_ENDPOINT));
             continue;
         }
         // First time the cron is executed, we just save the returned diff id and the first execution timestamp, without syncing anything
         if (null === $this->_entity_diff_meth_ids[$entity]['first_cron_execution']) {
             $this->_entity_diff_meth_ids[$entity]['diff_id'] = $new_diff_id;
             $this->_entity_diff_meth_ids[$entity]['first_cron_execution'] = time();
             continue;
         }
         if (count($ids_to_update) > 0) {
             // Initialize the "cache" for get call (this reduce the number of calls by doing bulk calls of ids and caching the result
             $cache_options = array();
             // Taken from getMustache() function
             if ($entity == "property") {
                 $cache_options = array("seo" => 1, "descrip" => 1, "avail" => 1, "rates" => 1, "reviews" => 1, "poi" => 1);
             } else {
                 if ($entity == "poi") {
                     // Taken from getMustache() function
                     $cache_options = array("nearbyprops" => 1, "seo" => 1);
                 }
             }
             // Initialize the "cache" of get calls, the return value is not checked because if it didn't worked, then get calls won't use the cache.
             $this->_bapi->init_get_cache($entity, $ids_to_update, $cache_options);
             foreach ($ids_to_update as $id) {
                 if (!is_array($seo = $this->get_seo_from_bapi_cache($entity, $id))) {
                     $this->log_error(3, 'Unable to retrieve the SEO', array('entity' => $entity, 'entity_id' => $id));
                     continue 2;
                 }
                 if (!is_a($post = get_page_by_path(BAPISync::cleanurl($seo["DetailURL"])), 'WP_Post')) {
                     continue 1;
                 }
                 if (!kigo_sync_entity($post, $seo, true)) {
                     $this->log_error(4, 'Unable to process the sync', array('entity' => $entity, 'entity_id' => $id, 'SEO' => $seo));
                     continue 2;
                 }
             }
             $success_log[] = array('entity' => $entity, 'nb_of_updates' => count($ids_to_update));
         }
         // If this point is reached that means the sync has been done without error, we can update the diff_id and save the timestamp
         $this->_entity_diff_meth_ids[$entity]['diff_id'] = $new_diff_id;
         $this->_entity_diff_meth_ids[$entity]['last_update_timestamp'] = time();
     }
     if (!count($this->_errors) && (!is_string($json_entity_diff_meth_ids = json_encode($this->_entity_diff_meth_ids)) || !update_option(self::KIGO_CRON_DIFF_OPTION, $json_entity_diff_meth_ids))) {
         $this->log_error(5, 'Unable to update the option', array('entity_diff_meth_ids' => $this->_entity_diff_meth_ids));
     }
     if (count($success_log)) {
         $this->log_error(10, 'Correct update', $success_log);
     }
     return 0 === count($this->_errors);
 }
Ejemplo n.º 3
0
 public function getSEOFromUrl($url)
 {
     if (empty($url)) {
         return null;
     }
     $url = BAPISync::cleanurl($url);
     if (!empty($this->seodata)) {
         foreach ($this->seodata as $seo) {
             $turl = BAPISync::cleanurl($seo["DetailURL"]);
             if ($turl == $url) {
                 return $seo;
             }
         }
     }
     return null;
 }