PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.10
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.10
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 4 years ago feedback.php 4 years ago help.php 4 years ago manage.php 4 years ago settings.php 4 years ago
settings.php
182 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(add_query_arg('pmxe_nt', urlencode(__('Settings saved', 'wp_all_export_plugin')), $this->baseUrl)); die();
34 }
35 }
36
37 if ($this->input->post('is_scheduling_license_submitted')) {
38
39 check_admin_referer('edit-license', '_wpnonce_edit-scheduling-license');
40
41 if (!$this->errors->get_error_codes()) { // no validation errors detected
42
43 PMXE_Plugin::getInstance()->updateOption($post);
44 if (empty($_POST['pmxe_scheduling_license_activate']) and empty($_POST['pmxe_scheduling_license_deactivate'])) {
45 $post['scheduling_license_status'] = $this->check_scheduling_license();
46 if ($post['scheduling_license_status'] == 'valid') {
47
48 $this->data['scheduling_license_message'] = __('License activated.', 'wp_all_import_plugin');
49 }
50
51 PMXE_Plugin::getInstance()->updateOption($post);
52 $this->activate_scheduling_licenses();
53
54 }
55 }
56
57 $this->data['post'] = $post = PMXE_Plugin::getInstance()->getOption();
58 }
59
60
61 $post['scheduling_license_status'] = $this->check_scheduling_license();
62 $this->data['is_license_active'] = false;
63 if (!empty($post['license_status']) && $post['license_status'] == 'valid') {
64 $this->data['is_license_active'] = true;
65 }
66
67 $this->data['is_scheduling_license_active'] = false;
68 if (!empty($post['scheduling_license_status']) && $post['scheduling_license_status'] == 'valid') {
69 $this->data['is_scheduling_license_active'] = true;
70 }
71
72 if ($this->input->post('is_templates_submitted')) { // delete templates form
73
74 check_admin_referer('delete-templates', '_wpnonce_delete-templates');
75
76 if ($this->input->post('import_templates')){
77
78 if (!empty($_FILES)){
79 $file_name = $_FILES['template_file']['name'];
80 $file_size = $_FILES['template_file']['size'];
81 $tmp_name = $_FILES['template_file']['tmp_name'];
82
83 if(isset($file_name))
84 {
85 $filename = stripslashes($file_name);
86 $extension = strtolower(pmxe_getExtension($filename));
87
88 if (($extension != "txt"))
89 {
90 $this->errors->add('form-validation', __('Unknown File extension. Only txt files are permitted', 'wp_all_export_plugin'));
91 }
92 else {
93 $import_data = @file_get_contents($tmp_name);
94 if (!empty($import_data)){
95 $templates_data = json_decode($import_data, true);
96
97 if (!empty($templates_data)){
98 $templateOptions = empty($templates_data[0]['options']) ? false : unserialize($templates_data[0]['options']);
99 if ( empty($templateOptions) ){
100 $this->errors->add('form-validation', __('The template is invalid. Options are missing.', 'wp_all_export_plugin'));
101 }
102 else{
103 if (!isset($templateOptions['is_user_export'])){
104 $this->errors->add('form-validation', __('The template you\'ve uploaded is intended to be used with WP All Import plugin.', 'wp_all_export_plugin'));
105 }
106 else{
107 $template = new PMXE_Template_Record();
108 foreach ($templates_data as $template_data) {
109 unset($template_data['id']);
110 $template->clear()->set($template_data)->insert();
111 }
112 wp_redirect(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));
113 die();
114 }
115 }
116 }
117 else $this->errors->add('form-validation', __('Wrong imported data format', 'wp_all_export_plugin'));
118 }
119 else $this->errors->add('form-validation', __('File is empty or doesn\'t exests', 'wp_all_export_plugin'));
120 }
121 }
122 else $this->errors->add('form-validation', __('Undefined entry!', 'wp_all_export_plugin'));
123 }
124 else $this->errors->add('form-validation', __('Please select file.', 'wp_all_export_plugin'));
125
126 }
127 else{
128 $templates_ids = $this->input->post('templates', array());
129 if (empty($templates_ids)) {
130 $this->errors->add('form-validation', __('Templates must be selected', 'wp_all_export_plugin'));
131 }
132
133 if ( ! $this->errors->get_error_codes()) { // no validation errors detected
134 if ($this->input->post('delete_templates')){
135 $template = new PMXE_Template_Record();
136 foreach ($templates_ids as $template_id) {
137 $template->clear()->set('id', $template_id)->delete();
138 }
139 wp_redirect(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)); die();
140 }
141 if ($this->input->post('export_templates')){
142 $export_data = array();
143 $template = new PMXE_Template_Record();
144 foreach ($templates_ids as $template_id) {
145 $export_data[] = $template->clear()->getBy('id', $template_id)->toArray(TRUE);
146 }
147
148 $uploads = wp_upload_dir();
149 $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::TEMP_DIRECTORY;
150 $export_file_name = "templates_".uniqid().".txt";
151 file_put_contents($targetDir . DIRECTORY_SEPARATOR . $export_file_name, json_encode($export_data));
152
153 PMXE_download::csv($targetDir . DIRECTORY_SEPARATOR . $export_file_name);
154
155 }
156 }
157 }
158 }
159
160 $this->render();
161
162 }
163
164 public function dismiss(){
165
166 PMXE_Plugin::getInstance()->updateOption("dismiss", 1);
167
168 exit('OK');
169 }
170
171 protected function activate_scheduling_licenses()
172 {
173 return $this->licenseActivator->activateLicense(PMXE_Plugin::getSchedulingName(),\Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING);
174 }
175
176 public function check_scheduling_license()
177 {
178 $options = PMXE_Plugin::getInstance()->getOption();
179
180 return $this->licenseActivator->checkLicense(PMXE_Plugin::getSchedulingName(), $options, \Wpae\App\Service\License\LicenseActivator::CONTEXT_SCHEDULING);
181 }
182 }