PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 3.0
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v3.0
3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / controllers / controller.php
wp-all-import / controllers Last commit date
admin 13 years ago controller 13 years ago controller.php 13 years ago
controller.php
102 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 PMXI_Controller {
8 /**
9 * Input class instance to retrieve parameters submitted during page request
10 * @var PMXI_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 PMXI_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 // assume template file name depending on calling function
60 if (is_null($viewPath)) {
61 $trace = debug_backtrace();
62 $viewPath = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXI_Plugin::PREFIX, '%') . '%', '', strtolower($trace[1]['class']))) . '/' . $trace[1]['function'];
63 }
64 // append file extension if not specified
65 if ( ! preg_match('%\.php$%', $viewPath)) {
66 $viewPath .= '.php';
67 }
68 $filePath = PMXI_Plugin::ROOT_DIR . '/views/' . $viewPath;
69 if (is_file($filePath)) {
70 extract($this->data);
71 include $filePath;
72 } else {
73 throw new Exception("Requested template file $filePath is not found.");
74 }
75 }
76
77 /**
78 * Display list of errors
79 *
80 * @param string|array|WP_Error[optional] $msgs
81 */
82 protected function error($msgs = NULL) {
83 if (is_null($msgs)) {
84 $msgs = $this->errors;
85 }
86 if (is_wp_error($msgs)) {
87 $msgs = $msgs->get_error_messages();
88 }
89 if ( ! is_array($msgs)) {
90 $msgs = array($msgs);
91 }
92 $this->data['errors'] = $msgs;
93
94 $viewPathRel = str_replace('_', '/', preg_replace('%^' . preg_quote(PMXI_Plugin::PREFIX, '%') . '%', '', strtolower(get_class($this)))) . '/error.php';
95 if (is_file(PMXI_Plugin::ROOT_DIR . '/views/' . $viewPathRel)) { // if calling controller class has specific error view
96 $this->render($viewPathRel);
97 } else { // render default error view
98 $this->render('controller/error.php');
99 }
100 }
101
102 }