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/network-.../componen.../db/category
File: NetsPostsCategoryQuery.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Created by PhpStorm.
[2] Fix | Delete
* User: admin
[3] Fix | Delete
* Date: 28.03.2019
[4] Fix | Delete
* Time: 10:55
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
namespace NetworkPosts\DB\Category;
[8] Fix | Delete
[9] Fix | Delete
use NetworkPosts\Components\DB\NetsPostsTemporaryTableManager;
[10] Fix | Delete
use NetworkPosts\db\NetsPostsDbHelper;
[11] Fix | Delete
use WPDB;
[12] Fix | Delete
[13] Fix | Delete
class NetsPostsCategoryQuery {
[14] Fix | Delete
[15] Fix | Delete
const COLUMNS = array(
[16] Fix | Delete
'post_id' => 'BIGINT UNSIGNED',
[17] Fix | Delete
'name' => 'VARCHAR(200)',
[18] Fix | Delete
'slug' => 'VARCHAR(200)',
[19] Fix | Delete
'taxonomy'=> 'VARCHAR(32)',
[20] Fix | Delete
'blog_id' => 'SMALLINT',
[21] Fix | Delete
);
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* @var WPDB
[25] Fix | Delete
*/
[26] Fix | Delete
private $db;
[27] Fix | Delete
private $blogs = array();
[28] Fix | Delete
[29] Fix | Delete
private $taxonomy_offsets = array();
[30] Fix | Delete
private $inclusion_mode;
[31] Fix | Delete
[32] Fix | Delete
private $tmp_tables_mgr;
[33] Fix | Delete
private $category_query_builder;
[34] Fix | Delete
private $category_filter_builder;
[35] Fix | Delete
[36] Fix | Delete
public function __construct( WPDB $db ) {
[37] Fix | Delete
$this->db = $db;
[38] Fix | Delete
$this->tmp_tables_mgr = new NetsPostsTemporaryTableManager( $db );
[39] Fix | Delete
$this->category_query_builder = new NetsPostsCategoryQueryBuilder( $db->base_prefix );
[40] Fix | Delete
$this->category_filter_builder = new NetsPostsCategoryResultsFilterBuilder( $db->base_prefix );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
public function include_blogs( array $blogs ): void {
[44] Fix | Delete
$this->blogs = $blogs;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
protected function set_taxonomy( array $taxonomy ): void {
[48] Fix | Delete
$taxonomy = array_unique( $taxonomy );
[49] Fix | Delete
$this->category_query_builder->set_taxonomy( $taxonomy );
[50] Fix | Delete
$this->category_filter_builder->set_taxonomy_count( count( $taxonomy ) );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
public function set_taxonomy_type( array $taxonomy ) {
[54] Fix | Delete
$types = array();
[55] Fix | Delete
foreach( $taxonomy as $type ) {
[56] Fix | Delete
$type = strtolower( $type );
[57] Fix | Delete
switch ( $type ) {
[58] Fix | Delete
case 'tag':
[59] Fix | Delete
$taxonomy_type_value = 'post_tag';
[60] Fix | Delete
break;
[61] Fix | Delete
case 'category':
[62] Fix | Delete
$taxonomy_type_value = 'category';
[63] Fix | Delete
break;
[64] Fix | Delete
case 'product_tag':
[65] Fix | Delete
$taxonomy_type_value = 'product_tag';
[66] Fix | Delete
break;
[67] Fix | Delete
case 'product_category':
[68] Fix | Delete
$taxonomy_type_value = 'product_cat';
[69] Fix | Delete
break;
[70] Fix | Delete
default:
[71] Fix | Delete
$taxonomy_type_value = $type;
[72] Fix | Delete
}
[73] Fix | Delete
$types[] = $taxonomy_type_value;
[74] Fix | Delete
}
[75] Fix | Delete
$this->category_query_builder->set_taxonomy_types( $types );
[76] Fix | Delete
$this->category_filter_builder->set_taxonomy_types( $types );
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
public function clear_taxonomy_types(): void {
[80] Fix | Delete
$this->category_query_builder->set_taxonomy_types( array() );
[81] Fix | Delete
$this->category_filter_builder->set_taxonomy_types( array() );
[82] Fix | Delete
}
[83] Fix | Delete
public function offset_taxonomy( $taxonomy, int $offset ) {
[84] Fix | Delete
$this->taxonomy_offsets[$taxonomy] = $offset;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* @param $taxonomy
[90] Fix | Delete
* @param int $mode
[91] Fix | Delete
*
[92] Fix | Delete
* @return string
[93] Fix | Delete
* @throws \Exception
[94] Fix | Delete
*/
[95] Fix | Delete
public function get_query_table( $taxonomy, $mode = CategoryInclusionMode::INCLUDE_ANY ): string {
[96] Fix | Delete
$this->set_taxonomy( $taxonomy );
[97] Fix | Delete
$this->inclusion_mode = $mode;
[98] Fix | Delete
[99] Fix | Delete
$columns = self::COLUMNS;
[100] Fix | Delete
$column_names = array_keys( $columns );
[101] Fix | Delete
$table = $this->tmp_tables_mgr->create_empty( $columns );
[102] Fix | Delete
foreach ( $this->blogs as $blog ) {
[103] Fix | Delete
$this->category_query_builder->set_blog_id( $blog );
[104] Fix | Delete
$query = $this->category_query_builder->build( $this->inclusion_mode );
[105] Fix | Delete
if( $mode === CategoryInclusionMode::INCLUDE_ONLY ){
[106] Fix | Delete
$temp_table = $this->tmp_tables_mgr->create_new( $query );
[107] Fix | Delete
$this->category_filter_builder->set_blog_id( $blog );
[108] Fix | Delete
$filtered_query = $this->category_filter_builder->build( $temp_table );
[109] Fix | Delete
$filtered_temp_table = $this->tmp_tables_mgr->create_new( $filtered_query );
[110] Fix | Delete
$this->tmp_tables_mgr->copy_from_table( $filtered_temp_table, $table, $column_names );
[111] Fix | Delete
} else {
[112] Fix | Delete
$this->tmp_tables_mgr->insert_data( $table, $column_names, $query );
[113] Fix | Delete
}
[114] Fix | Delete
}
[115] Fix | Delete
if( $this->taxonomy_offsets ){
[116] Fix | Delete
$table = $this->offset_taxonomy_rows( $table );
[117] Fix | Delete
}
[118] Fix | Delete
return $table;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
public function drop_temp_tables(): void {
[122] Fix | Delete
$this->tmp_tables_mgr->destroy();
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
private function offset_taxonomy_rows( string $table ): string {
[126] Fix | Delete
$taxonomies = array_keys( $this->taxonomy_offsets );
[127] Fix | Delete
$taxonomies = array_map( function( $name ){
[128] Fix | Delete
return "'" . $name . "'";
[129] Fix | Delete
}, $taxonomies );
[130] Fix | Delete
$taxonomy_list_string = '(' . join( ',', $taxonomies ) . ')';
[131] Fix | Delete
$other_posts_query = "SELECT * FROM $table WHERE slug NOT IN $taxonomy_list_string LIMIT 0, 10000";
[132] Fix | Delete
$this->db->query( $other_posts_query );
[133] Fix | Delete
[134] Fix | Delete
$result_table = $this->tmp_tables_mgr->create_empty( self::COLUMNS );
[135] Fix | Delete
$query_template = "INSERT INTO $result_table %s";
[136] Fix | Delete
foreach ( $this->taxonomy_offsets as $taxonomy => $offset ){
[137] Fix | Delete
$part_query = "SELECT * FROM $table WHERE slug = '$taxonomy' LIMIT $offset, 10000" ;
[138] Fix | Delete
$query = sprintf( $query_template, $part_query );
[139] Fix | Delete
$this->db->query( $query );
[140] Fix | Delete
}
[141] Fix | Delete
return $result_table;
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function