Plugin Directory

Changeset 1390214


Ignore:
Timestamp:
04/08/2016 12:55:51 PM (10 years ago)
Author:
derpixler
Message:

re sync folders

Location:
search-and-replace/trunk/inc
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • search-and-replace/trunk/inc/Database/Exporter.php

    r1390032 r1390214  
    7878     * $report ['changes'] : Array with replacements in tables
    7979     */
    80     public function db_backup( $search, $replace, $tables = array(), $domain_replace = FALSE, $new_table_prefix ) {
     80    public function db_backup( $search = '', $replace = '', $tables = array(), $domain_replace = FALSE, $new_table_prefix = '' ) {
    8181
    8282        if ( count( $tables ) < 1 ) {
     
    584584    }
    585585
    586     /**
    587      * Trims a given string to 50 chars before and after the search string, if the string is longer than 199 chars.
    588      *
    589      * @param $needle    string
    590      * @param $haystack  string
    591      * @param $delimiter array  $delimiter[0]=start delimiter, $delimiter[1] = end delimiter
    592      *
    593      * @return string The trimmed $haystack
    594      */
    595     protected function trim_search_results( $needle, $haystack, $delimiter ) {
    596 
    597         //if result has <200 characters we return the whole string
    598         if ( strlen( $haystack ) < 100 ) {
    599             return $haystack;
    600         }
    601         $trimmed_results = NULL;
    602         // Get all occurrences of $needle with up to 50 chars front & back.
    603         preg_match_all( '@.{0,50}' . $needle . '.{0,50}@', $haystack, $trimmed_results );
    604         $return_value = '';
    605         /** @var array $trimmed_results */
    606         $imax = count( $trimmed_results );
    607         for ( $i = 0; $i < $imax; $i ++ ) {
    608             //reset delimiter, might have been changed
    609             $local_delimiter = $delimiter;
    610             //check if the first trimmmed result is the beginning of $haystack. if so remove leading delimiter
    611             if ( $i === 0 ) {
    612                 $pos = strpos( $haystack, $trimmed_results[ 0 ][ $i ] );
    613                 if ( $pos === 0 ) {
    614                     $local_delimiter[ 0 ] = '';
    615                 }
    616             }
    617             //check if the last trimmed result is the end of $haystack. if so, remove trailing delimiter
    618             $last_index = count( $trimmed_results ) - 1;
    619             if ( $i === $last_index ) {
    620                 $trimmed_result_length = strlen( $trimmed_results[ 0 ][ $i ] );
    621                 $substring             = substr( $haystack, - $trimmed_result_length );
    622                 if ( $substring === $trimmed_results[ 0 ][ $i ] ) {
    623                     $local_delimiter[ 1 ] = '';
    624                 }
    625             }
    626             $return_value .= $local_delimiter[ 0 ] . $trimmed_results[ 0 ][ $i ] . $local_delimiter[ 1 ];
    627         }
    628 
    629         return $return_value;
    630     }
    631586
    632587}
  • search-and-replace/trunk/inc/Database/Replace.php

    r1390032 r1390214  
    7373    public function run_search_replace( $search, $replace, $tables ) {
    7474
    75         if( $search == $replace ){
     75        if ( $search === $replace ){
    7676            return new \WP_Error( 'error', __( "Search and replace pattern can't be the same!" ) );
    7777        }
     
    127127        //split columns array in primary key string and columns array
    128128        $columns     = $this->dbm->get_columns( $table );
    129         list( $primary_key, $columns ) = $columns;
     129        $primary_key = $columns[ 0 ];
     130        $columns     = $columns[ 1 ];
    130131
    131132        if ( NULL === $primary_key ) {
  • search-and-replace/trunk/inc/FileDownloader.php

    r1390032 r1390214  
    1111class FileDownloader {
    1212
     13    /**
     14     * @var string
     15     */
    1316    private $nonce_action = 'download_sql';
    1417
     18    /**
     19     * @var string
     20     */
    1521    private $nonce_name = 'insr_nonce';
    1622
     
    3541     * @param array $report
    3642     */
    37     public function show_download_modal( $report ) {
     43    public function show_modal( $report ) {
    3844
    3945        if ( ! isset( $report[ 'changes' ] ) ) {
    4046            echo '<p>' . esc_html__( 'Search pattern not found.', 'search-and-replace' ) . '</p>';
     47
    4148            return;
    4249        }
     
    5158                $this->show_changes( $report );
    5259            }
    53    
     60
    5461            //if no changes found report that
    5562            if ( 0 === count( $report [ 'changes' ] ) ) {
     
    6067
    6168        <div class="updated notice is-dismissible insr_sql_button_wrap">
    62             <p><?php esc_html_e('Your SQL file was created!', 'search-and-replace');?> </p>
     69            <p><?php esc_html_e( 'Your SQL file was created!', 'search-and-replace' ); ?> </p>
    6370            <form action method="post">
    6471                <?php wp_nonce_field( $this->nonce_action, $this->nonce_name ); ?>
    6572                <input type="hidden" name="action" value="download_file" />
    66                 <input type ="hidden" name="sql_file" value="<?php echo esc_attr( $report[ 'filename' ] ); ?>">
    67                 <input type ="hidden" name="compress" value="<?php echo esc_attr( $compress ); ?>">
    68                 <input id ="insr_submit" type="submit" value="<?php esc_attr_e( 'Download SQL File', 'search-and-replace' ) ?>" class="button" />
     73                <input type="hidden" name="sql_file" value="<?php echo esc_attr( $report[ 'filename' ] ); ?>">
     74                <input type="hidden" name="compress" value="<?php echo esc_attr( $compress ); ?>">
     75                <input id="insr_submit" type="submit" value="<?php esc_attr_e(
     76                    'Download SQL File', 'search-and-replace'
     77                ) ?>" class="button" />
    6978            </form>
    7079        </div>
    7180        <?php
    7281    }
    73 
    7482
    7583    /**
     
    9098     * @return string
    9199     */
    92     private function show_changes( $report ) {
     100    public function show_changes( $report ) {
    93101
    94102        //get search & replace values in order to highlight them in the results
     
    129137            </div>
    130138            <div class="search-replace-changes-modal-content">
     139                <?php
     140                foreach ( $report[ 'changes' ] as $table_report ) :
     141                    $changes = $table_report[ 'changes' ];
     142                    $changes_made = count( $changes );
     143
     144                    if ( $changes_made < 1 ) :
     145                        continue;
     146                    endif;
     147
     148                    $table = $table_report[ 'table_name' ];
     149                    ?>
     150                    <h2 class="search-replace-modal-table-headline">
     151                        <strong><?php esc_html_e( 'Table:', 'search-and-replace' ); ?></strong>
     152                        <?php echo $table; ?>
     153                        <strong><?php esc_html_e( 'Changes:', 'search-and-replace' ); ?></strong>
     154                        <?php echo $changes_made; ?>
     155                    </h2>
     156
     157                    <table class="search-replace-modal-table">
     158
     159                        <?php foreach ( $changes as $change ) : ?>
     160
     161                            <tr>
     162                                <th class="search-replace-narrow">
     163                                    <?php esc_html_e( 'row', 'search-and-replace' ); ?>
     164                                </th>
     165                                <td class="search-replace-narrow"><?php echo esc_html( $change [ 'row' ] ); ?></td>
     166                                <th><?php esc_html_e( 'column', 'search-and-replace' ); ?></th>
     167                                <td><?php echo esc_html( $change [ 'column' ] ); ?></td>
     168                                <?php
     169                                //trim results and wrap with highlight class
     170                                $old_value = esc_html( $change [ 'from' ] );
     171                                $old_value = $this->trim_search_results( $search, $old_value, $delimiter );
     172                                $old_value = str_replace( $search, $search_highlight, $old_value );
     173
     174                                $new_value = esc_html( $change[ 'to' ] );
     175                                $new_value = $this->trim_search_results( $replace, $new_value, $delimiter );
     176                                $new_value = str_replace( $replace, $replace_highlight, $new_value );
     177                                ?>
     178                                <th><?php esc_html_e( 'Old value:', 'search-and-replace' ); ?></th>
     179                                <td><?php echo wp_kses( $old_value, [ 'span' => [ 'class' => [] ] ] ); ?></td>
     180                                <th><?php esc_html_e( 'New value:', 'search-and-replace' ); ?></th>
     181                                <td><?php echo wp_kses( $new_value, [ 'span' => [ 'class' => [] ] ] ); ?></td>
     182                            </tr>
     183
     184                        <?php endforeach ?>
     185
     186                    </table>
     187
     188                <?php endforeach; ?>
     189
     190            </div>
     191        </div>
    131192        <?php
    132         foreach ( $report[ 'changes' ] as $table_report ) {
    133             $changes      = $table_report[ 'changes' ];
    134             $changes_made = count( $changes );
    135 
    136             if ( $changes_made > 0 ) {
    137                 $table = $table_report[ 'table_name' ];
    138                 $html  = '<h2 class = "search-replace-modal-table-headline">';
    139                 $html .= '<strong>' . esc_attr__( 'Table:', 'search-and-replace' ) . '</strong> ' . $table;
    140                 $html .= '<strong>' . esc_attr__( 'Changes:', 'search-and-replace' ) . '</strong> ' . $changes_made;
    141                 $html .= '</h2>';
    142 
    143                 $html .= '<table class="search-replace-modal-table"><colgroup><col><col><col><col><col><col><col><col></colgroup>';
    144 
    145                 foreach ( $changes as $change ) {
    146 
    147                     $html .= '<tr>';
    148                     $html .= '<th class="search-replace-narrow">' . __( 'row', 'search-and-replace' ) . '</th>
    149                         <td class="search-replace-narrow">' . $change [ 'row' ] . '</td>
    150                          <th> ' . __( 'column', 'search-and-replace' ) . '</th>
    151                         <td>' . $change [ 'column' ] . '</td> ';
    152 
    153                     //trim results and wrap with highlight class
    154                     $old_value = esc_html( $change [ 'from' ] );
    155                     $old_value = $this->trim_search_results( $search, $old_value, $delimiter );
    156                     $old_value = str_replace( $search, $search_highlight, $old_value );
    157 
    158                     $new_value = esc_html( $change[ 'to' ] );
    159                     $new_value = $this->trim_search_results( $replace, $new_value, $delimiter );
    160                     $new_value = str_replace( $replace, $replace_highlight, $new_value );
    161 
    162                     $html .= '<th>' . __( 'Old value:', 'search-and-replace' ) . '</th>
    163                             <td>' . $old_value . '</td>
    164                         <th> ' . __( 'New value:', 'search-and-replace' ) . '</th><td>' . $new_value . '</td>';
    165                     $html .= '</tr>';
     193    }
     194
     195    /**
     196     * Trims a given string to 50 chars before and after the search string, if the string is longer than 199 chars.
     197     *
     198     * @param $needle    string
     199     * @param $haystack  string
     200     * @param $delimiter array  $delimiter[0]=start delimiter, $delimiter[1] = end delimiter
     201     *
     202     * @return string The trimmed $haystack
     203     */
     204    public function trim_search_results( $needle, $haystack, $delimiter ) {
     205
     206        //if result has <200 characters we return the whole string
     207        if ( strlen( $haystack ) < 100 ) {
     208            return $haystack;
     209        }
     210        $trimmed_results = NULL;
     211        // Get all occurrences of $needle with up to 50 chars front & back.
     212        preg_match_all( '@.{0,50}' . $needle . '.{0,50}@', $haystack, $trimmed_results );
     213        $return_value = '';
     214        /** @var array $trimmed_results */
     215        $imax = count( $trimmed_results );
     216        for ( $i = 0; $i < $imax; $i ++ ) {
     217            //reset delimiter, might have been changed
     218            $local_delimiter = $delimiter;
     219            //check if the first trimmmed result is the beginning of $haystack. if so remove leading delimiter
     220            if ( $i === 0 ) {
     221                $pos = strpos( $haystack, $trimmed_results[ 0 ][ $i ] );
     222                if ( $pos === 0 ) {
     223                    $local_delimiter[ 0 ] = '';
    166224                }
    167                 $html .= '</table>';
    168 
    169                 echo $html;
    170             }
    171         }
    172 
    173         echo '</div></div>';
    174     }
    175 
    176 
     225            }
     226            //check if the last trimmed result is the end of $haystack. if so, remove trailing delimiter
     227            $last_index = count( $trimmed_results ) - 1;
     228            if ( $i === $last_index ) {
     229                $trimmed_result_length = strlen( $trimmed_results[ 0 ][ $i ] );
     230                $substring             = substr( $haystack, - $trimmed_result_length );
     231                if ( $substring === $trimmed_results[ 0 ][ $i ] ) {
     232                    $local_delimiter[ 1 ] = '';
     233                }
     234            }
     235            $return_value .= $local_delimiter[ 0 ] . $trimmed_results[ 0 ][ $i ] . $local_delimiter[ 1 ];
     236        }
     237
     238        return $return_value;
     239    }
    177240    /**
    178241     * calls the file delivery in Class DatabaseExporter
  • search-and-replace/trunk/inc/Page/BackupDatabase.php

    r1390032 r1390214  
    4343
    4444    /**
     45     * Return the static slug string.
     46     *
     47     * @return string
     48     */
     49    public function get_slug() {
     50
     51        return 'backup-database';
     52    }
     53
     54    /**
    4555     *shows the page template
    4656     */
     
    6474
    6575        $report = $this->dbe->db_backup();
    66         $this->downloader->show_download_modal( $report );
     76        $this->downloader->show_modal( $report );
    6777
    6878        return TRUE;
  • search-and-replace/trunk/inc/Page/Credits.php

    r1390032 r1390214  
    2626
    2727    /**
     28     * Return the static slug string.
     29     *
     30     * @return string
     31     */
     32    public function get_slug() {
     33
     34        return 'credits';
     35    }
     36
     37    /**
    2838     * @return boolean
    2939     */
  • search-and-replace/trunk/inc/Page/ReplaceDomain.php

    r1390032 r1390214  
    5959
    6060        $report = $this->dbe->db_backup( $search, $replace, array(), TRUE, $new_db_prefix );
    61         $this->downloader->show_download_modal( $report );
     61        $this->downloader->show_modal( $report );
    6262
    6363        return TRUE;
     
    8888    }
    8989
     90    /**
     91     * Return the static slug string.
     92     *
     93     * @return string
     94     */
     95    public function get_slug() {
     96
     97        return 'replace-domain-url';
     98    }
    9099}
  • search-and-replace/trunk/inc/Page/SearchReplace.php

    r1390032 r1390214  
    6363
    6464        return esc_html__( 'Search & Replace', 'search-and-replace' );
     65    }
     66
     67    /**
     68     * Return the static slug string.
     69     *
     70     * @return string
     71     */
     72    public function get_slug() {
     73
     74        return 'search-replace';
    6575    }
    6676
     
    134144            //'export'-button was checked
    135145            $report = $this->dbe->db_backup( $search, $replace, $tables );
    136             $this->downloader->show_download_modal( $report );
     146            $this->downloader->show_modal( $report );
    137147        } else {
    138148            //"Save changes to database" was checked
     
    190200
    191201            if ( count( $report[ 'changes' ] ) > 0 ) {
    192                 $this->dbe->show_changes( $report );
     202                $this->downloader->show_changes( $report );
    193203            }
    194204
  • search-and-replace/trunk/inc/Page/SqlImport.php

    r1390032 r1390214  
    3333
    3434        return esc_html__( 'SQL Import', 'search-and-replace' );
     35    }
     36
     37    /**
     38     * Return the static slug string.
     39     *
     40     * @return string
     41     */
     42    public function get_slug() {
     43
     44        return 'sql-import';
    3545    }
    3646
Note: See TracChangeset for help on using the changeset viewer.