1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @param string $content
|
5
|
* @return string
|
6
|
*/
|
7
|
function doFilterSnippetJs($sContent) {
|
8
|
$aFilterSettings = getOutputFilterSettings();
|
9
|
$key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', __FILE__);
|
10
|
if ($aFilterSettings[$key]) {
|
11
|
global $database, $wb;
|
12
|
$sql = 'SELECT DISTINCT `directory` FROM `'.TABLE_PREFIX.'addons` '
|
13
|
. 'WHERE `function`=\'snippet\'';
|
14
|
if (($oSnippetList = $database->query($sql))) {
|
15
|
while (($aSnippets = $oSnippetList->fetchRow(MYSQLI_ASSOC)))
|
16
|
{
|
17
|
$sFrontendJsFile = '/modules/'.$aSnippets['directory'].'/frontend.js';
|
18
|
if (!is_readable(WB_PATH.$sFrontendJsFile)) {
|
19
|
$sFrontendJsFile = '/modules/'.$aSnippets['directory'].'/js/frontend.js';
|
20
|
if (!is_readable(WB_PATH.$sFrontendJsFile)) {
|
21
|
continue;
|
22
|
}
|
23
|
}
|
24
|
$sPattern = '/<head.*?<script.*?src\s*?=\s*?\"'.preg_quote(WB_URL.$sFrontendJsFile, '/').'\"[^>]*?>.*?<\/head>/si';
|
25
|
if (preg_match($sPattern, $sContent)) {
|
26
|
continue;
|
27
|
}
|
28
|
$sPattern = '/(<head.*<\/script>)(.*?<\/head>)/si';
|
29
|
$sReplacement = '$1'.'<script src="'.WB_URL.$sFrontendJsFile.'" type="text/javascript"></script>'.'$2';
|
30
|
$sContent = preg_replace($sPattern, $sReplacement, $sContent);
|
31
|
}
|
32
|
}
|
33
|
}
|
34
|
return $sContent;
|
35
|
}
|