PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.4.13
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.4.13
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / controllers / admin / settings.php
wp-all-export / controllers / admin Last commit date
export.php 2 years ago feedback.php 10 years ago help.php 12 years ago manage.php 4 years ago partners.php 8 months ago settings.php 4 years ago
settings.php
184 lines
1 <?php
2 /**
3 * Admin Statistics page
4 *
5 * @author Pavel Kulbakin <p.kulbakin@gmail.com>
6 */
7 class PMXE_Admin_Settings extends PMXE_Controller_Admin {
8
9 /** @var \Wpae\App\Service\License\LicenseActivator */
10 private $licenseActivator;
11
12 protected function init()
13 {
14 $this->licenseActivator = new \Wpae\App\Service\License\LicenseActivator();
15 }
16
17 public function index() {
18
19 global $wp_roles;
20
21 $this->data['roles'] = $wp_roles->roles;
22
23 $this->data['post'] = $post = $this->input->post(PMXE_Plugin::getInstance()->getOption());
24
25 if ($this->input->post('is_settings_submitted')) { // save settings form
26
27 check_admin_referer('edit-settings', '_wpnonce_edit-settings');
28
29 if ( ! $this->errors->get_error_codes()) { // no validation errors detected
30
31 PMXE_Plugin::getInstance()->updateOption($post);
32
33 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Settings saved', 'wp_all_export_plugin')), $this->baseUrl)));
34 die();
35 }
36 }
37
38 if ($this->input->post('is_scheduling_license_submitted')) {
39
40 check_admin_referer('edit-license', '_wpnonce_edit-scheduling-license');
41
42 if (!$this->errors->get_error_codes()) { // no validation errors detected
43
44 PMXE_Plugin::getInstance()->updateOption($post);
45 if (empty($_POST['pmxe_scheduling_license_activate']) and empty($_POST['pmxe_scheduling_license_deactivate'])) {
46 $post['scheduling_license_status'] = $this->check_scheduling_license();
47 if ($post['scheduling_license_status'] == 'valid') {
48
49 $this->data['scheduling_license_message'] = __('License activated.', 'wp_all_import_plugin');
50 }
51
52 PMXE_Plugin::getInstance()->updateOption($post);
53 $this->activate_scheduling_licenses();
54
55 }
56 }
57
58 $this->data['post'] = $post = PMXE_Plugin::getInstance()->getOption();
59 }
60
61
62 $post['scheduling_license_status'] = $this->check_scheduling_license();
63 $this->data['is_license_active'] = false;
64 if (!empty($post['license_status']) && $post['license_status'] == 'valid') {
65 $this->data['is_license_active'] = true;
66 }
67
68 $this->data['is_scheduling_license_active'] = false;
69 if (!empty($post['scheduling_license_status']) && $post['scheduling_license_status'] == 'valid') {
70 $this->data['is_scheduling_license_active'] = true;
71 }
72
73 if ($this->input->post('is_templates_submitted')) { // delete templates form
74
75 check_admin_referer('delete-templates', '_wpnonce_delete-templates');
76
77 if ($this->input->post('import_templates')){
78
79 if (!empty($_FILES)){
80 $file_name = $_FILES['template_file']['name'];
81 $file_size = $_FILES['template_file']['size'];
82 $tmp_name = $_FILES['template_file']['tmp_name'];
83
84 if(isset($file_name))
85 {
86 $filename = stripslashes($file_name);
87 $extension = strtolower(pmxe_getExtension($filename));
88
89 if (($extension != "txt"))
90 {
91 $this->errors->add('form-validation', __('Unknown File extension. Only txt files are permitted', 'wp_all_export_plugin'));
92 }
93 else {
94 $import_data = @file_get_contents($tmp_name);
95 if (!empty($import_data)){
96 $templates_data = json_decode($import_data, true);
97
98 if (!empty($templates_data)){
99 $templateOptions = empty($templates_data[0]['options']) ? false : unserialize($templates_data[0]['options']);
100 if ( empty($templateOptions) ){
101 $this->errors->add('form-validation', __('The template is invalid. Options are missing.', 'wp_all_export_plugin'));
102 }
103 else{
104 if (!isset($templateOptions['is_user_export'])){
105 $this->errors->add('form-validation', __('The template you\'ve uploaded is intended to be used with WP All Import plugin.', 'wp_all_export_plugin'));
106 }
107 else{
108 $template = new PMXE_Template_Record();
109 foreach ($templates_data as $template_data) {
110 unset($template_data['id']);
111 $template->clear()->set($template_data)->insert();
112 }
113 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template imported', '%d templates imported', count($templates_data), 'wp_all_export_plugin'), count($templates_data))), $this->baseUrl)));
114 die();
115 }
116 }
117 }
118 else $this->errors->add('form-validation', __('Wrong imported data format', 'wp_all_export_plugin'));
119 }
120 else $this->errors->add('form-validation', __('File is empty or doesn\'t exests', 'wp_all_export_plugin'));
121 }
122 }
123 else $this->errors->add('form-validation', __('Undefined entry!', 'wp_all_export_plugin'));
124 }
125 else $this->errors->add('form-validation', __('Please select file.', 'wp_all_export_plugin'));
126
127 }
128 else{
129 $templates_ids = $this->input->post('templates', array());
130 if (empty($templates_ids)) {
131 $this->errors->add('form-validation', __('Templates must be selected', 'wp_all_export_plugin'));
132 }
133
134 if ( ! $this->errors->get_error_codes()) { // no validation errors detected
135 if ($this->input->post('delete_templates')){
136 $template = new PMXE_Template_Record();
137 foreach ($templates_ids as $template_id) {
138 $template->clear()->set('id', $template_id)->delete();
139 }
140 wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template deleted', '%d templates deleted', count($templates_ids), 'wp_all_export_plugin'), count($templates_ids))), $this->baseUrl)));
141 die();
142 }
143 if ($this->input->post('export_templates')){
144 $export_data = array();
145 $template = new PMXE_Template_Record();
146 foreach ($templates_ids as $template_id) {
147 $export_data[] = $template->clear()->getBy('id', $template_id)->toArray(TRUE);
148 }
149
150 $uploads = wp_upload_dir();
151 $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY;
152 $export_file_name = "templates_".uniqid().".txt";
153 file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
154
155 PMXE_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
156
157 }
158 }
159 }
160 }
161
162 $this->render();
163
164 }
165
166 public function dismiss(){
167
168 PMXE_Plugin::getInstance()->updateOption("dismiss", 1);
169
170 exit('OK');
171 }
172
173 protected function activate_scheduling_licenses()
174 {
175 return $this->licenseActivator->activateLicense(PMXE_Plugin::getSchedulingName(),\Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING);
176 }
177
178 public function check_scheduling_license()
179 {
180 $options = PMXE_Plugin::getInstance()->getOption();
181
182 return $this->licenseActivator->checkLicense(PMXE_Plugin::getSchedulingName(), $options, \Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING);
183 }
184 }