1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-25 00:41:52 +02:00

Bugfix: admin headers/footers just as much a mess as non-admin. Rearranged and doc's to match

spec, and also (mostly) be comparable to header_default and
 footer_default so bugfixes can more easily
 go in both. Side effect: admin code is now debuggable (debug options all work).
This commit is contained in:
mrpete
2006-12-05 09:28:02 +00:00
parent c9e582b6a4
commit 035ec70681
2 changed files with 354 additions and 86 deletions

View File

@@ -11,16 +11,51 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/footer.php,v $
| $Revision: 1.1.1.1 $
| $Date: 2006-12-02 04:33:22 $
| $Author: mcfly_e107 $
| $Revision: 1.2 $
| $Date: 2006-12-05 09:28:02 $
| $Author: mrpete $
+----------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
$In_e107_Footer = TRUE; // For registered shutdown function
global $eTraffic, $error_handler, $db_time, $sql, $mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb, $ADMIN_FOOTER, $e107;
global $ADMIN_FOOTER, $footer_js, $sql;
//
// SHUTDOWN SEQUENCE
//
// The following items have been carefully designed so page processing will finish properly
// Please DO NOT re-order these items without asking first! You WILL break something ;)
// These letters match the USER footer (that's why there is B.1,B.2)
//
// A Ensure sql and traffic objects exist
// B.1 Clear cache if over a week old
// B.2 Send the footer templated data
// C Dump any/all traffic and debug information
// [end of regular-page-only items]
// D Close the database connection
// E Themed footer code
// F Configured footer scripts
// G Browser-Server time sync script (must be the last one generated/sent)
// H Final HTML (/body, /html)
// I collect and send buffered page, along with needed headers
//
//
// A Ensure sql and traffic objects exist
//
if(!is_object($sql)){
// reinstigate db connection if another connection from third-party script closed it ...
$sql = new db;
$sql -> db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);
}
if (!is_object($eTraffic)) {
$eTraffic = new e107_traffic;
$eTraffic->Bump('Lost Traffic Counters');
}
//
// B.1 Clear cache if over a week old
//
if (ADMIN == TRUE) {
if ($pref['cachestatus']) {
if (!$sql->db_Select('generic', '*', "gen_type='empty_cache'"))
@@ -38,50 +73,117 @@ if (ADMIN == TRUE) {
}
}
}
//
// B.2 Send footer template
//
if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE) {
parse_admin($ADMIN_FOOTER);
}
//
// C Dump all debug and traffic information
//
$eTimingStop = microtime();
global $eTimingStart, $eTraffic;
global $eTimingStart;
$rendertime = number_format($eTraffic->TimeDelta( $eTimingStart, $eTimingStop ), 4);
$db_time = number_format($db_time,4);
$rinfo = '';
if($pref['displayrendertime']){ $rinfo .= "Render time: {$rendertime} second(s); {$db_time} of that for queries. "; }
if($pref['displaysql']){ $rinfo .= "DB queries: ".$sql -> db_QueryCount().". "; }
if(isset($pref['displaycacheinfo']) && $pref['displaycacheinfo']){ $rinfo .= $cachestring."."; }
echo ($rinfo ? "\n<div style='text-align:center' class='smalltext'>{$rinfo}</div>\n" : "");
if($pref['displayrendertime']){ $rinfo .= "Render time: {$rendertime} second(s); {$db_time} of that for queries. "; }
if($pref['displaysql']){ $rinfo .= "DB queries: ".$sql -> db_QueryCount().". "; }
if(isset($pref['display_memory_usage']) && $pref['display_memory_usage']){ $rinfo .= "Memory Usage: ".$e107->get_memory_usage(); }
if(isset($pref['displaycacheinfo']) && $pref['displaycacheinfo']){ $rinfo .= $cachestring."."; }
echo ($rinfo ? "\n<div style='text-align:center' class='smalltext'>{$rinfo}</div>\n" : "");
if($error_handler->debug == true) {
echo "
<br /><br />";
if ((ADMIN || $pref['developer']) && E107_DEBUG_LEVEL) {
global $db_debug;
echo "\n<!-- DEBUG -->\n";
$db_debug->Show_All();
}
/*
changes by jalist 24/01/2005:
show sql queries
usage: add ?showsql to query string, must be admin
*/
if(ADMIN && isset($queryinfo) && is_array($queryinfo))
{
$c=1;
$mySQLInfo = $sql->mySQLinfo;
echo "<table class='fborder' style='width: 100%;'>
<tr>
<td class='fcaption' style='width: 5%;'>ID</td><td class='fcaption' style='width: 95%;'>SQL Queries</td>\n</tr>\n";
foreach ($queryinfo as $infovalue)
{
echo "<tr>\n<td class='forumheader3' style='width: 5%;'>{$c}</td><td class='forumheader3' style='width: 95%;'>{$infovalue}</td>\n</tr>\n";
$c++;
}
echo "</table>";
}
//
// D Close DB connection. We're done talking to underlying MySQL
//
$sql -> db_Close(); // Only one is needed; the db is only connected once even with several $sql objects
//
// Just before we quit: dump quick timer if there is any
// Works any time we get this far. Not calibrated, but it is quick and simple to use.
// To use: eQTimeOn(); eQTimeOff();
//
$tmp = eQTimeElapsed();
if (strlen($tmp)) {
global $ns;
$ns->tablerender('Quick Admin Timer',"Results: {$tmp} microseconds");
}
if ($pref['developer']) {
global $oblev_at_start,$oblev_before_start;
if (ob_get_level() != $oblev_at_start) {
$oblev = ob_get_level();
$obdbg = "<div style='text-align:center' class='smalltext'>Software defect detected; ob_*() level {$oblev} at end instead of ($oblev_at_start). POPPING EXTRA BUFFERS!</div>";
while (ob_get_level() > $oblev_at_start) {
ob_end_flush();
}
echo $obdbg;
}
// 061109 PHP 5 has a bug such that the starting level might be zero or one.
// Until they work that out, we'll disable this message.
// Devs can re-enable for testing as needed.
//
if (0 && $oblev_before_start != 0) {
$obdbg = "<div style='text-align:center' class='smalltext'>Software warning; ob_*() level {$oblev_before_start} at start; this page not properly integrated into its wrapper.</div>";
echo $obdbg;
}
}
if((ADMIN == true || $pref['developer']) && $error_handler->debug == true) {
echo "
<br /><br />
<div>
<h3>PHP Errors:</h3><br />
".$error_handler->return_errors()."
</div>
";
$tmp = $eTraffic->Display();
if (strlen($tmp)) {
$ns->tablerender('Traffic Counters', $tmp);
}
$tmp = $db_debug->Show_Performance();
if (strlen($tmp)) {
$ns->tablerender('Time Analysis', $tmp);
}
$tmp = $db_debug->Show_SQL_Details();
if (strlen($tmp)) {
$ns->tablerender('SQL Analysis', $tmp);
}
}
//
// E Last themed footer code, usually JS
//
if (function_exists('theme_foot'))
{
echo theme_foot();
}
//
// F any included JS footer scripts
//
global $footer_js;
if(isset($footer_js) && is_array($footer_js))
{
$footer_js = array_unique($footer_js);
@@ -92,8 +194,57 @@ if(isset($footer_js) && is_array($footer_js))
}
}
//
// G final JS script keeps user and server time in sync.
// It must be the last thing created before sending the page to the user.
//
// see e107.js and class2.php
// This must be done as late as possible in page processing.
$_serverTime=time();
$lastSet = isset($_COOKIE['e107_tdSetTime']) ? $_COOKIE['e107_tdSetTime'] : 0;
if (abs($_serverTime - $lastSet) > 120) {
/* update time delay every couple of minutes.
* Benefit: account for user time corrections and changes in internet delays
* Drawback: each update may cause all server times to display a bit different
*/
echo "<script type='text/javascript'>\n";
echo "SyncWithServerTime('{$_serverTime}');
</script>\n";
}
//
// H Final HTML
//
echo "</body></html>";
$sql->db_Close();
//
// I Send the buffered page data, along with appropriate headers
//
$page = ob_get_clean();
$etag = md5($page);
header("Cache-Control: must-revalidate");
header("ETag: {$etag}");
$pref['compression_level'] == 6;
if(strstr($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") || strstr($_SERVER['HTTP_USER_AGENT'], "Mozilla")) {
$browser_support = true;
}
if(ini_get("zlib.output_compression") == false && function_exists("gzencode")) {
$server_support = true;
}
if($pref['compress_output'] == true && $server_support == true && $browser_support == true) {
$level = intval($pref['compression_level']);
$page = gzencode($page, $level);
header("Content-Encoding: gzip", true);
header("Content-Length: ".strlen($page), true);
echo $page;
} else {
header("Content-Length: ".strlen($page), true);
echo $page;
}
unset($In_e107_Footer);
$e107_Clean_Exit=TRUE; // For registered shutdown function -- let it know all is well!
?>

View File

@@ -12,22 +12,66 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/header.php,v $
| $Revision: 1.1.1.1 $
| $Date: 2006-12-02 04:33:22 $
| $Author: mcfly_e107 $
| $Revision: 1.2 $
| $Date: 2006-12-05 09:28:02 $
| $Author: mrpete $
+---------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
define("ADMIN_AREA",TRUE);
define("USER_AREA",FALSE);
$sql->db_Mark_Time('(Header Top)');
// send the charset to the browser - overides spurious server settings with the lan pack settings.
//
// *** Code sequence for headers ***
// IMPORTANT: These items are in a carefully constructed order. DO NOT REARRANGE
// without checking with experienced devs! Various subtle things WILL break.
//
// We realize this is a bit (!) of a mess and hope to make further cleanups in a future release.
//
// A: Admin Defines and Links
// B: Send HTTP headers that come before any html
// C: Send start of HTML
// D: Send JS
// E: Send CSS
// F: Send Meta Tags and Icon links
// G: Send final theme headers (theme_head() function)
// H: Generate JS for image preloading (setup for onload)
// I: Calculate onload() JS functions to be called
// J: Send end of html <head> and start of <body>
// K: (The rest is ignored for popups, which have no menus)
// L: (optional) Body JS to disable right clicks
// M: Send top of body for custom pages and for news
// N: Send other top-of-body HTML
//
// Load order notes for devs
// * Browsers wait until ALL HTML has loaded before executing ANY JS
// * The last CSS tag downloaded supercedes earlier CSS tags
// * Browsers don't care when Meta tags are loaded. We load last due to
// a quirk of e107's log subsystem.
// * Multiple external <link> file references slow down page load. Each one requires
// browser-server interaction even when cached.
//
//
// A: Admin Defines and Links
//
require_once(e_ADMIN.'ad_links.php');
//
// B: Send HTTP headers (these come before ANY html)
//
// send the charset to the browser - overrides spurious server settings with the lan pack settings.
header("Content-type: text/html; charset=".CHARSET, true);
require_once(e_ADMIN.'ad_links.php');
echo defined('STANDARDS_MODE') ? "" :
"<?xml version='1.0' encoding='".CHARSET."' ?>";
echo (defined("STANDARDS_MODE") ? "" : "<?xml version='1.0' encoding='".CHARSET."' "."?".">\n")."<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
//
// B.2: Include admin LAN defines
//
if (file_exists(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_header.php')) {
@include_once(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_header.php");
} else {
@@ -69,49 +113,37 @@ if (!defined('ADMIN_DELETE_ICON'))
define("ADMIN_DELETE_ICON_PATH", e_IMAGE."admin_images/delete_16.png");
}
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns='http://www.w3.org/1999/xhtml'".(defined("TEXTDIRECTION") ? " dir='".TEXTDIRECTION."'" : "").(defined("CORE_LC") ? " xml:lang=\"".CORE_LC."\"" : "").">
//
// C: Send start of HTML
//
echo "<html xmlns='http://www.w3.org/1999/xhtml'".(defined("TEXTDIRECTION") ? " dir='".TEXTDIRECTION."'" : "").(defined("CORE_LC") ? " xml:lang=\"".CORE_LC."\"" : "").">
<head>
<title>".SITENAME." : ".LAN_head_4."</title>\n";
echo "<meta http-equiv='content-type' content='text/html; charset=".CHARSET."' />
<meta http-equiv='content-style-type' content='text/css' />\n";
if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE && isset($pref['admincss']) && $pref['admincss'] && file_exists(THEME.$pref['admincss'])) {
$css_file = file_exists(THEME.'admin_'.$pref['admincss']) ? THEME_ABS.'admin_'.$pref['admincss'] : THEME_ABS.$pref['admincss'];
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
} else if (isset($pref['themecss']) && $pref['themecss'] && file_exists(THEME.$pref['themecss'])) {
$css_file = file_exists(THEME.'admin_'.$pref['themecss']) ? THEME_ABS.'admin_'.$pref['themecss'] : THEME_ABS.$pref['themecss'];
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
} else {
$css_file = file_exists(THEME.'admin_style.css') ? THEME_ABS.'admin_style.css' : THEME_ABS.'style.css';
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
//
// D: Send JS
//
echo "<!-- *JS* -->\n";
// Wysiwyg JS support on or off.
if (/* isset($WYSIWYG) && $WYSIWYG == TRUE && */ check_class($pref['post_html']) && isset($e_wysiwyg) && $e_wysiwyg != "") {
require_once(e_HANDLER."tiny_mce/wysiwyg.php");
define("e_WYSIWYG",TRUE);
echo wysiwyg($e_wysiwyg);
}else{
define("e_WYSIWYG",FALSE);
}
if (!isset($no_core_css) || !$no_core_css) {
echo "<link rel='stylesheet' href='".e_FILE_ABS."e107.css' type='text/css' />\n";
}
// ---------- Favicon ---------
if (file_exists(THEME."favicon.ico")) {
echo "<link rel='icon' href='".THEME_ABS."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".THEME_ABS."favicon.ico' type='image/xicon' />\n";
}elseif (file_exists(e_BASE."favicon.ico")) {
echo "<link rel='icon' href='".SITEURL."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".SITEURL."favicon.ico' type='image/xicon' />\n";
}
if (function_exists('theme_head')) {
echo theme_head();
}
if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE) {
echo "<script type='text/javascript' src='".e_FILE_ABS."e107.js'></script>\n";
}
if (file_exists(THEME."theme.js")) {
echo "<script type='text/javascript' src='".THEME_ABS."theme.js'></script>\n";
}
if (filesize(e_FILE.'user.js')) {
echo "<script type='text/javascript' src='".e_FILE_ABS."user.js'></script>\n";
}
if (function_exists("headerjs")) {
echo headerjs();
if (file_exists(THEME.'theme.js')) { echo "<script type='text/javascript' src='".THEME_ABS."theme.js'></script>\n"; }
if (filesize(e_FILE.'user.js')) { echo "<script type='text/javascript' src='".e_FILE_ABS."user.js'></script>\n"; }
if (isset($eplug_js) && $eplug_js) {
echo "\n<!-- eplug_js -->\n";
echo "<script type='text/javascript' src='{$eplug_js}'></script>\n";
}
if (isset($htmlarea_js) && $htmlarea_js) {
echo $htmlarea_js;
@@ -129,32 +161,115 @@ function savepreset(ps,pid){
//-->
</script>\n";
}
if (isset($eplug_js) && $eplug_js) {
echo "<script type='text/javascript' src='{$eplug_js}'></script>\n";
}
if (function_exists('headerjs')){echo headerjs(); }
//
// E: Send CSS
//
echo "<!-- *CSS* -->\n";
if (isset($eplug_css) && $eplug_css) {
echo "\n<link rel='stylesheet' href='{$eplug_css}' type='text/css' />\n";
echo "\n<!-- eplug_css -->\n";
echo "<link rel='stylesheet' href='{$eplug_css}' type='text/css' />\n";
}
if(check_class($pref['post_html']) && $pref['wysiwyg'] && $e_wysiwyg == TRUE){
require_once(e_HANDLER."tiny_mce/wysiwyg.php");
echo wysiwyg($e_wysiwyg);
define("e_WYSIWYG",TRUE);
}else{
define("e_WYSIWYG",FALSE);
}
// load plugin header-data.
foreach($pref['e_meta_list'] as $val)
echo "<!-- Theme css -->\n";
if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE && isset($pref['admincss']) && $pref['admincss'] && file_exists(THEME.$pref['admincss'])) {
$css_file = file_exists(THEME.'admin_'.$pref['admincss']) ? THEME_ABS.'admin_'.$pref['admincss'] : THEME_ABS.$pref['admincss'];
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
} else if (isset($pref['themecss']) && $pref['themecss'] && file_exists(THEME.$pref['themecss']))
{
if(is_readable(e_PLUGIN.$val."/e_meta.php"))
$css_file = file_exists(THEME.'admin_'.$pref['themecss']) ? THEME_ABS.'admin_'.$pref['themecss'] : THEME_ABS.$pref['themecss'];
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
}
else
{
$css_file = file_exists(THEME.'admin_style.css') ? THEME_ABS.'admin_style.css' : THEME_ABS.'style.css';
echo "<link rel='stylesheet' href='".$css_file."' type='text/css' />\n";
}
if (!isset($no_core_css) || !$no_core_css) {
echo "<link rel='stylesheet' href='".e_FILE_ABS."e107.css' type='text/css' />\n";
}
//
// F: Send Meta Tags and Icon links
//
echo "<!-- *META* -->\n";
// Multi-Language meta-tags with merge and override option.
echo "<meta http-equiv='content-type' content='text/html; charset=".CHARSET."' />
<meta http-equiv='content-style-type' content='text/css' />\n";
// --- Load plugin Meta files and eplug_ before others --------
if (is_array($pref['e_meta_list']))
{
foreach($pref['e_meta_list'] as $val)
{
require_once(e_PLUGIN.$val."/e_meta.php");
if(is_readable(e_PLUGIN.$val."/e_meta.php"))
{
echo "<!-- $val meta -->\n";
require_once(e_PLUGIN.$val."/e_meta.php");
}
}
}
// ---------- Favicon ---------
if (file_exists(THEME."favicon.ico")) {
echo "<link rel='icon' href='".THEME_ABS."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".THEME_ABS."favicon.ico' type='image/xicon' />\n";
}elseif (file_exists(e_BASE."favicon.ico")) {
echo "<link rel='icon' href='".SITEURL."favicon.ico' type='image/x-icon' />\n<link rel='shortcut icon' href='".SITEURL."favicon.ico' type='image/xicon' />\n";
}
//
// G: Send Theme Headers
//
if(function_exists('theme_head')){
echo "\n<!-- *THEME HEAD* -->\n";
echo theme_head();
}
//
// H: Generate JS for image preloads [user mode only]
//
echo "\n<!-- *PRELOAD* -->\n";
//
// I: Calculate JS onload() functions for the BODY tag [user mode only]
//
$body_onload = "";
//
// J: Send end of <head> and start of <body>
//
echo "</head>
<body>\n";
<body".$body_onload.">\n";
$sql->db_Mark_Time("End Head, Start Body");
//
// K: (The rest is ignored for popups, which have no menus) [reserved; user mode]
//
//
// L: (optional) Body JS to disable right clicks [reserved; user mode]
//
//
// M: Send top of body for custom pages and for news [user mode only]
//
//
// N: Send other top-of-body HTML
//
$ns = new e107table;
$e107_var = array();
@@ -329,8 +444,10 @@ function admin_purge_related($table, $id)
}
}
$sql->db_Mark_Time('Parse Admin Header');
if (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE) {
parse_admin($ADMIN_HEADER);
}
$sql->db_Mark_Time('(End: Parse Admin Header)');
?>