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 $engine = get_app()->get_template_engine();
83 get_app()->set_template_engine();
86 $email_tpl = get_intltext_template("register_open_eml.tpl");
87 $email_tpl = replace_macros($email_tpl, array(
88 '$sitename' => $a->config['sitename'],
89 '$siteurl' => $a->get_baseurl(),
90 '$username' => $user['username'],
91 '$email' => $user['email'],
92 '$password' => $result['password'],
93 '$uid' => $user['uid'] ));
96 get_app()->set_template_engine($engine);
99 $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
101 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
102 . 'Content-type: text/plain; charset=UTF-8' . "\n"
103 . 'Content-transfer-encoding: 8bit' );
107 info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
111 notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
114 elseif($a->config['register_policy'] == REGISTER_APPROVE) {
115 if(! strlen($a->config['admin_email'])) {
116 notice( t('Your registration can not be processed.') . EOL);
120 $hash = random_string();
121 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
123 dbesc(datetime_convert()),
124 intval($user['uid']),
125 dbesc($result['password']),
129 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
130 dbesc($a->config['admin_email'])
133 push_lang($r[0]['language']);
137 if($using_invites && $invite_id) {
138 q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
139 set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
143 $engine = get_app()->get_template_engine();
144 get_app()->set_template_engine();
146 $email_tpl = get_intltext_template("register_verify_eml.tpl");
147 $email_tpl = replace_macros($email_tpl, array(
148 '$sitename' => $a->config['sitename'],
149 '$siteurl' => $a->get_baseurl(),
150 '$username' => $user['username'],
151 '$email' => $user['email'],
152 '$password' => $result['password'],
153 '$uid' => $user['uid'],
157 get_app()->set_template_engine($engine);
160 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
162 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
163 . 'Content-type: text/plain; charset=UTF-8' . "\n"
164 . 'Content-transfer-encoding: 8bit' );
169 info( t('Your registration is pending approval by the site owner.') . EOL ) ;
183 if(! function_exists('register_content')) {
184 function register_content(&$a) {
186 // logged in users can register others (people/pages/groups)
187 // even with closed registrations, unless specifically prohibited by site policy.
188 // 'block_extended_register' blocks all registrations, period.
190 $block = get_config('system','block_extended_register');
192 if(local_user() && ($block)) {
193 notice("Permission denied." . EOL);
197 if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
198 notice("Permission denied." . EOL);
202 $max_dailies = intval(get_config('system','max_daily_registrations'));
204 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
205 if($r && $r[0]['total'] >= $max_dailies) {
206 logger('max daily registrations exceeded.');
207 notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
212 if(x($_SESSION,'theme'))
213 unset($_SESSION['theme']);
214 if(x($_SESSION,'mobile-theme'))
215 unset($_SESSION['mobile-theme']);
218 $username = ((x($_POST,'username')) ? $_POST['username'] : ((x($_GET,'username')) ? $_GET['username'] : ''));
219 $email = ((x($_POST,'email')) ? $_POST['email'] : ((x($_GET,'email')) ? $_GET['email'] : ''));
220 $openid_url = ((x($_POST,'openid_url')) ? $_POST['openid_url'] : ((x($_GET,'openid_url')) ? $_GET['openid_url'] : ''));
221 $nickname = ((x($_POST,'nickname')) ? $_POST['nickname'] : ((x($_GET,'nickname')) ? $_GET['nickname'] : ''));
222 $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ((x($_GET,'photo')) ? hex2bin($_GET['photo']) : ''));
223 $invite_id = ((x($_POST,'invite_id')) ? $_POST['invite_id'] : ((x($_GET,'invite_id')) ? $_GET['invite_id'] : ''));
225 $noid = get_config('system','no_openid');
234 $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" >';
235 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
236 $fillext = t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
237 $oidlabel = t("Your OpenID \x28optional\x29: ");
240 // I set this and got even more fake names than before...
242 $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
244 if(get_config('system','publish_all')) {
245 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
248 $publish_tpl = get_markup_template("profile_publish.tpl");
249 $profile_publish = replace_macros($publish_tpl,array(
250 '$instance' => 'reg',
251 '$pubdesc' => t('Include your profile in member directory?'),
252 '$yes_selected' => ' checked="checked" ',
253 '$no_selected' => '',
254 '$str_yes' => t('Yes'),
255 '$str_no' => t('No'),
261 $o = get_markup_template("register.tpl");
263 $arr = array('template' => $o);
265 call_hooks('register_form',$arr);
267 $o = $arr['template'];
269 $o = replace_macros($o, array(
270 '$oidhtml' => $oidhtml,
271 '$invitations' => get_config('system','invitation_only'),
272 '$invite_desc' => t('Membership on this site is by invitation only.'),
273 '$invite_label' => t('Your invitation ID: '),
274 '$invite_id' => $invite_id,
275 '$realpeople' => $realpeople,
276 '$regtitle' => t('Registration'),
277 '$registertext' =>((x($a->config,'register_text'))
278 ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
280 '$fillwith' => $fillwith,
281 '$fillext' => $fillext,
282 '$oidlabel' => $oidlabel,
283 '$openid' => $openid_url,
284 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
285 '$addrlabel' => t('Your Email Address: '),
286 '$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>\'.')),
287 '$nicklabel' => t('Choose a nickname: '),
289 '$publish' => $profile_publish,
290 '$regbutt' => t('Register'),
291 '$username' => $username,
293 '$nickname' => $nickname,
294 '$license' => $license,
295 '$sitename' => $a->get_hostname(),