Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
derpixler committed Apr 3, 2016
1 parent cca1a62 commit 6e1f16d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 49 deletions.
44 changes: 44 additions & 0 deletions inc/Database/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,48 @@ protected function get_new_table_name( $table, $new_table_prefix ) {
return $new_table_prefix . $part_after_prefix;
}

/**
* Trims a given string to 50 chars before and after the search string, if the string is longer than 199 chars.
*
* @param $needle string
* @param $haystack string
* @param $delimiter array $delimiter[0]=start delimiter, $delimiter[1] = end delimiter
*
* @return string The trimmed $haystack
*/
protected function trim_search_results( $needle, $haystack, $delimiter ) {
//if result has <200 characters we return the whole string
if ( strlen( $haystack ) < 100 ) {
return $haystack;
}
$trimmed_results = NULL;
// Get all occurrences of $needle with up to 50 chars front & back.
preg_match_all( '@.{0,50}' . $needle . '.{0,50}@', $haystack, $trimmed_results );

This comment has been minimized.

Copy link
@dnaber-de

dnaber-de Apr 5, 2017

Shouldn't $needle be sanitized via preg_quote() or is it sanitized before?

$return_value = '';
/** @var array $trimmed_results */
$imax = count( $trimmed_results );
for ( $i = 0; $i < $imax; $i ++ ) {
//reset delimiter, might have been changed
$local_delimiter = $delimiter;
//check if the first trimmmed result is the beginning of $haystack. if so remove leading delimiter
if ( $i === 0 ) {
$pos = strpos( $haystack, $trimmed_results[ 0 ][ $i ] );
if ( $pos === 0 ) {
$local_delimiter[ 0 ] = '';
}
}
//check if the last trimmed result is the end of $haystack. if so, remove trailing delimiter
$last_index = count( $trimmed_results ) - 1;
if ( $i === $last_index ) {
$trimmed_result_length = strlen( $trimmed_results[ 0 ][ $i ] );
$substring = substr( $haystack, - $trimmed_result_length );
if ( $substring === $trimmed_results[ 0 ][ $i ] ) {
$local_delimiter[ 1 ] = '';
}
}
$return_value .= $local_delimiter[ 0 ] . $trimmed_results[ 0 ][ $i ] . $local_delimiter[ 1 ];
}
return $return_value;
}

}
49 changes: 0 additions & 49 deletions inc/Page/SearchReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,53 +276,4 @@ private function get_replace_value() {

}

/**
* Trims a given string to 50 chars before and after the search string, if the string is longer than 199 chars.
*
* @param $needle string
* @param $haystack string
* @param $delimiter array $delimiter[0]=start delimiter, $delimiter[1] = end delimiter
*
* @return string The trimmed $haystack
*/
protected function trim_search_results( $needle, $haystack, $delimiter ) {

//if result has <200 characters we return the whole string
if ( strlen( $haystack ) < 100 ) {
return $haystack;
}

$trimmed_results = NULL;
// Get all occurrences of $needle with up to 50 chars front & back.
preg_match_all( '@.{0,50}' . $needle . '.{0,50}@', $haystack, $trimmed_results );
$return_value = '';
/** @var array $trimmed_results */
$imax = count( $trimmed_results );
for ( $i = 0; $i < $imax; $i ++ ) {
//reset delimiter, might have been changed
$local_delimiter = $delimiter;
//check if the first trimmmed result is the beginning of $haystack. if so remove leading delimiter
if ( $i === 0 ) {
$pos = strpos( $haystack, $trimmed_results[ 0 ][ $i ] );
if ( $pos === 0 ) {
$local_delimiter[ 0 ] = '';
}
}

//check if the last trimmed result is the end of $haystack. if so, remove trailing delimiter
$last_index = count( $trimmed_results ) - 1;
if ( $i === $last_index ) {
$trimmed_result_length = strlen( $trimmed_results[ 0 ][ $i ] );
$substring = substr( $haystack, - $trimmed_result_length );
if ( $substring === $trimmed_results[ 0 ][ $i ] ) {
$local_delimiter[ 1 ] = '';
}

}
$return_value .= $local_delimiter[ 0 ] . $trimmed_results[ 0 ][ $i ] . $local_delimiter[ 1 ];
}

return $return_value;
}

}
2 changes: 2 additions & 0 deletions inc/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function run( $file ) {

if ( is_admin() ) {

set_time_limit(0);

This comment has been minimized.

Copy link
@Chrico

Chrico Apr 3, 2016

Contributor

Ohoh bitte nicht!

This comment has been minimized.

Copy link
@derpixler

derpixler Apr 3, 2016

Author Contributor

Quick and dirty - das löst das problem nur temporär, ich weiß ;)
Wir haben hier zu noch das Issue #48 aber das kostet etwas mehr Zeit.

This comment has been minimized.

Copy link
@Chrico

Chrico Apr 3, 2016

Contributor

Aber dann setze das doch an der Stelle wo es gebraucht wird und resette es dann danach wieder zurück ( ini_get('max_execution_time'); ) und setze es nicht global immer auf endless im Backend. Vermute mal das da ein Job (Exporter/Importer) das braucht ohne die issue zu lesen.


$dbm = new Database\Manager( $wpdb );
$replace = new Database\Replace( $dbm );
$dbe = new Database\Exporter( $replace, $dbm );
Expand Down

1 comment on commit 6e1f16d

@dan-eth
Copy link

@dan-eth dan-eth commented on 6e1f16d Apr 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thread is cited on a couple of places. But the link refers to @Chirico comment "Ohoh bitte nicht!"

Is the solution just above his comment?

Please sign in to comment.