-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathblog-base.php
437 lines (353 loc) · 12.6 KB
/
blog-base.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?php
/*
Blog Post by Jack Siro
https://github.com/JacksiroKe/q2a-blog-post
Description: Basic and Database functions for the blog post plugin
*/
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
header('Location: ../../../');
exit;
}
function bp_p_path_html($permalink, $absolute = false, $showtype = null, $showid = null)
{
return qa_html(bp_p_path($permalink, $absolute, $showtype, $showid));
}
function bp_p_path($permalink, $absolute = false, $showtype = null, $showid = null)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
if (($showtype == 'P' || $showtype == 'C') && isset($showid)) {
$params = array('show' => $showid); // due to pagination
$anchor = qa_anchor($showtype, $showid);
}
else {
$params = null;
$anchor = null;
}
return qa_path(bp_p_request($permalink), $params, $absolute ? qa_opt('site_url') : null, null, $anchor);
}
function bp_p_request($permalink)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
require_once QA_INCLUDE_DIR . 'app/options.php';
require_once QA_INCLUDE_DIR . 'util/string.php';
return 'blog/' . $permalink;
}
function bp_cat_path($navcategories, $catid)
{
$upcategories = array();
for ($upcategory = @$navcategories[$catid]; isset($upcategory); $upcategory = @$navcategories[$upcategory['parentid']])
$upcategories[$upcategory['catid']] = $upcategory;
return array_reverse($upcategories, true);
}
function bp_cat_path_html($navcategories, $catid)
{
$blog_cats = bp_cat_path($navcategories, $catid);
$html = '';
foreach ($blog_cats as $category)
$html .= (strlen($html) ? ' / ' : '') . qa_html($category['title']);
return $html;
}
function bp_cat_path_request($navcategories, $catid)
{
$blog_cats = bp_cat_path($navcategories, $catid);
$request = '';
foreach ($blog_cats as $category)
$request .= (strlen($request) ? '/' : '') . $category['tags'];
return $request;
}
function bp_permit_options()
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$permits = array('bp_permit_view_p_page', 'bp_permit_post_p', 'bp_permit_post_c', 'bp_permit_vote', 'bp_permit_flag', 'bp_permit_moderate', 'bp_permit_hide_show', 'bp_permit_delete_hidden');
return $permits;
}
function bp_user_maximum_permit_error($permitoption, $limitaction = null, $checkblocks = true)
{
return bp_user_permit_error($permitoption, $limitaction, qa_user_level_maximum(), $checkblocks);
}
function bp_user_permit_error($permitoption = null, $limitaction = null, $userlevel = null, $checkblocks = true, $userfields = null)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
require_once QA_INCLUDE_DIR . 'app/limits.php';
if (!isset($userfields))
$userfields = qa_get_logged_in_user_cache();
$userid = isset($userfields['userid']) ? $userfields['userid'] : null;
if (!isset($userlevel))
$userlevel = isset($userfields['level']) ? $userfields['level'] : null;
$flags = isset($userfields['flags']) ? $userfields['flags'] : null;
if (!$checkblocks)
$flags &= ~QA_USER_FLAGS_USER_BLOCKED;
$error = qa_permit_error($permitoption, $userid, $userlevel, $flags);
if ($checkblocks && !$error && qa_is_ip_blocked())
$error = 'ipblock';
if (!$error && isset($userid) && ($flags & QA_USER_FLAGS_MUST_CONFIRM) && qa_opt('confirm_user_emails'))
$error = 'confirm';
if (isset($limitaction) && !$error) {
if (bp_user_limits_remaining($limitaction) <= 0)
$error = 'limit';
}
return $error;
}
function bp_user_limits_remaining($action)
{
$userlimits = qa_db_get_pending_result('userlimits', qa_db_user_limits_selectspec(qa_get_logged_in_userid()));
$iplimits = qa_db_get_pending_result('iplimits', qa_db_ip_limits_selectspec(qa_remote_ip_address()));
return bp_limits_calc_remaining($action, @$userlimits[$action], @$iplimits[$action]);
}
function bp_limits_calc_remaining($action, $userlimits, $iplimits)
{
switch ($action) {
case QA_LIMIT_BLOG_POSTS:
$usermax = qa_opt('bp_max_rate_user_ps');
$ipmax = qa_opt('bp_max_rate_ip_ps');
break;
case QA_LIMIT_BLOG_COMMENTS:
$usermax = qa_opt('bp_max_rate_user_cs');
$ipmax = qa_opt('bp_max_rate_ip_cs');
break;
default:
qa_fatal_error('Unknown limit code in qa_limits_calc_remaining: ' . $action);
break;
}
$period = (int)(qa_opt('db_time') / 3600);
return max(0, min(
$usermax - (@$userlimits['period'] == $period ? $userlimits['count'] : 0),
$ipmax - (@$iplimits['period'] == $period ? $iplimits['count'] : 0)
));
}
function bp_default_option($name)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$fixed_defaults = array(
'bp_avatar_p_page_c_size' => 20,
'bp_avatar_p_page_p_size' => 50,
'bp_do_write_check_ps' => 0,
'bp_blog_feed' => 1,
'bp_feed_for_articles' => 1,
'bp_match_write_check_ps' => 3,
'bp_match_related_ps' => 3,
'bp_max_len_p_title' => 120,
'bp_min_len_c_content' => 12,
'bp_min_len_p_content' => 0,
'bp_min_len_p_title' => 12,
'bp_permit_close_p' => QA_PERMIT_EDITORS,
'bp_permit_delete_hidden' => QA_PERMIT_MODERATORS,
'bp_permit_edit_c' => QA_PERMIT_EDITORS,
'bp_permit_edit_p' => QA_PERMIT_EDITORS,
'bp_permit_edit_silent' => QA_PERMIT_MODERATORS,
'bp_permit_flag' => QA_PERMIT_CONFIRMED,
'bp_permit_hide_show' => QA_PERMIT_EDITORS,
'bp_permit_moderate' => QA_PERMIT_EXPERTS,
'bp_permit_view_p_page' => QA_PERMIT_ALL,
'bp_points_post_p' => 2,
);
if (isset($fixed_defaults[$name]))
return $fixed_defaults[$name];
switch ($name) {
case 'bp_blog_editor':
require_once QA_INCLUDE_DIR . 'app/format.php';
$value = '-'; // to match none by default, i.e. choose based on who is best at editing HTML
qa_load_editor('', 'html', $value);
break;
case 'bp_permit_post_p': // convert from deprecated option if available
$value = qa_opt('bp_write_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
break;
case 'bp_permit_post_c': // convert from deprecated option if available
$value = qa_opt('bp_comment_needs_login') ? QA_PERMIT_USERS : QA_PERMIT_ALL;
break;
default: // call option_default method in any registered modules
$modules = qa_load_all_modules_with('option_default'); // Loads all modules with the 'option_default' method
foreach ($modules as $module) {
$value = $module->option_default($name);
if (strlen($value))
return $value;
}
$value = '';
break;
}
return $value;
}
function bp_reset_options($names)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
foreach ($names as $name) {
qa_set_option($name, bp_default_option($name));
}
}
function bp_get_options($names)
{
global $qa_options_cache, $qa_options_loaded;
$options = array();
foreach ($names as $name) {
if (!isset($qa_options_cache[$name])) {
$todatabase = true;
switch ($name) {
case 'bp_write_needs_login':
case 'bp_comment_needs_login':
$todatabase = false;
break;
}
qa_set_option($name, bp_default_option($name), $todatabase);
}
$options[$name] = $qa_options_cache[$name];
}
return $options;
}
function bp_cat_navigation($categories, $selectedid = null, $pathprefix = '', $showpcount = true, $pathparams = null)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$parentcategories = array();
foreach ($categories as $category)
$parentcategories[$category['parentid']][] = $category;
$selecteds = bp_cat_path($categories, $selectedid);
//$favoritemap = qa_get_favorite_non_ps_map();
return bp_cat_navigation_sub($parentcategories, null, $selecteds, $pathprefix, $showpcount, $pathparams, null); //$favoritemap);
}
function bp_cat_navigation_sub($parentcategories, $parentid, $selecteds, $pathprefix, $showpcount, $pathparams, $favoritemap = null)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$navigation = array();
if (!isset($parentid)) {
$navigation['all'] = array(
'url' => qa_path_html($pathprefix, $pathparams),
'label' => qa_lang_html('main/all_categories'),
'selected' => !count($selecteds),
'catid' => null,
);
}
if (isset($parentcategories[$parentid])) {
foreach ($parentcategories[$parentid] as $category) {
$navigation[qa_html($category['tags'])] = array(
'url' => qa_path_html($pathprefix . $category['tags'], $pathparams),
'label' => qa_html($category['title']),
'popup' => qa_html(@$category['content']),
'selected' => isset($selecteds[$category['catid']]),
'note' => $showpcount ? ('(' . qa_html(qa_format_number($category['pcount'], 0, true)) . ')') : null,
'subnav' => bp_cat_navigation_sub($parentcategories, $category['catid'], $selecteds,
$pathprefix . $category['tags'] . '/', $showpcount, $pathparams, $favoritemap),
'catid' => $category['catid'],
'favorited' => @$favoritemap['blogcat'][$category['backpath']],
);
}
}
return $navigation;
}
function bp_sub_navigation($request, $blog_cats)
{
$bp_request = 'blog';
$navigation = array();
$navigation['all'] = array(
'label' => qa_lang('bp_lang/nav_all'),
'url' => qa_path_html('blog'),
'selected' => ($request == 'blog') ? 'selected' : '',
);
foreach ($blog_cats as $blogcat) {
$navigation[$blogcat['tags']] = array(
'label' => $blogcat['title'],
'url' => qa_path_html('blog/' . $blogcat['tags']),
'selected' => ($request == 'blog' . $blogcat['tags']) ? 'selected' : '',
);
}
//if (qa_user_maximum_permit_error('bp_permit_post_p') != 'level') {
if (qa_is_logged_in()) {
$navigation['write'] = array(
'label' => qa_lang('bp_lang/nav_post'),
'url' => qa_path_html('blog/write'),
'selected' => ($request == 'blog/write') ? 'selected' : '',
);
}
return $navigation;
}
function bp_html_suggest_ps_tags($usingtags = false, $categoryrequest = null)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$hascategory = strlen($categoryrequest);
$htmlmessage = $hascategory ? qa_lang_html('bp_lang/suggest_category_qs') :
($usingtags ? qa_lang_html('bp_lang/suggest_ps_tags') : qa_lang_html('bp_lang/suggest_ps'));
return strtr(
$htmlmessage,
array(
'^1' => '<a href="' . qa_path_html('blog' . ($hascategory ? ('/' . $categoryrequest) : '')) . '">',
'^2' => '</a>',
'^3' => '<a href="' . qa_path_html('tags') . '">',
'^4' => '</a>',
)
);
}
function bp_html_suggest_write($catid = null)
{
if (qa_to_override(__FUNCTION__)) {
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$htmlmessage = qa_lang_html('bp_lang/suggest_write');
return strtr(
$htmlmessage,
array(
'^1' => '<a href="' . qa_path_html('blog/write', strlen($catid) ? array('blogcat' => $catid) : null) . '">',
'^2' => '</a>',
)
);
}
function bp_post_create($userid, $handle, $cookieid, $title, $content, $permalink, $format, $text, $tagstring, $notify, $email, $catid = null, $extravalue = null, $queued = false, $name = null)
{
require_once QA_INCLUDE_DIR . 'db/selects.php';
$postid = bp_db_post_create($queued ? 'P_QUEUED' : 'P', $userid, isset($userid) ? null : $cookieid,
qa_remote_ip_address(), $title, $content, $permalink, $format, $tagstring, qa_combine_notify_email($userid, $notify, $email), $catid, isset($userid) ? null : $name);
//$blogusers = bp_db_user_find_by_handle($userid);
//if (!count($blogusers)) bp_db_user_create($userid);
//else
//if ($queued) qa_db_bqueuedcount_update();
//else bp_update_counts_for_p($postid);
return $postid;
}
function bp_post_update($oldpost, $userid, $title, $permalink, $content, $format, $text, $tagstring, $notify, $email, $catid = null, $extravalue = null, $queued = false, $name = null)
{
$titlechanged = strcmp($oldpost['title'], $title) !== 0;
$contentchanged = strcmp($oldpost['content'], $content) !== 0 || strcmp($oldpost['format'], $format) !== 0;
$tagschanged = strcmp($oldpost['tags'], $tagstring) !== 0;
$setupdated = ($titlechanged || $contentchanged || $tagschanged);
bp_db_post_update($oldpost['postid'], $title, $permalink, $content, $format, $tagstring, $catid, $notify, $userid, qa_remote_ip_address(), $name);
}
function bp_post_hide($articleid, $userid)
{
bp_db_post_hide($articleid, 'P_HIDDEN', $userid, qa_remote_ip_address());
}
function bp_post_delete($articleid)
{
bp_db_post_delete($articleid);
}
function bp_update_counts_for_p($postid)
{
bp_db_cat_path_pcount_update(bp_db_post_get_cat_path($postid));
bp_db_bpcount_update();
}
/*
Omit PHP closing tag to help avoid accidental output */