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