1 |
1626
|
darkviper
|
<?php
|
2 |
2026
|
darkviper
|
|
3 |
|
|
|
4 |
|
|
/**
|
5 |
|
|
* ParseWbLink
|
6 |
|
|
* @param string $sContent
|
7 |
|
|
* @return array details of all found Wblink-Tags
|
8 |
|
|
* @description parse
|
9 |
|
|
*/
|
10 |
|
|
function _parseWbLink(&$sContent)
|
11 |
|
|
{
|
12 |
|
|
$aResults = array();
|
13 |
|
|
$aMatches = array();
|
14 |
|
|
$sPattern = '/\[wblink([0-9]+)(\#([^\?]+))?(\?([^\]]+))?\]/is';
|
15 |
|
|
if (preg_match_all($sPattern, $sContent, $aMatches, PREG_SET_ORDER)) {
|
16 |
|
|
foreach ($aMatches as $aTag) {
|
17 |
|
|
$aResults[$aTag[0]] = array();
|
18 |
|
|
$aResults[$aTag[0]]['pageid'] = $aTag[1];
|
19 |
|
|
$aResults[$aTag[0]]['ancor'] = (isset($aTag[3]) ? $aTag[3] : '');
|
20 |
|
|
$aResults[$aTag[0]]['params'] = array();
|
21 |
|
|
$aTag[5] = (isset($aTag[5]) ? $aTag[5] : '');
|
22 |
|
|
$aTmpArgs = preg_split('/&|&/i', $aTag[5], -1, PREG_SPLIT_NO_EMPTY);
|
23 |
|
|
foreach ($aTmpArgs as $sArgument) {
|
24 |
|
|
$aArgs = explode('=', $sArgument);
|
25 |
|
|
$aResults[$aTag[0]]['params'][$aArgs[0]] = $aArgs[1];
|
26 |
|
|
}
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
return $aResults;
|
30 |
|
|
}
|
31 |
1626
|
darkviper
|
/*
|
32 |
1993
|
darkviper
|
* @param string $content : contains the full content of the current page
|
33 |
|
|
* @return string
|
34 |
|
|
* @description replace all "[wblink{page_id}{?addon=n&item=n...}]" with real links to accessfiles<br />
|
35 |
|
|
* All modules must offer the class 'WbLink'(implementing 'WbLinkAbstract'), to be taken into consideration.
|
36 |
1626
|
darkviper
|
*/
|
37 |
1993
|
darkviper
|
function doFilterWbLink($sContent)
|
38 |
1626
|
darkviper
|
{
|
39 |
1993
|
darkviper
|
$oDb = WbDatabase::getInstance();
|
40 |
|
|
$oReg = WbAdaptor::getInstance();
|
41 |
|
|
$aReplaceList = array();
|
42 |
2026
|
darkviper
|
$aTagList = _parseWblink($sContent);
|
43 |
|
|
// iterate list if replacements are available
|
44 |
|
|
foreach ($aTagList as $sKey=>$aTag) {
|
45 |
|
|
// set link on failure ('#' means, still stay on current page)
|
46 |
|
|
$aReplaceList[$sKey] = '#';
|
47 |
|
|
// sanitize possible ancor
|
48 |
|
|
$aTag['ancor'] = ($aTag['ancor'] == '' ? '' : '#'.$aTag['ancor']);
|
49 |
|
|
// handle normal pages links
|
50 |
|
|
if (sizeof($aTag['params']) == 0) {
|
51 |
|
|
$sql = 'SELECT `link` FROM `'.$oDb->TablePrefix.'pages` WHERE `page_id` = '.(int)$aTag['pageid'];
|
52 |
|
|
if(($sLink = $oDb->get_one($sql)))
|
53 |
1993
|
darkviper
|
{
|
54 |
2026
|
darkviper
|
$sLink = trim(str_replace('\\', '/', $sLink), '/');
|
55 |
|
|
// test if valid accessfile is available
|
56 |
|
|
if(is_readable($oReg->AppPath.$oReg->PagesDir.$sLink.$oReg->PageExtension))
|
57 |
1993
|
darkviper
|
{
|
58 |
2026
|
darkviper
|
// create absolute URL
|
59 |
|
|
$aReplaceList[$sKey] = $oReg->AppUrl.$oReg->PagesDir.$sLink.$oReg->PageExtension.$aTag['ancor'];
|
60 |
1993
|
darkviper
|
}
|
61 |
1626
|
darkviper
|
}
|
62 |
2026
|
darkviper
|
// handle links of modules
|
63 |
|
|
} else {
|
64 |
|
|
// build name of the needed class
|
65 |
|
|
$sClass = 'm_'.$aTag['params']['addon'].'_WbLink';
|
66 |
|
|
// remove addon name from replacement array
|
67 |
|
|
// unset($aReplacement['Args']['addon']);
|
68 |
|
|
if(class_exists($sClass))
|
69 |
1993
|
darkviper
|
{
|
70 |
2026
|
darkviper
|
// instantiate class
|
71 |
|
|
$oWbLink = new $sClass();
|
72 |
|
|
// the class must implement the interface
|
73 |
|
|
if($oWbLink instanceof WbLinkAbstract)
|
74 |
1993
|
darkviper
|
{
|
75 |
2026
|
darkviper
|
$aTag['params']['pageid'] = $aTag['pageid'];
|
76 |
|
|
$aTag['params']['ancor'] = $aTag['ancor'];
|
77 |
|
|
// create real link from replacement data
|
78 |
|
|
$aReplaceList[$sKey] = $oWbLink->makeLinkFromTag($aTag['params']);
|
79 |
1993
|
darkviper
|
}
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
2026
|
darkviper
|
// extract indexes into a new array
|
83 |
|
|
$aSearchList = array_keys($aReplaceList);
|
84 |
|
|
// replace all identified wblink-tags in content
|
85 |
|
|
$sContent = str_replace($aSearchList, $aReplaceList, $sContent);
|
86 |
1626
|
darkviper
|
}
|
87 |
1993
|
darkviper
|
return $sContent;
|
88 |
1626
|
darkviper
|
}
|
89 |
2026
|
darkviper
|
|
90 |
|
|
|
91 |
|
|
// $oDb = WbDatabase::getInstance();
|
92 |
|
|
// $oReg = WbAdaptor::getInstance();
|
93 |
|
|
// $aReplaceList = array();
|
94 |
|
|
// $sPattern = '/\[wblink([0-9]+)\??([^\]]*)\]/is';
|
95 |
|
|
// if(preg_match_all($sPattern,$sContent,$aMatches))
|
96 |
|
|
// {
|
97 |
|
|
// // iterate through all found matches
|
98 |
|
|
// foreach($aMatches[0] as $iKey => $sKeyString )
|
99 |
|
|
// {
|
100 |
|
|
// $aReplaceList[$sKeyString] = array();
|
101 |
|
|
// // use original Tag to save PageId
|
102 |
|
|
// $aReplaceList[$sKeyString]['PageId'] = $aMatches[1][$iKey];
|
103 |
|
|
// // if there are additional arguments given
|
104 |
|
|
// if($aMatches[2][$iKey])
|
105 |
|
|
// {
|
106 |
|
|
// $aReplaceList[$sKeyString]['Args'] = array();
|
107 |
|
|
// $aArgs = preg_split('/&|&/i', $aMatches[2][$iKey], -1, PREG_SPLIT_NO_EMPTY);
|
108 |
|
|
// foreach($aArgs as $sArgument)
|
109 |
|
|
// {
|
110 |
|
|
// $aTmp = explode('=', $sArgument);
|
111 |
|
|
// $aReplaceList[$sKeyString]['Args'][$aTmp[0]] = $aTmp[1];
|
112 |
|
|
// }
|
113 |
|
|
// }
|
114 |
|
|
// }
|
115 |
|
|
// if(sizeof($aReplaceList) > 0)
|
116 |
|
|
// { // iterate list if replacements are available
|
117 |
|
|
// foreach($aReplaceList as $sKey => $aReplacement)
|
118 |
|
|
// {
|
119 |
|
|
// // set link on failure ('#' means, still stay on current page)
|
120 |
|
|
// $aReplaceList[$sKey] = '#';
|
121 |
|
|
// // handle normal pages links
|
122 |
|
|
// if(!isset($aReplacement['Args']))
|
123 |
|
|
// {
|
124 |
|
|
// // read corresponding link from table 'pages'
|
125 |
|
|
// $sql = 'SELECT `link` FROM `'.$oDb->TablePrefix.'pages` WHERE `page_id` = '.(int)$aReplacement['PageId'];
|
126 |
|
|
// if(($sLink = $oDb->get_one($sql)))
|
127 |
|
|
// {
|
128 |
|
|
// $sLink = trim(str_replace('\\', '/', $sLink), '/');
|
129 |
|
|
// // test if valid accessfile is available
|
130 |
|
|
// if(is_readable($oReg->AppPath.$oReg->PagesDir.$sLink.$oReg->PageExtension))
|
131 |
|
|
// {
|
132 |
|
|
// // create absolute URL
|
133 |
|
|
// $aReplaceList[$sKey] = $oReg->AppUrl.$oReg->PagesDir.$sLink.$oReg->PageExtension;
|
134 |
|
|
// }
|
135 |
|
|
// }
|
136 |
|
|
// // handle links of modules
|
137 |
|
|
// }else
|
138 |
|
|
// {
|
139 |
|
|
// // build name of the needed class
|
140 |
|
|
// $sClass = 'm_'.$aReplacement['Args']['addon'].'_WbLink';
|
141 |
|
|
// // remove addon name from replacement array
|
142 |
|
|
// unset($aReplacement['Args']['addon']);
|
143 |
|
|
// if(class_exists($sClass))
|
144 |
|
|
// {
|
145 |
|
|
// // instantiate class
|
146 |
|
|
// $oWbLink = new $sClass();
|
147 |
|
|
// // the class must implement the interface
|
148 |
|
|
// if($oWbLink instanceof WbLinkAbstract)
|
149 |
|
|
// {
|
150 |
|
|
// // create real link from replacement data
|
151 |
|
|
// $aReplaceList[$sKey] = $oWbLink->makeLinkFromTag($aReplacement['Args']);
|
152 |
|
|
// }
|
153 |
|
|
// }
|
154 |
|
|
// }
|
155 |
|
|
// }
|
156 |
|
|
// // extract indexes into a new array
|
157 |
|
|
// $aSearchList = array_keys($aReplaceList);
|
158 |
|
|
// // replace all identified wblink-tags in content
|
159 |
|
|
// $sContent = str_replace($aSearchList, $aReplaceList, $sContent);
|
160 |
|
|
// }
|
161 |
|
|
// }
|
162 |
|
|
// return $sContent;
|
163 |
|
|
// }
|