widget_archive.php
99 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @author lord_viper |
| 5 | * @copyright 2013 |
| 6 | */ |
| 7 | class parsidate_archive extends WP_Widget { |
| 8 | public function __construct() { |
| 9 | global $wp_version; |
| 10 | |
| 11 | // backwards compability |
| 12 | if ( version_compare( $wp_version, '4.3', '>=' ) ) { |
| 13 | parent::__construct( false, __( 'Jalali Date Archives', 'wp-parsidate' ), 'description=' . __( 'Jalali Date Archives', 'wp-parsidate' ) ); |
| 14 | } else { |
| 15 | parent::WP_Widget( false, __( 'Jalali Date Archives', 'wp-parsidate' ), 'description=' . __( 'Jalali Date Archives', 'wp-parsidate' ) ); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public function form( $instance ) { |
| 20 | global $wpp_settings; |
| 21 | $type = isset( $instance['parsidate_archive_type'] ) ? $instance['parsidate_archive_type'] : 'monthly'; |
| 22 | $instance['parsidate_archive_title'] = isset( $instance['parsidate_archive_title'] ) ? strip_tags( $instance['parsidate_archive_title'] ) : __( 'Jalali Date Archives', 'wp-parsidate' ); |
| 23 | $instance['parsidate_archive_count'] = isset( $instance['parsidate_archive_count'] ) ? $instance['parsidate_archive_count'] : 0; |
| 24 | $instance['parsidate_archive_list'] = isset( $instance['parsidate_archive_list'] ) ? $instance['parsidate_archive_list'] : 0; |
| 25 | |
| 26 | ?> |
| 27 | <p style="text-align:right; direction:rtl"> |
| 28 | <label></label> |
| 29 | <input style="width: 200px;" id="<?php echo $this->get_field_id( 'parsidate_archive_title' ); ?>" |
| 30 | name="<?php echo $this->get_field_name( 'parsidate_archive_title' ); ?>" type="text" |
| 31 | value="<?php echo( empty( $instance['parsidate_archive_title'] ) ? __( 'Jalali Date Archives', 'wp-parsidate' ) : $instance['parsidate_archive_title'] ) ?>"/> |
| 32 | <br/> |
| 33 | <label><input type="radio" id="parsidate_archive_type1" |
| 34 | name="<?php echo $this->get_field_name( 'parsidate_archive_type' ); ?>" |
| 35 | value="yearly" <?php checked( $type, 'yearly' ); ?>/><label |
| 36 | for="parsidate_archive_type1"><?php _e( 'Yearly', 'wp-parsidate' ) ?></label><br/> |
| 37 | <label><input type="radio" id="parsidate_archive_type2" |
| 38 | name="<?php echo $this->get_field_name( 'parsidate_archive_type' ); ?>" |
| 39 | value="monthly" <?php checked( $type, 'monthly' ); ?>/><?php _e( 'Monthly', 'wp-parsidate' ) ?> |
| 40 | </label><br/> |
| 41 | <label><input type="radio" id="parsidate_archive_type3" |
| 42 | name="<?php echo $this->get_field_name( 'parsidate_archive_type' ); ?>" |
| 43 | value="daily" <?php checked( $type, 'daily' ); ?>/><?php _e( 'Daily', 'wp-parsidate' ) ?> |
| 44 | </label><br/> |
| 45 | <br/> |
| 46 | <input type="checkbox" name="<?php echo $this->get_field_name( 'parsidate_archive_count' ); ?>" |
| 47 | id="<?php echo $this->get_field_id( 'parsidate_archive_count' ); ?>" |
| 48 | value="1" <?php checked( $instance['parsidate_archive_count'], 1, true ); ?>/> |
| 49 | <label for="<?php echo $this->get_field_id( 'parsidate_archive_count' ); ?>"><?php _e( 'Show post counts', 'wp-parsidate' ) ?></label> |
| 50 | <br/> |
| 51 | <input type="checkbox" name="<?php echo $this->get_field_name( 'parsidate_archive_list' ); ?>" |
| 52 | id="<?php echo $this->get_field_id( 'parsidate_archive_list' ); ?>" |
| 53 | value="1" <?php echo checked( $instance['parsidate_archive_list'], 1, true ); ?>/> |
| 54 | <label for="<?php echo $this->get_field_id( 'parsidate_archive_list' ); ?>"><?php _e( 'Display as dropdown', 'wp-parsidate' ) ?></label> |
| 55 | </p> |
| 56 | <?php |
| 57 | if ( $wpp_settings['conv_permalinks'] == 'disable' ) { |
| 58 | echo "<p style='color: #ff8153'>" . __( 'For use widget, active "Fix permalinks dates" option in plugin settings.', 'wp-parsidate' ) . "</p>"; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public function update( $new_instance, $old_instance ) { |
| 63 | $instance = $old_instance; |
| 64 | $instance['parsidate_archive_title'] = isset( $new_instance['parsidate_archive_title'] ) ? strip_tags( $new_instance['parsidate_archive_title'] ) : __( 'Jalali Date Archives', 'wp-parsidate' ); |
| 65 | $instance['parsidate_archive_count'] = isset( $new_instance['parsidate_archive_count'] ) ? $new_instance['parsidate_archive_count'] : 0; |
| 66 | $instance['parsidate_archive_list'] = isset( $new_instance['parsidate_archive_list'] ) ? $new_instance['parsidate_archive_list'] : 0; |
| 67 | $instance['parsidate_archive_type'] = isset( $new_instance['parsidate_archive_type'] ) ? $new_instance['parsidate_archive_type'] : 'monthly'; |
| 68 | |
| 69 | return $instance; |
| 70 | } |
| 71 | |
| 72 | public function widget( $args, $instance ) { |
| 73 | global $wpp_settings; |
| 74 | if ( $wpp_settings['conv_permalinks'] == 'disable' ) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | $type = isset( $instance['parsidate_archive_type'] ) ? $instance['parsidate_archive_type'] : 'monthly'; |
| 79 | $title = isset( $instance['parsidate_archive_title'] ) ? $instance['parsidate_archive_title'] : __( 'Jalali Date Archives', 'wp-parsidate' ); |
| 80 | $post_count = isset( $instance['parsidate_archive_count'] ) ? $instance['parsidate_archive_count'] : false; |
| 81 | $ddl_style = isset( $instance['parsidate_archive_list'] ) ? $instance['parsidate_archive_list'] : false; |
| 82 | |
| 83 | echo $args['before_widget']; |
| 84 | if ( ! empty( $instance['parsidate_archive_title'] ) ) { |
| 85 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['parsidate_archive_title'] ) . $args['after_title']; |
| 86 | } |
| 87 | |
| 88 | if ( $ddl_style ) { |
| 89 | echo "<select name='parsidate_archive_list' onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value='0'>" . esc_attr( $title ) . "</option>"; |
| 90 | wp_get_parchives( "type=$type&format=option&show_post_count=$post_count" ); |
| 91 | echo '</select>'; |
| 92 | } else { |
| 93 | echo '<ul>'; |
| 94 | wpp_get_archives( "type=$type&show_post_count=$post_count" ); |
| 95 | echo '</ul>'; |
| 96 | } |
| 97 | echo $args['after_widget']; |
| 98 | } |
| 99 | } |