forked from GATEOverflow/q2a-answerhide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqa-answerhide-layer.php
More file actions
123 lines (96 loc) · 2.77 KB
/
qa-answerhide-layer.php
File metadata and controls
123 lines (96 loc) · 2.77 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
<?php
class qa_html_theme_layer extends qa_html_theme_base {
public function q_view_buttons($q_view)
{
if($this -> template == 'question' and qa_is_logged_in())
{
$q_view['form']['buttons']['answer_hide'] = array("tags" => 'id="answer_hide"', "label" => "HIDE ANSWERS", "popup" => "Hide or Show the Answers");
$this->output('
<script type="text/javascript">
function answertoggle() {
$(\'#a_list\').toggle();
var AH = document.getElementById("answer_hide");
//alert(AH.innerHTML);
if(AH.value=="SHOW ANSWERS" || AH.innerHTML=="SHOW ANSWERS"){
AH.value="HIDE ANSWERS";
AH.innerHTML="HIDE ANSWERS";
}
else{
AH.value="SHOW ANSWERS";
AH.innerHTML="SHOW ANSWERS";
}
}
$(document).ready(function()
{
var Answers_Count = document.querySelector("[itemprop=answerCount]").textContent;
$("#answer_hide").attr("type", "button");
$("#answer_hide").click( function Click(){answertoggle();} );
if(Answers_Count==0)
document.getElementById("answer_hide").remove();
});
</script>');
require_once QA_INCLUDE_DIR . 'db/metas.php';
$userid = qa_get_logged_in_userid();
if(qa_db_usermeta_get($userid, 'answerhide')=="1")
{
$this->output('
<script type="text/javascript">
$(document).ready(function()
{
answertoggle();
});
</script>');
}
}
qa_html_theme_base::q_view_buttons($q_view);
}
function doctype()
{
if($this->template == 'account') {
// add answerhide form
$answerhide_form = $this->answerhide_form();
if($answerhide_form) {
$this->content['form_2'] = $answerhide_form;
}
}
qa_html_theme_base::doctype();
}
function answerhide_form() {
if($handle = qa_get_logged_in_handle()) {
require_once QA_INCLUDE_DIR . 'db/metas.php';
$userid = qa_get_logged_in_userid();
if (qa_clicked('answerhide_save')) {
if(qa_post_text('answerhide')){
qa_db_usermeta_set($userid, 'answerhide', qa_post_text('answerhide')) ;
}
else {
qa_db_usermeta_set($userid, 'answerhide', "0") ;
}
qa_redirect($this->request,array('ok'=>qa_lang_html('admin/options_saved')));
}
$ok = qa_get('ok')?qa_get('ok'):null;
$fields = array();
$fields['answerhide'] = array(
'label' => qa_opt('answerhide-plugin-text'),
'tags' => 'NAME="answerhide"',
'type' => 'checkbox',
'value' => qa_db_usermeta_get($userid, 'answerhide'),
);
$form=array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'style' => 'tall',
'title' => '<a name="answerhide_text"></a>'.qa_opt('answerhide-plugin-title'),
'tags' => 'action="'.qa_self_html().'#answerhide_text" method="POST"',
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang_html('main/save_button'),
'tags' => 'NAME="answerhide_save"',
),
),
);
return $form;
}
}
}
?>