]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
bypass smarty wherever using intltext_templates (install, register, friend confirmati...
[friendica.git] / mod / regmod.php
1 <?php
2
3 require_once('include/email.php');
4
5 function user_allow($hash) {
6
7         $a = get_app();
8
9         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
10                 dbesc($hash)
11         );
12
13
14         if(! count($register))
15                 return false;
16
17         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
18                 intval($register[0]['uid'])
19         );
20         
21         if(! count($user))
22                 killme();
23
24         $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
25                 dbesc($register[0]['hash'])
26         );
27
28
29         $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d LIMIT 1",
30                 intval($register[0]['uid'])
31         );
32         
33         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
34                 intval($user[0]['uid'])
35         );
36         if(count($r) && $r[0]['net-publish']) {
37                 $url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
38                 if($url && strlen(get_config('system','directory_submit_url')))
39                         proc_run('php',"include/directory.php","$url");
40         }
41
42         push_lang($register[0]['language']);
43
44         $engine = get_app()->get_template_engine();
45         get_app()->set_template_engine();
46
47         $email_tpl = get_intltext_template("register_open_eml.tpl");
48         $email_tpl = replace_macros($email_tpl, array(
49                         '$sitename' => $a->config['sitename'],
50                         '$siteurl' =>  $a->get_baseurl(),
51                         '$username' => $user[0]['username'],
52                         '$email' => $user[0]['email'],
53                         '$password' => $register[0]['password'],
54                         '$uid' => $user[0]['uid']
55         ));
56
57
58         get_app()->set_template_engine($engine);
59
60
61         $res = mail($user[0]['email'], email_header_encode( sprintf(t('Registration details for %s'), $a->config['sitename']), 'UTF-8'),
62                 $email_tpl,
63                         'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
64                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
65                         . 'Content-transfer-encoding: 8bit' );
66
67         pop_lang();
68
69         if($res) {
70                 info( t('Account approved.') . EOL );
71                 return true;
72         }       
73
74 }
75
76
77 // This does not have to go through user_remove() and save the nickname
78 // permanently against re-registration, as the person was not yet
79 // allowed to have friends on this system
80
81 function user_deny($hash) {
82
83         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
84                 dbesc($hash)
85         );
86
87         if(! count($register))
88                 return false;
89
90         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
91                 intval($register[0]['uid'])
92         );
93         
94         $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
95                 intval($register[0]['uid'])
96         );
97         $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
98                 intval($register[0]['uid'])
99         ); 
100         $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
101                 intval($register[0]['uid'])
102         ); 
103
104         $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
105                 dbesc($register[0]['hash'])
106         );
107         notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
108         return true;
109         
110 }
111
112 function regmod_content(&$a) {
113
114         global $lang;
115
116         $_SESSION['return_url'] = $a->cmd;
117
118         if(! local_user()) {
119                 info( t('Please login.') . EOL);
120                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
121                 return $o;
122         }
123
124         if((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) {
125                 notice( t('Permission denied.') . EOL);
126                 return '';
127         }
128
129         if($a->argc != 3)
130                 killme();
131
132         $cmd  = $a->argv[1];
133         $hash = $a->argv[2];
134
135
136
137         if($cmd === 'deny') {
138                 if (!user_deny($hash)) killme();
139         }
140
141         if($cmd === 'allow') {
142                 if (!user_allow($hash)) killme();
143         }
144 }