This file is indexed.

/usr/share/php/kohana2/modules/gmaps/libraries/Gmap.php is in libkohana2-modules-php 2.3.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
 * Google Maps API integration.
 *
 * $Id: Gmap.php 4302 2009-05-01 02:49:41Z kiall $
 *
 * @package    Gmaps
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @license    http://kohanaphp.com/license.html
 */
class Gmap_Core {
	
	// Map settings
	protected $id;
	protected $options;
	protected $center;
	protected $control;
	protected $overview_control;
	protected $type_control = FALSE;

	// Map types
	protected $types = array();
	protected $default_types = array
	(
		'G_NORMAL_MAP','G_SATELLITE_MAP','G_HYBRID_MAP','G_PHYSICAL_MAP'
	);
	
	// Markers icons
	protected $icons = array();

	// Map markers
	protected $markers = array();

	/**
	 * Set the GMap center point.
	 *
	 * @param string $id HTML map id attribute
	 * @param array $options array of GMap constructor options
	 * @return void
	 */
	public function __construct($id = 'map', $options = NULL)
	{
		// Set map ID and options
		$this->id = $id;
		$this->options = new Gmap_Options((array) $options);
	}

	/**
	 * Return GMap javascript url
	 *
	 * @param   string  API component
	 * @param   array   API parameters
	 * @return  string
	 */
	 public static function api_url($component = 'jsapi', $parameters = NULL, $separator = '&amp;')
	 {
		if (empty($parameters['ie']))
		{
			// Set input encoding to UTF-8
			$parameters['ie'] = 'utf-8';
		}

		if (empty($parameters['oe']))
		{
			// Set ouput encoding to input encoding
			$parameters['oe'] = $parameters['ie'];
		}

		if (empty($parameters['key']))
		{
			// Set the API key last
			$parameters['key'] = Kohana::config('gmaps.api_key');
		}

		return 'http://'.Kohana::config('gmaps.api_domain').'/'.$component.'?'.http_build_query($parameters, '', $separator);
	 }

	/**
	 * Retrieves the latitude and longitude of an address.
	 *
	 * @param string $address address
	 * @return array longitude, latitude
	 */
	public static function address_to_ll($address)
	{
		$lat = NULL;
		$lon = NULL;

		if ($xml = Gmap::address_to_xml($address))
		{
			// Get the latitude and longitude from the Google Maps XML
			// NOTE: the order (lon, lat) is the correct order
			list ($lon, $lat) = explode(',', $xml->Response->Placemark->Point->coordinates);
		}

		return array($lat, $lon);
	}

	/**
	 * Retrieves the XML geocode address lookup.
	 * ! Results of this method are cached for 1 day.
	 *
	 * @param string $address adress
	 * @return object SimpleXML
	 */
	public static function address_to_xml($address)
	{
		static $cache;

		// Load Cache
		if ($cache === NULL) 
		{
			$cache = Cache::instance();
		}
		
		// Address cache key
		$key = 'gmap-address-'.sha1($address);

		if ($xml = $cache->get($key))
		{
			// Return the cached XML
			return simplexml_load_string($xml);
		}
		else
		{
			// Setup the retry counter and retry delay
			$remaining_retries = Kohana::config('gmaps.retries');
			$retry_delay = Kohana::config('gmaps.retry_delay');

			// Set the XML URL
			$xml_url = Gmap::api_url('maps/geo', array('output' => 'xml', 'q' => $address), '&');

			// Disable error reporting while fetching the feed
			$ER = error_reporting(~E_NOTICE);

			// Enter the request/retry loop.
			while ($remaining_retries)
			{
				// Load the XML
				$xml = simplexml_load_file($xml_url);

				if (is_object($xml) AND ($xml instanceof SimpleXMLElement) AND (int) $xml->Response->Status->code === 200)
				{
					// Cache the XML
					$cache->set($key, $xml->asXML(), array('gmaps'), 86400);

					// Since the geocode was successful, theres no need to try again
					$remaining_retries = 0;
				}
				elseif ((int) $xml->Response->Status->code === 620)
				{
					/* Goole is rate limiting us - either we're making too many requests too fast, or
					 * we've exceeded the 15k per 24hour limit. */

					// Reduce the number of remaining retries
					$remaining_retries--;
					if ( ! $remaining_retries)
				 		return FALSE;

				 	// Sleep for $retry_delay microseconds before trying again.
				 	usleep($retry_delay);
				}
				else
				{
					// Invalid XML response
					$xml = FALSE;

					// Dont retry.
					$remaining_retries = 0;
				}
			}

			// Turn error reporting back on
			error_reporting($ER);
		}

		return $xml;
	}

	/**
	 * Returns an image map
	 *
	 * @param mixed $lat latitude or an array of marker points
	 * @param float $lon longitude
	 * @param integer $zoom zoom level (1-19)
	 * @param string $type map type (roadmap or mobile)
	 * @param integer $width map width
	 * @param integer $height map height
	 * @return string
	 */
	public static function static_map($lat = 0, $lon = 0, $zoom = 6, $type = NULL, $width = 300, $height = 300)
	{
		// Valid map types
		$types = array('roadmap', 'mobile');

		// Maximum width and height are 640px
		$width = min(640, abs($width));
		$height = min(640, abs($height));

		$parameters['size'] = $width.'x'.$height;

		// Minimum zoom = 0, maximum zoom = 19
		$parameters['zoom'] = max(0, min(19, abs($zoom)));

		if (in_array($type, $types))
		{
			// Set map type
			$parameters['maptype'] = $type;
		}

		if (is_array($lat))
		{
			foreach ($lat as $_lat => $_lon)
			{
				$parameters['markers'][] = $_lat.','.$_lon;
			}

			$parameters['markers'] = implode('|', $parameters['markers']);
		}
		else
		{
			$parameters['center'] = $lat.','.$lon;
		}

		return Gmap::api_url('staticmap', $parameters);
	}

	/**
	 * Set the GMap center point.
	 *
	 * @chainable
	 * @param float $lat latitude
	 * @param float $lon longitude
	 * @param integer $zoom zoom level (1-19)
	 * @param string $type default map type
	 * @return object
	 */
	public function center($lat, $lon, $zoom = 6, $type = 'G_NORMAL_MAP')
	{
		$zoom = max(0, min(19, abs($zoom)));
		$type = ($type != 'G_NORMAL_MAP' AND in_array($type, $this->default_types, true)) ? $type : 'G_NORMAL_MAP';

		// Set center location, zoom and default map type
		$this->center = array($lat, $lon, $zoom, $type);

		return $this;
	}

	/**
	 * Set the GMap controls size.
	 *
	 * @chainable
	 * @param string $size small or large
	 * @return object
	 */
	public function controls($size = NULL)
	{
		// Set the control type
		$this->control = (strtolower($size) == 'small') ? 'Small' : 'Large';

		return $this;
	}

	/**
	 * Set the GMap overview map.
	 *
	 * @chainable
	 * @param integer $width width
	 * @param integer $height height
	 * @return object
	 */
	public function overview($width = '', $height = '')
	{
		$size = (is_int($width) AND is_int($height)) ? 'new GSize('.$width.','.$height.')' : '';
		$this->overview_control = 'map.addControl(new google.maps.OverviewMapControl('.$size.'));';

		return $this;
	}

	/**
	 * Set the GMap type controls.
	 * by default renders G_NORMAL_MAP, G_SATELLITE_MAP, and G_HYBRID_MAP
	 *
	 * @chainable
	 * @param string $type map type
	 * @param string $action add or remove map type
	 * @return object
	 */
	public function types($type = NULL, $action = 'remove')
	{
		$this->type_control = TRUE;

		if ($type !== NULL AND in_array($type, $this->default_types, true))
		{
			// Set the map type and action
			$this->types[$type] = (strtolower($action) == 'remove') ? 'remove' : 'add';
		}

		return $this;
	}
	
	/**
	 * Create a custom marker icon
	 *
	 * @chainable
	 * @param string $name icon name
	 * @param array $options icon options
	 * @return object
	 */
	public function add_icon($name, array $options)
	{
		// Add a new cusotm icon
		$this->icons[] = new Gmap_Icon($name, $options);

		return $this;
	}

	/**
	 * Set the GMap marker point.
	 *
	 * @chainable
	 * @param float $lat latitude
	 * @param float $lon longitude
	 * @param string $html HTML for info window
	 * @param array $options marker options
	 * @return object
	 */
	public function add_marker($lat, $lon, $html = '', $options = array())
	{
		// Add a new marker
		$this->markers[] = new Gmap_Marker($lat, $lon, $html, $options);

		return $this;
	}

	/**
	 * Render the map into GMap Javascript.
	 *
	 * @param string $template template name
	 * @param array $extra extra fields passed to the template
	 * @return string
	 */
	public function render($template = 'gmaps/javascript', $extra = array())
	{
		// Latitude, longitude, zoom and default map type
		list ($lat, $lon, $zoom, $default_type) = $this->center;

		// Map
		$map = 'var map = new google.maps.Map2(document.getElementById("'.$this->id.'"));';

		// Map controls
		$controls[] = empty($this->control) ? '' : 'map.addControl(new google.maps.'.$this->control.'MapControl());';

		// Map Types
		if ($this->type_control === TRUE)
		{
			if (count($this->types) > 0)
			{
				foreach($this->types as $type => $action)
					$controls[] = 'map.'.$action.'MapType('.$type.');';
			}

			$controls[] = 'map.addControl(new google.maps.MapTypeControl());';
		}

		if ( ! empty($this->overview_control))
			$controls[] = $this->overview_control;

		// Map centering
		$center = 'map.setCenter(new google.maps.LatLng('.$lat.', '.$lon.'), '.$zoom.', '.$default_type.');';
		
		$data = array_merge($extra, array
			(
				'map' => $map,
				'options' => $this->options,
				'controls' => implode("\n", $controls),
				'center' => $center,
				'icons' => $this->icons,
				'markers' => $this->markers,
			));

		// Render the Javascript
		return View::factory($template, $data)->render();
	}

} // End Gmap