/
ScriptletWebpath.php
65 lines (54 loc) · 2.1 KB
/
ScriptletWebpath.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*"******************************************************************************************************
* (c) 2007-2016 by Kajona, www.kajona.de *
* Published under the GNU LGPL v2.1, see /system/licence_lgpl.txt *
********************************************************************************************************/
namespace Kajona\System\System\Scriptlets;
use Kajona\System\System\Resourceloader;
use Kajona\System\System\ScriptletInterface;
use Kajona\System\System\StringUtil;
/**
* A scriptlet to replace script / image src within templates.
* Provides a switch to check for content in /files/extract rather then the module-folders
* [webpath,module_name]
*
*
* @since 5.0
* @author sidler@mulchprod.de
*/
class ScriptletWebpath implements ScriptletInterface
{
/**
* Processes the content.
* Make sure to return the string again, otherwise the output will remain blank.
*
* @param string $strContent
*
* @return string
*/
public function processContent($strContent)
{
if ($strContent == "") {
return $strContent;
}
$arrTemp = array();
preg_match_all("#\[webpath,([A-Za-z0-9_]+)\]#i", $strContent, $arrTemp);
foreach ($arrTemp[0] as $intKey => $strSearchString) {
$strContent = StringUtil::replace($strSearchString, Resourceloader::getInstance()->getWebPathForModule($arrTemp[1][$intKey]), $strContent);
}
return $strContent;
}
/**
* Define the context the scriptlet is applied to.
* A combination of contexts is allowed using an or-concatenation.
* Examples:
* return ScriptletInterface::BIT_CONTEXT_ADMIN
* return ScriptletInterface::BIT_CONTEXT_ADMIN | ScriptletInterface::BIT_CONTEXT_PORTAL_ELEMENT
*
* @return mixed
*/
public function getProcessingContext()
{
return ScriptletInterface::BIT_CONTEXT_ADMIN | ScriptletInterface::BIT_CONTEXT_PORTAL_ELEMENT | ScriptletInterface::BIT_CONTEXT_PORTAL_PAGE;
}
}