Project

General

Profile

1
<?php
2
/**
3
 * doFilterReplaceSysvar
4
 * @param string to modify
5
 * @return string
6
 * Convert the {SYSVAR:xxxx} Placeholders into their real value
7
 */
8
   function doFilterSysvarMedia($sContent) {
9
      return doFilterReplaceSysvar($sContent);
10
    }
11

    
12
   function doFilterReplaceSysvar($sContent) {
13
        $aReg = array (
14
            'AppUrl' => WB_URL.'/',
15
            'MediaDir' => trim(MEDIA_DIRECTORY, '/').'/',
16
            'MEDIA_REL' => WB_URL.'/'.trim(MEDIA_DIRECTORY, '/')
17
        );
18
        $aSearches = array();
19
        $aReplacements = array();
20
        // search for all SYSVARs
21
        if (preg_match_all('/\{SYSVAR\:([^\}]+)\}/sU', $sContent, $aMatches)) {
22
            $aMatches = array_unique($aMatches[1], SORT_STRING);
23
            foreach ($aMatches as $sMatch) {
24
                $sTmp = '';
25
                $aTmp = preg_split('/\./', $sMatch);
26
                foreach ($aTmp as $sSysvar) {
27
                    if (!isset($aReg[$sSysvar])) {
28
                        $sTmp = '';
29
                        break;
30
                    }
31
                    $sTmp .= $aReg[$sSysvar];
32
                }
33
                if ($sTmp) {
34
                    $aSearches[] = '{SYSVAR:'.$sMatch.'}';
35
                    $aReplacements[] = $sTmp;
36
                }
37
            }
38
            $sContent = str_replace($aSearches, $aReplacements, $sContent);
39
        }
40
      return $sContent;
41
   }
(9-9/12)