create(
'saba',
__('Advanced search'),
self::parseWidget(...),
null,
__('Add more search options on public side')
)
->addTitle(__('Search'))
->setting(
'saba_filter_types',
__('Disable filter on post types'),
0,
'check'
)
->setting('saba_remove_types', __('Hidden types:'), '')
->setting(
'saba_filter_options',
__('Disable filter on post options'),
0,
'check'
)
->setting('saba_remove_options', __('Hidden options:'), '')
->setting(
'saba_filter_categories',
__('Disable filter on categories'),
0,
'check'
)
->setting('saba_remove_categories', __('Hidden categories:'), '')
->setting(
'saba_filter_authors',
__('Disable filter on authors'),
0,
'check'
)
->setting('saba_remove_authors', __('Hidden authors:'), '')
->setting(
'saba_filter_orders',
__('Disable filter on order'),
0,
'check'
)
->setting(
'saba_filter_ages',
__('Disable filter on age'),
0,
'check'
)
->addContentOnly()
->addClass()
->addOffline();
}
/**
* Public part for widget
*
* @param WidgetsElement $w WidgetsElement instance
*/
public static function parseWidget(WidgetsElement $w): string
{
if (!App::blog()->isDefined()
|| !App::blog()->settings()->get(My::id())->get('active')
|| !App::blog()->settings()->get(My::id())->get('error') && App::url()->type == '404'
|| $w->__get('offline')
) {
return '';
}
$saba_options = App::frontend()->context()->__get('saba_options') ?? [];
if (!is_array($saba_options) || empty($saba_options)) {
$saba_options = Utils::getSabaDefaultPostsOptions();
}
$res = '';
# advanced search only on search page
if (App::url()->type == 'search') {
# order
if (!$w->__get('saba_filter_orders')) {
$ct = '';
foreach (Utils::getSabaFormOrders() as $k => $v) {
$ct .= '
';
}
if (!empty($ct)) {
$ct .= '';
$res .= $w->renderTitle(__('Filter order')) . sprintf('', $ct);
}
}
# options
if (!$w->__get('saba_filter_options')) {
$ct = '';
$rm = explode(',', (string) $w->__get('saba_remove_options'));
foreach (Utils::getSabaFormOptions() as $k => $v) {
if (in_array($v, $rm)) {
continue;
}
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter options')) . sprintf('', $ct);
}
}
# ages
if (!$w->__get('saba_filter_ages')) {
$ct = '';
foreach (Utils::getSabaFormAges() as $k => $v) {
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by age')) . sprintf('', $ct);
}
}
# types
if (!$w->__get('saba_filter_types')) {
$ct = '';
$rm = explode(',', $w->__get('saba_remove_types'));
foreach (Utils::getSabaFormTypes() as $k => $v) {
if (in_array($v, $rm)) {
continue;
}
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by type')) . sprintf('', $ct);
}
}
# categories
if (!$w->__get('saba_filter_categories')) {
$ct = '';
$rm = explode(',', $w->__get('saba_remove_categories'));
$rs = App::blog()->getCategories();
while ($rs->fetch()) {
if (in_array($rs->f('cat_id'), $rm) || in_array($rs->f('cat_url'), $rm)) {
continue;
}
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by category')) . sprintf('', $ct);
}
}
# authors
if (!$w->__get('saba_filter_authors')) {
$ct = '';
$rm = explode(',', $w->__get('saba_remove_authors'));
$rs = App::blog()->getPostsUsers();
while ($rs->fetch()) {
if (in_array($rs->f('user_id'), $rm)) {
continue;
}
$ct .= sprintf(
'',
$rs->f('user_id'),
in_array($rs->f('user_id'), $saba_options['q_user']) ? 'checked="checked" ' : '',
Html::escapeHTML(App::users()->getUserCN($rs->f('user_id'), $rs->f('user_name'), $rs->f('user_firstname'), $rs->f('user_displayname')))
);
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by author')) . sprintf('', $ct);
}
}
}
return $w->renderDiv(
(bool) $w->__get('content_only'),
$w->__get('class'),
'id="search"',
($w->__get('title') ? $w->renderTitle('') : '') .
''
);
}
}