-
Notifications
You must be signed in to change notification settings - Fork 28
/
indieweb-post-kinds.php
executable file
·252 lines (215 loc) · 8.26 KB
/
indieweb-post-kinds.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
/**
* Post Kinds
*
* @link http://indieweb.org/Post_Kinds_Plugin
* @package Post Kinds
* Plugin Name: Post Kinds
* Plugin URI: https://wordpress.org/plugins/indieweb-post-kinds/
* Description: Ever want to reply to someone else's post with a post on your own site? Or to "like" someone else's post, but with your own site?
* Version: 3.7.3
* Author: David Shanske
* Author URI: https://david.shanske.com
* Text Domain: indieweb-post-kinds
* Domain Path: /languages
*/
if ( ! defined( 'POST_KINDS_KSES' ) ) {
define( 'POST_KINDS_KSES', false );
}
spl_autoload_register(
function ( $cls ) {
$base_dir = trailingslashit( __DIR__ ) . 'includes/';
$bases = array( 'Kind', 'Post_Kind', 'MF2' );
foreach ( $bases as $base ) {
if ( strncmp( $cls, $base, strlen( $base ) ) === 0 ) {
$filename = 'class-' . strtolower( str_replace( '_', '-', $cls ) );
$file = $base_dir . $filename . '.php';
if ( file_exists( $file ) ) {
require $file;
}
}
}
}
);
register_activation_hook( __FILE__, array( 'Post_Kinds_Plugin', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Post_Kinds_Plugin', 'deactivate' ) );
add_action( 'upgrader_process_complete', array( 'Post_Kinds_Plugin', 'upgrader_process_complete' ), 10, 2 );
if ( ! file_exists( plugin_dir_path( __FILE__ ) . 'lib/parse-this/parse-this.php' ) ) {
add_action( 'admin_notices', array( 'Post_Kinds_Plugin', 'parse_this_error' ) );
}
if ( Post_Kinds_Plugin::show_editor_error() ) {
add_action( 'admin_notices', array( 'Post_Kinds_Plugin', 'classic_editor_error' ) );
}
add_action( 'plugins_loaded', array( 'Post_Kinds_Plugin', 'plugins_loaded' ), 11 );
add_action( 'init', array( 'Post_Kinds_Plugin', 'init' ) );
class Post_Kinds_Plugin {
public static $version;
public static function init() {
self::$version = get_file_data( __FILE__, array( 'Version' => 'Version' ) )['Version'];
// Add Kind Taxonomy.
Kind_Taxonomy::init();
Kind_Taxonomy::register();
}
public static function parse_this_error() {
$class = 'notice notice-error';
$message = __( 'Parse This is not installed. Please advise the developer', 'indieweb-post-kinds' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
public static function show_editor_error() {
// Do not show this error in ClassicPress
if ( self::is_classicpress() ) {
return false;
}
// Do not show if less than Version 5
if ( version_compare( get_bloginfo( 'version' ), '5.0' ) <= 0 ) {
return false;
}
if ( class_exists( 'Classic_Editor' ) ) {
return false;
}
return true;
}
public static function is_classicpress() {
return function_exists( 'classicpress_version' );
}
public static function classic_editor_error() {
if ( ! self::post_uses_gutenberg() ) {
return '';
}
if ( class_exists( 'DisableGutenberg' ) || class_exists( 'Classic_Editor' ) ) {
return '';
}
$class = 'notice notice-error';
$message = __( 'Classic Editor or Disable Gutenberg Plugin is not active. The Post Kinds plugin will not function correctly at this time without using the Classic Editor.', 'indieweb-post-kinds' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
public static function upgrader_process_complete( $upgrade_object, $options ) {
$current_plugin_path_name = plugin_basename( __FILE__ );
if ( ( 'update' === $options['action'] ) && ( 'plugin' === $options['type'] ) && array_key_exists( 'plugins', $options ) ) {
foreach ( $options['plugins'] as $each_plugin ) {
if ( $each_plugin === $current_plugin_path_name ) {
flush_rewrite_rules();
}
}
}
}
public static function activate() {
Kind_Taxonomy::activate_kinds();
flush_rewrite_rules();
}
public static function deactivate() {
flush_rewrite_rules();
}
public static function plugins_loaded() {
$cls = get_called_class();
load_plugin_textdomain( 'indieweb-post-kinds', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// Add WordPress Compatibility File for Functions Introduced Post 4.9.9.
require_once plugin_dir_path( __FILE__ ) . 'includes/compat.php';
// Parse this Compat File.
require_once plugin_dir_path( __FILE__ ) . 'lib/parse-this/includes/compat-functions.php';
// Add Kind Global Functions.
require_once plugin_dir_path( __FILE__ ) . '/includes/kind-functions.php';
// Add Time Global Functions.
require_once plugin_dir_path( __FILE__ ) . '/includes/time-functions.php';
// Parse This
require_once plugin_dir_path( __FILE__ ) . 'lib/parse-this/includes/autoload.php';
if ( ! class_exists( 'REST_Parse_This' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'lib/parse-this/includes/class-rest-parse-this.php';
}
require_once plugin_dir_path( __FILE__ ) . 'lib/parse-this/includes/functions.php';
$class_load = array(
'Plugins', // Plugin Specific Customization
'Media_Metadata', // Media Metadata Enhancements
'Config', // Configuration Menu
'Metabox', // Metabox for Classic Editor
'View', // Kind Display Functionality
);
foreach ( $class_load as $load ) {
add_action( 'init', array( 'Kind_' . $load, 'init' ) );
}
// Add a Settings Link to the Plugins Page.
$plugin = plugin_basename( __FILE__ );
add_filter( "plugin_action_links_$plugin", array( 'Post_Kinds_Plugin', 'settings_link' ) );
// Load stylesheets.
add_action( 'wp_enqueue_scripts', array( $cls, 'style_load' ) );
add_action( 'admin_enqueue_scripts', array( $cls, 'admin_style_load' ) );
// Load Privacy Declaration
add_action( 'admin_init', array( $cls, 'privacy_declaration' ) );
remove_all_actions( 'do_feed_rss2' );
remove_all_actions( 'do_feed_atom' );
add_action( 'do_feed_rss2', array( $cls, 'do_feed_rss2' ), 10, 1 );
add_action( 'do_feed_atom', array( $cls, 'do_feed_atom' ), 10, 1 );
// Register Widgets
add_action(
'widgets_init',
function () {
register_widget( 'Kind_Menu_Widget' );
register_widget( 'Kind_Post_Widget' );
}
);
}
public static function do_feed_atom( $for_comments ) {
if ( $for_comments ) {
load_template( plugin_dir_path( __FILE__ ) . 'templates/feed-atom-comments.php' );
} else {
load_template( plugin_dir_path( __FILE__ ) . 'templates/feed-atom.php' );
}
}
public static function do_feed_rss2( $for_comments ) {
if ( $for_comments ) {
load_template( plugin_dir_path( __FILE__ ) . 'templates/feed-rss2-comments.php' );
} else {
load_template( plugin_dir_path( __FILE__ ) . 'templates/feed-rss2.php' );
}
}
/**
* Adds link to Plugin Page for Options Page.
*
* @access public
* @param array $links Array of Existing Links.
* @return array Modified Links.
*/
public static function settings_link( $links ) {
// Because of how Kind_Config::admin_menu() is set up, the settings page
// can be located at two different URLs; menu_page_url() finds both.
$settings_url = menu_page_url( 'kind_options', false );
$settings_link = sprintf(
'<a href="%1$s">%2$s</a>',
$settings_url,
__( 'Settings', 'indieweb-post-kinds' )
);
array_unshift( $links, $settings_link );
return $links;
}
/**
* Loads the Stylesheet for the Plugin.
*/
public static function style_load() {
wp_enqueue_style( 'kind', plugin_dir_url( __FILE__ ) . 'css/kind.min.css', array(), self::$version );
}
/**
* Loads the Admin Stylesheet for the Plugin.
*/
public static function admin_style_load() {
wp_enqueue_style( 'kind-admin', plugin_dir_url( __FILE__ ) . 'css/kind.admin.min.css', array(), self::$version );
}
public static function privacy_declaration() {
if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
$content = __(
'For responses to URLs, such as responding to a post or article, this site allows the storage of data around the post/article in order to generate a rich citation. Items such as author name and image, summary of the text, embed provided by third-party site, etc may be stored and are solely to provide this context. We will remove any of this on request.',
'indieweb-post-kinds'
);
wp_add_privacy_policy_content(
'Post Kinds',
wp_kses_post( wpautop( $content, false ) )
);
}
}
public static function post_uses_gutenberg() {
$screen = get_current_screen();
if ( ! is_object( $screen ) || 'post' !== $screen->base ) {
return true;
}
return $screen->is_block_editor;
}
}