芝麻web文件管理V1.00
编辑当前文件:/home/r5772835/public_html/rigato.ycreate.site/wp-content/plugins/search-regex/models/search.php
regex = true; if( !empty( $case)) $this->regex_options .= 'i'; if( !empty( $dotall)) $this->regex_options .= 's'; if( !empty( $multi)) $this->regex_options .= 'm'; } function regex_error( $errno, $errstr, $errfile, $errline) { $this->regex_error = __( "Invalid regular expression", 'search-regex').": ".preg_replace( '/(.*?):/', '', $errstr); } function name() { return '';} function run_search( $search) { return false; } function search_and_replace( $search, $replace, $limit, $offset, $orderby, $save = false) { $this->replace = $replace; $results = $this->search_for_pattern( $search, $limit, $offset, $orderby); if( $results !== false && $save) $this->replace( $results); return $results; } function search_for_pattern( $search, $limit, $offset, $orderby ) { if ( !in_array( $orderby, array( 'asc', 'desc' ) ) ) $orderby = 'asc'; $limit = intval( $limit ); $offset = intval( $offset ); if ( strlen( $search ) > 0 ) { if ( !ini_get( 'safe_mode' ) ) set_time_limit( 0 ); // First test that the search and replace strings are valid regex if ( $this->regex ) { set_error_handler( array( &$this, 'regex_error' ) ); $valid = @preg_match( $search, '', $matches ); restore_error_handler(); if ( $valid === false ) return $this->regex_error; return $this->find( $search, $limit, $offset, $orderby ); } else return $this->find( '@'.preg_quote( $search, '@' ).'@', $limit, $offset, $orderby ); } return __( "No search pattern", 'search-regex' ); } static function get_searches() { global $search_regex_searches; if( !is_array( $search_regex_searches)) { $available = get_declared_classes(); $files = glob( dirname( __FILE__).'/../searches/*.php'); if( !empty( $files)) { foreach( $files AS $file) include_once( $file); } $classes = array(); $available = array_diff( get_declared_classes(), $available); if( count( $available) > 0) { foreach( $available AS $class) $classes[] = new $class; } $search_regex_searches = $classes; } return $search_regex_searches; } static function valid_search( $class ) { $classes = Search::get_searches(); foreach ( $classes AS $item ) { if ( strcasecmp( get_class( $item ), $class ) === 0 ) return true; } return false; } function matches( $pattern, $content, $id) { if( preg_match_all( $pattern.$this->regex_options, $content, $matches, PREG_OFFSET_CAPTURE) > 0) { $results = array(); // We found something foreach( $matches[0] AS $found) { $result = new Result(); $result->id = $id; $result->offset = $found[1]; $result->length = strlen( $found[0]); // Extract the context - surrounding 40 characters either side // Index 0 is the match, index 1 is the position $start = $found[1] - 40; if( $start < 0) $start = 0; $end = $found[1] + 40; if( $end > strlen( $content)) $end = strlen( $content); $end -= $start; $left = substr( $content, $start, $found[1] - $start); $right = substr( $content, $found[1] + strlen( $found[0]), $end); $result->left = $start; $result->left_length = strlen( $found[0]) +( $found[1] - $start) + $end; if( $start != 0) $result->search = '… '; $result->search .= esc_html( $left ); $result->search .= '
'.esc_html( $found[0] ).'
'; $result->search .= esc_html( $right ); $result->search_plain = esc_html( $left ); $result->search_plain .= esc_html( $found[0] ); $result->search_plain .= esc_html( $right ); if( $start + $end < strlen( $content)) $result->search .= ' …'; if( !is_null( $this->replace)) { // Produce preview $rep = preg_replace( $pattern.$this->regex_options, $this->replace, $found[0]); $result->replace_string = $rep; if( $start != 0) $result->replace = '… '; $result->replace .= esc_html( $left ); $result->replace .= '
'.esc_html( $rep ).'
'; $result->replace .= esc_html( $right ); $result->left_length_replace = strlen( $left) + strlen( $rep) + strlen( $right) + 1; $result->replace_plain = esc_html( $left ); $result->replace_plain .= esc_html( $rep ); $result->replace_plain .= esc_html( $right ); if( $start + $end < strlen( $content)) $result->replace .= ' …'; // And the real thing $result->content = preg_replace( $pattern.$this->regex_options, $this->replace, $content); } $results[] = $result; } return $results; } return false; } function replace( $results) { global $wpdb; // Update database, if appropriate if( count( $results) > 0) { // We only do the first replace of any set, as that will cover everything $lastid = ''; foreach( $results AS $result) { if( $result->id != $lastid) { $this->replace_content( $result->id, $result->content); $lastid = $result->id; } } } } function replace_inline( $id, $offset, $length, $replace) { $content = $this->get_content( $id); // Delete the original string $before = substr( $content, 0, $offset); $after = substr( $content, $offset + $length); // Stick the new string between $content = $before.$replace.$after; // Insert back into database $this->replace_content( $id, $content); } } global $search_regex_searches;