2017-03-16 01:48:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zotlabs\Widget;
|
|
|
|
|
2021-12-02 22:33:36 +00:00
|
|
|
use App;
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Sitesearch
|
|
|
|
{
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public function widget($arr)
|
|
|
|
{
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$search = ((x($_GET, 'search')) ? $_GET['search'] : '');
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$srchurl = App::$query_string;
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$srchurl = rtrim(preg_replace('/search\=[^\&].*?(\&|$)/is', '', $srchurl), '&');
|
|
|
|
$srchurl = rtrim(preg_replace('/submit\=[^\&].*?(\&|$)/is', '', $srchurl), '&');
|
|
|
|
$srchurl = str_replace(array('?f=', '&f='), array('', ''), $srchurl);
|
2017-03-16 01:48:27 +00:00
|
|
|
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$hasq = ((strpos($srchurl, '?') !== false) ? true : false);
|
|
|
|
$hasamp = ((strpos($srchurl, '&') !== false) ? true : false);
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if (($hasamp) && (!$hasq)) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$srchurl = substr($srchurl, 0, strpos($srchurl, '&')) . '?f=&' . substr($srchurl, strpos($srchurl, '&') + 1);
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$o = '';
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$saved = [];
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$tpl = get_markup_template("sitesearch.tpl");
|
|
|
|
$o = replace_macros($tpl, array(
|
|
|
|
'$title' => t('Search'),
|
|
|
|
'$searchbox' => searchbox($search, 'netsearch-box', $srchurl . (($hasq) ? '' : '?f='), false),
|
|
|
|
'$saved' => $saved,
|
|
|
|
));
|
2017-03-16 01:48:27 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
return $o;
|
|
|
|
}
|
2017-03-16 01:48:27 +00:00
|
|
|
}
|