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