From: Alexander Ebert Date: Fri, 22 Jun 2018 11:31:12 +0000 (+0200) Subject: Custom icons and images for search result objects X-Git-Tag: 5.2.0_Alpha_1~140^2~15 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9ff2f3bc22ac94ecf3e6d9257a083fa61b66bc01;p=GitHub%2FWoltLab%2FWCF.git Custom icons and images for search result objects See #2581 --- diff --git a/com.woltlab.wcf/templates/searchResultList.tpl b/com.woltlab.wcf/templates/searchResultList.tpl index 291d73737b..b9b62eee57 100644 --- a/com.woltlab.wcf/templates/searchResultList.tpl +++ b/com.woltlab.wcf/templates/searchResultList.tpl @@ -3,14 +3,22 @@ {foreach from=$objects item=message}
  • - {if $message->getUserProfile()} - {if $message->getUserProfile()->userID} - {@$message->getUserProfile()->getAvatar()->getImageTag(48)} + {assign var=_messageObjectHash value=$message|spl_object_hash} + {assign var=_messageCustomIcon value=$customIcons[$_messageObjectHash]} + {if $_messageCustomIcon === ''} + {if $message->getUserProfile()} + {if $message->getUserProfile()->userID} + {@$message->getUserProfile()->getAvatar()->getImageTag(48)} + {else} +

    {@$message->getUserProfile()->getAvatar()->getImageTag(48)}

    + {/if} {else} -

    {@$message->getUserProfile()->getAvatar()->getImageTag(48)}

    +

    {/if} + {elseif $_messageCustomIcon|strpos:'fa-' === 0} +

    {else} -

    +

    {/if}
    @@ -39,4 +47,4 @@
  • {/foreach} - \ No newline at end of file + diff --git a/wcfsetup/install/files/lib/data/search/ICustomIconSearchResultObject.class.php b/wcfsetup/install/files/lib/data/search/ICustomIconSearchResultObject.class.php new file mode 100644 index 0000000000..846cf62124 --- /dev/null +++ b/wcfsetup/install/files/lib/data/search/ICustomIconSearchResultObject.class.php @@ -0,0 +1,24 @@ + + * @package WoltLabSuite\Core\Data\Search + * @since 3.2 + */ +interface ICustomIconSearchResultObject extends ISearchResultObject { + /** + * Returns either a FontAwesome icon name including the `fa-` prefix or + * a string that is interpreted as an URL to an image that can be scaled + * to 48x48. Returning an empty string will trigger the default behavior. + * + * @return string + */ + public function getCustomSearchResultIcon(): string; +} diff --git a/wcfsetup/install/files/lib/page/SearchResultPage.class.php b/wcfsetup/install/files/lib/page/SearchResultPage.class.php index ec42346d41..00e8d5b84b 100644 --- a/wcfsetup/install/files/lib/page/SearchResultPage.class.php +++ b/wcfsetup/install/files/lib/page/SearchResultPage.class.php @@ -1,6 +1,7 @@ getCustomSearchResultIcon(); + } + $this->messages[] = $message; + $this->customIcons[spl_object_hash($message)] = $customIcon; } } } @@ -171,7 +184,8 @@ class SearchResultPage extends MultipleLinkPage { 'resultListTemplateName' => $this->resultListTemplateName, 'resultListApplication' => $this->resultListApplication, 'application' => ApplicationHandler::getInstance()->getAbbreviation(ApplicationHandler::getInstance()->getActiveApplication()->packageID), - 'searchPreselectObjectType' => $searchPreselectObjectType + 'searchPreselectObjectType' => $searchPreselectObjectType, + 'customIcons' => $this->customIcons ]); }