plug_widgets.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. if (!class_exists("plug_widgets")) {
  3. class plug_widgets {
  4. function __construct($ns) {
  5. $this->title = __("Fancy Widgets","dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start() {
  11. if(get_option($this->pluginname."_widgets") == "on"){
  12. add_action( 'widgets_init', function(){ return register_widget("DisplayPageWidget"); } );
  13. add_action( 'widgets_init', function(){ return register_widget("dags_subpageswidget"); } );
  14. add_action( 'widgets_init', function(){ return register_widget("DisplayPageChildrenWidget"); } );
  15. }
  16. }
  17. function help(){
  18. ?>
  19. <?php echo(__("Adds fancy widgets","dagsopt")) ?><br>
  20. Display Page Widget<br>
  21. Subpages Widget<br>
  22. <?php
  23. }
  24. function Option($pre){
  25. //update_option ( $pre.'_data', $_POST [ $pre.'_data' ] );
  26. }
  27. function admin_line($pre){
  28. ?>
  29. <?php
  30. }
  31. }
  32. global $plug_widgets;
  33. $plug_widgets = new plug_widgets($this);
  34. $this->dagsopt['plug_widgets'] = $plug_widgets;
  35. }
  36. class DisplayPageChildrenWidget extends WP_Widget
  37. {
  38. function __construct()
  39. {
  40. $widget_ops = array('classname' => 'DisplayPageChildrenWidget', 'description' => 'Show Page Children Widget' );
  41. parent::__construct('DisplayPageChildrenWidget', 'Page Children Widget', $widget_ops);
  42. }
  43. function form($instance)
  44. {
  45. $instance = wp_parse_args( (array) $instance, array( 'title' => '','page_id'=>'' ) );
  46. $title = $instance['title'];
  47. $pageid = $instance['page_id'];
  48. ?>
  49. <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
  50. <p><label for="<?php echo $this->get_field_id('page_id'); ?>">
  51. Page: <?php wp_dropdown_pages(array('selected' => $pageid,'name'=>$this->get_field_name('page_id') )); ?>
  52. </label></p>
  53. <?php
  54. }
  55. function update($new_instance, $old_instance)
  56. {
  57. $instance = $old_instance;
  58. $instance['title'] = $new_instance['title'];
  59. $instance['page_id'] = $new_instance['page_id'];
  60. return $instance;
  61. }
  62. function widget($args, $instance)
  63. {
  64. extract($args, EXTR_SKIP);
  65. echo $before_widget;
  66. $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
  67. if (!empty($title))
  68. echo $before_title . $title . $after_title;;
  69. $args = array(
  70. 'depth' => 0,
  71. 'show_date' => '',
  72. 'date_format' => get_option('date_format'),
  73. 'child_of' => $instance['page_id'],
  74. 'exclude' => '',
  75. 'include' => '',
  76. 'title_li' => '',
  77. 'echo' => 1,
  78. 'authors' => '',
  79. 'sort_column' => 'menu_order, post_title',
  80. 'link_before' => '',
  81. 'link_after' => '',
  82. 'walker' => '',
  83. 'post_type' => 'page',
  84. 'post_status' => 'publish'
  85. );
  86. wp_list_pages( $args );
  87. /* query_posts('post_type=page&post_parent='.$instance['page_id'].'&orderby=menu_order&order=ASC');
  88. if (have_posts()) :
  89. while (have_posts()) : the_post();
  90. echo "<li><a href='".get_permalink()."'>".get_the_title();
  91. echo "</a></li>";
  92. endwhile;
  93. endif;
  94. wp_reset_query();
  95. */
  96. echo $after_widget;
  97. }
  98. }
  99. class DisplayPageWidget extends WP_Widget
  100. {
  101. function __construct()
  102. {
  103. $widget_ops = array('classname' => 'DisplayPageWidget', 'description' => 'Show Page as Widget' );
  104. parent::__construct('DisplayPageWidget', 'Display Page Widget', $widget_ops);
  105. }
  106. function form($instance)
  107. {
  108. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'page_id'=>'' ) );
  109. $title = $instance['title'];
  110. $pageid = $instance['page_id'];
  111. ?>
  112. <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
  113. <p><label for="<?php echo $this->get_field_id('page_id'); ?>">
  114. Page: <?php wp_dropdown_pages(array('selected' => $pageid,'name'=>$this->get_field_name('page_id') )); ?>
  115. </label></p>
  116. <?php
  117. }
  118. function update($new_instance, $old_instance)
  119. {
  120. $instance = $old_instance;
  121. $instance['title'] = $new_instance['title'];
  122. $instance['page_id'] = $new_instance['page_id'];
  123. return $instance;
  124. }
  125. function widget($args, $instance)
  126. {
  127. extract($args, EXTR_SKIP);
  128. echo $before_widget;
  129. $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
  130. if (!empty($title))
  131. echo $before_title . $title . $after_title;
  132. $page = get_page( $instance['page_id'] );
  133. echo('<div class="pw'.$instance['page_id'].'">');
  134. echo apply_filters('the_content',$page->post_content);
  135. echo('</div>');
  136. echo $after_widget;
  137. }
  138. }
  139. class dags_subpageswidget extends WP_Widget
  140. {
  141. public function __construct() {
  142. parent::__construct(
  143. 'dags_subpageswidget', // Base ID
  144. 'DAGS_subpageswidget', // Name
  145. array( 'description' => __( 'Widget which shows child pages', 'dagsopt' ), ) // Args
  146. );
  147. }
  148. public function widget( $args, $instance ) {
  149. $child_of = 0 ;
  150. if ( is_page() )
  151. $child_of = get_the_ID() ;
  152. $childs = array(
  153. 'title_li' => '',
  154. 'child_of' => $child_of,
  155. 'depth' => 1,
  156. 'echo' => 0,
  157. 'exclude' => $instance['exclude']
  158. ) ;
  159. $brothers = array_merge( $childs, array( 'child_of' => $GLOBALS['post']->post_parent ) ) ;
  160. $wp_list_pages = wp_list_pages($childs);
  161. $page = $child_of;
  162. $parent = $GLOBALS['post']->post_parent;
  163. $grandparent = get_post( $parent)->post_parent;
  164. if($grandparent === 0){
  165. }else{
  166. $wp_list_pages = wp_list_pages($brothers);
  167. }
  168. extract( $args );
  169. $title = apply_filters( 'widget_title', $instance['title'] );
  170. echo $before_widget;
  171. if ( ! empty( $title ) )
  172. echo $before_title . $title . $after_title;
  173. echo $wp_list_pages. $after_widget;
  174. }
  175. public function update( $new_instance, $old_instance ) {
  176. $instance = array();
  177. $instance['title'] = strip_tags( $new_instance['title'] );
  178. $instance['exclude'] = implode( ',', array_unique( array_filter( array_map( 'trim', preg_split( '/(\s)*,(\s)*/', $new_instance['exclude'] ) ), 'is_numeric' ) ) ) ;
  179. return $instance;
  180. }
  181. public function form( $instance ) {
  182. $title = '' ;
  183. if ( isset( $instance[ 'title' ] ) )
  184. $title = $instance[ 'title' ];
  185. $exclude = '' ;
  186. if ( isset( $instance[ 'exclude' ] ) )
  187. $exclude = $instance[ 'exclude' ];
  188. $exclude_id = $this->get_field_id( 'exclude' ) ;
  189. $select_name = $this->get_field_id( 'page_id' ) ;
  190. ?>
  191. <p>
  192. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( '<strong>Title</strong>:', 'dagsopt' ); ?></label>
  193. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  194. </p>
  195. <p>
  196. <label for="<?= $exclude_id ?>"><?php _e( '<strong>Exclude pages</strong>. Comma separated page ID values. Write:', 'dagsopt' ); ?></label>
  197. <input class="widefat" id="<?= $exclude_id ?>" name="<?php echo $this->get_field_name( 'exclude' ); ?>" type="text" value="<?php echo esc_attr( $exclude ); ?>" />
  198. <br><?= __( ' or select: ', 'dagsopt' ) ?>
  199. <?php wp_dropdown_pages( array( 'show_option_none' => __('-- select --', 'dagsopt'), 'name' => $select_name ) ) ; ?>
  200. <br><a href="#<?= $exclude_id ?>" rel="#<?= $select_name ?>" onclick="return false" class="exclude"><?= __( 'Exclude selected', 'dagsopt' ) ?></a>
  201. <?php
  202. }
  203. }