/** * Initialize self::$SETTINGS. */ private static function load_settings() { try { # This is an external code and it MAY generate E_NOTICEs. # We have to temporarilly disable our default error handler. OkapiErrorHandler::disable(); require_once $GLOBALS['rootpath'] . "okapi_settings.php"; $ref = get_okapi_settings(); OkapiErrorHandler::reenable(); } catch (Exception $e) { throw new Exception("Could not import <rootpath>/okapi_settings.php:\n" . $e->getMessage()); } self::$SETTINGS = self::$DEFAULT_SETTINGS; foreach (self::$SETTINGS as $key => $_) { if (isset($ref[$key])) { self::$SETTINGS[$key] = $ref[$key]; } } self::verify(self::$SETTINGS); }
/** * Call OKAPI, parse response and display the results * @param array $params - params of the cache to search and display */ private function htmlFormat(array $params) { //call OKAPI $okapi_resp = \okapi\Facade::service_call('services/caches/shortcuts/search_and_retrieve', $this->user_id, $params); if (!is_a($okapi_resp, "ArrayObject")) { // strange OKAPI return !? error_log(__METHOD__ . ": ERROR: strange OKAPI response - not an ArrayObject"); exit(0); } \okapi\OkapiErrorHandler::disable(); if ($okapi_resp->count() == 0) { // no caches found exit(0); } // get the first object from the list $arrayCopy = $okapi_resp->getArrayCopy(); $geoCache = new \lib\Objects\GeoCache\GeoCache(array('okapiRow' => array_pop($arrayCopy))); //generate the results if ($this->screenWidth < 400) { tpl_set_tplname('map/map_cacheinfo_small'); } else { tpl_set_tplname('map/map_cacheinfo'); } tpl_set_var('cache_lat', $geoCache->getCoordinates()->getLatitude()); tpl_set_var('cache_lon', $geoCache->getCoordinates()->getLongitude()); tpl_set_var('cache_name', $geoCache->getCacheName()); tpl_set_var('cache_icon', $geoCache->getCacheIcon()); $is_event = $geoCache->getCacheType() == $geoCache::TYPE_EVENT ? '1' : '0'; // be aware: booleans not working here tpl_set_var('is_event', $is_event, false); $is_scored = $geoCache->getRatingId() != 0 && $geoCache->getRatingVotes() > 2 ? '1' : '0'; tpl_set_var('is_scored', $is_scored, false); tpl_set_var('rating_desc', tr($geoCache->getRatingDesc())); $is_recommended = $geoCache->getRecommendations() > 0 ? '1' : '0'; tpl_set_var('is_recommended', $is_recommended, false); tpl_set_var('cache_recommendations', $geoCache->getRecommendations(), false); tpl_set_var('cache_code', $geoCache->getWaypointId()); tpl_set_var('cache_founds', $geoCache->getFounds()); tpl_set_var('cache_not_founds', $geoCache->getNotFounds()); tpl_set_var('cache_rating_votes', $geoCache->getRatingVotes()); tpl_set_var('cache_willattends', $geoCache->getWillattends()); tpl_set_var('cache_url', $geoCache->getCacheUrl()); tpl_set_var('user_name', $geoCache->getOwner()->getUserName()); tpl_set_var('user_profile', $geoCache->getOwner()->getProfileUrl()); tpl_set_var('cache_size_desc', tr($geoCache->getSizeDesc())); $is_powertrail_part = $geoCache->isPowerTrailPart() ? '1' : '0'; tpl_set_var('is_powertrail_part', $is_powertrail_part, false); if ($geoCache->isPowerTrailPart()) { tpl_set_var('pt_name', $geoCache->getPowerTrail()->getName()); tpl_set_var('pt_image', $geoCache->getPowerTrail()->getImage()); tpl_set_var('pt_icon', $geoCache->getPowerTrail()->getFootIcon()); tpl_set_var('pt_url', $geoCache->getPowerTrail()->getPowerTrailUrl()); } $is_titled = $geoCache->isTitled() ? 'true' : 'false'; tpl_set_var('is_titled', $is_titled, false); //tpl_set_var('is_titled', $geoCache->isTitled(), false); // make the template and send it out tpl_BuildTemplate(false, false, true); }
use Exception; use okapi\Okapi; use okapi\Settings; use okapi\views\menu\OkapiMenu; # # All HTTP requests within the /okapi/ path are redirected through this # controller. From here we'll pass them to the right entry point (or # display an appropriate error message). # # To learn more about OKAPI, see core.php. # $GLOBALS['rootpath'] = '../'; # this is for OC-code compatibility require_once $GLOBALS['rootpath'] . 'okapi/core.php'; OkapiErrorHandler::$treat_notices_as_errors = true; require_once $GLOBALS['rootpath'] . 'okapi/urls.php'; if (ob_list_handlers() == array('default output handler')) { # We will assume that this one comes from "output_buffering" being turned on # in PHP config. This is very common and probably is good for most other OC # pages. But we don't need it in OKAPI. We will just turn this off. ob_end_clean(); } class OkapiScriptEntryPointController { public static function dispatch_request($uri) { # Chop off the ?args=... part. if (strpos($uri, '?') !== false) { $uri = substr($uri, 0, strpos($uri, '?')); }
/** * If you disabled OKAPI's error handling with disable_error_handling, * you may reenable it with this method. */ public static function reenable_error_handling() { OkapiErrorHandler::reenable(); }
if ($_GET['h_own'] == "true") { $params['exclude_my_own'] = "true"; } # h_found, h_noattempt - convert to OKAPI's "found_status" parameter. $h_found = $_GET['h_found'] == "true"; $h_noattempt = $_GET['h_noattempt'] == "true"; if ($h_found && !$h_noattempt) { $params['found_status'] = "notfound_only"; } elseif (!$h_found && $h_noattempt) { $params['found_status'] = "found_only"; } elseif (!$h_found && !$h_noattempt) { $params['found_status'] = "either"; } else { $force_result_empty = true; } } # # We have all the parameters. Note, that some mapper-compatible parameter sets # always render empty results. We will just exit, without producing any image # whatsoever. # if ($force_result_empty) { die; } if (!$user_id) { die; } # End of "buggy" code. Re-enable OKAPI's error handler. \okapi\OkapiErrorHandler::reenable(); # Get OKAPI's response and display it. Add proper Cache-Control headers. \okapi\Facade::service_display('services/caches/map/tile', $user_id, $params);