| @@ -2,19 +2,21 @@ | ||
| 2 | 2 | |
| 3 | 3 | class Red_Group { |
| 4 | 4 | private $items = 0; |
| 5 | 5 | private $name; |
| 6 | + private $tracking; | |
| 6 | 7 | private $module_id; |
| 7 | 8 | private $status; |
| 8 | 9 | private $position; |
| 9 | 10 | |
| 10 | - public function __construct( $values = '' ) { | |
| 11 | + public function __construct( $values = '' ) { | |
| 11 | 12 | if ( is_object( $values ) ) { |
| 12 | - $this->name = $values->name; | |
| 13 | - $this->module_id = intval( $values->module_id, 10 ); | |
| 14 | - $this->status = $values->status; | |
| 15 | - $this->id = intval( $values->id, 10 ); | |
| 16 | - $this->position = intval( $values->position, 10 ); | |
| 13 | + foreach ( $values as $key => $value ) { | |
| 14 | + $this->$key = $value; | |
| 15 | + } | |
| 16 | + | |
| 17 | + $this->id = intval( $this->id, 10 ); | |
| 18 | + $this->module_id = intval( $this->module_id, 10 ); | |
| 17 | 19 | } |
| 18 | 20 | } |
| 19 | 21 | |
| 20 | 22 | public function get_name() { |
| @@ -92,9 +94,9 @@ | ||
| 92 | 94 | |
| 93 | 95 | static function create( $name, $module_id ) { |
| 94 | 96 | global $wpdb; |
| 95 | 97 | |
| 96 | - $name = trim( substr( $name, 0, 50 ) ); | |
| 98 | + $name = trim( substr( stripslashes( $name ), 0, 50 ) ); | |
| 97 | 99 | $module_id = intval( $module_id, 10 ); |
| 98 | 100 | |
| 99 | 101 | if ( $name !== '' && Red_Module::is_valid_id( $module_id ) ) { |
| 100 | 102 | $position = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( * ) FROM {$wpdb->prefix}redirection_groups WHERE module_id=%d", $module_id ) ); |
| @@ -104,9 +106,9 @@ | ||
| 104 | 106 | 'module_id' => intval( $module_id ), |
| 105 | 107 | 'position' => intval( $position ), |
| 106 | 108 | ); |
| 107 | 109 | |
| 108 | - $wpdb->insert( $wpdb->prefix . 'redirection_groups', $data ); | |
| 110 | + $wpdb->insert( $wpdb->prefix.'redirection_groups', $data ); | |
| 109 | 111 | |
| 110 | 112 | return Red_Group::get( $wpdb->insert_id ); |
| 111 | 113 | } |
| 112 | 114 | |
| @@ -116,15 +118,15 @@ | ||
| 116 | 118 | public function update( $data ) { |
| 117 | 119 | global $wpdb; |
| 118 | 120 | |
| 119 | 121 | $old_id = $this->module_id; |
| 120 | - $this->name = trim( wp_kses( $data['name'], array() ) ); | |
| 122 | + $this->name = trim( wp_kses( stripslashes( $data['name'] ), array() ) ); | |
| 121 | 123 | |
| 122 | 124 | if ( Red_Module::is_valid_id( intval( $data['moduleId'], 10 ) ) ) { |
| 123 | 125 | $this->module_id = intval( $data['moduleId'], 10 ); |
| 124 | 126 | } |
| 125 | 127 | |
| 126 | - $wpdb->update( $wpdb->prefix . 'redirection_groups', array( 'name' => $this->name, 'module_id' => $this->module_id ), array( 'id' => intval( $this->id ) ) ); | |
| 128 | + $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'name' => $this->name, 'module_id' => $this->module_id ), array( 'id' => intval( $this->id ) ) ); | |
| 127 | 129 | |
| 128 | 130 | if ( $old_id !== $this->module_id ) { |
| 129 | 131 | Red_Module::flush_by_module( $old_id ); |
| 130 | 132 | Red_Module::flush_by_module( $this->module_id ); |
| @@ -143,11 +145,10 @@ | ||
| 143 | 145 | |
| 144 | 146 | // Delete the group |
| 145 | 147 | $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_groups WHERE id=%d", $this->id ) ); |
| 146 | 148 | |
| 147 | - if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) === 0 ) { | |
| 148 | - $wpdb->insert( $wpdb->prefix . 'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) ); | |
| 149 | - } | |
| 149 | + if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) === 0 ) | |
| 150 | + $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) ); | |
| 150 | 151 | } |
| 151 | 152 | |
| 152 | 153 | public function get_total_redirects() { |
| 153 | 154 | global $wpdb; |
| @@ -157,10 +158,10 @@ | ||
| 157 | 158 | |
| 158 | 159 | public function enable() { |
| 159 | 160 | global $wpdb; |
| 160 | 161 | |
| 161 | - $wpdb->update( $wpdb->prefix . 'redirection_groups', array( 'status' => 'enabled' ), array( 'id' => $this->id ) ); | |
| 162 | - $wpdb->update( $wpdb->prefix . 'redirection_items', array( 'status' => 'enabled' ), array( 'group_id' => $this->id ) ); | |
| 162 | + $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'status' => 'enabled' ), array( 'id' => $this->id ) ); | |
| 163 | + $wpdb->update( $wpdb->prefix.'redirection_items', array( 'status' => 'enabled' ), array( 'group_id' => $this->id ) ); | |
| 163 | 164 | |
| 164 | 165 | Red_Module::flush( $this->id ); |
| 165 | 166 | } |
| 166 | 167 | |
| @@ -166,10 +167,10 @@ | ||
| 166 | 167 | |
| 167 | 168 | public function disable() { |
| 168 | 169 | global $wpdb; |
| 169 | 170 | |
| 170 | - $wpdb->update( $wpdb->prefix . 'redirection_groups', array( 'status' => 'disabled' ), array( 'id' => $this->id ) ); | |
| 171 | - $wpdb->update( $wpdb->prefix . 'redirection_items', array( 'status' => 'disabled' ), array( 'group_id' => $this->id ) ); | |
| 171 | + $wpdb->update( $wpdb->prefix.'redirection_groups', array( 'status' => 'disabled' ), array( 'id' => $this->id ) ); | |
| 172 | + $wpdb->update( $wpdb->prefix.'redirection_items', array( 'status' => 'disabled' ), array( 'group_id' => $this->id ) ); | |
| 172 | 173 | |
| 173 | 174 | Red_Module::flush( $this->id ); |
| 174 | 175 | } |
| 175 | 176 | |
| @@ -185,10 +186,10 @@ | ||
| 185 | 186 | $limit = RED_DEFAULT_PER_PAGE; |
| 186 | 187 | $offset = 0; |
| 187 | 188 | $where = ''; |
| 188 | 189 | |
| 189 | - if ( isset( $params['orderby'] ) && in_array( $params['orderby'], array( 'name' ), true ) ) { | |
| 190 | - $orderby = $params['orderby']; | |
| 190 | + if ( isset( $params['orderBy'] ) && in_array( $params['orderBy'], array( 'name' ), true ) ) { | |
| 191 | + $orderby = $params['orderBy']; | |
| 191 | 192 | } |
| 192 | 193 | |
| 193 | 194 | if ( isset( $params['direction'] ) && in_array( $params['direction'], array( 'asc', 'desc' ), true ) ) { |
| 194 | 195 | $direction = strtoupper( $params['direction'] ); |
| @@ -195,16 +196,16 @@ | ||
| 195 | 196 | } |
| 196 | 197 | |
| 197 | 198 | if ( isset( $params['filter'] ) && strlen( $params['filter'] ) > 0 ) { |
| 198 | 199 | if ( isset( $params['filterBy'] ) && $params['filterBy'] === 'module' ) { |
| 199 | - $where = $wpdb->prepare( 'WHERE module_id=%d', intval( $params['filter'], 10 ) ); | |
| 200 | + $where = $wpdb->prepare( "WHERE module_id=%d", intval( $params['filter'], 10 ) ); | |
| 200 | 201 | } else { |
| 201 | - $where = $wpdb->prepare( 'WHERE name LIKE %s', '%' . $wpdb->esc_like( trim( $params['filter'] ) ) . '%' ); | |
| 202 | + $where = $wpdb->prepare( 'WHERE name LIKE %s', '%'.$wpdb->esc_like( trim( $params['filter'] ) ).'%' ); | |
| 202 | 203 | } |
| 203 | 204 | } |
| 204 | 205 | |
| 205 | - if ( isset( $params['per_page'] ) ) { | |
| 206 | - $limit = intval( $params['per_page'], 10 ); | |
| 206 | + if ( isset( $params['perPage'] ) ) { | |
| 207 | + $limit = intval( $params['perPage'], 10 ); | |
| 207 | 208 | $limit = min( RED_MAX_PER_PAGE, $limit ); |
| 208 | 209 | $limit = max( 5, $limit ); |
| 209 | 210 | } |
| 210 | 211 | |
| @@ -213,25 +214,18 @@ | ||
| 213 | 214 | $offset = max( 0, $offset ); |
| 214 | 215 | $offset *= $limit; |
| 215 | 216 | } |
| 216 | 217 | |
| 217 | - $rows = $wpdb->get_results( | |
| 218 | - "SELECT * FROM {$wpdb->prefix}redirection_groups $where " . $wpdb->prepare( "ORDER BY $orderby $direction LIMIT %d,%d", $offset, $limit ) | |
| 219 | - ); | |
| 220 | - $total_items = intval( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups " . $where ) ); | |
| 218 | + $table = $wpdb->prefix.'redirection_groups'; | |
| 219 | + $sql = trim( "SELECT * FROM {$table} $where " ).$wpdb->prepare( " ORDER BY $orderby $direction LIMIT %d,%d", $offset, $limit ); | |
| 220 | + | |
| 221 | + $rows = $wpdb->get_results( $sql ); | |
| 222 | + $total_items = intval( $wpdb->get_var( "SELECT COUNT(*) FROM {$table} ".$where ) ); | |
| 221 | 223 | $items = array(); |
| 222 | 224 | |
| 223 | - $options = red_get_options(); | |
| 224 | - | |
| 225 | 225 | foreach ( $rows as $row ) { |
| 226 | 226 | $group = new Red_Group( $row ); |
| 227 | - $group_json = $group->to_json(); | |
| 228 | - | |
| 229 | - if ( $group->get_id() === $options['last_group_id'] ) { | |
| 230 | - $group_json['default'] = true; | |
| 231 | - } | |
| 232 | - | |
| 233 | - $items[] = $group_json; | |
| 227 | + $items[] = $group->to_json(); | |
| 234 | 228 | } |
| 235 | 229 | |
| 236 | 230 | return array( |
| 237 | 231 | 'items' => $items, |