Skip to content

Commit a8d3af9

Browse files
committed
Updated Web Informer widget
1 parent 2a612dd commit a8d3af9

File tree

2 files changed

+4
-61
lines changed

2 files changed

+4
-61
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "textpattern-com",
33
"description": "Official website of the Textpattern project.",
4-
"version": "1.7.0",
4+
"version": "1.7.1",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/textpattern/textpattern-com-website"
Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,12 @@
1-
<h3>Featured at:</h3>
21
<txp:php>
32
if (!gps('txpreview')) {
4-
global $prefs;
5-
6-
require_once __DIR__ .'/../../vendor/autoload.php';
7-
8-
// Do not let them slow us down.
93
$opts = array('http' => array('timeout' => 1.6));
10-
$url = 'https://website.informer.com/w/textpatternwidget.php';
11-
4+
$url = 'https://website.informer.com/widget/textpattern.com-2';
125
$context = stream_context_create($opts);
136
$widget = file_get_contents($url, false, $context);
147

15-
if (($widget)) {
16-
// Don't let them inject unwanted HTML.
17-
$config = HTMLPurifier_Config::createDefault();
18-
$config->set('Cache.SerializerPath', $prefs['tempdir']);
19-
$config->set('HTML.Allowed', 'div[class|id], a[class|href]');
20-
$config->set('Attr.EnableID', true);
21-
$config->set('Attr.IDPrefix', 'informer-');
22-
$config->set('URI.AllowedSchemes', array('http', 'https'));
23-
$purifier = new HTMLPurifier($config);
24-
25-
$widget = $purifier->purify($widget);
26-
27-
// Wrangle the output to simplify the returned markup.
28-
$doc = new \DOMDocument();
29-
$doc->loadHTML(mb_convert_encoding($widget, 'HTML-ENTITIES', 'UTF-8'));
30-
$finder = new \DomXPath($doc);
31-
32-
// Extract the header string.
33-
$classname = "b-webi-header";
34-
$heading = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
35-
$headStr = trim($heading->item(0)->nodeValue);
36-
37-
// Extract all the anchors and their attributes.
38-
$classname = "b-webi-link";
39-
$links = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
40-
41-
$linkInfo = array();
42-
43-
for ($idx = 0; $idx < $links->length; $idx++) {
44-
$me = $links->item($idx);
45-
$linkInfo[$idx]['href'] = $me->getAttribute('href');
46-
$linkInfo[$idx]['content'] = trim($me->nodeValue);
47-
}
48-
49-
// Create the simpler HTML.
50-
$out = <<<EOHTML
51-
<ul class="list--no-bullets ellipsis">
52-
53-
EOHTML;
54-
55-
foreach ($linkInfo as $row) {
56-
$out .= '<li><a rel="external" referrerpolicy="origin" href="'.$row['href'].'">'.$row['content'].'</a></li>'.n;
57-
}
58-
59-
// Hard-code the footer, since it's easier than trying to get innerHTML from DOMDocument.
60-
$out .= <<<EOHTML
61-
</ul>
62-
<small>Powered by <a rel="external" href="https://website.informer.com/">website.informer.com</a></small>
63-
EOHTML;
64-
65-
echo n,comment(date('c'));
66-
echo $out;
8+
if ($widget) {
9+
echo $widget;
6710
}
6811
}
6912
</txp:php>

0 commit comments

Comments
 (0)