-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.php
86 lines (76 loc) · 3.05 KB
/
script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Copyright (C) 2018 https://github.com/konmavrakis/
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* $chars array taken from: https://wordpress.org/plugins/greeklish-permalink/
*/
$chars = array(
'/[αάΑΆ]/u' => 'a',
'/[βΒ]/u' => 'v',
'/[γΓ]/u' => 'g',
'/[δΔ]/u' => 'd',
'/[εέΕΈ]/u' => 'e',
'/[ζΖ]/u' => 'z',
'/[ηήΗΉ]/u' => 'i',
'/[θΘ]/u' => 'th',
'/[ιίϊΐΙΊΪ]/u' => 'i',
'/[κΚ]/u' => 'k',
'/[λΛ]/u' => 'l',
'/[μΜ]/u' => 'm',
'/[νΝ]/u' => 'n',
'/[ξΞ]/u' => 'x',
'/[οόΟΌ]/u' => 'o',
'/[πΠ]/u' => 'p',
'/[ρΡ]/u' => 'r',
'/[σςΣ]/u' => 's',
'/[τΤ]/u' => 't',
'/[υύϋΰΥΎΫ]/u' => 'y',
'/[φΦ]/iu' => 'f',
'/[χΧ]/u' => 'ch',
'/[ψΨ]/u' => 'ps',
'/[ωώ]/iu' => 'o',
'/[αΑ][ιίΙΊ]/u' => 'e',
'/[οΟΕε][ιίΙΊ]/u' => 'i',
'/[αΑ][υύΥΎ]([θΘκΚξΞπΠσςΣτTφΡχΧψΨ]|\s|$)/u' => 'af$1',
'/[αΑ][υύΥΎ]/u' => 'av',
'/[εΕ][υύΥΎ]([θΘκΚξΞπΠσςΣτTφΡχΧψΨ]|\s|$)/u' => 'ef$1',
'/[εΕ][υύΥΎ]/u' => 'ev',
'/[οΟ][υύΥΎ]/u' => 'ou',
'/(^|\s)[μΜ][πΠ]/u' => '$1b',
'/[μΜ][πΠ](\s|$)/u' => 'b$1',
'/[μΜ][πΠ]/u' => 'b',
'/[νΝ][τΤ]/u' => 'nt',
'/[τΤ][σΣ]/u' => 'ts',
'/[τΤ][ζΖ]/u' => 'tz',
'/[γΓ][γΓ]/u' => 'ng',
'/[γΓ][κΚ]/u' => 'gk',
'/[ηΗ][υΥ]([θΘκΚξΞπΠσςΣτTφΡχΧψΨ]|\s|$)/u' => 'if$1',
'/[ηΗ][υΥ]/u' => 'iu',
);
$output = [];
$source = isset( $argv[1] ) ? $argv[1] : print_r( 'No source provided' ) . exit;
$stream = fopen( $source, 'r' );
while ( $line = fgets( $stream ) ) {
//Check if the url is encoded and decode it
if( preg_match( '~%[0-9A-F]{2}~i', $line ) ){
$line_encoded = urldecode( $line );
} else {
$line_encoded = $line;
}
$output[] = preg_replace( array_keys( $chars ), array_values( $chars ), $line_encoded );
}
return isset( $argv[2]) ? file_put_contents( $argv[2], $output ) . print_r( 'File saved!' ) : print_r( $output );
?>