-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
25 lines (23 loc) · 731 Bytes
/
index.php
File metadata and controls
25 lines (23 loc) · 731 Bytes
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
<?php namespace x\lazy;
function content($content) {
if (!$content || (false === \strpos($content, '</iframe>') && false === \strpos($content, '<img'))) {
return $content;
}
$r = "";
foreach (\apart($content) as $v) {
$n = \substr($v[0], 1, \strcspn($v[0], " \n\r\t", 1));
if ('iframe' !== $n && 'img' !== $n) {
$r .= $v[0];
continue;
}
$t = new \HTML($v[0]);
if (isset($t['loading']) || 0 === \strpos($t['src'] ?? "", 'data:image/')) {
$r .= $v[0];
continue;
}
$t['loading'] = 'lazy';
$r .= $t;
}
return "" !== $r ? $r : null;
}
\Hook::set('content', __NAMESPACE__ . "\\content", 20);