PluginProbe
Code Snippets / 3.10.0
Code Snippets v3.10.0
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / Migration / Export / Export_JSON.php

Export_JSON.php in Code Snippets 3.10.0, at php/Migration/Export/Export_JSON.php

50 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Migration\Export;
4
5 use Code_Snippets\Model\Snippet;
6 use const Code_Snippets\PLUGIN_VERSION;
7
8 /**
9 * Handles exporting snippets from the site in various downloadable formats
10 *
11 * @package Code_Snippets
12 */
13 class Export_JSON extends Export {
14
15 /**
16 * Retrieve the file extension for the export format.
17 *
18 * @return string
19 */
20 public function get_file_extension(): string {
21 return 'json';
22 }
23
24 /**
25 * Bundle snippets together into JSON format.
26 *
27 * @return array<string, string|Snippet[]> Snippets as JSON object.
28 */
29 public function generate_export(): array {
30 $snippets = [];
31
32 foreach ( $this->get_snippets_list() as $snippet ) {
33 $snippets[] = array_map(
34 function ( $value ) {
35 return is_string( $value ) ?
36 str_replace( "\r\n", "\n", $value ) :
37 $value;
38 },
39 $snippet->get_modified_fields()
40 );
41 }
42
43 return [
44 'generator' => 'Code Snippets v' . PLUGIN_VERSION,
45 'date_created' => gmdate( 'Y-m-d H:i' ),
46 'snippets' => $snippets,
47 ];
48 }
49 }
50