first commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class WPML_Page_Builders_Page_Built {
|
||||
|
||||
private $config;
|
||||
|
||||
public function __construct( WPML_Config_Built_With_Page_Builders $config ) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WP_Post $post
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_page_builder_page( WP_Post $post ) {
|
||||
$result = false;
|
||||
$config_data = $this->config->get();
|
||||
|
||||
if ( is_array( $config_data ) ) {
|
||||
foreach ( $config_data as $pattern ) {
|
||||
$result = (bool) preg_match_all( $pattern, $post->post_content, $matches );
|
||||
|
||||
if ( $result ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'wpml_pb_is_page_builder_page', $result, $post );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Based on https://github.com/paulgb/simplediff/blob/master/php/simplediff.php
|
||||
*/
|
||||
|
||||
class WPML_ST_Diff {
|
||||
|
||||
/**
|
||||
* @param string[] $old_words
|
||||
* @param string[] $new_words
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function diff( $old_words, $new_words ) {
|
||||
$matrix = array();
|
||||
$max_length = 0;
|
||||
$old_max = null;
|
||||
$new_max = null;
|
||||
foreach ( $old_words as $old_index => $old_value ) {
|
||||
$new_keys = array_keys( $new_words, $old_value );
|
||||
foreach ( $new_keys as $new_index ) {
|
||||
$matrix[ $old_index ][ $new_index ] = isset( $matrix[ $old_index - 1 ][ $new_index - 1 ] ) ?
|
||||
$matrix[ $old_index - 1 ][ $new_index - 1 ] + 1 : 1;
|
||||
if ( $matrix[ $old_index ][ $new_index ] > $max_length ) {
|
||||
$max_length = $matrix[ $old_index ][ $new_index ];
|
||||
$old_max = $old_index + 1 - $max_length;
|
||||
$new_max = $new_index + 1 - $max_length;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( $max_length == 0 ) {
|
||||
return array( array( 'deleted' => $old_words, 'inserted' => $new_words ) );
|
||||
}
|
||||
|
||||
return array_merge(
|
||||
self::diff( array_slice( $old_words, 0, $old_max ), array_slice( $new_words, 0, $new_max ) ),
|
||||
array_slice( $new_words, $new_max, $max_length ),
|
||||
self::diff( array_slice( $old_words, $old_max + $max_length ), array_slice( $new_words, $new_max + $max_length ) )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $old_text
|
||||
* @param string $new_text
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public static function get_sameness_percent( $old_text, $new_text ) {
|
||||
$old_text = $old_text ? strip_tags( $old_text ) : $old_text;
|
||||
if ( $old_text ) {
|
||||
$new_text = strip_tags( $new_text );
|
||||
|
||||
$diff = self::diff( preg_split( '/[\s]+/', $old_text ), preg_split( '/[\s]+/', $new_text ) );
|
||||
|
||||
$common_length = 0;
|
||||
foreach ( $diff as $diff_data ) {
|
||||
if ( ! is_array( $diff_data ) ) {
|
||||
$common_length += strlen( $diff_data );
|
||||
}
|
||||
}
|
||||
|
||||
return ( $common_length * 100 ) / strlen( $old_text );
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user