Remove unused deprecated XML output in mod/ping
- Remove unused parameters localUser and uid in mod/ping - Unify data array initialization in mod/ping
This commit is contained in:
parent
5a12bd87f3
commit
b002f6f027
2 changed files with 43 additions and 162 deletions
203
mod/ping.php
203
mod/ping.php
|
@ -24,6 +24,7 @@ use Friendica\Content\ForumManager;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Cache\Enum\Duration;
|
use Friendica\Core\Cache\Enum\Duration;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
@ -36,15 +37,10 @@ use Friendica\Protocol\Activity;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Proxy;
|
use Friendica\Util\Proxy;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
use Friendica\Util\XML;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Outputs the counts and the lists of various notifications
|
* 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:
|
* Expected JSON structure:
|
||||||
* {
|
* {
|
||||||
* "result": {
|
* "result": {
|
||||||
|
@ -75,12 +71,6 @@ use Friendica\Util\XML;
|
||||||
*/
|
*/
|
||||||
function ping_init(App $a)
|
function ping_init(App $a)
|
||||||
{
|
{
|
||||||
$format = 'xml';
|
|
||||||
|
|
||||||
if (isset($_GET['format']) && $_GET['format'] == 'json') {
|
|
||||||
$format = 'json';
|
|
||||||
}
|
|
||||||
|
|
||||||
$regs = [];
|
$regs = [];
|
||||||
$notifications = [];
|
$notifications = [];
|
||||||
|
|
||||||
|
@ -100,41 +90,8 @@ function ping_init(App $a)
|
||||||
$birthdays = 0;
|
$birthdays = 0;
|
||||||
$birthdays_today = 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()) {
|
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());
|
$notifications = ping_get_notifications(local_user());
|
||||||
|
|
||||||
$condition = ["`unseen` AND `uid` = ? AND NOT `origin` AND (`vid` != ? OR `vid` IS NULL)",
|
$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) {
|
foreach ($notifications as $notification) {
|
||||||
if ($notification['seen'] == 0) {
|
if ($notification['seen'] == 0) {
|
||||||
|
@ -339,49 +284,54 @@ function ping_init(App $a)
|
||||||
unset($_SESSION['sysmsg_info']);
|
unset($_SESSION['sysmsg_info']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($format == 'json') {
|
$notification_count = $sysnotify_count + $intro_count + $register_count;
|
||||||
$notification_count = $sysnotify_count + $intro_count + $register_count;
|
|
||||||
|
|
||||||
$tpl = \Friendica\Core\Renderer::getMarkupTemplate('notifications/nav/notify.tpl');
|
$tpl = Renderer::getMarkupTemplate('notifications/nav/notify.tpl');
|
||||||
|
|
||||||
$data['groups'] = $groups_unseen;
|
$data = [];
|
||||||
$data['forums'] = $forums_unseen;
|
$data['intro'] = $intro_count;
|
||||||
$data['notification'] = ($notification_count < 50) ? $notification_count : '49+';
|
$data['mail'] = $mail_count;
|
||||||
$data['notifications'] = array_map(function ($navNotification) use ($tpl) {
|
$data['net'] = ($network_count < 1000) ? $network_count : '999+';
|
||||||
$navNotification['contact']['photo'] = Contact::getAvatarUrlForUrl($navNotification['contact']['url'], local_user(), Proxy::SIZE_MICRO);
|
$data['home'] = ($home_count < 1000) ? $home_count : '999+';
|
||||||
|
$data['register'] = $register_count;
|
||||||
|
|
||||||
$navNotification['timestamp'] = strtotime($navNotification['date']);
|
$data['all-events'] = $all_events;
|
||||||
$navNotification['localdate'] = DateTimeFormat::local($navNotification['date']);
|
$data['all-events-today'] = $all_events_today;
|
||||||
$navNotification['ago'] = Temporal::getRelativeDate($navNotification['date']);
|
$data['events'] = $events;
|
||||||
$navNotification['richtext'] = Entity\Notify::formatMessage($navNotification['contact']['name'], $navNotification['message']);
|
$data['events-today'] = $events_today;
|
||||||
$navNotification['plaintext'] = strip_tags($navNotification['richtext']);
|
$data['birthdays'] = $birthdays;
|
||||||
$navNotification['html'] = \Friendica\Core\Renderer::replaceMacros($tpl, [
|
$data['birthdays-today'] = $birthdays_today;
|
||||||
'notify' => $navNotification,
|
$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);
|
||||||
|
|
||||||
return $navNotification;
|
$navNotification['timestamp'] = strtotime($navNotification['date']);
|
||||||
}, $notifications);
|
$navNotification['localdate'] = DateTimeFormat::local($navNotification['date']);
|
||||||
$data['sysmsgs'] = [
|
$navNotification['ago'] = Temporal::getRelativeDate($navNotification['date']);
|
||||||
'notice' => $sysmsgs,
|
$navNotification['richtext'] = Entity\Notify::formatMessage($navNotification['contact']['name'], $navNotification['message']);
|
||||||
'info' => $sysmsgs_info
|
$navNotification['plaintext'] = strip_tags($navNotification['richtext']);
|
||||||
];
|
$navNotification['html'] = Renderer::replaceMacros($tpl, [
|
||||||
|
'notify' => $navNotification,
|
||||||
|
]);
|
||||||
|
|
||||||
$json_payload = json_encode(["result" => $data]);
|
return $navNotification;
|
||||||
|
}, $notifications);
|
||||||
|
$data['sysmsgs'] = [
|
||||||
|
'notice' => $sysmsgs,
|
||||||
|
'info' => $sysmsgs_info
|
||||||
|
];
|
||||||
|
|
||||||
if (isset($_GET['callback'])) {
|
$json_payload = json_encode(["result" => $data]);
|
||||||
// JSONP support
|
|
||||||
header("Content-type: application/javascript");
|
if (isset($_GET['callback'])) {
|
||||||
echo $_GET['callback'] . '(' . $json_payload . ')';
|
// JSONP support
|
||||||
} else {
|
header("Content-type: application/javascript");
|
||||||
header("Content-type: application/json");
|
echo $_GET['callback'] . '(' . $json_payload . ')';
|
||||||
echo $json_payload;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Legacy slower XML format output
|
header("Content-type: application/json");
|
||||||
$data = ping_format_xml_data($data, $sysnotify_count, $notifications, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen);
|
echo $json_payload;
|
||||||
|
|
||||||
header("Content-type: text/xml");
|
|
||||||
echo XML::fromArray(["result" => $data], $xml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
|
@ -470,72 +420,3 @@ function ping_get_notifications($uid)
|
||||||
|
|
||||||
return($result);
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -499,7 +499,7 @@ function insertBBCodeInTextarea(BBCode, textarea) {
|
||||||
|
|
||||||
function NavUpdate() {
|
function NavUpdate() {
|
||||||
if (!stopped) {
|
if (!stopped) {
|
||||||
var pingCmd = 'ping?format=json' + ((localUser != 0) ? '&uid=' + localUser : '');
|
var pingCmd = 'ping';
|
||||||
$.get(pingCmd, function(data) {
|
$.get(pingCmd, function(data) {
|
||||||
if (data.result) {
|
if (data.result) {
|
||||||
// send nav-update event
|
// send nav-update event
|
||||||
|
|
Loading…
Reference in a new issue