本文整理汇总了PHP中okapi\Settings::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Settings::get方法的具体用法?PHP Settings::get怎么用?PHP Settings::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okapi\Settings
的用法示例。
在下文中一共展示了Settings::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: call
public static function call(OkapiRequest $request)
{
$issue_id = $request->get_parameter('issue_id');
if (!$issue_id) {
throw new ParamMissing('issue_id');
}
if (!preg_match("/^[0-9]+\$/", $issue_id) || strlen($issue_id) > 6) {
throw new InvalidParam('issue_id');
}
$cache_key = "apiref/issue#" . $issue_id;
$result = Cache::get($cache_key);
if ($result == null) {
# Download the number of comments from GitHub Issue Tracker.
try {
$extra_headers = array();
$extra_headers[] = "Accept: application/vnd.github.v3.html+json";
$extra_headers[] = "User-Agent: https://github.com/opencaching/okapi/";
if (Settings::get('GITHUB_ACCESS_TOKEN')) {
$extra_headers[] = "Authorization: token " . Settings::get('GITHUB_ACCESS_TOKEN');
}
$opts = array('http' => array('method' => "GET", 'timeout' => 2.0, 'header' => implode("\r\n", $extra_headers)));
$context = stream_context_create($opts);
$json = file_get_contents("https://api.github.com/repos/opencaching/okapi/issues/{$issue_id}", false, $context);
} catch (ErrorException $e) {
throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. " . "This is probably due to a temporary connection problem. Try again later or contact " . "us if this seems permanent.");
}
$doc = json_decode($json, true);
$result = array('id' => $issue_id + 0, 'last_updated' => $doc['updated_at'], 'title' => $doc['title'], 'url' => $doc['html_url'], 'comment_count' => $doc['comments']);
# On one hand, we want newly added comments to show up quickly.
# On the other, we don't want OKAPI to spam GitHub with queries.
# So it's difficult to choose the best timeout for this.
Cache::set($cache_key, $result, 3600);
}
return Okapi::formatted_response($request, $result);
}
示例2: call
static function call(OkapiRequest $request)
{
require_once 'log_images_common.inc.php';
list($image_uuid, $log_internal_id) = LogImagesCommon::validate_image_uuid($request);
$image_uuid_escaped = Db::escape_string($image_uuid);
Db::execute('start transaction');
$image_row = Db::select_row("\n select id, node, url, local\n from pictures\n where uuid = '" . $image_uuid_escaped . "'\n ");
Db::execute("\n delete from pictures where uuid = '" . $image_uuid_escaped . "'\n ");
# Remember that OCPL picture sequence numbers are always 1, and
# OCDE sequence numbers may have gaps. So we do not need to adjust
# any numbers after deleting from table 'pictures'.
if (Settings::get('OC_BRANCH') == 'oc.de') {
# OCDE does all the housekeeping by triggers
} else {
Db::execute("\n INSERT INTO removed_objects (\n localID, uuid, type, removed_date, node\n )\n VALUES (\n " . $image_row['id'] . "\n '" . $image_uuid_escaped . "',\n 6,\n NOW(),\n " . $image_row['node'] . "\n )\n ");
# This will also update cache_logs.okapi_syncbase, so that replication
# can output the updated log entry with one image less. For OCDE
# that's done by DB trigges.
Db::execute("\n update cache_logs\n set\n picturescount = greatest(0, picturescount - 1),\n last_modified = NOW()\n where id = '" . Db::escape_string($log_internal_id) . "'\n ");
}
Db::execute('commit');
if ($image_row['local']) {
$filename = basename($image_row['url']);
unlink(Settings::get('IMAGES_DIR') . '/' . $filename);
}
$result = array('success' => true);
return Okapi::formatted_response($request, $result);
}
示例3: call
public static function call()
{
$langpref = isset($_GET['langpref']) ? $_GET['langpref'] : Settings::get('SITELANG');
$langprefs = explode("|", $langpref);
# Determine which user is logged in to OC.
require_once $GLOBALS['rootpath'] . "okapi/lib/oc_session.php";
$OC_user_id = OCSession::get_user_id();
if ($OC_user_id == null) {
$after_login = "okapi/apps/" . ($langpref != Settings::get('SITELANG') ? "?langpref=" . $langpref : "");
$login_url = Settings::get('SITE_URL') . "login.php?target=" . urlencode($after_login);
return new OkapiRedirectResponse($login_url);
}
# Get the list of authorized apps.
$rs = Db::query("\n select c.`key`, c.name, c.url\n from\n okapi_consumers c,\n okapi_authorizations a\n where\n a.user_id = '" . mysql_real_escape_string($OC_user_id) . "'\n and c.`key` = a.consumer_key\n order by c.name\n ");
$vars = array();
$vars['okapi_base_url'] = Settings::get('SITE_URL') . "okapi/";
$vars['site_url'] = Settings::get('SITE_URL');
$vars['site_name'] = Okapi::get_normalized_site_name();
$vars['site_logo'] = Settings::get('SITE_LOGO');
$vars['apps'] = array();
while ($row = mysql_fetch_assoc($rs)) {
$vars['apps'][] = $row;
}
mysql_free_result($rs);
$response = new OkapiHttpResponse();
$response->content_type = "text/html; charset=utf-8";
ob_start();
Okapi::gettext_domain_init($langprefs);
include 'index.tpl.php';
$response->body = ob_get_clean();
Okapi::gettext_domain_restore();
return $response;
}
示例4: count
/**
* OCDE supports arbitrary ordering of log images. The pictures table
* contains sequence numbers, which are always > 0 and need not to be
* consecutive (may have gaps). There is a unique index which prevents
* inserting duplicate seq numbers for the same log.
*
* OCPL sequence numbers currently are always = 1.
*
* The purpose of this function is to bring the supplied 'position'
* parameter into bounds, and to calculate an appropriate sequence number
* from it.
*
* This function is always called when adding images. When editing images,
* it is called only for OCDE and if the position parameter was supplied.
*/
static function prepare_position($log_internal_id, $position, $end_offset)
{
if (Settings::get('OC_BRANCH') == 'oc.de' && $position !== null) {
# Prevent race conditions when creating sequence numbers if a
# user tries to upload multiple images simultaneously. With a
# few picture uploads per hour - most of them probably witout
# a 'position' parameter - the lock is neglectable.
Db::execute('lock tables pictures write');
}
$log_images_count = Db::select_value("\n select count(*)\n from pictures\n where object_type = 1 and object_id = '" . Db::escape_string($log_internal_id) . "'\n ");
if (Settings::get('OC_BRANCH') == 'oc.pl') {
# Ignore the position parameter, always insert at end.
# Remember that this function is NOT called when editing OCPL images.
$position = $log_images_count;
$seq = 1;
} else {
if ($position === null || $position >= $log_images_count) {
$position = $log_images_count - 1 + $end_offset;
$seq = Db::select_value("\n select max(seq)\n from pictures\n where object_type = 1 and object_id = '" . Db::escape_string($log_internal_id) . "'\n ") + $end_offset;
} else {
if ($position <= 0) {
$position = 0;
$seq = 1;
} else {
$seq = Db::select_value("\n select seq\n from pictures\n where object_type = 1 and object_id = '" . Db::escape_string($log_internal_id) . "'\n order by seq\n limit " . ($position + 0) . ", 1\n ");
}
}
}
# $position may have become a string, as returned by database queries.
return array($position + 0, $seq, $log_images_count);
}
示例5: get_installations
public static function get_installations()
{
$installations = OkapiServiceRunner::call("services/apisrv/installations", new OkapiInternalRequest(new OkapiInternalConsumer(), null, array()));
foreach ($installations as &$inst_ref) {
$inst_ref['selected'] = $inst_ref['site_url'] == Settings::get('SITE_URL');
}
return $installations;
}
示例6: call
public static function call(OkapiRequest $request)
{
$result = array();
$result['site_url'] = Settings::get('SITE_URL');
$result['okapi_base_url'] = $result['site_url'] . "okapi/";
$result['site_name'] = Okapi::get_normalized_site_name();
$result['okapi_revision'] = Okapi::$revision;
return Okapi::formatted_response($request, $result);
}
示例7: refresh_from_string
/**
* Refresh all attributes from the given XML. Usually, this file is
* downloaded from Google Code (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 = Settings::get('ORIGIN_URL');
$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 node, then it's NOT discontinued. */
$attr['is_discontinued'] = false;
if ((string) $ocnode['schema'] == $my_schema) {
/* It is used by THIS OC node. */
$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::$revision . self::cache_key_suffix();
Cache::set($cache_key, $cachedvalue, self::ttl());
self::$attr_dict = $cachedvalue['attr_dict'];
}
示例8: get_cache_key
/**
* Returns one of: array('cache_code', 'OPXXXX'), array('internal_id', '12345'),
* array('uuid', 'A408C3...') or null.
*/
private static function get_cache_key($url)
{
# Determine our own domain.
static $host = null;
static $length = null;
if ($host == null) {
$host = parse_url(Settings::get('SITE_URL'), PHP_URL_HOST);
if (strpos($host, "www.") === 0) {
$host = substr($host, 4);
}
$length = strlen($host);
}
# Parse the URL
$uri = parse_url($url);
if ($uri == false) {
return null;
}
if (!isset($uri['scheme']) || !in_array($uri['scheme'], array('http', 'https'))) {
return null;
}
if (!isset($uri['host']) || substr($uri['host'], -$length) != $host) {
return null;
}
if (!isset($uri['path'])) {
return null;
}
if (preg_match("#^/(O[A-Z][A-Z0-9]{4,5})\$#", $uri['path'], $matches)) {
# Some servers allow "http://oc.xx/<cache_code>" shortcut.
return array('cache_code', $matches[1]);
}
$parts = array();
if (isset($uri['query'])) {
$parts = array_merge($parts, explode('&', $uri['query']));
}
if (isset($uri['fragment'])) {
$parts = array_merge($parts, explode('&', $uri['fragment']));
}
foreach ($parts as $param) {
$item = explode('=', $param, 2);
if (count($item) != 2) {
continue;
}
$key = $item[0];
$value = $item[1];
if ($key == 'wp') {
return array('cache_code', $value);
}
if ($key == 'cacheid') {
return array('internal_id', $value);
}
if ($key == 'uuid') {
return array('uuid', $value);
}
}
return null;
}
示例9: call
public static function call($methodname)
{
require_once $GLOBALS['rootpath'] . 'okapi/service_runner.php';
if (!OkapiServiceRunner::exists($methodname)) {
throw new BadRequest("Method '{$methodname}' does not exist. " . "See OKAPI docs at " . Settings::get('SITE_URL') . "okapi/");
}
$options = OkapiServiceRunner::options($methodname);
$request = new OkapiHttpRequest($options);
return OkapiServiceRunner::call($methodname, $request);
}
示例10: call
public static function call(OkapiRequest $request)
{
$cachekey = "apisrv/stats";
$result = Cache::get($cachekey);
if (!$result) {
$result = array('cache_count' => 0 + Db::select_value("\n select count(*) from caches where status in (1,2,3)\n "), 'user_count' => 0 + Db::select_value("\n select count(*) from (\n select distinct user_id\n from cache_logs\n where\n type in (1,2,7)\n and " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "deleted = 0" : "true") . "\n UNION DISTINCT\n select distinct user_id\n from caches\n ) as t;\n "), 'apps_count' => 0 + Db::select_value("select count(*) from okapi_consumers;"), 'apps_active' => 0 + Db::select_value("\n select count(distinct s.consumer_key)\n from\n okapi_stats_hourly s,\n okapi_consumers c\n where\n s.consumer_key = c.`key`\n and s.period_start > date_add(now(), interval -30 day)\n "));
Cache::set($cachekey, $result, 86400);
# cache it for one day
}
return Okapi::formatted_response($request, $result);
}
示例11: call
public static function call(OkapiRequest $request)
{
$cache_code = $request->get_parameter('cache_code');
if (!$cache_code) {
throw new ParamMissing('cache_code');
}
if (strpos($cache_code, "|") !== false) {
throw new InvalidParam('cache_code');
}
$langpref = $request->get_parameter('langpref');
if (!$langpref) {
$langpref = "en";
}
$langpref .= "|" . Settings::get('SITELANG');
$fields = $request->get_parameter('fields');
if (!$fields) {
$fields = "code|name|location|type|status";
}
$log_fields = $request->get_parameter('log_fields');
if (!$log_fields) {
$log_fields = "uuid|date|user|type|comment";
}
$lpc = $request->get_parameter('lpc');
if (!$lpc) {
$lpc = 10;
}
$attribution_append = $request->get_parameter('attribution_append');
if (!$attribution_append) {
$attribution_append = 'full';
}
$params = array('cache_codes' => $cache_code, 'langpref' => $langpref, 'fields' => $fields, 'attribution_append' => $attribution_append, 'lpc' => $lpc, 'log_fields' => $log_fields);
$my_location = $request->get_parameter('my_location');
if ($my_location) {
$params['my_location'] = $my_location;
}
$user_uuid = $request->get_parameter('user_uuid');
if ($user_uuid) {
$params['user_uuid'] = $user_uuid;
}
# There's no need to validate the fields/lpc parameters as the 'geocaches'
# method does this (it will raise a proper exception on invalid values).
$results = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest($request->consumer, $request->token, $params));
$result = $results[$cache_code];
if ($result === null) {
# Two errors messages (for OCDE). Makeshift solution for issue #350.
$exists = Db::select_value("\n select 1\n from caches\n where wp_oc='" . Db::escape_string($cache_code) . "'\n ");
if ($exists) {
throw new InvalidParam('cache_code', "This cache is not accessible via OKAPI.");
} else {
throw new InvalidParam('cache_code', "This cache does not exist.");
}
}
return Okapi::formatted_response($request, $result);
}
示例12: call
public static function call()
{
require_once $GLOBALS['rootpath'] . 'okapi/service_runner.php';
require_once $GLOBALS['rootpath'] . 'okapi/views/menu.inc.php';
$vars = array('menu' => OkapiMenu::get_menu_html("examples.html"), 'okapi_base_url' => Settings::get('SITE_URL') . "okapi/", 'site_url' => Settings::get('SITE_URL'), 'installations' => OkapiMenu::get_installations(), 'okapi_rev' => Okapi::$version_number, 'site_name' => Okapi::get_normalized_site_name());
$response = new OkapiHttpResponse();
$response->content_type = "text/html; charset=utf-8";
ob_start();
include 'examples.tpl.php';
$response->body = ob_get_clean();
return $response;
}
示例13: call
public static function call(OkapiRequest $request)
{
$result = array();
$result['site_url'] = Settings::get('SITE_URL');
$result['okapi_base_url'] = $result['site_url'] . "okapi/";
$result['site_name'] = Okapi::get_normalized_site_name();
$result['okapi_version_number'] = Okapi::$version_number;
$result['okapi_revision'] = Okapi::$version_number;
/* Important for backward-compatibility! */
$result['okapi_git_revision'] = Okapi::$git_revision;
return Okapi::formatted_response($request, $result);
}
示例14: call
public static function call()
{
require_once 'menu.inc.php';
$vars = array('okapi_base_url' => Settings::get('SITE_URL') . "okapi/", 'menu' => OkapiMenu::get_menu_html(), 'installations' => OkapiMenu::get_installations(), 'okapi_rev' => Okapi::$revision);
$response = new OkapiHttpResponse();
$response->status = "404 Not Found";
$response->content_type = "text/html; charset=utf-8";
ob_start();
include 'http404.tpl.php';
$response->body = ob_get_clean();
return $response;
}
示例15: call
public static function call()
{
require_once $GLOBALS['rootpath'] . 'okapi/service_runner.php';
require_once $GLOBALS['rootpath'] . 'okapi/views/menu.inc.php';
$vars = array('menu' => OkapiMenu::get_menu_html("introduction.html"), 'okapi_base_url' => Settings::get('SITE_URL') . "okapi/", 'site_url' => Settings::get('SITE_URL'), 'method_index' => OkapiServiceRunner::call('services/apiref/method_index', new OkapiInternalRequest(new OkapiInternalConsumer(), null, array())), 'installations' => OkapiMenu::get_installations(), 'okapi_rev' => Okapi::$version_number);
$response = new OkapiHttpResponse();
$response->content_type = "text/html; charset=utf-8";
ob_start();
include 'introduction.tpl.php';
$response->body = ob_get_clean();
return $response;
}