3 if (!defined('GNUSOCIAL')) {
7 class Nodeinfo_2_0Action extends ApiAction
11 protected function handle()
15 $this->plugins = $this->getActivePluginList();
17 $this->showNodeInfo();
20 public function getActivePluginList()
22 $pluginversions = array();
25 Event::handle('PluginVersion', array(&$pluginversions));
27 foreach ($pluginversions as $plugin) {
28 $plugins[strtolower($plugin['name'])] = 1;
35 * Technically, the NodeInfo spec defines 'active' as 'signed in at least once',
36 * but GNU social doesn't keep track of when users last logged in, so let's return
37 * the number of users that 'posted at least once', I guess.
40 public function showNodeInfo()
42 $openRegistrations = $this->getRegistrationsStatus();
43 $userCount = $this->getUserCount();
44 $postCount = $this->getPostCount();
45 $commentCount = $this->getCommentCount();
47 $usersActiveHalfyear = $this->getActiveUsers(180);
48 $usersActiveMonth = $this->getActiveUsers(30);
50 $protocols = $this->getProtocols();
51 $inboundServices = $this->getInboundServices();
52 $outboundServices = $this->getOutboundServices();
58 'name' => 'gnusocial',
59 'version' => GNUSOCIAL_VERSION
62 'protocols' => $protocols,
64 // TODO: Have plugins register services
66 'inbound' => $inboundServices,
67 'outbound' => $outboundServices
70 'openRegistrations' => $openRegistrations,
74 'total' => $userCount,
75 'activeHalfyear' => $usersActiveHalfyear,
76 'activeMonth' => $usersActiveMonth
78 'localPosts' => $postCount,
79 'localComments' => $commentCount
82 'metadata' => new stdClass()
85 $this->initDocument('json');
87 $this->endDocument('json');
90 public function getRegistrationsStatus()
92 $areRegistrationsClosed = (common_config('site', 'closed')) ? true : false;
93 $isSiteInviteOnly = (common_config('site', 'inviteonly')) ? true : false;
95 return !($areRegistrationsClosed || $isSiteInviteOnly);
98 public function getUserCount()
100 $users = new Usage_stats();
101 $userCount = $users->getUserCount();
106 public function getPostCount()
108 $posts = new Usage_stats();
109 $postCount = $posts->getPostCount();
114 public function getCommentCount()
116 $comments = new Usage_stats();
117 $commentCount = $comments->getCommentCount();
119 return $commentCount;
122 public function getActiveUsers($days)
124 $notices = new Notice();
125 $notices->joinAdd(array('profile_id', 'user:id'));
126 $notices->whereAdd('notice.created >= NOW() - INTERVAL ' . $days . ' DAY');
128 $activeUsersCount = $notices->count('distinct profile_id');
130 return $activeUsersCount;
133 public function getProtocols()
137 Event::handle('NodeInfoProtocols', array(&$protocols));
142 public function getInboundServices()
144 // FIXME: Are those always on?
145 $inboundServices = array('atom1.0', 'rss2.0');
147 if (array_key_exists('twitterbridge', $this->plugins) && common_config('twitterimport', 'enabled')) {
148 $inboundServices[] = 'twitter';
151 if (array_key_exists('ostatus', $this->plugins)) {
152 $inboundServices[] = 'gnusocial';
155 return $inboundServices;
158 public function getOutboundServices()
160 $xmppEnabled = (array_key_exists('xmpp', $this->plugins) && common_config('xmpp', 'enabled')) ? true : false;
162 // FIXME: Are those always on?
163 $outboundServices = array('atom1.0', 'rss2.0');
165 if (array_key_exists('twitterbridge', $this->plugins)) {
166 $outboundServices[] = 'twitter';
169 if (array_key_exists('ostatus', $this->plugins)) {
170 $outboundServices[] = 'gnusocial';
174 $outboundServices[] = 'xmpp';
177 return $outboundServices;