blob: dbe23a03f45a23d0335e415c5a8f373e398b060b [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}
62global $context;
63
droye95652e2007-11-27 18:16:36 +000064session_name(COOKIE_SESSION);
65session_start();
66extract($_SESSION);
67
68
droy2d5fd192007-11-28 14:42:45 +000069function InitPage($login) {
droy51e2bcc2008-07-16 15:14:43 +000070 $page = $login;
droye95652e2007-11-27 18:16:36 +000071 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000072 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000073
74 if (empty($GLOBALS['page']))
75 $GLOBALS['page'] = '';
droy51e2bcc2008-07-16 15:14:43 +000076
gobrien3ab43962008-08-18 17:33:41 +000077 if((strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) &&
78 (strpos($_SERVER['REQUEST_URI'], "callback") == FALSE)) {
79 SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
droy51e2bcc2008-07-16 15:14:43 +000080 }
droye95652e2007-11-27 18:16:36 +000081
droy974b6af2007-11-27 19:19:49 +000082 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000083 global $dbh;
droy974b6af2007-11-27 19:19:49 +000084 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000085
droy2d5fd192007-11-28 14:42:45 +000086 if($login == "login" && !$User) {
87 # Login required, but the User object isn't there.
88
89 if(isset($_COOKIE[COOKIE_REMEMBER])) {
90 # Try to fetch username from session
91 require_once(BABEL_BASE_DIR . "classes/system/session.class.php");
92 $Session = new Session();
droye95652e2007-11-27 18:16:36 +000093
droy2d5fd192007-11-28 14:42:45 +000094 if(!$Session->validate()) {
droy0ab70092007-12-01 02:14:47 +000095 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +000096 }
97 else {
98 $User = new User();
99 $User->loadFromID($Session->_userid);
100 SetSessionVar("User", $User);
101 }
102 }
103 else {
droy0ab70092007-12-01 02:14:47 +0000104 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000105 }
106 }
droye95652e2007-11-27 18:16:36 +0000107
108 $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
109 $GLOBALS['g_PAGE'] = $page;
110 $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
111 $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4);
112 $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
113 $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000114 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000115}
droye95652e2007-11-27 18:16:36 +0000116
droy10ea8052007-11-27 18:38:06 +0000117function errorLog($str) {
118
119}
droyfd2bab22007-11-27 21:08:43 +0000120
droy10ea8052007-11-27 18:38:06 +0000121function exitTo() {
122 # TODO: sqlClose();
123 if (func_num_args() == 1) {
124 $url = func_get_arg(0);
125 header("Location: $url");
126 exit;
127 }
128 else if (func_num_args() == 2) {
129 $url = func_get_arg(0);
130 $arg1 = func_get_arg(1);
131 SetSessionVar("errStr",$arg1);
132 header("Location: $url");
133 exit;
134 }
135 else if (func_num_args() == 3) {
136 $url = func_get_arg(0);
137 $arg1 = func_get_arg(1);
138 $arg2 = func_get_arg(2);
139 SetSessionVar($arg1,$arg2);
140 header("Location: $url");
141 exit;
142 }
droye95652e2007-11-27 18:16:36 +0000143}
droy974b6af2007-11-27 19:19:49 +0000144function GetSessionVar($varName) {
145 if (isset($_SESSION[$varName]))
146 return $_SESSION[$varName];
147 return 0;
148}
droye95652e2007-11-27 18:16:36 +0000149
droy974b6af2007-11-27 19:19:49 +0000150function SetSessionVar($varName,$varVal) {
151 global $_SESSION;
152
153 $GLOBALS[$varName] = $varVal;
154 $_SESSION[$varName] = $varVal;
155 return $varVal;
156}
droye95652e2007-11-27 18:16:36 +0000157
gobrien35e23782007-11-28 21:37:18 +0000158function getLanguagebyID($id){
159 global $dbh;
160 $query = "select name from languages where language_id = '".addslashes($id)."' limit 1";
161 $res = mysql_query($query,$dbh);
162 $ret = mysql_fetch_array($res, MYSQL_ASSOC);
163 return $ret['name'];
164}
165
droy0f361be2008-07-18 12:37:19 +0000166/**
167 * Converts string to escaped unicode format
168 * Based on work by Scott Reynen - CQ 2498
169 *
170 * @param string $str
171 * @return string
172 * @since 2008-07-18
173 */
droy8a4e7e42008-07-18 15:24:53 +0000174if(!function_exists('toescapedunicode')) {
droy0f361be2008-07-18 12:37:19 +0000175function toescapedunicode($str) {
176 $unicode = array();
177 $values = array();
178 $lookingFor = 1;
179
180 for ($i = 0; $i < strlen( $str ); $i++ ) {
181 $thisValue = ord( $str[ $i ] );
182 if ( $thisValue < 128)
183 $unicode[] = $str[ $i ];
184 else {
185 if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
186 $values[] = $thisValue;
187 if ( count( $values ) == $lookingFor ) {
188 $number = ( $lookingFor == 3 ) ?
189 ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
190 ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
191 $number = dechex($number);
192
193 if(strlen($number) == 3) {
194 $unicode[] = "\u0" . $number;
195 }
196 elseif(strlen($number) == 2) {
197 $unicode[] = "\u00" . $number;
198 }
199 else {
200 $unicode[] = "\u" . $number;
201 }
202 $values = array();
203 $lookingFor = 1;
204 }
205 }
206 }
207 return implode("",$unicode);
208}
droy8a4e7e42008-07-18 15:24:53 +0000209}
droye95652e2007-11-27 18:16:36 +0000210?>