]> git.mxchange.org Git - friendica.git/blob - src/Content/Widget/SavedSearches.php
Merge pull request #8429 from tobiasd/2020.03-credits
[friendica.git] / src / Content / Widget / SavedSearches.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Content\Widget;
23
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27
28 class SavedSearches
29 {
30         /**
31          * @param string $return_url
32          * @param string $search
33          * @return string
34          * @throws \Exception
35          */
36         public static function getHTML($return_url, $search = '')
37         {
38                 $o = '';
39
40                 $saved_searches = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
41                 if (DBA::isResult($saved_searches)) {
42                         $saved = [];
43                         foreach ($saved_searches as $saved_search) {
44                                 $saved[] = [
45                                         'id'          => $saved_search['id'],
46                                         'term'        => $saved_search['term'],
47                                         'encodedterm' => urlencode($saved_search['term']),
48                                         'delete'      => DI::l10n()->t('Remove term'),
49                                         'selected'    => $search == $saved_search['term'],
50                                 ];
51                         }
52
53                         $tpl = Renderer::getMarkupTemplate('widget/saved_searches.tpl');
54
55                         $o = Renderer::replaceMacros($tpl, [
56                                 '$title'      => DI::l10n()->t('Saved Searches'),
57                                 '$add'        => '',
58                                 '$searchbox'  => '',
59                                 '$saved'      => $saved,
60                                 '$return_url' => urlencode($return_url),
61                         ]);
62                 }
63
64                 return $o;
65         }
66 }