No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

292 líneas
9.0KB

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