-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-webmentions.php
77 lines (48 loc) · 2.04 KB
/
get-webmentions.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
<?php
require_once 'loader.php';
$pages = \ArtlungLab\Nav::getMetadata();
foreach ($pages as $slug => $metadata) {
// echo "Checking $slug\n";
$webmentions_file = "webmention_data/$slug.json";
$yaml_file = "web/$slug/$slug.yaml";
if (!file_exists($yaml_file)) {
print "No YAML file for $slug, it's not a real page yet, skipping...";
continue;
}
$yaml = Spyc::YAMLLoad($yaml_file);
if (isset($yaml[\ArtlungLab\WebmentionIoGetter::WEBMENTION_LAST_CHECKED_KEY])) {
$last_checked = $yaml[\ArtlungLab\WebmentionIoGetter::WEBMENTION_LAST_CHECKED_KEY];
// print "Last checked date for $slug is $last_checked\n";
if (is_file($webmentions_file)) {
// print "There is a webmentions file for $slug\n";
$webmentions = json_decode(file_get_contents($webmentions_file), true);
$yaml[\ArtlungLab\WebmentionIoGetter::WEBMENTION_COUNT_KEY] = count($webmentions);
$count = count($webmentions);
if ($count > 0) {
print "Count for $slug is " . count($webmentions) . "\n";
}
$yaml_text = Spyc::YAMLDump($yaml);
file_put_contents($yaml_file, $yaml_text);
}
} else {
$last_checked = 0;
print "No last checked date for $slug, setting to 0\n";
}
// only get them once a week
if (time() - $last_checked < 604800) {
// print "Skipping $slug, last checked $last_checked\n";
continue;
}
$success = \ArtlungLab\WebmentionIoGetter::getAndStashWebmentions($slug, $metadata['canonical_url']);
if (!$success) {
print "Failed to get and stash webmentions for $slug\n";
continue;
}
$yaml[\ArtlungLab\WebmentionIoGetter::WEBMENTION_LAST_CHECKED_KEY] = time() ?? 0;
$yaml = Spyc::YAMLDump($yaml);
file_put_contents($yaml_file, $yaml);
print "Updated $slug\n";
}
echo "Done. If the webmention count changed,\n";
echo "be sure to run composer updatenav\n";
echo "and composer snifferfix\n";