2009-10-01 15:05:41 +00:00
< ? php
2006-12-02 04:36:16 +00:00
/*
2009-10-01 15:05:41 +00:00
* e107 website system
*
2019-06-17 09:23:21 -07:00
* Copyright ( C ) 2008 - 2019 e107 Inc ( e107 . org )
2009-10-01 15:05:41 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Admin Footer
*
* $Source : / cvs_backup / e107_0 . 8 / e107_admin / footer . php , v $
2010-02-10 18:18:01 +00:00
* $Revision $
* $Date $
* $Author $
2009-10-01 15:05:41 +00:00
*/
if ( ! defined ( 'e107_INIT' ))
{
exit ;
}
2021-01-16 16:13:48 -08:00
$GLOBALS [ 'E107_IN_FOOTER' ] = true ; // For registered shutdown function
2007-08-18 13:47:54 +00:00
2021-01-27 12:20:58 -08:00
global $error_handler , $db_time ;
2006-12-05 09:28:02 +00:00
2012-11-28 09:35:06 +02:00
// Legacy fix - call header if not already done, mainly fixing left side menus to work proper
2021-01-16 13:32:35 -08:00
if ( ! deftrue ( 'e_ADMIN_UI' ) )
2012-11-28 09:35:06 +02:00
{
// close the old buffer
$content = ob_get_contents ();
ob_get_clean ();
// open new
ob_start ();
require_once ( e_ADMIN . 'header.php' );
echo $content ;
2021-01-16 13:32:35 -08:00
2012-11-28 09:35:06 +02:00
}
2006-12-05 09:28:02 +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 ;)
// These letters match the USER footer (that's why there is B.1,B.2)
//
2007-01-17 13:03:53 +00:00
// A Ensure sql and traffic objects exist
2007-03-04 21:50:28 +00:00
// B.1 Clear cache (if over a week old)
2006-12-05 09:28:02 +00:00
// 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
2007-01-17 13:03:53 +00:00
//
2006-12-02 04:36:16 +00:00
2006-12-05 09:28:02 +00:00
//
// A Ensure sql and traffic objects exist
//
2006-12-02 04:36:16 +00:00
2009-10-01 15:05:41 +00:00
$e107 = e107 :: getInstance ();
2009-07-23 15:21:41 +00:00
$sql = e107 :: getDb ();
2009-09-13 10:29:56 +00:00
e107 :: getSingleton ( 'e107_traffic' ) -> Bump ( 'Lost Traffic Counters' );
2009-10-01 15:05:41 +00:00
$pref = e107 :: getPref ();
2009-07-23 15:21:41 +00:00
2009-10-01 15:05:41 +00:00
if ( varset ( $e107_popup ) != 1 )
{
2007-03-04 21:50:28 +00:00
//
// B.1 Clear cache if over a week old
//
2009-10-01 15:05:41 +00:00
if ( ADMIN === TRUE )
{
if ( $pref [ 'cachestatus' ])
2006-12-02 04:36:16 +00:00
{
2019-06-17 09:23:21 -07:00
if ( ! $sql -> select ( 'generic' , '*' , " gen_type='empty_cache' " ))
2006-12-02 04:36:16 +00:00
{
2019-06-17 09:23:21 -07:00
$sql -> insert ( 'generic' , " 0,'empty_cache',' " . time () . " ','0','','0','' " );
2009-10-01 15:05:41 +00:00
}
else
{
2019-06-17 09:23:21 -07:00
$row = $sql -> fetch ();
2009-10-01 15:05:41 +00:00
if (( $row [ 'gen_datestamp' ] + 604800 ) < time ()) // If cache not cleared in last 7 days, clear it.
{
require_once ( e_HANDLER . " cache_handler.php " );
$ec = new ecache ;
$ec -> clear ();
2019-06-17 09:23:21 -07:00
$sql -> update ( 'generic' , " gen_datestamp=' " . time () . " ' WHERE gen_type='empty_cache' " );
2009-10-01 15:05:41 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
}
2009-10-01 15:05:41 +00:00
2007-03-04 21:50:28 +00:00
//
// B.2 Send footer template, stop timing, send simple page stats
//
2009-08-19 14:39:57 +00:00
//NEW - Iframe mod
2015-02-14 23:34:15 -08:00
if ( ! deftrue ( 'e_IFRAME' ))
2009-08-19 14:39:57 +00:00
{
2021-01-27 12:20:58 -08:00
$ADMIN_FOOTER = e107 :: getCoreTemplate ( 'admin' , 'footer' , false );
e107 :: renderLayout ( $ADMIN_FOOTER , [ 'sc' => 'admin' ]);
2007-03-04 21:50:28 +00:00
}
2009-10-01 15:05:41 +00:00
2007-03-04 21:50:28 +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 21:50:28 +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 ;)
2007-03-04 21:50:28 +00:00
$rinfo = '' ;
2009-10-01 15:05:41 +00:00
2019-06-17 09:23:21 -07:00
if ( function_exists ( 'getrusage' ) && ! empty ( $eTimingStartCPU ))
2007-08-18 13:47:54 +00:00
{
2007-03-04 21:50:28 +00:00
$ru = getrusage ();
2009-10-01 15:05:41 +00:00
$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 ));
2007-03-04 21:50:28 +00:00
$cpuStart = $cpuUStart + $cpuSStart ;
2009-10-01 15:05:41 +00:00
$cpuTot = $cpuUTime + $cpuSTime ;
2007-03-04 21:50:28 +00:00
$cpuTime = $cpuTot - $cpuStart ;
$cpuPct = 100.0 * $cpuTime / $rendertime ; /* CPU load during known clock time */
2009-10-01 15:05:41 +00:00
2007-03-04 21:50:28 +00:00
// Format for display or logging (Uncomment as needed for logging)
2009-10-01 15:05:41 +00:00
// User cpu
//$cpuUTime = number_format($cpuUTime, 3);
// System cpu
//$cpuSTime = number_format($cpuSTime, 3);
// Total (User+System)
//$cpuTot = number_format($cpuTot, 3);
$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 21:50:28 +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 21:50:28 +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-18 13:47:54 +00:00
$rinfo .= CORE_LAN11 ;
2009-10-01 15:05:41 +00:00
if ( isset ( $cpuTime ))
2007-08-18 13:47:54 +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 21:50:28 +00:00
}
2009-10-01 15:05:41 +00:00
$rinfo .= $rendertime . CORE_LAN12 . $dbPercent . CORE_LAN13 ;
2007-03-04 21:50:28 +00:00
}
2009-10-01 15:05:41 +00:00
if ( $pref [ 'displaysql' ])
{
$rinfo .= CORE_LAN15 . $sql -> db_QueryCount () . " . " ;
}
2019-06-17 09:23:21 -07:00
if ( ! empty ( $pref [ 'display_memory_usage' ]))
2009-10-01 15:05:41 +00:00
{
$rinfo .= CORE_LAN16 . $memuse ;
}
2019-06-17 09:23:21 -07:00
if ( ! empty ( $pref [ 'displaycacheinfo' ]) && ! empty ( $cachestring ))
2009-10-01 15:05:41 +00:00
{
$rinfo .= $cachestring . " . " ;
}
2007-03-04 21:50:28 +00:00
if ( function_exists ( 'theme_renderinfo' ))
{
theme_renderinfo ( $rinfo );
}
2009-10-01 15:05:41 +00:00
else
{
2015-07-19 17:10:03 -07:00
if ( ! deftrue ( 'e_IFRAME' ))
{
echo ( $rinfo ? " \n <div class='e-footer-info muted center' style='padding-bottom:20px; margin-top:10px'><small> { $rinfo } </small></div> \n " : " " );
}
2009-10-01 15:05:41 +00:00
}
2007-01-17 13:03:53 +00:00
} // End of regular-page footer (the above NOT done for popups)
2006-12-02 04:36:16 +00:00
2007-01-17 13:03:53 +00:00
//
// C Dump all debug and traffic information
//
2009-10-01 15:05:41 +00:00
if (( ADMIN || $pref [ 'developer' ]) && E107_DEBUG_LEVEL )
{
2019-06-17 09:23:21 -07:00
// global $db_debug;
2009-10-01 15:05:41 +00:00
echo " \n <!-- DEBUG --> \n <div class='e-debug debug-info'> " ;
2019-06-17 09:23:21 -07:00
e107 :: getDebug () -> Show_All ();
2009-10-01 15:05:41 +00:00
echo " </div> \n " ;
}
2007-03-04 21:50:28 +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 21:50:28 +00:00
2020-12-19 10:50:08 -08:00
// XXX Part of DEBUG info
2009-10-01 15:05:41 +00:00
if ( ADMIN && isset ( $queryinfo ) && is_array ( $queryinfo ))
{
$c = 1 ;
$mySQLInfo = $sql -> mySQLinfo ;
2016-02-07 22:25:12 -08:00
echo " <div class='e-debug query-notice'>
2020-12-19 10:50:08 -08:00
< table class = 'table table-bordered table-striped' style = 'width: 100%;' >
2006-12-05 09:28:02 +00:00
< tr >
2020-12-19 10:50:08 -08:00
< th style = 'width: 5%;' > ID </ th >< th class = 'fcaption' style = 'width: 95%;' > SQL Queries </ th > \n </ tr > \n " ;
2009-10-01 15:05:41 +00:00
foreach ( $queryinfo as $infovalue )
{
2020-12-19 10:50:08 -08:00
echo " <tr> \n <td style='width: 5%;'> { $c } </td><td style='width: 95%;'> { $infovalue } </td> \n </tr> \n " ;
2009-10-01 15:05:41 +00:00
$c ++ ;
2006-12-05 09:28:02 +00:00
}
2009-10-01 15:05:41 +00:00
echo " </table></div> " ;
}
2006-12-05 09:28:02 +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-05 09:28:02 +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 ))
{
e107 :: getRender () -> tablerender ( 'Quick Admin Timer' , " Results: { $tmp } microseconds " );
}
2007-03-04 21:50:28 +00:00
2009-10-01 15:05:41 +00:00
if ( $pref [ 'developer' ])
{
2006-12-05 09:28:02 +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-05 09:28:02 +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-05 09:28:02 +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-05 09:28:02 +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 21:50:28 +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
}
2006-12-05 09:28:02 +00:00
//
// E Last themed footer code, usually JS
//
2006-12-02 04:36:16 +00:00
if ( function_exists ( 'theme_foot' ))
{
echo theme_foot ();
}
2006-12-05 09:28:02 +00:00
//
// F any included JS footer scripts
2015-01-29 11:26:56 -08:00
// DEPRECATED - use e107::js('footer', '{e_PLUGIN}myplug/js/my.js', $zone = 2)
2006-12-05 09:28:02 +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 ;
}
}
2015-01-29 11:26:56 -08:00
// Load e_footer.php files.
if ( is_array ( $pref [ 'e_footer_list' ]))
{
// ob_start();
foreach ( $pref [ 'e_footer_list' ] as $val )
{
$fname = e_PLUGIN . $val . " /e_footer.php " ; // Do not place inside a function - BC $pref required. .
if ( is_readable ( $fname ))
{
2020-04-26 13:32:18 -07:00
$ret = ( deftrue ( 'e_DEBUG' ) || isset ( $_E107 [ 'debug' ])) ? include_once ( $fname ) : @ include_once ( $fname );
2015-01-29 11:26:56 -08:00
}
}
// $e_footer_ouput = ob_get_contents(); // Don't use.
// ob_end_clean();
unset ( $ret );
}
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
2012-05-16 03:10:56 +00:00
2009-10-01 15:05:41 +00:00
2006-12-05 09:28:02 +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.
//
2019-06-17 09:23:21 -07:00
// All JavaScript settings are placed in the footer of the page with the library weight so that inline scripts appear afterwards.
2015-12-02 14:23:48 +01:00
e107 :: getJs () -> renderJs ( 'settings' );
2012-05-16 03:10:56 +00:00
e107 :: getJs () -> renderJs ( 'footer_inline' , true );
2006-12-05 09:28:02 +00:00
//
// H Final HTML
//
2006-12-02 04:36:16 +00:00
echo " </body></html> " ;
2006-12-05 09:28:02 +00:00
//
// I Send the buffered page data, along with appropriate headers
//
2010-01-12 07:38:29 +00:00
$tmp = array ();
2019-06-17 09:23:21 -07:00
$magicSC = e107 :: getRender () -> getMagicShortcodes (); // support for {---TITLE---} etc.
$tmp [ 'search' ] = array_keys ( $magicSC );
$tmp [ 'replace' ] = array_values ( $magicSC );
2010-01-12 07:38:29 +00:00
$e_js = e107 :: getJs ();
2018-05-12 11:45:55 -07:00
$tmp0 = $e_js -> renderJs ( 'library_css' , false , 'css' , true );
if ( $tmp0 )
{
$tmp [ 'search' ][] = '<!-- footer_library_css -->' ;
$tmp [ 'replace' ][] = $tmp0 ;
}
2010-01-12 07:38:29 +00:00
// Other CSS - from unknown location, different from core/theme/plugin location or backward compatibility
$tmp1 = $e_js -> renderJs ( 'other_css' , false , 'css' , true );
if ( $tmp1 )
{
$tmp [ 'search' ][] = '<!-- footer_other_css -->' ;
$tmp [ 'replace' ][] = $tmp1 ;
}
// Core CSS
$tmp1 = $e_js -> renderJs ( 'core_css' , false , 'css' , true );
if ( $tmp1 )
{
$tmp [ 'search' ][] = '<!-- footer_core_css -->' ;
$tmp [ 'replace' ][] = $tmp1 ;
}
// Plugin CSS
$tmp1 = $e_js -> renderJs ( 'plugin_css' , false , 'css' , true );
if ( $tmp1 )
{
$tmp [ 'search' ][] = '<!-- footer_plugin_css -->' ;
$tmp [ 'replace' ][] = $tmp1 ;
}
//echo "<!-- Theme css -->\n";
$tmp1 = $e_js -> renderJs ( 'theme_css' , false , 'css' , true );
if ( $tmp1 )
{
$tmp [ 'search' ][] = '<!-- footer_theme_css -->' ;
$tmp [ 'replace' ][] = $tmp1 ;
}
// Inline CSS - not sure if this should stay at all!
$tmp1 = $e_js -> renderJs ( 'inline_css' , false , 'css' , true );
if ( $tmp1 )
{
$tmp [ 'search' ][] = '<!-- footer_inline_css -->' ;
$tmp [ 'replace' ][] = $tmp1 ;
}
2016-03-19 17:14:22 -07:00
// New - see class2.php
$ehd = new e_http_header ;
2021-01-16 13:32:35 -08:00
2016-03-22 06:11:37 -07:00
if ( $tmp )
{
2021-01-16 13:32:35 -08:00
2016-03-22 06:11:37 -07:00
$ehd -> setContent ( 'buffer' , $tmp [ 'search' ], $tmp [ 'replace' ]);
}
else
{
$ehd -> setContent ( 'buffer' );
}
2021-01-16 13:32:35 -08:00
2016-03-22 06:11:37 -07:00
unset ( $tmp1 , $tmp1 );
2016-03-19 17:14:22 -07:00
$ehd -> send ();
$page = $ehd -> getOutput ();
// $ehd->debug();
// real output
echo $page ;
2021-01-16 16:13:48 -08:00
$GLOBALS [ 'E107_IN_FOOTER' ] = false ;
2019-06-17 09:23:21 -07:00
2020-05-26 02:42:45 -05:00
// Clean session shutdown
2021-01-16 13:32:35 -08:00
if ( ! e107 :: isCli ())
{
e107 :: getSession () -> shutdown ();
// Shutdown
$e107 -> destruct ();
2021-01-16 14:49:56 -08:00
}
2021-01-16 15:42:23 -08:00
$GLOBALS [ 'E107_CLEAN_EXIT' ] = true ; // For registered shutdown function -- let it know all is well!