blob: 85c227d8f0309c982b47fd9d1efba76c56f6b9c2 [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}
droy10ea8052007-11-27 18:38:06 +000017define('USE_PHOENIX', true);
18define("COOKIE_REMEMBER", "cBABEL");
19define("COOKIE_SESSION" , "sBABEL");
droye95652e2007-11-27 18:16:36 +000020
droye95652e2007-11-27 18:16:36 +000021# Load up Phoenix classes
droyfd2bab22007-11-27 21:08:43 +000022global $App;
droye95652e2007-11-27 18:16:36 +000023if(USE_PHOENIX) {
gobrien197d2832007-11-27 18:42:53 +000024 require_once('eclipse.org-common/system/app.class.php');
25 require_once("eclipse.org-common/system/nav.class.php");
26 require_once("eclipse.org-common/system/menu.class.php");
droy974b6af2007-11-27 19:19:49 +000027 $App = new App();
28 $Nav = new Nav();
droye95652e2007-11-27 18:16:36 +000029 $Menu = new Menu();
droy8aedeec2008-01-25 19:04:14 +000030 $MenuItemList = array();
31 $MenuItemList[0] = new MenuItem("Home", "./", "_self", 0);
32 $MenuItemList[1] = new MenuItem("For committers", "map_files.php", "_self", 0);
droy7fcffa72008-06-02 20:33:14 +000033 $MenuItemList[2] = new MenuItem("Recent Translations", "recent.php", "_self", 0);
34 $MenuItemList[3] = new MenuItem("About Babel", "http://www.eclipse.org/babel", "_self", 0);
droy8aedeec2008-01-25 19:04:14 +000035 $Menu->setMenuItemList($MenuItemList);
36
37 # set Phoenix defaults to prevent errors. These can be overridden on the page.
38 $pageTitle = "";
39 $pageAuthor = "";
40 $pageKeywords = "";
droye95652e2007-11-27 18:16:36 +000041}
42$GLOBALS['g_LOADTIME'] = microtime();
droy974b6af2007-11-27 19:19:49 +000043require(BABEL_BASE_DIR . "classes/system/dbconnection.class.php");
droy3e7f3a82007-11-29 19:35:51 +000044require(BABEL_BASE_DIR . "classes/system/event_log.class.php");
droyfd2bab22007-11-27 21:08:43 +000045require_once(BABEL_BASE_DIR . "classes/system/user.class.php");
droy3e7f3a82007-11-29 19:35:51 +000046
droy24242b82008-01-30 18:43:20 +000047# get context
48if (!($ini = @parse_ini_file(BABEL_BASE_DIR . 'classes/base.conf'))) {
49 errorLog("Failed to find/read database conf file - aborting.");
50 exitTo("error.php?errNo=101300","error: 101300 - database conf can not be found");
51}
gobrien0436d992008-01-31 00:08:04 +000052
53$context = "";
54if(isset($ini['context']))
55 $context = $ini['context'];
56
droy24242b82008-01-30 18:43:20 +000057if($context == "") {
58 $context = "staging";
59}
60global $context;
61
droye95652e2007-11-27 18:16:36 +000062session_name(COOKIE_SESSION);
63session_start();
64extract($_SESSION);
65
66
droy2d5fd192007-11-28 14:42:45 +000067function InitPage($login) {
droy51e2bcc2008-07-16 15:14:43 +000068 $page = $login;
droye95652e2007-11-27 18:16:36 +000069 $lastPage = GetSessionVar('s_pageName');
droyfd2bab22007-11-27 21:08:43 +000070 $User = GetSessionVar('User');
droye95652e2007-11-27 18:16:36 +000071
72 if (empty($GLOBALS['page']))
73 $GLOBALS['page'] = '';
droy51e2bcc2008-07-16 15:14:43 +000074
75 if(strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE) {
76 SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
77 }
droye95652e2007-11-27 18:16:36 +000078
droy974b6af2007-11-27 19:19:49 +000079 $dbc = new DBConnection();
droyfd2bab22007-11-27 21:08:43 +000080 global $dbh;
droy974b6af2007-11-27 19:19:49 +000081 $dbh = $dbc->connect();
droyfd2bab22007-11-27 21:08:43 +000082
droy2d5fd192007-11-28 14:42:45 +000083 if($login == "login" && !$User) {
84 # Login required, but the User object isn't there.
85
86 if(isset($_COOKIE[COOKIE_REMEMBER])) {
87 # Try to fetch username from session
88 require_once(BABEL_BASE_DIR . "classes/system/session.class.php");
89 $Session = new Session();
droye95652e2007-11-27 18:16:36 +000090
droy2d5fd192007-11-28 14:42:45 +000091 if(!$Session->validate()) {
droy0ab70092007-12-01 02:14:47 +000092 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +000093 }
94 else {
95 $User = new User();
96 $User->loadFromID($Session->_userid);
97 SetSessionVar("User", $User);
98 }
99 }
100 else {
droy0ab70092007-12-01 02:14:47 +0000101 exitTo("login.php");
droy2d5fd192007-11-28 14:42:45 +0000102 }
103 }
droye95652e2007-11-27 18:16:36 +0000104
105 $GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
106 $GLOBALS['g_PAGE'] = $page;
107 $GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
108 $GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'],0,strlen($GLOBALS['g_SITEURL'])-4);
109 $GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
110 $GLOBALS['g_ERRSTRS'] = array("","","","","","","","","","","",);
droye95652e2007-11-27 18:16:36 +0000111 $GLOBALS['DEBUG'] = "";
droy10ea8052007-11-27 18:38:06 +0000112}
droye95652e2007-11-27 18:16:36 +0000113
droy10ea8052007-11-27 18:38:06 +0000114function errorLog($str) {
115
116}
droyfd2bab22007-11-27 21:08:43 +0000117
droy10ea8052007-11-27 18:38:06 +0000118function exitTo() {
119 # TODO: sqlClose();
120 if (func_num_args() == 1) {
121 $url = func_get_arg(0);
122 header("Location: $url");
123 exit;
124 }
125 else if (func_num_args() == 2) {
126 $url = func_get_arg(0);
127 $arg1 = func_get_arg(1);
128 SetSessionVar("errStr",$arg1);
129 header("Location: $url");
130 exit;
131 }
132 else if (func_num_args() == 3) {
133 $url = func_get_arg(0);
134 $arg1 = func_get_arg(1);
135 $arg2 = func_get_arg(2);
136 SetSessionVar($arg1,$arg2);
137 header("Location: $url");
138 exit;
139 }
droye95652e2007-11-27 18:16:36 +0000140}
droy974b6af2007-11-27 19:19:49 +0000141function GetSessionVar($varName) {
142 if (isset($_SESSION[$varName]))
143 return $_SESSION[$varName];
144 return 0;
145}
droye95652e2007-11-27 18:16:36 +0000146
droy974b6af2007-11-27 19:19:49 +0000147function SetSessionVar($varName,$varVal) {
148 global $_SESSION;
149
150 $GLOBALS[$varName] = $varVal;
151 $_SESSION[$varName] = $varVal;
152 return $varVal;
153}
droye95652e2007-11-27 18:16:36 +0000154
gobrien35e23782007-11-28 21:37:18 +0000155function getLanguagebyID($id){
156 global $dbh;
157 $query = "select name from languages where language_id = '".addslashes($id)."' limit 1";
158 $res = mysql_query($query,$dbh);
159 $ret = mysql_fetch_array($res, MYSQL_ASSOC);
160 return $ret['name'];
161}
162
droy0f361be2008-07-18 12:37:19 +0000163/**
164 * Converts string to escaped unicode format
165 * Based on work by Scott Reynen - CQ 2498
166 *
167 * @param string $str
168 * @return string
169 * @since 2008-07-18
170 */
171function toescapedunicode($str) {
172 $unicode = array();
173 $values = array();
174 $lookingFor = 1;
175
176 for ($i = 0; $i < strlen( $str ); $i++ ) {
177 $thisValue = ord( $str[ $i ] );
178 if ( $thisValue < 128)
179 $unicode[] = $str[ $i ];
180 else {
181 if ( count( $values ) == 0 ) $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
182 $values[] = $thisValue;
183 if ( count( $values ) == $lookingFor ) {
184 $number = ( $lookingFor == 3 ) ?
185 ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
186 ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
187 $number = dechex($number);
188
189 if(strlen($number) == 3) {
190 $unicode[] = "\u0" . $number;
191 }
192 elseif(strlen($number) == 2) {
193 $unicode[] = "\u00" . $number;
194 }
195 else {
196 $unicode[] = "\u" . $number;
197 }
198 $values = array();
199 $lookingFor = 1;
200 }
201 }
202 }
203 return implode("",$unicode);
204}
droye95652e2007-11-27 18:16:36 +0000205?>