PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / trunk
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets vtrunk
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 / classes / handler.php
wp-all-import / classes Last commit date
XmlStreamReader 3 weeks ago partner-discount-sdk 3 weeks ago api.php 3 weeks ago arraytoxml.php 3 weeks ago chunk.php 3 weeks ago config.php 2 years ago download.php 3 weeks ago error.php 3 weeks ago handler.php 3 weeks ago helper.php 3 weeks ago input.php 3 weeks ago nested.php 3 weeks ago rapidaddon.php 3 weeks ago render.php 3 weeks ago session.php 9 months ago upload.php 3 weeks ago zip.php 10 years ago
handler.php
183 lines
1 <?php
2
3 class PMXI_Handler extends PMXI_Session {
4
5 /** cookie name */
6 private $_cookie;
7
8 /** session due to expire timestamp */
9 private $_session_expiring;
10
11 /** session expiration timestamp */
12 private $_session_expiration;
13
14 /** Bool based on whether a cookie exists **/
15 private $_has_cookie = false;
16
17 /**
18 * Constructor for the session class.
19 *
20 * @access public
21 * @return void
22 */
23 public function __construct() {
24
25 $this->set_session_expiration();
26
27 $this->_import_id = $this->generate_import_id();
28
29 $this->_data = $this->get_session_data();
30
31 //add_action( 'shutdown', array( $this, 'save_data' ), 20 );
32
33 }
34
35 /**
36 * Return true if the current user has an active session, i.e. a cookie to retrieve values
37 * @return boolean
38 */
39 public function has_session() {
40 return ( $this->_cookie !== null && isset( $_COOKIE[ $this->_cookie ] ) ) || $this->_has_cookie || is_user_logged_in();
41 }
42
43 /**
44 * set_session_expiration function.
45 *
46 * @access public
47 * @return void
48 */
49 public function set_session_expiration() {
50 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
51 $this->_session_expiring = time() + intval( apply_filters( 'wpallimport_session_expiring', 60 * 60 * 47 ) ); // 47 Hours
52 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
53 $this->_session_expiration = time() + intval( apply_filters( 'wpallimport_session_expiration', 60 * 60 * 48 ) ); // 48 Hours
54 }
55
56 public function generate_import_id() {
57
58 $input = new PMXI_Input();
59 $import_id = $input->get('id', 'new');
60
61 return $import_id;
62
63 }
64
65 /**
66 * get_session_data function.
67 *
68 * @access public
69 * @return array
70 */
71 public function get_session_data()
72 {
73 $session = get_option('_wpallimport_session_' . $this->_import_id . '_', []);
74 $delete_option = false;
75
76 if( false === $session ){
77 $delete_option = true;
78 }
79
80 if( !empty($session) && !is_array($session) ) {
81 $session_clear = \maybe_unserialize( base64_decode( $session ) );
82 if($session === $session_clear){
83 $delete_option = true;
84 }else{
85 $session = $session_clear;
86 }
87 }
88
89 if($delete_option){
90 delete_option('_wpallimport_session_' . $this->_import_id . '_');
91 delete_option('_wpallimport_session_expires_' . $this->_import_id . '_');
92 $session = [];
93 }
94
95 return $session;
96 }
97
98 /**
99 * save_data function.
100 *
101 * @access public
102 * @return void
103 */
104 public function save_data() {
105 // Dirty if something changed - prevents saving nothing new
106 if ( $this->_dirty && $this->has_session() ) {
107
108 $session_option = '_wpallimport_session_' . $this->_import_id . '_';
109 $session_expiry_option = '_wpallimport_session_expires_' . $this->_import_id . '_';
110
111 wp_cache_delete( 'notoptions', 'options' );
112 wp_cache_delete( $session_option, 'options' );
113 wp_cache_delete( $session_expiry_option, 'options' );
114
115 if ( false === get_option( $session_option ) )
116 {
117 add_option( $session_option, base64_encode(serialize($this->_data)), '', 'no' );
118 add_option( $session_expiry_option, $this->_session_expiration, '', 'no' );
119 } else {
120 update_option( $session_option, base64_encode(serialize($this->_data)) );
121 }
122 }
123 }
124
125 public function convertData( $import_id ){
126
127 $this->_import_id = 'new';
128
129 $this->_data = $this->get_session_data();
130
131 $this->set_session_expiration();
132
133 $this->_import_id = $import_id;
134
135 $this->clean_session();
136
137 $this->_dirty = true;
138
139 $this->save_data();
140
141 $parser_type = get_option('wpai_parser_type_0');
142
143 if ( ! empty($parser_type) ){
144 update_option('wpai_parser_type_' . $import_id, $parser_type, false);
145 delete_option('wpai_parser_type_0');
146 }
147 }
148
149 public function clean_session( $import_id = 'new' ){
150
151 global $wpdb;
152
153 $now = time();
154 $expired_sessions = array();
155 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
156 $wpallimport_session_expires = $wpdb->get_results( $wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE %s", "_wpallimport_session_expires_" . $import_id . "_%") );
157
158 $expired_sessions[] = "_wpallimport_session_{$import_id}_"; // Session key
159
160 foreach ( $wpallimport_session_expires as $wpallimport_session_expire ) {
161 //if ( $now > intval( $wpallimport_session_expire->option_value ) ) {
162 //$session_id = substr( $wpallimport_session_expire->option_name, 29 );
163 $expired_sessions[] = $wpallimport_session_expire->option_name; // Expires key
164 //$expired_sessions[] = "_wpallimport_session_$session_id"; // Session key
165 //}
166 }
167
168 if ( ! empty( $expired_sessions ) ) {
169 wp_cache_delete( 'notoptions', 'options' );
170 foreach ($expired_sessions as $expired) {
171 wp_cache_delete( $expired, 'options' );
172 delete_option($expired);
173 }
174 $expired_sessions_chunked = array_chunk( $expired_sessions, 100 );
175
176 foreach ( $expired_sessions_chunked as $chunk ) {
177 $option_names = implode( "','", $chunk );
178 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,PluginCheck.Security.DirectDB.UnescapedDBParameter
179 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
180 }
181 }
182 }
183 }