Project

General

Profile

1 1946 darkviper
//:search for an image in current page. If no image is present, the image of the parent page is inherited.
2 1681 darkviper
//:Use: [[iParentPageIcon?type=1]] Display the page-icon(0)(default) or menu_icon_0(1) or menu_icon_1(2) if found
3
// @author: Werner von der Decken
4
// @param int $type: 0=page_icon(default) | 1=menu_icon_0 | 2=menu_icon_1
5
// @param string $icon: name of a default image placed in WB_PATH/TEMPLATE/
6
// @return: a valid image-URL or empty string
7
//
8 1946 darkviper
9
$oDb = WbDatabase::getInstance();
10 2024 darkviper
$oReg = WbAdaptor::getInstance();
11 1681 darkviper
$type = !isset($type) ? 0 : (intval($type) % 3);
12
$icontypes = array( 0=>'page_icon', 1=>'menu_icon_0', 2=>'menu_icon_1');
13
$icon_url = '';
14 2024 darkviper
if( isset($icon) && is_readable($oReg->AppPath.'templates/'.TEMPLATE.'/'.$icon) )
15 1681 darkviper
{
16 2024 darkviper
	$icon_url = $oReg->AppUrl.'templates/'.TEMPLATE.'/'.$icon;
17 1681 darkviper
}
18 1946 darkviper
$tmp_trail = array_reverse($GLOBALS['wb']->page_trail);
19 1681 darkviper
foreach($tmp_trail as $pid)
20
{
21
	$sql  = 'SELECT `'.$icontypes[$type].'` ';
22 1946 darkviper
	$sql .= 'FROM `'.$oDb->TablePrefix.'pages` ';
23 1681 darkviper
	$sql .= 'WHERE `page_id`='.(int)$pid;
24 1946 darkviper
	if( ($icon = $oDb->get_one($sql)) != false )
25 1681 darkviper
	{
26 2024 darkviper
		$icon = ltrim(str_replace('\\', '/', $icon), '/');
27
		if( file_exists($oReg->AppPath.$icon) )
28 1681 darkviper
		{
29 2024 darkviper
			$icon_url = $oReg->AppUrl.$icon;
30 1681 darkviper
			break;
31
		}
32
	}
33
}
34
return $icon_url;