blob: 3247148e85147f7a88984394dcc82949e771105d [file] [log] [blame]
droye95652e2007-11-27 18:16:36 +00001<?php
2/*******************************************************************************
droy0f361be2008-07-18 12:37:19 +00003 * Copyright (c) 2007-2008 Eclipse Foundation and others.
droye95652e2007-11-27 18:16:36 +00004 * 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
droy0f361be2008-07-18 12:37:19 +000012 * Scott Reynen scott at randomchaos com - toescapedunicode
droye95652e2007-11-27 18:16:36 +000013*******************************************************************************/
gobrienda3a4502008-01-28 23:43:26 +000014if(!defined('BABEL_BASE_DIR')){
15 define('BABEL_BASE_DIR', "../");
16}
droy4f378832008-07-18 13:03:56 +000017if(!defined('USE_PHOENIX')) {
18 define('USE_PHOENIX', true);
19}
droy10ea8052007-11-27 18:38:06 +000020define("COOKIE_REMEMBER", "cBABEL");
21define("COOKIE_SESSION" , "sBABEL");
droye95652e2007-11-27 18:16:36 +000022
droye95652e2007-11-27 18:16:36 +000023# Load up Phoenix classes
droyfd2bab22007-11-27 21:08:43 +000024global $App;
droye95652e2007-11-27 18:16:36 +000025if(USE_PHOENIX) {
gobrien197d2832007-11-27 18:42:53 +000026 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");
droy974b6af2007-11-27 19:19:49 +000029 $App = new App();
30 $Nav = new Nav();
droye95652e2007-11-27 18:16:36 +000031 $Menu = new Menu();
droy8aedeec2008-01-25 19:04:14 +000032 $MenuItemList = array();
33 $MenuItemList[0] = new MenuItem("Home", "./", "_self", 0);
34 $MenuItemList[1] = new MenuItem("For committers", "map_files.php", "_self", 0);
droy7fcffa72008-06-02 20:33:14 +000035 $MenuItemList[2] = new MenuItem("Recent Translations", "recent.php", "_self", 0);
36 $MenuItemList[3] = new MenuItem("About Babel", "http://www.eclipse.org/babel", "_self", 0);
droy8aedeec2008-01-25 19:04:14 +000037 $Menu->setMenuItemList($MenuItemList);
38
39 # set Phoenix defaults to prevent errors. These can be overridden on the page.
40 $pageTitle = "";
41 $pageAuthor = "";
42 $pageKeywords = "";
droye95652e2007-11-27 18:16:36 +000043}
44$GLOBALS['g_LOADTIME'] = microtime();
droy974b6af2007-11-27 19:19:49 +000045require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
droy3e7f3a82007-11-29 19:35:51 +000046require(BABEL_BASE_DIR . "classes/system/event_log.class.php");
droyfd2bab22007-11-27 21:08:43 +000047require_once(BABEL_BASE_DIR . "classes/system/user.class.php");
droy3e7f3a82007-11-29 19:35:51 +000048
droy24242b82008-01-30 18:43:20 +000049# get context
50if (!($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}
gobrien0436d992008-01-31 00:08:04 +000054
55$context = "";
56if(isset($ini['context']))
57 $context = $ini['context'];
58
droy24242b82008-01-30 18:43:20 +000059if($context == "") {
60 $context = "staging";
61}
atoulmee9ec6d82008-11-19 14:41:30 +000062
63$image_root = "";
64# get the image root
65if(isset($ini['image_root']))
66 $image_root = $ini['image_root'];
67
68$genie_id = "";
69#get the genie id
70if(isset($ini['genie_id']))
71 $genie_id = $ini['genie_id'];
droy541f0402008-12-08 21:12:09 +000072
73$syncup_id = "";
74#get the syncup id
75if(isset($ini['syncup_id']))
droy5d0dc382008-12-08 21:22:53 +000076 $syncup_id = $ini['syncup_id'];
atoulmee9ec6d82008-11-19 14:41:30 +000077
droy24242b82008-01-30 18:43:20 +000078global $context;
79
droye95652e2007-11-27 18:16:36 +000080session_name(COOKIE_SESSION);
81session_start();
82extract($_SESSION);
83
84
droy2d5fd192007-11-28 14:42:45 +000085function InitPage($login) {
droy51e2bcc2008-07-16 15:14:43 +000086 $page = $login;
droye95652e2007-11-27 18:16:36 +000087 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000088 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000089
90 if (empty($GLOBALS['page']))
91 $GLOBALS['page'] = '';
droy51e2bcc2008-07-16 15:14:43 +000092
gobrien3ab43962008-08-18 17:33:41 +000093 if((strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) &&
94 (strpos($_SERVER['REQUEST_URI'], "callback") == FALSE)) {
95 SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
droy51e2bcc2008-07-16 15:14:43 +000096 }
droye95652e2007-11-27 18:16:36 +000097
droy974b6af2007-11-27 19:19:49 +000098 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000099 global $dbh;
droy974b6af2007-11-27 19:19:49 +0000100 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +0000101
droy2d5fd192007-11-28 14:42:45 +0000102 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();
droye95652e2007-11-27 18:16:36 +0000109
droy2d5fd192007-11-28 14:42:45 +0000110 if(!$Session->validate()) {
droy0ab70092007-12-01 02:14:47 +0000111 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000112 }
113 else {
114 $User = new User();
115 $User->loadFromID($Session->_userid);
116 SetSessionVar("User", $User);
117 }
118 }
119 else {
droy0ab70092007-12-01 02:14:47 +0000120 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000121 }
122 }
droye95652e2007-11-27 18:16:36 +0000123
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("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000130 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000131}
droye95652e2007-11-27 18:16:36 +0000132
droy10ea8052007-11-27 18:38:06 +0000133function errorLog($str) {
134
135}
droyfd2bab22007-11-27 21:08:43 +0000136
droy10ea8052007-11-27 18:38:06 +0000137function 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 }
droye95652e2007-11-27 18:16:36 +0000159}
droy974b6af2007-11-27 19:19:49 +0000160function GetSessionVar($varName) {
161 if (isset($_SESSION[$varName]))
162 return $_SESSION[$varName];
163 return 0;
164}
droye95652e2007-11-27 18:16:36 +0000165
droy974b6af2007-11-27 19:19:49 +0000166function SetSessionVar($varName,$varVal) {
167 global $_SESSION;
168
169 $GLOBALS[$varName] = $varVal;
170 $_SESSION[$varName] = $varVal;
171 return $varVal;
172}
droye95652e2007-11-27 18:16:36 +0000173
gobrien35e23782007-11-28 21:37:18 +0000174function 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
droy0f361be2008-07-18 12:37:19 +0000182/**
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 */
droy8a4e7e42008-07-18 15:24:53 +0000190if(!function_exists('toescapedunicode')) {
droy0f361be2008-07-18 12:37:19 +0000191function 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}
droy8a4e7e42008-07-18 15:24:53 +0000225}
atoulme9118d612008-11-12 18:21:38 +0000226
227/**
228* Returns the genie user to be used for headless applications.
atoulmee9ec6d82008-11-19 14:41:30 +0000229* The user is found by looking for genie_id in the base.conf file.
atoulme9118d612008-11-12 18:21:38 +0000230*/
231function getGenieUser() {
droyd4feed32008-11-20 18:47:22 +0000232 global $genie_id;
atoulme9118d612008-11-12 18:21:38 +0000233 $User = new User();
atoulmee9ec6d82008-11-19 14:41:30 +0000234 $User->loadFromID($genie_id);
atoulme9118d612008-11-12 18:21:38 +0000235 return $User;
236}
droy541f0402008-12-08 21:12:09 +0000237/**
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*/
241function getSyncupUser() {
242 global $syncup_id;
243 $User = new User();
244 $User->loadFromID($syncup_id);
245 return $User;
246}
atoulmee9ec6d82008-11-19 14:41:30 +0000247
248/**
249* Returns the folder in which the images may be found.
250* The folder may very well be an other server url.
251*/
252function imageRoot() {
droyd4feed32008-11-20 18:47:22 +0000253 global $image_root;
atoulmee9ec6d82008-11-19 14:41:30 +0000254 return $image_root;
255}
256
droye95652e2007-11-27 18:16:36 +0000257?>