3 if (!defined('GNUSOCIAL')) {
7 class NodeinfoPlugin extends Plugin
9 const PLUGIN_VERSION = '1.0.2';
11 public function onRouterInitialized($m)
13 $m->connect('.well-known/nodeinfo',
14 ['action' => 'nodeinfojrd']);
16 $m->connect('main/nodeinfo/2.0',
17 ['action' => 'nodeinfo_2_0']);
23 * Make sure necessary tables are filled out.
25 * @return boolean hook true
27 public function onCheckSchema()
30 $schema = Schema::get();
31 $schema->ensureTable('usage_stats', Usage_stats::schemaDef());
33 // Ensure default rows
34 if (Usage_stats::getKV('type', 'users') == null) {
35 $us = new Usage_stats();
40 if (Usage_stats::getKV('type', 'posts') == null) {
41 $us = new Usage_stats();
46 if (Usage_stats::getKV('type', 'comments') == null) {
47 $us = new Usage_stats();
48 $us->type = 'comments';
56 * Increment notices/replies counter
58 * @return boolean hook flag
59 * @author Diogo Cordeiro <diogo@fc.up.pt>
61 public function onStartNoticeDistribute($notice)
63 assert($notice->id > 0); // Ignore if not a valid notice
65 $profile = $notice->getProfile();
67 if (!$profile->isLocal()) {
71 // Ignore for activity/non-post-verb notices
72 if (method_exists('ActivityUtils', 'compareVerbs')) {
73 $is_post_verb = ActivityUtils::compareVerbs(
78 $is_post_verb = ($notice->verb == ActivityVerb::POST ? true : false);
80 if ($notice->source == 'activity' || !$is_post_verb) {
85 if ($notice->reply_to) {
86 $us = Usage_stats::getKV('type', 'comments');
93 if ($notice->isRepeat()) {
97 $us = Usage_stats::getKV('type', 'posts');
106 * Decrement notices/replies counter
108 * @return boolean hook flag
109 * @author Diogo Cordeiro <diogo@fc.up.pt>
111 public function onStartDeleteOwnNotice($user, $notice)
113 $profile = $user->getProfile();
115 // Only count local notices
116 if (!$profile->isLocal()) {
120 if ($notice->reply_to) {
121 $us = Usage_stats::getKV('type', 'comments');
127 $us = Usage_stats::getKV('type', 'posts');
134 * Increment users counter
136 * @return boolean hook flag
137 * @author Diogo Cordeiro <diogo@fc.up.pt>
139 public function onEndRegistrationTry()
141 $us = Usage_stats::getKV('type', 'users');
148 * Decrement users counter
150 * @return boolean hook flag
151 * @author Diogo Cordeiro <diogo@fc.up.pt>
153 public function onEndDeleteUser()
155 $us = Usage_stats::getKV('type', 'users');
162 public function onPluginVersion(array &$versions)
164 $versions[] = ['name' => 'Nodeinfo',
165 'version' => self::PLUGIN_VERSION,
167 'homepage' => 'https://github.com/chimo/gs-nodeinfo',
168 'description' => _m('Plugin that presents basic instance information using the NodeInfo standard.')];
172 public function onEndUpgrade()
174 $users = new Usage_stats();
175 if ($users->getUserCount() == 0) {
176 define('NODEINFO_UPGRADE', true);
177 require_once __DIR__ . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'fix_stats.php';