Beispiel #1
0
 /**
  * Get messaging possibilities between current user and this user
  *
  * @return NULL|string allowed messaging possibility: PM > email > login > NULL
  */
 function get_msgform_possibility($current_User = NULL)
 {
     if (!$this->check_status('can_receive_any_message')) {
         // there is no way to send a message to a user with closed account
         return NULL;
     }
     if (is_logged_in()) {
         // current User is a registered user
         if ($current_User == NULL) {
             global $current_User;
         }
         if ($this->accepts_pm() && $current_User->accepts_pm() && $this->ID != $current_User->ID) {
             // both user has permission to send or receive private message and not the same user
             // check if current_User is allowed to create a new conversation with this user.
             $blocked_contact = check_blocked_contacts(array($this->ID));
             if (empty($blocked_contact)) {
                 // user is allowed to send pm to this user, and he didn't reached his new thread limit yet
                 return 'PM';
             }
         }
         if ($this->accepts_email()) {
             // this user allows email => send email
             return 'email';
         }
     } else {
         // current User is not logged in
         if ($this->accepts_email()) {
             // this user allows email
             return 'email';
         }
         if ($this->accepts_pm()) {
             // no email option try to log in and send private message (just registered users can send PM)
             return 'login';
         }
     }
     // no messaging option between current_User and this user
     return NULL;
 }
Beispiel #2
0
 /**
  * Get messaging possibilities between current user and $this user
  *
  * @param object Current User (the one trying to send the PM)
  * @param string Type of contact method to check first: 'PM' > 'email'  
  * @return NULL|string allowed messaging possibility: PM > email > login > NULL
  */
 function get_msgform_possibility($current_User = NULL, $check_level = 'PM')
 {
     global $DB;
     $check_owner_SQL = new SQL();
     $check_owner_SQL->SELECT('blog_ID');
     $check_owner_SQL->FROM('T_blogs');
     $check_owner_SQL->WHERE('blog_owner_user_ID = ' . $DB->quote($this->ID));
     $check_owner_SQL->LIMIT('1');
     if ($DB->get_var($check_owner_SQL->get())) {
         // Always allow to contact this user because he is owner of at least one collection:
         $is_collection_owner = true;
     } else {
         $is_collection_owner = false;
     }
     if (!$is_collection_owner && !$this->check_status('can_receive_any_message')) {
         // In case of a closed account:
         return NULL;
     }
     if (is_logged_in()) {
         // current User is a registered user
         if ($current_User == NULL) {
             global $current_User;
         }
         if (!$is_collection_owner && has_cross_country_restriction('contact') && (empty($current_User->ctry_ID) || $current_User->ctry_ID !== $this->ctry_ID)) {
             // Contat to this user is not enabled
             return NULL;
         }
         if ($check_level == 'PM' && $this->accepts_pm() && $current_User->accepts_pm() && $this->ID != $current_User->ID) {
             // both user has permission to send or receive private message and not the same user
             // check if current_User is allowed to create a new conversation with this user.
             $blocked_contact = check_blocked_contacts(array($this->ID));
             if (empty($blocked_contact) && !$current_User->must_accept_terms()) {
                 // user is allowed to send pm to this user, and he didn't reached his new thread limit yet
                 return 'PM';
             }
         }
         if ($is_collection_owner || $this->accepts_email()) {
             // This User allows email => send email OR Force to allow to contact with this user because he is owner of the selected collection:
             return 'email';
         }
     } else {
         // current User is not logged in
         if ($is_collection_owner || $this->accepts_email()) {
             // This User allows email => send email OR Force to allow to contact with this user because he is owner of the selected collection:
             return 'email';
         }
         if ($this->accepts_pm()) {
             // no email option - try to log in and send private message (only registered users can send PM)
             return 'login';
         }
     }
     // no messaging option between current_User and this user
     return NULL;
 }
Beispiel #3
0
 /**
  * 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 &laquo;%s&raquo; 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 &laquo;%s&raquo; 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;
 }