Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.cmswt-InstantSearch .cmswt-CollectionMenu {
display: none;
}

.cmswt-Result-hits_unified_data .ais-Hits-item,
.cmswt-Result-hits_unified_data .ais-InfiniteHits-item {
background: #f5f5f5;
border-radius: 5px;
}

.cmswt-Result-hits_unified_data .ais-Hits-item .title,
.cmswt-Result-hits_unified_data .ais-InfiniteHits-item .title {
margin-top: 0;
margin-bottom: 0.25em;
}

.cmswt-theme-modern .hit-content {
padding: 1em!important;
}
55 changes: 48 additions & 7 deletions includes/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,46 @@ public static function get_instance(): ?Bootstrap {

protected function __construct() {
add_action( 'plugin_loaded', [ $this, 'init_modules' ] );
add_action( 'wp_footer', [ $this, 'load_template' ] );

}

public function init_modules() {
add_filter( 'cm_typesense_schema', [ $this, 'unified_schema' ], 20 );
add_action( 'wp_footer', [ $this, 'load_template' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
add_filter( 'cm_typesense_data_before_entry', [ $this, 'format_data' ], 10, 4 );
add_filter( 'cm_typesense_search_facet_title', [ $this, 'post_type_title' ], 10, 2 );
add_filter( 'cm_typesense_search_facet_label', [ $this, 'post_type_label' ], 10, 2 );
add_filter( 'cm_typesense_autocomplete_collections', [ $this, 'autocomplete_collection_rectify' ] );
}


public function unified_schema( $schema ) {
$schema['name'] = 'unified_data';

//taken from default TypesenseAPI.php schema
$schema['fields'] = [
[ 'name' => 'post_content', 'type' => 'string' ],
[ 'name' => 'post_title', 'type' => 'string' ],
[ 'name' => 'post_type', 'type' => 'string' ],
[ 'name' => 'post_type', 'type' => 'string', 'optional' => true, 'facet' => true ],
[ 'name' => 'post_author', 'type' => 'string' ],
[ 'name' => 'comment_count', 'type' => 'int64' ],
[ 'name' => 'is_sticky', 'type' => 'int32' ],
[ 'name' => 'post_excerpt', 'type' => 'string' ],
[ 'name' => 'post_date', 'type' => 'string' ],
[ 'name' => 'sort_by_date', 'type' => 'int64' ],
[ 'name' => 'post_id', 'type' => 'string' ],
[ 'name' => 'post_modified', 'type' => 'string' ],
[ 'name' => 'id', 'type' => 'string' ],
[ 'name' => 'permalink', 'type' => 'string' ],
[ 'name' => 'post_thumbnail', 'type' => 'string', 'optional' => true, 'index' => false ],
[ 'name' => 'post_thumbnail_html', 'type' => 'string', 'optional' => true, 'index' => false ],

/*
* Add And modify as necessary
//handled by default format document before entry
[ 'name' => 'category', 'type' => 'string[]', 'optional' => true, 'facet' => true ],
[ 'name' => 'cat_link', 'type' => 'string[]', 'optional' => true, 'index' => false ],
//Book post type specific options
[ 'name' => 'genre', 'type' => 'string[]', 'facet' => true, 'optional' => true ],
[ 'name' => 'price', 'type' => 'float', 'facet' => true, 'optional' => true ],
[ 'name' => 'author', 'type' => 'string', 'facet' => true, 'optional' => true ],
*/
];

$schema['default_sorting_field'] = 'sort_by_date';
Expand All @@ -56,6 +62,41 @@ public function load_template() {
require_once CM_UNIFIED_SEARCH_DIR_PATH . '/templates/hit-template.php';
}

public function enqueue_scripts() {
wp_register_style( 'cmswt-unified-search', CM_UNIFIED_SEARCH_ASSETS_URL . 'css/style.css', '', CM_UNIFIED_SEARCH_VERSION );
wp_enqueue_style( 'cmswt-unified-search' );
}

public function format_data( $formatted_data, $raw_data, $object_id, $schema_name ) {
if ( $raw_data instanceof \WP_Post ) {
$post_type_slug = get_post_type( $raw_data );
$post_type = get_post_type_object( $post_type_slug );
$formatted_data['post_type'] = $post_type->label;
}

return $formatted_data;
}

public function post_type_title( $label, $filter ) {
if ( $filter === 'post_type' ) {
$label = __( "Post Type", 'omni-search' );
}

return $label;
}

public function post_type_label( $label, $filter ) {
if ( $filter == 'post_type' ) {
$label = __( "Post Type", 'omni-search' );
}

return $label;
}

public function autocomplete_collection_rectify(): array {
return [ 'Search Results' => 'unified_data' ];
}

}

Bootstrap::get_instance();
3 changes: 2 additions & 1 deletion omni-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/


defined( 'CM_UNIFIED_SEARCH_VERSION' ) || define( 'CM_UNIFIED_SEARCH_VERSION', '1.0.0' );
defined( 'CM_UNIFIED_SEARCH_FILE' ) || define( 'CM_UNIFIED_SEARCH_FILE', __FILE__ );
defined( 'CM_UNIFIED_SEARCH_DIR_PATH' ) || define( 'CM_UNIFIED_SEARCH_DIR_PATH', dirname( __FILE__ ) );
defined( 'CM_UNIFIED_SEARCH_ASSETS_URL' ) || define( 'CM_UNIFIED_SEARCH_ASSETS_URL', plugins_url( 'assets/',__FILE__ ) );

require CM_UNIFIED_SEARCH_DIR_PATH.'/includes/Bootstrap.php';
40 changes: 0 additions & 40 deletions templates/hit-template.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,4 @@
<script type="text/html" id="tmpl-cmswt-Result-itemTemplate--unified_data">
<# if(data.taxonomy === undefined){ #>
<div class="hit-header">
<?php
//comment have to check //assets/placeholder.jpg because unfortunately that's how we saved it before version 1.6.0
?>
<?php // post_thumnail_html if exists ?>
<# if(data.post_thumbnail_html !== undefined){ #>
<a href="{{{data._highlightResult.permalink.value}}}" class="hit-header--link" rel="nofollow noopener">
{{{data.post_thumbnail_html}}}
</a>
<# } #>
<?php // post_thumbnail exists (backward compatibility) ?>
<#
if(
(data.post_thumbnail_html === undefined || data.post_thumbnail_html === '')
&& (data.post_thumbnail !== undefined
&& data.post_thumbnail !=
"<?php echo plugins_url( '', CODEMANAS_TYPESENSE_FILE_PATH ) . '//assets/placeholder.jpg'; ?>"
&& data.post_thumbnail != "" )
){
#>
<a href="{{{data._highlightResult.permalink.value}}}" class="hit-header--link" rel="nofollow noopener">
<img src="{{{data.post_thumbnail}}}"/>
</a>
<# } #>
<?php //Fallback ?>
<# if(
(data.post_thumbnail_html === undefined || data.post_thumbnail_html === '')
&& (data.post_thumbnail === undefined
|| data.post_thumbnail ===
'<?php echo plugins_url( '', CODEMANAS_TYPESENSE_FILE_PATH ) . '//assets/placeholder.jpg'; ?>'
|| data.post_thumbnail === ''
)
) { #>
<a href="{{{data._highlightResult.permalink.value}}}" class="hit-header--link" rel="nofollow noopener">
<img src="<?php echo plugins_url( '/assets/images/placeholder-300x300.jpg', CODEMANAS_TYPESENSE_FILE_PATH ); ?>"/>
</a>
<# } #>
</div>
<# } #>
<div class="hit-content">
<# if(data._highlightResult.permalink !== undefined ) { #>
<a href="{{{data._highlightResult.permalink.value}}}" rel="nofollow noopener"><h5 class="title">
Expand Down
18 changes: 18 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitbfc02e780a25e56573a1ea7d3a3d6d48::getLoader();
Loading