PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.0.3
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.0.3
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 / classes / handler.php
wp-all-export / classes Last commit date
XMLWriter.php 10 years ago chunk.php 10 years ago config.php 10 years ago download.php 10 years ago handler.php 10 years ago helper.php 10 years ago input.php 10 years ago session.php 10 years ago zip.php 10 years ago
handler.php
165 lines
1 <?php
2
3 class PMXE_Handler extends PMXE_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 }
32
33 /**
34 * Return true if the current user has an active session, i.e. a cookie to retrieve values
35 * @return boolean
36 */
37 public function has_session() {
38 return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in();
39 }
40
41 /**
42 * set_session_expiration function.
43 *
44 * @access public
45 * @return void
46 */
47 public function set_session_expiration() {
48 $this->_session_expiring = time() + intval( apply_filters( 'wpallexport_session_expiring', 60 * 60 * 47 ) ); // 47 Hours
49 $this->_session_expiration = time() + intval( apply_filters( 'wpallexport_session_expiration', 60 * 60 * 48 ) ); // 48 Hours
50 }
51
52 public function generate_import_id() {
53
54 $input = new PMXE_Input();
55 $import_id = $input->get('id', 'new');
56
57 return $import_id;
58
59 }
60
61 /**
62 * get_session_data function.
63 *
64 * @access public
65 * @return array
66 */
67 public function get_session_data() {
68 return (array) get_option( '_wpallexport_session_' . $this->_import_id . '_', array() );
69 }
70
71 /**
72 * get_session_data function.
73 *
74 * @access public
75 * @return array
76 */
77 public function get_clear_session_data() {
78 $this->_data = $this->get_session_data();
79 $clear_data = array();
80 foreach ($this->_data as $key => $value) {
81 $ckey = sanitize_key( $key );
82 $clear_data[ $ckey ] = maybe_unserialize( $value );
83 }
84
85 return $clear_data;
86 }
87
88 /**
89 * save_data function.
90 *
91 * @access public
92 * @return void
93 */
94 public function save_data() {
95 // Dirty if something changed - prevents saving nothing new
96 if ( $this->_dirty && $this->has_session() ) {
97
98 $session_option = '_wpallexport_session_' . $this->_import_id . '_';
99 $session_expiry_option = '_wpallexport_session_expires_' . $this->_import_id . '_';
100
101 wp_cache_delete( 'notoptions', 'options' );
102 wp_cache_delete( $session_option, 'options' );
103 wp_cache_delete( $session_expiry_option, 'options' );
104
105 if ( false === get_option( $session_option ) ) {
106 add_option( $session_option, $this->_data, '', 'no' );
107 add_option( $session_expiry_option, $this->_session_expiration, '', 'no' );
108 } else {
109 update_option( $session_option, $this->_data );
110 }
111 }
112 }
113
114 public function convertData( $import_id ){
115
116 $this->_import_id = 'new';
117
118 $this->_data = $this->get_session_data();
119
120 $this->set_session_expiration();
121
122 $this->_import_id = $import_id;
123
124 $this->clean_session();
125
126 $this->_dirty = true;
127
128 $this->save_data();
129 }
130
131 public function clean_session( $import_id = 'new' ){
132
133 global $wpdb;
134
135 $now = time();
136 $expired_sessions = array();
137 $wpallimport_session_expires = $wpdb->get_results( $wpdb->prepare("SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE %s", "_wpallexport_session_expires_" . $import_id . "_%") );
138
139 $expired_sessions[] = "_wpallexport_session_{$import_id}_"; // Session key
140
141 foreach ( $wpallimport_session_expires as $wpallimport_session_expire ) {
142 //if ( $now > intval( $wpallimport_session_expire->option_value ) ) {
143 //$session_id = substr( $wpallimport_session_expire->option_name, 29 );
144 $expired_sessions[] = $wpallimport_session_expire->option_name; // Expires key
145 //$expired_sessions[] = "_wpallimport_session_$session_id"; // Session key
146 //}
147 }
148
149 if ( ! empty( $expired_sessions ) ) {
150 wp_cache_delete( 'notoptions', 'options' );
151 foreach ($expired_sessions as $expired) {
152 wp_cache_delete( $expired, 'options' );
153 delete_option($expired);
154 }
155 $expired_sessions_chunked = array_chunk( $expired_sessions, 100 );
156
157 foreach ( $expired_sessions_chunked as $chunk ) {
158 $option_names = implode( "','", $chunk );
159 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
160 }
161 }
162
163 }
164
165 }