本文整理汇总了PHP中okapi\Db::query方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::query方法的具体用法?PHP Db::query怎么用?PHP Db::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类okapi\Db
的用法示例。
在下文中一共展示了Db::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: ParamMissing
function validate_image_uuid($request)
{
$image_uuid = $request->get_parameter('image_uuid');
if (!$image_uuid) {
throw new ParamMissing('image_uuid');
}
# When uploading images, OCPL stores the user_id of the uploader
# in the 'pictures' table. This is redundant to cache_logs.user_id,
# because only the log entry author may append images. We will stick
# to log_entries.user_id here, which is the original value and works
# for all OC branches, and ignore pictures.user_id.
$rs = Db::query("\n select\n cache_logs.id log_internal_id,\n cache_logs.user_id,\n pictures.node\n from cache_logs\n join pictures on pictures.object_id = cache_logs.id\n where pictures.object_type = 1 and pictures.uuid = '" . Db::escape_string($image_uuid) . "'\n ");
$row = Db::fetch_assoc($rs);
Db::free_result($rs);
if (!$row) {
throw new InvalidParam('image_uuid', "There is no log entry image with uuid '" . $image_uuid . "'.");
}
if ($row['node'] != Settings::get('OC_NODE_ID')) {
throw new Exception("This site's database contains the image '{$image_uuid}' which has been" . " imported from another OC node. OKAPI is not prepared for that.");
}
if ($row['user_id'] != $request->token->user_id) {
throw new InvalidParam('image_uuid', "The user of your access token is not the author of the associated log entry.");
}
return array($image_uuid, $row['log_internal_id']);
}
示例3: call
public static function call(OkapiRequest $request)
{
$usernames = $request->get_parameter('usernames');
if (!$usernames) {
throw new ParamMissing('usernames');
}
$usernames = explode("|", $usernames);
if (count($usernames) > 500) {
throw new InvalidParam('usernames', "Maximum allowed number of referenced users " . "is 500. You provided " . count($usernames) . " usernames.");
}
$fields = $request->get_parameter('fields');
if (!$fields) {
throw new ParamMissing('fields');
}
# There's no need to validate the fields parameter as the 'users'
# method does this (it will raise a proper exception on invalid values).
$rs = Db::query("\n select username, uuid\n from user\n where username collate " . Settings::get('DB_CHARSET') . "_general_ci in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $usernames)) . "')\n ");
$lower_username2useruuid = array();
while ($row = Db::fetch_assoc($rs)) {
$lower_username2useruuid[mb_strtolower($row['username'], 'utf-8')] = $row['uuid'];
}
Db::free_result($rs);
# Retrieve data for the found user_uuids.
if (count($lower_username2useruuid) > 0) {
$id_results = OkapiServiceRunner::call('services/users/users', new OkapiInternalRequest($request->consumer, $request->token, array('user_uuids' => implode("|", array_values($lower_username2useruuid)), 'fields' => $fields)));
} else {
$id_results = array();
}
# Map user_uuids back to usernames. Also check which usernames were not found
# and mark them with null.
$results = array();
foreach ($usernames as $username) {
if (!isset($lower_username2useruuid[mb_strtolower($username, 'utf-8')])) {
$results[$username] = null;
} else {
$results[$username] = $id_results[$lower_username2useruuid[mb_strtolower($username, 'utf-8')]];
}
}
return Okapi::formatted_response($request, $results);
}
示例4: query_fast
/**
* Return MySQL's result set iterator over all caches which are present
* in the given result set AND in the given tile.
*
* Each row is an array of the following format:
* list(cache_id, $pixel_x, $pixel_y, status, type, rating, flags, name_crc, [count]).
*
* Note that $pixels can also be negative or >=256 (up to a margin of 32px).
* Count is the number of other caches "eclipsed" by this geocache (such
* eclipsed geocaches are not included in the result).
*/
public static function query_fast($zoom, $x, $y, $set_id)
{
# First, we check if the cache-set for this tile was already computed
# (and if it was, was it empty).
$status = self::get_tile_status($zoom, $x, $y);
if ($status === null) {
# Note, that computing the tile does not involve taking any
# search parameters.
$status = self::compute_tile($zoom, $x, $y);
}
if ($status === 1) {
# This tile was already computed and it is empty.
return null;
}
# If we got here, then the tile is computed and not empty (status 2).
$tile_upper_x = $x << 8;
$tile_leftmost_y = $y << 8;
$zoom_escaped = "'" . Db::escape_string($zoom) . "'";
$tile_upper_x_escaped = "'" . Db::escape_string($tile_upper_x) . "'";
$tile_leftmost_y_escaped = "'" . Db::escape_string($tile_leftmost_y) . "'";
return Db::query("\n select\n otc.cache_id,\n cast(otc.z21x >> (21 - {$zoom_escaped}) as signed) - {$tile_upper_x_escaped} as px,\n cast(otc.z21y >> (21 - {$zoom_escaped}) as signed) - {$tile_leftmost_y_escaped} as py,\n otc.status, otc.type, otc.rating, otc.flags, otc.name_crc, count(*)\n from\n okapi_tile_caches otc,\n okapi_search_results osr\n where\n z = {$zoom_escaped}\n and x = '" . Db::escape_string($x) . "'\n and y = '" . Db::escape_string($y) . "'\n and otc.cache_id = osr.cache_id\n and osr.set_id = '" . Db::escape_string($set_id) . "'\n group by\n z21x >> (3 + (21 - {$zoom_escaped})),\n z21y >> (3 + (21 - {$zoom_escaped}))\n order by\n z21y >> (3 + (21 - {$zoom_escaped})),\n z21x >> (3 + (21 - {$zoom_escaped}))\n ");
}
示例5: call
public static function call(OkapiRequest $request)
{
$user_uuid = $request->get_parameter('user_uuid');
if (!$user_uuid) {
throw new ParamMissing('user_uuid');
}
$limit = $request->get_parameter('limit');
if (!$limit) {
$limit = "20";
}
if (!is_numeric($limit)) {
throw new InvalidParam('limit', "'{$limit}'");
}
$limit = intval($limit);
if ($limit < 1 || $limit > 1000) {
throw new InvalidParam('limit', "Has to be in range 1..1000.");
}
$offset = $request->get_parameter('offset');
if (!$offset) {
$offset = "0";
}
if (!is_numeric($offset)) {
throw new InvalidParam('offset', "'{$offset}'");
}
$offset = intval($offset);
if ($offset < 0) {
throw new InvalidParam('offset', "'{$offset}'");
}
# Check if user exists and retrieve user's ID (this will throw
# a proper exception on invalid UUID).
$user = OkapiServiceRunner::call('services/users/user', new OkapiInternalRequest($request->consumer, null, array('user_uuid' => $user_uuid, 'fields' => 'internal_id')));
# User exists. Retrieving logs.
$rs = Db::query("\n select cl.id, cl.uuid, cl.type, unix_timestamp(cl.date) as date, cl.text,\n c.wp_oc as cache_code\n from cache_logs cl, caches c\n where\n cl.user_id = '" . Db::escape_string($user['internal_id']) . "'\n and " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "cl.deleted = 0" : "true") . "\n and c.status in (1,2,3)\n and cl.cache_id = c.cache_id\n order by cl.date desc\n limit {$offset}, {$limit}\n ");
$results = array();
while ($row = Db::fetch_assoc($rs)) {
$results[] = array('uuid' => $row['uuid'], 'date' => date('c', $row['date']), 'cache_code' => $row['cache_code'], 'type' => Okapi::logtypeid2name($row['type']), 'comment' => $row['text']);
}
return Okapi::formatted_response($request, $results);
}
示例6: handle_geocache_replace
private static function handle_geocache_replace($c)
{
# Check if any relevant geocache attributes have changed.
# We will pick up "our" copy of the cache from zero-zoom level.
try {
$cache = OkapiServiceRunner::call("services/caches/geocache", new OkapiInternalRequest(new OkapiInternalConsumer(), null, array('cache_code' => $c['object_key']['code'], 'fields' => 'internal_id|code|name|location|type|status|rating|recommendations|founds|trackables_count')));
} catch (InvalidParam $e) {
# Unprobable, but possible. Ignore changelog entry.
return;
}
# Fetch our copy of the cache.
$ours = mysql_fetch_row(Db::query("\n select cache_id, z21x, z21y, status, type, rating, flags, name_crc\n from okapi_tile_caches\n where\n z=0\n and cache_id = '" . mysql_real_escape_string($cache['internal_id']) . "'\n "));
# Caches near the poles caused our computations to break here. We will
# ignore such caches!
list($lat, $lon) = explode("|", $cache['location']);
if (floatval($lat) >= 89.98999999999999 || floatval($lat) <= -89.98999999999999) {
if ($ours) {
self::remove_geocache_from_cached_tiles($ours[0]);
}
return;
}
# Compute the new row for okapi_tile_caches. Compare with the old one.
$theirs = TileTree::generate_short_row($cache);
if (!$ours) {
# Aaah, a new geocache! How nice... ;)
self::add_geocache_to_cached_tiles($theirs);
} elseif ($ours[1] != $theirs[1] || $ours[2] != $theirs[2]) {
# Location changed.
self::remove_geocache_from_cached_tiles($ours[0]);
self::add_geocache_to_cached_tiles($theirs);
} elseif ($ours != $theirs) {
self::update_geocache_attributes_in_cached_tiles($theirs);
} else {
# No need to update anything. This is very common (i.e. when the
# cache was simply found, not actually changed). Replicate module generates
# many updates which do not influence our cache.
}
}
示例7: call
public static function call(OkapiRequest $request)
{
$internal_ids = $request->get_parameter('internal_ids');
if (!$internal_ids) {
throw new ParamMissing('internal_ids');
}
$internal_ids = explode("|", $internal_ids);
if (count($internal_ids) > 500) {
throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users " . "is 500. You provided " . count($internal_ids) . " references.");
}
$fields = $request->get_parameter('fields');
if (!$fields) {
throw new ParamMissing('fields');
}
# There's no need to validate the fields parameter as the 'users'
# method does this (it will raise a proper exception on invalid values).
$rs = Db::query("\n select user_id, uuid\n from user\n where user_id in ('" . implode("','", array_map('mysql_real_escape_string', $internal_ids)) . "')\n ");
$internalid2useruuid = array();
while ($row = mysql_fetch_assoc($rs)) {
$internalid2useruuid[$row['user_id']] = $row['uuid'];
}
mysql_free_result($rs);
# Retrieve data on given user_uuids.
$id_results = OkapiServiceRunner::call('services/users/users', new OkapiInternalRequest($request->consumer, $request->token, array('user_uuids' => implode("|", array_values($internalid2useruuid)), 'fields' => $fields)));
# Map user_uuids to internal_ids. Also check which internal_ids were not found
# and mark them with null.
$results = array();
foreach ($internal_ids as $internal_id) {
if (!isset($internalid2useruuid[$internal_id])) {
$results[$internal_id] = null;
} else {
$results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]];
}
}
return Okapi::formatted_response($request, $results);
}
示例8: call
public static function call(OkapiRequest $request)
{
$checkpointA_started = microtime(true);
# Make sure the request is internal.
if (in_array($request->consumer->key, array('internal', 'facade'))) {
/* Okay, these two consumers can always access it. */
} elseif ($request->consumer->hasFlag(OkapiConsumer::FLAG_MAPTILE_ACCESS)) {
/* If the Consumer is aware that it is not backward-compatible, then
* he may be granted permission to access it. */
} else {
throw new BadRequest("Your Consumer Key has not been allowed to access this method.");
}
# zoom, x, y - required tile-specific parameters.
$zoom = self::require_uint($request, 'z');
if ($zoom > 21) {
throw new InvalidParam('z', "Maximum value for this parameter is 21.");
}
$x = self::require_uint($request, 'x');
$y = self::require_uint($request, 'y');
if ($x >= 1 << $zoom) {
throw new InvalidParam('x', "Should be in 0.." . ((1 << $zoom) - 1) . ".");
}
if ($y >= 1 << $zoom) {
throw new InvalidParam('y', "Should be in 0.." . ((1 << $zoom) - 1) . ".");
}
# Now, we will create a search set (or use one previously created).
# Instead of creating a new OkapiInternalRequest object, we will pass
# the current request directly. We can do that, because we inherit all
# of the "save" method's parameters.
$search_set = OkapiServiceRunner::call('services/caches/search/save', new OkapiInternalRequest($request->consumer, $request->token, $request->get_all_parameters_including_unknown()));
$set_id = $search_set['set_id'];
# Get caches which are present in the result set AND within the tile
# (+ those around the borders).
$rs = TileTree::query_fast($zoom, $x, $y, $set_id);
$rows = array();
if ($rs !== null) {
while ($row = Db::fetch_row($rs)) {
$rows[] = $row;
}
unset($row);
}
OkapiServiceRunner::save_stats_extra("caches/map/tile/checkpointA", null, microtime(true) - $checkpointA_started);
$checkpointB_started = microtime(true);
# Add dynamic, user-related flags.
if (count($rows) > 0) {
# Load user-related cache ids.
$cache_key = "tileuser/" . $request->token->user_id;
$user = self::$USE_OTHER_CACHE ? Cache::get($cache_key) : null;
if ($user === null) {
$user = array();
# Ignored caches.
$rs = Db::query("\n select cache_id\n from cache_ignore\n where user_id = '" . Db::escape_string($request->token->user_id) . "'\n ");
$user['ignored'] = array();
while (list($cache_id) = Db::fetch_row($rs)) {
$user['ignored'][$cache_id] = true;
}
# Found caches.
$rs = Db::query("\n select distinct cache_id\n from cache_logs\n where\n user_id = '" . Db::escape_string($request->token->user_id) . "'\n and type = 1\n and " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "deleted = 0" : "true") . "\n ");
$user['found'] = array();
while (list($cache_id) = Db::fetch_row($rs)) {
$user['found'][$cache_id] = true;
}
# Own caches.
$rs = Db::query("\n select distinct cache_id\n from caches\n where user_id = '" . Db::escape_string($request->token->user_id) . "'\n ");
$user['own'] = array();
while (list($cache_id) = Db::fetch_row($rs)) {
$user['own'][$cache_id] = true;
}
Cache::set($cache_key, $user, 30);
}
# Add extra flags to geocaches.
foreach ($rows as &$row_ref) {
# Add the "found" flag (to indicate that this cache needs
# to be drawn as found) and the "own" flag (to indicate that
# the current user is the owner).
if (isset($user['found'][$row_ref[0]])) {
$row_ref[6] |= TileTree::$FLAG_FOUND;
}
# $row[6] is "flags"
if (isset($user['own'][$row_ref[0]])) {
$row_ref[6] |= TileTree::$FLAG_OWN;
}
# $row[6] is "flags"
}
}
# Compute the image hash/fingerprint. This will be used both for ETags
# and internal cache ($cache_key).
$tile = new TileRenderer($zoom, $rows);
$image_fingerprint = $tile->get_unique_hash();
# Start creating response.
$response = new OkapiHttpResponse();
$response->content_type = $tile->get_content_type();
$response->cache_control = "Cache-Control: private, max-age=600";
$response->etag = 'W/"' . $image_fingerprint . '"';
$response->allow_gzip = false;
// images are usually compressed, prevent compression at Apache level
# Check if the request didn't include the same ETag.
OkapiServiceRunner::save_stats_extra("caches/map/tile/checkpointB", null, microtime(true) - $checkpointB_started);
$checkpointC_started = microtime(true);
if (self::$USE_ETAGS_CACHE && $request->etag == $response->etag) {
//.........这里部分代码省略.........
示例9: execute
public function execute()
{
Db::query("optimize table okapi_tile_caches");
Db::query("optimize table okapi_tile_status");
}
示例10: call
public static function call()
{
# Flush the stats, so the page is fresh upon every request.
require_once $GLOBALS['rootpath'] . "okapi/cronjobs.php";
CronJobController::force_run("StatsWriterCronJob");
# When services/caches/map/tile method is called, it writes some extra
# stats in the okapi_stats_hourly table. This page retrieves and
# formats these stats in a readable manner (for debugging).
$response = new OkapiHttpResponse();
$response->content_type = "text/plain; charset=utf-8";
ob_start();
$start = isset($_GET['start']) ? $_GET['start'] : date("Y-m-d 00:00:00", time() - 7 * 86400);
$end = isset($_GET['end']) ? $_GET['end'] : date("Y-m-d 23:59:59");
print "From: {$start}\n";
print " To: {$end}\n\n";
$rs = Db::query("\n select\n service_name,\n sum(total_calls),\n sum(total_runtime)\n from okapi_stats_hourly\n where\n period_start >= '" . mysql_real_escape_string($start) . "'\n and period_start < '" . mysql_real_escape_string($end) . "'\n and service_name like '%caches/map/tile%'\n group by service_name\n ");
$total_calls = 0;
$total_runtime = 0.0;
$calls = array('A' => 0, 'B' => 0, 'C' => 0, 'D' => 0);
$runtime = array('A' => 0.0, 'B' => 0.0, 'C' => 0.0, 'D' => 0.0);
while (list($name, $c, $r) = mysql_fetch_array($rs)) {
if ($name == 'services/caches/map/tile') {
$total_calls = $c;
$total_runtime = $r;
} elseif (strpos($name, 'extra/caches/map/tile/checkpoint') === 0) {
$calls[$name[32]] = $c;
$runtime[$name[32]] = $r;
}
}
if ($total_calls != $calls['A']) {
print "Partial results. Only " . $calls['A'] . " out of {$total_calls} are covered.\n";
print "All other will count as \"unaccounted for\".\n\n";
$total_calls = $calls['A'];
}
$calls_left = $total_calls;
$runtime_left = $total_runtime;
$perc = function ($a, $b) {
return $b > 0 ? sprintf("%.1f", 100 * $a / $b) . "%" : "(?)";
};
$avg = function ($a, $b) {
return $b > 0 ? sprintf("%.4f", $a / $b) . "s" : "(?)";
};
$get_stats = function () use(&$calls_left, &$runtime_left, &$total_calls, &$total_runtime, &$perc) {
return str_pad($perc($calls_left, $total_calls), 6, " ", STR_PAD_LEFT) . str_pad($perc($runtime_left, $total_runtime), 7, " ", STR_PAD_LEFT);
};
print "%CALLS %TIME Description\n";
print "====== ====== ======================================================================\n";
print $get_stats() . " {$total_calls} responses served. Total runtime: " . sprintf("%.2f", $total_runtime) . "s\n";
print "\n";
print " All of these requests needed a TileTree build/lookup. The average runtime of\n";
print " these lookups was " . $avg($runtime['A'], $total_calls) . ". " . $perc($runtime['A'], $total_runtime) . " of total runtime was spent here.\n";
print "\n";
$runtime_left -= $runtime['A'];
print $get_stats() . " All calls passed here after ~" . $avg($runtime['A'], $total_calls) . "\n";
print "\n";
print " Lookup result was then processed and \"image description\" was created. It was\n";
print " passed on to the TileRenderer to compute the ETag hash string. The average runtime\n";
print " of this part was " . $avg($runtime['B'], $total_calls) . ". " . $perc($runtime['B'], $total_runtime) . " of total runtime was spent here.\n";
print "\n";
$runtime_left -= $runtime['B'];
print $get_stats() . " All calls passed here after ~" . $avg($runtime['A'] + $runtime['B'], $total_calls) . "\n";
$etag_hits = $calls['B'] - $calls['C'];
print "\n";
print " {$etag_hits} of the requests matched the ETag and were served an HTTP 304 response.\n";
print "\n";
$calls_left = $calls['C'];
print $get_stats() . " {$calls_left} calls passed here after ~" . $avg($runtime['A'] + $runtime['B'], $total_calls) . "\n";
$imagecache_hits = $calls['C'] - $calls['D'];
print "\n";
print " {$imagecache_hits} of these calls hit the server image cache.\n";
print " " . $perc($runtime['C'], $total_runtime) . " of total runtime was spent to find these.\n";
print "\n";
$calls_left = $calls['D'];
$runtime_left -= $runtime['C'];
print $get_stats() . " {$calls_left} calls passed here after ~" . $avg($runtime['A'] + $runtime['B'] + $runtime['C'], $total_calls) . "\n";
print "\n";
print " These calls required the tile to be rendered. On average, it took\n";
print " " . $avg($runtime['D'], $calls['D']) . " to *render* a tile.\n";
print " " . $perc($runtime['D'], $total_runtime) . " of total runtime was spent here.\n";
print "\n";
$runtime_left -= $runtime['D'];
print $perc($runtime_left, $total_runtime) . " of runtime was unaccounted for (other processing).\n";
print "Average response time was " . $avg($total_runtime, $total_calls) . ".\n\n";
print "Current okapi_cache score distribution:\n";
$rs = Db::query("\n select floor(log2(score)), count(*), sum(length(value))\n from okapi_cache\n where score is not null\n group by floor(log2(score))\n ");
while (list($log2, $count, $size) = mysql_fetch_array($rs)) {
print $count . " elements ({$size} bytes) with score between " . pow(2, $log2) . " and " . pow(2, $log2 + 1) . ".\n";
}
$response->body = ob_get_clean();
return $response;
}
示例11: update_notes
private static function update_notes($cache_id, $user_id, $new_notes)
{
if (Settings::get('OC_BRANCH') == 'oc.de') {
/* See:
*
* - https://github.com/OpencachingDeutschland/oc-server3/tree/master/htdocs/libse/CacheNote
* - http://www.opencaching.de/okapi/devel/dbstruct
*/
$rs = Db::query("\n select max(id) as id\n from coordinates\n where\n type = 2 -- personal note\n and cache_id = '" . Db::escape_string($cache_id) . "'\n and user_id = '" . Db::escape_string($user_id) . "'\n ");
$id = null;
if ($row = Db::fetch_assoc($rs)) {
$id = $row['id'];
}
if ($id == null) {
Db::query("\n insert into coordinates (\n type, latitude, longitude, cache_id, user_id,\n description\n ) values (\n 2, 0, 0,\n '" . Db::escape_string($cache_id) . "',\n '" . Db::escape_string($user_id) . "',\n '" . Db::escape_string($new_notes) . "'\n )\n ");
} else {
Db::query("\n update coordinates\n set description = '" . Db::escape_string($new_notes) . "'\n where\n id = '" . Db::escape_string($id) . "'\n and type = 2\n ");
}
} else {
$rs = Db::query("\n select max(note_id) as id\n from cache_notes\n where\n cache_id = '" . Db::escape_string($cache_id) . "'\n and user_id = '" . Db::escape_string($user_id) . "'\n ");
$id = null;
if ($row = Db::fetch_assoc($rs)) {
$id = $row['id'];
}
if ($id == null) {
Db::query("\n insert into cache_notes (\n cache_id, user_id, date, desc_html, `desc`\n ) values (\n '" . Db::escape_string($cache_id) . "',\n '" . Db::escape_string($user_id) . "',\n NOW(), 0,\n '" . Db::escape_string($new_notes) . "'\n )\n ");
} else {
Db::query("\n update cache_notes\n set\n `desc` = '" . Db::escape_string($new_notes) . "',\n desc_html = 0,\n date = NOW()\n where note_id = '" . Db::escape_string($id) . "'\n ");
}
}
}
示例12: call
public static function call(OkapiRequest $request)
{
$user_uuids = $request->get_parameter('user_uuids');
if (!$user_uuids) {
throw new ParamMissing('user_uuids');
}
$user_uuids = explode("|", $user_uuids);
if (count($user_uuids) > 500) {
throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users " . "is 500. You provided " . count($user_uuids) . " user IDs.");
}
$fields = $request->get_parameter('fields');
if (!$fields) {
throw new ParamMissing('fields');
}
$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.");
}
}
$rs = Db::query("\n select user_id, uuid, username, admin, latitude, longitude, date_created\n from user\n where uuid in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $user_uuids)) . "')\n ");
$results = array();
$id2uuid = array();
$uuid2id = array();
while ($row = Db::fetch_assoc($rs)) {
$id2uuid[$row['user_id']] = $row['uuid'];
$uuid2id[$row['uuid']] = $row['user_id'];
$entry = array();
foreach ($fields as $field) {
switch ($field) {
case 'uuid':
$entry['uuid'] = $row['uuid'];
break;
case 'username':
$entry['username'] = $row['username'];
break;
case 'profile_url':
$entry['profile_url'] = Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id'];
break;
case 'is_admin':
if (!$request->token) {
$entry['is_admin'] = null;
} elseif ($request->token->user_id != $row['user_id']) {
$entry['is_admin'] = null;
} else {
$entry['is_admin'] = $row['admin'] ? true : false;
}
break;
case 'internal_id':
$entry['internal_id'] = $row['user_id'];
break;
case 'date_registered':
$entry['date_registered'] = date("Y-m-d", strtotime($row['date_created']));
case 'caches_found':
/* handled separately */
break;
case 'caches_notfound':
/* handled separately */
break;
case 'caches_hidden':
/* handled separately */
break;
case 'rcmds_given':
/* handled separately */
break;
case 'home_location':
if (!$request->token) {
$entry['home_location'] = null;
} elseif ($request->token->user_id != $row['user_id']) {
$entry['home_location'] = null;
} elseif (!$row['latitude'] && !$row['longitude']) {
# OCPL sets NULL/NULL for unknown location, OCDE sets 0/0.
# It is safe to return null also for OCPL 0/0, as this value
# does not make sense.
$entry['home_location'] = null;
} else {
$entry['home_location'] = round($row['latitude'], 6) . "|" . round($row['longitude'], 6);
}
break;
default:
throw new Exception("Missing field case: " . $field);
}
}
$results[$row['uuid']] = $entry;
}
Db::free_result($rs);
# caches_found, caches_notfound, caches_hidden
if (in_array('caches_found', $fields) || in_array('caches_notfound', $fields) || in_array('caches_hidden', $fields) || in_array('rcmds_given', $fields)) {
# We will load all these stats together. Then we may remove these which
# the user doesn't need.
$extras = array();
if (Settings::get('OC_BRANCH') == 'oc.pl') {
# OCPL stores user stats in 'user' table.
$rs = Db::query("\n select user_id, founds_count, notfounds_count, hidden_count\n from user\n where user_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($id2uuid))) . "')\n ");
} else {
# OCDE stores user stats in 'stat_user' table.
$rs = Db::query("\n select\n u.user_id,\n ifnull(su.found, 0) as founds_count,\n ifnull(su.notfound, 0) as notfounds_count,\n ifnull(su.hidden, 0) as hidden_count\n from\n user u\n left join stat_user su\n on su.user_id = u.user_id\n where u.user_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($id2uuid))) . "')\n ");
}
while ($row = Db::fetch_assoc($rs)) {
$extras[$row['user_id']] = array();
//.........这里部分代码省略.........
示例13: call
public static function call(OkapiRequest $request)
{
# Retrieve the list of URLs to check.
$tmp = $request->get_parameter('urls');
if (!$tmp) {
throw new ParamMissing('urls');
}
$urls = explode('|', $tmp);
$as_dict = $request->get_parameter('as_dict');
if (!$as_dict) {
$as_dict = 'false';
}
if (!in_array($as_dict, array('true', 'false'))) {
throw new InvalidParam('as_dict');
}
$as_dict = $as_dict == 'true';
# Generate the lists of keys.
$results = array();
$urls_with = array('cache_code' => array(), 'internal_id' => array(), 'uuid' => array());
foreach ($urls as &$url_ref) {
$key = self::get_cache_key($url_ref);
if ($key != null) {
$urls_with[$key[0]][$url_ref] = $key[1];
} else {
$results[$url_ref] = null;
}
}
# Include 'cache_code' references.
foreach ($urls_with['cache_code'] as $url => $cache_code) {
$results[$url] = $cache_code;
}
# Include 'internal_id' references.
$internal_ids = array_values($urls_with['internal_id']);
if (count($internal_ids) > 0) {
$rs = Db::query("\n select cache_id, wp_oc\n from caches\n where\n cache_id in ('" . implode("','", array_map('mysql_real_escape_string', $internal_ids)) . "')\n and status in (1,2,3)\n ");
$dict = array();
while ($row = mysql_fetch_assoc($rs)) {
$dict[$row['cache_id']] = $row['wp_oc'];
}
foreach ($urls_with['internal_id'] as $url => $internal_id) {
if (isset($dict[$internal_id])) {
$results[$url] = $dict[$internal_id];
} else {
$results[$url] = null;
}
}
}
# Include 'uuid' references.
$uuids = array_values($urls_with['uuid']);
if (count($uuids) > 0) {
$rs = Db::query("\n select uuid, wp_oc\n from caches\n where\n uuid in ('" . implode("','", array_map('mysql_real_escape_string', $uuids)) . "')\n and status in (1,2,3)\n ");
$dict = array();
while ($row = mysql_fetch_assoc($rs)) {
$dict[$row['uuid']] = $row['wp_oc'];
}
foreach ($urls_with['uuid'] as $url => $uuid) {
if (isset($dict[$uuid])) {
$results[$url] = $dict[$uuid];
} else {
$results[$url] = null;
}
}
}
# Format the results according to the 'as_dict' parameter.
if ($as_dict) {
return Okapi::formatted_response($request, $results);
} else {
$cache_codes = array();
foreach ($results as $url => $cache_code) {
if ($cache_code != null) {
$cache_codes[$cache_code] = true;
}
}
$flattened = array('results' => array_keys($cache_codes));
return Okapi::formatted_response($request, $flattened);
}
}
示例14: get_all_logtypes
/**
* Get an array of all site-specific log-types (id => name in English).
*/
private static function get_all_logtypes()
{
if (Settings::get('OC_BRANCH') == 'oc.pl') {
# OCPL branch does not store cache types in many languages (just two).
$rs = Db::query("select id, en from log_types order by id");
} else {
# OCDE branch uses translation tables.
$rs = Db::query("\n select\n lt.id,\n stt.text as en\n from\n log_types lt\n left join sys_trans_text stt\n on lt.trans_id = stt.trans_id\n and stt.lang = 'EN'\n order by lt.id\n ");
}
$dict = array();
while ($row = mysql_fetch_assoc($rs)) {
$dict[$row['id']] = $row['en'];
}
return $dict;
}
示例15: call
//.........这里部分代码省略.........
throw new InvalidParam('lpc', "Must be a positive value.");
}
}
if (in_array('distance', $fields) || in_array('bearing', $fields) || in_array('bearing2', $fields) || in_array('bearing3', $fields)) {
$tmp = $request->get_parameter('my_location');
if (!$tmp) {
throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter.");
}
$parts = explode('|', $tmp);
if (count($parts) != 2) {
throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got " . count($parts) . ".");
}
foreach ($parts as &$part_ref) {
if (!preg_match("/^-?[0-9]+(\\.?[0-9]*)\$/", $part_ref)) {
throw new InvalidParam('my_location', "'{$part_ref}' is not a valid float number.");
}
$part_ref = floatval($part_ref);
}
list($center_lat, $center_lon) = $parts;
if ($center_lat > 90 || $center_lat < -90) {
throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range.");
}
if ($center_lon > 180 || $center_lon < -180) {
throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range.");
}
}
if (Settings::get('OC_BRANCH') == 'oc.de') {
# DE branch:
# - Caches do not have ratings.
# - Total numbers of founds and notfounds are kept in the "stat_caches" table.
# - search_time and way_length are both round trip values and cannot be null;
# 0 = not specified
# - will-attend-count is stored in separate field
$rs = Db::query("\n select\n c.cache_id, c.name, c.longitude, c.latitude, c.listing_last_modified as last_modified,\n c.date_created, c.type, c.status, c.date_hidden, c.size, c.difficulty,\n c.terrain, c.wp_oc, c.wp_gc, c.logpw, c.user_id,\n if(c.search_time=0, null, c.search_time) as trip_time,\n if(c.way_length=0, null, c.way_length) as trip_distance,\n\n ifnull(sc.toprating, 0) as topratings,\n ifnull(sc.found, 0) as founds,\n ifnull(sc.notfound, 0) as notfounds,\n ifnull(sc.will_attend, 0) as willattends,\n sc.last_found,\n 0 as votes, 0 as score\n -- SEE ALSO OC.PL BRANCH BELOW\n from\n caches c\n left join stat_caches as sc on c.cache_id = sc.cache_id\n where\n wp_oc in ('" . implode("','", array_map('mysql_real_escape_string', $cache_codes)) . "')\n and status in (1,2,3)\n ");
} elseif (Settings::get('OC_BRANCH') == 'oc.pl') {
# PL branch:
# - Caches have ratings.
# - Total numbers of found and notfounds are kept in the "caches" table.
# - search_time is round trip and way_length one way or both ways (this is different on OCDE!);
# both can be null; 0 or null = not specified
# - will-attend-count is stored in caches.notfounds
$rs = Db::query("\n select\n c.cache_id, c.name, c.longitude, c.latitude, c.last_modified,\n c.date_created, c.type, c.status, c.date_hidden, c.size, c.difficulty,\n c.terrain, c.wp_oc, c.wp_gc, c.logpw, c.user_id,\n if(c.search_time=0, null, c.search_time) as trip_time,\n if(c.way_length=0, null, c.way_length) as trip_distance,\n\n c.topratings,\n c.founds,\n c.notfounds,\n c.notfounds as willattends,\n c.last_found,\n c.votes, c.score\n -- SEE ALSO OC.DE BRANCH ABOVE\n from\n caches c\n where\n wp_oc in ('" . implode("','", array_map('mysql_real_escape_string', $cache_codes)) . "')\n and c.status in (1,2,3)\n ");
}
$results = new ArrayObject();
$cacheid2wptcode = array();
$owner_ids = array();
while ($row = mysql_fetch_assoc($rs)) {
$entry = array();
$cacheid2wptcode[$row['cache_id']] = $row['wp_oc'];
foreach ($fields as $field) {
switch ($field) {
case 'code':
$entry['code'] = $row['wp_oc'];
break;
case 'gc_code':
// OC software allows entering anything here, and that's what users do.
// We do a formal verification so that only a valid GC code is returned:
if (preg_match('/^\\s*[Gg][Cc][A-Za-z0-9]+\\s*$/', $row['wp_gc'])) {
$entry['gc_code'] = strtoupper(trim($row['wp_gc']));
} else {
$entry['gc_code'] = null;
}
break;
case 'name':
$entry['name'] = $row['name'];
break;