本文整理汇总了PHP中okapi\Okapi::get_oc_schema_code方法的典型用法代码示例。如果您正苦于以下问题:PHP Okapi::get_oc_schema_code方法的具体用法?PHP Okapi::get_oc_schema_code怎么用?PHP Okapi::get_oc_schema_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okapi\Okapi
的用法示例。
在下文中一共展示了Okapi::get_oc_schema_code方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refresh_from_string
/**
* Refresh all attributes from the given XML. Usually, this file is
* downloaded from GitHub (using refresh_now).
*/
public static function refresh_from_string($xml)
{
/* The attribute-definitions.xml file defines relationships between
* attributes originating from various OC installations. Each
* installation uses internal IDs of its own. Which "attribute schema"
* is being used in THIS installation? */
$my_schema = Okapi::get_oc_schema_code();
$doc = simplexml_load_string($xml);
$cachedvalue = array('attr_dict' => array());
# Build cache attributes dictionary
$all_internal_ids = array();
foreach ($doc->attr as $attrnode) {
$attr = array('acode' => (string) $attrnode['acode'], 'gc_equivs' => array(), 'internal_id' => null, 'names' => array(), 'descriptions' => array(), 'is_discontinued' => true);
foreach ($attrnode->groundspeak as $gsnode) {
$attr['gc_equivs'][] = array('id' => (int) $gsnode['id'], 'inc' => in_array((string) $gsnode['inc'], array("true", "1")) ? 1 : 0, 'name' => (string) $gsnode['name']);
}
foreach ($attrnode->opencaching as $ocnode) {
/* If it is used by at least one OC site, then it's NOT discontinued. */
$attr['is_discontinued'] = false;
if ((string) $ocnode['schema'] == $my_schema) {
/* It is used by THIS OC site. */
$internal_id = (int) $ocnode['id'];
if (isset($all_internal_ids[$internal_id])) {
throw new Exception("The internal attribute " . $internal_id . " has multiple assigments to OKAPI attributes.");
}
$all_internal_ids[$internal_id] = true;
if (!is_null($attr['internal_id'])) {
throw new Exception("There are multiple internal IDs for the " . $attr['acode'] . " attribute.");
}
$attr['internal_id'] = $internal_id;
}
}
foreach ($attrnode->lang as $langnode) {
$lang = (string) $langnode['id'];
foreach ($langnode->name as $namenode) {
if (isset($attr['names'][$lang])) {
throw new Exception("Duplicate " . $lang . " name of attribute " . $attr['acode']);
}
$attr['names'][$lang] = (string) $namenode;
}
foreach ($langnode->desc as $descnode) {
if (isset($attr['descriptions'][$lang])) {
throw new Exception("Duplicate " . $lang . " description of attribute " . $attr['acode']);
}
$xml = $descnode->asxml();
/* contains "<desc>" and "</desc>" */
$innerxml = preg_replace("/(^[^>]+>)|(<[^<]+\$)/us", "", $xml);
$attr['descriptions'][$lang] = self::cleanup_string($innerxml);
}
}
$cachedvalue['attr_dict'][$attr['acode']] = $attr;
}
$cache_key = "attrhelper/dict#" . Okapi::$git_revision . self::cache_key_suffix();
Cache::set($cache_key, $cachedvalue, self::ttl());
self::$attr_dict = $cachedvalue['attr_dict'];
}
示例2: call
//.........这里部分代码省略.........
}
Db::free_result($rs);
} else {
# OCPL:
# - cache_location data is entered by the user.
# - The state is in adm3 field.
# get geocache countries and states
$rs = Db::query("\n select\n c.wp_oc as cache_code,\n cl.adm1 as country,\n cl.adm3 as state\n from\n caches c,\n cache_location cl\n where\n c.wp_oc in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $cache_codes)) . "')\n and c.cache_id = cl.cache_id\n ");
while ($row = Db::fetch_assoc($rs)) {
$countries[$row['cache_code']] = $row['country'];
$states[$row['cache_code']] = $row['state'];
}
Db::free_result($rs);
}
if (in_array('country', $fields)) {
foreach ($results as $cache_code => &$row_ref) {
$row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null;
}
}
if (in_array('state', $fields)) {
foreach ($results as $cache_code => &$row_ref) {
$row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null;
}
}
unset($countries);
unset($states);
}
# Attribution note
if (in_array('attribution_note', $fields)) {
/* Note, that the "owner" and "internal_id" fields are automatically included,
* whenever the attribution_note is included. */
foreach ($results as $cache_code => &$result_ref) {
$result_ref['attribution_note'] = self::get_cache_attribution_note($result_ref['internal_id'], $langpref[0], $langpref, $results[$cache_code]['owner'], 'full');
}
}
# Protection areas
if (in_array('protection_areas', $fields)) {
$cache_ids_escaped_and_imploded = "'" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($cacheid2wptcode))) . "'";
if (Settings::get('OC_BRANCH') == 'oc.de') {
$rs = Db::query("\n select\n c.wp_oc as cache_code,\n npa_types.name as type,\n npa_areas.name as name\n from\n caches c\n inner join cache_npa_areas on cache_npa_areas.cache_id=c.cache_id\n inner join npa_areas on cache_npa_areas.npa_id = npa_areas.id\n inner join npa_types on npa_areas.type_id = npa_types.id\n where\n c.cache_id in (" . $cache_ids_escaped_and_imploded . ")\n group by npa_areas.type_id, npa_areas.name\n order by npa_types.ordinal\n ");
} else {
if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) {
# Current OCPL table definitions use collation 'latin1' for parkipl
# and 'utf8' for np_areas. Union needs identical collations.
# To be sure, we convert both to utf8.
#
# TODO: use DB_CHARSET setting instead of literal 'utf8'
$rs = Db::query("\n select\n c.wp_oc as cache_code,\n '" . _('National Park / Landscape') . "' as type,\n CONVERT(parkipl.name USING utf8) as name\n from\n caches c\n inner join cache_npa_areas on cache_npa_areas.cache_id=c.cache_id\n inner join parkipl on cache_npa_areas.parki_id=parkipl.id\n where\n c.cache_id in (" . $cache_ids_escaped_and_imploded . ")\n and cache_npa_areas.parki_id != 0\n union\n select\n c.wp_oc as cache_code,\n 'Natura 2000' as type,\n CONVERT(npa_areas.sitename USING utf8) as name\n from\n caches c\n inner join cache_npa_areas on cache_npa_areas.cache_id=c.cache_id\n inner join npa_areas on cache_npa_areas.npa_id=npa_areas.id\n where\n c.cache_id in (" . $cache_ids_escaped_and_imploded . ")\n and cache_npa_areas.npa_id != 0\n ");
} else {
# OC.US and .UK do not have a 'parkipl' table.
# OC.US has a 'us_parks' table instead.
# Natura 2000 is Europe-only.
$rs = null;
}
}
foreach ($results as &$result_ref) {
$result_ref['protection_areas'] = array();
}
if ($rs) {
while ($row = Db::fetch_assoc($rs)) {
$results[$row['cache_code']]['protection_areas'][] = array('type' => $row['type'], 'name' => $row['name']);
}
Db::free_result($rs);
}
}
# Check which cache codes were not found and mark them with null.
foreach ($cache_codes as $cache_code) {
if (!isset($results[$cache_code])) {
$results[$cache_code] = null;
}
}
if (count($fields_to_remove_later) > 0) {
# Some of the fields in $results were added only temporarily
# (the Consumer did not ask for them). We will remove these fields now.
foreach ($results as &$result_ref) {
foreach ($fields_to_remove_later as $field) {
unset($result_ref[$field]);
}
}
}
# Order the results in the same order as the input codes were given.
# This might come in handy for languages which support ordered dictionaries
# (especially with conjunction with the search_and_retrieve method).
# See issue#97. PHP dictionaries (assoc arrays) are ordered structures,
# so we just have to rewrite it (sequentially).
$ordered_results = new ArrayObject();
foreach ($cache_codes as $cache_code) {
$ordered_results[$cache_code] = $results[$cache_code];
}
/* Handle OCPL's "access logs" feature. */
if (Settings::get('OC_BRANCH') == 'oc.pl' && Settings::get('OCPL_ENABLE_GEOCACHE_ACCESS_LOGS')) {
$cache_ids = array_keys($cacheid2wptcode);
/* Log this event only if some specific fields were accessed. */
if (in_array('location', $fields) && count(array_intersect(array('hint', 'hints', 'hint2', 'hints2', 'description', 'descriptions'), $fields)) > 0) {
require_once $GLOBALS['rootpath'] . 'okapi/lib/ocpl_access_logs.php';
\okapi\OCPLAccessLogs::log_geocache_access($request, $cache_ids);
}
}
return Okapi::formatted_response($request, $ordered_results);
}