-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.forum_discussions_filtered.php
executable file
·216 lines (174 loc) · 7.23 KB
/
data.forum_discussions_filtered.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
require_once(TOOLKIT . '/class.datasource.php');
require_once(DOCROOT . '/extensions/asdc/lib/class.asdc.php');
Class datasourceforum_discussions_filtered extends Datasource{
private static $_fields;
private static $_sections;
public $dsParamROOTELEMENT = 'forum-discussions';
public $dsParamLIMIT = '20';
public $dsParamSTARTPAGE = '{$dpage:1}';
public $dsParamFILTERS = array(
'id' => '{$discussion-id}',
);
public function about(){
return array(
'name' => 'Forum: Discussions (Filtered)',
'author' => array(
'name' => 'Alistair Kearney',
'website' => 'http://overture.projects.local:8888',
'email' => 'alistair@pointybeard.com'),
'version' => '1.0',
'release-date' => '2009-05-02');
}
public static function findSectionID($handle){
return self::$_sections[$handle];
}
public static function findFieldID($handle, $section){
return self::$_fields[$section][$handle];
}
private static function __init(){
if(!is_array(self::$_fields)){
self::$_fields = array();
$rows = ASDCLoader::instance()->query("SELECT s.handle AS `section`, f.`element_name` AS `handle`, f.`id`
FROM `tbl_fields` AS `f`
LEFT JOIN `tbl_sections` AS `s` ON f.parent_section = s.id
ORDER BY `id` ASC");
if($rows->length() > 0){
foreach($rows as $r){
self::$_fields[$r->section][$r->handle] = $r->id;
}
}
}
if(!is_array(self::$_sections)){
self::$_sections = array();
$rows = ASDCLoader::instance()->query("SELECT s.handle, s.id
FROM `tbl_sections` AS `s`
ORDER BY s.id ASC");
if($rows->length() > 0){
foreach($rows as $r){
self::$_sections[$r->handle] = $r->id;
}
}
}
}
public function grab(&$param_pool){
$Members = Symphony::ExtensionManager()->create('members');
$Members->Member->initialiseCookie();
// If not logged in, redirect to 403 Forbidden page
if($Members->Member->isLoggedIn() !== true){
redirect(URL . '/forbidden/');
exit();
}
$member = $Members->Member->Member;
$member_id = $member->get('id');
$result = new XMLElement($this->dsParamROOTELEMENT);
self::__init();
$db = ASDCLoader::instance();
$sql = "SELECT SQL_CALC_FOUND_ROWS
pinned.entry_id AS `id`,
pinned.value AS `pinned`,
closed.value AS `closed`,
creation_date.local AS `creation-date`,
last_active.local AS `last-active`,
created_by.relation_id AS `created-by-member-id`,
created_by_username.entry_id AS `created-by-id`,
created_by_username.value AS `created-by-username`,
last_post.relation_id AS `last-post-member-id`,
last_post_username.entry_id AS `last-post-id`,
last_post_username.value AS `last-post-username`,
topic.value AS `topic`,
COUNT(comments.relation_id) AS `comments`
FROM `tbl_entries_data_%d` AS `pinned`
LEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `created_by_username` ON created_by_username.entry_id = created_by.relation_id
LEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `last_post_username` ON last_post_username.entry_id = last_post.relation_id
LEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id
LEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id
WHERE 1 %s
AND created_by.relation_id = %d
GROUP BY pinned.entry_id
ORDER BY pinned.value ASC, last_active.local DESC
LIMIT %d, %d";
try{
$rows = $db->query(
sprintf(
$sql,
self::findFieldID('pinned', 'discussions'),
self::findFieldID('closed', 'discussions'),
self::findFieldID('creation-date', 'discussions'),
self::findFieldID('last-active', 'discussions'),
self::findFieldID('created-by', 'discussions'),
self::findFieldID('username', 'members'),
self::findFieldID('last-post', 'discussions'),
self::findFieldID('username', 'members'),
self::findFieldID('topic', 'discussions'),
self::findFieldID('parent-id', 'comments'),
(isset($this->dsParamFILTERS['id']) && (int)$this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id = ".(int)$this->dsParamFILTERS['id'] : NULL),
(int)$member_id,
max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT),
$this->dsParamLIMIT
)
);
}
catch(Exception $e){
$result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
return $result;
}
if($rows->length() == 0 && strlen(trim($dsParamFILTERS['id'])) > 0){
$this->__redirectToErrorPage();
}
elseif($rows->length() == 0){
return $this->emptyXMLSet();
}
$total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total;
$result->prependChild(
General::buildPaginationElement($total, ceil($total * (1/$this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE)
);
/*
stdClass Object
(
[id] => 666
[pinned] => yes
[closed] => no
[creation-date] => 1233599808
[last-active] => 1237161637
[created-by-member-id] => 2126
[created-by-username] => Lewis
[last-post-member-id] => 2126
[last-post-username] => Lewis
[topic] => Symphony 2 Documentation
[comments] => 18
)
<entry id="595" comments="7">
<created-by id="2150">newnomad</created-by>
<closed>No</closed>
<last-active time="18:30" weekday="1">2009-02-09</last-active>
<last-post id="2150">newnomad</last-post>
<pinned>No</pinned>
<topic handle="viewing-feeds">viewing feeds</topic>
<creation-date time="19:31" weekday="3">2009-01-07</creation-date>
</entry>
*/
$param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id');
foreach($rows as $r){
$entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $r->comments));
$entry->appendChild(
new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'}))
);
$entry->appendChild(
new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'}))
);
$entry->appendChild(new XMLElement('closed', ucfirst($r->closed)));
$entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned)));
$entry->appendChild(new XMLElement('topic', General::sanitize($r->topic)));
$entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date'));
$entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active'));
$result->appendChild($entry);
}
return $result;
}
}