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) && is_readable(WB_PATH.'/templates/'.TEMPLATE.'/'.$icon) )
13
{
14
	$icon_url = WB_REL.'/templates/'.TEMPLATE.'/'.$icon;
15
}
16
$tmp_trail = $wb->page_trail;
17
$tmp_trail = array_reverse($tmp_trail);
18
foreach($tmp_trail as $pid)
19
{
20
	$sql  = 'SELECT `'.$icontypes[$type].'` ';
21
	$sql .= 'FROM `'.TABLE_PREFIX.'pages` ';
22
	$sql .= 'WHERE `page_id`='.(int)$pid;
23
	if( ($icon = $database->get_one($sql)) != false )
24
	{
25
		if( file_exists(WB_PATH.$icon) )
26
		{
27
			$icon_url = WB_REL.$icon;
28
			break;
29
		}
30
	}
31
}
32
return $icon_url;
(19-19/21)