]> git.mxchange.org Git - friendica.git/commitdiff
Fix usages of Pager with JSON calls in mod/match and mod/dirfind
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 24 Oct 2018 16:03:14 +0000 (12:03 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 25 Oct 2018 04:07:16 +0000 (00:07 -0400)
mod/dirfind.php
mod/match.php

index 9d3c852f493833b23f1459ecfa5d0f072d16f0a1..5d7815bd808836bacc326082944c5cb7bfa59ebf 100644 (file)
@@ -67,6 +67,7 @@ function dirfind_content(App $a, $prefix = "") {
        $o = '';
 
        if ($search) {
+               $pager = new Pager($a->query_string);
 
                if ($discover_user) {
                        $j = new stdClass();
@@ -94,14 +95,13 @@ function dirfind_content(App $a, $prefix = "") {
                                Model\GContact::update($user_data);
                        }
                } elseif ($local) {
-
-                       if ($community)
+                       if ($community) {
                                $extra_sql = " AND `community`";
-                       else
+                       } else {
                                $extra_sql = "";
+                       }
 
-                       $perpage = 80;
-                       $startrec = (($pager->getPage()) * $perpage) - $perpage;
+                       $pager->setItemsPerPage(80);
 
                        if (Config::get('system','diaspora_enabled')) {
                                $diaspora = Protocol::DIASPORA;
@@ -138,10 +138,10 @@ function dirfind_content(App $a, $prefix = "") {
                                        DBA::escape(Protocol::DFRN), DBA::escape($ostatus), DBA::escape($diaspora),
                                        DBA::escape(escape_tags($search2)), DBA::escape(escape_tags($search2)), DBA::escape(escape_tags($search2)),
                                        DBA::escape(escape_tags($search2)), DBA::escape(escape_tags($search2)), DBA::escape(escape_tags($search2)),
-                                       intval($startrec), intval($perpage));
+                                       $pager->getStart(), $pager->getItemsPerPage());
                        $j = new stdClass();
                        $j->total = $count[0]["total"];
-                       $j->items_page = $perpage;
+                       $j->items_page = $pager->getItemsPerPage();
                        $j->page = $pager->getPage();
                        foreach ($results AS $result) {
                                if (PortableContact::alternateOStatusUrl($result["nurl"])) {
@@ -178,18 +178,18 @@ function dirfind_content(App $a, $prefix = "") {
                        // Add found profiles from the global directory to the local directory
                        Worker::add(PRIORITY_LOW, 'DiscoverPoCo', "dirsearch", urlencode($search));
                } else {
-
                        $p = (($pager->getPage() != 1) ? '&p=' . $pager->getPage() : '');
 
-                       if(strlen(Config::get('system','directory')))
-                               $x = Network::fetchUrl(get_server().'/lsearch?f=' . $p .  '&search=' . urlencode($search));
+                       if (strlen(Config::get('system','directory'))) {
+                               $x = Network::fetchUrl(get_server() . '/lsearch?f=' . $p .  '&search=' . urlencode($search));
+                       }
 
                        $j = json_decode($x);
+
+                       $pager->setItemsPerPage($j->items_page);
                }
 
                if (!empty($j->results)) {
-                       $pager = new Pager($a->query_string, $j->items_page);
-
                        $id = 0;
 
                        foreach ($j->results as $jj) {
@@ -250,13 +250,11 @@ function dirfind_content(App $a, $prefix = "") {
                        }
 
                        $tpl = get_markup_template('viewcontact_template.tpl');
-
                        $o .= replace_macros($tpl,[
                                'title' => $header,
                                '$contacts' => $entries,
                                '$paginate' => $pager->renderFull($j->total),
                        ]);
-
                } else {
                        info(L10n::t('No matches') . EOL);
                }
index a514439db6b8fd2900bf440b2d3ef56492d3f18d..43a3916506621252e8fd952dd183dc2d28eefed1 100644 (file)
@@ -54,7 +54,7 @@ function match_content(App $a)
        $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']);
 
        if ($tags) {
-               $pager = new Pager($a->query_string, $j->items_page);
+               $pager = new Pager($a->query_string);
 
                $params['s'] = $tags;
                if ($pager->getPage() != 1) {
@@ -70,6 +70,8 @@ function match_content(App $a)
                $j = json_decode($x);
 
                if (count($j->results)) {
+                       $pager->setItemsPerPage($j->items_page);
+
                        $id = 0;
 
                        foreach ($j->results as $jj) {