2019-10-07 18:13:31 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-10-07 18:13:31 +00:00
|
|
|
|
|
|
|
namespace Friendica\Content\Widget;
|
|
|
|
|
|
|
|
use Friendica\Core\Renderer;
|
2020-05-17 13:51:56 +00:00
|
|
|
use Friendica\Core\Search;
|
2019-10-07 18:13:31 +00:00
|
|
|
use Friendica\Database\DBA;
|
2020-01-18 21:07:07 +00:00
|
|
|
use Friendica\DI;
|
2019-10-07 18:13:31 +00:00
|
|
|
|
|
|
|
class SavedSearches
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param string $return_url
|
|
|
|
* @param string $search
|
|
|
|
* @return string
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public static function getHTML($return_url, $search = '')
|
|
|
|
{
|
2020-06-06 18:45:16 +00:00
|
|
|
$saved = [];
|
2019-10-07 18:13:31 +00:00
|
|
|
$saved_searches = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
|
2020-06-06 18:45:16 +00:00
|
|
|
while ($saved_search = DBA::fetch($saved_searches)) {
|
|
|
|
$saved[] = [
|
|
|
|
'id' => $saved_search['id'],
|
|
|
|
'term' => $saved_search['term'],
|
|
|
|
'encodedterm' => urlencode($saved_search['term']),
|
|
|
|
'searchpath' => Search::getSearchPath($saved_search['term']),
|
|
|
|
'delete' => DI::l10n()->t('Remove term'),
|
|
|
|
'selected' => $search == $saved_search['term'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
DBA::close($saved_searches);
|
2019-10-07 18:13:31 +00:00
|
|
|
|
2020-06-06 18:45:16 +00:00
|
|
|
if (empty($saved)) {
|
|
|
|
return '';
|
2019-10-07 18:13:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-06 18:45:16 +00:00
|
|
|
$tpl = Renderer::getMarkupTemplate('widget/saved_searches.tpl');
|
|
|
|
|
|
|
|
return Renderer::replaceMacros($tpl, [
|
|
|
|
'$title' => DI::l10n()->t('Saved Searches'),
|
|
|
|
'$add' => '',
|
|
|
|
'$searchbox' => '',
|
|
|
|
'$saved' => $saved,
|
|
|
|
'$return_url' => urlencode($return_url),
|
|
|
|
]);
|
2019-10-07 18:13:31 +00:00
|
|
|
}
|
|
|
|
}
|