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