function getWaypoints($cacheid) { global $waypointline; global $waypointlines; global $nowaypoints; $wphandler = new HandlerChildWp(); $waypoints = $wphandler->getChildWps($cacheid); $ret = ''; if (!empty($waypoints)) { $formatter = new FormatterCoordinate(); foreach ($waypoints as $waypoint) { $tmpline = $waypointline; $tmpline = mb_ereg_replace('{wp_image}', htmlspecialchars($waypoint['image'], ENT_COMPAT, 'UTF-8'), $tmpline); $tmpline = mb_ereg_replace('{wp_type}', htmlspecialchars($waypoint['name'], ENT_COMPAT, 'UTF-8'), $tmpline); $htmlcoordinate = $formatter->formatHtml($waypoint['coordinate'], '</td></tr><tr><td style="white-space:nowrap">'); $tmpline = mb_ereg_replace('{wp_coordinate}', $htmlcoordinate, $tmpline); $tmpline = mb_ereg_replace('{wp_description}', htmlspecialchars(trim($waypoint['description']), ENT_COMPAT, 'UTF-8'), $tmpline); $tmpline = mb_ereg_replace('{wp_show_description}', mb_ereg_replace('\\r\\n', '<br />', htmlspecialchars($waypoint['description'], ENT_COMPAT, 'UTF-8')), $tmpline); $tmpline = mb_ereg_replace('{cacheid}', htmlspecialchars($cacheid, ENT_COMPAT, 'UTF-8'), $tmpline); $tmpline = mb_ereg_replace('{childid}', htmlspecialchars($waypoint['childid'], ENT_COMPAT, 'UTF-8'), $tmpline); $ret .= $tmpline; } $ret = mb_ereg_replace('{lines}', $ret, $waypointlines); return $ret; } return $nowaypoints; }
function getChildWaypoints($cacheid) { $wphandler = new HandlerChildWp(); $waypoints = $wphandler->getChildWps($cacheid); $count = count($waypoints); if ($count > 0) { $formatter = new FormatterCoordinate(); for ($i = 0; $i < $count; $i++) { $waypoints[$i]['coord']['lat'] = $waypoints[$i]['coordinate']->latitude(); $waypoints[$i]['coord']['lon'] = $waypoints[$i]['coordinate']->longitude(); $waypoints[$i]['coordinateHtml'] = $formatter->formatHtml($waypoints[$i]['coordinate'], '<br />'); $waypoints[$i]['description'] = trim($waypoints[$i]['description']); $waypoints[$i]['position'] = $i + 1; } } return $waypoints; }
function output_cachexml($sWaypoint) { global $opt, $login; $rsCache = sql_slave("SELECT `caches`.`cache_id`, `caches`.`name`, `caches`.`wp_oc`, `caches`.`cache_id`, `caches`.`type`,\n `caches`.`longitude`, `caches`.`latitude`,\n `caches`.`status`>1 AS `inactive`,\n IFNULL(`trans_status_text`.`text`, `cache_status`.`name`) AS `statustext`,\n IFNULL(`trans_type_text`.`text`, `cache_type`.`en`) AS `type_text`, `cache_type`.`id` AS `type_id`,\n IFNULL(`trans_size_text`.`text`, `cache_size`.`name`) AS `size`,\n `caches`.`difficulty`, `caches`.`terrain`,\n `caches`.`date_created`, `caches`.`is_publishdate`,\n IFNULL(`stat_caches`.`toprating`, 0) AS `toprating`,\n IF(`caches`.`user_id`='&1', 1, 0) AS `owner`,\n `user`.`username`, `user`.`user_id`,\n IF(`caches_attributes`.`attrib_id` IS NULL, 0, 1) AS `oconly`,\n IFNULL(`pictures`.`url`,'') AS `picurl`,\n IFNULL(`pictures`.`title`,'') AS `pictitle`\n FROM `caches`\n INNER JOIN `cache_type` ON `caches`.`type`=`cache_type`.`id`\n INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id`\n INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`\n INNER JOIN `cache_size` ON `caches`.`size`=`cache_size`.`id`\n LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`\n LEFT JOIN `sys_trans` AS `trans_status` ON `cache_status`.`trans_id`=`trans_status`.`id` AND `cache_status`.`name`=`trans_status`.`text`\n LEFT JOIN `sys_trans_text` AS `trans_status_text` ON `trans_status`.`id`=`trans_status_text`.`trans_id` AND `trans_status_text`.`lang`='&2'\n LEFT JOIN `sys_trans` AS `trans_type` ON `cache_type`.`trans_id`=`trans_type`.`id` AND `cache_type`.`name`=`trans_type`.`text`\n LEFT JOIN `sys_trans_text` AS `trans_type_text` ON `trans_type`.`id`=`trans_type_text`.`trans_id` AND `trans_type_text`.`lang`='&2'\n LEFT JOIN `sys_trans` AS `trans_size` ON `cache_size`.`trans_id`=`trans_size`.`id` AND `cache_size`.`name`=`trans_size`.`text`\n LEFT JOIN `sys_trans_text` AS `trans_size_text` ON `trans_size`.`id`=`trans_size_text`.`trans_id` AND `trans_size_text`.`lang`='&2'\n LEFT JOIN `caches_attributes` ON `caches_attributes`.`cache_id`=`caches`.`cache_id` AND `caches_attributes`.`attrib_id`=6\n LEFT JOIN `pictures` ON `pictures`.`object_id`=`caches`.`cache_id` AND `pictures`.`object_type`='&4' AND `pictures`.`mappreview`=1\n WHERE (`caches`.`wp_oc`='&3' OR (`caches`.`wp_oc`!='&3' AND `caches`.`wp_gc_maintained`='&3')) AND\n (`cache_status`.`allow_user_view`=1 OR `caches`.`user_id`='&1')\n LIMIT 1", $login->userid, $opt['template']['locale'], $sWaypoint, OBJECT_CACHE); $rCache = sql_fetch_assoc($rsCache); sql_free_result($rsCache); if ($rCache === false) { echo '<caches></caches>'; exit; } $nGeokretyCount = sql_value_slave("SELECT COUNT(*) FROM `gk_item_waypoint` WHERE `wp`='&1'", 0, $sWaypoint); $nNotFoundCount = $nAttendedCount = 0; $nFoundCount = sql_value_slave("SELECT COUNT(*) FROM `cache_logs` WHERE `user_id`='&1' AND `cache_id`='&2' AND `type`=1", 0, $login->userid, $rCache['cache_id']); if ($nFoundCount == 0) { $nNotFoundCount = sql_value_slave("SELECT COUNT(*) FROM `cache_logs`\n WHERE `user_id`='&1' AND `cache_id`='&2' AND `type`=2", 0, $login->userid, $rCache['cache_id']); } if ($rCache['type'] == 6) { $nAttendedCount = sql_value_slave("SELECT COUNT(*)\n FROM `cache_logs`\n WHERE `user_id`='&1'\n AND `cache_id`='&2'\n AND `type`=7", 0, $login->userid, $rCache['cache_id']); } $wphandler = new HandlerChildWp(); $waypoints = $wphandler->getChildWps($rCache['cache_id'], true); echo '<caches>' . "\n"; echo ' <cache '; echo 'name="' . xmlentities($rCache['name']) . '" '; echo 'wpoc="' . xmlentities($rCache['wp_oc']) . '" '; echo 'coords="' . $rCache['longitude'] . ',' . $rCache['latitude'] . '" '; echo 'inactive="' . xmlentities($rCache['inactive']) . '" '; echo 'status_text="' . xmlentities($rCache['statustext']) . '" '; echo 'type_id="' . xmlentities($rCache['type_id']) . '" '; echo 'type_text="' . xmlentities($rCache['type_text']) . '" '; echo 'size="' . xmlentities($rCache['size']) . '" '; echo 'difficulty="' . xmlentities($rCache['difficulty'] / 2) . '" '; echo 'terrain="' . xmlentities($rCache['terrain'] / 2) . '" '; echo 'listed_since="' . xmlentities(strftime($opt['locale'][$opt['template']['locale']]['format']['date'], strtotime($rCache['date_created']))) . '" '; echo 'is_publishdate="' . xmlentities($rCache['is_publishdate']) . '" '; echo 'toprating="' . xmlentities($rCache['toprating']) . '" '; echo 'geokreties="' . xmlentities($nGeokretyCount) . '" '; echo 'found="' . xmlentities($nFoundCount > 0 ? 1 : 0) . '" '; echo 'notfound="' . xmlentities($nNotFoundCount > 0 ? 1 : 0) . '" '; echo 'attended="' . xmlentities($nAttendedCount > 0 ? 1 : 0) . '" '; echo 'oconly="' . xmlentities($rCache['oconly']) . '" '; echo 'owner="' . xmlentities($rCache['owner']) . '" '; echo 'username="******" '; echo 'userid="' . xmlentities($rCache['user_id']) . '" '; echo 'picurl="' . xmlentities($rCache['picurl']) . '" '; echo 'pictitle="' . xmlentities(trim($rCache['pictitle'])) . '" >\\n'; foreach ($waypoints as $waypoint) { echo ' <wpt '; echo 'typeid="' . xmlentities($waypoint['type']) . '" '; echo 'typename="' . xmlentities($waypoint['name']) . '" '; echo 'typepreposition="' . xmlentities($waypoint['preposition']) . '" '; echo 'image="' . xmlentities($waypoint['image']) . '" '; echo 'imagewidth="38" imageheight="38" '; echo 'latitude="' . xmlentities($waypoint['latitude']) . '" '; echo 'longitude="' . xmlentities($waypoint['longitude']) . '" '; echo 'description="' . xmlentities(mb_ereg_replace('\\r\\n', '<br />', htmlentities(trim($waypoint['description']), ENT_NOQUOTES, 'UTF-8'))) . '" />\\n'; } echo ' </cache>\\n'; echo '</caches>'; exit; }
function search_output() { global $opt, $login, $translate; global $cache_note_text; $server_domain = $opt['page']['domain']; $server_address = $opt['page']['default_absolute_url']; $server_name = $opt['page']['sitename']; $gpxHead = '<?xml version="1.0" encoding="utf-8"?> <gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" creator="' . $server_name . ' - ' . $server_address . '" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd" xmlns="http://www.topografix.com/GPX/1/0"> <name>Cache listing generated from ' . $server_name . '</name> <desc>This is a waypoint file generated from ' . $server_name . '{wpchildren}</desc> <author>Opencaching.de</author> <email>' . text_xmlentities($opt['mail']['contact']) . '</email> <url>' . $server_domain . '</url> <urlname>' . $opt['page']['slogan'] . '</urlname> <time>{time}</time> <keywords>cache, geocache, opencaching, waypoint</keywords> '; $gpxLine = ' <wpt lat="{lat}" lon="{lon}"> <time>{time}</time> <name>{waypoint}</name> <desc>{cachename}</desc> <src>' . $server_domain . '</src> <url>' . $server_address . 'viewcache.php?cacheid={cacheid}</url> <urlname>{cachename}</urlname> <sym>{sym}</sym> <type>Geocache|{type}</type> <groundspeak:cache id="{cacheid}" {status} xmlns:groundspeak="http://www.groundspeak.com/cache/1/0/1"> <groundspeak:name>{cachename}</groundspeak:name> <groundspeak:placed_by>{owner}</groundspeak:placed_by> <groundspeak:owner id="{userid}">{owner}</groundspeak:owner> <groundspeak:type>{type}</groundspeak:type> <groundspeak:container>{container}</groundspeak:container> <groundspeak:attributes> {attributes} </groundspeak:attributes> <groundspeak:difficulty>{difficulty}</groundspeak:difficulty> <groundspeak:terrain>{terrain}</groundspeak:terrain> <groundspeak:country>{country}</groundspeak:country> <groundspeak:state>{state}</groundspeak:state> <groundspeak:short_description html="True">{shortdesc}</groundspeak:short_description> <groundspeak:long_description html="True">{desc}<br />{images}</groundspeak:long_description> {hints} <groundspeak:logs> {logs} </groundspeak:logs> <groundspeak:travelbugs> {geokrety} </groundspeak:travelbugs> </groundspeak:cache> </wpt> {cache_waypoints}'; /* Ocprop: * <wpt\s+lat=\"([0-9\-\+\.]+)\"\s+lon=\"([0-9\-\+\.]+)\"> * <time>(.*?)<\/time> * (Date: ^([0-9]{4})\-([0-9]{2})\-([0-9]{2})T[0-9\:\-\.]+(Z)?$/s) * <name>(.*?)<\/name> * <url>http:\/\/www\.opencaching\.de\/viewcache\.php\?cacheid=([0-9]+)<\/url> * <sym>(.*?)<\/sym> * <groundspeak:cache\s+id=\"[0-9]+\"\s+available=\"(True|False)\"\s+archived=\"(True|False)\" * <groundspeak:name>(.*?)<\/groundspeak:name> * <groundspeak:placed_by>(.*?)<\/groundspeak:placed_by> * <groundspeak:owner id="([0-9])+">(.*?)<\/groundspeak:owner> * <groundspeak:type>(.*?)<\/groundspeak:type> * <groundspeak:container>(.*?)<\/groundspeak:container> * <groundspeak:difficulty>(.*?)<\/groundspeak:difficulty> * <groundspeak:terrain>(.*?)<\/groundspeak:terrain> * <groundspeak:country>(.*?)<\/groundspeak:country> * <groundspeak:state>(.*?)<\/groundspeak:state> * <groundspeak:short_description html="(.*?)".*?>(.*?)<\/groundspeak:short_description> * <groundspeak:long_description html="(.*?)".*?>(.*?)<\/groundspeak:long_description> * <groundspeak:encoded_hints>(.*?)<\/groundspeak:encoded_hints> */ $gpxAttributes = ' <groundspeak:attribute id="{attrib_id}" inc="{attrib_inc}">{attrib_name}</groundspeak:attribute>'; $gpxLog = ' <groundspeak:log id="{id}"> <groundspeak:date>{date}</groundspeak:date> <groundspeak:type>{type}</groundspeak:type> <groundspeak:finder id="{userid}">{username}</groundspeak:finder> <groundspeak:text encoded="False">{text}</groundspeak:text> </groundspeak:log>'; $gpxGeokrety = ' <groundspeak:travelbug id="{gkid}" ref="{gkref}"> <groundspeak:name>{gkname}</groundspeak:name> </groundspeak:travelbug>'; $gpxWaypoints = ' <wpt lat="{wp_lat}" lon="{wp_lon}"> <time>{time}</time> <name>{name}</name> <cmt>{comment}</cmt> <desc>{desc}</desc> <url>' . $server_address . 'viewcache.php?cacheid={cacheid}</url> <urlname>{parent} {cachename}</urlname> <sym>{type}</sym> <type>Waypoint|{type}</type> <gsak:wptExtension xmlns:gsak="http://www.gsak.net/xmlv1/4"> <gsak:Parent>{parent}</gsak:Parent> </gsak:wptExtension> </wpt> '; $gpxFoot = '</gpx>'; $gpxTimeFormat = 'Y-m-d\\TH:i:s\\Z'; $gpxStatus[0] = 'available="False" archived="False"'; // other (unavailable, not archived) $gpxStatus[1] = 'available="True" archived="False"'; //available, not archived $gpxStatus[2] = 'available="False" archived="False"'; //unavailable, not archived $gpxStatus[3] = 'available="False" archived="True"'; //unavailable, archived $gpxStatus[6] = 'available="False" archived="True"'; //locked, visible $gpxContainer[0] = 'Other'; $gpxContainer[2] = 'Micro'; $gpxContainer[3] = 'Small'; $gpxContainer[4] = 'Regular'; $gpxContainer[5] = 'Large'; $gpxContainer[6] = 'Large'; $gpxContainer[7] = 'Virtual'; $gpxContainer[8] = 'Micro'; // cache types known by gpx $gpxType[0] = 'Unknown Cache'; $gpxType[2] = 'Traditional Cache'; $gpxType[3] = 'Multi-cache'; $gpxType[4] = 'Virtual Cache'; $gpxType[5] = 'Webcam Cache'; $gpxType[6] = 'Event Cache'; // unknown ... converted $gpxType[7] = 'Unknown Cache'; $gpxType[8] = 'Unknown Cache'; $gpxType[10] = 'Traditional Cache'; $gpxLogType[0] = 'Other'; $gpxLogType[1] = 'Found it'; $gpxLogType[2] = 'Didn\'t find it'; $gpxLogType[3] = 'Write note'; $gpxLogType[7] = 'Attended'; $gpxLogType[8] = 'Will attend'; $gpxLogType[9] = 'Archive'; $gpxLogType[10] = 'Owner Maintenance'; $gpxLogType[11] = 'Temporarily Disable Listing'; $gpxLogType[13] = 'Archive'; $gpxLogType[14] = 'Archive'; $gpxSymNormal = 'Geocache'; $gpxSymFound = 'Geocache Found'; $childwphandler = new HandlerChildWp(); $children = ''; $rs = sql('SELECT &searchtmp.`cache_id` `cacheid` FROM &searchtmp'); while ($r = sql_fetch_array($rs)) { if (count($childwphandler->getChildWps($r['cacheid']))) { $children = ' (HasChildren)'; break; } } mysql_free_result($rs); $gpxHead = mb_ereg_replace('{wpchildren}', $children, $gpxHead); $gpxHead = mb_ereg_replace('{time}', date($gpxTimeFormat, time()), $gpxHead); append_output($gpxHead); $user_id = $login->userid; $rs = sql_slave("SELECT SQL_BUFFER_RESULT\n &searchtmp.`cache_id` `cacheid`,\n &searchtmp.`longitude` `longitude`,\n &searchtmp.`latitude` `latitude`,\n `caches`.`wp_oc` `waypoint`,\n `caches`.`date_hidden` `date_hidden`,\n `caches`.`name` `name`,\n `caches`.`country` `country`,\n `caches`.`terrain` `terrain`,\n `caches`.`difficulty` `difficulty`,\n `caches`.`desc_languages` `desc_languages`,\n `caches`.`size` `size`,\n `caches`.`type` `type`,\n `caches`.`status` `status`,\n `caches`.`user_id` `userid`,\n `caches`.`needs_maintenance`,\n `caches`.`listing_outdated`,\n `countries`.`name` AS `country_name`,\n `cache_location`.`adm2` `state`,\n `cache_desc`.`desc` `desc`,\n `cache_desc`.`short_desc` `short_desc`,\n `cache_desc`.`hint` `hint`,\n `cache_desc`.`language` `desc_language`,\n `user`.`username` `username`,\n `user`.`data_license`,\n IFNULL(`stat_cache_logs`.`found`, 0) `found`\n FROM &searchtmp\n INNER JOIN `caches` ON &searchtmp.`cache_id`=`caches`.`cache_id`\n INNER JOIN `countries` ON `caches`.`country`=`countries`.`short`\n INNER JOIN `user` ON &searchtmp.`user_id`=`user`.`user_id`\n INNER JOIN `cache_desc`\n ON `caches`.`cache_id`=`cache_desc`.`cache_id`\n AND `caches`.`default_desclang`=`cache_desc`.`language`\n LEFT JOIN `cache_location` ON &searchtmp.`cache_id`=`cache_location`.`cache_id`\n LEFT JOIN `stat_cache_logs`\n ON &searchtmp.`cache_id`=`stat_cache_logs`.`cache_id`\n AND `stat_cache_logs`.`user_id`='&1'", $user_id); while ($r = sql_fetch_array($rs)) { if (strlen($r['desc_languages']) > 2) { $r = get_locale_desc($r); } $thisline = $gpxLine; $lat = sprintf('%01.5f', $r['latitude']); $thisline = mb_ereg_replace('{lat}', $lat, $thisline); $lon = sprintf('%01.5f', $r['longitude']); $thisline = mb_ereg_replace('{lon}', $lon, $thisline); $time = date($gpxTimeFormat, strtotime($r['date_hidden'])); $thisline = mb_ereg_replace('{time}', $time, $thisline); $thisline = mb_ereg_replace('{waypoint}', $r['waypoint'], $thisline); $thisline = mb_ereg_replace('{cacheid}', $r['cacheid'], $thisline); $thisline = mb_ereg_replace('{cachename}', text_xmlentities($r['name']), $thisline); $thisline = mb_ereg_replace('{country}', text_xmlentities($r['country_name']), $thisline); $thisline = mb_ereg_replace('{state}', text_xmlentities($r['state']), $thisline); if ($r['hint'] == '') { $thisline = mb_ereg_replace('{hints}', '', $thisline); } else { // Ocprop: <groundspeak:encoded_hints>(.*?)<\/groundspeak:encoded_hints> $hint = html_entity_decode(strip_tags($r['hint']), ENT_COMPAT, "UTF-8"); $thisline = mb_ereg_replace('{hints}', ' <groundspeak:encoded_hints>' . text_xmlentities($hint) . '</groundspeak:encoded_hints>', $thisline); } $thisline = mb_ereg_replace('{shortdesc}', text_xmlentities($r['short_desc']), $thisline); $desc = $r['desc']; $desc = str_replace(' src="images/uploads/', ' src="' . $server_address . 'images/uploads/', $desc); if ($r['listing_outdated']) { $desc = "<p style='color:#c00000'><strong>" . $translate->t('This geocache description may be outdated.', '', basename(__FILE__), __LINE__) . '</strong> ' . $translate->t('See the log entries for more information.', '', basename(__FILE__), __LINE__) . "</p>\n" . $desc; } $license = getLicenseDisclaimer($r['userid'], $r['username'], $r['data_license'], $r['cacheid'], $opt['template']['locale'], true, true); if ($license != "") { $desc .= "<p><em>{$license}</em></p>\n"; } $desc .= get_desc_npas($r['cacheid']); $thisline = mb_ereg_replace('{desc}', text_xmlentities(decodeEntities($desc)), $thisline); $thisline = mb_ereg_replace('{images}', text_xmlentities(getPictures($r['cacheid'], $server_address)), $thisline); if (isset($gpxType[$r['type']])) { $thisline = mb_ereg_replace('{type}', $gpxType[$r['type']], $thisline); } else { $thisline = mb_ereg_replace('{type}', $gpxType[0], $thisline); } if (isset($gpxContainer[$r['size']])) { $thisline = mb_ereg_replace('{container}', $gpxContainer[$r['size']], $thisline); } else { $thisline = mb_ereg_replace('{container}', $gpxContainer[0], $thisline); } if (isset($gpxStatus[$r['status']])) { $thisline = mb_ereg_replace('{status}', $gpxStatus[$r['status']], $thisline); } else { $thisline = mb_ereg_replace('{status}', $gpxStatus[0], $thisline); } $sDiffDecimals = ''; if ($r['difficulty'] % 2) { $sDiffDecimals = '.5'; } $r['difficulty'] -= $r['difficulty'] % 2; $thisline = mb_ereg_replace('{difficulty}', $r['difficulty'] / 2 . $sDiffDecimals, $thisline); $sTerrDecimals = ''; if ($r['terrain'] % 2) { $sTerrDecimals = '.5'; } $r['terrain'] -= $r['terrain'] % 2; $thisline = mb_ereg_replace('{terrain}', $r['terrain'] / 2 . $sTerrDecimals, $thisline); $thisline = mb_ereg_replace('{owner}', text_xmlentities($r['username']), $thisline); $thisline = mb_ereg_replace('{userid}', $r['userid'], $thisline); if ($r['found'] > 0) { $thisline = mb_ereg_replace('{sym}', text_xmlentities($gpxSymFound), $thisline); } else { $thisline = mb_ereg_replace('{sym}', text_xmlentities($gpxSymNormal), $thisline); } // clear cache specific data $logentries = ''; $cacheNote = false; $attribentries = ''; $waypoints = ''; $gkentries = ''; // insert personal note if ($user_id != 0) { $cacheNote = getCacheNote($user_id, $r['cacheid']); if ($cacheNote) { $thislog = $gpxLog; $thislog = mb_ereg_replace('{id}', 0, $thislog); $thislog = mb_ereg_replace('{date}', date($gpxTimeFormat), $thislog); $thislog = mb_ereg_replace('{userid}', $user_id, $thislog); $thislog = mb_ereg_replace('{username}', text_xmlentities($login->username), $thislog); $thislog = mb_ereg_replace('{type}', $gpxLogType[3], $thislog); $thislog = mb_ereg_replace('{text}', text_xmlentities($cacheNote['note']), $thislog); $logentries .= $thislog . "\n"; } } // fetch all logs of the current user, then the last 20 other logs for ($currentuser = $user_id != 0 ? 1 : 0; $currentuser >= 0; --$currentuser) { if ($currentuser) { $user_operator = '='; $limit = ''; } else { $user_operator = '!='; $limit = ' LIMIT 20'; } $rsLogs = sql_slave("\n SELECT\n `cache_logs`.`id`,\n `cache_logs`.`type`,\n `cache_logs`.`date`,\n `cache_logs`.`text`,\n `cache_logs`.`needs_maintenance`,\n `cache_logs`.`listing_outdated`,\n `user`.`username`,\n `user`.`user_id`\n FROM\n `cache_logs`,\n `user`\n WHERE\n `cache_logs`.`user_id`=`user`.`user_id` AND\n `cache_logs`.`cache_id`='&1' AND\n `user`.`user_id`" . $user_operator . "'&2'\n ORDER BY\n `cache_logs`.`order_date` DESC,\n `cache_logs`.`date_created` DESC,\n `cache_logs`.`id` DESC" . $limit, $r['cacheid'], $user_id); while ($rLog = sql_fetch_array($rsLogs)) { $thislog = $gpxLog; $thislog = mb_ereg_replace('{id}', $rLog['id'], $thislog); $thislog = mb_ereg_replace('{date}', date($gpxTimeFormat, strtotime($rLog['date'])), $thislog); $thislog = mb_ereg_replace('{userid}', $rLog['user_id'], $thislog); $thislog = mb_ereg_replace('{username}', text_xmlentities($rLog['username']), $thislog); if ($rLog['type'] == 3 && $rLog['needs_maintenance'] == 2) { $logtype = 'Needs Maintenance'; // with capital M, other than cache attribute } elseif (isset($gpxLogType[$rLog['type']])) { $logtype = $gpxLogType[$rLog['type']]; } else { $logtype = $gpxLogType[0]; } $thislog = mb_ereg_replace('{type}', $logtype, $thislog); $logtext = decodeEntities($rLog['text']); if ($rLog['needs_maintenance'] > 0 || $rLog['listing_outdated'] > 0) { $flags = []; if ($rLog['needs_maintenance'] == 1) { $flags[] = 'geocache is ok'; } if ($rLog['needs_maintenance'] == 2) { $flags[] = 'geocache needs maintenance'; } if ($rLog['listing_outdated'] == 1) { $flags[] = 'description is ok'; } if ($rLog['listing_outdated'] == 2) { $flags[] = 'description is outdated'; } foreach ($flags as &$flag) { $ft = $translate->t($flag, '', basename(__FILE__), __LINE__); if (strstr($flag, 'is ok') == false) { $flag = '<span style="color:#c00000">' . $ft . '</span>'; } else { $flag = '<span style="color:#00c000">' . $ft . '</span>'; } } $logtext = "<p><i>" . implode(', ', $flags) . "</i></p>\n" . $logtext; } $thislog = mb_ereg_replace('{text}', text_xmlentities($logtext), $thislog); $logentries .= $thislog . "\n"; } } mysql_free_result($rsLogs); $thisline = mb_ereg_replace('{logs}', $logentries, $thisline); // attributes $rsAttributes = sql_slave(' SELECT `gc_id`, `gc_inc`, `gc_name` FROM `caches_attributes` INNER JOIN `cache_attrib` ON `cache_attrib`.`id`=`caches_attributes`.`attrib_id` WHERE `caches_attributes`.`cache_id`=&1', $r['cacheid']); $gc_ids = []; while ($rAttrib = sql_fetch_array($rsAttributes)) { // Multiple OC attributes can be mapped to one GC attribute, either with // the same "inc"s or with different. Both may disturb applications, so we // output each GC ID only once. if (!isset($gc_ids[$rAttrib['gc_id']])) { $thisattribute = mb_ereg_replace('{attrib_id}', $rAttrib['gc_id'], $gpxAttributes); $thisattribute = mb_ereg_replace('{attrib_inc}', $rAttrib['gc_inc'], $thisattribute); $thisattribute = mb_ereg_replace('{attrib_name}', text_xmlentities($rAttrib['gc_name']), $thisattribute); $attribentries .= $thisattribute . "\n"; $gc_ids[$rAttrib['gc_id']] = true; } } mysql_free_result($rsAttributes); if ($r['needs_maintenance'] > 0) { $thisattribute = mb_ereg_replace('{attrib_id}', '42', $gpxAttributes); $thisattribute = mb_ereg_replace('{attrib_inc}', '1', $thisattribute); $thisattribute = mb_ereg_replace('{attrib_name}', 'Needs maintenance', $thisattribute); // with lowercase m, other than log type $attribentries .= $thisattribute . "\n"; } $thisline = mb_ereg_replace('{attributes}', $attribentries, $thisline); // geokrety $rsGeokrety = sql_slave(' SELECT `gk_item`.`id`, `gk_item`.`name`, `caches`.`wp_oc` FROM `gk_item` INNER JOIN `gk_item_waypoint` ON `gk_item`.`id`=`gk_item_waypoint`.`id` INNER JOIN `caches` ON `gk_item_waypoint`.`wp`=`caches`.`wp_oc` WHERE `caches`.`cache_id`=&1', $r['cacheid']); while ($rGK = sql_fetch_array($rsGeokrety)) { $thiskrety = $gpxGeokrety; $thiskrety = mb_ereg_replace('{gkid}', $rGK['id'], $thiskrety); $thiskrety = mb_ereg_replace('{gkref}', sprintf("GK%04X", $rGK['id']), $thiskrety); $thiskrety = mb_ereg_replace('{gkname}', text_xmlentities($rGK['name']), $thiskrety); $gkentries .= $thiskrety . "\n"; } mysql_free_result($rsGeokrety); $thisline = mb_ereg_replace('{geokrety}', $gkentries, $thisline); // additional waypoints, including personal cache note $childWaypoints = $childwphandler->getChildWps($r['cacheid']); $n = 1; $digits = "%0" . strlen(count($childWaypoints)) . "d"; foreach ($childWaypoints as $childWaypoint) { $thiswp = $gpxWaypoints; $thiswp = mb_ereg_replace('{wp_lat}', sprintf('%01.5f', $childWaypoint['latitude']), $thiswp); $thiswp = mb_ereg_replace('{wp_lon}', sprintf('%01.5f', $childWaypoint['longitude']), $thiswp); $thiswp = mb_ereg_replace('{time}', $time, $thiswp); $thiswp = mb_ereg_replace('{name}', $r['waypoint'] . '-' . sprintf($digits, $n), $thiswp); $thiswp = mb_ereg_replace('{cachename}', text_xmlentities($r['name']), $thiswp); $thiswp = mb_ereg_replace('{comment}', text_xmlentities($childWaypoint['description']), $thiswp); $thiswp = mb_ereg_replace('{desc}', text_xmlentities($childWaypoint['name']), $thiswp); switch ($childWaypoint['type']) { case 1: $wp_typename = "Parking Area"; break; // well-known garmin symbols // well-known garmin symbols case 2: $wp_typename = "Flag, Green"; break; // stage / ref point // stage / ref point case 3: $wp_typename = "Flag, Blue"; break; // path // path case 4: $wp_typename = "Circle with X"; break; // final // final case 5: $wp_typename = "Diamond, Green"; break; // point of interest // point of interest default: $wp_typename = "Flag, Blue"; break; // for the case new types are forgotten here .. } $thiswp = mb_ereg_replace('{type}', text_xmlentities($wp_typename), $thiswp); $thiswp = mb_ereg_replace('{parent}', $r['waypoint'], $thiswp); $thiswp = mb_ereg_replace('{cacheid}', $r['cacheid'], $thiswp); $waypoints .= $thiswp; ++$n; } if ($cacheNote && !empty($cacheNote['latitude']) && !empty($cacheNote['longitude'])) { $thiswp = $gpxWaypoints; $thiswp = mb_ereg_replace('{wp_lat}', sprintf('%01.5f', $cacheNote['latitude']), $thiswp); $thiswp = mb_ereg_replace('{wp_lon}', sprintf('%01.5f', $cacheNote['longitude']), $thiswp); $thiswp = mb_ereg_replace('{time}', $time, $thiswp); $thiswp = mb_ereg_replace('{name}', $r['waypoint'] . 'NOTE', $thiswp); $thiswp = mb_ereg_replace('{cachename}', text_xmlentities($r['name']), $thiswp); $thiswp = mb_ereg_replace('{comment}', text_xmlentities($cacheNote['note']), $thiswp); $thiswp = mb_ereg_replace('{desc}', text_xmlentities($cache_note_text), $thiswp); $thiswp = mb_ereg_replace('{type}', "Reference Point", $thiswp); $thiswp = mb_ereg_replace('{parent}', $r['waypoint'], $thiswp); $thiswp = mb_ereg_replace('{cacheid}', $r['cacheid'], $thiswp); $waypoints .= $thiswp; } $thisline = mb_ereg_replace('{cache_waypoints}', $waypoints, $thisline); append_output($thisline); } mysql_free_result($rs); append_output($gpxFoot); }