addBehavior('initWidgets', ['sabaWidget', 'setWidget']);
class sabaWidget
{
public static function setWidget($w)
{
$w
->create(
'saba',
__('Advanced search'),
['sabaWidget', 'getWidget'],
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 static function getWidget($w)
{
dcCore::app()->blog->settings->addNamespace('saba');
if (!dcCore::app()->blog->settings->saba->active
|| !dcCore::app()->blog->settings->saba->error && dcCore::app()->url->type == '404'
|| $w->offline
) {
return;
}
$saba_options = dcCore::app()->ctx->saba_options ?? tplSaba::getSabaDefaultPostsOptions();
$res = '';
# advenced search only on search page
if (dcCore::app()->url->type == 'search') {
# order
if (!$w->saba_filter_orders) {
$ct = '';
foreach (tplSaba::getSabaFormOrders() as $k => $v) {
$ct .= '
';
}
if (!empty($ct)) {
$ct .= '';
$res .= $w->renderTitle(__('Filter order')) . sprintf('', $ct);
}
}
# options
if (!$w->saba_filter_options) {
$ct = '';
$rm = explode(',', $w->saba_remove_options);
foreach (tplSaba::getSabaFormOptions() as $k => $v) {
if (in_array($v, $rm)) {
continue;
}
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter options')) . sprintf('', $ct);
}
}
# ages
if (!$w->saba_filter_ages) {
$ct = '';
foreach (tplSaba::getSabaFormAges() as $k => $v) {
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by age')) . sprintf('', $ct);
}
}
# types
if (!$w->saba_filter_types) {
$ct = '';
$rm = explode(',', $w->saba_remove_types);
foreach (tplSaba::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->saba_filter_categories) {
$ct = '';
$rm = explode(',', $w->saba_remove_categories);
$rs = dcCore::app()->blog->getCategories();
while ($rs->fetch()) {
if (in_array($rs->cat_id, $rm) || in_array($rs->cat_url, $rm)) {
continue;
}
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by category')) . sprintf('', $ct);
}
}
# authors
if (!$w->saba_filter_authors) {
$ct = '';
$rm = explode(',', $w->saba_remove_authors);
$rs = dcCore::app()->blog->getPostsUsers();
while ($rs->fetch()) {
if (in_array($rs->user_id, $rm)) {
continue;
}
$ct .= '';
}
if (!empty($ct)) {
$res .= $w->renderTitle(__('Filter by author')) . sprintf('', $ct);
}
}
}
return $w->renderDiv(
$w->content_only,
$w->class,
'id="search"',
($w->title ? $w->renderTitle('') : '') .
''
);
}
}