From 440d0a3a63ffc24f608504e8df8d2038fd95ca5b Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 5 May 2019 17:59:57 +0200 Subject: [PATCH 1/3] Rename BookMarklet to Bookmarklet --- src/App/Router.php | 2 +- src/Module/{BookMarklet.php => Bookmarklet.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Module/{BookMarklet.php => Bookmarklet.php} (98%) diff --git a/src/App/Router.php b/src/App/Router.php index 1dffb6b40..11ce68677 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -89,7 +89,7 @@ class Router $this->routeCollector->addRoute(['GET'], '/apps', Module\Apps::class); $this->routeCollector->addRoute(['GET'], '/attach/{item:\d+}', Module\Attach::class); $this->routeCollector->addRoute(['GET'], '/babel', Module\Babel::class); - $this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\BookMarklet::class); + $this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\Bookmarklet::class); $this->routeCollector->addGroup('/contact', function (RouteCollector $collector) { $collector->addRoute(['GET'], '[/]', Module\Contact::class); $collector->addRoute(['GET'], '/{id:\d+}[/posts|conversations]', Module\Contact::class); diff --git a/src/Module/BookMarklet.php b/src/Module/Bookmarklet.php similarity index 98% rename from src/Module/BookMarklet.php rename to src/Module/Bookmarklet.php index 51feb25d7..1b6ff3845 100644 --- a/src/Module/BookMarklet.php +++ b/src/Module/Bookmarklet.php @@ -12,7 +12,7 @@ use Friendica\Util\Strings; * Creates a bookmarklet * Shows either a editor browser or adds the given bookmarklet to the current user */ -class BookMarklet extends BaseModule +class Bookmarklet extends BaseModule { public static function content() { From f6af90fa328bcf7e731917f011b3e20fefeace1c Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 5 May 2019 18:15:39 +0200 Subject: [PATCH 2/3] Create XML output for RSD with XML::fromArray() --- src/Module/ReallySimpleDiscovery.php | 42 +++++++++++++++++++++++++--- view/templates/rsd.tpl | 15 ---------- 2 files changed, 38 insertions(+), 19 deletions(-) delete mode 100644 view/templates/rsd.tpl diff --git a/src/Module/ReallySimpleDiscovery.php b/src/Module/ReallySimpleDiscovery.php index 4c14d3c83..515285dbf 100644 --- a/src/Module/ReallySimpleDiscovery.php +++ b/src/Module/ReallySimpleDiscovery.php @@ -3,7 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Core\Renderer; +use Friendica\Util\XML; /** * Prints the rsd.xml @@ -13,9 +13,43 @@ class ReallySimpleDiscovery extends BaseModule { public static function rawContent() { - header ('Content-Type: text/xml'); - $tpl = Renderer::getMarkupTemplate('rsd.tpl'); - echo Renderer::replaceMacros($tpl); + header('Content-Type: text/xml'); + + $app = self::getApp(); + $xml = null; + echo XML::fromArray([ + 'rsd' => [ + '@attributes' => [ + 'version' => '1.0', + 'xmlns' => 'http://archipelago.phrasewise.com/rsd', + ], + 'service' => [ + 'engineName' => 'Friendica', + 'engineLink' => 'http://friendica.com', + 'apis' => [ + 'api' => [ + '@attributes' => [ + 'name' => 'Twitter', + 'preferred' => 'true', + 'apiLink' => $app->getBaseURL(), + 'blogID' => '', + ], + 'settings' => [ + 'docs' => [ + 'http://status.net/wiki/TwitterCompatibleAPI', + ], + 'setting' => [ + '@attributes' => [ + 'name' => 'OAuth', + ], + 'false', + ], + ], + ] + ], + ], + ], + ], $xml); exit(); } } diff --git a/view/templates/rsd.tpl b/view/templates/rsd.tpl deleted file mode 100644 index c194e8f26..000000000 --- a/view/templates/rsd.tpl +++ /dev/null @@ -1,15 +0,0 @@ - - - - Friendica - http://friendica.com/ - - - - http://status.net/wiki/TwitterCompatibleAPI - false - - - - - From 039f9490dd6e8cb6551f58908076dfc267fa185a Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 5 May 2019 18:40:36 +0200 Subject: [PATCH 3/3] Optimized Profile::searchProfiles & Bugfix Contact::getProbeDataFromDatabase --- src/Model/Contact.php | 2 +- src/Model/Profile.php | 100 +++++++++++++++++++++++++++++------------- 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index f4c62fea8..3f25fd938 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1168,7 +1168,7 @@ class Contact extends BaseObject // The link could be provided as http although we stored it as https $ssl_url = str_replace('http://', 'https://', $url); - $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick', + $fields = ['id', 'uid', 'url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick', 'photo', 'keywords', 'location', 'about', 'network', 'priority', 'batch', 'request', 'confirm', 'poco']; diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 9d2600b3d..a854b1c9e 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -1249,56 +1249,96 @@ class Profile */ public static function searchProfiles($start = 0, $count = 100, $search = null) { - if ($search) { - $search = DBA::escape($search); - - $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR - (`user`.`nickname` LIKE '%$search%') OR - (`profile`.`pdesc` LIKE '%$search%') OR - (`profile`.`locality` LIKE '%$search%') OR - (`profile`.`region` LIKE '%$search%') OR - (`profile`.`country-name` LIKE '%$search%') OR - (`profile`.`gender` LIKE '%$search%') OR - (`profile`.`marital` LIKE '%$search%') OR - (`profile`.`sexual` LIKE '%$search%') OR - (`profile`.`about` LIKE '%$search%') OR - (`profile`.`romance` LIKE '%$search%') OR - (`profile`.`work` LIKE '%$search%') OR - (`profile`.`education` LIKE '%$search%') OR - (`profile`.`pub_keywords` LIKE '%$search%') OR - (`profile`.`prv_keywords` LIKE '%$search%'))"; - } else { - $sql_extra = ''; - } - $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 "); - $total = 0; - $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` + + if (!empty($search)) { + $searchTerm = '%' . $search . '%'; + $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` - WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` $sql_extra"); + WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` + AND ((`profile`.`name` LIKE ?) OR + (`user`.`nickname` LIKE ?) OR + (`profile`.`pdesc` LIKE ?) OR + (`profile`.`locality` LIKE ?) OR + (`profile`.`region` LIKE ?) OR + (`profile`.`country-name` LIKE ?) OR + (`profile`.`gender` LIKE ?) OR + (`profile`.`marital` LIKE ?) OR + (`profile`.`sexual` LIKE ?) OR + (`profile`.`about` LIKE ?) OR + (`profile`.`romance` LIKE ?) OR + (`profile`.`work` LIKE ?) OR + (`profile`.`education` LIKE ?) OR + (`profile`.`pub_keywords` LIKE ?) OR + (`profile`.`prv_keywords` LIKE ?))", + $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, + $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm); + } else { + $cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` + FROM `profile` + LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` + WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`"); + } + if (DBA::isResult($cnt)) { $total = $cnt['total']; } $order = " ORDER BY `name` ASC "; - $limit = $start . ',' . $count; + $profiles = []; - $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, + // If nothing found, don't try to select details + if ($total > 0) { + if (!empty($search)) { + $searchTerm = '%' . $search . '%'; + + $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, `contact`.`addr`, `contact`.`url` AS `profile_url` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid` WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self` - $sql_extra $order LIMIT $limit" - ); + AND ((`profile`.`name` LIKE ?) OR + (`user`.`nickname` LIKE ?) OR + (`profile`.`pdesc` LIKE ?) OR + (`profile`.`locality` LIKE ?) OR + (`profile`.`region` LIKE ?) OR + (`profile`.`country-name` LIKE ?) OR + (`profile`.`gender` LIKE ?) OR + (`profile`.`marital` LIKE ?) OR + (`profile`.`sexual` LIKE ?) OR + (`profile`.`about` LIKE ?) OR + (`profile`.`romance` LIKE ?) OR + (`profile`.`work` LIKE ?) OR + (`profile`.`education` LIKE ?) OR + (`profile`.`pub_keywords` LIKE ?) OR + (`profile`.`prv_keywords` LIKE ?)) + $order LIMIT ?,?", + $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, + $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, + $start, $count + ); + } else { + $profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`, + `contact`.`addr`, `contact`.`url` AS `profile_url` + FROM `profile` + LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` + LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid` + WHERE `is-default` $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self` + $order LIMIT ?,?", + $start, $count + ); + } + } - if (DBA::isResult($profiles)) { + if (DBA::isResult($profiles) && $total > 0) { return [ 'total' => $total, 'entries' => DBA::toArray($profiles), ]; + } else { return [ 'total' => $total,