This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
/
tiki-map_history.php
118 lines (117 loc) · 4.25 KB
/
tiki-map_history.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
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
<?php
/**
* @package tikiwiki
*/
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
require_once ('tiki-setup.php');
include_once ('lib/map/maplib.php');
if (!isset($prefs['feature_maps']) or $prefs['feature_maps'] != 'y') {
$smarty->assign('msg', tra("Feature disabled"));
$smarty->display("error.tpl");
die;
}
$access->check_permission('tiki_p_map_view');
// Validate to prevent editing any file
if (isset($_REQUEST["mapfile"])) {
if (strstr($_REQUEST["mapfile"], '..')) {
$smarty->assign('errortype', 401);
$smarty->assign('msg', tra("You dont have permission to do that"));
$smarty->display('error.tpl');
die;
}
$mapfile = $_REQUEST['mapfile'];
} else {
$mapfile = $prefs['default_map'];
}
if (!isset($prefs['map_path']) or !$prefs['map_path']) {
$smarty->assign('msg', tra("Maps feature is not correctly setup : Maps path is missing."));
$smarty->display('error.tpl');
die;
}
if (!is_dir($prefs['map_path'])) {
$smarty->assign('msg', tr('Please create a directory named %0 to hold your map files.', $prefs['map_path']));
$smarty->display('error.tpl');
die;
}
if (!preg_match('/\.map$/i', $mapfile)) {
$smarty->assign('msg', tra("mapfile name incorrect"));
$smarty->display("error.tpl");
die;
}
$smarty->assign('mapfile', $mapfile);
//Get the history
// Get mapfiles from the mapfiles directory
$files = $maplib->listMapsWithRev($prefs['map_path']);
$history = array();
$j = 0;
foreach ($files as $file) {
if (substr($file, 0, strlen($mapfile)) == $mapfile) {
$suffix = substr($file, strlen($mapfile));
$revision = intval(substr($suffix, 1));
if ($revision != 0) {
$history[$j]["version"] = $revision;
$history[$j]["data"] = nl2br(file_get_contents($prefs['map_path'] . $file));
$j++;
}
}
}
$history[$j]["version"] = $j + 1;
$history[$j]["data"] = nl2br(file_get_contents($prefs['map_path'] . $mapfile));
foreach ($history as $index =>$h ) {
if (strpos($h["data"], "##TIKIMAPS HEADER: END##") != FALSE) {
$searchdata = substr($h["data"], 0, strpos($h["data"], "##TIKIMAPS HEADER: END##"));
if (strpos($searchdata, "#IP: ") != FALSE) {
$IP = substr($searchdata, strpos($searchdata, "#IP: ") + 4);
$history[$index]["ip"] = substr($IP, 0, strpos($IP, "<br"));
}
if (strpos($searchdata, "#Modified by: ") != FALSE) {
$IP = substr($searchdata, strpos($searchdata, "#Modified by: ") + 13);
$history[$index]["user"] = substr($IP, 0, strpos($IP, "<br"));
}
if (strpos($searchdata, "#GMT Date: ") != FALSE) {
$IP = substr($searchdata, strpos($searchdata, "#GMT Date: ") + 10);
$IP = substr($IP, 0, strpos($IP, "<br"));
$history[$i]["lastModif"] = gmmktime(substr($IP, 10, 2), substr($IP, 12, 2), substr($IP, 14, 2), substr($IP, 5, 2), substr($IP, 7, 2), substr($IP, 1, 4));
}
}
}
$smarty->assign_by_ref('history', $history);
$smarty->assign('preview', false);
if (isset($_REQUEST["preview"])) {
$previewd = $history[$_REQUEST["preview"] - 1]["data"];
$smarty->assign_by_ref('previewd', $previewd);
$smarty->assign('preview', $_REQUEST["preview"]);
}
if (isset($_REQUEST["diff2"])) { // previous compatibility
$_REQUEST["compare"] = "y";
$_REQUEST["oldver"] = $_REQUEST["diff2"];
}
if (!isset($_REQUEST["newver"])) {
$_REQUEST["newver"] = count($history);
}
if (isset($_REQUEST["compare"])) {
foreach ($history as $old) {
if ($old["version"] == $_REQUEST["oldver"]) break;
}
$smarty->assign_by_ref('old', $old);
foreach ($history as $new) {
if ($new["version"] == $_REQUEST["newver"]) break;
}
$smarty->assign_by_ref('new', $new);
if (!isset($_REQUEST["diff_style"]) || $_REQUEST["diff_style"] == "old") $_REQUEST["diff_style"] = 'unidiff';
$smarty->assign('diff_style', $_REQUEST["diff_style"]);
if ($_REQUEST["diff_style"] != "sideview") {
require_once ('lib/diff/difflib.php');
$html = diff2($old["data"], $new["data"], $_REQUEST["diff_style"]);
$smarty->assign_by_ref('diffdata', $html);
}
} else $smarty->assign('diff_style', '');
$section = 'maps';
include_once ('tiki-section_options.php');
// Get templates from the templates/modules directori
$smarty->assign('mid', 'map/tiki-map_history.tpl');
$smarty->display("tiki.tpl");