PluginProbe
NodeInfo(2) / 1.0.8
NodeInfo(2) v1.0.8
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-nodeinfo2.php

class-nodeinfo2.php in NodeInfo(2) 1.0.8, at includes/class-nodeinfo2.php

88 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Nodeinfo2 class
4 *
5 * @link https://github.com/jaywink/nodeinfo2
6 */
7 class Nodeinfo2 {
8 public $version = '1.0';
9 public $server = 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 = '1.0' ) {
20 if ( in_array( $version, array( '1.0' ), true ) ) {
21 $this->version = $version;
22 }
23
24 $this->generate_server();
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 'nodeinfo2_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_server() {
51 $this->server = apply_filters(
52 'nodeinfo2_data_server',
53 array(
54 'baseUrl' => home_url( '/' ),
55 'name' => get_bloginfo( 'name' ),
56 'software' => 'wordpress',
57 'version' => get_bloginfo( 'version' ),
58 ),
59 $this->version
60 );
61 }
62
63 public function generate_protocols() {
64 $this->protocols = apply_filters( 'nodeinfo2_data_protocols', $this->protocols, $this->version );
65 }
66
67 public function generate_services() {
68 $services = $this->services;
69
70 $services['inbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'pop3' );
71 $services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' );
72
73 $this->services = apply_filters( 'nodeinfo2_data_services', $services, $this->version );
74 }
75
76 public function generate_metadata() {
77 $metadata = $this->metadata;
78
79 $metadata['email'] = get_option( 'admin_email' );
80
81 $this->metadata = apply_filters( 'nodeinfo2_data_metadata', $metadata, $this->version );
82 }
83
84 public function to_array() {
85 return apply_filters( 'nodeinfo2_data', get_object_vars( $this ), $this->version );
86 }
87 }
88