当前位置: 首页>>代码示例>>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;未经允许,请勿转载。