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.

304 lines
9.6KB

  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.1
  13. Stable tag: 2.0
  14. Version: 2.0
  15. Requires PHP: 5.2
  16. Text Domain: prismatic
  17. Domain Path: /languages
  18. License: GPL v2 or later
  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
  24. 2 of the License, or (at your option) any later version.
  25. This program is distributed in the hope that it will be useful,
  26. but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. GNU General Public License for more details.
  29. You should have received a copy of the GNU General Public License
  30. with this program. If not, visit: https://www.gnu.org/licenses/
  31. Copyright 2019 Monzilla Media. All rights reserved.
  32. */
  33. if (!defined('ABSPATH')) die();
  34. if (!class_exists('Prismatic')) {
  35. final class Prismatic {
  36. private static $instance;
  37. public static function instance() {
  38. if (!isset(self::$instance) && !(self::$instance instanceof Prismatic)) {
  39. self::$instance = new Prismatic;
  40. self::$instance->constants();
  41. self::$instance->includes();
  42. add_action('admin_init', array(self::$instance, 'check_plugin'));
  43. add_action('admin_init', array(self::$instance, 'check_version'));
  44. add_action('plugins_loaded', array(self::$instance, 'load_i18n'));
  45. add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
  46. add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
  47. add_action('wp_enqueue_scripts', 'prismatic_enqueue');
  48. add_action('admin_enqueue_scripts', 'prismatic_enqueue');
  49. add_action('admin_enqueue_scripts', 'prismatic_enqueue_settings');
  50. add_action('admin_notices', 'prismatic_admin_notice');
  51. add_action('admin_menu', 'prismatic_menu_pages');
  52. add_action('admin_init', 'prismatic_register_settings');
  53. add_action('admin_init', 'prismatic_reset_options');
  54. add_action('init', 'prismatic_add_filters');
  55. }
  56. return self::$instance;
  57. }
  58. public static function options_general() {
  59. $options = array(
  60. 'library' => 'none',
  61. );
  62. return apply_filters('prismatic_options_general', $options);
  63. }
  64. public static function options_prism() {
  65. $options = array(
  66. 'prism_theme' => 'default',
  67. 'filter_content' => 'none',
  68. 'filter_excerpts' => 'none',
  69. 'filter_comments' => 'none',
  70. 'line_highlight' => false,
  71. 'line_numbers' => false,
  72. 'show_language' => false,
  73. 'singular_only' => true,
  74. );
  75. return apply_filters('prismatic_options_prism', $options);
  76. }
  77. public static function options_highlight() {
  78. $options = array(
  79. 'highlight_theme' => 'default',
  80. 'filter_content' => 'none',
  81. 'filter_excerpts' => 'none',
  82. 'filter_comments' => 'none',
  83. 'init_javascript' => 'hljs.initHighlightingOnLoad();',
  84. 'singular_only' => true,
  85. );
  86. return apply_filters('prismatic_options_highlight', $options);
  87. }
  88. public static function options_plain() {
  89. $options = array(
  90. 'filter_content' => 'none',
  91. 'filter_excerpts' => 'none',
  92. 'filter_comments' => 'none',
  93. );
  94. return apply_filters('prismatic_options_plain', $options);
  95. }
  96. private function constants() {
  97. if (!defined('PRISMATIC_VERSION')) define('PRISMATIC_VERSION', '2.0');
  98. if (!defined('PRISMATIC_REQUIRE')) define('PRISMATIC_REQUIRE', '4.1');
  99. if (!defined('PRISMATIC_NAME')) define('PRISMATIC_NAME', 'Prismatic');
  100. if (!defined('PRISMATIC_AUTHOR')) define('PRISMATIC_AUTHOR', 'Jeff Starr');
  101. if (!defined('PRISMATIC_HOME')) define('PRISMATIC_HOME', 'https://perishablepress.com/prismatic/');
  102. if (!defined('PRISMATIC_URL')) define('PRISMATIC_URL', plugin_dir_url(__FILE__));
  103. if (!defined('PRISMATIC_DIR')) define('PRISMATIC_DIR', plugin_dir_path(__FILE__));
  104. if (!defined('PRISMATIC_FILE')) define('PRISMATIC_FILE', plugin_basename(__FILE__));
  105. if (!defined('PRISMATIC_SLUG')) define('PRISMATIC_SLUG', basename(dirname(__FILE__)));
  106. }
  107. private function includes() {
  108. require_once PRISMATIC_DIR .'inc/prismatic-core.php';
  109. require_once PRISMATIC_DIR .'inc/resources-enqueue.php';
  110. require_once PRISMATIC_DIR .'inc/settings-callbacks.php';
  111. require_once PRISMATIC_DIR .'inc/settings-display.php';
  112. require_once PRISMATIC_DIR .'inc/settings-register.php';
  113. require_once PRISMATIC_DIR .'inc/settings-reset.php';
  114. require_once PRISMATIC_DIR .'inc/settings-validate.php';
  115. }
  116. public function action_links($links, $file) {
  117. if ($file == PRISMATIC_FILE && (current_user_can('manage_options'))) {
  118. $prismatic_links = '<a href="'. admin_url('options-general.php?page=prismatic') .'">'. esc_html__('Settings', 'prismatic') .'</a>';
  119. array_unshift($links, $prismatic_links);
  120. }
  121. return $links;
  122. }
  123. public function plugin_links($links, $file) {
  124. if ($file == plugin_basename(__FILE__)) {
  125. $home_href = 'https://perishablepress.com/prismatic/';
  126. $home_title = esc_attr__('Plugin Homepage', 'prismatic');
  127. $home_text = esc_html__('Homepage', 'prismatic');
  128. $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
  129. $rate_href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
  130. $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'prismatic');
  131. $rate_text = esc_html__('Rate this plugin', 'prismatic') .'&nbsp;&raquo;';
  132. $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
  133. $pro_href = 'https://plugin-planet.com/prismatic-pro/?plugin';
  134. $pro_title = esc_attr__('Get Prismatic Pro!', 'prismatic');
  135. $pro_text = esc_html__('Go&nbsp;Pro', 'prismatic');
  136. $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
  137. // $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
  138. }
  139. return $links;
  140. }
  141. public function check_plugin() {
  142. if (class_exists('Prismatic_Pro')) {
  143. if (is_plugin_active(PRISMATIC_FILE)) {
  144. deactivate_plugins(PRISMATIC_FILE);
  145. $msg = '<strong>'. esc_html__('Warning:', 'prismatic') .'</strong> ';
  146. $msg .= esc_html__('Pro version of Prismatic currently active. Free and Pro versions cannot be activated at the same time. ', 'prismatic');
  147. $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'prismatic') .'</a> ';
  148. $msg .= esc_html__('and try again.', 'prismatic');
  149. wp_die($msg);
  150. }
  151. }
  152. }
  153. public function check_version() {
  154. $wp_version = get_bloginfo('version');
  155. if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
  156. if (version_compare($wp_version, PRISMATIC_REQUIRE, '<')) {
  157. if (is_plugin_active(PRISMATIC_FILE)) {
  158. deactivate_plugins(PRISMATIC_FILE);
  159. $msg = '<strong>'. PRISMATIC_NAME .'</strong> '. esc_html__('requires WordPress ', 'prismatic') . PRISMATIC_REQUIRE;
  160. $msg .= esc_html__(' or higher, and has been deactivated! ', 'prismatic');
  161. $msg .= esc_html__('Please return to the', 'prismatic') .' <a href="'. admin_url() .'">';
  162. $msg .= esc_html__('WP Admin Area', 'prismatic') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'prismatic');
  163. wp_die($msg);
  164. }
  165. }
  166. }
  167. }
  168. public function load_i18n() {
  169. load_plugin_textdomain('prismatic', false, PRISMATIC_DIR .'languages/');
  170. }
  171. public function __clone() {
  172. _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
  173. }
  174. public function __wakeup() {
  175. _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'prismatic'), PRISMATIC_VERSION);
  176. }
  177. }
  178. }
  179. if (class_exists('Prismatic')) {
  180. $prismatic_options_general = get_option('prismatic_options_general', Prismatic::options_general());
  181. $prismatic_options_general = apply_filters('prismatic_get_options_general', $prismatic_options_general);
  182. $prismatic_options_prism = get_option('prismatic_options_prism', Prismatic::options_prism());
  183. $prismatic_options_prism = apply_filters('prismatic_get_options_prism', $prismatic_options_prism);
  184. $prismatic_options_highlight = get_option('prismatic_options_highlight', Prismatic::options_highlight());
  185. $prismatic_options_highlight = apply_filters('prismatic_get_options_highlight', $prismatic_options_highlight);
  186. $prismatic_options_plain = get_option('prismatic_options_plain', Prismatic::options_plain());
  187. $prismatic_options_plain = apply_filters('prismatic_get_options_plain', $prismatic_options_plain);
  188. if (!function_exists('prismatic')) {
  189. function prismatic() {
  190. do_action('prismatic');
  191. return Prismatic::instance();
  192. }
  193. }
  194. prismatic();
  195. }