PluginProbe
Redirection / 2.1.29
Redirection v2.1.29
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / models / log.php

log.php in Redirection 2.1.29, at models/log.php

208 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Redirection
4 *
5 * @package Redirection
6 * @author John Godley
7 * @copyright Copyright (C) John Godley
8 **/
9
10 /*
11 ============================================================================================================
12 This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13 implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
14 the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
15 consequential damages (including, but not limited to, procurement of substitute goods or services; loss of
16 use, data, or profits; or business interruption) however caused and on any theory of liability, whether in
17 contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of
18 this software, even if advised of the possibility of such damage.
19
20 For full license details see license.txt
21 ============================================================================================================ */
22 class RE_Log
23 {
24 var $id;
25 var $created;
26 var $url;
27 var $agent;
28 var $referrer;
29 var $ip;
30 var $redirection_id;
31
32 function RE_Log ($values)
33 {
34 foreach ($values AS $key => $value)
35 $this->$key = $value;
36
37 $this->created = mysql2date ('U', $this->created);
38 $this->url = stripslashes ($this->url);
39 }
40
41 function get_by_id ($id)
42 {
43 global $wpdb;
44
45 $row = $wpdb->get_row ("SELECT * FROM {$wpdb->prefix}redirection_logs WHERE id='$id'", ARRAY_A);
46 if ($row)
47 return new RE_Log ($row);
48 return false;
49 }
50
51 function get (&$pager)
52 {
53 global $wpdb;
54
55 $rows = $wpdb->get_results ("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->prefix}redirection_logs".$pager->to_limits ('redirection_id IS NOT NULL', array ('url', 'sent_to', 'ip')), ARRAY_A);
56 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
57
58 $items = array ();
59 if (count ($rows) > 0)
60 {
61 foreach ($rows AS $row)
62 $items[] = new RE_Log ($row);
63 }
64
65 return $items;
66 }
67
68 function get_by_group (&$pager, $group)
69 {
70 global $wpdb;
71
72 $rows = $wpdb->get_results ("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->prefix}redirection_logs".$pager->to_limits ("redirection_id IS NOT NULL AND group_id='".$group."'", array ('url', 'sent_to', 'ip')), ARRAY_A);
73 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
74
75 $items = array ();
76 if (count ($rows) > 0)
77 {
78 foreach ($rows AS $row)
79 $items[] = new RE_Log ($row);
80 }
81
82 return $items;
83 }
84
85 function get_by_module (&$pager, $module)
86 {
87 global $wpdb;
88
89 $rows = $wpdb->get_results ("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->prefix}redirection_logs".$pager->to_limits ("module_id='".$module."'", array ('url', 'sent_to', 'ip')), ARRAY_A);
90 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
91
92 $items = array ();
93 if (count ($rows) > 0)
94 {
95 foreach ($rows AS $row)
96 $items[] = new RE_Log ($row);
97 }
98
99 return $items;
100 }
101
102 function get_by_redirect (&$pager, $redirect)
103 {
104 global $wpdb;
105
106 $rows = $wpdb->get_results ("SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->prefix}redirection_logs".$pager->to_limits ("redirection_id=$redirect", array ('url', 'sent_to', 'ip')), ARRAY_A);
107 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
108
109 $items = array ();
110 if (count ($rows) > 0)
111 {
112 foreach ($rows AS $row)
113 $items[] = new RE_Log ($row);
114 }
115
116 return $items;
117 }
118
119 function create ($url, $target, $agent, $ip, $referrer, $redirection_id = 'NULL', $module_id = 'NULL', $group_id = 'NULL')
120 {
121 global $wpdb, $redirection;
122
123 // Add a log entry
124 $url = $wpdb->escape ($url);
125 $agent = $wpdb->escape ($agent);
126 $ip = $wpdb->escape ($ip);
127
128 // And referring URL
129 if (strlen ($referrer) > 0)
130 $referrer = "'".$wpdb->escape ($referrer)."'";
131 else
132 $referrer = 'NULL';
133
134 if ($target == '')
135 $target = 'NULL';
136 else
137 $target = "'".$wpdb->escape ($target)."'";
138
139 $wpdb->query ("INSERT INTO {$wpdb->prefix}redirection_logs (url,sent_to,created,agent,redirection_id,ip,referrer,module_id,group_id) VALUES ('$url',$target,NOW(),'$agent',$redirection_id, '$ip', $referrer, $module_id, $group_id)");
140
141 // Expire old entries
142 $options = $redirection->get_options ();
143 if ($options['expire'] != 0)
144 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL ".$options['expire']." DAY)");
145 }
146
147 function show_url ($url)
148 {
149 return implode ('&#8203;/', explode ('/', substr (htmlspecialchars ($url), 0, 80))).(strlen ($url) > 80 ? '...' : '');
150 }
151
152 function delete ($id)
153 {
154 global $wpdb;
155 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE id='$id'");
156 }
157
158 function delete_404 ($pager)
159 {
160 global $wpdb;
161 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs ".$pager->to_conditions ('redirection_id IS NULL', array ('url', 'sent_to', 'ip')));
162 }
163
164 function delete_for_id ($id)
165 {
166 global $wpdb;
167 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE redirection_id='$id'");
168 }
169
170 function delete_for_group ($id)
171 {
172 global $wpdb;
173 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE group_id=$id");
174 }
175
176 function delete_for_module ($id)
177 {
178 global $wpdb;
179 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE module_id=$id");
180 }
181
182 function delete_all ($cond, $pager)
183 {
184 global $wpdb;
185
186 $sql = 'redirection_id IS NOT NULL';
187 if (!empty ($cond))
188 {
189 $sql = '';
190 foreach ($cond AS $key => $value)
191 $sql .= "$key=$value";
192 }
193
194 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs ".$pager->to_conditions ($sql, array ('url', 'sent_to', 'ip')));
195 }
196
197 function referrer ()
198 {
199 return preg_replace ('@https?://(.*?)/.*@', '$1', $this->referrer);
200 $home = get_bloginfo ('home');
201 if (substr ($this->referrer, 0, strlen ($home)) == $home)
202 return substr ($this->referrer, strlen ($home));
203 return $this->referrer;
204 }
205 }
206
207
208 ?>