PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.15.1
Import WP – CSV & XML Import Export for WordPress v2.15.1
2.15.1 2.15.0 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 All 144 releases
jc-importer / class / Common / Plugin / Menu.php

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

236 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 'is_debug' => $this->importer_manager->is_debug() ? 'yes' : 'no',
153 'export_fields' => $this->get_export_fields(),
154 'registered_addons' => apply_filters('iwp/register_js', []),
155 'global_notices' => apply_filters('iwp/frontent/notices', [])
156 ));
157
158 wp_enqueue_script($this->properties->plugin_domain . '-bundle');
159
160 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');
161
162 $this->load_help_tabs();
163
164 do_action('iwp/enqueue_assets');
165 }
166
167 private function get_export_fields()
168 {
169
170 $fields = array();
171 $comments = array();
172
173 $post_types = get_post_types();
174 foreach ($post_types as $post_type => $label) {
175 $mapper = new PostMapper($post_type);
176 $fields[] = array(
177 'id' => $post_type,
178 'label' => 'Post Type: ' . $label,
179 'fields' => $mapper->get_fields()
180 );
181
182 if (post_type_supports($post_type, 'comments')) {
183 $mapper = new CommentMapper($post_type);
184 $comments[] = array(
185 'id' => 'ewp_comment_' . $post_type,
186 'label' => 'Comments: ' . $label,
187 'fields' => $mapper->get_fields()
188 );
189 }
190 }
191
192 $fields = array_merge($fields, $comments);
193
194 $mapper = new UserMapper();
195 $fields[] = array(
196 'id' => 'user',
197 'label' => 'Users',
198 'fields' => $mapper->get_fields()
199 );
200
201 $taxonomies = get_taxonomies(array(), 'objects');
202 foreach ($taxonomies as $taxonomy) {
203 $mapper = new TaxMapper($taxonomy->name);
204 $fields[] = array(
205 'id' => 'ewp_tax_' . $taxonomy->name,
206 'label' => 'Taxonomy: ' . $taxonomy->labels->name,
207 'fields' => $mapper->get_fields()
208 );
209 }
210
211
212 $fields = apply_filters('iwp/exporter/export_field_list', $fields);
213
214 return $fields;
215 }
216
217 private function load_help_tabs()
218 {
219 $screen = get_current_screen();
220
221 $screen->add_help_tab(array(
222 'id' => 'iwp_help_tab',
223 'title' => __('Overview'),
224 'content' => '<p>' . __('ImportWP allows you to import any XML or CSV file into WordPress posts, pages, users, categories and tags.', 'jc-importer') . '</p>',
225 ));
226
227 $screen->add_help_tab([
228 'id' => 'iwp_support_tab',
229 'title' => __('Plugin Support', 'jc-importer'),
230 'content' => '<p>' . __('Import WP has the following support:', 'jc-importer') . '</p>'
231 . '<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>'
232 . '<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>',
233 ]);
234 }
235 }
236