0)setTimeout(run,T*1000)})(window,document);'; /** * Number of scripts delayed in this response. * * @var int */ private static $count = 0; /** * Reset (per response). */ public static function reset() { self::$count = 0; } /** * Delayed scripts in this response. * * @return int */ public static function count() { return self::$count; } /** * Script callback for AIOM_HTML_Minifier: returns a replacement opening tag for matching scripts. * * @param array $s Script info. * @return string|null */ public static function filter_script( array $s ) { if ( 'js' !== $s['kind'] ) { return null; } $a = $s['attrs']; if ( isset( $a['data-aiom-nodelay'] ) || isset( $a['data-no-optimize'] ) || isset( $a['data-aiom-delay'] ) || ( isset( $a['id'] ) && 'aiom-delay-loader' === $a['id'] ) ) { return null; } $subject = isset( $a['src'] ) ? $a['src'] : $s['content']; if ( ! self::matches( AIOM_Settings::lines( 'js_delay_patterns' ), $subject, isset( $a['id'] ) ? $a['id'] : '' ) ) { return null; } $out = ' $value ) { if ( ! preg_match( '/^[a-z_:][a-z0-9_:.@-]*$/', $name ) ) { return null; // Unusual attribute names: leave the script alone. } if ( 'type' === $name ) { continue; } $out .= ' ' . $name . ( '' === $value ? '' : '="' . esc_attr( $value ) . '"' ); } $out .= ' type="aiom/delayed" data-aiom-delay'; if ( '' !== $s['type'] ) { $out .= ' data-aiom-type="' . esc_attr( $s['type'] ) . '"'; } ++self::$count; return $out . '>'; } /** * Whether a script matches a delay pattern (substring of URL/content, or id). * * @param string[] $patterns Patterns. * @param string $subject URL or inline content. * @param string $id Element id. * @return bool */ public static function matches( array $patterns, $subject, $id ) { foreach ( $patterns as $p ) { if ( strlen( $p ) >= 3 && ( false !== stripos( $subject, $p ) || ( '' !== $id && 0 === strcasecmp( $id, $p ) ) ) ) { return true; } } return false; } /** * Insert the loader before . * * @param string $html Document. * @return string */ public static function inject_loader( $html ) { $script = ''; $pos = strripos( $html, '' ); if ( false === $pos ) { return $html . $script; } return substr_replace( $html, $script, $pos, 0 ); } }