-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupfront-theme-exporter.php
326 lines (275 loc) · 8.99 KB
/
upfront-theme-exporter.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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/*
Plugin Name: Upfront Builder
Plugin URI: https://cp-psource.github.io/upfront-builder/
Description: Der schnellste und visuellste Weg, um ClassicPress-Themes zu erstellen. Jetzt kann jeder ClassicPress-Themes entwerfen, erstellen, exportieren, teilen und verkaufen.
Version: 1.2.4
Author: PSOURCE
Author URI: https://github.com/cp-psource
Text Domain: upfront_thx
Domain Path: /languages
License: GPLv2 or later
*/
/*
Copyright 2014-2024 PSOURCE (https://github.com/cp-psource)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
the Free Software Foundation.
*/
require 'psource/psource-plugin-update/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/cp-psource/upfront-builder',
__FILE__,
'upfront-builder'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('master');
require_once dirname(__FILE__) . '/lib/util.php';
require_once dirname(__FILE__) . '/lib/class_thx_l10n.php';
define('THX_BASENAME', basename(dirname(__FILE__)));
define('THX_PLUGIN_BASENAME', plugin_basename(__FILE__));
register_deactivation_hook(__FILE__, array('UpfrontThemeExporter', 'deactivate'));
/**
* Main plugin class
*/
class UpfrontThemeExporter {
const DOMAIN = 'upfront_thx';
/**
* Just basic, context-free bootstrap here.
*/
private function __construct() {}
/**
* Plugin deactivation hook listener
*
* Cleans up stuff after itself.
* Currently cleans up kicsktart activation notice with no
* core present dismissal flag.
*
* @since 1.1.8-BETA-1
*/
public static function deactivate () {
if (!class_exists('Thx_Kickstart')) require_once dirname(__FILE__) . '/lib/class_thx_kickstart.php';
Thx_Kickstart::clean_up();
}
/**
* Boot point.
*/
public static function dispatch () {
// Check if we have proper core version support
if (!upfront_exporter_has_upfront_version('1.4')) {
return self::_serve_compat();
}
// Check if we have Upfront-related theme active
if (upfront_thx_is_current_theme_upfront_related()) {
return self::_serve_exporter();
}
// No? Serve kickstart
return self::_serve_kickstart();
}
/**
* Serves exporter compat
*
* @return object
*/
private static function _serve_compat () {
require_once dirname(__FILE__) . '/lib/class_thx_compat.php';
return Thx_Compat::serve();
}
/**
* Serves exporter kickstart
*
* @return object
*/
private static function _serve_kickstart () {
require_once dirname(__FILE__) . '/lib/class_thx_kickstart.php';
return Thx_Kickstart::serve();
}
/**
* Serves exporter, ready to work
*
* @return object
*/
private static function _serve_exporter () {
$me = new self;
$me->_add_hooks();
return $me;
}
/**
* This is where we dispatch the context-sensitive/global hooks.
*/
private function _add_hooks () {
$this->_add_exposed_hooks();
// Just dispatch specific scope hooks.
if (upfront_exporter_is_running()) {
$this->_add_exporter_hooks();
}
$this->_add_global_hooks();
}
/**
* These hooks will *always* trigger.
* No need to wait for the rest of Upfront, set our stuff up right now.
*/
private function _add_global_hooks () {
add_action('upfront-admin_bar-process', array($this, 'add_toolbar_item'), 10, 2);
add_filter('extra_theme_headers', array($this, 'process_extra_child_theme_headers'));
if (is_admin() && !(defined('DOING_AJAX') && DOING_AJAX)) {
require_once(dirname(__FILE__) . '/lib/class_thx_admin.php');
Thx_Admin::serve();
}
$this->_load_textdomain();
// Add shared Upfront/Exporter JS resources
add_action('upfront-core-inject_dependencies', array($this, 'add_shared_scripts'));
add_filter('upfront_data', array($this, 'add_shared_data'));
// Shared - context mode popup
add_action('wp_ajax_upfront_thx-mode_context-skip', array($this, 'json_context_mode_skip'));
}
/**
* Handle data augmentation for shared resource
*
* @param array $data Data gathered this far
*
* @return array Augmented data
*/
public function add_shared_data ($data) {
$user_id = get_current_user_id();
$data['exporter_shared'] = array(
'context_mode' => (int)get_user_option('upfront-context_mode_skip', $user_id),
);
return $data;
}
/**
* Stores user preference regarding context mode popup
*
* AJAX request handler
*/
public function json_context_mode_skip () {
$result = array('error' => 1);
if (!Upfront_Permissions::current(Upfront_Permissions::BOOT)) return wp_send_json($result);
$user_id = get_current_user_id();
if (empty($user_id) || !is_numeric($user_id)) return wp_send_json($result);
$skip = (int)get_user_option('upfront-context_mode_skip', $user_id);
if ($skip) return wp_send_json($result);
update_user_option($user_id, 'upfront-context_mode_skip', 1, true);
wp_send_json(array(
'error' => 0,
));
}
/**
* This is where we inject shared scripts
*/
public function add_shared_scripts () {
if (!Upfront_Permissions::current(Upfront_Permissions::BOOT)) return false;
$deps = Upfront_CoreDependencies_Registry::get_instance();
$deps->add_script(plugins_url('app/shared.js', __FILE__));
$deps->add_style(plugins_url('styles/shared.css', __FILE__));
}
/**
* Introduces additional theme headers, supported by exporter
*
* Filters the `extra_theme_headers` hook
*
* @param array $headers Existing headers
*
* @return array Augmented headers
*/
public function process_extra_child_theme_headers ($headers=array()) {
if (!is_array($headers)) return $headers;
if (!in_array('WDP ID', $headers)) $headers[] = 'WDP ID';
if (!in_array('License', $headers)) $headers[] = 'License';
if (!in_array('License URI', $headers)) $headers[] = 'License URI';
return $headers;
}
/**
* These hooks will *always* trigger even when doing AJAX either via admin or builder
*/
private function _add_exposed_hooks () {
if ( is_admin() || upfront_exporter_is_running() ) {
require_once(dirname(__FILE__) . '/lib/class_thx_exposed.php');
Thx_Exposed::serve();
}
}
/**
* Loads translations text domain for the plugin
*/
private function _load_textdomain () {
load_plugin_textdomain(self::DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Now, this is exporter-specific.
* Wait until Upfront is ready and set us up.
*/
private function _add_exporter_hooks () {
require_once(dirname(__FILE__) . '/lib/class_thx_exporter.php');
add_action('upfront-core-initialized', array('Thx_Exporter', 'serve'));
}
/**
* Adds the builder toolbar item
*
* @param object $toolbar Toolbar object
* @param array $item Upfront item
*/
public function add_toolbar_item ($toolbar, $item) {
if (!Upfront_Permissions::current(Upfront_Permissions::BOOT)) return false;
if (empty($item['meta'])) return false; // Only actual boot item has meta set
$child = upfront_thx_is_current_theme_upfront_child();
// Swap out root items
$root_item_id = $item['id'];
$new_item_root = 'upfront-editor_builder-hub';
$new_item = array_merge($item, array(
'id' => $root_item_id,
'parent' => $new_item_root,
));
$item['id'] = $new_item_root;
unset($item['meta']);
unset($item['href']);
$toolbar->add_node($item);
$toolbar->add_node($new_item);
// Now, let's make builder menu item expandable
$toolbar->add_node(array(
'id' => 'upfront-builder-hub',
'parent' => $new_item_root,
'title' => __('UpFront-Builder', self::DOMAIN),
));
if ((bool)$child) {
// Edit current
$toolbar->add_menu(array(
'parent' => 'upfront-builder-hub',
'id' => 'upfront-builder-current_theme',
'title' => __('Aktuelles UpFront-Theme anpassen', self::DOMAIN),
'href' => home_url('/' . UpfrontThemeExporter::get_root_slug() . '/' . $child),
));
}
// Create new
$toolbar->add_menu(array(
'parent' => 'upfront-builder-hub',
'id' => 'upfront-builder-create_theme',
'title' => __('Neues UpFront-Theme erstellen', self::DOMAIN),
'href' => admin_url('admin.php?page=upfront-builder'),
));
}
/**
* Get the root slug in endpoint-agnostic manner
*
* @return string Root slug
*/
public static function get_root_slug () {
return class_exists('Upfront_Thx_Builder_VirtualPage')
? Upfront_Thx_Builder_VirtualPage::SLUG
: 'create_new'
;
}
/**
* Fetches (and caches) the plugin version number
*
* @return string Plugin version number
*/
public static function get_version () {
static $version;
if (!empty($version)) return $version;
$data = get_plugin_data(__FILE__);
if (!empty($data['Version'])) $version = $data['Version'];
return $version;
}
}
UpfrontThemeExporter::dispatch();