forked from mikefreemantn/SourceHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourcehub.php
More file actions
291 lines (252 loc) · 8.11 KB
/
sourcehub.php
File metadata and controls
291 lines (252 loc) · 8.11 KB
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
/**
* Plugin Name: SourceHub - Hub & Spoke Publisher
* Plugin URI: https://github.com/mikefreemantn/SourceHub
* Description: A powerful content syndication plugin that enables centralized editorial teams to distribute content across multiple WordPress sites with full SEO integration.
* Version: 1.8.8
* Author: Mike Freeman
* Author URI: https://manovermachine.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: sourcehub
* Domain Path: /languages
* Requires at least: 5.0
* Tested up to: 6.4
* Requires PHP: 7.4
* Network: true
*
* GitHub Plugin URI: https://github.com/mikefreemantn/SourceHub
* Primary Branch: main
*
* @package SourceHub
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('SOURCEHUB_VERSION', '1.8.8');
define('SOURCEHUB_PLUGIN_FILE', __FILE__);
define('SOURCEHUB_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('SOURCEHUB_PLUGIN_URL', plugin_dir_url(__FILE__));
define('SOURCEHUB_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Main SourceHub Plugin Class
*/
final class SourceHub {
/**
* Plugin instance
*
* @var SourceHub
*/
private static $instance = null;
/**
* Hub Manager instance
*
* @var SourceHub_Hub_Manager
*/
public $hub_manager;
/**
* Spoke Manager instance
*
* @var SourceHub_Spoke_Manager
*/
public $spoke_manager;
/**
* Yoast Integration instance
*
* @var SourceHub_Yoast_Integration
*/
public $yoast_integration;
/**
* Admin instance
*
* @var SourceHub_Admin
*/
public $admin;
/**
* API Handler instance
*
* @var SourceHub_API_Handler
*/
public $api_handler;
/**
* Calendar instance
*
* @var SourceHub_Calendar
*/
public $calendar;
/**
* Get plugin instance
*
* @return SourceHub
*/
public static function instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
$this->init_hooks();
$this->includes();
$this->init_components();
}
/**
* Initialize hooks
*/
private function init_hooks() {
add_action('init', array($this, 'init'), 0);
add_action('plugins_loaded', array($this, 'load_textdomain'));
// Activation and deactivation hooks
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
}
/**
* Include required files
*/
private function includes() {
// Load core classes
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-database.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-logger.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-hub-manager.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-spoke-manager.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-yoast-integration.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-newspaper-integration.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-ai-rewriter.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-api-handler.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-smart-links.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-shortcodes.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-validation.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-gallery-handler.php';
require_once SOURCEHUB_PLUGIN_DIR . 'includes/class-sourcehub-bug-tracker.php';
// Load admin classes
if (is_admin()) {
require_once SOURCEHUB_PLUGIN_DIR . 'admin/class-sourcehub-admin.php';
require_once SOURCEHUB_PLUGIN_DIR . 'admin/class-sourcehub-calendar.php';
}
}
/**
* Initialize plugin components
*/
private function init_components() {
$this->hub_manager = new SourceHub_Hub_Manager();
$this->spoke_manager = new SourceHub_Spoke_Manager();
$this->yoast_integration = new SourceHub_Yoast_Integration();
$this->api_handler = new SourceHub_API_Handler();
// Initialize Bug Tracker
SourceHub_Bug_Tracker::init();
// Initialize admin
if (is_admin()) {
$this->admin = new SourceHub_Admin();
$this->calendar = new SourceHub_Calendar();
}
}
/**
* Initialize plugin
*/
public function init() {
// Initialize database tables
SourceHub_Database::init();
// Load components based on mode
$mode = get_option('sourcehub_mode', 'hub');
if ($mode === 'hub') {
$this->hub_manager->init();
} elseif ($mode === 'spoke') {
$this->spoke_manager->init();
}
// Initialize the API handler for REST endpoints
$this->api_handler->init();
// Admin is initialized via constructor, no init() method needed
// Calendar init if it exists
if (is_admin() && isset($this->calendar)) {
$this->calendar->init();
}
}
/**
* Load plugin textdomain
*/
public function load_textdomain() {
load_plugin_textdomain('sourcehub', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Plugin activation
*/
public function activate() {
// Create database tables
SourceHub_Database::create_tables();
SourceHub_Bug_Tracker::create_tables();
// Verify tables were created
global $wpdb;
$connections_table = $wpdb->prefix . 'sourcehub_connections';
$logs_table = $wpdb->prefix . 'sourcehub_logs';
$queue_table = $wpdb->prefix . 'sourcehub_queue';
if ($wpdb->get_var("SHOW TABLES LIKE '$connections_table'") != $connections_table ||
$wpdb->get_var("SHOW TABLES LIKE '$logs_table'") != $logs_table ||
$wpdb->get_var("SHOW TABLES LIKE '$queue_table'") != $queue_table) {
error_log('SourceHub: Failed to create database tables during activation');
}
// Set default options
add_option('sourcehub_mode', 'hub');
add_option('sourcehub_version', SOURCEHUB_VERSION);
add_option('sourcehub_db_version', SOURCEHUB_VERSION);
add_option('sourcehub_api_key', wp_generate_password(32, false));
// Generate spoke API key if it doesn't exist
if (!get_option('sourcehub_spoke_api_key')) {
$spoke_api_key = wp_generate_password(32, false);
add_option('sourcehub_spoke_api_key', $spoke_api_key);
}
// Flush rewrite rules
flush_rewrite_rules();
// Log activation (only if tables exist)
if ($wpdb->get_var("SHOW TABLES LIKE '$logs_table'") == $logs_table) {
SourceHub_Logger::log('Plugin activated', 'INFO');
}
}
/**
* Plugin deactivation
*/
public function deactivate() {
// Flush rewrite rules
flush_rewrite_rules();
// Log deactivation
SourceHub_Logger::log('Plugin deactivated', 'INFO');
}
/**
* Get plugin mode
*
* @return string
*/
public function get_mode() {
return get_option('sourcehub_mode', 'hub');
}
/**
* Check if current site is hub
*
* @return bool
*/
public function is_hub() {
return $this->get_mode() === 'hub';
}
/**
* Check if current site is spoke
*
* @return bool
*/
public function is_spoke() {
return $this->get_mode() === 'spoke';
}
}
/**
* Get main SourceHub instance
*
* @return SourceHub
*/
function sourcehub() {
return SourceHub::instance();
}
// Initialize the plugin
sourcehub();