1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<?php
/**
* Plugin for Nexus creating a tikiwiki style menu with the difference of multiple levels being available
*
* @abstract creates a javascript expandable menu
* @author xing@synapse.plus.com
* @version $Revision: 1.1 $
* @package Nexus Plugin
*/
global $gNexusSystem;
// GUID should be a maximum of 16 chars
define( 'NEXUS_PLUGIN_GUID_TIKIWIKI', 'tikiwiki' );
$pluginParams = array(
'write_cache_function' => 'writeTikiWikiCache',
'description' => 'expandable menu reminiscent of the tikiwiki menu',
'web_link' => '<a class="external" href="http://www.tikiwiki.org">TikiWiki</a>',
'browser_requirements' => 'Most browsers that support javascript should support these menus.',
'edit_label' => 'TikiWiki menus',
'menu_types' => array(
'heo' => array( 'label' => 'head expands - open', 'note' => 'Head item serves merely as container and clicking on it will expand the underlying items (initial setting is open).' ),
'hec' => array( 'label' => 'head expands - closed', 'note' => 'Initial setting is closed' ),
'ieo' => array( 'label' => 'icon expands - open', 'note' => 'Menu head item serves as link and there is an icon to expand the menu (initial setting is open).' ),
'iec' => array( 'label' => 'icon expands - closed', 'note' => 'Initial setting is closed' ),
),
'plugin_type' => NEXUS_HTML_PLUGIN,
'include_js_in_head' => FALSE,
);
$gNexusSystem->registerPlugin( NEXUS_PLUGIN_GUID_TIKIWIKI, $pluginParams );
/**
* exports tikiwiki style menu
* @param $pMenuHash full menu hash
* @return full menu string ready for printing (key serves as cache file path)
*/
function writeTikiWikiCache( $pMenuHash ) {
global $smarty;
$menu_name = preg_replace( "/ +/", "_", trim( $pMenuHash->mInfo['title'] ) );
$menu_name = strtolower( $menu_name );
$menu_file = 'mod_'.$menu_name.'_'.$pMenuHash->mInfo['menu_id'].'.tpl';
$data = '{bitmodule title="{tr}'.$pMenuHash->mInfo['title'].'{/tr}" name="'.$menu_name.'"}';
$data .= '<div class="tikiwiki menu">';
// if a permission has been set, we need to work out when to close the {if} clause
$permCloseIds = array();
$perm_close = FALSE;
$perm_cycle = FALSE;
$type = $pMenuHash->mInfo['type'];
foreach( $pMenuHash->mInfo['tree'] as $key => $item ) {
if( $item['first'] ) {
$togid = 'togid'.$item['item_id'];
$data .= '<div id="'.$togid.'" ';
$data .= 'style="display:{if $smarty.cookies.'.$togid.' eq \'c\'}none{elseif $smarty.cookies.'.$togid.' eq \'o\'}block{else}';
if( $key != 0 && preg_match( "/c$/", $type ) ) {
$data .= 'none';
} else {
$data .= 'block';
}
$data .= '{/if};">';
} else {
// close permission clauses
if( $perm_cycle ) {
$data .= '{/if}';
$perm_cycle = FALSE;
}
if( in_array( $item['item_id'], $permCloseIds ) ) {
$perm_cycle = TRUE;
}
if( $perm_close ) {
$data .= '{/if}';
$perm_close = FALSE;
}
}
if( $item['last'] ) {
$data .= '</div>';
} else {
if( !empty( $item['perm'] ) ) {
// open permission if clause
$data .= '{if $gBitUser->hasPermission("'.$item['perm'].'")}';
if( !$item['head'] ) {
$perm_close = TRUE;
} else {
$permCloseIds[] = $item['item_id'];
}
}
if( $item['head'] ) {
$tog_next = 'togid'.$pMenuHash->mInfo['tree'][$key+1]['item_id'];
if( $type == 'heo' || $type == 'hec' ) {
$item['display_url'] = "javascript:toggle('".$tog_next."');";
} elseif( $type == 'ieo' || $type == 'iec' ) {
$item['expand_url'] = "javascript:icntoggle('".$tog_next."');";
}
$smarty->assign( 'tog_next', $tog_next );
}
$smarty->assign( 'item', $item );
$smarty->assign( 'type', $type );
$data .= $smarty->fetch( NEXUS_PKG_PATH.'templates/'.NEXUS_PLUGIN_GUID_TIKIWIKI.'/item.tpl' );
}
}
$data .= '</div><!-- end .menu -->';
$data .= '{/bitmodule}';
$ret[$menu_file] = $data;
return $ret;
}
?>
|