-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEasyEnter.php
More file actions
221 lines (179 loc) · 5.89 KB
/
EasyEnter.php
File metadata and controls
221 lines (179 loc) · 5.89 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
# Mantis Plugin "EasyEnter"
# Copyright (C) 2017 Frithjof Gnas - fg@prae-sensation.de
#
# Description:
# Often there's a problem for noob-users to know what to do with a bugtracker.
# Even if it is really easy and there is a pictured documentation the users just
# don't get it to enter their wishes/feature requests, bugs etc. into the
# bugtracker. Instead they send you dozens of mails or worse: they call you to
# tell you about an idea they just got.
#
# Even the users goodwilled capitulate seeing a bug tracker interface the first
# time. From the thinking that any bug-report is better than nothing or doing
# the user's work (enter the tickets yourself), this plugin wants to present the
# reporters an easier flattened bug report form. Everything else stays the same,
# but the hurdle of entering bugs is lowered significantly!
#
#
# Disclaimer & License:
# This plugin - EasyEnter - is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
require_once( config_get( 'class_path' ) . 'MantisPlugin.class.php' );
class EasyEnterPlugin extends MantisPlugin {
/**
* @var array
*/
var $current_config = [];
/**
* @var int
*/
var $project_id;
/**
* A method that populates the plugin information and minimum requirements.
*/
function register( ) {
$this->name = lang_get( 'plugin_easyenter_title' );
$this->description = lang_get( 'plugin_easyenter_description' );
$this->page = 'config';
$this->version = '1.2';
$this->requires = array(
'MantisCore' => '2.10.0',
);
$this->author = 'Frithjof Gnas';
$this->contact = 'fg@prae-sensation.de';
}
function config( ) {
return array(
'include_fields' => array(
'summary', 'description'
),
# Exclude fields: Entries with prefix "special." are for special
# elements that should be excluded additionally
'exclude_fields' => array(
# hide the "profile ...or enter"-row
'special.custom_profile',
# hide the asterisks at the mandatory field-labels
#'special.mandatory_asterisks'
),
'field_values' => array(
'category_id' => 1,
'priority' => NORMAL,
'additional_info' => 'Submitted using "EasyEnter"',
'report_stay' => 'CHECKED',
),
# EasyEnter active for users with (including) maximum access level
'max_access_level' => UPDATER
);
}
function events()
{
return array(
'EVENT_LAYOUT_CONTENT_BEGIN' => EVENT_TYPE_OUTPUT,
'EVENT_LAYOUT_PAGE_FOOTER' => EVENT_TYPE_OUTPUT,
);
}
/**
* @return array
*/
function hooks( ) {
return array(
'EVENT_LAYOUT_CONTENT_BEGIN' => 'show_noscript_warning',
'EVENT_LAYOUT_PAGE_FOOTER' => 'replace_bug_report_page',
);
}
/**
* Insert warning into page about EasyEnter requiring javascript to work
* @param string $p_event
* @return string
*/
function show_noscript_warning( $p_event ) {
$this->set_current_project( );
if( !$this->plugin_requirements_fulfilled( ) ) {
return '';
}
return '<noscript>
<br>
<table class="width100" cellspacing="1"><tbody><tr><td
style="background-color:#fcbdbd; text-align:center">
<strong>' . plugin_lang_get( 'noscriptwarning' ) . '</strong>
</td></tr></tbody></table>
<br>
</noscript>
<script>document.write(\'<div class="powered_easyenter" '
. 'style="text-align:right;font-style:italic;">powered by '
. 'EasyEnter</div>\')</script>
';
}
/**
* Replace bug report page with version where the mandatory and shown fields
* are notable reduced.
* In configuration is set which fields should be hidden and for what
* usergroup the "EasyEnter" should become active.
* @param string $p_event
* @return string
*/
function replace_bug_report_page( $p_event ) {
$this->set_current_project( );
if( !$this->plugin_requirements_fulfilled( ) ) {
return '';
}
return $this->jquery_rebuild_bug_report_page( );
}
/**
* Ensure the requirements for executing the plugin's main hook
* ("replace_bug_report_page") are fulfilled.
* Requirements are met if...
* ..the current page is the bug_report_page and
* ..the current user's access level is lower or equal the configured one
*
* @access protected
* @return bool
*/
function plugin_requirements_fulfilled( ) {
if( !is_page_name( 'bug_report_page' ) ) {
return false;
}
# access levels (defined in core/constant_in.php)
$t_user_id = auth_get_current_user_id( );
$t_user_access_level = user_get_access_level( $t_user_id, $this->project_id );
$t_max_access_level = $this->get_current_config( 'max_access_level' );
if( $t_user_access_level > $t_max_access_level ) {
return false;
}
return true;
}
/**
* Sets the current globally set project id to class-property
*/
function set_current_project( ) {
$this->project_id = (int) helper_get_current_project();
}
/**
* Get the configuration valid for current project.
* @param string $p_key
* @return mixed
*/
function get_current_config( $p_key ) {
return plugin_config_get( $p_key, null, null, null, $this->project_id );
}
/**
* Include JS Snippets with EasyEnter-config and corresponding script to apply it
* @return string
*/
function jquery_rebuild_bug_report_page()
{
$t_modified = filemtime( plugin_file_path( 'easyenter_plugin_configuration.js', plugin_get_current() ) );
$t_html = '
<span id="easyenter-helper_current_project_id" data-current_project_id="' . (int) $this->project_id . '"></span>
<script src="' . plugin_file( 'easyenter_plugin_configuration.js' ) . '&' . $t_modified . '"></script>
<script type="text/javascript" src="'
. plugin_file( 'easyenter_page.js' ) . '"></script>';
return $t_html;
}
}