Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+42 -31
View File
@@ -11,29 +11,40 @@
namespace IPS\core\DataLayer;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Data\Store;
use IPS\Settings;
use OutOfRangeException;
use UnexpectedValueException;
use function defined;
use function is_array;
use function preg_replace;
use function str_replace;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Data Layer Handler class
*/
class _Handler
#[\AllowDynamicProperties]
class Handler
{
public static $cicHandlerClass = '\IPS\cloud\DataLayer\Handler';
public static string $cicHandlerClass = '\IPS\cloud\DataLayer\Handler';
public static $handlerCacheKey = 'dataLayerHandlers';
public static string $handlerCacheKey = 'dataLayerHandlers';
public $id = 'gtm';
public string $id = 'gtm';
/**
* Returns the enabled handlers to be used in the global template as an array of head and body HTML snippets.
*
* @return array
*/
public static function loadForTemplates()
public static function loadForTemplates() : array
{
$return = array();
@@ -41,16 +52,16 @@ class _Handler
$key = static::$handlerCacheKey;
try
{
$cached = json_decode( \IPS\Data\Store::i()->$key, true );
if ( \is_array( $cached ) )
$cached = json_decode( Store::i()->$key, true );
if ( is_array( $cached ) )
{
return $cached;
}
}
catch ( \OutOfRangeException $e ) {}
catch ( OutOfRangeException $e ) {}
$handlers = static::loadEnabled();
if ( \IPS\Settings::i()->core_datalayer_use_gtm )
if ( Settings::i()->core_datalayer_use_gtm )
{
$handlers[] = static::gtm();
}
@@ -124,9 +135,9 @@ class _Handler
initcode{$handler->id}(IpsDataLayerContext || {});
</script>
HTML;
$code = \preg_replace( '/\/\/(.*)[\n|\r]/', '/*$1*/', $code );
$code = \preg_replace( '/\s+/', ' ', $code);
$headInserts .= \str_replace("\n", ' ', $code ) . "\n";
$code = preg_replace( '/\/\/(.*)[\n|\r]/', '/*$1*/', $code );
$code = preg_replace( '/\s+/', ' ', $code);
$headInserts .= str_replace("\n", ' ', $code ) . "\n";
}
if ( $handler->event_handler AND $handler->use_js )
@@ -141,9 +152,9 @@ HTML;
}
} )
JS;
$code = \preg_replace( '/\/\/(.*)[\n|\r]?/', '/*$1*/', $code );
$code = \preg_replace( '/\s+/', ' ', $code);
$eventCallbacks[] = \str_replace( "\n", ' ', $code );
$code = preg_replace( '/\/\/(.*)[\n|\r]?/', '/*$1*/', $code );
$code = preg_replace( '/\s+/', ' ', $code);
$eventCallbacks[] = str_replace( "\n", ' ', $code );
}
if ( $handler->properties_handler AND $handler->use_js )
@@ -158,9 +169,9 @@ JS;
}
} )
JS;
$code = \preg_replace( '/\/\/(.*)[\n|\r]?/', '/*$1*/', $code );
$code = \preg_replace( '/\s+/', ' ', $code);
$propertiesCallbacks[] = \str_replace( "\n", ' ', $code );
$code = preg_replace( '/\/\/(.*)[\n|\r]?/', '/*$1*/', $code );
$code = preg_replace( '/\s+/', ' ', $code);
$propertiesCallbacks[] = str_replace( "\n", ' ', $code );
}
}
@@ -173,7 +184,7 @@ JS;
<script>
const IpsDataLayerEventHandlers = [
$eventsJoined
];
]
</script>
<!-- END Event Callbacks -->
@@ -186,7 +197,7 @@ HTML;
<script>
const IpsDataLayerPropertiesHandlers = [
$propertiesJoined
];
]
</script>
<!-- END Properties Callbacks -->
@@ -201,7 +212,7 @@ HTML;
);
/* add to cache before returning */
\IPS\Data\Store::i()->$key = json_encode( $return );
Store::i()->$key = json_encode( $return );
return $return;
}
@@ -211,7 +222,7 @@ HTML;
*
* @return static[]
*/
public static function loadEnabled()
public static function loadEnabled() : array
{
if ( class_exists( static::$cicHandlerClass ) )
{
@@ -226,7 +237,7 @@ HTML;
*
* @return static
*/
public static function gtm()
public static function gtm() : static
{
$gtm = new static();
$gtm->initializer_code = <<<JS
@@ -239,10 +250,10 @@ if (context instanceof Object) {
Debug.log( 'Invalid Data Layer Context: The IPS GTM Data Layer Initializer failed because the context wasn\'t an Object' );
JS;
$gtm->head_code = \IPS\Settings::i()->googletag_head_code;
$gtm->head_code = Settings::i()->googletag_head_code;
$gtm->use_js = true;
$gtm->body_code = \IPS\Settings::i()->googletag_noscript_code;
$gtm->datalayer_key = \IPS\Settings::i()->core_datalayer_gtmkey ?: 'window.dataLayer';
$gtm->body_code = Settings::i()->googletag_noscript_code;
$gtm->datalayer_key = Settings::i()->core_datalayer_gtmkey ?: 'window.dataLayer';
$gtm->event_handler = <<<JS
if ( (_event._properties instanceof Object) && (typeof _event._key === 'string')) {
@@ -275,9 +286,9 @@ JS;
* @param array $where The where clause
*
* @return array
* @throws \UnexpectedValueException If $where contains invalid fields and/or invalid SQL logic
* @throws UnexpectedValueException If $where contains invalid fields and/or invalid SQL logic
*/
public static function loadWhere( array $where=array() )
public static function loadWhere( array $where=array() ) : array
{
if ( ( $class = static::$cicHandlerClass ) AND class_exists( $class ) )
{
@@ -291,7 +302,7 @@ JS;
*
* @return bool
*/
public function mockFunction()
public function mockFunction() : bool
{
return true;
}