first commit

This commit is contained in:
2026-04-30 14:38:11 +02:00
commit e22bbde336
1994 changed files with 613950 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*
* If true, the debug toolbar will be automagically displayed
* NOTE: if IN_PRODUCTION is set to TRUE, the toolbar will
* not automatically render, even if auto_render is TRUE
*/
$config['auto_render'] = TRUE;
/*
* If true, the toolbar will default to the minimized position
*/
$config['minimized'] = FALSE;
/*
* Location of icon images
* relative to your site_domain
*/
$config['icon_path'] = 'images/debug_toolbar';
/*
* List config files you would like to exclude
* from showing in the toolbar (without extension).
* Alternatively, set to true to stop all
* config files from showing.
*/
$config['skip_configs'] = array('database', 'encryption');
/*
* Log toolbar data to FirePHP
*/
$config['firephp_enabled'] = TRUE;
/*
* Enable or disable specific panels
*/
$config['panels'] = array(
'benchmarks' => TRUE,
'database' => TRUE,
'vars_and_config' => TRUE,
'logs' => TRUE,
'ajax' => TRUE,
'files' => TRUE
);
/*
* Toolbar alignment
* options: right, left, center
*/
$config['align'] = 'right';
/*
* Secret Key
*/
$config['secret_key'] = FALSE;

View File

@@ -0,0 +1,7 @@
<?php defined('SYSPATH') or die('No direct script access.');
if (Debug_Toolbar::is_enabled())
{
// Allows the debug toolbar to inject itsself into the html
Event::add('system.display', array('Debug_Toolbar', 'render'));
}

View File

@@ -0,0 +1,6 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*
* Capture logs
*/
Event::add('system.log', array('Debug_Toolbar', 'log'));
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 861 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

View File

@@ -0,0 +1,366 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Copyright (c) 2009 Aaron Forsander <aaron.forsander@gmail.com>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* Icons taken from the wonderful work of Mark James.
*
* More information available at:
* http://www.famfamfam.com/lab/icons/silk/
*/
/**
* Displays a debug toolbar at the top of the rendered web page.
*
* For more information see: http://projects.kohanaphp.com/projects/show/kohana-debug-toolbar
*
* @copyright Copyright (C) 2009 Aaron Forsander
* @author Aaron Forsander <aaron.forsander@gmail.com>
* @package Debug_Toolbar_Core
*/
class Debug_Toolbar_Core {
// Stores system.log events
public static $logs = array();
// Name for debug toolbar's benchmark
public static $benchmark_name = 'debug_toolbar';
/**
* Renders the Debug Toolbar
*
* @param bool print rendered output
* @return string debug toolbar rendered output
*/
public static function render($print = false)
{
Benchmark::start(self::$benchmark_name);
$template = new View('toolbar');
// Database panel
if (Kohana::config('debug_toolbar.panels.database') === TRUE)
{
$template->set('queries', self::get_queries());
}
// Logs panel
if (Kohana::config('debug_toolbar.panels.logs') === TRUE)
{
$template->set('logs', self::get_logs());
}
// Vars and Config panel
if (Kohana::config('debug_toolbar.panels.vars_and_config') === TRUE)
{
$template->set('configs', self::get_configs());
}
// Files panel
if (Kohana::config('debug_toolbar.panels.files') === TRUE)
{
$template->set('files', self::get_files());
}
// FirePHP
if (Kohana::config('debug_toolbar.firephp_enabled') === TRUE)
{
self::firephp();
}
// Set alignment for toolbar
switch (Kohana::config('debug_toolbar.align'))
{
case 'right':
case 'center':
case 'left':
$template->set('align', Kohana::config('debug_toolbar.align'));
break;
default:
$template->set('align', 'left');
}
// Javascript for toolbar
$template->set('scripts', file_get_contents(Kohana::find_file('views', 'toolbar', TRUE, 'js')));
// CSS for toolbar
$styles = file_get_contents(Kohana::find_file('views', 'toolbar', FALSE, 'css'));
Benchmark::stop(self::$benchmark_name);
// Benchmarks panel
if (Kohana::config('debug_toolbar.panels.benchmarks') === TRUE)
{
$template->set('benchmarks', self::get_benchmarks());
}
if (Event::$data and self::is_enabled())
{
// Try to add css just before the </head> tag
if (stripos(Event::$data, '</head>') !== FALSE)
{
Event::$data = str_ireplace('</head>', $styles.'</head>', Event::$data);
}
else
{
// No </head> tag found, append styles to output
$template->set('styles', $styles);
}
// Try to add js and HTML just before the </body> tag
if (stripos(Event::$data, '</body>') !== FALSE)
{
Event::$data = str_ireplace('</body>', $template->render().'</body>', Event::$data);
}
else
{
// Closing <body> tag not found, just append toolbar to output
Event::$data .= $template->render();
}
}
else
{
$template->set('styles', $styles);
return $template->render($print);
}
}
/**
* Hooks the system.log event to catch all log messages
*/
public static function log()
{
self::$logs[] = Event::$data;
}
/**
* Retrieves all Kohana logs captured by system.log
*/
public static function get_logs()
{
return self::$logs;
}
/**
* Retrieves query benchmarks from Database
*/
public static function get_queries()
{
return Database::$benchmarks;
}
/**
* Creates a formatted array of all Benchmarks
*
* @return array formatted benchmarks
*/
public static function get_benchmarks()
{
$benchmarks = array();
foreach ((array)Benchmark::get(TRUE) as $name => $benchmark)
{
$benchmarks[$name] = array(
'name' => ucwords(str_replace(array('_', '-'), ' ', str_replace(SYSTEM_BENCHMARK.'_', '', $name))),
'time' => $benchmark['time'],
'memory' => $benchmark['memory']
);
}
$benchmarks = array_slice($benchmarks, 1) + array_slice($benchmarks, 0, 1);
return $benchmarks;
}
/**
* Get config data
*
* @return array all configs included by Kohana
*/
private static function get_configs()
{
if (Kohana::config('debug_toolbar.skip_configs') === TRUE)
return array();
$inc_paths = Kohana::include_paths();
$configs = array();
foreach ((array)$inc_paths as $inc_path)
{
foreach ((array)glob($inc_path.'/config/*.php') as $filename)
{
$filename = pathinfo($filename, PATHINFO_FILENAME);
if (in_array($filename, (array)Kohana::config('debug_toolbar.skip_configs')))
continue;
if (!isset($configs[$filename]))
{
$configs[$filename] = Kohana::Config($filename);
}
}
}
return $configs;
}
/**
* Get list of included files
*
* @return array file currently included by php
*/
public static function get_files()
{
$files = (array)get_included_files();
sort($files);
return $files;
}
/**
* Add toolbar data to FirePHP console
*/
private static function firephp()
{
$firephp = FirePHP::getInstance(TRUE);
$firephp->fb('KOHANA DEBUG TOOLBAR:');
// Globals
$globals = array(
'Post' => empty($_POST) ? array() : $_POST,
'Get' => empty($_GET) ? array() : $_GET,
'Cookie' => empty($_COOKIE) ? array() : $_COOKIE,
'Session' => empty($_SESSION) ? array() : $_SESSION
);
foreach ($globals as $name => $global)
{
$table = array();
$table[] = array($name,'Value');
foreach((array)$global as $key => $value)
{
if (is_object($value))
{
$value = get_class($value).' [object]';
}
$table[] = array($key, $value);
}
$message = "$name: ".count($global).' variables';
$firephp->fb(array($message, $table), FirePHP::TABLE);
}
// Database
$queries = self::get_queries();
$total_time = $total_rows = 0;
$table = array();
$table[] = array('SQL Statement','Time','Rows');
foreach ((array)$queries as $query)
{
$table[] = array(
str_replace("\n",' ',$query['query']),
number_format($query['time'], 3),
$query['rows']
);
$total_time += $query['time'];
$total_rows += $query['rows'];
}
$message = 'Queries: '.count($queries).' SQL queries took '.
number_format($total_time, 3).' seconds and returned '.$total_rows.' rows';
$firephp->fb(array($message, $table), FirePHP::TABLE);
// Benchmarks
$benchmarks = self::get_benchmarks();
$table = array();
$table[] = array('Benchmark', 'Time', 'Memory');
foreach ((array)$benchmarks as $name => $benchmark)
{
$table[] = array(
ucwords(str_replace(array('_', '-'), ' ', str_replace(SYSTEM_BENCHMARK.'_', '', $name))),
number_format($benchmark['time'], 3). ' s',
text::bytes($benchmark['memory'])
);
}
$message = 'Benchmarks: '.count($benchmarks).' benchmarks took '.
number_format($benchmark['time'], 3).' seconds and used up '.
text::bytes($benchmark['memory']).' memory';
$firephp->fb(array($message, $table), FirePHP::TABLE);
}
/**
* Determines if all the conditions are correct to display the toolbar
* (pretty kludgy, I know)
*
* @returns bool toolbar enabled
*/
public static function is_enabled()
{
// Don't auto render toolbar for ajax requests
if (request::is_ajax())
return FALSE;
// Don't auto render toolbar if $_GET['debug'] = 'false'
if (isset($_GET['debug']) and strtolower($_GET['debug']) == 'false')
return FALSE;
// Don't auto render if auto_render config is FALSE
if (Kohana::config('debug_toolbar.auto_render') !== TRUE)
return FALSE;
// Auto render if secret key isset
$secret_key = Kohana::config('debug_toolbar.secret_key');
if ($secret_key !== FALSE and isset($_GET[$secret_key]))
return TRUE;
// Don't auto render when IN_PRODUCTION (this can obviously be
// overridden by the above secret key)
if (IN_PRODUCTION)
return FALSE;
return TRUE;
}
/**
* Return a filename without extension
*
* @param string name of a file
* @return string name of file with extension removed
*/
private static function _strip_ext($file)
{
return (($pos = strrpos($file, '.')) !== FALSE) ? substr($file, 0, $pos) : $file;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,192 @@
<style type="text/css">
/* Reset */
div#kohana-debug-toolbar,
div#kohana-debug-toolbar div,
div#kohana-debug-toolbar span,
div#kohana-debug-toolbar pre,
div#kohana-debug-toolbar h1,
div#kohana-debug-toolbar img,
div#kohana-debug-toolbar a,
div#kohana-debug-toolbar ul,
div#kohana-debug-toolbar li,
div#kohana-debug-toolbar table,
div#kohana-debug-toolbar tr,
div#kohana-debug-toolbar td,
div#kohana-debug-toolbar th {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: middle;
background: transparent;
line-height: 1;
text-transform: none;
font-size:100%;
}
div#kohana-debug-toolbar table {
border-collapse: collapse;
border-spacing: 0;
}
div#kohana-debug-toolbar :focus { outline: 0; }
div#kohana-debug-toolbar ul {
list-style:none;
}
/* Global */
div#kohana-debug-toolbar {
font-family: Arial, sans-serif;
font-size: 12px;
color: #333;
text-align: left;
line-height: 12px;
}
div#kohana-debug-toolbar h1 {
font-size: 16px;
font-weight: bold;
margin-top: 30px;
margin-bottom: 10px;
padding:0px 5px;
border: 0px;
background-color: #eee;
color: #000;
display:block;
}
div#kohana-debug-toolbar a,
div#kohana-debug-toolbar a:hover {
text-decoration: none;
color: #222;
}
div#kohana-debug-toolbar pre { line-height: 1.3 }
div#kohana-debug-toolbar .top {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
z-index: 9999;
border-bottom: 1px solid #aaa;
background-color: #efefef;
padding: 10px;
}
/* Tables */
div#kohana-debug-toolbar table {
padding: 3px;
font-size: 11px;
border: 1px solid #999;
width: 99%;
margin:0px 5px;
font-family: monospace;
}
div#kohana-debug-toolbar td {
padding: 3px 3px;
vertical-align: top;
background-color: #eee;
}
div#kohana-debug-toolbar tr.odd td {
background-color: #ddd;
}
div#kohana-debug-toolbar th {
padding: 3px 5px;
vertical-align: top;
background-color: #999;
color: #eee;
white-space: nowrap;
}
div#kohana-debug-toolbar td,
div#kohana-debug-toolbar th {
border: 1px solid #efefef;
}
/* Toolbar */
div#kohana-debug-toolbar div#debug-toolbar {
position: fixed;
padding: 0 0 3px 0;
top: 0px;
opacity: 0.80;
filter: alpha(opacity:80);
z-index: 10000;
white-space: nowrap;
line-height: 16px;
background-color: #ccc;
}
div#kohana-debug-toolbar div#debug-toolbar.debug-toolbar-align-center { left: auto; right: auto; }
div#kohana-debug-toolbar div#debug-toolbar.debug-toolbar-align-right { right: 0; }
div#kohana-debug-toolbar div#debug-toolbar.debug-toolbar-align-left { left: 0; }
div#kohana-debug-toolbar div#debug-toolbar img { vertical-align: middle; }
div#kohana-debug-toolbar div#debug-toolbar ul.menu {
padding: 5px;
display: inline;
}
div#kohana-debug-toolbar div#debug-toolbar ul.menu li {
display: inline;
list-style: none;
padding: 0 5px;
border-right: 1px solid #aaa;
cursor: pointer;
line-height: 16px;
}
div#kohana-debug-toolbar div#debug-toolbar ul.menu li.last {
border: none;
}
/* Benchmarks */
div#kohana-debug-toolbar div#debug-benchmarks { padding: 3px 0px; }
/* SQL queries */
div#kohana-debug-toolbar div#debug-database { padding: 3px 0px; }
/* Vars & Config */
div#kohana-debug-toolbar div#debug-vars {
padding: 3px 0px;
}
div#kohana-debug-toolbar div#debug-vars pre {
background-color: #ddd;
padding: 5px;
color: #333;
}
div#kohana-debug-toolbar div#debug-vars .varmenu {
margin: 20px 0 0 0;
height: 23px;
}
div#kohana-debug-toolbar div#debug-vars .varmenu li {
float: left;
display: block;
padding: 5px;
margin: 0 6px 0 0;
border-top: 1px solid #999;
border-left: 1px solid #999;
border-right: 1px solid #999;
cursor: pointer;
}
div#kohana-debug-toolbar div#debug-vars .varmenu li.active {
background-color: #ddd;
color: #000;
}
div#kohana-debug-toolbar div#debug-vars .configmenu { background-color: #ddd; }
div#kohana-debug-toolbar div#debug-vars .configmenu li {
display: block;
padding: 5px;
cursor: pointer;
}
div#kohana-debug-toolbar div#debug-vars .configmenu li.odd { background-color: #eee; }
div#kohana-debug-toolbar div#debug-vars .configmenu li.even { background-color: #fff; }
div#kohana-debug-toolbar div#debug-vars .configmenu li.odd pre { background-color: #eee; }
div#kohana-debug-toolbar div#debug-vars .configmenu li.even pre { background-color: #fff; }
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.odd { background-color: #ddd; }
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.even { background-color: #ddd; }
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.odd pre { background-color: #ddd; }
div#kohana-debug-toolbar div#debug-vars .configmenu li:hover.even pre { background-color: #ddd; }
/* Logs & Msgs */
div#kohana-debug-toolbar div#debug-log {
padding: 3px 0px;
font-size: 11px;
}
/* Ajax */
div#kohana-debug-toolbar div#debug-ajax {
padding: 3px 0px;
font-size: 11px;
}
</style>

View File

@@ -0,0 +1,122 @@
var debugToolbar = {
// current toolbar section thats open
current: null,
// current vars and config section open
currentvar: null,
// current config section open
currentli: null,
// toggle a toolbar section
show : function(obj) {
if (obj == debugToolbar.current) {
debugToolbar.off(obj);
debugToolbar.current = null;
} else {
debugToolbar.off(debugToolbar.current);
debugToolbar.on(obj);
debugToolbar.current = obj;
}
},
// toggle a vars and configs section
showvar : function(li, obj) {
if (obj == debugToolbar.currentvar) {
debugToolbar.off(obj);
debugToolbar.currentli.className = '';
debugToolbar.currentli = null;
debugToolbar.currentvar = null;
} else {
debugToolbar.off(debugToolbar.currentvar);
if (debugToolbar.currentli)
debugToolbar.currentli.className = '';
debugToolbar.on(obj);
debugToolbar.currentvar = obj;
debugToolbar.currentli = li;
debugToolbar.currentli.className = 'active';
}
},
// turn an element on
on : function(obj) {
if (document.getElementById(obj) != null)
document.getElementById(obj).style.display = '';
},
// turn an element off
off : function(obj) {
if (document.getElementById(obj) != null)
document.getElementById(obj).style.display = 'none';
},
// toggle an element
toggle : function(obj) {
if (typeof obj == 'string')
obj = document.getElementById(obj);
if (obj)
obj.style.display = obj.style.display == 'none' ? '' : 'none';
},
// close the toolbar
close : function() {
document.getElementById('kohana-debug-toolbar').style.display = 'none';
},
swap: function() {
var toolbar = document.getElementById('debug-toolbar');
if (toolbar.className == 'debug-toolbar-align-center') {
toolbar.className = 'debug-toolbar-align-left';
} else if (toolbar.className == 'debug-toolbar-align-left') {
toolbar.className = 'debug-toolbar-align-right';
} else {
toolbar.className = 'debug-toolbar-align-center';
}
},
collapse: function() {
debugToolbar.toggle('debug-toolbar-menu');
}
};
/*
* Test for javascript libraries
* (only supports jQuery at the moment
*/
if (typeof jQuery != 'undefined') {
$(document).ready(function(){
// display ajax button in toolbar
$('#toggle-ajax').css({display: 'inline'});
// bind ajax event
$('#debug-ajax').bind("ajaxComplete", function(event, xmlrequest, ajaxOptions){
// add a new row to ajax table
$('#debug-ajax table').append(
'<tr class="even">' +
'<td>' + $('#debug-ajax table tr').size() +'<\/td>' +
'<td>jQuery ' + jQuery.fn.jquery + '<\/td>' +
'<td>' + xmlrequest.statusText + ' (' + xmlrequest.status + ')<\/td>' +
'<td>' + ajaxOptions.url + '<\/td>' +
'<\/tr>'
);
// stripe table
$('#debug-ajax table tbody tr:nth-child(even)').attr('class', 'odd');
// update count in toolbar
$('#toggle-ajax span').text($('#debug-ajax table tr').size()-1);
});
});
}
if (typeof Prototype != 'undefined') {
}

View File

@@ -0,0 +1,281 @@
<?php defined('SYSPATH') or die('No direct script access.') ?>
<!-- CSS styles (if not added to <head>) -->
<?php if (isset($styles)): ?>
<?php echo $styles ?>
<?php endif ?>
<!-- Javascript -->
<script type="text/javascript">
<?php echo $scripts ?>
</script>
<div id="kohana-debug-toolbar">
<!-- Toolbar -->
<div id="debug-toolbar" class="debug-toolbar-align-<?php echo $align ?>">
<!-- Kohana link -->
<?php echo html::image(
Kohana::config('debug_toolbar.icon_path').'/kohana.png',
array('onclick' => 'debugToolbar.collapse()')
) ?>
<!-- Kohana icon -->
<?php if (Kohana::config('debug_toolbar.minimized') === TRUE): ?>
<ul id="debug-toolbar-menu" class="menu" style="display: none">
<?php else: ?>
<ul id="debug-toolbar-menu" class="menu">
<?php endif ?>
<!-- Kohana version -->
<li>
<?php echo html::anchor("http://kohanaphp.com/home", KOHANA_VERSION, array('target' => '_blank')) ?>
</li>
<!-- Benchmarks -->
<?php if (Kohana::config('debug_toolbar.panels.benchmarks')): ?>
<!-- Time -->
<li id="time" onclick="debugToolbar.show('debug-benchmarks'); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/time.png', array('alt' => 'time')) ?>
<?php echo round(($benchmarks['system_benchmark_total_execution']['time'])*1000, 2) ?> ms
</li>
<!-- Memory -->
<li id="memory" onclick="debugToolbar.show('debug-benchmarks'); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/memory.png', array('alt' => 'memory')) ?>
<?php echo text::bytes($benchmarks['system_benchmark_total_execution']['memory']) ?>
</li>
<?php endif ?>
<!-- Queries -->
<?php if (Kohana::config('debug_toolbar.panels.database')): ?>
<li id="toggle-database" onclick="debugToolbar.show('debug-database'); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/database.png', array('alt' => 'queries')) ?>
<?php echo isset($queries) ? count($queries) : 0 ?>
</li>
<?php endif ?>
<!-- Vars and Config -->
<?php if (Kohana::config('debug_toolbar.panels.vars_and_config')): ?>
<li id="toggle-vars" onclick="debugToolbar.show('debug-vars'); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/config.png', array('alt' => 'vars &amp; config')) ?>
vars &amp; config
</li>
<?php endif ?>
<!-- Logs -->
<?php if (Kohana::config('debug_toolbar.panels.logs')): ?>
<li id="toggle-log" onclick="debugToolbar.show('debug-log'); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/logs.png', array('alt' => 'logs')) ?>
logs
</li>
<?php endif ?>
<!-- Ajax -->
<?php if (Kohana::config('debug_toolbar.panels.ajax')): ?>
<li id="toggle-ajax" onclick="debugToolbar.show('debug-ajax'); return false;" style="display: none">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/ajax.png', array('alt' => 'ajax')) ?>
ajax (<span>0</span>)
</li>
<?php endif ?>
<!-- Files -->
<?php if (Kohana::config('debug_toolbar.panels.files')): ?>
<li id="toggle-files" onclick="debugToolbar.show('debug-files'); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/page_copy.png', array('alt' => 'files')) ?>
files
</li>
<?php endif ?>
<!-- Swap sides -->
<li onclick="debugToolbar.swap(); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/text_align_left.png', array('alt' => 'align')) ?>
</li>
<!-- Close -->
<li class="last" onclick="debugToolbar.close(); return false;">
<?php echo html::image(Kohana::config('debug_toolbar.icon_path').'/close.png', array('alt' => 'close')) ?>
</li>
</ul>
</div>
<!-- Benchmarks -->
<?php if (Kohana::config('debug_toolbar.panels.benchmarks')): ?>
<div id="debug-benchmarks" class="top" style="display: none;">
<h1>Benchmarks</h1>
<table cellspacing="0" cellpadding="0">
<tr>
<th align="left">benchmark</th>
<th align="right">time</th>
<th align="right">memory</th>
</tr>
<?php if (count($benchmarks)): ?>
<?php foreach ((array)$benchmarks as $benchmark): ?>
<tr class="<?php echo text::alternate('odd','even')?>">
<td align="left"><?php echo $benchmark['name'] ?></td>
<td align="right"><?php echo sprintf('%.2f', $benchmark['time'] * 1000) ?> ms</td>
<td align="right"><?php echo text::bytes($benchmark['memory']) ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr class="<?php echo text::alternate('odd','even') ?>">
<td colspan="3">no benchmarks to display</td>
</tr>
<?php endif ?>
</table>
</div>
<?php endif ?>
<!-- Database -->
<?php if (Kohana::config('debug_toolbar.panels.database')): ?>
<div id="debug-database" class="top" style="display: none;">
<h1>SQL Queries</h1>
<table cellspacing="0" cellpadding="0">
<tr align="left">
<th>#</th>
<th>query</th>
<th>time</th>
<th>rows</th>
</tr>
<?php $total_time = $total_rows = 0; ?>
<?php foreach ((array)$queries as $id => $query): ?>
<tr class="<?php echo text::alternate('odd','even')?>">
<td><?php echo $id + 1 ?></td>
<td><?php echo $query['query']?></td>
<td><?php echo sprintf('%.3f', $query['time'] * 1000)?> ms</td>
<td><?php echo $query['rows']?></td>
</tr>
<?php
$total_time += $query['time'];
$total_rows += $query['rows'];
?>
<?php endforeach; ?>
<tr align="left">
<th>&nbsp;</th>
<th><?php echo count($queries) ?> total</th>
<th><?php echo sprintf('%.3f', $total_time * 1000) ?> ms</th>
<th><?php echo $total_rows ?></th>
</tr>
</table>
</div>
<?php endif ?>
<!-- Vars and Config -->
<?php if (Kohana::config('debug_toolbar.panels.vars_and_config')): ?>
<div id="debug-vars" class="top" style="display: none;">
<h1>Vars &amp; Config</h1>
<ul class="varmenu">
<li onclick="debugToolbar.showvar(this, 'vars-post'); return false;">POST</li>
<li onclick="debugToolbar.showvar(this, 'vars-get'); return false;">GET</li>
<li onclick="debugToolbar.showvar(this, 'vars-server'); return false;">SERVER</li>
<li onclick="debugToolbar.showvar(this, 'vars-cookie'); return false;">COOKIE</li>
<li onclick="debugToolbar.showvar(this, 'vars-session'); return false;">SESSION</li>
<li onclick="debugToolbar.showvar(this, 'vars-config'); return false;">CONFIG</li>
</ul>
<div style="display: none;" id="vars-post">
<?php echo isset($_POST) ? Kohana::debug($_POST) : Kohana::debug(array()) ?>
</div>
<div style="display: none;" id="vars-get">
<?php echo isset($_GET) ? Kohana::debug($_GET) : Kohana::debug(array()) ?>
</div>
<div style="display: none;" id="vars-server">
<?php echo isset($_SERVER) ? Kohana::debug($_SERVER) : Kohana::debug(array()) ?>
</div>
<div style="display: none;" id="vars-cookie">
<?php echo isset($_COOKIE) ? Kohana::debug($_COOKIE) : Kohana::debug(array()) ?>
</div>
<div style="display: none;" id="vars-session">
<?php echo isset($_SESSION) ? Kohana::debug($_SESSION) : Kohana::debug(array()) ?>
</div>
<div style="display: none;" id="vars-config">
<ul class="configmenu">
<?php foreach ($configs as $section => $vars): ?>
<li class="<?php echo text::alternate('odd', 'even') ?>" onclick="debugToolbar.toggle('vars-config-<?php echo $section ?>'); return false;">
<div><?php echo $section ?></div>
<div style="display: none;" id="vars-config-<?php echo $section ?>">
<?php echo Kohana::debug($vars) ?>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif ?>
<!-- Logs and Messages -->
<?php if (Kohana::config('debug_toolbar.panels.logs')): ?>
<div id="debug-log" class="top" style="display: none;">
<h1>Logs</h1>
<table cellspacing="0" cellpadding="0">
<tr align="left">
<th width="1%">#</th>
<th width="200">time</th>
<th width="100">level</th>
<th>message</th>
</tr>
<?php foreach ((array)$logs as $id => $log): ?>
<tr class="<?php echo text::alternate('odd','even')?>">
<td><?php echo $id + 1 ?></td>
<td><?php echo $log[0] ?></td>
<td><?php echo $log[1] ?></td>
<td><?php echo $log[2] ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<?php endif ?>
<!-- Ajax Requests -->
<?php if (Kohana::config('debug_toolbar.panels.ajax')): ?>
<div id="debug-ajax" class="top" style="display:none;">
<h1>Ajax</h1>
<table cellspacing="0" cellpadding="0">
<tr align="left">
<th width="1%">#</th>
<th width="150">source</th>
<th width="150">status</th>
<th>request</th>
</tr>
</table>
</div>
<?php endif ?>
<!-- Included Files -->
<?php if (Kohana::config('debug_toolbar.panels.files')): ?>
<div id="debug-files" class="top" style="display: none;">
<h1>Files</h1>
<table cellspacing="0" cellpadding="0">
<tr align="left">
<th>#</th>
<th>file</th>
<th>size</th>
<th>lines</th>
</tr>
<?php $total_size = $total_lines = 0 ?>
<?php foreach ((array)$files as $id => $file): ?>
<?php
$size = filesize($file);
$lines = count(file($file));
?>
<tr class="<?php echo text::alternate('odd','even')?>">
<td><?php echo $id + 1 ?></td>
<td><?php echo $file ?></td>
<td><?php echo $size ?></td>
<td><?php echo $lines ?></td>
</tr>
<?php
$total_size += $size;
$total_lines += $lines;
?>
<?php endforeach; ?>
<tr align="left">
<th colspan="2">total</th>
<th><?php echo text::bytes($total_size) ?></th>
<th><?php echo number_format($total_lines) ?></th>
</tr>
</table>
</div>
<?php endif ?>
</div>

View File

@@ -0,0 +1,30 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* You should set your own API key in application/config/gmaps.php
* This API key is usable for http://localhost/*
*/
$config['api_key'] = 'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA';
/**
* Using a localised google domain gives more accurated results on geolocation
* For example, searches for "Toledo" will return different results within the domain of Spain (http://maps.google.es)
* specified by a country code of "es" than within the default domain within the United States (http://maps.google.com).
*/
$config['api_domain'] = 'maps.google.com';
/**
* This is used to determine how many times we should retry the geocode when Google sends back a 620 status code.
* The 620 status code is used as a way to let you know Google is rate limiting your requests.
*/
$config['retries'] = 10;
/**
* This is used to determine how long we should wait before retrying (in microseconds).
* Default: 100000 (0.1 seconds)
*/
$config['retry_delay'] = 100000;

View File

@@ -0,0 +1,179 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Gmaps module demo controller. This controller should NOT be used in production.
* It is for demonstration purposes only!
*
* $Id: gmaps_demo.php 3769 2008-12-15 00:48:56Z zombor $
*
* @package Gmaps
* @author Woody Gilk
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Gmaps_Demo_Controller extends Controller {
// Do not allow to run in production
const ALLOW_PRODUCTION = FALSE;
public function index()
{
// Create a new Gmap
$map = new Gmap('map', array
(
'ScrollWheelZoom' => TRUE,
));
// Set the map center point
$map->center(0, 0, 1)->controls('large')->types('G_PHYSICAL_MAP', 'add');
// Add a custom marker icon
$map->add_icon('tinyIcon', array
(
'image' => 'http://labs.google.com/ridefinder/images/mm_20_red.png',
'shadow' => 'http://labs.google.com/ridefinder/images/mm_20_shadow.png',
'iconSize' => array('12', '20'),
'shadowSize' => array('22', '20'),
'iconAnchor' => array('6', '20'),
'infoWindowAnchor' => array('5', '1')
));
// Add a new marker
$map->add_marker(44.9801, -93.2519, '<strong>Minneapolis, MN</strong><p>Hello world!</p>', array('icon' => 'tinyIcon', 'draggable' => true, 'bouncy' => true));
View::factory('gmaps/api_demo')->set(array('api_url' => Gmap::api_url(), 'map' => $map->render()))->render(TRUE);
}
public function image_map()
{
$points = array('-37.814251' => '144.963169', '-33.867139' => '151.207114', '-27.467580' => '153.027892');
View::factory('gmaps/static_demo')->set(array('simple' => Gmap::static_map(44.9801, -93.2519),'multi' => Gmap::static_map($points)))->render(TRUE);
}
public function azmap()
{
// Create a new Gmap
$map = new Gmap('map', array
(
'ScrollWheelZoom' => TRUE,
));
// Set the map center point
$map->center(0, 35, 2)->controls('large');
// Set marker locations
foreach (ORM::factory('location')->find_all() as $location)
{
// Add a new marker
$map->add_marker($location->lat, $location->lon,
// Get the info window HTML
View::factory('gmaps/info_window')->bind('location', $location)->render());
}
header('Content-Type: text/javascript');
echo $map->render();
}
public function admin()
{
$valid = ! empty($_POST);
$_POST = Validation::factory($_POST)
->pre_filter('trim')
->add_rules('title', 'required', 'length[4,32]')
->add_rules('description', 'required', 'length[4,127]')
->add_rules('link', 'length[6,127]', 'valid::url')
->add_rules('address', 'required', 'length[4,127]')
->add_callbacks('address', array($this, '_admin_check_address'));
if ($_POST->validate())
{
// Create a new location
$location = ORM::factory('location');
//
foreach ($_POST->as_array() as $key => $val)
{
$location->$key = $val;
}
echo Kohana::debug($_POST->as_array());
}
if ($errors = $_POST->errors())
{
foreach ($errors as $input => $rule)
{
// Add the errors
$_POST->message($input, Kohana::lang("gmaps.form.$input"));
}
}
View::factory('gmaps/admin')->render(TRUE);
}
public function _admin_check_address(Validation $array, $input)
{
if ($array[$input] == '')
return;
// Fetch the lat and lon via Gmap
list ($lat, $lon) = Gmap::address_to_ll($array[$input]);
if ($lat === NULL OR $lon === NULL)
{
// Add an error
$array->add_error($input, 'address');
}
else
{
// Set the latitude and longitude
$_POST['lat'] = $lat;
$_POST['lon'] = $lon;
}
}
public function jquery()
{
$map = new Gmap('map');
$map->center(0, 35, 16)->controls('large');
View::factory('gmaps/jquery')->set(array('api_url' => Gmap::api_url(), 'map' => $map->render('gmaps/jquery_javascript')))->render(TRUE);
}
public function xml()
{
// Get all locations
$locations = ORM::factory('location')->find_all();
// Create the XML container
$xml = new SimpleXMLElement('<gmap></gmap>');
foreach ($locations as $location)
{
// Create a new mark
$node = $xml->addChild('marker');
// Set the latitude and longitude
$node->addAttribute('lon', sprintf('%F', $location->lon));
$node->addAttribute('lat', sprintf('%F', $location->lat));
$node->html = View::factory('gmaps/xml')->bind('location', $location)->render();
foreach ($location->as_array() as $key => $val)
{
// Skip the ID
if ($key === 'id') continue;
// Add the data to the XML
$node->$key = $val;
}
}
header('Content-Type: text/xml');
echo $xml->asXML();
}
} // End Google Map Controller

View File

@@ -0,0 +1,7 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
$lang = array
(
'invalid_marker' => 'Invalid marker params (latitude: %s, longitude: %s)',
'invalid_dimensions' => 'Invalid map dimensions (width: %s, height: %s)',
);

View File

@@ -0,0 +1,7 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
$lang = array
(
'invalid_marker' => 'Nieprawidłowe parametry markera (szerokość geograficzna: %s, długość geograficzna: %s)',
'invalid_dimensions' => 'Nieprawidłowe wymiary mapy (szerokość: %s, wysokość: %s)',
);

View File

@@ -0,0 +1,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

View File

@@ -0,0 +1,120 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* GMaps Icon library.
*
* $Id$
*
* @package Gmaps
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Gmap_Icon_Core {
// Valid options
protected $valid_options = array
(
'image',
'shadow',
'iconSize',
'shadowSize',
'iconAnchor',
'infoWindowAnchor',
'printImage',
'mozPrintImage',
'printShadow',
'transparent',
'imageMap',
'maxHeight',
'dragCrossImage',
'dragCrossSize',
'dragCrossAnchor'
);
// Settable options
protected $options = array();
// Icon name
protected $name;
/**
* Create a new GMap icon
*
* @param string $name icon name
* @param array $options GMap2 icon options
* @return void
*/
public function __construct($name, array $options)
{
// set icon name
$this->name = $name;
foreach ($options as $key => $value)
{
if (in_array($key, $this->valid_options, true))
{
// Set all valid methods
switch($key)
{
case 'image':
case 'shadow':
case 'printImage':
case 'mozPrintImage':
case 'printShadow':
case 'transparent':
case 'dragCrossImage':
$this->set_url($key, $value);
break;
case 'iconAnchor':
case 'infoWindowAnchor':
case 'infoShadowAnchor':
case 'dragCrossAnchor':
$this->set_point($key, $value);
break;
case 'iconSize':
case 'shadowSize':
case 'dragCrossSize':
$this->set_size($key, $value);
break;
default:
$this->options[$key] = json_encode($value);
break;
}
}
}
}
public function set_url($key, $url)
{
$this->options[$key] = (valid::url($url)) ? '"'.$url.'";' : '"'.url::site($url).'";';
}
public function set_size($key, $val)
{
$this->options[$key] = 'new google.maps.Size('.implode(',', $val).');';
}
public function set_point($key, $val)
{
$this->options[$key] = 'new google.maps.Point('.implode(',', $val).');';
}
public function render($tabs = 0)
{
// Create the tabs
$tabs = empty($tabs) ? '' : str_repeat("\t", $tabs);
$output = array();
// Render each option
$output[] = "var $this->name = ".((count($this->options) > 1) ? 'new google.maps.Icon();' : 'new google.maps.Icon(G_DEFAULT_ICON);');
foreach($this->options as $option => $value)
{
$output[] = "$this->name.$option = $value";
}
return implode("\n".$tabs, $output);
}
} // End Gmap Icon

View File

@@ -0,0 +1,84 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Gmap_Marker_Core {
// Marker HTML
public $html;
// Latitude and longitude
public $latitude;
public $longitude;
// Marker ID
protected static $id = 0;
// Marker Options
protected $options = array();
protected $valid_options = array
(
'icon',
'dragCrossMove',
'title',
'clickable',
'draggable',
'bouncy',
'bounceGravity',
'autoPan'
);
/**
* Create a new GMap marker.
*
* @param float $lat latitude
* @param float $lon longitude
* @param string $html HTML of info window
* @param array $options marker options
* @return void
*/
public function __construct($lat, $lon, $html, $options = array())
{
if ( ! is_numeric($lat) OR ! is_numeric($lon))
throw new Kohana_Exception('gmaps.invalid_marker', $lat, $lon);
// Set the latitude and longitude
$this->latitude = $lat;
$this->longitude = $lon;
// Set the info window HTML
$this->html = $html;
if (count($options) > 0)
{
foreach ($options as $option => $value)
{
// Set marker options
if (in_array($option, $this->valid_options, true))
$this->options[] = "$option:$value";
}
}
}
public function render($tabs = 0)
{
// Create the tabs
$tabs = empty($tabs) ? '' : str_repeat("\t", $tabs);
// Marker ID
$marker = 'm'.++self::$id;
$output[] = 'var '.$marker.' = new google.maps.Marker(new google.maps.LatLng('.$this->latitude.', '.$this->longitude.'), {'.implode(",", $this->options).'});';
if ($html = $this->html)
{
$output[] = 'google.maps.Event.addListener('.$marker.', "click", function()';
$output[] = '{';
$output[] = "\t".$marker.'.openInfoWindowHtml(';
$output[] = "\t\t'".implode("'+\n\t\t$tabs'", explode("\n", $html))."'";
$output[] = "\t);";
$output[] = '});';
}
$output[] = 'map.addOverlay('.$marker.');';
return implode("\n".$tabs, $output);
}
} // End Gmap Marker

View File

@@ -0,0 +1,70 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* GMaps options container.
*
* $Id: Gmap_Options.php 4179 2009-04-07 23:39:20Z zombor $
*
* @package Gmaps
* @author Kohana Team
* @copyright (c) 2007-2008 Kohana Team
* @license http://kohanaphp.com/license.html
*/
class Gmap_Options_Core {
// Valid options
protected $valid_options = array
(
'Dragging',
'InfoWindow',
'DoubleClickZoom',
'ContinuousZoom',
'GoogleBar',
'ScrollWheelZoom'
);
// Settable options
protected $options = array();
/**
* Create a new GMap options
*
* @param array GMap2 object options
* @return void
*/
public function __construct(array $options)
{
foreach ($options as $key => $value)
{
if (in_array($key, $this->valid_options))
{
// Set all valid options
$this->options[$key] = (bool) $value;
}
}
}
public function render($tabs = 0)
{
// Create the tabs
$tabs = empty($tabs) ? '' : str_repeat("\t", $tabs);
// Render each option
$output = array();
foreach ($this->options as $option => $value)
{
if ($value === TRUE)
{
// Add an enable
$output[] = 'map.enable'.$option.'();';
}
else
{
// Add a disable
$output[] = 'map.disable'.$option.'();';
}
}
return implode("\n".$tabs, $output);
}
} // End Gmap Options

View File

@@ -0,0 +1,23 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/*
CREATE TABLE `locations` (
`id` mediumint(8) unsigned NOT NULL auto_increment,
`created` int(10) unsigned NOT NULL,
`title` varchar(32) NOT NULL,
`description` varchar(127) NOT NULL,
`link` varchar(127) NOT NULL,
`lon` float(10,6) NOT NULL,
`lat` float(10,6) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_ll` (`lon`,`lat`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
*/
class Location_Model extends ORM {
// Exciting!
} // End Location Model

View File

@@ -0,0 +1,16 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="<?php echo $api_url ?>" type="text/javascript"></script>
<script type="text/javascript">
<?php echo $map ?>
</script>
</head>
<body>
<p>You can use your scroll wheel to zoom in and out of the map.</p>
<div id="map" style="width: 600px; height: 400px"></div>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<div class="gmap-html">
<span class="image"><?php echo html::image(array('src' => $location->link, 'alt' => $location->title, 'width' => 100, 'height' => 100)) ?></span>
<h6 class="title"><?php echo $location->title ?></h6>
<?php
echo '<p>', implode("</p>\n<p>", explode("\n\n", $location->description)), "</p>\n";
?>
<p class="link"><?php echo html::anchor($location->link, $location->title) ?></p>
</div>

View File

@@ -0,0 +1,24 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
google.load("maps", "2.x", {"language" : "<?php echo substr(Kohana::config('locale.language.0'), 0, 2);?>"});
function initialize() {
if (GBrowserIsCompatible()) {
// Initialize the GMap
<?php echo $map, "\n" ?>
<?php echo $controls, "\n" ?>
<?php echo $center, "\n" ?>
<?php echo $options->render(1), "\n" ?>
<?php if ( ! empty($icons)): ?>
// Build custom marker icons
<?php foreach($icons as $icon): ?>
<?php echo $icon->render(1), "\n" ?>
<?php endforeach ?>
<?php endif ?>
// Show map points
<?php foreach($markers as $marker): ?>
<?php echo $marker->render(1), "\n" ?>
<?php endforeach ?>
}
}
google.setOnLoadCallback(initialize);

View File

@@ -0,0 +1,17 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Gmaps jQuery + XML Example</title>
<script src="<?php echo $api_url ?>" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
<?php echo $map?>
</script>
</head>
<body>
<p>You can use your scroll wheel to zoom in and out of the map.</p>
<div id="map" style="width:600px;height:400px;"></div>
</body>
</html>

View File

@@ -0,0 +1,49 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
google.load("maps", "2.x", {"language" : "<?php echo substr(Kohana::config('locale.language.0'), 0, 2);?>"});
$(function()
{
if (GBrowserIsCompatible())
{
// Initialize the Gmap
<?php echo $map, "\n" ?>
<?php echo $controls, "\n" ?>
<?php echo $center, "\n" ?>
<?php echo $options->render(1), "\n" ?>
// Load map markers
$.ajax
({
type: 'GET',
url: '<?php echo url::site('google_map/xml') ?>',
dataType: 'xml',
success: function(data, status)
{
$(data).find('marker').each(function()
{
// Current marker
var node = $(this);
// Extract HTML
var html = node.find('html').text();
// Create a new map marker
var marker = new google.maps.Marker(new google.maps.LatLng(node.attr("lat"), node.attr("lon")));
google.maps.Event.addListener(marker, "click", function()
{
marker.openInfoWindowHtml(html);
});
// Add the marker to the map
map.addOverlay(marker);
});
},
error: function(request, status, error)
{
alert('There was an error retrieving the marker information, please refresh the page to try again.');
}
});
}
});
// Unload the map when the window is closed
$(document.body).unload(function(){ GBrowserIsCompatible() && GUnload(); });

View File

@@ -0,0 +1,13 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps Static Map Example</title>
</head>
<body>
<img src="<?php echo $simple;?>" />
<img src="<?php echo $multi;?>" />
</body>
</html>

View File

@@ -0,0 +1,2 @@
<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>
<p><?=$location->title;?>, <br /><?=$location->description;?></p>