diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2025-05-22 18:43:12 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2025-05-22 19:03:06 +0200 |
commit | daf8531804a2644fa1de57fef6e53bce16be31ae (patch) | |
tree | 3579a9dea9a17a9ea65bd88e700bea76fa217295 /Zotlabs/Module | |
parent | 961996a0512103b6ce09d49fedf57b9f2a43c88a (diff) | |
download | volse-hubzilla-daf8531804a2644fa1de57fef6e53bce16be31ae.tar.gz volse-hubzilla-daf8531804a2644fa1de57fef6e53bce16be31ae.tar.bz2 volse-hubzilla-daf8531804a2644fa1de57fef6e53bce16be31ae.zip |
Fix undefined var in Module/Invite.php
Fir ref to undefined $ihave variable in the Module\Invite::get() method.
The var was defined later in the method. Also refactor to fix some other
strange logic in the same area while I was there.
- Moved the logic to cound invites currently in use by a channel to a
private function. This should probably be moved further to a Regiter
class once we have these things more in order.
- Changed the logic checking the configuration for how many invites a
channel can use at the same time to just return 4 (the default)
instead of going via 'na' and then checking if it's 'na' to then use
the default value.
- Dropped setting the config to the default if the module is visited by
an admin. That belongs somewhere else.
Diffstat (limited to 'Zotlabs/Module')
-rw-r--r-- | Zotlabs/Module/Invite.php | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/Zotlabs/Module/Invite.php b/Zotlabs/Module/Invite.php index 3e1e98f89..1c48b92ce 100644 --- a/Zotlabs/Module/Invite.php +++ b/Zotlabs/Module/Invite.php @@ -310,9 +310,9 @@ class Invite extends Controller { function get() { - // zai1 + $channel_id = local_channel(); - if(! local_channel()) { + if ($channel_id === false || $channel_id < 1) { notice( 'ZAI0101E,' . t('Permission denied.') . EOL); return; } @@ -330,15 +330,15 @@ class Invite extends Controller { return $o; } - // invitation_by_user may still not configured, the default 'na' will tell this - // if configured, 0 disables invitations by users, other numbers are how many invites a user may propagate - $invuser = Config::Get('system','invitation_by_user', 'na'); + $ihave = $this->count_invites_by_user($channel_id); - // if the mortal user drives the invitation - If (! is_site_admin()) { - - // when not configured, 4 is the default - $invuser = ($invuser === 'na') ? 4 : $invuser; + if (is_site_admin()) { + // Admins have unlimited invites + $invuser = '∞'; + } else { + // invitation_by_user may still not configured, the default 'na' will tell this + // if configured, 0 disables invitations by users, other numbers are how many invites a user may propagate + $invuser = Config::Get('system','invitation_by_user', 4); // a config value 0 disables invitation by users if (!$invuser) { @@ -350,12 +350,6 @@ class Invite extends Controller { notice( 'ZAI0105W,' . t('You have no more invitations available') . EOL); return ''; } - - } else { - // general deity admin invite limit infinite (theoretical) - if ($invuser === 'na') Config::Set('system','invitation_by_user', 4); - // for display only - $invuser = '∞'; } // xchan record of the page observer @@ -400,11 +394,6 @@ class Invite extends Controller { } } - // let see how many invites currently used by the user - $r = q("SELECT count(reg_id) AS n FROM register WHERE reg_vital = 1 AND reg_byc = %d", - intval(local_channel())); - $ihave = $r ? $r[0]['n'] : 0; - $tpl = get_markup_template('invite.tpl'); $inv_rabots = array( @@ -583,5 +572,18 @@ class Invite extends Controller { } return false; } + + /** + * Find how many invites the given channel is currently using. + * + * @param int $channel_id The id of the channel + * + * @return int Number of invites this channel is currently using. + */ + private function count_invites_by_user(int $channel): int { + $r = q("SELECT count(reg_id) AS n FROM register WHERE reg_vital = 1 AND reg_byc = %d", $channel); + + return $r ? $r[0]['n'] : 0; + } } |