PluginProbe
NodeInfo(2) / 2.1.1
NodeInfo(2) v2.1.1
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) 2.1.1, at includes/class-nodeinfo.php

122 lines 2.9 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 = get_users(
34 array(
35 'capability__in' => array( 'publish_posts' ),
36 )
37 );
38
39 if ( is_array( $users ) ) {
40 $users = count( $users );
41 } else {
42 $users = 1;
43 }
44
45 $posts = wp_count_posts();
46 $comments = wp_count_comments();
47
48 $this->usage = apply_filters(
49 'nodeinfo_data_usage',
50 array(
51 'users' => array(
52 'total' => $users,
53 ),
54 'localPosts' => (int) $posts->publish,
55 'localComments' => (int) $comments->approved,
56 ),
57 $this->version
58 );
59 }
60
61 public function generate_software() {
62 $software = array(
63 'name' => 'wordpress',
64 'version' => get_bloginfo( 'version' ),
65 );
66
67 if ( '2.1' === $this->version ) {
68 $software['repository'] = 'https://github.com/wordpress/wordpress';
69 }
70
71 $this->software = apply_filters(
72 'nodeinfo_data_software',
73 $software,
74 $this->version
75 );
76 }
77
78 public function generate_protocols() {
79 $protocols = $this->protocols;
80
81 if ( version_compare( $this->version, '2.0', '>=' ) ) {
82 $protocols = array();
83 } else {
84 $protocols['inbound'] = array( 'smtp' );
85 $protocols['outbound'] = array( 'smtp' );
86 }
87
88 $this->protocols = apply_filters( 'nodeinfo_data_protocols', $protocols, $this->version );
89 }
90
91 public function generate_services() {
92 $services = $this->services;
93
94 if ( version_compare( $this->version, '2.0', '>=' ) ) {
95 $services['inbound'] = array( 'atom1.0', 'rss2.0', 'pop3' );
96 $services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' );
97 } else {
98 $services['outbound'] = array( 'smtp' );
99 }
100
101 $this->services = apply_filters( 'nodeinfo_data_services', $services, $this->version );
102 }
103
104 public function generate_metadata() {
105 $metadata = $this->metadata;
106
107 $metadata['email'] = get_option( 'admin_email' );
108
109 $metadata['generator'] = array(
110 'name' => 'NodeInfo WordPress-Plugin',
111 'version' => nodeinfo_version(),
112 'repository' => 'https://github.com/pfefferle/wordpress-nodeinfo/',
113 );
114
115 $this->metadata = apply_filters( 'nodeinfo_data_metadata', $metadata, $this->version );
116 }
117
118 public function to_array() {
119 return apply_filters( 'nodeinfo_data', get_object_vars( $this ), $this->version );
120 }
121 }
122