PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.5.0
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.5.0
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 / controller.php
wp-all-export / controllers Last commit date
admin 3 weeks ago controller 3 weeks ago controller.php 3 weeks ago
controller.php
186 lines
1 <?php
2 /**
3 * Common logic for all shortcodes plugin implements
4 *
5 * @author Pavel Kulbakin <p.kulbakin@gmail.com>
6 */
7 abstract class PMXE_Controller {
8 /**
9 * Input class instance to retrieve parameters submitted during page request
10 * @var PMXE_Input
11 */
12 protected $input;
13 /**
14 * Error messages
15 * @var WP_Error
16 */
17 protected $errors;
18 /**
19 * Associative array of data which will be automatically available as variables when template is rendered
20 * @var array
21 */
22 public $data = array();
23 /**
24 * Constructor
25 */
26 public function __construct() {
27 $this->input = new PMXE_Input();
28 $this->input->addFilter('trim');
29
30 $this->errors = new WP_Error();
31
32 $this->init();
33 }
34
35 /**
36 * Method to put controller initialization logic to
37 */
38 protected function init() {}
39
40 /**
41 * Checks wether protocol is HTTPS and redirects user to secure connection if not
42 */
43 protected function force_ssl() {
44 if (force_ssl_admin() && ! is_ssl()) {
45 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
46 $http_host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : '';
47 if ( 0 === strpos( $request_uri, 'http' ) ) {
48 wp_safe_redirect(preg_replace('|^http://|', 'https://', $request_uri)); die();
49 } else {
50 wp_safe_redirect('https://' . $http_host . $request_uri); die();
51 }
52 }
53 }
54
55 /**
56 * Method returning resolved template content
57 *
58 * @param string [optional] $viewPath Template path to render
59 * @throws Exception
60 */
61 protected function render($viewPath = null) {
62
63 if ( ! get_current_user_id() or ! current_user_can( PMXE_Plugin::$capabilities )) {
64 // This nonce is not valid.
65 die( 'Security check' );
66
67 } else {
68
69 // assume template file name depending on calling function
70 if (is_null($viewPath)) {
71 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- used to derive view path from calling class/function
72 $trace = debug_backtrace();
73 $viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function'];
74 }
75 // append file extension if not specified
76 if ( ! preg_match('%\.php$%', $viewPath)) {
77 $viewPath .= '.php';
78 }
79 $filePath = PMXE_Plugin::ROOT_DIR . '/views/' . $viewPath;
80 if (is_file($filePath)) {
81 extract($this->data);
82 include $filePath;
83 } else {
84 throw new Exception( esc_html( "Requested template file $filePath is not found." ) );
85 }
86 }
87 }
88
89 /**
90 * Display list of errors
91 *
92 * @param string|array|WP_Error[optional] $msgs
93 */
94 protected function error($msgs = NULL) {
95 if (is_null($msgs)) {
96 $msgs = $this->errors;
97 }
98 if (is_wp_error($msgs))
99 {
100 unset($msgs->errors['count-validation']);
101
102 $msgs = $msgs->get_error_messages();
103 }
104 if ( ! is_array($msgs)) {
105 $msgs = array($msgs);
106 }
107 $this->data['errors'] = $msgs;
108
109 $viewPathRel = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower(get_class($this)))) . '/error.php';
110 if (is_file(PMXE_Plugin::ROOT_DIR . '/views/' . $viewPathRel)) { // if calling controller class has specific error view
111 $this->render($viewPathRel);
112 } else { // render default error view
113 $this->render('controller/error.php');
114 }
115 }
116
117 public function download(){
118
119
120 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce verified on next line
121 $nonce = (!empty($_REQUEST['_wpnonce'])) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
122 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_feed' ) ) {
123 die( esc_html__('Security check', 'wp-all-export') );
124 } else {
125
126 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
127
128 $id = $this->input->get('id');
129
130 $export = new PMXE_Export_Record();
131
132 $filepath = '';
133
134 if ( ! $export->getById($id)->isEmpty())
135 {
136 if($export->options['export_to'] != XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS && isset($_GET['google_feed'])) {
137 die('Unauthorized');
138 }
139 if ( ! $is_secure_import)
140 {
141 $filepath = get_attached_file($export->attch_id);
142 }
143 else
144 {
145 $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
146 }
147 if ( @file_exists($filepath) )
148 {
149 switch ($export['options']['export_to'])
150 {
151 case XmlExportEngine::EXPORT_TYPE_XML:
152
153 if($export['options']['xml_template_type'] == XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS) {
154 PMXE_download::txt($filepath);
155 } else {
156 PMXE_download::xml($filepath);
157 }
158
159 break;
160 case XmlExportEngine::EXPORT_TYPE_CSV:
161 if (empty($export->options['export_to_sheet']) or $export->options['export_to_sheet'] == 'csv')
162 {
163 PMXE_download::csv($filepath);
164 }
165 else
166 {
167 switch ($export->options['export_to_sheet']){
168 case 'xls':
169 PMXE_download::xls($filepath);
170 break;
171 case 'xlsx':
172 PMXE_download::xlsx($filepath);
173 break;
174 }
175 }
176 break;
177
178 default:
179
180 break;
181 }
182 }
183 }
184 }
185 }
186 }