PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.0
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.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 8 years ago controller 8 years ago controller.php 8 years ago
controller.php
182 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 if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
46 wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); die();
47 } else {
48 wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); die();
49 }
50 }
51 }
52
53 /**
54 * Method returning resolved template content
55 *
56 * @param string [optional] $viewPath Template path to render
57 * @throws Exception
58 */
59 protected function render($viewPath = null) {
60
61 if ( ! get_current_user_id() or ! current_user_can( PMXE_Plugin::$capabilities )) {
62 // This nonce is not valid.
63 die( 'Security check' );
64
65 } else {
66
67 // assume template file name depending on calling function
68 if (is_null($viewPath)) {
69 $trace = debug_backtrace();
70 $viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function'];
71 }
72 // append file extension if not specified
73 if ( ! preg_match('%\.php$%', $viewPath)) {
74 $viewPath .= '.php';
75 }
76 $filePath = PMXE_Plugin::ROOT_DIR . '/views/' . $viewPath;
77 if (is_file($filePath)) {
78 extract($this->data);
79 include $filePath;
80 } else {
81 throw new Exception("Requested template file $filePath is not found.");
82 }
83 }
84 }
85
86 /**
87 * Display list of errors
88 *
89 * @param string|array|WP_Error[optional] $msgs
90 */
91 protected function error($msgs = NULL) {
92 if (is_null($msgs)) {
93 $msgs = $this->errors;
94 }
95 if (is_wp_error($msgs))
96 {
97 unset($msgs->errors['count-validation']);
98
99 $msgs = $msgs->get_error_messages();
100 }
101 if ( ! is_array($msgs)) {
102 $msgs = array($msgs);
103 }
104 $this->data['errors'] = $msgs;
105
106 $viewPathRel = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower(get_class($this)))) . '/error.php';
107 if (is_file(PMXE_Plugin::ROOT_DIR . '/views/' . $viewPathRel)) { // if calling controller class has specific error view
108 $this->render($viewPathRel);
109 } else { // render default error view
110 $this->render('controller/error.php');
111 }
112 }
113
114 public function download(){
115
116
117 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
118 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_feed' ) && !isset($_GET['google_feed']) ) {
119 die( __('Security check', 'wp_all_export_plugin') );
120 } else {
121
122 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
123
124 $id = $this->input->get('id');
125
126 $export = new PMXE_Export_Record();
127
128 $filepath = '';
129
130 if ( ! $export->getById($id)->isEmpty())
131 {
132 if($export->options['export_to'] != XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS && isset($_GET['google_feed'])) {
133 die('Unauthorized');
134 }
135 if ( ! $is_secure_import)
136 {
137 $filepath = get_attached_file($export->attch_id);
138 }
139 else
140 {
141 $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
142 }
143 if ( @file_exists($filepath) )
144 {
145 switch ($export['options']['export_to'])
146 {
147 case XmlExportEngine::EXPORT_TYPE_XML:
148
149 if($export['options']['xml_template_type'] == XmlExportEngine::EXPORT_TYPE_GOOLE_MERCHANTS) {
150 PMXE_download::txt($filepath);
151 } else {
152 PMXE_download::xml($filepath);
153 }
154
155 break;
156 case XmlExportEngine::EXPORT_TYPE_CSV:
157 if (empty($export->options['export_to_sheet']) or $export->options['export_to_sheet'] == 'csv')
158 {
159 PMXE_download::csv($filepath);
160 }
161 else
162 {
163 switch ($export->options['export_to_sheet']){
164 case 'xls':
165 PMXE_download::xls($filepath);
166 break;
167 case 'xlsx':
168 PMXE_download::xlsx($filepath);
169 break;
170 }
171 }
172 break;
173
174 default:
175
176 break;
177 }
178 }
179 }
180 }
181 }
182 }