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 | } |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 62 | |
| 63 | $image_root = ""; |
| 64 | # get the image root |
| 65 | if(isset($ini['image_root'])) |
| 66 | $image_root = $ini['image_root']; |
| 67 | |
| 68 | $genie_id = ""; |
| 69 | #get the genie id |
| 70 | if(isset($ini['genie_id'])) |
| 71 | $genie_id = $ini['genie_id']; |
droy | 541f040 | 2008-12-08 21:12:09 +0000 | [diff] [blame] | 72 | |
| 73 | $syncup_id = ""; |
| 74 | #get the syncup id |
| 75 | if(isset($ini['syncup_id'])) |
droy | 5d0dc38 | 2008-12-08 21:22:53 +0000 | [diff] [blame^] | 76 | $syncup_id = $ini['syncup_id']; |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 77 | |
droy | 24242b8 | 2008-01-30 18:43:20 +0000 | [diff] [blame] | 78 | global $context; |
| 79 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 80 | session_name(COOKIE_SESSION); |
| 81 | session_start(); |
| 82 | extract($_SESSION); |
| 83 | |
| 84 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 85 | function InitPage($login) { |
droy | 51e2bcc | 2008-07-16 15:14:43 +0000 | [diff] [blame] | 86 | $page = $login; |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 87 | $lastPage = GetSessionVar('s_pageName'); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 88 | $User = GetSessionVar('User'); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 89 | |
| 90 | if (empty($GLOBALS['page'])) |
| 91 | $GLOBALS['page'] = ''; |
droy | 51e2bcc | 2008-07-16 15:14:43 +0000 | [diff] [blame] | 92 | |
gobrien | 3ab4396 | 2008-08-18 17:33:41 +0000 | [diff] [blame] | 93 | if((strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) && |
| 94 | (strpos($_SERVER['REQUEST_URI'], "callback") == FALSE)) { |
| 95 | SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']); |
droy | 51e2bcc | 2008-07-16 15:14:43 +0000 | [diff] [blame] | 96 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 97 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 98 | $dbc = new DBConnection(); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 99 | global $dbh; |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 100 | $dbh = $dbc->connect(); |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 101 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 102 | if($login == "login" && !$User) { |
| 103 | # Login required, but the User object isn't there. |
| 104 | |
| 105 | if(isset($_COOKIE[COOKIE_REMEMBER])) { |
| 106 | # Try to fetch username from session |
| 107 | require_once(BABEL_BASE_DIR . "classes/system/session.class.php"); |
| 108 | $Session = new Session(); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 109 | |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 110 | if(!$Session->validate()) { |
droy | 0ab7009 | 2007-12-01 02:14:47 +0000 | [diff] [blame] | 111 | exitTo("login.php"); |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 112 | } |
| 113 | else { |
| 114 | $User = new User(); |
| 115 | $User->loadFromID($Session->_userid); |
| 116 | SetSessionVar("User", $User); |
| 117 | } |
| 118 | } |
| 119 | else { |
droy | 0ab7009 | 2007-12-01 02:14:47 +0000 | [diff] [blame] | 120 | exitTo("login.php"); |
droy | 2d5fd19 | 2007-11-28 14:42:45 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 123 | |
| 124 | $GLOBALS['g_PHPSELF'] = $GLOBALS['page']; |
| 125 | $GLOBALS['g_PAGE'] = $page; |
| 126 | $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST']; |
| 127 | $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4); |
| 128 | $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME']; |
| 129 | $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",); |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 130 | $GLOBALS['DEBUG'] = ""; |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 131 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 132 | |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 133 | function errorLog($str) { |
| 134 | |
| 135 | } |
droy | fd2bab2 | 2007-11-27 21:08:43 +0000 | [diff] [blame] | 136 | |
droy | 10ea805 | 2007-11-27 18:38:06 +0000 | [diff] [blame] | 137 | function exitTo() { |
| 138 | # TODO: sqlClose(); |
| 139 | if (func_num_args() == 1) { |
| 140 | $url = func_get_arg(0); |
| 141 | header("Location: $url"); |
| 142 | exit; |
| 143 | } |
| 144 | else if (func_num_args() == 2) { |
| 145 | $url = func_get_arg(0); |
| 146 | $arg1 = func_get_arg(1); |
| 147 | SetSessionVar("errStr",$arg1); |
| 148 | header("Location: $url"); |
| 149 | exit; |
| 150 | } |
| 151 | else if (func_num_args() == 3) { |
| 152 | $url = func_get_arg(0); |
| 153 | $arg1 = func_get_arg(1); |
| 154 | $arg2 = func_get_arg(2); |
| 155 | SetSessionVar($arg1,$arg2); |
| 156 | header("Location: $url"); |
| 157 | exit; |
| 158 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 159 | } |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 160 | function GetSessionVar($varName) { |
| 161 | if (isset($_SESSION[$varName])) |
| 162 | return $_SESSION[$varName]; |
| 163 | return 0; |
| 164 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 165 | |
droy | 974b6af | 2007-11-27 19:19:49 +0000 | [diff] [blame] | 166 | function SetSessionVar($varName,$varVal) { |
| 167 | global $_SESSION; |
| 168 | |
| 169 | $GLOBALS[$varName] = $varVal; |
| 170 | $_SESSION[$varName] = $varVal; |
| 171 | return $varVal; |
| 172 | } |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 173 | |
gobrien | 35e2378 | 2007-11-28 21:37:18 +0000 | [diff] [blame] | 174 | function getLanguagebyID($id){ |
| 175 | global $dbh; |
| 176 | $query = "select name from languages where language_id = '".addslashes($id)."' limit 1"; |
| 177 | $res = mysql_query($query,$dbh); |
| 178 | $ret = mysql_fetch_array($res, MYSQL_ASSOC); |
| 179 | return $ret['name']; |
| 180 | } |
| 181 | |
droy | 0f361be | 2008-07-18 12:37:19 +0000 | [diff] [blame] | 182 | /** |
| 183 | * Converts string to escaped unicode format |
| 184 | * Based on work by Scott Reynen - CQ 2498 |
| 185 | * |
| 186 | * @param string $str |
| 187 | * @return string |
| 188 | * @since 2008-07-18 |
| 189 | */ |
droy | 8a4e7e4 | 2008-07-18 15:24:53 +0000 | [diff] [blame] | 190 | if(!function_exists('toescapedunicode')) { |
droy | 0f361be | 2008-07-18 12:37:19 +0000 | [diff] [blame] | 191 | function toescapedunicode($str) { |
| 192 | $unicode = array(); |
| 193 | $values = array(); |
| 194 | $lookingFor = 1; |
| 195 | |
| 196 | for ($i = 0; $i < strlen( $str ); $i++ ) { |
| 197 | $thisValue = ord( $str[ $i ] ); |
| 198 | if ( $thisValue < 128) |
| 199 | $unicode[] = $str[ $i ]; |
| 200 | else { |
| 201 | if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3; |
| 202 | $values[] = $thisValue; |
| 203 | if ( count( $values ) == $lookingFor ) { |
| 204 | $number = ( $lookingFor == 3 ) ? |
| 205 | ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ): |
| 206 | ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 ); |
| 207 | $number = dechex($number); |
| 208 | |
| 209 | if(strlen($number) == 3) { |
| 210 | $unicode[] = "\u0" . $number; |
| 211 | } |
| 212 | elseif(strlen($number) == 2) { |
| 213 | $unicode[] = "\u00" . $number; |
| 214 | } |
| 215 | else { |
| 216 | $unicode[] = "\u" . $number; |
| 217 | } |
| 218 | $values = array(); |
| 219 | $lookingFor = 1; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | return implode("",$unicode); |
| 224 | } |
droy | 8a4e7e4 | 2008-07-18 15:24:53 +0000 | [diff] [blame] | 225 | } |
atoulme | 9118d61 | 2008-11-12 18:21:38 +0000 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Returns the genie user to be used for headless applications. |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 229 | * The user is found by looking for genie_id in the base.conf file. |
atoulme | 9118d61 | 2008-11-12 18:21:38 +0000 | [diff] [blame] | 230 | */ |
| 231 | function getGenieUser() { |
droy | d4feed3 | 2008-11-20 18:47:22 +0000 | [diff] [blame] | 232 | global $genie_id; |
atoulme | 9118d61 | 2008-11-12 18:21:38 +0000 | [diff] [blame] | 233 | $User = new User(); |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 234 | $User->loadFromID($genie_id); |
atoulme | 9118d61 | 2008-11-12 18:21:38 +0000 | [diff] [blame] | 235 | return $User; |
| 236 | } |
droy | 541f040 | 2008-12-08 21:12:09 +0000 | [diff] [blame] | 237 | /** |
| 238 | * Returns the syncup user to be used for headless applications. |
| 239 | * The user is found by looking for syncup_id in the base.conf file. |
| 240 | */ |
| 241 | function getSyncupUser() { |
| 242 | global $syncup_id; |
| 243 | $User = new User(); |
| 244 | $User->loadFromID($syncup_id); |
| 245 | return $User; |
| 246 | } |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 247 | |
| 248 | /** |
| 249 | * Returns the folder in which the images may be found. |
| 250 | * The folder may very well be an other server url. |
| 251 | */ |
| 252 | function imageRoot() { |
droy | d4feed3 | 2008-11-20 18:47:22 +0000 | [diff] [blame] | 253 | global $image_root; |
atoulme | e9ec6d8 | 2008-11-19 14:41:30 +0000 | [diff] [blame] | 254 | return $image_root; |
| 255 | } |
| 256 | |
droy | e95652e | 2007-11-27 18:16:36 +0000 | [diff] [blame] | 257 | ?> |