PluginProbe
Code Snippets / 2.12.0
Code Snippets v2.12.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 / editor.php

editor.php in Code Snippets 2.12.0, at php/editor.php

106 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Get the attributes for the code editor
5 *
6 * @param array $override_atts Pass an array of attributes to override the saved ones
7 * @param bool $json_encode Encode the data as JSON
8 * @return array|string Array if $json_encode is false, JSON string if it is true
9 */
10 function code_snippets_get_editor_atts( $override_atts, $json_encode ) {
11 $settings = code_snippets_get_settings();
12 $settings = $settings['editor'];
13
14 $fields = code_snippets_get_settings_fields();
15 $fields = $fields['editor'];
16
17 $saved_atts = array(
18 'matchBrackets' => true,
19 );
20
21 foreach ( $fields as $field_id => $field ) {
22 $saved_atts[ $field['codemirror'] ] = $settings[ $field_id ];
23 }
24
25 $atts = wp_parse_args( $override_atts, $saved_atts );
26 $atts = apply_filters( 'code_snippets_codemirror_atts', $atts );
27
28 if ( $json_encode ) {
29
30 /* JSON_UNESCAPED_SLASHES was added in PHP 5.4 */
31 if ( version_compare( phpversion(), '5.4.0', '>=' ) ) {
32 $atts = json_encode( $atts, JSON_UNESCAPED_SLASHES );
33 } else {
34 /* Use a fallback for < 5.4 */
35 $atts = str_replace( '\\/', '/', json_encode( $atts ) );
36 }
37 }
38
39 return $atts;
40 }
41
42 /**
43 * Registers and loads the CodeMirror library
44 *
45 * @uses wp_enqueue_style() to add the stylesheets to the queue
46 * @uses wp_enqueue_script() to add the scripts to the queue
47 */
48 function code_snippets_enqueue_codemirror() {
49 $codemirror_version = '5.40.2';
50 $url = plugin_dir_url( CODE_SNIPPETS_FILE );
51
52 /* Remove other CodeMirror styles */
53 wp_deregister_style( 'codemirror' );
54 wp_deregister_style( 'wpeditor' );
55
56 /* CodeMirror */
57 wp_enqueue_style(
58 'code-snippets-codemirror',
59 $url . 'css/min/codemirror.css',
60 false, $codemirror_version
61 );
62
63 wp_enqueue_script(
64 'code-snippets-codemirror',
65 $url . 'js/min/codemirror.js',
66 false, $codemirror_version
67 );
68
69 /* CodeMirror Theme */
70 $theme = code_snippets_get_setting( 'editor', 'theme' );
71
72 if ( 'default' !== $theme ) {
73
74 wp_enqueue_style(
75 'code-snippets-codemirror-theme-' . $theme,
76 $url . "css/min/cmthemes/$theme.css",
77 array( 'code-snippets-codemirror' ),
78 $codemirror_version
79 );
80 }
81 }
82
83 /**
84 * Retrieve a list of the available CodeMirror themes
85 * @return array the available themes
86 */
87 function code_snippets_get_available_themes() {
88 static $themes = null;
89
90 if ( ! is_null( $themes ) ) {
91 return $themes;
92 }
93
94 $themes = array();
95 $themes_dir = plugin_dir_path( CODE_SNIPPETS_FILE ) . 'css/min/cmthemes/';
96 $theme_files = glob( $themes_dir . '*.css' );
97
98 foreach ( $theme_files as $i => $theme ) {
99 $theme = str_replace( $themes_dir, '', $theme );
100 $theme = str_replace( '.css', '', $theme );
101 $themes[] = $theme;
102 }
103
104 return $themes;
105 }
106