blob: ddd0a8813540ba75b6cac965dd5eb14cf9113c78 [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'];
72
droy24242b82008-01-30 18:43:20 +000073global $context;
74
droye95652e2007-11-27 18:16:36 +000075session_name(COOKIE_SESSION);
76session_start();
77extract($_SESSION);
78
79
droy2d5fd192007-11-28 14:42:45 +000080function InitPage($login) {
droy51e2bcc2008-07-16 15:14:43 +000081 $page = $login;
droye95652e2007-11-27 18:16:36 +000082 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000083 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000084
85 if (empty($GLOBALS['page']))
86 $GLOBALS['page'] = '';
droy51e2bcc2008-07-16 15:14:43 +000087
gobrien3ab43962008-08-18 17:33:41 +000088 if((strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) &&
89 (strpos($_SERVER['REQUEST_URI'], "callback") == FALSE)) {
90 SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
droy51e2bcc2008-07-16 15:14:43 +000091 }
droye95652e2007-11-27 18:16:36 +000092
droy974b6af2007-11-27 19:19:49 +000093 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000094 global $dbh;
droy974b6af2007-11-27 19:19:49 +000095 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000096
droy2d5fd192007-11-28 14:42:45 +000097 if($login == "login" && !$User) {
98 # Login required, but the User object isn't there.
99
100 if(isset($_COOKIE[COOKIE_REMEMBER])) {
101 # Try to fetch username from session
102 require_once(BABEL_BASE_DIR . "classes/system/session.class.php");
103 $Session = new Session();
droye95652e2007-11-27 18:16:36 +0000104
droy2d5fd192007-11-28 14:42:45 +0000105 if(!$Session->validate()) {
droy0ab70092007-12-01 02:14:47 +0000106 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000107 }
108 else {
109 $User = new User();
110 $User->loadFromID($Session->_userid);
111 SetSessionVar("User", $User);
112 }
113 }
114 else {
droy0ab70092007-12-01 02:14:47 +0000115 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000116 }
117 }
droye95652e2007-11-27 18:16:36 +0000118
119 $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
120 $GLOBALS['g_PAGE'] = $page;
121 $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
122 $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4);
123 $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
124 $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000125 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000126}
droye95652e2007-11-27 18:16:36 +0000127
droy10ea8052007-11-27 18:38:06 +0000128function errorLog($str) {
129
130}
droyfd2bab22007-11-27 21:08:43 +0000131
droy10ea8052007-11-27 18:38:06 +0000132function exitTo() {
133 # TODO: sqlClose();
134 if (func_num_args() == 1) {
135 $url = func_get_arg(0);
136 header("Location: $url");
137 exit;
138 }
139 else if (func_num_args() == 2) {
140 $url = func_get_arg(0);
141 $arg1 = func_get_arg(1);
142 SetSessionVar("errStr",$arg1);
143 header("Location: $url");
144 exit;
145 }
146 else if (func_num_args() == 3) {
147 $url = func_get_arg(0);
148 $arg1 = func_get_arg(1);
149 $arg2 = func_get_arg(2);
150 SetSessionVar($arg1,$arg2);
151 header("Location: $url");
152 exit;
153 }
droye95652e2007-11-27 18:16:36 +0000154}
droy974b6af2007-11-27 19:19:49 +0000155function GetSessionVar($varName) {
156 if (isset($_SESSION[$varName]))
157 return $_SESSION[$varName];
158 return 0;
159}
droye95652e2007-11-27 18:16:36 +0000160
droy974b6af2007-11-27 19:19:49 +0000161function SetSessionVar($varName,$varVal) {
162 global $_SESSION;
163
164 $GLOBALS[$varName] = $varVal;
165 $_SESSION[$varName] = $varVal;
166 return $varVal;
167}
droye95652e2007-11-27 18:16:36 +0000168
gobrien35e23782007-11-28 21:37:18 +0000169function getLanguagebyID($id){
170 global $dbh;
171 $query = "select name from languages where language_id = '".addslashes($id)."' limit 1";
172 $res = mysql_query($query,$dbh);
173 $ret = mysql_fetch_array($res, MYSQL_ASSOC);
174 return $ret['name'];
175}
176
droy0f361be2008-07-18 12:37:19 +0000177/**
178 * Converts string to escaped unicode format
179 * Based on work by Scott Reynen - CQ 2498
180 *
181 * @param string $str
182 * @return string
183 * @since 2008-07-18
184 */
droy8a4e7e42008-07-18 15:24:53 +0000185if(!function_exists('toescapedunicode')) {
droy0f361be2008-07-18 12:37:19 +0000186function toescapedunicode($str) {
187 $unicode = array();
188 $values = array();
189 $lookingFor = 1;
190
191 for ($i = 0; $i < strlen( $str ); $i++ ) {
192 $thisValue = ord( $str[ $i ] );
193 if ( $thisValue < 128)
194 $unicode[] = $str[ $i ];
195 else {
196 if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
197 $values[] = $thisValue;
198 if ( count( $values ) == $lookingFor ) {
199 $number = ( $lookingFor == 3 ) ?
200 ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
201 ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
202 $number = dechex($number);
203
204 if(strlen($number) == 3) {
205 $unicode[] = "\u0" . $number;
206 }
207 elseif(strlen($number) == 2) {
208 $unicode[] = "\u00" . $number;
209 }
210 else {
211 $unicode[] = "\u" . $number;
212 }
213 $values = array();
214 $lookingFor = 1;
215 }
216 }
217 }
218 return implode("",$unicode);
219}
droy8a4e7e42008-07-18 15:24:53 +0000220}
atoulme9118d612008-11-12 18:21:38 +0000221
222/**
223* Returns the genie user to be used for headless applications.
atoulmee9ec6d82008-11-19 14:41:30 +0000224* The user is found by looking for genie_id in the base.conf file.
atoulme9118d612008-11-12 18:21:38 +0000225*/
226function getGenieUser() {
atoulme9118d612008-11-12 18:21:38 +0000227 $User = new User();
atoulmee9ec6d82008-11-19 14:41:30 +0000228 $User->loadFromID($genie_id);
atoulme9118d612008-11-12 18:21:38 +0000229 return $User;
230}
atoulmee9ec6d82008-11-19 14:41:30 +0000231
232/**
233* Returns the folder in which the images may be found.
234* The folder may very well be an other server url.
235*/
236function imageRoot() {
237 return $image_root;
238}
239
droye95652e2007-11-27 18:16:36 +0000240?>