PluginProbe
Prismatic / 3.6
Prismatic v3.6
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.6, at prismatic.php

361 lines 11.5 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
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.7
12 Tested up to: 6.9
13 Stable tag: 3.6
14 Version: 3.6
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 2025 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 register_activation_hook(__FILE__, 'prismatic_dismiss_notice_activate');
55
56 add_action('admin_init', array(self::$instance, 'check_plugin'));
57 add_action('admin_init', array(self::$instance, 'check_version'));
58 add_action('init', array(self::$instance, 'load_i18n'));
59 add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
60 add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
61 add_filter('admin_footer_text', array(self::$instance, 'footer_text'), 10, 1);
62
63 add_action('wp_enqueue_scripts', 'prismatic_block_styles');
64 add_action('wp_enqueue_scripts', 'prismatic_enqueue');
65 add_action('admin_enqueue_scripts', 'prismatic_enqueue');
66 add_action('admin_enqueue_scripts', 'prismatic_enqueue_settings');
67 add_action('admin_enqueue_scripts', 'prismatic_enqueue_buttons');
68 add_action('admin_print_footer_scripts', 'prismatic_add_quicktags');
69 add_action('admin_notices', 'prismatic_admin_notice');
70 add_action('admin_menu', 'prismatic_menu_pages');
71 add_action('admin_init', 'prismatic_register_settings');
72 add_action('admin_init', 'prismatic_reset_options');
73 add_action('admin_init', 'prismatic_buttons');
74 add_action('admin_init', 'prismatic_dismiss_notice_save');
75 add_action('admin_init', 'prismatic_dismiss_notice_version');
76
77 add_action('init', 'prismatic_register_block_assets');
78 add_action('init', 'prismatic_add_filters');
79
80 add_shortcode('prismatic_code', 'prismatic_code_shortcode');
81
82 }
83
84 return self::$instance;
85
86 }
87
88 public static function options_general() {
89
90 $options = array(
91
92 'library' => 'none',
93 'disable_block_styles' => false,
94
95 );
96
97 return apply_filters('prismatic_options_general', $options);
98
99 }
100
101 public static function options_prism() {
102
103 $options = array(
104
105 'prism_theme' => 'default',
106 'filter_content' => 'none',
107 'filter_excerpts' => 'none',
108 'filter_comments' => 'none',
109 'line_highlight' => false,
110 'line_numbers' => false,
111 'show_language' => false,
112 'copy_clipboard' => false,
113 'command_line' => false,
114 'singular_only' => true,
115
116 );
117
118 return apply_filters('prismatic_options_prism', $options);
119
120 }
121
122 public static function options_highlight() {
123
124 $options = array(
125
126 'highlight_theme' => 'default',
127 'filter_content' => 'none',
128 'filter_excerpts' => 'none',
129 'filter_comments' => 'none',
130 'init_javascript' => 'hljs.highlightAll();',
131 'singular_only' => true,
132
133 );
134
135 return apply_filters('prismatic_options_highlight', $options);
136
137 }
138
139 public static function options_plain() {
140
141 $options = array(
142
143 'filter_content' => 'none',
144 'filter_excerpts' => 'none',
145 'filter_comments' => 'none',
146
147 );
148
149 return apply_filters('prismatic_options_plain', $options);
150
151 }
152
153 public static function options_advanced() {
154
155 $options = array(
156
157 'custom_style' => '',
158
159 );
160
161 return apply_filters('prismatic_options_advanced', $options);
162
163 }
164
165 private function constants() {
166
167 if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '3.6');
168 if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.7');
169 if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
170 if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
171 if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
172 if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
173 if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
174 if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
175 if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
176
177 }
178
179 private function includes() {
180
181 require_once PRISMATIC_DIR .'inc/prismatic-blocks.php';
182 require_once PRISMATIC_DIR .'inc/prismatic-buttons.php';
183 require_once PRISMATIC_DIR .'inc/prismatic-core.php';
184 require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
185 require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
186 require_once PRISMATIC_DIR .'inc/settings-display.php';
187 require_once PRISMATIC_DIR .'inc/settings-register.php';
188 require_once PRISMATIC_DIR .'inc/settings-reset.php';
189 require_once PRISMATIC_DIR .'inc/settings-validate.php';
190
191 }
192
193 public function action_links($links, $file) {
194
195 if ($file == PRISMATIC_FILE && (current_user_can('manage_options'))) {
196
197 $prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
198 array_unshift($links, $prismatic_links);
199
200 }
201
202 return $links;
203
204 }
205
206 public function plugin_links($links, $file) {
207
208 if ($file == PRISMATIC_FILE) {
209
210 $home_href = 'https://perishablepress.com/prismatic/';
211 $home_title = esc_attr__('Plugin Homepage', 'prismatic');
212 $home_text = esc_html__('Homepage', 'prismatic');
213
214 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
215
216 $rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
217 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
218 $rate_text = esc_html__('Rate this plugin', 'prismatic') .'&nbsp;&raquo;';
219
220 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
221
222 $pro_href = 'https://plugin-planet.com/prismatic-pro/';
223 $pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
224 $pro_text = esc_html__('Go&nbsp;Pro', 'prismatic');
225 $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
226
227 // $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
228
229 }
230
231 return $links;
232
233 }
234
235 function footer_text($text) {
236
237 $screen_id = prismatic_get_current_screen_id();
238
239 $ids = array('settings_page_prismatic');
240
241 if ($screen_id && apply_filters('prismatic_admin_footer_text', in_array($screen_id, $ids))) {
242
243 $text = __('Like Prismatic? Give it a', 'prismatic');
244
245 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/prismatic/reviews/?rate=5#new-post">';
246
247 $text .= __('�
248 �
249 �
250 �
251 �
252 rating&nbsp;&raquo;', 'prismatic') .'</a>';
253
254 }
255
256 return $text;
257
258 }
259
260 public function check_plugin() {
261
262 if (class_exists('Prismatic_Pro')) {
263
264 if (is_plugin_active(PRISMATIC_FILE)) {
265
266 deactivate_plugins(PRISMATIC_FILE);
267
268 $msg = '<strong>'. esc_html__('Warning:', 'prismatic') .'</strong> ';
269 $msg .= esc_html__('Pro version of Prismatic currently active. Free and Pro versions cannot be activated at the same time. ', 'prismatic');
270 $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'prismatic') .'</a> ';
271 $msg .= esc_html__('and try again.', 'prismatic');
272
273 wp_die($msg);
274
275 }
276
277 }
278
279 }
280
281 public function check_version() {
282
283 $wp_version = get_bloginfo('version');
284
285 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
286
287 if (version_compare($wp_version, PRISMATIC_REQUIRE, '<')) {
288
289 if (is_plugin_active(PRISMATIC_FILE)) {
290
291 deactivate_plugins(PRISMATIC_FILE);
292
293 $msg = '<strong>'. PRISMATIC_NAME .'</strong> '. esc_html__('requires WordPress ', 'prismatic') . PRISMATIC_REQUIRE;
294 $msg .= esc_html__(' or higher, and has been deactivated! ', 'prismatic');
295 $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">';
296 $msg .= esc_html__('WP Admin Area', 'prismatic') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'prismatic');
297
298 wp_die($msg);
299
300 }
301
302 }
303
304 }
305
306 }
307
308 public function load_i18n() {
309
310 load_plugin_textdomain('prismatic', false, dirname(PRISMATIC_FILE) .'/languages/');
311
312 }
313
314 public function __clone() {
315
316 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
317
318 }
319
320 public function __wakeup() {
321
322 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
323
324 }
325
326 }
327
328 }
329
330 if (class_exists('Prismatic')) {
331
332 $prismatic_options_general = get_option('prismatic_options_general', Prismatic::options_general());
333 $prismatic_options_general = apply_filters('prismatic_get_options_general', $prismatic_options_general);
334
335 $prismatic_options_prism = get_option('prismatic_options_prism', Prismatic::options_prism());
336 $prismatic_options_prism = apply_filters('prismatic_get_options_prism', $prismatic_options_prism);
337
338 $prismatic_options_highlight = get_option('prismatic_options_highlight', Prismatic::options_highlight());
339 $prismatic_options_highlight = apply_filters('prismatic_get_options_highlight', $prismatic_options_highlight);
340
341 $prismatic_options_plain = get_option('prismatic_options_plain', Prismatic::options_plain());
342 $prismatic_options_plain = apply_filters('prismatic_get_options_plain', $prismatic_options_plain);
343
344 $prismatic_options_advanced = get_option('prismatic_options_advanced', Prismatic::options_advanced());
345 $prismatic_options_advanced = apply_filters('prismatic_get_options_advanced', $prismatic_options_advanced);
346
347 if (!function_exists('prismatic')) {
348
349 function prismatic() {
350
351 do_action('prismatic');
352
353 return Prismatic::instance();
354 }
355
356 }
357
358 prismatic();
359
360 }
361