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 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)); }