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.../public_h.../wp-conte.../plugins/network-.../componen...
File: NetsPostsUtils.php
<?php
[0] Fix | Delete
function array_has_value($needle, $array) {
[1] Fix | Delete
foreach ( $array as $value ) {
[2] Fix | Delete
if ( trim( $needle ) == trim( $value ) ) {
[3] Fix | Delete
return true;
[4] Fix | Delete
}
[5] Fix | Delete
}
[6] Fix | Delete
return false;
[7] Fix | Delete
}
[8] Fix | Delete
function array_msort($array, $cols) {
[9] Fix | Delete
$colarr = array();
[10] Fix | Delete
foreach ( $cols as $col => $order ) {
[11] Fix | Delete
$colarr[$col] = array();
[12] Fix | Delete
foreach ( $array as $k => $row ) {
[13] Fix | Delete
$colarr[$col]['_' . $k] = strtolower( $row[$col] );
[14] Fix | Delete
}
[15] Fix | Delete
}
[16] Fix | Delete
$eval = 'array_multisort(';
[17] Fix | Delete
foreach ( $cols as $col => $order ) {
[18] Fix | Delete
$eval .= '$colarr[\'' . $col . '\'],' . $order . ',';
[19] Fix | Delete
}
[20] Fix | Delete
$eval = substr( $eval, 0, -1 ) . ');';
[21] Fix | Delete
eval( $eval );
[22] Fix | Delete
$ret = array();
[23] Fix | Delete
foreach ( $colarr as $col => $arr ) {
[24] Fix | Delete
foreach ( $arr as $k => $v ) {
[25] Fix | Delete
$k = substr( $k, 1 );
[26] Fix | Delete
if ( !isset( $ret[$k] ) ) {
[27] Fix | Delete
$ret[$k] = $array[$k];
[28] Fix | Delete
}
[29] Fix | Delete
$ret[$k][$col] = $array[$k][$col];
[30] Fix | Delete
}
[31] Fix | Delete
}
[32] Fix | Delete
return $ret;
[33] Fix | Delete
}
[34] Fix | Delete
function custom_sort($a, $b) {
[35] Fix | Delete
if ( array_key_exists( 'post_date', $a ) && array_key_exists( 'post_date', $b ) ) {
[36] Fix | Delete
return $a['post_date'] < $b['post_date'];
[37] Fix | Delete
} else if ( array_key_exists( 'post_date', $a ) ) {
[38] Fix | Delete
return false;
[39] Fix | Delete
} else if ( array_key_exists( 'post_date', $b ) ) {
[40] Fix | Delete
return true;
[41] Fix | Delete
} else {
[42] Fix | Delete
return false;
[43] Fix | Delete
}
[44] Fix | Delete
}
[45] Fix | Delete
function format_exclusion($table_name, $column_name, $values) {
[46] Fix | Delete
if ( is_array( $values ) ) {
[47] Fix | Delete
$values = array_map( function ($item) use($column_name){
[48] Fix | Delete
if( is_array( $item ) ){
[49] Fix | Delete
return "'" . esc_sql( $item[$column_name] ) . "'";
[50] Fix | Delete
}
[51] Fix | Delete
return "'" . esc_sql( $item ) . "'";
[52] Fix | Delete
}, $values );
[53] Fix | Delete
return "($table_name.$column_name NOT IN (" . join( ',', $values ) . '))';
[54] Fix | Delete
} else {
[55] Fix | Delete
return '';
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
function format_inclusion($table_name, $column_name, $values, $union = 'OR') {
[59] Fix | Delete
if ( is_array( $values ) ) {
[60] Fix | Delete
if ( count( $values ) > 0 ) {
[61] Fix | Delete
$values = array_map( function ($item) use ($column_name){
[62] Fix | Delete
if( is_array( $item ) ){
[63] Fix | Delete
return "'" . esc_sql( $item[$column_name] ) . "'";
[64] Fix | Delete
}
[65] Fix | Delete
return "'" . esc_sql( $item ) . "'";
[66] Fix | Delete
}, $values );
[67] Fix | Delete
if( $union === 'OR' ) {
[68] Fix | Delete
return "($table_name.$column_name IN (" . join( ',', $values ) . '))';
[69] Fix | Delete
}
[70] Fix | Delete
else{
[71] Fix | Delete
$sql = [];
[72] Fix | Delete
foreach($values as $value){
[73] Fix | Delete
$sql[] = "$table_name.$column_name = $value";
[74] Fix | Delete
}
[75] Fix | Delete
return join( ' AND ', $sql );
[76] Fix | Delete
}
[77] Fix | Delete
} else {
[78] Fix | Delete
return "({$table_name}.{$column_name} = '')";
[79] Fix | Delete
}
[80] Fix | Delete
} else {
[81] Fix | Delete
return '';
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
function get_letters_excerpt($length, $content, $permalink) {
[85] Fix | Delete
if ( !$length ) {
[86] Fix | Delete
return $content;
[87] Fix | Delete
} else {
[88] Fix | Delete
$content = substr( $content, 0, intval( $length ) );
[89] Fix | Delete
$words = explode( ' ', $content );
[90] Fix | Delete
array_pop( $words );
[91] Fix | Delete
$content = implode( ' ', $words );
[92] Fix | Delete
/* Original Code return $content.'... <a href="'.$permalink.'"> '.__('read more&rarr;','trans-nlp').'</a>'; */
[93] Fix | Delete
/* Edited Code Turned argument 'read more&rarr;' to ''*/
[94] Fix | Delete
return $content . '...';
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
function get_words_excerpt($length, $content, $permalink) {
[98] Fix | Delete
if ( !$length ) {
[99] Fix | Delete
return $content;
[100] Fix | Delete
} else {
[101] Fix | Delete
$words = explode( ' ', $content );
[102] Fix | Delete
if ( count( $words ) > $length ) {
[103] Fix | Delete
$words = array_slice( $words, 0, $length );
[104] Fix | Delete
$content = implode( ' ', $words );
[105] Fix | Delete
/* Original Code return $content.'... <a href="'.$permalink.'"> '.__('read more&rarr;','trans-nlp').'</a>'; */
[106] Fix | Delete
/* Edited Code Turned argument 'read more&rarr;' to ''*/
[107] Fix | Delete
return $content . '... <a href="' . $permalink . '"> ' . __( '', 'trans-nlp' ) . '</a>';
[108] Fix | Delete
} else {
[109] Fix | Delete
$content = implode( ' ', $words );
[110] Fix | Delete
/* Original Code return $content.' <a href="'.$permalink.'"> '.__('read more&rarr;','trans-nlp').'</a>'; */
[111] Fix | Delete
/* Edited Code Turned argument 'read more&rarr;' to ''*/
[112] Fix | Delete
return $content . ' <a href="' . $permalink . '"> ' . __( '', 'trans-nlp' ) . '</a>';
[113] Fix | Delete
}
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
function netsposts_strip_text_words( string $text, int $word_count ): string {
[117] Fix | Delete
$words = explode( ' ', $text );
[118] Fix | Delete
if ( count( $words ) > $word_count ) {
[119] Fix | Delete
$words = array_slice( $words, 0, $word_count );
[120] Fix | Delete
$stripped_text = implode( ' ', $words ) . '...';
[121] Fix | Delete
return $stripped_text;
[122] Fix | Delete
}
[123] Fix | Delete
return $text;
[124] Fix | Delete
}
[125] Fix | Delete
function removeElementWithValue(&$array, $key, $value) {
[126] Fix | Delete
foreach ( $array as $subKey => $subArray ) {
[127] Fix | Delete
if ( $subArray[$key] == $value ) {
[128] Fix | Delete
unset( $array[$subKey] );
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
function sanitize_quotes($str) {
[133] Fix | Delete
return str_replace( '&#039;', '"', $str );
[134] Fix | Delete
}
[135] Fix | Delete
function ShortenText($text, $limit) {
[136] Fix | Delete
$chars_limit = $limit;
[137] Fix | Delete
$chars_text = strlen( $text );
[138] Fix | Delete
$text = $text . " ";
[139] Fix | Delete
$text = substr( $text, 0, $chars_limit );
[140] Fix | Delete
$nearest_space_position = strrpos( $text, ' ' );
[141] Fix | Delete
if( $nearest_space_position !== false ) {
[142] Fix | Delete
$text = substr( $text, 0, $nearest_space_position );
[143] Fix | Delete
}
[144] Fix | Delete
if ( $chars_text > $chars_limit ) {
[145] Fix | Delete
$text = $text . "...";
[146] Fix | Delete
}
[147] Fix | Delete
return $text;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
function shorten_text_exact( $text, $limit ) {
[151] Fix | Delete
return mb_substr( $text, 0, $limit );
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
function super_unique($array, $key) {
[155] Fix | Delete
$temp_array = array();
[156] Fix | Delete
foreach ( $array as $v ) {
[157] Fix | Delete
if ( !isset( $temp_array[$v[$key]] ) ) {
[158] Fix | Delete
$temp_array[$v[$key]] = $v;
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
$array = array_values( $temp_array );
[162] Fix | Delete
return $array;
[163] Fix | Delete
}
[164] Fix | Delete
/**
[165] Fix | Delete
* @param $str String representation of date or 'now'
[166] Fix | Delete
*
[167] Fix | Delete
* @return DateTime|null Returns date with time equal 00:00:00
[168] Fix | Delete
*/
[169] Fix | Delete
function netsposts_strtodate($str) {
[170] Fix | Delete
$filter_date = null;
[171] Fix | Delete
if ( $str ) {
[172] Fix | Delete
$filter_date = new DateTime( $str );
[173] Fix | Delete
$filter_date->setTime( 0, 0, 0 );
[174] Fix | Delete
} else {
[175] Fix | Delete
$filter_date = new DateTime();
[176] Fix | Delete
}
[177] Fix | Delete
return $filter_date;
[178] Fix | Delete
}
[179] Fix | Delete
/**
[180] Fix | Delete
* @param array $src_array
[181] Fix | Delete
* @param array $show_after_date - An array contains field name and date to filter posts after target date including today.
[182] Fix | Delete
* @param array $show_before_date - An array contains field name and date to filter posts before target date not including today.
[183] Fix | Delete
* @param $show_for_today - String Field name to filter posts during today.
[184] Fix | Delete
*
[185] Fix | Delete
* @return array Returns array filtered by date fields
[186] Fix | Delete
*/
[187] Fix | Delete
function netsposts_filter_by_date(array $src_array, array $show_after_date = null, array $show_before_date = null, $show_for_today = null) {
[188] Fix | Delete
$current_date = netsposts_strtodate( 'now' );
[189] Fix | Delete
return array_filter( $src_array, function ($post) use ($show_after_date, $show_before_date, $show_for_today, $current_date) {
[190] Fix | Delete
try {
[191] Fix | Delete
$result = false;
[192] Fix | Delete
if ( $show_after_date ) {
[193] Fix | Delete
if ( isset( $post[$show_after_date[0]] ) ) {
[194] Fix | Delete
$post_after_date = netsposts_strtodate( $post[$show_after_date[0]] );
[195] Fix | Delete
$result = $result || $post_after_date->getTimestamp() >= $show_after_date[1]->getTimestamp();
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
if ( $show_before_date ) {
[199] Fix | Delete
if ( isset( $post[$show_before_date[0]] ) ) {
[200] Fix | Delete
$post_before_date = netsposts_strtodate( $post[$show_before_date[0]] );
[201] Fix | Delete
$result = $result || $post_before_date->getTimestamp() < $show_before_date[1]->getTimestamp();
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
if ( $show_for_today ) {
[205] Fix | Delete
if ( isset( $post[$show_for_today] ) ) {
[206] Fix | Delete
$post_today_date = new DateTime( $post[$show_for_today] );
[207] Fix | Delete
$result = $result || $post_today_date->getTimestamp() === $current_date->getTimestamp();
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
return $result;
[211] Fix | Delete
} catch ( Exception $e ) {
[212] Fix | Delete
return false;
[213] Fix | Delete
}
[214] Fix | Delete
} );
[215] Fix | Delete
}
[216] Fix | Delete
function netsposts_create_label_from_id($id) {
[217] Fix | Delete
$fullname = str_replace( "_", " ", $id );
[218] Fix | Delete
return strtoupper( mb_substr( $fullname, 0, 1 ) ) . mb_substr( $fullname, 1 );
[219] Fix | Delete
}
[220] Fix | Delete
function netsposts_modify_pagination($route_url, $pagination, $page) {
[221] Fix | Delete
$escaped_route_url = str_replace( '/', '\/', $route_url );
[222] Fix | Delete
$pagination = str_replace( "'", '"', $pagination );
[223] Fix | Delete
$pattern = '/\b' . $escaped_route_url . '.*?\/([0-9]+)\/"/m';
[224] Fix | Delete
$new_pagination = preg_replace( $pattern, $route_url . '$1"', $pagination );
[225] Fix | Delete
return $new_pagination;
[226] Fix | Delete
}
[227] Fix | Delete
function netsposts_filter_empty_values( array $data ): array{
[228] Fix | Delete
return array_filter( $data, function( $item ){
[229] Fix | Delete
return $item == true;
[230] Fix | Delete
} );
[231] Fix | Delete
}
[232] Fix | Delete
/**
[233] Fix | Delete
* @param int $post_id
[234] Fix | Delete
*
[235] Fix | Delete
* @return WP_Term[]
[236] Fix | Delete
*/
[237] Fix | Delete
function netsposts_get_post_custom_taxonomies( int $post_id ): array{
[238] Fix | Delete
if( function_exists( 'cptui_get_taxonomy_slugs' ) ){
[239] Fix | Delete
$custom_taxonomies = cptui_get_taxonomy_slugs();
[240] Fix | Delete
$terms = wp_get_post_terms( $post_id, $custom_taxonomies );
[241] Fix | Delete
if( is_array( $terms ) ){
[242] Fix | Delete
foreach ( $terms as &$term ){
[243] Fix | Delete
$term->url= get_term_link( $term );
[244] Fix | Delete
}
[245] Fix | Delete
return $terms;
[246] Fix | Delete
}
[247] Fix | Delete
}
[248] Fix | Delete
return array();
[249] Fix | Delete
}
[250] Fix | Delete
function netsposts_get_post_taxonomies( int $post_id, array $types ): array {
[251] Fix | Delete
$terms = wp_get_post_terms( $post_id, $types );
[252] Fix | Delete
if( is_array( $terms ) ){
[253] Fix | Delete
foreach ( $terms as &$term ){
[254] Fix | Delete
$term->url= get_term_link( $term );
[255] Fix | Delete
}
[256] Fix | Delete
return $terms;
[257] Fix | Delete
}
[258] Fix | Delete
return array();
[259] Fix | Delete
}
[260] Fix | Delete
function netsposts_remove_pagination( ?string $text ): string {
[261] Fix | Delete
if( is_null( $text ) ) return '';
[262] Fix | Delete
$re = '/\<div\sclass\=\"netsposts-paginate\"\>.*?\<\/div\>/s';
[263] Fix | Delete
return preg_replace( $re, '', $text );
[264] Fix | Delete
}
[265] Fix | Delete
function netsposts_get_local_fields( int $post_id ): array {
[266] Fix | Delete
global $acf;
[267] Fix | Delete
do_action( 'acf/include_fields' );
[268] Fix | Delete
if($acf->local) {
[269] Fix | Delete
$local_fields = $acf->local->fields;
[270] Fix | Delete
} elseif( function_exists( 'acf_get_local_fields' ) ) {
[271] Fix | Delete
$local_fields = acf_get_local_fields();
[272] Fix | Delete
} else {
[273] Fix | Delete
$local_fields = array();
[274] Fix | Delete
}
[275] Fix | Delete
if( $local_fields ) {
[276] Fix | Delete
$output_fields = array();
[277] Fix | Delete
foreach ( $local_fields as $field ) {
[278] Fix | Delete
$value = get_post_meta( $post_id, $field['name'], true );
[279] Fix | Delete
$field['value'] = acf_format_value( $value, $post_id, $field );
[280] Fix | Delete
$output_fields[ $field['name'] ] = $field;
[281] Fix | Delete
}
[282] Fix | Delete
return $output_fields;
[283] Fix | Delete
}
[284] Fix | Delete
return array();
[285] Fix | Delete
}
[286] Fix | Delete
function netsposts_replace_image_domains( string $html, string $needle, string $replacement ): string {
[287] Fix | Delete
$needle_escaped = str_replace( '/', '\/', $needle );
[288] Fix | Delete
$pattern = '/img.*?src=[\'"](' . $needle_escaped . '.*?)[\'"]/';
[289] Fix | Delete
$matches = array();
[290] Fix | Delete
if( preg_match_all( $pattern, $html, $matches ) ){
[291] Fix | Delete
foreach ( $matches[0] as $match ){
[292] Fix | Delete
$replaced = str_replace( $needle, $replacement, $match );
[293] Fix | Delete
$html = str_replace( $match, $replaced, $html );
[294] Fix | Delete
}
[295] Fix | Delete
}
[296] Fix | Delete
$pattern = '/img.*?srcset=[\'"](' . $needle_escaped . '.*?)[\'"]/';
[297] Fix | Delete
$matches = array();
[298] Fix | Delete
if( preg_match_all( $pattern, $html, $matches ) ){
[299] Fix | Delete
foreach ( $matches[0] as $match ){
[300] Fix | Delete
$replaced = str_replace( $needle, $replacement, $match );
[301] Fix | Delete
$html = str_replace( $match, $replaced, $html );
[302] Fix | Delete
}
[303] Fix | Delete
}
[304] Fix | Delete
return $html;
[305] Fix | Delete
}
[306] Fix | Delete
function netsposts_replace_image_link_domains( string $html, string $needle, string $replacement ): string {
[307] Fix | Delete
$needle_escaped = str_replace( '/', '\/', $needle );
[308] Fix | Delete
$needle_escaped = str_replace( '.', '\.', $needle_escaped );
[309] Fix | Delete
$pattern = '/a.*?href\=[\'"](' . $needle_escaped . '.*?)[\'"].*?\>\s*\<img/';
[310] Fix | Delete
$matches = array();
[311] Fix | Delete
if( preg_match_all( $pattern, $html, $matches ) ){
[312] Fix | Delete
foreach ( $matches[0] as $match ){
[313] Fix | Delete
$replaced = str_replace( $needle, $replacement, $match );
[314] Fix | Delete
$html = str_replace( $match, $replaced, $html );
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
return $html;
[318] Fix | Delete
}
[319] Fix | Delete
function display_var( $var ): void {
[320] Fix | Delete
if( isset( $GLOBALS['NETSPOSTS_DEBUG'] ) &&
[321] Fix | Delete
$GLOBALS['NETSPOSTS_DEBUG'] && ! is_admin() ) {
[322] Fix | Delete
var_dump( $var );
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
function display_string( $str ): void {
[326] Fix | Delete
if( isset( $GLOBALS['NETSPOSTS_DEBUG'] ) &&
[327] Fix | Delete
$GLOBALS['NETSPOSTS_DEBUG'] && ! is_admin() ) {
[328] Fix | Delete
var_dump( $str );
[329] Fix | Delete
}
[330] Fix | Delete
}
[331] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function