Esempio n. 1
0
 /**
 * 会员注册
 *  member_id 会员id
 		member_name 会员名
 		password 密码
 		salt 随机数
 		type 会员类型
 		type_name 会员类型名
 		avatar 头像
 		signature 个性签名
 		appid 应用id
 		appname 应用名
 		create_time 注册时间
 		update_time 更新时间
 		ip 注册ip
 *
 * $appid
 * $appkey
 * $callback
 *
 * $mobile_verifycode
 *
 * 绑定表
 *  member_id 会员id
 		platform_id 第三方平台会员id char
 		nick_name 昵称
 		type 会员类型
 		type_name 会员类型名称
 		avatar_url 头像地址
 		bind_time 绑定时间
 		bind_ip 绑定ip
 *
 * 返回
 * member_id
 * member_name
 * type
 * avatar
 * access_token
 */
 public function register()
 {
     try {
         $this->check_verifycode();
         //验证码
         $this->oldtype = $this->type = trim($this->input['type']);
         $member_name = $this->checkRegMemberName();
         $this->checkRegType();
         $this->checkRegMemberNameError();
         $password = trim($this->input['password']);
         $identifierUserSystem = new identifierUserSystem();
         $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier();
         //多用户系统
         if (empty($this->type)) {
             $this->errorOutput(NO_MEMBER_TYPE);
         }
         $platformInfo = $this->Members->get_platform_name($this->type);
         if (empty($platformInfo)) {
             $this->errorOutput(REG_MEMBER_TYPE_ERROR);
         } else {
             if (!$platformInfo['status']) {
                 $this->errorOutput(REG_MEMBER_TYPE_CLOSE);
             }
         }
         $type_name = $platformInfo['name'];
         $signature = trim($this->input['signature']);
         $ip = hg_getip();
         $appid = intval($this->input['appid']);
         $appkey = trim($this->input['appkey']);
         $platform_id = '';
         $mobile_verifycode = trim($this->input['mobile_verifycode']);
         $email = trim($this->input['email']);
         $reg_mail = $this->Members->check_reg_mail($email, 0, $identifier);
         if ($reg_mail == -4) {
             $this->errorOutput(EMAIL_FORMAT_ERROR);
         } elseif ($reg_mail == -5) {
             $this->errorOutput(EMAIL_NO_REGISTER);
         } elseif ($reg_mail == -6) {
             $this->errorOutput(EMAIL_HAS_BINDED);
         }
         $this->type == 'email' && $this->checkEmailVerifyCode($member_name);
         $this->type != 'email' && $email && $this->checkEmailVerifyCode($email);
         $_mobile = trim($this->input['mobile']);
         //简单验证手机号格式
         if ($_mobile && !hg_verify_mobile($_mobile)) {
             $this->errorOutput(MOBILE_NUMBER_FORMAT_ERROR);
         } else {
             if ($_mobile && (isset($this->input['mobile_verifycode']) || defined('NO_VERIFY_MOBILEBIND') && NO_VERIFY_MOBILEBIND)) {
                 $check_bind = new check_Bind();
                 if ($check_bind->checkmembernamereg($_mobile, $identifier)) {
                     $this->errorOutput(MOBILE_REG_BIND);
                 }
             }
         }
         if ($this->type != 'shouji' && $_mobile && isset($this->input['mobile_verifycode'])) {
             //验证码
             $verifycode = $this->mSmsServer->get_verifycode_info($_mobile, $mobile_verifycode);
             if (empty($verifycode)) {
                 $this->errorOutput(VERIFY_FAILED);
             }
             //删除验证码
             $this->mSmsServer->mobile_verifycode_delete($_mobile, $mobile_verifycode);
             if (TIMENOW > $verifycode['create_time'] + VERIFYCODE_EXPIRED_TIME) {
                 $this->errorOutput(VERIFY_EXPIRED);
             }
             $this->ismobileverify = 1;
         } else {
             if ($this->type != 'shouji' && $_mobile && defined('NO_VERIFY_MOBILEBIND') && NO_VERIFY_MOBILEBIND) {
                 $this->ismobileverify = 1;
             }
         }
         $device_token = $this->Members->check_device_token(trim($this->input['device_token']));
         if ($device_token === 0) {
             $this->errorOutput(ERROR_DEVICE_TOKEN);
         }
         $udid = $this->Members->check_udid(trim($this->input['uuid']));
         if ($udid === 0) {
             $this->errorOutput(ERROR_UDID);
         }
         //验证设备号和ip是否在黑名单
         if ($udid) {
             $device_res = $this->Blacklist->detailDeviceBlacklist(array('device_token' => $udid, 'identifier' => $identifier));
             if ($device_res[0]['deadline'] == -1 && $device_res[0]['type'] == 2) {
                 $this->errorOutput(DEVICE_BLACKLIST_FOREVER);
             } elseif ($device_res[0]['deadline'] == -1) {
                 $this->errorOutput(DEVICE_BLACKLIST);
             }
         }
         if ($ip) {
             $ip_res = $this->Blacklist->detailIpBlacklist(array('ip' => ip2long($ip), 'identifier' => $identifier));
             if ($ip_res[0]['deadline'] == -1 && $ip_res[0]['type'] == 2) {
                 $this->errorOutput(IP_BLACKLIST_FOREVER);
             } elseif ($ip_res[0]['deadline'] == -1) {
                 $this->errorOutput(IP_BLACKLIST);
             }
         }
         //密码
         if (!$password) {
             $this->errorOutput(NO_PASSWORD);
         }
         //验证手机验证码
         if ($this->type == 'shouji') {
             $check_bind = new check_Bind();
             if ($check_bind->checkmembernamereg($member_name, $identifier)) {
                 $this->errorOutput(MOBILE_REG_BIND);
             }
             $platform_id = $mobile = $member_name;
             $_mobile = $mobile ? $mobile : $_mobile;
             //简单验证手机号格式
             if (!hg_verify_mobile($mobile)) {
                 $this->errorOutput(MOBILE_NUMBER_FORMAT_ERROR);
             }
             if (!$mobile_verifycode) {
                 $this->errorOutput(MOBILE_NOT_VERIFY);
             }
             //验证码
             $verifycode = $this->mSmsServer->get_verifycode_info($mobile, $mobile_verifycode);
             if (empty($verifycode)) {
                 $this->errorOutput(VERIFY_FAILED);
             }
             //删除验证码
             $this->mSmsServer->mobile_verifycode_delete($mobile, $mobile_verifycode);
             if (TIMENOW > $verifycode['create_time'] + VERIFYCODE_EXPIRED_TIME) {
                 $this->errorOutput(VERIFY_EXPIRED);
             }
         }
         //如果是m2o注册类型屏蔽字检测
         if ($this->settings['App_banword']) {
             include ROOT_PATH . 'lib/class/banword.class.php';
             $banword = new banword();
             $signature_banword = $banword->exists($signature);
             if ($signature_banword && is_array($signature_banword)) {
                 $this->errorOutput(SIGNATURE_INVALID);
             }
         }
         if ($this->type == 'm2o' && $this->settings['App_banword']) {
             $member_name_banword = $banword->exists($member_name);
             if ($member_name_banword && is_array($member_name_banword)) {
                 $this->errorOutput(MEMBER_NAME_INVALID);
             }
         }
         //头像
         $avatar = array();
         if (isset($this->input['avatar']) && $_FILES['avatar']['tmp_name']) {
             $avatar = $_FILES['avatar'];
         }
         //验证会员名
         $ret_verify = $this->mMember->verify_member_name($member_name, 0, $identifier, $type);
         switch ($ret_verify) {
             case -1:
                 $this->errorOutput(MEMBER_NAME_ILLEGAL);
                 break;
             case -2:
                 $this->errorOutput(PROHIBITED_WORDS);
                 break;
             case -3:
                 $this->errorOutput(UC_MEMBER_NAME_REGISTER);
                 break;
             case -4:
                 $this->errorOutput(MEMBER_NAME_EXCEEDS_MAX);
                 break;
             case -5:
                 $this->errorOutput(USERNAME_BELOW_MINIMUM);
                 break;
             case -6:
                 $this->errorOutput(MEMBER_NAME_ERROR);
                 break;
             case -7:
                 $this->errorOutput(MEMBER_NAME_REGISTER);
                 break;
             default:
                 break;
         }
         //随机串
         $salt = hg_generate_salt();
         //密码md5
         $md5_password = md5(md5($password) . $salt);
         $groupInfo = $this->Members->checkgroup_credits(0);
         $gradeInfo = $this->Members->checkgrade_credits(0);
         $data = array('member_name' => $member_name, 'password' => $md5_password, 'salt' => $salt, 'type' => $this->type, 'type_name' => $type_name, 'gid' => $groupInfo['gid'], 'gradeid' => $gradeInfo['gradeid'], 'signature' => $signature, 'mobile' => $_mobile, 'email' => $email, 'status' => $this->settings['member_status'], 'identifier' => $identifier, 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => $ip, 'guid' => guid(), 'reg_device_token' => $device_token, 'reg_udid' => $udid);
         //入ucenter
         $inuc = 0;
         if ($this->type == 'm2o' && $this->settings['ucenter']['open'] && !$identifier) {
             //邮箱 m2o类型必须传入email
             if (!$email) {
                 $this->errorOutput(NO_EMAIL);
             }
             $virtual_email = $email;
             //忽略返回值
             $reinfo = $this->uc_register(array('member_name' => $data['member_name'], 'password' => $password, 'email' => $virtual_email));
             $inuc = $reinfo['member_id'];
         }
         //会员数据入库
         $ret = $this->mMember->create($data);
         if (!$ret['member_id']) {
             $this->errorOutput(MEMBER_DATA_ADD_FAILED);
         }
         $member_id = $ret['member_id'];
         //编辑扩展信息 #@param platformMark 平台标示
         if ($this->input['platformMark'] && $this->input['platformMark'] == 'dingdone' && $this->input['identifier']) {
             //为叮当注册根据app配置不同的扩展信息
             $this->mMemberInfo->extension_editByApp($member_id, $this->input['member_info'], $this->input['identifier'], $_FILES);
         } else {
             $this->mMemberInfo->extension_edit($member_id, $this->input['member_info'], $_FILES);
         }
         //获取扩展信息
         $extension = $this->getExtensionInfo($member_id, $identifier);
         if (!$identifier) {
             $invite_user = new invite();
             $id = $this->input['invite_id'] ? $this->input['invite_id'] : 0;
             //邀请码id
             $invite_code = $this->input['invite_code'] ? $this->input['invite_code'] : $member_name;
             //如果未传邀请码则已用户名为邀请码去邀请数据库查询是否存在邀请信息,目前仅支持手机注册类型用户名;
             $invite = $invite_user->invite_rules($member_id, $invite_code, $id);
             //邀请用户处理
             $this->invite_error($invite);
         }
         //uc打开平台id为uc 否则为自身id
         if ($this->type == 'm2o') {
             $platform_id = $this->settings['ucenter']['open'] && $reinfo['member_id'] > 0 && !$identifier ? $reinfo['member_id'] : $member_id;
         } elseif ($this->type == 'email') {
             $platform_id = $member_name;
         }
         $data['member_id'] = $member_id;
         //绑定表
         $bind_data = array('member_id' => $member_id, 'platform_id' => $platform_id, 'nick_name' => $member_name, 'type' => $this->type, 'type_name' => $type_name, 'bind_time' => TIMENOW, 'bind_ip' => $ip, 'inuc' => $inuc, 'is_primary' => 1, 'identifier' => $identifier, 'reg_device_token' => $device_token, 'reg_udid' => $udid);
         $ret_bind = $this->mMember->bind_create($bind_data);
         if (empty($ret_bind)) {
             $this->errorOutput(BIND_DATA_ADD_FAILED);
         }
         $this->registerCreditRules($member_id);
         //注册相关积分规则
         //如果注册时填写邮箱则可以同时入绑定表
         if ($data['email']) {
             if ($this->type != 'email' && $this->isemailverify) {
                 $_bind_data = $bind_data;
                 $_bind_data['platform_id'] = $data['email'];
                 $_bind_data['is_primary'] = 0;
                 $_bind_data['type'] = 'email';
                 $_bind_data['type_name'] = '邮箱';
                 $_ret_bind = $this->mMember->bind_create($_bind_data);
                 if (empty($_ret_bind)) {
                     $this->errorOutput(BIND_DATA_ADD_FAILED);
                 }
                 unset($_bind_data, $_ret_bind);
             }
         }
         if ($data['mobile']) {
             if ($this->type != 'shouji' && $this->ismobileverify) {
                 $_bind_data = $bind_data;
                 $_bind_data['platform_id'] = $data['mobile'];
                 $_bind_data['is_primary'] = 0;
                 $_bind_data['type'] = 'shouji';
                 $_bind_data['type_name'] = '手机';
                 $_ret_bind = $this->mMember->bind_create($_bind_data);
                 if (empty($_ret_bind)) {
                     $this->errorOutput(BIND_DATA_ADD_FAILED);
                 }
                 unset($_bind_data, $_ret_bind);
             }
         }
         //头像入库
         if (!empty($avatar)) {
             $avatar = $this->mMember->add_material($avatar, $member_id);
             if (!empty($avatar)) {
                 $update_data = array('member_id' => $member_id, 'avatar' => daddslashes(serialize($avatar)));
                 $ret_updata = $this->mMember->update($update_data);
                 if (!$ret_updata['member_id']) {
                     $this->errorOutput(AVATAR_ADD_FAILED);
                 }
             }
         } else {
             $avatar_url = $this->input['avatar_url'] ? trim($this->input['avatar_url']) : '';
             if ($avatar_url) {
                 $avatar = $this->mMember->local_material($avatar_url, $member_id);
                 if (!empty($avatar)) {
                     $update_data = array('member_id' => $member_id, 'avatar' => daddslashes(serialize($avatar)));
                     $ret_updata = $this->mMember->update($update_data);
                     if (!$ret_updata['member_id']) {
                         $this->errorOutput(AVATAR_ADD_FAILED);
                     }
                 }
             }
         }
         //到auth接口取access_token
         $callback = 'http://' . $this->settings['App_members']['host'] . '/' . $this->settings['App_members']['dir'] . 'login.php?a=verify_member&appid=' . $appid . '&appkey=' . $appkey;
         $encryptPassword = urlencode(passport_encrypt($password, CUSTOM_APPKEY));
         $auth_data = array('user_name' => $member_name, 'appid' => $appid, 'appkey' => $appkey, 'ip' => $ip, 'verify_user_cb' => $callback, 'extend' => 'platform_id=' . $platform_id . '&password='******'&encrypt=1&type=' . $this->type . '&identifier=' . $identifier);
         $auth = $this->mMember->get_access_token($auth_data);
         if (!$auth['token']) {
             $this->errorOutput(MEMBERS_LOGIN_ERROR);
         }
         $return = array('member_id' => $member_id, 'member_name' => $ret['member_name'], 'nick_name' => $auth['nick_name'], 'platform_id' => $auth['platform_id'], 'inuc' => $auth['inuc'] ? $auth['inuc'] : 0, 'type' => $this->type, 'type_name' => $auth['type_name'], 'avatar' => $avatar, 'access_token' => $auth['token'], 'guid' => $auth['guid'], 'gid' => $auth['gid'], 'gradeid' => $auth['gradeid'], 'copywriting_credit' => $auth['copywriting_credit'], 'copywriting' => $auth['copywriting'], 'signature' => $auth['signature'], 'mobile' => $auth['mobile'], 'email' => $auth['email'], 'isVerify' => $auth['isVerify'], 'isComplete' => $auth['isComplete'], 'identifier' => $auth['identifier'], 'last_login_device' => $auth['last_login_device']);
         if ($extension) {
             $return['extension'] = $extension;
         }
         //会员痕迹
         $member_trace_data = array('member_id' => $member_id, 'member_name' => $member_name, 'content_id' => $member_id, 'title' => $member_name, 'type' => 'register', 'op_type' => '注册', 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'ip' => hg_getip(), 'device_token' => $device_token, 'udid' => $udid);
         $this->mMember->member_trace_create($member_trace_data);
         //记录登陆信息
         $loginInfoRecord = array('last_login_device' => $member_trace_data['device_token'], 'final_login_time' => $member_trace_data['create_time'], 'last_login_time' => $member_trace_data['create_time'], 'last_login_udid' => $member_trace_data['udid']);
         $this->mMember->loginInfoRecord($return['member_id'], $loginInfoRecord);
         $return = hg_mermber2members_compatible(array('member_name' => 'nick_name', 'access_token' => 'token'), $return, false);
         $this->addItem($return);
         $this->output();
     } catch (Exception $e) {
         $this->errorOutput($e->getMessage(), $e->getCode());
     }
 }
Esempio n. 2
0
 private function get_condition()
 {
     $condition = '';
     if (($gid = (int) $this->input['groupid']) > 0 || ($gradeid = (int) $this->input['gradeid']) > 0) {
         $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'member as m ON m.member_id = mc.u_id');
         $gid && ($condition = ' AND m.gid = \'' . $gid . '\'');
         $gradeid && ($condition = ' AND m.gradeid = \'' . $gradeid . '\'');
         $this->memberCredits->setWhere($condition);
     } else {
         if (isset($this->input['startcredit1']) || isset($this->input['endcredit1'])) {
             if (($startcredit1 = (int) $this->input['startcredit1']) || isset($this->input['startcredit1'])) {
                 $condition = ' AND credit1>=' . $startcredit1;
                 $this->memberCredits->setWhere($condition);
             }
             if ((($endcredit1 = (int) $this->input['endcredit1']) || isset($this->input['endcredit1'])) && $endcredit1 >= $startcredit1) {
                 $condition = ' AND ' . 'credit1<=' . $endcredit1;
                 $this->memberCredits->setWhere($condition);
             }
         } else {
             if (isset($this->input['startcredit2']) || isset($this->input['endcredit2'])) {
                 if (($startcredit2 = (int) $this->input['startcredit2']) || isset($this->input['startcredit2'])) {
                     $condition = ' AND credit2>=' . $startcredit2;
                     $this->memberCredits->setWhere($condition);
                 }
                 if ((($endcredit2 = (int) $this->input['endcredit2']) || isset($this->input['endcredit2'])) && $endcredit2 >= $startcredit2) {
                     $condition = ' AND ' . 'credit2<=' . $endcredit2;
                     $this->memberCredits->setWhere($condition);
                 }
             } else {
                 if (($fbid = (int) $this->input['fbid']) > 0) {
                     $feedback = new feedback();
                     $membersId = $feedback->get_feed_members($fbid, '0,1');
                     if (!$membersId) {
                         throw new Exception(FEEDBACK_ID_NO_MEMBER, 200);
                     }
                     $this->memberCredits->setWhere(array('u_id' => $membersId['member_id']));
                 } else {
                     if ($spreadCode = trim($this->input['spreadcode'])) {
                         $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'spread_record as sr ON mc.u_id=sr.fuid');
                         $condition = " AND sr.spreadcode = '" . $spreadCode . "'";
                         $this->memberCredits->setWhere($condition);
                     } else {
                         if (($invite_userid = (int) $this->input['invite_userid']) > 0) {
                             $_invite = new invite();
                             $fuidArr = $_invite->select_uid_to_fuid($invite_userid, 'mi.fuid', 'fuid', 3, false);
                             if (!$fuidArr) {
                                 throw new Exception(MEMBER_NO_INVITE_MEMBERS, 200);
                             }
                             $this->memberCredits->setWhere(array('u_id' => $fuidArr));
                         } else {
                             if (($medalid = (int) $this->input['medalid']) > 0) {
                                 $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'member_medal as mm ON mm.member_id=mc.u_id');
                                 $condition = " AND mm.medalid = " . $medalid . " AND (mm.expiration=0 OR mm.expiration>" . TIMENOW . ")";
                                 $this->memberCredits->setWhere($condition);
                             } else {
                                 if ($member_type = trim($this->input['member_type'])) {
                                     $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'member_bind as mb ON mb.member_id=mc.u_id');
                                     $condition = ' AND mb.type = \'' . $member_type . '\'';
                                     $this->memberCredits->setWhere($condition);
                                 } else {
                                     if ($this->input['start_time'] || $this->input['end_time']) {
                                         $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'member as m ON m.member_id = mc.u_id');
                                         if ($start_time = trim(urldecode($this->input['start_time']))) {
                                             $start_time = strtotime($start_time);
                                             $condition = " AND m.create_time >= " . (int) $start_time;
                                             $this->memberCredits->setWhere($condition);
                                         }
                                         if ($end_time = trim(urldecode($this->input['end_time']))) {
                                             $end_time = strtotime($end_time);
                                             if ($end_time >= $start_time) {
                                                 $condition = " AND m.create_time <= " . (int) $end_time;
                                                 $this->memberCredits->setWhere($condition);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (($appid = (int) $this->input['mappid']) > 0) {
         $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'member as m ON m.member_id = mc.u_id');
         $condition = " AND m.appid = " . $appid;
         $this->memberCredits->setWhere($condition);
     }
     if (isset($this->input['identifier'])) {
         $identifierUserSystem = new identifierUserSystem();
         $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier();
         //多用户系统
         $this->memberCredits->setJoin(' LEFT JOIN ' . DB_PREFIX . 'member as m ON m.member_id = mc.u_id');
         $condition = " AND m.identifier = " . $identifier;
         $this->memberCredits->setWhere($condition);
     }
     $this->memberCredits->setAs('mc');
     return $condition;
 }
Esempio n. 3
0
 /**
  *
  *  获取已经邀请人数 ... ...
  * @param unknown_type $uid
  */
 private function get_Invitees_count($uid)
 {
     $_invite = new invite();
     return $_invite->select_uid_to_count($uid);
 }
 function main($id, $mode)
 {
     global $config, $db, $user, $auth, $template;
     global $phpbb_admin_path, $phpbb_root_path, $phpEx;
     include $phpbb_root_path . 'includes/functions_invite.' . $phpEx;
     $invite = new invite();
     $user->add_lang(array('mods/info_acp_invite', 'acp/email'));
     switch ($mode) {
         case 'invite':
             $submit = isset($_POST['submit']) ? true : false;
             $remove_rc = isset($_REQUEST['remove_rc']) ? true : false;
             $add_rc = isset($_REQUEST['add_rc']) ? true : false;
             $disable_form = false;
             $sent = false;
             $error = array();
             $email_ary = array();
             // CAPTCHA
             $confirm_id = request_var('confirm_id', '');
             $s_hidden_fields = $confirm_id ? array('confirm_id' => $confirm_id) : array();
             // Handle multiple recipients
             $recipient_count = (int) request_var('rc', 1);
             $recipient_count = $add_rc ? $recipient_count + 1 : $recipient_count;
             $recipient_count = $remove_rc ? $recipient_count - 1 : $recipient_count;
             $recipient_count = $recipient_count < 1 ? 1 : $recipient_count;
             $recipient_count = $invite->config['multiple_recipients_max'] <= $recipient_count ? $invite->config['multiple_recipients_max'] : $recipient_count;
             $s_hidden_fields['rc'] = $recipient_count;
             add_form_key('ucp_invite');
             // Authorised?
             if (!$invite->config['enable'] || !$invite->config['enable_invitation']) {
                 trigger_error('INVITE_DISABLED');
             }
             if (!$auth->acl_get('u_send_invite')) {
                 trigger_error('NOT_AUTHORISED');
             }
             // Oops?
             if (!$config['email_enable']) {
                 trigger_error('EMAIL_DISABLED');
             }
             // Queue?
             if ($user->data['user_invitations']) {
                 $sql = 'SELECT MAX(invite_time) AS max_time FROM ' . INVITE_LOG_TABLE . ' WHERE invite_user_id = ' . $user->data['user_id'];
                 $result = $db->sql_query($sql);
                 $last_invite = (int) $db->sql_fetchfield('max_time');
                 $db->sql_freeresult();
                 if (time() - $last_invite < $invite->config['queue_time']) {
                     $queue_time_m = floor(($invite->config['queue_time'] - (time() - $last_invite)) / 60);
                     $queue_time_s = ($invite->config['queue_time'] - (time() - $last_invite)) % 60;
                     $error[] = sprintf($user->lang['QUEUE_QUEUE'], $queue_time_m, $queue_time_s);
                     $disable_form = true;
                 }
             }
             // Reached limit?
             $limit_enabled = false;
             $limit_periods = array('limit_daily', 'limit_total');
             $limit_criteria = array('posts', 'topics', 'memberdays', 'registrations', 'referrals');
             foreach ($limit_periods as $k => $v) {
                 if ($invite->config['enable_' . $v]) {
                     $limit_enabled = true;
                 }
             }
             // Unlimited invitations?
             if ($invite->config['enable_unlimited']) {
                 $limit_enabled = false;
             }
             // Collect some statistical information
             if ($limit_enabled) {
                 // Invitations sent today (last 24h)
                 $last_day = time() - 86400;
                 $sql = 'SELECT COUNT(log_id) AS invitations_today FROM ' . INVITE_LOG_TABLE . ' WHERE invite_user_id = ' . $user->data['user_id'] . ' AND invite_time >= ' . $last_day;
                 $result = $db->sql_query($sql);
                 $user->data['user_invitations_limit_daily'] = (int) $db->sql_fetchfield('invitations_today');
                 $db->sql_freeresult();
                 // Invitations sent altogether
                 $user->data['user_invitations_limit_total'] = $user->data['user_invitations'];
                 // Number of topics created
                 $sql = 'SELECT COUNT(topic_id) AS user_topics FROM ' . TOPICS_TABLE . ' WHERE topic_poster = ' . $user->data['user_id'];
                 $result = $db->sql_query($sql);
                 $user->data['user_topics'] = (int) $db->sql_fetchfield('user_topics');
                 $db->sql_freeresult();
                 // Days of membership
                 $user->data['user_memberdays'] = floor((time() - $user->data['user_regdate']) / 86400);
                 // Calculate the available amount of invitations
                 foreach ($limit_periods as $k => $v) {
                     if ($invite->config['enable_' . $v]) {
                         $user->data['user_' . $v] = (int) $invite->config[$v . '_basic'];
                         foreach ($limit_criteria as $ck => $cv) {
                             // Don't divide by zero
                             $user->data['user_' . $v] += $invite->config[$v . '_' . $cv] == 0 ? 0 : floor($user->data['user_' . $cv] / $invite->config[$v . '_' . $cv]) * $invite->config[$v . '_' . $cv . '_invitations'];
                         }
                         // Single recipient
                         if ($user->data['user_invitations_' . $v] >= $user->data['user_' . $v]) {
                             $error[] = sprintf($user->lang['INVITATION_' . strtoupper($v)], $user->data['user_' . $v]);
                             $disable_form = true;
                         }
                         // Multiple recipients
                         if ($recipient_count > 1 && $user->data['user_invitations_' . $v] + $recipient_count > $user->data['user_' . $v]) {
                             // $reduce = $recipient_count - ($user->data['user_' . $v] - $user->data['user_invitations_' . $v]);
                             $error[] = sprintf($user->lang['REDUCE_RECIPIENTS']) . ' ' . sprintf($user->lang['INVITATION_' . strtoupper($v) . '_MULTI'], $user->data['user_invitations_' . $v], $user->data['user_' . $v], $recipient_count);
                             $disable_form = true;
                         }
                     }
                 }
             }
             // Requirements met?
             if ($user->data['user_posts'] < $invite->config['invite_required_posts']) {
                 $error[] = sprintf($user->lang['TOO_FEW_POSTS'], $invite->config['invite_required_posts']);
                 $disable_form = true;
             }
             // Set up the array containing the important information
             $email_data = array('message_type' => $INVITE_MESSAGE_TYPE['invite'], 'method' => EMAIL, 'method_user_id' => $user->data['user_id'], 'invite_language' => $invite->config['invite_language_select'] == 'opt' ? utf8_normalize_nfc(request_var('form_invite_language_select', $user->data['user_lang'], true)) : ($invite->config['invite_language_select'] == 'user' ? $user->data['user_lang'] : $invite->config['invite_language_select']), 'priority' => $invite->config['invite_priority_flag'] == MAIL_LOW_PRIORITY + 1 ? request_var('form_priority', 0) : $invite->config['invite_priority_flag'], 'subject' => utf8_normalize_nfc(request_var('form_subject', '', true)), 'message' => utf8_normalize_nfc(request_var('form_message', '', true)), 'register_key' => $invite->generate_key(), 'register_key_used' => 0, 'register_user_id' => 0, 'invite_user_id' => $user->data['user_id'], 'invite_session_ip' => $user->data['session_ip'], 'invite_time' => time(), 'expiration_time' => time() + $invite->config['invite_expiration_time'] * 86400, 'invite_zebra' => request_var('form_invite_zebra', 0), 'confirm_code' => request_var('confirm_code', ''), 'confirm_id' => request_var('confirm_id', ''));
             // Additional email data concerning the templates
             foreach ($INVITE_MESSAGE_TYPE as $string => $int) {
                 $email_data['invite_' . $string] = request_var('form_invite_' . $string, 0);
                 $email_data['invite_' . $string . '_method'] = request_var('form_invite_' . $string . '_method', 0);
             }
             // The CAPTCHA kicks in here
             if ($invite->config['invite_confirm_code']) {
                 if (!class_exists('phpbb_captcha_factory')) {
                     include $phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx;
                 }
                 $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
                 $captcha->init(CONFIRM_POST);
             }
             // Prevalidate the static data so we don't have to do it in the loop later
             if ($submit) {
                 if (!check_form_key('ucp_invite')) {
                     $error[] = 'FORM_INVALID';
                 }
                 $check_ary = array('subject' => array('string', false, $invite->config['subject_min_chars'], $invite->config['subject_max_chars']), 'message' => array('string', false, $invite->config['message_min_chars'], $invite->config['message_max_chars']));
                 $error = validate_data($email_data, $check_ary);
                 // Visual Confirmation handling
                 if ($invite->config['invite_confirm_code']) {
                     $vc_response = $captcha->validate($email_data);
                     if ($vc_response !== false) {
                         $error[] = $vc_response;
                     }
                 }
             }
             // Send out multiple invitations
             for ($i = 0; $i < $recipient_count; $i++) {
                 // Add index specific values to the data array
                 $form_register_email = utf8_normalize_nfc(request_var('form_register_email_' . $i, '', true));
                 $form_register_real_name = utf8_normalize_nfc(request_var('form_register_real_name_' . $i, '', true));
                 $email_data['register_email_' . $i] = $form_register_email;
                 $email_data['register_real_name_' . $i] = $form_register_real_name;
                 // Add every e-mail address to the referring array in order to search for multiple entries later
                 $email_ary[] = $form_register_email;
                 // No need to loop through the submit part...
                 if (sizeof($error)) {
                     continue;
                 }
                 // Do the job ...
                 if ($submit) {
                     $email_data['register_email'] = $form_register_email;
                     $email_data['register_real_name'] = $form_register_real_name;
                     // Fix language vars defined in ucp.php
                     $email_data['email'] = $email_data['register_email'];
                     // Validate index specific data
                     $check_ary = array('email' => array(array('string', false, 1, 60), array('email')), 'register_real_name' => array('string', false, 1, 60));
                     $error = validate_data($email_data, $check_ary);
                     // Fix language vars defined in ucp.php
                     unset($email_data['email']);
                     // That wouldn't make any sense...
                     if ($email_data['register_email'] == $user->data['user_email']) {
                         $error[] = $user->lang['INVITE_TO_YOUR_EMAIL'];
                     }
                     // Have our recipients received an invitation yet?
                     $sql = 'SELECT COUNT(log_id) AS multiple_invite FROM ' . INVITE_LOG_TABLE . ' WHERE register_email = "' . $email_data['register_email'] . '"';
                     $result = $db->sql_query($sql);
                     $multiple = (int) $db->sql_fetchfield('multiple_invite');
                     if ($multiple && $invite->config['invite_multiple']) {
                         $error[] = $user->lang['INVITE_MULTIPLE'];
                     }
                     if ($invite->config['invite_multiple']) {
                         $count_values = array_count_values($email_ary);
                         foreach ($count_values as $k => $v) {
                             if ($v > 1) {
                                 $error[] = $user->lang['INVITE_SAME_RECIPIENT'];
                                 break;
                             }
                         }
                     }
                     if (!sizeof($error)) {
                         $send_message = $invite->message_handle($email_data, true, false);
                         $sent = true;
                         // Email successfully sent to friend? Only check on last loop
                         if ($i == $recipient_count - 1) {
                             if ($send_message) {
                                 meta_refresh(2, append_sid("{$phpbb_root_path}index.{$phpEx}"));
                                 $message = $user->lang['EMAIL_SENT_SUCCESS'];
                             } else {
                                 $message = '<span class="error">' . $user->lang['EMAIL_SENT_FAILURE'] . '</span>';
                             }
                             $message .= '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.{$phpEx}") . '">', '</a>');
                             trigger_error($message);
                         }
                     } else {
                         // No need to highlight the correct recipient block if there's only one...
                         if ($recipient_count > 1) {
                             $template->assign_var('S_ERROR_RECIPIENT_INDEX', $i);
                         }
                     }
                 }
                 unset($email_data['register_email']);
                 unset($email_data['register_real_name']);
             }
             // Replace "error" strings with their real, localised form
             $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
             if ($invite->config['invite_confirm_code']) {
                 $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
             }
             $s_hidden_fields = build_hidden_fields($s_hidden_fields);
             $confirm_image = '';
             // Visual Confirmation - Show images
             if ($invite->config['invite_confirm_code']) {
                 $template->assign_vars(array('CAPTCHA_TEMPLATE' => $captcha->get_template()));
             }
             $template->assign_vars(array('ERROR' => sizeof($error) ? $error[0] : '', 'FORM_LANGUAGE_SELECT' => language_select($email_data['invite_language']), 'FORM_CONFIRM_IMG' => $confirm_image, 'S_ENABLE_POWERED_BY' => $invite->config['enable_powered_by'], 'S_MAIL_LOW_PRIORITY' => MAIL_LOW_PRIORITY, 'S_MAIL_NORMAL_PRIORITY' => MAIL_NORMAL_PRIORITY, 'S_MAIL_HIGH_PRIORITY' => MAIL_HIGH_PRIORITY, 'S_VALUE_EMAIL' => EMAIL, 'S_VALUE_PM' => PM, 'S_DISABLE' => $disable_form ? true : false, 'S_DISPLAY_PRIORITY' => $invite->config['invite_priority_flag'] == MAIL_LOW_PRIORITY + 1 ? true : false, 'S_DISPLAY_ZEBRA' => $invite->config['zebra'] == OPTIONAL ? true : false, 'S_DISPLAY_LANGUAGE' => $invite->config['invite_language_select'] == 'opt' ? true : false, 'S_RECIPIENTS_LIMIT' => $invite->config['multiple_recipients_max'] <= $recipient_count ? true : false, 'S_CONFIRM_REFRESH' => true, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'U_ACTION' => $this->u_action));
             // Repeat the recipient block as many times as desired
             for ($i = 0; $i < $recipient_count; $i++) {
                 $template->assign_block_vars('recipient_row', array('INDEX' => $i, 'FORM_REGISTER_EMAIL' => $email_data['register_email_' . $i], 'FORM_REGISTER_REAL_NAME' => $email_data['register_real_name_' . $i]));
             }
             // Display other message options
             foreach ($INVITE_MESSAGE_TYPE as $string => $int) {
                 // [Fix] Undefined index
                 if ($string == 'invite' || $string == 'referral') {
                     continue;
                 }
                 $template->assign_vars(array('S_DISPLAY_' . strtoupper($string) => !$invite->config[$string] ? false : ($invite->config[$string] == OPTIONAL ? true : false), 'S_DISPLAY_' . strtoupper($string) . '_METHOD' => !$invite->config[$string] ? false : ($invite->config[$string . '_method'] == OPTIONAL ? true : false)));
             }
             // Assign already existing input
             foreach ($email_data as $k => $v) {
                 $template->assign_vars(array('FORM_' . strtoupper($k) => isset($email_data[$k]) ? utf8_normalize_nfc(request_var($k, $v, true)) : ''));
             }
             break;
         case 'statistics':
             //
             break;
     }
     $this->tpl_name = 'ucp_invite_' . $mode;
     $this->page_title = 'UCP_INVITE_' . strtoupper($mode);
 }
 function print_wildcard_array($invite, $mode)
 {
     global $config, $user, $phpEx, $phpbb_root_path;
     if (!class_exists('invite')) {
         include $phpbb_root_path . 'includes/functions_invite.' . $phpEx;
     }
     $invite = new invite();
     switch ($mode) {
         case 'general':
             $wildcards['USER_SUBJECT'] = $wildcards['USER_MESSAGE'] = $user->lang['USER_DEFINED'];
             $wildcards['REGISTRATION_KEY'] = $wildcards['INVITATION_KEY'] = $wildcards['INVITATION_CODE'] = $invite->generate_key();
             $wildcards['REGISTRATION_URL'] = generate_board_url() . '/ucp.' . $phpEx . '?mode=register&key=' . $wildcards['REGISTRATION_KEY'];
             $wildcards['REFERRAL_URL'] = $wildcards['REFERRER_URL'] = $wildcards['REFERRAL_LINK'] = generate_board_url() . '/ucp.' . $phpEx . '?mode=register&referrer_id=' . urlencode($user->data['user_id']);
             $wildcards['SITENAME'] = htmlspecialchars_decode($config['sitename']);
             $wildcards['CONTACT_EMAIL'] = $config['board_contact'];
             $wildcards['BOARD_URL'] = generate_board_url();
             break;
         case 'user':
             // Show only the most important ones as there's a lot of boring crap in users table
             $user_wildcards = array('user_id', 'username', 'username_clean', 'user_ip', 'user_email', 'user_posts', 'user_lang', 'user_from', 'user_icq', 'user_aim', 'user_yim', 'user_msnm', 'user_jabber', 'user_website', 'user_occ', 'user_interests', 'user_inviter_id', 'user_inviter_name', 'user_invitations', 'user_registrations', 'user_referrals', 'user_referrer_id', 'user_referrer_name');
             $wildcards['INVITED_USER_PROFILE_URL'] = generate_board_url() . '/memberlist.' . $phpEx . '?mode=viewprofile&u=' . $user->data['user_id'];
             $wildcards['RECIPIENT_NAME'] = $user->lang['USER_DEFINED'];
             foreach ($user->data as $k => $v) {
                 if (array_search($k, $user_wildcards)) {
                     $wildcards['INVITER_' . strtoupper($k)] = $v;
                     $wildcards['INVITED_' . strtoupper($k)] = $v;
                 }
             }
             break;
         default:
             break;
     }
     return $wildcards;
 }