Source of trunk/cp_settings.php at revision 363 (05/07/2008 10:05:26, 10940 bytes, 277 lines, language: php) [download]:
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | ** Control Panel :: Settings Page |
| 5 | ** for CodewiseBlog Multi-User |
| 6 | ** |
| 7 | |
| 8 | ** Copyright (c) 2005-2008 Codewise.org |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | ** This file is part of CodewiseBlog |
| 13 | ** |
| 14 | ** CodewiseBlog is free software; you can redistribute it and/or modify |
| 15 | ** it under the terms of the GNU General Public License as published by |
| 16 | ** the Free Software Foundation; either version 2 of the License, or |
| 17 | ** (at your option) any later version. |
| 18 | ** |
| 19 | ** CodewiseBlog is distributed in the hope that it will be useful, |
| 20 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | ** GNU General Public License for more details. |
| 23 | ** |
| 24 | ** You should have received a copy of the GNU General Public License |
| 25 | ** along with CodewiseBlog; if not, write to the Free Software |
| 26 | ** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | */ |
| 28 | |
| 29 | $current = "settings"; |
| 30 | |
| 31 | if(BLOGID != 1) |
| 32 | { |
| 33 | $body = skinvoodoo("error","error",array("message"=>"You do not have permission to access this area of the control panel.")); |
| 34 | } elseif(empty($_POST)) { |
| 35 | global $ALLOWED_TAGS; |
| 36 | |
| 37 | $allowed_tags = ""; |
| 38 | foreach($ALLOWED_TAGS as $name => $attribs) |
| 39 | $allowed_tags .= "<$name>: " . implode(", ", $attribs) . "\n"; |
| 40 | |
| 41 | $body = skinvoodoo( |
| 42 | "controlpanel_settings", "", |
| 43 | array( |
| 44 | "posturl" => INDEX_URL . "?controlpanel:settings", |
| 45 | "fspath" => FSPATH, |
| 46 | "custom_url_enabled" => CUSTOM_URL_ENABLED, |
| 47 | "sample_url" => SUBDOMAIN_MODE ? "http://username." . BASE_DOMAIN . INSTALLED_PATH : "http://" . DEFAULT_SUBDOMAIN . BASE_DOMAIN . INSTALLED_PATH . "/username", |
| 48 | "main_url" => "http://" . (DEFAULT_SUBDOMAIN == "" ? "" : DEFAULT_SUBDOMAIN . "." ) . BASE_DOMAIN . INSTALLED_PATH, |
| 49 | "subdomain_mode" => SUBDOMAIN_MODE, |
| 50 | "base_domain" => BASE_DOMAIN, |
| 51 | "installed_path" => INSTALLED_PATH, |
| 52 | "default_subdomain" => DEFAULT_SUBDOMAIN, |
| 53 | "site_title" => SITE_TITLE, |
| 54 | "site_motto" => SITE_MOTTO, |
| 55 | "topics_per_page" => TOPICS_PER_PAGE, |
| 56 | "posts_per_page" => POSTS_PER_PAGE, |
| 57 | "shouts_per_page" => SHOUTS_PER_PAGE, |
| 58 | "date_format" => DATE_FORMAT, |
| 59 | "anonymous_name" => ANONYMOUS_NAME, |
| 60 | "email" => EMAIL, |
| 61 | "sql_admin_email" => SQL_ADMIN_EMAIL, |
| 62 | "sql_host" => SQL_HOST, |
| 63 | "sql_user" => SQL_USER, |
| 64 | "sql_pass" => SQL_PASS, |
| 65 | "sql_db" => SQL_DB, |
| 66 | "allowed_tags" => $allowed_tags, |
| 67 | "imageverify" => IMAGEVERIFY, |
| 68 | ) |
| 69 | ); |
| 70 | } else { |
| 71 | |
| 72 | $file = file_get_contents(SETTINGS_FILE); |
| 73 | |
| 74 | $applied = array(); |
| 75 | |
| 76 | $filenew = preg_replace( |
| 77 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)FSPATH)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(FSPATH)) . ")\\3\\s*\\);/is", |
| 78 | "define('FSPATH', '" . $_POST['fspath'] . "');", |
| 79 | $file); |
| 80 | if($file != $filenew) |
| 81 | $applied[] = "FSPATH"; |
| 82 | $file = $filenew; |
| 83 | |
| 84 | $filenew = preg_replace( |
| 85 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)CUSTOM_URL_ENABLED)\\1,\\s*" . (CUSTOM_URL_ENABLED ? "TRUE" : "FALSE") . "\\s*\\);/is", |
| 86 | "define('CUSTOM_URL_ENABLED', " . $_POST['custom_url_enabled'] . ");", |
| 87 | $file); |
| 88 | if($file != $filenew) |
| 89 | $applied[] = "CUSTOM_URL_ENABLED"; |
| 90 | $file = $filenew; |
| 91 | |
| 92 | $filenew = preg_replace( |
| 93 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SUBDOMAIN_MODE)\\1,\\s*" . (SUBDOMAIN_MODE ? "TRUE" : "FALSE") . "\\s*\\);/is", |
| 94 | "define('SUBDOMAIN_MODE', " . $_POST['subdomain_mode'] . ");", |
| 95 | $file); |
| 96 | if($file != $filenew) |
| 97 | $applied[] = "SUBDOMAIN_MODE"; |
| 98 | $file = $filenew; |
| 99 | |
| 100 | $filenew = preg_replace( |
| 101 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)BASE_DOMAIN)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(BASE_DOMAIN)) . ")\\3\\s*\\);/is", |
| 102 | "define('BASE_DOMAIN', '" . $_POST['base_domain'] . "');", |
| 103 | $file); |
| 104 | if($file != $filenew) |
| 105 | $applied[] = "BASE_DOMAIN"; |
| 106 | $file = $filenew; |
| 107 | |
| 108 | $filenew = preg_replace( |
| 109 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)INSTALLED_PATH)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(INSTALLED_PATH)) . ")\\3\\s*\\);/is", |
| 110 | "define('INSTALLED_PATH', '" . $_POST['installed_path'] . "');", |
| 111 | $file); |
| 112 | if($file != $filenew) |
| 113 | $applied[] = "INSTALLED_PATH"; |
| 114 | $file = $filenew; |
| 115 | |
| 116 | $filenew = preg_replace( |
| 117 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)DEFAULT_SUBDOMAIN)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(DEFAULT_SUBDOMAIN)) . ")\\3\\s*\\);/is", |
| 118 | "define('DEFAULT_SUBDOMAIN', '" . $_POST['default_subdomain'] . "');", |
| 119 | $file); |
| 120 | if($file != $filenew) |
| 121 | $applied[] = "DEFAULT_SUBDOMAIN"; |
| 122 | $file = $filenew; |
| 123 | |
| 124 | $filenew = preg_replace( |
| 125 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SITE_TITLE)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SITE_TITLE)) . ")\\3\\s*\\);/is", |
| 126 | "define('SITE_TITLE', '" . $_POST['site_title'] . "');", |
| 127 | $file); |
| 128 | if($file != $filenew) |
| 129 | $applied[] = "TOPICS_PER_PAGE"; |
| 130 | $file = $filenew; |
| 131 | |
| 132 | $filenew = preg_replace( |
| 133 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SITE_MOTTO)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SITE_MOTTO)) . ")\\3\\s*\\);/is", |
| 134 | "define('SITE_MOTTO', '" . $_POST['site_motto'] . "');", |
| 135 | $file); |
| 136 | if($file != $filenew) |
| 137 | $applied[] = "SITE_MOTTO"; |
| 138 | $file = $filenew; |
| 139 | |
| 140 | $filenew = preg_replace( |
| 141 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)TOPICS_PER_PAGE)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(TOPICS_PER_PAGE)) . ")\\3\\s*\\);/is", |
| 142 | "define('TOPICS_PER_PAGE', '" . $_POST['topics_per_page'] . "');", |
| 143 | $file); |
| 144 | if($file != $filenew) |
| 145 | $applied[] = "TOPICS_PER_PAGE"; |
| 146 | $file = $filenew; |
| 147 | |
| 148 | $filenew = preg_replace( |
| 149 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)POSTS_PER_PAGE)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(POSTS_PER_PAGE)) . ")\\3\\s*\\);/is", |
| 150 | "define('POSTS_PER_PAGE', '" . $_POST['posts_per_page'] . "');", |
| 151 | $file); |
| 152 | if($file != $filenew) |
| 153 | $applied[] = "POSTS_PER_PAGE"; |
| 154 | $file = $filenew; |
| 155 | |
| 156 | $filenew = preg_replace( |
| 157 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SHOUTS_PER_PAGE)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SHOUTS_PER_PAGE)) . ")\\3\\s*\\);/is", |
| 158 | "define('SHOUTS_PER_PAGE', '" . $_POST['shouts_per_page'] . "');", |
| 159 | $file); |
| 160 | if($file != $filenew) |
| 161 | $applied[] = "SHOUTS_PER_PAGE"; |
| 162 | $file = $filenew; |
| 163 | |
| 164 | $filenew = preg_replace( |
| 165 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)DATE_FORMAT)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(DATE_FORMAT)) . ")\\3\\s*\\);/is", |
| 166 | "define('DATE_FORMAT', '" . $_POST['date_format'] . "');", |
| 167 | $file); |
| 168 | if($file != $filenew) |
| 169 | $applied[] = "DATE_FORMAT"; |
| 170 | $file = $filenew; |
| 171 | |
| 172 | $filenew = preg_replace( |
| 173 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)ANONYMOUS_NAME)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(ANONYMOUS_NAME)) . ")\\3\\s*\\);/is", |
| 174 | "define('ANONYMOUS_NAME', '" . $_POST['anonymous_name'] . "');", |
| 175 | $file); |
| 176 | if($file != $filenew) |
| 177 | $applied[] = "ANONYMOUS_NAME"; |
| 178 | $file = $filenew; |
| 179 | |
| 180 | $filenew = preg_replace( |
| 181 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)EMAIL)\\1,\\s*" . (EMAIL ? "TRUE" : "FALSE") . "\\s*\\);/is", |
| 182 | "define('EMAIL', " . $_POST['email'] . ");", |
| 183 | $file); |
| 184 | if($file != $filenew) |
| 185 | $applied[] = "EMAIL"; |
| 186 | $file = $filenew; |
| 187 | |
| 188 | $filenew = preg_replace( |
| 189 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SQL_ADMIN_EMAIL)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SQL_ADMIN_EMAIL)) . ")\\3\\s*\\);/is", |
| 190 | "define('SQL_ADMIN_EMAIL', '" . $_POST['sql_admin_email'] . "');", |
| 191 | $file); |
| 192 | if($file != $filenew) |
| 193 | $applied[] = "SQL_ADMIN_EMAIL"; |
| 194 | $file = $filenew; |
| 195 | |
| 196 | $filenew = preg_replace( |
| 197 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SQL_HOST)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SQL_HOST)) . ")\\3\\s*\\);/is", |
| 198 | "define('SQL_HOST', '" . $_POST['sql_host'] . "');", |
| 199 | $file); |
| 200 | if($file != $filenew) |
| 201 | $applied[] = "SQL_HOST"; |
| 202 | $file = $filenew; |
| 203 | |
| 204 | $filenew = preg_replace( |
| 205 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SQL_USER)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SQL_USER)) . ")\\3\\s*\\);/is", |
| 206 | "define('SQL_USER', '" . $_POST['sql_user'] . "');", |
| 207 | $file); |
| 208 | if($file != $filenew) |
| 209 | $applied[] = "SQL_USER"; |
| 210 | $file = $filenew; |
| 211 | |
| 212 | $filenew = preg_replace( |
| 213 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SQL_PASS)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SQL_PASS)) . ")\\3\\s*\\);/is", |
| 214 | "define('SQL_PASS', '" . $_POST['sql_pass'] . "');", |
| 215 | $file); |
| 216 | if($file != $filenew) |
| 217 | $applied[] = "SQL_PASS"; |
| 218 | $file = $filenew; |
| 219 | |
| 220 | $filenew = preg_replace( |
| 221 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)SQL_DB)\\1,\\s*(['\"])((?-i)" . str_replace("/", "\\/", quotemeta(SQL_DB)) . ")\\3\\s*\\);/is", |
| 222 | "define('SQL_DB', '" . $_POST['sql_db'] . "');", |
| 223 | $file); |
| 224 | if($file != $filenew) |
| 225 | $applied[] = "SQL_DB"; |
| 226 | $file = $filenew; |
| 227 | |
| 228 | $filenew = preg_replace( |
| 229 | "/(?<=\\s)define\\(\\s*(['\"])((?-i)IMAGEVERIFY)\\1,\\s*" . (IMAGEVERIFY ? "TRUE" : "FALSE") . "\\s*\\);/is", |
| 230 | "define('IMAGEVERIFY', " . $_POST['imageverify'] . ");", |
| 231 | $file); |
| 232 | if($file != $filenew) |
| 233 | $applied[] = "IMAGEVERIFY"; |
| 234 | $file = $filenew; |
| 235 | |
| 236 | $new_php_array = "\$ALLOWED_TAGS = array\n(\n"; |
| 237 | $lines = explode("\n", $_POST['allowed_tags']); |
| 238 | foreach($lines as $line) |
| 239 | { |
| 240 | $tagname = substr($line, 1, strpos($line, ":") - 2); |
| 241 | |
| 242 | $attribs = substr($line, strpos($line, ":") + 2); |
| 243 | $attribs_array = explode(", ", $attribs); |
| 244 | |
| 245 | foreach($attribs_array as $i => $text) |
| 246 | $attribs_array[$i] = trim($text); |
| 247 | |
| 248 | if($tagname == "") |
| 249 | continue; |
| 250 | elseif(count($attribs_array) == 0 || empty($attribs_array[0])) |
| 251 | $new_php_array .= " '$tagname' => array(),\n"; |
| 252 | else |
| 253 | $new_php_array .= " '$tagname' => array('" . implode("', '", $attribs_array) . "'),\n"; |
| 254 | } |
| 255 | $new_php_array .= ");"; |
| 256 | |
| 257 | $filenew = preg_replace("/\\\$ALLOWED_TAGS = array\n\\(.*\\);/s", $new_php_array, $file); |
| 258 | if($file != $filenew) |
| 259 | $applied[] = "ALLOWED_TAGS"; |
| 260 | $file = $filenew; |
| 261 | |
| 262 | if(count($applied)) |
| 263 | { |
| 264 | $message = ""; |
| 265 | foreach($applied as $configvar) |
| 266 | $message .= "changed value of $configvar<br />"; |
| 267 | } else { |
| 268 | $message = "No config values changed."; |
| 269 | } |
| 270 | |
| 271 | file_put_contents(SETTINGS_FILE, $file); |
| 272 | |
| 273 | $body = skinvoodoo("error", "notify", array("message" => $message)) . "<a href=\"" . INDEX_URL . "?controlpanel:settings\">Back to Settings</a>"; |
| 274 | } |
| 275 | |
| 276 | ?> |
| 277 |