]> git.mxchange.org Git - friendica.git/blob - mod/register.php
Merge remote-tracking branch 'upstream/master'
[friendica.git] / mod / register.php
1 <?php
2
3 require_once('include/email.php');
4
5 if(! function_exists('register_post')) {
6 function register_post(&$a) {
7
8         global $lang;
9
10         $verified = 0;
11         $blocked  = 1;
12
13         $arr = array('post' => $_POST);
14         call_hooks('register_post', $arr);
15
16         $max_dailies = intval(get_config('system','max_daily_registrations'));
17         if($max_dailies) {
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) {
20                         return;
21                 }
22         }
23
24         switch($a->config['register_policy']) {
25
26         
27         case REGISTER_OPEN:
28                 $blocked = 0;
29                 $verified = 1;
30                 break;
31
32         case REGISTER_APPROVE:
33                 $blocked = 1;
34                 $verified = 0;
35                 break;
36
37         default:
38         case REGISTER_CLOSED:
39                 if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) {
40                         notice( t('Permission denied.') . EOL );
41                         return;
42                 }
43                 $blocked = 1;
44                 $verified = 0;
45                 break;
46         }
47     
48
49         require_once('include/user.php');
50
51         $arr = $_POST;
52
53         $arr['blocked'] = $blocked;
54         $arr['verified'] = $verified;
55
56         $result = create_user($arr);
57
58         if(! $result['success']) {
59                 notice($result['message']);
60                 return;
61         }
62
63         $user = $result['user'];
64  
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");
68         }
69
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']))  : '');
73
74
75         if( $a->config['register_policy'] == REGISTER_OPEN ) {
76
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);
80                 }
81
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'] ));
90
91                 $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
92                         $email_tpl, 
93                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
94                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
95                                 . 'Content-transfer-encoding: 8bit' );
96
97
98                 if($res) {
99                         info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
100                         goaway(z_root());
101                 }
102                 else {
103                         notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
104                 }
105         }
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);
109                         goaway(z_root());
110                 }
111
112                 $hash = random_string();
113                 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
114                         dbesc($hash),
115                         dbesc(datetime_convert()),
116                         intval($user['uid']),
117                         dbesc($result['password']),
118                         dbesc($lang)
119                 );
120
121                 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
122                         dbesc($a->config['admin_email'])
123                 );
124                 if(count($r))
125                         push_lang($r[0]['language']);
126                 else
127                         push_lang('en');
128
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);
132                 }
133
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'],
142                                 '$hash' => $hash
143                  ));
144
145                 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
146                         $email_tpl,
147                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
148                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
149                                 . 'Content-transfer-encoding: 8bit' );
150
151                 pop_lang();
152
153                 if($res) {
154                         info( t('Your registration is pending approval by the site owner.') . EOL ) ;
155                         goaway(z_root());
156                 }
157
158         }
159
160         return;
161 }}
162
163
164
165
166
167
168 if(! function_exists('register_content')) {
169 function register_content(&$a) {
170
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.
174
175         $block = get_config('system','block_extended_register');
176
177         if(local_user() && ($block)) {
178                 notice("Permission denied." . EOL);
179                 return;
180         }
181
182         if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
183                 notice("Permission denied." . EOL);
184                 return;
185         }
186
187         $max_dailies = intval(get_config('system','max_daily_registrations'));
188         if($max_dailies) {
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);
193                         return;
194                 }
195         }
196
197         if(x($_SESSION,'theme'))
198                 unset($_SESSION['theme']);
199         if(x($_SESSION,'mobile-theme'))
200                 unset($_SESSION['mobile-theme']);
201
202
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']             : ''));
209
210         $noid = get_config('system','no_openid');
211
212         if($noid) {
213                 $oidhtml = '';
214                 $fillwith = '';
215                 $fillext = '';
216                 $oidlabel = '';
217         }
218         else {
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: ");
223         }
224
225         // I set this and got even more fake names than before...
226
227         $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
228
229         if(get_config('system','publish_all')) {
230                 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
231         }
232         else {
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'),
241                 ));
242         }
243
244         $license = '';
245
246         $o = get_markup_template("register.tpl");
247
248         $arr = array('template' => $o);
249
250         call_hooks('register_form',$arr);
251
252         $o = $arr['template'];
253
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>'
264                         : "" ),
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: '),
273                 '$photo'     => $photo,
274                 '$publish'   => $profile_publish,
275                 '$regbutt'   => t('Register'),
276                 '$username'  => $username,
277                 '$email'     => $email,
278                 '$nickname'  => $nickname,
279                 '$license'   => $license,
280                 '$sitename'  => $a->get_hostname(),
281                 '$importh'   => t('Import'),
282                 '$importt'   => t('Import your profile to this friendica instance'),
283
284         ));
285         return $o;
286
287 }}
288