PluginProbe
Prismatic / 2.9
Prismatic v2.9
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 2.9, at prismatic.php

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