A lot rewrites from double-quote to single-quote, some fixes for extension handling...
[mailer.git] / inc / libs / removeip_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/01/2008 *
4  * ===============                              Last change: 10/01/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : removeip_functions.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Special functions for removeip extension         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Spezielle Funktion fuer removeip-Erweiterung     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 // "Getter" for anonymous remote IP number
46 function GET_ANONYMOUS_REMOTE_ADDR ($remoteAddr) {
47         // Is config enabled?
48         if (getConfig('removeip_anon_ip') == 'Y') {
49                 // Switch way do we like?
50                 switch (getConfig('anonymous_ip')) {
51                         case "127.0.0.1": // mod_removeip style
52                         case "0.0.0.0": // Some people may prefer this...
53                                 $remoteAddr = getConfig('anonymous_ip');
54                                 break;
55
56                         case "RANDOM": // Pseudo-random IP number
57                                 $remoteAddr = mt_rand(1,254).".".mt_rand(0,254).".".mt_rand(0,254).".".mt_rand(1,254);
58                                 break;
59                 } // END - switch
60         } // END - if
61
62         // Return it
63         return $remoteAddr;
64 }
65 // "Getter" for anonymous remote hostname
66 function GET_ANONYMOUS_REMOTE_HOST ($remoteHost) {
67         // Is config enabled?
68         if (getConfig('removeip_anon_host') == 'Y') {
69                 // Set anon hostname
70                 $remoteHost = "localhost.localnet";
71         } // END - if
72
73         // Return it
74         return $remoteHost;
75 }
76 // "Getter" for anonymous user agent
77 function GET_ANONYMOUS_USER_AGENT ($userAgent) {
78         // Is config enabled?
79         if (getConfig('removeip_anon_ua') == 'Y') {
80                 // Set anon user agent
81                 $userAgent = "-";
82         } // END - if
83
84         // Return it
85         return $userAgent;
86 }
87 // "Getter" for anonymous referer
88 function GET_ANONYMOUS_REFERER ($referer) {
89         // Is config enabled?
90         if (getConfig('removeip_anon_ref') == 'Y') {
91                 // Set anon user agent
92                 $referer = "-";
93         } // END - if
94
95         // Return it
96         return $referer;
97 }
98 // Adds informations about anonymity/privacy to the menu
99 function REMOVEIP_ADD_INFOS () {
100         // "Base-privacy" is by default low (we add more later)
101         $anonymity = 0;
102
103         // Is some data anonymized?
104         if (getConfig('removeip_anon_ip')   == 'Y') $anonymity++;
105         if (getConfig('removeip_anon_host') == 'Y') $anonymity++;
106         if (getConfig('removeip_anon_ua')   == 'Y') $anonymity++;
107         if (getConfig('removeip_anon_ref')  == 'Y') $anonymity++;
108
109         // Calculate anonymity level
110         $level = round($anonymity / 4 * 3);
111
112         // Set constant name suffix depending on that level
113         $suffix = "unsupported_{$level}";
114         switch ($level) {
115                 case 0:
116                         $suffix = "none";
117                         break;
118
119                 case 1:
120                         $suffix = "low";
121                         break;
122
123                 case 2:
124                         $suffix = "medium";
125                         break;
126
127                 case 3: // High level
128                         $suffix = "high";
129                         break;
130         } // END - while
131
132         // Construct constant name
133         $constantName = strtoupper(sprintf("REMOVEIP_LEVEL_%s", $suffix));
134
135         // Default message
136         $message = sprintf(REMOVEIP_UNKNOWN_LEVEL, $suffix);
137
138         // Is that constant there?
139         if (defined($constantName)) {
140                 // Use that string
141                 $message = constant($constantName);
142         } // END - if
143
144         // Output message in template
145         return LOAD_TEMPLATE("removeip_level", true, $message);
146 }
147
148 // Filter for adding anonymity notice to the output stream
149 function FILTER_ADD_ANONYMITY_NOTICE ($data) {
150         // Init content
151         $content = $data;
152
153         // Extension removeip activated?
154         if ((EXT_IS_ACTIVE('removeip')) && (getConfig('removeip_'.strtolower($data['access_level']).'_show') == 'Y')) {
155                 // Add anoymity/privacy infos
156                 $content['content'] .= REMOVEIP_ADD_INFOS()."<br />\n";
157         } // END - if
158
159         // Return it
160         return $content;
161 }
162
163 //
164 ?>