]> git.mxchange.org Git - friendica.git/blob - mod/regmod.php
allow Smarty use on international templates
[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         $email_tpl = get_intltext_template("register_open_eml.tpl");
45         $email_tpl = replace_macros($email_tpl, array(
46                         '$sitename' => $a->config['sitename'],
47                         '$siteurl' =>  $a->get_baseurl(),
48                         '$username' => $user[0]['username'],
49                         '$email' => $user[0]['email'],
50                         '$password' => $register[0]['password'],
51                         '$uid' => $user[0]['uid']
52         ));
53
54         $res = mail($user[0]['email'], email_header_encode( sprintf(t('Registration details for %s'), $a->config['sitename']), 'UTF-8'),
55                 $email_tpl,
56                         'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
57                         . 'Content-type: text/plain; charset=UTF-8' . "\n"
58                         . 'Content-transfer-encoding: 8bit' );
59
60         pop_lang();
61
62         if($res) {
63                 info( t('Account approved.') . EOL );
64                 return true;
65         }       
66
67 }
68
69
70 // This does not have to go through user_remove() and save the nickname
71 // permanently against re-registration, as the person was not yet
72 // allowed to have friends on this system
73
74 function user_deny($hash) {
75
76         $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1",
77                 dbesc($hash)
78         );
79
80         if(! count($register))
81                 return false;
82
83         $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
84                 intval($register[0]['uid'])
85         );
86         
87         $r = q("DELETE FROM `user` WHERE `uid` = %d LIMIT 1",
88                 intval($register[0]['uid'])
89         );
90         $r = q("DELETE FROM `contact` WHERE `uid` = %d LIMIT 1",
91                 intval($register[0]['uid'])
92         ); 
93         $r = q("DELETE FROM `profile` WHERE `uid` = %d LIMIT 1",
94                 intval($register[0]['uid'])
95         ); 
96
97         $r = q("DELETE FROM `register` WHERE `hash` = '%s' LIMIT 1",
98                 dbesc($register[0]['hash'])
99         );
100         notice( sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL);
101         return true;
102         
103 }
104
105 function regmod_content(&$a) {
106
107         global $lang;
108
109         $_SESSION['return_url'] = $a->cmd;
110
111         if(! local_user()) {
112                 info( t('Please login.') . EOL);
113                 $o .= '<br /><br />' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1);
114                 return $o;
115         }
116
117         if((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) {
118                 notice( t('Permission denied.') . EOL);
119                 return '';
120         }
121
122         if($a->argc != 3)
123                 killme();
124
125         $cmd  = $a->argv[1];
126         $hash = $a->argv[2];
127
128
129
130         if($cmd === 'deny') {
131                 if (!user_deny($hash)) killme();
132         }
133
134         if($cmd === 'allow') {
135                 if (!user_allow($hash)) killme();
136         }
137 }