author | Dan |
Wed, 25 Jul 2007 18:09:21 -0400 | |
changeset 75 | 1f85c1c609fd |
parent 73 | 0a74676a2f2f |
child 76 | 608dee512bf0 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
69
diff
changeset
|
2 |
|
0 | 3 |
/* |
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
69
diff
changeset
|
5 |
* Version 1.0.1 (Loch Ness) |
0 | 6 |
* Copyright (C) 2006-2007 Dan Fuhry |
7 |
* |
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 |
*/ |
|
14 |
||
15 |
require('includes/common.php'); |
|
16 |
||
17 |
global $db, $session, $paths, $template, $plugins; // Common objects |
|
18 |
if(!isset($_GET['_mode'])) die('This script cannot be accessed directly.'); |
|
19 |
||
20 |
$_ob = ''; |
|
21 |
||
22 |
switch($_GET['_mode']) { |
|
23 |
case "checkusername": |
|
24 |
echo PageUtils::checkusername($_GET['name']); |
|
25 |
break; |
|
26 |
case "getsource": |
|
27 |
$p = ( isset($_GET['pagepass']) ) ? $_GET['pagepass'] : false; |
|
28 |
echo PageUtils::getsource($paths->page, $p); |
|
29 |
break; |
|
30 |
case "getpage": |
|
31 |
// echo PageUtils::getpage($paths->page, false, ( (isset($_GET['oldid'])) ? $_GET['oldid'] : false )); |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
32 |
$revision_id = ( (isset($_GET['oldid'])) ? intval($_GET['oldid']) : 0 ); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
33 |
$page = new PageProcessor( $paths->cpage['urlname_nons'], $paths->namespace, $revision_id ); |
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
34 |
|
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
35 |
$pagepass = ( isset($_REQUEST['pagepass']) ) ? $_REQUEST['pagepass'] : ''; |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
36 |
$page->password = $pagepass; |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
37 |
|
0 | 38 |
$page->send(); |
39 |
break; |
|
40 |
case "savepage": |
|
41 |
$summ = ( isset($_POST['summary']) ) ? $_POST['summary'] : ''; |
|
42 |
$minor = isset($_POST['minor']); |
|
43 |
$e = PageUtils::savepage($paths->cpage['urlname_nons'], $paths->namespace, $_POST['text'], $summ, $minor); |
|
44 |
if($e=='good') |
|
45 |
{ |
|
46 |
$page = new PageProcessor($paths->cpage['urlname_nons'], $paths->namespace); |
|
47 |
$page->send(); |
|
48 |
} |
|
49 |
else |
|
50 |
{ |
|
51 |
echo 'Error saving the page: '.$e; |
|
52 |
} |
|
53 |
break; |
|
54 |
case "protect": |
|
55 |
echo PageUtils::protect($paths->cpage['urlname_nons'], $paths->namespace, (int)$_POST['level'], $_POST['reason']); |
|
56 |
break; |
|
57 |
case "histlist": |
|
58 |
echo PageUtils::histlist($paths->cpage['urlname_nons'], $paths->namespace); |
|
59 |
break; |
|
60 |
case "rollback": |
|
61 |
echo PageUtils::rollback( (int)$_GET['id'] ); |
|
62 |
break; |
|
63 |
case "comments": |
|
64 |
$comments = new Comments($paths->cpage['urlname_nons'], $paths->namespace); |
|
65 |
if ( isset($_POST['data']) ) |
|
66 |
{ |
|
67 |
$comments->process_json($_POST['data']); |
|
68 |
} |
|
69 |
else |
|
70 |
{ |
|
71 |
die('{ "mode" : "error", "error" : "No input" }'); |
|
72 |
} |
|
73 |
break; |
|
74 |
case "rename": |
|
75 |
echo PageUtils::rename($paths->cpage['urlname_nons'], $paths->namespace, $_POST['newtitle']); |
|
76 |
break; |
|
77 |
case "flushlogs": |
|
78 |
echo PageUtils::flushlogs($paths->cpage['urlname_nons'], $paths->namespace); |
|
79 |
break; |
|
80 |
case "deletepage": |
|
28 | 81 |
$reason = ( isset($_POST['reason']) ) ? $_POST['reason'] : false; |
82 |
if ( empty($reason) ) |
|
83 |
die('Please enter a reason for deleting this page.'); |
|
84 |
echo PageUtils::deletepage($paths->cpage['urlname_nons'], $paths->namespace, $reason); |
|
0 | 85 |
break; |
86 |
case "delvote": |
|
87 |
echo PageUtils::delvote($paths->cpage['urlname_nons'], $paths->namespace); |
|
88 |
break; |
|
89 |
case "resetdelvotes": |
|
90 |
echo PageUtils::resetdelvotes($paths->cpage['urlname_nons'], $paths->namespace); |
|
91 |
break; |
|
92 |
case "getstyles": |
|
93 |
echo PageUtils::getstyles($_GET['id']); |
|
94 |
break; |
|
95 |
case "catedit": |
|
96 |
echo PageUtils::catedit($paths->cpage['urlname_nons'], $paths->namespace); |
|
97 |
break; |
|
98 |
case "catsave": |
|
99 |
echo PageUtils::catsave($paths->cpage['urlname_nons'], $paths->namespace, $_POST); |
|
100 |
break; |
|
101 |
case "setwikimode": |
|
102 |
echo PageUtils::setwikimode($paths->cpage['urlname_nons'], $paths->namespace, (int)$_GET['mode']); |
|
103 |
break; |
|
104 |
case "setpass": |
|
105 |
echo PageUtils::setpass($paths->cpage['urlname_nons'], $paths->namespace, $_POST['password']); |
|
106 |
break; |
|
107 |
case "wikihelp": |
|
36
425261984266
Added "page hint" on search page; deprecated "www." on EnanoCMS.org links
Dan
parents:
33
diff
changeset
|
108 |
$html = file_get_contents('http://enanocms.org/ajax.php?title=Help:Wiki_formatting&_mode=getpage&nofooters'); |
425261984266
Added "page hint" on search page; deprecated "www." on EnanoCMS.org links
Dan
parents:
33
diff
changeset
|
109 |
$html = str_replace('src="/Special', 'src="http://enanocms.org/Special', $html); |
0 | 110 |
echo '<div class="contentDiv"><h2>Wiki formatting guide</h2>'.$html.'</div>'; |
111 |
break; |
|
112 |
case "fillusername": |
|
113 |
$name = (isset($_GET['name'])) ? $db->escape($_GET['name']) : false; |
|
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
114 |
if ( !$name ) |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
115 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
116 |
die('userlist = new Array(); errorstring=\'Invalid URI\''); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
117 |
} |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
118 |
$q = $db->sql_query('SELECT username,user_id FROM '.table_prefix.'users WHERE lcase(username) LIKE lcase(\'%'.$name.'%\');'); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
119 |
if ( !$q ) |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
120 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
121 |
die('userlist = new Array(); errorstring=\'MySQL error selecting username data: '.addslashes(mysql_error()).'\''); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
122 |
} |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
123 |
if($db->numrows() < 1) |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
124 |
{ |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
125 |
die('userlist = new Array(); errorstring=\'No usernames found\';'); |
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
126 |
} |
0 | 127 |
echo 'var errorstring = false; userlist = new Array();'; |
32
4d87aad3c4c0
Finished everything on the TODO list (yay!); several CSS cleanups; tons more changes in this commit - see the patch for details
Dan
parents:
29
diff
changeset
|
128 |
$i = 0; |
0 | 129 |
while($r = $db->fetchrow()) |
130 |
{ |
|
131 |
echo "userlist[$i] = '".addslashes($r['username'])."'; "; |
|
132 |
$i++; |
|
133 |
} |
|
134 |
$db->free_result(); |
|
135 |
break; |
|
136 |
case "fillpagename": |
|
137 |
$name = (isset($_GET['name'])) ? $_GET['name'] : false; |
|
138 |
if(!$name) die('userlist = new Array(); namelist = new Array(); errorstring=\'Invalid URI\''); |
|
139 |
$nd = RenderMan::strToPageID($name); |
|
140 |
$c = 0; |
|
141 |
$u = Array(); |
|
142 |
$n = Array(); |
|
22
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
143 |
|
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
144 |
$name = sanitize_page_id($name); |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
145 |
$name = str_replace('_', ' ', $name); |
d0314575e2f0
More preliminary l10n work; userpage portal style basics implemented
Dan
parents:
21
diff
changeset
|
146 |
|
0 | 147 |
for($i=0;$i<sizeof($paths->pages)/2;$i++) |
148 |
{ |
|
149 |
if( ( |
|
150 |
preg_match('#'.preg_quote($name).'(.*)#i', $paths->pages[$i]['name']) || |
|
151 |
preg_match('#'.preg_quote($name).'(.*)#i', $paths->pages[$i]['urlname']) || |
|
152 |
preg_match('#'.preg_quote($name).'(.*)#i', $paths->pages[$i]['urlname_nons']) || |
|
153 |
preg_match('#'.preg_quote(str_replace(' ', '_', $name)).'(.*)#i', $paths->pages[$i]['name']) || |
|
154 |
preg_match('#'.preg_quote(str_replace(' ', '_', $name)).'(.*)#i', $paths->pages[$i]['urlname']) || |
|
155 |
preg_match('#'.preg_quote(str_replace(' ', '_', $name)).'(.*)#i', $paths->pages[$i]['urlname_nons']) |
|
156 |
) && |
|
157 |
( ( $nd[1] != 'Article' && $paths->pages[$i]['namespace'] == $nd[1] ) || $nd[1] == 'Article' ) |
|
158 |
&& $paths->pages[$i]['visible'] |
|
159 |
) |
|
160 |
{ |
|
161 |
$c++; |
|
162 |
$u[] = $paths->pages[$i]['name']; |
|
163 |
$n[] = $paths->pages[$i]['urlname']; |
|
164 |
} |
|
165 |
} |
|
166 |
if($c > 0) |
|
167 |
{ |
|
168 |
echo 'userlist = new Array(); namelist = new Array(); errorstring = false; '."\n"; |
|
169 |
for($i=0;$i<sizeof($u);$i++) // Can't use foreach because we need the value of $i and we need to use both $u and $n |
|
170 |
{ |
|
171 |
echo "userlist[$i] = '".addslashes($n[$i])."';\n"; |
|
172 |
echo "namelist[$i] = '".addslashes($u[$i])."';\n"; |
|
173 |
} |
|
174 |
} else { |
|
175 |
die('userlist = new Array(); namelist = new Array(); errorstring=\'No page matches found.\''); |
|
176 |
} |
|
177 |
break; |
|
178 |
case "preview": |
|
179 |
echo PageUtils::genPreview($_POST['text']); |
|
180 |
break; |
|
181 |
case "pagediff": |
|
182 |
$id1 = ( isset($_GET['diff1']) ) ? (int)$_GET['diff1'] : false; |
|
183 |
$id2 = ( isset($_GET['diff2']) ) ? (int)$_GET['diff2'] : false; |
|
184 |
if(!$id1 || !$id2) { echo '<p>Invalid request.</p>'; $template->footer(); break; } |
|
185 |
if(!preg_match('#^([0-9]+)$#', (string)$_GET['diff1']) || |
|
186 |
!preg_match('#^([0-9]+)$#', (string)$_GET['diff2'] )) { echo '<p>SQL injection attempt</p>'; $template->footer(); break; } |
|
187 |
echo PageUtils::pagediff($paths->cpage['urlname_nons'], $paths->namespace, $id1, $id2); |
|
188 |
break; |
|
189 |
case "jsres": |
|
190 |
die('// ERROR: this section is deprecated and has moved to includes/clientside/static/enano-lib-basic.js.'); |
|
191 |
break; |
|
192 |
case "rdns": |
|
193 |
if(!$session->get_permissions('mod_misc')) die('Go somewhere else for your reverse DNS info!'); |
|
194 |
$ip = $_GET['ip']; |
|
195 |
$rdns = gethostbyaddr($ip); |
|
196 |
if($rdns == $ip) echo 'Unable to get reverse DNS information. Perhaps the IP address does not exist anymore.'; |
|
197 |
else echo $rdns; |
|
198 |
break; |
|
199 |
case 'acljson': |
|
200 |
$parms = ( isset($_POST['acl_params']) ) ? rawurldecode($_POST['acl_params']) : false; |
|
201 |
echo PageUtils::acl_json($parms); |
|
202 |
break; |
|
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
203 |
case "change_theme": |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
204 |
if ( !isset($_POST['theme_id']) || !isset($_POST['style_id']) ) |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
205 |
{ |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
206 |
die('Invalid input'); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
207 |
} |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
208 |
if ( !preg_match('/^([a-z0-9_-]+)$/i', $_POST['theme_id']) || !preg_match('/^([a-z0-9_-]+)$/i', $_POST['style_id']) ) |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
209 |
{ |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
210 |
die('Invalid input'); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
211 |
} |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
212 |
if ( !file_exists(ENANO_ROOT . '/themes/' . $_POST['theme_id'] . '/css/' . $_POST['style_id'] . '.css') ) |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
213 |
{ |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
214 |
die('Can\'t find theme file: ' . ENANO_ROOT . '/themes/' . $_POST['theme_id'] . '/css/' . $_POST['style_id'] . '.css'); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
215 |
} |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
216 |
if ( !$session->user_logged_in ) |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
217 |
{ |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
218 |
die('You must be logged in to change your theme'); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
219 |
} |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
220 |
// Just in case something slipped through... |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
221 |
$theme_id = $db->escape($_POST['theme_id']); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
222 |
$style_id = $db->escape($_POST['style_id']); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
223 |
$e = $db->sql_query('UPDATE ' . table_prefix . "users SET theme='$theme_id', style='$style_id' WHERE user_id=$session->user_id;"); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
224 |
if ( !$e ) |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
225 |
die( $db->get_error() ); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
226 |
die('GOOD'); |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
28
diff
changeset
|
227 |
break; |
0 | 228 |
default: |
229 |
die('Hacking attempt'); |
|
230 |
break; |
|
231 |
} |
|
232 |
||
233 |
?> |