Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @param string $content
5
 * @return string
6
 */
7
function doFilterFrontendJs($sContent) {
8
        $aFilterSettings = getOutputFilterSettings();
9
        $key = preg_replace('=^.*?filter([^\.\/\\\\]+)(\.[^\.]+)?$=is', '\1', __FILE__);
10
        if ($aFilterSettings[$key]) {
11
            global $database, $wb;
12
            $sql = 'SELECT DISTINCT `module` FROM `'.TABLE_PREFIX.'sections` '
13
                 . 'WHERE `page_id` = '.(int)$wb->page['page_id'];
14
            if (($oModuleList = $database->query($sql))) {
15
                while (($aModules = $oModuleList->fetchRow(MYSQLI_ASSOC)))
16
                {
17
                    $sFrontendJsFile = '/modules/'.$aModules['module'].'/frontend.js';
18
                    if (!is_readable(WB_PATH.$sFrontendJsFile)) {
19
                        $sFrontendJsFile = '/modules/'.$aModules['module'].'/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'."\n".'<script src="'.WB_URL.$sFrontendJsFile.'" type="text/javascript"></script>'.'$2';
30
                    $sContent = preg_replace($sPattern, $sReplacement, $sContent);
31
                }
32
            }
33
        }
34
    return $sContent;
35
}
(4-4/12)