Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/smart-sl.../Nextend/Framewor.../WordPres...
File: AssetInjector.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
namespace Nextend\Framework\WordPress;
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
use Nextend\Framework\Asset\AssetManager;
[6] Fix | Delete
use Nextend\Framework\Pattern\SingletonTrait;
[7] Fix | Delete
use Nextend\WordPress\OutputBuffer;
[8] Fix | Delete
[9] Fix | Delete
class AssetInjector {
[10] Fix | Delete
[11] Fix | Delete
use SingletonTrait;
[12] Fix | Delete
[13] Fix | Delete
private static $cssComment = '<!--n2css-->';
[14] Fix | Delete
[15] Fix | Delete
protected $js = '';
[16] Fix | Delete
protected $css = '';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* @var OutputBuffer
[20] Fix | Delete
*/
[21] Fix | Delete
protected $outputBuffer;
[22] Fix | Delete
[23] Fix | Delete
private $headTokens = array();
[24] Fix | Delete
[25] Fix | Delete
private $useAlternativeAction = false;
[26] Fix | Delete
[27] Fix | Delete
protected function init() {
[28] Fix | Delete
if (is_admin()) {
[29] Fix | Delete
$this->useAlternativeAction = true;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
[33] Fix | Delete
if (defined('WP_CLI') && WP_CLI) {
[34] Fix | Delete
//Do not start output buffering while WP_CLI active
[35] Fix | Delete
[36] Fix | Delete
} else {
[37] Fix | Delete
[38] Fix | Delete
$this->outputBuffer = OutputBuffer::getInstance();
[39] Fix | Delete
if (defined('SMART_SLIDER_OB_START') && SMART_SLIDER_OB_START >= 0) {
[40] Fix | Delete
$this->outputBuffer->setExtraObStart(SMART_SLIDER_OB_START);
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
$this->addInjectCSSComment();
[44] Fix | Delete
[45] Fix | Delete
add_filter('wordpress_prepare_output', array(
[46] Fix | Delete
$this,
[47] Fix | Delete
'prepareOutput'
[48] Fix | Delete
));
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
public function prepareOutput($buffer) {
[53] Fix | Delete
static $once = false;
[54] Fix | Delete
if (!$once) {
[55] Fix | Delete
$once = true;
[56] Fix | Delete
$this->finalizeCssJs();
[57] Fix | Delete
[58] Fix | Delete
if (!empty($this->css)) {
[59] Fix | Delete
$n2cssPos = strpos($buffer, self::$cssComment);
[60] Fix | Delete
if ($n2cssPos !== false) {
[61] Fix | Delete
$buffer = substr_replace($buffer, $this->css, $n2cssPos, strlen(self::$cssComment));
[62] Fix | Delete
$this->css = '';
[63] Fix | Delete
} else {
[64] Fix | Delete
$parts = preg_split('/<\/head[\s]*>/i', $buffer, 2);
[65] Fix | Delete
// There might be no head and it would result a notice.
[66] Fix | Delete
if (count($parts) == 2) {
[67] Fix | Delete
list($head, $body) = $parts;
[68] Fix | Delete
/**
[69] Fix | Delete
* We must tokenize the HTML comments in the head to prepare for condition CSS/scripts
[70] Fix | Delete
* Eg.: <!--[if lt IE 9]><link rel='stylesheet' href='ie8.css?ver=1.0' type='text/css' media='all'> <![endif]-->
[71] Fix | Delete
*/
[72] Fix | Delete
$head = preg_replace_callback('/<!--.*?-->/s', array(
[73] Fix | Delete
$this,
[74] Fix | Delete
'tokenizeHead'
[75] Fix | Delete
), $head);
[76] Fix | Delete
[77] Fix | Delete
$head = preg_replace_callback('/<noscript>.*?<\/noscript>/s', array(
[78] Fix | Delete
$this,
[79] Fix | Delete
'tokenizeHead'
[80] Fix | Delete
), $head);
[81] Fix | Delete
[82] Fix | Delete
$lastStylesheetPosition = strrpos($head, "<link rel='stylesheet'");
[83] Fix | Delete
if ($lastStylesheetPosition === false) {
[84] Fix | Delete
$lastStylesheetPosition = strrpos($head, "<link rel=\"stylesheet\"");
[85] Fix | Delete
if ($lastStylesheetPosition === false) {
[86] Fix | Delete
$lastStylesheetPosition = strrpos($head, "<link");
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
if ($lastStylesheetPosition !== false) {
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Find the end of the tag <link tag
[93] Fix | Delete
*/
[94] Fix | Delete
$lastStylesheetPositionEnd = strpos($head, ">", $lastStylesheetPosition);
[95] Fix | Delete
if ($lastStylesheetPositionEnd !== false) {
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Insert CSS after the ending >
[99] Fix | Delete
*/
[100] Fix | Delete
$head = substr_replace($head, $this->css, $lastStylesheetPositionEnd + 1, 0);
[101] Fix | Delete
$this->css = '';
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Restore HTML comments
[105] Fix | Delete
*/
[106] Fix | Delete
$head = preg_replace_callback('/<!--TOKEN([0-9]+)-->/', array(
[107] Fix | Delete
$this,
[108] Fix | Delete
'restoreHeadTokens'
[109] Fix | Delete
), $head);
[110] Fix | Delete
[111] Fix | Delete
$buffer = $head . '</head>' . $body;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
if ($this->css != '' || $this->js != '') {
[120] Fix | Delete
$parts = preg_split('/<\/head[\s]*>/', $buffer, 2);
[121] Fix | Delete
[122] Fix | Delete
return implode($this->css . $this->js . '</head>', $parts);
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
return $buffer;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
public function tokenizeHead($matches) {
[130] Fix | Delete
[131] Fix | Delete
$index = count($this->headTokens);
[132] Fix | Delete
[133] Fix | Delete
$this->headTokens[$index] = $matches[0];
[134] Fix | Delete
[135] Fix | Delete
return '<!--TOKEN' . $index . '-->';
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
public function restoreHeadTokens($matches) {
[139] Fix | Delete
[140] Fix | Delete
return $this->headTokens[$matches[1]];
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
private function finalizeCssJs() {
[144] Fix | Delete
static $finalized = false;
[145] Fix | Delete
if (!$finalized) {
[146] Fix | Delete
$finalized = true;
[147] Fix | Delete
[148] Fix | Delete
if (class_exists('\\Nextend\\Framework\\Asset\\AssetManager', false)) {
[149] Fix | Delete
$this->css = AssetManager::getCSS();
[150] Fix | Delete
$this->js = AssetManager::getJs();
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
return true;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
public function addInjectCSSComment() {
[158] Fix | Delete
if (!$this->useAlternativeAction) {
[159] Fix | Delete
add_action('wp_print_scripts', array(
[160] Fix | Delete
$this,
[161] Fix | Delete
'injectCSSComment'
[162] Fix | Delete
));
[163] Fix | Delete
} else {
[164] Fix | Delete
/**
[165] Fix | Delete
* @see SSDEV-3909
[166] Fix | Delete
* The Site editor fires the wp_print_scripts action inside a the wp.editSite.initializeEditor script.
[167] Fix | Delete
* The Widgets editor fires the wp_print_scripts action inside a the wp.editWidgets.initialize script.
[168] Fix | Delete
* The Customizer fires the wp_print_scripts action inside a the wp.customizeWidgets.initialize script.
[169] Fix | Delete
*/
[170] Fix | Delete
add_action('admin_head', array(
[171] Fix | Delete
$this,
[172] Fix | Delete
'injectCSSComment'
[173] Fix | Delete
));
[174] Fix | Delete
}
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
public function removeInjectCSSComment() {
[178] Fix | Delete
if (!$this->useAlternativeAction) {
[179] Fix | Delete
remove_action('wp_print_scripts', array(
[180] Fix | Delete
$this,
[181] Fix | Delete
'injectCSSComment'
[182] Fix | Delete
));
[183] Fix | Delete
} else {
[184] Fix | Delete
/**
[185] Fix | Delete
* @see SSDEV-3909
[186] Fix | Delete
* The Site editor fires the wp_print_scripts action inside a the wp.editSite.initializeEditor script.
[187] Fix | Delete
* The Widgets editor fires the wp_print_scripts action inside a the wp.editWidgets.initialize script.
[188] Fix | Delete
* The Customizer fires the wp_print_scripts action inside a the wp.customizeWidgets.initialize script.
[189] Fix | Delete
*/
[190] Fix | Delete
remove_action('admin_head', array(
[191] Fix | Delete
$this,
[192] Fix | Delete
'injectCSSComment'
[193] Fix | Delete
));
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
public function injectCSSComment() {
[198] Fix | Delete
static $once;
[199] Fix | Delete
if (!$once) {
[200] Fix | Delete
echo wp_kses(self::$cssComment, array());
[201] Fix | Delete
$once = true;
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
}
[205] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function