Mercurial > hg > mlmmj
annotate contrib/web/php-admin/htdocs/edit.php @ 769:fc5892d87716
Update php code to use superglobals
author | Ben Schmidt |
---|---|
date | Fri, 29 Oct 2010 22:13:47 +1100 |
parents | 4be42e1ca045 |
children | b9b60f3dd694 |
rev | line source |
---|---|
309 | 1 <?php |
2 | |
3 /* mlmmj/php-admin: | |
4 * Copyright (C) 2004 Christoph Thiel <ct at kki dot org> | |
5 * | |
6 * mlmmj/php-perl: | |
7 * Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk> | |
8 * Copyright (C) 2004 Christian Laursen <christian@pil.dk> | |
9 * | |
10 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
11 * of this software and associated documentation files (the "Software"), to | |
12 * deal in the Software without restriction, including without limitation the | |
13 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
14 * sell copies of the Software, and to permit persons to whom the Software is | |
15 * furnished to do so, subject to the following conditions: | |
16 * | |
17 * The above copyright notice and this permission notice shall be included in | |
18 * all copies or substantial portions of the Software. | |
19 * | |
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
26 * IN THE SOFTWARE. | |
27 */ | |
28 | |
759
73c8715367fb
Better techniques for locating support files in php-admin
Ben Schmidt
parents:
733
diff
changeset
|
29 require(dirname(dirname(__FILE__))."/conf/config.php"); |
73c8715367fb
Better techniques for locating support files in php-admin
Ben Schmidt
parents:
733
diff
changeset
|
30 require(dirname(__FILE__)."/class.rFastTemplate.php"); |
309 | 31 |
32 function mlmmj_boolean($name, $nicename, $text) | |
33 { | |
34 global $tpl, $topdir, $list; | |
35 | |
36 if(is_file($topdir."/".$list."/control/".$name)) | |
37 $checked = TRUE; | |
38 else | |
39 $checked = FALSE; | |
40 | |
41 $tpl->assign(array("NAME" => htmlentities($name), | |
42 "NICENAME" => htmlentities($nicename), | |
43 "TEXT" => htmlentities($text))); | |
44 $tpl->assign(array("CHECKED" => $checked ? " checked" : "")); | |
45 | |
46 $tpl->parse("ROWS",".boolean"); | |
47 } | |
48 | |
49 function mlmmj_string($name, $nicename, $text) | |
50 { | |
51 global $tpl, $topdir, $list; | |
52 | |
53 $file = $topdir."/".$list."/control/".$name; | |
54 $value = ""; | |
55 | |
767
4be42e1ca045
Simplify file-reading code in php-admin (Franky Van Liedekerke)
Ben Schmidt
parents:
762
diff
changeset
|
56 if(is_file($file)) { |
309 | 57 $lines = file($file); |
767
4be42e1ca045
Simplify file-reading code in php-admin (Franky Van Liedekerke)
Ben Schmidt
parents:
762
diff
changeset
|
58 $value = $lines[0]; |
4be42e1ca045
Simplify file-reading code in php-admin (Franky Van Liedekerke)
Ben Schmidt
parents:
762
diff
changeset
|
59 } |
309 | 60 |
61 $tpl->assign(array("NAME" => htmlentities($name), | |
62 "NICENAME" => htmlentities($nicename), | |
63 "TEXT" => htmlentities($text), | |
64 "VALUE" => htmlentities($value))); | |
65 | |
66 $tpl->parse("ROWS",".string"); | |
67 } | |
68 | |
69 function mlmmj_list($name, $nicename, $text) | |
70 { | |
71 global $tpl, $topdir, $list; | |
72 | |
73 $file = "$topdir/$list/control/$name"; | |
74 $value = ""; | |
75 | |
767
4be42e1ca045
Simplify file-reading code in php-admin (Franky Van Liedekerke)
Ben Schmidt
parents:
762
diff
changeset
|
76 if(is_file($file)) |
4be42e1ca045
Simplify file-reading code in php-admin (Franky Van Liedekerke)
Ben Schmidt
parents:
762
diff
changeset
|
77 $value = file_get_contents($file); |
309 | 78 |
79 $tpl->assign(array("NAME" => htmlentities($name), | |
80 "NICENAME" => htmlentities($nicename), | |
81 "TEXT" => htmlentities($text), | |
82 "VALUE" => htmlentities($value))); | |
83 | |
84 $tpl->parse("ROWS",".list"); | |
85 } | |
86 | |
503 | 87 // Perl's encode_entities (to be able to use tunables.pl) |
88 function encode_entities($str) { return htmlentities($str); } | |
89 | |
90 | |
710
6d354f3a8d90
Replaced class.FastTemplate.php with class.rFastTemplate.php in contrib/web/php-admin (Christoph Thiel)
mortenp
parents:
687
diff
changeset
|
91 $tpl = new rFastTemplate($templatedir); |
309 | 92 |
769 | 93 $list = $_GET["list"]; |
309 | 94 |
384 | 95 if(!isset($list)) |
96 die("no list specified"); | |
97 | |
762
dbb144f085a5
Fix php-admin to work when topdir contains a symlink (e.g. on Mac)
Ben Schmidt
parents:
759
diff
changeset
|
98 if (dirname(realpath($topdir."/".$list)) != realpath($topdir)) |
725
d92234debf5c
Better validation of input in php-admin (Thomas Goirand)
Ben Schmidt
parents:
722
diff
changeset
|
99 die("list outside topdir"); |
722
773c6ef6fb10
Validate input in php-admin to avoid altering arbitrary files
Ben Schmidt
parents:
710
diff
changeset
|
100 |
309 | 101 if(!is_dir($topdir."/".$list)) |
102 die("non-existent list"); | |
103 | |
104 $tpl->define(array("main" => "edit.html", | |
105 "boolean" => "edit_boolean.html", | |
106 "string" => "edit_string.html", | |
107 "list" => "edit_list.html")); | |
108 | |
109 $tpl->assign(array("LIST" =>htmlentities($list))); | |
110 | |
759
73c8715367fb
Better techniques for locating support files in php-admin
Ben Schmidt
parents:
733
diff
changeset
|
111 $tunables = file_get_contents($confdir.'/tunables.pl'); |
503 | 112 eval($tunables); |
309 | 113 |
114 $tpl->parse("MAIN","main"); | |
115 $tpl->FastPrint("MAIN"); | |
116 | |
117 ?> |