- Fixed the cross-theme blank search issue in [plugin.php](/Users/tyemeclifford/Documents/GH/blog/bl-plugins/search/plugin.php).

The important change: search still intercepts the route early, but 
before themes render it now feeds results through the normal 
home/listing state. That avoids themes going blank when they do not know 
how to render a custom search state.
I also made search safer:
Indexes raw page text instead of fully rendered content.
Uses raw content for excerpts.
Guards the search call so exceptions do not white-screen the page.
Updated Dark Neon so it still detects search pages correctly after this 
compatibility change.
This commit is contained in:
Ty Clifford
2026-07-03 09:34:49 -04:00
parent 9d9790976a
commit d149a0bf8f
3 changed files with 22 additions and 9 deletions
+14 -3
View File
@@ -491,7 +491,14 @@ EOF;
$this->searchTerm = $stringToSearch;
// Search the string in the cache and get all pages with matches
try {
$list = $this->search($stringToSearch);
} catch (Exception $e) {
if (class_exists('Log')) {
Log::set(__METHOD__ . LOG_SEP . 'Search failed: ' . $e->getMessage());
}
$list = array();
}
$this->numberOfItems = count($list);
// Split the content in pages
@@ -528,7 +535,9 @@ EOF;
if ($this->webhook($webhook, false, false)) {
global $url;
global $WHERE_AM_I;
$WHERE_AM_I = 'search';
// Feed search results through regular listing templates for theme compatibility.
$url->setWhereAmI('home');
$WHERE_AM_I = 'home';
// Get the pre-defined variable from the rule 69.pages.php
// We change the content to show in the website
@@ -537,7 +546,8 @@ EOF;
foreach ($this->pagesFound as $pageKey) {
try {
$page = new Page($pageKey);
$excerpt = $this->getSearchExcerpt($page->content(), $this->searchTerm);
$contentSource = method_exists($page, 'contentRaw') ? $page->contentRaw() : $page->content();
$excerpt = $this->getSearchExcerpt($contentSource, $this->searchTerm);
if (!empty($excerpt)) {
$page->setField('content', '<p class="search-result-excerpt">' . $this->highlightTerms($excerpt, $this->searchTerm) . '</p>');
}
@@ -690,7 +700,8 @@ EOF;
// Process content
$characterLimit = max(250, (int) $this->getValue('wordsToCachePerPage') * 6);
$content = Text::truncate($this->plainText($page->content()), $characterLimit, '');
$contentSource = method_exists($page, 'contentRaw') ? $page->contentRaw() : $page->content();
$content = Text::truncate($this->plainText($contentSource), $characterLimit, '');
// Include the page to the cache
$cache[$pageKey] = array(
+5 -4
View File
@@ -1,5 +1,6 @@
<?php
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
$isSearchPage = $searchPlugin && $searchPlugin->getSearchTerm() !== '';
$sidebarHtml = '';
ob_start();
Theme::plugins('siteSidebar');
@@ -19,7 +20,7 @@ $socialIconMap = array(
);
?>
<?php if ($WHERE_AM_I !== 'search') : ?>
<?php if (!$isSearchPage) : ?>
<section class="neon-hero">
<div class="container">
<div class="hero-panel">
@@ -82,7 +83,7 @@ $socialIconMap = array(
<a href="<?php echo $page->permalink(); ?>"><?php echo htmlspecialchars($page->title(), ENT_QUOTES, 'UTF-8'); ?></a>
</h2>
<?php if ($page->description() && $WHERE_AM_I !== 'search') : ?>
<?php if ($page->description() && !$isSearchPage) : ?>
<p class="post-description"><?php echo htmlspecialchars($page->description(), ENT_QUOTES, 'UTF-8'); ?></p>
<?php endif; ?>
@@ -99,9 +100,9 @@ $socialIconMap = array(
</div>
<?php endif; ?>
<?php if ($page->readMore() || $WHERE_AM_I === 'search') : ?>
<?php if ($page->readMore() || $isSearchPage) : ?>
<a class="read-link" href="<?php echo $page->permalink(); ?>">
<span><?php echo ($WHERE_AM_I === 'search') ? $L->get('Open result') : $L->get('Read more'); ?></span>
<span><?php echo $isSearchPage ? $L->get('Open result') : $L->get('Read more'); ?></span>
<i class="bi bi-arrow-right" aria-hidden="true"></i>
</a>
<?php endif; ?>
+2 -1
View File
@@ -1,6 +1,7 @@
<?php
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
$searchValue = ($searchPlugin && $WHERE_AM_I === 'search') ? $searchPlugin->getSearchTerm() : '';
$isSearchPage = $searchPlugin && $searchPlugin->getSearchTerm() !== '';
$searchValue = $isSearchPage ? $searchPlugin->getSearchTerm() : '';
$searchMinChars = $searchPlugin ? max(1, (int) $searchPlugin->getValue('minChars')) : 1;
$searchAction = json_encode(Theme::siteUrl() . 'search/');
$socialIconMap = array(