]> git.mxchange.org Git - friendica.git/blob - mod/register.php
bypass smarty wherever using intltext_templates (install, register, friend confirmati...
[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                 $engine = get_app()->get_template_engine();
83                 get_app()->set_template_engine();
84
85
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'] ));
94
95
96                 get_app()->set_template_engine($engine);
97
98
99                 $res = mail($user['email'], email_header_encode( sprintf( t('Registration details for %s'), $a->config['sitename']),'UTF-8'),
100                         $email_tpl, 
101                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
102                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
103                                 . 'Content-transfer-encoding: 8bit' );
104
105
106                 if($res) {
107                         info( t('Registration successful. Please check your email for further instructions.') . EOL ) ;
108                         goaway(z_root());
109                 }
110                 else {
111                         notice( t('Failed to send email message. Here is the message that failed.') . $email_tpl . EOL );
112                 }
113         }
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);
117                         goaway(z_root());
118                 }
119
120                 $hash = random_string();
121                 $r = q("INSERT INTO `register` ( `hash`, `created`, `uid`, `password`, `language` ) VALUES ( '%s', '%s', %d, '%s', '%s' ) ",
122                         dbesc($hash),
123                         dbesc(datetime_convert()),
124                         intval($user['uid']),
125                         dbesc($result['password']),
126                         dbesc($lang)
127                 );
128
129                 $r = q("SELECT `language` FROM `user` WHERE `email` = '%s' LIMIT 1",
130                         dbesc($a->config['admin_email'])
131                 );
132                 if(count($r))
133                         push_lang($r[0]['language']);
134                 else
135                         push_lang('en');
136
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);
140                 }
141
142
143                 $engine = get_app()->get_template_engine();
144                 get_app()->set_template_engine();
145
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'],
154                                 '$hash' => $hash
155                  ));
156
157                 get_app()->set_template_engine($engine);
158
159
160                 $res = mail($a->config['admin_email'], email_header_encode( sprintf(t('Registration request at %s'), $a->config['sitename']),'UTF-8'),
161                         $email_tpl,
162                                 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
163                                 . 'Content-type: text/plain; charset=UTF-8' . "\n"
164                                 . 'Content-transfer-encoding: 8bit' );
165
166                 pop_lang();
167
168                 if($res) {
169                         info( t('Your registration is pending approval by the site owner.') . EOL ) ;
170                         goaway(z_root());
171                 }
172
173         }
174
175         return;
176 }}
177
178
179
180
181
182
183 if(! function_exists('register_content')) {
184 function register_content(&$a) {
185
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.
189
190         $block = get_config('system','block_extended_register');
191
192         if(local_user() && ($block)) {
193                 notice("Permission denied." . EOL);
194                 return;
195         }
196
197         if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) {
198                 notice("Permission denied." . EOL);
199                 return;
200         }
201
202         $max_dailies = intval(get_config('system','max_daily_registrations'));
203         if($max_dailies) {
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);
208                         return;
209                 }
210         }
211
212         if(x($_SESSION,'theme'))
213                 unset($_SESSION['theme']);
214         if(x($_SESSION,'mobile-theme'))
215                 unset($_SESSION['mobile-theme']);
216
217
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']             : ''));
224
225         $noid = get_config('system','no_openid');
226
227         if($noid) {
228                 $oidhtml = '';
229                 $fillwith = '';
230                 $fillext = '';
231                 $oidlabel = '';
232         }
233         else {
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: ");
238         }
239
240         // I set this and got even more fake names than before...
241
242         $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.');
243
244         if(get_config('system','publish_all')) {
245                 $profile_publish_reg = '<input type="hidden" name="profile_publish_reg" value="1" />';
246         }
247         else {
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'),
256                 ));
257         }
258
259         $license = '';
260
261         $o = get_markup_template("register.tpl");
262
263         $arr = array('template' => $o);
264
265         call_hooks('register_form',$arr);
266
267         $o = $arr['template'];
268
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>'
279                         : "" ),
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: '),
288                 '$photo'     => $photo,
289                 '$publish'   => $profile_publish,
290                 '$regbutt'   => t('Register'),
291                 '$username'  => $username,
292                 '$email'     => $email,
293                 '$nickname'  => $nickname,
294                 '$license'   => $license,
295                 '$sitename'  => $a->get_hostname(),
296       
297         ));
298         return $o;
299
300 }}
301