PluginProbe
Assistant – Every Day Productivity Apps / 1.5.5.1
Assistant – Every Day Productivity Apps v1.5.5.1
1.5.5.1 1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 All 72 releases
← All changes | backend/src/Controllers/PostsExportController.php +10 -50 0.5.0 → 1.5.5.1 View file →
@@ -32,21 +32,8 @@
32 32 },
33 33 ],
34 34 ]
35 35 );
36 -
37 - $this->route(
38 - '/posts/(?P<id>\d+)/export',
39 - [
40 - [
41 - 'methods' => WP_REST_Server::DELETABLE,
42 - 'callback' => [ $this, 'delete_export' ],
43 - 'permission_callback' => function () {
44 - return current_user_can( 'export' );
45 - },
46 - ],
47 - ]
48 - );
49 36 }
50 37
51 38 /**
52 39 * Export a single post.
@@ -51,21 +38,18 @@
51 38 /**
52 39 * Export a single post.
53 40 */
54 41 public function export_post( $request ) {
42 +
55 43 /* Get requested post data */
56 44 $post_id = absint( $request->get_param( 'id' ) );
57 45 $post = get_post( $post_id );
58 46
59 47 /* Create temporary file */
60 - $file_url = WP_CONTENT_URL . '/' . sanitize_file_name( $post->post_title ) . '_' . $post->ID . '.xml';
61 - $file = WP_CONTENT_DIR . '/' . sanitize_file_name( $post->post_title ) . '_' . $post->ID . '.xml';
62 - $current = '';
48 + $upload_dir = wp_upload_dir( null, false );
49 + $file_url = $upload_dir['baseurl'] . '/assistant_export_' . $post->ID . '.xml';
50 + $file = $upload_dir['basedir'] . '/assistant_export_' . $post->ID . '.xml';
63 51
64 - if ( file_exists( $file ) ) {
65 - $current = file_get_contents( $file );
66 - }
67 -
68 52 /* Creates taxonomies string for xml export */
69 53 $taxonomies = get_taxonomies( '', 'names' );
70 54 $terms = wp_get_object_terms( $post->ID, $taxonomies );
71 55
@@ -102,8 +86,12 @@
102 86 $meta_str = '';
103 87 $meta_values = get_post_meta( $post->ID );
104 88 foreach ( $meta_values as $key => $values ) {
105 89 foreach ( $values as $value ) {
90 + /* Ignore BB history meta */
91 + if ( false !== strpos( $key, '_fl_builder_history' ) ) {
92 + continue;
93 + }
106 94 $meta_str .= '<wp:postmeta>
107 95 <wp:meta_key>' . $this->wxr_cdata( $key ) . '</wp:meta_key>
108 96 <wp:meta_value>' . $this->wxr_cdata( $value ) . '</wp:meta_value>
109 97 </wp:postmeta>
@@ -146,40 +134,12 @@
146 134 'post_type' => $post_type,
147 135 ]
148 136 );
149 137
150 - file_put_contents( $file, $current . $export_data );
151 -
138 + file_put_contents( $file, $export_data );
139 + update_option( 'fl_assistant_export_file', true );
152 140 return $file_url;
153 141 }
154 -
155 - /**
156 - * Remove temporary exported file.
157 - */
158 - public function delete_export( $request ) {
159 -
160 - $post_id = absint( $request->get_param( 'id' ) );
161 - $post = get_post( $post_id );
162 -
163 - /* Remove temporary file */
164 - $file = WP_CONTENT_DIR . '/' . sanitize_file_name( $post->post_title ) . '_' . $post->ID . '.xml';
165 -
166 - if ( file_exists( $file ) ) {
167 - unlink( $file );
168 - return rest_ensure_response(
169 - [
170 - 'success' => true,
171 - ]
172 - );
173 - } else {
174 - return rest_ensure_response(
175 - [
176 - 'error' => true,
177 - ]
178 - );
179 - }
180 - }
181 -
182 142
183 143 function wxr_cdata( $str ) {
184 144 if ( ! seems_utf8( $str ) ) {
185 145 $str = utf8_encode( $str );