]> git.mxchange.org Git - friendica.git/commitdiff
Remove unused deprecated XML output in mod/ping
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 4 Mar 2022 12:36:44 +0000 (07:36 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 14 Mar 2022 11:57:00 +0000 (07:57 -0400)
- Remove unused parameters localUser and uid in mod/ping
- Unify data array initialization in mod/ping

mod/ping.php
view/js/main.js

index 813ea6a1adb72fccd500494d5c9d4e6cd36dc21c..7d954610b9d067d36992d3fd9e2abe2e7d3a975b 100644 (file)
@@ -24,6 +24,7 @@ use Friendica\Content\ForumManager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Cache\Enum\Duration;
 use Friendica\Core\Hook;
+use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
@@ -36,15 +37,10 @@ use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy;
 use Friendica\Util\Temporal;
-use Friendica\Util\XML;
 
 /**
  * Outputs the counts and the lists of various notifications
  *
- * The output format can be controlled via the GET parameter 'format'. It can be
- * - xml (deprecated legacy default)
- * - json (outputs JSONP with the 'callback' GET parameter)
- *
  * Expected JSON structure:
  * {
  *        "result": {
@@ -75,12 +71,6 @@ use Friendica\Util\XML;
  */
 function ping_init(App $a)
 {
-       $format = 'xml';
-
-       if (isset($_GET['format']) && $_GET['format'] == 'json') {
-               $format = 'json';
-       }
-
        $regs          = [];
        $notifications = [];
 
@@ -100,41 +90,8 @@ function ping_init(App $a)
        $birthdays        = 0;
        $birthdays_today  = 0;
 
-       $data = [];
-       $data['intro']    = $intro_count;
-       $data['mail']     = $mail_count;
-       $data['net']      = $network_count;
-       $data['home']     = $home_count;
-       $data['register'] = $register_count;
-
-       $data['all-events']       = $all_events;
-       $data['all-events-today'] = $all_events_today;
-       $data['events']           = $events;
-       $data['events-today']     = $events_today;
-       $data['birthdays']        = $birthdays;
-       $data['birthdays-today']  = $birthdays_today;
 
        if (local_user()) {
-               // Different login session than the page that is calling us.
-               if (!empty($_GET['uid']) && intval($_GET['uid']) != local_user()) {
-                       $data = ['result' => ['invalid' => 1]];
-
-                       if ($format == 'json') {
-                               if (isset($_GET['callback'])) {
-                                       // JSONP support
-                                       header("Content-type: application/javascript");
-                                       echo $_GET['callback'] . '(' . json_encode($data) . ')';
-                               } else {
-                                       header("Content-type: application/json");
-                                       echo json_encode($data);
-                               }
-                       } else {
-                               header("Content-type: text/xml");
-                               echo XML::fromArray($data, $xml);
-                       }
-                       exit();
-               }
-
                $notifications = ping_get_notifications(local_user());
 
                $condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
@@ -241,18 +198,6 @@ function ping_init(App $a)
                        }
                }
 
-               $data['intro']    = $intro_count;
-               $data['mail']     = $mail_count;
-               $data['net']      = ($network_count < 1000) ? $network_count : '999+';
-               $data['home']     = ($home_count < 1000) ? $home_count : '999+';
-               $data['register'] = $register_count;
-
-               $data['all-events']       = $all_events;
-               $data['all-events-today'] = $all_events_today;
-               $data['events']           = $events;
-               $data['events-today']     = $events_today;
-               $data['birthdays']        = $birthdays;
-               $data['birthdays-today']  = $birthdays_today;
 
                foreach ($notifications as $notification) {
                        if ($notification['seen'] == 0) {
@@ -339,49 +284,54 @@ function ping_init(App $a)
                unset($_SESSION['sysmsg_info']);
        }
 
-       if ($format == 'json') {
-               $notification_count = $sysnotify_count + $intro_count + $register_count;
-
-               $tpl = \Friendica\Core\Renderer::getMarkupTemplate('notifications/nav/notify.tpl');
-
-               $data['groups'] = $groups_unseen;
-               $data['forums'] = $forums_unseen;
-               $data['notification'] = ($notification_count < 50) ? $notification_count : '49+';
-               $data['notifications'] = array_map(function ($navNotification) use ($tpl) {
-                       $navNotification['contact']['photo'] = Contact::getAvatarUrlForUrl($navNotification['contact']['url'], local_user(), Proxy::SIZE_MICRO);
-
-                       $navNotification['timestamp'] = strtotime($navNotification['date']);
-                       $navNotification['localdate'] = DateTimeFormat::local($navNotification['date']);
-                       $navNotification['ago']       = Temporal::getRelativeDate($navNotification['date']);
-                       $navNotification['richtext']  = Entity\Notify::formatMessage($navNotification['contact']['name'], $navNotification['message']);
-                       $navNotification['plaintext'] = strip_tags($navNotification['richtext']);
-                       $navNotification['html']      = \Friendica\Core\Renderer::replaceMacros($tpl, [
-                               'notify' => $navNotification,
-                       ]);
-
-                       return $navNotification;
-               }, $notifications);
-               $data['sysmsgs'] = [
-                       'notice' => $sysmsgs,
-                       'info' => $sysmsgs_info
-               ];
-
-               $json_payload = json_encode(["result" => $data]);
-
-               if (isset($_GET['callback'])) {
-                       // JSONP support
-                       header("Content-type: application/javascript");
-                       echo $_GET['callback'] . '(' . $json_payload . ')';
-               } else {
-                       header("Content-type: application/json");
-                       echo $json_payload;
-               }
-       } else {
-               // Legacy slower XML format output
-               $data = ping_format_xml_data($data, $sysnotify_count, $notifications, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen);
+       $notification_count = $sysnotify_count + $intro_count + $register_count;
+
+       $tpl = Renderer::getMarkupTemplate('notifications/nav/notify.tpl');
+
+       $data = [];
+       $data['intro']    = $intro_count;
+       $data['mail']     = $mail_count;
+       $data['net']      = ($network_count < 1000) ? $network_count : '999+';
+       $data['home']     = ($home_count < 1000) ? $home_count : '999+';
+       $data['register'] = $register_count;
 
-               header("Content-type: text/xml");
-               echo XML::fromArray(["result" => $data], $xml);
+       $data['all-events']       = $all_events;
+       $data['all-events-today'] = $all_events_today;
+       $data['events']           = $events;
+       $data['events-today']     = $events_today;
+       $data['birthdays']        = $birthdays;
+       $data['birthdays-today']  = $birthdays_today;
+       $data['groups'] = $groups_unseen;
+       $data['forums'] = $forums_unseen;
+       $data['notification'] = ($notification_count < 50) ? $notification_count : '49+';
+       $data['notifications'] = array_map(function ($navNotification) use ($tpl) {
+               $navNotification['contact']['photo'] = Contact::getAvatarUrlForUrl($navNotification['contact']['url'], local_user(), Proxy::SIZE_MICRO);
+
+               $navNotification['timestamp'] = strtotime($navNotification['date']);
+               $navNotification['localdate'] = DateTimeFormat::local($navNotification['date']);
+               $navNotification['ago']       = Temporal::getRelativeDate($navNotification['date']);
+               $navNotification['richtext']  = Entity\Notify::formatMessage($navNotification['contact']['name'], $navNotification['message']);
+               $navNotification['plaintext'] = strip_tags($navNotification['richtext']);
+               $navNotification['html']      = Renderer::replaceMacros($tpl, [
+                       'notify' => $navNotification,
+               ]);
+
+               return $navNotification;
+       }, $notifications);
+       $data['sysmsgs'] = [
+               'notice' => $sysmsgs,
+               'info' => $sysmsgs_info
+       ];
+
+       $json_payload = json_encode(["result" => $data]);
+
+       if (isset($_GET['callback'])) {
+               // JSONP support
+               header("Content-type: application/javascript");
+               echo $_GET['callback'] . '(' . $json_payload . ')';
+       } else {
+               header("Content-type: application/json");
+               echo $json_payload;
        }
 
        exit();
@@ -470,72 +420,3 @@ function ping_get_notifications($uid)
 
        return($result);
 }
-
-/**
- * Backward-compatible XML formatting for ping.php output
- * @deprecated
- *
- * @param array $data            The initial ping data array
- * @param int   $sysnotify_count Number of unseen system notifications
- * @param array $notifs          Complete list of notification
- * @param array $sysmsgs         List of system notice messages
- * @param array $sysmsgs_info    List of system info messages
- * @param array $groups_unseen   List of unseen group items
- * @param array $forums_unseen   List of unseen forum items
- *
- * @return array XML-transform ready data array
- */
-function ping_format_xml_data($data, $sysnotify_count, $notifs, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen)
-{
-       $notifications = [];
-       foreach ($notifs as $key => $notif) {
-               $notifications[$key . ':note'] = $notif['message'];
-
-               $notifications[$key . ':@attributes'] = [
-                       'id'        => $notif['id'],
-                       'href'      => $notif['href'],
-                       'name'      => $notif['name'],
-                       'url'       => $notif['url'],
-                       'photo'     => $notif['photo'],
-                       'date'      => $notif['date'],
-                       'seen'      => $notif['seen'],
-                       'timestamp' => $notif['timestamp']
-               ];
-       }
-
-       $sysmsg = [];
-       foreach ($sysmsgs as $key => $m) {
-               $sysmsg[$key . ':notice'] = $m;
-       }
-       foreach ($sysmsgs_info as $key => $m) {
-               $sysmsg[$key . ':info'] = $m;
-       }
-
-       $data['notif'] = $notifications;
-       $data['@attributes'] = ['count' => $sysnotify_count + $data['intro'] + $data['mail'] + $data['register']];
-       $data['sysmsgs'] = $sysmsg;
-
-       if ($data['register'] == 0) {
-               unset($data['register']);
-       }
-
-       $groups = [];
-       if (count($groups_unseen)) {
-               foreach ($groups_unseen as $key => $item) {
-                       $groups[$key . ':group'] = $item['count'];
-                       $groups[$key . ':@attributes'] = ['id' => $item['id']];
-               }
-               $data['groups'] = $groups;
-       }
-
-       $forums = [];
-       if (count($forums_unseen)) {
-               foreach ($forums_unseen as $key => $item) {
-                       $forums[$key . ':forum'] = $item['count'];
-                       $forums[$key . ':@attributes'] = ['id' => $item['id']];
-               }
-               $data['forums'] = $forums;
-       }
-
-       return $data;
-}
index c4109a8c70d09a24734f0814e137539c7406e4b6..93340dc37f6fdcb6ba58321489de3c93caf97977 100644 (file)
@@ -499,7 +499,7 @@ function insertBBCodeInTextarea(BBCode, textarea) {
 
 function NavUpdate() {
        if (!stopped) {
-               var pingCmd = 'ping?format=json' + ((localUser != 0) ? '&uid=' + localUser : '');
+               var pingCmd = 'ping';
                $.get(pingCmd, function(data) {
                        if (data.result) {
                                // send nav-update event