/**
 * 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;
}
示例#2
0
function save_seo_meta($postid)
{
    $bapisync = new BAPISync();
    $bapisync->init();
    $perma = get_permalink();
    $permaPath = parse_url($perma);
    $relativePerma = get_relative($perma);
    $pageID = get_post_meta(get_the_ID(), 'bapi_page_id');
    if ($relativePerma == '/' && $pageID[0] != 'bapi_home') {
        return;
    }
    $seo = $bapisync->getSEOFromUrl($relativePerma);
    $meta_words = get_post_custom($post->ID, '', true);
    $myPageId = $seo['ID'];
    $myType = $seo['entity'];
    $myPkId = $seo['pkid'];
    if ($myType === null) {
        $myType = 0;
    }
    if ($myPageId === null) {
        $myPageId = 0;
    }
    if ($myPkId === null) {
        $myPkId = 0;
    }
    $apiKey = getbapiapikey();
    $bapi = getBAPIObj();
    if (!$bapi->isvalid()) {
        return;
    }
    $keywor = sanitize_text_field($_POST['bapi_meta_keywords']);
    $metle = sanitize_text_field($_POST['bapi_meta_title']);
    $meta_desc = sanitize_text_field($_POST['bapi_meta_description']);
    // save old value if keyword empty or null
    if ($metle === null || empty($metle)) {
        $metle = $meta_words['bapi_meta_title'][0];
    }
    if ($meta_desc === null || empty($meta_desc)) {
        $meta_desc = $meta_words['bapi_meta_description'][0];
    }
    if ($keywor === null || empty($keywor)) {
        $keywor = $meta_words['bapi_meta_keywords'][0];
    }
    //saves to wordpress database
    if (isset($_POST['bapi_meta_keywords'])) {
        if ($_POST['bapi_meta_keywords'] !== $meta_words['bapi_meta_keywords'][0]) {
        }
        update_post_meta($postid, 'bapi_meta_keywords', sanitize_text_field($_POST['bapi_meta_keywords']));
    }
    if (isset($_POST['bapi_meta_title']) && $_POST['bapi_meta_title'] !== $meta_words['bapi_meta_title'][0]) {
        update_post_meta($postid, 'bapi_meta_title', sanitize_text_field($_POST['bapi_meta_title']));
    }
    if (isset($_POST['bapi_meta_description']) && $_POST['bapi_meta_description'] !== $meta_words['bapi_meta_description'][0]) {
        update_post_meta($postid, 'bapi_meta_description', sanitize_text_field($_POST['bapi_meta_description']));
    }
    $metaArr = array('MetaKeywords' => $keywor, 'PageTitle' => $metle, 'MetaDescrip' => $meta_desc, 'ID' => $myPageId, 'pkid' => $myPkId, 'Keyword' => $relativePerma, 'entity' => $myType);
    $jsify = json_encode($metaArr);
    $jsonObj = 'data=' . (string) $jsify;
    // entety: tyoe and language  needs to be
    //print_r($jsonObj);exit();
    $bapi->save($jsonObj, $apiKey);
    update_option('bapi_keywords_lastmod', 0);
    bapi_sync_coredata();
}
<?php

// handle if this is a post
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    update_option('bapi_global_header', stripslashes($_POST['bapi_global_header']));
    update_option('bapi_google_conversion_key', stripslashes($_POST['bapi_google_conversion_key']));
    update_option('bapi_google_conversion_label', stripslashes($_POST['bapi_google_conversion_label']));
    update_option('bapi_google_webmaster_htmltag', sanitize_text_field(stripslashes($_POST['bapi_google_webmaster_htmltag'])));
    bapi_wp_site_options();
    BAPISync::updateLastSettingsUpdate();
    echo '<div id="message" class="updated"><p><strong>Settings saved.</strong></p></div>';
}
global $bapi_all_options;
?>
 
<link rel="stylesheet" type="text/css" href="<?php 
echo plugins_url('/css/jquery.ui/jquery-ui-1.10.2.min.css', __FILE__);
?>
" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript">
	jQuery(document).ready(function($){
		$('#bapi_google_webmaster_htmltag').click(function() { $("#bapi_google_webmaster_htmltag-large").dialog({ width: $(window).width()-60, height: $(window).height()-60 });});
	});
</script>
<div class="wrap">
<?php 
if (is_newapp_website()) {
    echo '<h1><img src="' . plugins_url('/img/logo_kigo.png', __FILE__) . '"/></h1>';
} else {
    echo '<h1><a href="http://www.bookt.com" target="_blank"><img src="' . plugins_url('/img/logo-im.png', __FILE__) . '" /></a></h1>';
 /**
  * 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);
 }
        $pos = strrpos($newSiteSettings, $search);
        if ($pos !== false) {
            $newSiteSettings = substr_replace($newSiteSettings, $replace, $pos, strlen($search));
        }
        update_option('bapi_sitesettings', $newSiteSettings);
        echo 'settings.propdetailratestable = "BAPI.config().hideratestable=false;";';
    }
    if (strpos($sitesettings, 'BAPI.config().amenity.enabled') == false) {
        echo 'settings.amenitysearch = "BAPI.config().amenity.enabled=false;";';
    }
    if (strpos($sitesettings, 'BAPI.config().sleeps.enabled') == false) {
        echo 'settings.sleepsearch = "BAPI.config().sleeps.enabled=false;";';
    }
} else {
    /* this is the data from the app, this is in the database, the bizrules */
    $bapiSolutionData = BAPISync::getSolutionData();
    $bapiSolutionDataConfig = $bapiSolutionData["ConfigObj"];
    $maxratesearch = $bapiSolutionDataConfig["rate"]["enabled"] ? 'true' : 'false';
    $amenitysearch = $bapiSolutionDataConfig["amenity"]["enabled"] ? 'true' : 'false';
    $devsearch = $bapiSolutionDataConfig["dev"]["enabled"] ? 'true' : 'false';
    $adultsearch = $bapiSolutionDataConfig["adults"]["enabled"] ? 'true' : 'false';
    $childsearch = $bapiSolutionDataConfig["children"]["enabled"] ? 'true' : 'false';
    $headlinesearch = $bapiSolutionDataConfig["headline"]["enabled"] ? 'true' : 'false';
    $propdetailavailcal = $bapiSolutionDataConfig["displayavailcalendar"] ? 'true' : 'false';
    $availcalendarmonths = $bapiSolutionDataConfig["availcalendarmonths"];
    $propdetailreviewtab = $bapiSolutionDataConfig["hasreviews"] ? 'true' : 'false';
    $propdetailrateavailtab = $bapiSolutionDataConfig["hideratesandavailabilitytab"] ? 'true' : 'false';
    $propdetailratestable = $bapiSolutionDataConfig["hideratestable"] ? 'true' : 'false';
    $poitypefilter = $bapiSolutionDataConfig["haspoitypefilter"] ? 'true' : 'false';
    $checkin = $bapiSolutionDataConfig["checkin"]["enabled"] ? 'true' : 'false';
    $checkout = $bapiSolutionDataConfig["checkout"]["enabled"] ? 'true' : 'false';
示例#6
0
 public static function getMustache($entity, $pkid)
 {
     $bapi = getBAPIObj();
     if (!$bapi->isvalid()) {
         return false;
     }
     $pkid = array(intval($pkid));
     // Set the options for get call
     switch ($entity) {
         case "property":
             $options = array("seo" => 1, "descrip" => 1, "avail" => 1, "rates" => 1, "reviews" => 1, "poi" => 1);
             break;
         case "poi":
             $options = array("nearbyprops" => 1, "seo" => 1);
             break;
         default:
             $options = null;
             break;
     }
     if (!is_array($c = $bapi->get($entity, $pkid, $options))) {
         if ($c === true) {
             return false;
         } else {
             wp_die('This page is temporarily unavailable. Please try again later.');
         }
     }
     // when rendering a template, get() must result in at least one element
     if (count($c['result']) < 1 || !is_array($c['result'][0]) || $entity === 'property' && isset($c['result'][0]['AvailableOnline']) && !$c['result'][0]['AvailableOnline']) {
         return false;
     }
     $c["config"] = BAPISync::getSolutionData();
     $c["config"] = $c["config"]["ConfigObj"];
     /* we get the sitesettings */
     global $bapi_all_options;
     $sitesettings = json_decode($bapi_all_options['bapi_sitesettings'], TRUE);
     if (!empty($sitesettings)) {
         /* we get the review value from the sitesettings*/
         $hasreviews = $sitesettings["propdetail-reviewtab"];
         if (!empty($hasreviews)) {
             /* we make an array using = and ; as delimiters */
             $hasreviews = split('[=;]', $hasreviews);
             /* we assign the value to var in the config array - reviews*/
             $hasreviews = $hasreviews[1];
             $c["config"]["hasreviews"] = $hasreviews === 'true';
         }
         /* the same as review but for the availability calendar */
         $displayavailcalendar = $sitesettings["propdetail-availcal"];
         if (!empty($displayavailcalendar)) {
             $displayavailcalendar = split('[=;]', $displayavailcalendar);
             $availcalendarmonths = (int) $displayavailcalendar[3];
             $displayavailcalendar = $displayavailcalendar[1];
             $c["config"]["displayavailcalendar"] = $displayavailcalendar === 'true';
             $c["config"]["availcalendarmonths"] = $availcalendarmonths;
         }
         /* the same as review but for the rates and availability tab */
         $hiderateavailtab = $sitesettings["propdetailrateavailtab"];
         if (!empty($hiderateavailtab)) {
             $hiderateavailtab = split('[=;]', $hiderateavailtab);
             /* we assign the value to var in the config array */
             $hiderateavailtab = $hiderateavailtab[1];
             $c["config"]["hideratesandavailabilitytab"] = $hiderateavailtab === 'true';
         }
         /* the same as review but for star reviews */
         $hidestarsreviews = $sitesettings["averagestarsreviews"];
         if (!empty($hidestarsreviews)) {
             $hidestarsreviews = split('[=;]', $hidestarsreviews);
             /* we assign the value to var in the config array */
             $hidestarsreviews = $hidestarsreviews[1];
             $c["config"]["hidestarsreviews"] = $hidestarsreviews === 'true';
         }
         /* the same as review but for the rates table */
         $hideratestable = $sitesettings["propdetailratestable"];
         if (!empty($hideratestable)) {
             $hideratestable = split('[=;]', $hideratestable);
             /* we assign the value to var in the config array */
             $hideratestable = $hideratestable[1];
             $c["config"]["hideratestable"] = $hideratestable === 'true';
         }
     }
     $c["textdata"] = kigo_I18n::get_translations(kigo_get_site_language());
     // Load bapisync
     global $bapisync;
     if (is_a($bapisync, 'BAPISync')) {
         $bapisync = new BAPISync();
         $bapisync->init();
     }
     $mustache_loader = new Kigo_Mustache_Loader_By_Name($bapisync->get_templates());
     $m = new Mustache_Engine(array('partials_loader' => $mustache_loader));
     return str_replace(array("\t", "\n", "\r"), '', $m->render($bapisync->getMustacheTemplateByEntity($entity, $mustache_loader), $c));
 }