-
Notifications
You must be signed in to change notification settings - Fork 0
/
jojo_gmaps.php
executable file
·67 lines (59 loc) · 2.68 KB
/
jojo_gmaps.php
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
<?php
/**
*
* Copyright 2007 Michael Cochrane <code@gardyneholt.co.nz>
*
* See the enclosed file license.txt for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Michael Cochrane <code@gardyneholt.co.nz>
* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License
* @link http://www.jojocms.org JojoCMS
*/
class JOJO_Plugin_jojo_gmaps extends JOJO_Plugin
{
public static function mapfilter($content)
{
if (strpos($content, '[[gmap:') === false) {
return $content;
}
global $smarty;
/* Find all [[gmap:map name]] tags */
preg_match_all('/\[\[gmap:([^\]]*)\]\]/', $content, $matches);
if ($matches[0]) {
foreach($matches[1] as $id => $match) {
/* Find the map in the database */
$map = Jojo::selectRow('SELECT * FROM {map} WHERE mp_name = ? or mapid = ?', array(trim($match),trim($match)));
if (!$map) {
$content = str_replace($matches[0][$id], "Map '$match' not found", $content);
continue;
}
$map['name'] = htmlspecialchars($map['mp_name'], ENT_COMPAT, 'UTF-8', false);
$maplocations = Jojo::selectQuery('SELECT * FROM {maplocation} WHERE mapid = ? ORDER BY ml_name', $map['mapid']);
usort($maplocations, array('JOJO_Plugin_jojo_gmaps', 'ordersort'));
foreach ($maplocations as &$ml) {
$ml['name'] = htmlspecialchars($ml['ml_name'], ENT_COMPAT, 'UTF-8', false);
$ml['description'] = nl2br(htmlspecialchars($ml['ml_description'], ENT_COMPAT, 'UTF-8', false));
}
/* Create url to KML file */
$url = _SITEURL . '/'. JOJO_Plugin_jojo_gmaps_kml::_getPrefix() . '/' . urlencode(strtolower($map['mp_name'])) . '.kml';
$smarty->assign('kmlurl', $url);
$map['mapunit_w'] = is_numeric($map['mp_width']) ? 'px' : '';
$map['mapunit_h'] = is_numeric($map['mp_height']) ? 'px' : '';
$smarty->assign('map', $map);
$smarty->assign('mapLocations', $maplocations);
$smarty->assign('mapid', $map['mapid']);
/* Get the map html */
$html = $smarty->fetch('jojo_gmap.tpl');
$content = str_replace($matches[0][$id], $html, $content);
}
}
return $content;
}
private static function ordersort($a, $b)
{
if (isset($a['displayorder'])) {
return strnatcasecmp($a['displayorder'],$b['displayorder']);
}
}
}