You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
8.4KB

  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, css, fence, highlight, language, pre, prettify, prism, snippet, syntax
  7. Author: Jeff Starr
  8. Contributors: specialk
  9. Author URI: https://plugin-planet.com/
  10. Donate link: http://m0n.co/donate
  11. Requires at least: 4.1
  12. Tested up to: 4.7
  13. Stable tag: 1.2
  14. Version: 1.2
  15. Text Domain: prismatic
  16. Domain Path: /languages
  17. License: GPL v2 or later
  18. */
  19. if (!defined('ABSPATH')) die();
  20. if (!class_exists('Prismatic')) {
  21. final class Prismatic {
  22. private static $instance;
  23. public static function instance() {
  24. if (!isset(self::$instance) && !(self::$instance instanceof Prismatic)) {
  25. self::$instance = new Prismatic;
  26. self::$instance->constants();
  27. self::$instance->includes();
  28. add_action('admin_init', array(self::$instance, 'check_plugin'));
  29. add_action('admin_init', array(self::$instance, 'check_version'));
  30. add_action('plugins_loaded', array(self::$instance, 'load_i18n'));
  31. add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
  32. add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
  33. add_action('wp_enqueue_scripts', 'prismatic_enqueue_front');
  34. add_action('admin_enqueue_scripts', 'prismatic_enqueue_admin');
  35. add_action('admin_notices', 'prismatic_admin_notice');
  36. add_action('admin_menu', 'prismatic_menu_pages');
  37. add_action('admin_init', 'prismatic_register_settings');
  38. add_action('admin_init', 'prismatic_reset_options');
  39. add_action('init', 'prismatic_add_filters');
  40. }
  41. return self::$instance;
  42. }
  43. public static function options_general() {
  44. $options = array(
  45. 'library' => 'none',
  46. );
  47. return apply_filters('prismatic_options_general', $options);
  48. }
  49. public static function options_prism() {
  50. $options = array(
  51. 'prism_theme' => 'default',
  52. 'filter_content' => 'none',
  53. 'filter_excerpts' => 'none',
  54. 'filter_comments' => 'none',
  55. 'line_highlight' => false,
  56. 'line_numbers' => false,
  57. 'show_language' => false,
  58. 'singular_only' => true,
  59. );
  60. return apply_filters('prismatic_options_prism', $options);
  61. }
  62. public static function options_highlight() {
  63. $options = array(
  64. 'highlight_theme' => 'default',
  65. 'filter_content' => 'none',
  66. 'filter_excerpts' => 'none',
  67. 'filter_comments' => 'none',
  68. 'init_javascript' => 'hljs.initHighlightingOnLoad();',
  69. 'singular_only' => true,
  70. );
  71. return apply_filters('prismatic_options_highlight', $options);
  72. }
  73. public static function options_plain() {
  74. $options = array(
  75. 'filter_content' => 'none',
  76. 'filter_excerpts' => 'none',
  77. 'filter_comments' => 'none',
  78. );
  79. return apply_filters('prismatic_options_plain', $options);
  80. }
  81. private function constants() {
  82. if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '1.2');
  83. if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.1');
  84. if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
  85. if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
  86. if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
  87. if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
  88. if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
  89. if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
  90. if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
  91. }
  92. private function includes() {
  93. require_once PRISMATIC_DIR .'inc/prismatic-core.php';
  94. require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
  95. require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
  96. require_once PRISMATIC_DIR .'inc/settings-display.php';
  97. require_once PRISMATIC_DIR .'inc/settings-register.php';
  98. require_once PRISMATIC_DIR .'inc/settings-reset.php';
  99. require_once PRISMATIC_DIR .'inc/settings-validate.php';
  100. }
  101. public function action_links($links, $file) {
  102. if ($file == PRISMATIC_FILE) {
  103. $prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
  104. array_unshift($links, $prismatic_links);
  105. }
  106. return $links;
  107. }
  108. public function plugin_links($links, $file) {
  109. if ($file == plugin_basename(__FILE__)) {
  110. $rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
  111. $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
  112. $rate_text = esc_html__('Rate this plugin', 'prismatic') .'&nbsp;&raquo;';
  113. $pro_href = 'https://plugin-planet.com/prismatic-pro/?plugin';
  114. $pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
  115. $pro_text = esc_html__('Go&nbsp;Pro', 'prismatic');
  116. $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
  117. $links[] = '<a target="_blank" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
  118. // $links[] = '<a target="_blank" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
  119. }
  120. return $links;
  121. }
  122. public function check_plugin() {
  123. if (class_exists('Prismatic_Pro')) {
  124. if (is_plugin_active(PRISMATIC_FILE)) {
  125. deactivate_plugins(PRISMATIC_FILE);
  126. $msg = '<strong>'. esc_html__('Warning:', 'prismatic') .'</strong> ';
  127. $msg .= esc_html__('Pro version of Prismatic currently active. Free and Pro versions cannot be activated at the same time. ', 'prismatic');
  128. $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'prismatic') .'</a> ';
  129. $msg .= esc_html__('and try again.', 'prismatic');
  130. wp_die($msg);
  131. }
  132. }
  133. }
  134. public function check_version() {
  135. global $wp_version;
  136. if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
  137. if (version_compare($wp_version, PRISMATIC_REQUIRE, '<')) {
  138. if (is_plugin_active(PRISMATIC_FILE)) {
  139. deactivate_plugins(PRISMATIC_FILE);
  140. $msg = '<strong>'. PRISMATIC_NAME .'</strong> '. esc_html__('requires WordPress ', 'prismatic') . PRISMATIC_REQUIRE;
  141. $msg .= esc_html__(' or higher, and has been deactivated! ', 'prismatic');
  142. $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">';
  143. $msg .= esc_html__('WP Admin Area', 'prismatic') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'prismatic');
  144. wp_die($msg);
  145. }
  146. }
  147. }
  148. }
  149. public function load_i18n() {
  150. load_plugin_textdomain('prismatic', false, PRISMATIC_DIR .'languages/');
  151. }
  152. public function __clone() {
  153. _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
  154. }
  155. public function __wakeup() {
  156. _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
  157. }
  158. }
  159. }
  160. if (class_exists('Prismatic')) {
  161. $prismatic_options_general = get_option('prismatic_options_general', Prismatic::options_general());
  162. $prismatic_options_general = apply_filters('prismatic_get_options_general', $prismatic_options_general);
  163. $prismatic_options_prism = get_option('prismatic_options_prism', Prismatic::options_prism());
  164. $prismatic_options_prism = apply_filters('prismatic_get_options_prism', $prismatic_options_prism);
  165. $prismatic_options_highlight = get_option('prismatic_options_highlight', Prismatic::options_highlight());
  166. $prismatic_options_highlight = apply_filters('prismatic_get_options_highlight', $prismatic_options_highlight);
  167. $prismatic_options_plain = get_option('prismatic_options_plain', Prismatic::options_plain());
  168. $prismatic_options_plain = apply_filters('prismatic_get_options_plain', $prismatic_options_plain);
  169. if (!function_exists('prismatic')) {
  170. function prismatic() {
  171. do_action('prismatic');
  172. return Prismatic::instance();
  173. }
  174. }
  175. prismatic();
  176. }