PluginProbe
Redirection / 2.2.9
Redirection v2.2.9
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 / group.php

group.php in Redirection 2.2.9, at models/group.php

215 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Red_Group {
4 function Red_Group( $values = '' ) {
5 if ( is_object( $values ) ) {
6 foreach ( $values AS $key => $value ) {
7 $this->$key = $value;
8 }
9 }
10 }
11
12 /**
13 * Get list of groups
14 */
15 function get( $id ) {
16 global $wpdb;
17
18 $row = $wpdb->get_row( $wpdb->prepare( "SELECT {$wpdb->prefix}redirection_groups.*,COUNT( {$wpdb->prefix}redirection_items.id ) AS items,SUM( {$wpdb->prefix}redirection_items.last_count ) AS redirects FROM {$wpdb->prefix}redirection_groups LEFT JOIN {$wpdb->prefix}redirection_items ON {$wpdb->prefix}redirection_items.group_id={$wpdb->prefix}redirection_groups.id WHERE {$wpdb->prefix}redirection_groups.id=%d GROUP BY {$wpdb->prefix}redirection_groups.id", $id ) );
19 if ( $row )
20 return new Red_Group( $row );
21 return false;
22 }
23
24 function get_for_module( $module ) {
25 global $wpdb;
26
27 $sql = $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS {$wpdb->prefix}redirection_groups.* FROM {$wpdb->prefix}redirection_groups WHERE {$wpdb->prefix}redirection_groups.module_id=%d", $module );
28
29 $rows = $wpdb->get_results( $sql );
30 $items = array();
31 if ( count( $rows ) > 0 ) {
32 foreach( $rows AS $row ) {
33 $items[] = new Red_Group( $row );
34 }
35 }
36
37 return $items;
38 }
39
40 /**
41 * Get all groups with number of items in each group
42 * DBW
43 */
44 function get_all( $module, $pager ) {
45 global $wpdb;
46
47 $sql = $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS {$wpdb->prefix}redirection_groups.*,COUNT( {$wpdb->prefix}redirection_items.id ) AS items,SUM( {$wpdb->prefix}redirection_items.last_count ) AS redirects FROM {$wpdb->prefix}redirection_groups LEFT JOIN {$wpdb->prefix}redirection_items ON {$wpdb->prefix}redirection_items.group_id={$wpdb->prefix}redirection_groups.id WHERE {$wpdb->prefix}redirection_groups.module_id=%d", $module );
48 $sql .= str_replace( 'WHERE', 'AND', $pager->to_limits( '', array( 'name' ), '', "GROUP BY {$wpdb->prefix}redirection_groups.id" ) );
49
50 $rows = $wpdb->get_results( $sql );
51 $pager->set_total( $wpdb->get_var( "SELECT FOUND_ROWS()" ) );
52 $items = array();
53 if ( count( $rows ) > 0 ) {
54 foreach( $rows AS $row ) {
55 $items[] = new Red_Group( $row );
56 }
57 }
58
59 return $items;
60 }
61
62 /**
63 * Get list of groups
64 * DBW
65 */
66 function get_for_select() {
67 global $wpdb;
68
69 $data = array();
70 $rows = $wpdb->get_results( $wpdb->prepare( "SELECT {$wpdb->prefix}redirection_modules.name AS module_name,{$wpdb->prefix}redirection_groups.name AS group_name,{$wpdb->prefix}redirection_groups.id FROM {$wpdb->prefix}redirection_groups INNER JOIN {$wpdb->prefix}redirection_modules ON {$wpdb->prefix}redirection_modules.id={$wpdb->prefix}redirection_groups.module_id ORDER BY {$wpdb->prefix}redirection_modules.name,{$wpdb->prefix}redirection_groups.position" ) );
71 if ( $rows ) {
72 foreach ( $rows AS $row ) {
73 $data[$row->module_name][$row->id] = $row->group_name;
74 }
75 }
76
77 return $data;
78 }
79
80 /**
81 * Get first group ID
82 */
83 function get_first_id() {
84 global $wpdb;
85
86 return $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}redirection_groups ORDER BY id LIMIT 0,1" );
87 }
88
89 function create( $data ) {
90 global $wpdb;
91
92 $name = trim( $data['name'] );
93 $module = intval( $data['module_id'] );
94
95 if ( $name != '' && $module > 0 ) {
96 $position = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( * ) FROM {$wpdb->prefix}redirection_groups WHERE module_id=%d", $module ) );
97 if ( isset( $data['position'] ) )
98 $position = $data['position'];
99
100 $data = array(
101 'name' => trim( $name ),
102 'module_id' => intval( $module ),
103 'position' => intval( $position )
104 );
105
106 if ( isset( $data['status'] ) && isset( $data['position'] ) )
107 $data['status'] = $data['status'];
108
109 $wpdb->insert( $wpdb->prefix.'redirection_groups', $data );
110
111 Red_Module::flush( $module );
112 return $wpdb->insert_id;
113 }
114
115 return false;
116 }
117
118 function update( $data ) {
119 global $wpdb;
120
121 $this->tracking = isset( $data['tracking'] ) ? true : false;
122 $this->status = isset( $data['status'] ) ? 'enabled' : 'disabled';
123
124 $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'name' => $data['name'], 'status' => $this->status, 'tracking' => intval( $this->tracking ) ), array( 'id' => intval( $this->id ) ) );
125
126 Red_Module::flush( $this->module_id );
127 }
128
129 function delete( $group ) {
130 global $wpdb;
131
132 $obj = Red_Group::get( $group );
133
134 // Delete all items in this group
135 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group ) );
136
137 // Delete the group
138 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_groups WHERE id=%d", $group ) );
139
140 // Update positions
141 $rows = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}redirection_groups ORDER BY position" );
142 if ( count( $rows ) > 0 ) {
143 foreach ( $rows AS $pos => $row ) {
144 $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'position' => intval( $pos ) ), array( 'id' => intval( $row->id ) ) );
145 }
146 }
147 }
148
149 function save_order( $items, $start ) {
150 global $wpdb;
151
152 foreach ( $items AS $pos => $id ) {
153 $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'position' => $pos + $start ), array( 'id' => intval( $id ) ) );
154 }
155
156 $group = Red_Group::get( $items[0] );
157 Red_Module::flush( $group->module_id );
158 }
159
160 function move_to( $module ) {
161 global $wpdb;
162
163 $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'module_id' => intval( $module ) ), array( 'id' => $this->id ) );
164
165 Red_Module::flush( $module );
166 Red_Module::flush( $this->id );
167 }
168
169 function reset() {
170 global $wpdb;
171
172 $this->last_count = 0;
173 $this->last_access = '0000-00-00 00:00:00';
174
175 $wpdb->update( $wpdb->prefix.'redirection_items', array( 'last_count' => 0, 'last_access' => $this->last_access ), array( 'group_id' => $this->id ) );
176
177 RE_Log::delete_for_group( $this->id );
178 }
179
180 function items() {
181 if ( $this->items > 0 )
182 return sprintf( ' (%d)', $this->items );
183 return '';
184 }
185
186 function type() {
187 if ( $this->apache )
188 return '.ht';
189 return 'WP';
190 }
191
192 function tracked() {
193 if ( $this->tracking == 1 )
194 return __( 'Yes', 'redirection' );
195 return __( 'No', 'redirection' );
196 }
197
198 function toggle_status() {
199 global $wpdb;
200
201 $this->status = ( $this->status == 'enabled' ) ? 'disabled' : 'enabled';
202
203 $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'status' => $this->status ), array( 'id' => $this->id ) );
204 }
205
206 function hits() {
207 global $wpdb;
208
209 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$wpdb->prefix}redirection_logs WHERE group_id=%d", $this->id ) );
210 if ( $count > 0 )
211 return $count;
212 return 0;
213 }
214 }
215