PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.0.5
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.0.5
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 10 years ago controller 10 years ago controller.php 10 years ago
controller.php
159 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 */
58 protected function render($viewPath = null) {
59
60 if ( ! get_current_user_id() or ! current_user_can(PMXE_Plugin::$capabilities)) {
61 // This nonce is not valid.
62 die( 'Security check' );
63
64 } else {
65
66 // assume template file name depending on calling function
67 if (is_null($viewPath)) {
68 $trace = debug_backtrace();
69 $viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function'];
70 }
71 // append file extension if not specified
72 if ( ! preg_match('%\.php$%', $viewPath)) {
73 $viewPath .= '.php';
74 }
75 $filePath = PMXE_Plugin::ROOT_DIR . '/views/' . $viewPath;
76 if (is_file($filePath)) {
77 extract($this->data);
78 include $filePath;
79 } else {
80 throw new Exception("Requested template file $filePath is not found.");
81 }
82 }
83 }
84
85 /**
86 * Display list of errors
87 *
88 * @param string|array|WP_Error[optional] $msgs
89 */
90 protected function error($msgs = NULL) {
91 if (is_null($msgs)) {
92 $msgs = $this->errors;
93 }
94 if (is_wp_error($msgs))
95 {
96 unset($msgs->errors['count-validation']);
97
98 $msgs = $msgs->get_error_messages();
99 }
100 if ( ! is_array($msgs)) {
101 $msgs = array($msgs);
102 }
103 $this->data['errors'] = $msgs;
104
105 $viewPathRel = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXE_Plugin::PREFIX, '%') . '%', '', strtolower(get_class($this)))) . '/error.php';
106 if (is_file(PMXE_Plugin::ROOT_DIR . '/views/' . $viewPathRel)) { // if calling controller class has specific error view
107 $this->render($viewPathRel);
108 } else { // render default error view
109 $this->render('controller/error.php');
110 }
111 }
112
113 public function download(){
114
115 $nonce = (!empty($_REQUEST['_wpnonce'])) ? $_REQUEST['_wpnonce'] : '';
116 if ( ! wp_verify_nonce( $nonce, '_wpnonce-download_feed' ) ) {
117 die( __('Security check', 'wp_all_export_plugin') );
118 } else {
119
120 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
121
122 $id = $this->input->get('id');
123
124 $export = new PMXE_Export_Record();
125
126 $filepath = '';
127
128 if ( ! $export->getById($id)->isEmpty())
129 {
130 if ( ! $is_secure_import)
131 {
132 $filepath = get_attached_file($export->attch_id);
133 }
134 else
135 {
136 $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
137 }
138
139 if ( @file_exists($filepath) )
140 {
141 switch ($export['options']['export_to'])
142 {
143 case 'xml':
144 PMXE_download::xml($filepath);
145 break;
146 case 'csv':
147 PMXE_download::csv($filepath);
148 break;
149
150 default:
151
152 break;
153 }
154 }
155 }
156 }
157
158 }
159 }