[354] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[2213] | 5 | // | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[354] | 6 | // +-----------------------------------------------------------------------+ |
---|
[1598] | 7 | // | file : $Id: common.inc.php 2213 2008-02-16 13:27:50Z rub $ |
---|
[354] | 8 | // | last update : $Date: 2008-02-16 13:27:50 +0000 (Sat, 16 Feb 2008) $ |
---|
| 9 | // | last modifier : $Author: rub $ |
---|
| 10 | // | revision : $Revision: 2213 $ |
---|
| 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 13 | // | it under the terms of the GNU General Public License as published by | |
---|
| 14 | // | the Free Software Foundation | |
---|
| 15 | // | | |
---|
| 16 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 19 | // | General Public License for more details. | |
---|
| 20 | // | | |
---|
| 21 | // | You should have received a copy of the GNU General Public License | |
---|
| 22 | // | along with this program; if not, write to the Free Software | |
---|
| 23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 24 | // | USA. | |
---|
| 25 | // +-----------------------------------------------------------------------+ |
---|
[383] | 26 | |
---|
[650] | 27 | if (!defined('PHPWG_ROOT_PATH')) |
---|
[364] | 28 | { |
---|
[650] | 29 | die('Hacking attempt!'); |
---|
[364] | 30 | } |
---|
| 31 | // determine the initial instant to indicate the generation time of this page |
---|
[354] | 32 | $t1 = explode( ' ', microtime() ); |
---|
| 33 | $t2 = explode( '.', $t1[0] ); |
---|
| 34 | $t2 = $t1[1].'.'.$t2[1]; |
---|
| 35 | |
---|
| 36 | set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
---|
| 37 | |
---|
| 38 | // |
---|
[359] | 39 | // addslashes to vars if magic_quotes_gpc is off this is a security |
---|
| 40 | // precaution to prevent someone trying to break out of a SQL statement. |
---|
[354] | 41 | // |
---|
| 42 | if( !get_magic_quotes_gpc() ) |
---|
| 43 | { |
---|
[359] | 44 | if( is_array( $_GET ) ) |
---|
[354] | 45 | { |
---|
[359] | 46 | while( list($k, $v) = each($_GET) ) |
---|
[354] | 47 | { |
---|
[359] | 48 | if( is_array($_GET[$k]) ) |
---|
| 49 | { |
---|
| 50 | while( list($k2, $v2) = each($_GET[$k]) ) |
---|
[354] | 51 | { |
---|
[359] | 52 | $_GET[$k][$k2] = addslashes($v2); |
---|
| 53 | } |
---|
| 54 | @reset($_GET[$k]); |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { |
---|
| 58 | $_GET[$k] = addslashes($v); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | @reset($_GET); |
---|
[354] | 62 | } |
---|
[1092] | 63 | |
---|
[359] | 64 | if( is_array($_POST) ) |
---|
[354] | 65 | { |
---|
[359] | 66 | while( list($k, $v) = each($_POST) ) |
---|
| 67 | { |
---|
| 68 | if( is_array($_POST[$k]) ) |
---|
| 69 | { |
---|
| 70 | while( list($k2, $v2) = each($_POST[$k]) ) |
---|
| 71 | { |
---|
| 72 | $_POST[$k][$k2] = addslashes($v2); |
---|
| 73 | } |
---|
| 74 | @reset($_POST[$k]); |
---|
| 75 | } |
---|
| 76 | else |
---|
| 77 | { |
---|
| 78 | $_POST[$k] = addslashes($v); |
---|
| 79 | } |
---|
[354] | 80 | } |
---|
[359] | 81 | @reset($_POST); |
---|
[354] | 82 | } |
---|
| 83 | |
---|
[359] | 84 | if( is_array($_COOKIE) ) |
---|
[354] | 85 | { |
---|
[359] | 86 | while( list($k, $v) = each($_COOKIE) ) |
---|
[354] | 87 | { |
---|
[359] | 88 | if( is_array($_COOKIE[$k]) ) |
---|
| 89 | { |
---|
| 90 | while( list($k2, $v2) = each($_COOKIE[$k]) ) |
---|
| 91 | { |
---|
| 92 | $_COOKIE[$k][$k2] = addslashes($v2); |
---|
| 93 | } |
---|
| 94 | @reset($_COOKIE[$k]); |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | $_COOKIE[$k] = addslashes($v); |
---|
| 99 | } |
---|
[354] | 100 | } |
---|
[359] | 101 | @reset($_COOKIE); |
---|
[354] | 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // |
---|
[359] | 106 | // Define some basic configuration arrays this also prevents malicious |
---|
| 107 | // rewriting of language and otherarray values via URI params |
---|
[354] | 108 | // |
---|
| 109 | $conf = array(); |
---|
| 110 | $page = array(); |
---|
| 111 | $user = array(); |
---|
| 112 | $lang = array(); |
---|
[1414] | 113 | $header_msgs = array(); |
---|
[1677] | 114 | $header_notes = array(); |
---|
[2111] | 115 | $filter = array(); |
---|
[354] | 116 | |
---|
[766] | 117 | @include(PHPWG_ROOT_PATH .'include/mysql.inc.php'); |
---|
[650] | 118 | if (!defined('PHPWG_INSTALLED')) |
---|
[354] | 119 | { |
---|
[650] | 120 | header('Location: install.php'); |
---|
[359] | 121 | exit; |
---|
[354] | 122 | } |
---|
| 123 | |
---|
[1744] | 124 | foreach( array( |
---|
| 125 | 'array_intersect_key', //PHP 5 >= 5.1.0RC1 |
---|
| 126 | 'hash_hmac', //(hash) - enabled by default as of PHP 5.1.2 |
---|
[2213] | 127 | 'preg_last_error', // PHP 5 >= 5.2.0 |
---|
[1744] | 128 | ) as $func) |
---|
| 129 | { |
---|
| 130 | if (!function_exists($func)) |
---|
| 131 | { |
---|
| 132 | include_once(PHPWG_ROOT_PATH . 'include/php_compat/'.$func.'.php'); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
[770] | 136 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
| 137 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
[808] | 138 | include(PHPWG_ROOT_PATH . 'include/constants.php'); |
---|
[364] | 139 | include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); |
---|
| 140 | include(PHPWG_ROOT_PATH . 'include/template.php'); |
---|
| 141 | |
---|
[354] | 142 | // Database connection |
---|
[681] | 143 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) |
---|
[512] | 144 | or die ( "Could not connect to database server" ); |
---|
[681] | 145 | mysql_select_db( $cfgBase ) |
---|
[359] | 146 | or die ( "Could not connect to database" ); |
---|
[953] | 147 | |
---|
[2127] | 148 | defined('PWG_CHARSET') and defined('DB_CHARSET') |
---|
| 149 | or die('PWG_CHARSET and/or DB_CHARSET is not defined'); |
---|
| 150 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) |
---|
| 151 | { |
---|
| 152 | if (DB_CHARSET!='') |
---|
| 153 | { |
---|
| 154 | pwg_query('SET NAMES "'.DB_CHARSET.'"'); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | if ( strtolower(PWG_CHARSET)!='iso-8859-1' ) |
---|
| 160 | { |
---|
| 161 | die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info()); |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
[354] | 165 | // |
---|
[394] | 166 | // Setup gallery wide options, if this fails then we output a CRITICAL_ERROR |
---|
| 167 | // since basic gallery information is not available |
---|
[354] | 168 | // |
---|
[1284] | 169 | load_conf_from_db(); |
---|
[1655] | 170 | load_plugins(); |
---|
[354] | 171 | |
---|
[650] | 172 | include(PHPWG_ROOT_PATH.'include/user.inc.php'); |
---|
[808] | 173 | |
---|
[1568] | 174 | |
---|
[808] | 175 | // language files |
---|
[2126] | 176 | load_language('common.lang'); |
---|
[808] | 177 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
| 178 | { |
---|
[2126] | 179 | load_language('admin.lang'); |
---|
[808] | 180 | } |
---|
[1699] | 181 | trigger_action('loading_lang'); |
---|
[2126] | 182 | load_language('local.lang'); |
---|
[808] | 183 | |
---|
[1568] | 184 | // only now we can set the localized username of the guest user (and not in |
---|
| 185 | // include/user.inc.php) |
---|
[2029] | 186 | if (is_a_guest()) |
---|
[1568] | 187 | { |
---|
[2201] | 188 | $user['username'] = l10n('guest'); |
---|
[1568] | 189 | } |
---|
| 190 | |
---|
| 191 | // template instance |
---|
[2117] | 192 | if |
---|
[2038] | 193 | ( |
---|
[2117] | 194 | defined('IN_ADMIN') and IN_ADMIN and |
---|
[2038] | 195 | isset($user['admin_template']) and |
---|
| 196 | isset($user['admin_theme']) |
---|
| 197 | ) |
---|
| 198 | { |
---|
| 199 | // Admin template |
---|
| 200 | $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['admin_template'], $user['admin_theme'] ); |
---|
| 201 | } |
---|
| 202 | else |
---|
| 203 | { |
---|
| 204 | // Classic template |
---|
| 205 | $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme'] ); |
---|
| 206 | } |
---|
[1568] | 207 | |
---|
[2055] | 208 | if (isset($user['internal_status']['guest_must_be_guest']) |
---|
| 209 | and |
---|
| 210 | $user['internal_status']['guest_must_be_guest'] === true) |
---|
| 211 | { |
---|
| 212 | $header_msgs[] = l10n('guest_must_be_guest'); |
---|
| 213 | } |
---|
| 214 | |
---|
[1036] | 215 | if ($conf['gallery_locked']) |
---|
| 216 | { |
---|
[2201] | 217 | $header_msgs[] = l10n('gallery_locked_message'); |
---|
[1036] | 218 | |
---|
[1692] | 219 | if ( script_basename() != 'identification' and !is_admin() ) |
---|
[1036] | 220 | { |
---|
[2046] | 221 | set_status_header(503, 'Service Unavailable'); |
---|
| 222 | @header('Retry-After: 900'); |
---|
[2201] | 223 | echo l10n('gallery_locked_message') |
---|
[1750] | 224 | .'<a href="'.get_absolute_root_url(false).'identification.php">.</a>'; |
---|
[1036] | 225 | exit(); |
---|
| 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
[1568] | 229 | if ($conf['check_upgrade_feed'] |
---|
| 230 | and defined('PHPWG_IN_UPGRADE') |
---|
| 231 | and PHPWG_IN_UPGRADE) |
---|
[1377] | 232 | { |
---|
[1578] | 233 | |
---|
[1568] | 234 | // retrieve already applied upgrades |
---|
| 235 | $query = ' |
---|
| 236 | SELECT id |
---|
| 237 | FROM '.UPGRADE_TABLE.' |
---|
| 238 | ;'; |
---|
| 239 | $applied = array_from_query($query, 'id'); |
---|
| 240 | |
---|
| 241 | // retrieve existing upgrades |
---|
| 242 | $existing = get_available_upgrade_ids(); |
---|
| 243 | |
---|
| 244 | // which upgrades need to be applied? |
---|
| 245 | if (count(array_diff($existing, $applied)) > 0) |
---|
| 246 | { |
---|
| 247 | $header_msgs[] = 'Some database upgrades are missing, ' |
---|
[1750] | 248 | .'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>'; |
---|
[1568] | 249 | } |
---|
[1377] | 250 | } |
---|
[960] | 251 | |
---|
[1303] | 252 | if (is_adviser()) |
---|
| 253 | { |
---|
[2201] | 254 | $header_msgs[] = l10n('adviser_mode_enabled'); |
---|
[1303] | 255 | } |
---|
| 256 | |
---|
[1414] | 257 | if (count($header_msgs) > 0) |
---|
[1380] | 258 | { |
---|
[1414] | 259 | $template->assign_block_vars('header_msgs',array()); |
---|
| 260 | foreach ($header_msgs as $header_msg) |
---|
[1380] | 261 | { |
---|
[1418] | 262 | $template->assign_block_vars('header_msgs.header_msg', |
---|
| 263 | array('HEADER_MSG'=>$header_msg)); |
---|
[1380] | 264 | } |
---|
| 265 | } |
---|
[1598] | 266 | |
---|
[1722] | 267 | if (!empty($conf['filter_pages']) and get_filter_page_value('used')) |
---|
[1677] | 268 | { |
---|
| 269 | include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php'); |
---|
| 270 | include(PHPWG_ROOT_PATH.'include/filter.inc.php'); |
---|
| 271 | } |
---|
[1722] | 272 | else |
---|
| 273 | { |
---|
| 274 | $filter['enabled'] = false; |
---|
| 275 | } |
---|
[1677] | 276 | |
---|
| 277 | if (isset($conf['header_notes'])) |
---|
| 278 | { |
---|
| 279 | $header_notes = array_merge($header_notes, $conf['header_notes']); |
---|
| 280 | } |
---|
| 281 | |
---|
[1598] | 282 | // default event handlers |
---|
[2117] | 283 | add_event_handler('render_category_literal_description', 'render_category_literal_description'); |
---|
| 284 | add_event_handler('render_category_description', 'render_category_description'); |
---|
[1849] | 285 | add_event_handler('render_comment_content', 'htmlspecialchars'); |
---|
[1598] | 286 | add_event_handler('render_comment_content', 'parse_comment_content'); |
---|
[2030] | 287 | add_event_handler('render_comment_author', 'strip_tags'); |
---|
[1598] | 288 | trigger_action('init'); |
---|
[1679] | 289 | ?> |
---|