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); } }
public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); //echo $before_widget; $apikey = getbapiapikey(); if (!empty($apikey)) { $t = '{{#site.HasMultiSites}}<span class="siteselector widget">{{#site.Sites}} <a href="http://{{Url}}"><i class="flag flag-{{Language}}"><span style="display:none">{{RegionInfo.DisplayName}}</span></i></a>{{/site.Sites}}</span>{{/site.HasMultiSites}}'; $m = new Mustache_Engine(); $wrapper = getbapisolutiondata(); $string = $m->render($t, $wrapper); echo $string; } //echo $after_widget; }
function get_doc_template($docname, $setting) { global $bapi_all_options; $docmod = $bapi_all_options[$setting . '_lastmod']; //settings must be registered w/ this consistent format. $doctext = $bapi_all_options[$setting]; if (time() - 60 - $docmod > 0) { // FIXME: WHY NOT USING BAPI object? $getopts = array('http' => array('method' => "GET", 'header' => "User-Agent: InstaSites Agent\r\nReferer: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\r\n")); $stream = stream_context_create($getopts); $url = getbapiurl() . '/ws/?method=get&ids=0&entity=doctemplate&docname=' . urlencode($docname) . '&apikey=' . getbapiapikey(); $d = file_get_contents($url, FALSE, $stream); $darr = json_decode($d); $doctext = $darr->result[0]->DocText; /* Temporary Hack For Tag Substitution */ $siteurl = parse_url($bapi_all_options['bapi_site_cdn_domain'], PHP_URL_HOST); $solution = $bapi_all_options['blogname']; $doctext = str_replace("#Solution.Solution#", $solution, $doctext); $doctext = str_replace("#Site.PrimaryURL#", $siteurl, $doctext); /* End Temporary Hack */ update_option($setting, $doctext); update_option($setting . '_lastmod', time()); bapi_wp_site_options(); } return $bapi_all_options[$setting]; }