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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
<?php
namespace Bitweaver\Plugins;
use Bitweaver\KernelTools;
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {formhelp} function plugin
*
* Type: function
* Name: formhelp
* Input:
* - note (optional) words that are displayed, can also be an array, where: 'key: value'<br /> is printed
* only displayed if site_form_help is enabled
* - link (optional) provide a link to an internal page (avoids the problem with links being inerpreted
* prematurely by the KernelTools::tra() function
* <package>/<path to file>/<title>
* - package (optional) creates a page to 'Package'.ucfirst( $package ) and takes precedence over $page, should both be set.
* only dispalyed if help is enabled
* - install (optional) used for packages that require a separate installation
* passed in as an array:
* package => name of package to be installed
* file => path to installation file e.g.: admin/install.php
* - page (optional) page name on bitweaver
* only dispalyed if help is enabled
* - force (optional) if set, it will always dipslay this entry regardless of the feature settings
*/
function smarty_function_formhelp( $pParams, &$pSmarty=NULL ) {
$atts = $ret_note = $ret_page = $ret_link = $ret_install = '';
if( !empty( $pParams['hash'] ) ) {
$hash = &$pParams['hash'];
} else {
// maybe params were passed in separately
$hash = &$pParams;
}
$force = 'n';
// we need to do some hash modification if we're in the installer
if( !empty( $hash['is_installer'] )) {
if( !empty( $hash['note']['upgrade'] )) {
$hash['note']['version'] = $hash['note']['upgrade'];
unset( $hash['note']['upgrade'] );
}
}
foreach( $hash as $key => $val ) {
switch( $key ) {
case 'note':
case 'warning':
case 'link':
case 'page':
$rawHash[$key] = $val;
break;
case 'label':
case 'package':
case 'install':
case 'force':
$$key = $val;
break;
default:
if( $val ) {
$atts .= $key.'="'.$val.'" ';
}
break;
}
}
if( !empty( $package ) ) {
$rawHash['page'] = ucfirst( $package ).'Package';
}
// if link was passed in as a string, convert it into an array
if( !empty( $rawHash['link'] ) && is_string( $rawHash['link'] ) ) {
$l = explode( '/', $rawHash['link'] );
unset( $rawHash['link'] );
// package is first, title last, and all remaining elements file (can be 'foo/bar.php' as well)
$rawHash['link']['package'] = array_shift( $l );
$rawHash['link']['title'] = array_pop( $l );
$rawHash['link']['file'] = implode( '/', $l );
}
global $gBitSystem;
if( $gBitSystem->isFeatureActive( 'site_online_help' ) || $gBitSystem->isFeatureActive( 'site_form_help' ) || $force == 'y' ) {
if( !empty( $rawHash ) ) {
if( !empty( $rawHash['page'] ) && ( $gBitSystem->isFeatureActive('site_online_help') || $force == 'y' ) ) {
$ret_page = '<strong>'.KernelTools::tra( 'Online help' ).'</strong>: <a class=\'external\' href=\'https://bitweaver.org/wiki/index.php?page='.$rawHash['page'].'\'>'.$rawHash['page'].'</a><br />';
}
if( !empty( $rawHash['link'] ) && ( $gBitSystem->isFeatureActive('site_online_help') || $force == 'y' ) ) {
if( is_array( $rawHash['link'] ) ) {
$ret_link = '<strong>'.KernelTools::tra( 'IntraLink' ).'</strong>: ';
$ret_link .= '<a href=\'';
$ret_link .= constant( strtoupper( $rawHash['link']['package'] ).'_PKG_URL' ).$rawHash['link']['file'];
$ret_link .= '\'>'.KernelTools::tra( $rawHash['link']['title'] ).'</a>';
}
}
if( ( !empty( $rawHash['note'] ) && $gBitSystem->isFeatureActive('site_form_help') ) || ( !empty( $force ) && !empty( $rawHash['note'] ) ) ) {
if( is_array( $rawHash['note'] ) ) {
foreach( $rawHash['note'] as $name => $value ) {
if( $name == 'install' ) {
$ret_install = '<strong>'.KernelTools::tra( 'Install' ).'</strong>: '.KernelTools::tra( 'To use this package, you will first have to run the package specific installer' ).': ';
$ret_install .= '<a href=\'';
$ret_install .= constant( strtoupper( $value['package'] ).'_PKG_URL' ).$value['file'];
$ret_install .= '\'>'.ucfirst( $value['package'] ).'</a>';
} else {
$ret_note .= '<strong>'.ucfirst( KernelTools::tra( $name ) ).'</strong>: '.KernelTools::tra( $value ).'<br />';
}
}
} else {
$ret_note .= KernelTools::tra( $rawHash['note'] ).'<br />';
}
}
if( !empty( $rawHash['warning'] ) ) {
$ret_note .= '<span class="warning">'.KernelTools::tra( $rawHash['warning'] ).'</span><br />';
}
// join all the output content into one string
$content = $ret_note.$ret_page.$ret_link.$ret_install;
$html = '';
// using the overlib popup system
if( !empty( $content ) ) {
if( $gBitSystem->isFeatureActive('site_help_popup') ) {
global $gBitSmarty;
// $gBitSmarty->loadPlugin( 'smarty_modifier_popup' );
// $gBitSmarty->loadPlugin( 'smarty_function_biticon' );
$gBitSmarty->assign( 'title',KernelTools::tra('Extended Help') );
$gBitSmarty->assign( 'content', $content );
$gBitSmarty->assign( 'closebutton', TRUE );
$text = $gBitSmarty->fetch('bitpackage:kernel/popup_box.tpl');
$text = preg_replace( '/"/',"'",$text );
$popup = [
'trigger' => 'onclick',
'text' => $text,
'fullhtml' => '1',
'sticky' => '1',
'timeout' => '8000',
];
$biticon = [
'ipackage' => 'icons',
'iname' => 'dialog-information',
'iforce' => 'icon',
'iexplain' => 'Extended Help',
];
$html .= ' <span class="formhelppopup" '.$atts.'> ';
$html .= '<a '.smarty_function_popup( $popup, $pSmarty ).'>';
$html .= smarty_function_biticon( $biticon );
$html .= '</a>';
$html .= '</span>';
} else {
$html .= '<span class="help-block" '.$atts.'>'.$content.'</span>';
}
}
return $html;
}
}
}
|