3 if(! function_exists('register_post')) {
4 function register_post(&$a) {
11 $arr = array('post' => $_POST);
12 call_hooks('register_post', $arr);
14 $max_dailies = intval(get_config('system','max_daily_registrations'));
16 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
17 if($r && $r[0]['total'] >= $max_dailies) {
22 switch($a->config['register_policy']) {
30 case REGISTER_APPROVE:
37 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
38 notice( t('Permission denied.') . EOL );
47 require_once('include/user.php');
51 $arr['blocked'] = $blocked;
52 $arr['verified'] = $verified;
54 $result = create_user($arr);
56 if(! $result['success']) {
57 notice($result['message']);
61 $user = $result['user'];
63 if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
64 $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
65 proc_run('php',"include/directory.php","$url");
68 $using_invites = get_config('system','invitation_only');
69 $num_invites = get_config('system','number_invites');
70 $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : '');
73 if( $a->config['register_policy'] == REGISTER_OPEN ) {
75 if($using_invites && $invite_id) {
76 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
77 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
80 $email_tpl = get_intltext_template("register_open_eml.tpl");
81 $email_tpl = replace_macros($email_tpl, array(
82 '$sitename' => $a->config['sitename'],
83 '$siteurl' => $a->get_baseurl(),
84 '$username' => $user['username'],
85 '$email' => $user['email'],
86 '$password' => $result['password'],
87 '$uid' => $user['uid'] ));
89 $res = mail($user['email'], sprintf(t('Registration details for %s'), $a->config['sitename']),
91 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
92 . 'Content-type: text/plain; charset=UTF-8' . "\n"
93 . 'Content-transfer-encoding: 8bit' );
97 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
101 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
104 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
105 if(! strlen($a->config['admin_email'])) {
106 notice( t('Your registration can not be processed.') . EOL);
110 $hash = random_string();
111 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
113 dbesc(datetime_convert()),
114 intval($user['uid']),
115 dbesc($result['password']),
119 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
120 dbesc($a->config['admin_email'])
123 push_lang($r[0]['language']);
127 if($using_invites && $invite_id) {
128 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
129 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
132 $email_tpl = get_intltext_template("register_verify_eml.tpl");
133 $email_tpl = replace_macros($email_tpl, array(
134 '$sitename' => $a->config['sitename'],
135 '$siteurl' => $a->get_baseurl(),
136 '$username' => $user['username'],
137 '$email' => $user['email'],
138 '$password' => $result['password'],
139 '$uid' => $user['uid'],
143 $res = mail($a->config['admin_email'], sprintf(t('Registration request at %s'), $a->config['sitename']),
145 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
146 . 'Content-type: text/plain; charset=UTF-8' . "\n"
147 . 'Content-transfer-encoding: 8bit' );
152 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
166 if(! function_exists('register_content')) {
167 function register_content(&$a) {
169 // logged in users can register others (people/pages/groups)
170 // even with closed registrations, unless specifically prohibited by site policy.
171 // 'block_extended_register' blocks all registrations, period.
173 $block = get_config('system','block_extended_register');
175 if(local_user() && ($block)) {
176 notice("Permission denied." . EOL);
180 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
181 notice("Permission denied." . EOL);
185 $max_dailies = intval(get_config('system','max_daily_registrations'));
187 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
188 if($r && $r[0]['total'] >= $max_dailies) {
189 logger('max daily registrations exceeded.');
190 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
195 if(x($_SESSION,'theme'))
196 unset($_SESSION['theme']);
197 if(x($_SESSION,'mobile-theme'))
198 unset($_SESSION['mobile-theme']);
201 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
202 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
203 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
204 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
205 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
206 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
208 $noid = get_config('system','no_openid');
217 $oidhtml = '<label for="register-openid" id="label-register-openid" >%s</label><input type="text" maxlength="60" size="32" name="openid_url" class="openid" id="register-openid" value="%s" >';
218 $oidhtml_old = '<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" >';
219 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
220 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
221 $oidlabel = t("Your OpenID \x28optional\x29: ");
224 // I set this and got even more fake names than before...
226 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
228 if(get_config('system','publish_all')) {
229 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
232 $publish_tpl = get_markup_template("profile_publish.tpl");
233 $profile_publish = replace_macros($publish_tpl,array(
234 '$instance' => 'reg',
235 '$pubdesc' => t('Include your profile in member directory?'),
236 '$yes_selected' => ' checked="checked" ',
237 '$no_selected' => '',
238 '$str_yes' => t('Yes'),
239 '$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 '$oidhtml_old' => $oidhtml_old,
257 '$invitations' => get_config('system','invitation_only'),
258 '$invite_desc' => t('Membership on this site is by invitation only.'),
259 '$invite_label' => t('Your invitation ID: '),
260 '$invite_id' => $invite_id,
261 '$realpeople' => $realpeople,
262 '$regtitle' => t('Registration'),
263 '$registertext' =>((x($a->config,'register_text'))
264 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
266 '$fillwith' => $fillwith,
267 '$fillext' => $fillext,
268 '$oidlabel' => $oidlabel,
269 '$openid' => $openid_url,
270 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
271 '$addrlabel' => t('Your Email Address: '),
272 '$nickdesc' => 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>\'.'),
273 '$nicklabel' => t('Choose a nickname: '),
275 '$publish' => $profile_publish,
276 '$regbutt' => t('Register'),
277 '$username' => $username,
279 '$nickname' => $nickname,
280 '$license' => $license,
281 '$sitename' => $a->get_hostname(),