2016-10-24 13:20:42 -04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Plugin Name: Prismatic
|
2016-11-16 18:27:56 -05:00
|
|
|
Plugin URI: https://perishablepress.com/prismatic/
|
2016-10-24 13:20:42 -04:00
|
|
|
Description: Display beautiful syntax-highlighted code snippets with Prism.js or Highlight.js
|
2017-05-20 19:58:35 -04:00
|
|
|
Tags: code, snippets, syntax, highlight, language, snippet, pre, prettify, prism, css, fence
|
2016-10-24 13:20:42 -04:00
|
|
|
Author: Jeff Starr
|
|
|
|
Contributors: specialk
|
|
|
|
Author URI: https://plugin-planet.com/
|
2017-05-20 19:58:35 -04:00
|
|
|
Donate link: https://m0n.co/donate
|
2016-10-24 13:20:42 -04:00
|
|
|
Requires at least: 4.1
|
2017-05-20 19:58:35 -04:00
|
|
|
Tested up to: 4.8
|
2017-08-05 15:47:50 -04:00
|
|
|
Stable tag: 1.4
|
|
|
|
Version: 1.4
|
2016-10-24 13:20:42 -04:00
|
|
|
Text Domain: prismatic
|
|
|
|
Domain Path: /languages
|
|
|
|
License: GPL v2 or later
|
|
|
|
*/
|
|
|
|
|
2017-05-20 19:58:35 -04:00
|
|
|
/*
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
2017-08-05 15:47:50 -04:00
|
|
|
as published by the Free Software Foundation; either version
|
|
|
|
2 of the License, or (at your option) any later version.
|
2017-05-20 19:58:35 -04:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2017-08-05 15:47:50 -04:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
with this program. If not, visit: https://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
Copyright 2017 Monzilla Media. All rights reserved.
|
2017-05-20 19:58:35 -04:00
|
|
|
*/
|
|
|
|
|
2016-10-24 13:20:42 -04:00
|
|
|
if (!defined('ABSPATH')) die();
|
|
|
|
|
|
|
|
if (!class_exists('Prismatic')) {
|
|
|
|
|
|
|
|
final class Prismatic {
|
|
|
|
|
|
|
|
private static $instance;
|
|
|
|
|
|
|
|
public static function instance() {
|
|
|
|
|
|
|
|
if (!isset(self::$instance) && !(self::$instance instanceof Prismatic)) {
|
|
|
|
|
|
|
|
self::$instance = new Prismatic;
|
|
|
|
self::$instance->constants();
|
|
|
|
self::$instance->includes();
|
|
|
|
|
|
|
|
add_action('admin_init', array(self::$instance, 'check_plugin'));
|
|
|
|
add_action('admin_init', array(self::$instance, 'check_version'));
|
|
|
|
add_action('plugins_loaded', array(self::$instance, 'load_i18n'));
|
|
|
|
add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
|
|
|
|
add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
|
|
|
|
|
|
|
|
add_action('wp_enqueue_scripts', 'prismatic_enqueue_front');
|
|
|
|
add_action('admin_enqueue_scripts', 'prismatic_enqueue_admin');
|
|
|
|
add_action('admin_notices', 'prismatic_admin_notice');
|
|
|
|
add_action('admin_menu', 'prismatic_menu_pages');
|
|
|
|
add_action('admin_init', 'prismatic_register_settings');
|
|
|
|
add_action('admin_init', 'prismatic_reset_options');
|
|
|
|
|
|
|
|
add_action('init', 'prismatic_add_filters');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function options_general() {
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
|
|
|
'library' => 'none',
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return apply_filters('prismatic_options_general', $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function options_prism() {
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
|
|
|
'prism_theme' => 'default',
|
|
|
|
'filter_content' => 'none',
|
|
|
|
'filter_excerpts' => 'none',
|
|
|
|
'filter_comments' => 'none',
|
|
|
|
'line_highlight' => false,
|
|
|
|
'line_numbers' => false,
|
|
|
|
'show_language' => false,
|
|
|
|
'singular_only' => true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return apply_filters('prismatic_options_prism', $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function options_highlight() {
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
|
|
|
'highlight_theme' => 'default',
|
|
|
|
'filter_content' => 'none',
|
|
|
|
'filter_excerpts' => 'none',
|
|
|
|
'filter_comments' => 'none',
|
|
|
|
'init_javascript' => 'hljs.initHighlightingOnLoad();',
|
|
|
|
'singular_only' => true,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return apply_filters('prismatic_options_highlight', $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function options_plain() {
|
|
|
|
|
|
|
|
$options = array(
|
|
|
|
|
|
|
|
'filter_content' => 'none',
|
|
|
|
'filter_excerpts' => 'none',
|
|
|
|
'filter_comments' => 'none',
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return apply_filters('prismatic_options_plain', $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function constants() {
|
|
|
|
|
2017-08-05 15:47:50 -04:00
|
|
|
if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '1.4');
|
2016-10-24 13:20:42 -04:00
|
|
|
if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.1');
|
|
|
|
if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
|
|
|
|
if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
|
2016-11-16 18:27:56 -05:00
|
|
|
if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
|
2016-10-24 13:20:42 -04:00
|
|
|
if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
|
|
|
|
if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
|
|
|
|
if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
|
|
|
|
if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function includes() {
|
|
|
|
|
|
|
|
require_once PRISMATIC_DIR .'inc/prismatic-core.php';
|
|
|
|
require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
|
|
|
|
require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
|
|
|
|
require_once PRISMATIC_DIR .'inc/settings-display.php';
|
|
|
|
require_once PRISMATIC_DIR .'inc/settings-register.php';
|
|
|
|
require_once PRISMATIC_DIR .'inc/settings-reset.php';
|
|
|
|
require_once PRISMATIC_DIR .'inc/settings-validate.php';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_links($links, $file) {
|
|
|
|
|
|
|
|
if ($file == PRISMATIC_FILE) {
|
|
|
|
|
|
|
|
$prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
|
|
|
|
array_unshift($links, $prismatic_links);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $links;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function plugin_links($links, $file) {
|
|
|
|
|
|
|
|
if ($file == plugin_basename(__FILE__)) {
|
|
|
|
|
|
|
|
$rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
|
|
|
|
$rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
|
2016-11-16 18:27:56 -05:00
|
|
|
$rate_text = esc_html__('Rate this plugin', 'prismatic') .' »';
|
2016-10-24 13:20:42 -04:00
|
|
|
|
|
|
|
$pro_href = 'https://plugin-planet.com/prismatic-pro/?plugin';
|
|
|
|
$pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
|
|
|
|
$pro_text = esc_html__('Go Pro', 'prismatic');
|
|
|
|
$pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
|
|
|
|
|
|
|
|
$links[] = '<a target="_blank" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
|
|
|
|
// $links[] = '<a target="_blank" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $links;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function check_plugin() {
|
|
|
|
|
|
|
|
if (class_exists('Prismatic_Pro')) {
|
|
|
|
|
|
|
|
if (is_plugin_active(PRISMATIC_FILE)) {
|
|
|
|
|
|
|
|
deactivate_plugins(PRISMATIC_FILE);
|
|
|
|
|
|
|
|
$msg = '<strong>'. esc_html__('Warning:', 'prismatic') .'</strong> ';
|
|
|
|
$msg .= esc_html__('Pro version of Prismatic currently active. Free and Pro versions cannot be activated at the same time. ', 'prismatic');
|
|
|
|
$msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'prismatic') .'</a> ';
|
|
|
|
$msg .= esc_html__('and try again.', 'prismatic');
|
|
|
|
|
|
|
|
wp_die($msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function check_version() {
|
|
|
|
|
2017-05-20 19:58:35 -04:00
|
|
|
$wp_version = get_bloginfo('version');
|
2016-10-24 13:20:42 -04:00
|
|
|
|
|
|
|
if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
|
|
|
|
|
|
|
|
if (version_compare($wp_version, PRISMATIC_REQUIRE, '<')) {
|
|
|
|
|
|
|
|
if (is_plugin_active(PRISMATIC_FILE)) {
|
|
|
|
|
|
|
|
deactivate_plugins(PRISMATIC_FILE);
|
|
|
|
|
|
|
|
$msg = '<strong>'. PRISMATIC_NAME .'</strong> '. esc_html__('requires WordPress ', 'prismatic') . PRISMATIC_REQUIRE;
|
|
|
|
$msg .= esc_html__(' or higher, and has been deactivated! ', 'prismatic');
|
|
|
|
$msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">';
|
|
|
|
$msg .= esc_html__('WP Admin Area', 'prismatic') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'prismatic');
|
|
|
|
|
|
|
|
wp_die($msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function load_i18n() {
|
|
|
|
|
|
|
|
load_plugin_textdomain('prismatic', false, PRISMATIC_DIR .'languages/');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __clone() {
|
|
|
|
|
|
|
|
_doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'prismatic'), PRISMATIC_VERSION);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __wakeup() {
|
|
|
|
|
|
|
|
_doing_it_wrong(__FUNCTION__, esc_html__('Cheatin’ huh?', 'prismatic'), PRISMATIC_VERSION);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (class_exists('Prismatic')) {
|
|
|
|
|
|
|
|
$prismatic_options_general = get_option('prismatic_options_general', Prismatic::options_general());
|
|
|
|
$prismatic_options_general = apply_filters('prismatic_get_options_general', $prismatic_options_general);
|
|
|
|
|
|
|
|
$prismatic_options_prism = get_option('prismatic_options_prism', Prismatic::options_prism());
|
|
|
|
$prismatic_options_prism = apply_filters('prismatic_get_options_prism', $prismatic_options_prism);
|
|
|
|
|
|
|
|
$prismatic_options_highlight = get_option('prismatic_options_highlight', Prismatic::options_highlight());
|
|
|
|
$prismatic_options_highlight = apply_filters('prismatic_get_options_highlight', $prismatic_options_highlight);
|
|
|
|
|
|
|
|
$prismatic_options_plain = get_option('prismatic_options_plain', Prismatic::options_plain());
|
|
|
|
$prismatic_options_plain = apply_filters('prismatic_get_options_plain', $prismatic_options_plain);
|
|
|
|
|
|
|
|
if (!function_exists('prismatic')) {
|
|
|
|
|
|
|
|
function prismatic() {
|
|
|
|
|
|
|
|
do_action('prismatic');
|
|
|
|
|
|
|
|
return Prismatic::instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
prismatic();
|
|
|
|
|
|
|
|
}
|