1
|
<?php
|
2
|
/*
|
3
|
* replace all "[wblink{page_id}]" with real links
|
4
|
* @param string &$content : reference to global $content
|
5
|
* @return void
|
6
|
* @history 100216 17:00:00 optimise errorhandling, speed, SQL-strict
|
7
|
*/
|
8
|
function doFilterWbLink($content)
|
9
|
{
|
10
|
global $database, $wb;
|
11
|
$replace_list = array();
|
12
|
$pattern = '/\[wblink([0-9]+)\]/isU';
|
13
|
if(preg_match_all($pattern,$content,$ids))
|
14
|
{
|
15
|
foreach($ids[1] as $key => $page_id) {
|
16
|
$replace_list[$page_id] = $ids[0][$key];
|
17
|
}
|
18
|
foreach($replace_list as $page_id => $tag)
|
19
|
{
|
20
|
$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.(int)$page_id;
|
21
|
$link = $database->get_one($sql);
|
22
|
if(!is_null($link)) {
|
23
|
$link = $wb->page_link($link);
|
24
|
$content = str_replace($tag, $link, $content);
|
25
|
}
|
26
|
}
|
27
|
}
|
28
|
return $content;
|
29
|
}
|