當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Okapi::pick_best_language方法代碼示例

本文整理匯總了PHP中okapi\Okapi::pick_best_language方法的典型用法代碼示例。如果您正苦於以下問題:PHP Okapi::pick_best_language方法的具體用法?PHP Okapi::pick_best_language怎麽用?PHP Okapi::pick_best_language使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在okapi\Okapi的用法示例。


在下文中一共展示了Okapi::pick_best_language方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: call


//.........這裏部分代碼省略.........
     # Descriptions and hints.
     if (in_array('description', $fields) || in_array('descriptions', $fields) || in_array('short_description', $fields) || in_array('short_descriptions', $fields) || in_array('hint', $fields) || in_array('hints', $fields) || in_array('hint2', $fields) || in_array('hints2', $fields)) {
         # At first, we will fill all those fields, even if user requested just one
         # of them. We will chop off the unwanted ones at the end.
         foreach ($results as &$result_ref) {
             $result_ref['short_descriptions'] = new ArrayObject();
             $result_ref['descriptions'] = new ArrayObject();
             $result_ref['hints'] = new ArrayObject();
             $result_ref['hints2'] = new ArrayObject();
         }
         # Get cache descriptions and hints.
         $rs = Db::query("\n                select cache_id, language, `desc`, short_desc, hint\n                from cache_desc\n                where cache_id in ('" . implode("','", array_map('mysql_real_escape_string', array_keys($cacheid2wptcode))) . "')\n            ");
         while ($row = mysql_fetch_assoc($rs)) {
             $cache_code = $cacheid2wptcode[$row['cache_id']];
             // strtolower - ISO 639-1 codes are lowercase
             if ($row['desc']) {
                 /* Note, that the "owner" and "internal_id" fields are automatically included,
                  * whenever the cache description is included. */
                 $tmp = Okapi::fix_oc_html($row['desc']);
                 if ($attribution_append != 'none') {
                     $tmp .= "\n<p><em>" . self::get_cache_attribution_note($row['cache_id'], strtolower($row['language']), $langpref, $results[$cache_code]['owner'], $attribution_append) . "</em></p>";
                 }
                 $results[$cache_code]['descriptions'][strtolower($row['language'])] = $tmp;
             }
             if ($row['short_desc']) {
                 $results[$cache_code]['short_descriptions'][strtolower($row['language'])] = $row['short_desc'];
             }
             if ($row['hint']) {
                 $results[$cache_code]['hints'][strtolower($row['language'])] = $row['hint'];
                 $results[$cache_code]['hints2'][strtolower($row['language'])] = htmlspecialchars_decode(mb_ereg_replace("<br />", "", $row['hint']), ENT_COMPAT);
             }
         }
         foreach ($results as &$result_ref) {
             $result_ref['short_description'] = Okapi::pick_best_language($result_ref['short_descriptions'], $langpref);
             $result_ref['description'] = Okapi::pick_best_language($result_ref['descriptions'], $langpref);
             $result_ref['hint'] = Okapi::pick_best_language($result_ref['hints'], $langpref);
             $result_ref['hint2'] = Okapi::pick_best_language($result_ref['hints2'], $langpref);
         }
         # Remove unwanted fields.
         foreach (array('short_description', 'short_descriptions', 'description', 'descriptions', 'hint', 'hints', 'hint2', 'hints2') as $field) {
             if (!in_array($field, $fields)) {
                 foreach ($results as &$result_ref) {
                     unset($result_ref[$field]);
                 }
             }
         }
     }
     # Images.
     if (in_array('images', $fields) || in_array('preview_image', $fields)) {
         if (in_array('images', $fields)) {
             foreach ($results as &$result_ref) {
                 $result_ref['images'] = array();
             }
         }
         if (in_array('preview_image', $fields)) {
             foreach ($results as &$result_ref) {
                 $result_ref['preview_image'] = null;
             }
         }
         if (Db::field_exists('pictures', 'mappreview')) {
             $preview_field = "mappreview";
         } else {
             $preview_field = "0";
         }
         $sql = "\n                select object_id, uuid, url, title, spoiler, " . $preview_field . " as preview\n                from pictures\n                where\n                    object_id in ('" . implode("','", array_map('mysql_real_escape_string', array_keys($cacheid2wptcode))) . "')\n                    and display = 1\n                    and object_type = 2\n                    and unknown_format = 0\n            ";
         if (Settings::get('OC_BRANCH') == 'oc.pl') {
開發者ID:Slini11,項目名稱:okapi,代碼行數:67,代碼來源:geocaches.php

示例2: get_acode_to_name_mapping

 /**
  * Get the mapping: A-codes => attribute name. The language for the name
  * is selected based on the $langpref parameter. The result is cached!
  */
 public static function get_acode_to_name_mapping($langpref)
 {
     static $mapping = null;
     if ($mapping !== null) {
         return $mapping;
     }
     $cache_key = md5(serialize(array("attrhelper/acode2name", $langpref, Okapi::$revision, self::cache_key_suffix())));
     $mapping = Cache::get($cache_key);
     if (!$mapping) {
         self::init_from_cache();
         $mapping = array();
         foreach (self::$attr_dict as $acode => &$attr_ref) {
             $mapping[$acode] = Okapi::pick_best_language($attr_ref['names'], $langpref);
         }
         Cache::set($cache_key, $mapping, self::ttl());
     }
     return $mapping;
 }
開發者ID:4Vs,項目名稱:oc-server3,代碼行數:22,代碼來源:attr_helper.inc.php

示例3: call

 public static function call(OkapiRequest $request)
 {
     # Read the parameters.
     $acodes = $request->get_parameter('acodes');
     if (!$acodes) {
         throw new ParamMissing('acodes');
     }
     $acodes = explode("|", $acodes);
     $langpref = $request->get_parameter('langpref');
     if (!$langpref) {
         $langpref = "en";
     }
     $langpref = explode("|", $langpref);
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         $fields = "name";
     }
     $fields = explode("|", $fields);
     foreach ($fields as $field) {
         if (!in_array($field, self::$valid_field_names)) {
             throw new InvalidParam('fields', "'{$field}' is not a valid field code.");
         }
     }
     $forward_compatible = $request->get_parameter('forward_compatible');
     if (!$forward_compatible) {
         $forward_compatible = "true";
     }
     if (!in_array($forward_compatible, array("true", "false"))) {
         throw new InvalidParam('forward_compatible');
     }
     $forward_compatible = $forward_compatible == "true";
     # Load the attributes (all of them).
     require_once 'attr_helper.inc.php';
     $attrdict = AttrHelper::get_attrdict();
     # For each A-code, check if it exists, filter its fields and add it
     # to the results.
     $results = array();
     foreach ($acodes as $acode) {
         /* Please note, that the $attr variable from the $attrdict dictionary
          * below is NOT fully compatible with the interface of the "attribute"
          * method. Some of $attr's fields are private and should not be exposed,
          * other fields don't exist and have to be added dynamically! */
         if (isset($attrdict[$acode])) {
             $attr = $attrdict[$acode];
         } elseif ($forward_compatible) {
             $attr = AttrHelper::get_unknown_placeholder($acode);
         } else {
             $results[$acode] = null;
             continue;
         }
         # Fill langpref-specific fields.
         $attr['name'] = Okapi::pick_best_language($attr['names'], $langpref);
         $attr['description'] = Okapi::pick_best_language($attr['descriptions'], $langpref);
         # Fill some other fields (not kept in the cached attrdict).
         $attr['is_locally_used'] = $attr['internal_id'] !== null;
         $attr['is_deprecated'] = $attr['is_discontinued'];
         // deprecated and undocumetned field, see issue 70
         # Add to results.
         $results[$acode] = $attr;
     }
     # If the user wanted local_icon_urls, fetch them now. (We cannot cache them
     # in the $attrdict because currently we have no way of knowing then they
     # change.)
     if (in_array('local_icon_url', $fields)) {
         $tmp = Db::select_all("\n                select id, icon_large\n                from cache_attrib\n            ");
         $map = array();
         foreach ($tmp as &$row_ref) {
             $map[$row_ref['id']] =& $row_ref;
         }
         $prefix = Settings::get('SITE_URL');
         foreach ($results as &$attr_ref) {
             $internal_id = $attr_ref['internal_id'];
             if (isset($map[$internal_id])) {
                 $row = $map[$internal_id];
                 $attr_ref['local_icon_url'] = $prefix . $row['icon_large'];
             } else {
                 $attr_ref['local_icon_url'] = null;
             }
         }
     }
     # Filter the fields.
     foreach ($results as &$attr_ref) {
         $clean_row = array();
         foreach ($fields as $field) {
             $clean_row[$field] = $attr_ref[$field];
         }
         $attr_ref = $clean_row;
     }
     return Okapi::formatted_response($request, $results);
 }
開發者ID:PaulinaKowalczuk,項目名稱:oc-server3,代碼行數:90,代碼來源:attributes.php


注:本文中的okapi\Okapi::pick_best_language方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。