Plugin Directory

Changeset 2225503


Ignore:
Timestamp:
01/10/2020 04:08:52 PM (6 years ago)
Author:
jayhybrid
Message:
  • Rewrote code for better understanding
  • Further updated RegEx for better Log extraction
  • Table is no longer a css grid
  • added Plugin, Folder, File, Line columns
Location:
debug-log-list/tags/0.2.1.1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • debug-log-list/tags/0.2.1.1/css/admin-style.css

    r2205111 r2225503  
    7171
    7272tr {
    73     display: grid;
    74     grid-auto-flow: column;
    75     grid-template-columns: repeat(3, minmax(max-content, 1fr)) minmax(min-content, 4fr) repeat(2, minmax(max-content, 1fr));
    76 
    7773    cursor: default;
    7874}
     
    8480
    8581th {
    86     text-align: left;   
     82    text-align: left;
     83}
     84
     85thead {
     86    position: sticky;
     87    top: 0;
     88    background-color: #f4f4f4;
    8789}
    8890
     
    9193}
    9294
    93 tbody tr { 
     95tbody tr {
    9496
    9597}
  • debug-log-list/tags/0.2.1.1/hybridsupply-log.php

    r2225500 r2225503  
    1010 */
    1111defined('HYBRIDSUPPLY_LOG_FILE') or define('HYBRIDSUPPLY_LOG_FILE', __FILE__);
    12 defined('HYBRIDSUPPLY_LOG_REGEX_EXTRACT') or define('HYBRIDSUPPLY_LOG_REGEX_EXTRACT', '/\[(\d{1,2}-\w{3}-\d{4} \d{2}:\d{2}:\d{2}).*\]\w*\w*\s*([ \w]*):?\s*(.+)/');
    1312
    1413function hybridsupply_log_options_html() {
     
    2726
    2827    if ( file_exists($logfile) ) {
    29       $logfile_contents = file_get_contents( $logfile );
    30 
    31       preg_match_all(HYBRIDSUPPLY_LOG_REGEX_EXTRACT , $logfile_contents, $output, PREG_SET_ORDER);
    32 
    33       for ($i=0; $i < count($output); $i++) {
    34         for ($ii=0; $ii < count($output[$i]); $ii++) {
    35           $part = $output[$i][$ii] ? $output[$i][$ii] : 'Unknown';
    36 
    37           if ( substr($part, 0, 4) === '<!--' ) {
    38             $part = esc_html($part);
    39           }
    40 
    41           switch ($ii) {
    42             case 0:
    43               $log[$i] = new stdClass();
    44               $log[$i]->fullmatch = $part;
    45               break;
    46 
    47             case 1:
    48               $log[$i]->time = $part;
    49               break;
    50 
    51             case 2:
    52               $log[$i]->type = $part;
    53               break;
    54 
    55             case 3:
    56               $hash = hash( 'crc32', $part );
    57 
    58               if ( ! in_array($hash, $log_hashes) ) {
    59                 $log_hashes[] = $hash;
    60               }
    61 
    62               $log[$i]->folder ='';
    63               $log[$i]->message = $part;
    64               $log[$i]->hash = $hash;
    65               $log[$i]->occurrences = 1;
    66               $log[$i]->options = '<form method="post"><input type="hidden" name="action" value="delete"><input type="hidden" name="hash" value="' . $hash . '"><button type="submit" class="button button">Remove</button></form>';
    67               break;
    68           }
    69         }
     28      /* Read file into an array */
     29      $logfile_contents = file( $logfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
     30
     31      /* Extract information per line */
     32      for ($i=0; $i < count($logfile_contents); $i++) {
     33        $n = count($log);
     34        $log[$n] = new stdClass();
     35
     36        /* Timestamp */
     37        if ( preg_match('/\d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2}/', $logfile_contents[$i], $matches) ) {
     38          $log[$n]->timestamp = $matches[0];
     39        }
     40        else {
     41          $log[$n]->timestamp = '';
     42        }
     43
     44        /* Type */
     45        if ( preg_match('/\]\s*([\w ]*\w)/', $logfile_contents[$i], $matches) ) {
     46          $log[$n]->type = $matches[1];
     47        }
     48        else {
     49          $log[$n]->type = '';
     50        }
     51
     52        /* Message */
     53        if ( preg_match('/\]\s*[\w ]*\w\W+(.+)/', $logfile_contents[$i], $matches) ) {
     54          $log[$n]->message = substr($matches[1], 0, 4) === '<!--' ? esc_html( $matches[1] ) : $matches[1];
     55        }
     56        else {
     57          $log[$n]->message = '';
     58        }
     59
     60        /* Hash */
     61        if ( preg_match('/\]\s*[\w ]*\w\W+(.+)/', $logfile_contents[$i], $matches) ) {
     62          $log[$n]->hash = hash( 'crc32' , $log[$n]->message );
     63        }
     64        else {
     65          $log[$n]->hash = '';
     66        }
     67
     68        /* Plugin */
     69        if ( preg_match('/plugins\/[^\/.]+/', $logfile_contents[$i], $matches) ) {
     70          $log[$n]->plugin = $matches[0];
     71        }
     72        else {
     73          $log[$n]->plugin = '';
     74        }
     75
     76        /* Folder */
     77        if ( preg_match('/ \/[\w\/\-_\.]+/', $logfile_contents[$i], $matches) ) {
     78          $log[$n]->folder = $matches[0];
     79        }
     80        else {
     81          $log[$n]->folder = '';
     82        }
     83
     84        /* File */
     85        if ( preg_match('/ \/[\w\/\-_\.]+/', $logfile_contents[$i], $matches) ) {
     86          $log[$n]->file = $matches[0];
     87        }
     88        else {
     89          $log[$n]->file = '';
     90        }
     91
     92        /* Line */
     93        if ( preg_match('/on line \d+/', $logfile_contents[$i], $matches) ) {
     94          $log[$n]->line = $matches[0];
     95        }
     96        else {
     97          $log[$n]->line = '';
     98        }
     99
     100        /* Occurrences */
     101        $log[$n]->occurrences = 1;
     102
     103        /* Options */
     104        $log[$n]->options = '<form method="post"><input type="hidden" name="action" value="delete"><input type="hidden" name="hash" value="' . $log[$n]->hash . '"><button type="submit" class="button button">Remove</button></form>';
    70105      }
    71 
    72       hybridsupply_log_count(array(
    73         'count' => count($log_hashes),
    74         'count_all' => count($log),
    75       ));
    76106
    77107      /*
     
    119149      <?php
    120150      if ( $logfile_contents && file_exists($logfile) ) {
    121         if ( $output ) { ?>
     151        if ( TRUE ) { ?>
    122152          <table>
    123153            <thead>
     
    125155                    <th class="time">Time</th>
    126156                    <th class="type">Type</th>
     157                <th class="message">Message</th>
     158                <th class="plugin">Plugin</th>
    127159                <th class="folder">Folder</th>
    128                     <th class="message">Message</th>
     160                <th class="file">File</th>
     161                <th class="line">Line</th>
    129162                    <th class="occurrences">Occurrences</th>
    130163                    <th class="options">Options</th>
     
    134167            <tbody>
    135168                <?php
    136               $log_hashes = array();
    137 
    138169                for ($i=0; $i < count($log); $i++) {
    139170                    if ( ! in_array($log[$i]->hash, $log_hashes) ) {
     
    148179                        foreach ($log[$i] as $key => $value) {
    149180                            switch ($key) {
    150                                 case 'time':
     181                                case 'timestamp':
    151182                        echo '<td>' . date(get_option('date_format') . ' ' . get_option('time_format'), strtotime( $value) ) . '</td>';
    152                         break;
    153 
    154                       case 'folder':
    155                         echo '<td>' . $value . '</td>';
    156183                        break;
    157184
    158185                      case 'message':
    159186                        echo '<td class="message">' . $value . '</td>';
     187                        break;
     188
     189                      case 'plugin':
     190                        $folder = substr($value, 8) ? substr($value, 8) : NULL;
     191                        $plugin;
     192
     193                        if ( $folder ) {
     194                          $files = glob(WP_PLUGIN_DIR . '/' . $folder . '/*.php');
     195
     196                          for ($i=0; $i < count( $files ); $i++) {
     197                            $plugin = get_plugin_data( $files[$i], FALSE, FALSE );
     198
     199                            if ( $plugin['Name'] != '' ) {
     200                              break;
     201                            }
     202                          }
     203
     204                          echo '<td>' . $plugin['Name'] . '</td>';
     205                        }
     206                        else {
     207                          echo '<td></td>';
     208                        }
     209                        break;
     210
     211                      case 'folder':
     212                        echo '<td>' . dirname($value) . '</td>';
     213                        break;
     214
     215                      case 'file':
     216                        echo '<td>' . basename($value) . '</td>';
     217                        break;
     218
     219                      case 'line':
     220                        echo '<td>' . substr($value, 8) . '</td>';
    160221                        break;
    161222
     
    193254          echo '<p>Sorry about that.</p>';
    194255          echo '<textarea>';
    195           echo $logfile_contents;
     256          echo var_dump($logfile_contents);
    196257          echo '</textarea>';
    197258        }
     
    338399 * Function: Extract Log
    339400 */
    340 function hybridsupply_log_count_determine() {
     401function hybridsupply_log_count_determine() {/*
    341402  $log = array();
    342403  $log_hashes = array();
     
    374435    'count_all' => count($log),
    375436  ));
    376 }
     437*/}
    377438
    378439/*
  • debug-log-list/tags/0.2.1.1/readme.txt

    r2225500 r2225503  
    3232== Changelog ==
    3333
     34= 0.2.1.1 =
     35
     36* Rewrote code for better understanding
     37* Further updated RegEx for better Log extraction
     38* Table is no longer a css grid
     39* added Plugin, Folder, File, Line columns
     40
    3441= 0.1.1.1 =
    3542
Note: See TracChangeset for help on using the changeset viewer.