Project

General

Profile

1
//:search for icon in current page and parent pages if not found
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
global $wb, $database;
9
$type = !isset($type) ? 0 : (intval($type) % 3);
10
$icontypes = array( 0=>'page_icon', 1=>'menu_icon_0', 2=>'menu_icon_1');
11
$icon_url = '';
12
if( isset($icon) && file_exists(WB_PATH.'/'.TEMPLATE.'/'.$icon) )
13
{
14
	$icon_url = WB_REL.'/'.TEMPLATE.'/'.$icon;
15
}
16
if( !isset($wb->page_icon) ) { return $icon_url; }
17
$tmp_trail = $wb->page_trail;
18
$tmp_trail = array_reverse($tmp_trail);
19
foreach($tmp_trail as $pid)
20
{
21
	$sql  = 'SELECT `'.$icontypes[$type].'` ';
22
	$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
23
	$sql .= 'WHERE `page_id`='.(int)$pid;
24
	if( ($icon = $database->get_one($sql)) != false )
25
	{
26
		if( file_exists(WB_PATH.$icon) )
27
		{
28
			$icon_url = WB_REL.$icon;
29
			break;
30
		}
31
	}
32
}
33
return $icon_url;
(17-17/19)