forked from justdeleteme/justdelete.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.php
35 lines (29 loc) · 874 Bytes
/
sort.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
<?php
$file = "sites.json";
$sites = json_decode(file_get_contents($file));
$cs1 = md5(json_encode($sites, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
if (!is_null($sites)) {
usort($sites, function($a, $b)
{
$a = strtolower($a->name);
$b = strtolower($b->name);
if ($a < $b) {
return -1;
}
if ($a > $b) {
return 1;
}
return 0;
});
$sites_sort = json_encode($sites, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$cs2 = md5($sites_sort);
if ($cs1 != $cs2) {
$sites_sort = preg_replace("/(},)(\s+{)/", "$1\n$2", $sites_sort);
file_put_contents($file, $sites_sort);
} else {
echo "$file is already sorted.\n";
}
} else {
echo "$file is not valid.\n";
}
?>