forked from ProThoughts/q2apro-popular-questions-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq2apro-popular-questions-widget.php
118 lines (106 loc) · 3.25 KB
/
q2apro-popular-questions-widget.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
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
<?php
/*
Plugin Name: q2apro Popular questions widget
Plugin Author: q2apro (extended by Ramon Kaes)
*/
class q2apro_popular_questions_widget
{
function allow_template($template)
{
$allow = false;
switch ($template) {
case 'activity':
case 'qa':
case 'questions':
case 'hot':
case 'ask':
case 'categories':
case 'question':
case 'tag':
case 'tags':
case 'unanswered':
case 'user':
case 'users':
case 'search':
case 'admin':
case 'custom':
$allow = true;
break;
}
return $allow;
}
function allow_region($region)
{
$allow = false;
switch ($region) {
case 'side':
$allow = true;
break;
case 'main':
case 'full':
break;
}
return $allow;
}
function output_widget($region, $place, $themeobject, $template, $request, $qa_content)
{
if (time() - qa_opt('q2apro_popularqu_checktime') > qa_opt('q2apro_popularqu_checkhours') * 60 * 60) {
q2apro_save_most_viewed_questions();
}
// output widget using cached values
$output = '';
$output .= '
<div class="popularquestions-widget">
<h2>
' . qa_lang('q2apro_popularqu_lang/most_popqu') . ' ' . qa_opt('q2apro_popularqu_lastdays') . ' ' . qa_lang('q2apro_popularqu_lang/days') . '
</h2>
<ol>
' . qa_opt('q2apro_popularqu_cached') . '
</ol>
</div>
';
// css (could also go into your theme css to save load)
$output .= '
<style type="text/css">
.popularquestions-widget {
margin: 0;
}
.popularquestions-widget p {
}
.popularquestions-widget ol {
padding:0;
font-size: .75rem;
}
.popularquestions-widget ol li {
padding: 5px 0;
display: flex;
align-items: center;
justify-content: space-between;
}
.popularquestions-widget ol li img.qa-avatar-image {
margin-right: 10px;
width: 36px;
height: 36px;
}
.popularquestions-widget ol li a {
word-wrap: break-word;
flex-grow: 1;
margin-right: 10px;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.popularquestions-widget ol li span {
white-space: nowrap;
cursor: default;
}
</style>
';
// output widget into theme
$themeobject->output($output);
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/