PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/superfish-dropdown-menu/superfish-widget.php

https://gitlab.com/Gashler/sg
PHP | 271 lines | 184 code | 76 blank | 11 comment | 38 complexity | 64ee1193c70d141edea1c2158ef91fec MD5 | raw file
  1. <?php
  2. class shailan_SFWidget extends WP_Widget {
  3. /** constructor */
  4. function shailan_SFWidget() {
  5. $name = 'Superfish Dropdown Menu';
  6. $desc = 'Dropdown page/category menu';
  7. $id_base = 'superfish_widget';
  8. $css_class = 'shailan-sf-dropdown';
  9. $alt_option = 'widget_superfish_navigation';
  10. $widget_ops = array(
  11. 'classname' => $css_class,
  12. 'description' => __( $desc, 'shailan-sf-dropdown' ),
  13. );
  14. $this->WP_Widget($id_base, __($name, 'superfish'), $widget_ops);
  15. $this->alt_option_name = $alt_option;
  16. add_action( 'wp_head', array(&$this, 'styles'), 10, 1 );
  17. add_action( 'wp_footer', array(&$this, 'footer'), 10, 1 );
  18. $this->defaults = array(
  19. 'title' => '',
  20. 'type' => 'Pages',
  21. 'exclude' => '',
  22. 'home' => 'on',
  23. 'login' => 'off',
  24. 'admin' => 'off',
  25. 'shadows' => 'off',
  26. 'skin' => 'demo.css',
  27. 'style' => '',
  28. 'min_width' => '10em',
  29. 'max_width' => '22em'
  30. );
  31. }
  32. /** @see WP_Widget::widget */
  33. function widget($args, $instance) {
  34. extract( $args );
  35. if(! isset($instance['home']) ){ $instance['home'] = 'off'; }
  36. if(! isset($instance['login']) ){ $instance['login'] = 'off'; }
  37. if(! isset($instance['admin']) ){ $instance['admin'] = 'off'; }
  38. if(! isset($instance['shadows']) ){ $instance['shadows'] = 'off'; }
  39. $widget_options = wp_parse_args( $instance, $this->defaults );
  40. extract( $widget_options, EXTR_SKIP );
  41. ?>
  42. <?php echo $before_widget; ?>
  43. <ul class="sf-menu <?php echo $style; ?>" >
  44. <?php if('on' == $home){ ?>
  45. <li class="page_item cat-item blogtab <?php if ( is_front_page() && !is_paged() ){ ?>current_page_item current-cat<?php } ?>"><a href="<?php echo get_option('home'); ?>/"><span><?php _e('Home', 'shailan-sf-dropdown'); ?></span></a></li>
  46. <?php } ?>
  47. <?php if($type == 'Pages'){ ?>
  48. <?php
  49. wp_list_pages(array(
  50. 'sort_column'=>'menu_order',
  51. 'depth'=>'4',
  52. 'title_li'=>'',
  53. 'exclude'=>$exclude
  54. )); ?>
  55. <?php } else { ?>
  56. <?php
  57. wp_list_categories(array(
  58. 'order_by'=>'name',
  59. 'depth'=>'4',
  60. 'title_li'=>'',
  61. 'exclude'=>$exclude
  62. )); ?>
  63. <?php } ?>
  64. <?php if('on' == $admin){ wp_register('<li class="admintab">','</li>'); } if('on' == $login){ ?><li class="page_item"><?php wp_loginout(); ?><?php } ?>
  65. </ul>
  66. <div style="clear:both;"></div>
  67. <?php echo $after_widget; ?>
  68. <?php
  69. }
  70. /** @see WP_Widget::update */
  71. function update($new_instance, $old_instance) {
  72. if(! isset($old_instance['home']) ){ $old_instance['home'] = 'off'; }
  73. if(! isset($old_instance['login']) ){ $old_instance['login'] = 'off'; }
  74. if(! isset($old_instance['admin']) ){ $old_instance['admin'] = 'off'; }
  75. if(! isset($old_instance['shadows']) ){ $old_instance['shadows'] = 'off'; }
  76. return $new_instance;
  77. }
  78. /** @see WP_Widget::form */
  79. function form($instance) {
  80. if(! isset($instance['home']) ){ $instance['home'] = 'off'; }
  81. if(! isset($instance['login']) ){ $instance['login'] = 'off'; }
  82. if(! isset($instance['admin']) ){ $instance['admin'] = 'off'; }
  83. if(! isset($instance['shadows']) ){ $instance['shadows'] = 'off'; }
  84. $widget_options = wp_parse_args( $instance, $this->defaults );
  85. extract( $widget_options, EXTR_SKIP );
  86. ?>
  87. <p><?php _e('Type:'); ?> <label for="Pages"><input type="radio" id="Pages" name="<?php echo $this->get_field_name('type'); ?>" value="Pages" <?php if($type=='Pages'){ echo 'checked="checked"'; } ?> /> <?php _e('Pages', 'shailan-sf-dropdown'); ?></label> <label for="Categories"><input type="radio" id="Categories" name="<?php echo $this->get_field_name('type'); ?>" value="Categories" <?php if($type=='Categories'){ echo 'checked="checked"'; } ?>/> <?php _e('Categories', 'shailan-sf-dropdown'); ?></label></p>
  88. <p>
  89. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('home'); ?>" name="<?php echo $this->get_field_name('home'); ?>"<?php checked( $home, 'on' ); ?> />
  90. <label for="<?php echo $this->get_field_id('home'); ?>"><?php _e( 'Add homepage link' , 'shailan-sf-dropdown' ); ?></label><br />
  91. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('login'); ?>" name="<?php echo $this->get_field_name('login'); ?>"<?php checked( $login, 'on'); ?> />
  92. <label for="<?php echo $this->get_field_id('login'); ?>"><?php _e( 'Add login/logout' , 'shailan-sf-dropdown' ); ?></label><br />
  93. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('admin'); ?>" name="<?php echo $this->get_field_name('admin'); ?>"<?php checked( $admin, 'on' ); ?> />
  94. <label for="<?php echo $this->get_field_id('admin'); ?>"><?php _e( 'Add Register/Site Admin' , 'shailan-sf-dropdown' ); ?></label><br />
  95. </p>
  96. <p><label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e('Exclude:', 'shailan-sf-dropdown'); ?> <input class="widefat" id="<?php echo $this->get_field_id('exclude'); ?>" name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $exclude; ?>" /></label><br />
  97. <small>Page IDs, separated by commas.</small></p>
  98. <p><label for="<?php echo $this->get_field_id('skin'); ?>"><?php _e('Skin:', 'shailan-sf-dropdown'); ?> <?php
  99. // http://www.codewalkers.com/c/a/File-Manipulation-Code/List-files-in-a-directory-no-subdirectories/
  100. echo "<select name='".$this->get_field_name('skin')."' id='".$this->get_field_id('skin')."'>";
  101. echo "<option value='no-theme' ".selected( $skin, 'no-theme', false).">No theme</option>";
  102. //The path to the style directory
  103. $dirpath = plugin_dir_path(__FILE__) . 'skins/';
  104. $dh = opendir($dirpath);
  105. while (false !== ($file = readdir($dh))) {
  106. //Don't list subdirectories
  107. if (!is_dir("$dirpath/$file")) {
  108. //Truncate the file extension and capitalize the first letter
  109. echo "<option value='$file' ".selected($skin, $file, false).">" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</option>';
  110. }
  111. }
  112. closedir($dh);
  113. echo "</select>";
  114. ?> </label><br />
  115. <small><?php _e('Menu theme.', 'shailan-sf-dropdown'); ?></small></p>
  116. <p> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('shadows'); ?>" name="<?php echo $this->get_field_name('shadows'); ?>"<?php checked( $shadows, 'on' ); ?> />
  117. <label for="<?php echo $this->get_field_id('shadows'); ?>"><?php _e( 'Use shadows' , 'shailan-sf-dropdown' ); ?></label><br /></p>
  118. <p><label for="<?php echo $this->get_field_id('style'); ?>"><?php _e('Style:', 'shailan-sf-dropdown'); ?>
  119. <select name="<?php echo $this->get_field_name('style'); ?>" id="<?php echo $this->get_field_id('style'); ?>" >
  120. <option value='' <?php selected( $style, ''); ?> >Dropdown</option>
  121. <option value='sf-vertical' <?php selected( $style, 'sf-vertical'); ?> >Vertical</option>
  122. <option value='sf-navbar' <?php selected( $style, 'sf-navbar'); ?> >Navbar</option>
  123. </select>
  124. </label><br />
  125. <small><?php _e('Menu style.', 'shailan-sf-dropdown'); ?></small></p>
  126. <p><label for="<?php echo $this->get_field_id('min_width'); ?>"><?php _e('Minimum Width:', 'shailan-sf-dropdown'); ?> <input id="<?php echo $this->get_field_id('min_width'); ?>" name="<?php echo $this->get_field_name('min_width'); ?>" type="text" value="<?php echo $min_width; ?>" size="6" />em</label><br />
  127. <small>Minimum width of sub menus.</small></p>
  128. <p><label for="<?php echo $this->get_field_id('max_width'); ?>"><?php _e('Maximum width:', 'shailan-sf-dropdown'); ?> <input id="<?php echo $this->get_field_id('max_width'); ?>" name="<?php echo $this->get_field_name('max_width'); ?>" type="text" value="<?php echo $max_width; ?>" size="6" />em</label><br />
  129. <small>Maximum width of sub menus.</small></p>
  130. <div class="widget-control-actions alignright">
  131. <p><small><a href="http://shailan.com/wordpress/plugins/superfish-dropdown-menu/"><?php esc_attr_e('Visit plugin site', 'shailan-sf-dropdown'); ?></a></small></p>
  132. </div>
  133. <?php
  134. }
  135. /** Adds ID based dropdown menu skin to the header. */
  136. function styles(){
  137. if(!is_admin()){
  138. $all_widgets = $this->get_settings();
  139. foreach ($all_widgets as $key => $sfdropdown){
  140. $widget_id = $this->id_base . '-' . $key;
  141. if(is_active_widget(false, $widget_id, $this->id_base)){
  142. $skin = $sfdropdown['skin'];
  143. if('no-theme'!=$skin){
  144. echo "\n\t<link rel=\"stylesheet\" href=\"".shailan_SFdropdown::get_plugin_directory()."/skin.php?widget_id=".$key."&skin=".strtolower($skin)."\" type=\"text/css\" media=\"screen\" />";
  145. }
  146. }
  147. }
  148. }
  149. }
  150. /** Adds ID based activation script to the footer */
  151. function footer(){
  152. if(!is_admin()){
  153. $all_widgets = $this->get_settings();
  154. foreach ($all_widgets as $key => $sfdropdown){
  155. $widget_id = $this->id_base . '-' . $key;
  156. if(is_active_widget(false, $widget_id, $this->id_base)){
  157. $type = $sfdropdown['type'];
  158. if($type=='Pages'){
  159. $path_class = 'current_page_item';
  160. } elseif($type == 'Categories'){
  161. $path_class = 'current-cat';
  162. };
  163. $min_width = $sfdropdown['min_width'];
  164. if(empty($min_width)){$min_width = 10;};
  165. $max_width = $sfdropdown['max_width'];
  166. if(empty($max_width)){$max_width = 27;};
  167. $shadows = $sfdropdown['shadows'];
  168. if(empty($shadows)){ $shadows = 'false'; } else { $shadows = 'true'; }
  169. ?>
  170. <script type="text/javascript">
  171. // Dom Ready
  172. jQuery(document).ready(function($) {
  173. opts = {
  174. pathClass: '<?php echo $path_class ?>',
  175. pathLevels: 0,
  176. delay: 800,
  177. animation: {opacity:'show'},
  178. speed: 'normal',
  179. autoArrows: true,
  180. dropShadows: <?php echo $shadows ?>,
  181. disableHI: true
  182. };
  183. jQuery('#<?php echo $widget_id; ?> ul.sf-menu').supersubs({
  184. minWidth: '<?php echo $min_width; ?>', // minimum width of sub-menus in em units
  185. maxWidth: '<?php echo $max_width; ?>', // maximum width of sub-menus in em units
  186. extraWidth: 1 // extra width can ensure lines don't sometimes turn over
  187. }).superfish( opts ).find('ul').bgIframe({opacity:false});
  188. });
  189. </script>
  190. <?php
  191. }
  192. }
  193. }
  194. }
  195. } // class shailan_SFWidget