-
Notifications
You must be signed in to change notification settings - Fork 0
/
WordPress SSO.xml
1468 lines (1293 loc) · 40.6 KB
/
WordPress SSO.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<plugin name="WordPress SSO" version_long="103002" version_human="1.3.2" author="The Necrotic" website="https://forum.bg-gamer.com/files/file/10-wordpress-ips-sso/" update_check="https://forum.bg-gamer.com/files/file/10-wordpress-ips-sso/"><hooks><hook type="C" class="\IPS\Member" filename="member"><![CDATA[//<?php
/**
* WordPress SSO - IPS4
*
* @author The Necrotic
* @link http://forum.bg-gamer.com
*/
class hook154 extends _HOOK_CLASS_
{
/**
* Add our own column to default fields
*/
public function __construct()
{
try
{
static::$databaseIdFields = array_merge( static::$databaseIdFields, array( 'wordpress_id' ) );
parent::__construct();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Member Sync
*
* @param string $method Method
* @param array $params Additional parameters to pass
* @return void
*/
public function memberSync( $method, $params=array() )
{
try
{
/* Let normal class do its thing */
call_user_func_array( 'parent::memberSync', func_get_args() );
if( $method == 'onLogout' AND !empty( \IPS\Settings::i()->wordpress_url ) )
{
try
{
$apiResponse = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp_api.php' )
->setQueryString( [ 'api_key' => \IPS\Settings::i()->wordpress_api_key, 'type' => 'logout', 'redirect' => \IPS\Http\Url::internal( '' ) ] )
->request()
->setHeaders( array( 'Cookie' => \IPS\Session\Front::$wpCookie . '=' . $_COOKIE[ \IPS\Session\Front::$wpCookie ] ) )
->get();
if( in_array( $apiResponse->httpResponseCode, array( '404', '401', '403' ) ) )
{
throw new \Exception( 'invalid_request' );
}
$api = $apiResponse->decodeJson();
}
catch( \Exception $e )
{
/* Redirect to Logout */
\IPS\Output::i()->redirect( \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp-login.php' )->setQueryString( 'action', 'logout' ) );
exit;
}
/* Redirect to Logout */
\IPS\Output::i()->redirect( \IPS\Http\Url::external( str_replace( '&', '&', $api['url'] ) ) );
exit;
}
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}]]></hook><hook type="C" class="\IPS\core\extensions\core\MemberForm\BasicInformation" filename="BasicInformationMemberForm"><![CDATA[//<?php
/**
* WordPress SSO - MemberForm Hook
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
exit;
}
class hook2172 extends _HOOK_CLASS_
{
/**
* Action Buttons
*
* @param \IPS\Member $member The Member
* @return array
*/
public function actionButtons( $member )
{
try
{
$result = parent::actionButtons( $member );
if( !isset( $result['actions']['menu'] ) )
{
return $result;
}
foreach( $result['actions']['menu'] as $k => $v )
{
/* If it's sign in as */
if( $v['icon'] == 'key' )
{
unset( $result['actions']['menu'] [$k] );
}
}
return $result;
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}
]]></hook><hook type="C" class="\IPS\Session\Front" filename="session"><![CDATA[//<?php
/**
* WordPress SSO - IPS4
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
class hook155 extends _HOOK_CLASS_
{
/**
* @brief API data storage
*/
public $wpData = [];
/**
* @brief Cookie name storage
*/
public static $wpCookie = null;
/**
* Guess if the user is logged in
*
* This is a lightweight check that does not rely on other classes. It is only intended
* to be used by the guest caching mechanism so that it can check if the user is logged
* in before other classes are initiated.
*
* This method MUST NOT be used for other purposes as it IS NOT COMPLETELY ACCURATE.
*
* @return bool
*/
public static function loggedIn()
{
try
{
if( parent::loggedIn() )
{
return TRUE;
}
if( static::_getWordPressCookie() )
{
return TRUE;
}
return FALSE;
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Read Session
*
* @param string $sessionId Session ID
* @return string
*/
public function read( $sessionId )
{
try
{
/* Let normal class do its thing */
$result = call_user_func_array( 'parent::read', func_get_args() );
/* WordPress Cookie */
$cookieName = $this->_getWordPressCookie();
/* Check for the Cookie, log out if logged in here, but not on master */
if( $this->member->member_id AND !$cookieName )
{
$this->_logout();
return '';
}
/* This is a guest session, no WP data to log them in */
elseif( !$cookieName )
{
return $result;
}
/* Check the cookie is the one we're expecting */
if( !$this->_compareWordPressCookie( $cookieName ) )
{
/* Log out but purposefully continue so the new member can be logged in */
$this->_logout();
}
/* Check the IPS4 session is a valid member */
if( $this->member->member_id )
{
return $result;
}
/* If we've sent a request in the last 30s, don't send one again */
if( isset( \IPS\Request::i()->cookies[ $cookieName . '_ips4_request'] ) )
{
return $result;
}
/* Fetch member data from WP API */
$this->wpData = $this->_getWordPressData( $cookieName );
if( !is_array( $this->wpData ) OR isset( \IPS\Request::i()->cookies['spammer'] ) )
{
/* Set cookie so we don't send lots of requests */
\IPS\Request::i()->setCookie( $cookieName . '_ips4_request', 1, \IPS\DateTime::create()->add( new \DateInterval( 'PT30S' ) ) );
$this->_logout();
return '';
}
/* Try loading */
$this->member = \IPS\Member::load( $this->wpData['user_id'], 'wordpress_id' );
if( !$this->member->member_id )
{
$this->member = \IPS\Member::load( $this->wpData['email'], 'email' );
}
/* Get the member group ID */
$memberGroups = $this->_getMemberGroups();
/* Check display name is correct */
if( !empty( $this->wpData['display_name'] ) AND $this->member->name != $this->wpData['display_name'] )
{
$this->member->name = $this->wpData['display_name'];
}
/* Check email address is correct */
if( $this->member->email != $this->wpData['email'] )
{
$this->member->email = $this->wpData['email'];
}
/* Check the member has a WordPress ID for future look ups */
if( !$this->member->wordpress_id AND $this->wpData['user_id'] )
{
$this->member->wordpress_id = $this->wpData['user_id'];
}
/* Check existing group ID (ignore admins) */
$primaryGroupId = array_shift( $memberGroups );
if( $this->member->member_group_id != $primaryGroupId AND !$this->member->isAdmin() )
{
$this->member->member_group_id = $primaryGroupId;
}
/* If enabled, assign the secondary groups */
if( \IPS\Settings::i()->wordpress_secondary_groups )
{
$this->member->mgroup_others = implode( ',', $memberGroups );
}
/* Spam Service Check */
if( !$this->member->member_id AND \IPS\Settings::i()->spam_service_enabled AND $this->member->email )
{
if( $this->member->spamService() == 4 )
{
\IPS\Request::i()->setCookie( 'spammer', 1, \IPS\DateTime::create()->add( new \DateInterval( 'P7D' ) ) );
return $result;
}
}
/* Save any changes to the member object */
$this->member->wordpress_cookie = md5( $_COOKIE[ $cookieName ] );
$this->member->save();
/* At this point, we're logged in. - We cannot call setMember here because it will not work with PHP 7.1
* -- We cannot call session_regenerate_id() from within the session read.
*/
$_SESSION['forcedWrite'] = time();
/* Make sure session handler saves during write() */
$this->save = TRUE;
/* For 4.2 we need to do some device management stuff */
if( \IPS\Application::load( 'core' )->long_version >= 101100 )
{
\IPS\Member\Device::loadOrCreate( $this->member )->updateAfterAuthentication( NULL );
}
/* Reset any logged in member */
\IPS\Member::$loggedInMember = $this->member;
/* Session read() method MUST return a string, or this can result in PHP errors */
return $result;
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Get users member group id based on role mapping
*
* @return array Array of IPS4 group ids
*/
protected function _getMemberGroups()
{
try
{
$groups = array();
$groupMap = json_decode( \IPS\Settings::i()->wordpress_group_map, TRUE );
/* Make sure the role response is in the expected format. - Some customised APIs may not return an array */
if( $this->wpData['role'] AND !is_array( $this->wpData['role'] ) )
{
$this->wpData['role'] = array( $this->wpData['role'] );
}
/* Any assigned roles? */
$roles = ( $this->wpData['role'] AND count( $this->wpData['role'] ) ) ? $this->wpData['role'] : array();
/* Group map */
foreach( $roles as $role )
{
$lowerRole = \mb_strtolower( $role );
if( isset( $groupMap[ $lowerRole ] ) )
{
try
{
/* Yep, that's a real group */
$groups[] = \IPS\Member\Group::load( $groupMap[ $lowerRole ] )->g_id;
}
catch( \UnderflowException $e ) { }
}
}
/* Still here? default member group for you */
if( !count( $groups ) )
{
return array( \IPS\Settings::i()->member_group );
}
return $groups;
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Compare WP cookie hash to verify the cookie is for the same member.
*
* @param string $cookie WP Cookie contents
* @return boolean
*/
protected function _compareWordPressCookie( $cookie )
{
try
{
if( !$this->member->wordpress_cookie )
{
return FALSE;
}
elseif( !\IPS\Login::compareHashes( $this->member->wordpress_cookie, md5( $_COOKIE[ $cookie ] ) ) )
{
return FALSE;
}
return TRUE;
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Fetch cookie name
*
* @return boolean|string FALSE or name of cookie
*/
protected static function _getWordPressCookie()
{
try
{
if( static::$wpCookie !== NULL )
{
return static::$wpCookie;
}
if( count( $_COOKIE ) )
{
foreach( $_COOKIE as $k => $v )
{
if( \substr( $k, 0, 19 ) === 'wordpress_logged_in' )
{
return static::$wpCookie = $k;
}
}
}
/* No cookie was found */
return static::$wpCookie = FALSE;
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Fetch data from our WordPress API
*
* @param string $cookie
* @return boolean|array
*/
protected function _getWordPressData( $cookie )
{
try
{
try
{
return \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp_api.php' )
->setQueryString( [ 'api_key' => \IPS\Settings::i()->wordpress_api_key, 'type' => 'userinfo' ] )
->request()
->setHeaders( array( 'Cookie' => $cookie . '=' . $_COOKIE[ $cookie ] ) )
->get()
->decodeJson();
}
catch( \Exception $ex )
{
return FALSE;
}
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Log the member out of IPS4
*
* @return void
*/
protected function _logout()
{
try
{
$this->member = new \IPS\Member;
\IPS\Request::i()->setCookie( 'member_id', NULL );
\IPS\Request::i()->setCookie( 'pass_hash', NULL );
/* Set data */
$this->data = array_merge(
$this->data,
array(
'member_name' => $this->member->name,
'seo_name' => $this->member->members_seo_name,
'member_id' => $this->member->member_id,
'member_group' => \IPS\Settings::i()->guest_group,
)
);
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}]]></hook><hook type="C" class="\IPS\core\modules\front\system\settings" filename="settings"><![CDATA[//<?php
/**
* WordPress SSO - Account Settings Hook
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
class hook1050 extends _HOOK_CLASS_
{
/**
* Register
*
* @return void
*/
protected function _email()
{
try
{
if( !empty( \IPS\Settings::i()->wordpress_url ) )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp-admin/profile.php' ) );
exit;
}
return parent::_email();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Password
*
* @return void
*/
protected function _password()
{
try
{
if( !empty( \IPS\Settings::i()->wordpress_url ) )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp-admin/profile.php' ) );
exit;
}
return parent::_password();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Username
*
* @return void
*/
protected function _username()
{
try
{
if( !empty( \IPS\Settings::i()->wordpress_url ) )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp-admin/profile.php' ) );
exit;
}
return parent::_username();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}]]></hook><hook type="C" class="\IPS\core\modules\front\system\register" filename="register"><![CDATA[//<?php
/**
* WordPress SSO - Register Hook
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
class hook1051 extends _HOOK_CLASS_
{
/**
* Register
*
* @return void
*/
protected function manage()
{
try
{
if( !empty( \IPS\Settings::i()->wordpress_url ) )
{
try
{
$apiResponse = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp_api.php' )
->setQueryString( [ 'api_key' => \IPS\Settings::i()->wordpress_api_key, 'type' => 'register', 'redirect' => $_SERVER['HTTP_REFERER'] ?: \IPS\Settings::i()->base_url ] )
->request()
->get();
if( in_array( $apiResponse->httpResponseCode, array( '404', '401', '403' ) ) )
{
throw new \Exception( 'invalid_request' );
}
$api = $apiResponse->decodeJson();
}
catch( \Exception $e )
{
/* Redirect to register - Fallback to default WP URL */
\IPS\Output::i()->redirect( \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp-login.php' ) )->setQueryString( array( 'action' => 'register', 'redirect_to' => $_SERVER['HTTP_REFERER'] ?: \IPS\Settings::i()->base_url ) );
exit;
}
/* Redirect to register url */
\IPS\Output::i()->redirect( \IPS\Http\Url::external( $api['url'] ) );
exit;
}
parent::manage();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}]]></hook><hook type="C" class="\IPS\core\modules\front\system\login" filename="login"><![CDATA[//<?php
/**
* WordPress SSO - Login Hook
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
class hook1052 extends _HOOK_CLASS_
{
/**
* Log In
*
* @return void
*/
protected function manage()
{
try
{
if( !empty( \IPS\Settings::i()->wordpress_url ) )
{
if( defined( 'WP_SSO_LOGIN_URL' ) )
{
$url = WP_SSO_LOGIN_URL;
}
else
{
$redirect = isset( \IPS\Request::i()->ref ) ? base64_decode( \IPS\Request::i()->ref ) : ( $_SERVER['HTTP_REFERER'] ?: \IPS\Settings::i()->base_url );
try
{
$apiResponse = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp_api.php' )
->setQueryString( [ 'api_key' => \IPS\Settings::i()->wordpress_api_key, 'type' => 'login', 'redirect' => $redirect ] )
->request()
->get();
if( in_array( $apiResponse->httpResponseCode, array( '404', '401', '403' ) ) )
{
throw new \Exception( 'invalid_request' );
}
$api = $apiResponse->decodeJson();
$url = $api['url'];
}
catch( \Exception $e )
{
/* Redirect to login - Fallback to default WP URL */
\IPS\Output::i()->redirect( \IPS\Http\Url::external( \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp-login.php' ) )->setQueryString( 'redirect_to', $redirect ) );
exit;
}
}
/* Redirect to login URL */
\IPS\Output::i()->redirect( \IPS\Http\Url::external( $url ) );
exit;
}
parent::manage();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}]]></hook><hook type="S" class="\IPS\Theme\class_core_front_global" filename="frontGlobal"><![CDATA[//<?php
/**
* WordPress SSO - Template Hook
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
class hook1053 extends _HOOK_CLASS_
{
/* !Hook Data - DO NOT REMOVE */
public static function hookData() {
return array_merge_recursive( array (
'userBar' =>
array (
0 =>
array (
'selector' => '#elSignInLink',
'type' => 'replace',
'content' => '{{if !empty(\IPS\Settings::i()->wordpress_url)}}
<li id=\'elSignInLink\'>
<a href=\'{url="app=core&module=system&controller=login" seoTemplate="login" protocol="\IPS\Settings::i()->logins_over_https"}\' id=\'elUserSignIn\'>
{lang="sign_in"}
</a>
</li>
{{else}}
<li id=\'elSignInLink\'>
<a href=\'{url="app=core&module=system&controller=login" seoTemplate="login" protocol="\IPS\Settings::i()->logins_over_https"}\' data-ipsMenu-closeOnClick="false" data-ipsMenu id=\'elUserSignIn\'>
{lang="sign_in"} Â <i class=\'fa fa-caret-down\'></i>
</a>
{template="loginPopup" app="core" group="global" params="new \IPS\Login( \IPS\Http\Url::internal( \'app=core&module=system&controller=login\', \'front\', \'login\', NULL, \IPS\Settings::i()->logins_over_https ) )"}
</li>
{{endif}}',
),
),
), parent::hookData() );
}
/* End Hook Data */
}]]></hook><hook type="C" class="\IPS\core\modules\admin\members\members" filename="adminCpMembers"><![CDATA[//<?php
/**
* WordPress SSO - Admin Members Hook
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
class hook1054 extends _HOOK_CLASS_
{
/**
* Edit Member
*
* @return void
*/
public function edit()
{
try
{
\IPS\Member::loggedIn()->language()->words['group_desc'] = \IPS\Member::loggedIn()->language()->addToStack('wordpress_member_group_desc');
if( \IPS\Settings::i()->wordpress_secondary_groups )
{
\IPS\Member::loggedIn()->language()->words['secondary_groups_desc'] = \IPS\Member::loggedIn()->language()->addToStack('wordpress_member_sgroup_desc');
}
return parent::edit();
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
/**
* Login as member
*
* @return void
*/
public function login()
{
try
{
\IPS\Dispatcher::i()->checkAcpPermission( 'member_login' );
\IPS\Output::i()->error( 'wordpress_signin_as_notavailable', '2S100/1', 404, '' );
}
catch ( \RuntimeException $e )
{
if ( method_exists( get_parent_class(), __FUNCTION__ ) )
{
return call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );
}
else
{
throw $e;
}
}
}
}]]></hook></hooks><settings><setting><key>wordpress_group_map</key><default/></setting><setting><key>wordpress_url</key><default/></setting><setting><key>wordpress_api_key</key><default/></setting><setting><key>wordpress_secondary_groups</key><default>0</default></setting></settings><settingsCode><![CDATA[//<?php
/**
* WordPress SSO Settings
*
* @author Stuart Silvester
* @copyright 2017 - Stuart Silvester
* @link http://ipb.silvesterwebdesigns.com
*/
$form->addTab( 'wordpress_configuration' );
/* Validator method for URL */
$urlTest = function( $value )
{
try
{
$response = \IPS\Http\Url::external( rtrim( $value, '/' ) . '/wp_api.php' )
->setQueryString( 'type', 'test' )
->request()
->get();
if( parse_url( $value, PHP_URL_SCHEME ) === 'https' AND parse_url( \IPS\Settings::i()->base_url, PHP_URL_SCHEME ) === 'http' )
{
throw new \InvalidArgumentException( 'wordpress_url_https' );
}
if( !in_array( $response->httpResponseCode, array( '200', '401' ) ) )
{
throw new \InvalidArgumentException( 'wordpress_api_notfound' );
}
}
catch( \IPS\Http\Request\Exception $e )
{
throw new \InvalidArgumentException( 'wordpress_url_connection_err' );
}
};
/* Validator method for API Key */
$keyTest = function( $value )
{
try
{
$response = \IPS\Http\Url::external( rtrim( \IPS\Request::i()->wordpress_url, '/' ) . '/wp_api.php' )
->setQueryString( array( 'type' => 'test', 'api_key' => $value ) )
->request()
->get();
if( !in_array( $response->httpResponseCode, array( '200' ) ) )
{
throw new \InvalidArgumentException( 'wordpress_api_key_wrong' );
}
}
catch( \IPS\Http\Request\Exception $e )
{
throw new \InvalidArgumentException( 'wordpress_url_connection_err' );
}
};
$form->add( new \IPS\Helpers\Form\Url( 'wordpress_url', \IPS\Settings::i()->wordpress_url, TRUE, array(), $urlTest ) );
$form->add( new \IPS\Helpers\Form\Text( 'wordpress_api_key', \IPS\Settings::i()->wordpress_api_key ?: md5( uniqid() ), TRUE, array(), $keyTest ) );
/* Don't show the mapping untill the settings are configured */
if( \IPS\Settings::i()->wordpress_url and \IPS\Settings::i()->wordpress_url )
{
try
{
/* Fetch WordPress Roles */
$wpRoles = \IPS\Http\Url::external( rtrim( \IPS\Settings::i()->wordpress_url, '/' ) . '/wp_api.php' )
->setQueryString( array( 'type' => 'roles', 'api_key' => \IPS\Settings::i()->wordpress_api_key ) )
->request()->get()->decodeJson( TRUE );
if( !$wpRoles )
{
throw new \RuntimeException;
}
$form->addTab( 'wordpress_roleMap' );
$form->addMessage( 'wordpress_roleMap_desc', 'ipsMessage ipsMessage_info' );
/* Unset Admin */
unset( $wpRoles['administrator'] );
/* Group Sync Matrix */
$groups = \IPS\Member\Group::groups();
$groupList = array();
foreach ( $groups as $group )
{