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

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