Compare commits

..

2 Commits

Author SHA1 Message Date
598d28551d feat: add a power html rewriter to customized my old pages 2022-11-06 11:42:22 +01:00
dd7f80ee5a feat: remove HTML blocks 2022-10-19 21:50:10 +02:00
3 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,8 @@
<div id="hosted-on" class="widget widget_text">
<h5>Auto-hébergé sur mon NAS</h5>
<div class="textwidget">
<div style="text-align: center">
Ce blog est hébergé à la maison avec de l'Internet fournit par <a href="https://www.franciliens.net">Franciliens.net</a>
</div>
</div>
</div>

View File

@ -0,0 +1,4 @@
<div style="background-color: orange;border-radius: 6px;font-weight: bold;margin-bottom: 10px;" class="container">
Ceci est la version legacy de mon blog si vous voulez voir les nouveaux articles et et savoir pourquoi c'est par
<a href="/new">ICI</a>
</div>

View File

@ -111,6 +111,24 @@ const ARCHIVARIX_INCLUDE_CUSTOM = array(
'REGEX' => 0,
'POSITION' => -1,
],
// remove twitter widget in the right column on all the pages
[
'OPERATION' => 'REMOVE',
'XPATH' => '//*[@id="twitter-2"]',
],
[
'OPERATION' => 'REPLACE',
'XPATH' => '//*[@id="text-6"]',
'FILE' => 'hosted_by_franciliens.html',
],
[
'OPERATION' => 'APPEND',
'XPATH' => '//nav[contains(@class, "navbar")]',
'FILE' => 'warning_new_blog.php',
],
);
/**
@ -368,7 +386,7 @@ function prepareContent( $file, $sourcePath )
$content = file_get_contents( $file );
foreach ( $LOADER['ARCHIVARIX_INCLUDE_CUSTOM'] as $includeCustom ) {
if ( $includeCustom['FILE'] ) {
if ( $includeCustom['FILE'] && $includeCustom['KEYPHRASE'] ) {
global $includeRule;
$includeRule = $includeCustom;
ob_start();
@ -391,8 +409,36 @@ function prepareContent( $file, $sourcePath )
}
$content = preg_replace( '~' . $includeCustom['KEYPHRASE'] . '~is', $includedContent, $content, $includeCustom['LIMIT'] );
} else if ( $includeCustom['OPERATION'] && $includeCustom['XPATH'] ) {
$doc = new DOMDocument();
$doc->loadHTML($content);
$xpath = new DOMXpath($doc);
$elementsToChange = $xpath->query($includeCustom['XPATH']);
foreach ( $elementsToChange as $elementToChange ) {
switch ( $includeCustom['OPERATION'] ) {
case 'APPEND':
case 'REPLACE' :
$fragment = $doc->createDocumentFragment();
ob_start();
require($sourcePath . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . $includeCustom['FILE']);
$fragment->appendXML(ob_get_clean());
if ($includeCustom['OPERATION'] === 'APPEND') {
$elementToChange->append($fragment->firstChild);
} else {
$elementToChange->replaceWith($fragment->firstChild);
}
break;
case 'REMOVE' :
$elementToChange->remove();
break;
}
}
$content = $doc->saveHTML();
}
}
if ( function_exists( 'mb_strlen' ) ) {
header( 'Content-Length: ' . mb_strlen( $content, '8bit' ), true );
}