-
Notifications
You must be signed in to change notification settings - Fork 13
/
syndication-links.php
executable file
·210 lines (192 loc) · 6.12 KB
/
syndication-links.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* Plugin Name: Syndication Links
* Plugin URI: http://wordpress.org/plugins/syndication-links
* Description: Add Links to Syndicated Copies of Your Posts
* Version: 4.4.21
* Requires at least: 4.9.9
* Requires PHP: 7.0
* Author: David Shanske
* Author URI: http://david.shanske.com
* Text Domain: syndication-links
* Domain Path: /languages
* License: GPLv2 or later
*/
// Version Number Constant.
define( 'SYNDICATION_LINKS_VERSION', get_file_data( __FILE__, array( 'Version' => 'Version' ) )['Version'] );
// If set to 0 disable the webmention version of Bridgy in favor of Micropub.
defined( 'SYNDICATION_LINKS_BRIDGY_WEBMENTION' ) || define( 'SYNDICATION_LINKS_BRIDGY_WEBMENTION', 0 );
function syndication_links_load( $files, $dir = 'includes/' ) {
$dir = trailingslashit( $dir );
if ( empty( $files ) ) {
return;
}
$path = plugin_dir_path( __FILE__ ) . $dir;
foreach ( $files as $file ) {
if ( file_exists( $path . $file ) ) {
require_once $path . $file;
} else {
error_log( $path . $file );
}
}
}
/**
* Filename to Classname Function.
*
* @param string $filename.
*/
function syndication_links_filename_to_classname( $filename ) {
$class = str_replace( 'class-', '', $filename );
$class = str_replace( '.php', '', $class );
$class = ucwords( $class, '-' );
$class = str_replace( '-', '_', $class );
if ( class_exists( $class ) ) {
return $class;
}
return false;
}
/**
* Load and register files.
*
* Checks for the existence of and loads files, then registers them as providers.
*
* @param array $files An array of filenames.
* @param string $dir The directory the files can be found in, relative to the current directory.
*/
function syndication_links_register_providers( $files, $dir = 'includes/' ) {
$dir = trailingslashit( $dir );
if ( empty( $files ) ) {
return;
}
$path = plugin_dir_path( __FILE__ ) . $dir;
foreach ( $files as $file ) {
if ( file_exists( $path . $file ) ) {
require_once $path . $file;
if ( str_contains( $file, 'provider' ) ) {
$class = syndication_links_filename_to_classname( $file );
if ( $class ) {
register_syndication_provider( new $class() );
} else {
error_log( 'Cannot register ' . $class );
}
}
} else {
error_log( $path . $file );
}
}
}
function syndication_links_init() {
syndication_links_load(
array(
'simple-icons.php', // Icon Information
'class-syn-link-domain-icon-map.php', // Mapping domains to icon names
'class-syn-meta.php', // Information on Metadata
'class-syn-config.php', // Configuration Options
'class-social-plugins.php', // Social Plugin Add-Ons
'functions.php', // Global Functions
'compat-functions.php', // Compat Functions
'class-widget-original-of.php', // Original Of Widget
)
);
if ( class_exists( 'Widget_Original_Of' ) ) {
add_action(
'widgets_init',
function () {
register_widget( 'Widget_Original_Of' );
}
);
}
if ( 1 === intval( get_option( 'syndication_posse_enable', 0 ) ) ) {
syndication_links_load(
array(
'class-syndication-provider.php', // Syndication Provider Base Class
'class-post-syndication.php', // Post syndication logic
)
);
// Providers that require access to a third-party API or other method
syndication_links_register_providers(
array(
'class-syndication-provider-microdotblog.php', // Micro.blog
),
'/includes/apis'
);
// Micropub Base Class
syndication_links_register_providers(
array(
'class-synprovider-micropub.php', // Class for any Micropub Based Service
),
'/includes/micropub'
);
// Webmention Only Providers
if ( function_exists( 'send_webmention' ) ) {
syndication_links_load(
array(
'class-synprovider-webmention.php', // Class for Any Webmention Based Service
'class-synprovider-webmention-custom.php', // Class for A Custom Webmention Based Service
),
'/includes/webmentions'
);
syndication_links_register_providers(
array(
'class-synprovider-webmention-bridgy-fed.php', // Bridgy Fed
),
'/includes/webmentions'
);
if ( class_exists( 'SynProvider_Webmention_Custom' ) ) {
$custom = get_option( 'syndication_links_custom_posse' );
if ( ! empty( $custom ) && is_array( $custom ) ) {
foreach ( $custom as $c ) {
register_syndication_provider( new SynProvider_Webmention_Custom( $c ) );
}
}
}
}
if ( 0 === SYNDICATION_LINKS_BRIDGY_WEBMENTION ) {
// Providers that require Micropub
syndication_links_register_providers(
array(
'class-synprovider-micropub-bridgy-flickr.php',
'class-synprovider-micropub-bridgy-github.php',
'class-synprovider-micropub-bridgy-mastodon.php',
'class-synprovider-micropub-bridgy-bluesky.php',
),
'/includes/micropub'
);
} elseif ( function_exists( 'send_webmention' ) ) {
syndication_links_register_providers(
array(
'class-synprovider-webmention-bridgy.php', // Bridgy Base Class
'class-synprovider-webmention-bridgy-github.php', // Github via Bridgy
'class-synprovider-webmention-bridgy-flickr.php', // Flickr via Bridgy
'class-synprovider-webmention-bridgy-mastodon.php', // Mastodon via Bridgy
),
'/includes/webmentions'
);
}
// Providers that have a Post Kinds Dependency
if ( class_exists( 'Post_Kinds_Plugin' ) ) {
syndication_links_register_providers(
array(
'class-syndication-provider-pinboard.php', // Pinboard
),
'/includes/apis'
);
}
}
load_plugin_textdomain( 'syndication-links', false, basename( __DIR__ ) . '/languages/' );
}
add_action( 'plugins_loaded', 'syndication_links_init', 11 );
function syndication_links_privacy_declaration() {
if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
$content = __(
'Syndication Links, which are links to the same content on other sites, may be displayed on comments, but only if supplied by the submitter or if your comment was
generated by webmention, if they appear on your site.',
'syndication-links'
);
wp_add_privacy_policy_content(
'Syndication Links',
wp_kses_post( wpautop( $content, false ) )
);
}
}
add_action( 'admin_init', 'syndication_links_privacy_declaration' );