/**
  * Send Message
  */
 public function sendMessage($h)
 {
     $result = $h->sendMessage($this->to, '', $this->subject, $this->body);
     if (is_array($result)) {
         // error array!
         $this->errors = $result;
         return false;
     } else {
         // must be the insert id:
         $this->id = $result;
     }
     // code here to call sendEmailNotification IF PERMITTED
     $recipient = new UserAuth();
     $recipient_id = $h->getUserIdFromName($this->to);
     $recipient->getUserBasic($h, $recipient_id);
     $recipient_settings = $recipient->getProfileSettingsData($h, 'user_settings');
     if ($recipient_settings['pm_notify']) {
         $this->sendEmailNotification($h);
     }
     return true;
 }
 /**
  * Send new password
  */
 public function sendPassword($h)
 {
     // check username
     $username = $h->cage->post->testUsername('username');
     $userAuth = new UserAuth();
     $userAuth->getUserBasic($h, 0, $username);
     if ($userAuth->id) {
         // send password!
         $passconf = md5(crypt(md5($userAuth->email), md5($userAuth->email)));
         $userAuth->newRandomPassword($h, $userAuth->id, $passconf);
         $h->messages[$h->lang['user_man_new_password_sent']] = 'green';
     } else {
         $h->vars['user_man_username_2'] = $username;
         // to fill the username field
         $h->messages[$h->lang['user_man_user_not_found']] = 'red';
     }
 }
 /**
  * Check email confirmation code
  *
  * @return true;
  */
 public function checkEmailConfirmation($h)
 {
     $user_id = $h->cage->get->getInt('id');
     $conf = $h->cage->get->getAlnum('conf');
     $user = new UserAuth();
     $user->getUserBasic($h, $user_id);
     if (!$user_id || !$conf) {
         $h->messages[$h->lang['user_signin_register_emailconf_fail']] = 'red';
     }
     $sql = "SELECT user_email_conf FROM " . TABLE_USERS . " WHERE user_id = %d";
     $user_email_conf = $h->db->get_var($h->db->prepare($sql, $user_id));
     if ($conf === $user_email_conf) {
         // update role:
         $user->role = $h->vars['regStatus'];
         $h->pluginHook('user_signin_email_conf_post_role');
         // update user with new permissions:
         $new_perms = $user->getDefaultPermissions($h, $user->role);
         unset($new_perms['options']);
         // don't need this for individual users
         $user->setAllPermissions($new_perms);
         $user->updatePermissions($h);
         $user->updateUserBasic($h);
         // set email valid to 1:
         $sql = "UPDATE " . TABLE_USERS . " SET user_email_valid = %d WHERE user_id = %d";
         $h->db->query($h->db->prepare($sql, 1, $user->id));
         // notify chosen mods of new user by email:
         if ($h->vars['useEmailNotify'] == 'checked' && file_exists(PLUGINS . 'users/libs/UserFunctions.php')) {
             require_once PLUGINS . 'users/libs/UserFunctions.php';
             $uf = new UserFunctions();
             $uf->notifyMods($h, 'user', $user->role, $user->id);
         }
         $success_message = $h->lang['user_signin_register_emailconf_success'] . " <br /><b><a href='" . $h->url(array('page' => 'login')) . "'>" . $h->lang['user_signin_register_emailconf_success_login'] . "</a></b>";
         $h->messages[$success_message] = 'green';
     } else {
         $h->messages[$h->lang['user_signin_register_emailconf_fail']] = 'red';
     }
     return true;
 }
 /**
  * Get user rankings <li> items
  *
  * @param array $users
  * @param bool $widget
  * return string $output
  */
 public function displayUserRankings($h, $widget = false)
 {
     // get settings from the database
     $ur_settings = $h->getSerializedSettings('user_rankings');
     if (!$ur_settings) {
         return false;
     }
     if ($widget) {
         $limit = "widget_number";
         $css = 'widget';
     } else {
         $limit = "page_number";
         $css = 'page';
     }
     $need_cache = false;
     $label = 'user_rankings_' . $css;
     // check for a cached version and use it if no recent update:
     $output = $h->cacheHTML($ur_settings['cache_duration'], '', $label);
     if ($output) {
         return $output;
     } else {
         $need_cache = true;
     }
     // get all users with activity in the last X days, ordered by points
     $users = $this->generateUserRankings($h);
     if (!$users) {
         return false;
     }
     $output = '';
     $i = 0;
     foreach ($users as $id => $points) {
         $user = new UserAuth();
         $user->getUserBasic($h, $id);
         if (!$user->id) {
             continue;
         }
         // i.e. if this user doesn't exist anymore, skip to the next one
         $i++;
         $output .= "<li class='user_rankings_" . $css . "_item user_rankings_clearfix'>\n";
         if ($ur_settings['show_avatar'] && $h->isActive('avatar')) {
             $size = 'avatar_size_' . $css;
             $h->setAvatar($user->id, $ur_settings[$size]);
             $output .= "<div class='user_rankings_" . $css . "_avatar'>\n";
             $output .= $h->linkAvatar();
             $output .= "</div> \n";
         }
         if ($ur_settings['show_name']) {
             $output .= "<a class='user_rankings_" . $css . "_name' href='" . $h->url(array('user' => $user->name)) . "'>" . $user->name . "</a> \n";
         }
         $h->vars['user_rankings_output'] = "";
         $h->pluginHook('user_rankings_item', '', array('points' => $points, 'css' => $css));
         $output .= $h->vars['user_rankings_output'];
         $output .= "<div class='user_rankings_" . $css . "_points'>" . $points . "</div>\n";
         $output .= "</li>\n\n";
         if ($i >= $ur_settings[$limit]) {
             break;
         }
     }
     if ($need_cache) {
         $h->cacheHTML($ur_settings['cache_duration'], $output, $label);
         // make or rewrite the cache file
     }
     return $output;
 }