/gadgets/Search/Actions/Search.php
https://github.com/jaws-project/jaws · PHP · 171 lines · 118 code · 20 blank · 33 comment · 13 complexity · 1329abecf270e97c7d02c5c8bdf69815 MD5 · raw file
- <?php
- /**
- * Search boxes actions
- *
- * @category GadgetLayout
- * @package Search
- * @author Jonathan Hernandez <ion@suavizado.com>
- * @author Ali Fazelzadeh <afz@php.net>
- * @copyright 2004-2022 Jaws Development Group
- * @license http://www.gnu.org/copyleft/lesser.html
- */
- class Search_Actions_Search extends Jaws_Gadget_Action
- {
- /**
- * Builds the search box
- *
- * @access public
- * @param bool $gadgets_combo Display gadgets combo (optional, default true)
- * @return string XHTML search box
- */
- function Box($gadgets_combo = true)
- {
- $post = $this->gadget->request->fetch(
- array('all', 'exact', 'least', 'exclude', 'gadgets', 'date'),
- 'get',
- false
- );
- if ($this->app->requestedActionMode === 'normal') {
- $tFilename = 'Search.html';
- } else {
- $tFilename = 'Search0.html';
- }
- $tpl = $this->gadget->template->load($tFilename);
- if ($gadgets_combo) {
- $block = 'Box';
- } else {
- $block = 'SimpleBox';
- }
- $tpl->SetBlock("$block");
- $tpl->SetVariable('base_script', BASE_SCRIPT);
- $tpl->SetVariable('title', $this->gadget->title);
- $tpl->SetVariable('lbl_all', $this::t('WORD_FILTER_ALL'));
- $tpl->SetVariable('ttl_all', $this::t('WORD_FILTER_ALL'));
- $model = $this->gadget->model->load('Search');
- $tpl->SetVariable('all', $model->implodeSearch($post));
- // gadgets select box
- if ($gadgets_combo) {
- $tpl->SetVariable('lbl_search_in', $this::t('SEARCH_IN'));
- $gadgetList = $model->GetSearchableGadgets();
- $gSearchable = $this->gadget->registry->fetch('searchable_gadgets');
- $searchableGadgets = ($gSearchable=='*')? array_keys($gadgetList) : explode(', ', $gSearchable);
- array_unshift($searchableGadgets, '*');
- foreach ($searchableGadgets as $gadget) {
- if ($gadget == '*') {
- $title = Jaws::t('ALL');
- } else {
- $gInfo = Jaws_Gadget::getInstance($gadget);
- if (Jaws_Error::IsError($gInfo)) {
- continue;
- }
- $title = $gInfo->title;
- }
- $tpl->SetBlock("$block/gadget");
- $tpl->SetVariable('gadget', $gadget);
- $tpl->SetVariable('title', $title);
- $tpl->SetVariable('selected', ($post['gadgets'] == $gadget)? 'selected="selected"' : '');
- $tpl->ParseBlock("$block/gadget");
- }
- }
- $tpl->SetVariable('search', $this::t('BUTTON'));
- $tpl->ParseBlock("$block");
- return $tpl->Get();
- }
- /**
- * Builds the simple search box
- *
- * @access public
- * @return string XHTML search box
- */
- function SimpleBox()
- {
- return $this->Box(false);
- }
- /**
- * Builds the advanced search box
- *
- * @access public
- * @return string XHTML search box
- */
- function AdvancedBox()
- {
- $post = $this->gadget->request->fetch(
- array('all', 'exact', 'least', 'exclude', 'gadgets', 'date'),
- 'get',
- false
- );
- if ($this->app->requestedActionMode === 'normal') {
- $tFilename = 'Search.html';
- } else {
- $tFilename = 'Search0.html';
- }
- $tpl = $this->gadget->template->load($tFilename);
- $tpl->SetBlock('AdvancedBox');
- $tpl->SetVariable('base_script', BASE_SCRIPT);
- $tpl->SetVariable('title', $this->gadget->title);
- $tpl->SetVariable('lbl_word_filter', $this::t('WORD_FILTER'));
- $tpl->SetVariable('lbl_all', $this::t('WORD_FILTER_ALL'));
- $tpl->SetVariable('lbl_exact', $this::t('WORD_FILTER_EXACT'));
- $tpl->SetVariable('lbl_least', $this::t('WORD_FILTER_LEAST'));
- $tpl->SetVariable('lbl_exclude', $this::t('WORD_FILTER_EXCLUDE'));
- $tpl->SetVariable('lbl_data_filter', $this::t('DATA_FILTER'));
- $tpl->SetVariable('lbl_search_in', $this::t('SEARCH_IN'));
- $model = $this->gadget->model->load('Search');
- $options = $model->parseSearch($post, $searchable);
- //$options = array_map('Jaws_XSS::filter', $options);
- array_walk_recursive($options, function (&$value) {
- $value = Jaws_XSS::filter($value);
- });
- $wordAll =& Piwi::CreateWidget('Entry', 'all', implode(' ', $options['all']));
- $wordExact =& Piwi::CreateWidget('Entry', 'exact', implode(' ', $options['exact']));
- $wordLeast =& Piwi::CreateWidget('Entry', 'least', implode(' ', $options['least']));
- $wordExclude =& Piwi::CreateWidget('Entry', 'exclude', implode(' ', $options['exclude']));
- $tpl->SetVariable('all', $wordAll->Get());
- $tpl->SetVariable('exclude', $wordExclude->Get());
- $tpl->SetVariable('least', $wordLeast->Get());
- $tpl->SetVariable('exact', $wordExact->Get());
- //Gadgets filter combo
- $gadgetList = $model->GetSearchableGadgets();
- $gSearchable = $this->gadget->registry->fetch('searchable_gadgets');
- $searchableGadgets = ($gSearchable=='*')? array_keys($gadgetList) : explode(', ', $gSearchable);
- $gchk =& Piwi::CreateWidget('Combo', 'gadgets');
- $gchk->addOption(Jaws::t('ALL'), '');
- foreach ($searchableGadgets as $gadget) {
- $info = Jaws_Gadget::getInstance($gadget);
- if (Jaws_Error::IsError($info)) {
- continue;
- }
- $gchk->AddOption($info->title, $gadget);
- }
- $default = !is_null($post['gadgets']) ? $post['gadgets'] : '';
- $gchk->SetDefault($default);
- $tpl->SetVariable('gadgets_combo', $gchk->Get());
- //Search button
- $btnSearch =& Piwi::CreateWidget('Button', '', $this::t('BUTTON'));
- $btnSearch->SetID('btn_search');
- $btnSearch->SetSubmit(true);
- $tpl->SetVariable('btn_search', $btnSearch->Get());
- $tpl->ParseBlock('AdvancedBox');
- return $tpl->Get();
- }
- }