]> git.mxchange.org Git - friendica.git/blob - mod/register.php
multiple admin mails. It is now possible to define more than one admin mail address...
[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                 $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
122
123                 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
124                         //dbesc($a->config['admin_email'])
125                         dbesc($adminlist[0])
126                 );
127                 if(count($r))
128                         push_lang($r[0]['language']);
129                 else
130                         push_lang('en');
131
132                 if($using_invites && $invite_id) {
133                         q("delete * from register where hash = '%s' limit 1", dbesc($invite_id));
134                         set_pconfig($user['uid'],'system','invites_remaining',$num_invites);
135                 }
136
137                 $email_tpl = get_intltext_template("register_verify_eml.tpl");
138                 $email_tpl = replace_macros($email_tpl, array(
139                                 '$sitename' => $a->config['sitename'],
140                                 '$siteurl' =>  $a->get_baseurl(),
141                                 '$username' => $user['username'],
142                                 '$email' => $user['email'],
143                                 '$password' => $result['password'],
144                                 '$uid' => $user['uid'],
145                                 '$hash' => $hash
146                  ));
147
148                 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
149                         $email_tpl,
150                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
151                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
152                                 . 'Content-transfer-encoding: 8bit' );
153
154                 pop_lang();
155
156                 if($res) {
157                         info( t('Your registration is pending approval by the site owner.') . EOL ) ;
158                         goaway(z_root());
159                 }
160
161         }
162
163         return;
164 }}
165
166
167
168
169
170
171 if(! function_exists('register_content')) {
172 function register_content(&$a) {
173
174         // logged in users can register others (people/pages/groups)
175         // even with closed registrations, unless specifically prohibited by site policy.
176         // 'block_extended_register' blocks all registrations, period.
177
178         $block = get_config('system','block_extended_register');
179
180         if(local_user() && ($block)) {
181                 notice("Permission denied." . EOL);
182                 return;
183         }
184
185         if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
186                 notice("Permission denied." . EOL);
187                 return;
188         }
189
190         $max_dailies = intval(get_config('system','max_daily_registrations'));
191         if($max_dailies) {
192                 $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
193                 if($r && $r[0]['total'] >= $max_dailies) {
194                         logger('max daily registrations exceeded.');
195                         notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
196                         return;
197                 }
198         }
199
200         if(x($_SESSION,'theme'))
201                 unset($_SESSION['theme']);
202         if(x($_SESSION,'mobile-theme'))
203                 unset($_SESSION['mobile-theme']);
204
205
206         $username     = ((x($_POST,'username'))     ? $_POST['username']     : ((x($_GET,'username'))     ? $_GET['username']              : ''));
207         $email        = ((x($_POST,'email'))        ? $_POST['email']        : ((x($_GET,'email'))        ? $_GET['email']                 : ''));
208         $openid_url   = ((x($_POST,'openid_url'))   ? $_POST['openid_url']   : ((x($_GET,'openid_url'))   ? $_GET['openid_url']            : ''));
209         $nickname     = ((x($_POST,'nickname'))     ? $_POST['nickname']     : ((x($_GET,'nickname'))     ? $_GET['nickname']              : ''));
210         $photo        = ((x($_POST,'photo'))        ? $_POST['photo']        : ((x($_GET,'photo'))        ? hex2bin($_GET['photo'])        : ''));
211         $invite_id    = ((x($_POST,'invite_id'))    ? $_POST['invite_id']    : ((x($_GET,'invite_id'))    ? $_GET['invite_id']             : ''));
212
213         $noid = get_config('system','no_openid');
214
215         if($noid) {
216                 $oidhtml = '';
217                 $fillwith = '';
218                 $fillext = '';
219                 $oidlabel = '';
220         }
221         else {
222                 $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" >';
223                 $fillwith = t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
224                 $fillext =  t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
225                 $oidlabel = t("Your OpenID \x28optional\x29: ");
226         }
227
228         // I set this and got even more fake names than before...
229
230         $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
231
232         if(get_config('system','publish_all')) {
233                 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
234         }
235         else {
236                 $publish_tpl = get_markup_template("profile_publish.tpl");
237                 $profile_publish = replace_macros($publish_tpl,array(
238                         '$instance'     => 'reg',
239                         '$pubdesc'      => t('Include your profile in member directory?'),
240                         '$yes_selected' => ' checked="checked" ',
241                         '$no_selected'  => '',
242                         '$str_yes'      => t('Yes'),
243                         '$str_no'       => t('No'),
244                 ));
245         }
246
247         $license = '';
248
249         $o = get_markup_template("register.tpl");
250
251         $arr = array('template' => $o);
252
253         call_hooks('register_form',$arr);
254
255         $o = $arr['template'];
256
257         $o = replace_macros($o, array(
258                 '$oidhtml' => $oidhtml,
259                 '$invitations' => get_config('system','invitation_only'),
260                 '$invite_desc' => t('Membership on this site is by invitation only.'),
261                 '$invite_label' => t('Your invitation ID: '),
262                 '$invite_id' => $invite_id,
263                 '$realpeople' => $realpeople,
264                 '$regtitle'  => t('Registration'),
265                 '$registertext' =>((x($a->config,'register_text'))
266                         ? '<div class="error-message">' . $a->config['register_text'] . '</div>'
267                         : "" ),
268                 '$fillwith'  => $fillwith,
269                 '$fillext'   => $fillext,
270                 '$oidlabel'  => $oidlabel,
271                 '$openid'    => $openid_url,
272                 '$namelabel' => t('Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '),
273                 '$addrlabel' => t('Your Email Address: '),
274                 '$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>\'.')),
275                 '$nicklabel' => t('Choose a nickname: '),
276                 '$photo'     => $photo,
277                 '$publish'   => $profile_publish,
278                 '$regbutt'   => t('Register'),
279                 '$username'  => $username,
280                 '$email'     => $email,
281                 '$nickname'  => $nickname,
282                 '$license'   => $license,
283                 '$sitename'  => $a->get_hostname(),
284                 '$importh'   => t('Import'),
285                 '$importt'   => t('Import your profile to this friendica instance'),
286
287         ));
288         return $o;
289
290 }}
291