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 // 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>';
/** * 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; }
function addpage($pagedef, $menu_id) { $ret = null; $parent = $pagedef['parent']; $parentid = 0; $test = get_page_by_path($parent); if (!empty($test)) { $parentid = $test->ID; } // try to find if this page already exists $pid = getPageID($parent, $pagedef['url'], $pagedef['title']); // create the post $post = array(); $post['ID'] = $pid; $post['menu_order'] = $pagedef['order']; $post['post_name'] = $pagedef['url']; if (empty($post['post_name'])) { $post['post_name'] = null; } $post['post_title'] = $pagedef['title']; $post['post_status'] = 'publish'; $post['post_parent'] = $parentid; $post['comment_status'] = 'closed'; // set the default content $content = $pagedef['content']; if ($content != '') { /* we check if the content is pointing to a local file */ if (strpos($content, '/') === 0) { $cpath = get_local(plugins_url($content, __FILE__)); $t = file_get_contents($cpath); $m = new Mustache_Engine(); /* we need to call this function so the $bapi_all_options gets populated */ bapi_wp_site_options(); $wrapper = getbapisolutiondata(); $string = $m->render($t, $wrapper); } else { /* if not is pointing to a json object */ $jsonContent = file_get_contents($content); if ($jsonContent != FALSE) { $jsonObjContent = json_decode($jsonContent); $string = $jsonObjContent->result[0]->DocText; } else { $string = ''; } } $string = str_replace("\t", '', $string); // remove tabs $string = str_replace("\n", '', $string); // remove new lines $string = str_replace("\r", '', $string); // remove carriage returns $post['post_content'] = $string; //utf8_encode($string); } else { $post['post_content'] = ''; } $post['post_type'] = 'page'; $action = "Added"; if ($pid == 0) { $pid = wp_insert_post($post, $error); } else { $action = "Edited"; wp_update_post($post); } add_post_meta($pid, 'bapi_page_id', $pagedef['intid'], true); update_post_meta($pid, "_wp_page_template", $pagedef['template']); $miid = 0; $addtomenu = $pagedef['addtomenu'] == 'true'; if ($addtomenu && !doesNavMenuExist($pid)) { $miid = addtonav($pid, $menu_id, $post, $parent, $ret); } if ($post['post_title'] == 'Home') { update_option('page_on_front', $pid); update_option('show_on_front', 'page'); } if ($post['post_title'] == 'Blog') { update_option('page_for_posts', $pid); } return array('action' => $action, 'post_title' => $post['post_title'], 'post_id' => $pid, 'miid' => $miid, 'menu_id' => $menu_id, 'add_to_nav' => $ret); }
function bapi_create_site() { if (!preg_match('/bapi-signup\\.php$/', $_SERVER['REQUEST_URI'])) { return; } if (extension_loaded('newrelic')) { newrelic_start_transaction('WP InstaSites'); newrelic_name_transaction('create-instasite'); } if (isset($_POST['blogid']) && $_POST['blogid'] != 0) { header('Content-Type: application/javascript'); $d = get_blog_details($_POST['blogid']); if ($d === false) { $new_site = array("status" => "error", "data" => array("errors" => array("blogid_invalid" => "Unable to locate blog with ID: " . $_POST['blogid']), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } switch_to_blog($_POST['blogid']); $blogid = get_current_blog_id(); if ($blogid != $_POST['blogid']) { $new_site = array("status" => "error", "data" => array("errors" => array("blogid_switch_fail" => "Unable to switch to BlogID: " . $_POST['blogid']), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } //Do Update Stuff Here $prefix = $_POST['siteprefix']; $sname = $_POST['sitename']; $tagline = ''; if (isset($_POST['tagline']) && !empty($_POST['tagline'])) { $tagline = $_POST['tagline']; } $apikey = ""; if (isset($_POST['apikey']) && !empty($_POST['apikey'])) { $apikey = $_POST['apikey']; } $username = $_POST['username']; $password = $_POST['password']; $domain = $_SERVER['SERVER_NAME']; $siteurl = $prefix . '.' . $domain; //How to check which domain is used for current service $liveurl = 'http://' . $siteurl; if (isset($_POST['domain']) && !empty($_POST['domain'])) { $liveurl = $_POST['domain']; //bapi_site_cdn_domain } $cf_url = str_replace('http://', '', $liveurl); $cf_origin = str_replace('http://', '', $siteurl); $cf = modify_cf_distro($cf_origin, $cf_url); if ($cf['CreatingDistrib'] === false) { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("cloudfront_distrib" => 'Error Creating CloudFront Distribution'), "message" => $cf['Message'], "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $liveurl = get_site_url(); if (isset($_POST['domain']) && !empty($_POST['domain'])) { $liveurl = $_POST['domain']; //bapi_site_cdn_domain } update_option('bapi_site_cdn_domain', $liveurl); update_option('bapi_cloudfrontid', $cf['Id']); $new_site = array("status" => "success", "data" => array("blog_id" => $_POST['blogid'], "blog_url" => get_site_url())); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $prefix = $_POST['siteprefix']; $sname = $_POST['sitename']; $tagline = ''; if (isset($_POST['tagline']) && !empty($_POST['tagline'])) { $tagline = $_POST['tagline']; } $apikey = ""; if (isset($_POST['apikey']) && !empty($_POST['apikey'])) { $apikey = $_POST['apikey']; } $username = $_POST['username']; $password = $_POST['password']; $domain = $_SERVER['SERVER_NAME']; $siteurl = $prefix . '.' . $domain; //How to check which domain is used for current service $liveurl = 'http://' . $siteurl; if (isset($_POST['domain']) && !empty($_POST['domain'])) { $liveurl = $_POST['domain']; //bapi_site_cdn_domain } $cf_url = str_replace('http://', '', $liveurl); $cf_origin = str_replace('http://', '', $siteurl); if ($apikey == "") { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("apikey_not_set" => "A valid API key is required."), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $cf = create_cf_distro($cf_origin, $cf_url); if ($cf['CreatingDistrib'] === false) { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("cloudfront_distrib" => 'Error Creating CloudFront Distribution'), "message" => $cf['Message'], "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } $meta = array('api_key' => $apikey, 'bapi_secureurl' => '', 'bapi_site_cdn_domain' => $liveurl, 'bapi_cloudfronturl' => $cf['DomainName'], 'bapi_cloudfrontid' => $cf['Id'], 'blogdescription' => $tagline, 'bapi_first_look' => 1, 'blog_public' => 1); //http://codex.wordpress.org/Option_Reference#Privacy if (defined('BAPI_BASEURL') && BAPI_BASEURL == 'connect.bookt.biz') { $meta['bapi_secureurl'] = $prefix . '.lodgingcloud.com'; $meta['bapi_baseurl'] = BAPI_BASEURL; } //$siteurl = $prefix.'.imbookingsecure.com'; $u = username_exists($username); if (empty($u)) { $u = wpmu_create_user($username, $password, $username); } //$u = wpmu_create_user($username,$password,$username); if (is_numeric($u)) { $s = wpmu_create_blog($siteurl, '/', $sname, $u, $meta); //$t = wpmu_create_blog('wpmutest.localhost','/','Test1',1); //use this one to force a 'blog_taken' failure. if (is_numeric($s)) { //success switch_to_blog($s); //echo get_site_url();exit(); if (defined('KIGO_SELF_HOSTED') && !KIGO_SELF_HOSTED) { switch_theme(WP_DEFAULT_THEME); } else { switch_theme('instatheme01'); } bapi_wp_site_options(); //Initialize menu and pages //$path = '/bapi.init?p=1'; //$url = get_site_url().$path; //$server_output = file_get_contents($url); //Provide response header('Content-Type: application/javascript'); $new_site = array("status" => "success", "data" => array("blog_id" => $s, "blog_url" => get_site_url())); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } } else { //fail //print_r($s->errors['blog_taken'][0]); exit(); //Not sure if this is the only error returned. Need a more generic message handler. header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => $s); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } } else { header('Content-Type: application/javascript'); $new_site = array("status" => "error", "data" => array("errors" => array("user_unknown" => "Sorry, the username specified is invalid."), "error_data" => "")); echo json_encode($new_site); if (extension_loaded('newrelic')) { newrelic_end_transaction(); } exit; } exit; }
function site_config_error() { global $bapi_all_options; bapi_wp_site_options(); $bapi_solutiondata = json_decode($bapi_all_options['bapi_solutiondata'], true); //values saved in our bapi options array our old values //print_r($bapi_solutiondata); exit(); $bapi_unique_prefx = $bapi_solutiondata['UniquePrefix']; //Unique prefix DOES NOT need to match to domain!!! $primaryUrl = 'http://' . $bapi_solutiondata['PrimaryURL']; $secureUrl = $bapi_solutiondata['SecureURL']; $plugUrl = plugins_url(); $setUpErr = array(); //update fields $bapi_cdn_domain = $bapi_all_options['bapi_site_cdn_domain']; $bapi_secure_url = $bapi_all_options['bapi_secureurl']; $contains = strpos($bapi_secure_url, "lodgingcloud.com"); $contains2 = strpos($bapi_secure_url, "imbookingsecure.com"); if ($bapi_unique_prefx != array_shift(explode(".", $_SERVER['HTTP_HOST']))) { //throw error - "" if (is_newapp_website()) { echo '<div id="mis-match-config" class="error"><p>Kigo site domain prefix (<em>"' . array_shift(explode(".", $_SERVER['HTTP_HOST'])) . '"</em>) is mis-matched with Kigo app (<em>"' . $bapi_unique_prefx . '"</em>). Please contact <a href="mailto:support@kigo.net?subject=Kigo site%20Error%20Report%20for%20' . $bapi_cdn_domain . '&body=Kigo%20site%20domain%20prefix%20%27' . array_shift(explode(".", $_SERVER['HTTP_HOST'])) . '%27%20is%20mis-matched%20with%20Kigo%20app%20%27' . $bapi_unique_prefx . '%27">support@kigo.net</a> and provide this error message for expedited assistance.</p></div>'; } else { echo '<div id="mis-match-config" class="error"><p>InstaSite domain prefix (<em>"' . array_shift(explode(".", $_SERVER['HTTP_HOST'])) . '"</em>) is mis-matched with InstaApp (<em>"' . $bapi_unique_prefx . '"</em>). Please contact <a href="mailto:support@instamanager.com?subject=InstaSite%20Error%20Report%20for%20' . $bapi_cdn_domain . '&body=InstaSite%20domain%20prefix%20%27' . array_shift(explode(".", $_SERVER['HTTP_HOST'])) . '%27%20is%20mis-matched%20with%20InstaApp%20%27' . $bapi_unique_prefx . '%27">support@instamanager.com</a> and provide this error message for expedited assistance.</p></div>'; } } if ($bapi_cdn_domain != $primaryUrl) { if (is_newapp_website()) { echo '<div id="mis-match-config" class="error"><p>Kigo site URL configuration does not match the Kigo app settings. Please <a href="' . menu_page_url('site_settings_initial', false) . '">CLICK HERE</a> to change your Site URL to <em>"' . $primaryUrl . '"</em> or contact <a href="mailto:support@kigo.net?subject=Kigo%20site%20Error%20Report%20for%20' . $bapi_cdn_domain . '&body=Kigo%20site%20URL%20configuration%20does%20not%20match%20the%20Kigo%20app%20settings.%20Change%20your%20Site%20URL%20to%20%27' . $primaryUrl . '%27%20or%20contact%20support%20to%20continue%20using%20%27' . $bapi_cdn_domain . '%27">support@kigo.net</a> to continue using <em>"' . $bapi_cdn_domain . '"</em>.</p></div>'; } else { echo '<div id="mis-match-config" class="error"><p>InstaSite URL configuration does not match the InstaApp settings. Please <a href="' . menu_page_url('site_settings_initial', false) . '">CLICK HERE</a> to change your Site URL to <em>"' . $primaryUrl . '"</em> or contact <a href="mailto:support@instamanager.com?subject=InstaSite%20Error%20Report%20for%20' . $bapi_cdn_domain . '&body=InstaSite%20URL%20configuration%20does%20not%20match%20the%20InstaApp%20settings.%20Change%20your%20Site%20URL%20to%20%27' . $primaryUrl . '%27%20or%20contact%20support%20to%20continue%20using%20%27' . $bapi_cdn_domain . '%27">support@instamanager.com</a> to continue using <em>"' . $bapi_cdn_domain . '"</em>.</p></div>'; } } if ($bapi_secure_url == $bapi_solutiondata['PrimaryURL']) { } elseif (empty($bapi_secure_url)) { } elseif ($contains) { } elseif ($contains2) { } else { if (is_newapp_website()) { echo '<div id="mis-match-config" class="error"><p>Kigo site plugin (<em>"' . $bapi_all_options['bapi_secureurl'] . '"</em>) configuration is mis-matched with Kigo app (<em>"' . $secureUrl . '"</em>). Please <a href="' . menu_page_url('site_settings_initial', false) . '">CLICK HERE</a> to correct the Secure Site URL. Secure Site URL must be set to <em>"' . $secureUrl . '"</em>, <em>"' . $bapi_solutiondata['PrimaryURL'] . '"</em> or left blank.</p></div>'; } else { echo '<div id="mis-match-config" class="error"><p>InstaSite plugin (<em>"' . $bapi_all_options['bapi_secureurl'] . '"</em>) configuration is mis-matched with InstaApp (<em>"' . $secureUrl . '"</em>). Please <a href="' . menu_page_url('site_settings_initial', false) . '">CLICK HERE</a> to correct the Secure Site URL. Secure Site URL must be set to <em>"' . $secureUrl . '"</em>, <em>"' . $bapi_solutiondata['PrimaryURL'] . '"</em> or left blank.</p></div>'; } } }
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]; }