3 if (!defined('GNUSOCIAL')) {
7 class NodeinfoPlugin extends Plugin
9 const VERSION = '0.0.1';
11 public function onRouterInitialized($m)
14 '.well-known/nodeinfo',
16 'action' => 'nodeinfojrd'
23 'action' => 'nodeinfo_2_0'
31 * Make sure necessary tables are filled out.
33 * @return boolean hook true
35 public function onCheckSchema()
38 $schema = Schema::get();
39 $schema->ensureTable('usage_stats', Usage_stats::schemaDef());
41 // Ensure default rows
42 if (Usage_stats::getKV('type', 'users') == null) {
43 $us = new Usage_stats();
48 if (Usage_stats::getKV('type', 'posts') == null) {
49 $us = new Usage_stats();
54 if (Usage_stats::getKV('type', 'comments') == null) {
55 $us = new Usage_stats();
56 $us->type = 'comments';
64 * Increment notices/replies counter
66 * @return boolean hook flag
67 * @author Diogo Cordeiro <diogo@fc.up.pt>
69 public function onStartNoticeDistribute($notice)
71 assert($notice->id > 0); // Ignore if not a valid notice
73 $profile = $notice->getProfile();
75 if (!$profile->isLocal()) {
79 // Ignore for activity/non-post-verb notices
80 if (method_exists('ActivityUtils', 'compareVerbs')) {
81 $is_post_verb = ActivityUtils::compareVerbs(
86 $is_post_verb = ($notice->verb == ActivityVerb::POST ? true : false);
88 if ($notice->source == 'activity' || !$is_post_verb) {
93 if ($notice->reply_to) {
94 $us = Usage_stats::getKV('type', 'comments');
101 if ($notice->isRepeat()) {
105 $us = Usage_stats::getKV('type', 'posts');
114 * Decrement notices/replies counter
116 * @return boolean hook flag
117 * @author Diogo Cordeiro <diogo@fc.up.pt>
119 public function onStartDeleteOwnNotice($user, $notice)
121 $profile = $user->getProfile();
123 // Only count local notices
124 if (!$profile->isLocal()) {
128 if ($notice->reply_to) {
129 $us = Usage_stats::getKV('type', 'comments');
135 $us = Usage_stats::getKV('type', 'posts');
142 * Increment users counter
144 * @return boolean hook flag
145 * @author Diogo Cordeiro <diogo@fc.up.pt>
147 public function onEndRegistrationTry()
149 $us = Usage_stats::getKV('type', 'users');
156 * Decrement users counter
158 * @return boolean hook flag
159 * @author Diogo Cordeiro <diogo@fc.up.pt>
161 public function onEndDeleteUser()
163 $us = Usage_stats::getKV('type', 'users');
170 public function onPluginVersion(array &$versions)
172 $versions[] = ['name' => 'Nodeinfo',
173 'version' => self::VERSION,
175 'homepage' => 'https://github.com/chimo/gs-nodeinfo',
176 'description' => _m('Plugin that presents basic instance information using the NodeInfo standard.')];