当前位置: 首页>>代码示例>>PHP>>正文


PHP Db::select_value方法代码示例

本文整理汇总了PHP中okapi\Db::select_value方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::select_value方法的具体用法?PHP Db::select_value怎么用?PHP Db::select_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在okapi\Db的用法示例。


在下文中一共展示了Db::select_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:11,代码来源:stats.php

示例2: 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);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:54,代码来源:geocache.php

示例3: call

 public static function call()
 {
     if (!isset($_GET['id'])) {
         throw new ParamMissing("id");
     }
     $tmp = Db::select_value("\n            select data\n            from okapi_clog\n            where id='" . Db::escape_string($_GET['id']) . "'\n        ");
     $data = unserialize(gzinflate($tmp));
     $response = new OkapiHttpResponse();
     $response->content_type = "application/json; charset=utf-8";
     $response->body = json_encode($data);
     return $response;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:12,代码来源:clogentry.php

示例4: _call

 private static function _call()
 {
     ignore_user_abort(true);
     set_time_limit(0);
     header("Content-Type: text/plain; charset=utf-8");
     $current_ver = self::get_current_version();
     $max_ver = self::get_max_version();
     self::out("Current OKAPI database version: {$current_ver}\n");
     if ($current_ver == 0 && (!isset($_GET['install']) || $_GET['install'] != 'true')) {
         self::out("Current OKAPI settings are:\n\n" . Settings::describe_settings() . "\n\n" . "Make sure they are correct, then append '?install=true' to your query.");
         try {
             Db::select_value("select 1 from caches limit 1");
         } catch (Exception $e) {
             self::out("\n\n" . "IMPORTANT: If you're trying to install OKAPI on an empty database then\n" . "you will fail. OKAPI is not a standalone application, it is a plugin\n" . "for Opencaching sites. Please read this:\n\n" . "https://github.com/opencaching/okapi/issues/299");
         }
         return;
     } elseif ($max_ver == $current_ver) {
         self::out("It is up-to-date.\n\n");
     } elseif ($max_ver < $current_ver) {
         throw new Exception();
     } else {
         self::out("Updating to version {$max_ver}... PLEASE WAIT\n\n");
         while ($current_ver < $max_ver) {
             $version_to_apply = $current_ver + 1;
             self::out("Applying mutation #{$version_to_apply}...");
             try {
                 call_user_func(array(__CLASS__, "ver" . $version_to_apply));
                 self::out(" OK!\n");
                 Okapi::set_var('db_version', $version_to_apply);
                 $current_ver += 1;
             } catch (Exception $e) {
                 self::out(" ERROR\n\n");
                 throw $e;
             }
         }
         self::out("\nDatabase updated.\n\n");
     }
     self::out("Registering new cronjobs...\n");
     # Validate all cronjobs (some might have been added).
     Okapi::set_var("cron_nearest_event", 0);
     Okapi::execute_prerequest_cronjobs();
     self::out("\nUpdate complete.\n");
 }
开发者ID:kojoty,项目名称:okapi,代码行数:43,代码来源:update.php

示例5: execute

 public function execute()
 {
     ob_start();
     $apisrv_stats = OkapiServiceRunner::call('services/apisrv/stats', new OkapiInternalRequest(new OkapiInternalConsumer(), null, array()));
     $active_apps_count = 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 -7 day)\n        ");
     $weekly_stats = Db::select_row("\n            select\n                sum(s.http_calls) as total_http_calls,\n                sum(s.http_runtime) as total_http_runtime\n            from okapi_stats_hourly s\n            where\n                s.consumer_key != 'internal' -- we don't want to exclude 'anonymous' nor 'facade'\n                and s.period_start > date_add(now(), interval -7 day)\n        ");
     print "Hello! This is your weekly summary of OKAPI usage.\n\n";
     print "Apps active this week: " . $active_apps_count . " out of " . $apisrv_stats['apps_count'] . ".\n";
     print "Total of " . $weekly_stats['total_http_calls'] . " requests were made (" . sprintf("%01.1f", $weekly_stats['total_http_runtime']) . " seconds).\n\n";
     $consumers = Db::select_all("\n            select\n                s.consumer_key,\n                c.name,\n                sum(s.http_calls) as http_calls,\n                sum(s.http_runtime) as http_runtime\n            from\n                okapi_stats_hourly s\n                left join okapi_consumers c\n                    on s.consumer_key = c.`key`\n            where s.period_start > date_add(now(), interval -7 day)\n            group by s.consumer_key\n            having sum(s.http_calls) > 0\n            order by sum(s.http_calls) desc\n        ");
     print "== Consumers ==\n\n";
     print "Consumer name                         Calls     Runtime\n";
     print "----------------------------------- ------- -----------\n";
     foreach ($consumers as $row) {
         $name = $row['name'];
         if ($row['consumer_key'] == 'anonymous') {
             $name = "Anonymous (Level 0 Authentication)";
         } elseif ($row['consumer_key'] == 'facade') {
             $name = "Internal usage via Facade";
         }
         if (mb_strlen($name) > 35) {
             $name = mb_substr($name, 0, 32) . "...";
         }
         print self::mb_str_pad($name, 35, " ", STR_PAD_RIGHT);
         print str_pad($row['http_calls'], 8, " ", STR_PAD_LEFT);
         print str_pad(sprintf("%01.2f", $row['http_runtime']), 11, " ", STR_PAD_LEFT) . "s\n";
     }
     print "\n";
     $methods = Db::select_all("\n            select\n                s.service_name,\n                sum(s.http_calls) as http_calls,\n                sum(s.http_runtime) as http_runtime\n            from okapi_stats_hourly s\n            where s.period_start > date_add(now(), interval -7 day)\n            group by s.service_name\n            having sum(s.http_calls) > 0\n            order by sum(s.http_calls) desc\n        ");
     print "== Methods ==\n\n";
     print "Service name                          Calls     Runtime      Avg\n";
     print "----------------------------------- ------- ----------- --------\n";
     foreach ($methods as $row) {
         $name = $row['service_name'];
         if (mb_strlen($name) > 35) {
             $name = mb_substr($name, 0, 32) . "...";
         }
         print self::mb_str_pad($name, 35, " ", STR_PAD_RIGHT);
         print str_pad($row['http_calls'], 8, " ", STR_PAD_LEFT);
         print str_pad(sprintf("%01.2f", $row['http_runtime']), 11, " ", STR_PAD_LEFT) . "s";
         print str_pad(sprintf("%01.4f", $row['http_calls'] > 0 ? $row['http_runtime'] / $row['http_calls'] : 0), 8, " ", STR_PAD_LEFT) . "s\n";
     }
     print "\n";
     $oauth_users = Db::select_all("\n            select\n                c.name,\n                count(*) as users\n            from\n                okapi_authorizations a,\n                okapi_consumers c\n            where a.consumer_key = c.`key`\n            group by a.consumer_key\n            having count(*) >= 5\n            order by count(*) desc;\n        ");
     print "== Current OAuth usage by Consumers with at least 5 users ==\n\n";
     print "Consumer name                         Users\n";
     print "----------------------------------- -------\n";
     foreach ($oauth_users as $row) {
         $name = $row['name'];
         if (mb_strlen($name) > 35) {
             $name = mb_substr($name, 0, 32) . "...";
         }
         print self::mb_str_pad($name, 35, " ", STR_PAD_RIGHT);
         print str_pad($row['users'], 8, " ", STR_PAD_LEFT) . "\n";
     }
     print "\n";
     print "This report includes requests from external consumers and those made via\n";
     print "Facade class (used by OC code). It does not include methods used by OKAPI\n";
     print "internally (i.e. while running cronjobs). Runtimes do not include HTTP\n";
     print "request handling overhead.\n";
     $message = ob_get_clean();
     Okapi::mail_admins("Weekly OKAPI usage report", $message);
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:63,代码来源:cronjobs.php

示例6: call

 public static function call()
 {
     $token_key = isset($_GET['oauth_token']) ? $_GET['oauth_token'] : '';
     $langpref = isset($_GET['langpref']) ? $_GET['langpref'] : Settings::get('SITELANG');
     $langprefs = explode("|", $langpref);
     $locales = array();
     foreach (Locales::$languages as $lang => $attrs) {
         $locales[$attrs['locale']] = $attrs;
     }
     # Current implementation of the "interactivity" parameter is: If developer
     # wants to "confirm_user", then just log out the current user before we
     # continue.
     $force_relogin = isset($_GET['interactivity']) && $_GET['interactivity'] == 'confirm_user';
     $token = Db::select_row("\n            select\n                t.`key` as `key`,\n                c.`key` as consumer_key,\n                c.name as consumer_name,\n                c.url as consumer_url,\n                t.callback,\n                t.verifier\n            from\n                okapi_consumers c,\n                okapi_tokens t\n            where\n                t.`key` = '" . Db::escape_string($token_key) . "'\n                and t.consumer_key = c.`key`\n                and t.user_id is null\n        ");
     $callback_concat_char = strpos($token['callback'], '?') === false ? "?" : "&";
     if (!$token) {
         # Probably Request Token has expired. This will be usually viewed
         # by the user, who knows nothing on tokens and OAuth. Let's be nice then!
         $vars = array('okapi_base_url' => Settings::get('SITE_URL') . "okapi/", 'token' => $token, 'token_expired' => true, 'site_name' => Okapi::get_normalized_site_name(), 'site_url' => Settings::get('SITE_URL'), 'site_logo' => Settings::get('SITE_LOGO'), 'locales' => $locales);
         $response = new OkapiHttpResponse();
         $response->content_type = "text/html; charset=utf-8";
         ob_start();
         $vars['locale_displayed'] = Okapi::gettext_domain_init($langprefs);
         include 'authorize.tpl.php';
         $response->body = ob_get_clean();
         Okapi::gettext_domain_restore();
         return $response;
     }
     # Determine which user is logged in to OC.
     require_once $GLOBALS['rootpath'] . "okapi/lib/oc_session.php";
     $OC_user_id = OCSession::get_user_id();
     # Ensure a user is logged in (or force re-login).
     if ($force_relogin || $OC_user_id == null) {
         # TODO: confirm_user should first ask the user if he's "the proper one",
         # and then offer to sign in as a different user.
         $login_page = 'login.php?';
         if ($OC_user_id !== null) {
             if (Settings::get('OC_BRANCH') == 'oc.de') {
                 # OCDE login.php?action=logout&target=... will NOT logout and
                 # then redirect to the target, but it will log out, prompt for
                 # login and then redirect to the target after logging in -
                 # that's exactly the relogin that we want.
                 $login_page .= 'action=logout&';
             } else {
                 # OCPL uses REAL MAGIC for session handling. I don't get ANY of it.
                 # The logout.php DOES NOT support the "target" parameter, so we
                 # can't just call it. The only thing that comes to mind is...
                 # Try to destroy EVERYTHING. (This still won't necessarilly work,
                 # because OC may store cookies in separate paths, but hopefully
                 # they won't).
                 if (isset($_SERVER['HTTP_COOKIE'])) {
                     $cookies = explode(';', $_SERVER['HTTP_COOKIE']);
                     foreach ($cookies as $cookie) {
                         $parts = explode('=', $cookie);
                         $name = trim($parts[0]);
                         setcookie($name, '', time() - 1000);
                         setcookie($name, '', time() - 1000, '/');
                         foreach (self::getPossibleCookieDomains() as $domain) {
                             setcookie($name, '', time() - 1000, '/', $domain);
                         }
                     }
                 }
                 # We should be logged out now. Let's login again.
             }
         }
         $after_login = "okapi/apps/authorize?oauth_token={$token_key}" . ($langpref != Settings::get('SITELANG') ? "&langpref=" . $langpref : "");
         $login_url = Settings::get('SITE_URL') . $login_page . "target=" . urlencode($after_login) . "&langpref=" . $langpref;
         return new OkapiRedirectResponse($login_url);
     }
     # Check if this user has already authorized this Consumer. If he did,
     # then we will automatically authorize all subsequent Request Tokens
     # from this Consumer.
     $authorized = Db::select_value("\n            select 1\n            from okapi_authorizations\n            where\n                user_id = '" . Db::escape_string($OC_user_id) . "'\n                and consumer_key = '" . Db::escape_string($token['consumer_key']) . "'\n        ", 0);
     if (!$authorized) {
         if (isset($_POST['authorization_result'])) {
             # Not yet authorized, but user have just submitted the authorization form.
             # WRTODO: CSRF protection
             if ($_POST['authorization_result'] == 'granted') {
                 Db::execute("\n                        insert ignore into okapi_authorizations (consumer_key, user_id)\n                        values (\n                            '" . Db::escape_string($token['consumer_key']) . "',\n                            '" . Db::escape_string($OC_user_id) . "'\n                        );\n                    ");
                 $authorized = true;
             } else {
                 # User denied access. Nothing sensible to do now. Will try to report
                 # back to the Consumer application with an error.
                 if ($token['callback']) {
                     return new OkapiRedirectResponse($token['callback'] . $callback_concat_char . "error=access_denied" . "&oauth_token=" . $token['key']);
                 } else {
                     # Consumer did not provide a callback URL (oauth_callback=oob).
                     # We'll have to redirect to the Opencaching main page then...
                     return new OkapiRedirectResponse(Settings::get('SITE_URL') . "index.php");
                 }
             }
         } else {
             # Not yet authorized. Display an authorization request.
             $vars = array('okapi_base_url' => Settings::get('SITE_URL') . "okapi/", 'token' => $token, 'site_name' => Okapi::get_normalized_site_name(), 'site_url' => Settings::get('SITE_URL'), 'site_logo' => Settings::get('SITE_LOGO'), 'locales' => $locales);
             $response = new OkapiHttpResponse();
             $response->content_type = "text/html; charset=utf-8";
             ob_start();
             $vars['locale_displayed'] = Okapi::gettext_domain_init($langprefs);
             include 'authorize.tpl.php';
             $response->body = ob_get_clean();
//.........这里部分代码省略.........
开发者ID:kratenko,项目名称:oc-server3,代码行数:101,代码来源:authorize.php

示例7: compute_tile

 /**
  * Precache the ($zoom, $x, $y) slot in the okapi_tile_caches table.
  */
 public static function compute_tile($zoom, $x, $y)
 {
     $time_started = microtime(true);
     # Note, that multiple threads may try to compute tiles simulatanously.
     # For low-level tiles, this can be expensive.
     $status = self::get_tile_status($zoom, $x, $y);
     if ($status !== null) {
         return $status;
     }
     if ($zoom === 0) {
         # When computing zoom zero, we don't have a parent to speed up
         # the computation. We need to use the caches table. Note, that
         # zoom level 0 contains *entire world*, so we don't have to use
         # any WHERE condition in the following query.
         # This can be done a little faster (without the use of internal requests),
         # but there is *no need* to - this query is run seldom and is cached.
         $params = array();
         $params['status'] = "Available|Temporarily unavailable|Archived";
         # we want them all
         $params['limit'] = "10000000";
         # no limit
         $internal_request = new OkapiInternalRequest(new OkapiInternalConsumer(), null, $params);
         $internal_request->skip_limits = true;
         $response = OkapiServiceRunner::call("services/caches/search/all", $internal_request);
         $cache_codes = $response['results'];
         $internal_request = new OkapiInternalRequest(new OkapiInternalConsumer(), null, array('cache_codes' => implode('|', $cache_codes), 'fields' => 'internal_id|code|name|location|type|status|rating|recommendations|founds|trackables_count'));
         $internal_request->skip_limits = true;
         $caches = OkapiServiceRunner::call("services/caches/geocaches", $internal_request);
         foreach ($caches as $cache) {
             $row = self::generate_short_row($cache);
             if (!$row) {
                 /* Some caches cannot be included, e.g. the ones near the poles. */
                 continue;
             }
             Db::execute("\n                    replace into okapi_tile_caches (\n                        z, x, y, cache_id, z21x, z21y, status, type, rating, flags, name_crc\n                    ) values (\n                        0, 0, 0,\n                        '" . Db::escape_string($row[0]) . "',\n                        '" . Db::escape_string($row[1]) . "',\n                        '" . Db::escape_string($row[2]) . "',\n                        '" . Db::escape_string($row[3]) . "',\n                        '" . Db::escape_string($row[4]) . "',\n                        " . ($row[5] === null ? "null" : "'" . Db::escape_string($row[5]) . "'") . ",\n                        '" . Db::escape_string($row[6]) . "',\n                        '" . Db::escape_string($row[7]) . "'\n                    );\n                ");
         }
         $status = 2;
     } else {
         # We will use the parent tile to compute the contents of this tile.
         $parent_zoom = $zoom - 1;
         $parent_x = $x >> 1;
         $parent_y = $y >> 1;
         $status = self::get_tile_status($parent_zoom, $parent_x, $parent_y);
         if ($status === null) {
             $time_started = microtime(true);
             $status = self::compute_tile($parent_zoom, $parent_x, $parent_y);
         }
         if ($status === 1) {
             # No need to check.
         } else {
             $scale = 8 + 21 - $zoom;
             $parentcenter_z21x = ($parent_x << 1 | 1) << $scale;
             $parentcenter_z21y = ($parent_y << 1 | 1) << $scale;
             $margin = 1 << $scale - 2;
             $left_z21x = ($parent_x << 1 << $scale) - $margin;
             $right_z21x = ($parent_x + 1 << 1 << $scale) + $margin;
             $top_z21y = ($parent_y << 1 << $scale) - $margin;
             $bottom_z21y = ($parent_y + 1 << 1 << $scale) + $margin;
             # Choose the right quarter.
             # |1 2|
             # |3 4|
             if ($x & 1) {
                 # 2 or 4
                 $left_z21x = $parentcenter_z21x - $margin;
             } else {
                 # 1 or 3
                 $right_z21x = $parentcenter_z21x + $margin;
             }
             if ($y & 1) {
                 # 3 or 4
                 $top_z21y = $parentcenter_z21y - $margin;
             } else {
                 # 1 or 2
                 $bottom_z21y = $parentcenter_z21y + $margin;
             }
             # Cache the result.
             # Avoid deadlocks, see https://github.com/opencaching/okapi/issues/388
             Db::execute("lock tables okapi_tile_caches write, okapi_tile_caches tc2 read");
             Db::execute("\n                    replace into okapi_tile_caches (\n                        z, x, y, cache_id, z21x, z21y, status, type, rating,\n                        flags, name_crc\n                    )\n                    select\n                        '" . Db::escape_string($zoom) . "',\n                        '" . Db::escape_string($x) . "',\n                        '" . Db::escape_string($y) . "',\n                        cache_id, z21x, z21y, status, type, rating,\n                        flags, name_crc\n                    from okapi_tile_caches tc2\n                    where\n                        z = '" . Db::escape_string($parent_zoom) . "'\n                        and x = '" . Db::escape_string($parent_x) . "'\n                        and y = '" . Db::escape_string($parent_y) . "'\n                        and z21x between {$left_z21x} and {$right_z21x}\n                        and z21y between {$top_z21y} and {$bottom_z21y}\n                ");
             Db::execute("unlock tables");
             $test = Db::select_value("\n                    select 1\n                    from okapi_tile_caches\n                    where\n                        z = '" . Db::escape_string($zoom) . "'\n                        and x = '" . Db::escape_string($x) . "'\n                        and y = '" . Db::escape_string($y) . "'\n                    limit 1;\n                ");
             if ($test) {
                 $status = 2;
             } else {
                 $status = 1;
             }
         }
     }
     # Mark tile as computed.
     Db::execute("\n            replace into okapi_tile_status (z, x, y, status)\n            values (\n                '" . Db::escape_string($zoom) . "',\n                '" . Db::escape_string($x) . "',\n                '" . Db::escape_string($y) . "',\n                '" . Db::escape_string($status) . "'\n            );\n        ");
     return $status;
 }
开发者ID:kirstenko,项目名称:oc-server3,代码行数:95,代码来源:tiletree.inc.php

示例8: prepare_common_search_params


//.........这里部分代码省略.........
     if ($tmp = $this->request->get_parameter('powertrail_only')) {
         if ($tmp === 'true') {
             $join_powertrails = true;
         } elseif ($tmp === 'false') {
             $join_powertrails = false;
         } else {
             throw new InvalidParam('powertrail_only', "Boolean expected, '{$tmp}' found.");
         }
     }
     $powertrail_ids = $this->request->get_parameter('powertrail_ids');
     if ($powertrail_ids) {
         $join_powertrails = true;
     }
     if ($join_powertrails) {
         if (Settings::get('OC_BRANCH') == 'oc.pl') {
             $extra_tables[] = "powerTrail_caches";
             $extra_tables[] = "PowerTrail";
             $where_conds[] = "powerTrail_caches.cacheId = caches.cache_id";
             $where_conds[] = "PowerTrail.id = powerTrail_caches.powerTrailId";
             $where_conds[] = 'PowerTrail.status = 1';
             if ($powertrail_ids) {
                 $where_conds[] = "PowerTrail.id in ('" . implode("','", array_map('mysql_real_escape_string', explode("|", $powertrail_ids))) . "')";
             }
         } else {
             $where_conds[] = "0=1";
         }
     }
     unset($powertrail_ids, $join_powertrails);
     #
     # set_and
     #
     if ($tmp = $this->request->get_parameter('set_and')) {
         # Check if the set exists.
         $exists = Db::select_value("\n                select 1\n                from okapi_search_sets\n                where id = '" . mysql_real_escape_string($tmp) . "'\n            ");
         if (!$exists) {
             throw new InvalidParam('set_and', "Couldn't find a set by given ID.");
         }
         $extra_tables[] = "okapi_search_results osr_and";
         $where_conds[] = "osr_and.cache_id = caches.cache_id";
         $where_conds[] = "osr_and.set_id = '" . mysql_real_escape_string($tmp) . "'";
     }
     #
     # limit
     #
     $limit = $this->request->get_parameter('limit');
     if ($limit == null) {
         $limit = "100";
     }
     if (!is_numeric($limit)) {
         throw new InvalidParam('limit', "'{$limit}'");
     }
     if ($limit < 1 || $limit > 500 && !$this->request->skip_limits) {
         throw new InvalidParam('limit', $this->request->skip_limits ? "Cannot be lower than 1." : "Has to be between 1 and 500.");
     }
     #
     # offset
     #
     $offset = $this->request->get_parameter('offset');
     if ($offset == null) {
         $offset = "0";
     }
     if (!is_numeric($offset)) {
         throw new InvalidParam('offset', "'{$offset}'");
     }
     if ($offset + $limit > 500 && !$this->request->skip_limits) {
         throw new BadRequest("The sum of offset and limit may not exceed 500.");
开发者ID:harrieklomp,项目名称:oc-server3,代码行数:67,代码来源:searching.inc.php

示例9: check_since_param

 /**
  * Check if the 'since' parameter is up-do-date. If it is not, then it means
  * that the user waited too long and he has to download the fulldump again.
  */
 public static function check_since_param($since)
 {
     $first_id = Db::select_value("\n            select id from okapi_clog where id > '" . mysql_real_escape_string($since) . "' limit 1\n        ");
     if ($first_id === null) {
         return true;
     }
     # okay, since points to the newest revision
     if ($first_id == $since + 1) {
         return true;
     }
     # okay, revision $since + 1 is present
     # If we're here, then this means that $first_id > $since + 1.
     # Revision $since + 1 is already deleted, $since must be too old!
     return false;
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:19,代码来源:replicate_common.inc.php

示例10: count_calls

 private static function count_calls($consumer_key, $days)
 {
     return Db::select_value("\n                select count(*)\n                from okapi_stats_temp\n                where\n                    consumer_key = '" . mysql_real_escape_string($consumer_key) . "'\n                    and service_name='services/replicate/fulldump'\n            ") + Db::select_value("\n                select sum(total_calls)\n                from okapi_stats_hourly\n                where\n                    consumer_key = '" . mysql_real_escape_string($consumer_key) . "'\n                    and service_name='services/replicate/fulldump'\n                    and period_start > date_add(now(), interval -{$days} day)\n                limit 1\n            ");
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:4,代码来源:fulldump.php

示例11: get_caption

 /**
  * Return 64x26 bitmap with the caption (name) for the given geocache.
  */
 private function get_caption($cache_id)
 {
     # Check cache.
     $cache_key = "tilecaption/" . self::$VERSION . "/" . $cache_id;
     $gd2 = self::$USE_CAPTIONS_CACHE ? Cache::get($cache_key) : null;
     if ($gd2 === null) {
         # We'll work with 16x bigger image to get smoother interpolation.
         $im = imagecreatetruecolor(64 * 4, 26 * 4);
         imagealphablending($im, false);
         $transparent = imagecolorallocatealpha($im, 255, 255, 255, 127);
         imagefilledrectangle($im, 0, 0, 64 * 4, 26 * 4, $transparent);
         imagealphablending($im, true);
         # Get the name of the cache.
         $name = Db::select_value("\n                select name\n                from caches\n                where cache_id = '" . mysql_real_escape_string($cache_id) . "'\n            ");
         # Split the name into a couple of lines.
         //$font = $GLOBALS['rootpath'].'util.sec/bt.ttf';
         $font = $GLOBALS['rootpath'] . 'okapi/static/tilemap/tahoma.ttf';
         $size = 25;
         $lines = explode("\n", self::wordwrap($font, $size, 64 * 4 - 6 * 2, $name));
         # For each line, compute its (x, y) so that the text is centered.
         $y = 0;
         $positions = array();
         foreach ($lines as $line) {
             $bbox = imagettfbbox($size, 0, $font, $line);
             $width = $bbox[2] - $bbox[0];
             $x = 128 - ($width >> 1);
             $positions[] = array($x, $y);
             $y += 36;
         }
         $drawer = function ($x, $y, $color) use(&$lines, &$positions, &$im, &$size, &$font) {
             $len = count($lines);
             for ($i = 0; $i < $len; $i++) {
                 $line = $lines[$i];
                 list($offset_x, $offset_y) = $positions[$i];
                 imagettftext($im, $size, 0, $offset_x + $x, $offset_y + $y, $color, $font, $line);
             }
         };
         # Draw an outline.
         $outline_color = imagecolorallocatealpha($im, 255, 255, 255, 80);
         for ($x = 0; $x <= 12; $x += 3) {
             for ($y = $size - 3; $y <= $size + 9; $y += 3) {
                 $drawer($x, $y, $outline_color);
             }
         }
         # Add a slight shadow effect (on top of the outline).
         $drawer(9, $size + 3, imagecolorallocatealpha($im, 0, 0, 0, 110));
         # Draw the caption.
         $drawer(6, $size + 3, imagecolorallocatealpha($im, 150, 0, 0, 40));
         # Resample.
         imagealphablending($im, false);
         $small = imagecreatetruecolor(64, 26);
         imagealphablending($small, false);
         imagecopyresampled($small, $im, 0, 0, 0, 0, 64, 26, 64 * 4, 26 * 4);
         # Cache it!
         ob_start();
         imagegd2($small);
         $gd2 = ob_get_clean();
         Cache::set_scored($cache_key, $gd2);
     }
     return imagecreatefromstring($gd2);
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:64,代码来源:tilerenderer.inc.php

示例12: handle_geocache_delete

 private static function handle_geocache_delete($c)
 {
     # Simply delete the cache at all zoom levels.
     $cache_id = Db::select_value("\n            select cache_id\n            from caches\n            where wp_oc='" . mysql_real_escape_string($c['object_key']['code']) . "'\n        ");
     self::remove_geocache_from_cached_tiles($cache_id);
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:6,代码来源:replicate_listener.inc.php

示例13: _call


//.........这里部分代码省略.........
     }
     if (!in_array($needs_maintenance, array('true', 'false'))) {
         throw new InvalidParam('needs_maintenance', "Unknown option: '{$needs_maintenance}'.");
     }
     $needs_maintenance = $needs_maintenance == 'true';
     if ($needs_maintenance && !Settings::get('SUPPORTS_LOGTYPE_NEEDS_MAINTENANCE')) {
         # If not supported, just ignore it.
         self::$success_message .= " " . sprintf(_("However, your \"needs maintenance\" flag was ignored, because %s does not support this feature."), Okapi::get_normalized_site_name());
         $needs_maintenance = false;
     }
     # Check if cache exists and retrieve cache internal ID (this will throw
     # a proper exception on invalid cache_code). Also, get the user object.
     $cache = OkapiServiceRunner::call('services/caches/geocache', new OkapiInternalRequest($request->consumer, null, array('cache_code' => $cache_code, 'fields' => 'internal_id|status|owner|type|req_passwd')));
     $user = OkapiServiceRunner::call('services/users/by_internal_id', new OkapiInternalRequest($request->consumer, $request->token, array('internal_id' => $request->token->user_id, 'fields' => 'is_admin|uuid|internal_id|caches_found|rcmds_given')));
     # Various integrity checks.
     if ($cache['type'] == 'Event') {
         if (!in_array($logtype, array('Will attend', 'Attended', 'Comment'))) {
             throw new CannotPublishException(_('This cache is an Event cache. You cannot "Find" it (but you can attend it, or comment on it)!'));
         }
     } else {
         if (in_array($logtype, array('Will attend', 'Attended'))) {
             throw new CannotPublishException(_('This cache is NOT an Event cache. You cannot "Attend" it (but you can find it, or comment on it)!'));
         } else {
             if (!in_array($logtype, array('Found it', "Didn't find it", 'Comment'))) {
                 throw new Exception("Unknown log entry - should be documented here.");
             }
         }
     }
     if ($logtype == 'Comment' && strlen(trim($comment)) == 0) {
         throw new CannotPublishException(_("Your have to supply some text for your comment."));
     }
     # Password check.
     if (($logtype == 'Found it' || $logtype == 'Attended') && $cache['req_passwd']) {
         $valid_password = Db::select_value("\n                select logpw\n                from caches\n                where cache_id = '" . mysql_real_escape_string($cache['internal_id']) . "'\n            ");
         $supplied_password = $request->get_parameter('password');
         if (!$supplied_password) {
             throw new CannotPublishException(_("This cache requires a password. You didn't provide one!"));
         }
         if (strtolower($supplied_password) != strtolower($valid_password)) {
             throw new CannotPublishException(_("Invalid password!"));
         }
     }
     # Prepare our comment to be inserted into the database. This may require
     # some reformatting which depends on the current OC installation.
     if (Settings::get('OC_BRANCH') == 'oc.de') {
         # OCDE stores all comments in HTML format, while the 'text_html' field
         # indicates their *original* format as delivered by the user. This
         # allows processing the 'text' field contents without caring about the
         # original format, while still being able to re-create the comment in
         # its original form. It requires us to HTML-encode plaintext comments
         # and to indicate this by setting 'html_text' to FALSE.
         #
         # For user-supplied HTML comments, OCDE requires us to do additional
         # HTML purification prior to the insertion into the database.
         if ($comment_format == 'plaintext') {
             $formatted_comment = htmlspecialchars($comment, ENT_QUOTES);
             $formatted_comment = nl2br($formatted_comment);
             $value_for_text_html_field = 0;
         } else {
             if ($comment_format == 'auto') {
                 # 'Auto' is for backward compatibility. Before the "comment_format"
                 # was introduced, OKAPI used a weird format in between (it allowed
                 # HTML, but applied nl2br too).
                 $formatted_comment = nl2br($comment);
             } else {
                 $formatted_comment = $comment;
开发者ID:4Vs,项目名称:oc-server3,代码行数:67,代码来源:submit.php

示例14: _call

 /**
  * Edit an log entry image and return its (new) position.
  * Throws CannotPublishException or BadRequest on errors.
  */
 private static function _call(OkapiRequest $request)
 {
     # Developers! Please notice the fundamental difference between throwing
     # CannotPublishException and the "standard" BadRequest/InvalidParam
     # exceptions. CannotPublishException will be caught by the service's
     # call() function and returns a message to be displayed to the user.
     require_once 'log_images_common.inc.php';
     # validate the 'image_uuid' parameter
     list($image_uuid, $log_internal_id) = LogImagesCommon::validate_image_uuid($request);
     # validate the 'caption', 'is_spoiler' and 'position' parameters
     $caption = $request->get_parameter('caption');
     if ($caption !== null && $caption == '') {
         throw new CannotPublishException(sprintf(_("Please enter an image caption."), Okapi::get_normalized_site_name()));
     }
     $is_spoiler = $request->get_parameter('is_spoiler');
     if ($is_spoiler !== null) {
         if (!in_array($is_spoiler, array('true', 'false'))) {
             throw new InvalidParam('is_spoiler');
         }
     }
     $position = LogImagesCommon::validate_position($request);
     if ($caption === null && $is_spoiler === null && $position === null) {
         # If no-params were allowed, what would be the success message?
         # It's more reasonable to assume that this was a developer's error.
         throw new BadRequest("At least one of the parameters 'caption', 'is_spoiler' and 'position' must be supplied");
     }
     $image_uuid_escaped = Db::escape_string($image_uuid);
     $log_entry_modified = false;
     # update caption
     if ($caption !== null) {
         Db::execute("\n                update pictures\n                set title = '" . Db::escape_string($caption) . "'\n                where uuid = '" . $image_uuid_escaped . "'\n            ");
         $log_entry_modified = true;
     }
     # update spoiler flag
     if ($is_spoiler !== null) {
         Db::execute("\n                update pictures\n                set spoiler = " . ($is_spoiler == 'true' ? 1 : 0) . "\n                where uuid = '" . $image_uuid_escaped . "'\n            ");
         $log_entry_modified = true;
     }
     # update position
     if ($position !== null) {
         if (Settings::get('OC_BRANCH') == 'oc.pl') {
             # OCPL as no arbitrary log picture ordering => ignore position parameter
             # and return the picture's current position.
             $image_uuids = Db::select_column("\n                    select uuid from pictures\n                    where object_type = 1 and object_id = '" . Db::escape_string($log_internal_id) . "'\n                    order by date_created\n                ");
             $position = array_search($image_uuid, $image_uuids);
         } else {
             list($position, $seq) = LogImagesCommon::prepare_position($log_internal_id, $position, 0);
             # For OCDE the pictures table is write locked now.
             $old_seq = DB::select_value("\n                    select seq from pictures where uuid = '" . $image_uuid_escaped . "'\n                ");
             if ($seq != $old_seq) {
                 # First move the edited picture to the end, to make space for rotating.
                 # Remember that we have no transactions at OC.de. If something goes wrong,
                 # the image will stay at the end of the list.
                 $max_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                    ");
                 Db::query("\n                        update pictures\n                        set seq = '" . Db::escape_string($max_seq + 1) . "'\n                        where uuid = '" . $image_uuid_escaped . "'\n                    ");
                 # now move the pictures inbetween
                 if ($seq < $old_seq) {
                     Db::execute("\n                            update pictures\n                            set seq = seq + 1\n                            where\n                                object_type = 1\n                                and object_id = '" . Db::escape_string($log_internal_id) . "'\n                                and seq >= '" . Db::escape_string($seq) . "'\n                                and seq < '" . Db::escape_string($old_seq) . "'\n                            order by seq desc\n                        ");
                 } else {
                     Db::execute("\n                            update pictures\n                            set seq = seq - 1\n                            where\n                                object_type = 1\n                                and object_id = '" . Db::escape_string($log_internal_id) . "'\n                                and seq <= '" . Db::escape_string($seq) . "'\n                                and seq > '" . Db::escape_string($old_seq) . "'\n                            order by seq asc\n                        ");
                 }
                 # and finally move the edited picture into place
                 Db::query("\n                        update pictures\n                        set seq = '" . Db::escape_string($seq) . "'\n                        where uuid = '" . $image_uuid_escaped . "'\n                    ");
             }
             Db::execute('unlock tables');
             $log_entry_modified = true;
         }
     }
     if (Settings::get('OC_BRANCH') == 'oc.pl' && $log_entry_modified) {
         # OCDE touches the log entry via trigger, OCPL needs an explicit update.
         # This will also update okapi_syncbase.
         Db::query("\n                update cache_logs\n                set last_modified = NOW()\n                where id = '" . Db::escape_string($log_internal_id) . "'\n            ");
         # OCPL code currently does not update pictures.last_modified when
         # editing, but that is a bug, see
         # https://github.com/opencaching/opencaching-pl/issues/341.
     }
     return $position;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:82,代码来源:edit.php

示例15: __construct

 public function __construct($options)
 {
     Okapi::init_internals();
     $this->init_request();
     #
     # Parsing options.
     #
     $DEBUG_AS_USERNAME = null;
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'min_auth_level':
                 if (!in_array($value, array(0, 1, 2, 3))) {
                     throw new Exception("'min_auth_level' option has invalid value: {$value}");
                 }
                 $this->opt_min_auth_level = $value;
                 break;
             case 'token_type':
                 if (!in_array($value, array("request", "access"))) {
                     throw new Exception("'token_type' option has invalid value: {$value}");
                 }
                 $this->opt_token_type = $value;
                 break;
             case 'DEBUG_AS_USERNAME':
                 $DEBUG_AS_USERNAME = $value;
                 break;
             default:
                 throw new Exception("Unknown option: {$key}");
                 break;
         }
     }
     if ($this->opt_min_auth_level === null) {
         throw new Exception("Required 'min_auth_level' option is missing.");
     }
     if ($DEBUG_AS_USERNAME != null) {
         # Enables debugging Level 2 and Level 3 methods. Should not be committed
         # at any time! If run on production server, make it an error.
         if (!Settings::get('DEBUG')) {
             throw new Exception("Attempted to use DEBUG_AS_USERNAME in " . "non-debug environment. Accidental commit?");
         }
         # Lower required authentication to Level 0, to pass the checks.
         $this->opt_min_auth_level = 0;
     }
     #
     # Let's see if the request is signed. If it is, verify the signature.
     # It it's not, check if it isn't against the rules defined in the $options.
     #
     if ($this->get_parameter('oauth_signature')) {
         # User is using OAuth.
         # Check for duplicate keys in the parameters. (Datastore doesn't
         # do that on its own, it caused vague server errors - issue #307.)
         $this->get_parameter('oauth_consumer');
         $this->get_parameter('oauth_version');
         $this->get_parameter('oauth_token');
         $this->get_parameter('oauth_nonce');
         # Verify OAuth request.
         list($this->consumer, $this->token) = Okapi::$server->verify_request2($this->request, $this->opt_token_type, $this->opt_min_auth_level == 3);
         if ($this->get_parameter('consumer_key') && $this->get_parameter('consumer_key') != $this->get_parameter('oauth_consumer_key')) {
             throw new BadRequest("Inproper mixing of authentication types. You used both 'consumer_key' " . "and 'oauth_consumer_key' parameters (Level 1 and Level 2), but they do not match with " . "each other. Were you trying to hack me? ;)");
         }
         if ($this->opt_min_auth_level == 3 && !$this->token) {
             throw new BadRequest("This method requires a valid Token to be included (Level 3 " . "Authentication). You didn't provide one.");
         }
     } else {
         if ($this->opt_min_auth_level >= 2) {
             throw new BadRequest("This method requires OAuth signature (Level " . $this->opt_min_auth_level . " Authentication). You didn't sign your request.");
         } else {
             $consumer_key = $this->get_parameter('consumer_key');
             if ($consumer_key) {
                 $this->consumer = Okapi::$data_store->lookup_consumer($consumer_key);
                 if (!$this->consumer) {
                     throw new InvalidParam('consumer_key', "Consumer does not exist.");
                 }
             }
             if ($this->opt_min_auth_level == 1 && !$this->consumer) {
                 throw new BadRequest("This method requires the 'consumer_key' argument (Level 1 " . "Authentication). You didn't provide one.");
             }
         }
     }
     if (is_object($this->consumer) && $this->consumer->hasFlag(OkapiConsumer::FLAG_SKIP_LIMITS)) {
         $this->skip_limits = true;
     }
     #
     # Prevent developers from accessing request parameters with PHP globals.
     # Remember, that OKAPI requests can be nested within other OKAPI requests!
     # Search the code for "new OkapiInternalRequest" to see examples.
     #
     $_GET = $_POST = $_REQUEST = null;
     # When debugging, simulate as if been run using a proper Level 3 Authentication.
     if ($DEBUG_AS_USERNAME != null) {
         # Note, that this will override any other valid authentication the
         # developer might have issued.
         $debug_user_id = Db::select_value("select user_id from user where username='" . mysql_real_escape_string($options['DEBUG_AS_USERNAME']) . "'");
         if ($debug_user_id == null) {
             throw new Exception("Invalid user name in DEBUG_AS_USERNAME: '" . $options['DEBUG_AS_USERNAME'] . "'");
         }
         $this->consumer = new OkapiDebugConsumer();
         $this->token = new OkapiDebugAccessToken($debug_user_id);
     }
     # Read the ETag.
     if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
//.........这里部分代码省略.........
开发者ID:Slini11,项目名称:okapi,代码行数:101,代码来源:core.php


注:本文中的okapi\Db::select_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。