PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / trunk
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin vtrunk
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / includes / class-pdfprnt-buttons-widget.php

class-pdfprnt-buttons-widget.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin trunk, at includes/class-pdfprnt-buttons-widget.php

152 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Pdfprnt_Buttons_Widget Class
4 */
5
6 /**
7 * Buttons Widget
8 */
9 class Pdfprnt_Buttons_Widget extends WP_Widget {
10 /**
11 * Constract
12 */
13 public function __construct() {
14 parent::__construct( 'pdfprnt_buttons', esc_html__( 'PDF & Print Buttons', 'pdf-print' ), array( 'description' => esc_html__( 'Show PDF & Print Buttons on your site', 'pdf-print' ) ) );
15 }
16
17 /**
18 * Functiona for widget
19 *
20 * @param array $args Arguments for widget.
21 * @param array $instance Widget instance.
22 */
23 public function widget( $args, $instance ) {
24 global $pdfprnt_options, $pdfprnt_is_search_archive, $pdfprnt_is_custom_post_type;
25 $url = isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ? ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
26 $url = esc_url( $url );
27 $buttons = '';
28 $target = '_blank';
29
30 if ( ! pdfprnt_is_user_role_enabled() ) {
31 return;
32 }
33
34 foreach ( array( 'pdf', 'print' ) as $button ) {
35 $instance[ $button . '_button_show' ] = ! empty( $instance[ $button . '_button_show' ] ) ? 1 : 0;
36 $instance[ $button . '_button_title' ] = wp_strip_all_tags( $pdfprnt_options['button_title'][ $button ] );
37 if (
38 isset( $pdfprnt_options['button_image'][ $button ]['type'] ) &&
39 in_array( $pdfprnt_options['button_image'][ $button ]['type'], array( 'none', 'default' ), true )
40 ) {
41 $instance[ $button . '_button_image' ] = $pdfprnt_options['button_image'][ $button ]['type'];
42 } else {
43 $instance[ $button . '_button_image' ] = 'default';
44 }
45 }
46
47 if ( ! empty( $pdfprnt_is_search_archive ) ) {
48 $custom_query = '-search';
49 } elseif ( ! empty( $pdfprnt_is_custom_post_type ) ) {
50 $custom_query = '-custom';
51 } else {
52 $custom_query = '';
53 }
54
55 if ( 1 === intval( $instance['pdf_button_show'] ) ) {
56 $pdf_url = add_query_arg( 'print', 'pdf' . $custom_query, $url );
57 $button_title = ! empty( $instance['pdf_button_title'] ) ? '<span class="pdfprnt-button-title pdfprnt-button-pdf-title">' . $instance['pdf_button_title'] . '</span>' : '';
58 $button_image = 'none' !== $instance['pdf_button_image'] ? '<img src="' . plugins_url( 'images/pdf.png', dirname( __FILE__ ) ) . '" alt="image_pdf" title="' . esc_html__( 'View PDF', 'pdf-print' ) . '" />' : '';
59
60 if ( $pdfprnt_options['image_to_pdf'] ) {
61 $pdf_url = 'javascript: imageToPdf()';
62 $target = '_self';
63 }
64 $buttons_pdf = sprintf(
65 '<a href="%s" class="pdfprnt-button pdfprnt-button-pdf" target="%s">%s%s</a>',
66 $pdf_url,
67 $target,
68 $button_title,
69 $button_image
70 );
71 $buttons_pdf = apply_filters( 'pdfprnt_add_atribute_rel_widget_pdf', $buttons_pdf, $pdf_url, $target, $button_image, $button_title );
72 add_action( 'wp_footer', 'pdfprnt_add_script' );
73 }
74 if ( 1 === intval( $instance['print_button_show'] ) ) {
75 $print_url = add_query_arg( 'print', 'print' . $custom_query, $url );
76 $button_title = ! empty( $instance['print_button_title'] ) ? '<span class="pdfprnt-button-title pdfprnt-button-pdf-title">' . $instance['print_button_title'] . '</span>' : '';
77 $button_image = 'none' !== $instance['print_button_image'] ? '<img src="' . plugins_url( 'images/print.png', dirname( __FILE__ ) ) . '" alt="image_print" title="' . esc_html__( 'Print Content', 'pdf-print-plus' ) . '" />' : '';
78 $buttons_print = sprintf(
79 '<a href="%s" class="pdfprnt-button pdfprnt-button-print" target="_blank">%s%s</a>',
80 $print_url,
81 $button_image,
82 $button_title
83 );
84 $buttons_print = apply_filters( 'pdfprnt_add_atribute_rel_widget_print', $buttons_print, $print_url, $button_image, $button_title );
85 }
86 $buttons = $buttons_pdf . $buttons_print;
87 if ( ! empty( $buttons ) ) {
88 $title = ( ! empty( $instance['title'] ) ) ? apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) : '';
89 $buttons = sprintf(
90 '<div class="pdfprnt-buttons pdfprnt-widget">%s</div>',
91 $buttons
92 );
93 echo wp_kses_post( $args['before_widget'] );
94 if ( ! empty( $title ) ) {
95 echo wp_kses_post( $args['before_title'] . $title . $args['after_title'] );
96 }
97 echo wp_kses_post( $buttons );
98 echo wp_kses_post( $args['after_widget'] );
99 }
100 }
101
102 /**
103 * Functiona for update widget form
104 *
105 * @param array $new_instance New info for widget.
106 * @param array $old_instance Old info for widget.
107 */
108 public function update( $new_instance, $old_instance ) {
109 $instance = $old_instance;
110 $instance['title'] = wp_strip_all_tags( $new_instance['title'] );
111 $instance['pdf_button_show'] = ! empty( $new_instance['pdf_button_show'] ) ? 1 : 0;
112 $instance['print_button_show'] = ! empty( $new_instance['print_button_show'] ) ? 1 : 0;
113 return $instance;
114 }
115
116 /**
117 * Functiona for widget form
118 *
119 * @param array $instance Info for widget.
120 */
121 public function form( $instance ) {
122 global $pdfprnt_options;
123 if ( empty( $pdfprnt_options ) ) {
124 $pdfprnt_options = get_option( 'pdfprnt_options' );
125 }
126
127 if ( ! empty( $instance ) ) {
128 $title = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
129 $pdf_button_show = ! empty( $instance['pdf_button_show'] ) ? 1 : 0;
130 $print_button_show = ! empty( $instance['print_button_show'] ) ? 1 : 0;
131 } else {
132 $title = '';
133 $pdf_button_show = 1;
134 $print_button_show = 1;
135 }
136 ?>
137 <p>
138 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title', 'pdf-print' ); ?>:</label>
139 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_html( $title ); ?>" />
140 </p>
141 <p>
142 <input class="widefat pdfprnt-show-button-cb" id="<?php echo esc_attr( $this->get_field_id( 'pdf_button_show' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'pdf_button_show' ) ); ?>" type="checkbox" value="1" <?php checked( 1, $pdf_button_show ); ?> />
143 <label for="<?php echo esc_attr( $this->get_field_id( 'pdf_button_show' ) ); ?>"><?php esc_html_e( 'Display PDF Button', 'pdf-print' ); ?></label>
144 </p>
145 <p>
146 <input class="widefat pdfprnt-show-button-cb" id="<?php echo esc_attr( $this->get_field_id( 'print_button_show' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'print_button_show' ) ); ?>" type="checkbox" value="1" <?php checked( 1, $print_button_show ); ?> />
147 <label for="<?php echo esc_attr( $this->get_field_id( 'print_button_show' ) ); ?>"><?php esc_html_e( 'Display Print Button', 'pdf-print' ); ?></label>
148 </p>
149 <?php
150 }
151 }
152