PluginProbe
Import WP – CSV & XML Import Export for WordPress / trunk
Import WP – CSV & XML Import Export for WordPress vtrunk
2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 trunk 0.1.6 All 142 releases
jc-importer / class / Common / Plugin / Menu.php

Menu.php in Import WP – CSV & XML Import Export for WordPress trunk, at class/Common/Plugin/Menu.php

235 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Plugin;
4
5 use ImportWP\Common\Exporter\Mapper\CommentMapper;
6 use ImportWP\Common\Exporter\Mapper\PostMapper;
7 use ImportWP\Common\Exporter\Mapper\TaxMapper;
8 use ImportWP\Common\Exporter\Mapper\UserMapper;
9 use ImportWP\Common\Importer\ImporterManager;
10 use ImportWP\Common\Importer\Template\TemplateManager;
11 use ImportWP\Common\Migration\Migrations;
12 use ImportWP\Common\Properties\Properties;
13 use ImportWP\Common\UI\ViewManager;
14
15 class Menu
16 {
17 /**
18 * @var Properties
19 */
20 private $properties;
21 /**
22 * @var ViewManager
23 */
24 private $view_manager;
25 /**
26 * @var ImporterManager
27 */
28 private $importer_manager;
29 /**
30 * @var TemplateManager $template_manager
31 */
32 private $template_manager;
33
34 public function __construct(Properties $properties, ViewManager $view_manager, ImporterManager $importer_manager, TemplateManager $template_manager)
35 {
36 $this->properties = $properties;
37 $this->view_manager = $view_manager;
38 $this->importer_manager = $importer_manager;
39 $this->template_manager = $template_manager;
40
41 add_action('admin_menu', array($this, 'register_tools_menu'));
42 add_action('tool_box', array($this->view_manager, 'tool_box'));
43 add_filter('plugin_action_links_' . $this->properties->plugin_basename, array($this, 'add_plugin_links'));
44 add_filter('update_footer', [$this, 'add_footer_text_right'], 20);
45 add_filter('admin_footer_text', [$this, 'add_footer_text_left']);
46 }
47
48 public function add_footer_text_left($text)
49 {
50 $screen = get_current_screen();
51 if ($screen->id !== 'tools_page_importwp') {
52 return $text;
53 }
54
55 return '<a target="_blank" href="https://www.importwp.com/support/">Contact support</a> | Add your <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/jc-importer#postform">�
56
57
58
59
60 </a> on <a target="_blank" href="http://wordpress.org/plugins/jc-importer/">wordpress.org</a>';
61 }
62
63 public function add_footer_text_right($text)
64 {
65 $screen = get_current_screen();
66 if ($screen->id !== 'tools_page_importwp') {
67 return $text;
68 }
69
70 return '<a class="iwp-footer-link" target="_blank" href="https://translate.wordpress.org/projects/wp-plugins/jc-importer/"><span class="dashicons dashicons-translation"></span> Translate</a> |
71 <a class="iwp-footer-link" target="_blank" href="https://www.importwp.com/documentation/?utm_campaign=support%2Bdocs&utm_source=Import%2BWP%2BFree&utm_medium=footer">View Documentation</a> |
72 ImportWP v' . IWP_VERSION . (defined('IWP_PRO_VERSION') ? ' | ImportWP PRO v' . IWP_PRO_VERSION : '');
73 }
74
75 public function register_tools_menu()
76 {
77 $title = __('Import WP', $this->properties->plugin_domain);
78
79 $hook_suffix = add_management_page($title, $title, 'export', $this->properties->plugin_domain, array(
80 $this->view_manager,
81 'plugin_page'
82 ));
83
84 add_action('load-' . $hook_suffix, array($this, 'load_assets'));
85 }
86
87 public function add_plugin_links($links)
88 {
89 return array_merge(
90 [
91 '<a href="' .
92 admin_url('tools.php?page=' . $this->properties->plugin_domain) .
93 '">' . __('Dashboard', 'jc-importer') . '</a>',
94 '<a href="' .
95 admin_url('tools.php?page=' . $this->properties->plugin_domain . '&tab=settings') .
96 '">' . __('Settings', 'jc-importer') . '</a>',
97 ],
98 $links
99 );
100 }
101
102 public function load_assets()
103 {
104 $asset_file = include(plugin_dir_path($this->properties->plugin_file_path) . 'dist/index.asset.php');
105
106 wp_register_script($this->properties->plugin_domain . '-bundle', plugin_dir_url($this->properties->plugin_file_path) . 'dist/index.js', $asset_file['dependencies'], $asset_file['version'], 'all');
107
108 $matches = false;
109 preg_match('/^https?:\/\/[^\/]+(.*?)$/', admin_url('/tools.php?page=' . $this->properties->plugin_domain), $matches);
110 $ajax_base = $matches[1];
111
112 /**
113 * Generate template data
114 */
115 $templates = $this->importer_manager->get_templates();
116 $template_data = [];
117 foreach ($templates as $template_id => $template) {
118
119 $template_class = $this->template_manager->load_template($template);
120 $unique_fields = $this->template_manager->get_template_unique_fields($template_class);
121
122 $template_data[] = [
123 'id' => $template_id,
124 'label' => $template_class->get_name(),
125 'map' => [],
126 'settings' => $template_class->register_settings(),
127 'options' => $template_class->register_options(),
128 'unique_fields' => $unique_fields
129 ];
130 }
131
132 $migrations = new Migrations();
133 $is_setup = $migrations->isSetup() ? 'yes' : 'no';
134
135 $pro_version = '';
136 if (defined('IWP_PRO_VERSION') && $this->properties->is_pro) {
137 $pro_version .= ' (v' . IWP_PRO_VERSION . ' PRO)';
138 }
139
140 wp_localize_script($this->properties->plugin_domain . '-bundle', 'iwp', array(
141 'root' => esc_url_raw(rest_url()),
142 'nonce' => wp_create_nonce('wp_rest'),
143 'download_nonce' => wp_create_nonce('iwp_export_download'),
144 'admin_base' => $ajax_base,
145 'ajax_base' => rest_url('/' . $this->properties->rest_namespace . '/' . $this->properties->rest_version),
146 'templates' => $template_data,
147 'is_setup' => $is_setup,
148 'plugin_url' => plugin_dir_url($this->properties->plugin_file_path),
149 'version' => 'v' . $this->properties->plugin_version . $pro_version,
150 'encodings' => $this->properties->encodings,
151 'is_pro' => $this->properties->is_pro ? 'yes' : 'no',
152 'export_fields' => $this->get_export_fields(),
153 'registered_addons' => apply_filters('iwp/register_js', []),
154 'global_notices' => apply_filters('iwp/frontent/notices', [])
155 ));
156
157 wp_enqueue_script($this->properties->plugin_domain . '-bundle');
158
159 wp_enqueue_style($this->properties->plugin_domain . '-bundle-styles', plugin_dir_url($this->properties->plugin_file_path) . 'dist/index.css', array(), $asset_file['version'], 'all');
160
161 $this->load_help_tabs();
162
163 do_action('iwp/enqueue_assets');
164 }
165
166 private function get_export_fields()
167 {
168
169 $fields = array();
170 $comments = array();
171
172 $post_types = get_post_types();
173 foreach ($post_types as $post_type => $label) {
174 $mapper = new PostMapper($post_type);
175 $fields[] = array(
176 'id' => $post_type,
177 'label' => 'Post Type: ' . $label,
178 'fields' => $mapper->get_fields()
179 );
180
181 if (post_type_supports($post_type, 'comments')) {
182 $mapper = new CommentMapper($post_type);
183 $comments[] = array(
184 'id' => 'ewp_comment_' . $post_type,
185 'label' => 'Comments: ' . $label,
186 'fields' => $mapper->get_fields()
187 );
188 }
189 }
190
191 $fields = array_merge($fields, $comments);
192
193 $mapper = new UserMapper();
194 $fields[] = array(
195 'id' => 'user',
196 'label' => 'Users',
197 'fields' => $mapper->get_fields()
198 );
199
200 $taxonomies = get_taxonomies(array(), 'objects');
201 foreach ($taxonomies as $taxonomy) {
202 $mapper = new TaxMapper($taxonomy->name);
203 $fields[] = array(
204 'id' => 'ewp_tax_' . $taxonomy->name,
205 'label' => 'Taxonomy: ' . $taxonomy->labels->name,
206 'fields' => $mapper->get_fields()
207 );
208 }
209
210
211 $fields = apply_filters('iwp/exporter/export_field_list', $fields);
212
213 return $fields;
214 }
215
216 private function load_help_tabs()
217 {
218 $screen = get_current_screen();
219
220 $screen->add_help_tab(array(
221 'id' => 'iwp_help_tab',
222 'title' => __('Overview'),
223 'content' => '<p>' . __('ImportWP allows you to import any XML or CSV file into WordPress posts, pages, users, categories and tags.', 'jc-importer') . '</p>',
224 ));
225
226 $screen->add_help_tab([
227 'id' => 'iwp_support_tab',
228 'title' => __('Plugin Support', 'jc-importer'),
229 'content' => '<p>' . __('Import WP has the following support:', 'jc-importer') . '</p>'
230 . '<p>' . sprintf(__('documentation Online documentation can be found at %s', 'jc-importer'), '<a href="https://www.importwp.com/docs/?utm_campaign=support%2Bdocs&utm_source=Import%2BWP%2BFree&utm_medium=help%2Btab" target="_blank">https://www.importwp.com/docs/</a>') . '</p>'
231 . '<p>' . sprintf(__('Support Tickets — Support requests are handled on our support system at %s', 'jc-importer'), '<a href="https://helpdesk.importwp.com/" target="_blank">https://helpdesk.importwp.com/</a>') . '</p>',
232 ]);
233 }
234 }
235