]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7067 from MrPetovan/task/remove-app-error
authorPhilipp <admin+Github@philipp.info>
Thu, 2 May 2019 15:24:56 +0000 (17:24 +0200)
committerGitHub <noreply@github.com>
Thu, 2 May 2019 15:24:56 +0000 (17:24 +0200)
Remove App->error

33 files changed:
mod/_well_known.php [deleted file]
mod/hostxrd.php [deleted file]
mod/webfinger.php [deleted file]
mod/xrd.php [deleted file]
src/App/Router.php
src/Model/Search.php [new file with mode: 0644]
src/Model/User.php
src/Module/Attach.php
src/Module/Contact.php
src/Module/Feed.php
src/Module/Filer.php
src/Module/Followers.php
src/Module/Following.php
src/Module/Group.php
src/Module/Inbox.php
src/Module/Install.php
src/Module/Itemsource.php
src/Module/NodeInfo.php [new file with mode: 0644]
src/Module/Nodeinfo.php [deleted file]
src/Module/Objects.php
src/Module/Oembed.php
src/Module/Outbox.php
src/Module/Photo.php
src/Module/Profile.php
src/Module/Proxy.php
src/Module/Register.php
src/Module/Statistics.php [new file with mode: 0644]
src/Module/Statistics_json.php [deleted file]
src/Module/WebFinger.php [new file with mode: 0644]
src/Module/WellKnown/HostMeta.php [new file with mode: 0644]
src/Module/WellKnown/XSocialRelay.php [new file with mode: 0644]
src/Module/Xrd.php [new file with mode: 0644]
view/templates/webfinger.tpl [new file with mode: 0644]

diff --git a/mod/_well_known.php b/mod/_well_known.php
deleted file mode 100644 (file)
index 8e82dab..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-
-use Friendica\App;
-use Friendica\Core\Config;
-use Friendica\Core\System;
-use Friendica\Module\Nodeinfo;
-
-require_once 'mod/hostxrd.php';
-require_once 'mod/xrd.php';
-
-function _well_known_init(App $a)
-{
-       if ($a->argc > 1) {
-               switch ($a->argv[1]) {
-                       case "host-meta":
-                               hostxrd_init($a);
-                               break;
-                       case "x-social-relay":
-                               wk_social_relay();
-                               break;
-                       case "nodeinfo":
-                               Nodeinfo::printWellKnown($a);
-                               break;
-                       case "webfinger":
-                               xrd_init($a);
-                               break;
-               }
-       }
-       System::httpExit(404);
-}
-
-function wk_social_relay()
-{
-       $subscribe = (bool) Config::get('system', 'relay_subscribe', false);
-
-       if ($subscribe) {
-               $scope = Config::get('system', 'relay_scope', SR_SCOPE_ALL);
-       } else {
-               $scope = SR_SCOPE_NONE;
-       }
-
-       $tags = [];
-
-       if ($scope == SR_SCOPE_TAGS) {
-               $server_tags = Config::get('system', 'relay_server_tags');
-               $tagitems = explode(",", $server_tags);
-
-               /// @todo Check if it was better to use "strtolower" on the tags
-               foreach ($tagitems AS $tag) {
-                       $tag = trim($tag, "# ");
-                       $tags[$tag] = $tag;
-               }
-
-               if (Config::get('system', 'relay_user_tags')) {
-                       $terms = q("SELECT DISTINCT(`term`) FROM `search`");
-
-                       foreach ($terms AS $term) {
-                               $tag = trim($term["term"], "#");
-                               $tags[$tag] = $tag;
-                       }
-               }
-       }
-
-       $taglist = [];
-       foreach ($tags AS $tag) {
-               if (!empty($tag)) {
-                       $taglist[] = $tag;
-               }
-       }
-
-       $relay = [
-               'subscribe' => $subscribe,
-               'scope' => $scope,
-               'tags' => $taglist,
-               'protocols' => ['diaspora' => ['receive' => System::baseUrl() . '/receive/public'],
-                       'dfrn' => ['receive' => System::baseUrl() . '/dfrn_notify']]
-       ];
-
-       header('Content-type: application/json; charset=utf-8');
-       echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
-       exit;
-}
diff --git a/mod/hostxrd.php b/mod/hostxrd.php
deleted file mode 100644 (file)
index 93a9d83..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-/**
- * @file mod/hostxrd.php
- */
-use Friendica\App;
-use Friendica\Core\Config;
-use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Protocol\Salmon;
-use Friendica\Util\Crypto;
-
-function hostxrd_init(App $a)
-{
-       header('Access-Control-Allow-Origin: *');
-       header("Content-type: text/xml");
-       $pubkey = Config::get('system', 'site_pubkey');
-
-       if (! $pubkey) {
-               $res = Crypto::newKeypair(1024);
-
-               Config::set('system','site_prvkey', $res['prvkey']);
-               Config::set('system','site_pubkey', $res['pubkey']);
-       }
-
-       $tpl = Renderer::getMarkupTemplate('xrd_host.tpl');
-       echo Renderer::replaceMacros($tpl, [
-               '$zhost' => $a->getHostName(),
-               '$zroot' => System::baseUrl(),
-               '$domain' => System::baseUrl(),
-               '$bigkey' => Salmon::salmonKey(Config::get('system', 'site_pubkey'))]
-       );
-
-       exit();
-}
diff --git a/mod/webfinger.php b/mod/webfinger.php
deleted file mode 100644 (file)
index b22b1ee..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
- * @file mod/webfinger.php
- */
-use Friendica\App;
-use Friendica\Core\L10n;
-use Friendica\Core\System;
-use Friendica\Network\Probe;
-
-function webfinger_content(App $a)
-{
-       if (!local_user()) {
-               System::httpExit(
-                       403,
-                       [
-                               "title" => L10n::t("Public access denied."),
-                               "description" => L10n::t("Only logged in users are permitted to perform a probing.")
-                       ]
-               );
-               exit();
-       }
-
-       $o = '<div class="generic-page-wrapper">';
-       $o .= '<h3>Webfinger Diagnostic</h3>';
-
-       $o .= '<form action="webfinger" method="get">';
-       $o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . defaults($_GET, 'addr', '') .'" />';
-       $o .= '<input type="submit" name="submit" value="Submit" /></form>';
-
-       $o .= '<br /><br />';
-
-       if (!empty($_GET['addr'])) {
-               $addr = trim($_GET['addr']);
-               $res = Probe::lrdd($addr);
-               $o .= '<pre>';
-               $o .= str_replace("\n", '<br />', print_r($res, true));
-               $o .= '</pre>';
-       }
-       $o .= '</div>';
-
-       return $o;
-}
diff --git a/mod/xrd.php b/mod/xrd.php
deleted file mode 100644 (file)
index b4cb60a..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-/**
- * @file mod/xrd.php
- */
-
-use Friendica\App;
-use Friendica\Core\Hook;
-use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Database\DBA;
-use Friendica\Protocol\Salmon;
-use Friendica\Util\Strings;
-
-function xrd_init(App $a)
-{
-       if ($a->argv[0] == 'xrd') {
-               if (empty($_GET['uri'])) {
-                       System::httpExit(404);
-               }
-
-               $uri = urldecode(Strings::escapeTags(trim($_GET['uri'])));
-               if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
-                       $mode = 'json';
-               } else {
-                       $mode = 'xml';
-               }
-       } else {
-               if (empty($_GET['resource'])) {
-                       System::httpExit(404);
-               }
-
-               $uri = urldecode(Strings::escapeTags(trim($_GET['resource'])));
-               if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
-                       $mode = 'xml';
-               } else {
-                       $mode = 'json';
-               }
-       }
-
-       if (substr($uri, 0, 4) === 'http') {
-               $name = ltrim(basename($uri), '~');
-       } else {
-               $local = str_replace('acct:', '', $uri);
-               if (substr($local, 0, 2) == '//') {
-                       $local = substr($local, 2);
-               }
-
-               $name = substr($local, 0, strpos($local, '@'));
-       }
-
-       $user = DBA::selectFirst('user', [], ['nickname' => $name]);
-       if (!DBA::isResult($user)) {
-               System::httpExit(404);
-       }
-
-       $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
-
-       $alias = str_replace('/profile/', '/~', $profile_url);
-
-       $addr = 'acct:'.$user['nickname'].'@'.$a->getHostName();
-       if ($a->getURLPath()) {
-               $addr .= '/'.$a->getURLPath();
-       }
-
-       if ($mode == 'xml') {
-               xrd_xml($addr, $alias, $profile_url, $user);
-       } else {
-               xrd_json($addr, $alias, $profile_url, $user);
-       }
-}
-
-function xrd_json($uri, $alias, $profile_url, $r)
-{
-       $salmon_key = Salmon::salmonKey($r['spubkey']);
-
-       header('Access-Control-Allow-Origin: *');
-       header("Content-type: application/json; charset=utf-8");
-
-       $json = ['subject' => $uri,
-               'aliases' => [$alias, $profile_url],
-               'links' => [
-                       ['rel' => NAMESPACE_DFRN, 'href' => $profile_url],
-                       ['rel' => NAMESPACE_FEED, 'type' => 'application/atom+xml', 'href' => System::baseUrl().'/dfrn_poll/'.$r['nickname']],
-                       ['rel' => 'http://webfinger.net/rel/profile-page', 'type' => 'text/html', 'href' => $profile_url],
-                       ['rel' => 'self', 'type' => 'application/activity+json', 'href' => $profile_url],
-                       ['rel' => 'http://microformats.org/profile/hcard', 'type' => 'text/html', 'href' => System::baseUrl().'/hcard/'.$r['nickname']],
-                       ['rel' => NAMESPACE_POCO, 'href' => System::baseUrl().'/poco/'.$r['nickname']],
-                       ['rel' => 'http://webfinger.net/rel/avatar', 'type' => 'image/jpeg', 'href' => System::baseUrl().'/photo/profile/'.$r['uid'].'.jpg'],
-                       ['rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => System::baseUrl()],
-                       ['rel' => 'salmon', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
-                       ['rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => System::baseUrl().'/salmon/'.$r['nickname']],
-                       ['rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => System::baseUrl().'/salmon/'.$r['nickname'].'/mention'],
-                       ['rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => System::baseUrl().'/follow?url={uri}'],
-                       ['rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,'.$salmon_key],
-                       ['rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-zot+json', 'href' => System::baseUrl().'/owa']
-               ]
-       ];
-
-       echo json_encode($json);
-       exit();
-}
-
-function xrd_xml($uri, $alias, $profile_url, $r)
-{
-       $salmon_key = Salmon::salmonKey($r['spubkey']);
-
-       header('Access-Control-Allow-Origin: *');
-       header("Content-type: text/xml");
-
-       $tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
-
-       $o = Renderer::replaceMacros($tpl, [
-               '$nick'        => $r['nickname'],
-               '$accturi'     => $uri,
-               '$alias'       => $alias,
-               '$profile_url' => $profile_url,
-               '$hcard_url'   => System::baseUrl() . '/hcard/'         . $r['nickname'],
-               '$atom'        => System::baseUrl() . '/dfrn_poll/'     . $r['nickname'],
-               '$poco_url'    => System::baseUrl() . '/poco/'          . $r['nickname'],
-               '$photo'       => System::baseUrl() . '/photo/profile/' . $r['uid']      . '.jpg',
-               '$baseurl'     => System::baseUrl(),
-               '$salmon'      => System::baseUrl() . '/salmon/'        . $r['nickname'],
-               '$salmen'      => System::baseUrl() . '/salmon/'        . $r['nickname'] . '/mention',
-               '$subscribe'   => System::baseUrl() . '/follow?url={uri}',
-               '$openwebauth' => System::baseUrl() . '/owa',
-               '$modexp'      => 'data:application/magic-public-key,'  . $salmon_key]
-       );
-
-       $arr = ['user' => $r, 'xml' => $o];
-       Hook::callAll('personal_xrd', $arr);
-
-       echo $arr['xml'];
-       exit();
-}
index 039d3e2cf9fb1e133d7283a6bf9b805a10b0143e..cdd40ac9da4f9952da87100419b1a7176af72465 100644 (file)
@@ -42,6 +42,81 @@ class Router
        {
                $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Itemsource::class);
                $this->routeCollector->addRoute(['GET'],         '/amcd',                Module\AccountManagementControlDocument::class);
+               $this->routeCollector->addGroup('/.well-known', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '/host-meta'       , Module\WellKnown\HostMeta::class);
+                       $collector->addRoute(['GET'], '/nodeinfo[/1.0]'  , Module\NodeInfo::class);
+                       $collector->addRoute(['GET'], '/webfinger'       , Module\Xrd::class);
+                       $collector->addRoute(['GET'], '/x-social-relay'  , Module\WellKnown\XSocialRelay::class);
+               });
+               $this->routeCollector->addRoute(['GET'],         '/acctlink',            Module\Acctlink::class);
+               $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->addGroup('/contact', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '[/]',                                 Module\Contact::class);
+                       $collector->addRoute(['GET'], '/{id:\d+}[/posts|conversations]',     Module\Contact::class);
+               });
+               $this->routeCollector->addRoute(['GET'],         '/credits',             Module\Credits::class);
+               $this->routeCollector->addGroup('/feed', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '/{nickname}',                         Module\Feed::class);
+                       $collector->addRoute(['GET'], '/{nickname}/posts',                   Module\Feed::class);
+                       $collector->addRoute(['GET'], '/{nickname}/comments',                Module\Feed::class);
+                       $collector->addRoute(['GET'], '/{nickname}/replies',                 Module\Feed::class);
+                       $collector->addRoute(['GET'], '/{nickname}/activity',                Module\Feed::class);
+               });
+               $this->routeCollector->addRoute(['GET'],         '/feedtest',            Module\Feedtest::class);
+               $this->routeCollector->addRoute(['GET'],         '/filer[/{id:\d+}]',    Module\Filer::class);
+               $this->routeCollector->addRoute(['GET'],         '/followers/{owner}',   Module\Followers::class);
+               $this->routeCollector->addRoute(['GET'],         '/following/{owner}',   Module\Following::class);
+               $this->routeCollector->addGroup('/group', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET', 'POST'], '[/]',                         Module\Group::class);
+                       $collector->addRoute(['GET', 'POST'], '/{group:\d+}',                Module\Group::class);
+                       $collector->addRoute(['GET', 'POST'], '/none',                       Module\Group::class);
+                       $collector->addRoute(['GET', 'POST'], '/new',                        Module\Group::class);
+                       $collector->addRoute(['GET', 'POST'], '/drop/{group:\d+}',           Module\Group::class);
+                       $collector->addRoute(['GET', 'POST'], '/{group:\d+}/{contact:\d+}',  Module\Group::class);
+
+                       $collector->addRoute(['POST'], '/{group:\d+}/add/{contact:\d+}',     Module\Group::class);
+                       $collector->addRoute(['POST'], '/{group:\d+}/remove/{contact:\d+}',  Module\Group::class);
+               });
+               $this->routeCollector->addRoute(['GET'],         '/hashtag',             Module\Hashtag::class);
+               $this->routeCollector->addRoute(['GET'],         '/inbox[/{nickname}]',  Module\Inbox::class);
+               $this->routeCollector->addGroup('/install', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET', 'POST'], '[/]',                         Module\Install::class);
+                       $collector->addRoute(['GET'],         '/testrewrite',                Module\Install::class);
+               });
+               $this->routeCollector->addRoute(['GET', 'POST'], '/localtime',           Module\Localtime::class);
+               $this->routeCollector->addRoute(['GET', 'POST'], '/login',               Module\Login::class);
+               $this->routeCollector->addRoute(['GET'],         '/magic',               Module\Magic::class);
+               $this->routeCollector->addRoute(['GET'],         '/manifest',            Module\Manifest::class);
+               $this->routeCollector->addRoute(['GET'],         '/nodeinfo/1.0',        Module\NodeInfo::class);
+               $this->routeCollector->addRoute(['GET'],         '/objects/{guid}',      Module\Objects::class);
+               $this->routeCollector->addGroup('/oembed', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '/[b2h|h2b]',                          Module\Oembed::class);
+                       $collector->addRoute(['GET'], '/{hash}',                             Module\Oembed::class);
+               });
+               $this->routeCollector->addRoute(['GET'],         '/outbox/{owner}',      Module\Outbox::class);
+               $this->routeCollector->addRoute(['GET'],         '/owa',                 Module\Owa::class);
+               $this->routeCollector->addGroup('/photo', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '/{name}',                             Module\Photo::class);
+                       $collector->addRoute(['GET'], '/{type}/{name}',                      Module\Photo::class);
+                       $collector->addRoute(['GET'], '/{type}/{customize}/{name}',          Module\Photo::class);
+               });
+               $this->routeCollector->addGroup('/profile', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '/{nickname}',                         Module\Profile::class);
+                       $collector->addRoute(['GET'], '/{profile:\d+}/view',                 Module\Profile::class);
+               });
+               $this->routeCollector->addGroup('/proxy', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET'], '[/]',                                 Module\Proxy::class);
+                       $collector->addRoute(['GET'], '/{url}',                              Module\Proxy::class);
+                       $collector->addRoute(['GET'], '/sub1/{url}',                         Module\Proxy::class);
+                       $collector->addRoute(['GET'], '/sub1/sub2/{url}',                    Module\Proxy::class);
+               });
+               $this->routeCollector->addRoute(['GET', 'POST'], '/register',            Module\Register::class);
+               $this->routeCollector->addRoute(['GET'],         '/statistics.json',     Module\Statistics::class);
+               $this->routeCollector->addRoute(['GET'],         '/tos',                 Module\Tos::class);
+               $this->routeCollector->addRoute(['GET'],         '/webfinger',           Module\WebFinger::class);
+               $this->routeCollector->addRoute(['GET'],         '/xrd',                 Module\Xrd::class);
        }
 
        public function __construct(RouteCollector $routeCollector = null)
diff --git a/src/Model/Search.php b/src/Model/Search.php
new file mode 100644 (file)
index 0000000..5829ff9
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+namespace Friendica\Model;
+
+use Friendica\BaseObject;
+use Friendica\Database\DBA;
+
+/**
+ * Model for DB specific logic for the search entity
+ */
+class Search extends BaseObject
+{
+       /**
+        * Returns the list of user defined tags (e.g. #Friendica)
+        *
+        * @return array
+        *
+        * @throws \Exception
+        */
+       public static function getUserTags()
+       {
+               $termsStmt = DBA::p("SELECT DISTINCT(`term`) FROM `search`");
+
+               $tags = [];
+
+               while ($term = DBA::fetch($termsStmt)) {
+                       $tags[] = trim($term['term'], '#');
+               }
+
+               return $tags;
+       }
+}
index 4b3823f040d0e1db8f1f7dca070274bee68667fa..c575b44d38ea222593a6b20896fec42ee6d2753d 100644 (file)
@@ -91,12 +91,24 @@ class User
 
        /**
         * @param  integer       $uid
+        * @param array          $fields
         * @return array|boolean User record if it exists, false otherwise
         * @throws Exception
         */
-       public static function getById($uid)
+       public static function getById($uid, array $fields = [])
        {
-               return DBA::selectFirst('user', [], ['uid' => $uid]);
+               return DBA::selectFirst('user', $fields, ['uid' => $uid]);
+       }
+
+       /**
+        * @param  string        $nickname
+        * @param array          $fields
+        * @return array|boolean User record if it exists, false otherwise
+        * @throws Exception
+        */
+       public static function getByNickname($nickname, array $fields = [])
+       {
+               return DBA::selectFirst('user', $fields, ['nickname' => $nickname]);
        }
 
        /**
index dd4e368058b7c3583424dfed3122aef629f789d1..24e0edc5552ad774d7187573249835acd31474b7 100644 (file)
@@ -8,8 +8,8 @@ namespace Friendica\Module;
 
 use Friendica\BaseModule;
 use Friendica\Core\L10n;
-use Friendica\Core\System;
 use Friendica\Core\Logger;
+use Friendica\Core\System;
 use Friendica\Model\Attach as MAttach;
 
 /**
@@ -26,8 +26,8 @@ class Attach extends BaseModule
                if ($a->argc != 2) {
                        System::httpExit(400); // Bad Request.
                }
-       
 
+               // @TODO: Replace with parameter from router
                $item_id = intval($a->argv[1]);
                
                // Check for existence
index 230ad4b57bd008938c0a273846609c734424a4c8..3074bf7d6b7c49475890b9d72113295d41533586 100644 (file)
@@ -46,6 +46,7 @@ class Contact extends BaseModule
 
                $contact_id = null;
                $contact = null;
+               // @TODO: Replace with parameter from router
                if ($a->argc == 2 && intval($a->argv[1])
                        || $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
                ) {
@@ -64,6 +65,7 @@ class Contact extends BaseModule
 
                if (DBA::isResult($contact)) {
                        if ($contact['self']) {
+                               // @TODO: Replace with parameter from router
                                if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
                                        $a->internalRedirect('profile/' . $contact['nick']);
                                } else {
index e5ebe2a4d66239e4551232fb68c49b3fe639e05a..eabd45da23eef073fef2af295390a2b3bdd4fa0a 100644 (file)
@@ -31,11 +31,13 @@ class Feed extends BaseModule
                $last_update = defaults($_GET, 'last_update', '');
                $nocache     = !empty($_GET['nocache']) && local_user();
 
+               // @TODO: Replace with parameter from router
                if ($a->argc < 2) {
                        System::httpExit(400);
                }
 
                $type = null;
+               // @TODO: Replace with parameter from router
                if ($a->argc > 2) {
                        $type = $a->argv[2];
                }
@@ -53,6 +55,7 @@ class Feed extends BaseModule
                                $type = 'posts';
                }
 
+               // @TODO: Replace with parameter from router
                $nickname = $a->argv[1];
                header("Content-type: application/atom+xml; charset=utf-8");
                echo OStatus::feed($nickname, $last_update, 10, $type, $nocache, true);
index 08c656ed388151665aa17c30b42716c4e0c51e83..da59084da090c911ec1014e901cd43316a2b58b5 100644 (file)
@@ -28,6 +28,7 @@ class Filer extends BaseModule
                $logger = $a->getLogger();
 
                $term = XML::unescape(trim(defaults($_GET, 'term', '')));
+               // @TODO: Replace with parameter from router
                $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
 
                $logger->info('filer', ['tag' => $term, 'item' => $item_id]);
index 56160aecf81a10f8df4e857561ee99b1992302c5..9906dfc33e3b2882ee0da885a523da6ad97fd354 100644 (file)
@@ -5,9 +5,9 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
-use Friendica\Protocol\ActivityPub;
 use Friendica\Core\System;
 use Friendica\Model\User;
+use Friendica\Protocol\ActivityPub;
 
 /**
  * ActivityPub Followers
@@ -18,10 +18,12 @@ class Followers extends BaseModule
        {
                $a = self::getApp();
 
+               // @TODO: Replace with parameter from router
                if (empty($a->argv[1])) {
                        System::httpExit(404);
                }
 
+               // @TODO: Replace with parameter from router
                $owner = User::getOwnerDataByNick($a->argv[1]);
                if (empty($owner)) {
                        System::httpExit(404);
index 71e6613f0c19629810a7b7d0cd26ccb8f0da51b1..670142c4897ad0c261c9853aef6cbdeff3a82f72 100644 (file)
@@ -5,9 +5,9 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
-use Friendica\Protocol\ActivityPub;
 use Friendica\Core\System;
 use Friendica\Model\User;
+use Friendica\Protocol\ActivityPub;
 
 /**
  * ActivityPub Following
@@ -18,10 +18,12 @@ class Following extends BaseModule
        {
                $a = self::getApp();
 
+               // @TODO: Replace with parameter from router
                if (empty($a->argv[1])) {
                        System::httpExit(404);
                }
 
+               // @TODO: Replace with parameter from router
                $owner = User::getOwnerDataByNick($a->argv[1]);
                if (empty($owner)) {
                        System::httpExit(404);
index 747ec1e56d8224f8ae71e7930e38242fefba9773..eb1389d799e33d5c27d2d15f1264306ba0dd5cba 100644 (file)
-<?php\r
-/**\r
- * @file src/Module/Group.php\r
- */\r
-\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Core\Config;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\PConfig;\r
-use Friendica\Core\Renderer;\r
-use Friendica\Core\System;\r
-use Friendica\Database\DBA;\r
-use Friendica\Model;\r
-use Friendica\Util\Strings;\r
-\r
-require_once 'boot.php';\r
-\r
-class Group extends BaseModule\r
-{\r
-       public static function post()\r
-       {\r
-               $a = self::getApp();\r
-\r
-               if ($a->isAjax()) {\r
-                       self::ajaxPost();\r
-               }\r
-\r
-               if (!local_user()) {\r
-                       notice(L10n::t('Permission denied.'));\r
-                       $a->internalRedirect();\r
-               }\r
-\r
-               if (($a->argc == 2) && ($a->argv[1] === 'new')) {\r
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');\r
-\r
-                       $name = Strings::escapeTags(trim($_POST['groupname']));\r
-                       $r = Model\Group::create(local_user(), $name);\r
-                       if ($r) {\r
-                               info(L10n::t('Group created.'));\r
-                               $r = Model\Group::getIdByName(local_user(), $name);\r
-                               if ($r) {\r
-                                       $a->internalRedirect('group/' . $r);\r
-                               }\r
-                       } else {\r
-                               notice(L10n::t('Could not create group.'));\r
-                       }\r
-                       $a->internalRedirect('group');\r
-               }\r
-\r
-               if (($a->argc == 2) && intval($a->argv[1])) {\r
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');\r
-\r
-                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]);\r
-                       if (!DBA::isResult($group)) {\r
-                               notice(L10n::t('Group not found.'));\r
-                               $a->internalRedirect('contact');\r
-                       }\r
-                       $groupname = Strings::escapeTags(trim($_POST['groupname']));\r
-                       if (strlen($groupname) && ($groupname != $group['name'])) {\r
-                               if (Model\Group::update($group['id'], $groupname)) {\r
-                                       info(L10n::t('Group name changed.'));\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       public static function ajaxPost()\r
-       {\r
-               try {\r
-                       $a = self::getApp();\r
-\r
-                       if (!local_user()) {\r
-                               throw new \Exception(L10n::t('Permission denied.'), 403);\r
-                       }\r
-\r
-                       // POST /group/123/add/123\r
-                       // POST /group/123/remove/123\r
-                       if ($a->argc == 4) {\r
-                               list($group_id, $command, $contact_id) = array_slice($a->argv, 1);\r
-\r
-                               if (!Model\Group::exists($group_id, local_user())) {\r
-                                       throw new \Exception(L10n::t('Unknown group.'), 404);\r
-                               }\r
-\r
-                               $contact = DBA::selectFirst('contact', ['pending', 'blocked', 'deleted'], ['id' => $contact_id, 'uid' => local_user()]);\r
-                               if (!DBA::isResult($contact)) {\r
-                                       throw new \Exception(L10n::t('Contact not found.'), 404);\r
-                               }\r
-\r
-                               if ($contact['pending']) {\r
-                                       throw new \Exception(L10n::t('Contact is unavailable.'), 400);\r
-                               }\r
-\r
-                               if ($contact['deleted']) {\r
-                                       throw new \Exception(L10n::t('Contact is deleted.'), 410);\r
-                               }\r
-\r
-                               switch($command) {\r
-                                       case 'add':\r
-                                               if ($contact['blocked']) {\r
-                                                       throw new \Exception(L10n::t('Contact is blocked, unable to add it to a group.'), 400);\r
-                                               }\r
-\r
-                                               if (!Model\Group::addMember($group_id, $contact_id)) {\r
-                                                       throw new \Exception(L10n::t('Unable to add the contact to the group.'), 500);\r
-                                               }\r
-                                               $message = L10n::t('Contact successfully added to group.');\r
-                                               break;\r
-                                       case 'remove':\r
-                                               if (!Model\Group::removeMember($group_id, $contact_id)) {\r
-                                                       throw new \Exception(L10n::t('Unable to remove the contact from the group.'), 500);\r
-                                               }\r
-                                               $message = L10n::t('Contact successfully removed from group.');\r
-                                               break;\r
-                                       default:\r
-                                               throw new \Exception(L10n::t('Unknown group command.'), 400);\r
-                               }\r
-                       } else {\r
-                               throw new \Exception(L10n::t('Bad request.'), 400);\r
-                       }\r
-\r
-                       notice($message);\r
-                       System::jsonExit(['status' => 'OK', 'message' => $message]);\r
-               } catch (\Exception $e) {\r
-                       notice($e->getMessage());\r
-                       System::jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);\r
-               }\r
-       }\r
-\r
-       public static function content()\r
-       {\r
-               $change = false;\r
-\r
-               if (!local_user()) {\r
-                       System::httpExit(403);\r
-               }\r
-\r
-               $a = self::getApp();\r
-\r
-               $a->page['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone'));\r
-\r
-               // With no group number provided we jump to the unassigned contacts as a starting point\r
-               if ($a->argc == 1) {\r
-                       $a->internalRedirect('group/none');\r
-               }\r
-\r
-               // Switch to text mode interface if we have more than 'n' contacts or group members\r
-               $switchtotext = PConfig::get(local_user(), 'system', 'groupedit_image_limit');\r
-               if (is_null($switchtotext)) {\r
-                       $switchtotext = Config::get('system', 'groupedit_image_limit', 200);\r
-               }\r
-\r
-               $tpl = Renderer::getMarkupTemplate('group_edit.tpl');\r
-\r
-\r
-               $context = [\r
-                       '$submit' => L10n::t('Save Group'),\r
-                       '$submit_filter' => L10n::t('Filter'),\r
-               ];\r
-\r
-               if (($a->argc == 2) && ($a->argv[1] === 'new')) {\r
-                       return Renderer::replaceMacros($tpl, $context + [\r
-                               '$title' => L10n::t('Create a group of contacts/friends.'),\r
-                               '$gname' => ['groupname', L10n::t('Group Name: '), '', ''],\r
-                               '$gid' => 'new',\r
-                               '$form_security_token' => BaseModule::getFormSecurityToken("group_edit"),\r
-                       ]);\r
-               }\r
-\r
-               $nogroup = false;\r
-\r
-               if (($a->argc == 2) && ($a->argv[1] === 'none')) {\r
-                       $id = -1;\r
-                       $nogroup = true;\r
-                       $group = [\r
-                               'id' => $id,\r
-                               'name' => L10n::t('Contacts not in any group'),\r
-                       ];\r
-\r
-                       $members = [];\r
-                       $preselected = [];\r
-\r
-                       $context = $context + [\r
-                               '$title' => $group['name'],\r
-                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],\r
-                               '$gid' => $id,\r
-                               '$editable' => 0,\r
-                       ];\r
-               }\r
-\r
-               if (($a->argc == 3) && ($a->argv[1] === 'drop')) {\r
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_drop', 't');\r
-\r
-                       if (intval($a->argv[2])) {\r
-                               if (!Model\Group::exists($a->argv[2], local_user())) {\r
-                                       notice(L10n::t('Group not found.'));\r
-                                       $a->internalRedirect('contact');\r
-                               }\r
-\r
-                               if (Model\Group::remove($a->argv[2])) {\r
-                                       info(L10n::t('Group removed.'));\r
-                               } else {\r
-                                       notice(L10n::t('Unable to remove group.'));\r
-                               }\r
-                       }\r
-                       $a->internalRedirect('group');\r
-               }\r
-\r
-               if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {\r
-                       BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');\r
-\r
-                       if (DBA::exists('contact', ['id' => $a->argv[2], 'uid' => local_user(), 'self' => false, 'pending' => false, 'blocked' => false])) {\r
-                               $change = intval($a->argv[2]);\r
-                       }\r
-               }\r
-\r
-               if (($a->argc > 1) && intval($a->argv[1])) {\r
-                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]);\r
-                       if (!DBA::isResult($group)) {\r
-                               notice(L10n::t('Group not found.'));\r
-                               $a->internalRedirect('contact');\r
-                       }\r
-\r
-                       $members = Model\Contact::getByGroupId($group['id']);\r
-                       $preselected = [];\r
-\r
-                       if (count($members)) {\r
-                               foreach ($members as $member) {\r
-                                       $preselected[] = $member['id'];\r
-                               }\r
-                       }\r
-\r
-                       if ($change) {\r
-                               if (in_array($change, $preselected)) {\r
-                                       Model\Group::removeMember($group['id'], $change);\r
-                               } else {\r
-                                       Model\Group::addMember($group['id'], $change);\r
-                               }\r
-\r
-                               $members = Model\Contact::getByGroupId($group['id']);\r
-                               $preselected = [];\r
-                               if (count($members)) {\r
-                                       foreach ($members as $member) {\r
-                                               $preselected[] = $member['id'];\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       $drop_tpl = Renderer::getMarkupTemplate('group_drop.tpl');\r
-                       $drop_txt = Renderer::replaceMacros($drop_tpl, [\r
-                               '$id' => $group['id'],\r
-                               '$delete' => L10n::t('Delete Group'),\r
-                               '$form_security_token' => BaseModule::getFormSecurityToken("group_drop"),\r
-                       ]);\r
-\r
-                       $context = $context + [\r
-                               '$title' => $group['name'],\r
-                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],\r
-                               '$gid' => $group['id'],\r
-                               '$drop' => $drop_txt,\r
-                               '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),\r
-                               '$edit_name' => L10n::t('Edit Group Name'),\r
-                               '$editable' => 1,\r
-                       ];\r
-               }\r
-\r
-               if (!isset($group)) {\r
-                       System::httpExit(400);\r
-               }\r
-\r
-               $groupeditor = [\r
-                       'label_members' => L10n::t('Members'),\r
-                       'members' => [],\r
-                       'label_contacts' => L10n::t('All Contacts'),\r
-                       'group_is_empty' => L10n::t('Group is empty'),\r
-                       'contacts' => [],\r
-               ];\r
-\r
-               $sec_token = addslashes(BaseModule::getFormSecurityToken('group_member_change'));\r
-\r
-               // Format the data of the group members\r
-               foreach ($members as $member) {\r
-                       if ($member['url']) {\r
-                               $entry = Contact::getContactTemplateVars($member);\r
-                               $entry['label'] = 'members';\r
-                               $entry['photo_menu'] = '';\r
-                               $entry['change_member'] = [\r
-                                       'title'     => L10n::t("Remove contact from group"),\r
-                                       'gid'       => $group['id'],\r
-                                       'cid'       => $member['id'],\r
-                                       'sec_token' => $sec_token\r
-                               ];\r
-\r
-                               $groupeditor['members'][] = $entry;\r
-                       } else {\r
-                               Model\Group::removeMember($group['id'], $member['id']);\r
-                       }\r
-               }\r
-\r
-               if ($nogroup) {\r
-                       $contacts = Model\Contact::getUngroupedList(local_user());\r
-               } else {\r
-                       $contacts_stmt = DBA::select('contact', [],\r
-                               ['uid' => local_user(), 'pending' => false, 'blocked' => false, 'self' => false],\r
-                               ['order' => ['name']]\r
-                       );\r
-                       $contacts = DBA::toArray($contacts_stmt);\r
-                       $context['$desc'] = L10n::t('Click on a contact to add or remove.');\r
-               }\r
-\r
-               if (DBA::isResult($contacts)) {\r
-                       // Format the data of the contacts who aren't in the contact group\r
-                       foreach ($contacts as $member) {\r
-                               if (!in_array($member['id'], $preselected)) {\r
-                                       $entry = Contact::getContactTemplateVars($member);\r
-                                       $entry['label'] = 'contacts';\r
-                                       if (!$nogroup)\r
-                                               $entry['photo_menu'] = [];\r
-\r
-                                       if (!$nogroup) {\r
-                                               $entry['change_member'] = [\r
-                                                       'title'     => L10n::t("Add contact to group"),\r
-                                                       'gid'       => $group['id'],\r
-                                                       'cid'       => $member['id'],\r
-                                                       'sec_token' => $sec_token\r
-                                               ];\r
-                                       }\r
-\r
-                                       $groupeditor['contacts'][] = $entry;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               $context['$groupeditor'] = $groupeditor;\r
-\r
-               // If there are to many contacts we could provide an alternative view mode\r
-               $total = count($groupeditor['members']) + count($groupeditor['contacts']);\r
-               $context['$shortmode'] = (($switchtotext && ($total > $switchtotext)) ? true : false);\r
-\r
-               if ($change) {\r
-                       $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');\r
-                       echo Renderer::replaceMacros($tpl, $context);\r
-                       exit();\r
-               }\r
-\r
-               return Renderer::replaceMacros($tpl, $context);\r
-       }\r
+<?php
+/**
+ * @file src/Module/Group.php
+ */
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\Model;
+use Friendica\Util\Strings;
+
+require_once 'boot.php';
+
+class Group extends BaseModule
+{
+       public static function post()
+       {
+               $a = self::getApp();
+
+               if ($a->isAjax()) {
+                       self::ajaxPost();
+               }
+
+               if (!local_user()) {
+                       notice(L10n::t('Permission denied.'));
+                       $a->internalRedirect();
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && ($a->argv[1] === 'new')) {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
+
+                       $name = Strings::escapeTags(trim($_POST['groupname']));
+                       $r = Model\Group::create(local_user(), $name);
+                       if ($r) {
+                               info(L10n::t('Group created.'));
+                               $r = Model\Group::getIdByName(local_user(), $name);
+                               if ($r) {
+                                       $a->internalRedirect('group/' . $r);
+                               }
+                       } else {
+                               notice(L10n::t('Could not create group.'));
+                       }
+                       $a->internalRedirect('group');
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && intval($a->argv[1])) {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');
+
+                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]);
+                       if (!DBA::isResult($group)) {
+                               notice(L10n::t('Group not found.'));
+                               $a->internalRedirect('contact');
+                       }
+                       $groupname = Strings::escapeTags(trim($_POST['groupname']));
+                       if (strlen($groupname) && ($groupname != $group['name'])) {
+                               if (Model\Group::update($group['id'], $groupname)) {
+                                       info(L10n::t('Group name changed.'));
+                               }
+                       }
+               }
+       }
+
+       public static function ajaxPost()
+       {
+               try {
+                       $a = self::getApp();
+
+                       if (!local_user()) {
+                               throw new \Exception(L10n::t('Permission denied.'), 403);
+                       }
+
+                       // POST /group/123/add/123
+                       // POST /group/123/remove/123
+                       // @TODO: Replace with parameter from router
+                       if ($a->argc == 4) {
+                               list($group_id, $command, $contact_id) = array_slice($a->argv, 1);
+
+                               if (!Model\Group::exists($group_id, local_user())) {
+                                       throw new \Exception(L10n::t('Unknown group.'), 404);
+                               }
+
+                               $contact = DBA::selectFirst('contact', ['pending', 'blocked', 'deleted'], ['id' => $contact_id, 'uid' => local_user()]);
+                               if (!DBA::isResult($contact)) {
+                                       throw new \Exception(L10n::t('Contact not found.'), 404);
+                               }
+
+                               if ($contact['pending']) {
+                                       throw new \Exception(L10n::t('Contact is unavailable.'), 400);
+                               }
+
+                               if ($contact['deleted']) {
+                                       throw new \Exception(L10n::t('Contact is deleted.'), 410);
+                               }
+
+                               switch($command) {
+                                       case 'add':
+                                               if ($contact['blocked']) {
+                                                       throw new \Exception(L10n::t('Contact is blocked, unable to add it to a group.'), 400);
+                                               }
+
+                                               if (!Model\Group::addMember($group_id, $contact_id)) {
+                                                       throw new \Exception(L10n::t('Unable to add the contact to the group.'), 500);
+                                               }
+                                               $message = L10n::t('Contact successfully added to group.');
+                                               break;
+                                       case 'remove':
+                                               if (!Model\Group::removeMember($group_id, $contact_id)) {
+                                                       throw new \Exception(L10n::t('Unable to remove the contact from the group.'), 500);
+                                               }
+                                               $message = L10n::t('Contact successfully removed from group.');
+                                               break;
+                                       default:
+                                               throw new \Exception(L10n::t('Unknown group command.'), 400);
+                               }
+                       } else {
+                               throw new \Exception(L10n::t('Bad request.'), 400);
+                       }
+
+                       notice($message);
+                       System::jsonExit(['status' => 'OK', 'message' => $message]);
+               } catch (\Exception $e) {
+                       notice($e->getMessage());
+                       System::jsonError($e->getCode(), ['status' => 'error', 'message' => $e->getMessage()]);
+               }
+       }
+
+       public static function content()
+       {
+               $change = false;
+
+               if (!local_user()) {
+                       System::httpExit(403);
+               }
+
+               $a = self::getApp();
+
+               $a->page['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone'));
+
+               // With no group number provided we jump to the unassigned contacts as a starting point
+               // @TODO: Replace with parameter from router
+               if ($a->argc == 1) {
+                       $a->internalRedirect('group/none');
+               }
+
+               // Switch to text mode interface if we have more than 'n' contacts or group members
+               $switchtotext = PConfig::get(local_user(), 'system', 'groupedit_image_limit');
+               if (is_null($switchtotext)) {
+                       $switchtotext = Config::get('system', 'groupedit_image_limit', 200);
+               }
+
+               $tpl = Renderer::getMarkupTemplate('group_edit.tpl');
+
+
+               $context = [
+                       '$submit' => L10n::t('Save Group'),
+                       '$submit_filter' => L10n::t('Filter'),
+               ];
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 2) && ($a->argv[1] === 'new')) {
+                       return Renderer::replaceMacros($tpl, $context + [
+                               '$title' => L10n::t('Create a group of contacts/friends.'),
+                               '$gname' => ['groupname', L10n::t('Group Name: '), '', ''],
+                               '$gid' => 'new',
+                               '$form_security_token' => BaseModule::getFormSecurityToken("group_edit"),
+                       ]);
+               }
+
+               $nogroup = false;
+
+               if (($a->argc == 2) && ($a->argv[1] === 'none')) {
+                       $id = -1;
+                       $nogroup = true;
+                       $group = [
+                               'id' => $id,
+                               'name' => L10n::t('Contacts not in any group'),
+                       ];
+
+                       $members = [];
+                       $preselected = [];
+
+                       $context = $context + [
+                               '$title' => $group['name'],
+                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],
+                               '$gid' => $id,
+                               '$editable' => 0,
+                       ];
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc == 3) && ($a->argv[1] === 'drop')) {
+                       BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_drop', 't');
+
+                       // @TODO: Replace with parameter from router
+                       if (intval($a->argv[2])) {
+                               if (!Model\Group::exists($a->argv[2], local_user())) {
+                                       notice(L10n::t('Group not found.'));
+                                       $a->internalRedirect('contact');
+                               }
+
+                               if (Model\Group::remove($a->argv[2])) {
+                                       info(L10n::t('Group removed.'));
+                               } else {
+                                       notice(L10n::t('Unable to remove group.'));
+                               }
+                       }
+                       $a->internalRedirect('group');
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
+                       BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');
+
+                       if (DBA::exists('contact', ['id' => $a->argv[2], 'uid' => local_user(), 'self' => false, 'pending' => false, 'blocked' => false])) {
+                               $change = intval($a->argv[2]);
+                       }
+               }
+
+               // @TODO: Replace with parameter from router
+               if (($a->argc > 1) && intval($a->argv[1])) {
+                       $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]);
+                       if (!DBA::isResult($group)) {
+                               notice(L10n::t('Group not found.'));
+                               $a->internalRedirect('contact');
+                       }
+
+                       $members = Model\Contact::getByGroupId($group['id']);
+                       $preselected = [];
+
+                       if (count($members)) {
+                               foreach ($members as $member) {
+                                       $preselected[] = $member['id'];
+                               }
+                       }
+
+                       if ($change) {
+                               if (in_array($change, $preselected)) {
+                                       Model\Group::removeMember($group['id'], $change);
+                               } else {
+                                       Model\Group::addMember($group['id'], $change);
+                               }
+
+                               $members = Model\Contact::getByGroupId($group['id']);
+                               $preselected = [];
+                               if (count($members)) {
+                                       foreach ($members as $member) {
+                                               $preselected[] = $member['id'];
+                                       }
+                               }
+                       }
+
+                       $drop_tpl = Renderer::getMarkupTemplate('group_drop.tpl');
+                       $drop_txt = Renderer::replaceMacros($drop_tpl, [
+                               '$id' => $group['id'],
+                               '$delete' => L10n::t('Delete Group'),
+                               '$form_security_token' => BaseModule::getFormSecurityToken("group_drop"),
+                       ]);
+
+                       $context = $context + [
+                               '$title' => $group['name'],
+                               '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''],
+                               '$gid' => $group['id'],
+                               '$drop' => $drop_txt,
+                               '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),
+                               '$edit_name' => L10n::t('Edit Group Name'),
+                               '$editable' => 1,
+                       ];
+               }
+
+               if (!isset($group)) {
+                       System::httpExit(400);
+               }
+
+               $groupeditor = [
+                       'label_members' => L10n::t('Members'),
+                       'members' => [],
+                       'label_contacts' => L10n::t('All Contacts'),
+                       'group_is_empty' => L10n::t('Group is empty'),
+                       'contacts' => [],
+               ];
+
+               $sec_token = addslashes(BaseModule::getFormSecurityToken('group_member_change'));
+
+               // Format the data of the group members
+               foreach ($members as $member) {
+                       if ($member['url']) {
+                               $entry = Contact::getContactTemplateVars($member);
+                               $entry['label'] = 'members';
+                               $entry['photo_menu'] = '';
+                               $entry['change_member'] = [
+                                       'title'     => L10n::t("Remove contact from group"),
+                                       'gid'       => $group['id'],
+                                       'cid'       => $member['id'],
+                                       'sec_token' => $sec_token
+                               ];
+
+                               $groupeditor['members'][] = $entry;
+                       } else {
+                               Model\Group::removeMember($group['id'], $member['id']);
+                       }
+               }
+
+               if ($nogroup) {
+                       $contacts = Model\Contact::getUngroupedList(local_user());
+               } else {
+                       $contacts_stmt = DBA::select('contact', [],
+                               ['uid' => local_user(), 'pending' => false, 'blocked' => false, 'self' => false],
+                               ['order' => ['name']]
+                       );
+                       $contacts = DBA::toArray($contacts_stmt);
+                       $context['$desc'] = L10n::t('Click on a contact to add or remove.');
+               }
+
+               if (DBA::isResult($contacts)) {
+                       // Format the data of the contacts who aren't in the contact group
+                       foreach ($contacts as $member) {
+                               if (!in_array($member['id'], $preselected)) {
+                                       $entry = Contact::getContactTemplateVars($member);
+                                       $entry['label'] = 'contacts';
+                                       if (!$nogroup)
+                                               $entry['photo_menu'] = [];
+
+                                       if (!$nogroup) {
+                                               $entry['change_member'] = [
+                                                       'title'     => L10n::t("Add contact to group"),
+                                                       'gid'       => $group['id'],
+                                                       'cid'       => $member['id'],
+                                                       'sec_token' => $sec_token
+                                               ];
+                                       }
+
+                                       $groupeditor['contacts'][] = $entry;
+                               }
+                       }
+               }
+
+               $context['$groupeditor'] = $groupeditor;
+
+               // If there are to many contacts we could provide an alternative view mode
+               $total = count($groupeditor['members']) + count($groupeditor['contacts']);
+               $context['$shortmode'] = (($switchtotext && ($total > $switchtotext)) ? true : false);
+
+               if ($change) {
+                       $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');
+                       echo Renderer::replaceMacros($tpl, $context);
+                       exit();
+               }
+
+               return Renderer::replaceMacros($tpl, $context);
+       }
 }
\ No newline at end of file
index 1bc127b7c9a76c65c2188a402d3b5a80ef28271a..35160bd88d03a4e92f0ae8afec80187e732a00d5 100644 (file)
@@ -6,12 +6,12 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
+use Friendica\Core\Config;
 use Friendica\Core\Logger;
-use Friendica\Protocol\ActivityPub;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Protocol\ActivityPub;
 use Friendica\Util\HTTPSignature;
-use Friendica\Core\Config;
 
 /**
  * ActivityPub Inbox
@@ -39,6 +39,7 @@ class Inbox extends BaseModule
                        Logger::log('Incoming message stored under ' . $tempfile);
                }
 
+               // @TODO: Replace with parameter from router
                if (!empty($a->argv[1])) {
                        $user = DBA::selectFirst('user', ['uid'], ['nickname' => $a->argv[1]]);
                        if (!DBA::isResult($user)) {
index 65a30e894bed610c356318699910d7f1bc0b2f03..1cef8fbafa5ac63a24d2693d8311e9abb6020eff 100644 (file)
@@ -56,6 +56,7 @@ class Install extends BaseModule
 
                // route: install/testrwrite
                // $baseurl/install/testrwrite to test if rewrite in .htaccess is working
+               // @TODO: Replace with parameter from router
                if ($a->getArgumentValue(1, '') == 'testrewrite') {
                        // Status Code 204 means that it worked without content
                        Core\System::httpExit(204);
index f92baa987c6d5de819402abf3a3c53c0d6f457a6..d781db3ac5d207b54bdfb4f3a7050e17587acdfa 100644 (file)
@@ -2,12 +2,9 @@
 
 namespace Friendica\Module;
 
-use Friendica\Content\Text\HTML;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Model;
-use Friendica\Protocol\ActivityPub\Processor;
-use Friendica\Protocol\Diaspora;
 
 /**
  * @author Hypolite Petovan <mrpetovan@gmail.com>
@@ -22,6 +19,7 @@ class Itemsource extends \Friendica\BaseModule
 
                $a = self::getApp();
 
+               // @TODO: Replace with parameter from router
                if (!empty($a->argv[1])) {
                        $guid = $a->argv[1];
                }
diff --git a/src/Module/NodeInfo.php b/src/Module/NodeInfo.php
new file mode 100644 (file)
index 0000000..c8d75b8
--- /dev/null
@@ -0,0 +1,184 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\App;
+use Friendica\BaseModule;
+use Friendica\Core\Addon;
+use Friendica\Core\System;
+
+/**
+ * Standardized way of exposing metadata about a server running one of the distributed social networks.
+ * @see https://github.com/jhass/nodeinfo/blob/master/PROTOCOL.md
+ */
+class NodeInfo extends BaseModule
+{
+       public static function init()
+       {
+               $config = self::getApp()->getConfig();
+
+               if (!$config->get('system', 'nodeinfo')) {
+                       System::httpExit(404);
+               }
+       }
+
+       public static function rawContent()
+       {
+               $app = self::getApp();
+
+               // @TODO: Replace with parameter from router
+               // if the first argument is ".well-known", print the well-known text
+               if (($app->argc > 1) && ($app->argv[0] == '.well-known')) {
+                       self::printWellKnown($app);
+               // otherwise print the nodeinfo
+               } else {
+                       self::printNodeInfo($app);
+               }
+       }
+
+       /**
+        * Prints the well-known nodeinfo redirect
+        *
+        * @param App $app
+        *
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       private static function printWellKnown(App $app)
+       {
+               $config = $app->getConfig();
+
+               if (!$config->get('system', 'nodeinfo')) {
+                       System::httpExit(404);
+               }
+
+               $nodeinfo = [
+                       'links' => [[
+                               'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
+                               'href' => $app->getBaseURL() . '/nodeinfo/1.0']]
+               ];
+
+               header('Content-type: application/json; charset=utf-8');
+               echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+               exit;
+       }
+
+       /**
+        * Print the nodeinfo
+        *
+        * @param App $app
+        */
+       private static function printNodeInfo(App $app)
+       {
+               $config = $app->getConfig();
+
+               $smtp = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
+
+               $nodeinfo = [
+                       'version'           => 1.0,
+                       'software'          => [
+                               'name'    => 'friendica',
+                               'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
+                       ],
+                       'protocols'         => [
+                               'inbound'  => [
+                                       'friendica',
+                               ],
+                               'outbound' => [
+                                       'friendica',
+                               ],
+                       ],
+                       'services'          => [
+                               'inbound'  => [],
+                               'outbound' => [],
+                       ],
+                       'usage'             => [],
+                       'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
+                       'metadata'          => [
+                               'nodeName' => $config->get('config', 'sitename'),
+                       ],
+               ];
+
+               if (!empty($config->get('system', 'diaspora_enabled'))) {
+                       $nodeinfo['protocols']['inbound'][] = 'diaspora';
+                       $nodeinfo['protocols']['outbound'][] = 'diaspora';
+               }
+
+               if (empty($config->get('system', 'ostatus_disabled'))) {
+                       $nodeinfo['protocols']['inbound'][] = 'gnusocial';
+                       $nodeinfo['protocols']['outbound'][] = 'gnusocial';
+               }
+
+               if (!empty($config->get('system', 'nodeinfo'))) {
+
+                       $nodeinfo['usage']['users'] = [
+                               'total'          => intval($config->get('nodeinfo', 'total_users')),
+                               'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
+                               'activeMonth'    => intval($config->get('nodeinfo', 'active_users_monthly'))
+                       ];
+                       $nodeinfo['usage']['localPosts'] = intval($config->get('nodeinfo', 'local_posts'));
+                       $nodeinfo['usage']['localComments'] = intval($config->get('nodeinfo', 'local_comments'));
+
+                       if (Addon::isEnabled('blogger')) {
+                               $nodeinfo['services']['outbound'][] = 'blogger';
+                       }
+                       if (Addon::isEnabled('dwpost')) {
+                               $nodeinfo['services']['outbound'][] = 'dreamwidth';
+                       }
+                       if (Addon::isEnabled('statusnet')) {
+                               $nodeinfo['services']['inbound'][] = 'gnusocial';
+                               $nodeinfo['services']['outbound'][] = 'gnusocial';
+                       }
+                       if (Addon::isEnabled('ijpost')) {
+                               $nodeinfo['services']['outbound'][] = 'insanejournal';
+                       }
+                       if (Addon::isEnabled('libertree')) {
+                               $nodeinfo['services']['outbound'][] = 'libertree';
+                       }
+                       if (Addon::isEnabled('buffer')) {
+                               $nodeinfo['services']['outbound'][] = 'linkedin';
+                       }
+                       if (Addon::isEnabled('ljpost')) {
+                               $nodeinfo['services']['outbound'][] = 'livejournal';
+                       }
+                       if (Addon::isEnabled('buffer')) {
+                               $nodeinfo['services']['outbound'][] = 'pinterest';
+                       }
+                       if (Addon::isEnabled('posterous')) {
+                               $nodeinfo['services']['outbound'][] = 'posterous';
+                       }
+                       if (Addon::isEnabled('pumpio')) {
+                               $nodeinfo['services']['inbound'][] = 'pumpio';
+                               $nodeinfo['services']['outbound'][] = 'pumpio';
+                       }
+
+                       if ($smtp) {
+                               $nodeinfo['services']['outbound'][] = 'smtp';
+                       }
+                       if (Addon::isEnabled('tumblr')) {
+                               $nodeinfo['services']['outbound'][] = 'tumblr';
+                       }
+                       if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
+                               $nodeinfo['services']['outbound'][] = 'twitter';
+                       }
+                       if (Addon::isEnabled('wppost')) {
+                               $nodeinfo['services']['outbound'][] = 'wordpress';
+                       }
+                       $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
+                       $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
+                       $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
+                       $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
+
+                       $nodeinfo['metadata']['services'] = $nodeinfo['services'];
+
+                       if (Addon::isEnabled('twitter')) {
+                               $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
+                       }
+
+                       $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
+               }
+
+               header('Content-type: application/json; charset=utf-8');
+               echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+               exit;
+       }
+}
diff --git a/src/Module/Nodeinfo.php b/src/Module/Nodeinfo.php
deleted file mode 100644 (file)
index 18f2c72..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\App;
-use Friendica\BaseModule;
-use Friendica\Core\Addon;
-use Friendica\Core\System;
-
-/**
- * Prints infos about the current node
- */
-class Nodeinfo extends BaseModule
-{
-       /**
-        * Prints the Nodeinfo for a well-known request
-        *
-        * @param App $app
-        *
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        */
-       public static function printWellKnown(App $app)
-       {
-               $config = $app->getConfig();
-
-               if (!$config->get('system', 'nodeinfo')) {
-                       System::httpExit(404);
-               }
-
-               $nodeinfo = [
-                       'links' => [[
-                               'rel'  => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
-                               'href' => $app->getBaseURL() . '/nodeinfo/1.0']]
-               ];
-
-               header('Content-type: application/json; charset=utf-8');
-               echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
-               exit;
-       }
-
-       public static function init()
-       {
-               $app = self::getApp();
-               $config = $app->getConfig();
-
-               if (!$config->get('system', 'nodeinfo')) {
-                       System::httpExit(404);
-               }
-
-               if (($app->argc != 2) || ($app->argv[1] != '1.0')) {
-                       System::httpExit(404);
-               }
-       }
-
-       public static function rawContent()
-       {
-               $config = self::getApp()->getConfig();
-
-               $smtp = (function_exists('imap_open') && !$config->get('system', 'imap_disabled') && !$config->get('system', 'dfrn_only'));
-
-               $nodeinfo = [
-                       'version'           => 1.0,
-                       'software'          => [
-                               'name'    => 'friendica',
-                               'version' => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
-                       ],
-                       'protocols'         => [
-                               'inbound'  => [
-                                       'friendica',
-                               ],
-                               'outbound' => [
-                                       'friendica',
-                               ],
-                       ],
-                       'services'          => [
-                               'inbound'  => [],
-                               'outbound' => [],
-                       ],
-                       'usage'             => [],
-                       'openRegistrations' => intval($config->get('config', 'register_policy')) !== Register::CLOSED,
-                       'metadata'          => [
-                               'nodeName' => $config->get('config', 'sitename'),
-                       ],
-               ];
-
-               if (!empty($config->get('system', 'diaspora_enabled'))) {
-                       $nodeinfo['protocols']['inbound'][] = 'diaspora';
-                       $nodeinfo['protocols']['outbound'][] = 'diaspora';
-               }
-
-               if (empty($config->get('system', 'ostatus_disabled'))) {
-                       $nodeinfo['protocols']['inbound'][] = 'gnusocial';
-                       $nodeinfo['protocols']['outbound'][] = 'gnusocial';
-               }
-
-               if (!empty($config->get('system', 'nodeinfo'))) {
-
-                       $nodeinfo['usage']['users'] = [
-                               'total'          => intval($config->get('nodeinfo', 'total_users')),
-                               'activeHalfyear' => intval($config->get('nodeinfo', 'active_users_halfyear')),
-                               'activeMonth'    => intval($config->get('nodeinfo', 'active_users_monthly'))
-                       ];
-                       $nodeinfo['usage']['localPosts'] = intval($config->get('nodeinfo', 'local_posts'));
-                       $nodeinfo['usage']['localComments'] = intval($config->get('nodeinfo', 'local_comments'));
-
-                       if (Addon::isEnabled('blogger')) {
-                               $nodeinfo['services']['outbound'][] = 'blogger';
-                       }
-                       if (Addon::isEnabled('dwpost')) {
-                               $nodeinfo['services']['outbound'][] = 'dreamwidth';
-                       }
-                       if (Addon::isEnabled('statusnet')) {
-                               $nodeinfo['services']['inbound'][] = 'gnusocial';
-                               $nodeinfo['services']['outbound'][] = 'gnusocial';
-                       }
-                       if (Addon::isEnabled('ijpost')) {
-                               $nodeinfo['services']['outbound'][] = 'insanejournal';
-                       }
-                       if (Addon::isEnabled('libertree')) {
-                               $nodeinfo['services']['outbound'][] = 'libertree';
-                       }
-                       if (Addon::isEnabled('buffer')) {
-                               $nodeinfo['services']['outbound'][] = 'linkedin';
-                       }
-                       if (Addon::isEnabled('ljpost')) {
-                               $nodeinfo['services']['outbound'][] = 'livejournal';
-                       }
-                       if (Addon::isEnabled('buffer')) {
-                               $nodeinfo['services']['outbound'][] = 'pinterest';
-                       }
-                       if (Addon::isEnabled('posterous')) {
-                               $nodeinfo['services']['outbound'][] = 'posterous';
-                       }
-                       if (Addon::isEnabled('pumpio')) {
-                               $nodeinfo['services']['inbound'][] = 'pumpio';
-                               $nodeinfo['services']['outbound'][] = 'pumpio';
-                       }
-
-                       if ($smtp) {
-                               $nodeinfo['services']['outbound'][] = 'smtp';
-                       }
-                       if (Addon::isEnabled('tumblr')) {
-                               $nodeinfo['services']['outbound'][] = 'tumblr';
-                       }
-                       if (Addon::isEnabled('twitter') || Addon::isEnabled('buffer')) {
-                               $nodeinfo['services']['outbound'][] = 'twitter';
-                       }
-                       if (Addon::isEnabled('wppost')) {
-                               $nodeinfo['services']['outbound'][] = 'wordpress';
-                       }
-                       $nodeinfo['metadata']['protocols'] = $nodeinfo['protocols'];
-                       $nodeinfo['metadata']['protocols']['outbound'][] = 'atom1.0';
-                       $nodeinfo['metadata']['protocols']['inbound'][] = 'atom1.0';
-                       $nodeinfo['metadata']['protocols']['inbound'][] = 'rss2.0';
-
-                       $nodeinfo['metadata']['services'] = $nodeinfo['services'];
-
-                       if (Addon::isEnabled('twitter')) {
-                               $nodeinfo['metadata']['services']['inbound'][] = 'twitter';
-                       }
-
-                       $nodeinfo['metadata']['explicitContent'] = $config->get('system', 'explicit_content', false) == true;
-               }
-
-               header('Content-type: application/json; charset=utf-8');
-               echo json_encode($nodeinfo, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
-               exit;
-       }
-}
index 558b274919ce33bad609074dec5aac569ceca9e0..f34af3a08044af329836ff00b937bf93b92a8c4e 100644 (file)
@@ -5,11 +5,10 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
-use Friendica\Protocol\ActivityPub;
 use Friendica\Core\System;
-use Friendica\Model\Item;
 use Friendica\Database\DBA;
-use Friendica\Util\HTTPSignature;
+use Friendica\Model\Item;
+use Friendica\Protocol\ActivityPub;
 
 /**
  * ActivityPub Objects
@@ -32,9 +31,11 @@ class Objects extends BaseModule
                // $requester = HTTPSignature::getSigner('', $_SERVER);
 
                // At first we try the original post with that guid
+               // @TODO: Replace with parameter from router
                $item = Item::selectFirst(['id'], ['guid' => $a->argv[1], 'origin' => true, 'private' => false]);
                if (!DBA::isResult($item)) {
                        // If no original post could be found, it could possibly be a forum post, there we remove the "origin" field.
+                       // @TODO: Replace with parameter from router
                        $item = Item::selectFirst(['id', 'author-link'], ['guid' => $a->argv[1], 'private' => false]);
                        if (!DBA::isResult($item) || !strstr($item['author-link'], System::baseUrl())) {
                                System::httpExit(404);
index d5ff62dac9c5a91aca8ef7e2d0cb5a4514e41a34..0107782122b5c0c877025d09805eca4a22794315 100644 (file)
@@ -35,6 +35,7 @@ class Oembed extends BaseModule
                        exit();
                }
 
+               // @TODO: Replace with parameter from router
                if ($a->argc == 2) {
                        echo '<html><body>';
                        $url = Strings::base64UrlDecode($a->argv[1]);
index 41e10757f1231ae90a10138fe49cc09cc4ef722b..27dcd5c1f44b905b51423e6f3cccc3bfe8e43e6b 100644 (file)
@@ -5,10 +5,9 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
-use Friendica\Protocol\ActivityPub;
 use Friendica\Core\System;
 use Friendica\Model\User;
-use Friendica\Util\HTTPSignature;
+use Friendica\Protocol\ActivityPub;
 
 /**
  * ActivityPub Outbox
@@ -19,6 +18,7 @@ class Outbox extends BaseModule
        {
                $a = self::getApp();
 
+               // @TODO: Replace with parameter from router
                if (empty($a->argv[1])) {
                        System::httpExit(404);
                }
index ed5609640c34eb4d9f9da17e15ffd0c2355fff8e..9165af8bedbbaad213c98833563887df25849d64 100644 (file)
@@ -25,6 +25,7 @@ class Photo extends BaseModule
        public static function init()
        {
                $a = self::getApp();
+               // @TODO: Replace with parameter from router
                if ($a->argc <= 1 || $a->argc > 4) {
                        System::httpExit(400);
                }
@@ -47,6 +48,7 @@ class Photo extends BaseModule
 
                $customsize = 0;
                $photo = false;
+               // @TODO: Replace with parameter from router
                switch($a->argc) {
                        case 4:
                                $customsize = intval($a->argv[2]);
index 55150a9649d8d1d741008945d041c95e419e5bfe..c3297d261a295ec9a8abc368f983aa1833f30d71 100644 (file)
-<?php\r
-\r
-namespace Friendica\Module;\r
-\r
-use Friendica\BaseModule;\r
-use Friendica\Content\Nav;\r
-use Friendica\Content\Pager;\r
-use Friendica\Content\Widget;\r
-use Friendica\Core\ACL;\r
-use Friendica\Core\Config;\r
-use Friendica\Core\Hook;\r
-use Friendica\Core\L10n;\r
-use Friendica\Core\PConfig;\r
-use Friendica\Core\System;\r
-use Friendica\Database\DBA;\r
-use Friendica\Model\Contact as ContactModel;\r
-use Friendica\Model\Group;\r
-use Friendica\Model\Item;\r
-use Friendica\Model\Profile AS ProfileModel;\r
-use Friendica\Model\User;\r
-use Friendica\Protocol\ActivityPub;\r
-use Friendica\Protocol\DFRN;\r
-use Friendica\Util\DateTimeFormat;\r
-use Friendica\Util\Security;\r
-use Friendica\Util\Strings;\r
-use Friendica\Util\XML;\r
-\r
-require_once 'boot.php';\r
-\r
-class Profile extends BaseModule\r
-{\r
-       public static $which = '';\r
-       public static $profile = 0;\r
-\r
-       public static function init()\r
-       {\r
-               $a = self::getApp();\r
-\r
-               if ($a->argc < 2) {\r
-                       System::httpExit(400);\r
-               }\r
-\r
-               self::$which = filter_var($a->argv[1], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);\r
-\r
-               if (local_user() && $a->argc > 2 && $a->argv[2] === 'view') {\r
-                       self::$which = $a->user['nickname'];\r
-                       self::$profile = filter_var($a->argv[1], FILTER_SANITIZE_NUMBER_INT);\r
-               } else {\r
-                       DFRN::autoRedir($a, self::$which);\r
-               }\r
-       }\r
-\r
-       public static function rawContent()\r
-       {\r
-               if (ActivityPub::isRequest()) {\r
-                       $user = DBA::selectFirst('user', ['uid'], ['nickname' => self::$which]);\r
-                       $data = [];\r
-                       if (DBA::isResult($user)) {\r
-                               $data = ActivityPub\Transmitter::getProfile($user['uid']);\r
-                       }\r
-\r
-                       if (!empty($data)) {\r
-                               System::jsonExit($data, 'application/activity+json');\r
-                       } elseif (DBA::exists('userd', ['username' => self::$which])) {\r
-                               // Known deleted user\r
-                               $data = ActivityPub\Transmitter::getDeletedUser(self::$which);\r
-\r
-                               System::jsonError(410, $data);\r
-                       } else {\r
-                               // Any other case (unknown, blocked, unverified, expired, no profile, no self contact)\r
-                               System::jsonError(404, $data);\r
-                       }\r
-               }\r
-       }\r
-\r
-       public static function content($update = 0)\r
-       {\r
-               $a = self::getApp();\r
-\r
-               if (!$update) {\r
-                       ProfileModel::load($a, self::$which, self::$profile);\r
-\r
-                       $blocked   = !local_user() && !remote_user() && Config::get('system', 'block_public');\r
-                       $userblock = !local_user() && !remote_user() && $a->profile['hidewall'];\r
-\r
-                       if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {\r
-                               $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';\r
-                       }\r
-\r
-                       if (!empty($a->profile['openidserver'])) {\r
-                               $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\n";\r
-                       }\r
-\r
-                       if (!empty($a->profile['openid'])) {\r
-                               $delegate = strstr($a->profile['openid'], '://') ? $a->profile['openid'] : 'https://' . $a->profile['openid'];\r
-                               $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";\r
-                       }\r
-\r
-                       // site block\r
-                       if (!$blocked && !$userblock) {\r
-                               $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], defaults($a->profile, 'pub_keywords', ''));\r
-                               if (strlen($keywords)) {\r
-                                       $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";\r
-                               }\r
-                       }\r
-\r
-                       $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";\r
-                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/dfrn_poll/' . self::$which . '" title="DFRN: ' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";\r
-                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/" title="' . L10n::t('%s\'s posts', $a->profile['username']) . '"/>' . "\n";\r
-                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/comments" title="' . L10n::t('%s\'s comments', $a->profile['username']) . '"/>' . "\n";\r
-                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/activity" title="' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";\r
-                       $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''));\r
-                       $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . System::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\n";\r
-                       header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);\r
-\r
-                       $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];\r
-                       foreach ($dfrn_pages as $dfrn) {\r
-                               $a->page['htmlhead'] .= '<link rel="dfrn-' . $dfrn . '" href="' . System::baseUrl() . '/dfrn_' . $dfrn . '/' . self::$which . '" />' . "\n";\r
-                       }\r
-                       $a->page['htmlhead'] .= '<link rel="dfrn-poco" href="' . System::baseUrl() . '/poco/' . self::$which . '" />' . "\n";\r
-               }\r
-\r
-               $category = $datequery = $datequery2 = '';\r
-\r
-               if ($a->argc > 2) {\r
-                       for ($x = 2; $x < $a->argc; $x ++) {\r
-                               if (is_a_date_arg($a->argv[$x])) {\r
-                                       if ($datequery) {\r
-                                               $datequery2 = Strings::escapeHtml($a->argv[$x]);\r
-                                       } else {\r
-                                               $datequery = Strings::escapeHtml($a->argv[$x]);\r
-                                       }\r
-                               } else {\r
-                                       $category = $a->argv[$x];\r
-                               }\r
-                       }\r
-               }\r
-\r
-               if (empty($category)) {\r
-                       $category = defaults($_GET, 'category', '');\r
-               }\r
-\r
-               $hashtags = defaults($_GET, 'tag', '');\r
-\r
-               if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {\r
-                       return Login::form();\r
-               }\r
-\r
-               $groups = [];\r
-               $remote_cid = null;\r
-\r
-               $o = '';\r
-\r
-               if ($update) {\r
-                       // Ensure we've got a profile owner if updating.\r
-                       $a->profile['profile_uid'] = $update;\r
-               } elseif ($a->profile['profile_uid'] == local_user()) {\r
-                       Nav::setSelected('home');\r
-               }\r
-\r
-               $remote_contact = ContactModel::isFollower(remote_user(), $a->profile['profile_uid']);\r
-               $is_owner = local_user() == $a->profile['profile_uid'];\r
-               $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . remote_user();\r
-\r
-               if ($remote_contact) {\r
-                       $cdata = ContactModel::getPublicAndUserContacID(remote_user(), $a->profile['profile_uid']);\r
-                       if (!empty($cdata['user'])) {\r
-                               $groups = Group::getIdsByContactId($cdata['user']);\r
-                               $remote_cid = $cdata['user'];\r
-                       }\r
-               }\r
-\r
-               if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {\r
-                       notice(L10n::t('Access to this profile has been restricted.') . EOL);\r
-                       return '';\r
-               }\r
-\r
-               if (!$update) {\r
-                       $tab = false;\r
-                       if (!empty($_GET['tab'])) {\r
-                               $tab = Strings::escapeTags(trim($_GET['tab']));\r
-                       }\r
-\r
-                       $o .= ProfileModel::getTabs($a, $is_owner, $a->profile['nickname']);\r
-\r
-                       if ($tab === 'profile') {\r
-                               $o .= ProfileModel::getAdvanced($a);\r
-                               Hook::callAll('profile_advanced', $o);\r
-                               return $o;\r
-                       }\r
-\r
-                       $o .= Widget::commonFriendsVisitor($a->profile['profile_uid']);\r
-\r
-                       $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;\r
-                       $commvisitor = $commpage && $remote_contact;\r
-\r
-                       $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);\r
-                       $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : ''));\r
-                       $a->page['aside'] .= Widget::tagCloud();\r
-\r
-                       if (Security::canWriteToUserWall($a->profile['profile_uid'])) {\r
-                               $x = [\r
-                                       'is_owner' => $is_owner,\r
-                                       'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],\r
-                                       'default_location' => $is_owner ? $a->user['default-location'] : '',\r
-                                       'nickname' => $a->profile['nickname'],\r
-                                       'lockstate' => is_array($a->user)\r
-                                       && (strlen($a->user['allow_cid'])\r
-                                               || strlen($a->user['allow_gid'])\r
-                                               || strlen($a->user['deny_cid'])\r
-                                               || strlen($a->user['deny_gid'])\r
-                                       ) ? 'lock' : 'unlock',\r
-                                       'acl' => $is_owner ? ACL::getFullSelectorHTML($a->user, true) : '',\r
-                                       'bang' => '',\r
-                                       'visitor' => $is_owner || $commvisitor ? 'block' : 'none',\r
-                                       'profile_uid' => $a->profile['profile_uid'],\r
-                               ];\r
-\r
-                               $o .= status_editor($a, $x);\r
-                       }\r
-               }\r
-\r
-               // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups\r
-               $sql_extra = Item::getPermissionsSQLByUserId($a->profile['profile_uid'], $remote_contact, $groups, $remote_cid);\r
-               $sql_extra2 = '';\r
-\r
-               if ($update) {\r
-                       $last_updated = (defaults($_SESSION['last_updated'], $last_updated_key, 0));\r
-\r
-                       // If the page user is the owner of the page we should query for unseen\r
-                       // items. Otherwise use a timestamp of the last succesful update request.\r
-                       if ($is_owner || !$last_updated) {\r
-                               $sql_extra4 = " AND `item`.`unseen`";\r
-                       } else {\r
-                               $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);\r
-                               $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";\r
-                       }\r
-\r
-                       $items_stmt = DBA::p(\r
-                               "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`\r
-                               FROM `item`\r
-                               INNER JOIN `contact`\r
-                               ON `contact`.`id` = `item`.`contact-id`\r
-                                       AND NOT `contact`.`blocked`\r
-                                       AND NOT `contact`.`pending`\r
-                               WHERE `item`.`uid` = ?\r
-                                       AND `item`.`visible`\r
-                                       AND     (NOT `item`.`deleted` OR `item`.`gravity` = ?)\r
-                                       AND NOT `item`.`moderated`\r
-                                       AND `item`.`wall`\r
-                                       $sql_extra4\r
-                                       $sql_extra\r
-                               ORDER BY `item`.`created` DESC",\r
-                               $a->profile['profile_uid'],\r
-                               GRAVITY_ACTIVITY\r
-                       );\r
-\r
-                       if (!DBA::isResult($items_stmt)) {\r
-                               return '';\r
-                       }\r
-\r
-                       $pager = new Pager($a->query_string);\r
-               } else {\r
-                       $sql_post_table = "";\r
-\r
-                       if (!empty($category)) {\r
-                               $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",\r
-                                       DBA::escape(Strings::protectSprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));\r
-                       }\r
-\r
-                       if (!empty($hashtags)) {\r
-                               $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",\r
-                                       DBA::escape(Strings::protectSprintf($hashtags)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval($a->profile['profile_uid']));\r
-                       }\r
-\r
-                       if (!empty($datequery)) {\r
-                               $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));\r
-                       }\r
-                       if (!empty($datequery2)) {\r
-                               $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));\r
-                       }\r
-\r
-                       // Does the profile page belong to a forum?\r
-                       // If not then we can improve the performance with an additional condition\r
-                       $condition = ['uid' => $a->profile['profile_uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];\r
-                       if (!DBA::exists('user', $condition)) {\r
-                               $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));\r
-                       } else {\r
-                               $sql_extra3 = "";\r
-                       }\r
-\r
-                       //  check if we serve a mobile device and get the user settings\r
-                       //  accordingly\r
-                       if ($a->is_mobile) {\r
-                               $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 10);\r
-                       } else {\r
-                               $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 20);\r
-                       }\r
-\r
-                       //  now that we have the user settings, see if the theme forces\r
-                       //  a maximum item number which is lower then the user choice\r
-                       if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {\r
-                               $itemspage_network = $a->force_max_items;\r
-                       }\r
-\r
-                       $pager = new Pager($a->query_string, $itemspage_network);\r
-\r
-                       $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());\r
-\r
-                       $items_stmt = DBA::p(\r
-                               "SELECT `item`.`uri`\r
-                               FROM `thread`\r
-                               STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`\r
-                               $sql_post_table\r
-                               STRAIGHT_JOIN `contact`\r
-                               ON `contact`.`id` = `thread`.`contact-id`\r
-                                       AND NOT `contact`.`blocked`\r
-                                       AND NOT `contact`.`pending`\r
-                               WHERE `thread`.`uid` = ?\r
-                                       AND `thread`.`visible`\r
-                                       AND NOT `thread`.`deleted`\r
-                                       AND NOT `thread`.`moderated`\r
-                                       AND `thread`.`wall`\r
-                                       $sql_extra3\r
-                                       $sql_extra\r
-                                       $sql_extra2\r
-                               ORDER BY `thread`.`created` DESC\r
-                               $pager_sql",\r
-                               $a->profile['profile_uid']\r
-                       );\r
-               }\r
-\r
-               // Set a time stamp for this page. We will make use of it when we\r
-               // search for new items (update routine)\r
-               $_SESSION['last_updated'][$last_updated_key] = time();\r
-\r
-               if ($is_owner && !$update && !Config::get('theme', 'hide_eventlist')) {\r
-                       $o .= ProfileModel::getBirthdays();\r
-                       $o .= ProfileModel::getEventsReminderHTML();\r
-               }\r
-\r
-               if ($is_owner) {\r
-                       $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);\r
-                       if ($unseen) {\r
-                               Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);\r
-                       }\r
-               }\r
-\r
-               $items = DBA::toArray($items_stmt);\r
-\r
-               $o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);\r
-\r
-               if (!$update) {\r
-                       $o .= $pager->renderMinimal(count($items));\r
-               }\r
-\r
-               return $o;\r
-       }\r
-}\r
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\Nav;
+use Friendica\Content\Pager;
+use Friendica\Content\Widget;
+use Friendica\Core\ACL;
+use Friendica\Core\Config;
+use Friendica\Core\Hook;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
+use Friendica\Core\System;
+use Friendica\Database\DBA;
+use Friendica\Model\Contact as ContactModel;
+use Friendica\Model\Group;
+use Friendica\Model\Item;
+use Friendica\Model\Profile as ProfileModel;
+use Friendica\Model\User;
+use Friendica\Protocol\ActivityPub;
+use Friendica\Protocol\DFRN;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Security;
+use Friendica\Util\Strings;
+use Friendica\Util\XML;
+
+require_once 'boot.php';
+
+class Profile extends BaseModule
+{
+       public static $which = '';
+       public static $profile = 0;
+
+       public static function init()
+       {
+               $a = self::getApp();
+
+               // @TODO: Replace with parameter from router
+               if ($a->argc < 2) {
+                       System::httpExit(400);
+               }
+
+               self::$which = filter_var($a->argv[1], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
+
+               // @TODO: Replace with parameter from router
+               if (local_user() && $a->argc > 2 && $a->argv[2] === 'view') {
+                       self::$which = $a->user['nickname'];
+                       self::$profile = filter_var($a->argv[1], FILTER_SANITIZE_NUMBER_INT);
+               } else {
+                       DFRN::autoRedir($a, self::$which);
+               }
+       }
+
+       public static function rawContent()
+       {
+               if (ActivityPub::isRequest()) {
+                       $user = DBA::selectFirst('user', ['uid'], ['nickname' => self::$which]);
+                       $data = [];
+                       if (DBA::isResult($user)) {
+                               $data = ActivityPub\Transmitter::getProfile($user['uid']);
+                       }
+
+                       if (!empty($data)) {
+                               System::jsonExit($data, 'application/activity+json');
+                       } elseif (DBA::exists('userd', ['username' => self::$which])) {
+                               // Known deleted user
+                               $data = ActivityPub\Transmitter::getDeletedUser(self::$which);
+
+                               System::jsonError(410, $data);
+                       } else {
+                               // Any other case (unknown, blocked, unverified, expired, no profile, no self contact)
+                               System::jsonError(404, $data);
+                       }
+               }
+       }
+
+       public static function content($update = 0)
+       {
+               $a = self::getApp();
+
+               if (!$update) {
+                       ProfileModel::load($a, self::$which, self::$profile);
+
+                       $blocked   = !local_user() && !remote_user() && Config::get('system', 'block_public');
+                       $userblock = !local_user() && !remote_user() && $a->profile['hidewall'];
+
+                       if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
+                               $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
+                       }
+
+                       if (!empty($a->profile['openidserver'])) {
+                               $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\n";
+                       }
+
+                       if (!empty($a->profile['openid'])) {
+                               $delegate = strstr($a->profile['openid'], '://') ? $a->profile['openid'] : 'https://' . $a->profile['openid'];
+                               $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";
+                       }
+
+                       // site block
+                       if (!$blocked && !$userblock) {
+                               $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], defaults($a->profile, 'pub_keywords', ''));
+                               if (strlen($keywords)) {
+                                       $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";
+                               }
+                       }
+
+                       $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";
+                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/dfrn_poll/' . self::$which . '" title="DFRN: ' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
+                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/" title="' . L10n::t('%s\'s posts', $a->profile['username']) . '"/>' . "\n";
+                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/comments" title="' . L10n::t('%s\'s comments', $a->profile['username']) . '"/>' . "\n";
+                       $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/activity" title="' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
+                       $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''));
+                       $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . System::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\n";
+                       header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
+
+                       $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
+                       foreach ($dfrn_pages as $dfrn) {
+                               $a->page['htmlhead'] .= '<link rel="dfrn-' . $dfrn . '" href="' . System::baseUrl() . '/dfrn_' . $dfrn . '/' . self::$which . '" />' . "\n";
+                       }
+                       $a->page['htmlhead'] .= '<link rel="dfrn-poco" href="' . System::baseUrl() . '/poco/' . self::$which . '" />' . "\n";
+               }
+
+               $category = $datequery = $datequery2 = '';
+
+               if ($a->argc > 2) {
+                       for ($x = 2; $x < $a->argc; $x ++) {
+                               if (is_a_date_arg($a->argv[$x])) {
+                                       if ($datequery) {
+                                               $datequery2 = Strings::escapeHtml($a->argv[$x]);
+                                       } else {
+                                               $datequery = Strings::escapeHtml($a->argv[$x]);
+                                       }
+                               } else {
+                                       $category = $a->argv[$x];
+                               }
+                       }
+               }
+
+               if (empty($category)) {
+                       $category = defaults($_GET, 'category', '');
+               }
+
+               $hashtags = defaults($_GET, 'tag', '');
+
+               if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
+                       return Login::form();
+               }
+
+               $groups = [];
+               $remote_cid = null;
+
+               $o = '';
+
+               if ($update) {
+                       // Ensure we've got a profile owner if updating.
+                       $a->profile['profile_uid'] = $update;
+               } elseif ($a->profile['profile_uid'] == local_user()) {
+                       Nav::setSelected('home');
+               }
+
+               $remote_contact = ContactModel::isFollower(remote_user(), $a->profile['profile_uid']);
+               $is_owner = local_user() == $a->profile['profile_uid'];
+               $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . remote_user();
+
+               if ($remote_contact) {
+                       $cdata = ContactModel::getPublicAndUserContacID(remote_user(), $a->profile['profile_uid']);
+                       if (!empty($cdata['user'])) {
+                               $groups = Group::getIdsByContactId($cdata['user']);
+                               $remote_cid = $cdata['user'];
+                       }
+               }
+
+               if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
+                       notice(L10n::t('Access to this profile has been restricted.') . EOL);
+                       return '';
+               }
+
+               if (!$update) {
+                       $tab = false;
+                       if (!empty($_GET['tab'])) {
+                               $tab = Strings::escapeTags(trim($_GET['tab']));
+                       }
+
+                       $o .= ProfileModel::getTabs($a, $is_owner, $a->profile['nickname']);
+
+                       if ($tab === 'profile') {
+                               $o .= ProfileModel::getAdvanced($a);
+                               Hook::callAll('profile_advanced', $o);
+                               return $o;
+                       }
+
+                       $o .= Widget::commonFriendsVisitor($a->profile['profile_uid']);
+
+                       $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
+                       $commvisitor = $commpage && $remote_contact;
+
+                       $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
+                       $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : ''));
+                       $a->page['aside'] .= Widget::tagCloud();
+
+                       if (Security::canWriteToUserWall($a->profile['profile_uid'])) {
+                               $x = [
+                                       'is_owner' => $is_owner,
+                                       'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
+                                       'default_location' => $is_owner ? $a->user['default-location'] : '',
+                                       'nickname' => $a->profile['nickname'],
+                                       'lockstate' => is_array($a->user)
+                                       && (strlen($a->user['allow_cid'])
+                                               || strlen($a->user['allow_gid'])
+                                               || strlen($a->user['deny_cid'])
+                                               || strlen($a->user['deny_gid'])
+                                       ) ? 'lock' : 'unlock',
+                                       'acl' => $is_owner ? ACL::getFullSelectorHTML($a->user, true) : '',
+                                       'bang' => '',
+                                       'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
+                                       'profile_uid' => $a->profile['profile_uid'],
+                               ];
+
+                               $o .= status_editor($a, $x);
+                       }
+               }
+
+               // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
+               $sql_extra = Item::getPermissionsSQLByUserId($a->profile['profile_uid'], $remote_contact, $groups, $remote_cid);
+               $sql_extra2 = '';
+
+               if ($update) {
+                       $last_updated = (defaults($_SESSION['last_updated'], $last_updated_key, 0));
+
+                       // If the page user is the owner of the page we should query for unseen
+                       // items. Otherwise use a timestamp of the last succesful update request.
+                       if ($is_owner || !$last_updated) {
+                               $sql_extra4 = " AND `item`.`unseen`";
+                       } else {
+                               $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
+                               $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
+                       }
+
+                       $items_stmt = DBA::p(
+                               "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`
+                               FROM `item`
+                               INNER JOIN `contact`
+                               ON `contact`.`id` = `item`.`contact-id`
+                                       AND NOT `contact`.`blocked`
+                                       AND NOT `contact`.`pending`
+                               WHERE `item`.`uid` = ?
+                                       AND `item`.`visible`
+                                       AND     (NOT `item`.`deleted` OR `item`.`gravity` = ?)
+                                       AND NOT `item`.`moderated`
+                                       AND `item`.`wall`
+                                       $sql_extra4
+                                       $sql_extra
+                               ORDER BY `item`.`created` DESC",
+                               $a->profile['profile_uid'],
+                               GRAVITY_ACTIVITY
+                       );
+
+                       if (!DBA::isResult($items_stmt)) {
+                               return '';
+                       }
+
+                       $pager = new Pager($a->query_string);
+               } else {
+                       $sql_post_table = "";
+
+                       if (!empty($category)) {
+                               $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
+                                       DBA::escape(Strings::protectSprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
+                       }
+
+                       if (!empty($hashtags)) {
+                               $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
+                                       DBA::escape(Strings::protectSprintf($hashtags)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval($a->profile['profile_uid']));
+                       }
+
+                       if (!empty($datequery)) {
+                               $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
+                       }
+                       if (!empty($datequery2)) {
+                               $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
+                       }
+
+                       // Does the profile page belong to a forum?
+                       // If not then we can improve the performance with an additional condition
+                       $condition = ['uid' => $a->profile['profile_uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
+                       if (!DBA::exists('user', $condition)) {
+                               $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));
+                       } else {
+                               $sql_extra3 = "";
+                       }
+
+                       //  check if we serve a mobile device and get the user settings
+                       //  accordingly
+                       if ($a->is_mobile) {
+                               $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 10);
+                       } else {
+                               $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 20);
+                       }
+
+                       //  now that we have the user settings, see if the theme forces
+                       //  a maximum item number which is lower then the user choice
+                       if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
+                               $itemspage_network = $a->force_max_items;
+                       }
+
+                       $pager = new Pager($a->query_string, $itemspage_network);
+
+                       $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
+
+                       $items_stmt = DBA::p(
+                               "SELECT `item`.`uri`
+                               FROM `thread`
+                               STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
+                               $sql_post_table
+                               STRAIGHT_JOIN `contact`
+                               ON `contact`.`id` = `thread`.`contact-id`
+                                       AND NOT `contact`.`blocked`
+                                       AND NOT `contact`.`pending`
+                               WHERE `thread`.`uid` = ?
+                                       AND `thread`.`visible`
+                                       AND NOT `thread`.`deleted`
+                                       AND NOT `thread`.`moderated`
+                                       AND `thread`.`wall`
+                                       $sql_extra3
+                                       $sql_extra
+                                       $sql_extra2
+                               ORDER BY `thread`.`created` DESC
+                               $pager_sql",
+                               $a->profile['profile_uid']
+                       );
+               }
+
+               // Set a time stamp for this page. We will make use of it when we
+               // search for new items (update routine)
+               $_SESSION['last_updated'][$last_updated_key] = time();
+
+               if ($is_owner && !$update && !Config::get('theme', 'hide_eventlist')) {
+                       $o .= ProfileModel::getBirthdays();
+                       $o .= ProfileModel::getEventsReminderHTML();
+               }
+
+               if ($is_owner) {
+                       $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
+                       if ($unseen) {
+                               Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
+                       }
+               }
+
+               $items = DBA::toArray($items_stmt);
+
+               $o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);
+
+               if (!$update) {
+                       $o .= $pager->renderMinimal(count($items));
+               }
+
+               return $o;
+       }
+}
index 54870abe055469e20e715b269281644d539b5de3..387667a1a5a20c58e9cc6d246b3e501a7af620e7 100644 (file)
@@ -12,7 +12,6 @@ use Friendica\Model\Photo;
 use Friendica\Object\Image;
 use Friendica\Util\HTTPSignature;
 use Friendica\Util\Proxy as ProxyUtils;
-use Friendica\Core\Logger;
 
 /**
  * @brief Module Proxy
@@ -159,6 +158,7 @@ class Proxy extends BaseModule
                $sizetype = '';
 
                // Look for filename in the arguments
+               // @TODO: Replace with parameter from router
                if (($a->argc > 1) && !isset($_REQUEST['url'])) {
                        if (isset($a->argv[3])) {
                                $url = $a->argv[3];
@@ -169,6 +169,7 @@ class Proxy extends BaseModule
                        }
 
                        /// @TODO: Why? And what about $url in this case?
+                       /// @TODO: Replace with parameter from router
                        if (isset($a->argv[3]) && ($a->argv[3] == 'thumb')) {
                                $size = 200;
                        }
index 6744a0a5f34040ca1a2e02b7968dfdc4353d701f..202cf948e001289938175fea1eaa8c4cad946a8d 100644 (file)
@@ -19,7 +19,7 @@ use Friendica\Util\Strings;
 /**
  * @author Hypolite Petovan <hypolite@mrpetovan.com>
  */
-abstract class Register extends BaseModule
+class Register extends BaseModule
 {
        const CLOSED  = 0;
        const APPROVE = 1;
diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php
new file mode 100644 (file)
index 0000000..566ace3
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Addon;
+use Friendica\Core\System;
+
+class Statistics extends BaseModule
+{
+       public static function init()
+       {
+               $config = self::getApp()->getConfig();
+
+               if (!$config->get("system", "nodeinfo")) {
+                       System::httpExit(404);
+               }
+       }
+
+       public static function rawContent()
+       {
+               $config = self::getApp()->getConfig();
+               $logger = self::getApp()->getLogger();
+
+               $registration_open =
+                       intval($config->get('config', 'register_policy')) !== Register::CLOSED
+                       && !$config->get('config', 'invitation_only');
+
+               /// @todo mark the "service" addons and load them dynamically here
+               $services = [
+                       'appnet'      => Addon::isEnabled('appnet'),
+                       'buffer'      => Addon::isEnabled('buffer'),
+                       'dreamwidth'  => Addon::isEnabled('dreamwidth'),
+                       'gnusocial'   => Addon::isEnabled('gnusocial'),
+                       'libertree'   => Addon::isEnabled('libertree'),
+                       'livejournal' => Addon::isEnabled('livejournal'),
+                       'pumpio'      => Addon::isEnabled('pumpio'),
+                       'twitter'     => Addon::isEnabled('twitter'),
+                       'tumblr'      => Addon::isEnabled('tumblr'),
+                       'wordpress'   => Addon::isEnabled('wordpress'),
+               ];
+
+               $statistics = array_merge([
+                       'name'                  => $config->get('config', 'sitename'),
+                       'network'               => FRIENDICA_PLATFORM,
+                       'version'               => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
+                       'registrations_open'    => $registration_open,
+                       'total_users'           => $config->get('nodeinfo', 'total_users'),
+                       'active_users_halfyear' => $config->get('nodeinfo', 'active_users_halfyear'),
+                       'active_users_monthly'  => $config->get('nodeinfo', 'active_users_monthly'),
+                       'local_posts'           => $config->get('nodeinfo', 'local_posts'),
+                       'services'              => $services,
+               ], $services);
+
+               header("Content-Type: application/json");
+               echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+               $logger->debug("statistics.", ['statistics' => $statistics]);
+               exit();
+       }
+}
diff --git a/src/Module/Statistics_json.php b/src/Module/Statistics_json.php
deleted file mode 100644 (file)
index aca204b..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Core\Addon;
-use Friendica\Core\System;
-
-class Statistics_json extends BaseModule
-{
-       public static function init()
-       {
-               $config = self::getApp()->getConfig();
-
-               if (!$config->get("system", "nodeinfo")) {
-                       System::httpExit(404);
-               }
-       }
-
-       public static function rawContent()
-       {
-               $config = self::getApp()->getConfig();
-               $logger = self::getApp()->getLogger();
-
-               $registration_open =
-                       intval($config->get('config', 'register_policy')) !== Register::CLOSED
-                       && !$config->get('config', 'invitation_only');
-
-               /// @todo mark the "service" addons and load them dynamically here
-               $services = [
-                       'appnet'      => Addon::isEnabled('appnet'),
-                       'buffer'      => Addon::isEnabled('buffer'),
-                       'dreamwidth'  => Addon::isEnabled('dreamwidth'),
-                       'gnusocial'   => Addon::isEnabled('gnusocial'),
-                       'libertree'   => Addon::isEnabled('libertree'),
-                       'livejournal' => Addon::isEnabled('livejournal'),
-                       'pumpio'      => Addon::isEnabled('pumpio'),
-                       'twitter'     => Addon::isEnabled('twitter'),
-                       'tumblr'      => Addon::isEnabled('tumblr'),
-                       'wordpress'   => Addon::isEnabled('wordpress'),
-               ];
-
-               $statistics = array_merge([
-                       'name'                  => $config->get('config', 'sitename'),
-                       'network'               => FRIENDICA_PLATFORM,
-                       'version'               => FRIENDICA_VERSION . '-' . DB_UPDATE_VERSION,
-                       'registrations_open'    => $registration_open,
-                       'total_users'           => $config->get('nodeinfo', 'total_users'),
-                       'active_users_halfyear' => $config->get('nodeinfo', 'active_users_halfyear'),
-                       'active_users_monthly'  => $config->get('nodeinfo', 'active_users_monthly'),
-                       'local_posts'           => $config->get('nodeinfo', 'local_posts'),
-                       'services'              => $services,
-               ], $services);
-
-               header("Content-Type: application/json");
-               echo json_encode($statistics, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
-               $logger->debug("statistics.", ['statistics' => $statistics]);
-               exit();
-       }
-}
diff --git a/src/Module/WebFinger.php b/src/Module/WebFinger.php
new file mode 100644 (file)
index 0000000..3afcecb
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Network\Probe;
+
+/**
+ * Web based module to perform webfinger probing
+ */
+class WebFinger extends BaseModule
+{
+       public static function init()
+       {
+               if (!local_user()) {
+                       System::httpExit(
+                               403,
+                               [
+                                       'title'       => L10n::t('Public access denied.'),
+                                       'description' => L10n::t('Only logged in users are permitted to perform a probing.'),
+                               ],
+                       );
+                       exit();
+               }
+       }
+
+       public static function content()
+       {
+               $app = self::getApp();
+
+               $addr = defaults($_GET, 'addr', '');
+               $res = '';
+
+               if (!empty($addr)) {
+                       $res = Probe::lrdd($addr);
+                       $res = print_r($res, true);
+               }
+
+               $tpl = Renderer::getMarkupTemplate('webfinger.tpl');
+               return Renderer::replaceMacros($tpl, [
+                       '$addr' => $addr,
+                       '$res'  => $res,
+               ]);
+       }
+}
diff --git a/src/Module/WellKnown/HostMeta.php b/src/Module/WellKnown/HostMeta.php
new file mode 100644 (file)
index 0000000..fd04467
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+namespace Friendica\Module\WellKnown;
+
+use Friendica\BaseModule;
+use Friendica\Core\Renderer;
+use Friendica\Protocol\Salmon;
+use Friendica\Util\Crypto;
+
+/**
+ * Prints the metadata for describing this host
+ * @see https://tools.ietf.org/html/rfc6415
+ */
+class HostMeta extends BaseModule
+{
+       public static function rawContent()
+       {
+               $app = self::getApp();
+               $config = $app->getConfig();
+
+               header('Content-type: text/xml');
+
+               if (!$config->get('system', 'site_pubkey', false)) {
+                       $res = Crypto::newKeypair(1024);
+
+                       $config->set('system', 'site_prvkey', $res['prvkey']);
+                       $config->set('system', 'site_pubkey', $res['pubkey']);
+               }
+
+               $tpl = Renderer::getMarkupTemplate('xrd_host.tpl');
+               echo Renderer::replaceMacros($tpl, [
+                       '$zhost'  => $app->getHostName(),
+                       '$zroot'  => $app->getBaseURL(),
+                       '$domain' => $app->getBaseURL(),
+                       '$bigkey' => Salmon::salmonKey($config->get('system', 'site_pubkey'))
+               ]);
+
+               exit();
+       }
+}
diff --git a/src/Module/WellKnown/XSocialRelay.php b/src/Module/WellKnown/XSocialRelay.php
new file mode 100644 (file)
index 0000000..a1bbeb7
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+namespace Friendica\Module\WellKnown;
+
+use Friendica\BaseModule;
+use Friendica\Model\Search;
+
+/**
+ * Node subscription preferences for social realy systems
+ * @see https://git.feneas.org/jaywink/social-relay/blob/master/docs/relays.md
+ */
+class XSocialRelay extends BaseModule
+{
+       public static function rawContent()
+       {
+               $app = self::getApp();
+               $config = $app->getConfig();
+
+               $subscribe = $config->get('system', 'relay_subscribe', false);
+
+               if ($subscribe) {
+                       $scope = $config->get('system', 'relay_scope', SR_SCOPE_ALL);
+               } else {
+                       $scope = SR_SCOPE_NONE;
+               }
+
+               $systemTags = [];
+               $userTags = [];
+
+               if ($scope == SR_SCOPE_TAGS) {
+                       $server_tags = $config->get('system', 'relay_server_tags');
+                       $tagitems = explode(',', $server_tags);
+
+                       /// @todo Check if it was better to use "strtolower" on the tags
+                       foreach ($tagitems AS $tag) {
+                               $systemTags[] = trim($tag, '# ');
+                       }
+
+                       if ($config->get('system', 'relay_user_tags')) {
+                               $userTags = Search::getUserTags();
+                       }
+               }
+
+               $tagList = array_unique(array_merge($systemTags, $userTags));
+
+               $relay = [
+                       'subscribe' => $subscribe,
+                       'scope'     => $scope,
+                       'tags'      => $tagList,
+                       'protocols' => [
+                               'diaspora' => [
+                                       'receive' => $app->getBaseURL() . '/receive/public'
+                               ],
+                               'dfrn'     => [
+                                       'receive' => $app->getBaseURL() . '/dfrn_notify'
+                               ]
+                       ]
+               ];
+
+               header('Content-type: application/json; charset=utf-8');
+               echo json_encode($relay, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
+               exit;
+       }
+}
diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php
new file mode 100644 (file)
index 0000000..38ce151
--- /dev/null
@@ -0,0 +1,195 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\Hook;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Model\User;
+use Friendica\Protocol\Salmon;
+use Friendica\Util\Strings;
+
+/**
+ * Prints responses to /.well-known/webfinger  or /xrd requests
+ */
+class Xrd extends BaseModule
+{
+       public static function rawContent()
+       {
+               $app = self::getApp();
+
+               // @TODO: Replace with parameter from router
+               if ($app->argv[0] == 'xrd') {
+                       if (empty($_GET['uri'])) {
+                               return;
+                       }
+
+                       $uri = urldecode(Strings::escapeTags(trim($_GET['uri'])));
+                       if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/jrd+json') {
+                               $mode = 'json';
+                       } else {
+                               $mode = 'xml';
+                       }
+               } else {
+                       if (empty($_GET['resource'])) {
+                               return;
+                       }
+
+                       $uri = urldecode(Strings::escapeTags(trim($_GET['resource'])));
+                       if (defaults($_SERVER, 'HTTP_ACCEPT', '') == 'application/xrd+xml') {
+                               $mode = 'xml';
+                       } else {
+                               $mode = 'json';
+                       }
+               }
+
+               if (substr($uri, 0, 4) === 'http') {
+                       $name = ltrim(basename($uri), '~');
+               } else {
+                       $local = str_replace('acct:', '', $uri);
+                       if (substr($local, 0, 2) == '//') {
+                               $local = substr($local, 2);
+                       }
+
+                       $name = substr($local, 0, strpos($local, '@'));
+               }
+
+               $user = User::getByNickname($name);
+
+               if (empty($user)) {
+                       System::httpExit(404);
+               }
+
+               $profileURL = $app->getBaseURL() . '/profile/' . $user['nickname'];
+               $alias = str_replace('/profile/', '/~', $profileURL);
+
+               $addr = 'acct:' . $user['nickname'] . '@' . $app->getHostName();
+               if ($app->getURLPath()) {
+                       $addr .= '/' . $app->getURLPath();
+               }
+
+               if ($mode == 'xml') {
+                       self::printXML($addr, $alias, $profileURL, $app->getBaseURL(), $user);
+               } else {
+                       self::printJSON($addr, $alias, $profileURL, $app->getBaseURL(), $user);
+               }
+       }
+
+       private static function printJSON($uri, $alias, $orofileURL, $baseURL, $user)
+       {
+               $salmon_key = Salmon::salmonKey($user['spubkey']);
+
+               header('Access-Control-Allow-Origin: *');
+               header('Content-type: application/json; charset=utf-8');
+
+               $json = [
+                       'subject' => $uri,
+                       'aliases' => [
+                               $alias,
+                               $orofileURL,
+                       ],
+                       'links'   => [
+                               [
+                                       'rel'  => NAMESPACE_DFRN,
+                                       'href' => $orofileURL,
+                               ],
+                               [
+                                       'rel'  => NAMESPACE_FEED,
+                                       'type' => 'application/atom+xml',
+                                       'href' => $baseURL . '/dfrn_poll/' . $user['nickname'],
+                               ],
+                               [
+                                       'rel'  => 'http://webfinger.net/rel/profile-page',
+                                       'type' => 'text/html',
+                                       'href' => $orofileURL,
+                               ],
+                               [
+                                       'rel'  => 'self',
+                                       'type' => 'application/activity+json',
+                                       'href' => $orofileURL,
+                               ],
+                               [
+                                       'rel'  => 'http://microformats.org/profile/hcard',
+                                       'type' => 'text/html',
+                                       'href' => $baseURL . '/hcard/' . $user['nickname'],
+                               ],
+                               [
+                                       'rel'  => NAMESPACE_POCO,
+                                       'href' => $baseURL . '/poco/' . $user['nickname'],
+                               ],
+                               [
+                                       'rel'  => 'http://webfinger.net/rel/avatar',
+                                       'type' => 'image/jpeg',
+                                       'href' => $baseURL . '/photo/profile/' . $user['uid'] . '.jpg',
+                               ],
+                               [
+                                       'rel'  => 'http://joindiaspora.com/seed_location',
+                                       'type' => 'text/html',
+                                       'href' => $baseURL,
+                               ],
+                               [
+                                       'rel'  => 'salmon',
+                                       'href' => $baseURL . '/salmon/' . $user['nickname'],
+                               ],
+                               [
+                                       'rel'  => 'http://salmon-protocol.org/ns/salmon-replies',
+                                       'href' => $baseURL . '/salmon/' . $user['nickname'],
+                               ],
+                               [
+                                       'rel'  => 'http://salmon-protocol.org/ns/salmon-mention',
+                                       'href' => $baseURL . '/salmon/' . $user['nickname'] . '/mention',
+                               ],
+                               [
+                                       'rel'      => 'http://ostatus.org/schema/1.0/subscribe',
+                                       'template' => $baseURL . '/follow?url={uri}',
+                               ],
+                               [
+                                       'rel'  => 'magic-public-key',
+                                       'href' => 'data:application/magic-public-key,' . $salmon_key,
+                               ],
+                               [
+                                       'rel'  => 'http://purl.org/openwebauth/v1',
+                                       'type' => 'application/x-zot+json',
+                                       'href' => $baseURL . '/owa',
+                               ],
+                       ],
+               ];
+
+               echo json_encode($json);
+               exit();
+       }
+
+       private static function printXML($uri, $alias, $profileURL, $baseURL, $user)
+       {
+               $salmon_key = Salmon::salmonKey($user['spubkey']);
+
+               header('Access-Control-Allow-Origin: *');
+               header('Content-type: text/xml');
+
+               $tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
+
+               $o = Renderer::replaceMacros($tpl, [
+                       '$nick'        => $user['nickname'],
+                       '$accturi'     => $uri,
+                       '$alias'       => $alias,
+                       '$profile_url' => $profileURL,
+                       '$hcard_url'   => $baseURL . '/hcard/' . $user['nickname'],
+                       '$atom'        => $baseURL . '/dfrn_poll/' . $user['nickname'],
+                       '$poco_url'    => $baseURL . '/poco/' . $user['nickname'],
+                       '$photo'       => $baseURL . '/photo/profile/' . $user['uid'] . '.jpg',
+                       '$baseurl'     => $baseURL,
+                       '$salmon'      => $baseURL . '/salmon/' . $user['nickname'],
+                       '$salmen'      => $baseURL . '/salmon/' . $user['nickname'] . '/mention',
+                       '$subscribe'   => $baseURL . '/follow?url={uri}',
+                       '$openwebauth' => $baseURL . '/owa',
+                       '$modexp'      => 'data:application/magic-public-key,' . $salmon_key
+               ]);
+
+               $arr = ['user' => $user, 'xml' => $o];
+               Hook::callAll('personal_xrd', $arr);
+
+               echo $arr['xml'];
+               exit();
+       }
+}
diff --git a/view/templates/webfinger.tpl b/view/templates/webfinger.tpl
new file mode 100644 (file)
index 0000000..109a7fc
--- /dev/null
@@ -0,0 +1,16 @@
+<div class="generic-page-wrapper">
+       <h3>Webfinger Diagnostic</h3>
+
+       <form action="webfinger" method="get">
+               Lookup address: <input type="text" style="width: 250px;" name="addr" value="{{$addr}}" />
+               <input type="submit" name="submit" value="Submit" />
+       </form>
+
+       <br /><br />
+
+       {{if $res}}
+       <pre>
+               {{$res}}
+       </pre>
+       {{/if}}
+</div>