-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqa-plugin.php
More file actions
86 lines (71 loc) · 2.75 KB
/
qa-plugin.php
File metadata and controls
86 lines (71 loc) · 2.75 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
<?php
/*
Plugin Name: q2apro Popular questions widget
Plugin URI: http://www.q2apro.com/plugins/popular-questions
Plugin Description: Displays the most viewed questions in a widget
Plugin Version: 0.2
Plugin Date: 2016-02-21
Plugin Author: q2apro
Plugin Author URI: http://www.q2apro.com/
Plugin License: GPLv3
Plugin Minimum Question2Answer Version: 1.5
Plugin Update Check URI:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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.
More about this license: http://www.gnu.org/licenses/gpl.html
*/
if(!defined('QA_VERSION'))
{
header('Location: ../../');
exit;
}
// language file
qa_register_plugin_phrases('q2apro-popular-questions-lang-*.php', 'q2apro_popularqu_lang');
// widget
qa_register_plugin_module('widget', 'q2apro-popular-questions-widget.php', 'q2apro_popular_questions_widget', 'q2apro Popular Questions Widget');
// admin
qa_register_plugin_module('module', 'q2apro-popular-questions-admin.php', 'q2apro_popular_questions_admin', 'Popular Questions Admin');
function q2apro_save_most_viewed_questions()
{
// save checktime of cache
qa_opt('q2apro_popularqu_checktime', time());
$maxquestions = qa_opt('q2apro_popularqu_maxqu');
$lastdays = qa_opt('q2apro_popularqu_lastdays');
$ourTopQuestions = qa_db_read_all_assoc(
qa_db_query_sub('SELECT postid, title, acount FROM `^posts`
WHERE `created` > NOW() - INTERVAL # DAY
AND `type` = "Q"
AND `closedbyid` IS NULL
ORDER BY views DESC
LIMIT #;',
$lastdays,
$maxquestions)
);
$saveoutput = '';
foreach($ourTopQuestions as $qu)
{
$activity_url = qa_path_html(qa_q_request($qu['postid'], $qu['title']), null, qa_opt('site_url'), null, null);
$questionlink = '<a href="'.$activity_url.'">'.htmlspecialchars($qu['title']).'</a>';
$answercnt = '';
if(qa_opt('q2apro_popularqu_answercount'))
{
$acnttitle = ($qu['acount'] == 1) ? qa_lang('q2apro_popularqu_lang/answer_one') : $qu['acount'].' '.qa_lang('q2apro_popularqu_lang/answers');
$answercnt = ' <span title="'.$acnttitle.'">('.$qu['acount'].')</span>';
}
$saveoutput .= '<li>
'.$questionlink.$answercnt.'
</li>
';
}
// save into cache
qa_opt('q2apro_popularqu_cached', $saveoutput);
} // end q2apro_save_most_viewed_questions
/*
Omit PHP closing tag to help avoid accidental output
*/