PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-glossary/class/wpg-admin.class.php

https://gitlab.com/decarola/mistic-be
PHP | 240 lines | 207 code | 24 blank | 9 comment | 0 complexity | e6f60d12ca362d2d24181ec36fb09f4e MD5 | raw file
  1. <?php
  2. /**
  3. * WP-Glossary Admin
  4. */
  5. class WPG_Admin{
  6. static $base;
  7. static $base_url;
  8. public function __construct( $plugin_base ) {
  9. self::$base = $plugin_base . '/class';
  10. self::$base_url = plugins_url( '', dirname(__FILE__) );
  11. add_action( 'admin_menu', array(&$this, 'options_submenu') );
  12. add_action( 'wp_ajax_wpg_update_options', array(&$this, 'update_options') );
  13. add_action( 'admin_head', array(&$this, 'add_tinymce_dropdown_hooks') );
  14. add_action( 'admin_init', array(&$this, 'setup_localixed_dropdown_values') );
  15. }
  16. static function base() {
  17. return self::$base;
  18. }
  19. static function base_url() {
  20. return self::$base_url;
  21. }
  22. public function add_tinymce_dropdown_hooks() {
  23. add_filter( 'mce_external_plugins', array(&$this, 'tinymce_add_dropdown_plugin') );
  24. add_filter( 'mce_buttons', array(&$this, 'tinymce_add_dropdown_button') );
  25. }
  26. public function tinymce_add_dropdown_plugin( $plugin_array ){
  27. $plugin_array['wpglossary'] = $this->base_url() . '/js/tinymce-wpglossary-dropdown.js';
  28. return $plugin_array;
  29. }
  30. public function tinymce_add_dropdown_button( $buttons ){
  31. array_push( $buttons, 'wpglossary' );
  32. return $buttons;
  33. }
  34. public function setup_localixed_dropdown_values(){
  35. $args = array(
  36. 'post_type' => 'glossary',
  37. 'numberposts' => -1,
  38. 'post_status' => 'publish',
  39. 'orderby' => 'title',
  40. 'order' => 'ASC',
  41. );
  42. $glossaryposts = get_posts( $args );
  43. $glossaryterms = array();
  44. foreach( $glossaryposts as $glossary ):
  45. $glossaryterms[$glossary->post_title] = "[glossary id='{$glossary->ID}' slug='{$glossary->post_name}' /]";
  46. endforeach;
  47. wp_localize_script( 'jquery', 'WPG', array(
  48. 'tinymce_dropdown' => $glossaryterms,
  49. ) );
  50. }
  51. public function options_submenu(){
  52. $slug = 'glossary';
  53. // Add menu page (capture page for adding admin style and javascript
  54. $glossary_options = add_submenu_page(
  55. "edit.php?post_type=$slug",
  56. __( 'Glossary Options', 'wp-glossary' ),
  57. __( 'Glossary Options', 'wp-glossary' ),
  58. 'manage_options',
  59. 'glossary-options',
  60. array($this, 'options')
  61. );
  62. }
  63. public function options(){
  64. $ajax = admin_url( 'admin-ajax.php' );
  65. $options = get_option( 'wp_glossary', array() );
  66. $tooltips = isset( $options['tooltips'] ) ? $options['tooltips'] : 'excerpt';
  67. $alphaarchive = isset( $options['alphaarchive'] ) ? $options['alphaarchive'] : 'standard';
  68. $qtipstyle = isset( $options['qtipstyle'] ) ? $options['qtipstyle'] : 'cream';
  69. $termlinkopt = isset( $options['termlinkopt'] ) ? $options['termlinkopt'] : 'standard';
  70. $reflinkopt = isset( $options['reflinkopt'] ) ? $options['reflinkopt'] : 'on';
  71. $termusage = isset( $options['termusage'] ) ? $options['termusage'] : 'on';
  72. $qtiptrigger = isset( $options['qtiptrigger'] ) ? $options['qtiptrigger'] : 'hover';
  73. // Tooptip DD
  74. $ttddoptions = array(
  75. 'full' => array(
  76. 'title' => __('Full', 'wp-glossary'),
  77. 'attrs' => array('title'=>__('Display full post content', 'wp-glossary'))
  78. ),
  79. 'excerpt' => array(
  80. 'title' => __('Excerpt', 'wp-glossary'),
  81. 'attrs' => array('title'=>__('Display shorter excerpt content', 'wp-glossary'))
  82. ),
  83. 'off' => array(
  84. 'title' => __('Off', 'wp-glossary'),
  85. 'attrs' => array('title'=>__('Do not display tooltip at all', 'wp-glossary'))
  86. ),
  87. );
  88. $tooltipdropdown = tcb_wpg_build_dropdown( 'tooltips', array(
  89. 'selected' => $tooltips,
  90. 'options' => $ttddoptions,
  91. ) );
  92. // Alpha Arrhive DD
  93. $aaddoptions = array(
  94. 'alphabet' => array('title'=>__('Alphabetical', 'wp-glossary'), 'attrs'=>array('title'=>__('Display glossary archive alphabetically', 'wp-glossary'))),
  95. 'standard' => array('title'=>__('Standard', 'wp-glossary'), 'attrs'=>array('title'=>__('No filtering, display as standard archive', 'wp-glossary'))),
  96. );
  97. $archivedropdown = tcb_wpg_build_dropdown( 'alphaarchive', array(
  98. 'selected' => $alphaarchive,
  99. 'options' => $aaddoptions,
  100. ) );
  101. // qTipd syle options
  102. $qtipdropdown = tcb_wpg_build_dropdown( 'qtipstyle', array(
  103. 'selected' => $qtipstyle,
  104. 'options' => array(
  105. 'cream' => __('Cream', 'wp-glossary'),
  106. 'dark' => __('Dark', 'wp-glossary'),
  107. 'green' => __('Green', 'wp-glossary'),
  108. 'light' => __('Light', 'wp-glossary'),
  109. 'red' => __('Red', 'wp-glossary'),
  110. 'blue' => __('Blue', 'wp-glossary'),
  111. 'plain' => __('Plain', 'wp-glossary'),
  112. 'bootstrap' => __('Bootstrap', 'wp-glossary'),
  113. 'youtube' => __('YouTube', 'wp-glossary'),
  114. 'tipsy' => __('Tipsy', 'wp-glossary'),
  115. ),
  116. ));
  117. $qtiptriggerdropdown = tcb_wpg_build_dropdown( 'qtiptrigger', array(
  118. 'selected' => $qtiptrigger,
  119. 'options' => array(
  120. 'hover' => array('title'=>__('Hover', 'wp-glossary'), 'attrs'=>array('title'=>__('On mouseover (hover)', 'wp-glossary'))),
  121. 'click' => array('title'=>__('Click', 'wp-glossary'), 'attrs'=>array('title'=>__('On click', 'wp-glossary'))),
  122. ),
  123. ));
  124. // Term Link HREF target
  125. $termlinkoptdropdown = tcb_wpg_build_dropdown( 'termlinkopt', array(
  126. 'selected' => $termlinkopt,
  127. 'options' => array(
  128. 'standard' => array('title'=>__('Normal', 'wp-glossary'), 'attrs'=>array('title'=>__('Normal link with no modifications', 'wp-glossary'))),
  129. 'none' => array('title'=>__('No link', 'wp-glossary'), 'attrs'=>array('title'=>__("Don't link to term", 'wp-glossary'))),
  130. 'blank' => array('title'=>__('New tab', 'wp-glossary'), 'attrs'=>array('title'=>__("Always open in a new tab", 'wp-glossary'))),
  131. ),
  132. ));
  133. // Term Link HREF target
  134. $reflinkoptdropdown = tcb_wpg_build_dropdown( 'reflinkopt', array(
  135. 'selected' => $reflinkopt,
  136. 'options' => array(
  137. 'on' => array('title'=>__('On', 'wp-glossary'), 'attrs'=>array('title'=>__('Reference link will be shown', 'wp-glossary'))),
  138. 'off' => array('title'=>__('Off', 'wp-glossary'), 'attrs'=>array('title'=>__("Don't link to reference", 'wp-glossary'))),
  139. ),
  140. ));
  141. // Term usage
  142. $termusagedd = tcb_wpg_build_dropdown( 'termusage', array(
  143. 'selected' => $termusage,
  144. 'options' => array(
  145. 'on' => __('On', 'wp-glossary'),
  146. 'off' => __('Off', 'wp-glossary'),
  147. ),
  148. ) );
  149. ?>
  150. <div class="wrap">
  151. <div id="wp-glossary-options" class="meta-box meta-box-50" style="width: 50%;">
  152. <div class="meta-box-inside admin-help">
  153. <div class="icon32" id="icon-options-general">
  154. <br>
  155. </div>
  156. <h2><?php _e('WP Glossary Options', 'wp-glossary'); ?></h2>
  157. <div id="dashboard-widgets-wrap">
  158. <div id="dashboard-widgets" class="metabox-holder">
  159. <div class="postbox-container" style="width:98%">
  160. <div id="normal-sortables" class="meta-box-sortables ui-sortable">
  161. <form action="<?php echo $ajax; ?>" method="post" class="simpleajaxform" data-target="update-response">
  162. <div id="wpglossary_options_1" class="postbox">
  163. <h3 class="handle"><span>Term Options</span></h3>
  164. <div class="inside">
  165. <p><?php _e('Archive:', 'wp-glossary'); echo "{$archivedropdown}" ?></p>
  166. <p><?php _e('Term link:', 'wp-glossary'); echo "{$termlinkoptdropdown}" ?></p>
  167. <p><?php _e('Reference link:', 'wp-glossary'); echo "{$reflinkoptdropdown}" ?></p>
  168. </div>
  169. </div>
  170. <div id="wpglossary_options_2" class="postbox">
  171. <h3 class="handle"><span>qTip2 Tooltip Options</span></h3>
  172. <div class="inside">
  173. <p>WP Glossary uses the jQuery based <a href="http://qtip2.com/">qTip2</a> library for tooltips</p>
  174. <p><?php _e('Tooltip Content:', 'wp-glossary'); echo "{$tooltipdropdown}" ?></p>
  175. <p><?php _e('Tooltip Style (qTip):', 'wp-glossary'); echo "{$qtipdropdown}" ?></p>
  176. <p><?php _e('Tooltip activation:', 'wp-glossary'); echo "{$qtiptriggerdropdown}" ?></p>
  177. </div>
  178. </div>
  179. <div id="wpglossary_options_3" class="postbox">
  180. <h3 class="handle"><span>Experimental Options</span></h3>
  181. <div class="inside">
  182. <p>Do not rely on these at all, I am experimenting with them</p>
  183. <p><?php _e('Term usage:', 'wp-glossary'); echo "{$termusagedd}" ?></p>
  184. </div>
  185. </div>
  186. <p>
  187. <input type="hidden" name="action" value="wpg_update_options"/>
  188. <input type="submit" name="submit" class="alignleft button-primary" value="<?php _e('Update Glossary Options', 'wp-glossary'); ?>"/>
  189. </p>
  190. </form>
  191. <div id="update-response" class="clear confweb-update"></div>
  192. </div>
  193. </div>
  194. </div>
  195. <?php
  196. }
  197. public function update_options(){
  198. $defaults = array(
  199. 'tooltips' => 'excerpt',
  200. 'alphaarchive' => 'standard',
  201. 'qtipstyle' => 'cream',
  202. 'termlinkopt' => 'standard',
  203. 'reflinkopt' => 'on',
  204. 'termusage' => 'on',
  205. 'qtiptrigger' => 'hover',
  206. );
  207. $glossary_options = get_option( 'wp_glossary', $defaults );
  208. foreach( $defaults as $key => $default ){
  209. $value = $_POST[$key] ? $_POST[$key] : $default;
  210. $glossary_options[$key] = $value;
  211. }
  212. update_option( 'wp_glossary', $glossary_options );
  213. die( '<p>' . __('Glossary options updated', 'wp-glossary') . '</p>' );
  214. }
  215. }