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 = "******" . ($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; }
/** * 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; }
public static function call() { $token_key = isset($_GET['oauth_token']) ? $_GET['oauth_token'] : ''; $verifier = isset($_GET['oauth_verifier']) ? $_GET['oauth_verifier'] : ''; $langpref = isset($_GET['langpref']) ? $_GET['langpref'] : Settings::get('SITELANG'); $langprefs = explode("|", $langpref); $token = Db::select_row("\n select\n c.`key` as consumer_key,\n c.name as consumer_name,\n c.url as consumer_url,\n t.verifier\n from\n okapi_consumers c,\n okapi_tokens t\n where\n t.`key` = '" . mysql_real_escape_string($token_key) . "'\n and t.consumer_key = c.`key`\n "); if (!$token) { # Probably Request Token has expired or it was already used. We'll # just redirect to the Opencaching main page. return new OkapiRedirectResponse(Settings::get('SITE_URL')); } $vars = array('okapi_base_url' => Settings::get('SITE_URL') . "okapi/", 'token' => $token, 'verifier' => $verifier, 'site_name' => Okapi::get_normalized_site_name(), 'site_url' => Settings::get('SITE_URL'), 'site_logo' => Settings::get('SITE_LOGO')); $response = new OkapiHttpResponse(); $response->content_type = "text/html; charset=utf-8"; ob_start(); Okapi::gettext_domain_init($langprefs); include 'authorized.tpl.php'; $response->body = ob_get_clean(); Okapi::gettext_domain_restore(); return $response; }
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 = "******" . ($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(); Okapi::gettext_domain_restore(); return $response; } } # User granted access. Now we can authorize the Request Token. Db::execute("\n update okapi_tokens\n set user_id = '" . Db::escape_string($OC_user_id) . "'\n where `key` = '" . Db::escape_string($token_key) . "';\n "); # Redirect to the callback_url. if ($token['callback']) { return new OkapiRedirectResponse($token['callback'] . $callback_concat_char . "oauth_token=" . $token_key . "&oauth_verifier=" . $token['verifier']); } else { # Consumer did not provide a callback URL (probably the user is using a desktop # or mobile application). We'll just have to display the verifier to the user. return new OkapiRedirectResponse(Settings::get('SITE_URL') . "okapi/apps/authorized?oauth_token=" . $token_key . "&oauth_verifier=" . $token['verifier'] . "&langpref=" . $langpref); } }
/** * Generate a GPX file. * * @param OkapiRequest $request * @param integer $flags * @throws BadRequest * @return An array with GPX file content under 'gpx' key */ public static function create_gpx(OkapiRequest $request, $flags = null) { $vars = array(); # Validating arguments. We will also assign some of them to the # $vars variable which we will use later in the GPS template. $cache_codes = $request->get_parameter('cache_codes'); if ($cache_codes === null) { throw new ParamMissing('cache_codes'); } # Issue 106 requires us to allow empty list of cache codes to be passed into this method. # All of the queries below have to be ready for $cache_codes to be empty! $langpref = $request->get_parameter('langpref'); if (!$langpref) { $langpref = "en"; } $langpref .= "|" . Settings::get('SITELANG'); foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param) { $val = $request->get_parameter($param); if (!$val) { $val = "false"; } elseif (!in_array($val, array("true", "false"))) { throw new InvalidParam($param); } $vars[$param] = $val == "true"; } if ($vars['latest_logs'] && !$vars['ns_ground']) { throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions."); } $tmp = $request->get_parameter('my_notes'); $vars['my_notes'] = array(); if ($tmp && $tmp != 'none') { $tmp = explode('|', $tmp); foreach ($tmp as $elem) { if ($elem == 'none') { /* pass */ } elseif (in_array($elem, array('desc:text', 'gc:personal_note'))) { if (in_array('none', $tmp)) { throw new InvalidParam('my_notes', "You cannot mix 'none' and '{$elem}'"); } if ($request->token == null) { throw new BadRequest("Level 3 Authentication is required to access my_notes data."); } $vars['my_notes'][] = $elem; } else { throw new InvalidParam('my_notes', "Invalid list entry: '{$elem}'"); } } } $images = $request->get_parameter('images'); if (!$images) { $images = 'descrefs:nonspoilers'; } if (!in_array($images, array('none', 'descrefs:thumblinks', 'descrefs:nonspoilers', 'descrefs:all', 'ox:all'))) { throw new InvalidParam('images', "'{$images}'"); } $vars['images'] = $images; $tmp = $request->get_parameter('attrs'); if (!$tmp) { $tmp = 'desc:text'; } $tmp = explode("|", $tmp); $vars['attrs'] = array(); foreach ($tmp as $elem) { if ($elem == 'none') { /* pass */ } elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs', 'gc_ocde:attrs'))) { if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') { $vars['attrs'][] = 'gc:attrs'; } else { $vars['attrs'][] = $elem; } } else { throw new InvalidParam('attrs', "Invalid list entry: '{$elem}'"); } } $protection_areas = $request->get_parameter('protection_areas'); if (!$protection_areas || $protection_areas == 'desc:auto') { if (Settings::get('OC_BRANCH') == 'oc.de') { $protection_areas = 'desc:text'; } else { $protection_areas = 'none'; } } if (!in_array($protection_areas, array('none', 'desc:text'))) { throw new InvalidParam('protection_areas', "'{$protection_areas}'"); } $vars['protection_areas'] = $protection_areas; $tmp = $request->get_parameter('trackables'); if (!$tmp) { $tmp = 'none'; } if (!in_array($tmp, array('none', 'desc:list', 'desc:count'))) { throw new InvalidParam('trackables', "'{$tmp}'"); } $vars['trackables'] = $tmp; $tmp = $request->get_parameter('recommendations'); if (!$tmp) { $tmp = 'none'; } if (!in_array($tmp, array('none', 'desc:count'))) { throw new InvalidParam('recommendations', "'{$tmp}'"); } $vars['recommendations'] = $tmp; $lpc = $request->get_parameter('lpc'); if ($lpc === null) { $lpc = 10; } # will be checked in services/caches/geocaches call $user_uuid = $request->get_parameter('user_uuid'); # location_source (part 1 of 2) $location_source = $request->get_parameter('location_source'); if (!$location_source) { $location_source = 'default-coords'; } # Make sure location_source has prefix alt_wpt: if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) { throw new InvalidParam('location_source', '\'' . $location_source . '\''); } # Make sure we have sufficient authorization if ($location_source == 'alt_wpt:user-coords' && $request->token == null) { throw new BadRequest("Level 3 Authentication is required to access 'alt_wpt:user-coords'."); } # Which fields of the services/caches/geocaches method do we need? $fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize' . '|difficulty|terrain|description|hint2|rating|owner|url|internal_id' . '|protection_areas|short_description'; if ($vars['images'] != 'none') { $fields .= "|images"; } if (count($vars['attrs']) > 0) { $fields .= "|attrnames|attr_acodes"; } if ($vars['trackables'] == 'desc:list') { $fields .= "|trackables"; } elseif ($vars['trackables'] == 'desc:count') { $fields .= "|trackables_count"; } if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords') { $fields .= "|alt_wpts"; } if ($vars['recommendations'] != 'none') { $fields .= "|recommendations|founds"; } if (count($vars['my_notes']) > 0) { $fields .= "|my_notes"; } if ($vars['latest_logs']) { $fields .= "|latest_logs"; } if ($vars['mark_found']) { $fields .= "|is_found"; } $vars['caches'] = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest($request->consumer, $request->token, array('cache_codes' => $cache_codes, 'langpref' => $langpref, 'fields' => $fields, 'lpc' => $lpc, 'user_uuid' => $user_uuid, 'log_fields' => 'uuid|date|user|type|comment|internal_id|was_recommended'))); # Get rid of invalid cache references. $valid = array(); foreach ($vars['caches'] as $key => &$ref) { if ($ref !== null) { $valid[$key] =& $ref; } } $vars['caches'] =& $valid; unset($valid); # Get all the other data need. $vars['installation'] = OkapiServiceRunner::call('services/apisrv/installation', new OkapiInternalRequest(new OkapiInternalConsumer(), null, array())); $vars['cache_GPX_types'] = self::$cache_GPX_types; $vars['cache_GPX_sizes'] = self::$cache_GPX_sizes; if (count($vars['attrs']) > 0) { /* The user asked for some kind of attribute output. We'll fetch all * the data we MAY need. This is often far too much, but thanks to * caching, it will work fast. */ $vars['attr_index'] = OkapiServiceRunner::call('services/attrs/attribute_index', new OkapiInternalRequest($request->consumer, $request->token, array('only_locally_used' => 'true', 'langpref' => $langpref, 'fields' => 'name|gc_equivs'))); # prepare GS attribute data $vars['gc_attrs'] = in_array('gc:attrs', $vars['attrs']); $vars['gc_ocde_attrs'] = in_array('gc_ocde:attrs', $vars['attrs']); if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { if ($vars['gc_ocde_attrs']) { # As this is an OCDE compatibility feature, we use the same Pseudo-GS # attribute names here as OCDE. Note that this code is specific to OCDE # database; OCPL stores attribute names in a different way and may use # different names for equivalent attributes. $ocde_attrnames = Db::select_group_by('id', "\n select id, name\n from cache_attrib\n "); $attr_dict = AttrHelper::get_attrdict(); } foreach ($vars['caches'] as &$cache_ref) { $cache_ref['gc_attrs'] = array(); foreach ($cache_ref['attr_acodes'] as $acode) { $has_gc_equivs = false; foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) { # The assignment via GC-ID as array key will prohibit duplicate # GC attributes, which can result from # - assigning the same GC ID to multiple A-Codes, # - contradicting attributes in one OC listing, e.g. 24/4 + not 24/7. $cache_ref['gc_attrs'][$gc['id']] = $gc; $has_gc_equivs = true; } if (!$has_gc_equivs && $vars['gc_ocde_attrs']) { # Generate an OCDE pseudo-GS attribute; # see https://github.com/opencaching/okapi/issues/190 and # https://github.com/opencaching/okapi/issues/271. # # Groundspeak uses ID 1..65 (as of June, 2013), and OCDE makeshift # IDs start at 106, so there is space for 40 new GS attributes. $internal_id = $attr_dict[$acode]['internal_id']; $cache_ref['gc_attrs'][100 + $internal_id] = array('inc' => 1, 'name' => $ocde_attrnames[$internal_id][0]['name']); } } } } } /* 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('mysql_real_escape_string', array_keys($dict))) . "')\n "); while ($row = mysql_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'])); } break; } } } } # Do we need a GGZ index? if ($flags & self::FLAG_CREATE_GGZ_IDX) { # GGZ index consist of entries - one per each waypoint in the GPX file. # We will keep a list of all such entries here. $ggz_entries = array(); foreach ($vars['caches'] as &$cache_ref) { # Every $cache_ref will also be holding a reference to its entry. # Note, that more attributes are added while processing gpsfile.tpl.php! if (!isset($cache_ref['ggz_entry'])) { $cache_ref['ggz_entry'] = array(); } $ggz_entry =& $cache_ref['ggz_entry']; $ggz_entries[] =& $ggz_entry; $ggz_entry['code'] = $cache_ref['code']; $ggz_entry['name'] = isset($cache_ref['name_2']) ? $cache_ref['name_2'] : $cache_ref['name']; $ggz_entry['type'] = $vars['cache_GPX_types'][$cache_ref['type']]; list($lat, $lon) = explode("|", $cache_ref['location']); $ggz_entry['lat'] = $lat; $ggz_entry['lon'] = $lon; $ggz_entry['ratings'] = array(); $ratings_ref =& $ggz_entry['ratings']; if (isset($cache_ref['rating'])) { $ratings_ref['awesomeness'] = $cache_ref['rating']; } $ratings_ref['difficulty'] = $cache_ref['difficulty']; if (!isset($cache_ref['size'])) { $ratings_ref['size'] = 0; // Virtual, Event } else { if ($cache_ref['oxsize'] !== null) { // is this ox size one-to-one? $ratings_ref['size'] = $cache_ref['oxsize']; } } $ratings_ref['terrain'] = $cache_ref['terrain']; if ($vars['mark_found'] && $cache_ref['is_found']) { $ggz_entry['found'] = true; } # Additional waypoints. Currently, we're not 100% sure if their entries should # be included in the GGZ file (the format is undocumented). if (isset($cache_ref['alt_wpts'])) { $idx = 1; foreach ($cache_ref['alt_wpts'] as &$alt_wpt_ref) { if (!isset($alt_wpt_ref['ggz_entry'])) { $alt_wpt_ref['ggz_entry'] = array(); } $ggz_entry =& $alt_wpt_ref['ggz_entry']; $ggz_entries[] =& $ggz_entry; $ggz_entry['code'] = $cache_ref['code'] . '-' . $idx; $ggz_entry['name'] = $alt_wpt_ref['type_name']; $ggz_entry['type'] = $alt_wpt_ref['sym']; list($lat, $lon) = explode("|", $alt_wpt_ref['location']); $ggz_entry['lat'] = $lat; $ggz_entry['lon'] = $lon; $idx++; } } } } ob_start(); Okapi::gettext_domain_init(explode("|", $langpref)); # Consumer gets properly localized GPX file. include 'gpxfile.tpl.php'; Okapi::gettext_domain_restore(); $result = array('gpx' => ob_get_clean()); if ($flags & self::FLAG_CREATE_GGZ_IDX) { $result['ggz_entries'] = $ggz_entries; } return $result; }
/** * Return attribution note for the given geocache. * * The $lang parameter identifies the language of the cache description * to which the attribution note will be appended to (one cache may * have descriptions in multiple languages!). * * The $langpref parameter is *an array* of language preferences * extracted from the langpref parameter passed to the method by the * OKAPI Consumer. * * Both values ($lang and $langpref) will be taken into account when * generating the attribution note, but $lang will have a higher * priority than $langpref (we don't want to mix the languages in the * descriptions if we don't have to). * * $owner is in object describing the user, it has the same format as * defined in "geocache" method specs (see the "owner" field). * * The $type is either "full" or "static". Full attributions may contain * dates and are not suitable for the replicate module. Static attributions * don't change that frequently. */ public static function get_cache_attribution_note($cache_id, $lang, array $langpref, $owner, $type) { $site_url = Settings::get('SITE_URL'); $site_name = Okapi::get_normalized_site_name(); $cache_url = $site_url . "viewcache.php?cacheid={$cache_id}"; Okapi::gettext_domain_init(array_merge(array($lang), $langpref)); if (Settings::get('OC_BRANCH') == 'oc.pl') { # This does not vary on $type (yet). $note = sprintf(_("This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</a> site."), $cache_url, $site_url, $site_name); } else { # OC.de wants the tld in lowercase here $site_name = ucfirst(strtolower($site_name)); if ($type == 'full') { $note = sprintf(_("© <a href='%s'>%s</a>, <a href='%s'>%s</a>, " . "<a href='http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en'>CC-BY-NC-ND</a>, " . "as of %s; all log entries © their authors"), $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x')); } elseif ($type == 'static') { $note = sprintf(_("© <a href='%s'>%s</a>, <a href='%s'>%s</a>, " . "<a href='http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en'>CC-BY-NC-ND</a>; " . "all log entries © their authors"), $owner['profile_url'], $owner['username'], $cache_url, $site_name); } } Okapi::gettext_domain_restore(); return $note; }
public static function call(OkapiRequest $request) { # This is the "real" entry point. A wrapper for the _call method. $langpref = $request->get_parameter('langpref'); if (!$langpref) { $langpref = "en"; } # Error messages thrown via CannotPublishException exceptions should be localized. # They will be delivered for end user to display in his language. Okapi::gettext_domain_init(explode("|", $langpref)); try { # If appropriate, $success_message might be changed inside the _call. self::$success_message = _("Your cache log entry was posted successfully."); $log_uuid = self::_call($request); $result = array('success' => true, 'message' => self::$success_message, 'log_uuid' => $log_uuid); Okapi::gettext_domain_restore(); } catch (CannotPublishException $e) { Okapi::gettext_domain_restore(); $result = array('success' => false, 'message' => $e->getMessage(), 'log_uuid' => null); } return Okapi::formatted_response($request, $result); }
# cronjobs to be run before "okapi/update", for example before database # was installed). $allow_cronjobs = $uri != "update"; Okapi::init_internals($allow_cronjobs); # Checking for allowed patterns... try { foreach (OkapiUrls::$mapping as $pattern => $namespace) { $matches = null; if (preg_match("#{$pattern}#", $uri, $matches)) { # Pattern matched! Moving on to the proper View... array_shift($matches); require_once $GLOBALS['rootpath'] . "okapi/views/{$namespace}.php"; $response = call_user_func_array(array('\\okapi\\views\\' . str_replace('/', '\\', $namespace) . '\\View', 'call'), $matches); if ($response) { $response->display(); } return; } } } catch (Http404 $e) { /* pass */ } # None of the patterns matched OR method threw the Http404 exception. require_once $GLOBALS['rootpath'] . "okapi/views/http404.php"; $response = \okapi\views\http404\View::call(); $response->display(); } } Okapi::gettext_domain_init(); OkapiScriptEntryPointController::dispatch_request($_SERVER['REQUEST_URI']); Okapi::gettext_domain_restore();
public static function call(OkapiRequest $request) { # This is the "real" entry point. A wrapper for the _call method. $langpref = $request->get_parameter('langpref'); if (!$langpref) { $langpref = "en"; } Okapi::gettext_domain_init(explode("|", $langpref)); try { $position = self::_call($request); $result = array('success' => true, 'message' => _("Your log image has been updated."), 'position' => $position); Okapi::gettext_domain_restore(); } catch (CannotPublishException $e) { Okapi::gettext_domain_restore(); $result = array('success' => false, 'message' => $e->getMessage(), 'position' => null); } return Okapi::formatted_response($request, $result); }