-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqa-feature-overrides.php
164 lines (147 loc) · 6.19 KB
/
qa-feature-overrides.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
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
<?php
function qa_db_posts_basic_selectspec($voteuserid=null, $full=false, $user=true)
{
global $qa_template;
$res = null;
if(($qa_template === 'questions' || $qa_template === 'unanswered') && (qa_get('sort') == 'featured') )
{
$res = qa_db_posts_basic_selectspec_base($voteuserid, $full, $user);
$res['source'] .= " join ^postmetas gfeat on ^posts.postid = gfeat.postid and gfeat.title like 'featured'";
}
if(qa_is_logged_in() && qa_opt("qa_featured_enable_user_reads") && (($qa_template === 'questions') || ($qa_template === 'unanswered') || ($qa_template === 'activity')|| ($qa_template === 'question') || ($qa_template === 'tag') || ($qa_template === 'search')))
{
if(!$res){
$res = qa_db_posts_basic_selectspec_base($voteuserid, $full, $user);
}
$userid = qa_get_logged_in_userid();
$res['columns'][] = "ureads.postid as readid";
$res['source'] .= " left join ^userreads ureads on ^posts.postid = ureads.postid and ureads.userid = $userid";
}
if($res)
return $res;
else
return qa_db_posts_basic_selectspec_base($voteuserid, $full, $user);
}
function qa_q_list_page_content($questions, $pagesize, $start, $count, $sometitle, $nonetitle,
$navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest,
$pagelinkparams=null, $categoryparams=null, $dummy=null)
{
$request = qa_request_parts();
$request = $request[0];
if(($request === 'questions' || $request === 'unanswered') && (qa_get('sort') == 'featured') )
{
$pagelinkparams= array("sort" => "featured");
$categorytitlehtml = qa_html($navcategories[$categoryid]['title']);
$sometitle = $categoryid != null ? qa_lang_html_sub('featured_lang/featured_qs_in_x', $categorytitlehtml) : qa_lang_html('featured_lang/featured_qs_title');
if($request === 'questions')
{
$nonetitle = $categoryid != null ? qa_lang_html_sub('featured_lang/nofeatured_qs_in_x', $categorytitlehtml) : qa_lang_html('featured_lang/nofeatured_qs_title');
}
else
{
$nonetitle = $categoryid != null ? qa_lang_html_sub('featured_lang/nofeatured_qs_un_in_x', $categorytitlehtml) : qa_lang_html('featured_lang/nofeatured_qs_un_title');
}
$feedpathprefix = null;
$list = "featured_qcount";
$listc = "fcount";
if($request == "unanswered")
{
$list.= "_un";
$listc .= "_in";
}
if(!$categoryid){
$count=qa_opt($list);
}
else{
$count = qa_db_categorymeta_get($categoryid, $listc);
}
}
return qa_q_list_page_content_base($questions, $pagesize, $start, $count, $sometitle, $nonetitle,
$navcategories, $categoryid, $categoryqcount, $categorypathprefix, $feedpathprefix, $suggest,
$pagelinkparams, $categoryparams, $dummy);
}
function category_path_fqcount_update($postid)
{
$pathq = "select categoryid, catidpath1, catidpath2, catidpath3 from ^posts where postid = #";
$result = qa_db_query_sub($pathq, $postid);
$path = qa_db_read_one_assoc($result, true);
if($path){
ifcategory_fqcount_update($path['categoryid']); // requires QA_CATEGORY_DEPTH=4
ifcategory_fqcount_update($path['catidpath1']);
ifcategory_fqcount_update($path['catidpath2']);
ifcategory_fqcount_update($path['catidpath3']);
}
}
function updatefeaturedcount($postid)
{
$query = qa_db_query_sub("select count(*) from ^postmetas where title like 'featured'");
$count = qa_db_read_one_value($query);
qa_opt('featured_qcount', $count);
category_path_fqcount_update($postid);
$query = qa_db_query_sub("select count(*) from ^postmetas a, ^posts b where a.postid=b.postid and b.acount = 0 and a.title like 'featured'");
$count = qa_db_read_one_value($query);
qa_opt('featured_qcount_un', $count);
}
function ifcategory_fqcount_update($categoryid)
{
if (isset($categoryid)) {
// This seemed like the most sensible approach which avoids explicitly calculating the category's depth in the hierarchy
$filter = " and postid in (select postid from ^postmetas where title like 'featured')";
$query = qa_db_query_sub(
"select GREATEST( (SELECT COUNT(*) FROM ^posts WHERE categoryid=# AND type='Q'".$filter."), (SELECT COUNT(*) FROM ^posts WHERE catidpath1=# AND type='Q'".$filter."), (SELECT COUNT(*) FROM ^posts WHERE catidpath2=# AND type='Q'".$filter."), (SELECT COUNT(*) FROM ^posts WHERE catidpath3=# AND type='Q'".$filter.") ) ",
$categoryid, $categoryid, $categoryid, $categoryid
); // requires QA_CATEGORY_DEPTH=4
$count = qa_db_read_one_value($query);
qa_db_categorymeta_set($categoryid, 'fcount', $count);
$filter .=" and acount = 0";
$query = qa_db_query_sub(
"select GREATEST( (SELECT COUNT(*) FROM ^posts WHERE categoryid=# AND type='Q'".$filter."), (SELECT COUNT(*) FROM ^posts WHERE catidpath1=# AND type='Q'".$filter."), (SELECT COUNT(*) FROM ^posts WHERE catidpath2=# AND type='Q'".$filter."), (SELECT COUNT(*) FROM ^posts WHERE catidpath3=# AND type='Q'".$filter.") ) ",
$categoryid, $categoryid, $categoryid, $categoryid
); // requires QA_CATEGORY_DEPTH=4
$count = qa_db_read_one_value($query);
qa_db_categorymeta_set($categoryid, 'fcount_un', $count);
}
}
function qa_check_page_clicks()
{
global $qa_page_error_html;
global $qa_request;
require_once QA_INCLUDE_DIR."db/metas.php";
if ( qa_is_http_post() ) {
$postid = @$_POST['postid'];
if(qa_get_logged_in_level()>= qa_opt('qa_featured_questions_level'))
{
if(isset($_POST['feature-button']) )
{
qa_db_postmeta_set($postid, "featured", "1");
updatefeaturedcount($postid);
qa_redirect( qa_request(), $_GET );
}
if(isset($_POST['unfeature-button']) )
{
qa_db_postmeta_clear($postid, "featured");
updatefeaturedcount($postid);
qa_redirect( qa_request(), $_GET );
}
}
if(qa_opt('qa_featured_enable_user_reads') && qa_is_logged_in())
{
if(isset($_POST['read-button']) )
{
//$postid = $_POST['read-button'];
$query = "insert into ^userreads(userid, postid) values (#,#)";
qa_db_query_sub($query, qa_get_logged_in_userid(), $postid);
qa_redirect( qa_request(), $_GET );
}
if(isset($_POST['unread-button']) )
{
//$postid = $_POST['unread-button'];
$query = "delete from ^userreads where userid = # and postid = #";
qa_db_query_sub($query, qa_get_logged_in_userid(), $postid);
qa_redirect( qa_request(), $_GET );
}
}
}
qa_check_page_clicks_base();
}
?>