@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - private static function unserialize_property($property) { |
|
| 48 | - if ( ! isset($property) ) |
|
| 47 | + private static function unserialize_property( $property ) { |
|
| 48 | + if ( ! isset( $property ) ) |
|
| 49 | 49 | return; |
| 50 | 50 | |
| 51 | - if ( $unserialized_string = is_serialized($property) ) |
|
| 52 | - return unserialize($property); |
|
| 51 | + if ( $unserialized_string = is_serialized( $property ) ) |
|
| 52 | + return unserialize( $property ); |
|
| 53 | 53 | |
| 54 | 54 | return $property; |
| 55 | 55 | } |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | // "id" columns and those ending on "_id" get an index by default |
| 90 | 90 | $index = $name == 'id' || stripos( $name, '_id' ); |
| 91 | 91 | // but if the argument is set, it overrides the default |
| 92 | - if (isset($args['index'])) { |
|
| 93 | - $index = $args['index']; |
|
| 92 | + if ( isset( $args[ 'index' ] ) ) { |
|
| 93 | + $index = $args[ 'index' ]; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - static::$properties[ $class ][] = array( |
|
| 96 | + static::$properties[ $class ][ ] = array( |
|
| 97 | 97 | 'name' => $name, |
| 98 | 98 | 'type' => $type, |
| 99 | 99 | 'index' => $index, |
| 100 | - 'index_length' => isset($args['index_length']) ? $args['index_length'] : null, |
|
| 101 | - 'unique' => isset($args['unique']) ? $args['unique'] : null |
|
| 100 | + 'index_length' => isset( $args[ 'index_length' ] ) ? $args[ 'index_length' ] : null, |
|
| 101 | + 'unique' => isset( $args[ 'unique' ] ) ? $args[ 'unique' ] : null |
|
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | * @return array property names |
| 134 | 134 | */ |
| 135 | 135 | public static function property_names() { |
| 136 | - return array_map( function ( $p ) { return $p['name']; } , static::properties() ); |
|
| 136 | + return array_map( function( $p ) { return $p[ 'name' ]; } , static::properties() ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | foreach ( $row as $property => $value ) { |
| 174 | - $model->$property = static::unserialize_property($value); |
|
| 174 | + $model->$property = static::unserialize_property( $value ); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $model; |
@@ -184,15 +184,15 @@ discard block |
||
| 184 | 184 | $model = new $class(); |
| 185 | 185 | $model->flag_as_not_new(); |
| 186 | 186 | |
| 187 | - $query = $wpdb->prepare('SELECT * FROM ' . static::table_name() . ' WHERE ' . $property . ' = \'%s\' LIMIT 0,1', $value); |
|
| 188 | - $row = $wpdb->get_row($query); |
|
| 187 | + $query = $wpdb->prepare( 'SELECT * FROM ' . static::table_name() . ' WHERE ' . $property . ' = \'%s\' LIMIT 0,1', $value ); |
|
| 188 | + $row = $wpdb->get_row( $query ); |
|
| 189 | 189 | |
| 190 | 190 | if ( ! $row ) { |
| 191 | 191 | return null; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | foreach ( $row as $property => $value ) { |
| 195 | - $model->$property = static::unserialize_property($value); |
|
| 195 | + $model->$property = static::unserialize_property( $value ); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | return $model; |
@@ -215,9 +215,9 @@ discard block |
||
| 215 | 215 | $model = new $class(); |
| 216 | 216 | $model->flag_as_not_new(); |
| 217 | 217 | foreach ( $row as $property => $value ) { |
| 218 | - $model->$property = static::unserialize_property($value); |
|
| 218 | + $model->$property = static::unserialize_property( $value ); |
|
| 219 | 219 | } |
| 220 | - $models[] = $model; |
|
| 220 | + $models[ ] = $model; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | return $models; |
@@ -247,18 +247,18 @@ discard block |
||
| 247 | 247 | if ( ! is_array( $attributes ) ) |
| 248 | 248 | return false; |
| 249 | 249 | |
| 250 | - $request = filter_input_array(INPUT_POST); // Do this for security reasons |
|
| 250 | + $request = filter_input_array( INPUT_POST ); // Do this for security reasons |
|
| 251 | 251 | |
| 252 | 252 | foreach ( $attributes as $key => $value ) { |
| 253 | - if ( is_array($value) ) { |
|
| 254 | - $this->{$key} = serialize($value); |
|
| 253 | + if ( is_array( $value ) ) { |
|
| 254 | + $this->{$key} = serialize( $value ); |
|
| 255 | 255 | } else { |
| 256 | - $this->{$key} = esc_sql($value); |
|
| 256 | + $this->{$key} = esc_sql( $value ); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ( isset( $request['checkboxes'] ) && is_array( $request['checkboxes'] ) ) { |
|
| 261 | - foreach ( $request['checkboxes'] as $checkbox ) { |
|
| 260 | + if ( isset( $request[ 'checkboxes' ] ) && is_array( $request[ 'checkboxes' ] ) ) { |
|
| 261 | + foreach ( $request[ 'checkboxes' ] as $checkbox ) { |
|
| 262 | 262 | if ( isset( $attributes[ $checkbox ] ) && $attributes[ $checkbox ] === 'on' ) { |
| 263 | 263 | $this->$checkbox = 1; |
| 264 | 264 | } else { |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | // @todo this is the wrong place to do this! |
| 271 | 271 | // The feed password is the only "passphrase" which is saved. It is not encrypted! |
| 272 | 272 | // However, we keep this function for later use |
| 273 | - if ( isset( $request['passwords'] ) && is_array( $request['passwords'] ) ) { |
|
| 274 | - foreach ( $request['passwords'] as $password ) { |
|
| 273 | + if ( isset( $request[ 'passwords' ] ) && is_array( $request[ 'passwords' ] ) ) { |
|
| 274 | + foreach ( $request[ 'passwords' ] as $password ) { |
|
| 275 | 275 | $this->$password = $attributes[ $password ]; |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @param mixed $value |
| 286 | 286 | * @return (bool) query success |
| 287 | 287 | */ |
| 288 | - public function update_attribute($attribute, $value) { |
|
| 288 | + public function update_attribute( $attribute, $value ) { |
|
| 289 | 289 | global $wpdb; |
| 290 | 290 | |
| 291 | 291 | $this->$attribute = $value; |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | "UPDATE %s SET %s = '%s' WHERE id = %s", |
| 295 | 295 | static::table_name(), |
| 296 | 296 | $attribute, |
| 297 | - mysqli_real_escape_string($value), |
|
| 297 | + mysqli_real_escape_string( $value ), |
|
| 298 | 298 | $this->id |
| 299 | 299 | ); |
| 300 | 300 | |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | $this->is_new = false; |
| 341 | 341 | |
| 342 | - do_action('podlove_model_save', $this); |
|
| 343 | - do_action('podlove_model_change', $this); |
|
| 342 | + do_action( 'podlove_model_save', $this ); |
|
| 343 | + do_action( 'podlove_model_change', $this ); |
|
| 344 | 344 | |
| 345 | 345 | return $success; |
| 346 | 346 | } |
@@ -384,8 +384,8 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | $rows_affected = $wpdb->query( $sql ); |
| 386 | 386 | |
| 387 | - do_action('podlove_model_delete', $this); |
|
| 388 | - do_action('podlove_model_change', $this); |
|
| 387 | + do_action( 'podlove_model_delete', $this ); |
|
| 388 | + do_action( 'podlove_model_change', $this ); |
|
| 389 | 389 | |
| 390 | 390 | return $rows_affected !== false; |
| 391 | 391 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | global $wpdb; |
| 395 | 395 | |
| 396 | 396 | if ( $this->$p !== null && $this->$p !== '' ) { |
| 397 | - return sprintf( "%s = '%s'", $p, ( is_array($this->$p) ? serialize($this->$p) : $this->$p ) ); |
|
| 397 | + return sprintf( "%s = '%s'", $p, ( is_array( $this->$p ) ? serialize( $this->$p ) : $this->$p ) ); |
|
| 398 | 398 | } else { |
| 399 | 399 | return "$p = NULL"; |
| 400 | 400 | } |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | |
| 422 | 422 | $property_sql = array(); |
| 423 | 423 | foreach ( static::properties() as $property ) |
| 424 | - $property_sql[] = "`{$property['name']}` {$property['type']}"; |
|
| 424 | + $property_sql[ ] = "`{$property[ 'name' ]}` {$property[ 'type' ]}"; |
|
| 425 | 425 | |
| 426 | 426 | $sql = 'CREATE TABLE IF NOT EXISTS ' |
| 427 | 427 | . static::table_name() |
@@ -447,14 +447,14 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | $indices_sql = 'SHOW INDEX FROM `' . static::table_name() . '`'; |
| 449 | 449 | $indices = $wpdb->get_results( $indices_sql ); |
| 450 | - $index_columns = array_map( function($index){ return $index->Column_name; }, $indices ); |
|
| 450 | + $index_columns = array_map( function( $index ) { return $index->Column_name; }, $indices ); |
|
| 451 | 451 | |
| 452 | 452 | foreach ( static::properties() as $property ) { |
| 453 | 453 | |
| 454 | - if ( $property['index'] && ! in_array( $property['name'], $index_columns ) ) { |
|
| 455 | - $length = isset($property['index_length']) ? '(' . (int) $property['index_length'] . ')' : ''; |
|
| 456 | - $unique = isset($property['unique']) && $property['unique'] ? 'UNIQUE' : ''; |
|
| 457 | - $sql = 'ALTER TABLE `' . static::table_name() . '` ADD ' . $unique . ' INDEX `' . $property['name'] . '` (' . $property['name'] . $length . ')'; |
|
| 454 | + if ( $property[ 'index' ] && ! in_array( $property[ 'name' ], $index_columns ) ) { |
|
| 455 | + $length = isset( $property[ 'index_length' ] ) ? '(' . (int) $property[ 'index_length' ] . ')' : ''; |
|
| 456 | + $unique = isset( $property[ 'unique' ] ) && $property[ 'unique' ] ? 'UNIQUE' : ''; |
|
| 457 | + $sql = 'ALTER TABLE `' . static::table_name() . '` ADD ' . $unique . ' INDEX `' . $property[ 'name' ] . '` (' . $property[ 'name' ] . $length . ')'; |
|
| 458 | 458 | $wpdb->query( $sql ); |
| 459 | 459 | } |
| 460 | 460 | } |