Version 4.2.0

This commit is contained in:
Neo committed 2025-12-19 05:44:59 -08:00
1 parent 0dc2aee5ed
commit 96997ddd8e
2074 files changed
+125454 -55780

No files matched your search

+78 -43
View File
@@ -1,18 +1,17 @@
<?php
/**
* @brief Initiates IPS Community Suite constants, autoloader and exception handler
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @brief Initiates Invision Community constants, autoloader and exception handler
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 18 Feb 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS;
/**
* Class to contain IPS Community Suite autoloader and exception handler
* Class to contain Invision Community autoloader and exception handler
*/
class IPS
{
@@ -69,15 +68,15 @@ class IPS
'LOG_FALLBACK_DIR' => '{root}/uploads/logs',
'STORE_METHOD' => ( isset( $_SERVER['IPS_CIC'] ) ? 'Database' : 'FileSystem' ),
'STORE_CONFIG' => '{"path":"{root}/datastore"}',
'CACHE_METHOD' => 'None',
'CACHE_CONFIG' => '{}',
'CACHE_METHOD' => isset( $_SERVER['IPS_CIC_REDIS'] ) ? 'Redis' : 'None',
'CACHE_CONFIG' => isset( $_SERVER['IPS_CIC_REDIS'] ) ? '{ "server": "' . $_SERVER['IPS_CIC_REDIS'] . '", "port": 6379 }' : '{}',
'CACHE_PAGE_TIMEOUT' => ( isset( $_SERVER['IPS_CIC'] ) ? 300 : 30 ),
'TEST_CACHING' => FALSE,
'EMAIL_DEBUG_PATH' => NULL,
'BULK_MAILS_PER_CYCLE' => 50,
'JAVA_PATH' => "",
'ERROR_PAGE' => 'error.php',
'UPGRADING_PAGE' => 'upgrading.html',
'UPGRADING_PAGE' => ( defined( 'CP_DIRECTORY' ) ) ? CP_DIRECTORY . '/upgrade/upgrading.html' : 'admin/upgrade/upgrading.html', # defined call here just as a sanity check
'QUERY_LOG' => FALSE,
'CACHING_LOG' => FALSE,
'ENFORCE_ACCESS' => FALSE,
@@ -96,7 +95,7 @@ class IPS
'NEXUS_LKEY_API_ALLOW_IP_OVERRIDE' => FALSE,
'UPGRADE_MANUAL_THRESHOLD' => 250000,
'HTMLENTITIES' => ( version_compare( phpversion(), '5.4.0', '<' ) ) ? ENT_IGNORE : ENT_DISALLOWED,
'SUITE_UNIQUE_KEY' => mb_substr( md5( '13_mafia' . '$Rev: 3023$'), 10, 10 ),
'SUITE_UNIQUE_KEY' => ( isset( $_SERVER['IPS_CIC'] ) and preg_match( '/^\/var\/www\/html\/(.+?)\/conf_global\.php$/i', __DIR__, $matches ) ) ? str_replace( '/', '', $matches[1] ) : mb_substr( md5( '13_mafia' . '$Rev: 3023$'), 10, 10 ),
'CACHEBUST_KEY' => mb_substr( md5( '13_mafia' . '$Rev: 3023$'), 10, 10 ), // This looks unnecessary but SUITE_UNIQUE_KEY can be set to a constant constant in constants.php whereas we need a version specific constant for cache busting.
'TEXT_ENCRYPTION_KEY' => NULL,
'CONNECT_MASTER_KEY' => NULL,
@@ -118,7 +117,7 @@ class IPS
}
/**
* Initiate IPS Community Suite constants, autoloader and exception handler
* Initiate Invision Community constants, autoloader and exception handler
*
* @return void
*/
@@ -450,7 +449,14 @@ class IPS
$realClass = $data['class'];
}
}
catch ( \ParseError $e ) { }
catch ( \ParseError $e )
{
/* Show the error if we have development mode enabled */
if( \IPS\IN_DEV )
{
throw $e;
}
}
}
}
}
@@ -497,8 +503,12 @@ class IPS
*/
public static function exceptionHandler( $exception )
{
/* Are we trying to access the ACP? */
$acp = ( \IPS\Dispatcher::hasInstance() AND \IPS\Dispatcher::i()->controllerLocation == 'admin' );
/* Should we show the exception message? */
$showMessage = ( \IPS\Dispatcher::hasInstance() AND \IPS\Dispatcher::i()->controllerLocation == 'admin' );
if ( method_exists( $exception, 'isServerError' ) and $exception->isServerError() )
{
$showMessage = TRUE;
}
/* Work out what we'll log - exception classes can provide extra data */
$log = '';
@@ -514,7 +524,7 @@ class IPS
/* Report it */
try
{
if ( !\IPS\IN_DEV and \IPS\Settings::i()->diagnostics_reporting and !\IPS\Settings::i()->theme_designers_mode and !self::exceptionWasThrownByThirdParty( $exception ) )
if ( !\IPS\IN_DEV and \IPS\Settings::i()->diagnostics_reporting and !\IPS\Settings::i()->theme_designers_mode and !self::exceptionWasThrownByThirdParty( $exception ) and ( !method_exists( $exception, 'isServerError' ) or !$exception->isServerError() ) )
{
self::reportExceptionToIPS( $exception );
}
@@ -545,11 +555,11 @@ class IPS
/* And if *that* fails, show our generic page */
catch ( \Exception $e )
{
static::genericExceptionPage( $acp ? $exception->getMessage() : NULL );
static::genericExceptionPage( $showMessage ? $exception->getMessage() : NULL );
}
catch ( \Throwable $e )
{
static::genericExceptionPage( $acp ? $exception->getMessage() : NULL );
static::genericExceptionPage( $showMessage ? $exception->getMessage() : NULL );
}
exit;
@@ -602,6 +612,28 @@ class IPS
exit;
}
/**
* Small utility function to check if a class has a trait as PHP doesn't have an operator
* for this and the monkey patching means we can't use class_uses() directly
*
* @param string|object $class The class
* @param string $trait Trait name to look for
* @return bool
*/
public static function classUsesTrait( $class, $trait )
{
do
{
if ( in_array( $trait, class_uses( $class ) ) )
{
return TRUE;
}
}
while( $class = get_parent_class( $class ) );
return FALSE;
}
/**
* Get license key data
*
@@ -684,48 +716,50 @@ class IPS
* Was the exception thrown by a third party app/plugin?
*
* @param \Throwable $exception The exception
* @return string|int|NULL string = application directory, int = hook id, null means, that it was probably caused by an IPS4 application
* @return string|int|NULL string = application directory, int = hook id, null means that it was probably caused by an application
*/
public static function exceptionWasThrownByThirdParty( $exception )
{
$trace = $exception->getTraceAsString();
/* Did it happen in a hook? */
if ( preg_match( '/init\.php\(\d*\) : eval\(\)\'d code$/', $exception->getFile() ) )
{
$trace = $exception->getTraceAsString();
/* Did it happen inside an applications hook? */
if ( preg_match( '/([a-zA-Z]+)_hook/', $trace, $matches ) )
{
if ( !in_array( $matches[1], \IPS\Application::$ipsApps ) )
{
return $matches[1];
}
else
{
return FALSE;
}
}
/* Did it happen inside a plugin hook? */
else if ( preg_match( '/hook(\d)/', $trace, $matches ) )
if ( preg_match( '/hook(\d+)/', $trace, $matches ) )
{
/* Return the hook id, the error method will fetch the plugin name */
return $matches[1];
}
/* Did it happen inside an applications hook? */
else if ( preg_match_all( '/([a-zA-Z]+)_hook/', $trace, $matches ) )
{
foreach ( $matches[1] as $appKey )
{
if ( !in_array( $appKey, \IPS\Application::$ipsApps ) )
{
return $appKey;
}
}
}
return NULL;
}
/* Exception was thrown by 'normal code', check if it's from a third-party app */
else
{
if ( preg_match( '/' . preg_quote( DIRECTORY_SEPARATOR, '/' ) . 'applications' . preg_quote( DIRECTORY_SEPARATOR, '/' ) . '([a-zA-Z]+)/', str_replace( \IPS\ROOT_PATH, '', $exception->getFile() ), $matches ) )
foreach ( explode( "\n", $trace ) as $line )
{
if ( !in_array( $matches[1], \IPS\Application::$ipsApps ) )
if ( preg_match( '/' . preg_quote( DIRECTORY_SEPARATOR, '/' ) . 'applications' . preg_quote( DIRECTORY_SEPARATOR, '/' ) . '([a-zA-Z]+)/', str_replace( \IPS\ROOT_PATH, '', $line ), $matches ) )
{
return $matches[1];
}
else
{
return NULL;
if ( !in_array( $matches[1], \IPS\Application::$ipsApps ) )
{
return $matches[1];
}
else
{
return NULL;
}
}
}
}
@@ -738,9 +772,10 @@ class IPS
* Resync IPS Cloud File System
* Must be called when writing any files to disk on IPS Community in the Cloud
*
* @param string $reason Reason
* @return void
*/
public static function resyncIPSCloud()
public static function resyncIPSCloud( $reason = NULL )
{
if ( \IPS\CIC )
{
@@ -749,7 +784,7 @@ class IPS
try
{
\IPS\Http\Url::external('http://ips-cic-fileupdate.invisioncic.com/')
->setQueryString( 'user', $matches[1] )
->setQueryString( array( 'user' => $matches[1], 'reason' => $reason ) )
->request()
->post();
}