PluginProbe
Prismatic / 1.3
Prismatic v1.3
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 1.3, at prismatic.php

292 lines 9.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://m0n.co/donate
11 Requires at least: 4.1
12 Tested up to: 4.8
13 Stable tag: 1.3
14 Version: 1.3
15 Text Domain: prismatic
16 Domain Path: /languages
17 License: GPL v2 or later
18 */
19
20 /*
21 This program is free software; you can redistribute it and/or
22 modify it under the terms of the GNU General Public License
23 as published by the Free Software Foundation; either version 2
24 of the License, or (at your option) any later version.
25
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 Get a copy of the GNU General Public License: http://www.gnu.org/licenses/
32 */
33
34 if (!defined('ABSPATH')) die();
35
36 if (!class_exists('Prismatic')) {
37
38 final class Prismatic {
39
40 private static $instance;
41
42 public static function instance() {
43
44 if (!isset(self::$instance) && !(self::$instance instanceof Prismatic)) {
45
46 self::$instance = new Prismatic;
47 self::$instance->constants();
48 self::$instance->includes();
49
50 add_action('admin_init', array(self::$instance, 'check_plugin'));
51 add_action('admin_init', array(self::$instance, 'check_version'));
52 add_action('plugins_loaded', array(self::$instance, 'load_i18n'));
53 add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
54 add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
55
56 add_action('wp_enqueue_scripts', 'prismatic_enqueue_front');
57 add_action('admin_enqueue_scripts', 'prismatic_enqueue_admin');
58 add_action('admin_notices', 'prismatic_admin_notice');
59 add_action('admin_menu', 'prismatic_menu_pages');
60 add_action('admin_init', 'prismatic_register_settings');
61 add_action('admin_init', 'prismatic_reset_options');
62
63 add_action('init', 'prismatic_add_filters');
64
65 }
66
67 return self::$instance;
68
69 }
70
71 public static function options_general() {
72
73 $options = array(
74
75 'library' => 'none',
76
77 );
78
79 return apply_filters('prismatic_options_general', $options);
80
81 }
82
83 public static function options_prism() {
84
85 $options = array(
86
87 'prism_theme' => 'default',
88 'filter_content' => 'none',
89 'filter_excerpts' => 'none',
90 'filter_comments' => 'none',
91 'line_highlight' => false,
92 'line_numbers' => false,
93 'show_language' => false,
94 'singular_only' => true,
95
96 );
97
98 return apply_filters('prismatic_options_prism', $options);
99
100 }
101
102 public static function options_highlight() {
103
104 $options = array(
105
106 'highlight_theme' => 'default',
107 'filter_content' => 'none',
108 'filter_excerpts' => 'none',
109 'filter_comments' => 'none',
110 'init_javascript' => 'hljs.initHighlightingOnLoad();',
111 'singular_only' => true,
112
113 );
114
115 return apply_filters('prismatic_options_highlight', $options);
116
117 }
118
119 public static function options_plain() {
120
121 $options = array(
122
123 'filter_content' => 'none',
124 'filter_excerpts' => 'none',
125 'filter_comments' => 'none',
126
127 );
128
129 return apply_filters('prismatic_options_plain', $options);
130
131 }
132
133 private function constants() {
134
135 if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '1.3');
136 if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.1');
137 if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
138 if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
139 if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
140 if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
141 if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
142 if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
143 if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
144
145 }
146
147 private function includes() {
148
149 require_once PRISMATIC_DIR .'inc/prismatic-core.php';
150 require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
151 require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
152 require_once PRISMATIC_DIR .'inc/settings-display.php';
153 require_once PRISMATIC_DIR .'inc/settings-register.php';
154 require_once PRISMATIC_DIR .'inc/settings-reset.php';
155 require_once PRISMATIC_DIR .'inc/settings-validate.php';
156
157 }
158
159 public function action_links($links, $file) {
160
161 if ($file == PRISMATIC_FILE) {
162
163 $prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
164 array_unshift($links, $prismatic_links);
165
166 }
167
168 return $links;
169
170 }
171
172 public function plugin_links($links, $file) {
173
174 if ($file == plugin_basename(__FILE__)) {
175
176 $rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
177 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
178 $rate_text = esc_html__('Rate this plugin', 'prismatic') .'&nbsp;&raquo;';
179
180 $pro_href = 'https://plugin-planet.com/prismatic-pro/?plugin';
181 $pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
182 $pro_text = esc_html__('Go&nbsp;Pro', 'prismatic');
183 $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
184
185 $links[] = '<a target="_blank" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
186 // $links[] = '<a target="_blank" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
187
188 }
189
190 return $links;
191
192 }
193
194 public function check_plugin() {
195
196 if (class_exists('Prismatic_Pro')) {
197
198 if (is_plugin_active(PRISMATIC_FILE)) {
199
200 deactivate_plugins(PRISMATIC_FILE);
201
202 $msg = '<strong>'. esc_html__('Warning:', 'prismatic') .'</strong> ';
203 $msg .= esc_html__('Pro version of Prismatic currently active. Free and Pro versions cannot be activated at the same time. ', 'prismatic');
204 $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'prismatic') .'</a> ';
205 $msg .= esc_html__('and try again.', 'prismatic');
206
207 wp_die($msg);
208
209 }
210
211 }
212
213 }
214
215 public function check_version() {
216
217 $wp_version = get_bloginfo('version');
218
219 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
220
221 if (version_compare($wp_version, PRISMATIC_REQUIRE, '<')) {
222
223 if (is_plugin_active(PRISMATIC_FILE)) {
224
225 deactivate_plugins(PRISMATIC_FILE);
226
227 $msg = '<strong>'. PRISMATIC_NAME .'</strong> '. esc_html__('requires WordPress ', 'prismatic') . PRISMATIC_REQUIRE;
228 $msg .= esc_html__(' or higher, and has been deactivated! ', 'prismatic');
229 $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">';
230 $msg .= esc_html__('WP Admin Area', 'prismatic') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'prismatic');
231
232 wp_die($msg);
233
234 }
235
236 }
237
238 }
239
240 }
241
242 public function load_i18n() {
243
244 load_plugin_textdomain('prismatic', false, PRISMATIC_DIR .'languages/');
245
246 }
247
248 public function __clone() {
249
250 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
251
252 }
253
254 public function __wakeup() {
255
256 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
257
258 }
259
260 }
261
262 }
263
264 if (class_exists('Prismatic')) {
265
266 $prismatic_options_general = get_option('prismatic_options_general', Prismatic::options_general());
267 $prismatic_options_general = apply_filters('prismatic_get_options_general', $prismatic_options_general);
268
269 $prismatic_options_prism = get_option('prismatic_options_prism', Prismatic::options_prism());
270 $prismatic_options_prism = apply_filters('prismatic_get_options_prism', $prismatic_options_prism);
271
272 $prismatic_options_highlight = get_option('prismatic_options_highlight', Prismatic::options_highlight());
273 $prismatic_options_highlight = apply_filters('prismatic_get_options_highlight', $prismatic_options_highlight);
274
275 $prismatic_options_plain = get_option('prismatic_options_plain', Prismatic::options_plain());
276 $prismatic_options_plain = apply_filters('prismatic_get_options_plain', $prismatic_options_plain);
277
278 if (!function_exists('prismatic')) {
279
280 function prismatic() {
281
282 do_action('prismatic');
283
284 return Prismatic::instance();
285 }
286
287 }
288
289 prismatic();
290
291 }
292