]> git.mxchange.org Git - friendica.git/blobdiff - mod/dirfind.php
Merge pull request #6474 from tobiasd/2019.01-CHANGELOG
[friendica.git] / mod / dirfind.php
index 3e5aa83a7208df0f14c3cddc6b523b4bcc927afc..909a723165b49c84b678535ba713ee38f1127930 100644 (file)
@@ -5,10 +5,12 @@
 
 use Friendica\App;
 use Friendica\Content\ContactSelector;
+use Friendica\Content\Pager;
 use Friendica\Content\Widget;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
@@ -18,6 +20,7 @@ use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\Network;
 use Friendica\Util\Proxy as ProxyUtils;
+use Friendica\Util\Strings;
 
 
 function dirfind_init(App $a) {
@@ -27,7 +30,7 @@ function dirfind_init(App $a) {
                return;
        }
 
-       if (! x($a->page,'aside')) {
+       if (empty($a->page['aside'])) {
                $a->page['aside'] = '';
        }
 
@@ -43,15 +46,15 @@ function dirfind_content(App $a, $prefix = "") {
 
        $local = Config::get('system','poco_local_search');
 
-       $search = $prefix.notags(trim(defaults($_REQUEST, 'search', '')));
+       $search = $prefix.Strings::escapeTags(trim(defaults($_REQUEST, 'search', '')));
 
        $header = '';
 
        if (strpos($search,'@') === 0) {
                $search = substr($search,1);
                $header = L10n::t('People Search - %s', $search);
-               if ((valid_email($search) && Network::isEmailDomainValid($search)) ||
-                       (substr(normalise_link($search), 0, 7) == "http://")) {
+               if ((filter_var($search, FILTER_VALIDATE_EMAIL) && Network::isEmailDomainValid($search)) ||
+                       (substr(Strings::normaliseLink($search), 0, 7) == "http://")) {
                        $user_data = Probe::uri($search);
                        $discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]));
                }
@@ -66,12 +69,13 @@ function dirfind_content(App $a, $prefix = "") {
        $o = '';
 
        if ($search) {
+               $pager = new Pager($a->query_string);
 
                if ($discover_user) {
                        $j = new stdClass();
                        $j->total = 1;
                        $j->items_page = 1;
-                       $j->page = $a->pager['page'];
+                       $j->page = $pager->getPage();
 
                        $objresult = new stdClass();
                        $objresult->cid = 0;
@@ -93,14 +97,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 = (($a->pager['page']) * $perpage) - $perpage;
+                       $pager->setItemsPerPage(80);
 
                        if (Config::get('system','diaspora_enabled')) {
                                $diaspora = Protocol::DIASPORA;
@@ -118,30 +121,30 @@ function dirfind_content(App $a, $prefix = "") {
 
                        /// @TODO These 2 SELECTs are not checked on validity with DBA::isResult()
                        $count = q("SELECT count(*) AS `total` FROM `gcontact`
-                                       WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s') AND
+                                       WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s', '%s') AND
                                                ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
                                                (`url` LIKE '%s' OR `name` LIKE '%s' OR `location` LIKE '%s' OR
                                                `addr` LIKE '%s' OR `about` LIKE '%s' OR `keywords` LIKE '%s') $extra_sql",
-                                       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)));
+                                       DBA::escape(Protocol::ACTIVITYPUB), DBA::escape(Protocol::DFRN), DBA::escape($ostatus), DBA::escape($diaspora),
+                                       DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)),
+                                       DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)));
 
                        $results = q("SELECT `nurl`
                                        FROM `gcontact`
-                                       WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s') AND
+                                       WHERE NOT `hide` AND `network` IN ('%s', '%s', '%s', '%s') AND
                                                ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
                                                (`url` LIKE '%s' OR `name` LIKE '%s' OR `location` LIKE '%s' OR
                                                `addr` LIKE '%s' OR `about` LIKE '%s' OR `keywords` LIKE '%s') $extra_sql
                                                GROUP BY `nurl`
                                                ORDER BY `updated` DESC LIMIT %d, %d",
-                                       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));
+                                       DBA::escape(Protocol::ACTIVITYPUB), DBA::escape(Protocol::DFRN), DBA::escape($ostatus), DBA::escape($diaspora),
+                                       DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)),
+                                       DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)), DBA::escape(Strings::escapeHtml($search2)),
+                                       $pager->getStart(), $pager->getItemsPerPage());
                        $j = new stdClass();
                        $j->total = $count[0]["total"];
-                       $j->items_page = $perpage;
-                       $j->page = $a->pager['page'];
+                       $j->items_page = $pager->getItemsPerPage();
+                       $j->page = $pager->getPage();
                        foreach ($results AS $result) {
                                if (PortableContact::alternateOStatusUrl($result["nurl"])) {
                                        continue;
@@ -177,22 +180,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() : '');
 
-                       $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : '');
-
-                       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);
-               }
 
-               if ($j->total) {
-                       $a->setPagerTotal($j->total);
-                       $a->setPagerItemsPage($j->items_page);
+                       $pager->setItemsPerPage($j->items_page);
                }
 
                if (!empty($j->results)) {
-
                        $id = 0;
 
                        foreach ($j->results as $jj) {
@@ -236,7 +235,7 @@ function dirfind_content(App $a, $prefix = "") {
                                        'alt_text' => $alt_text,
                                        'url' => Model\Contact::magicLink($jj->url),
                                        'itemurl' => $itemurl,
-                                       'name' => htmlentities($jj->name),
+                                       'name' => $jj->name,
                                        'thumb' => ProxyUtils::proxifyUrl($jj->photo, false, ProxyUtils::SIZE_THUMB),
                                        'img_hover' => $jj->tags,
                                        'conntxt' => $conntxt,
@@ -252,14 +251,12 @@ function dirfind_content(App $a, $prefix = "") {
                                $entries[] = $entry;
                        }
 
-               $tpl = get_markup_template('viewcontact_template.tpl');
-
-               $o .= replace_macros($tpl,[
-                       'title' => $header,
-                       '$contacts' => $entries,
-                       '$paginate' => paginate($a),
-               ]);
-
+                       $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
+                       $o .= Renderer::replaceMacros($tpl,[
+                               'title' => $header,
+                               '$contacts' => $entries,
+                               '$paginate' => $pager->renderFull($j->total),
+                       ]);
                } else {
                        info(L10n::t('No matches') . EOL);
                }