]> git.mxchange.org Git - friendica.git/commitdiff
Issue 8732: Fix fetch aved searches
authorMichael <heluecht@pirati.ca>
Sat, 6 Jun 2020 18:45:16 +0000 (18:45 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 6 Jun 2020 18:45:16 +0000 (18:45 +0000)
src/Content/Widget/SavedSearches.php

index 6bc363a81a1ecba926b0177e250430bf83aa117e..30e5b9c2ab65fbd272a7fb86c00794eb39ea0ca5 100644 (file)
@@ -36,33 +36,32 @@ class SavedSearches
         */
        public static function getHTML($return_url, $search = '')
        {
-               $o = '';
-
+               $saved = [];
                $saved_searches = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
-               if (DBA::isResult($saved_searches)) {
-                       $saved = [];
-                       foreach ($saved_searches as $saved_search) {
-                               $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'],
-                               ];
-                       }
-
-                       $tpl = Renderer::getMarkupTemplate('widget/saved_searches.tpl');
+               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);
 
-                       $o = Renderer::replaceMacros($tpl, [
-                               '$title'      => DI::l10n()->t('Saved Searches'),
-                               '$add'        => '',
-                               '$searchbox'  => '',
-                               '$saved'      => $saved,
-                               '$return_url' => urlencode($return_url),
-                       ]);
+               if (empty($saved)) {
+                       return '';
                }
 
-               return $o;
+               $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),
+               ]);
        }
 }