[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 2215 2008-02-27 02:22:19Z rvelices $ |
---|
[354] | 8 | // | last update : $Date: 2008-02-27 02:22:19 +0000 (Wed, 27 Feb 2008) $ |
---|
| 9 | // | last modifier : $Author: rvelices $ |
---|
| 10 | // | revision : $Revision: 2215 $ |
---|
| 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 |
---|
[2215] | 128 | 'file_put_contents', //PHP5 |
---|
[1744] | 129 | ) as $func) |
---|
| 130 | { |
---|
| 131 | if (!function_exists($func)) |
---|
| 132 | { |
---|
| 133 | include_once(PHPWG_ROOT_PATH . 'include/php_compat/'.$func.'.php'); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
[770] | 137 | include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); |
---|
| 138 | @include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); |
---|
[808] | 139 | include(PHPWG_ROOT_PATH . 'include/constants.php'); |
---|
[364] | 140 | include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); |
---|
| 141 | include(PHPWG_ROOT_PATH . 'include/template.php'); |
---|
| 142 | |
---|
[354] | 143 | // Database connection |
---|
[681] | 144 | mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) |
---|
[512] | 145 | or die ( "Could not connect to database server" ); |
---|
[681] | 146 | mysql_select_db( $cfgBase ) |
---|
[359] | 147 | or die ( "Could not connect to database" ); |
---|
[953] | 148 | |
---|
[2127] | 149 | defined('PWG_CHARSET') and defined('DB_CHARSET') |
---|
| 150 | or die('PWG_CHARSET and/or DB_CHARSET is not defined'); |
---|
| 151 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) |
---|
| 152 | { |
---|
| 153 | if (DB_CHARSET!='') |
---|
| 154 | { |
---|
| 155 | pwg_query('SET NAMES "'.DB_CHARSET.'"'); |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
| 160 | if ( strtolower(PWG_CHARSET)!='iso-8859-1' ) |
---|
| 161 | { |
---|
| 162 | die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info()); |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
[354] | 166 | // |
---|
[394] | 167 | // Setup gallery wide options, if this fails then we output a CRITICAL_ERROR |
---|
| 168 | // since basic gallery information is not available |
---|
[354] | 169 | // |
---|
[1284] | 170 | load_conf_from_db(); |
---|
[1655] | 171 | load_plugins(); |
---|
[354] | 172 | |
---|
[650] | 173 | include(PHPWG_ROOT_PATH.'include/user.inc.php'); |
---|
[808] | 174 | |
---|
[1568] | 175 | |
---|
[808] | 176 | // language files |
---|
[2126] | 177 | load_language('common.lang'); |
---|
[808] | 178 | if (defined('IN_ADMIN') and IN_ADMIN) |
---|
| 179 | { |
---|
[2126] | 180 | load_language('admin.lang'); |
---|
[808] | 181 | } |
---|
[1699] | 182 | trigger_action('loading_lang'); |
---|
[2126] | 183 | load_language('local.lang'); |
---|
[808] | 184 | |
---|
[1568] | 185 | // only now we can set the localized username of the guest user (and not in |
---|
| 186 | // include/user.inc.php) |
---|
[2029] | 187 | if (is_a_guest()) |
---|
[1568] | 188 | { |
---|
[2201] | 189 | $user['username'] = l10n('guest'); |
---|
[1568] | 190 | } |
---|
| 191 | |
---|
| 192 | // template instance |
---|
[2117] | 193 | if |
---|
[2038] | 194 | ( |
---|
[2117] | 195 | defined('IN_ADMIN') and IN_ADMIN and |
---|
[2038] | 196 | isset($user['admin_template']) and |
---|
| 197 | isset($user['admin_theme']) |
---|
| 198 | ) |
---|
| 199 | { |
---|
| 200 | // Admin template |
---|
| 201 | $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['admin_template'], $user['admin_theme'] ); |
---|
| 202 | } |
---|
| 203 | else |
---|
| 204 | { |
---|
| 205 | // Classic template |
---|
| 206 | $template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template'], $user['theme'] ); |
---|
| 207 | } |
---|
[1568] | 208 | |
---|
[2055] | 209 | if (isset($user['internal_status']['guest_must_be_guest']) |
---|
| 210 | and |
---|
| 211 | $user['internal_status']['guest_must_be_guest'] === true) |
---|
| 212 | { |
---|
| 213 | $header_msgs[] = l10n('guest_must_be_guest'); |
---|
| 214 | } |
---|
| 215 | |
---|
[1036] | 216 | if ($conf['gallery_locked']) |
---|
| 217 | { |
---|
[2201] | 218 | $header_msgs[] = l10n('gallery_locked_message'); |
---|
[1036] | 219 | |
---|
[1692] | 220 | if ( script_basename() != 'identification' and !is_admin() ) |
---|
[1036] | 221 | { |
---|
[2046] | 222 | set_status_header(503, 'Service Unavailable'); |
---|
| 223 | @header('Retry-After: 900'); |
---|
[2201] | 224 | echo l10n('gallery_locked_message') |
---|
[1750] | 225 | .'<a href="'.get_absolute_root_url(false).'identification.php">.</a>'; |
---|
[1036] | 226 | exit(); |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
[1568] | 230 | if ($conf['check_upgrade_feed'] |
---|
| 231 | and defined('PHPWG_IN_UPGRADE') |
---|
| 232 | and PHPWG_IN_UPGRADE) |
---|
[1377] | 233 | { |
---|
[1578] | 234 | |
---|
[1568] | 235 | // retrieve already applied upgrades |
---|
| 236 | $query = ' |
---|
| 237 | SELECT id |
---|
| 238 | FROM '.UPGRADE_TABLE.' |
---|
| 239 | ;'; |
---|
| 240 | $applied = array_from_query($query, 'id'); |
---|
| 241 | |
---|
| 242 | // retrieve existing upgrades |
---|
| 243 | $existing = get_available_upgrade_ids(); |
---|
| 244 | |
---|
| 245 | // which upgrades need to be applied? |
---|
| 246 | if (count(array_diff($existing, $applied)) > 0) |
---|
| 247 | { |
---|
| 248 | $header_msgs[] = 'Some database upgrades are missing, ' |
---|
[1750] | 249 | .'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>'; |
---|
[1568] | 250 | } |
---|
[1377] | 251 | } |
---|
[960] | 252 | |
---|
[1303] | 253 | if (is_adviser()) |
---|
| 254 | { |
---|
[2201] | 255 | $header_msgs[] = l10n('adviser_mode_enabled'); |
---|
[1303] | 256 | } |
---|
| 257 | |
---|
[1414] | 258 | if (count($header_msgs) > 0) |
---|
[1380] | 259 | { |
---|
[1414] | 260 | $template->assign_block_vars('header_msgs',array()); |
---|
| 261 | foreach ($header_msgs as $header_msg) |
---|
[1380] | 262 | { |
---|
[1418] | 263 | $template->assign_block_vars('header_msgs.header_msg', |
---|
| 264 | array('HEADER_MSG'=>$header_msg)); |
---|
[1380] | 265 | } |
---|
| 266 | } |
---|
[1598] | 267 | |
---|
[1722] | 268 | if (!empty($conf['filter_pages']) and get_filter_page_value('used')) |
---|
[1677] | 269 | { |
---|
| 270 | include(PHPWG_ROOT_PATH.'include/functions_filter.inc.php'); |
---|
| 271 | include(PHPWG_ROOT_PATH.'include/filter.inc.php'); |
---|
| 272 | } |
---|
[1722] | 273 | else |
---|
| 274 | { |
---|
| 275 | $filter['enabled'] = false; |
---|
| 276 | } |
---|
[1677] | 277 | |
---|
| 278 | if (isset($conf['header_notes'])) |
---|
| 279 | { |
---|
| 280 | $header_notes = array_merge($header_notes, $conf['header_notes']); |
---|
| 281 | } |
---|
| 282 | |
---|
[1598] | 283 | // default event handlers |
---|
[2117] | 284 | add_event_handler('render_category_literal_description', 'render_category_literal_description'); |
---|
| 285 | add_event_handler('render_category_description', 'render_category_description'); |
---|
[1849] | 286 | add_event_handler('render_comment_content', 'htmlspecialchars'); |
---|
[1598] | 287 | add_event_handler('render_comment_content', 'parse_comment_content'); |
---|
[2030] | 288 | add_event_handler('render_comment_author', 'strip_tags'); |
---|
[1598] | 289 | trigger_action('init'); |
---|
[1679] | 290 | ?> |
---|