{foreach from=$objects item=message}
<li>
<div class="box48">
- {if $message->getUserProfile()}
- {if $message->getUserProfile()->userID}
- <a href="{link controller='User' object=$message->getUserProfile()}{/link}" title="{$message->getUserProfile()->username}">{@$message->getUserProfile()->getAvatar()->getImageTag(48)}</a>
+ {assign var=_messageObjectHash value=$message|spl_object_hash}
+ {assign var=_messageCustomIcon value=$customIcons[$_messageObjectHash]}
+ {if $_messageCustomIcon === ''}
+ {if $message->getUserProfile()}
+ {if $message->getUserProfile()->userID}
+ <a href="{link controller='User' object=$message->getUserProfile()}{/link}" title="{$message->getUserProfile()->username}">{@$message->getUserProfile()->getAvatar()->getImageTag(48)}</a>
+ {else}
+ <p>{@$message->getUserProfile()->getAvatar()->getImageTag(48)}</p>
+ {/if}
{else}
- <p>{@$message->getUserProfile()->getAvatar()->getImageTag(48)}</p>
+ <p><span class="icon icon48 fa-file-o"></span></p>
{/if}
+ {elseif $_messageCustomIcon|strpos:'fa-' === 0}
+ <p><span class="icon icon48 {$_messageCustomIcon}"></span></p>
{else}
- <p><span class="icon icon48 fa-file-o"></span></p>
+ <p><img src="{$_messageCustomIcon}" style="width: 48px; height: 48px" alt=""></p>
{/if}
<div>
</li>
{/foreach}
</ul>
-</div>
\ No newline at end of file
+</div>
--- /dev/null
+<?php
+declare(strict_types=1);
+namespace wcf\data\search;
+
+/**
+ * Extends the base search result objects with the ability to provide a custom image or icon
+ * class name instead of the default avatar/icon.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2018 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
+}
<?php
declare(strict_types=1);
namespace wcf\page;
+use wcf\data\search\ICustomIconSearchResultObject;
use wcf\data\search\ISearchResultObject;
use wcf\data\search\Search;
use wcf\system\application\ApplicationHandler;
* @package WoltLabSuite\Core\Page
*/
class SearchResultPage extends MultipleLinkPage {
+ /**
+ * list of custom icons per message
+ * @var string[]
+ */
+ public $customIcons = [];
+
/**
* @inheritDoc
*/
throw new ImplementationException(get_class($message), ISearchResultObject::class);
}
+ $customIcon = '';
+ if ($message instanceof ICustomIconSearchResultObject) {
+ $customIcon = $message->getCustomSearchResultIcon();
+ }
+
$this->messages[] = $message;
+ $this->customIcons[spl_object_hash($message)] = $customIcon;
}
}
}
'resultListTemplateName' => $this->resultListTemplateName,
'resultListApplication' => $this->resultListApplication,
'application' => ApplicationHandler::getInstance()->getAbbreviation(ApplicationHandler::getInstance()->getActiveApplication()->packageID),
- 'searchPreselectObjectType' => $searchPreselectObjectType
+ 'searchPreselectObjectType' => $searchPreselectObjectType,
+ 'customIcons' => $this->customIcons
]);
}