Repository navigation
Expand file tree
/
Copy pathdistribution.php
More file actions
322 lines (284 loc) · 10.1 KB
/
Copy pathdistribution.php
File metadata and controls
322 lines (284 loc) · 10.1 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
// +--------------------------------------------------------------------------+
// | Maps Plugin 1.6.0 |
// +--------------------------------------------------------------------------+
// | Maintainer: ::Ben |
// | distribution.php |
// | |
// | Native Geeklog distribution and discovery callbacks. |
// +--------------------------------------------------------------------------+
if (!defined('VERSION')) {
die('This file can not be used on its own.');
}
/**
* Translate a Geeklog syndication limit into Maps collection options.
*
* Geeklog feed limits may be an item count (for example "10") or an hour
* window (for example "24h"). Maps keeps the common convention and bounds
* item-count queries so a feed request cannot become unbounded accidentally.
*
* @param mixed $limit
* @return array
*/
function MAPS_feedCollectionOptions($limit)
{
$options = array('limit' => 10, 'order' => 'modified-desc');
$limit = trim((string) $limit);
if ($limit === '') {
return $options;
}
if (substr($limit, -1) === 'h') {
$hours = (int) substr($limit, 0, -1);
if ($hours > 0) {
$options['since'] = time() - ($hours * 3600);
$options['limit'] = 100;
}
return $options;
}
if (ctype_digit($limit)) {
$options['limit'] = max(1, min(100, (int) $limit));
}
return $options;
}
/**
* Expose Maps as a source in Geeklog Content Syndication.
*
* @return array
*/
function plugin_getfeednames_maps()
{
global $LANG_MAPS_1;
$name = isset($LANG_MAPS_1['plugin_name']) ? $LANG_MAPS_1['plugin_name'] : 'Maps';
return array(
array('id' => 'all', 'name' => $name)
);
}
/**
* Supply Maps entries to Geeklog's RSS/Atom generator.
*
* Geeklog's dispatcher also supplies the feed type and version. Older plugin
* examples often omit them, but accepting them lets Maps expose extension tags
* correctly while remaining compatible with Geeklog 2.1.1 through 2.2.2.
*
* @param int|string $feed
* @param string $link
* @param string $update
* @param string $feedType
* @param string $feedVersion
* @return array
*/
function plugin_getfeedcontent_maps($feed, &$link, &$update, $feedType = '', $feedVersion = '')
{
global $_TABLES, $_MAPS_CONF;
$link = rtrim($_MAPS_CONF['site_url'], '/') . '/';
$update = '';
$feedId = (int) $feed;
if ($feedId <= 0) {
return array();
}
$result = DB_query(
"SELECT topic,limits,content_length FROM {$_TABLES['syndication']} WHERE fid=" . $feedId
);
$syndication = DB_fetchArray($result);
if (!is_array($syndication)) {
return array();
}
$source = isset($syndication['topic']) ? (string) $syndication['topic'] : 'all';
if ($source !== '' && $source !== 'all') {
return array();
}
$options = MAPS_feedCollectionOptions(isset($syndication['limits']) ? $syndication['limits'] : '');
$items = MAPS_contentQuery('*', 1, $options);
$contentLength = isset($syndication['content_length']) ? (int) $syndication['content_length'] : 0;
$entries = array();
$ids = array();
foreach ($items as $item) {
if (empty($item['id']) || empty($item['url'])) {
continue;
}
$summary = isset($item['description']) ? $item['description'] : '';
$summary = PLG_replaceTags($summary);
if ($contentLength > 1 && function_exists('COM_truncateHTML')) {
$summary = COM_truncateHTML($summary, $contentLength, ' ...');
}
$entry = array(
'title' => isset($item['title']) ? $item['title'] : '',
'summary' => $summary,
'text' => $summary,
'link' => $item['url'],
'uid' => isset($item['uid']) ? (int) $item['uid'] : 0,
'author' => isset($item['author']) ? $item['author'] : '',
'date' => isset($item['date-modified']) ? (int) $item['date-modified'] : 0,
'format' => 'html'
);
if (function_exists('PLG_getFeedElementExtensions')) {
$entry['extensions'] = PLG_getFeedElementExtensions(
'maps',
(string) $item['id'],
(string) $feedType,
(string) $feedVersion,
'all',
$feedId
);
}
$entries[] = $entry;
$ids[] = (string) $item['id'];
}
$update = implode(',', $ids);
return $entries;
}
/**
* Tell Geeklog whether an existing Maps feed still represents current data.
*
* @param int|string $feed
* @param string $topic
* @param string $updateData
* @param string $limit
* @param string $updatedType
* @param string $updatedTopic
* @param string $updatedId
* @return bool true when current, false when regeneration is required
*/
function plugin_feedupdatecheck_maps(
$feed,
$topic,
$updateData,
$limit,
$updatedType = '',
$updatedTopic = '',
$updatedId = ''
) {
if ($updatedType === 'maps' && $updatedId !== '') {
return false;
}
$items = MAPS_contentQuery('*', 1, MAPS_feedCollectionOptions($limit));
$ids = array();
foreach ($items as $item) {
if (isset($item['id'])) {
$ids[] = (string) $item['id'];
}
}
return implode(',', $ids) === (string) $updateData;
}
/**
* Native Geeklog XML Sitemap collector.
*
* General metadata remains owned by plugin_getiteminfo_maps(); this callback
* supplies the optimized sitemap-specific representation requested by core.
*
* @param int $uid User ID, normally 1 for anonymous sitemap generation
* @param int $limit Maximum number of items, 0 for no explicit limit
* @return array
*/
function plugin_collectSitemapItems_maps($uid = 1, $limit = 0)
{
global $_TABLES;
$uid = (int) $uid;
$limit = (int) $limit;
$sql = "SELECT mid,modified FROM {$_TABLES['maps_maps']} "
. "WHERE active=1 AND hidden=0"
. COM_getPermSQL('AND', $uid, 2)
. " ORDER BY modified DESC, mid DESC";
if ($limit > 0) {
$sql .= ' LIMIT ' . $limit;
}
$result = DB_query($sql);
$items = array();
while ($row = DB_fetchArray($result)) {
if (!is_array($row) || empty($row['mid'])) {
continue;
}
$modified = isset($row['modified']) ? strtotime($row['modified']) : false;
$items[] = array(
'url' => MAPS_contentUrl((int) $row['mid']),
'date-modified' => ($modified === false ? 0 : $modified)
);
}
// Marker pages are indexable content too. Use the same canonical URL as
// public links and search results, and require both marker and parent-map
// visibility/permissions so the sitemap never advertises an inaccessible URL.
$markerSql = "SELECT mk.mkid,mk.modified FROM {$_TABLES['maps_markers']} mk "
. "INNER JOIN {$_TABLES['maps_maps']} m ON m.mid=mk.mid "
. "WHERE mk.active=1 AND mk.hidden=0 AND m.active=1 AND m.hidden=0"
. COM_getPermSQL('AND', $uid, 2, 'mk')
. COM_getPermSQL('AND', $uid, 2, 'm')
. " ORDER BY mk.modified DESC, mk.mkid DESC";
$markerResult = DB_query($markerSql);
while ($marker = DB_fetchArray($markerResult)) {
if (!is_array($marker) || !isset($marker['mkid']) || trim((string) $marker['mkid']) === '') {
continue;
}
$modified = isset($marker['modified']) ? strtotime($marker['modified']) : false;
$items[] = array(
'url' => MAPS_markerContentUrl($marker['mkid']),
'date-modified' => ($modified === false ? 0 : $modified)
);
if ($limit > 0 && count($items) >= $limit) {
break;
}
}
if ($limit > 0 && count($items) > $limit) {
$items = array_slice($items, 0, $limit);
}
return $items;
}
/**
* Native Geeklog related-items callback.
*
* Geeklog's current related-items contract is topic based. Maps therefore uses
* the shared topic_assignments table when Maps topic assignments exist and
* returns no invented relationship when none exists.
*
* @param array $tids Topic IDs
* @param int $max Maximum number of items
* @param int $trim Maximum title length
* @return array Unix timestamp => clickable related-item link
*/
function plugin_getrelateditems_maps($tids, $max, $trim)
{
global $_TABLES;
if (!is_array($tids) || empty($tids)) {
return array();
}
$safeTids = array();
foreach ($tids as $tid) {
$tid = trim((string) $tid);
if ($tid !== '') {
$safeTids[] = "'" . MAPS_dbEscape($tid) . "'";
}
}
if (empty($safeTids)) {
return array();
}
$max = max(1, min(100, (int) $max));
$trim = max(1, (int) $trim);
$sql = "SELECT DISTINCT m.mid,m.name,m.modified "
. "FROM {$_TABLES['maps_maps']} m "
. "INNER JOIN {$_TABLES['topic_assignments']} ta "
. "ON ta.type='maps' AND ta.id=m.mid "
. "WHERE ta.tid IN (" . implode(',', $safeTids) . ") "
. "AND m.active=1 AND m.hidden=0"
. COM_getPermSQL('AND', 0, 2, 'm')
. " ORDER BY m.modified DESC, m.mid DESC LIMIT " . $max;
$result = DB_query($sql);
$related = array();
while ($row = DB_fetchArray($result)) {
if (!is_array($row) || empty($row['mid'])) {
continue;
}
$title = MAPS_decodeStoredText(isset($row['name']) ? $row['name'] : '');
$title = COM_truncate($title, $trim, '...');
$timestamp = isset($row['modified']) ? strtotime($row['modified']) : false;
if ($timestamp === false || $timestamp <= 0) {
$timestamp = time();
}
while (isset($related[$timestamp])) {
$timestamp--;
}
$related[$timestamp] = COM_createLink(
htmlspecialchars($title, ENT_QUOTES, 'UTF-8'),
MAPS_contentUrl((int) $row['mid'])
);
}
return $related;
}