PluginProbe
Prismatic / 3.2
Prismatic v3.2
trunk 1.3 1.4 1.5 1.6 1.6.1 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.9.1 3.0 3.1 3.1.1 3.2 3.2.1 All 40 releases
prismatic / prismatic.php

prismatic.php in Prismatic 3.2, at prismatic.php

359 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Prismatic
4 Plugin URI: https://perishablepress.com/prismatic/
5 Description: Display beautiful syntax-highlighted code snippets with Prism.js or Highlight.js
6 Tags: code, snippets, syntax, highlight, language, snippet, pre, prettify, prism, css, fence
7 Author: Jeff Starr
8 Contributors: specialk
9 Author URI: https://plugin-planet.com/
10 Donate link: https://monzillamedia.com/donate.html
11 Requires at least: 4.6
12 Tested up to: 6.1
13 Stable tag: 3.2
14 Version: 3.2
15 Requires PHP: 5.6.20
16 Text Domain: prismatic
17 Domain Path: /languages
18 License: GPL v2 or later
19 */
20
21 /*
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License
24 as published by the Free Software Foundation; either version
25 2 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 with this program. If not, visit: https://www.gnu.org/licenses/
34
35 Copyright 2022 Monzilla Media. All rights reserved.
36 */
37
38 if (!defined('ABSPATH')) die();
39
40 if (!class_exists('Prismatic')) {
41
42 final class Prismatic {
43
44 private static $instance;
45
46 public static function instance() {
47
48 if (!isset(self::$instance) && !(self::$instance instanceof Prismatic)) {
49
50 self::$instance = new Prismatic;
51 self::$instance->constants();
52 self::$instance->includes();
53
54 add_action('admin_init', array(self::$instance, 'check_plugin'));
55 add_action('admin_init', array(self::$instance, 'check_version'));
56 add_action('init', array(self::$instance, 'load_i18n'));
57 add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
58 add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
59 add_filter('admin_footer_text', array(self::$instance, 'footer_text'), 10, 1);
60
61 add_action('wp_enqueue_scripts', 'prismatic_block_styles');
62 add_action('wp_enqueue_scripts', 'prismatic_enqueue');
63 add_action('admin_enqueue_scripts', 'prismatic_enqueue');
64 add_action('admin_enqueue_scripts', 'prismatic_enqueue_settings');
65 add_action('admin_enqueue_scripts', 'prismatic_enqueue_buttons');
66 add_action('admin_print_footer_scripts', 'prismatic_add_quicktags');
67 add_action('admin_notices', 'prismatic_admin_notice');
68 add_action('admin_menu', 'prismatic_menu_pages');
69 add_action('admin_init', 'prismatic_register_settings');
70 add_action('admin_init', 'prismatic_reset_options');
71 add_action('admin_init', 'prismatic_buttons');
72
73 add_action('init', 'prismatic_register_block_assets');
74 add_action('init', 'prismatic_add_filters');
75
76 add_shortcode('prismatic_code', 'prismatic_code_shortcode');
77
78 }
79
80 return self::$instance;
81
82 }
83
84 public static function options_general() {
85
86 $options = array(
87
88 'library' => 'none',
89 'disable_block_styles' => false,
90
91 );
92
93 return apply_filters('prismatic_options_general', $options);
94
95 }
96
97 public static function options_prism() {
98
99 $options = array(
100
101 'prism_theme' => 'default',
102 'filter_content' => 'none',
103 'filter_excerpts' => 'none',
104 'filter_comments' => 'none',
105 'line_highlight' => false,
106 'line_numbers' => false,
107 'show_language' => false,
108 'copy_clipboard' => false,
109 'command_line' => false,
110 'singular_only' => true,
111
112 );
113
114 return apply_filters('prismatic_options_prism', $options);
115
116 }
117
118 public static function options_highlight() {
119
120 $options = array(
121
122 'highlight_theme' => 'default',
123 'filter_content' => 'none',
124 'filter_excerpts' => 'none',
125 'filter_comments' => 'none',
126 'init_javascript' => 'hljs.highlightAll();',
127 'singular_only' => true,
128
129 );
130
131 return apply_filters('prismatic_options_highlight', $options);
132
133 }
134
135 public static function options_plain() {
136
137 $options = array(
138
139 'filter_content' => 'none',
140 'filter_excerpts' => 'none',
141 'filter_comments' => 'none',
142
143 );
144
145 return apply_filters('prismatic_options_plain', $options);
146
147 }
148
149 public static function options_advanced() {
150
151 $options = array(
152
153 'custom_style' => '',
154
155 );
156
157 return apply_filters('prismatic_options_advanced', $options);
158
159 }
160
161 private function constants() {
162
163 if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '3.2');
164 if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.6');
165 if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
166 if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
167 if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
168 if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
169 if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
170 if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
171 if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
172
173 }
174
175 private function includes() {
176
177 require_once PRISMATIC_DIR .'inc/prismatic-blocks.php';
178 require_once PRISMATIC_DIR .'inc/prismatic-buttons.php';
179 require_once PRISMATIC_DIR .'inc/prismatic-core.php';
180 require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
181 require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
182 require_once PRISMATIC_DIR .'inc/settings-display.php';
183 require_once PRISMATIC_DIR .'inc/settings-register.php';
184 require_once PRISMATIC_DIR .'inc/settings-reset.php';
185 require_once PRISMATIC_DIR .'inc/settings-validate.php';
186
187 }
188
189 public function action_links($links, $file) {
190
191 if ($file == PRISMATIC_FILE && (current_user_can('manage_options'))) {
192
193 $prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
194 array_unshift($links, $prismatic_links);
195
196 }
197
198 return $links;
199
200 }
201
202 public function plugin_links($links, $file) {
203
204 if ($file == plugin_basename(__FILE__)) {
205
206 $home_href = 'https://perishablepress.com/prismatic/';
207 $home_title = esc_attr__('Plugin Homepage', 'prismatic');
208 $home_text = esc_html__('Homepage', 'prismatic');
209
210 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
211
212 $rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
213 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
214 $rate_text = esc_html__('Rate this plugin', 'prismatic') .'&nbsp;&raquo;';
215
216 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
217
218 $pro_href = 'https://plugin-planet.com/prismatic-pro/?plugin';
219 $pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
220 $pro_text = esc_html__('Go&nbsp;Pro', 'prismatic');
221 $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
222
223 // $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
224
225 }
226
227 return $links;
228
229 }
230
231 function footer_text($text) {
232
233 if (!function_exists('get_current_screen')) require_once ABSPATH .'/wp-admin/includes/screen.php';
234
235 $screen = get_current_screen();
236
237 $ids = array('settings_page_prismatic');
238
239 if (isset($screen->id) && apply_filters('prismatic_admin_footer_text', in_array($screen->id, $ids))) {
240
241 $text = __('Like Prismatic? Give it a', 'prismatic');
242
243 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/prismatic/reviews/?rate=5#new-post">';
244
245 $text .= __('�
246 �
247 �
248 �
249 �
250 rating&nbsp;&raquo;', 'prismatic') .'</a>';
251
252 }
253
254 return $text;
255
256 }
257
258 public function check_plugin() {
259
260 if (class_exists('Prismatic_Pro')) {
261
262 if (is_plugin_active(PRISMATIC_FILE)) {
263
264 deactivate_plugins(PRISMATIC_FILE);
265
266 $msg = '<strong>'. esc_html__('Warning:', 'prismatic') .'</strong> ';
267 $msg .= esc_html__('Pro version of Prismatic currently active. Free and Pro versions cannot be activated at the same time. ', 'prismatic');
268 $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'prismatic') .'</a> ';
269 $msg .= esc_html__('and try again.', 'prismatic');
270
271 wp_die($msg);
272
273 }
274
275 }
276
277 }
278
279 public function check_version() {
280
281 $wp_version = get_bloginfo('version');
282
283 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
284
285 if (version_compare($wp_version, PRISMATIC_REQUIRE, '<')) {
286
287 if (is_plugin_active(PRISMATIC_FILE)) {
288
289 deactivate_plugins(PRISMATIC_FILE);
290
291 $msg = '<strong>'. PRISMATIC_NAME .'</strong> '. esc_html__('requires WordPress ', 'prismatic') . PRISMATIC_REQUIRE;
292 $msg .= esc_html__(' or higher, and has been deactivated! ', 'prismatic');
293 $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">';
294 $msg .= esc_html__('WP Admin Area', 'prismatic') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'prismatic');
295
296 wp_die($msg);
297
298 }
299
300 }
301
302 }
303
304 }
305
306 public function load_i18n() {
307
308 load_plugin_textdomain('prismatic', false, dirname(plugin_basename(__FILE__)) .'/languages/');
309
310 }
311
312 public function __clone() {
313
314 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
315
316 }
317
318 public function __wakeup() {
319
320 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
321
322 }
323
324 }
325
326 }
327
328 if (class_exists('Prismatic')) {
329
330 $prismatic_options_general = get_option('prismatic_options_general', Prismatic::options_general());
331 $prismatic_options_general = apply_filters('prismatic_get_options_general', $prismatic_options_general);
332
333 $prismatic_options_prism = get_option('prismatic_options_prism', Prismatic::options_prism());
334 $prismatic_options_prism = apply_filters('prismatic_get_options_prism', $prismatic_options_prism);
335
336 $prismatic_options_highlight = get_option('prismatic_options_highlight', Prismatic::options_highlight());
337 $prismatic_options_highlight = apply_filters('prismatic_get_options_highlight', $prismatic_options_highlight);
338
339 $prismatic_options_plain = get_option('prismatic_options_plain', Prismatic::options_plain());
340 $prismatic_options_plain = apply_filters('prismatic_get_options_plain', $prismatic_options_plain);
341
342 $prismatic_options_advanced = get_option('prismatic_options_advanced', Prismatic::options_advanced());
343 $prismatic_options_advanced = apply_filters('prismatic_get_options_advanced', $prismatic_options_advanced);
344
345 if (!function_exists('prismatic')) {
346
347 function prismatic() {
348
349 do_action('prismatic');
350
351 return Prismatic::instance();
352 }
353
354 }
355
356 prismatic();
357
358 }
359