<?php
/**
 * modified for GroURL by Krzysztof Burghardt <krzysztof@burghardt.pl>
 */
/**
 * Google Analytics for DokuWiki
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Terence J. Grant<tjgrant@tatewake.com>
 */

$gu_loaded = 0;

function gu_load()
{
	global $gu_loaded, $gu_settings;

	$gu_file = dirname(__FILE__).'/local_pref.php';

	if ($gu_loaded == 0)
	{
		if(file_exists($gu_file))
		{
			include($gu_file);

			$gu_loaded = 1;
		}
	}
}

function gu_write($fp, $name, $val)
{
	fwrite($fp, '$gu_settings[\''.$name.'\'] = \''.$val.'\';'."\n");
}

function gu_save()
{
	global $gu_loaded, $gu_settings;

	$gu_file = dirname(__FILE__).'/local_pref.php';

	if (is_writable($gu_file))
	{
		$fp = fopen($gu_file, "w");
		fwrite($fp, '<?php'."\n// This file is automatically generated\n");
		gu_write($fp, 'latitude', $gu_settings['latitude']);
		gu_write($fp, 'longitude', $gu_settings['longitude']);
		fclose($fp);

		ptln('<div class="success">'.'GeoURL pref saved successfully.'.'</div>');
	}
	else
	{
		ptln('<div class="error">'.'GeoURL pref is not writable by the server.'.'</div>');
	}
}

function gu_geourl_code()
{
	global $gu_loaded, $gu_settings, $conf;

	if ($gu_settings['latitude'])
	    if ($gu_settings['longitude'])
	    {
		ptln('  <meta name="ICBM" content="'.$gu_settings['latitude'].', '.$gu_settings['longitude'].'" />');
		ptln('  <meta name="DC.title" content="'.$conf['title'].'" />');
	    }
}

//Load settings
gu_load();
