Project

General

Profile

1
//:search for an image in current page. If no image is present, the image of the parent page is inherited.
2
//: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

    
9
$oDb = WbDatabase::getInstance();
10
$oReg = WbAdaptor::getInstance();
11
$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
if( isset($icon) && is_readable($oReg->AppPath.'templates/'.TEMPLATE.'/'.$icon) )
15
{
16
	$icon_url = $oReg->AppUrl.'templates/'.TEMPLATE.'/'.$icon;
17
}
18
$tmp_trail = array_reverse($GLOBALS['wb']->page_trail);
19
foreach($tmp_trail as $pid)
20
{
21
	$sql  = 'SELECT `'.$icontypes[$type].'` ';
22
	$sql .= 'FROM `'.$oDb->TablePrefix.'pages` ';
23
	$sql .= 'WHERE `page_id`='.(int)$pid;
24
	if( ($icon = $oDb->get_one($sql)) != false )
25
	{
26
		$icon = ltrim(str_replace('\\', '/', $icon), '/');
27
		if( file_exists($oReg->AppPath.$icon) )
28
		{
29
			$icon_url = $oReg->AppUrl.$icon;
30
			break;
31
		}
32
	}
33
}
34
return $icon_url;
(20-20/22)