PluginProbe
Redirection / 2.2.12
Redirection v2.2.12
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.12, at models/log.php

191 lines 5.5 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 global $wpdb, $redirection;
120
121 $wpdb->query( $wpdb->prepare( "INSERT INTO {$wpdb->prefix}redirection_logs (url,sent_to,created,agent,redirection_id,ip,referrer,module_id,group_id) VALUES (%s,%s,NOW(),%s,%d,%s,%s,%d,%d)", $url, $target, $agent, $redirection_id, $ip, $referrer, $module_id, $group_id ) );
122
123 // Expire old entries
124 $options = $redirection->get_options ();
125 if ($options['expire'] != 0)
126 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL ".$options['expire']." DAY)");
127 }
128
129 function show_url ($url)
130 {
131 return implode ('&#8203;/', explode ('/', substr (esc_html ($url), 0, 80))).(strlen ($url) > 80 ? '...' : '');
132 }
133
134 function delete ($id)
135 {
136 global $wpdb;
137 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE id='$id'");
138 }
139
140 function delete_404 ($pager)
141 {
142 global $wpdb;
143 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs ".$pager->to_conditions ('redirection_id IS NULL', array ('url', 'sent_to', 'ip')));
144 }
145
146 function delete_for_id ($id)
147 {
148 global $wpdb;
149 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE redirection_id='$id'");
150 }
151
152 function delete_for_group ($id)
153 {
154 global $wpdb;
155 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE group_id=$id");
156 }
157
158 function delete_for_module ($id)
159 {
160 global $wpdb;
161 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs WHERE module_id=$id");
162 }
163
164 function delete_all ($cond, $pager)
165 {
166 global $wpdb;
167
168 $sql = 'redirection_id IS NOT NULL';
169 if (!empty ($cond))
170 {
171 $sql = '';
172 foreach ($cond AS $key => $value)
173 $sql .= "$key=$value";
174 }
175
176 $wpdb->query ("DELETE FROM {$wpdb->prefix}redirection_logs ".$pager->to_conditions ($sql, array ('url', 'sent_to', 'ip')));
177 }
178
179 function referrer ()
180 {
181 return preg_replace ('@https?://(.*?)/.*@', '$1', $this->referrer);
182 $home = get_bloginfo ('url');
183 if (substr ($this->referrer, 0, strlen ($home)) == $home)
184 return substr ($this->referrer, strlen ($home));
185 return $this->referrer;
186 }
187 }
188
189
190 ?>
191