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

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