Skip to content

Commit

Permalink
Merge pull request #13 from sitecrafting/curated-results
Browse files Browse the repository at this point in the history
Curated results
  • Loading branch information
akoziolsc authored Oct 29, 2024
2 parents bbd85bc + 9dfc521 commit e561588
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": ">=7.3",
"composer/installers": "~1.0",
"sitecrafting/gearlab-tools-php": "v2.0.0-rc.03"
"sitecrafting/gearlab-tools-php": "^3.0"
},
"license": "MIT",
"authors": [
Expand Down
18 changes: 8 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions css/sitka-insights-search.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@
padding-bottom: 30px;
border-bottom: 1px solid #d8d8d8;
}
.curated-results {
background-color: #f6f6f6;

display: flex;
flex-direction: column;
gap: 20px;

padding: 20px;
}
.sitka-curated-results-section-headline {
margin-bottom: 0;
}
.sitka-curated-result {
padding: 20px;
border: 1px solid #d8d8d8;

display: flex;
flex-direction: column;
align-items: flex-start;
gap: 6px;
}
.curated-result-headline {
margin-bottom: 0;
}
.curated-result-text {}
.curated-result-link {}
.curated-result-button {
display: inline-block;
align-items: center;
column-gap: 12px;
padding: 20px 28px;
cursor: pointer;
border: 0;

text-decoration: none;

color: #000;
background: #00aeef;
-webkit-appearance: none;
}

.curated-result-button:hover {
color: #000;
text-decoration: none;
}
.sitka-search-card__label{
text-transform: uppercase;
margin: 0 0 5px 0;
Expand Down
3 changes: 2 additions & 1 deletion sitka-insights.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin URI: https://www.sitkainsights.com
* Author: SiteCrafting, Inc. <hello@sitecrafting.com>
* Author URI: https://www.sitecrafting.com/
* Version: 2.3.3
* Version: 3.0.0
* Requires PHP: 7.1
*/

Expand Down Expand Up @@ -97,6 +97,7 @@ function sitka_default_client() : Client {
'sitka_search_enabled',
'sitka_search_redirect',
'sitka_search_instead_enabled',
'sitka_search_curated_results_enabled',
],
]);
// Process any user updates
Expand Down
3 changes: 3 additions & 0 deletions src/Paginated.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
namespace Sitka\Plugin;

trait Paginated {

protected $pagination;

public function set_pagination(array $pagination) {
$this->pagination = $pagination;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$field = $data['curated_result_field'] ?? [];

?>

<?php foreach ($field['value'] as $field_link) : ?>

<?php $render = true; ?>
<?php if ( ($field_link['link_text'] ?? false) === false || empty($field_link['link_text'])) : $render = false; endif; ?>
<?php if ( ($field_link['url'] ?? false) === false || empty($field_link['url'])) : $render = false; endif; ?>

<?php if ($render) : ?>
<a href="<?= $field_link['url'] ?>" target="<?= (isset($field_link['new_window']) && $field_link['new_window'] ? '_blank' : '_self') ?>" class="curated-result-<?= $field['type'] ?>"><?= $field_link['link_text'] ?></a>
<?php endif; ?>

<?php endforeach; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$field = $data['curated_result_field'] ?? [];

?>

<?php foreach ($field['value'] as $field_value) : ?>

<?php if ($field_value['headline'] ?? false && !empty($field_value['headline'])) : ?>
<h3 class="curated-result-<?= $field['type'] ?>"><?= $field_value['headline'] ?></h3>
<?php endif; ?>

<?php endforeach; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$field = $data['curated_result_field'] ?? [];

?>

<?php foreach ($field['value'] as $field_link) : ?>

<?php $render = true; ?>
<?php if ( ($field_link['link_text'] ?? false) === false || empty($field_link['link_text'])) : $render = false; endif; ?>
<?php if ( ($field_link['url'] ?? false) === false || empty($field_link['url'])) : $render = false; endif; ?>

<?php if ($render) : ?>
<a href="<?= $field_link['url'] ?>" target="<?= ($field_link['new_window'] ? '_blank' : '_self') ?>" class="curated-result-<?= $field['type'] ?>"><?= $field_link['link_text'] ?></a>
<?php endif; ?>

<?php endforeach; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$field = $data['curated_result_field'] ?? [];
?>

<?php foreach ($field['value'] as $field_value) : ?>

<?php if ($field_value['text'] ?? false && !empty($field_value['text'])) : ?>
<div class="curated-result-<?= $field['type'] ?>"><?= $field_value['text'] ?></div>
<?php endif; ?>

<?php endforeach; ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$result = $data['curated_result'] ?? [];

?>

<?php foreach ($result['fields'] as $field) : ?>

<?= apply_filters('sitka/render', 'curated-result-field-templates/curated-result-field-template-'.$field['type'].'.php', array_merge($data, [
'curated_result_field' => $field,
])) ?>

<?php endforeach; ?>
10 changes: 10 additions & 0 deletions views/frontend/curated-result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$result = $data['curated_result'] ?? [];

?>
<div class="sitka-curated-result">
<?= apply_filters('sitka/render', 'curated-result-templates/curated-result-template-'.$result['template'].'.php', array_merge($data, [
'curated_result' => $result,
])) ?>
</div>
24 changes: 22 additions & 2 deletions views/frontend/search-results.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
$originalQuery = $response['originalQueryPhrase'] ?? '';
$supersedingSuggestion = $response['supersedingSuggestion'] ?? '';
$didYouMeanOption = get_option('sitka_search_instead_enabled') ?? 'disabled';
$curatedResultsOption = get_option('sitka_search_curated_results_enabled') ?? 'disabled';
$curatedResultsEnabled = $response['curatedResultsEnabled'] ?? false;

?>
<section class="sitka-search-form-container">
Expand All @@ -25,7 +27,7 @@
placeholder="Enter keyword or phrase"
title="Enter keyword or phrase"
/>
<?php if ($response['suggestionSupersededQuery'] && $didYouMeanOption == "enabled") : ?>
<?php if (isset($response['suggestionSupersededQuery']) && $response['suggestionSupersededQuery'] && $didYouMeanOption == "enabled") : ?>
<div class="superseding-suggestion-container">
<p>
Showing results for <?= $supersedingSuggestion ?> </br>
Expand All @@ -38,12 +40,30 @@
</div><!-- global-search -->
</div><!-- container -->
</section>

<?php if ($curatedResultsOption == "enabled" && $curatedResultsEnabled && isset($response['curatedResults']) && !empty($response['curatedResults'])) { ?>
<section class="sitka-search-results-container curated-results">

<h2 class="sitka-curated-results-section-headline"> Recommended results</h2>
<?php if (!empty($response['curatedResults'])) : ?>
<?php foreach ($response['curatedResults'] as $result) : ?>

<?= apply_filters('sitka/render', 'curated-result.php', array_merge($data, [
'curated_result' => $result,
])) ?>

<?php endforeach; ?>
<?php endif; ?>

</section>
<?php } ?>

<section class="sitka-search-results-container">
<div class="container">

<?php if (!empty($response['results'])) : ?>
<?php foreach ($response['results'] as $result) : ?>

<?= apply_filters('sitka/render', 'search-result.php', array_merge($data, [
'result' => $result,
])) ?>
Expand Down
30 changes: 26 additions & 4 deletions views/settings-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@
<input type="radio" id="env-prd" name="sitka_environment" value="production" <?= $data['sitka_environment'] === 'production' ? 'checked' : '' ?>>
<label for="env-prd">Production</label>
</div>
<?php
/* Option removed per request from Phil Price
* If a developer needs to test someting against the staging instance of the Sitka, simply remove the comments around this block of code to begin the staging option back in.
* This should be temporary change will be reverted when the plugin is reinstalled using composer.
<div class="sitka-field__env-option">
<input type="radio" id="env-stg" name="sitka_environment" value="staging" <?= $data['sitka_environment'] === 'staging' ? 'checked' : '' ?>>
<label for="env-stg">Staging</label>
<input type="radio" id="env-stg" name="sitka_environment" value="staging" <?= $data['sitka_environment'] === 'staging' ? 'checked' : '' ?>>
<label for="env-stg">Staging</label>
</div>
*/
?>
</div>
</div>

Expand All @@ -57,13 +63,29 @@
<label for="sitka_search_instead_enabled">Enable</label>
</div>
<div class="sitka-field__dym-option">
<input type="radio" id="sitka_search_instead_enabled" name="sitka_search_instead_enabled" value="disabled"<?= $data['sitka_search_instead_enabled'] !== 'enabled' ? 'checked' : '' ?>>
<label for="sitka_search_instead_enabled">Disable</label>
<input type="radio" id="sitka_search_instead_disabled" name="sitka_search_instead_enabled" value="disabled"<?= $data['sitka_search_instead_enabled'] !== 'enabled' ? 'checked' : '' ?>>
<label for="sitka_search_instead_disabled">Disable</label>
</div>
<p>When enabled, Sitka will present a link to override automatic typo correction.</p>
</div>
</div>

<div class="sitka-field sitka-field--flex">
<div class="sitka-field__label">
<label><b>Include Curated Results on the search page</b></label>
</div>
<div class="sitka-field__input">
<div class="sitka-field__dym-option">
<input type="radio" id="sitka_search_curated_results_enabled" name="sitka_search_curated_results_enabled" value="enabled"<?= $data['sitka_search_curated_results_enabled'] === 'enabled' ? 'checked' : '' ?>>
<label for="sitka_search_curated_results_enabled">Enable</label>
</div>
<div class="sitka-field__dym-option">
<input type="radio" id="sitka_search_curated_results_disabled" name="sitka_search_curated_results_enabled" value="disabled"<?= $data['sitka_search_curated_results_enabled'] !== 'enabled' ? 'checked' : '' ?>>
<label for="sitka_search_curated_results_disabled">Disable</label>
</div>
<p>When enabled, curated result will appear in search results. Please note: This feature must first be enabled in the Sitka Dashboard.</p>
</div>
</div>
<h3>Add Shortcode To Page</h3>
<div class="sitka-field">
<p>Please insert this shortcode on the page where you would like search results to appear.</p>
Expand Down

0 comments on commit e561588

Please sign in to comment.