-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.php
409 lines (364 loc) · 14.8 KB
/
page.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
<?php
/**
* page
*
* @package Delus
* @author Dmitry
*/
// fetch bootloader
require('bootloader.php');
// user access
if (!$system['system_public']) {
user_access();
}
// check username
if (is_empty($_GET['username']) || !valid_username($_GET['username'])) {
_error(404);
}
try {
// [1] get main page info
$get_page = $db->query(sprintf("SELECT pages.*, picture_photo.source as page_picture_full, cover_photo.source as page_cover_full, pages_categories.category_name as page_category_name FROM pages LEFT JOIN posts_photos as picture_photo ON pages.page_picture_id = picture_photo.photo_id LEFT JOIN posts_photos as cover_photo ON pages.page_cover_id = cover_photo.photo_id LEFT JOIN pages_categories ON pages.page_category = pages_categories.category_id WHERE pages.page_name = %s", secure($_GET['username'])));
if ($get_page->num_rows == 0) {
_error(404);
}
$spage = $get_page->fetch_assoc();
/* check username case */
if (strtolower($_GET['username']) == strtolower($spage['page_name']) && $_GET['username'] != $spage['page_name']) {
redirect('/pages/' . $spage['page_name']);
}
/* get page picture */
$spage['page_picture_default'] = ($spage['page_picture']) ? false : true;
$spage['page_picture'] = get_picture($spage['page_picture'], 'page');
$spage['page_picture_full'] = ($spage['page_picture_full']) ? $system['system_uploads'] . '/' . $spage['page_picture_full'] : $spage['page_picture_full'];
/* get page cover */
$spage['page_cover'] = ($spage['page_cover']) ? $system['system_uploads'] . '/' . $spage['page_cover'] : $spage['page_cover'];
$spage['page_cover_full'] = ($spage['page_cover_full']) ? $system['system_uploads'] . '/' . $spage['page_cover_full'] : $spage['page_cover_full'];
/* check page category */
$spage['page_category_name'] = (!$spage['page_category_name']) ? __('N/A') : $spage['page_category_name']; /* in case deleted by admin */
/* get the connection */
$spage['i_admin'] = $user->check_page_adminship($user->_data['user_id'], $spage['page_id']);
$spage['i_like'] = $user->check_page_membership($user->_data['user_id'], $spage['page_id']);
/* get page posts count */
$spage['posts_count'] = $user->get_posts_count($spage['page_id'], 'page');
/* get page photos count */
$spage['photos_count'] = $user->get_photos_count($spage['page_id'], 'page');
/* get page videos count */
if ($system['videos_enabled']) {
$spage['videos_count'] = $user->get_videos_count($spage['page_id'], 'page');
}
/* get page reviews count */
if ($system['pages_reviews_enabled']) {
$spage['reviews_count'] = $user->get_reviews_count($spage['page_id']);
}
/* get page events */
if ($system['events_enabled'] && $system['pages_events_enabled']) {
$spage['events'] = $user->get_events(['page_id' => $spage['page_id'], 'results' => $system['min_results']]);
}
/* check if can sell products */
$spage['can_sell_products'] = $system['market_enabled'] && $user->check_user_permission($spage['page_admin'], 'market_permission');
/* check if can receivce tips */
$spage['can_receive_tips'] = $system['tips_enabled'] && $user->check_user_permission($spage['page_admin'], 'tips_permission');
/* check if page's admin can monetize content */
$spage['can_monetize_content'] = $system['monetization_enabled'] && $user->check_user_permission($spage['page_admin'], 'monetization_permission');
/* check if page has monetization enabled && subscriptions plans */
$spage['has_subscriptions_plans'] = $spage['can_monetize_content'] && $spage['page_monetization_enabled'] && $spage['page_monetization_plans'] > 0;
/* check if the page needs subscription (exclude: admins & mods & page's admin) */
$spage['needs_subscription'] = false;
if ($spage['has_subscriptions_plans']) {
if ($user->_logged_in) {
if ($user->_data['user_group'] == 3 && !$spage['i_admin']) {
if (!$user->is_subscribed($spage['page_id'], 'page')) {
$spage['needs_subscription'] = true;
}
}
} else {
$spage['needs_subscription'] = true;
}
}
// [2] get view content
switch ($_GET['view']) {
case '':
/* get custom fields */
$smarty->assign('custom_fields', $user->get_custom_fields(["for" => "page", "get" => "profile", "node_id" => $spage['page_id']]));
/* get photos */
if (!$spage['needs_subscription']) {
$spage['photos'] = $user->get_photos($spage['page_id'], 'page');
}
/* get subscribers */
if ($spage['has_subscriptions_plans']) {
/* get subscribers count */
$spage['subscribers_count'] = $user->get_subscribers_count($spage['page_id'], 'page');
/* get subscribers */
if ($spage['subscribers_count'] > 0) {
$spage['subscribers'] = $user->get_subscribers($spage['page_id'], 'page');
}
}
/* get invites */
$spage['invites'] = $user->get_page_invites($spage['page_id']);
/* get pinned post */
$pinned_post = $user->get_post($spage['page_pinned_post'], true, false, true);
$smarty->assign('pinned_post', $pinned_post);
/* prepare publisher */
$smarty->assign('feelings', get_feelings());
$smarty->assign('feelings_types', get_feelings_types());
if ($system['colored_posts_enabled']) {
$smarty->assign('colored_patterns', $user->get_posts_colored_patterns());
}
if ($user->_data['can_upload_videos']) {
$smarty->assign('videos_categories', $user->get_categories("posts_videos_categories"));
}
/* check if there is share URL */
if ($_GET['url']) {
$smarty->assign('url', $_GET['url']);
}
/* get posts */
$posts = $user->get_posts(['get' => 'posts_page', 'id' => $spage['page_id']]);
/* assign variables */
$smarty->assign('posts', $posts);
/* get ads */
$smarty->assign('ads', $user->ads('pages', $spage['page_id']));
break;
case 'photos':
/* get content */
if (!$spage['needs_subscription']) {
/* get photos */
$spage['photos'] = $user->get_photos($spage['page_id'], 'page');
}
break;
case 'albums':
/* get content */
if (!$spage['needs_subscription']) {
/* get albums */
$spage['albums'] = $user->get_albums($spage['page_id'], 'page');
}
break;
case 'album':
/* get content */
if (!$spage['needs_subscription']) {
/* get album */
$album = $user->get_album($_GET['id']);
if (!$album || $album['in_group'] || $album['user_type'] == "user" || ($album['user_type'] == "page" && $album['page_id'] != $spage['page_id'])) {
_error(404);
}
/* assign variables */
$smarty->assign('album', $album);
}
break;
case 'videos':
/* check if videos enabled */
if (!$system['videos_enabled']) {
_error(404);
}
/* get content */
if (!$spage['needs_subscription']) {
/* get videos */
$spage['videos'] = $user->get_videos($spage['page_id'], 'page');
}
break;
case 'reels':
/* check if reels enabled */
if (!$system['reels_enabled']) {
_error(404);
}
/* get content */
if (!$spage['needs_subscription']) {
/* get reels */
$spage['reels'] = $user->get_reels($spage['page_id'], 'page');
}
break;
case 'products':
/* get content */
if (!$spage['needs_subscription']) {
/* get posts (products) */
$posts = $user->get_posts(['get' => 'posts_page', 'id' => $spage['page_id'], 'filter' => 'product']);
/* assign variables */
$smarty->assign('posts', $posts);
}
break;
case 'reviews':
/* check if reviews enabled */
if (!$system['pages_reviews_enabled']) {
_error(404);
}
/* get reviews */
if ($spage['reviews_count'] > 0) {
$spage['reviews'] = $user->get_reviews($spage['page_id']);
}
break;
case 'events':
/* check if pages events enabled */
if (!$system['events_enabled'] && $system['pages_events_enabled']) {
_error(404);
}
/* get content */
$spage['events'] = $user->get_events(['page_id' => $spage['page_id'], 'results' => $system['max_results_even']]);
break;
case 'activities':
/* check if pages activities enabled */
if (!$system['pages_activities_enabled'] && !$spage['page_activities_enabled']) {
_error(404);
}
/* get user activities permission */
$spage['activities_permission'] = false;
if ($spage['i_admin']) {
$spage['activities_permission'] = 'editor';
} else {
$spage['activities_permission'] = $user->get_page_activities_user_permission($spage['page_id']);
}
/* get content */
if ($spage['activities_permission']) {
$spage['activities'] = $user->get_page_activities($spage['page_id']);
} else {
/* check viewer request status */
$case = "request";
$get_last_request = $db->query(sprintf("SELECT * FROM activities_permisions_requests WHERE user_id = %s AND page_id = %s ORDER BY request_id DESC LIMIT 1", secure($user->_data['user_id'], 'int'), secure($spage['page_id'], 'int')));
if ($get_last_request->num_rows > 0) {
$last_request = $get_last_request->fetch_assoc();
if ($last_request['status'] == '1') {
$case = "request";
/* delete all requests */
$db->query(sprintf("DELETE FROM activities_permisions_requests WHERE user_id = %s AND page_id = %s", secure($user->_data['user_id'], 'int'), secure($spage['page_id'], 'int')));
} elseif ($last_request['status'] == '0') {
$case = "pending";
} else {
$case = "declined";
}
}
/* assign variables */
$smarty->assign('case', $case);
}
break;
case 'subscribers':
/* check if has subscriptions plans */
if (!$spage['has_subscriptions_plans']) {
_error(404);
}
/* get subscribers count */
$spage['subscribers_count'] = $user->get_subscribers_count($spage['page_id'], 'page');
/* get subscribers */
if ($spage['subscribers_count'] > 0) {
$spage['subscribers'] = $user->get_subscribers($spage['page_id'], 'page');
}
break;
case 'invites':
/* check if the viewer is a page member */
if (!$spage['i_like']) {
_error(404);
}
/* get invites */
$spage['invites'] = $user->get_page_invites($spage['page_id']);
break;
case 'search':
/* get search */
if (isset($_GET['query'])) {
$filter = (isset($_GET['filter'])) ? $_GET['filter'] : 'all';
$posts = $user->get_posts(['get' => 'posts_page', 'id' => $spage['page_id'], 'query' => $_GET['query'], 'filter' => $filter]);
/* assign variables */
$smarty->assign('query', htmlentities($_GET['query'], ENT_QUOTES, 'utf-8'));
$smarty->assign('filter', $filter);
$smarty->assign('posts', $posts);
}
break;
case 'settings':
/* check if the viewer is the admin */
if (!$spage['i_admin']) {
_error(404);
}
/* get sub_view content */
$sub_view = $_GET['id'];
switch ($sub_view) {
case '':
/* get pages categories */
$smarty->assign('categories', $user->get_categories("pages_categories"));
break;
case 'info':
/* get countries if not defined */
if (!$countries) {
$smarty->assign('countries', $user->get_countries());
}
/* get custom fields */
$smarty->assign('custom_fields', $user->get_custom_fields(["for" => "page", "get" => "settings", "node_id" => $spage['page_id']]));
break;
case 'admins':
/* get admins */
$spage['page_admins_count'] = count($user->get_page_admins_ids($spage['page_id']));
$spage['page_admins'] = $user->get_page_admins($spage['page_id']);
/* get members */
if ($spage['page_likes'] > 0) {
$spage['members'] = $user->get_page_members($spage['page_id']);
}
break;
case 'activities':
/* get activities users */
$spage['page_activities_users'] = $user->get_page_activities_users($spage['page_id']);
$spage['page_activities_permission_requests'] = $user->get_page_activities_permisions_requests($spage['page_id']);
break;
case 'monetization':
/* check monetization permission (only page's super admin can do this) */
if (!$user->_data['can_monetize_content']) {
_error(404);
}
/* get monetozaion plans */
$smarty->assign('monetization_plans', $user->get_monetization_plans($spage['page_id'], 'page'));
/* get subscribers count */
$smarty->assign('subscribers_count', $user->get_subscribers_count($spage['page_id'], 'page'));
break;
case 'verification':
if (!$system['verification_requests']) {
_error(404);
}
/* verification */
if ($spage['page_verified']) {
$case = "verified";
$user->delete_all_verification_requests($spage['page_id'], 'page');
} else {
/* check last verification request */
$get_last_request = $db->query(sprintf("SELECT * FROM verification_requests WHERE node_id = %s AND node_type = 'page' ORDER BY request_id DESC LIMIT 1", secure($spage['page_id'], 'int')));
if ($get_last_request->num_rows > 0) {
$last_request = $get_last_request->fetch_assoc();
if ($last_request['status'] == '1') {
$case = "request";
$user->delete_all_verification_requests($spage['page_id'], 'page');
} elseif ($last_request['status'] == '0') {
$case = "pending";
} else {
$case = "declined";
}
} else {
$case = "request";
}
}
/* assign variables */
$smarty->assign('case', $case);
break;
case 'delete':
/* check if the viewer not the super admin */
if ($user->_data['user_id'] != $spage['page_admin']) {
_error(404);
}
break;
default:
_error(404);
break;
}
/* assign variables */
$smarty->assign('sub_view', $sub_view);
break;
default:
_error(404);
break;
}
// recent rearches
if (isset($_GET['ref']) && $_GET['ref'] == "qs") {
$user->set_search_log($spage['page_id'], 'page');
}
} catch (Exception $e) {
_error(__("Error"), $e->getMessage());
}
// page header
page_header($spage['page_title'], $spage['page_description'], $spage['page_picture']);
// assign variables
$smarty->assign('spage', $spage);
$smarty->assign('view', $_GET['view']);
// page footer
page_footer('page');