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

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