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

359 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.7
14 Version: 3.7
15 Requires PHP: 5.6.20
16 Text Domain: prismatic
17 Domain Path: /languages
18 License: GPL v2 or later
19
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License
22 as published by the Free Software Foundation; either version
23 2 of the License, or (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 with this program. If not, visit: https://www.gnu.org/licenses/
32
33 Copyright 2016-2026 Monzilla Media. All rights reserved.
34 */
35
36 if (!defined('ABSPATH')) die();
37
38 if (!class_exists('Prismatic')) {
39
40 final class Prismatic {
41
42 private static $instance;
43
44 public static function instance() {
45
46 if (!isset(self::$instance) && !(self::$instance instanceof Prismatic)) {
47
48 self::$instance = new Prismatic;
49 self::$instance->constants();
50 self::$instance->includes();
51
52 register_activation_hook(__FILE__, 'prismatic_dismiss_notice_activate');
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 add_action('admin_init', 'prismatic_dismiss_notice_save');
73 add_action('admin_init', 'prismatic_dismiss_notice_version');
74
75 add_action('init', 'prismatic_register_block_assets');
76 add_action('init', 'prismatic_add_filters');
77
78 add_shortcode('prismatic_code', 'prismatic_code_shortcode');
79
80 }
81
82 return self::$instance;
83
84 }
85
86 public static function options_general() {
87
88 $options = array(
89
90 'library' => 'none',
91 'disable_block_styles' => false,
92
93 );
94
95 return apply_filters('prismatic_options_general', $options);
96
97 }
98
99 public static function options_prism() {
100
101 $options = array(
102
103 'prism_theme' => 'default',
104 'filter_content' => 'none',
105 'filter_excerpts' => 'none',
106 'filter_comments' => 'none',
107 'line_highlight' => false,
108 'line_numbers' => false,
109 'show_language' => false,
110 'copy_clipboard' => false,
111 'command_line' => false,
112 'singular_only' => true,
113
114 );
115
116 return apply_filters('prismatic_options_prism', $options);
117
118 }
119
120 public static function options_highlight() {
121
122 $options = array(
123
124 'highlight_theme' => 'default',
125 'filter_content' => 'none',
126 'filter_excerpts' => 'none',
127 'filter_comments' => 'none',
128 'init_javascript' => 'hljs.highlightAll();',
129 'singular_only' => true,
130
131 );
132
133 return apply_filters('prismatic_options_highlight', $options);
134
135 }
136
137 public static function options_plain() {
138
139 $options = array(
140
141 'filter_content' => 'none',
142 'filter_excerpts' => 'none',
143 'filter_comments' => 'none',
144
145 );
146
147 return apply_filters('prismatic_options_plain', $options);
148
149 }
150
151 public static function options_advanced() {
152
153 $options = array(
154
155 'custom_style' => '',
156
157 );
158
159 return apply_filters('prismatic_options_advanced', $options);
160
161 }
162
163 private function constants() {
164
165 if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '3.7');
166 if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.7');
167 if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
168 if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
169 if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
170 if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
171 if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
172 if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
173 if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
174
175 }
176
177 private function includes() {
178
179 require_once PRISMATIC_DIR .'inc/prismatic-blocks.php';
180 require_once PRISMATIC_DIR .'inc/prismatic-buttons.php';
181 require_once PRISMATIC_DIR .'inc/prismatic-core.php';
182 require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
183 require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
184 require_once PRISMATIC_DIR .'inc/settings-display.php';
185 require_once PRISMATIC_DIR .'inc/settings-register.php';
186 require_once PRISMATIC_DIR .'inc/settings-reset.php';
187 require_once PRISMATIC_DIR .'inc/settings-validate.php';
188
189 }
190
191 public function action_links($links, $file) {
192
193 if ($file == PRISMATIC_FILE && (current_user_can('manage_options'))) {
194
195 $prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
196 array_unshift($links, $prismatic_links);
197
198 }
199
200 return $links;
201
202 }
203
204 public function plugin_links($links, $file) {
205
206 if ($file == PRISMATIC_FILE) {
207
208 $home_href = 'https://perishablepress.com/prismatic/';
209 $home_title = esc_attr__('Plugin Homepage', 'prismatic');
210 $home_text = esc_html__('Homepage', 'prismatic');
211
212 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
213
214 $rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
215 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
216 $rate_text = esc_html__('Rate this plugin', 'prismatic') .'&nbsp;&raquo;';
217
218 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
219
220 $pro_href = 'https://plugin-planet.com/prismatic-pro/';
221 $pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
222 $pro_text = esc_html__('Go&nbsp;Pro', 'prismatic');
223 $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
224
225 // $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
226
227 }
228
229 return $links;
230
231 }
232
233 function footer_text($text) {
234
235 $screen_id = prismatic_get_current_screen_id();
236
237 $ids = array('settings_page_prismatic');
238
239 if ($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(PRISMATIC_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