123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <?php
- if (!class_exists("plug_widgets")) {
- class plug_widgets {
- function __construct($ns) {
- $this->title = __("Fancy Widgets","dagsopt");
- $this->pluginname = $ns->pluginname;
- $this->file = $ns->file;
- $this->ns = $ns;
- }
- function start() {
- if(get_option($this->pluginname."_widgets") == "on"){
- add_action( 'widgets_init', function(){ return register_widget("DisplayPageWidget"); } );
- add_action( 'widgets_init', function(){ return register_widget("dags_subpageswidget"); } );
- add_action( 'widgets_init', function(){ return register_widget("DisplayPageChildrenWidget"); } );
- }
- }
-
- function help(){
- ?>
- <?php echo(__("Adds fancy widgets","dagsopt")) ?><br>
- Display Page Widget<br>
- Subpages Widget<br>
-
- <?php
- }
- function Option($pre){
- //update_option ( $pre.'_data', $_POST [ $pre.'_data' ] );
- }
- function admin_line($pre){
- ?>
- <?php
- }
- }
- global $plug_widgets;
- $plug_widgets = new plug_widgets($this);
- $this->dagsopt['plug_widgets'] = $plug_widgets;
-
- }
- class DisplayPageChildrenWidget extends WP_Widget
- {
- function __construct()
- {
- $widget_ops = array('classname' => 'DisplayPageChildrenWidget', 'description' => 'Show Page Children Widget' );
- parent::__construct('DisplayPageChildrenWidget', 'Page Children Widget', $widget_ops);
- }
-
- function form($instance)
- {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '','page_id'=>'' ) );
- $title = $instance['title'];
- $pageid = $instance['page_id'];
- ?>
- <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>
- <p><label for="<?php echo $this->get_field_id('page_id'); ?>">
- Page: <?php wp_dropdown_pages(array('selected' => $pageid,'name'=>$this->get_field_name('page_id') )); ?>
- </label></p>
-
-
- <?php
- }
-
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- $instance['title'] = $new_instance['title'];
- $instance['page_id'] = $new_instance['page_id'];
- return $instance;
- }
-
- function widget($args, $instance)
- {
- extract($args, EXTR_SKIP);
-
- echo $before_widget;
- $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
-
- if (!empty($title))
- echo $before_title . $title . $after_title;;
- $args = array(
- 'depth' => 0,
- 'show_date' => '',
- 'date_format' => get_option('date_format'),
- 'child_of' => $instance['page_id'],
- 'exclude' => '',
- 'include' => '',
- 'title_li' => '',
- 'echo' => 1,
- 'authors' => '',
- 'sort_column' => 'menu_order, post_title',
- 'link_before' => '',
- 'link_after' => '',
- 'walker' => '',
- 'post_type' => 'page',
- 'post_status' => 'publish'
- );
- wp_list_pages( $args );
-
- /* query_posts('post_type=page&post_parent='.$instance['page_id'].'&orderby=menu_order&order=ASC');
- if (have_posts()) :
- while (have_posts()) : the_post();
- echo "<li><a href='".get_permalink()."'>".get_the_title();
- echo "</a></li>";
- endwhile;
- endif;
- wp_reset_query();
- */
-
- echo $after_widget;
- }
-
- }
- class DisplayPageWidget extends WP_Widget
- {
- function __construct()
- {
- $widget_ops = array('classname' => 'DisplayPageWidget', 'description' => 'Show Page as Widget' );
- parent::__construct('DisplayPageWidget', 'Display Page Widget', $widget_ops);
- }
-
- function form($instance)
- {
- $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'page_id'=>'' ) );
- $title = $instance['title'];
- $pageid = $instance['page_id'];
-
- ?>
- <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>
- <p><label for="<?php echo $this->get_field_id('page_id'); ?>">
- Page: <?php wp_dropdown_pages(array('selected' => $pageid,'name'=>$this->get_field_name('page_id') )); ?>
- </label></p>
- <?php
- }
-
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- $instance['title'] = $new_instance['title'];
- $instance['page_id'] = $new_instance['page_id'];
- return $instance;
- }
-
- function widget($args, $instance)
- {
- extract($args, EXTR_SKIP);
-
- echo $before_widget;
- $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
-
- if (!empty($title))
- echo $before_title . $title . $after_title;
- $page = get_page( $instance['page_id'] );
- echo('<div class="pw'.$instance['page_id'].'">');
- echo apply_filters('the_content',$page->post_content);
- echo('</div>');
- echo $after_widget;
- }
-
- }
-
- class dags_subpageswidget extends WP_Widget
- {
- public function __construct() {
- parent::__construct(
- 'dags_subpageswidget', // Base ID
- 'DAGS_subpageswidget', // Name
- array( 'description' => __( 'Widget which shows child pages', 'dagsopt' ), ) // Args
- );
- }
- public function widget( $args, $instance ) {
- $child_of = 0 ;
- if ( is_page() )
- $child_of = get_the_ID() ;
-
- $childs = array(
- 'title_li' => '',
- 'child_of' => $child_of,
- 'depth' => 1,
- 'echo' => 0,
- 'exclude' => $instance['exclude']
- ) ;
-
-
- $brothers = array_merge( $childs, array( 'child_of' => $GLOBALS['post']->post_parent ) ) ;
-
- $wp_list_pages = wp_list_pages($childs);
- $page = $child_of;
- $parent = $GLOBALS['post']->post_parent;
- $grandparent = get_post( $parent)->post_parent;
-
- if($grandparent === 0){
- }else{
- $wp_list_pages = wp_list_pages($brothers);
- }
-
- extract( $args );
- $title = apply_filters( 'widget_title', $instance['title'] );
- echo $before_widget;
-
-
- if ( ! empty( $title ) )
- echo $before_title . $title . $after_title;
-
- echo $wp_list_pages. $after_widget;
-
- }
-
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = strip_tags( $new_instance['title'] );
- $instance['exclude'] = implode( ',', array_unique( array_filter( array_map( 'trim', preg_split( '/(\s)*,(\s)*/', $new_instance['exclude'] ) ), 'is_numeric' ) ) ) ;
- return $instance;
- }
-
- public function form( $instance ) {
-
- $title = '' ;
- if ( isset( $instance[ 'title' ] ) )
- $title = $instance[ 'title' ];
-
- $exclude = '' ;
- if ( isset( $instance[ 'exclude' ] ) )
- $exclude = $instance[ 'exclude' ];
-
- $exclude_id = $this->get_field_id( 'exclude' ) ;
- $select_name = $this->get_field_id( 'page_id' ) ;
-
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( '<strong>Title</strong>:', 'dagsopt' ); ?></label>
- <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 ); ?>" />
- </p>
- <p>
- <label for="<?= $exclude_id ?>"><?php _e( '<strong>Exclude pages</strong>. Comma separated page ID values. Write:', 'dagsopt' ); ?></label>
- <input class="widefat" id="<?= $exclude_id ?>" name="<?php echo $this->get_field_name( 'exclude' ); ?>" type="text" value="<?php echo esc_attr( $exclude ); ?>" />
- <br><?= __( ' or select: ', 'dagsopt' ) ?>
- <?php wp_dropdown_pages( array( 'show_option_none' => __('-- select --', 'dagsopt'), 'name' => $select_name ) ) ; ?>
- <br><a href="#<?= $exclude_id ?>" rel="#<?= $select_name ?>" onclick="return false" class="exclude"><?= __( 'Exclude selected', 'dagsopt' ) ?></a>
-
- <?php
- }
-
-
- }
-
-
-
-
-
-
-
-
-
-
|