3 require_once('include/email.php');
5 if(! function_exists('register_post')) {
6 function register_post(&$a) {
13 $arr = array('post' => $_POST);
14 call_hooks('register_post', $arr);
16 $max_dailies = intval(get_config('system','max_daily_registrations'));
18 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
19 if($r && $r[0]['total'] >= $max_dailies) {
24 switch($a->config['register_policy']) {
32 case REGISTER_APPROVE:
39 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
40 notice( t('Permission denied.') . EOL );
49 require_once('include/user.php');
53 $arr['blocked'] = $blocked;
54 $arr['verified'] = $verified;
56 $result = create_user($arr);
58 if(! $result['success']) {
59 notice($result['message']);
63 $user = $result['user'];
65 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
66 $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
67 proc_run('php',"include/directory.php","$url");
70 $using_invites = get_config('system','invitation_only');
71 $num_invites = get_config('system','number_invites');
72 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
75 if( $a->config['register_policy'] == REGISTER_OPEN ) {
77 if($using_invites && $invite_id) {
78 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
79 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
82 $email_tpl = get_intltext_template("register_open_eml.tpl");
83 $email_tpl = replace_macros($email_tpl, array(
84 '$sitename' => $a->config['sitename'],
85 '$siteurl' => $a->get_baseurl(),
86 '$username' => $user['username'],
87 '$email' => $user['email'],
88 '$password' => $result['password'],
89 '$uid' => $user['uid'] ));
91 $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
93 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
94 . 'Content-type: text/plain; charset=UTF-8' . "\n"
95 . 'Content-transfer-encoding: 8bit' );
99 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
103 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
106 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
107 if(! strlen($a->config['admin_email'])) {
108 notice( t('Your registration can not be processed.') . EOL);
112 $hash = random_string();
113 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
115 dbesc(datetime_convert()),
116 intval($user['uid']),
117 dbesc($result['password']),
121 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
122 dbesc($a->config['admin_email'])
125 push_lang($r[0]['language']);
129 if($using_invites && $invite_id) {
130 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
131 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
134 $email_tpl = get_intltext_template("register_verify_eml.tpl");
135 $email_tpl = replace_macros($email_tpl, array(
136 '$sitename' => $a->config['sitename'],
137 '$siteurl' => $a->get_baseurl(),
138 '$username' => $user['username'],
139 '$email' => $user['email'],
140 '$password' => $result['password'],
141 '$uid' => $user['uid'],
145 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
147 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
148 . 'Content-type: text/plain; charset=UTF-8' . "\n"
149 . 'Content-transfer-encoding: 8bit' );
154 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
168 if(! function_exists('register_content')) {
169 function register_content(&$a) {
171 // logged in users can register others (people/pages/groups)
172 // even with closed registrations, unless specifically prohibited by site policy.
173 // 'block_extended_register' blocks all registrations, period.
175 $block = get_config('system','block_extended_register');
177 if(local_user() && ($block)) {
178 notice("Permission denied." . EOL);
182 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
183 notice("Permission denied." . EOL);
187 $max_dailies = intval(get_config('system','max_daily_registrations'));
189 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
190 if($r && $r[0]['total'] >= $max_dailies) {
191 logger('max daily registrations exceeded.');
192 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
197 if(x($_SESSION,'theme'))
198 unset($_SESSION['theme']);
199 if(x($_SESSION,'mobile-theme'))
200 unset($_SESSION['mobile-theme']);
203 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
204 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
205 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
206 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
207 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
208 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
210 $noid = get_config('system','no_openid');
219 $oidhtml = '<label for="register-openid" id="label-register-openid" >$oidlabel</label><input type="text" maxlength="60" size="32" name="openid_url" class="openid" id="register-openid" value="$openid" >';
220 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
221 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
222 $oidlabel = t("Your OpenID \x28optional\x29: ");
225 // I set this and got even more fake names than before...
227 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
229 if(get_config('system','publish_all')) {
230 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
233 $publish_tpl = get_markup_template("profile_publish.tpl");
234 $profile_publish = replace_macros($publish_tpl,array(
235 '$instance' => 'reg',
236 '$pubdesc' => t('Include your profile in member directory?'),
237 '$yes_selected' => ' checked="checked" ',
238 '$no_selected' => '',
239 '$str_yes' => t('Yes'),
240 '$str_no' => t('No'),
246 $o = get_markup_template("register.tpl");
248 $arr = array('template' => $o);
250 call_hooks('register_form',$arr);
252 $o = $arr['template'];
254 $o = replace_macros($o, array(
255 '$oidhtml' => $oidhtml,
256 '$invitations' => get_config('system','invitation_only'),
257 '$invite_desc' => t('Membership on this site is by invitation only.'),
258 '$invite_label' => t('Your invitation ID: '),
259 '$invite_id' => $invite_id,
260 '$realpeople' => $realpeople,
261 '$regtitle' => t('Registration'),
262 '$registertext' =>((x($a->config,'register_text'))
263 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
265 '$fillwith' => $fillwith,
266 '$fillext' => $fillext,
267 '$oidlabel' => $oidlabel,
268 '$openid' => $openid_url,
269 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
270 '$addrlabel' => t('Your Email Address: '),
271 '$nickdesc' => str_replace('$sitename',$a->get_hostname(),t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'<strong>nickname@$sitename</strong>\'.')),
272 '$nicklabel' => t('Choose a nickname: '),
274 '$publish' => $profile_publish,
275 '$regbutt' => t('Register'),
276 '$username' => $username,
278 '$nickname' => $nickname,
279 '$license' => $license,
280 '$sitename' => $a->get_hostname(),