/** * Check if current User already reached his 'create new thread' limit for today or not. * Important: The current User messaging permission is not checked here! * * @param boolean true to add a success/error message to $Messages about the current User thread limit, false otherwise * @return boolean true if current user already reached his limit, false otherwise */ function check_create_thread_limit($add_message = false) { global $Messages; list($max_new_threads, $new_threads_count) = get_todays_thread_settings(); if ($max_new_threads === '0') { // user new conversation limit is 0 if ($add_message) { $Messages->add(T_('You are not allowed to start a new conversation, because your limit is 0.')); } return true; } if (empty($max_new_threads)) { // user has no limit return false; } if ($max_new_threads > $new_threads_count) { // user didn't reach his limit yet if ($add_message) { $Messages->add(sprintf(T_('You can still start %d new conversations today.'), $max_new_threads - $new_threads_count), 'success'); } return false; } if ($add_message) { // user has already reached his limit $Messages->add(sprintf(T_('You have reached the limit of %d new conversations today. You can start new conversations again tomorrow.'), $max_new_threads)); } return true; }
/** * Check if recipients available in database * * @param string Input name * @param string Recipients logins separated with comma (Used for browsers without JavaScript) * @param string Recipients logins in array format (Used with jQuery plugin fbautocomplete) * @return boolean true if all recipients allow the current User to contact them, false otherwise */ function param_check__recipients($var, $recipients, $recipients_array) { global $DB, $current_User, $UserSettings, $Messages; if (!empty($recipients_array)) { // These data is created by jQuery plugin fbautocomplete $recipients_list = $recipients_array['title']; } else { // For browsers without JavaScript // split recipients into array using comma separator $recipients_list = array(); $recipients = trim(str_replace(',', ' ', $recipients)); foreach (explode(' ', $recipients) as $recipient) { $login = trim($recipient); if (!empty($login)) { $recipients_list[] = evo_strtolower($login); } } } $recipients_list = array_unique($recipients_list); $error_msg = ''; // check has recipients list login of current user if (in_array($current_User->login, $recipients_list)) { $error_msg = sprintf(T_('You cannot send threads to yourself: %s'), $current_User->login); } // load recipient User objects $UserCache =& get_UserCache(); $UserCache->load_where('user_login IN ( "' . implode('","', $recipients_list) . '" )'); // check are recipients available in database $this->recipients_list = array(); $unavailable_recipients_list = array(); $closed_recipients_list = array(); $status_restricted_recipients = array(); $recipients_without_perm = array(); $recipients_restricted_pm = array(); // check if recipient user enable private messages only if sender user doesn't have 'delete' messaging permission $check_enable_pm = !$current_User->check_perm('perm_messaging', 'delete'); foreach ($recipients_list as $recipient) { $recipient_User = $UserCache->get_by_login($recipient, false); if ($recipient_User === false) { // user doesn't exists $unavailable_recipients_list[] = $recipient; continue; } if (!$recipient_User->check_status('can_receive_pm')) { // user status restrict to receive private messages if ($recipient_User->check_status('is_closed')) { // user account was closed $closed_recipients_list[] = $recipient; continue; } $status_restricted_recipients[] = $recipient; continue; } if (!$recipient_User->check_perm('perm_messaging', 'reply')) { // user doesn't have permission to read private messages $recipients_without_perm[] = $recipient; continue; } if (!$UserSettings->get('enable_PM', $recipient_User->ID)) { // recipient doesn't want to receive private messages $recipients_restricted_pm[] = $recipient; if ($check_enable_pm) { // sender is not a user with delete ( "admin" ) messaging permission, so this user can't be in the recipients list continue; } } // recipient is correct, add to recipient list $this->recipients_list[] = $recipient_User->ID; } if (count($unavailable_recipients_list) > 0) { if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf('The following users were not found: %s', implode(', ', $unavailable_recipients_list)); } if (count($closed_recipients_list) > 0) { if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf('The following users no longer exist: %s', implode(', ', $closed_recipients_list)); } if (count($status_restricted_recipients) > 0) { if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf('The following users status currently does not permit to receive private messages: %s', implode(', ', $status_restricted_recipients)); } if (count($recipients_without_perm) > 0) { if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf('The following users have no permission to read private messages: %s', implode(', ', $recipients_without_perm)); } $restricted_pm_count = count($recipients_restricted_pm); if ($restricted_pm_count > 0) { // there is at least one recipient who doesn't want to receive private messages if ($check_enable_pm) { // sender is not a user with delete ( "admin" ) messaging permission, so this user can't be in the recipients list if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= sprintf('The following users don\'t want to receive private messages: %s', implode(', ', $recipients_restricted_pm)); } else { // send is an admin $manual_link = get_manual_link('messaging', T_('See manual') . '.'); if ($restricted_pm_count > 1) { // more then one recipient don't want to receive private messages $note = sprintf(T_('Users «%s» do not allow receiving private messages. Message has been sent anyway because you are an administrator.'), implode(', ', $recipients_restricted_pm)); } else { // one recipient doesn't want to receive private messages $note = sprintf(T_('User «%s» does not allow receiving private messages. Message has been sent anyway because you are an administrator.'), $recipients_restricted_pm[0]); } // add note $Messages->add($note . $manual_link, 'note'); } } // Here we select those recipients who has blocked the sender. Note that users with 'delete' messaging permission can't be blocked! $blocked_contacts = check_blocked_contacts($this->recipients_list); if (!empty($blocked_contacts)) { // There is at least one blocked recipient if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg .= T_('The following users don\'t want you to contact them at this time: ') . ' ' . implode(', ', $blocked_contacts); } if (empty($error_msg)) { // no errors yet $recipients_count = count($recipients_list); if ($recipients_count > 1 && param('thrdtype', 'string', 'discussion') != 'discussion') { // user want's to send more then one individual messages, check if is allowed list($max_new_threads, $new_threads_count) = get_todays_thread_settings(); if (!empty($max_new_threads) && $max_new_threads - $new_threads_count < $recipients_count) { // user has a create thread limit, and recipients number exceed that limit $error_msg .= '<br />'; $error_msg .= sprintf(T_('You are unable to send %d individual messages, because it exceeds your remaining daily limit of %d.'), $recipients_count, $max_new_threads - $new_threads_count); } } } if (!empty($error_msg)) { // show error param_error($var, $error_msg); return false; } return true; }