Linux multi-monitor fullscreen support
[ryzomcore.git] / web / public_php / api / common / render.php
blob29309bfdca2f1e47461e6e7f9d56c9b8a20a0d04
1 <?php
3 /* Copyright (C) 2009 Winch Gate Property Limited
5 * This file is part of ryzom_api.
6 * ryzom_api is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * ryzom_api is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
20 function ryzom_app_render($title, $content, $style='', $files=array(), $homeLink=false) {
21 $c = '';
23 // get Lua code
24 $c .= ryLua::get(RYZOM_IG);
25 $at_end = ryLua::getEnd(RYZOM_IG);
27 // Render header
28 $title_prefix = '';
29 if (ON_IPHONE) {
30 $title_prefix = 'Ryzom - ';
33 if (!RYZOM_IG)
34 $c .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
35 $c .= '<html><head>'."\n";
36 $c .= ' <title>'.$title_prefix.(translation_exists($title)?_t($title):$title).'</title>'."\n";
37 if (!RYZOM_IG)
38 $c .= ' <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8" />'."\n";
40 $events = '';
41 if (!RYZOM_IG) {
42 $c .= ryzom_render_header();
43 $c .= ryzom_render_header_www();
44 if (function_exists('newrelic_get_browser_timing_header'))
45 $c .= newrelic_get_browser_timing_header();
46 if(ON_IPHONE) $events = 'onorientationchange="updateOrientation();" ';
47 } else {
48 #if (!$style)
49 $style='bgcolor="#00000000"';
52 if (!RYZOM_IG) {
53 // Javascript
54 $extra_code = '';
55 if (is_string($files))
56 $files = array($files);
57 foreach ($files as $file) {
58 $sfile = explode('.', $file);
59 if ($sfile[count($sfile)-1] == 'js')
60 $extra_code .= ' <script type="text/javascript" src="'.$file.'"></script>'."\n";
61 else if ($sfile[count($sfile)-1] == 'css')
62 $extra_code .= ' <link rel="stylesheet" type="text/css" media="all" href="'.$file.'" />'."\n";
64 $c .= $extra_code;
67 $c .= ' </head>'."\n";
68 $c .= ' <body '.$events.' '.$style.'>'."\n";
70 if (!RYZOM_IG) {
71 $c .= ryzom_render_www(ryzom_render_window($title, $content, $homeLink));
72 $c .= '</body>';
73 if (function_exists('newrelic_get_browser_timing_header'))
74 $c .= newrelic_get_browser_timing_footer();
75 } else {
76 $c .= $content.'<br /><table bgcolor="#000000"><tr><td>'.ryLogger::getInstance()->getLogs().'</td></tr></table></body>';
79 $c .= '</html>'.$at_end;
81 return $c;
84 function ryzom_render_header() {
85 if (ON_IPHONE) {
86 return '';
87 } else {
88 return ' <link type="text/css" href="'.RYAPI_URL.'data/css/ryzom_ui.css" rel="stylesheet" media="all" />';
92 // Call this inside the <head> part if you want to use ryzom_render_www
93 function ryzom_render_header_www() {
94 if (ON_IPHONE) {
95 return '
96 <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.8;">
97 <link rel="apple-touch-icon" href="data/img/ryzom_icon.png"/>
98 <link type="text/css" href="data/css/ryzom_iphone.css" rel="stylesheet" media="all" />
99 <script type="text/javascript">
100 window.addEventListener("load", function() { setTimeout(loaded, 100) }, false);
101 window.onload = function initialLoad() { updateOrientation(); }
102 iPhone.DomLoad(updateOrientation);
103 setInterval(updateOrientation, 500);
105 function loaded() {
106 document.getElementById("main").style.visibility = "visible";
107 window.scrollTo(0, 1); // hide the location bar
109 function updateOrientation(){
110 switch (window.orientation) {
111 case 0:
112 case 180:
113 contentType = "show_normal";
114 break;
115 case -90:
116 case 90:
117 default:
118 contentType = "show_wide";
119 break;
121 document.getElementById("main").setAttribute("class", contentType);
123 function sizeTextarea(t) {
124 a = t.value.split(\'\n\');
125 b=1;
126 for (x=0;x < a.length; x++) {
127 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
129 b+= a.length;
130 if (b > t.rows) t.rows = b;
132 </script>
134 } else {
135 return '
136 <style type="text/css">
137 body{background-image:url('.RYAPI_URL.'data/img/bg.jpg);background-repeat:no-repeat;color:white;background-color:black;font-family:arial;font-size:12px}
138 #main{width:95%;height:300px;margin-left:auto;margin-right:auto;text-align:left}
139 a, a:visited{color:orange;font-size:12px}
140 td{font-size:12px}
141 a:hover{color:orange}
142 .error{padding:.5em;background:#ff5555;color:white;font-weight:bold}
143 img{border:0px}
144 textarea{background-color:black;color:white;font-family:arial;font-size:12px}
145 pre{overflow:auto;width:800px}
146 </style>
151 // Render a Ryzom style window
152 function ryzom_render_window($title, $content, $homeLink=false) {
153 return ryzom_render_window_begin($title, $homeLink) . $content . ryzom_render_window_end();
156 function ryzom_render_window_begin($title, $homeLink=false) {
158 if ($homeLink === false)
159 $homeLink = '<span style="float:right;margin-right:12px;"><a href="'.RYAPP_URL.'/index.php" class="ryzom-ui-text-button">'._t('home').'</a></span>';
161 return '
162 <div class="ryzom-ui ryzom-ui-header">
163 <div class="ryzom-ui-tl"><div class="ryzom-ui-tr">
164 <div class="ryzom-ui-t">'.(translation_exists($title)?_t($title):$title).$homeLink.'</div>
165 </div>
166 </div>
167 <div class="ryzom-ui-l"><div class="ryzom-ui-r"><div class="ryzom-ui-m">
168 <div class="ryzom-ui-body">
172 function ryzom_render_window_end() {
173 global $user;
174 return '</div>
175 <div>P_'.(isset($user['id'])?$user['id']:'GUEST').':'.(isset( $user['groups'])?implode(':', $user['groups']):'').'</div>
176 <div style="background-color: #000000">'.ryLogger::getInstance()->getLogs().'</div></div></div></div>
177 <div class="ryzom-ui-bl"><div class="ryzom-ui-br"><div class="ryzom-ui-b"></div></div></div><p class="ryzom-ui-notice">powered by <a class="ryzom-ui-notice" href="http://dev.ryzom.com/projects/ryzom-api/wiki">ryzom-api</a></p>
178 </div>
182 // Render a webpage using www.ryzom.com style
183 function ryzom_render_www($content) {
184 return ryzom_render_www_begin() . $content . ryzom_render_www_end();
187 function ryzom_render_www_begin($url='') {
188 $style1 = 'position: relative; padding-top: 20px; padding-right: 30px; margin-bottom: -3px';
189 $style2 = 'position: absolute; bottom: 0; right: 0; ';
190 if (ON_IPHONE) {
191 $style1 = 'position: relative; padding-top: 30px; padding-right: 30px; ';
192 $style2 = 'position: fixed; top: 0; right: 0; padding-right: 0px;';
193 $marginBottom = '';
195 if (!$url) {
196 $url_params = parse_query($_SERVER['REQUEST_URI']);
197 unset($url_params['lang']);
199 $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.http_build_query($url_params);
201 return '
202 <br />
203 <div id="main">
204 <div style="'.$style1.'">
205 <a href="'.$url.'&lang=en"><img hspace="5" border="0" src="'.RYAPI_URL.'data/img/lang/en.png" alt="English" /></a>
206 <a href="'.$url.'&lang=fr"><img hspace="5" border="0" src="'.RYAPI_URL.'data/img/lang/fr.png" alt="French" /></a>
207 <a href="'.$url.'&lang=de"><img hspace="5" border="0" src="'.RYAPI_URL.'data/img/lang/de.png" alt="German" /></a>
208 <a href="'.$url.'&lang=es"><img hspace="5" border="0" src="'.RYAPI_URL.'data/img/lang/es.png" alt="Spanish" /></a>
209 <a href="'.$url.'&lang=ru"><img hspace="5" border="0" src="'.RYAPI_URL.'data/img/lang/ru.png" alt="Russian" /></a>
210 <div style="'.$style2.'">
211 <a href="http://www.ryzom.com/"><img border="0" src="'.RYAPI_URL.'data/img/logo.gif" alt=""/></a>
212 </div>
213 </div>
217 function ryzom_render_www_end() {
218 return '</div>';
222 function _s($tag, $text) {
223 global $ryzom_render_styles, $ryzom_render_tmpls;
224 if (!array_key_exists($tag, $ryzom_render_tmpls))
225 return $text;
226 if (is_array($text))
227 return $p = $text;
228 else
229 $p[0] = $text;
230 $p['color1'] = $ryzom_render_styles[$tag][0];
231 $p['color2'] = $ryzom_render_styles[$tag][1];
232 $code = '$c = "'.str_replace('"', '\"', $ryzom_render_tmpls[$tag]).'";';
233 eval($code);
234 return $c;
237 function ryzom_get_color_style($tag, $color=0) {
238 global $ryzom_render_styles;
239 if (!array_key_exists($tag, $ryzom_render_styles))
240 return '000000';
241 return $ryzom_render_styles[$tag][$color];
244 function ryzom_set_title($title) {
245 $GLOBALS['ryzom_render_title'] = $title;
248 function ryzom_get_title() {
249 return $GLOBALS['ryzom_render_title'];
252 function ryzom_font($text, $color="", $size="") {
253 if (RYZOM_IG) {
254 $color = $color?'color="'.$color.'"':'';
255 $size = $size?'size="'.$size.'"':'';
256 } else {
257 $color = $color?'color:'.$color.';':'';
258 $size = $size?'font-size:'.$size.'pt':'';
260 return (RYZOM_IG?"<font $color $size>":"<font style=\"$color $size\">").$text.'</font>';
263 function ryzom_render_login_form($char, $aligned=true, $action="") {
264 $c = '';
265 if ($aligned) {
266 $c .= '<form action="'.$action.'" method="post"><table>';
267 $c .= '<tr><td>'._t('enter_char').'</td></tr>';
268 $c .= '<tr><td><input cols="80" style="width: 200px" type="text" name="char" value="'.$char.'"/></td></tr>';
269 $c .= '<tr><td>'._t('enter_password').'</td></tr>';
270 if (RYZOM_IG)
271 $c .= '<tr><td><input cols="80" style="width: 200px" type="text" name="password" /></td></tr>';
272 else
273 $c .= '<tr><td><input style="width: 200px" type="password" name="password" /></td></tr>';
274 $c .= '<tr><td><input type="submit" value="'._t('submit').'" /></td></tr>';
275 } else {
276 $c .= '<form action="'.$action.'" method="post"><table width="100%">';
277 $c .= '<tr><td align="center">'._t('login').'</td></tr>';
278 $c .= '<tr><td align="center"><input cols="80" style="width: 200px" type="text" name="char" value="'.$char.'"/></td></tr>';
279 $c .= '<tr><td align="center">'._t('password').'</td></tr>';
280 if (RYZOM_IG)
281 $c .= '<tr><td align="center"><input cols="80" style="width: 200px" type="text" name="password" /></td></tr>';
282 else
283 $c .= '<tr><td align="center"><input style="width: 200px" type="password" name="password" /></td></tr>';
284 $c .= '<tr><td align="center"><input type="submit" value="'._t('submit').'" /></td></tr>';
286 $c .= '</table></form>';
287 return $c;
290 function ryzom_dialog_yes_no($desc, $action, $name) { // will append ryzom_dialog=yes|no to url
292 return '<table width="100%"><tr bgcolor="#333333"><td height="35px" align="center" valign="middle">'.(RYZOM_IG?'<font color="#DDAA33" size="11">':'<font style="color:#DDAA33; font-size:11pt">').
293 $desc.'<form action="'.$action.'" method="POST">
294 <table width="100%">
295 <tr><td align="center"><select name="'.$name.'"><option value="no">'._t('no').'</option><option value="yes">'._t('yes').'</option></select></td></tr>
296 <tr><td align="center"><input type="submit" value="'._t('submit').'"/></td></tr>
297 </table>
298 </form></font></td></tr></table>';
301 $GLOBALS['ryzom_render_title'] = defined('APP_NAME')?APP_NAME:'Ryzom';
303 $ig = (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Ryzom')) || ryzom_get_param('ig'); // need be set using url param because auth is not done
304 $transparency = $ig?'':'';
305 $ryzom_render_styles = array();
306 $ryzom_render_tmpls = array();
308 $ryzom_render_styles['main title'] = array('#222222'.$transparency, '#FFFFFF');
309 $ryzom_render_tmpls['main title'] = '<table width="100%" cellpadding="0" cellspacing="0"><tr bgcolor="${p[\'color1\']}"><td height="42px" valign="middle"><font '.($ig?'color="${p[\'color2\']}" size="14"':'style="color:${p[\'color2\']};font-size:16pt; font-weight: bold"').'>&nbsp;${p[0]}</font></td></tr></table>'."\n";
311 $ryzom_render_styles['section'] = array('#555555'.$transparency, '#FFFFFF');
312 $ryzom_render_tmpls['section'] = '<table width="100%" cellpadding="0" cellspacing="0"><tr bgcolor="${p[\'color1\']}"><td height="40px" align="left" valign="middle"><font '.($ig?'color="${p[\'color2\']}" size="12"':'style="color:${p[\'color2\']}; font-size:10pt; font-weight: bold"').'>&nbsp;${p[0]}</font></td></tr></table>'."\n";
314 $ryzom_render_styles['color'] = array('', '');
315 $ryzom_render_tmpls['color'] = ($ig?'<font color="${p[0]}">':'<font style="color:${p[0]}">').'${p[0]}</font>';
317 $ryzom_render_styles['link'] = array('#111111', '');
318 $ryzom_render_tmpls['link'] = '<table width="100%" cellpadding="0" cellspacing="0"><tr bgcolor="${p[\'color1\']}" ><td height="24px" valign="middle">&nbsp;${p[0]}</td></tr></table>'."\n";
320 $ryzom_render_styles['button'] = array('#000000', '');
321 $ryzom_render_tmpls['button'] = '<table cellpadding="5" cellspacing="0"><tr bgcolor="${p[\'color1\']}" ><td height="20px" align="center" valign="middle">&nbsp;${p[0]}</td></tr></table>'."\n";
323 $ryzom_render_styles['links'] = array('#111111'.$transparency, '');
324 $ryzom_render_tmpls['links'] = '<table width="100%" cellpadding="0" cellspacing="0"><tr bgcolor="${p[\'color1\']}"><td height="28px" valign="middle">&nbsp;${p[0]}</td></tr></table>'."\n";
326 $ryzom_render_styles['back'] = array('#000000'.$transparency, '');
327 $ryzom_render_tmpls['back'] = '<table cellpadding="0" cellspacing="0" width="100%"><tr valign="middle" bgcolor="${p[\'color1\']}"><td align="left" height="25px" nowrap>&nbsp;<b><a href="${p[0]}">&laquo;'.'main'.'</a></b></td></tr><tr><td>&nbsp;</td></tr></table>';
329 $ryzom_render_styles['highlight'] = array('#55ff55'.$transparency, '');
330 $ryzom_render_tmpls['highlight'] = '<font color="${p[\'color1\']}">${p[0]}</font>';
332 $ryzom_render_styles['backlight'] = array('#272727'.$transparency, '');
333 $ryzom_render_tmpls['backlight'] = '<table width="100%"><tr bgcolor="${p[\'color1\']}"><td height="35px" valign="middle">${p[0]}</td></tr></table>'."\n";
335 $ryzom_render_styles['actionbar'] = array('#555555'.$transparency, '');
336 $ryzom_render_tmpls['actionbar'] = '<tr bgcolor="${p[\'color1\']}" valign="middle">${p[0]}</tr>'."\n";
338 $ryzom_render_styles['table'] = array('#050505'.$transparency, '#FFFFFF');
339 $ryzom_render_tmpls['table'] = '<table width="100%" cellpadding="0" cellspacing="0">${p[0]}</table>'."\n";
341 $ryzom_render_styles['t header'] = array('#111111'.$transparency, '#FFFFFF');
342 $ryzom_render_tmpls['t header'] = '<tr style="color: #FFFFFF" bgcolor="${p[\'color1\']}" valign="middle">${p[0]}</tr>'."\n";
344 $ryzom_render_styles['t row 0'] = array('#353535'.$transparency, '');
345 $ryzom_render_tmpls['t row 0'] = '<tr bgcolor="${p[\'color1\']}" valign="middle">${p[0]}</tr>'."\n";
347 $ryzom_render_styles['t row 1'] = array('#252525'.$transparency, '');
348 $ryzom_render_tmpls['t row 1'] = '<tr bgcolor="${p[\'color1\']}" valign="middle">${p[0]}</tr>'."\n";
350 $ryzom_render_styles['t element'] = array('#FFFFFF'.$transparency, '');
351 $ryzom_render_tmpls['t element'] = '<font color="${p[\'color1\']}">${p[0]}</font>';
353 $ryzom_render_styles['log'] = array('#001100'.$transparency, '');
354 $ryzom_render_tmpls['log'] = '<div style="background-color: ${p[\'color1\']}"><pre style="width: auto">${p[0]}</pre></div>'."\n";
356 $ryzom_render_styles['message'] = array('#445566'.$transparency, '#FFDDAA');
357 $ryzom_render_tmpls['message'] = '<table width="100%" cellspacing="0" cellpadding="0"><tr bgcolor="${p[\'color1\']}"><td height="5px"></td></tr><tr bgcolor="${p[\'color1\']}"><td align="center" valign="middle"><font '.($ig?'color="${p[\'color2\']}" size="16"':'style="color:${p[\'color2\']};font-size:12pt; font-weight: bold"').'>${p[0]}</font></td></tr><tr bgcolor="${p[\'color1\']}"><td height="5px"></td></tr></table>'."\n";
359 $ryzom_render_styles['message warning'] = array('#AA3300'.$transparency, '');
360 $ryzom_render_tmpls['message warning'] = '<table width="100%"><tr bgcolor="${p[\'color1\']}"><td align="center" valign="middle"><h3>&nbsp;${p[0]}</h3></td></tr></table>'."\n";
362 $ryzom_render_styles['message window'] = array('#5555ff'.$transparency, '#7799ff');
363 $ryzom_render_tmpls['message window'] = '<table width="100%" cellspacing="0" cellpadding="0"><tr><td bgcolor="${p[\'color2\']}" width="3px"></td><td height="3px" bgcolor="${p[\'color2\']}"></td><td bgcolor="${p[\'color2\']}"></td><td bgcolor="${p[\'color2\']}" width="3px"></td></tr>'.'<tr><td bgcolor="${p[\'color2\']}" width="3px"></td><td bgcolor="${p[\'color1\']}" align="center" valign="middle">${p[0]}</td><td bgcolor="${p[\'color1\']}" valign="top" align="right">${p[0]}</td><td width="3px" bgcolor="${p[\'color2\']}"></td>'.
364 '<tr bgcolor="${p[\'color1\']}"><td bgcolor="${p[\'color2\']}" width="3px"></td><td height="3px" bgcolor="${p[\'color2\']}"></td><td bgcolor="${p[\'color2\']}" width="3px"></td><td bgcolor="${p[\'color2\']}"></td></tr></table>'."\n";
366 $ryzom_render_styles['message ask'] = array('#333333'.$transparency, '');
367 $ryzom_render_tmpls['message ask'] = '<table width="100%"><tr bgcolor="${p[\'color1\']}"><td valign="middle">'.($ig?'<font color="#DDAA33" size="11">':'<font style="color:#DDAA33; font-size:11pt">').'${p[0]}</font></td></tr></table>'."\n";
369 $ryzom_render_styles['message error'] = array('#AA2222'.$transparency, '');
370 $ryzom_render_tmpls['message error'] = '<table width="100%"><tr bgcolor="${p[\'color1\']}"><td height="30px" align="center" valign="middle"><h3>&nbsp;${p[0]}</h3></td></tr></table>'."\n";
372 $ryzom_render_styles['message debug'] = array('#FFAA22'.$transparency, '');
373 $ryzom_render_tmpls['message debug'] = '<table width="100%"><tr bgcolor="${p[\'color1\']}"><td height="30px" valign="middle"><font color="#000">${p[0]}</font></td></tr></table>'."\n";
375 $ryzom_render_styles['progress bar'] = array('#FF0000'.$transparency, '#000000');
376 $ryzom_render_tmpls['progress bar'] = '<table width="100%"><tr><td bgcolor="${p[\'color1\']}" height="30px" width="${p[0]}%" align="center" valign="middle">&nbsp;</td>${p[0]}<td bgcolor="${p[\'color2\']}" height="30px" valign="middle" align="center">${p[0]}&nbsp;</td></tr></table>'."\n";