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/string-l.../includes/Base
File: class-search.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Base class for handling Search requests.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace StringLocator\Base;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Search class.
[8] Fix | Delete
*/
[9] Fix | Delete
class Search {
[10] Fix | Delete
/**
[11] Fix | Delete
* The server-configured max time a script can run.
[12] Fix | Delete
*
[13] Fix | Delete
* @var int
[14] Fix | Delete
*/
[15] Fix | Delete
protected $max_execution_time = null;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* The current time when our script started executing.
[19] Fix | Delete
*
[20] Fix | Delete
* @var float
[21] Fix | Delete
*/
[22] Fix | Delete
protected $start_execution_timer = 0;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The server-configured max amount of memory a script can use.
[26] Fix | Delete
*
[27] Fix | Delete
* @var int
[28] Fix | Delete
*/
[29] Fix | Delete
protected $max_memory_consumption = 0;
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The path to the currently editable file.
[33] Fix | Delete
*
[34] Fix | Delete
* @var string
[35] Fix | Delete
*/
[36] Fix | Delete
protected $path_to_use = '';
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Class constructor.
[40] Fix | Delete
*/
[41] Fix | Delete
public function __construct() {
[42] Fix | Delete
/**
[43] Fix | Delete
* Define class variables requiring expressions
[44] Fix | Delete
*/
[45] Fix | Delete
$this->path_to_use = ( is_multisite() ? 'network/admin.php' : 'tools.php' );
[46] Fix | Delete
[47] Fix | Delete
$this->max_execution_time = absint( ini_get( 'max_execution_time' ) );
[48] Fix | Delete
$this->start_execution_timer = microtime( true );
[49] Fix | Delete
[50] Fix | Delete
if ( $this->max_execution_time > 30 ) {
[51] Fix | Delete
$this->max_execution_time = 30;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
$this->set_memory_limit();
[55] Fix | Delete
[56] Fix | Delete
add_action( 'string_locator_search_templates', array( $this, 'add_search_response_template' ) );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Load an underscores template file to be used in the search response.
[61] Fix | Delete
*
[62] Fix | Delete
* @return void
[63] Fix | Delete
*/
[64] Fix | Delete
public function add_search_response_template() {
[65] Fix | Delete
require_once STRING_LOCATOR_PLUGIN_DIR . '/views/templates/search-default.php';
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Sets up the memory limit variables.
[70] Fix | Delete
*
[71] Fix | Delete
* @return void
[72] Fix | Delete
* @since 2.0.0
[73] Fix | Delete
*
[74] Fix | Delete
*/
[75] Fix | Delete
function set_memory_limit() {
[76] Fix | Delete
$memory_limit = ini_get( 'memory_limit' );
[77] Fix | Delete
[78] Fix | Delete
$this->max_memory_consumption = absint( $memory_limit );
[79] Fix | Delete
[80] Fix | Delete
if ( strstr( $memory_limit, 'k' ) ) {
[81] Fix | Delete
$this->max_memory_consumption = ( str_replace( 'k', '', $memory_limit ) * 1000 );
[82] Fix | Delete
}
[83] Fix | Delete
if ( strstr( $memory_limit, 'M' ) ) {
[84] Fix | Delete
$this->max_memory_consumption = ( str_replace( 'M', '', $memory_limit ) * 1000000 );
[85] Fix | Delete
}
[86] Fix | Delete
if ( strstr( $memory_limit, 'G' ) ) {
[87] Fix | Delete
$this->max_memory_consumption = ( str_replace( 'G', '', $memory_limit ) * 1000000000 );
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Check if the script is about to exceed the max execution time.
[93] Fix | Delete
*
[94] Fix | Delete
* @return bool
[95] Fix | Delete
* @since 1.9.0
[96] Fix | Delete
*
[97] Fix | Delete
*/
[98] Fix | Delete
function nearing_execution_limit() {
[99] Fix | Delete
// Max execution time is 0 or -1 (infinite) in server config
[100] Fix | Delete
if ( 0 === $this->max_execution_time || - 1 === $this->max_execution_time ) {
[101] Fix | Delete
return false;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
$back_compat_filter = apply_filters( 'string-locator-extra-search-delay', 2 ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[105] Fix | Delete
[106] Fix | Delete
$built_in_delay = apply_filters( 'string_locator_extra_search_delay', $back_compat_filter );
[107] Fix | Delete
$execution_time = ( microtime( true ) - $this->start_execution_timer + $built_in_delay );
[108] Fix | Delete
[109] Fix | Delete
if ( $execution_time >= $this->max_execution_time ) {
[110] Fix | Delete
return $execution_time;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
return false;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Check if the script is about to exceed the server memory limit.
[118] Fix | Delete
*
[119] Fix | Delete
* @return bool
[120] Fix | Delete
* @since 2.0.0
[121] Fix | Delete
*
[122] Fix | Delete
*/
[123] Fix | Delete
function nearing_memory_limit() {
[124] Fix | Delete
// Check if the memory limit is set t o0 or -1 (infinite) in server config
[125] Fix | Delete
if ( 0 === $this->max_memory_consumption || - 1 === $this->max_memory_consumption ) {
[126] Fix | Delete
return false;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
// We give our selves a 256k memory buffer, as we need to close off the script properly as well
[130] Fix | Delete
$back_compat_filter = apply_filters( 'string-locator-extra-memory-buffer', 256000 ); //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[131] Fix | Delete
$built_in_buffer = apply_filters( 'string_locator_extra_memory_buffer', $back_compat_filter );
[132] Fix | Delete
$memory_use = ( memory_get_usage( true ) + $built_in_buffer );
[133] Fix | Delete
[134] Fix | Delete
if ( $memory_use >= $this->max_memory_consumption ) {
[135] Fix | Delete
return $memory_use;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
return false;
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function