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