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

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