function getTextDataArray() { return kigo_I18n::get_translations(kigo_get_site_language()); }
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)); }
/** * Return the site overwritten array of translations. * Use a "cache" ($array_i18n_overwritten) not to call get_option every time. * * @param $lang_code * * @return array|null */ private static function get_i18n_site_array($lang_code) { if (is_array(self::$array_i18n_overwritten)) { return self::$array_i18n_overwritten; } if (!is_string($json_i18n = get_option(self::SITE_I18N_OPTION, null)) || !is_array(self::$array_i18n_overwritten = json_decode($json_i18n, true)) || !is_array(self::$array_i18n_overwritten[$lang_code])) { if (!is_array($old_customized_translations = kigo_I18n::get_old_customized_translations($lang_code)) || !is_array($default_translations = self::get_default_translations($lang_code)) || !is_array(self::$array_i18n_overwritten[$lang_code] = array_diff_assoc($old_customized_translations, $default_translations)) || !self::update_i18n_customized_translation(self::$array_i18n_overwritten)) { // If something goes wrong in retrieving the old custom translations, let's consider there are none. // This is done not to trigger error when get entity textdata will be deprecated or on newly created sites. self::update_i18n_customized_translation(array($lang_code => array())); return array(); } return self::$array_i18n_overwritten[$lang_code]; } return self::$array_i18n_overwritten[$lang_code]; }
/** * Retrieve all the default and overwritten translations, and apply search and sort on it. * * @param $nb_items * * @return array|null */ private function _prepare_items(&$nb_items) { if (!is_string($lang_code = kigo_get_site_language()) || !is_array($translations = kigo_I18n::get_translations_for_edit($lang_code))) { Loggly_logs::log(array('msg' => 'Unable to retrieve translation for edit', 'lang_code' => $lang_code), array(kigo_I18n::LOGGLY_LOG_TAG_FATAL)); return null; } // Handle the input search if (isset($_GET['s']) && strlen($search = wp_unslash(trim($_GET['s'])))) { $translations = array_filter($translations, function ($item) use($search) { return false !== stripos($item['key'], $search) || false !== stripos($item['default_value'], $search) || false !== stripos($item['value'], $search); }); } $nb_items = count($translations); if (!isset($_REQUEST['orderby']) || !strlen($orderby = $_REQUEST['orderby']) || !in_array($orderby, array_keys(self::$sortable_colums))) { $orderby = 'key'; } if (!isset($_REQUEST['order']) || !strlen($order = $_REQUEST['order']) || !in_array($orderby, array('asc', 'desc'))) { $order = 'asc'; } uasort($translations, function ($item_a, $item_b) use($orderby, $order) { return ('desc' === $order ? -1 : 1) * strnatcasecmp($item_a[$orderby], $item_b[$orderby]); }); return array_slice($translations, ($this->get_pagenum() - 1) * Kigo_Translations_List_Table::TRANSLATIONS_PER_PAGE, Kigo_Translations_List_Table::TRANSLATIONS_PER_PAGE, true); }