PluginProbe
NodeInfo(2) / 1.0.5
NodeInfo(2) v1.0.5
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 3.0.0 3.1.0
nodeinfo / includes / class-nodeinfo.php

class-nodeinfo.php in NodeInfo(2) 1.0.5, at includes/class-nodeinfo.php

105 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Nodeinfo class
4 *
5 * @link https://github.com/jhass/nodeinfo
6 */
7 class Nodeinfo {
8 public $version = '2.0';
9 public $software = array();
10 public $usage = array();
11 public $openRegistrations = false; // phpcs:ignore
12 public $services = array(
13 'inbound' => array(),
14 'outbound' => array(),
15 );
16 public $protocols = array();
17 public $metadata = array();
18
19 public function __construct( $version = '2.0' ) {
20 if ( in_array( $version, array( '1.0', '1.1', '2.0', '2.1' ), true ) ) {
21 $this->version = $version;
22 }
23
24 $this->generate_software();
25 $this->generate_usage();
26 $this->generate_protocols();
27 $this->generate_services();
28 $this->generate_metadata();
29 $this->openRegistrations = (boolean) get_option( 'users_can_register', false ); // phpcs:ignore
30 }
31
32 public function generate_usage() {
33 $users = count_users();
34 $posts = wp_count_posts();
35 $comments = wp_count_comments();
36
37 $this->usage = apply_filters(
38 'nodeinfo_data_usage',
39 array(
40 'users' => array(
41 'total' => (int) $users['total_users'],
42 ),
43 'localPosts' => (int) $posts->publish,
44 'localComments' => (int) $comments->approved,
45 ),
46 $this->version
47 );
48 }
49
50 public function generate_software() {
51 $software = array(
52 'name' => 'wordpress',
53 'version' => get_bloginfo( 'version' ),
54 );
55
56 if ( '2.1' === $this->version ) {
57 $software['repository'] = 'https://github.com/pfefferle/wordpress-nodeinfo';
58 }
59
60 $this->software = apply_filters(
61 'nodeinfo_data_software',
62 $software,
63 $this->version
64 );
65 }
66
67 public function generate_protocols() {
68 $protocols = $this->protocols;
69
70 if ( '2.0' === $this->version ) {
71 $protocols = array();
72 } else {
73 $protocols['inbound'] = array( 'smtp' );
74 $protocols['outbound'] = array( 'smtp' );
75 }
76
77 $this->protocols = apply_filters( 'nodeinfo_data_protocols', $protocols, $this->version );
78 }
79
80 public function generate_services() {
81 $services = $this->services;
82
83 if ( '2.0' === $this->version ) {
84 $services['inbound'] = array( 'atom1.0', 'rss2.0', 'pop3' );
85 $services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' );
86 } else {
87 $services['outbound'] = array( 'smtp' );
88 }
89
90 $this->services = apply_filters( 'nodeinfo_data_services', $services, $this->version );
91 }
92
93 public function generate_metadata() {
94 $metadata = $this->metadata;
95
96 $metadata['email'] = get_option( 'admin_email' );
97
98 $this->metadata = apply_filters( 'nodeinfo_data_metadata', $metadata, $this->version );
99 }
100
101 public function to_array() {
102 return apply_filters( 'nodeinfo_data', get_object_vars( $this ), $this->version );
103 }
104 }
105