• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP okapi\Okapi类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Okapi类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:33,代码来源:index.php


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


示例3: call

 public static function call(OkapiRequest $request)
 {
     $search_assistant = new SearchAssistant($request);
     $search_assistant->prepare_common_search_params();
     $result = $search_assistant->get_common_search_result();
     return Okapi::formatted_response($request, $result);
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:7,代码来源:all.php


示例4: new_access_token

 public function new_access_token($token, $consumer, $verifier = null)
 {
     if ($token->consumer_key != $consumer->key) {
         throw new BadRequest("Request Token given is not associated with the Consumer who signed the request.");
     }
     if (!$token->authorized_by_user_id) {
         throw new BadRequest("Request Token given has not been authorized.");
     }
     if ($token->verifier != $verifier) {
         throw new BadRequest("Invalid verifier.");
     }
     # Invalidate the Request Token.
     Db::execute("\n            delete from okapi_tokens\n            where `key` = '" . Db::escape_string($token->key) . "'\n        ");
     # In OKAPI, all Access Tokens are long lived. Therefore, we don't want
     # to generate a new one every time a Consumer wants it. We will check
     # if there is already an Access Token generated for this (Consumer, User)
     # pair and return it if there is.
     $row = Db::select_row("\n            select `key`, secret\n            from okapi_tokens\n            where\n                token_type = 'access'\n                and user_id = '" . Db::escape_string($token->authorized_by_user_id) . "'\n                and consumer_key = '" . Db::escape_string($consumer->key) . "'\n        ");
     if ($row) {
         # Use existing Access Token
         $access_token = new OkapiAccessToken($row['key'], $row['secret'], $consumer->key, $token->authorized_by_user_id);
     } else {
         # Generate a new Access Token.
         $access_token = new OkapiAccessToken(Okapi::generate_key(20), Okapi::generate_key(40), $consumer->key, $token->authorized_by_user_id);
         Db::execute("\n                insert into okapi_tokens\n                    (`key`, secret, token_type, timestamp, user_id, consumer_key)\n                values (\n                    '" . Db::escape_string($access_token->key) . "',\n                    '" . Db::escape_string($access_token->secret) . "',\n                    'access',\n                    unix_timestamp(),\n                    '" . Db::escape_string($access_token->user_id) . "',\n                    '" . Db::escape_string($consumer->key) . "'\n                );\n            ");
     }
     return $access_token;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:28,代码来源:datastore.php


示例5: call

 public static function call(OkapiRequest $request)
 {
     # User is already verified (via OAuth), but we need to verify the
     # cache code (check if it exists). We will simply call a geocache method
     # on it - this will also throw a proper exception if it doesn't exist.
     $cache_code = $request->get_parameter('cache_code');
     if ($cache_code == null) {
         throw new ParamMissing('cache_code');
     }
     $geocache = OkapiServiceRunner::call('services/caches/geocache', new OkapiInternalRequest($request->consumer, $request->token, array('cache_code' => $cache_code, 'fields' => 'internal_id')));
     # watched
     if ($tmp = $request->get_parameter('watched')) {
         if (!in_array($tmp, array('true', 'false', 'unchanged'))) {
             throw new InvalidParam('watched', $tmp);
         }
         if ($tmp == 'true') {
             Db::execute("\n                    insert ignore into cache_watches (cache_id, user_id)\n                    values (\n                        '" . Db::escape_string($geocache['internal_id']) . "',\n                        '" . Db::escape_string($request->token->user_id) . "'\n                    );\n                ");
         } elseif ($tmp == 'false') {
             Db::execute("\n                    delete from cache_watches\n                    where\n                        cache_id = '" . Db::escape_string($geocache['internal_id']) . "'\n                        and user_id = '" . Db::escape_string($request->token->user_id) . "';\n                ");
         }
     }
     # ignored
     if ($tmp = $request->get_parameter('ignored')) {
         if (!in_array($tmp, array('true', 'false', 'unchanged'))) {
             throw new InvalidParam('ignored', $tmp);
         }
         if ($tmp == 'true') {
             Db::execute("\n                    insert ignore into cache_ignore (cache_id, user_id)\n                    values (\n                        '" . Db::escape_string($geocache['internal_id']) . "',\n                        '" . Db::escape_string($request->token->user_id) . "'\n                    );\n                ");
         } elseif ($tmp == 'false') {
             Db::execute("\n                    delete from cache_ignore\n                    where\n                        cache_id = '" . Db::escape_string($geocache['internal_id']) . "'\n                        and user_id = '" . Db::escape_string($request->token->user_id) . "'\n                ");
         }
     }
     $result = array('success' => true);
     return Okapi::formatted_response($request, $result);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:35,代码来源:mark.php


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


示例7: call

 /**
  * Execute the method and return the result.
  *
  * OKAPI methods return OkapiHttpResponses, but some MAY also return
  * PHP objects (see OkapiRequest::construct_inside_request for details).
  *
  * If $request must be consistent with given method's options (must
  * include Consumer and Token, if they are required).
  */
 public static function call($service_name, OkapiRequest $request)
 {
     Okapi::init_internals();
     if (!self::exists($service_name)) {
         throw new Exception("Method does not exist: '{$service_name}'");
     }
     $options = self::options($service_name);
     if ($options['min_auth_level'] >= 2 && $request->consumer == null) {
         throw new Exception("Method '{$service_name}' called with mismatched OkapiRequest: " . "\$request->consumer MAY NOT be empty for Level 2 and Level 3 methods. Provide " . "a dummy Consumer if you have to.");
     }
     if ($options['min_auth_level'] >= 3 && $request->token == null) {
         throw new Exception("Method '{$service_name}' called with mismatched OkapiRequest: " . "\$request->token MAY NOT be empty for Level 3 methods.");
     }
     $time_started = microtime(true);
     Okapi::gettext_domain_init();
     try {
         require_once $GLOBALS['rootpath'] . "okapi/{$service_name}.php";
         $response = call_user_func(array('\\okapi\\' . str_replace('/', '\\', $service_name) . '\\WebService', 'call'), $request);
         Okapi::gettext_domain_restore();
     } catch (Exception $e) {
         Okapi::gettext_domain_restore();
         throw $e;
     }
     $runtime = microtime(true) - $time_started;
     # Log the request to the stats table. Only valid requests (these which didn't end up
     # with an exception) are logged.
     self::save_stats($service_name, $request, $runtime);
     return $response;
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:38,代码来源:service_runner.php


示例8: call

 public static function call(OkapiRequest $request)
 {
     # Read the parameters.
     $acode = $request->get_parameter('acode');
     if ($acode === null) {
         throw new ParamMissing('acode');
     }
     if (strstr($acode, '|')) {
         throw new InvalidParam('acode', "Only a single A-code must be supplied.");
     }
     $langpref = $request->get_parameter('langpref');
     if (!$langpref) {
         $langpref = "en";
     }
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         $fields = "name";
     }
     $forward_compatible = $request->get_parameter('forward_compatible');
     if (!$forward_compatible) {
         $forward_compatible = "true";
     }
     # Pass them all to the attributes method.
     $params = array('acodes' => $acode, 'langpref' => $langpref, 'fields' => $fields, 'forward_compatible' => $forward_compatible);
     $results = OkapiServiceRunner::call('services/attrs/attributes', new OkapiInternalRequest($request->consumer, $request->token, $params));
     $result = $results[$acode];
     if ($result === null) {
         /* Note, this can happen only when $forward_compatible is false. */
         throw new InvalidParam('acode', "Unknown A-code.");
     }
     return Okapi::formatted_response($request, $result);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:32,代码来源:attribute.php


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


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


示例11: call

 public static function call()
 {
     ignore_user_abort(true);
     set_time_limit(0);
     header("Content-Type: text/plain; charset=utf-8");
     # Uncomment the following if you want to debug a specific cronjob. It will be run
     # every 5 minutes (run 'crontab -e' to change or disable it) AND additionally
     # every time you visit http://yoursite/okapi/cron5
     # require_once($GLOBALS['rootpath']."okapi/cronjobs.php"); CronJobController::force_run("JOB_NAME"); die();
     Okapi::execute_cron5_cronjobs();
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:11,代码来源:cron5.php


示例12: 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


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


示例14: 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;
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:12,代码来源:examples.php


示例15: call

 public static function call(OkapiRequest $request)
 {
     require_once 'replicate_common.inc.php';
     $result = array();
     $result['changelog'] = array('min_since' => ReplicateCommon::get_min_since(), 'revision' => ReplicateCommon::get_revision());
     $dump = Cache::get("last_fulldump");
     if ($dump) {
         $result['latest_fulldump'] = array('revision' => $dump['revision'], 'generated_at' => $dump['meta']['generated_at'], 'size' => $dump['meta']['compressed_size'], 'size_uncompressed' => $dump['meta']['uncompressed_size']);
     } else {
         $result['latest_fulldump'] = null;
     }
     return Okapi::formatted_response($request, $result);
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:13,代码来源:info.php


示例16: call

 public static function call()
 {
     require_once $GLOBALS['rootpath'] . 'okapi/views/menu.inc.php';
     require_once $GLOBALS['rootpath'] . 'okapi/views/changelog_helper.inc.php';
     $changelog = new Changelog();
     $vars = array('menu' => OkapiMenu::get_menu_html("changelog.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(), 'changes' => array('unavailable' => $changelog->unavailable_changes, 'available' => $changelog->available_changes));
     $response = new OkapiHttpResponse();
     $response->content_type = "text/html; charset=utf-8";
     ob_start();
     include 'changelog.tpl.php';
     $response->body = ob_get_clean();
     return $response;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:13,代码来源:changelog.php


示例17: 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');
     }
     # In October 2013, Google Code feed at:
     # http://code.google.com/feeds/issues/p/opencaching-api/issues/$issue_id/comments/full
     # stopped working. We are forced to respond with a simple placeholder.
     $result = array('id' => $issue_id + 0, 'last_updated' => null, 'title' => null, 'url' => "https://code.google.com/p/opencaching-api/issues/detail?id=" . $issue_id, 'comment_count' => null);
     return Okapi::formatted_response($request, $result);
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:15,代码来源:issue.php


示例18: call

 public static function call(OkapiRequest $request)
 {
     $username = $request->get_parameter('username');
     if (!$username) {
         throw new ParamMissing('username');
     }
     $fields = $request->get_parameter('fields');
     # There's no need to validate the fields parameter.
     $results = OkapiServiceRunner::call('services/users/by_usernames', new OkapiInternalRequest($request->consumer, $request->token, array('usernames' => $username, 'fields' => $fields)));
     $result = $results[$username];
     if ($result == null) {
         throw new InvalidParam('username', "There is no user by this username.");
     }
     return Okapi::formatted_response($request, $result);
 }
开发者ID:4Vs,项目名称:oc-server3,代码行数:15,代码来源:by_username.php


示例19: call

 public static function call(OkapiRequest $request)
 {
     $methodnames = OkapiServiceRunner::$all_names;
     sort($methodnames);
     $cache_key = "api_ref/method_index#" . md5(implode("#", $methodnames));
     $results = Cache::get($cache_key);
     if ($results == null) {
         $results = array();
         foreach ($methodnames as $methodname) {
             $info = OkapiServiceRunner::call('services/apiref/method', new OkapiInternalRequest(new OkapiInternalConsumer(), null, array('name' => $methodname)));
             $results[] = array('name' => $info['name'], 'brief_description' => $info['brief_description']);
         }
         Cache::set($cache_key, $results, 3600);
     }
     return Okapi::formatted_response($request, $results);
 }
开发者ID:PaulinaKowalczuk,项目名称:oc-server3,代码行数:16,代码来源:method_index.php


示例20: call

 public static function call(OkapiRequest $request)
 {
     # Get current notes, and verify cache_code
     $cache_code = $request->get_parameter('cache_code');
     if ($cache_code == null) {
         throw new ParamMissing('cache_code');
     }
     $geocache = OkapiServiceRunner::call('services/caches/geocache', new OkapiInternalRequest($request->consumer, $request->token, array('cache_code' => $cache_code, 'fields' => 'my_notes|internal_id')));
     $current_value = $geocache['my_notes'];
     if ($current_value == null) {
         $current_value = "";
     }
     $cache_id = $geocache['internal_id'];
     # old_value
     $old_value = $request->get_parameter('old_value');
     if ($old_value === null) {
         $old_value = '';
     }
     # new_value (force "no HTML" policy).
     $new_value = $request->get_parameter('new_value');
     if ($new_value === null) {
         throw new ParamMissing('new_value');
     }
     # Force "no HTML" policy.
     $new_value = strip_tags($new_value);
     # Placeholders for returned values.
     $ret_saved_value = null;
     $ret_replaced = false;
     if (trim($current_value) == "" || self::str_equals($old_value, $current_value)) {
         /* REPLACE mode */
         $ret_replaced = true;
         if (trim($new_value) == "") {
             /* empty new value means delete */
             self::remove_notes($cache_id, $request->token->user_id);
             $ret_saved_value = null;
         } else {
             self::update_notes($cache_id, $request->token->user_id, $new_value);
             $ret_saved_value = $new_value;
         }
     } else {
         /* APPEND mode */
         $ret_saved_value = trim($current_value) . "\n\n" . trim($new_value);
         self::update_notes($cache_id, $request->token->user_id, $ret_saved_value);
     }
     $result = array('saved_value' => $ret_saved_value, 'replaced' => $ret_replaced);
     return Okapi::formatted_response($request, $result);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:47,代码来源:save_personal_notes.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP okapi\Settings类代码示例发布时间:2022-05-23
下一篇:
PHP okapi\Db类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap