update to kirby 4.8
This commit is contained in:
commit
7d7df341d1
636 changed files with 139949 additions and 0 deletions
36
site/plugins/content-size/index.php
Normal file
36
site/plugins/content-size/index.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
Kirby::plugin('adrienpayet/content-size', [
|
||||
'pageMethods' => [
|
||||
'contentSize' => function () {
|
||||
$contentSize = 0;
|
||||
$site = site();
|
||||
$html = $this->render();
|
||||
$dom = new DOMDocument();
|
||||
@$dom->loadHTML($html);
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
$currentDivs = $xpath->query('//div[contains(@class, "current")]');
|
||||
|
||||
if ($currentDivs->length > 0) {
|
||||
$content = $dom->saveHTML($currentDivs->item(0));
|
||||
$contentSize += strlen($content);
|
||||
} else {
|
||||
throw new Exception("No content div founded.", 1);
|
||||
}
|
||||
|
||||
$images = $dom->getElementsByTagName('img');
|
||||
foreach ($images as $image) {
|
||||
$src = $image->getAttribute('src');
|
||||
|
||||
if (!empty($src)) {
|
||||
$localSrc = str_replace($site->url(), realpath(__DIR__ . '/../../../'), $src);
|
||||
|
||||
$contentSize += filesize($localSrc);
|
||||
}
|
||||
}
|
||||
|
||||
return $contentSize;
|
||||
}
|
||||
]
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue