droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 1 | <?php |
| 2 | /******************************************************************************* |
droy | 0f361be | 2008-07-18 12:37:19 +0000 | [diff] [blame] | 3 | * Copyright (c) 2007-2008 Eclipse Foundation and others. |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 4 | * All rights reserved. This program and the accompanying materials |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| 6 | * which accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Paul Colton (Aptana)- initial API and implementation |
| 11 | * Eclipse Foundation |
droy | 0f361be | 2008-07-18 12:37:19 +0000 | [diff] [blame] | 12 | * Scott Reynen scott at randomchaos com - toescapedunicode |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 13 | *******************************************************************************/ |
gobrien | da3a450 | 2008-01-28 23:43:26 +0000 | [diff] [blame] | 14 | if(!defined('BABEL_BASE_DIR')){ |
| 15 | define('BABEL_BASE_DIR', "../"); |
| 16 | } |
droy | 4f37883 | 2008-07-18 13:03:56 +0000 | [diff] [blame] | 17 | if(!defined('USE_PHOENIX')) { |
| 18 | define('USE_PHOENIX', true); |
| 19 | } |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 20 | define("COOKIE_REMEMBER", "cBABEL"); |
| 21 | define("COOKIE_SESSION" , "sBABEL"); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 22 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 23 | # Load up Phoenix classes |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 24 | global $App; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 25 | if(USE_PHOENIX) { |
gobrien | 197d283 | 2007-11-27 18:42:53 +0000 | [diff] [blame] | 26 | require_once('eclipse.org-common/system/app.class.php'); |
| 27 | require_once("eclipse.org-common/system/nav.class.php"); |
| 28 | require_once("eclipse.org-common/system/menu.class.php"); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 29 | $App = new App(); |
| 30 | $Nav = new Nav(); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 31 | $Menu = new Menu(); |
droy | 8aedeec | 2008-01-25 19:04:14 +0000 | [diff] [blame] | 32 | $MenuItemList = array(); |
| 33 | $MenuItemList[0] = new MenuItem("Home", "./", "_self", 0); |
| 34 | $MenuItemList[1] = new MenuItem("For committers", "map_files.php", "_self", 0); |
droy | 7fcffa7 | 2008-06-02 20:33:14 +0000 | [diff] [blame] | 35 | $MenuItemList[2] = new MenuItem("Recent Translations", "recent.php", "_self", 0); |
| 36 | $MenuItemList[3] = new MenuItem("About Babel", "http://www.eclipse.org/babel", "_self", 0); |
droy | 8aedeec | 2008-01-25 19:04:14 +0000 | [diff] [blame] | 37 | $Menu->setMenuItemList($MenuItemList); |
| 38 | |
| 39 | # set Phoenix defaults to prevent errors. These can be overridden on the page. |
| 40 | $pageTitle = ""; |
| 41 | $pageAuthor = ""; |
| 42 | $pageKeywords = ""; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 43 | } |
| 44 | $GLOBALS['g_LOADTIME'] = microtime(); |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 45 | require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php"); |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 46 | require(BABEL_BASE_DIR . "classes/system/event_log.class.php"); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 47 | require_once(BABEL_BASE_DIR . "classes/system/user.class.php"); |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 48 | |
droy | 24242b8 | 2008-01-30 18:43:20 +0000 | [diff] [blame] | 49 | # get context |
| 50 | if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) { |
| 51 | errorLog("Failed to find/read database conf file - aborting."); |
| 52 | exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found"); |
| 53 | } |
gobrien | 0436d99 | 2008-01-31 00:08:04 +0000 | [diff] [blame] | 54 | |
| 55 | $context = ""; |
| 56 | if(isset($ini['context'])) |
| 57 | $context = $ini['context']; |
| 58 | |
droy | 24242b8 | 2008-01-30 18:43:20 +0000 | [diff] [blame] | 59 | if($context == "") { |
| 60 | $context = "staging"; |
| 61 | } |
| 62 | global $context; |
| 63 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 64 | session_name(COOKIE_SESSION); |
| 65 | session_start(); |
| 66 | extract($_SESSION); |
| 67 | |
| 68 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 69 | function InitPage($login) { |
droy | 51e2bcc | 2008-07-16 15:14:43 +0000 | [diff] [blame] | 70 | $page = $login; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 71 | $lastPage = GetSessionVar('s_pageName'); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 72 | $User = GetSessionVar('User'); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 73 | |
| 74 | if (empty($GLOBALS['page'])) |
| 75 | $GLOBALS['page'] = ''; |
droy | 51e2bcc | 2008-07-16 15:14:43 +0000 | [diff] [blame] | 76 | |
| 77 | if(strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) { |
| 78 | SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']); |
| 79 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 80 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 81 | $dbc = new DBConnection(); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 82 | global $dbh; |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 83 | $dbh = $dbc->connect(); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 84 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 85 | if($login == "login" && !$User) { |
| 86 | # Login required, but the User object isn't there. |
| 87 | |
| 88 | if(isset($_COOKIE[COOKIE_REMEMBER])) { |
| 89 | # Try to fetch username from session |
| 90 | require_once(BABEL_BASE_DIR . "classes/system/session.class.php"); |
| 91 | $Session = new Session(); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 92 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 93 | if(!$Session->validate()) { |
droy | 0ab7009 | 2007-12-01 02:14:47 +0000 | [diff] [blame] | 94 | exitTo("login.php"); |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 95 | } |
| 96 | else { |
| 97 | $User = new User(); |
| 98 | $User->loadFromID($Session->_userid); |
| 99 | SetSessionVar("User", $User); |
| 100 | } |
| 101 | } |
| 102 | else { |
droy | 0ab7009 | 2007-12-01 02:14:47 +0000 | [diff] [blame] | 103 | exitTo("login.php"); |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 106 | |
| 107 | $GLOBALS['g_PHPSELF'] = $GLOBALS['page']; |
| 108 | $GLOBALS['g_PAGE'] = $page; |
| 109 | $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST']; |
| 110 | $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4); |
| 111 | $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME']; |
| 112 | $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 113 | $GLOBALS['DEBUG'] = ""; |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 114 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 115 | |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 116 | function errorLog($str) { |
| 117 | |
| 118 | } |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 119 | |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 120 | function exitTo() { |
| 121 | # TODO: sqlClose(); |
| 122 | if (func_num_args() == 1) { |
| 123 | $url = func_get_arg(0); |
| 124 | header("Location: $url"); |
| 125 | exit; |
| 126 | } |
| 127 | else if (func_num_args() == 2) { |
| 128 | $url = func_get_arg(0); |
| 129 | $arg1 = func_get_arg(1); |
| 130 | SetSessionVar("errStr",$arg1); |
| 131 | header("Location: $url"); |
| 132 | exit; |
| 133 | } |
| 134 | else if (func_num_args() == 3) { |
| 135 | $url = func_get_arg(0); |
| 136 | $arg1 = func_get_arg(1); |
| 137 | $arg2 = func_get_arg(2); |
| 138 | SetSessionVar($arg1,$arg2); |
| 139 | header("Location: $url"); |
| 140 | exit; |
| 141 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 142 | } |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 143 | function GetSessionVar($varName) { |
| 144 | if (isset($_SESSION[$varName])) |
| 145 | return $_SESSION[$varName]; |
| 146 | return 0; |
| 147 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 148 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 149 | function SetSessionVar($varName,$varVal) { |
| 150 | global $_SESSION; |
| 151 | |
| 152 | $GLOBALS[$varName] = $varVal; |
| 153 | $_SESSION[$varName] = $varVal; |
| 154 | return $varVal; |
| 155 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 156 | |
gobrien | 35e2378 | 2007-11-28 21:37:18 +0000 | [diff] [blame] | 157 | function getLanguagebyID($id){ |
| 158 | global $dbh; |
| 159 | $query = "select name from languages where language_id = '".addslashes($id)."' limit 1"; |
| 160 | $res = mysql_query($query,$dbh); |
| 161 | $ret = mysql_fetch_array($res, MYSQL_ASSOC); |
| 162 | return $ret['name']; |
| 163 | } |
| 164 | |
droy | 0f361be | 2008-07-18 12:37:19 +0000 | [diff] [blame] | 165 | /** |
| 166 | * Converts string to escaped unicode format |
| 167 | * Based on work by Scott Reynen - CQ 2498 |
| 168 | * |
| 169 | * @param string $str |
| 170 | * @return string |
| 171 | * @since 2008-07-18 |
| 172 | */ |
droy | 8a4e7e4 | 2008-07-18 15:24:53 +0000 | [diff] [blame^] | 173 | if(!function_exists('toescapedunicode')) { |
droy | 0f361be | 2008-07-18 12:37:19 +0000 | [diff] [blame] | 174 | function toescapedunicode($str) { |
| 175 | $unicode = array(); |
| 176 | $values = array(); |
| 177 | $lookingFor = 1; |
| 178 | |
| 179 | for ($i = 0; $i < strlen( $str ); $i++ ) { |
| 180 | $thisValue = ord( $str[ $i ] ); |
| 181 | if ( $thisValue < 128) |
| 182 | $unicode[] = $str[ $i ]; |
| 183 | else { |
| 184 | if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3; |
| 185 | $values[] = $thisValue; |
| 186 | if ( count( $values ) == $lookingFor ) { |
| 187 | $number = ( $lookingFor == 3 ) ? |
| 188 | ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ): |
| 189 | ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 ); |
| 190 | $number = dechex($number); |
| 191 | |
| 192 | if(strlen($number) == 3) { |
| 193 | $unicode[] = "\u0" . $number; |
| 194 | } |
| 195 | elseif(strlen($number) == 2) { |
| 196 | $unicode[] = "\u00" . $number; |
| 197 | } |
| 198 | else { |
| 199 | $unicode[] = "\u" . $number; |
| 200 | } |
| 201 | $values = array(); |
| 202 | $lookingFor = 1; |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | return implode("",$unicode); |
| 207 | } |
droy | 8a4e7e4 | 2008-07-18 15:24:53 +0000 | [diff] [blame^] | 208 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 209 | ?> |