Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../admin
File: class-database-proxy.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Represents the proxy for communicating with the database.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Database_Proxy {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Holds the table name.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string
[15] Fix | Delete
*/
[16] Fix | Delete
protected $table_name;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Determines whether to suppress errors or not.
[20] Fix | Delete
*
[21] Fix | Delete
* @var bool
[22] Fix | Delete
*/
[23] Fix | Delete
protected $suppress_errors = true;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Determines if this table is multisite.
[27] Fix | Delete
*
[28] Fix | Delete
* @var bool
[29] Fix | Delete
*/
[30] Fix | Delete
protected $is_multisite_table = false;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Holds the last suppressed state.
[34] Fix | Delete
*
[35] Fix | Delete
* @var bool
[36] Fix | Delete
*/
[37] Fix | Delete
protected $last_suppressed_state;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Holds the WordPress database object.
[41] Fix | Delete
*
[42] Fix | Delete
* @var wpdb
[43] Fix | Delete
*/
[44] Fix | Delete
protected $database;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Holds the table prefix.
[48] Fix | Delete
*
[49] Fix | Delete
* @var string
[50] Fix | Delete
*/
[51] Fix | Delete
protected $table_prefix;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Sets the class attributes and registers the table.
[55] Fix | Delete
*
[56] Fix | Delete
* @param wpdb $database The database object.
[57] Fix | Delete
* @param string $table_name The table name that is represented.
[58] Fix | Delete
* @param bool $suppress_errors Should the errors be suppressed.
[59] Fix | Delete
* @param bool $is_multisite_table Should the table be global in multisite.
[60] Fix | Delete
*/
[61] Fix | Delete
public function __construct( $database, $table_name, $suppress_errors = true, $is_multisite_table = false ) {
[62] Fix | Delete
$this->table_name = $table_name;
[63] Fix | Delete
$this->suppress_errors = (bool) $suppress_errors;
[64] Fix | Delete
$this->is_multisite_table = (bool) $is_multisite_table;
[65] Fix | Delete
$this->database = $database;
[66] Fix | Delete
[67] Fix | Delete
// If the table prefix was provided, strip it as it's handled automatically.
[68] Fix | Delete
$table_prefix = $this->get_table_prefix();
[69] Fix | Delete
if ( ! empty( $table_prefix ) && strpos( $this->table_name, $table_prefix ) === 0 ) {
[70] Fix | Delete
$this->table_prefix = substr( $this->table_name, strlen( $table_prefix ) );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( ! $this->is_table_registered() ) {
[74] Fix | Delete
$this->register_table();
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Inserts data into the database.
[80] Fix | Delete
*
[81] Fix | Delete
* @param array $data Data to insert.
[82] Fix | Delete
* @param array|string|null $format Formats for the data.
[83] Fix | Delete
*
[84] Fix | Delete
* @return false|int Total amount of inserted rows or false on error.
[85] Fix | Delete
*/
[86] Fix | Delete
public function insert( array $data, $format = null ) {
[87] Fix | Delete
$this->pre_execution();
[88] Fix | Delete
[89] Fix | Delete
$result = $this->database->insert( $this->get_table_name(), $data, $format );
[90] Fix | Delete
[91] Fix | Delete
$this->post_execution();
[92] Fix | Delete
[93] Fix | Delete
return $result;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Updates data in the database.
[98] Fix | Delete
*
[99] Fix | Delete
* @param array $data Data to update on the table.
[100] Fix | Delete
* @param array $where Where condition as key => value array.
[101] Fix | Delete
* @param array|string|null $format Optional. Data prepare format.
[102] Fix | Delete
* @param array|string|null $where_format Optional. Where prepare format.
[103] Fix | Delete
*
[104] Fix | Delete
* @return false|int False when the update request is invalid, int on number of rows changed.
[105] Fix | Delete
*/
[106] Fix | Delete
public function update( array $data, array $where, $format = null, $where_format = null ) {
[107] Fix | Delete
$this->pre_execution();
[108] Fix | Delete
[109] Fix | Delete
$result = $this->database->update( $this->get_table_name(), $data, $where, $format, $where_format );
[110] Fix | Delete
[111] Fix | Delete
$this->post_execution();
[112] Fix | Delete
[113] Fix | Delete
return $result;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Upserts data in the database.
[118] Fix | Delete
*
[119] Fix | Delete
* Performs an insert into and if key is duplicate it will update the existing record.
[120] Fix | Delete
*
[121] Fix | Delete
* @param array $data Data to update on the table.
[122] Fix | Delete
* @param array|null $where Unused. Where condition as key => value array.
[123] Fix | Delete
* @param array|string|null $format Optional. Data prepare format.
[124] Fix | Delete
* @param array|string|null $where_format Optional. Where prepare format.
[125] Fix | Delete
*
[126] Fix | Delete
* @return false|int False when the upsert request is invalid, int on number of rows changed.
[127] Fix | Delete
*/
[128] Fix | Delete
public function upsert( array $data, ?array $where = null, $format = null, $where_format = null ) {
[129] Fix | Delete
if ( $where_format !== null ) {
[130] Fix | Delete
_deprecated_argument( __METHOD__, '7.7.0', 'The where_format argument is deprecated' );
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
$this->pre_execution();
[134] Fix | Delete
[135] Fix | Delete
$update = [];
[136] Fix | Delete
$keys = [];
[137] Fix | Delete
$columns = array_keys( $data );
[138] Fix | Delete
foreach ( $columns as $column ) {
[139] Fix | Delete
$keys[] = '`' . $column . '`';
[140] Fix | Delete
$update[] = sprintf( '`%1$s` = VALUES(`%1$s`)', $column );
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
$query = sprintf(
[144] Fix | Delete
'INSERT INTO `%1$s` (%2$s) VALUES ( %3$s ) ON DUPLICATE KEY UPDATE %4$s',
[145] Fix | Delete
$this->get_table_name(),
[146] Fix | Delete
implode( ', ', $keys ),
[147] Fix | Delete
implode( ', ', array_fill( 0, count( $data ), '%s' ) ),
[148] Fix | Delete
implode( ', ', $update )
[149] Fix | Delete
);
[150] Fix | Delete
[151] Fix | Delete
$result = $this->database->query(
[152] Fix | Delete
$this->database->prepare(
[153] Fix | Delete
$query,
[154] Fix | Delete
array_values( $data )
[155] Fix | Delete
)
[156] Fix | Delete
);
[157] Fix | Delete
[158] Fix | Delete
$this->post_execution();
[159] Fix | Delete
[160] Fix | Delete
return $result;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Deletes a record from the database.
[165] Fix | Delete
*
[166] Fix | Delete
* @param array $where Where clauses for the query.
[167] Fix | Delete
* @param array|string|null $format Formats for the data.
[168] Fix | Delete
*
[169] Fix | Delete
* @return false|int
[170] Fix | Delete
*/
[171] Fix | Delete
public function delete( array $where, $format = null ) {
[172] Fix | Delete
$this->pre_execution();
[173] Fix | Delete
[174] Fix | Delete
$result = $this->database->delete( $this->get_table_name(), $where, $format );
[175] Fix | Delete
[176] Fix | Delete
$this->post_execution();
[177] Fix | Delete
[178] Fix | Delete
return $result;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
/**
[182] Fix | Delete
* Executes the given query and returns the results.
[183] Fix | Delete
*
[184] Fix | Delete
* @param string $query The query to execute.
[185] Fix | Delete
*
[186] Fix | Delete
* @return array|object|null The resultset
[187] Fix | Delete
*/
[188] Fix | Delete
public function get_results( $query ) {
[189] Fix | Delete
$this->pre_execution();
[190] Fix | Delete
[191] Fix | Delete
$results = $this->database->get_results( $query );
[192] Fix | Delete
[193] Fix | Delete
$this->post_execution();
[194] Fix | Delete
[195] Fix | Delete
return $results;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Creates a table to the database.
[200] Fix | Delete
*
[201] Fix | Delete
* @param array $columns The columns to create.
[202] Fix | Delete
* @param array $indexes The indexes to use.
[203] Fix | Delete
*
[204] Fix | Delete
* @return bool True when creation is successful.
[205] Fix | Delete
*/
[206] Fix | Delete
public function create_table( array $columns, array $indexes = [] ) {
[207] Fix | Delete
$create_table = sprintf(
[208] Fix | Delete
'CREATE TABLE IF NOT EXISTS %1$s ( %2$s ) %3$s',
[209] Fix | Delete
$this->get_table_name(),
[210] Fix | Delete
implode( ',', array_merge( $columns, $indexes ) ),
[211] Fix | Delete
$this->database->get_charset_collate()
[212] Fix | Delete
);
[213] Fix | Delete
[214] Fix | Delete
$this->pre_execution();
[215] Fix | Delete
[216] Fix | Delete
$is_created = (bool) $this->database->query( $create_table );
[217] Fix | Delete
[218] Fix | Delete
$this->post_execution();
[219] Fix | Delete
[220] Fix | Delete
return $is_created;
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
/**
[224] Fix | Delete
* Checks if there is an error.
[225] Fix | Delete
*
[226] Fix | Delete
* @return bool Returns true when there is an error.
[227] Fix | Delete
*/
[228] Fix | Delete
public function has_error() {
[229] Fix | Delete
return ( $this->database->last_error !== '' );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Executed before a query will be ran.
[234] Fix | Delete
*
[235] Fix | Delete
* @return void
[236] Fix | Delete
*/
[237] Fix | Delete
protected function pre_execution() {
[238] Fix | Delete
if ( $this->suppress_errors ) {
[239] Fix | Delete
$this->last_suppressed_state = $this->database->suppress_errors();
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Executed after a query has been ran.
[245] Fix | Delete
*
[246] Fix | Delete
* @return void
[247] Fix | Delete
*/
[248] Fix | Delete
protected function post_execution() {
[249] Fix | Delete
if ( $this->suppress_errors ) {
[250] Fix | Delete
$this->database->suppress_errors( $this->last_suppressed_state );
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
/**
[255] Fix | Delete
* Returns the full table name.
[256] Fix | Delete
*
[257] Fix | Delete
* @return string Full table name including prefix.
[258] Fix | Delete
*/
[259] Fix | Delete
public function get_table_name() {
[260] Fix | Delete
return $this->get_table_prefix() . $this->table_name;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Returns the prefix to use for the table.
[265] Fix | Delete
*
[266] Fix | Delete
* @return string The table prefix depending on the database context.
[267] Fix | Delete
*/
[268] Fix | Delete
protected function get_table_prefix() {
[269] Fix | Delete
if ( $this->is_multisite_table ) {
[270] Fix | Delete
return $this->database->base_prefix;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
return $this->database->get_blog_prefix();
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Registers the table with WordPress.
[278] Fix | Delete
*
[279] Fix | Delete
* @return void
[280] Fix | Delete
*/
[281] Fix | Delete
protected function register_table() {
[282] Fix | Delete
$table_name = $this->table_name;
[283] Fix | Delete
$full_table_name = $this->get_table_name();
[284] Fix | Delete
[285] Fix | Delete
$this->database->$table_name = $full_table_name;
[286] Fix | Delete
[287] Fix | Delete
if ( $this->is_multisite_table ) {
[288] Fix | Delete
$this->database->ms_global_tables[] = $table_name;
[289] Fix | Delete
return;
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
$this->database->tables[] = $table_name;
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* Checks if the table has been registered with WordPress.
[297] Fix | Delete
*
[298] Fix | Delete
* @return bool True if the table is registered, false otherwise.
[299] Fix | Delete
*/
[300] Fix | Delete
protected function is_table_registered() {
[301] Fix | Delete
if ( $this->is_multisite_table ) {
[302] Fix | Delete
return in_array( $this->table_name, $this->database->ms_global_tables, true );
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
return in_array( $this->table_name, $this->database->tables, true );
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function