PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.77
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.77
5.5.85 5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 All 161 releases
wp-data-access / WPDataAccess / Dashboard / WPDA_Widget_Publication.php

WPDA_Widget_Publication.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.77, at WPDataAccess/Dashboard/WPDA_Widget_Publication.php

139 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page
4 namespace WPDataAccess\Dashboard;
5
6 use WPDataAccess\Data_Tables\WPDA_Data_Tables;
7 use WPDataAccess\Plugin_Table_Models\WPDA_Publisher_Model;
8 use WPDataAccess\WPDA;
9 class WPDA_Widget_Publication extends WPDA_Widget {
10 protected $pub_id;
11
12 protected $pub_content;
13
14 protected $table_name;
15
16 protected $search_header;
17
18 public function __construct( $args = array() ) {
19 parent::__construct( $args );
20 $this->can_share = true;
21 $this->can_refresh = true;
22 if ( isset( $args['pub_id'] ) ) {
23 $this->pub_id = $args['pub_id'];
24 $embedding = isset( $args['embedding'] ) && true === $args['embedding'];
25 $wpda_data_tables = new WPDA_Data_Tables();
26 $this->pub_content = $wpda_data_tables->show(
27 $this->pub_id,
28 '',
29 '',
30 '',
31 '',
32 '',
33 '',
34 '',
35 '',
36 '',
37 '',
38 '',
39 '',
40 true,
41 $embedding
42 );
43 $wpda_publication = WPDA_Publisher_Model::get_publication( $this->pub_id );
44 $this->table_name = $wpda_publication['0']['pub_table_name'];
45 try {
46 $json = json_decode( $wpda_publication['0']['pub_table_options_advanced'] );
47 if ( isset( $json->wpda_searchbox ) && ('header' === $json->wpda_searchbox || 'both' === $json->wpda_searchbox) ) {
48 $this->search_header = true;
49 }
50 } catch ( \Exception $e ) {
51 $this->search_header = false;
52 }
53 }
54 }
55
56 public function do_shortcode( $widget ) {
57 // Not implemented (use Data Tables short code)
58 }
59
60 public function do_embed( $widget, $target_element ) {
61 }
62
63 protected function js( $is_backend = true ) {
64 ?>
65 <script type="application/javascript">
66 jQuery(function() {
67 jQuery("#wpda-widget-<?php
68 echo esc_attr( $this->widget_id );
69 ?>").find(".wpda-widget-refresh").on("click", function(e, action = null) {
70 if (action==="refresh") {
71 jQuery("#<?php
72 echo esc_attr( $this->table_name ) . esc_attr( $this->pub_id );
73 ?>").DataTable().ajax.json();
74 } else {
75 jQuery("#<?php
76 echo esc_attr( $this->table_name ) . esc_attr( $this->pub_id );
77 ?>").DataTable().draw("page");
78 }
79 jQuery("#<?php
80 echo esc_attr( $this->table_name ) . esc_attr( $this->pub_id );
81 ?>").DataTable().responsive.recalc();
82 <?php
83 if ( $this->search_header && $is_backend ) {
84 ?>
85 post_publication_widget("<?php
86 echo esc_attr( $this->table_name );
87 ?>", "<?php
88 echo esc_attr( $this->pub_id );
89 ?>");
90 <?php
91 }
92 ?>
93 });
94 });
95 </script>
96 <?php
97 }
98
99 protected function container() {
100 ob_start();
101 // phpcs:disable WordPress.Security.EscapeOutput
102 echo parent::container();
103 $post_publication = ( $this->search_header ? "post_publication_widget('{$this->table_name}', '{$this->pub_id}');" : '' );
104 $post_content = "\n\t\t\t\t<div id='wpda-panel-pub-id-{$this->pub_id}' style='display: block'>\n\t\t\t\t\t{$this->pub_content}\n\t\t\t\t</div>\n\t\t\t\t<script type='application/javascript'>\n\t\t\t\tjQuery(function() {\n\t\t\t\t\tsetTimeout(waitUntilWidgetIsLoaded_{$this->pub_id}, 1000);\n\t\t\t\t\tfunction waitUntilWidgetIsLoaded_{$this->pub_id}() {\n\t\t\t\t\t\tif (jQuery('#wpda-widget-{$this->widget_id} div.ui-widget-content').length>0) {\n\t\t\t\t\t\t\tjQuery('#wpda-widget-{$this->widget_id} div.ui-widget-content').html('');\n\t\t\t\t\t\t\tjQuery('#wpda-panel-pub-id-{$this->pub_id}').appendTo(jQuery('#wpda-widget-{$this->widget_id} div.ui-widget-content'));\n\t\t\t\t\t\t\tjQuery('#{$this->table_name}{$this->pub_id}').DataTable().responsive.recalc();\n\t\t\t\t\t\t\tjQuery('#{$this->table_name}{$this->pub_id}').DataTable().columns.adjust();\n\t\t\t\t\t\t\t{$post_publication}\n\t\t\t\t\t\t\t// console.log('WP Data Access data table libraries loaded...');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tsetTimeout(waitUntilWidgetIsLoaded_{$this->pub_id}, 1000);\n\t\t\t\t\t\t\tconsole.log('Waiting for WP Data Access data table libraries to be loaded...');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\t</script>\n\t\t\t";
105 echo $post_content;
106 // phpcs:enable WordPress.Security.EscapeOutput
107 return ob_get_clean();
108 }
109
110 public static function widget() {
111 $panel_name = ( isset( $_REQUEST['wpda_panel_name'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_panel_name'] ) ) : '' );
112 $panel_pub_id = ( isset( $_REQUEST['wpda_panel_pub_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_panel_pub_id'] ) ) : '' );
113 $panel_column = ( isset( $_REQUEST['wpda_panel_column'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_panel_column'] ) ) : '1' );
114 $column_position = ( isset( $_REQUEST['wpda_column_position'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_column_position'] ) ) : 'prepend' );
115 $widget_sequence_nr = ( isset( $_REQUEST['wpda_widget_sequence_nr'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_widget_sequence_nr'] ) ) : '1' );
116 $wdg = new WPDA_Widget_Publication(array(
117 'name' => $panel_name,
118 'pub_id' => $panel_pub_id,
119 'column' => $panel_column,
120 'position' => $column_position,
121 'widget_id' => $widget_sequence_nr,
122 ));
123 WPDA::sent_header( 'text/html; charset=UTF-8' );
124 // phpcs:disable WordPress.Security.EscapeOutput
125 echo $wdg->container();
126 // phpcs:enable WordPress.Security.EscapeOutput
127 wp_die();
128 }
129
130 public static function refresh() {
131 // phpcs:disable WordPress.Security.EscapeOutput
132 echo static::msg( 'ERROR', 'Method not available for this panel type' );
133 // phpcs:enable WordPress.Security.EscapeOutput
134 wp_die();
135 }
136
137 }
138
139 // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing