Created
April 8, 2020 09:28
-
-
Save ozh/a09cc69bc6d478d9aa370bf8d09fd8b0 to your computer and use it in GitHub Desktop.
Perl script to generate hook list in YOURLS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl | |
use File::Find; | |
my $dir = '.'; | |
my %actions; | |
my %filters; | |
$dir = $ARGV[0] if ($#ARGV != -1); | |
find(\&processfile, $dir); | |
sub processfile | |
{ | |
if($_ eq '.git') #Don't go into .git | |
{ | |
$File::Find::prune = 1; | |
return; | |
} | |
my $sourcefile = $_; #Preserve filename | |
open SOURCEFILE, $sourcefile; | |
my $line = 0; #Count linenumbers | |
while(<SOURCEFILE>) | |
{ | |
$line++; | |
if($_ =~ m/yourls_do_action\(\s*'(\w*)'/) #Search for first argument surrounded by quotes | |
{ | |
$actions{$1} = {'line' => $line, 'file' => $File::Find::name} | |
} | |
if($_ =~ m/yourls_apply_filter\(\s*'(\w*)'/) | |
{ | |
$filters{$1} = {'line' => $line, 'file' => $File::Find::name} | |
} | |
} | |
close SOURCEFILE; | |
} | |
foreach $key (sort keys %actions) | |
{ | |
$file = $actions{$key}{'file'}; | |
$file =~ s/$dir//; | |
print "<tr class='action'><td class='hook action'>ACTION</td><td class='name'>" . $key . "</td><td class='file'>" . $file . ", line " . $actions{$key}{'line'} . "</td></tr>\n"; | |
} | |
foreach $key (sort keys %filters) | |
{ | |
$file = $filters{$key}{'file'}; | |
$file =~ s/$dir//; | |
print "<tr class='filter'><td class='hook filter'>FILTER</td><td class='name'>" . $key . "</td><td class='file'>" . $file . ", line " . $filters{$key}{'line'} . "</td></tr>\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment