-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathqa-tt-layer.php
49 lines (41 loc) · 1.49 KB
/
qa-tt-layer.php
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
<?php
/*
Question2Answer Tagging Tools plugin
Copyright (C) 2011 Scott Vivian
License: https://www.gnu.org/licenses/gpl.html
*/
class qa_html_theme_layer extends qa_html_theme_base
{
public function head_script()
{
qa_html_theme_base::head_script();
$userPoints = qa_get_logged_in_points();
$userLevel = qa_get_logged_in_level();
// skip JS if no permission to post
if (qa_user_permit_error('permit_post_q') !== false)
return;
if (!$this->forbidNewTags($userPoints, $userLevel))
return;
$jsVars =
'var taggingTools = {' .
'separator: ' . (qa_opt('tag_separator_comma') ? qa_js(',') : qa_js(' ')) .
', points: ' . qa_js(qa_opt('tagging_tools_rep')) .
', minLength: ' . qa_js(qa_opt('tagging_tools_min_length')) .
', maxLength: ' . qa_js(qa_opt('tagging_tools_max_length')) .
', newTagErrorTemplate: ' . qa_js(qa_lang('taggingtools/tag_not_usable_js')) .
', shortErrorTemplate: ' . qa_js(qa_lang('taggingtools/tag_too_short_js')) .
', lengthErrorTemplate: ' . qa_js(qa_lang('taggingtools/tag_wrong_length_js')) .
'};';
$js = file_get_contents(QA_HTML_THEME_LAYER_DIRECTORY . '/tag-filter.js');
$this->output_raw('<script>' . $jsVars . $js . '</script>');
}
private function forbidNewTags($userPoints, $userLevel)
{
$qEditForm = $this->template == 'ask' || isset($this->content['form_q_edit']);
return
$qEditForm &&
qa_opt('tagging_tools_prevent') &&
$userPoints < (int) qa_opt('tagging_tools_rep') &&
$userLevel < QA_USER_LEVEL_EXPERT;
}
}