- 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:
@@ -491,7 +491,14 @@ EOF;
|
|||||||
$this->searchTerm = $stringToSearch;
|
$this->searchTerm = $stringToSearch;
|
||||||
|
|
||||||
// Search the string in the cache and get all pages with matches
|
// Search the string in the cache and get all pages with matches
|
||||||
$list = $this->search($stringToSearch);
|
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);
|
$this->numberOfItems = count($list);
|
||||||
|
|
||||||
// Split the content in pages
|
// Split the content in pages
|
||||||
@@ -528,7 +535,9 @@ EOF;
|
|||||||
if ($this->webhook($webhook, false, false)) {
|
if ($this->webhook($webhook, false, false)) {
|
||||||
global $url;
|
global $url;
|
||||||
global $WHERE_AM_I;
|
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
|
// Get the pre-defined variable from the rule 69.pages.php
|
||||||
// We change the content to show in the website
|
// We change the content to show in the website
|
||||||
@@ -537,7 +546,8 @@ EOF;
|
|||||||
foreach ($this->pagesFound as $pageKey) {
|
foreach ($this->pagesFound as $pageKey) {
|
||||||
try {
|
try {
|
||||||
$page = new Page($pageKey);
|
$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)) {
|
if (!empty($excerpt)) {
|
||||||
$page->setField('content', '<p class="search-result-excerpt">' . $this->highlightTerms($excerpt, $this->searchTerm) . '</p>');
|
$page->setField('content', '<p class="search-result-excerpt">' . $this->highlightTerms($excerpt, $this->searchTerm) . '</p>');
|
||||||
}
|
}
|
||||||
@@ -690,7 +700,8 @@ EOF;
|
|||||||
|
|
||||||
// Process content
|
// Process content
|
||||||
$characterLimit = max(250, (int) $this->getValue('wordsToCachePerPage') * 6);
|
$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
|
// Include the page to the cache
|
||||||
$cache[$pageKey] = array(
|
$cache[$pageKey] = array(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
|
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
|
||||||
|
$isSearchPage = $searchPlugin && $searchPlugin->getSearchTerm() !== '';
|
||||||
$sidebarHtml = '';
|
$sidebarHtml = '';
|
||||||
ob_start();
|
ob_start();
|
||||||
Theme::plugins('siteSidebar');
|
Theme::plugins('siteSidebar');
|
||||||
@@ -19,7 +20,7 @@ $socialIconMap = array(
|
|||||||
);
|
);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if ($WHERE_AM_I !== 'search') : ?>
|
<?php if (!$isSearchPage) : ?>
|
||||||
<section class="neon-hero">
|
<section class="neon-hero">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="hero-panel">
|
<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>
|
<a href="<?php echo $page->permalink(); ?>"><?php echo htmlspecialchars($page->title(), ENT_QUOTES, 'UTF-8'); ?></a>
|
||||||
</h2>
|
</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>
|
<p class="post-description"><?php echo htmlspecialchars($page->description(), ENT_QUOTES, 'UTF-8'); ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
@@ -99,9 +100,9 @@ $socialIconMap = array(
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($page->readMore() || $WHERE_AM_I === 'search') : ?>
|
<?php if ($page->readMore() || $isSearchPage) : ?>
|
||||||
<a class="read-link" href="<?php echo $page->permalink(); ?>">
|
<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>
|
<i class="bi bi-arrow-right" aria-hidden="true"></i>
|
||||||
</a>
|
</a>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$searchPlugin = pluginActivated('pluginSearch') ? getPlugin('pluginSearch') : false;
|
$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;
|
$searchMinChars = $searchPlugin ? max(1, (int) $searchPlugin->getValue('minChars')) : 1;
|
||||||
$searchAction = json_encode(Theme::siteUrl() . 'search/');
|
$searchAction = json_encode(Theme::siteUrl() . 'search/');
|
||||||
$socialIconMap = array(
|
$socialIconMap = array(
|
||||||
|
|||||||
Reference in New Issue
Block a user