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


PHP Db::fetch_assoc方法代码示例

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


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

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

示例2: 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 = '" . Db::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 = Db::fetch_assoc($rs)) {
         $vars['apps'][] = $row;
     }
     Db::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:kratenko,项目名称:oc-server3,代码行数:33,代码来源:index.php

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

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

示例5: 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('\\okapi\\Db::escape_string', $internal_ids)) . "')\n        ");
     $internalid2useruuid = array();
     while ($row = Db::fetch_assoc($rs)) {
         $internalid2useruuid[$row['user_id']] = $row['uuid'];
     }
     Db::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);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:36,代码来源:by_internal_ids.php

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

示例7: 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();
//.........这里部分代码省略.........
开发者ID:kratenko,项目名称:oc-server3,代码行数:101,代码来源:users.php

示例8: execute

 public function execute()
 {
     if (Okapi::get_var('db_version', 0) + 0 < 32) {
         return;
     }
     Db::execute("lock tables okapi_stats_hourly write, okapi_stats_temp write;");
     $rs = Db::query("\n            select\n                consumer_key,\n                user_id,\n                concat(substr(`datetime`, 1, 13), ':00:00') as period_start,\n                service_name,\n                calltype,\n                count(*) as calls,\n                sum(runtime) as runtime\n            from okapi_stats_temp\n            group by substr(`datetime`, 1, 13), consumer_key, user_id, service_name, calltype\n        ");
     while ($row = Db::fetch_assoc($rs)) {
         Db::execute("\n                insert into okapi_stats_hourly (consumer_key, user_id, period_start, service_name,\n                    total_calls, http_calls, total_runtime, http_runtime)\n                values (\n                    '" . Db::escape_string($row['consumer_key']) . "',\n                    '" . Db::escape_string($row['user_id']) . "',\n                    '" . Db::escape_string($row['period_start']) . "',\n                    '" . Db::escape_string($row['service_name']) . "',\n                    '" . Db::escape_string($row['calls']) . "',\n                    '" . Db::escape_string($row['calltype'] == 'http' ? $row['calls'] : 0) . "',\n                    '" . Db::escape_string($row['runtime']) . "',\n                    '" . Db::escape_string($row['calltype'] == 'http' ? $row['runtime'] : 0) . "'\n                )\n                on duplicate key update\n                    " . ($row['calltype'] == 'http' ? "\n                        http_calls = http_calls + '" . Db::escape_string($row['calls']) . "',\n                        http_runtime = http_runtime + '" . Db::escape_string($row['runtime']) . "',\n                    " : "") . "\n                    total_calls = total_calls + '" . Db::escape_string($row['calls']) . "',\n                    total_runtime = total_runtime + '" . Db::escape_string($row['runtime']) . "'\n            ");
     }
     Db::execute("delete from okapi_stats_temp;");
     Db::execute("unlock tables;");
 }
开发者ID:kirstenko,项目名称:oc-server3,代码行数:13,代码来源:cronjobs.php

示例9: call


//.........这里部分代码省略.........
                 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.wp_gc_maintained, 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                    c.listing_outdated, c.needs_maintenance,\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('\\okapi\\Db::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, '' as wp_gc_maintained, 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                    0 as listing_outdated, 0 as needs_maintenance,\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('\\okapi\\Db::escape_string', $cache_codes)) . "')\n                    and c.status in (1,2,3)\n            ");
     }
     $results = new ArrayObject();
     $cacheid2wptcode = array();
     $owner_ids = array();
     $outdated_listings = array();
     while ($row = Db::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':
                     $wp_gc = $row['wp_gc_maintained'] ? $row['wp_gc_maintained'] : $row['wp_gc'];
                     // 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*$/', $wp_gc)) {
                         $entry['gc_code'] = strtoupper(trim($wp_gc));
                     } else {
                         $entry['gc_code'] = null;
                     }
                     unset($wp_gc);
                     break;
                 case 'name':
                     $entry['name'] = $row['name'];
                     break;
                 case 'names':
                     $entry['names'] = array(Settings::get('SITELANG') => $row['name']);
                     break;
                     // for the future
                 // for the future
                 case 'location':
                     $entry['location'] = round($row['latitude'], 6) . "|" . round($row['longitude'], 6);
                     break;
                 case 'type':
                     $entry['type'] = Okapi::cache_type_id2name($row['type']);
                     break;
开发者ID:kratenko,项目名称:oc-server3,代码行数:67,代码来源:geocaches.php

示例10: call

 public static function call(OkapiRequest $request)
 {
     $log_uuids = $request->get_parameter('log_uuids');
     if ($log_uuids === null) {
         throw new ParamMissing('log_uuids');
     }
     if ($log_uuids === "") {
         $log_uuids = array();
     } else {
         $log_uuids = explode("|", $log_uuids);
     }
     if (count($log_uuids) > 500 && !$request->skip_limits) {
         throw new InvalidParam('log_uuids', "Maximum allowed number of referenced " . "log entries is 500. You provided " . count($log_uuids) . " UUIDs.");
     }
     if (count($log_uuids) != count(array_unique($log_uuids))) {
         throw new InvalidParam('log_uuids', "Duplicate UUIDs detected (make sure each UUID is referenced only once).");
     }
     $fields = $request->get_parameter('fields');
     if (!$fields) {
         $fields = "date|user|type|comment";
     }
     $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.");
         }
     }
     if (Settings::get('OC_BRANCH') == 'oc.de') {
         $teamentry_field = 'cl.oc_team_comment';
         $ratingdate_condition = 'and cr.rating_date=cl.date';
         $needs_maintenance_SQL = 'cl.needs_maintenance';
         $listing_is_outdated_SQL = 'cl.listing_outdated';
     } else {
         $teamentry_field = '(cl.type=12)';
         $ratingdate_condition = '';
         $needs_maintenance_SQL = 'IF(cl.type=5, 2, IF(cl.type=6, 1, 0))';
         $listing_is_outdated_SQL = '0';
     }
     $rs = Db::query("\n            select\n                cl.id, c.wp_oc as cache_code, cl.uuid, cl.type,\n                " . $teamentry_field . " as oc_team_entry,\n                " . $needs_maintenance_SQL . " as needs_maintenance2,\n                " . $listing_is_outdated_SQL . " as listing_is_outdated,\n                unix_timestamp(cl.date) as date, cl.text,\n                u.uuid as user_uuid, u.username, u.user_id,\n                if(cr.user_id is null, 0, 1) as was_recommended\n            from\n                (cache_logs cl,\n                user u,\n                caches c)\n                left join cache_rating cr\n                    on cr.user_id = u.user_id\n                    and cr.cache_id = c.cache_id\n                    " . $ratingdate_condition . "\n                    and cl.type in (\n                        " . Okapi::logtypename2id("Found it") . ",\n                        " . Okapi::logtypename2id("Attended") . "\n                    )\n            where\n                cl.uuid in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $log_uuids)) . "')\n                and " . (Settings::get('OC_BRANCH') == 'oc.pl' ? "cl.deleted = 0" : "true") . "\n                and cl.user_id = u.user_id\n                and c.cache_id = cl.cache_id\n                and c.status in (1,2,3)\n        ");
     $results = array();
     $log_id2uuid = array();
     /* Maps logs' internal_ids to uuids */
     $flag_options = array('null', 'false', 'true');
     while ($row = Db::fetch_assoc($rs)) {
         $results[$row['uuid']] = array('uuid' => $row['uuid'], 'cache_code' => $row['cache_code'], 'date' => date('c', $row['date']), 'user' => array('uuid' => $row['user_uuid'], 'username' => $row['username'], 'profile_url' => Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id']), 'type' => Okapi::logtypeid2name($row['type']), 'was_recommended' => $row['was_recommended'] ? true : false, 'needs_maintenance2' => $flag_options[$row['needs_maintenance2']], 'listing_is_outdated' => $flag_options[$row['listing_is_outdated']], 'oc_team_entry' => $row['oc_team_entry'] ? true : false, 'comment' => Okapi::fix_oc_html($row['text'], Okapi::OBJECT_TYPE_CACHE_LOG), 'images' => array(), 'internal_id' => $row['id']);
         $log_id2uuid[$row['id']] = $row['uuid'];
     }
     Db::free_result($rs);
     # fetch images
     if (in_array('images', $fields)) {
         # For OCPL log entry images, pictures.seq currently is always = 1,
         # while OCDE uses it for ordering the images.
         $rs = Db::query("\n                select object_id, uuid, url, title, spoiler\n                from pictures\n                where\n                    object_type = 1\n                    and object_id in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($log_id2uuid))) . "')\n                    and display = 1   /* currently is always 1 for logpix */\n                    and unknown_format = 0\n                order by seq, date_created\n            ");
         if (Settings::get('OC_BRANCH') == 'oc.de') {
             $object_type_param = 'type=1&';
         } else {
             $object_type_param = '';
         }
         while ($row = Db::fetch_assoc($rs)) {
             $results[$log_id2uuid[$row['object_id']]]['images'][] = array('uuid' => $row['uuid'], 'url' => $row['url'], 'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?' . $object_type_param . 'uuid=' . $row['uuid'], 'caption' => $row['title'], 'is_spoiler' => $row['spoiler'] ? true : false);
         }
         Db::free_result($rs);
     }
     # Check which UUIDs were not found and mark them with null.
     foreach ($log_uuids as $log_uuid) {
         if (!isset($results[$log_uuid])) {
             $results[$log_uuid] = null;
         }
     }
     # Remove unwanted fields.
     foreach (self::$valid_field_names as $field) {
         if (!in_array($field, $fields)) {
             foreach ($results as &$result_ref) {
                 unset($result_ref[$field]);
             }
         }
     }
     # Order the results in the same order as the input codes were given.
     $ordered_results = array();
     foreach ($log_uuids as $log_uuid) {
         $ordered_results[$log_uuid] = $results[$log_uuid];
     }
     return Okapi::formatted_response($request, $ordered_results);
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:84,代码来源:entries.php

示例11: 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 = Db::fetch_assoc($rs)) {
         $dict[$row['id']] = $row['en'];
     }
     return $dict;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:18,代码来源:attrlist.php

示例12: get_many

 /** Do 'get' on many keys at once. */
 public static function get_many($keys)
 {
     $dict = array();
     $rs = Db::query("\n            select `key`, value\n            from okapi_cache\n            where\n                `key` in ('" . implode("','", array_map('\\okapi\\Db::escape_string', $keys)) . "')\n                and expires > now()\n        ");
     while ($row = Db::fetch_assoc($rs)) {
         try {
             $dict[$row['key']] = unserialize(gzinflate($row['value']));
         } catch (ErrorException $e) {
             unset($dict[$row['key']]);
             Okapi::mail_admins("Debug: Unserialize error", "Could not unserialize key '" . $row['key'] . "' from Cache.\n" . "Probably something REALLY big was put there and data has been truncated.\n" . "Consider upgrading cache table to LONGBLOB.\n\n" . "Length of data, compressed: " . strlen($row['value']));
         }
     }
     if (count($dict) < count($keys)) {
         foreach ($keys as $key) {
             if (!isset($dict[$key])) {
                 $dict[$key] = null;
             }
         }
     }
     return $dict;
 }
开发者ID:kojoty,项目名称:opencaching-pl,代码行数:22,代码来源:core.php

示例13: _call

 /**
  * Append a new image to a log entry and return the image uuid and position.
  * Throws CannotPublishException or BadRequest on errors.
  */
 private static function _call(OkapiRequest $request)
 {
     require_once 'log_images_common.inc.php';
     # Developers! Please notice the fundamental difference between throwing
     # CannotPublishException and the "standard" BadRequest/InvalidParam
     # exceptions. You're reading the "_call" method now (see below for
     # "call").
     # validate the 'log_uuid' parameter
     $log_uuid = $request->get_parameter('log_uuid');
     if (!$log_uuid) {
         throw new ParamMissing('log_uuid');
     }
     $rs = Db::query("\n            select id, node, user_id\n            from cache_logs\n            where uuid = '" . Db::escape_string($log_uuid) . "'");
     $row = Db::fetch_assoc($rs);
     Db::free_result($rs);
     if (!$row) {
         throw new InvalidParam('log_uuid', "There is no log entry with uuid '" . $log_uuid . "'.");
     }
     if ($row['node'] != Settings::get('OC_NODE_ID')) {
         throw new Exception("This site's database contains the log entry '{$log_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('log_uuid', "The user of your access token is not the log entry's author.");
     }
     $log_internal_id = $row['id'];
     unset($row);
     # validate the 'caption', 'is_spoiler' and 'position' parameters
     $caption = $request->get_parameter('caption');
     if (!$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) {
         $is_spoiler = 'false';
     }
     if (!in_array($is_spoiler, array('true', 'false'))) {
         throw new InvalidParam('is_spoiler');
     }
     $position = LogImagesCommon::validate_position($request);
     # validate the 'image' parameter
     $base64_image = $request->get_parameter('image');
     if (!$base64_image) {
         throw new ParamMissing('image');
     }
     $estimated_decoded_size = strlen($base64_image) / 4 * 3 - 2;
     if ($estimated_decoded_size > Settings::get('IMAGE_MAX_UPLOAD_SIZE')) {
         $estimated_decoded_size_MB = round($estimated_decoded_size / 1024 / 1024, 1);
         $max_upload_size_MB = round(Settings::get('IMAGE_MAX_UPLOAD_SIZE') / 1024 / 1024, 1);
         throw new CannotPublishException(sprintf(_("Your image file is too large (%s.%s MB); %s accepts a maximum image size of %s.%s MB."), floor($estimated_decoded_size_MB), $estimated_decoded_size_MB * 10 % 10, Okapi::get_normalized_site_name(), floor($max_upload_size_MB), $max_upload_size_MB * 10 % 10));
     }
     $image = base64_decode($base64_image);
     if (!$image) {
         throw new InvalidParam('image', "bad base64 encoding");
     }
     try {
         $image_properties = getimagesizefromstring($image);
         # can throw
         if (!$image_properties) {
             throw new Exception();
         }
         list($width, $height, $image_type) = $image_properties;
         if (!in_array($image_type, array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF))) {
             # This will happen e.g. for BMP and XBM images, which are supported by GD.
             throw new Exception();
         }
     } catch (Exception $e) {
         # Note: There may be *subtypes* which are not accepted by the GD library.
         # About 1 of 2000 JPEGs at OC.de is not readable by the PHP functions,
         # though they can be displayed by web browsers.
         throw new CannotPublishException(sprintf(_("The uploaded image file is broken, or the image type is not accepted by %s. Allowed types are JPEG, PNG and GIF."), Okapi::get_normalized_site_name()));
     }
     unset($image_properties);
     if ($width * $height > self::max_pixels($base64_image)) {
         # This large image may crash the image processing functions.
         throw new CannotPublishException(sprintf(_("The uploaded image is too large (%s megapixels), please downscale it."), round($width * $height / 1024 / 1024)));
     }
     try {
         $image = imagecreatefromstring($image);
         # can throw
         if (!$image) {
             throw new Exception();
         }
     } catch (Exception $e) {
         throw new CannotPublishException(_("The uploaded image file is broken."));
     }
     # Now all supplied paramters are validated.
     # Do any postprocessing like scaling and rotating
     $image = self::postprocess_image($base64_image, $image, $image_type, $width, $height);
     unset($base64_image);
     # Save the image file. By saving it always from the $image object instead of
     # the original image data (even if not downscaled or rotated), we
     #   - strip JPEG EXIF information, which is intentional for privacy reasons,
     #   - eliminate any data flaws which have may been in the source files.
     $image_uuid = Okapi::create_uuid();
     $imagepath = Settings::get('IMAGES_DIR') . '/' . $image_uuid;
     switch ($image_type) {
//.........这里部分代码省略.........
开发者ID:kratenko,项目名称:oc-server3,代码行数:101,代码来源:add.php

示例14: get_chunk

 /**
  * Return changelog chunk, starting at $from, ending as $to.
  */
 public static function get_chunk($from, $to)
 {
     if ($to < $from) {
         return array();
     }
     if ($to - $from > self::$chunk_size) {
         throw new Exception("You should not get chunksize bigger than " . self::$chunk_size . " entries at one time.");
     }
     # Check if we already have this chunk in cache.
     $cache_key = 'clog_chunk#' . $from . '-' . $to;
     $chunk = Cache::get($cache_key);
     if ($chunk === null) {
         $rs = Db::query("\n                select id, data\n                from okapi_clog\n                where id between '" . Db::escape_string($from) . "' and '" . Db::escape_string($to) . "'\n                order by id\n            ");
         $chunk = array();
         while ($row = Db::fetch_assoc($rs)) {
             $chunk[] = unserialize(gzinflate($row['data']));
         }
         # Cache timeout depends on the chunk starting and ending point. Chunks
         # which start and end on the boundries of chunk_size should be cached
         # longer (they can be accessed even after 10 days). Other chunks won't
         # be ever accessed after the next revision appears, so there is not point
         # in storing them that long.
         if ($from % self::$chunk_size === 0 && $to % self::$chunk_size === 0) {
             $timeout = 10 * 86400;
         } else {
             $timeout = 86400;
         }
         Cache::set($cache_key, $chunk, $timeout);
     }
     return $chunk;
 }
开发者ID:kratenko,项目名称:oc-server3,代码行数:34,代码来源:replicate_common.inc.php

示例15: create_gpx


//.........这里部分代码省略.........
                     $cache_ref['gc_attrs']['42'] = array('inc' => 1, 'name' => 'Needs maintenance');
                 }
             }
         }
         # As the 'needs maintenance' flag is usually transported as attribute in
         # GPX files, we add it also to desc:text attribs.
         if (in_array('desc:text', $vars['attrs'])) {
             foreach ($vars['caches'] as &$cache_ref) {
                 if ($cache_ref['needs_maintenance']) {
                     $cache_ref['attrnames'][] = 'Needs maintenance';
                 }
             }
         }
     }
     /* OC sites always used internal user_ids in their generated GPX files.
      * This might be considered an error in itself (Groundspeak's XML namespace
      * doesn't allow that), but it very common (Garmin's OpenCaching.COM
      * also does that). Therefore, for backward-compatibility reasons, OKAPI
      * will do it the same way. See issue 174.
      *
      * Currently, the caches method does not expose "owner.internal_id" and
      * "latest_logs.user.internal_id" fields, we will read them manually
      * from the database here. */
     $dict = array();
     foreach ($vars['caches'] as &$cache_ref) {
         $dict[$cache_ref['owner']['uuid']] = true;
         if (isset($cache_ref['latest_logs'])) {
             foreach ($cache_ref['latest_logs'] as &$log_ref) {
                 $dict[$log_ref['user']['uuid']] = true;
             }
         }
     }
     $rs = Db::query("\n            select uuid, user_id\n            from user\n            where uuid in ('" . implode("','", array_map('\\okapi\\Db::escape_string', array_keys($dict))) . "')\n        ");
     while ($row = Db::fetch_assoc($rs)) {
         $dict[$row['uuid']] = $row['user_id'];
     }
     $vars['user_uuid_to_internal_id'] =& $dict;
     unset($dict);
     # location_source (part 2 of 2)
     if ($location_source != 'default-coords') {
         $location_change_prefix = $request->get_parameter('location_change_prefix');
         if (!$location_change_prefix) {
             $location_change_prefix = '# ';
         }
         # lets find requested coords
         foreach ($vars['caches'] as &$cache_ref) {
             foreach ($cache_ref['alt_wpts'] as $alt_wpt_key => $alt_wpt) {
                 if ('alt_wpt:' . $alt_wpt['type'] == $location_source) {
                     # Switch locations between primary wpt and alternate wpt.
                     # Also alter the cache name and make sure to append a proper
                     # notice.
                     $original_location = $cache_ref['location'];
                     $cache_ref['location'] = $alt_wpt['location'];
                     $cache_ref['name_2'] = $location_change_prefix . $cache_ref['name'];
                     if ($location_source == "alt_wpt:user-coords") {
                         # In case of "user-coords", replace the default warning with a custom-tailored one.
                         $cache_ref['warning_prefix'] = _("<b>Geocache coordinates have been changed.</b> They have been replaced with " . "your own custom coordinates which you have provided for this geocache.");
                     } else {
                         # Default warning
                         $cache_ref['warning_prefix'] = _("<b>Geocache coordinates have been changed.</b> Currently they " . "point to one of the alternate waypoints originally described as:") . " " . $alt_wpt['description'];
                     }
                     # remove current alt waypoint
                     unset($cache_ref['alt_wpts'][$alt_wpt_key]);
                     # add original location as alternate
                     if ($vars['alt_wpts']) {
                         $cache_ref['alt_wpts'][] = array('name' => $cache_ref['code'] . '-DEFAULT-COORDS', 'location' => $original_location, 'type' => 'default-coords', 'type_name' => _("Original geocache location"), 'sym' => 'Block, Blue', 'description' => sprintf(_("Original (owner-supplied) location of the %s geocache"), $cache_ref['code']));
开发者ID:kratenko,项目名称:oc-server3,代码行数:67,代码来源:gpx.php


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