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/clone/wp-conte.../plugins/network-.../componen.../db/category
File: NetsPostsCategoryQueryBuilder.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
namespace NetworkPosts\DB\Category;
[3] Fix | Delete
[4] Fix | Delete
[5] Fix | Delete
use NetworkPosts\db\NetsPostsDbHelper;
[6] Fix | Delete
[7] Fix | Delete
class NetsPostsCategoryQueryBuilder {
[8] Fix | Delete
private $blog_id = 1;
[9] Fix | Delete
private $base_prefix;
[10] Fix | Delete
private $terms_table;
[11] Fix | Delete
private $relationships_table;
[12] Fix | Delete
private $taxonomy_table;
[13] Fix | Delete
[14] Fix | Delete
private $mode;
[15] Fix | Delete
private $taxonomy = array();
[16] Fix | Delete
private $taxonomy_types = array();
[17] Fix | Delete
[18] Fix | Delete
public function __construct( string $base_prefix, int $blog_id = 1 ) {
[19] Fix | Delete
$this->base_prefix = $base_prefix;
[20] Fix | Delete
$this->set_blog_id( $blog_id );
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
public function set_blog_id( int $id ): void {
[24] Fix | Delete
$this->blog_id = $id;
[25] Fix | Delete
$this->terms_table = NetsPostsDbHelper::make_table_name( $this->base_prefix, 'terms', $this->blog_id );
[26] Fix | Delete
$this->taxonomy_table = NetsPostsDbHelper::make_table_name( $this->base_prefix, 'term_taxonomy', $this->blog_id );
[27] Fix | Delete
$this->relationships_table = NetsPostsDbHelper::make_table_name( $this->base_prefix, 'term_relationships', $this->blog_id );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* @param string[] $taxonomy
[32] Fix | Delete
*/
[33] Fix | Delete
public function set_taxonomy( array $taxonomy ): void {
[34] Fix | Delete
$this->taxonomy = $taxonomy;
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* @param string[] $types
[39] Fix | Delete
*/
[40] Fix | Delete
public function set_taxonomy_types( array $types ): void {
[41] Fix | Delete
$this->taxonomy_types = $types;
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
public function build( int $mode = CategoryInclusionMode::INCLUDE_ANY ): string {
[45] Fix | Delete
$this->mode = $mode;
[46] Fix | Delete
$columns = array(
[47] Fix | Delete
'object_id as post_id',
[48] Fix | Delete
'name',
[49] Fix | Delete
'slug',
[50] Fix | Delete
'taxonomy',
[51] Fix | Delete
);
[52] Fix | Delete
$base_query = $this->build_base_query( $columns );
[53] Fix | Delete
$where = $this->build_where_condition();
[54] Fix | Delete
return $base_query . ' ' . $where;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
protected function build_base_query( array $columns ): string {
[58] Fix | Delete
$tables = $this->join_tables();
[59] Fix | Delete
[60] Fix | Delete
$base_select_query = 'SELECT %1$s, %2$d as blog_id FROM %3$s %4$s';
[61] Fix | Delete
[62] Fix | Delete
$column_str = join( ',', $columns );
[63] Fix | Delete
$select = sprintf(
[64] Fix | Delete
$base_select_query,
[65] Fix | Delete
$column_str,
[66] Fix | Delete
$this->blog_id,
[67] Fix | Delete
$this->terms_table,
[68] Fix | Delete
$tables
[69] Fix | Delete
);
[70] Fix | Delete
return $select;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
protected function join_tables(): string {
[74] Fix | Delete
$query = 'INNER JOIN %2$s ON %1$s.term_id = %2$s.term_id
[75] Fix | Delete
INNER JOIN %3$s ON %2$s.term_taxonomy_id = %3$s.term_taxonomy_id';
[76] Fix | Delete
[77] Fix | Delete
[78] Fix | Delete
return sprintf(
[79] Fix | Delete
$query,
[80] Fix | Delete
$this->terms_table,
[81] Fix | Delete
$this->taxonomy_table,
[82] Fix | Delete
$this->relationships_table
[83] Fix | Delete
);
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
protected function build_where_condition(): string {
[87] Fix | Delete
$conditions = array();
[88] Fix | Delete
if( $this->taxonomy_types ){
[89] Fix | Delete
$conditions[] = $this->build_taxonomy_types_filter();
[90] Fix | Delete
}
[91] Fix | Delete
if( $this->taxonomy ){
[92] Fix | Delete
$condition = $this->build_inclusion();
[93] Fix | Delete
[94] Fix | Delete
if( $this->mode !== CategoryInclusionMode::INCLUDE_ANY ) {
[95] Fix | Delete
$condition .= ' ';
[96] Fix | Delete
$condition .= $this->build_strict_inclusion();
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
$conditions[] = $condition;
[100] Fix | Delete
}
[101] Fix | Delete
if( $conditions ){
[102] Fix | Delete
return 'WHERE ' . implode( ' AND ', $conditions );
[103] Fix | Delete
}
[104] Fix | Delete
return '';
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
protected function build_taxonomy_types_filter() {
[108] Fix | Delete
$taxonomy_types = array_map( function( $type ){ return "'$type'"; }, $this->taxonomy_types );
[109] Fix | Delete
$types = join( ',', $taxonomy_types );
[110] Fix | Delete
return '(taxonomy IN (' . $types . '))';
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
protected function build_inclusion(): string {
[114] Fix | Delete
$query = '(';
[115] Fix | Delete
$parts = array();
[116] Fix | Delete
foreach ( $this->taxonomy as $taxonomy ){
[117] Fix | Delete
$parts[] = "(LOWER(slug) LIKE '%$taxonomy%')";
[118] Fix | Delete
}
[119] Fix | Delete
$query .= join( ' OR ', $parts ) . ')';
[120] Fix | Delete
return $query;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
protected function build_strict_inclusion(): string {
[124] Fix | Delete
$category_count = count( $this->taxonomy );
[125] Fix | Delete
$relationship_table = $this->relationships_table;
[126] Fix | Delete
return "GROUP BY $relationship_table.object_id HAVING COUNT(*) = $category_count;";
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function