2009-10-01 15:05:41 +00:00
< ? php
2006-12-02 04:36:16 +00:00
/*
2010-07-26 21:47:31 +00:00
* e107 website system
*
2012-10-16 07:35:42 +00:00
* Copyright 2008 - 2012 e107 Inc ( e107 . org )
2010-07-26 21:47:31 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Default footer for user pages
*
* $URL $
* $Id $
*
*/
2009-10-01 15:05:41 +00:00
if ( ! defined ( 'e107_INIT' ))
{
exit ;
}
$In_e107_Footer = TRUE ; // For registered shutdown function
2006-12-02 04:36:16 +00:00
2009-10-01 15:05:41 +00:00
global $error_handler , $db_time , $FOOTER ;
2006-12-02 04:36:16 +00:00
2010-10-26 07:41:20 +00:00
// Clean session shutdown
e107 :: getSession () -> shutdown ();
2011-12-06 08:00:42 +00:00
// System browser CACHE control - defaults to no cache; override in e107_config or on the fly
// This is temporary solution, we'll implement more flexible way for cache control override
// per page, more investigation needed about cache related headers, browser quirks etc
2012-12-15 10:25:14 +02:00
// Auto-detect from session (registered per page, per user session)
2011-12-06 08:00:42 +00:00
if ( ! defined ( 'e_NOCACHE' ))
{
2012-12-15 10:25:14 +02:00
define ( 'e_NOCACHE' , ! e107 :: canCache ());
2011-12-06 08:00:42 +00:00
}
2006-12-02 04:36:16 +00:00
//
// 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 ;)
2007-03-04 22:04:18 +00:00
// These letters match the ADMIN footer (that's why there is B.1,B.2)
2006-12-02 04:36:16 +00:00
//
2007-01-17 13:43:14 +00:00
// A Ensure sql and traffic objects exist
2006-12-02 04:36:16 +00:00
// [Next few ONLY if a regular page; not done for popups]
2007-03-04 22:04:18 +00:00
// B.1 Clear cache (if admin page, not here)
// B.2 Send the footer templated data
2006-12-02 04:36:16 +00:00
// 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
2007-01-17 13:43:14 +00:00
//
2009-10-01 15:05:41 +00:00
$e107 = e107 :: getInstance ();
2009-09-13 10:29:56 +00:00
$sql = e107 :: getDb ();
2009-10-01 15:05:41 +00:00
$pref = e107 :: getPref ();
2006-12-02 04:36:16 +00:00
2009-10-01 15:05:41 +00:00
if ( varset ( $e107_popup ) != 1 )
2008-11-23 22:49:52 +00:00
{
2006-12-02 04:36:16 +00:00
//
2007-03-04 22:04:18 +00:00
// B.1 Clear cache (admin-only)
//
2009-10-01 15:05:41 +00:00
2007-03-04 22:04:18 +00:00
//
// B.2 Send footer template, stop timing, send simple page stats
2006-12-02 04:36:16 +00:00
//
2013-02-27 04:03:13 -08:00
if ( ! deftrue ( 'e_IFRAME' ))
{
parseheader (( varset ( $ph ) ? $cust_footer : $FOOTER ));
}
2006-12-02 04:36:16 +00:00
$eTimingStop = microtime ();
global $eTimingStart ;
2009-10-01 15:05:41 +00:00
$clockTime = e107 :: getSingleton ( 'e107_traffic' ) -> TimeDelta ( $eTimingStart , $eTimingStop );
2007-03-04 22:04:18 +00:00
$dbPercent = 100.0 * $db_time / $clockTime ;
// Format for display or logging
2009-10-01 15:05:41 +00:00
$rendertime = number_format ( $clockTime , 2 ); // Clock time during page render
$db_time = number_format ( $db_time , 2 ); // Clock time in DB render
$dbPercent = number_format ( $dbPercent , 0 ); // DB as percent of clock
2012-01-02 13:12:48 +00:00
$memuse = eHelper :: getMemoryUsage (); // Memory at end, in B/KB/MB/GB ;)
2009-10-01 15:05:41 +00:00
$queryCount = $sql -> db_QueryCount ();
2006-12-02 04:36:16 +00:00
$rinfo = '' ;
2008-11-23 22:49:52 +00:00
$logLine = '' ;
if ( $pref [ 'log_page_accesses' ])
2009-10-01 15:05:41 +00:00
{ // Collect the first batch of data to log
2012-06-17 12:19:05 +00:00
$logLine .= " ' " . ( $now = time ()) . " ',' " . gmstrftime ( '%y-%m-%d %H:%M:%S' , $now ) . " ',' " . e107 :: getIPHandler () -> getIP ( FALSE ) . " ',' " . e_PAGE . '?' . e_QUERY . " ',' " . $rendertime . " ',' " . $db_time . " ',' " . $queryCount . " ',' " . $memuse . " ',' " . $_SERVER [ 'HTTP_USER_AGENT' ] . " ',' { $_SERVER [ " REQUEST_METHOD " ] } ' " ;
2008-11-23 22:49:52 +00:00
}
2009-10-01 15:05:41 +00:00
if ( function_exists ( 'getrusage' ))
2007-08-13 19:56:46 +00:00
{
2007-03-04 22:04:18 +00:00
$ru = getrusage ();
$cpuUTime = $ru [ 'ru_utime.tv_sec' ] + ( $ru [ 'ru_utime.tv_usec' ] * 1e-6 );
$cpuSTime = $ru [ 'ru_stime.tv_sec' ] + ( $ru [ 'ru_stime.tv_usec' ] * 1e-6 );
$cpuUStart = $eTimingStartCPU [ 'ru_utime.tv_sec' ] + ( $eTimingStartCPU [ 'ru_utime.tv_usec' ] * 1e-6 );
$cpuSStart = $eTimingStartCPU [ 'ru_stime.tv_sec' ] + ( $eTimingStartCPU [ 'ru_stime.tv_usec' ] * 1e-6 );
$cpuStart = $cpuUStart + $cpuSStart ;
2009-10-01 15:05:41 +00:00
$cpuTot = $cpuUTime + $cpuSTime ;
2007-03-04 22:04:18 +00:00
$cpuTime = $cpuTot - $cpuStart ;
$cpuPct = 100.0 * $cpuTime / $rendertime ; /* CPU load during known clock time */
// Format for display or logging (Uncomment as needed for logging)
//$cpuUTime = number_format($cpuUTime, 3); // User cpu
//$cpuSTime = number_format($cpuSTime, 3); // System cpu
//$cpuTot = number_format($cpuTot, 3); // Total (User+System)
2009-10-01 15:05:41 +00:00
$cpuStart = number_format ( $cpuStart , 3 ); // Startup time (i.e. CPU used before class2.php)
$cpuTime = number_format ( $cpuTime , 3 ); // CPU while we were measuring the clock (cpuTot-cpuStart)
$cpuPct = number_format ( $cpuPct , 0 ); // CPU Load (CPU/Clock)
2007-03-04 22:04:18 +00:00
}
//
// Here's a good place to log CPU usage in case you want graphs and/or your host cares about that
// e.g. (on a typical vhosted linux host)
2009-10-01 15:05:41 +00:00
//
2007-03-04 22:04:18 +00:00
// $logname = "/home/mysite/public_html/queryspeed.log";
// $logfp = fopen($logname, 'a+'); fwrite($logfp, "$cpuTot,$cpuPct,$cpuStart,$rendertime,$db_time\n"); fclose($logfp);
2009-10-01 15:05:41 +00:00
if ( $pref [ 'displayrendertime' ])
{
2007-08-13 19:56:46 +00:00
$rinfo .= CORE_LAN11 ;
2009-10-01 15:05:41 +00:00
if ( isset ( $cpuTime ))
2007-08-13 19:56:46 +00:00
{
2009-10-01 15:05:41 +00:00
// $rinfo .= "{$cpuTime} cpu sec ({$cpuPct}% load, {$cpuStart} startup). Clock: ";
$rinfo .= sprintf ( CORE_LAN14 , $cpuTime , $cpuPct , $cpuStart );
2007-03-04 22:04:18 +00:00
}
2009-10-01 15:05:41 +00:00
$rinfo .= $rendertime . CORE_LAN12 . $dbPercent . CORE_LAN13 . ' ' ;
2007-03-04 22:04:18 +00:00
}
2009-10-01 15:05:41 +00:00
if ( $pref [ 'displaysql' ])
{
$rinfo .= CORE_LAN15 . $queryCount . " . " ;
}
if ( isset ( $pref [ 'display_memory_usage' ]) && $pref [ 'display_memory_usage' ])
{
$rinfo .= CORE_LAN16 . $memuse ;
}
if ( isset ( $pref [ 'displaycacheinfo' ]) && $pref [ 'displaycacheinfo' ])
{
$rinfo .= $cachestring . " . " ;
}
2008-11-23 22:49:52 +00:00
if ( $pref [ 'log_page_accesses' ])
2009-11-17 09:17:08 +00:00
{
// Need to log the page info to a text file as CSV data
2012-06-22 07:01:32 +00:00
$logname = e_LOG . " logd_ " . date ( " Y-m-d " , time ()) . " .csv " ;
2012-06-17 12:19:05 +00:00
$logHeader = " Unix time,Date/Time,IP,URL,RenderTime,DbTime,Qrys,Memory-Usage,User-Agent,Request-Method " ;
2008-11-23 22:49:52 +00:00
$logfp = fopen ( $logname , 'a+' );
2012-06-17 12:19:05 +00:00
if ( filesize ( $logname ) == 0 || ! is_file ( $logname ))
{
fwrite ( $logfp , $logHeader . " \n " );
}
2009-10-01 15:05:41 +00:00
fwrite ( $logfp , $logLine . " \n " );
2008-11-23 22:49:52 +00:00
fclose ( $logfp );
}
2009-10-01 15:05:41 +00:00
2012-12-16 21:03:46 -08:00
if ( function_exists ( 'theme_renderinfo' ))
2007-03-04 22:04:18 +00:00
{
theme_renderinfo ( $rinfo );
}
2009-10-01 15:05:41 +00:00
else
{
2013-06-20 01:31:03 -07:00
echo ( $rinfo ? " \n <div class='e-footer-info muted smalltext'><small> { $rinfo } </small></div> \n " : " " );
2009-10-01 15:05:41 +00:00
}
2007-01-17 13:43:14 +00:00
} // End of regular-page footer (the above NOT done for popups)
2007-03-04 22:04:18 +00:00
//
// C Dump all debug and traffic information
//
2009-10-01 15:05:41 +00:00
if (( ADMIN || $pref [ 'developer' ]) && E107_DEBUG_LEVEL )
{
global $db_debug ;
echo " \n <!-- DEBUG --> \n <div class='e-debug debug-info'> " ;
$db_debug -> Show_All ();
echo " </div> \n " ;
}
2007-03-04 22:04:18 +00:00
2009-10-01 15:05:41 +00:00
/*
changes by jalist 24 / 01 / 2005 :
show sql queries
usage : add ? showsql to query string , must be admin
*/
2007-03-04 22:04:18 +00:00
2009-10-01 15:05:41 +00:00
if ( ADMIN && isset ( $queryinfo ) && is_array ( $queryinfo ))
{
$c = 1 ;
$mySQLInfo = $sql -> mySQLinfo ;
echo " <div class='e-debug query-notice'><table class='fborder' style='width: 100%;'>
2006-12-02 04:36:16 +00:00
< tr >
< td class = 'fcaption' style = 'width: 5%;' > ID </ td >< td class = 'fcaption' style = 'width: 95%;' > SQL Queries </ td > \n </ tr > \n " ;
2009-10-01 15:05:41 +00:00
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 ++ ;
2006-12-02 04:36:16 +00:00
}
2009-10-01 15:05:41 +00:00
echo " </table></div> " ;
}
2006-12-02 04:36:16 +00:00
//
// D Close DB connection. We're done talking to underlying MySQL
//
2009-10-01 15:05:41 +00:00
$sql -> db_Close (); // Only one is needed; the db is only connected once even with several $sql objects
2006-12-02 04:36:16 +00:00
2009-10-01 15:05:41 +00:00
//
// 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 " );
}
2007-03-04 22:04:18 +00:00
2009-10-01 15:05:41 +00:00
if ( $pref [ 'developer' ])
{
2006-12-02 04:36:16 +00:00
global $oblev_at_start , $oblev_before_start ;
2009-10-01 15:05:41 +00:00
if ( ob_get_level () != $oblev_at_start )
{
2006-12-02 04:36:16 +00:00
$oblev = ob_get_level ();
2009-10-01 15:05:41 +00:00
$obdbg = " <div class='e-debug ob-error'>Software defect detected; ob_*() level { $oblev } at end instead of ( $oblev_at_start ). POPPING EXTRA BUFFERS!</div> " ;
while ( ob_get_level () > $oblev_at_start )
{
2006-12-02 04:36:16 +00:00
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.
//
2009-10-01 15:05:41 +00:00
if ( 0 && $oblev_before_start != 0 )
{
$obdbg = " <div class='e-debug ob-error'>Software warning; ob_*() level { $oblev_before_start } at start; this page not properly integrated into its wrapper.</div> " ;
2006-12-02 04:36:16 +00:00
echo $obdbg ;
}
}
2009-10-01 15:05:41 +00:00
if (( ADMIN == true || $pref [ 'developer' ]) && count ( $error_handler -> errors ) && $error_handler -> debug == true )
2007-03-04 22:04:18 +00:00
{
2009-10-01 15:05:41 +00:00
$tmp = $error_handler -> return_errors ();
if ( $tmp )
{
echo "
< div class = 'e-debug php-errors block-text' >
< h3 > PHP Errors :</ h3 >< br />
" . $tmp . "
</ div >
" ;
}
unset ( $tmp );
2006-12-02 04:36:16 +00:00
}
//
// E Last themed footer code, usually JS
//
2006-12-05 09:33:20 +00:00
if ( function_exists ( 'theme_foot' ))
{
2006-12-02 04:36:16 +00:00
echo theme_foot ();
}
//
// F any included JS footer scripts
2009-10-01 15:05:41 +00:00
// DEPRECATED - use e107::getJs()->footerFile('{e_PLUGIN}myplug/js/my.js', $zone = 2)
2006-12-02 04:36:16 +00:00
//
global $footer_js ;
2009-10-01 15:05:41 +00:00
if ( isset ( $footer_js ) && is_array ( $footer_js ))
2006-12-02 04:36:16 +00:00
{
$footer_js = array_unique ( $footer_js );
2009-10-01 15:05:41 +00:00
foreach ( $footer_js as $fname )
2006-12-02 04:36:16 +00:00
{
echo " <script type='text/javascript' src=' { $fname } '></script> \n " ;
$js_included [] = $fname ;
}
}
2009-10-01 15:05:41 +00:00
// [JSManager] Load JS Footer Includes by priority
e107 :: getJs () -> renderJs ( 'footer' , true );
// [JSManager] Load JS Footer inline code by priority
e107 :: getJs () -> renderJs ( 'footer_inline' , true );
2006-12-02 04:36:16 +00:00
//
// 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.
2009-10-01 15:05:41 +00:00
$_serverTime = time ();
2012-08-10 11:37:20 +00:00
$lastSet = isset ( $_COOKIE [ 'e107_tdSetTime' ]) ? intval ( $_COOKIE [ 'e107_tdSetTime' ]) : 0 ;
2010-10-26 07:41:20 +00:00
$_serverPath = e_HTTP ;
$_serverDomain = deftrue ( 'MULTILANG_SUBDOMAIN' ) ? '.' . e_DOMAIN : '' ;
2009-10-01 15:05:41 +00:00
if ( abs ( $_serverTime - $lastSet ) > 120 )
{
2006-12-02 04:36:16 +00:00
/* update time delay every couple of minutes .
2009-10-01 15:05:41 +00:00
* Benefit : account for user time corrections and changes in internet delays
* Drawback : each update may cause all server times to display a bit different
*/
2006-12-02 04:36:16 +00:00
echo " <script type='text/javascript'> \n " ;
2010-12-16 16:56:00 +00:00
echo " SyncWithServerTime('', ' { $_serverPath } ', ' { $_serverDomain } '); \n " ;
//tdOffset disabled as it can't live together with HTTP_IF_NONE_MATCH (page load speed)
//echo " SyncWithServerTime('{$_serverTime}', '{$_serverPath}', '{$_serverDomain}');\n";
echo " </script> \n " ;
2006-12-02 04:36:16 +00:00
}
//
// H Final HTML
//
2011-01-15 20:51:35 +00:00
// browser cache control - FIXME - use this value as AJAX requests cache control!
2012-12-15 10:25:14 +02:00
// TODO - create the $bcache string via e107 class method, use it in the canCache() method
$uclist = e107 :: getUser () -> getClassList ();
sort ( $uclist , SORT_NUMERIC );
$bcache = ( deftrue ( 'e_NOCACHE' ) ? time () : e107 :: getPref ( 'e_jslib_browser_cache' )) . '.' . implode ( ',' , $uclist );
echo " \n <!-- " . md5 ( $bcache ) . " --> \n " ;
unset ( $uclist , $bcache );
2013-03-22 19:54:37 -07:00
$show = deftrue ( 'e_POWEREDBY_DISABLE' ) ? " none " : " block " ; // Let search engines find us to increase e107.org ranking - even if hidden.
//XXX Must not contain IDs or Classes
2013-06-20 01:31:03 -07:00
// echo "<div style='text-align:center; display:".$show."; position: absolute; width:99%; height:20px; margin-top:-30px; z-index:30000; opacity:1.0; color: silver'>Proudly powered by <a style='color:silver' href='http://e107.org/' title='e107 Content Management System'>e107</a></div>";
2013-03-22 19:54:37 -07:00
unset ( $show );
2013-03-08 02:19:18 -08:00
echo " \n </body> \n </html> " ;
2006-12-02 04:36:16 +00:00
2013-05-27 10:54:42 +03:00
// Shutdown
$e107 -> destruct ();
2006-12-02 04:36:16 +00:00
//
// I Send the buffered page data, along with appropriate headers
//
$page = ob_get_clean ();
$etag = md5 ( $page );
2010-09-03 22:02:30 +00:00
2010-12-17 17:21:48 +00:00
//header('Pragma:');
2010-12-16 16:56:00 +00:00
// previously disabled or there is posted data
2012-12-15 10:25:14 +02:00
$canCache = e107 :: canCache ();
2013-03-20 16:58:39 -07:00
header ( " Cache-Control: must-revalidate " , true ); //XXX testing it here to check for improvement.
2012-12-15 10:25:14 +02:00
if ( $canCache && ! deftrue ( 'e_NOCACHE' ) && $_SERVER [ 'REQUEST_METHOD' ] === 'GET' && $_SERVER [ 'QUERY_STRING' ] != 'logout' )
2010-09-03 22:02:30 +00:00
{
2013-03-20 05:55:15 -07:00
// header("Cache-Control: must-revalidate", true);
2011-01-15 20:51:35 +00:00
if ( e107 :: getPref ( 'site_page_expires' )) // TODO - allow per page
2011-12-06 08:00:42 +00:00
{
2011-01-15 20:51:35 +00:00
if ( function_exists ( 'date_default_timezone_set' ))
{
date_default_timezone_set ( 'UTC' );
}
2011-01-15 21:02:43 +00:00
$time = time () + ( integer ) e107 :: getPref ( 'site_page_expires' );
2011-01-15 20:51:35 +00:00
header ( 'Expires: ' . gmdate ( " D, d M Y H:i:s " , $time ) . ' GMT' , true );
2010-09-03 22:02:30 +00:00
}
}
2012-12-15 10:25:14 +02:00
else
{
$canCache = false ;
}
2006-12-02 04:36:16 +00:00
2006-12-09 06:53:06 +00:00
$pref [ 'compression_level' ] = 6 ;
2010-07-26 21:47:31 +00:00
$browser_support = FALSE ;
$server_support = FALSE ;
if ( strstr ( varset ( $_SERVER [ 'HTTP_ACCEPT_ENCODING' ], '' ), 'gzip' ))
2009-10-01 15:05:41 +00:00
{
2006-12-02 04:36:16 +00:00
$browser_support = true ;
}
2010-07-26 21:47:31 +00:00
if ( ini_get ( " zlib.output_compression " ) == '' && function_exists ( " gzencode " ))
2009-10-01 15:05:41 +00:00
{
2006-12-02 04:36:16 +00:00
$server_support = true ;
}
2010-07-26 21:47:31 +00:00
if ( varset ( $pref [ 'compress_output' ], false ) && $server_support == true && $browser_support == true )
2009-10-01 15:05:41 +00:00
{
2006-12-02 04:36:16 +00:00
$level = intval ( $pref [ 'compression_level' ]);
2010-09-03 22:02:30 +00:00
header ( " ETag: \" { $etag } -gzip \" " );
2006-12-02 04:36:16 +00:00
$page = gzencode ( $page , $level );
header ( " Content-Encoding: gzip " , true );
header ( " Content-Length: " . strlen ( $page ), true );
2014-05-24 15:58:56 -07:00
header ( 'Vary: Accept-Encoding' );
2010-07-26 21:47:31 +00:00
}
else
2009-10-01 15:05:41 +00:00
{
2010-09-03 22:02:30 +00:00
if ( $browser_support == TRUE )
{
header ( " ETag: \" { $etag } -gzip \" " );
}
else
{
header ( " ETag: \" { $etag } \" " );
}
2006-12-02 04:36:16 +00:00
header ( " Content-Length: " . strlen ( $page ), true );
2014-05-24 15:58:56 -07:00
header ( 'Vary: Accept' );
2006-12-02 04:36:16 +00:00
}
2012-08-10 04:52:32 +00:00
header ( " X-Powered-By: e107 " , true ); // no less secure than e107-specific html.
2014-05-24 15:58:56 -07:00
2012-08-10 04:52:32 +00:00
2010-12-16 16:56:00 +00:00
// should come after the Etag header
2011-12-06 08:00:42 +00:00
if ( $canCache && isset ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ]))
2010-12-16 16:56:00 +00:00
{
$IF_NONE_MATCH = str_replace ( '"' , '' , $_SERVER [ 'HTTP_IF_NONE_MATCH' ]);
if ( $IF_NONE_MATCH == $etag || ( $IF_NONE_MATCH == ( $etag . " -gzip " )))
{
header ( 'HTTP/1.1 304 Not Modified' );
exit ();
}
}
// real output
echo $page ;
2006-12-05 09:33:20 +00:00
unset ( $In_e107_Footer );
2010-07-26 21:47:31 +00:00
$e107_Clean_Exit = TRUE ; // For registered shutdown function -- let it know all is well!
2007-01-17 20:47:41 +00:00
?>