Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.1] Images in the Smart Search results #35612

Merged
merged 44 commits into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
455e4ea
Add the image object in the Result item
sakiss Feb 17, 2021
34c3a37
Add image to content Result
sakiss Feb 17, 2021
8a3928f
Add a 'show_image' setting, both to the finder's configuration and th…
sakiss Feb 17, 2021
656b19d
Show image defaults to 0 (hide)
sakiss Feb 17, 2021
4e71f5d
Add image class setting (as set for the com_content)
sakiss Feb 17, 2021
c31f773
Rename addImage to setImage (we only have 1)
sakiss Feb 17, 2021
507bbb3
getImage function
sakiss Feb 17, 2021
c4a48c7
print the image in the results layout
sakiss Feb 17, 2021
ebc7166
code style
sakiss Feb 17, 2021
e9ffcaa
Update administrator/components/com_finder/config.xml
sakiss Feb 17, 2021
622fb3d
Update administrator/components/com_finder/config.xml
sakiss Feb 17, 2021
295e207
Update administrator/components/com_finder/src/Indexer/Result.php
sakiss Feb 17, 2021
e2954f7
Update components/com_finder/tmpl/search/default.xml
sakiss Feb 17, 2021
489f29a
Update components/com_finder/tmpl/search/default_result.php
sakiss Feb 17, 2021
455d132
Fix language constants order
sakiss Feb 17, 2021
869cb37
Revert "Fix language constants order" as it ovewrites github commits
sakiss Feb 17, 2021
e7981c5
__DEPLOY_VERSION__
sakiss Feb 17, 2021
abc1837
alphabetic order to lang constants
sakiss Feb 17, 2021
dab69de
Update components/com_finder/tmpl/search/default_result.php
sakiss Feb 17, 2021
796b44b
Update components/com_finder/tmpl/search/default_result.php
sakiss Feb 17, 2021
b168bfb
CS
sakiss Feb 17, 2021
7c05273
Revert "CS"
sakiss Feb 17, 2021
448a12c
cs hell
sakiss Feb 17, 2021
38f868d
Tabs
sakiss Feb 17, 2021
b15ae5e
alt attribute
sakiss Feb 17, 2021
2f210ef
Remove description from class field
sakiss Feb 18, 2021
0d5d82b
initialize $extraAttr
sakiss Feb 18, 2021
531a261
Update administrator/components/com_finder/config.xml
sakiss Feb 18, 2021
7a161c6
docBlocks
sakiss Feb 18, 2021
a22bd51
Image Url and Image Alt as public scalar properties
sakiss Sep 1, 2021
910ccf4
Set image url and image alt directly, in finder plugin
sakiss Sep 1, 2021
a348ca0
Access image url and image alt directly in the layout
sakiss Sep 1, 2021
0195a8c
Alt & url strings docblock
sakiss Sep 1, 2021
5032e13
linked image
sakiss Sep 20, 2021
0f2b019
Update administrator/components/com_finder/config.xml
sakiss Sep 22, 2021
3a2f800
Update components/com_finder/tmpl/search/default.xml
sakiss Sep 22, 2021
084e874
Update components/com_finder/tmpl/search/default_result.php
sakiss Sep 24, 2021
84c0a1b
Update administrator/components/com_finder/src/Indexer/Result.php
sakiss Sep 24, 2021
a292150
Update administrator/components/com_finder/src/Indexer/Result.php
sakiss Sep 24, 2021
f5a3a87
1 indent
sakiss Sep 27, 2021
c32f0ca
!$images then false
sakiss Sep 27, 2021
627dbfd
Merge branch '4.1-dev' into finder_images
sakiss Sep 30, 2021
fc71eb3
Make Fedir Happy
sakiss Oct 7, 2021
75b5d25
Merge branch '4.1-dev' into finder_images
bembelimen Oct 24, 2021
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
31 changes: 31 additions & 0 deletions administrator/components/com_finder/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@
showon="show_description:1"
/>

<field
name="show_image"
type="radio"
label="COM_FINDER_CONFIG_SHOW_IMAGE_LABEL"
layout="joomla.form.field.radio.switcher"
default="0"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>

<field
name="image_class"
type="text"
label="COM_FINDER_CONFIG_IMAGE_CLASS_LABEL"
validate="CssIdentifier"
showon="show_image:1"
/>

<field
name="link_image"
type="radio"
label="COM_FINDER_CONFIG_LINKED_IMAGE_LABEL"
layout="joomla.form.field.radio.switcher"
default="0"
showon="show_image:1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="show_date"
type="radio"
Expand Down
3 changes: 3 additions & 0 deletions administrator/language/en-GB/com_finder.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ COM_FINDER_CONFIG_FILTER_COMMONWORDS_LABEL="Filter Common Words"
COM_FINDER_CONFIG_FILTER_NUMERICS_LABEL="Filter Numeric Terms"
COM_FINDER_CONFIG_GATHER_SEARCH_STATISTICS_LABEL="Gather Search Statistics"
COM_FINDER_CONFIG_HILIGHT_CONTENT_SEARCH_TERMS_LABEL="Highlight Search Terms"
COM_FINDER_CONFIG_IMAGE_CLASS_LABEL="Image Class"
COM_FINDER_CONFIG_LANGUAGE_DEFAULT_DEFAULT_LANGUAGE="Default Site Language"
COM_FINDER_CONFIG_LANGUAGE_DEFAULT_DESC="Set the language to be used for non-multilingual sites or content marked as \"All\"."
COM_FINDER_CONFIG_LANGUAGE_DEFAULT_LABEL="Default Language"
COM_FINDER_CONFIG_LANGUAGE_DEFAULT_NONE="None"
COM_FINDER_CONFIG_LINKED_IMAGE_LABEL="Linked Image"
COM_FINDER_CONFIG_MEMORY_TABLE_LIMIT_LABEL="Memory Table Limit"
COM_FINDER_CONFIG_META_MULTIPLIER_LABEL="Metadata Weight Multiplier"
COM_FINDER_CONFIG_MISC_MULTIPLIER_LABEL="Misc. Text Weight Multiplier"
Expand All @@ -34,6 +36,7 @@ COM_FINDER_CONFIG_SHOW_DATE_FILTERS_LABEL="Date Filters"
COM_FINDER_CONFIG_SHOW_DATE_LABEL="Result Date"
COM_FINDER_CONFIG_SHOW_DESCRIPTION_LABEL="Result Description"
COM_FINDER_CONFIG_SHOW_EXPLAINED_QUERY_LABEL="Query Explanation"
COM_FINDER_CONFIG_SHOW_IMAGE_LABEL="Result Image"
COM_FINDER_CONFIG_SHOW_SUGGESTED_QUERY_LABEL="Did You Mean"
COM_FINDER_CONFIG_SHOW_TAXONOMY_LABEL="Result Taxonomy"
COM_FINDER_CONFIG_SHOW_URL_LABEL="Result URL"
Expand Down
34 changes: 34 additions & 0 deletions components/com_finder/tmpl/search/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,40 @@
size="5"
useglobal="true"
/>
<field
name="show_image"
type="list"
label="COM_FINDER_CONFIG_SHOW_IMAGE_LABEL"
default=""
useglobal="true"
class="form-select-color-state"
validate="options"
>
<option value="1">JSHOW</option>
<option value="0">JHIDE</option>
</field>
<field
name="image_class"
type="text"
label="COM_FINDER_CONFIG_IMAGE_CLASS_LABEL"
default=""
useglobal="true"
validate="CssIdentifier"
showon="show_image!:0"
/>
<field
name="link_image"
type="list"
label="COM_FINDER_CONFIG_LINKED_IMAGE_LABEL"
default=""
useglobal="true"
class="form-select-color-state"
validate="options"
showon="show_image!:0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field
name="show_date"
type="list"
Expand Down
36 changes: 35 additions & 1 deletion components/com_finder/tmpl/search/default_result.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
use Joomla\Component\Finder\Administrator\Indexer\Helper;
use Joomla\Component\Finder\Administrator\Indexer\Taxonomy;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;

$user = Factory::getUser();
$user = Factory::getApplication()->getIdentity();

$show_description = $this->params->get('show_description', 1);

Expand Down Expand Up @@ -48,6 +49,22 @@
$description = HTMLHelper::_('string.truncate', StringHelper::substr($full_description, $start), $desc_length, true);
}

$showImage = $this->params->get('show_image', 0);

if ($showImage && !empty($this->result->imageUrl))
{
$imageclass = $this->params->get('image_class', '');
$image = HTMLHelper::cleanImageURL($this->result->imageUrl);
$extraAttr = '';

// Set lazyloading only for images which have width and height attributes
if ((isset($image->attributes['width']) && (int) $image->attributes['width'] > 0)
&& (isset($image->attributes['height']) && (int) $image->attributes['height'] > 0))
{
$extraAttr = ArrayHelper::toString($image->attributes) . ' loading="lazy"';
}
}

$icon = '';
if (!empty($this->result->mime)) :
$icon = '<span class="icon-file-' . $this->result->mime . '" aria-hidden="true"></span> ';
Expand All @@ -59,6 +76,23 @@
endif;
?>
<li class="result__item">
<?php if (isset($image)) : ?>
<figure class="<?php echo htmlspecialchars($imageclass, ENT_COMPAT, 'UTF-8'); ?> result__image">
<?php if ($this->params->get('link_image') && $this->result->route) : ?>
<a href="<?php echo Route::_($this->result->route); ?>">
<img src="<?php echo htmlspecialchars($image->url, ENT_COMPAT, 'UTF-8'); ?>"
alt="<?php echo htmlspecialchars($this->result->imageAlt, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $extraAttr; ?>
/>
</a>
<?php else : ?>
<img src="<?php echo htmlspecialchars($image->url, ENT_COMPAT, 'UTF-8'); ?>"
alt="<?php echo htmlspecialchars($this->result->imageAlt, ENT_COMPAT, 'UTF-8'); ?>"
<?php echo $extraAttr; ?>
/>
<?php endif; ?>
</figure>
<?php endif; ?>
<p class="result__title">
<?php if ($this->result->route) : ?>
<?php echo HTMLHelper::link(
Expand Down
9 changes: 9 additions & 0 deletions plugins/finder/content/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ protected function index(Result $item)
$item->title = $title;
}

$images = $item->images ? json_decode($item->images) : false;

// Add the image.
if ($images && !empty($images->image_intro))
{
$item->imageUrl = $images->image_intro;
$item->imageAlt = $images->image_intro_alt ?? '';
}

// Add the meta author.
$item->metaauthor = $item->metadata->get('author');

Expand Down