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