blob: b496f1d199bfe02fc3b4948c417f2c032f318428 [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
77 if(strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) {
78 SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
79 }
droye95652e2007-11-27 18:16:36 +000080
droy974b6af2007-11-27 19:19:49 +000081 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000082 global $dbh;
droy974b6af2007-11-27 19:19:49 +000083 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000084
droy2d5fd192007-11-28 14:42:45 +000085 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();
droye95652e2007-11-27 18:16:36 +000092
droy2d5fd192007-11-28 14:42:45 +000093 if(!$Session->validate()) {
droy0ab70092007-12-01 02:14:47 +000094 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +000095 }
96 else {
97 $User = new User();
98 $User->loadFromID($Session->_userid);
99 SetSessionVar("User", $User);
100 }
101 }
102 else {
droy0ab70092007-12-01 02:14:47 +0000103 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000104 }
105 }
droye95652e2007-11-27 18:16:36 +0000106
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("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000113 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000114}
droye95652e2007-11-27 18:16:36 +0000115
droy10ea8052007-11-27 18:38:06 +0000116function errorLog($str) {
117
118}
droyfd2bab22007-11-27 21:08:43 +0000119
droy10ea8052007-11-27 18:38:06 +0000120function 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 }
droye95652e2007-11-27 18:16:36 +0000142}
droy974b6af2007-11-27 19:19:49 +0000143function GetSessionVar($varName) {
144 if (isset($_SESSION[$varName]))
145 return $_SESSION[$varName];
146 return 0;
147}
droye95652e2007-11-27 18:16:36 +0000148
droy974b6af2007-11-27 19:19:49 +0000149function SetSessionVar($varName,$varVal) {
150 global $_SESSION;
151
152 $GLOBALS[$varName] = $varVal;
153 $_SESSION[$varName] = $varVal;
154 return $varVal;
155}
droye95652e2007-11-27 18:16:36 +0000156
gobrien35e23782007-11-28 21:37:18 +0000157function 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
droy0f361be2008-07-18 12:37:19 +0000165/**
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 */
droy8a4e7e42008-07-18 15:24:53 +0000173if(!function_exists('toescapedunicode')) {
droy0f361be2008-07-18 12:37:19 +0000174function 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}
droy8a4e7e42008-07-18 15:24:53 +0000208}
droye95652e2007-11-27 18:16:36 +0000209?>