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