]> git.mxchange.org Git - friendica.git/blob - mod/register.php
Merge pull request #904 from annando/master
[friendica.git] / mod / register.php
1 <?php
2
3 require_once('include/email.php');
4 require_once('include/bbcode.php');
5
6 if(! function_exists('register_post')) {
7 function register_post(&$a) {
8
9         global $lang;
10
11         $verified = 0;
12         $blocked  = 1;
13
14         $arr = array('post' => $_POST);
15         call_hooks('register_post', $arr);
16
17         $max_dailies = intval(get_config('system','max_daily_registrations'));
18         if($max_dailies) {
19                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
20                 if($r && $r[0]['total'] >= $max_dailies) {
21                         return;
22                 }
23         }
24
25         switch($a->config['register_policy']) {
26
27
28         case REGISTER_OPEN:
29                 $blocked = 0;
30                 $verified = 1;
31                 break;
32
33         case REGISTER_APPROVE:
34                 $blocked = 1;
35                 $verified = 0;
36                 break;
37
38         default:
39         case REGISTER_CLOSED:
40                 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
41                         notice( t('Permission denied.') . EOL );
42                         return;
43                 }
44                 $blocked = 1;
45                 $verified = 0;
46                 break;
47         }
48     
49
50         require_once('include/user.php');
51
52         $arr = $_POST;
53
54         $arr['blocked'] = $blocked;
55         $arr['verified'] = $verified;
56
57         $result = create_user($arr);
58
59         if(! $result['success']) {
60                 notice($result['message']);
61                 return;
62         }
63
64         $user = $result['user'];
65  
66         if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
67                 $url = $a->get_baseurl() . '/profile/' . $user['nickname'];
68                 proc_run('php',"include/directory.php","$url");
69         }
70
71         $using_invites = get_config('system','invitation_only');
72         $num_invites   = get_config('system','number_invites');
73         $invite_id  = ((x($_POST,'invite_id'))  ? notags(trim($_POST['invite_id']))  : '');
74
75
76         if( $a->config['register_policy'] == REGISTER_OPEN ) {
77
78                 if($using_invites && $invite_id) {
79                         q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
80                         set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
81                 }
82
83                 $email_tpl = get_intltext_template("register_open_eml.tpl");
84                 $email_tpl = replace_macros($email_tpl, array(
85                                 '$sitename' => $a->config['sitename'],
86                                 '$siteurl' =>  $a->get_baseurl(),
87                                 '$username' => $user['username'],
88                                 '$email' => $user['email'],
89                                 '$password' => $result['password'],
90                                 '$uid' => $user['uid'] ));
91
92                 $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
93                         $email_tpl, 
94                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
95                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
96                                 . 'Content-transfer-encoding: 8bit' );
97
98
99                 if($res) {
100                         info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
101                         goaway(z_root());
102                 }
103                 else {
104                         notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
105                 }
106         }
107         elseif($a->config['register_policy'] == REGISTER_APPROVE) {
108                 if(! strlen($a->config['admin_email'])) {
109                         notice( t('Your registration can not be processed.') . EOL);
110                         goaway(z_root());
111                 }
112
113                 $hash = random_string();
114                 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
115                         dbesc($hash),
116                         dbesc(datetime_convert()),
117                         intval($user['uid']),
118                         dbesc($result['password']),
119                         dbesc($lang)
120                 );
121
122                 $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
123
124                 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
125                         //dbesc($a->config['admin_email'])
126                         dbesc($adminlist[0])
127                 );
128                 if(count($r))
129                         push_lang($r[0]['language']);
130                 else
131                         push_lang('en');
132
133                 if($using_invites && $invite_id) {
134                         q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
135                         set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
136                 }
137
138                 $email_tpl = get_intltext_template("register_verify_eml.tpl");
139                 $email_tpl = replace_macros($email_tpl, array(
140                                 '$sitename' => $a->config['sitename'],
141                                 '$siteurl' =>  $a->get_baseurl(),
142                                 '$username' => $user['username'],
143                                 '$email' => $user['email'],
144                                 '$password' => $result['password'],
145                                 '$uid' => $user['uid'],
146                                 '$hash' => $hash
147                  ));
148
149                 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
150                         $email_tpl,
151                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
152                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
153                                 . 'Content-transfer-encoding: 8bit' );
154
155                 pop_lang();
156
157                 if($res) {
158                         info( t('Your registration is pending approval by the site owner.') . EOL ) ;
159                         goaway(z_root());
160                 }
161
162         }
163
164         return;
165 }}
166
167
168
169
170
171
172 if(! function_exists('register_content')) {
173 function register_content(&$a) {
174
175         // logged in users can register others (people/pages/groups)
176         // even with closed registrations, unless specifically prohibited by site policy.
177         // 'block_extended_register' blocks all registrations, period.
178
179         $block = get_config('system','block_extended_register');
180
181         if(local_user() && ($block)) {
182                 notice("Permission denied." . EOL);
183                 return;
184         }
185
186         if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
187                 notice("Permission denied." . EOL);
188                 return;
189         }
190
191         $max_dailies = intval(get_config('system','max_daily_registrations'));
192         if($max_dailies) {
193                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
194                 if($r && $r[0]['total'] >= $max_dailies) {
195                         logger('max daily registrations exceeded.');
196                         notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
197                         return;
198                 }
199         }
200
201         if(x($_SESSION,'theme'))
202                 unset($_SESSION['theme']);
203         if(x($_SESSION,'mobile-theme'))
204                 unset($_SESSION['mobile-theme']);
205
206
207         $username     = ((x($_POST,'username'))     ? $_POST['username']     : ((x($_GET,'username'))     ? $_GET['username']              : ''));
208         $email        = ((x($_POST,'email'))        ? $_POST['email']        : ((x($_GET,'email'))        ? $_GET['email']                 : ''));
209         $openid_url   = ((x($_POST,'openid_url'))   ? $_POST['openid_url']   : ((x($_GET,'openid_url'))   ? $_GET['openid_url']            : ''));
210         $nickname     = ((x($_POST,'nickname'))     ? $_POST['nickname']     : ((x($_GET,'nickname'))     ? $_GET['nickname']              : ''));
211         $photo        = ((x($_POST,'photo'))        ? $_POST['photo']        : ((x($_GET,'photo'))        ? hex2bin($_GET['photo'])        : ''));
212         $invite_id    = ((x($_POST,'invite_id'))    ? $_POST['invite_id']    : ((x($_GET,'invite_id'))    ? $_GET['invite_id']             : ''));
213
214         $noid = get_config('system','no_openid');
215
216         if($noid) {
217                 $oidhtml = '';
218                 $fillwith = '';
219                 $fillext = '';
220                 $oidlabel = '';
221         }
222         else {
223                 $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" >';
224                 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
225                 $fillext =  t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
226                 $oidlabel = t("Your OpenID \x28optional\x29: ");
227         }
228
229         // I set this and got even more fake names than before...
230
231         $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
232
233         if(get_config('system','publish_all')) {
234                 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
235         }
236         else {
237                 $publish_tpl = get_markup_template("profile_publish.tpl");
238                 $profile_publish = replace_macros($publish_tpl,array(
239                         '$instance'     => 'reg',
240                         '$pubdesc'      => t('Include your profile in member directory?'),
241                         '$yes_selected' => ' checked="checked" ',
242                         '$no_selected'  => '',
243                         '$str_yes'      => t('Yes'),
244                         '$str_no'       => t('No'),
245                 ));
246         }
247
248         $license = '';
249
250         $o = get_markup_template("register.tpl");
251
252         $arr = array('template' => $o);
253
254         call_hooks('register_form',$arr);
255
256         $o = $arr['template'];
257
258         $o = replace_macros($o, array(
259                 '$oidhtml' => $oidhtml,
260                 '$invitations' => get_config('system','invitation_only'),
261                 '$invite_desc' => t('Membership on this site is by invitation only.'),
262                 '$invite_label' => t('Your invitation ID: '),
263                 '$invite_id' => $invite_id,
264                 '$realpeople' => $realpeople,
265                 '$regtitle'  => t('Registration'),
266                 '$registertext' =>((x($a->config,'register_text'))
267                         ? bbcode($a->config['register_text'])
268                         : "" ),
269                 '$fillwith'  => $fillwith,
270                 '$fillext'   => $fillext,
271                 '$oidlabel'  => $oidlabel,
272                 '$openid'    => $openid_url,
273                 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
274                 '$addrlabel' => t('Your Email Address: '),
275                 '$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>\'.')),
276                 '$nicklabel' => t('Choose a nickname: '),
277                 '$photo'     => $photo,
278                 '$publish'   => $profile_publish,
279                 '$regbutt'   => t('Register'),
280                 '$username'  => $username,
281                 '$email'     => $email,
282                 '$nickname'  => $nickname,
283                 '$license'   => $license,
284                 '$sitename'  => $a->get_hostname(),
285                 '$importh'   => t('Import'),
286                 '$importt'   => t('Import your profile to this friendica instance'),
287
288         ));
289         return $o;
290
291 }}
292