| @@ -28,15 +28,8 @@ | ||
| 28 | 28 | */ |
| 29 | 29 | class Visualizer_Render_Library extends Visualizer_Render { |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * Cached result of _isListView() to avoid repeat DB reads per request. | |
| 33 | - * | |
| 34 | - * @var bool|null | |
| 35 | - */ | |
| 36 | - private $_list_view_cached = null; | |
| 37 | - | |
| 38 | - /** | |
| 39 | 32 | * Renders library page. |
| 40 | 33 | * |
| 41 | 34 | * @since 1.0.0 |
| 42 | 35 | * |
| @@ -46,23 +39,12 @@ | ||
| 46 | 39 | echo '<div class="wrap">'; |
| 47 | 40 | echo '<div id="visualizer-icon" class="icon32"><br></div>'; |
| 48 | 41 | echo '<h2>'; |
| 49 | 42 | esc_html_e( 'Visualizer Library', 'visualizer' ); |
| 50 | - echo ' <div class="viz-add-new-group">'; | |
| 51 | - echo '<a href="javascript:;" class="add-new-h2 add-new-chart">', esc_html__( 'Add New Chart', 'visualizer' ), '</a>'; | |
| 52 | - echo '<button type="button" class="viz-add-new-toggle" aria-haspopup="true" aria-expanded="false"><span class="dashicons dashicons-arrow-down-alt2"></span></button>'; | |
| 53 | - echo '<div class="viz-add-new-menu" role="menu" aria-hidden="true">'; | |
| 54 | - echo '<button type="button" class="viz-add-new-item" data-viz-builder="ai">', esc_html__( 'AI Chart Builder', 'visualizer' ), '</button>'; | |
| 55 | - echo '<button type="button" class="viz-add-new-item" data-viz-builder="classic">', esc_html__( 'Classic Builder', 'visualizer' ), '</button>'; | |
| 56 | - echo '</div>'; | |
| 57 | - if ( Visualizer_Module::is_pro() ) { | |
| 58 | - echo ' <a href="' . admin_url( 'options-general.php#visualizer_pro_license' ) . '" class="page-title-action">', esc_html__( 'License Settings', 'visualizer' ), '</a>'; | |
| 59 | - } | |
| 60 | - echo '</div>'; | |
| 43 | + echo ' <a href="javascript:;" class="add-new-h2">', esc_html__( 'Add New', 'visualizer' ), '</a>'; | |
| 61 | 44 | echo '</h2>'; |
| 62 | 45 | $this->_renderMessages(); |
| 63 | 46 | $this->_renderLibrary(); |
| 64 | - echo '<div id="viz-chart-builder-root"></div>'; | |
| 65 | 47 | echo '</div>'; |
| 66 | 48 | } |
| 67 | 49 | |
| 68 | 50 | /** |
| @@ -75,13 +57,9 @@ | ||
| 75 | 57 | private function _renderMessages() { |
| 76 | 58 | if ( ! filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN ) ) { |
| 77 | 59 | echo '<div class="updated error">'; |
| 78 | 60 | echo '<p>'; |
| 79 | - printf( | |
| 80 | - // translators: %s - the name of the option. | |
| 81 | - esc_html__( '%s option is disabled in your php.ini config. Please enable it by changing its value to 1. This option increases the speed of remote CSV uploading.', 'visualizer' ), | |
| 82 | - '<b>allow_url_fopen</b>' | |
| 83 | - ); | |
| 61 | + printf( esc_html__( '%s option is disabled in your php.ini config. Please, enable it by change its value to 1. This option increases the speed of remote CSV uploading.', 'visualizer' ), '<b>allow_url_fopen</b>' ); | |
| 84 | 62 | echo '</p>'; |
| 85 | 63 | echo '</div>'; |
| 86 | 64 | } |
| 87 | 65 | } |
| @@ -86,197 +64,8 @@ | ||
| 86 | 64 | } |
| 87 | 65 | } |
| 88 | 66 | |
| 89 | 67 | /** |
| 90 | - * Displays the search form. | |
| 91 | - */ | |
| 92 | - private function getDisplayForm() { | |
| 93 | - echo '<div class="visualizer-library-form"> | |
| 94 | - <form action="' . admin_url( 'admin.php' ) . '"> | |
| 95 | - <input type="hidden" name="page" value="' . Visualizer_Plugin::NAME . '"/> | |
| 96 | - <input type="hidden" name="view" value="' . esc_attr( $this->_isListView() ? 'list' : 'grid' ) . '"/> | |
| 97 | - <span class="viz-view-toggle-group">' . $this->_getViewToggleHTML() . '</span> | |
| 98 | - <select class="viz-filter" name="type"> | |
| 99 | - '; | |
| 100 | - | |
| 101 | - echo '<option value="" selected>' . __( 'All types', 'visualizer' ) . '</option>'; | |
| 102 | - | |
| 103 | - $type = isset( $_GET['type'] ) ? $_GET['type'] : ''; | |
| 104 | - $enabled = array(); | |
| 105 | - $disabled = array(); | |
| 106 | - foreach ( $this->types as $id => $array ) { | |
| 107 | - if ( ! is_array( $array ) ) { | |
| 108 | - // support for old pro | |
| 109 | - $array = array( 'enabled' => true, 'name' => $array ); | |
| 110 | - } | |
| 111 | - if ( ! $array['enabled'] ) { | |
| 112 | - $disabled[ $id ] = $array['name']; | |
| 113 | - continue; | |
| 114 | - } | |
| 115 | - $enabled[ $id ] = $array['name']; | |
| 116 | - } | |
| 117 | - | |
| 118 | - asort( $enabled ); | |
| 119 | - asort( $disabled ); | |
| 120 | - | |
| 121 | - foreach ( $enabled as $id => $name ) { | |
| 122 | - echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . '>' . $name . '</option>'; | |
| 123 | - } | |
| 124 | - | |
| 125 | - if ( $disabled ) { | |
| 126 | - echo '<optgroup label="' . __( 'Not available', 'visualizer' ) . '">'; | |
| 127 | - foreach ( $disabled as $id => $name ) { | |
| 128 | - echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . ' disabled>' . $name . '</option>'; | |
| 129 | - } | |
| 130 | - echo '</optgroup>'; | |
| 131 | - } | |
| 132 | - | |
| 133 | - echo ' | |
| 134 | - </select> | |
| 135 | - <select class="viz-filter" name="library"> | |
| 136 | - '; | |
| 137 | - | |
| 138 | - $libraries = array( '', 'ChartJS', 'DataTable', 'GoogleCharts' ); | |
| 139 | - $library = isset( $_GET['library'] ) ? $_GET['library'] : ''; | |
| 140 | - foreach ( $libraries as $lib ) { | |
| 141 | - echo '<option value="' . esc_attr( $lib ) . '" ' . selected( $library, $lib ) . '>' . ( $lib === '' ? __( 'All libraries', 'visualizer' ) : $lib ) . '</option>'; | |
| 142 | - } | |
| 143 | - | |
| 144 | - echo ' | |
| 145 | - </select> | |
| 146 | - <select class="viz-filter" name="date"> | |
| 147 | - '; | |
| 148 | - | |
| 149 | - $dates = Visualizer_Plugin::getSupportedDateFilter(); | |
| 150 | - $date = isset( $_GET['date'] ) ? $_GET['date'] : ''; | |
| 151 | - foreach ( Visualizer_Plugin::getSupportedDateFilter() as $dt => $label ) { | |
| 152 | - echo '<option value="' . esc_attr( $dt ) . '" ' . selected( $date, $dt ) . '>' . $label . '</option>'; | |
| 153 | - } | |
| 154 | - | |
| 155 | - echo ' | |
| 156 | - </select> | |
| 157 | - <select class="viz-filter" name="source"> | |
| 158 | - '; | |
| 159 | - | |
| 160 | - $disabled = array(); | |
| 161 | - $sources = array( 'json' => __( 'JSON', 'visualizer' ), 'csv' => __( 'Local CSV', 'visualizer' ), 'csv_remote' => __( 'Remote CSV', 'visualizer' ), 'query' => __( 'Database', 'visualizer' ), 'query_wp' => __( 'WordPress', 'visualizer' ) ); | |
| 162 | - if ( ! Visualizer_Module::is_pro() ) { | |
| 163 | - $disabled['query'] = $sources['query']; | |
| 164 | - unset( $sources['query'] ); | |
| 165 | - } | |
| 166 | - if ( ! apply_filters( 'visualizer_is_business', false ) ) { | |
| 167 | - $disabled['query_wp'] = $sources['query_wp']; | |
| 168 | - unset( $sources['query_wp'] ); | |
| 169 | - } | |
| 170 | - $sources = array_filter( $sources ); | |
| 171 | - uasort( | |
| 172 | - $sources, function ( $a, $b ) { | |
| 173 | - if ( $a === $b ) { | |
| 174 | - return 0; | |
| 175 | - } | |
| 176 | - return ( $a < $b ) ? -1 : 1; | |
| 177 | - } | |
| 178 | - ); | |
| 179 | - | |
| 180 | - $source = isset( $_GET['source'] ) ? $_GET['source'] : ''; | |
| 181 | - echo '<option value="">' . __( 'All sources', 'visualizer' ) . '</option>'; | |
| 182 | - foreach ( $sources as $field => $label ) { | |
| 183 | - echo '<option value="' . esc_attr( $field ) . '" ' . selected( $source, $field ) . '>' . $label . '</option>'; | |
| 184 | - } | |
| 185 | - | |
| 186 | - if ( $disabled ) { | |
| 187 | - echo '<optgroup label="' . __( 'Not available', 'visualizer' ) . '">'; | |
| 188 | - foreach ( $disabled as $id => $name ) { | |
| 189 | - echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . ' disabled>' . $name . '</option>'; | |
| 190 | - } | |
| 191 | - echo '</optgroup>'; | |
| 192 | - } | |
| 193 | - | |
| 194 | - $name = isset( $_GET['s'] ) ? $_GET['s'] : ''; | |
| 195 | - echo ' | |
| 196 | - </select> | |
| 197 | - <input class="viz-filter" type="text" name="s" placeholder="' . __( 'Enter title', 'visualizer' ) . '" value="' . esc_attr( $name ) . '"> | |
| 198 | - '; | |
| 199 | - | |
| 200 | - echo ' | |
| 201 | - <span class="viz-filter">|</span> | |
| 202 | - <select class="viz-filter" name="orderby"> | |
| 203 | - '; | |
| 204 | - | |
| 205 | - $order_by_fields = apply_filters( 'visualizer_filter_order_by', array( 'date' => __( 'Date', 'visualizer' ), 's' => __( 'Title', 'visualizer' ) ) ); | |
| 206 | - $order_by = isset( $_GET['orderby'] ) ? $_GET['orderby'] : ''; | |
| 207 | - echo '<option value="">' . __( 'Order By', 'visualizer' ) . '</option>'; | |
| 208 | - foreach ( $order_by_fields as $field => $label ) { | |
| 209 | - echo '<option value="' . esc_attr( $field ) . '" ' . selected( $order_by, $field ) . '>' . $label . '</option>'; | |
| 210 | - } | |
| 211 | - | |
| 212 | - echo ' | |
| 213 | - </select> | |
| 214 | - <select class="viz-filter" name="order"> | |
| 215 | - '; | |
| 216 | - | |
| 217 | - $order_type = array( 'desc' => __( 'Descending', 'visualizer' ), 'asc' => __( 'Ascending', 'visualizer' ) ); | |
| 218 | - $order = isset( $_GET['order'] ) ? $_GET['order'] : 'desc'; | |
| 219 | - foreach ( $order_type as $field => $label ) { | |
| 220 | - echo '<option value="' . esc_attr( $field ) . '" ' . selected( $order, $field ) . '>' . $label . '</option>'; | |
| 221 | - } | |
| 222 | - | |
| 223 | - echo ' | |
| 224 | - </select> | |
| 225 | - <input type="submit" class="viz-filter button button-secondary" value="' . __( 'Apply Filters', 'visualizer' ) . '"> | |
| 226 | - <input type="button" id="viz-lib-reset" class="viz-filter button button-secondary" value="' . __( 'Clear Filters', 'visualizer' ) . '"> | |
| 227 | - </form> | |
| 228 | - </div>'; | |
| 229 | - } | |
| 230 | - /** | |
| 231 | - * Renders pro charts blocker. | |
| 232 | - * | |
| 233 | - * @access private | |
| 234 | - */ | |
| 235 | - private function _renderProPopupBlocker() { | |
| 236 | - if ( Visualizer_Module::is_pro() ) { | |
| 237 | - return; | |
| 238 | - } | |
| 239 | - $license = get_option( 'visualizer_pro_license_data', 'free' ); | |
| 240 | - $license_key = ''; | |
| 241 | - $download_id = ''; | |
| 242 | - if ( ! empty( $license ) && is_object( $license ) ) { | |
| 243 | - $license_key = isset( $license->key ) ? $license->key : ''; | |
| 244 | - $download_id = isset( $license->download_id ) ? $license->download_id : ''; | |
| 245 | - } | |
| 246 | - $admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' ); | |
| 247 | - $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' ); | |
| 248 | - echo ' | |
| 249 | - <div class="vizualizer-renew-notice-overlay" id="overlay-visualizer"></div> | |
| 250 | - <div class="vizualizer-renew-notice-popup"> | |
| 251 | - <h1 class="vizualizer-renew-notice-heading">Alert!</h1> | |
| 252 | - <p class="vizualizer-renew-notice-message">' . esc_html__( 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.', 'visualizer' ) . '</p> | |
| 253 | - <div class="vizualizer-renew-notice-buttons-container"> | |
| 254 | - <a href="' . esc_url( $renew_license_url) . '" target="_blank"> | |
| 255 | - <button class="vizualizer-renew-notice-button vizualizer-renew-notice-renew-button"> | |
| 256 | - <span class="dashicons dashicons-cart"></span>' . esc_html__( 'Renew License', 'visualizer' ) . ' | |
| 257 | - </button> | |
| 258 | - </a> | |
| 259 | - <a href="' . esc_url( $admin_license_url ) . '"> | |
| 260 | - <button class="vizualizer-renew-notice-button vizualizer-renew-notice-activate-button"> | |
| 261 | - <span class="dashicons dashicons-unlock"></span> ' . esc_html__( 'Activate License', 'visualizer' ) . ' | |
| 262 | - </button> | |
| 263 | - </a> | |
| 264 | - <button class="vizualizer-renew-notice-button vizualizer-renew-notice-close-icon" aria-label="Close" onclick="closePopup()"> | |
| 265 | - <i class="dashicons dashicons-no"></i> | |
| 266 | - </button> | |
| 267 | - </div> | |
| 268 | - </div> | |
| 269 | - <script> | |
| 270 | - function closePopup() { | |
| 271 | - var overlay = document.getElementById("overlay-visualizer"); | |
| 272 | - var popup = document.querySelector(".vizualizer-renew-notice-popup"); | |
| 273 | - overlay.style.display = "none"; | |
| 274 | - popup.style.display = "none"; | |
| 275 | - } | |
| 276 | - </script>'; | |
| 277 | - } | |
| 278 | - /** | |
| 279 | 68 | * Renders library content. |
| 280 | 69 | * |
| 281 | 70 | * @since 1.0.0 |
| 282 | 71 | * |
| @@ -282,105 +71,82 @@ | ||
| 282 | 71 | * |
| 283 | 72 | * @access private |
| 284 | 73 | */ |
| 285 | 74 | private function _renderLibrary() { |
| 286 | - | |
| 287 | 75 | // Added by Ash/Upwork |
| 288 | - $filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 289 | - | |
| 76 | + $filterBy = null; | |
| 77 | + if ( isset( $_GET['s'] ) && strlen( $_GET['s'] ) > 0 ) { | |
| 78 | + $filterBy = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING ); | |
| 79 | + } | |
| 290 | 80 | // Added by Ash/Upwork |
| 291 | - echo $this->custom_css; | |
| 292 | - | |
| 293 | - $this->_renderProPopupBlocker(); | |
| 294 | - | |
| 295 | 81 | echo '<div id="visualizer-types" class="visualizer-clearfix">'; |
| 296 | - echo '<svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><symbol id="list-icon" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM7.385 12.66H6.045L2.805 8.12L4.146 6.87L6.715 9.27L11.856 3.339L13.196 4.279L7.385 12.66Z"/></symbol></svg>'; | |
| 297 | - $this->getDisplayForm(); | |
| 82 | + echo '<ul class="subsubsub">'; | |
| 83 | + foreach ( $this->types as $type => $array ) { | |
| 84 | + if ( ! is_array( $array ) ) { | |
| 85 | + // support for old pro | |
| 86 | + $array = array( 'enabled' => true, 'name' => $array ); | |
| 87 | + } | |
| 88 | + $label = $array['name']; | |
| 89 | + $link = '<a class=" " href="' . esc_url( add_query_arg( array( | |
| 90 | + 'type' => $type, | |
| 91 | + 'vpage' => false, | |
| 92 | + ) ) ) . '">'; | |
| 93 | + if ( ! $array['enabled'] ) { | |
| 94 | + $link = "<a class=' visualizer-pro-only' href='" . Visualizer_Plugin::PRO_TEASER_URL . "' target='_blank'>"; | |
| 95 | + } | |
| 96 | + echo '<li class="visualizer-list-item all">'; | |
| 97 | + if ( $type == $this->type ) { | |
| 98 | + echo '<a class=" current" href="', esc_url( add_query_arg( 'vpage', false ) ), '">'; | |
| 99 | + echo $label; | |
| 100 | + echo '</a>'; | |
| 101 | + } else { | |
| 102 | + echo $link; | |
| 103 | + echo $label; | |
| 104 | + echo '</a>'; | |
| 105 | + } | |
| 106 | + echo ' | </li>'; | |
| 107 | + } | |
| 108 | + echo '</ul>'; | |
| 109 | + echo '<form action="" method="get"><p id="visualizer-search" class="search-box"> | |
| 110 | + <input type="search" name="s" value="' . $filterBy . '"> | |
| 111 | + <input type="hidden" name="page" value="visualizer"> | |
| 112 | + <input type="submit" id="search-submit" class="button button-secondary" value="' . esc_attr__( 'Search', 'visualizer' ) . '"> | |
| 113 | + </p> </form>'; | |
| 298 | 114 | echo '</div>'; |
| 299 | 115 | echo '<div id="visualizer-content-wrapper">'; |
| 300 | - echo '<div id="tsdk_banner" class="visualizer-banner"></div>'; | |
| 301 | 116 | if ( ! empty( $this->charts ) ) { |
| 302 | - if ( $this->_isListView() ) { | |
| 303 | - echo '<div id="visualizer-library" class="visualizer-clearfix view-list">'; | |
| 304 | - $this->_renderSidebar(); | |
| 305 | - echo '<table class="wp-list-table widefat striped viz-charts-table">'; | |
| 306 | - echo '<thead><tr>'; | |
| 307 | - echo '<th class="col-id">' . esc_html__( 'ID', 'visualizer' ) . '</th>'; | |
| 308 | - echo '<th class="col-title">' . esc_html__( 'Title', 'visualizer' ) . '</th>'; | |
| 309 | - echo '<th class="col-type">' . esc_html__( 'Type', 'visualizer' ) . '</th>'; | |
| 310 | - echo '<th class="col-shortcode">' . esc_html__( 'Shortcode', 'visualizer' ) . '</th>'; | |
| 311 | - echo '<th class="col-actions">' . esc_html__( 'Actions', 'visualizer' ) . '</th>'; | |
| 312 | - echo '</tr></thead><tbody>'; | |
| 313 | - foreach ( $this->charts as $placeholder_id => $chart ) { | |
| 314 | - $enable_controls = false; | |
| 315 | - $settings = isset( $chart['settings'] ) ? $chart['settings'] : array(); | |
| 316 | - if ( ! empty( $settings['controls']['controlType'] ) ) { | |
| 317 | - $column_index = $settings['controls']['filterColumnIndex']; | |
| 318 | - $column_label = $settings['controls']['filterColumnLabel']; | |
| 319 | - if ( 'false' !== $column_index || 'false' !== $column_label ) { | |
| 320 | - $enable_controls = true; | |
| 321 | - } | |
| 322 | - } | |
| 323 | - $this->_renderChartBox( $placeholder_id, $chart['id'], $enable_controls ); | |
| 117 | + echo '<div id="visualizer-library" class="visualizer-clearfix">'; | |
| 118 | + foreach ( $this->charts as $placeholder_id => $chart ) { | |
| 119 | + $this->_renderChartBox( $placeholder_id, $chart['id'] ); | |
| 120 | + } | |
| 121 | + echo '</div>'; | |
| 122 | + if ( is_array( $this->pagination ) ) { | |
| 123 | + echo '<ul class=" subsubsub">'; | |
| 124 | + foreach ( $this->pagination as $page ) { | |
| 125 | + echo '<li class="all">', $page, '</li>'; | |
| 324 | 126 | } |
| 325 | - echo '</tbody></table>'; | |
| 326 | - echo '</div>'; | |
| 327 | - } else { | |
| 328 | - echo '<div id="visualizer-library" class="visualizer-clearfix view-grid">'; | |
| 329 | - $this->_renderSidebar(); | |
| 330 | - foreach ( $this->charts as $placeholder_id => $chart ) { | |
| 331 | - $enable_controls = false; | |
| 332 | - $settings = isset( $chart['settings'] ) ? $chart['settings'] : array(); | |
| 333 | - if ( ! empty( $settings['controls']['controlType'] ) ) { | |
| 334 | - $column_index = $settings['controls']['filterColumnIndex']; | |
| 335 | - $column_label = $settings['controls']['filterColumnLabel']; | |
| 336 | - if ( 'false' !== $column_index || 'false' !== $column_label ) { | |
| 337 | - $enable_controls = true; | |
| 338 | - } | |
| 339 | - } | |
| 340 | - $this->_renderChartBox( $placeholder_id, $chart['id'], $enable_controls ); | |
| 341 | - } | |
| 342 | - echo '</div>'; | |
| 127 | + echo '</ul>'; | |
| 343 | 128 | } |
| 344 | 129 | } else { |
| 345 | - echo '<div id="visualizer-library" class="visualizer-clearfix view-grid">'; | |
| 346 | - $this->_renderSidebar(); | |
| 347 | - echo '<div class="items"><div class="visualizer-chart">'; | |
| 130 | + echo '<div id="visualizer-library" class="visualizer-clearfix">'; | |
| 131 | + echo '<div class="visualizer-chart">'; | |
| 348 | 132 | echo '<div class="visualizer-chart-canvas visualizer-nochart-canvas">'; |
| 349 | - echo '<div class="visualizer-notfound">'; | |
| 350 | - echo esc_html__( 'No charts found. Click \'Add New Chart\' to create one.', 'visualizer' ); | |
| 351 | - echo '<p><h2>'; | |
| 352 | - echo '<div class="viz-add-new-group">'; | |
| 353 | - echo '<a href="javascript:;" class="add-new-h2 add-new-chart">', esc_html__( 'Add New Chart', 'visualizer' ), '</a>'; | |
| 354 | - echo '<button type="button" class="viz-add-new-toggle" aria-haspopup="true" aria-expanded="false"><span class="dashicons dashicons-arrow-down-alt2"></span></button>'; | |
| 355 | - echo '<div class="viz-add-new-menu" role="menu" aria-hidden="true">'; | |
| 356 | - echo '<button type="button" class="viz-add-new-item" data-viz-builder="ai">', esc_html__( 'AI Chart Builder', 'visualizer' ), '</button>'; | |
| 357 | - echo '<button type="button" class="viz-add-new-item" data-viz-builder="classic">', esc_html__( 'Classic Builder', 'visualizer' ), '</button>'; | |
| 133 | + echo '<div class="visualizer-notfound">', esc_html__( 'No charts found', 'visualizer' ), '</div>'; | |
| 358 | 134 | echo '</div>'; |
| 359 | - echo '</div>'; | |
| 360 | - echo '</h2></p></div>'; | |
| 361 | - echo '</div>'; | |
| 362 | 135 | echo '<div class="visualizer-chart-footer visualizer-clearfix">'; |
| 363 | - echo '<div class="visualizer-action-group visualizer-nochart">'; | |
| 364 | - echo '<span class="visualizer-chart-action visualizer-nochart-delete"><span class="dashicons dashicons-trash"></span></span>'; | |
| 365 | - echo '<span class="visualizer-chart-action visualizer-nochart-shortcode"><span class="dashicons dashicons-shortcode"></span></span>'; | |
| 366 | - echo '<span class="visualizer-chart-action visualizer-nochart-image"><span class="dashicons dashicons-format-image"></span></span>'; | |
| 367 | - echo '<span class="visualizer-chart-action visualizer-nochart-export"><span class="dashicons dashicons-download"></span></span>'; | |
| 368 | - echo '<span class="visualizer-chart-action visualizer-nochart-clone"><span class="dashicons dashicons-admin-page"></span></span>'; | |
| 369 | - echo '<span class="visualizer-chart-action visualizer-nochart-edit"><span class="dashicons dashicons-edit"></span></span>'; | |
| 136 | + echo '<span class="visualizer-chart-action visualizer-nochart-delete"></span>'; | |
| 137 | + echo '<span class="visualizer-chart-action visualizer-nochart-clone"></span>'; | |
| 138 | + echo '<span class="visualizer-chart-action visualizer-nochart-edit"></span>'; | |
| 139 | + echo '<span class="visualizer-chart-action visualizer-nochart-export"></span>'; | |
| 140 | + echo '<span class="visualizer-chart-shortcode">'; | |
| 141 | + echo ' [visualizer] '; | |
| 142 | + echo '</span>'; | |
| 370 | 143 | echo '</div>'; |
| 371 | 144 | echo '</div>'; |
| 372 | - echo '</div></div>'; | |
| 373 | 145 | echo '</div>'; |
| 374 | 146 | } |
| 147 | + $this->_renderSidebar(); | |
| 375 | 148 | echo '</div>'; |
| 376 | - if ( is_array( $this->pagination ) ) { | |
| 377 | - echo '<ul class=" subsubsub">'; | |
| 378 | - foreach ( $this->pagination as $page ) { | |
| 379 | - echo '<li class="all">', $page, '</li>'; | |
| 380 | - } | |
| 381 | - echo '</ul>'; | |
| 382 | - } | |
| 383 | 149 | } |
| 384 | 150 | |
| 385 | 151 | /** |
| 386 | 152 | * Renders chart's box block. |
| @@ -391,184 +157,67 @@ | ||
| 391 | 157 | * |
| 392 | 158 | * @param string $placeholder_id The placeholder's id for the chart. |
| 393 | 159 | * @param int $chart_id The id of the chart. |
| 394 | 160 | */ |
| 395 | - private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = false ) { | |
| 396 | - $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS ); | |
| 397 | - $chart_library = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ); | |
| 398 | - $title = '#' . $chart_id; | |
| 399 | - if ( ! empty( $settings[0]['title'] ) ) { | |
| 400 | - $title = $settings[0]['title']; | |
| 401 | - } | |
| 402 | - // for ChartJS, title is an array. | |
| 403 | - if ( is_array( $title ) && isset( $title['text'] ) ) { | |
| 404 | - $title = $title['text']; | |
| 405 | - } | |
| 406 | - if ( ! empty( $settings[0]['backend-title'] ) ) { | |
| 407 | - $title = $settings[0]['backend-title']; | |
| 408 | - } | |
| 409 | - if ( empty( $title ) ) { | |
| 410 | - $title = '#' . $chart_id; | |
| 411 | - } | |
| 412 | - | |
| 161 | + private function _renderChartBox( $placeholder_id, $chart_id ) { | |
| 413 | 162 | $ajax_url = admin_url( 'admin-ajax.php' ); |
| 414 | - $delete_url = esc_url( | |
| 415 | - add_query_arg( | |
| 416 | - array( | |
| 417 | - 'action' => Visualizer_Plugin::ACTION_DELETE_CHART, | |
| 418 | - 'nonce' => wp_create_nonce(), | |
| 419 | - 'chart' => $chart_id, | |
| 420 | - ), | |
| 421 | - $ajax_url | |
| 422 | - ) | |
| 423 | - ); | |
| 424 | - $clone_url = esc_url( | |
| 425 | - add_query_arg( | |
| 426 | - array( | |
| 427 | - 'action' => Visualizer_Plugin::ACTION_CLONE_CHART, | |
| 428 | - 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_CLONE_CHART ), | |
| 429 | - 'chart' => $chart_id, | |
| 430 | - 'type' => $this->type, | |
| 431 | - ), | |
| 432 | - $ajax_url | |
| 433 | - ) | |
| 434 | - ); | |
| 435 | - $export_link = esc_url( | |
| 436 | - add_query_arg( | |
| 437 | - array( | |
| 438 | - 'action' => Visualizer_Plugin::ACTION_EXPORT_DATA, | |
| 439 | - 'chart' => $chart_id, | |
| 440 | - 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ), | |
| 441 | - ), | |
| 442 | - admin_url( 'admin-ajax.php' ) | |
| 443 | - ) | |
| 444 | - ); | |
| 445 | - $chart_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); | |
| 446 | - $chart_type_label = $chart_type; | |
| 447 | - if ( empty( $chart_type_label ) && 'd3' === strtolower( (string) $chart_library ) ) { | |
| 448 | - $chart_type_label = __( 'AI', 'visualizer' ); | |
| 449 | - } | |
| 450 | - | |
| 451 | - $types = array( 'area', 'geo', 'column', 'bubble', 'scatter', 'gauge', 'candlestick', 'timeline', 'combo', 'polarArea', 'radar' ); | |
| 452 | - | |
| 453 | - $pro_class = ''; | |
| 454 | - | |
| 455 | - if ( ! empty( $chart_type ) && in_array( $chart_type, $types, true ) ) { | |
| 456 | - $pro_class = 'viz-is-pro-chart'; | |
| 457 | - } | |
| 458 | - | |
| 459 | - $chart_status = array( 'date' => get_the_modified_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $chart_id ), 'error' => get_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, true ), 'icon' => 'dashicons-yes-alt', 'title' => 'A-OK!' ); | |
| 460 | - if ( ! empty( $chart_status['error'] ) ) { | |
| 461 | - $chart_status['icon'] = 'error dashicons-dismiss'; | |
| 462 | - $chart_status['title'] = __( 'Click to view the error', 'visualizer' ); | |
| 463 | - } | |
| 464 | - $shortcode = sprintf( '[visualizer id="%s" class=""]', $chart_id ); | |
| 465 | - | |
| 466 | - if ( $this->_isListView() ) { | |
| 467 | - // ── List view: table row ── | |
| 468 | - echo '<tr class="viz-list-row">'; | |
| 469 | - echo '<td class="col-id">#' . esc_html( (string) $chart_id ) . '</td>'; | |
| 470 | - echo '<td class="col-title">' . esc_html( $title ) . '</td>'; | |
| 471 | - echo '<td class="col-type">' . ( ! empty( $chart_type_label ) ? '<span class="viz-chart-type-badge">' . esc_html( $chart_type_label ) . '</span>' : '—' ) . '</td>'; | |
| 472 | - echo '<td class="col-shortcode"><code class="viz-shortcode-display">' . esc_html( $shortcode ) . '</code></td>'; | |
| 473 | - echo '<td class="col-actions"><div class="visualizer-action-group">'; | |
| 474 | - echo '<a class="visualizer-chart-action visualizer-chart-delete" href="' . $delete_url . '" onclick="return showNotice.warn();"><span class="dashicons dashicons-trash"></span><span class="tooltip-text">' . esc_html__( 'Delete', 'visualizer' ) . '</span></a>'; | |
| 475 | - echo '<a class="visualizer-chart-action visualizer-chart-shortcode ' . esc_attr( $pro_class ) . '" href="javascript:;" data-clipboard-text="' . esc_attr( $shortcode ) . '"><span class="dashicons dashicons-shortcode ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Copy Shortcode', 'visualizer' ) . '</span></a>'; | |
| 476 | - echo '<a class="visualizer-chart-action visualizer-chart-export ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="' . $export_link . '"><span class="dashicons dashicons-download ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Export CSV', 'visualizer' ) . '</span></a>'; | |
| 477 | - echo '<a class="visualizer-chart-action visualizer-chart-clone ' . esc_attr( $pro_class ) . '" href="' . $clone_url . '"><span class="dashicons dashicons-admin-page ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Duplicate', 'visualizer' ) . '</span></a>'; | |
| 478 | - echo '<a class="visualizer-chart-action visualizer-chart-edit button button-secondary ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="' . esc_attr( (string) $chart_id ) . '" data-library="' . esc_attr( $chart_library ) . '"><span class="dashicons dashicons-edit ' . esc_attr( $pro_class ) . '"></span><span class="visualizer-action-label">' . esc_html__( 'Edit', 'visualizer' ) . '</span><span class="tooltip-text">' . esc_html__( 'Edit', 'visualizer' ) . '</span></a>'; | |
| 479 | - echo '</div></td>'; | |
| 480 | - echo '</tr>'; | |
| 481 | - return; | |
| 482 | - } | |
| 483 | - | |
| 484 | - // ── Grid view: card ── | |
| 485 | - $type_badge = ! empty( $chart_type ) ? '<span class="viz-chart-type-badge">' . esc_html( $chart_type ) . '</span>' : ''; | |
| 486 | - echo '<div class="items"><div class="visualizer-chart"><div class="visualizer-chart-title"><span>' . esc_html( $title ) . '</span>' . $type_badge . '</div>'; | |
| 487 | - if ( Visualizer_Module::is_pro() && $with_filter ) { | |
| 488 | - echo '<div id="chart_wrapper_' . $placeholder_id . '">'; | |
| 489 | - echo '<div id="control_wrapper_' . $placeholder_id . '" class="vz-library-chart-filter"></div>'; | |
| 490 | - } | |
| 163 | + $delete_url = add_query_arg( array( | |
| 164 | + 'action' => Visualizer_Plugin::ACTION_DELETE_CHART, | |
| 165 | + 'nonce' => wp_create_nonce(), | |
| 166 | + 'chart' => $chart_id, | |
| 167 | + ), $ajax_url ); | |
| 168 | + $clone_url = add_query_arg( array( | |
| 169 | + 'action' => Visualizer_Plugin::ACTION_CLONE_CHART, | |
| 170 | + 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_CLONE_CHART ), | |
| 171 | + 'chart' => $chart_id, | |
| 172 | + 'type' => $this->type, | |
| 173 | + ), $ajax_url ); | |
| 174 | + $export_link = add_query_arg( array( | |
| 175 | + 'action' => Visualizer_Plugin::ACTION_EXPORT_DATA, | |
| 176 | + 'chart' => $chart_id, | |
| 177 | + 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ), | |
| 178 | + ), admin_url( 'admin-ajax.php' ) ); | |
| 179 | + echo '<div class="visualizer-chart">'; | |
| 491 | 180 | echo '<div id="', $placeholder_id, '" class="visualizer-chart-canvas">'; |
| 492 | 181 | echo '<img src="', VISUALIZER_ABSURL, 'images/ajax-loader.gif" class="loader">'; |
| 493 | 182 | echo '</div>'; |
| 494 | - if ( Visualizer_Module::is_pro() && $with_filter ) { | |
| 495 | - echo '</div>'; | |
| 496 | - } | |
| 497 | 183 | echo '<div class="visualizer-chart-footer visualizer-clearfix">'; |
| 498 | - echo '<div class="visualizer-action-group">'; | |
| 499 | - echo '<a class="visualizer-chart-action visualizer-chart-edit button button-secondary ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="', esc_attr( (string) $chart_id ), '" data-library="' . esc_attr( $chart_library ) . '"><span class="dashicons dashicons-edit ' . esc_attr( $pro_class ) . '"></span><span class="visualizer-action-label">' . esc_html__( 'Edit', 'visualizer' ) . '</span><span class="tooltip-text">' . esc_html__( 'Edit', 'visualizer' ) . '</span></a>'; | |
| 500 | - echo '<a class="visualizer-chart-action visualizer-chart-shortcode ' . esc_attr( $pro_class ) . '" href="javascript:;" data-clipboard-text="', esc_attr( $shortcode ), '"><span class="dashicons dashicons-shortcode ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Copy Shortcode', 'visualizer' ) . '</span></a>'; | |
| 501 | - if ( $this->can_chart_have_action( 'image', $chart_id ) ) { | |
| 502 | - echo '<a class="visualizer-chart-action visualizer-chart-image ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="visualizer-', esc_attr( (string) $chart_id ), '" data-chart-title="', esc_attr( $title ), '"><span class="dashicons dashicons-format-image ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Download PNG', 'visualizer' ) . '</span></a>'; | |
| 503 | - } | |
| 504 | - echo '<a class="visualizer-chart-action visualizer-chart-export ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="', $export_link, '"><span class="dashicons dashicons-download ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Export CSV', 'visualizer' ) . '</span></a>'; | |
| 505 | - echo '<a class="visualizer-chart-action visualizer-chart-clone ' . esc_attr( $pro_class ) . '" href="', $clone_url, '"><span class="dashicons dashicons-admin-page ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_html__( 'Duplicate', 'visualizer' ) . '</span></a>'; | |
| 506 | - echo '<a class="visualizer-chart-action visualizer-chart-delete" href="', $delete_url, '" onclick="return showNotice.warn();"><span class="dashicons dashicons-trash"></span><span class="tooltip-text">' . esc_html__( 'Delete', 'visualizer' ) . '</span></a>'; | |
| 184 | + echo '<a class="visualizer-chart-action visualizer-chart-delete" href="', $delete_url, '" title="', esc_attr__( 'Delete', 'visualizer' ), '" onclick="return showNotice.warn();"></a>'; | |
| 185 | + echo '<a class="visualizer-chart-action visualizer-chart-clone" href="', $clone_url, '" title="', esc_attr__( 'Clone', 'visualizer' ), '"></a>'; | |
| 186 | + echo '<a class="visualizer-chart-action visualizer-chart-edit" href="javascript:;" title="', esc_attr__( 'Edit', 'visualizer' ), '" data-chart="', $chart_id, '"></a>'; | |
| 187 | + echo '<a class="visualizer-chart-action visualizer-chart-export" href="javascript:;" title="', esc_attr__( 'Export', 'visualizer' ), '" data-chart="', $export_link, '"></a>'; | |
| 188 | + echo '<span class="visualizer-chart-shortcode" title="', esc_attr__( 'Click to select', 'visualizer' ), '">'; | |
| 189 | + echo ' [visualizer id="', $chart_id, '"] '; | |
| 190 | + echo '</span>'; | |
| 507 | 191 | echo '</div>'; |
| 508 | - do_action( 'visualizer_chart_languages', $chart_id ); | |
| 509 | - echo '<hr><div class="visualizer-chart-status"><span title="' . __( 'Chart ID', 'visualizer' ) . '">(' . $chart_id . '):</span> <span class="visualizer-date" title="' . __( 'Last Updated', 'visualizer' ) . '">' . $chart_status['date'] . '</span><span class="visualizer-error"><i class="dashicons ' . $chart_status['icon'] . '" data-viz-error="' . esc_attr( str_replace( '"', "'", $chart_status['error'] ) ) . '" title="' . esc_attr( $chart_status['title'] ) . '"></i></span></div>'; | |
| 510 | 192 | echo '</div>'; |
| 511 | - echo '</div></div>'; | |
| 512 | 193 | } |
| 513 | 194 | |
| 514 | 195 | /** |
| 515 | - * Returns true when the library should render in list (no-preview) mode. | |
| 516 | - * | |
| 517 | - * Priority: ?view= URL param (saves to user meta) → saved user meta → grid default. | |
| 518 | - * | |
| 519 | - * No nonce needed: this is a bookmarkable UI preference URL. A nonce would expire | |
| 520 | - * and break saved/shared links for zero real security gain — the value is allowlisted | |
| 521 | - * to 'list'|'grid' before any write happens. | |
| 196 | + * Render sidebar. | |
| 522 | 197 | */ |
| 523 | - private function _isListView(): bool { | |
| 524 | - if ( null !== $this->_list_view_cached ) { | |
| 525 | - return $this->_list_view_cached; | |
| 526 | - } | |
| 527 | - if ( isset( $_GET['view'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 528 | - $view = sanitize_text_field( wp_unslash( $_GET['view'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 529 | - if ( in_array( $view, array( 'list', 'grid' ), true ) ) { | |
| 530 | - update_user_meta( get_current_user_id(), 'visualizer_library_view', $view ); | |
| 531 | - } | |
| 532 | - $this->_list_view_cached = ( 'list' === $view ); | |
| 533 | - } else { | |
| 534 | - $saved = get_user_meta( get_current_user_id(), 'visualizer_library_view', true ); | |
| 535 | - $this->_list_view_cached = ( 'list' === $saved ); | |
| 536 | - } | |
| 537 | - return $this->_list_view_cached; | |
| 538 | - } | |
| 539 | - | |
| 540 | - /** | |
| 541 | - * Returns the HTML for the grid/list view toggle links. | |
| 542 | - */ | |
| 543 | - private function _getViewToggleHTML(): string { | |
| 544 | - $is_list = $this->_isListView(); | |
| 545 | - $grid_url = esc_url( add_query_arg( 'view', 'grid' ) ); | |
| 546 | - $list_url = esc_url( add_query_arg( 'view', 'list' ) ); | |
| 547 | - return '<a href="' . $grid_url . '" class="viz-view-toggle' . ( ! $is_list ? ' active' : '' ) . '" title="' . esc_attr__( 'Grid View', 'visualizer' ) . '"><span class="dashicons dashicons-screenoptions"></span></a>' | |
| 548 | - . '<a href="' . $list_url . '" class="viz-view-toggle' . ( $is_list ? ' active' : '' ) . '" title="' . esc_attr__( 'List View', 'visualizer' ) . '"><span class="dashicons dashicons-list-view"></span></a>'; | |
| 549 | - } | |
| 550 | - | |
| 551 | - /** | |
| 552 | - * Render 2-col sidebar | |
| 553 | - */ | |
| 554 | 198 | private function _renderSidebar() { |
| 555 | - if ( ! Visualizer_Module::is_pro() ) { | |
| 556 | - $upgrade_url = tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'sidebarMenuUpgrade', 'index' ); | |
| 557 | - $chart_types = Visualizer_Module_Admin::proFeaturesEnabled() ? __( '6 more chart types', 'visualizer' ) : __( '11 more chart types', 'visualizer' ); | |
| 558 | - echo '<div class="items--upsell">'; | |
| 559 | - echo '<div class="viz-upsell-banner">'; | |
| 560 | - echo '<span class="dashicons dashicons-star-filled viz-upsell-banner__icon"></span>'; | |
| 561 | - echo '<div class="viz-upsell-banner__text">'; | |
| 562 | - echo '<strong>' . esc_html__( 'Unlock the full power of Visualizer PRO!', 'visualizer' ) . '</strong>'; | |
| 563 | - /* translators: %s: number of additional chart types (e.g. "11 more chart types") */ | |
| 564 | - echo '<span>' . sprintf( esc_html__( '%s, periodic data sync, database queries, frontend editor, and more.', 'visualizer' ), esc_html( $chart_types ) ) . '</span>'; | |
| 199 | + if ( ! VISUALIZER_PRO ) { | |
| 200 | + $checked = apply_filters( 'visualizer_logger_flag', false ); | |
| 201 | + $checked = ( $checked === false ) ? '' : 'checked'; | |
| 202 | + echo '<div id="visualizer-sidebar">'; | |
| 203 | + echo '<div class="visualizer-sidebar-box">'; | |
| 204 | + echo '<h3>' . __( 'Gain more editing power', 'visualizer' ) . '</h3><ul>'; | |
| 205 | + echo '<li>' . __( 'Spreadsheet like editor', 'visualizer' ) . '</li>'; | |
| 206 | + echo '<li>' . __( 'Import from other charts', 'visualizer' ) . '</li>'; | |
| 207 | + echo '<li>' . __( 'Auto-sync with online files', 'visualizer' ) . '</li>'; | |
| 208 | + echo '<li>' . __( '3 more chart types', 'visualizer' ) . '</li></ul>'; | |
| 209 | + echo '<a href="' . Visualizer_Plugin::PRO_TEASER_URL . '" target="_blank" class="button button-primary">' . __( 'View more features', 'visualizer' ) . '</a>'; | |
| 565 | 210 | echo '</div>'; |
| 566 | - echo '<div class="viz-upsell-banner__actions">'; | |
| 567 | - echo '<a href="' . esc_url( $upgrade_url . '#pro-features' ) . '" target="_blank" class="button button-secondary">' . esc_html__( 'View Features', 'visualizer' ) . '</a>'; | |
| 568 | - echo '<a href="' . esc_url( $upgrade_url . '#pricing' ) . '" target="_blank" class="button button-primary">' . esc_html__( 'Upgrade Now', 'visualizer' ) . '</a>'; | |
| 211 | + echo '<div class="visualizer-sidebar-box visualizer-tracking">'; | |
| 212 | + echo '<label class="visualizer-switch">'; | |
| 213 | + echo '<input type="checkbox" ' . $checked . ' >'; | |
| 214 | + echo '<div class="visualizer-slider visualizer-round"></div>'; | |
| 215 | + echo '</label>'; | |
| 216 | + echo '<span>' . __( 'Enable Tracking', 'visualizer' ) . '<sup>*</sup></span>'; | |
| 217 | + echo '<p><small><sup>*</sup>' . __( 'Allow Visualizer to anonymously track how this plugin is used and help us make the plugin better. No sensitive data is tracked.', 'visualizer' ) . '</small></p>'; | |
| 569 | 218 | echo '</div>'; |
| 570 | 219 | echo '</div>'; |
| 571 | - echo '</div>'; | |
| 572 | 220 | } |
| 573 | 221 | } |
| 222 | + | |
| 574 | 223 | } |