PluginProbe
Redirection / 2.2.2
Redirection v2.2.2
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.2.2, at models/log.php

207 lines 5.9 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
23 class RE_Log {
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 global $wpdb;
53
54 $rows = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM {$wpdb->prefix}redirection_logs FORCE INDEX(created) ".$pager->to_limits ('redirection_id IS NOT NULL', array ('url', 'sent_to', 'ip')), ARRAY_A );
55 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
56
57 $items = array ();
58 if (count ($rows) > 0)
59 {
60 foreach ($rows AS $row)
61 $items[] = new RE_Log ($row);
62 }
63
64 return $items;
65 }
66
67 function get_by_group (&$pager, $group)
68 {
69 global $wpdb;
70
71 $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);
72 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
73
74 $items = array ();
75 if (count ($rows) > 0)
76 {
77 foreach ($rows AS $row)
78 $items[] = new RE_Log ($row);
79 }
80
81 return $items;
82 }
83
84 function get_by_module (&$pager, $module)
85 {
86 global $wpdb;
87
88 $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);
89 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
90
91 $items = array ();
92 if (count ($rows) > 0)
93 {
94 foreach ($rows AS $row)
95 $items[] = new RE_Log ($row);
96 }
97
98 return $items;
99 }
100
101 function get_by_redirect (&$pager, $redirect)
102 {
103 global $wpdb;
104
105 $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);
106 $pager->set_total ($wpdb->get_var ("SELECT FOUND_ROWS()"));
107
108 $items = array ();
109 if (count ($rows) > 0)
110 {
111 foreach ($rows AS $row)
112 $items[] = new RE_Log ($row);
113 }
114
115 return $items;
116 }
117
118 function create ($url, $target, $agent, $ip, $referrer, $redirection_id = 'NULL', $module_id = 'NULL', $group_id = 'NULL')
119 {
120 global $wpdb, $redirection;
121
122 // Add a log entry
123 $url = $wpdb->escape ($url);
124 $agent = $wpdb->escape ($agent);
125 $ip = $wpdb->escape ($ip);
126
127 // And referring URL
128 if (strlen ($referrer) > 0)
129 $referrer = "'".$wpdb->escape ($referrer)."'";
130 else
131 $referrer = 'NULL';
132
133 if ($target == '')
134 $target = 'NULL';
135 else
136 $target = "'".$wpdb->escape ($target)."'";
137
138 $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)");
139
140 // Expire old entries
141 $options = $redirection->get_options ();
142 if ($options['expire'] != 0)
143 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL ".$options['expire']." DAY)");
144 }
145
146 function show_url ($url)
147 {
148 return implode ('&#8203;/', explode ('/', substr (htmlspecialchars ($url), 0, 80))).(strlen ($url) > 80 ? '...' : '');
149 }
150
151 function delete ($id)
152 {
153 global $wpdb;
154 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE id='$id'");
155 }
156
157 function delete_404 ($pager)
158 {
159 global $wpdb;
160 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs ".$pager->to_conditions ('redirection_id IS NULL', array ('url', 'sent_to', 'ip')));
161 }
162
163 function delete_for_id ($id)
164 {
165 global $wpdb;
166 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE redirection_id='$id'");
167 }
168
169 function delete_for_group ($id)
170 {
171 global $wpdb;
172 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE group_id=$id");
173 }
174
175 function delete_for_module ($id)
176 {
177 global $wpdb;
178 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE module_id=$id");
179 }
180
181 function delete_all ($cond, $pager)
182 {
183 global $wpdb;
184
185 $sql = 'redirection_id IS NOT NULL';
186 if (!empty ($cond))
187 {
188 $sql = '';
189 foreach ($cond AS $key => $value)
190 $sql .= "$key=$value";
191 }
192
193 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs ".$pager->to_conditions ($sql, array ('url', 'sent_to', 'ip')));
194 }
195
196 function referrer ()
197 {
198 return preg_replace ('@https?://(.*?)/.*@', '$1', $this->referrer);
199 $home = get_bloginfo ('url');
200 if (substr ($this->referrer, 0, strlen ($home)) == $home)
201 return substr ($this->referrer, strlen ($home));
202 return $this->referrer;
203 }
204 }
205
206
207 ?>