| 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; |
| 18 |
|
| 19 |
public function __construct( $version = '1.0' ) { |
| 20 |
if ( in_array( $version, array( '1.0' ) ) ) { |
| 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( 'nodeinfo2_data_usage', array( |
| 38 |
'users' => array( |
| 39 |
'total' => (int) $users['total_users'], |
| 40 |
), |
| 41 |
'localPosts' => (int) $posts->publish, |
| 42 |
'localComments' => (int) $comments->approved, |
| 43 |
), $this->version ); |
| 44 |
} |
| 45 |
|
| 46 |
public function generate_server() { |
| 47 |
$this->server = apply_filters( 'nodeinfo2_data_server', array( |
| 48 |
'baseUrl' => home_url( '/' ), |
| 49 |
'name' => get_bloginfo( 'name' ), |
| 50 |
'software' => 'wordpress', |
| 51 |
'version' => get_bloginfo( 'version' ), |
| 52 |
), $this->version ); |
| 53 |
} |
| 54 |
|
| 55 |
public function generate_protocols() { |
| 56 |
$this->protocols = apply_filters( 'nodeinfo2_data_protocols', $this->protocols, $this->version ); |
| 57 |
} |
| 58 |
|
| 59 |
public function generate_services() { |
| 60 |
$services = $this->services; |
| 61 |
|
| 62 |
$services['inbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'pop3' ); |
| 63 |
$services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' ); |
| 64 |
|
| 65 |
$this->services = apply_filters( 'nodeinfo2_data_services', $services, $this->version ); |
| 66 |
} |
| 67 |
|
| 68 |
public function generate_metadata() { |
| 69 |
$this->metadata = apply_filters( 'nodeinfo2_data_metadata', new stdClass, $this->version ); |
| 70 |
} |
| 71 |
|
| 72 |
public function to_array() { |
| 73 |
return apply_filters( 'nodeinfo2_data', get_object_vars( $this ), $this->version ); |
| 74 |
} |
| 75 |
} |
| 76 |
|