-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-remote-sync.php
156 lines (130 loc) · 3.16 KB
/
wp-remote-sync.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
<?php
require_once __DIR__."/src/plugin/RemoteSyncPlugin.php";
require_once __DIR__."/src/model/SyncResource.php";
require_once __DIR__."/src/controller/ScheduledSyncController.php";
/*
Plugin Name: Remote Sync
Plugin URI: http://github.com/tunapanda/wp-remote-sync
Description: Sync content with a remote site in a similar way to a distributed version control system.
Version: 0.1.28
GitHub Plugin URI: https://github.com/tunapanda/wp-remote-sync
*/
/**
* Create the admin menu.
*/
function rs_admin_menu() {
add_options_page(
'Remote Sync',
'Remote Sync',
'manage_options',
'rs_main',
'rs_main'
);
add_submenu_page(
'options.php',
'Remote Sync',
'Remote Sync',
'manage_options',
'rs_sync_preview',
'rs_sync_preview'
);
add_submenu_page(
'options.php',
'Remote Sync',
'Remote Sync',
'manage_options',
'rs_sync',
'rs_sync'
);
// test
add_submenu_page(
'options.php',
'Remote Sync Operations',
'Remote Sync Operations',
'manage_options',
'rs_view_test',
'rs_view_test'
);
}
/**
* Show the sync preview page.
*/
function rs_sync_preview() {
require_once __DIR__."/src/controller/RemoteSyncPageController.php";
$controller=new RemoteSyncPageController();
$controller->showSyncPreview();
}
/**
* Show main page.
*/
function rs_main() {
require_once __DIR__."/src/controller/RemoteSyncPageController.php";
$controller=new RemoteSyncPageController();
$controller->showMain();
}
/**
* The sync page.
*/
function rs_sync() {
echo "<style>";
require __DIR__."/wp-remote-sync.css";
echo "</style>";
require_once __DIR__."/src/controller/RemoteSyncPageController.php";
$controller=new RemoteSyncPageController();
$controller->showSync();
}
/**
* Test view.
*/
function rs_view_test() {
switch ($_REQUEST["case"]) {
case "syncpreview":
require __DIR__."/tests/view/resourcelisttest.php";
break;
case "sync":
require __DIR__."/tests/view/synctest.php";
break;
default:
echo "No such test case.";
exit;
}
}
add_action('admin_menu','rs_admin_menu');
/**
* Activate.
*/
function rs_activate() {
if (!function_exists("curl_init"))
trigger_error("wp-remote-sync requires the cURL module",E_USER_ERROR);
RemoteSyncPlugin::instance()->install();
}
/**
* Deactivate.
*/
function rs_deactivate() {
wp_clear_scheduled_hook('rs_scheduled_sync');
}
/**
* Uninstall.
*/
function rs_uninstall() {
SyncResource::uninstall();
delete_option("rs_remote_site_url");
delete_option("rs_access_key");
delete_option("rs_download_access_key");
delete_option("rs_upload_access_key");
delete_option("rs_resulotion_strategy");
}
register_activation_hook(__FILE__,'rs_activate');
register_deactivation_hook(__FILE__,'rs_deactivate');
register_uninstall_hook(__FILE__,'rs_uninstall');
/**
* Wp cli interface.
*/
if (class_exists("WP_CLI")) {
require_once __DIR__."/src/controller/WpCliController.php";
WP_CLI::add_command("remote status",array(WpCliController::instance(),'status'));
WP_CLI::add_command("remote sync",array(WpCliController::instance(),'sync'));
WP_CLI::add_command("remote revert",array(WpCliController::instance(),'revert'));
}
add_action("rs_scheduled_sync",array(ScheduledSyncController::instance(),"run"));