@@ -100,11 +100,12 @@ public static function save_referral(&$regOptions, &$theme_vars, &$knownInts)
100
100
* Updates a member ref_count if set as the referral
101
101
*
102
102
* @param array $regOptions The register options
103
+ * @param int $memberID The id of the newly registered member
103
104
* @return void
104
105
*/
105
- public static function update_count ($ regOptions )
106
+ public static function update_count ($ regOptions, $ memberID )
106
107
{
107
- global $ smcFunc ;
108
+ global $ smcFunc, $ modSettings ;
108
109
109
110
// Do a checking just in case something is broken
110
111
if (!empty ($ regOptions ['register_vars ' ]['referral ' ]))
@@ -118,8 +119,9 @@ public static function update_count($regOptions)
118
119
]
119
120
);
120
121
121
- // Are we doing anything else with this?
122
- call_integration_hook ('integrate_mod_simplereferrals ' , [$ regOptions ['register_vars ' ]['referral ' ]]);
122
+ // Send an alert?
123
+ if (!empty ($ modSettings ['SimpleReferrals_send_alerts ' ]))
124
+ self ::sendAlert ($ regOptions ['register_vars ' ], $ memberID );
123
125
}
124
126
125
127
// If we still have the referral in the session, remove it
@@ -360,6 +362,7 @@ public static function settings($return_config = false)
360
362
['check ' , 'SimpleReferrals_enable_posts ' ],
361
363
['check ' , 'SimpleReferrals_display_link ' ],
362
364
['check ' , 'SimpleReferrals_enable_stats ' ],
365
+ ['check ' , 'SimpleReferrals_send_alerts ' ],
363
366
];
364
367
365
368
// Return config vars
@@ -615,4 +618,108 @@ public function forum_stats()
615
618
$ context ['stats_blocks ' ]['most_referrals ' ][$ i ]['percent ' ] = round (($ referral_count ['num ' ] * 100 ) / $ max_referrals );
616
619
}
617
620
}
621
+
622
+ /**
623
+ * SimpleReferrals::alertTypes()
624
+ *
625
+ * Adds the top referrers in the forum
626
+ *
627
+ * @param array $alert_types The type of content/alerts
628
+ * @return void
629
+ */
630
+ public static function alertTypes (&$ alert_types )
631
+ {
632
+ global $ modSettings ;
633
+
634
+ // No alertts, no fun
635
+ if (empty ($ modSettings ['SimpleReferrals_send_alerts ' ]))
636
+ return ;
637
+
638
+ // Language
639
+ loadLanguage ('SimpleReferrals/ ' );
640
+
641
+ $ alert_types ['referrals ' ] = [
642
+ 'new_referred ' => ['alert ' => 'yes ' , 'email ' => 'never ' ],
643
+ ];
644
+ }
645
+
646
+ /**
647
+ * SimpleReferrals::alertFetch()
648
+ *
649
+ * Fetch the alert fot the user
650
+ *
651
+ * @param array $alerts The alerts being sent out
652
+ * @return void
653
+ */
654
+ public static function alertFetch (&$ alerts )
655
+ {
656
+ global $ settings , $ scripturl , $ modSettings ;
657
+
658
+ // No alertts, no fun
659
+ if (empty ($ modSettings ['SimpleReferrals_send_alerts ' ]))
660
+ return ;
661
+
662
+ // Language
663
+ loadLanguage ('SimpleReferrals/ ' );
664
+
665
+ foreach ($ alerts as $ alert_id => $ alert )
666
+ {
667
+ if ($ alert ['content_type ' ] == 'referral ' )
668
+ {
669
+ $ alerts [$ alert_id ]['icon ' ] = '<img class="alert_icon" src=" ' . $ settings ['images_url ' ] . '/icons/most_referrals.png"> ' ;
670
+ $ alerts [$ alert_id ]['extra ' ]['content_link ' ] = $ scripturl . $ alert ['extra ' ]['referred_link ' ];
671
+ }
672
+ }
673
+ }
674
+
675
+ /**
676
+ * SimpleReferrals::sendAlert()
677
+ *
678
+ * Send an alert to the referral
679
+ *
680
+ * @param array $register_vars Contains $regOptions['register_vars']
681
+ * @param int $memID It's the id of the referred user
682
+ * @return void
683
+ */
684
+ public static function sendAlert ($ register_vars , $ memID )
685
+ {
686
+ global $ smcFunc , $ sourcedir ;
687
+
688
+ require_once ($ sourcedir . '/Subs-Notify.php ' );
689
+ $ prefs = getNotifyPrefs ($ register_vars ['referral ' ], 'new_referred ' , true );
690
+
691
+ // Send alert
692
+ // Check the value. If no value or it's empty, they didn't want alerts, oh well.
693
+ if (empty ($ prefs [$ register_vars ['referral ' ]]['new_referred ' ]))
694
+ return true ;
695
+
696
+ // Issue, update, move on.
697
+ $ smcFunc ['db_insert ' ]('insert ' ,
698
+ '{db_prefix}user_alerts ' ,
699
+ [
700
+ 'alert_time ' => 'int ' ,
701
+ 'id_member ' => 'int ' ,
702
+ 'id_member_started ' => 'int ' ,
703
+ 'member_name ' => 'string ' ,
704
+ 'content_type ' => 'string ' ,
705
+ 'content_id ' => 'int ' ,
706
+ 'content_action ' => 'string ' ,
707
+ 'is_read ' => 'int ' ,
708
+ 'extra ' => 'string '
709
+ ],
710
+ [
711
+ time (),
712
+ $ register_vars ['referral ' ],
713
+ $ memID ,
714
+ $ register_vars ['real_name ' ],
715
+ 'referral ' ,
716
+ $ memID ,
717
+ 'new_referred ' ,
718
+ 0 ,
719
+ $ smcFunc ['json_encode ' ](['referred_link ' => '?action=profile;u= ' . $ memID ])
720
+ ],
721
+ ['id_alert ' ]
722
+ );
723
+ updateMemberData ($ register_vars ['referral ' ], ['alerts ' => '+ ' ]);
724
+ }
618
725
}
0 commit comments