forked from civicrm/civicrm-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
civicrm.php
990 lines (852 loc) · 29.5 KB
/
civicrm.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
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
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.3 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2013
*
*/
/*
Plugin Name: CiviCRM
Plugin URI: http://civicrm.org/
Description: CiviCRM WP Plugin
Author: CiviCRM LLC
Version: 4.3
Author URI: http://civicrm.org/
License: AGPL3
*/
define('CIVICRM_UF_HEAD', TRUE);
// there is no session handling in WP hence we start it for CiviCRM pages
if (!session_id()) {
session_start();
}
//this is require for ajax calls in civicrm
if (civicrm_wp_in_civicrm()) {
$_GET['noheader'] = TRUE;
}
else {
$_GET['civicrm_install_type'] = 'wordpress';
}
/**
* Method that runs only when civicrm plugin is activated.
*/
register_activation_hook( __FILE__, 'civicrm_activate');
function civicrm_activate() {
// Assign minimum capabilities for all wordpress roles and create anonymous_user' role
civicrm_wp_set_capabilities();
}
/*
* Function to create anonymous_user' role, if 'anonymous_user' role is not in the wordpress installation
* and assign minimum capabilities for all wordpress roles
*/
function civicrm_wp_set_capabilities() {
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
//Minimum capabilities (Civicrm permissions) arrays
$min_capabilities = array(
'access_civimail_subscribe_unsubscribe_pages' => 1,
'access_all_custom_data' => 1,
'access_uploaded_files' => 1,
'make_online_contributions' => 1,
'profile_create' => 1,
'profile_edit' => 1,
'profile_view' => 1,
'register_for_events' => 1,
'view_event_info' => 1,
'sign_civicrm_petition' => 1,
'view_public_civimail_content' => 1,
);
// Assign the Minimum capabilities (Civicrm permissions) to all WP roles
foreach ( $wp_roles->role_names as $role => $name ) {
$roleObj = $wp_roles->get_role($role);
foreach ($min_capabilities as $capability_name => $capability_value) {
$roleObj->add_cap($capability_name);
}
}
//Add the 'anonymous_user' role with minimum capabilities.
if (!in_array('anonymous_user' , $wp_roles->roles)) {
add_role(
'anonymous_user',
'Anonymous User',
$min_capabilities
);
}
}
function civicrm_wp_add_menu_items() {
$settingsFile =
WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'civicrm.settings.php';
if (file_exists($settingsFile)) {
$civilogo =
plugins_url() . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'i' . DIRECTORY_SEPARATOR .
'logo16px.png';
add_menu_page('CiviCRM', 'CiviCRM', 'access_civicrm', 'CiviCRM', 'civicrm_wp_invoke', $civilogo);
}
else {
add_options_page('CiviCRM Installer', 'CiviCRM Installer', 'manage_options', 'civicrm-install', 'civicrm_run_installer');
}
}
function civicrm_run_installer() {
$installFile =
WP_PLUGIN_DIR . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'civicrm' . DIRECTORY_SEPARATOR .
'install' . DIRECTORY_SEPARATOR .
'index.php';
include ($installFile);
}
function civicrm_setup_warning() {
$installLink = admin_url() . "options-general.php?page=civicrm-install";
echo '<div id="civicrm-warning" class="updated fade"><p><strong>' . t('CiviCRM is almost ready.') . '</strong> ' . t('You must <a href="!1">configure CiviCRM</a> for it to work.', array(
'!1' => $installLink)) . '</p></div>';
}
function civicrm_remove_wp_magic_quotes() {
$_GET = stripslashes_deep($_GET);
$_POST = stripslashes_deep($_POST);
$_COOKIE = stripslashes_deep($_COOKIE);
$_REQUEST = stripslashes_deep($_REQUEST);
}
/**
* This was the original name of the initialization function and is
* retained for backward compatibility
*/
function civicrm_wp_initialize() {
return civicrm_initialize();
}
/**
* Initialize CiviCRM. Call this function from other modules too if
* they use the CiviCRM API.
*/
function civicrm_initialize() {
static $initialized = FALSE;
static $failure = FALSE;
if ($failure) {
return FALSE;
}
if (!$initialized) {
// Check for php version and ensure its greater than minPhpVersion
$minPhpVersion = '5.3.3';
if (version_compare(PHP_VERSION, $minPhpVersion) < 0) {
echo "CiviCRM requires PHP Version $minPhpVersion or greater. You are running PHP Version " . PHP_VERSION . "<p>";
exit();
}
$settingsFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php';
if (!file_exists($settingsFile)) {
$error = FALSE;
}
else {
define('CIVICRM_SETTINGS_PATH', $settingsFile);
$error = include_once ($settingsFile);
}
// autoload
require_once 'CRM/Core/ClassLoader.php';
CRM_Core_ClassLoader::singleton()->register();
// get ready for problems
$installLink = admin_url() . "options-general.php?page=civicrm-install";
$docLinkInstall = "http://wiki.civicrm.org/confluence/display/CRMDOC/WordPress+Installation+Guide";
$docLinkTrouble = "http://wiki.civicrm.org/confluence/display/CRMDOC/Installation+and+Configuration+Trouble-shooting";
$forumLink = "http://forum.civicrm.org/index.php/board,6.0.html";
$errorMsgAdd = t("Please review the <a href='!1'>WordPress Installation Guide</a> and the <a href='!2'>Trouble-shooting page</a> for assistance. If you still need help installing, you can often find solutions to your issue by searching for the error message in the <a href='!3'>installation support section of the community forum</a>.</strong></p>",
array('!1' => $docLinkInstall, '!2' => $docLinkTrouble, '!3' => $forumLink)
);
$installMessage = t("Click <a href='!1'>here</a> for fresh install.", array('!1' => $installLink));
if ($error == FALSE) {
header('Location: ' . admin_url() . 'options-general.php?page=civicrm-install');
return FALSE;
}
// this does pretty much all of the civicrm initialization
if (!file_exists($civicrm_root . 'CRM/Core/Config.php')) {
$error = FALSE;
}
else {
$error = include_once ('CRM/Core/Config.php');
}
if ($error == FALSE) {
$failure = TRUE;
//FIX ME
wp_die("<strong><p class='error'>" .
t("Oops! - The path for including CiviCRM code files is not set properly. Most likely there is an error in the <em>civicrm_root</em> setting in your CiviCRM settings file (!1).",
array('!1' => $settingsFile)
) .
"</p><p class='error'> » " .
t("civicrm_root is currently set to: <em>!1</em>.", array(
'!1' => $civicrm_root)) .
"</p><p class='error'>" . $errorMsgAdd . "</p></strong>"
);
return FALSE;
}
$initialized = TRUE;
// initialize the system by creating a config object
$config = CRM_Core_Config::singleton();
// sync the logged in user with WP
global $current_user;
if ($current_user) {
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::synchronize(
$current_user,
FALSE,
'WordPress',
civicrm_get_ctype('Individual')
);
}
}
return TRUE;
}
/**
* Function to get the contact type
*
* @param string $default contact type
*
* @return $ctype contact type
*/
function civicrm_get_ctype($default = NULL) {
// here we are creating a new contact
// get the contact type from the POST variables if any
if (isset($_REQUEST['ctype'])) {
$ctype = $_REQUEST['ctype'];
}
elseif (isset($_REQUEST['edit']) &&
isset($_REQUEST['edit']['ctype'])
) {
$ctype = $_REQUEST['edit']['ctype'];
}
else {
$ctype = $default;
}
if ($ctype != 'Individual' &&
$ctype != 'Organization' &&
$ctype != 'Household'
) {
$ctype = $default;
}
return $ctype;
}
function civicrm_wp_invoke() {
static $alreadyInvoked = FALSE;
if ($alreadyInvoked) {
return;
}
$alreadyInvoked = TRUE;
if (!civicrm_initialize()) {
return '';
}
// CRM-12523 - WordPress has it's own timezone calculations
$WP_base_timezone = date_default_timezone_get();
$WP_user_timezone = get_option('timezone_string');
if ($WP_user_timezone) {
date_default_timezone_set($WP_user_timezone);
}
// Add our standard css & js
CRM_Core_Resources::singleton()->addCoreResources();
// CRM-95XX
// At this point we are calling a civicrm function
// Since WP messes up and always quotes the request, we need to reverse
// what it just did
civicrm_remove_wp_magic_quotes();
if (isset($_GET['q'])) {
$args = explode('/', trim($_GET['q']));
}
else {
$_GET['q'] = 'civicrm/dashboard';
$_GET['reset'] = 1;
$args = array('civicrm', 'dashboard');
}
global $current_user;
get_currentuserinfo();
/* bypass synchronize if running upgrade
* to avoid any serious non-recoverable error
* which might hinder the upgrade process.
*/
if (CRM_Utils_Array::value('q', $_GET) != 'civicrm/upgrade') {
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::synchronize($current_user, FALSE, 'WordPress', 'Individual', TRUE);
}
CRM_Core_Invoke::invoke($args);
date_default_timezone_set($WP_base_timezone);
}
function civicrm_wp_head() {
// CRM-11823 - If Civi bootstrapped, then merge its HTML header with the CMS's header
global $civicrm_root;
if (empty($civicrm_root)) {
return;
}
$region = CRM_Core_Region::instance('html-header', FALSE);
if ($region) {
echo $region->render('');
}
}
function civicrm_wp_frontend($shortcode = FALSE) {
if (!civicrm_initialize()) {
return;
}
CRM_Core_Resources::singleton()->addCoreResources();
// set the frontend part for civicrm code
$config = CRM_Core_Config::singleton();
$config->userFrameworkFrontend = TRUE;
if (isset($_GET['q'])) {
$args = explode('/', trim($_GET['q']));
}
if ($shortcode) {
civicrm_turn_comments_off();
civicrm_set_post_blank();
}
else {
add_filter('get_header', 'civicrm_turn_comments_off');
add_filter('get_header', 'civicrm_set_post_blank');
}
// check permission
if (!civicrm_check_permission($args)) {
if ($shortcode) {
civicrm_set_frontendmessage();
}
else {
add_filter('the_content', 'civicrm_set_frontendmessage');
}
return;
}
require_once ABSPATH . WPINC . '/pluggable.php';
// if snippet is set, which means ajax call, we just
// output civicrm html and skip the header
if (
CRM_Utils_Array::value('snippet', $_GET) ||
(
CRM_Utils_Array::value(0, $args) == 'civicrm' &&
CRM_Utils_Array::value(1, $args) == 'ajax'
) ||
// we also follow this pattern where civicrm controls the
// entire page like an ical feed
(
CRM_Utils_Array::value(0, $args) == 'civicrm' &&
CRM_Utils_Array::value(1, $args) == 'event' &&
CRM_Utils_Array::value(2, $args) == 'ical' &&
// skip the html page since that is rendered in the CMS theme
CRM_Utils_Array::value('html', $_GET) != 1
)
) {
add_filter('init', 'civicrm_wp_invoke');
return;
}
// this places civicrm inside frontend theme
// wp documentation rocks if you know what you are looking for
// but best way is to check other plugin implementation :)
if ($shortcode) {
ob_start(); // start buffering
civicrm_wp_invoke( ); // now, instead of echoing, shortcode output ends up in buffer
$content = ob_get_clean(); // save the output and flush the buffer
return $content;
}
else {
add_filter('the_content', 'civicrm_wp_invoke');
}
}
function civicrm_set_blank() {
return;
}
function civicrm_set_frontendmessage() {
return ts('You do not have permission to execute this url.');
}
function civicrm_set_post_blank() {
global $post;
// to hide posted on
$post->post_type = '';
// to hide post title
$post->post_title = '';
// hide the edit link
add_action('edit_post_link', 'civicrm_set_blank');
}
function civicrm_turn_comments_off() {
global $post;
$post->comment_status = "closed";
}
function civicrm_check_permission($args) {
if ($args[0] != 'civicrm') {
return FALSE;
}
$config = CRM_Core_Config::singleton();
// set frontend true
$config->userFrameworkFrontend = TRUE;
require_once 'CRM/Utils/Array.php';
// all profile and file urls, as well as user dashboard and tell-a-friend are valid
$arg1 = CRM_Utils_Array::value(1, $args);
$validPaths = array('profile', 'user', 'dashboard', 'friend', 'file', 'ajax');
if (in_array($arg1, $validPaths)) {
return TRUE;
}
$arg2 = CRM_Utils_Array::value(2, $args);
$arg3 = CRM_Utils_Array::value(3, $args);
// allow editing of related contacts
if ($arg1 == 'contact' &&
$arg2 == 'relatedcontact'
) {
return TRUE;
}
// a contribution page
if (in_array('CiviContribute', $config->enableComponents)) {
if (
$arg1 == 'contribute' &&
in_array($arg2, array('transact', 'campaign', 'pcp'))
) {
return TRUE;
}
if (
$arg1 == 'pcp' &&
(!$arg2 || in_array($arg2, array('info')))
) {
return TRUE;
}
}
// an event registration page is valid
if (in_array('CiviEvent', $config->enableComponents)) {
if (
$arg1 == 'event' &&
in_array($arg2, array('register', 'info', 'participant', 'ical', 'confirm'))
) {
return TRUE;
}
// also allow events to be mapped
if (
$arg1 == 'contact' &&
$arg2 == 'map' &&
$arg3 == 'event'
) {
return TRUE;
}
if ($arg1 == 'pcp' &&
(!$arg2 || in_array($arg2, array('info')))
) {
return TRUE;
}
}
// allow mailing urls to be processed
if ($arg1 == 'mailing' &&
in_array('CiviMail', $config->enableComponents)
) {
if (in_array($arg2,
array('forward', 'unsubscribe', 'resubscribe', 'optout', 'subscribe', 'confirm', 'view')
)) {
return TRUE;
}
}
// allow petition sign in, CRM-7401
if (in_array('CiviCampaign', $config->enableComponents)) {
if ($arg1 == 'petition' &&
$arg2 == 'sign'
) {
return TRUE;
}
}
return FALSE;
}
function wp_civicrm_capability() {
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
//access civicrm page menu link to particular roles
$roles = array('super admin', 'administrator');
foreach ($roles as $role) {
$roleObj = $wp_roles->get_role($role);
if (
is_object($roleObj) &&
is_array($roleObj->capabilities) &&
! array_key_exists('access_civicrm', $wp_roles->get_role($role)->capabilities )
) {
$wp_roles->add_cap($role, 'access_civicrm');
}
}
}
function civicrm_wp_main() {
add_action('init', 'wp_civicrm_capability');
$isAdmin = is_admin();
if ($isAdmin) {
add_action('admin_menu', 'civicrm_wp_add_menu_items');
//Adding "embed form" button
if (in_array(
basename($_SERVER['PHP_SELF']),
array('post.php', 'page.php', 'page-new.php', 'post-new.php')
)) {
add_action('media_buttons_context', 'civicrm_add_form_button');
add_action('admin_footer', 'civicrm_add_form_button_html');
}
// check if settings file exist, do not show configuration link on
// install / settings page
if (isset($_GET['page']) && $_GET['page'] != 'civicrm-install') {
$settingsFile = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR . 'civicrm.settings.php';
if (!file_exists($settingsFile)) {
add_action('admin_notices', 'civicrm_setup_warning');
}
}
add_action('admin_head', 'civicrm_wp_head');
}
add_action('user_register', 'civicrm_user_register');
add_action('profile_update', 'civicrm_profile_update');
add_shortcode('civicrm', 'civicrm_shortcode_handler');
if (! $isAdmin) {
add_action('wp_head', 'civicrm_wp_head');
add_filter('get_header', 'civicrm_wp_shortcode_includes');
}
if (!civicrm_wp_in_civicrm()) {
return;
}
if (!$isAdmin) {
add_action('wp_footer', 'civicrm_buffer_end');
// we do this here rather than as an action, since we dont control
// the order
civicrm_buffer_start();
civicrm_wp_frontend();
}
}
function civicrm_add_form_button($context) {
if (!civicrm_initialize()) {
return '';
}
$config = CRM_Core_Config::singleton();
$imageBtnURL = $config->resourceBase . 'i/logo16px.png';
$out = '<a href="#TB_inline?width=480&inlineId=civicrm_frontend_pages" class="button thickbox" id="add_civi" style="padding-left: 4px;" title="' . __("Add CiviCRM Public Pages", 'CiviCRM') . '"><img src="' . $imageBtnURL . '" height="15" width="15" alt="' . __("Add CiviCRM Public Pages", 'CiviCRM') . '" />CiviCRM</a>';
return $context . $out;
}
function civicrm_add_form_button_html() {
$title = ts("Please select a CiviCRM front-end page type.");
$now = date("Ymdhis");
$sql = "
SELECT id, title
FROM civicrm_contribution_page
WHERE is_active = 1
AND (
( start_date IS NULL AND end_date IS NULL )
OR ( start_date <= $now AND end_date IS NULL )
OR ( start_date IS NULL AND end_date >= $now )
OR ( start_date <= $now AND end_date >= $now )
)
";
$dao = CRM_Core_DAO::executeQuery($sql);
$contributionPages = array();
while ($dao->fetch()) {
$contributionPages[$dao->id] = $dao->title;
}
$sql = "
SELECT id, title
FROM civicrm_event
WHERE is_active = 1
AND ( is_template = 0 OR is_template IS NULL )
AND (
( start_date IS NULL AND end_date IS NULL )
OR ( start_date <= $now AND end_date IS NULL )
OR ( start_date IS NULL AND end_date >= $now )
OR ( start_date <= $now AND end_date >= $now )
OR ( start_date >= $now )
)
";
$dao = CRM_Core_DAO::executeQuery($sql);
$eventPages = array();
while ($dao->fetch()) {
$eventPages[$dao->id] = $dao->title;
}
$sql = "
SELECT g.id as id, g.title as title
FROM civicrm_uf_group g, civicrm_uf_join j
WHERE g.is_active = 1
AND j.is_active = 1
AND ( group_type LIKE '%Individual%'
OR group_type LIKE '%Contact%' )
AND g.id = j.uf_group_id
AND j.module = 'Profile'
";
$dao = CRM_Core_DAO::executeQuery($sql);
$profilePages = array();
while ($dao->fetch()) {
$profilePages[$dao->id] = $dao->title;
}
?>
<script type="text/javascript">
jQuery(function($) {
$('#crm-wp-insert-shortcode').on('click', function() {
var form_id = $("#add_civicomponent_id").val();
if (form_id == ""){
alert ('Please select a frontend element.');
return;
}
var component = $("#add_civicomponent_id").val( );
var shortcode = '[civicrm component="' + component + '"';
switch (component) {
case 'contribution':
shortcode += ' id="' + $("#add_contributepage_id").val() + '"';
shortcode += ' mode="' + $("input[name='component_mode']:checked").val() + '"';
break;
case 'event':
shortcode += ' id="' + $("#add_eventpage_id").val() + '"';
shortcode += ' action="' + $("input[name='event_action']:checked").val() + '"';
shortcode += ' mode="' + $("input[name='component_mode']:checked").val() + '"';
break;
case 'profile':
shortcode += ' gid="' + $("#add_profilepage_id").val() + '"';
shortcode += ' mode="' + $("input[name='profile_mode']:checked").val() + '"';
break;
case 'user-dashboard':
break;
}
shortcode += ']';
window.send_to_editor( shortcode );
});
$('#add_civicomponent_id').on('change', function() {
switch ($(this).val()) {
case 'contribution':
$('#contribution-section, #component-section').show();
$('#profile-section, #profile-mode-section').hide();
$('#event-section, #action-section-event').hide();
break;
case 'event':
$('#contribution-section').hide();
$('#profile-section, #profile-mode-section').hide();
$('#event-section, #component-section, #action-section-event').show();
break;
case 'profile':
$('#contribution-section, #component-section').hide();
$('#profile-section, #profile-mode-section').show();
$('#event-section, #action-section-event').hide();
break;
default:
$('#contribution-section, #event-section, #component-section, #action-section-event').hide();
$('#profile-section, #profile-mode-section').hide();
break;
}
});
});
</script>
<div id="civicrm_frontend_pages" style="display:none;">
<div class="wrap">
<div>
<div style="padding:15px 15px 0 15px;">
<h3 style="color:#5A5A5A!important; font-family:Georgia,Times New Roman,Times,serif!important; font-size:1.8em!important; font-weight:normal!important;">
<?php echo $title; ?>
</h3>
<span>
<?php echo $title; ?>
</span>
</div>
<div style="padding:15px 15px 0 15px;">
<select id="add_civicomponent_id">
<option value=""> <?php echo ts("Select a frontend element."); ?> </option>
<option value="contribution">Contribution Page</option>
<option value="event">Event Page</option>
<option value="profile">Profile</option>
<option value="user-dashboard">User Dashboard</option>
</select>
<span id="contribution-section" style="display:none;">
<select id="add_contributepage_id">
<?php
foreach ($contributionPages as $key => $value) { ?>
<option value="<?php echo absint($key) ?>"><?php echo esc_html($value) ?></option>
<?php
}?>
</select>
</span>
<span id="event-section" style="display:none;">
<select id="add_eventpage_id">
<?php
foreach ($eventPages as $key => $value) { ?>
<option value="<?php echo absint($key) ?>"><?php echo esc_html($value) ?></option>
<?php
}?>
</select>
</span>
<br>
<span id="action-section-event" style="display:none;">
<div style="padding:15px 15px 0 15px;">
<input type="radio" name="event_action" value="info" checked="checked" /> Event Info Page
<input type="radio" name="event_action" value="register" /> Event Registration Page
</div>
</span>
<br/>
<span id="component-section" style="display:none;">
<div style="padding:15px 15px 0 15px;">
<input type="radio" name="component_mode" value="live" checked="checked"/> Live Page
<input type="radio" name="component_mode" value="test" /> Test Drive
</div>
</span>
<br/>
<span id="profile-section" style="display:none;">
<select id="add_profilepage_id">
<?php
foreach ($profilePages as $key => $value) { ?>
<option value="<?php echo absint($key) ?>"><?php echo esc_html($value) ?></option>
<?php
}?>
</select>
</span>
<br/>
<span id="profile-mode-section" style="display:none;">
<div style="padding:15px 15px 0 15px;">
<input type="radio" name="profile_mode" value="create" checked="checked"/> Create
<input type="radio" name="profile_mode" value="edit" /> Edit
<input type="radio" name="profile_mode" value="edit" /> View
</div>
</span>
<div style="padding:8px 0 0 0; font-size:11px; font-style:italic; color:#5A5A5A"><?php echo ts("Can't find your form? Make sure it is active."); ?></div>
</div>
<div style="padding:15px;">
<input type="button" class="button-primary" value="Insert Form" id="crm-wp-insert-shortcode"/>
<a class="button" style="color:#bbb;" href="#" onclick="tb_remove(); return false;"><?php echo ts("Cancel"); ?></a>
</div>
</div>
</div>
</div>
<?php
}
function civicrm_shortcode_handler($atts) {
extract(shortcode_atts(array(
'component' => 'contribution',
'action' => NULL,
'mode' => NULL,
'id' => NULL,
'cid' => NULL,
'gid' => NULL,
'cs' => NULL,
),
$atts
));
$args = array(
'reset' => 1,
'id' => $id,
);
switch ($component) {
case 'contribution':
if ($mode == 'preview' || $mode == 'test') {
$args['action'] = 'preview';
}
$args['q'] = 'civicrm/contribute/transact';
break;
case 'event':
switch ($action) {
case 'register':
$args['q'] = 'civicrm/event/register';
if ($mode == 'preview' || $mode == 'test') {
$args['action'] = 'preview';
}
break;
case 'info':
$args['q'] = 'civicrm/event/info';
break;
default:
echo 'Do not know how to handle this shortcode<p>';
return;
}
break;
case 'user-dashboard':
$args['q'] = 'civicrm/user';
unset($args['id']);
break;
case 'profile':
if ($mode == 'edit') {
$args['q'] = 'civicrm/profile/edit';
}
else if ($mode == 'view') {
$args['q'] = 'civicrm/profile/view';
}
else {
$args['q'] = 'civicrm/profile/create';
}
$args['gid'] = $gid;
break;
default:
echo 'Do not know how to handle this shortcode<p>';
return;
}
foreach ($args as $key => $value) {
if ($value !== NULL) {
$_REQUEST[$key] = $_GET[$key] = $value;
}
}
return civicrm_wp_frontend(TRUE);
}
function civicrm_wp_in_civicrm() {
return (isset($_GET['page']) &&
$_GET['page'] == 'CiviCRM'
) ? TRUE : FALSE;
}
function civicrm_wp_shortcode_includes() {
global $post;
if (preg_match('/\[civicrm/', $post->post_content)) {
if (!civicrm_initialize()) {
return;
}
CRM_Core_Resources::singleton()->addCoreResources();
}
}
function wp_get_breadcrumb() {
global $wp_set_breadCrumb;
return $wp_set_breadCrumb;
}
function wp_set_breadcrumb($breadCrumb) {
global $wp_set_breadCrumb;
$wp_set_breadCrumb = $breadCrumb;
return $wp_set_breadCrumb;
}
function t($str, $sub = NULL) {
if (is_array($sub)) {
$str = str_replace(array_keys($sub), array_values($sub), $str);
}
return $str;
}
function civicrm_user_register($userID) {
_civicrm_update_user($userID);
}
function civicrm_profile_update($userID) {
_civicrm_update_user($userID);
}
function _civicrm_update_user($userID) {
$user = get_userdata($userID);
if ($user) {
if (!civicrm_initialize()) {
return;
}
require_once 'CRM/Core/BAO/UFMatch.php';
CRM_Core_BAO_UFMatch::synchronize(
$user,
TRUE,
'WordPress',
'Individual'
);
}
}
function civicrm_buffer_start() {
ob_start("civicrm_buffer_callback");
}
function civicrm_buffer_end() {
ob_end_flush();
}
function civicrm_buffer_callback($buffer) {
// modify buffer here, and then return the updated code
return $buffer;
}
civicrm_wp_main();