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.

276 lines
7.8KB

  1. <?php // Prismatic - Settings Callbacks
  2. if (!defined('ABSPATH')) exit;
  3. function prismatic_section_general() {
  4. echo '<p>'. esc_html__('Thank you for using the free version of', 'prismatic') .' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/plugins/prismatic/">'. esc_html__('Prismatic', 'prismatic') .'</a>.</p>';
  5. }
  6. function prismatic_section_prism() {
  7. echo '<p>'. esc_html__('Settings for syntax highlighting via', 'prismatic') .' <a target="_blank" rel="noopener noreferrer" href="https://prismjs.com/">'. esc_html__('Prism.js', 'prismatic') .'</a>.</p>';
  8. }
  9. function prismatic_section_prism_code() {
  10. echo '<p>'. esc_html__('Settings for code escaping when Prism.js is enabled.', 'prismatic') .'</p>';
  11. }
  12. function prismatic_section_highlight() {
  13. echo '<p>'. esc_html__('Settings for syntax highlighting via', 'prismatic') .' <a target="_blank" rel="noopener noreferrer" href="https://highlightjs.org/">'. esc_html__('Highlight.js', 'prismatic') .'</a>.</p>';
  14. }
  15. function prismatic_section_highlight_code() {
  16. echo '<p>'. esc_html__('Settings for code escaping when Highlight.js is enabled.', 'prismatic') .'</p>';
  17. }
  18. function prismatic_section_plain() {
  19. echo '<p>'. esc_html__('Settings for code escaping without syntax highlighting.', 'prismatic') .'</p>';
  20. }
  21. function prismatic_library() {
  22. $library = array(
  23. 'prism' => array(
  24. 'value' => 'prism',
  25. 'label' => esc_html__('Prism.js', 'prismatic'),
  26. ),
  27. 'highlight' => array(
  28. 'value' => 'highlight',
  29. 'label' => esc_html__('Highlight.js', 'prismatic'),
  30. ),
  31. 'plain' => array(
  32. 'value' => 'plain',
  33. 'label' => esc_html__('Plain Flavor', 'prismatic'),
  34. ),
  35. 'none' => array(
  36. 'value' => 'none',
  37. 'label' => esc_html__('None (Disable)', 'prismatic'),
  38. ),
  39. );
  40. return $library;
  41. }
  42. function prismatic_location() {
  43. $array = array(
  44. 'front' => array(
  45. 'value' => 'front',
  46. 'label' => esc_html__('Frontend only', 'prismatic'),
  47. ),
  48. 'admin' => array(
  49. 'value' => 'admin',
  50. 'label' => esc_html__('Admin Area only', 'prismatic'),
  51. ),
  52. 'both' => array(
  53. 'value' => 'both',
  54. 'label' => esc_html__('Frontend &amp; Admin Area', 'prismatic'),
  55. ),
  56. 'none' => array(
  57. 'value' => 'none',
  58. 'label' => esc_html__('None (Disable)', 'prismatic'),
  59. ),
  60. );
  61. return $array;
  62. }
  63. function prismatic_prism_theme() {
  64. $theme = array(
  65. 'coy' => array(
  66. 'value' => 'coy',
  67. 'label' => esc_html__('Coy', 'prismatic'),
  68. ),
  69. 'dark' => array(
  70. 'value' => 'dark',
  71. 'label' => esc_html__('Dark', 'prismatic'),
  72. ),
  73. 'default' => array(
  74. 'value' => 'default',
  75. 'label' => esc_html__('Default', 'prismatic'),
  76. ),
  77. 'funky' => array(
  78. 'value' => 'funky',
  79. 'label' => esc_html__('Funky', 'prismatic'),
  80. ),
  81. 'okaidia' => array(
  82. 'value' => 'okaidia',
  83. 'label' => esc_html__('Okaidia', 'prismatic'),
  84. ),
  85. 'solarized' => array(
  86. 'value' => 'solarized',
  87. 'label' => esc_html__('Solarized', 'prismatic'),
  88. ),
  89. 'tomorrow-night' => array(
  90. 'value' => 'tomorrow-night',
  91. 'label' => esc_html__('Tomorrow Night', 'prismatic'),
  92. ),
  93. 'twilight' => array(
  94. 'value' => 'twilight',
  95. 'label' => esc_html__('Twilight', 'prismatic'),
  96. ),
  97. );
  98. return $theme;
  99. }
  100. function prismatic_highlight_theme() {
  101. require_once PRISMATIC_DIR .'lib/highlight/themes.php';
  102. return $theme;
  103. }
  104. function prismatic_callback_select($args) {
  105. $id = isset($args['id']) ? $args['id'] : '';
  106. $label = isset($args['label']) ? $args['label'] : '';
  107. $section = isset($args['section']) ? $args['section'] : '';
  108. $setting = 'prismatic_options_'. $section;
  109. $options = prismatic_get_default_options($section);
  110. $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : '';
  111. $options_array = array();
  112. if ($id === 'library') {
  113. $options_array = prismatic_library();
  114. } elseif ($id === 'filter_content' || $id === 'filter_excerpts' || $id === 'filter_comments') {
  115. $options_array = prismatic_location();
  116. } elseif ($id === 'prism_theme') {
  117. $options_array = prismatic_prism_theme();
  118. } elseif ($id === 'highlight_theme') {
  119. $options_array = prismatic_highlight_theme();
  120. }
  121. echo '<select name="'. $setting .'['. $id .']">';
  122. foreach ($options_array as $option) {
  123. echo '<option '. selected($option['value'], $value, false) .' value="'. $option['value'] .'">'. $option['label'] .'</option>';
  124. }
  125. echo '</select> <label class="prismatic-label inline-block" for="'. $setting .'['. $id .']">'. $label .'</label>';
  126. }
  127. function prismatic_callback_text($args) {
  128. $id = isset($args['id']) ? $args['id'] : '';
  129. $label = isset($args['label']) ? $args['label'] : '';
  130. $section = isset($args['section']) ? $args['section'] : '';
  131. $setting = 'prismatic_options_'. $section;
  132. $options = prismatic_get_default_options($section);
  133. $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : '';
  134. echo '<input name="'. $setting .'['. $id .']" type="text" size="40" value="'. $value .'"> ';
  135. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label">'. $label .'</label>';
  136. }
  137. function prismatic_callback_textarea($args) {
  138. $id = isset($args['id']) ? $args['id'] : '';
  139. $label = isset($args['label']) ? $args['label'] : '';
  140. $section = isset($args['section']) ? $args['section'] : '';
  141. $setting = 'prismatic_options_'. $section;
  142. $options = prismatic_get_default_options($section);
  143. $allowed_tags = wp_kses_allowed_html('post');
  144. $value = isset($options[$id]) ? wp_kses(stripslashes_deep($options[$id]), $allowed_tags) : '';
  145. echo '<textarea name="'. $setting .'['. $id .']" rows="3" cols="50">'. $value .'</textarea> ';
  146. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label" >'. $label .'</label>';
  147. }
  148. function prismatic_callback_checkbox($args) {
  149. $id = isset($args['id']) ? $args['id'] : '';
  150. $label = isset($args['label']) ? $args['label'] : '';
  151. $section = isset($args['section']) ? $args['section'] : '';
  152. $setting = 'prismatic_options_'. $section;
  153. $options = prismatic_get_default_options($section);
  154. $checked = isset($options[$id]) ? checked($options[$id], 1, false) : '';
  155. echo '<input name="'. $setting .'['. $id .']" value="1" type="checkbox" '. $checked .'> ';
  156. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label inline">'. $label .'</label>';
  157. }
  158. function prismatic_callback_number($args) {
  159. $id = isset($args['id']) ? $args['id'] : '';
  160. $label = isset($args['label']) ? $args['label'] : '';
  161. $section = isset($args['section']) ? $args['section'] : '';
  162. $setting = 'prismatic_options_'. $section;
  163. $options = prismatic_get_default_options($section);
  164. $value = isset($options[$id]) ? sanitize_text_field($options[$id]) : '';
  165. $min = 0;
  166. $max = 999;
  167. echo '<input name="'. $setting .'['. $id .']" type="number" min="'. $min .'" max="'. $max .'" value="'. $value .'"> ';
  168. echo '<label for="'. $setting .'['. $id .']" class="prismatic-label inline-block">'. $label .'</label>';
  169. }
  170. function prismatic_callback_reset($args) {
  171. $nonce = wp_create_nonce('prismatic_reset_options');
  172. $url = admin_url('options-general.php?page=prismatic');
  173. $href = esc_url(add_query_arg(array('reset-options-verify' => $nonce), $url));
  174. echo '<a class="prismatic-reset-options" href="'. $href .'">'. esc_html__('Restore default plugin options', 'prismatic') .'</a>';
  175. }
  176. function prismatic_callback_rate($args) {
  177. $href = 'https://wordpress.org/support/plugin/'. PRISMATIC_SLUG .'/reviews/?rate=5#new-post';
  178. $title = esc_attr__('Help keep Prismatic going strong! A huge THANK YOU for your support!', 'prismatic');
  179. $text = isset($args['label']) ? $args['label'] : esc_html__('Show support with a 5-star rating &raquo;', 'prismatic');
  180. echo '<a target="_blank" rel="noopener noreferrer" class="prismatic-rate-plugin" href="'. $href .'" title="'. $title .'">'. $text .'</a>';
  181. }