forked from b2evolution/b2evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanon_async.php
More file actions
2099 lines (1755 loc) · 67.4 KB
/
anon_async.php
File metadata and controls
2099 lines (1755 loc) · 67.4 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
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This is the handler for ANONYMOUS (non logged in) asynchronous 'AJAX' calls.
*
* This file is part of the evoCore framework - {@link http://evocore.net/}
* See also {@link https://github.com/b2evolution/b2evolution}.
*
* @license GNU GPL v2 - {@link http://b2evolution.net/about/gnu-gpl-license}
*
* @copyright (c)2003-2020 by Francois Planque - {@link http://fplanque.com/}
*
* @package evocore
*/
/**
* Do the MAIN initializations:
*/
require_once dirname(__FILE__).'/../conf/_config.php';
/**
* @global boolean Is this AJAX request? Use {@link is_ajax_request()} to query it, because it may change.
*/
$is_ajax_request = true;
// Disable log in with HTTP basic authentication because we need some action even for anonymous users,
// but it is impossible if wrong login was entered on "HTTP Basic Authentication" form.
// (Used to correct work of action "get_user_salt")
$disable_http_auth = true;
require_once $inc_path.'_main.inc.php';
load_funcs( '../inc/skins/_skin.funcs.php' );
global $skins_path, $ads_current_skin_path, $disp, $ctrl;
param( 'action', 'string', '' );
$item_ID = param( 'p', 'integer' );
$blog_ID = param( 'blog', 'integer' );
// Initialize this array in order to don't load JS files twice in they have been already loaded on parent page:
$required_js = param( 'required_js', 'array:string', array(), false, true );
// Send the predefined cookies:
evo_sendcookies();
// Make sure the async responses are never cached:
header_nocache();
header_content_type( 'text/html', $io_charset );
// Save current debug values
$current_debug = $debug;
$current_debug_jslog = $debug_jslog;
// Do not append Debuglog to response!
$debug = false;
// Do not append Debug JSlog to response!
$debug_jslog = false;
// Don't check new updates from b2evolution.net (@see b2evonet_get_updates()),
// in order to don't break the response data:
$allow_evo_stats = false;
// Init AJAX log
$ajax_Log = new Log();
ajax_log_add( sprintf( 'action: %s', $action ), 'note' );
$params = param( 'params', 'array', array() );
switch( $action )
{
case 'get_item_form':
// Display item form:
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
$cat_ID = param( 'cat', 'integer' );
$BlogCache = & get_BlogCache();
$Collection = $Blog = & $BlogCache->get_by_ID( $blog_ID );
locale_activate( $Blog->get( 'locale' ) );
$blog_skin_ID = $Blog->get_skin_ID();
if( ! empty( $blog_skin_ID ) )
{ // Initialize collection skin folder to check if it has a specific new item form:
$SkinCache = & get_SkinCache();
$Skin = & $SkinCache->get_by_ID( $blog_skin_ID );
$ads_current_skin_path = $skins_path.$Skin->folder.'/';
}
require skin_template_path( '_item_new_form.inc.php' );
break;
case 'get_comment_form':
// Display comment form:
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
$ItemCache = & get_ItemCache();
$Item = $ItemCache->get_by_ID( $item_ID );
$BlogCache = & get_BlogCache();
$Collection = $Blog = $BlogCache->get_by_ID( $blog_ID );
locale_activate( $Blog->get('locale') );
$disp = param( 'disp', '/^[a-z0-9\-_]+$/', '' );
$blog_skin_ID = $Blog->get_skin_ID();
if( ! empty( $blog_skin_ID ) )
{ // check if Blog skin has specific comment form
$SkinCache = & get_SkinCache();
$Skin = & $SkinCache->get_by_ID( $blog_skin_ID );
$ads_current_skin_path = $skins_path.$Skin->folder.'/';
}
require skin_template_path( '_item_comment_form.inc.php' );
break;
case 'get_msg_form':
// display send message form
$recipient_id = param( 'recipient_id', 'integer', 0 );
$recipient_name = param( 'recipient_name', 'string', '' );
$subject = param( 'subject', 'string', '' );
$subject_other = param( 'subject_other', 'string', '' );
$contact_method = param( 'contact_method', 'string', '' );
$email_author = param( 'email_author', 'string', '' );
$email_author_address = param( 'email_author_address', 'string', '' );
$redirect_to = param( 'redirect_to', 'url', '' );
$post_id = NULL;
$comment_id = param( 'comment_id', 'integer', 0 );
$BlogCache = & get_BlogCache();
$Collection = $Blog = $BlogCache->get_by_ID( $blog_ID );
locale_activate( $Blog->get('locale') );
$blog_skin_ID = $Blog->get_skin_ID();
if( ! empty( $blog_skin_ID ) )
{ // check if Blog skin has specific concact message form
$SkinCache = & get_SkinCache();
$Skin = & $SkinCache->get_by_ID( $blog_skin_ID );
$ads_current_skin_path = $skins_path.$Skin->folder.'/';
}
require skin_template_path( '_contact_msg.form.php' );
break;
case 'get_widget_form':
// Display widget form:
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
if( param( 'wi_ID', 'integer', 0 ) )
{ // Try to get a Widget by ID if it called from DB:
$WidgetCache = & get_WidgetCache();
$Widget = & $WidgetCache->get_by_ID( $wi_ID );
if( ! $Widget || ( $Widget->get( 'coll_ID' ) !== NULL && $Widget->get( 'coll_ID' ) != $blog_ID ) )
{
debug_die( 'Wrong widget request!' );
}
}
else
{ // Try to get a Widget by code if it called from content with inline short tag like [emailcapture]:
param( 'wi_code', 'string', true );
if( ! file_exists( $inc_path.'widgets/widgets/_'.$wi_code.'.widget.php' ) )
{ // For some reason, that widget doesn't seem to exist... (any more?)
debug_die( 'Wrong widget request!' );
}
require_once $inc_path.'widgets/widgets/_'.$wi_code.'.widget.php';
// Create new widget by provided code:
$widget_classname = $wi_code.'_Widget';
$Widget = new $widget_classname();
}
param( 'params', 'array', array() );
$BlogCache = & get_BlogCache();
$Collection = $Blog = $BlogCache->get_by_ID( $blog_ID );
locale_activate( $Blog->get('locale') );
$blog_skin_ID = $Blog->get_skin_ID();
if( ! empty( $blog_skin_ID ) )
{ // check if Blog skin has specific comment form
$SkinCache = & get_SkinCache();
$Skin = & $SkinCache->get_by_ID( $blog_skin_ID );
$ads_current_skin_path = $skins_path.$Skin->folder.'/';
}
// Display widget form:
$Widget->display_form( $params );
break;
case 'get_user_bubbletip':
// Get contents of a user bubbletip
// Displays avatar & name
$user_ID = param( 'userid', 'integer', 0 );
$comment_ID = param( 'commentid', 'integer', 0 );
if( strpos( $_SERVER["HTTP_REFERER"], $admin_url ) !== false )
{ // If ajax is requested from admin page we should to set a variable $is_admin_page = true if user has permissions
// Check global permission:
if( ! check_user_perm( 'admin', 'restricted' ) )
{ // No permission to access admin...
require $adminskins_path.'_access_denied.main.php';
}
else
{ // Set this page as admin page
$is_admin_page = true;
}
}
if( $blog_ID > 0 )
{ // Get Blog if ID is set
$BlogCache = & get_BlogCache();
$Collection = $Blog = $BlogCache->get_by_ID( $blog_ID );
}
if( $user_ID > 0 )
{ // Print info of the registered users
$UserCache = & get_UserCache();
$User = & $UserCache->get_by_ID( $user_ID );
ajax_log_add( 'User: #'.$user_ID.' '.$User->login );
if( check_user_perm( 'admin', 'restricted' ) &&
( $current_User->ID == $User->ID || $current_User->can_moderate_user( $User->ID ) ) &&
check_user_status( 'can_access_admin' ) )
{ // Display the moderation buttons only if current user has a permission:
$moderation_buttons = '<p class="bubbletip_user__buttons">';
if( ! is_admin_page() )
{
$moderation_buttons .= '<a href="'.url_add_param( $admin_url, 'ctrl=user&user_ID='.$User->ID ).'" class="btn btn-sm btn-block btn-primary">'
.T_('Edit in Back-Office').'</a>';
}
if( $current_User->ID != $User->ID && check_user_perm( 'users', 'edit' ) )
{ // Display a button to delete a spammer only for other users and if current user can edit them:
$moderation_buttons .= '<a href="'.url_add_param( $admin_url, 'ctrl=users&action=delete&deltype=spammer&user_ID='.$User->ID )
.'" class="btn btn-sm btn-block btn-danger">'
.T_('Delete Spammer')
.'</a>';
}
$moderation_buttons .= '</p>';
}
else
{ // No permission to moderate users:
$moderation_buttons = '';
}
echo '<div class="bubbletip_user">';
if( $User->check_status( 'is_closed' ) )
{ // display only info about closed accounts
echo T_( 'This account has been closed.' );
echo $moderation_buttons;
echo '</div>'; /* end of: <div class="bubbletip_user"> */
break;
}
$avatar_overlay_text = '';
$link_class = '';
if( is_admin_page() )
{ // Set avatar size for Back-office
$avatar_size = $Settings->get('bubbletip_size_admin');
}
else if( is_logged_in() )
{ // Set avatar size for logged in users in the Front-office
$avatar_size = $Settings->get('bubbletip_size_front');
}
else
{ // Set avatar size for Anonymous users
$avatar_size = $Settings->get('bubbletip_size_anonymous');
$avatar_overlay_text = $Settings->get('bubbletip_overlay');
$link_class = 'overlay_link';
}
$width = $thumbnail_sizes[$avatar_size][1];
$height = $thumbnail_sizes[$avatar_size][2];
// Display user avatar with login
// Attributes 'w' & 'h' we use for following js-scale div If image is downloading first time (Fix bubbletip)
echo '<div class="center" w="'.$width.'" h="'.$height.'">';
echo get_avatar_imgtag( $User->login, 'login', true, $avatar_size, 'avatar_above_login', '', $avatar_overlay_text, $link_class, true, '' );
echo '</div>';
if( ! ( $Settings->get( 'allow_anonymous_user_profiles' ) || ( check_user_perm( 'user', 'view', false, $User ) ) ) )
{ // User is not logged in and anonymous users may NOT view user profiles, or if current User has no permission to view additional information about the User
echo $moderation_buttons;
echo '</div>'; /* end of: <div class="bubbletip_user"> */
break;
}
// Additional user info
$user_info = array();
// Preferred Name
if( $User->get_preferred_name() != $User->login )
{
$user_info[] = $User->get_preferred_name();
}
// Location
$location = array();
if( !empty( $User->city_ID ) )
{ // City
$location[] = $User->get_city_name( false );
}
if( !empty( $User->subrg_ID ) )
{ // Subregion
if( !is_logged_in() )
{ // Display subregion for not logged in users
$location[] = $User->get_subregion_name();
}
else if( $current_User->subrg_ID != $User->subrg_ID )
{ // If subregions are different
$location[] = $User->get_subregion_name();
}
}
if( !empty( $User->rgn_ID ) )
{ // Region
if( !is_logged_in() )
{ // Display region for not logged in users
$location[] = $User->get_region_name();
}
else if( $current_User->rgn_ID != $User->rgn_ID )
{ // If regions are different
$location[] = $User->get_region_name();
}
}
if( !empty( $User->ctry_ID ) )
{ // Country
if( !is_logged_in() )
{ // Display country for not logged in users
$location[] = $User->get_country_name();
}
else if( $current_User->ctry_ID != $User->ctry_ID )
{ // If countries are different
$location[] = $User->get_country_name();
}
}
if( !empty( $location ) )
{ // Set location info
$user_info[] = implode( '<br />', $location );
}
// Age group
if( !empty( $User->age_min ) && !empty( $User->age_max ) && $User->age_min != $User->age_max )
{
$user_info[] = sprintf( T_('%d to %d years old '), $User->age_min, $User->age_max );
}
else if( !empty( $User->age_min ) || !empty( $User->age_max ) )
{ // Min age equals max age
$age = !empty( $User->age_min ) ? $User->age_min : $User->age_max;
$user_info[] = sprintf( T_('%d years old '), $age );
}
if( !empty( $user_info ) )
{ // Display additional user info
echo '<ul>';
foreach( $user_info as $info )
{
echo '<li>'.$info.'</li>';
}
echo '</ul>';
}
echo $moderation_buttons;
echo '</div>'; /* end of: <div class="bubbletip_user"> */
}
else if( $comment_ID > 0 )
{ // Print info for an anonymous user who posted a comment
$CommentCache = & get_CommentCache();
$Comment = $CommentCache->get_by_ID( $comment_ID );
ajax_log_add( 'Comment: #'.$comment_ID.' '.$Comment->get_author_name() );
echo '<div class="bubbletip_anon">';
echo $Comment->get_avatar( 'fit-160x160', 'bCommentAvatarCenter' );
echo '<div>'.$Comment->get_author_name_anonymous( 'htmlbody', array( 'rel' => '' ) ).'</div>';
echo '<div>'.T_('This user is not registered on this site.').'</div>';
echo $Comment->get_author_url_link( '', '<div>', '</div>');
if( isset( $Blog ) )
{ // Link to send message
echo '<div>';
$Comment->msgform_link( $Blog->get('msgformurl'), '', '', get_icon( 'email', 'imgtag' ).' '.T_('Send a message') );
echo '</div>';
}
echo '</div>';
}
else
{ // user_ID and comment_ID are both null, this can happen when the user was deleted
echo '<div class="bubbletip_user">';
echo T_( 'This account has been deleted.' );
echo '</div>';
break;
}
break;
case 'set_comment_vote':
// Used for quick SPAM vote of comments
// Check that this action request is not a CSRF hacked request:
$Session->assert_received_crumb( 'comment' );
if( !is_logged_in( false ) )
{ // Only active logged in users can vote
break;
}
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
if( param( 'is_backoffice', 'integer', 0 ) )
{ // Set admin skin, used for buttons, @see button_class()
global $current_User, $UserSettings, $is_admin_page, $adminskins_path;
$admin_skin = $UserSettings->get( 'admin_skin', $current_User->ID );
$is_admin_page = true;
require_once $adminskins_path.$admin_skin.'/_adminUI.class.php';
$AdminUI = new AdminUI();
}
else
{
$BlogCache = &get_BlogCache();
$Collection = $Blog = & $BlogCache->get_by_ID( $blog_ID, true );
$skin_ID = $Blog->get_skin_ID();
$SkinCache = & get_SkinCache();
$Skin = & $SkinCache->get_by_ID( $skin_ID );
}
// Check permission for spam voting
check_user_perm( 'blog_vote_spam_comments', 'edit', true, $blog_ID );
$type = param( 'type', 'string' );
$commentid = param( 'commentid', 'integer' );
if( $type != 'spam' || empty( $commentid ) )
{ // Incorrect params
break;
}
$edited_Comment = & Comment_get_by_ID( $commentid, false );
if( $edited_Comment !== false )
{ // The comment still exists
if( $current_User->ID == $edited_Comment->author_user_ID )
{ // Do not allow users to vote on their own comments
break;
}
// Update a vote of the comment for current User:
$edited_Comment->set_vote( 'spam', param( 'vote', 'string' ) );
$edited_Comment->dbupdate();
// Display a panel for next spam voting:
$edited_Comment->vote_spam( '', '', '&', true, true, array(
'display' => true,
'button_group_class' => button_class( 'group' ).( is_admin_page() ? ' btn-group-sm' : '' ),
) );
}
break;
case 'voting':
// Actions for voting by AJAX
if( !is_logged_in( false ) )
{ // Only active logged in users can vote
break;
}
param( 'vote_action', 'string', '' );
if( !empty( $vote_action ) )
{ // Use crumb checking only for actions
// Check that this action request is not a CSRF hacked request:
$Session->assert_received_crumb( 'voting' );
}
param( 'vote_type', 'string', '' );
param( 'vote_ID', 'string', 0 );
param( 'checked', 'integer', 0 );
param( 'redirect_to', 'url', '' );
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
ajax_log_add( sprintf( 'vote action: %s', $vote_action ), 'note' );
ajax_log_add( sprintf( 'vote type: %s', $vote_type ), 'note' );
ajax_log_add( sprintf( 'vote ID: %s', $vote_ID ), 'note' );
$voting_form_params = array(
'vote_type' => $vote_type,
);
switch( $vote_type )
{
case 'link':
// Vote on pictures
$link_ID = preg_replace( '/link_(\d+)/i', '$1', $vote_ID );
if( empty( $link_ID ) || ( ! is_decimal( $link_ID ) ) )
{ // There is no correct link ID
break 2;
}
$LinkCache = & get_LinkCache();
$Link = & $LinkCache->get_by_ID( $link_ID, false );
if( !$Link )
{ // Incorrect link ID
break 2;
}
$File = & $Link->get_File();
if( !$File )
{ // The Link File is not available
break 2;
}
if( empty( $File->hash ) )
{ // File hash still is not defined, we should create and save it
$File->set_param( 'hash', 'string', md5_file( $File->get_full_path(), true ) );
$File->dbsave();
}
if( !empty( $vote_action ) )
{ // Vote for this file link
link_vote( $link_ID, $current_User->ID, $vote_action, $checked );
}
$voting_form_params['vote_ID'] = $link_ID;
if( empty( $vote_action ) || in_array( $vote_action, array( 'like', 'noopinion', 'dontlike' ) ) )
{ // Display a voting form if no action
// or Refresh a voting form only for these actions (in order to disable icons)
if( ! empty( $blog_ID ) )
{ // If blog is defined we should check if we can display info about number of votes
$BlogCache = & get_BlogCache();
if( ( $Collection = $Blog = & $BlogCache->get_by_ID( $blog_ID, false, false ) ) &&
$blog_skin_ID = $Blog->get_skin_ID() )
{
$LinkOwner = & $Link->get_LinkOwner();
$SkinCache = & get_SkinCache();
if( $Skin = & $SkinCache->get_by_ID( $blog_skin_ID, false, false ) &&
$Skin->get_setting( 'colorbox_vote_'.$LinkOwner->get( 'name' ).'_numbers' ) )
{ // Display number of votes for current link type if it is enabled by blog skin
$voting_form_params['display_numbers'] = true;
}
}
}
display_voting_form( $voting_form_params );
}
break;
case 'comment':
// Vote on comments
$comment_ID = (int)$vote_ID;
if( empty( $comment_ID ) )
{ // No comment ID
break 2;
}
$CommentCache = & get_CommentCache();
$Comment = $CommentCache->get_by_ID( $comment_ID, false );
if( !$Comment )
{ // Incorrect comment ID
break 2;
}
if( $current_User->ID == $Comment->author_user_ID )
{ // Do not allow users to vote on their own comments
break 2;
}
$comment_Item = & $Comment->get_Item();
$comment_Item->load_Blog();
if( ! $comment_Item->Blog->get_setting('allow_rating_comment_helpfulness') )
{ // If Users cannot vote
break 2;
}
if( !empty( $vote_action ) )
{ // Vote for this comment
switch( $vote_action )
{ // Set field value
case 'like':
$field_value = 'yes';
break;
case 'noopinion':
$field_value = 'noopinion';
break;
case 'dontlike':
$field_value = 'no';
break;
}
if( isset( $field_value ) )
{ // Update a vote of current user
$Comment->set_vote( 'helpful', $field_value );
$Comment->dbupdate();
}
}
if( !empty( $redirect_to ) )
{ // Redirect to back page, It is used by browsers without JavaScript
header_redirect( $redirect_to, 303 ); // Will EXIT
// We have EXITed already at this point!!
}
if( param( 'skin_ID', 'integer', 0 ) > 0 )
{ // If request is from skin:
$SkinCache = & get_SkinCache();
// Initialize global Collection in order to get Skin settings values from the Collection and not from defaults of the Skin:
$Blog = $comment_Item->get_Blog();
$request_Skin = & $SkinCache->get_by_ID( get_param( 'skin_ID' ), false, false );
if( $request_Skin && method_exists( $request_Skin, 'display_comment_voting_panel' ) )
{ // Request skin to display a voting panel for item:
$request_Skin->display_comment_voting_panel( $Comment, $request_Skin->get_setting( 'voting_place' ), array( 'display_wrapper' => false ) );
break 2;
}
}
$Comment->vote_helpful( '', '', '&', true, true, array( 'display_wrapper' => false ) );
break;
case 'item':
// Vote on items:
$item_ID = intval( $vote_ID );
if( empty( $item_ID ) )
{ // No item ID
break 2;
}
$ItemCache = & get_ItemCache();
$Item = $ItemCache->get_by_ID( $item_ID, false );
if( ! $Item )
{ // Incorrect item ID:
break 2;
}
if( $current_User->ID == $Item->creator_user_ID )
{ // Do not allow users to vote on their own comments:
break 2;
}
$item_Blog = & $Item->get_Blog();
if( empty( $item_Blog ) || ! $item_Blog->get_setting( 'voting_positive' ) )
{ // If Users cannot vote:
break 2;
}
if( ! empty( $vote_action ) )
{ // Vote for the item:
switch( $vote_action )
{ // Set field value
case 'like':
$field_value = 'positive';
break;
case 'noopinion':
$field_value = 'neutral';
break;
case 'dontlike':
$field_value = 'negative';
break;
}
if( isset( $field_value ) )
{ // Update a vote of current user
$Item->set_vote( $field_value );
$Item->dbupdate();
// Invalidate key for the voted Item:
BlockCache::invalidate_key( 'item_ID', $Item->ID );
}
}
if( ! empty( $redirect_to ) )
{ // Redirect to back page, It is used by browsers without JavaScript:
header_redirect( $redirect_to, 303 ); // Will EXIT
// We have EXITed already at this point!!
}
if( param( 'widget_ID', 'integer', 0 ) > 0 )
{ // If request is from widget:
$WidgetCache = & get_WidgetCache();
$item_Widget = & $WidgetCache->get_by_ID( get_param( 'widget_ID' ), false, false );
if( $item_Widget && $item_Widget->code == 'item_vote' )
{ // Request widget to display a voting panel for item:
$item_Widget->display_voting_panel( $Item, array( 'display_wrapper' => false ) );
break 2;
}
}
elseif( param( 'skin_ID', 'integer', 0 ) > 0 )
{ // If request is from skin:
$SkinCache = & get_SkinCache();
// Initialize global Collection in order to get Skin settings values from the Collection and not from defaults of the Skin:
$Blog = $item_Blog;
$request_Skin = & $SkinCache->get_by_ID( get_param( 'skin_ID' ), false, false );
if( $request_Skin && method_exists( $request_Skin, 'display_item_voting_panel' ) )
{ // Request skin to display a voting panel for item:
$request_Skin->display_item_voting_panel( $Item, $request_Skin->get_setting( 'voting_place' ), array( 'display_wrapper' => false ) );
break 2;
}
}
// Display a voting panel for item:
$Item->display_voting_panel( array( 'display_wrapper' => false ) );
break;
}
break;
case 'get_user_new_field':
// Used in the identity user form to add a new field
$field_ID = param( 'field_id', 'integer', 0 );
$user_ID = param( 'user_id', 'integer', 0 );
if( $field_ID == 0 )
{ // Bad request
break;
}
$userfields = $DB->get_results( '
SELECT T_users__fielddefs.*, "0" AS uf_ID, "" AS uf_varchar, ufgp_ID, ufgp_name
FROM T_users__fielddefs
LEFT JOIN T_users__fieldgroups ON ufgp_ID = ufdf_ufgp_ID
WHERE ufdf_ID = "'.$field_ID.'"' );
if( $userfields[0]->ufdf_duplicated == 'forbidden' )
{ // This field can be only one instance for one user
echo '[0]'; // not duplicated field
$user_field_exist = $DB->get_var( '
SELECT uf_ID
FROM T_users__fields
WHERE uf_user_ID = "'.$user_ID.'" AND uf_ufdf_ID = "'.$field_ID.'"' );
if( $user_field_exist > 0 )
{ // User already has a current field type
break;
}
}
else
{ // It Means: this field can be duplicated
echo '[1]';
}
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
$Form = new Form();
$Form->fieldstart = '#fieldstart#';
$Form->fieldend = '#fieldend#';
$Form->labelclass = '#labelclass#';
$Form->labelstart = '#labelstart#';
$Form->labelend = '#labelend#';
$Form->inputstart = '#inputstart#';
$Form->inputend = '#inputend#';
userfields_display( $userfields, $Form, 'add', false, $user_ID );
break;
case 'get_user_field_autocomplete':
// Used for autocompletion of the user field
/**
* Possible values of var $attr_id
* 1) 111 - this goes from filter search, it is ufdf_ID
* 2) uf_new_222_ - field from identity form ( doesn't still exist in DB (recommened & required fields) )
* 3) uf_add_222_ - field from identity form ( user want add this field )
* where 222 == ufdf_ID
* 4) uf_333 - field exists in DB (where 333 == uf_ID from table T_users__fields)
*/
$attr_id = param( 'attr_id', 'string' );
$term = param( 'term', 'string' );
$field_type_id = 0;
if( (int)$attr_id > 0 )
{ // From filter 'Specific criteria'
$field_type_id = (int)$attr_id;
}
else if( preg_match( '/^uf_(new|add)_(\d+)_/i', $attr_id, $match ) )
{ // From new fields we can get the value for uf_ufdf_ID
$field_type_id = (int)$match[2];
}
else if( preg_match( '/^uf_(\d+)$/i', $attr_id, $match ) )
{ // From fields in DB we can get only uf_ID, then we should get a value uf_ufdf_ID from DB
$field_id = (int)$match[1];
$field_type_id = $DB->get_var( '
SELECT uf_ufdf_ID
FROM T_users__fields
WHERE uf_ID = "'.$field_id.'"' );
}
if( $field_type_id == 0 )
{ // Bad request
break;
}
echo evo_json_encode( $DB->get_col( '
SELECT DISTINCT ( uf_varchar )
FROM T_users__fields
WHERE uf_varchar LIKE '.$DB->quote('%'.$term.'%').'
AND uf_ufdf_ID = "'.$field_type_id.'"
ORDER BY uf_varchar' ) );
exit(0); // Exit here in order to don't display the AJAX debug info after JSON formatted data
break;
case 'get_regions_option_list':
// Get option list with regions by selected country
$country_ID = param( 'ctry_id', 'integer', 0 );
$region_ID = param( 'rgn_id', 'integer', 0 );
$page = param( 'page', 'string', '' );
$mode = param( 'mode', 'string', '' );
$params = array();
if( $page == 'edit' )
{
$params['none_option_text'] = T_( 'Unknown' );
}
load_funcs( 'regional/model/_regional.funcs.php' );
echo get_regions_option_list( $country_ID, 0, $params );
if( $mode == 'load_subregions' || $mode == 'load_all' )
{ // Load also the subregions
echo '-##-'.get_subregions_option_list( $region_ID, 0, $params );
}
if( $mode == 'load_all' )
{ // Load also the cities
echo '-##-'.get_cities_option_list( $country_ID, $region_ID, 0, 0, $params );
}
break;
case 'get_subregions_option_list':
// Get option list with sub-regions by selected region
$country_ID = param( 'ctry_id', 'integer', 0 );
$region_ID = param( 'rgn_id', 'integer', 0 );
$page = param( 'page', 'string', '' );
$mode = param( 'mode', 'string', '' );
$params = array();
if( $page == 'edit' )
{
$params['none_option_text'] = T_( 'Unknown' );
}
load_funcs( 'regional/model/_regional.funcs.php' );
echo get_subregions_option_list( $region_ID, 0, $params );
if( $mode == 'load_all' )
{ // Load also the cities
echo '-##-'.get_cities_option_list( $country_ID, $region_ID, 0, 0, $params );
}
break;
case 'get_cities_option_list':
// Get option list with cities by selected country, region or sub-region
$country_ID = param( 'ctry_id', 'integer', 0 );
$region_ID = param( 'rgn_id', 'integer', 0 );
$subregion_ID = param( 'subrg_id', 'integer', 0 );
$page = param( 'page', 'string', '' );
$params = array();
if( $page == 'edit' )
{
$params['none_option_text'] = T_( 'Unknown' );
}
load_funcs( 'regional/model/_regional.funcs.php' );
echo get_cities_option_list( $country_ID, $region_ID, $subregion_ID, 0, $params );
break;
case 'get_field_bubbletip':
// Get info for user field
$field_ID = param( 'field_ID', 'integer', 0 );
if( $field_ID > 0 )
{ // Get field info from DB
$field = $DB->get_row( '
SELECT ufdf_bubbletip, ufdf_duplicated
FROM T_users__fielddefs
WHERE ufdf_ID = '.$DB->quote( $field_ID ) );
if( is_null( $field ) )
{ // No field in DB
break;
}
if( !empty( $field->ufdf_bubbletip ) )
{ // Field has a defined bubbletip text
$field_info = nl2br( $field->ufdf_bubbletip );
}
else if( in_array( $field->ufdf_duplicated, array( 'allowed', 'list' ) ) )
{ // Default info for fields with multiple values
$field_info = T_('To enter multiple values,<br />please click on (+)');
}
}
if( !empty( $field_info ) )
{ // Replace mask text (+) with img tag
// Use the glyph or font-awesome icons if requested by skin
param( 'b2evo_icons_type', 'string', '' );
echo str_replace( '(+)', get_icon( 'add' ), $field_info );
}
break;
case 'validate_login':
// Validate if username is available
param( 'login', 'string', '' );
if( param_check_valid_login( 'login' ) )
{ // Login format is correct
if( !empty( $login ) )
{
$SQL = new SQL( 'Validate if username is available' );
$SQL->SELECT( 'user_ID' );
$SQL->FROM( 'T_users' );
$SQL->WHERE( 'user_login = "'.$DB->escape( $login ).'"' );
if( $DB->get_var( $SQL ) )
{ // Login already exists
echo 'exists';
}
else
{ // Login is available
echo 'available';
}
}
}
else
{ // Incorrect format of login
echo param_get_error_msg( 'login' );
}
break;
case 'results':
// Refresh a results table (To change page, page size, an order)
/**
* Variable to define a current request as ajax content
* It is used to don't display a wrapper data such as header, footer and etc.
* @see is_ajax_content()
*
* @var boolean
*/
$ajax_content_mode = true;
// get callback function param, this function will display the results content
$callback_function = param( 'callback_function', 'string', '' );
if( param( 'is_backoffice', 'integer', 0 ) )
{
global $current_User, $UserSettings, $is_admin_page;
$admin_skin = $UserSettings->get( 'admin_skin', $current_User->ID );
$params = array( 'skin_type' => 'admin', 'skin_name' => $admin_skin );
$is_admin_page = true;
/**
* Load the AdminUI class for the skin.
*/
require_once $adminskins_path.$admin_skin.'/_adminUI.class.php';
$AdminUI = new AdminUI();
// Get the requested params and memorize it to make correct links for paging, ordering and etc.
param( 'ctrl', '/^[a-z0-9_]+$/', $default_ctrl, true );
param( 'blog', 'integer', NULL, true );
$ReqPath = $admin_url;
}
else
{
$BlogCache = &get_BlogCache();
$Collection = $Blog = & $BlogCache->get_by_ID( $blog_ID, true );
$skin_ID = $Blog->get_skin_ID();
$SkinCache = & get_SkinCache();
$Skin = & $SkinCache->get_by_ID( $skin_ID );
$params = array( 'skin_type' => 'front', 'skin_name' => $Skin->folder );
}
// load required resource for each callback function
switch( $callback_function )
{
case 'hits_results_block':
load_funcs('sessions/model/_hitlog.funcs.php');
break;
case 'items_created_results_block':
case 'items_edited_results_block':