PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.2.4
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.2.4
2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 2.7.1 All 27 releases
insert-php / admin / pages / settings.php

settings.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.2.4, at admin/pages/settings.php

286 lines 9.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file contains a short help info.
4 *
5 * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 * @since 1.0.0
7 * @package core
8 * @copyright (c) 2018, OnePress Ltd
9 * s
10 */
11
12 // Exit if accessed directly
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Common Settings
19 */
20 class WINP_SettingsPage extends WINP_Page {
21
22 /**
23 * @param Wbcr_Factory413_Plugin $plugin
24 */
25 public function __construct( Wbcr_Factory413_Plugin $plugin ) {
26 $this->menu_post_type = WINP_SNIPPETS_POST_TYPE;
27
28 /*if( !current_user_can('administrator') ) {
29 $this->capabilitiy = "read_wbcr-scrapes";
30 }*/
31
32 $this->id = "settings";
33 $this->menu_title = __( 'Settings', 'insert-php' );
34
35 parent::__construct( $plugin );
36
37 $this->plugin = $plugin;
38
39 do_action( 'wbcr/inp/settings/after_construct' );
40 }
41
42 public function assets( $scripts, $styles ) {
43 $this->scripts->request( 'jquery' );
44
45 $this->scripts->request( [
46 'control.checkbox',
47 'control.dropdown'
48 ], 'bootstrap' );
49
50 $this->styles->request( [
51 'bootstrap.core',
52 'bootstrap.form-group',
53 'bootstrap.separator',
54 'control.dropdown',
55 'control.checkbox',
56 ], 'bootstrap' );
57 }
58
59 /**
60 * Returns options for the Basic Settings screen.
61 *
62 * @since 1.0.0
63 * @return array
64 */
65 public function getOptions() {
66
67 $options = [];
68
69 $options[] = [
70 'type' => 'separator'
71 ];
72
73 $options[] = [
74 'type' => 'checkbox',
75 'way' => 'buttons',
76 'name' => 'activate_by_default',
77 'title' => __( 'Activate by Default', 'insert-php' ),
78 'default' => true,
79 'hint' => __( 'When creating a new snippet or updating an old one, make the code snippets active by default.', 'insert-php' )
80 ];
81
82 $options[] = [
83 'type' => 'checkbox',
84 'way' => 'buttons',
85 'name' => 'keep_html_entities',
86 'title' => __( 'Keep the HTML entities, don\'t convert to its character', 'insert-php' ),
87 'default' => false,
88 'hint' => __( 'If you want to use an HTML entity in your code (for example &gt; or &quot;), but the editor keeps on changing them to its equivalent character (> and " for the previous example), then you might want to enable this option.', 'insert-php' )
89 ];
90
91 $options[] = [
92 'type' => 'checkbox',
93 'way' => 'buttons',
94 'name' => 'complete_uninstall',
95 'title' => __( 'Complete Uninstall', 'insert-php' ),
96 'default' => false,
97 'hint' => __( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings.', 'insert-php' )
98 ];
99
100 $options[] = [
101 'type' => 'checkbox',
102 'way' => 'buttons',
103 'name' => 'support_old_shortcodes',
104 'title' => __( 'Support old shortcodes [insert_php]', 'insert-php' ),
105 'default' => false,
106 'hint' => __( 'If you used our plugin from version 1.3.0, then you could use the old shortcodes [insert_php][/insert_php]; from version 2.2.0 we disabled this type of shortcodes by default, as their use is not safe. If you still want to execute your php code via [insert_php][/insert_php] shortcodes, you can enable this option.', 'insert-php' )
107 ];
108
109 $options[] = [
110 'type' => 'html',
111 'html' => '<h3 style="margin-left:0">Code Editor</h3>'
112 ];
113
114 $options[] = [
115 'type' => 'separator'
116 ];
117
118 $options[] = [
119 'type' => 'dropdown',
120 'name' => 'code_editor_theme',
121 'title' => __( 'Code style', 'insert-php' ),
122 'data' => $this->getAvailableThemes(),
123 'default' => 'default',
124 'hint' => __( 'The optional feature. You can customize the code style in the snippet editor. The "Default" style is applied by default.', 'insert-php' )
125 ];
126
127 $options[] = [
128 'type' => 'checkbox',
129 'way' => 'buttons',
130 'name' => 'code_editor_indent_with_tabs',
131 'title' => __( 'Indent With Tabs', 'insert-php' ),
132 'default' => false,
133 'hint' => __( 'The optional feature. Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. The default is false.', 'insert-php' )
134 ];
135
136 $options[] = [
137 'type' => 'integer',
138 'way' => 'buttons',
139 'name' => 'code_editor_tab_size',
140 'title' => __( 'Tab Size', 'insert-php' ),
141 'default' => 4,
142 'hint' => __( 'The optional feature. Pressing Tab in the code editor increases left indent to N spaces. N is a number pre-defined by you.', 'insert-php' )
143 ];
144
145 $options[] = [
146 'type' => 'integer',
147 'way' => 'buttons',
148 'name' => 'code_editor_indent_unit',
149 'title' => __( 'Indent Unit', 'insert-php' ),
150 'default' => 4,
151 'hint' => __( 'The optional feature. The indent for code lines (units). Example: select a snippet, press Tab. The left indent in the selected code increases to N spaces. N is a number pre-defined by you.', 'insert-php' )
152 ];
153
154 $options[] = [
155 'type' => 'checkbox',
156 'way' => 'buttons',
157 'name' => 'code_editor_wrap_lines',
158 'title' => __( 'Wrap Lines', 'insert-php' ),
159 'default' => true,
160 'hint' => __( 'The optional feature. If ON, the editor will wrap long lines. Otherwise, it will create a horizontal scroll.', 'insert-php' )
161 ];
162
163 $options[] = [
164 'type' => 'checkbox',
165 'way' => 'buttons',
166 'name' => 'code_editor_line_numbers',
167 'title' => __( 'Line Numbers', 'insert-php' ),
168 'default' => true,
169 'hint' => __( 'The optional feature. If ON, all lines in the editor will be numbered.', 'insert-php' )
170 ];
171
172 $options[] = [
173 'type' => 'checkbox',
174 'way' => 'buttons',
175 'name' => 'code_editor_auto_close_brackets',
176 'title' => __( 'Auto Close Brackets', 'insert-php' ),
177 'default' => true,
178 'hint' => __( 'The optional feature. If ON, the editor will automatically close opened quotes or brackets. Sometimes, it speeds up coding.', 'insert-php' )
179 ];
180
181 $options[] = [
182 'type' => 'checkbox',
183 'way' => 'buttons',
184 'name' => 'code_editor_highlight_selection_matches',
185 'title' => __( 'Highlight Selection Matches', 'insert-php' ),
186 'default' => false,
187 'hint' => __( 'The optional feature. If ON, it searches for matches for the selected variable/function name. Highlight matches with green. Improves readability.', 'insert-php' )
188 ];
189
190 $options = apply_filters( 'wbcr/inp/settings/form_options', $options );
191
192 $options[] = [
193 'type' => 'separator'
194 ];
195
196 return $options;
197 }
198
199
200 public function indexAction() {
201
202 // creating a form
203 $form = WINP_Helper::get_factory_form( [
204 'scope' => substr( $this->plugin->getPrefix(), 0, - 1 ),
205 'name' => 'setting'
206 ], $this->plugin );
207
208 $form->setProvider( WINP_Helper::get_options_value_provider( $this->plugin ) );
209
210 $form->add( $this->getOptions() );
211
212 $wbcr_saved = WINP_Plugin::app()->request->post( $this->plugin->getPrefix() . 'saved', '' );
213 if ( ! empty( $wbcr_saved ) ) {
214 $wbcr_nonce = WINP_Plugin::app()->request->post( $this->plugin->getPrefix() . 'nonce', '' );
215 if ( ! wp_verify_nonce( $wbcr_nonce, $this->plugin->getPrefix() . 'settings_form' ) ) {
216 wp_die( 'Permission error. You can not edit this page.' );
217 }
218 $form->save();
219
220 do_action( 'wbcr/inp/settings/after_form_save' );
221 }
222 ?>
223 <div class="wrap">
224 <div class="<?php echo WINP_Helper::get_factory_class(); ?>">
225 <h3><?php _e( 'Settings', 'insert-php' ) ?></h3>
226 <div class="row">
227 <div class="col-md-9">
228 <form method="post" class="form-horizontal">
229 <?php if ( ! empty( $wbcr_saved ) ) { ?>
230 <div id="message" class="alert alert-success">
231 <p><?php _e( 'The settings have been updated successfully!', 'insert-php' ) ?></p>
232 </div>
233 <?php } ?>
234 <div style="padding-top: 10px;">
235 <?php $form->html(); ?>
236 </div>
237 <div class="form-group form-horizontal">
238 <label class="col-sm-2 control-label"> </label>
239 <div class="control-group controls col-sm-10">
240 <?php wp_nonce_field( $this->plugin->getPrefix() . 'settings_form', $this->plugin->getPrefix() . 'nonce' ); ?>
241 <input name="<?php echo $this->plugin->getPrefix() . 'saved' ?>" class="btn btn-primary" type="submit" value="<?php _e( 'Save settings', 'insert-php' ) ?>"/>
242 </div>
243 </div>
244 </form>
245 </div>
246 <div class="col-md-3">
247 <div id="winp-dashboard-widget" class="winp-right-widget">
248 <?php
249 apply_filters( 'wbcr/inp/dashboard/widget/print', '' );
250 ?>
251 </div>
252 </div>
253 </div>
254 </div>
255 </div>
256 <?php
257 }
258
259 /**
260 * Retrieve a list of the available CodeMirror themes
261 *
262 * @return array the available themes
263 */
264 public function getAvailableThemes() {
265 static $themes = null;
266
267 if ( ! is_null( $themes ) ) {
268 return $themes;
269 }
270
271 $themes = [];
272 $themes_dir = WINP_PLUGIN_DIR . '/admin/assets/css/cmthemes/';
273 $theme_files = glob( $themes_dir . '*.css' );
274
275 foreach ( $theme_files as $i => $theme ) {
276 $theme = str_replace( $themes_dir, '', $theme );
277 $theme = str_replace( '.css', '', $theme );
278 $themes[] = [ $theme, $theme ];
279 }
280
281 array_unshift( $themes, [ 'default', 'default' ] );
282
283 return $themes;
284 }
285 }
286