Esempio n. 1
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();
}
 public function __construct($force_full_sync = false)
 {
     // Reload all option to correspond to the right site/blog
     bapi_wp_site_options();
     $this->_blog_id = get_current_blog_id();
     $this->_api_key = getbapiapikey();
     // Retrieve the correct bapi object
     // In this case all bapi calls (diff, get etc..) during cron execution are going to be called on this endpoint
     if (defined('BAPI_CRON_ENDPOINT') && is_string(BAPI_CRON_ENDPOINT) && strlen($cron_host = BAPI_CRON_ENDPOINT)) {
         //Check if "http(s)://" is included
         if (0 !== strpos($cron_host, 'http://') || 0 !== strpos($cron_host, 'https://')) {
             $cron_host = 'http://' . $cron_host;
         }
         $this->_bapi = new BAPI($this->_api_key, $cron_host);
     } else {
         $this->_bapi = getBAPIObj();
     }
     // Get the stored diff ids/methods for each entity and merge it with the default (allow to add entity in future)
     if ($force_full_sync || !is_array($entity_diff_meth_ids = json_decode(get_option(self::KIGO_CRON_DIFF_OPTION), true))) {
         $this->_entity_diff_meth_ids = $this->_default_entity_diff_meth_ids;
         // Special case: if cron has never been executed and full sync is asked we need to set first_cron_execution = 1 otherwise it wont actually sync
         if ($force_full_sync) {
             foreach ($this->_default_entity_diff_meth_ids as $entity => $info) {
                 $this->_entity_diff_meth_ids[$entity]['first_cron_execution'] = 1;
             }
         }
     } else {
         $this->_entity_diff_meth_ids = array_merge($this->_default_entity_diff_meth_ids, $entity_diff_meth_ids);
     }
 }
<?php

$bapi = getBAPIObj();
if (!$bapi->isvalid()) {
    echo '<script type="text/javascript">window.location.href="' . menu_page_url('site_settings_general', false) . '"</script>';
    exit;
}
global $bapi_all_options;
// handle if this is a post
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //bapi_wp_site_options();
    unset($_POST['submit']);
    //$postSitesettings = $_POST;
    //print_r($postSitesettings);
    /*foreach ($postSitesettings as $k => $v) {
    			echo "[$k] => $v<br/>";
    		}*/
    $sitesettings = json_encode($_POST);
    update_option('bapi_sitesettings', $sitesettings);
    BAPISync::updateLastSettingsUpdate();
    echo '<div id="message" class="updated"><p><strong>Settings saved.</strong></p></div>';
} else {
    $sitesettings = $bapi_all_options['bapi_sitesettings'];
}
/* we get BAPI */
loadscriptjquery();
getconfig();
?>


<div class="wrap sitesettings-wrapper" style="display: none;">
 /**
  * Retrieves the translations (ex textdata) saved in bapi for a specific bapi key and compare them to the default ones arriving from the plugin.
  * This will only allows customers not to lose their specific translations while moving to this new system.
  * 
  * @return array|null
  */
 private static function get_old_customized_translations($lang_code)
 {
     bapi_wp_site_options();
     $bapi = getBAPIObj();
     if (!$bapi->isvalid() || !is_array($ret = $bapi->gettextdata(true)) || !isset($ret['result']) || !is_array($old_textdata = $ret['result']) || !isset($ret['retparams']) || !is_array($ret['retparams']) || !isset($ret['retparams']['language']) || !is_string($old_lang_code = $ret['retparams']['language'])) {
         Loggly_logs::log(array('msg' => 'Unable to get BAPI textdata', 'blog_id' => get_current_blog_id()), array(self::LOGGLY_LOG_TAG_FATAL));
         return null;
     }
     if ($lang_code !== $old_lang_code) {
         return array();
     }
     return $old_textdata;
 }
Esempio n. 5
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));
 }