Newer
Older
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
<?php
// Static page producer module
// A user must be in the html group in order to edit pages in this component
$permission = "html";
// Get the right filename...
$myfile = $base."static".$path.$language['file'].".txt";
$secondaryfile = $base."static".$path.$language['file']."-secondary.txt";
if (!file_exists($myfile)) {
$myfile = $base."static$path.txt";
$secondaryfile = $base."static$path-secondary.txt";
// If the file doesn't exist...
if (!file_exists($myfile)) {
if (isset($session->groups[$permission]) && @$_REQUEST['action']=="create") {
// ...and we have permission and have been asked to, create it
$body = "foo";
} else {
$redirect_path = $DB->GetOne("SELECT to_uri FROM redirect where from_uri=?", array("/".$pathlist[1]));
if (isset($_SERVER['HTTPS'])) $proto = "https://";
else $proto = "http://";
if ($redirect_path!="") {
$variables = "";
for ($i=2;$i<count($pathlist);$i++) {
$variables .= "/".$pathlist[$i];
}
$redirect_uri = $proto.$_SERVER['SERVER_NAME'].$redirect_path.$variables;
if ($_SERVER['QUERY_STRING']!="") $redirect_uri.="?".$_SERVER['QUERY_STRING'];
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$redirect_uri);
} else {
// ...serve a 404 error
header("HTTP/1.1 404 Not Found");
$body = @file_get_contents($base."static/404.txt");
$smarty->assign("pathlist", array("", "Error"));
$title = "File not found";
$smarty->assign("title", $title);
$smarty->assign("body", $body);
// Give those with permission the chance to create the page
if (isset($session->groups[$permission])) $smarty->assign("creatable", TRUE);
}
return;
}
}
}
// If we've got edit permission...
if (isset($session->groups[$permission])) {
switch (@$_REQUEST['action']) {
case "Save":
// ...save the file
$savesuccess = @file_put_contents($myfile, $_REQUEST['body'], LOCK_EX);
if (!$savesuccess) trigger_error("Write failed", E_USER_ERROR);
$id = $DB->GetOne("select id from static where path=?", array($path));
$record = array();
$record['summary'] = $_REQUEST['summary'];
$record['editor'] = $session->username;
$record['path'] = $path;
if ($id>0) {
$DB->AutoExecute("static", $record, 'UPDATE', "id = '".$id."'");
} else {
$DB->AutoExecute("static", $record, 'INSERT');
}
// probably need some error-handling here...
break;
case "Delete":
$deleted = unlink($myfile);
break;
}
}
$title = end($pathlist);
if (file_exists($myfile)) {
$body = file_get_contents($myfile);
$modified = date("r", filectime($myfile));
$modifiedby = $DB->GetOne("select editor from static where path=?", array($path));
}
if (file_exists($secondaryfile)) {
$secondary = file_get_contents($secondaryfile);
$smarty->assign("secondary", $secondary);
}
Graham Cole
committed
// include a widget for leaving feedback on this page if the user is logged in
if ($session->loggedin) {
// include("../lib/page-feedback.php");
Graham Cole
committed
}
Denis Walker
committed
$smarty->assign("title", str_replace("_", " ", $title));
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
// Editing static pages - does the user have permission?
if (isset($session->groups[$permission])) {
// display Edit link on page
$smarty->assign("editable", TRUE);
switch (@$_REQUEST['action']) {
// load the editing template
case "create":
if (!file_exists($myfile)) file_put_contents($myfile, "Page under construction\n", LOCK_EX);
case "edit":
$smarty->assign("editcontent", $body);
$record['summary'] = $DB->GetOne("select summary from static where path=?", array($path));
$smarty->assign("record", $record);
$smarty->assign("action", "edit");
$modified = NULL;
$body = $smarty->fetch('static_edit.tpl');
break;
case "delete-query":
$body = $smarty->fetch('static_delete.tpl').$body;
break;
case "Delete":
if ($deleted) $body = "File deleted";
break;
}
}
$smarty->assign("body", $body);
$smarty->assign("modified", @$modified);
$smarty->assign("modifiedby", @$modifiedby);
?>