-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqa-eql-homepage.php
149 lines (119 loc) · 4.7 KB
/
qa-eql-homepage.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
<?php
/*
Question2Answer (c) Gideon Greenspan
http://www.question2answer.org/
Expandable Question Lists by Bruno Vandekerkhove © 2015
*/
require_once QA_INCLUDE_DIR.'qa-app-format.php';
/*
CUSTOM HOMEPAGE
*/
class qa_expandable_homepage {
private $directory;
private $urltoroot;
// Load module
public function load_module($directory, $urltoroot) {
$this->directory = $directory;
$this->urltoroot = $urltoroot;
}
// Suggest requests
public function suggest_requests() {
return array(
array(
'title' => 'Expandable Homepage',
'request' => qa_opt('eql_homepage'),
'nav' => 'M', // 'M'=main, 'F'=footer, 'B'=before main, 'O'=opposite main, null=none
),
);
}
// Check if given request matches
public function match_request( $request ) {
$call = explode('/', $request);
return qa_opt('qa_eql_enabled') && qa_opt('qa_eql_homepage') && strtolower($call[0]) == qa_opt('qa_homepage_url');
}
// Process request
public function process_request( $request ) {
$requestparts=explode('/', qa_request());
$slugs=array_slice($requestparts, 1);
$countslugs=count($slugs);
$userid=qa_get_logged_in_userid();
$start = qa_get_start();
$count = qa_opt_if_loaded('page_size_activity');
$totalcount = qa_opt('cache_qcount');
$qspec = qa_db_posts_basic_selectspec($userid, false);
qa_db_add_selectspec_opost($qspec, 'ra', false, false);
qa_db_add_selectspec_ousers($qspec, 'rau', 'raup');
$qspec['source'].=" JOIN (SELECT questionid, childid FROM ^homepage ORDER BY ^homepage.updated DESC) AS rcaq ON ^posts.postid=rcaq.questionid".
" LEFT JOIN ^posts AS ra ON childid=ra.postid".
(QA_FINAL_EXTERNAL_USERS ? "" : " LEFT JOIN ^users AS rau ON ra.userid=rau.userid").
" LEFT JOIN ^userpoints AS raup ON ra.userid=raup.userid LIMIT #,#";
array_push($qspec['columns'], 'childid');
array_push($qspec['arguments'], $start, $count);
$qspec['sortdesc']='otime';
$query = 'SELECT ';
foreach ($qspec['columns'] as $columnas => $columnfrom)
$query .= $columnfrom . (is_int($columnas) ? '' : (' AS '.$columnas)) . ', ';
$query = qa_db_apply_sub(
substr($query, 0, -2).(strlen(@$qspec['source']) ? (' FROM '.$qspec['source']) : ''),
@$qspec['arguments']);
$results = qa_db_read_all_assoc(qa_db_query_raw($query));
qa_db_post_select($results, $qspec);
list($categories, $categoryid)=qa_db_select_with_pending(
qa_db_category_nav_selectspec($slugs, false, false, true),
$countslugs ? qa_db_slugs_to_category_id_selectspec($slugs) : null
);
$questions=qa_any_sort_and_dedupe($results);
// $questions=qa_any_sort_and_dedupe(array_merge($recentquestions,$recentanswers));
$pagesize=qa_opt('page_size_home');
if ($countslugs) {
if (!isset($categoryid))
return include QA_INCLUDE_DIR.'qa-page-not-found.php';
$categorytitlehtml=qa_html($categories[$categoryid]['title']);
$sometitle=qa_lang_html_sub('main/recent_qs_as_in_x', $categorytitlehtml);
$nonetitle=qa_lang_html_sub('main/no_questions_in_x', $categorytitlehtml);
} else {
$sometitle=qa_lang_html('main/recent_qs_as_title');
$nonetitle=qa_lang_html('main/no_questions_found');
}
require_once QA_INCLUDE_DIR.'qa-app-q-list.php';
$qa_content=qa_q_list_page_content(
$questions, // questions
$pagesize, // questions per page
$start, // start offset
$totalcount, // total count (null to hide page links)
$sometitle, // title if some questions
$nonetitle, // title if no questions
$categories, // categories for navigation
$categoryid, // selected category id
true, // show question counts in category navigation
qa_opt('eql_homepage_url'), // prefix for links in category navigation
qa_opt('feed_for_qa') ? qa_opt('eql_homepage_url') : null, // prefix for RSS feed paths (null to hide)
(count($questions)<$pagesize) // suggest what to do next
? qa_html_suggest_ask($categoryid)
: qa_html_suggest_qs_tags(qa_using_tags(), qa_category_path_request($categories, $categoryid)),
null, // page link params
null // category nav params
);
return $qa_content;
}
// Get handle from user ID
function handleForID($id) {
$result = qa_db_query_sub('SELECT * FROM ^users WHERE userid=# LIMIT 1',$id);
if ($row = mysql_fetch_array($result)) {
return $row['handle'];
}
return '';
}
// Parse elapsed time since given time (in seconds)
function elapsedTime($timestamp){
$html = qa_when_to_html($timestamp,qa_opt('show_full_date_days'));
$time = '<span>';
if (strlen(@$html['prefix']))
$time .= '<span>'.$html['prefix'].'</span>';
if (strlen(@$html['data']))
$time .= '<span>'.$html['data'].'</span>';
if (strlen(@$html['suffix']))
$time .= '<span>'.$html['suffix'].'</span>';
return $time.'</span>';
}
}