|
2 | 2 |
|
3 | 3 | /**
|
4 | 4 | * @package Simple Referrals
|
5 |
| - * @version 1.3.1 |
| 5 | + * @version 1.4.2 |
6 | 6 | * @author Diego Andrés <diegoandres_cortes@outlook.com>
|
7 | 7 | * @copyright Copyright (c) 2021, SMF Tricks
|
8 | 8 | * @license https://www.gnu.org/licenses/gpl-3.0.en.html
|
@@ -574,49 +574,55 @@ public function forum_stats()
|
574 | 574 | global $smcFunc, $context, $scripturl, $settings, $modSettings;
|
575 | 575 |
|
576 | 576 | // Referrals Top.
|
577 |
| - if (!empty($modSettings['SimpleReferrals_enable_stats'])) |
578 |
| - { |
579 |
| - // Ref language |
580 |
| - loadLanguage('SimpleReferrals/'); |
| 577 | + if (empty($modSettings['SimpleReferrals_enable_stats'])) |
| 578 | + return; |
581 | 579 |
|
582 |
| - // Template |
583 |
| - loadTemplate('SimpleReferrals'); |
| 580 | + // Ref language |
| 581 | + loadLanguage('SimpleReferrals/'); |
584 | 582 |
|
585 |
| - // Add the icon without adding a css file... |
586 |
| - addInlineCss(' |
587 |
| - .main_icons.most_referrals::before { |
588 |
| - background: url('. $settings['default_images_url'] . '/icons/most_referrals.png); |
589 |
| - } |
590 |
| - '); |
| 583 | + // Template |
| 584 | + loadTemplate('SimpleReferrals'); |
591 | 585 |
|
592 |
| - // Top 10 referrals |
593 |
| - $context['stats_blocks']['most_referrals'] = []; |
594 |
| - $max_referrals = 1; |
595 |
| - $request = $smcFunc['db_query']('', ' |
596 |
| - SELECT mem.ref_count, mem.id_member, mem.real_name |
597 |
| - FROM {db_prefix}members AS mem |
598 |
| - WHERE mem.ref_count > 0 |
599 |
| - ORDER BY mem.ref_count DESC |
600 |
| - LIMIT 10', |
601 |
| - [] |
602 |
| - ); |
603 |
| - while ($ref_row = $smcFunc['db_fetch_assoc']($request)) |
604 |
| - { |
605 |
| - $context['stats_blocks']['most_referrals'][] = [ |
606 |
| - 'id' => $ref_row['id_member'], |
607 |
| - 'num' => $ref_row['ref_count'], |
608 |
| - 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $ref_row['id_member'] . '">' . $ref_row['real_name'] . '</a>', |
609 |
| - ]; |
610 |
| - |
611 |
| - if ($max_referrals < $ref_row['ref_count']) |
612 |
| - $max_referrals = $ref_row['ref_count']; |
| 586 | + // Add the icon without adding a css file... |
| 587 | + addInlineCss(' |
| 588 | + .main_icons.most_referrals::before { |
| 589 | + background: url('. $settings['default_images_url'] . '/icons/most_referrals.png); |
613 | 590 | }
|
614 |
| - $smcFunc['db_free_result']($request); |
| 591 | + '); |
615 | 592 |
|
616 |
| - // Percentage |
617 |
| - foreach ($context['stats_blocks']['most_referrals'] as $i => $referral_count) |
618 |
| - $context['stats_blocks']['most_referrals'][$i]['percent'] = round(($referral_count['num'] * 100) / $max_referrals); |
| 593 | + // Top 10 referrals |
| 594 | + $max_referrals = 1; |
| 595 | + $request = $smcFunc['db_query']('', ' |
| 596 | + SELECT mem.ref_count, mem.id_member, mem.real_name |
| 597 | + FROM {db_prefix}members AS mem |
| 598 | + WHERE mem.ref_count > 0 |
| 599 | + ORDER BY mem.ref_count DESC |
| 600 | + LIMIT 10', |
| 601 | + [] |
| 602 | + ); |
| 603 | + |
| 604 | + // Don't do anything if there are no referrals |
| 605 | + if (empty($smcFunc['db_num_rows']($request))) |
| 606 | + return; |
| 607 | + |
| 608 | + // Setup the block |
| 609 | + $context['stats_blocks']['most_referrals'] = []; |
| 610 | + while ($ref_row = $smcFunc['db_fetch_assoc']($request)) |
| 611 | + { |
| 612 | + $context['stats_blocks']['most_referrals'][] = [ |
| 613 | + 'id' => $ref_row['id_member'], |
| 614 | + 'num' => $ref_row['ref_count'], |
| 615 | + 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $ref_row['id_member'] . '">' . $ref_row['real_name'] . '</a>', |
| 616 | + ]; |
| 617 | + |
| 618 | + if ($max_referrals < $ref_row['ref_count']) |
| 619 | + $max_referrals = $ref_row['ref_count']; |
619 | 620 | }
|
| 621 | + $smcFunc['db_free_result']($request); |
| 622 | + |
| 623 | + // Percentage |
| 624 | + foreach ($context['stats_blocks']['most_referrals'] as $i => $referral_count) |
| 625 | + $context['stats_blocks']['most_referrals'][$i]['percent'] = round(($referral_count['num'] * 100) / $max_referrals); |
620 | 626 | }
|
621 | 627 |
|
622 | 628 | /**
|
|
0 commit comments