| 1 | <?php |
|---|
| 2 | // +----------------------------------------------------------------------+ |
|---|
| 3 | // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
|---|
| 4 | // +----------------------------------------------------------------------+ |
|---|
| 5 | // | This program is free software; you can redistribute it and/or modify | |
|---|
| 6 | // | it under the terms of the GNU General Public License, version 2, as | |
|---|
| 7 | // | published by the Free Software Foundation. | |
|---|
| 8 | // | | |
|---|
| 9 | // | This program is distributed in the hope that it will be useful, | |
|---|
| 10 | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 11 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|---|
| 12 | // | GNU General Public License for more details. | |
|---|
| 13 | // | | |
|---|
| 14 | // | You should have received a copy of the GNU General Public License | |
|---|
| 15 | // | along with this program; if not, write to the Free Software | |
|---|
| 16 | // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
|---|
| 17 | // | MA 02110-1301 USA | |
|---|
| 18 | // +----------------------------------------------------------------------+ |
|---|
| 19 | // | Author: Eugene Manuilov <eugene@manuilov.org> | |
|---|
| 20 | // +----------------------------------------------------------------------+ |
|---|
| 21 | /** |
|---|
| 22 | * Renders visualizer library page. |
|---|
| 23 | * |
|---|
| 24 | * @category Visualizer |
|---|
| 25 | * @package Render |
|---|
| 26 | * |
|---|
| 27 | * @since 1.0.0 |
|---|
| 28 | */ |
|---|
| 29 | class Visualizer_Render_Library extends Visualizer_Render { |
|---|
| 30 | |
|---|
| 31 | /** |
|---|
| 32 | * Renders library page. |
|---|
| 33 | * |
|---|
| 34 | * @since 1.0.0 |
|---|
| 35 | * |
|---|
| 36 | * @access protected |
|---|
| 37 | */ |
|---|
| 38 | protected function _toHTML() { |
|---|
| 39 | echo '<div class="wrap">'; |
|---|
| 40 | echo '<div id="visualizer-icon" class="icon32"><br></div>'; |
|---|
| 41 | echo '<h2>'; |
|---|
| 42 | esc_html_e( 'Visualizer Library', 'visualizer' ); |
|---|
| 43 | echo ' <a href="javascript:;" class="add-new-h2 add-new-chart">', esc_html__( 'Add New', 'visualizer' ), '</a>'; |
|---|
| 44 | if ( Visualizer_Module::is_pro() ) { |
|---|
| 45 | echo ' <a href="' . admin_url( 'options-general.php' ) . '" class="page-title-action">', esc_html__( 'License Settings', 'visualizer' ), '</a>'; |
|---|
| 46 | } |
|---|
| 47 | echo '</h2>'; |
|---|
| 48 | $this->_renderMessages(); |
|---|
| 49 | $this->_renderLibrary(); |
|---|
| 50 | echo '</div>'; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * Renders notification messages if need be. |
|---|
| 55 | * |
|---|
| 56 | * @since 1.4.2 |
|---|
| 57 | * |
|---|
| 58 | * @access private |
|---|
| 59 | */ |
|---|
| 60 | private function _renderMessages() { |
|---|
| 61 | if ( ! filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN ) ) { |
|---|
| 62 | echo '<div class="updated error">'; |
|---|
| 63 | echo '<p>'; |
|---|
| 64 | printf( |
|---|
| 65 | // translators: %s - the name of the option. |
|---|
| 66 | 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' ), |
|---|
| 67 | '<b>allow_url_fopen</b>' |
|---|
| 68 | ); |
|---|
| 69 | echo '</p>'; |
|---|
| 70 | echo '</div>'; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Displays the search form. |
|---|
| 76 | */ |
|---|
| 77 | private function getDisplayForm() { |
|---|
| 78 | echo '<div class="visualizer-library-form"> |
|---|
| 79 | <form action="' . admin_url( 'admin.php' ) . '"> |
|---|
| 80 | <input type="hidden" name="page" value="' . Visualizer_Plugin::NAME . '"/> |
|---|
| 81 | <select class="viz-filter" name="type"> |
|---|
| 82 | '; |
|---|
| 83 | |
|---|
| 84 | echo '<option value="" selected>' . __( 'All types', 'visualizer' ) . '</option>'; |
|---|
| 85 | |
|---|
| 86 | $type = isset( $_GET['type'] ) ? $_GET['type'] : ''; |
|---|
| 87 | $enabled = array(); |
|---|
| 88 | $disabled = array(); |
|---|
| 89 | foreach ( $this->types as $id => $array ) { |
|---|
| 90 | if ( ! is_array( $array ) ) { |
|---|
| 91 | // support for old pro |
|---|
| 92 | $array = array( 'enabled' => true, 'name' => $array ); |
|---|
| 93 | } |
|---|
| 94 | if ( ! $array['enabled'] ) { |
|---|
| 95 | $disabled[ $id ] = $array['name']; |
|---|
| 96 | continue; |
|---|
| 97 | } |
|---|
| 98 | $enabled[ $id ] = $array['name']; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | asort( $enabled ); |
|---|
| 102 | asort( $disabled ); |
|---|
| 103 | |
|---|
| 104 | foreach ( $enabled as $id => $name ) { |
|---|
| 105 | echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . '>' . $name . '</option>'; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if ( $disabled ) { |
|---|
| 109 | echo '<optgroup label="' . __( 'Not available', 'visualizer' ) . '">'; |
|---|
| 110 | foreach ( $disabled as $id => $name ) { |
|---|
| 111 | echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . ' disabled>' . $name . '</option>'; |
|---|
| 112 | } |
|---|
| 113 | echo '</optgroup>'; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | echo ' |
|---|
| 117 | </select> |
|---|
| 118 | <select class="viz-filter" name="library"> |
|---|
| 119 | '; |
|---|
| 120 | |
|---|
| 121 | $libraries = array( '', 'ChartJS', 'DataTable', 'GoogleCharts' ); |
|---|
| 122 | $library = isset( $_GET['library'] ) ? $_GET['library'] : ''; |
|---|
| 123 | foreach ( $libraries as $lib ) { |
|---|
| 124 | echo '<option value="' . esc_attr( $lib ) . '" ' . selected( $library, $lib ) . '>' . ( $lib === '' ? __( 'All libraries', 'visualizer' ) : $lib ) . '</option>'; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | echo ' |
|---|
| 128 | </select> |
|---|
| 129 | <select class="viz-filter" name="date"> |
|---|
| 130 | '; |
|---|
| 131 | |
|---|
| 132 | $dates = Visualizer_Plugin::getSupportedDateFilter(); |
|---|
| 133 | $date = isset( $_GET['date'] ) ? $_GET['date'] : ''; |
|---|
| 134 | foreach ( Visualizer_Plugin::getSupportedDateFilter() as $dt => $label ) { |
|---|
| 135 | echo '<option value="' . esc_attr( $dt ) . '" ' . selected( $date, $dt ) . '>' . $label . '</option>'; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | echo ' |
|---|
| 139 | </select> |
|---|
| 140 | <select class="viz-filter" name="source"> |
|---|
| 141 | '; |
|---|
| 142 | |
|---|
| 143 | $disabled = array(); |
|---|
| 144 | $sources = array( 'json' => __( 'JSON', 'visualizer' ), 'csv' => __( 'Local CSV', 'visualizer' ), 'csv_remote' => __( 'Remote CSV', 'visualizer' ), 'query' => __( 'Database', 'visualizer' ), 'query_wp' => __( 'WordPress', 'visualizer' ) ); |
|---|
| 145 | if ( ! Visualizer_Module::is_pro() ) { |
|---|
| 146 | $disabled['query'] = $sources['query']; |
|---|
| 147 | unset( $sources['query'] ); |
|---|
| 148 | } |
|---|
| 149 | if ( ! apply_filters( 'visualizer_is_business', false ) ) { |
|---|
| 150 | $disabled['query_wp'] = $sources['query_wp']; |
|---|
| 151 | unset( $sources['query_wp'] ); |
|---|
| 152 | } |
|---|
| 153 | $sources = array_filter( $sources ); |
|---|
| 154 | uasort( |
|---|
| 155 | $sources, function( $a, $b ) { |
|---|
| 156 | if ( $a === $b ) { |
|---|
| 157 | return 0; |
|---|
| 158 | } |
|---|
| 159 | return ( $a < $b ) ? -1 : 1; |
|---|
| 160 | } |
|---|
| 161 | ); |
|---|
| 162 | |
|---|
| 163 | $source = isset( $_GET['source'] ) ? $_GET['source'] : ''; |
|---|
| 164 | echo '<option value="">' . __( 'All sources', 'visualizer' ) . '</option>'; |
|---|
| 165 | foreach ( $sources as $field => $label ) { |
|---|
| 166 | echo '<option value="' . esc_attr( $field ) . '" ' . selected( $source, $field ) . '>' . $label . '</option>'; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | if ( $disabled ) { |
|---|
| 170 | echo '<optgroup label="' . __( 'Not available', 'visualizer' ) . '">'; |
|---|
| 171 | foreach ( $disabled as $id => $name ) { |
|---|
| 172 | echo '<option value="' . esc_attr( $id ) . '" ' . selected( $type, $id ) . ' disabled>' . $name . '</option>'; |
|---|
| 173 | } |
|---|
| 174 | echo '</optgroup>'; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | $name = isset( $_GET['s'] ) ? $_GET['s'] : ''; |
|---|
| 178 | echo ' |
|---|
| 179 | </select> |
|---|
| 180 | <input class="viz-filter" type="text" name="s" placeholder="' . __( 'Enter title', 'visualizer' ) . '" value="' . esc_attr( $name ) . '"> |
|---|
| 181 | '; |
|---|
| 182 | |
|---|
| 183 | echo ' |
|---|
| 184 | <span class="viz-filter">|</span> |
|---|
| 185 | <select class="viz-filter" name="orderby"> |
|---|
| 186 | '; |
|---|
| 187 | |
|---|
| 188 | $order_by_fields = apply_filters( 'visualizer_filter_order_by', array( 'date' => __( 'Date', 'visualizer' ), 's' => __( 'Title', 'visualizer' ) ) ); |
|---|
| 189 | $order_by = isset( $_GET['orderby'] ) ? $_GET['orderby'] : ''; |
|---|
| 190 | echo '<option value="">' . __( 'Order By', 'visualizer' ) . '</option>'; |
|---|
| 191 | foreach ( $order_by_fields as $field => $label ) { |
|---|
| 192 | echo '<option value="' . esc_attr( $field ) . '" ' . selected( $order_by, $field ) . '>' . $label . '</option>'; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | echo ' |
|---|
| 196 | </select> |
|---|
| 197 | <select class="viz-filter" name="order"> |
|---|
| 198 | '; |
|---|
| 199 | |
|---|
| 200 | $order_type = array( 'desc' => __( 'Descending', 'visualizer' ), 'asc' => __( 'Ascending', 'visualizer' ) ); |
|---|
| 201 | $order = isset( $_GET['order'] ) ? $_GET['order'] : 'desc'; |
|---|
| 202 | foreach ( $order_type as $field => $label ) { |
|---|
| 203 | echo '<option value="' . esc_attr( $field ) . '" ' . selected( $order, $field ) . '>' . $label . '</option>'; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | echo ' |
|---|
| 207 | </select> |
|---|
| 208 | <input type="submit" class="viz-filter button button-secondary" value="' . __( 'Apply Filters', 'visualizer' ) . '"> |
|---|
| 209 | <input type="button" id="viz-lib-reset" class="viz-filter button button-secondary" value="' . __( 'Clear Filters', 'visualizer' ) . '"> |
|---|
| 210 | </form> |
|---|
| 211 | </div>'; |
|---|
| 212 | } |
|---|
| 213 | /** |
|---|
| 214 | * Renders pro charts blocker. |
|---|
| 215 | * |
|---|
| 216 | * @access private |
|---|
| 217 | */ |
|---|
| 218 | private function _renderProPopupBlocker() { |
|---|
| 219 | if ( Visualizer_Module::is_pro() ) { |
|---|
| 220 | return; |
|---|
| 221 | } |
|---|
| 222 | $license = get_option( 'visualizer_pro_license_data', 'free' ); |
|---|
| 223 | $license_key = ''; |
|---|
| 224 | $download_id = ''; |
|---|
| 225 | if ( ! empty( $license ) && is_object( $license ) ) { |
|---|
| 226 | $license_key = $license->key; |
|---|
| 227 | $download_id = $license->download_id; |
|---|
| 228 | } |
|---|
| 229 | $admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' ); |
|---|
| 230 | $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' ); |
|---|
| 231 | echo ' |
|---|
| 232 | <div class="vizualizer-renew-notice-overlay" id="overlay-visualizer"></div> |
|---|
| 233 | <div class="vizualizer-renew-notice-popup"> |
|---|
| 234 | <h1 class="vizualizer-renew-notice-heading">Alert!</h1> |
|---|
| 235 | <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> |
|---|
| 236 | <div class="vizualizer-renew-notice-buttons-container"> |
|---|
| 237 | <a href="' . esc_url( $renew_license_url) . '" target="_blank"> |
|---|
| 238 | <button class="vizualizer-renew-notice-button vizualizer-renew-notice-renew-button"> |
|---|
| 239 | <span class="dashicons dashicons-cart"></span>' . esc_html__( 'Renew License', 'visualizer' ) . ' |
|---|
| 240 | </button> |
|---|
| 241 | </a> |
|---|
| 242 | <a href="' . esc_url( $admin_license_url ) . '"> |
|---|
| 243 | <button class="vizualizer-renew-notice-button vizualizer-renew-notice-activate-button"> |
|---|
| 244 | <span class="dashicons dashicons-unlock"></span> ' . esc_html__( 'Activate License', 'visualizer' ) . ' |
|---|
| 245 | </button> |
|---|
| 246 | </a> |
|---|
| 247 | <button class="vizualizer-renew-notice-button vizualizer-renew-notice-close-icon" aria-label="Close" onclick="closePopup()"> |
|---|
| 248 | <i class="dashicons dashicons-no"></i> |
|---|
| 249 | </button> |
|---|
| 250 | </div> |
|---|
| 251 | </div> |
|---|
| 252 | <script> |
|---|
| 253 | function closePopup() { |
|---|
| 254 | var overlay = document.getElementById("overlay-visualizer"); |
|---|
| 255 | var popup = document.querySelector(".vizualizer-renew-notice-popup"); |
|---|
| 256 | overlay.style.display = "none"; |
|---|
| 257 | popup.style.display = "none"; |
|---|
| 258 | } |
|---|
| 259 | </script>'; |
|---|
| 260 | |
|---|
| 261 | } |
|---|
| 262 | /** |
|---|
| 263 | * Renders library content. |
|---|
| 264 | * |
|---|
| 265 | * @since 1.0.0 |
|---|
| 266 | * |
|---|
| 267 | * @access private |
|---|
| 268 | */ |
|---|
| 269 | private function _renderLibrary() { |
|---|
| 270 | |
|---|
| 271 | // Added by Ash/Upwork |
|---|
| 272 | $filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|---|
| 273 | |
|---|
| 274 | // Added by Ash/Upwork |
|---|
| 275 | echo $this->custom_css; |
|---|
| 276 | |
|---|
| 277 | $this->_renderProPopupBlocker(); |
|---|
| 278 | |
|---|
| 279 | echo '<div id="visualizer-types" class="visualizer-clearfix">'; |
|---|
| 280 | 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>'; |
|---|
| 281 | $this->getDisplayForm(); |
|---|
| 282 | echo '</div>'; |
|---|
| 283 | echo '<div id="visualizer-content-wrapper">'; |
|---|
| 284 | echo '<div id="tsdk_banner" class="visualizer-banner"></div>'; |
|---|
| 285 | if ( ! empty( $this->charts ) ) { |
|---|
| 286 | echo '<div id="visualizer-library" class="visualizer-clearfix">'; |
|---|
| 287 | $count = 0; |
|---|
| 288 | foreach ( $this->charts as $placeholder_id => $chart ) { |
|---|
| 289 | // show the sidebar after the first 3 charts. |
|---|
| 290 | $count++; |
|---|
| 291 | $enable_controls = false; |
|---|
| 292 | $settings = isset( $chart['settings'] ) ? $chart['settings'] : array(); |
|---|
| 293 | if ( ! empty( $settings['controls']['controlType'] ) ) { |
|---|
| 294 | $column_index = $settings['controls']['filterColumnIndex']; |
|---|
| 295 | $column_label = $settings['controls']['filterColumnLabel']; |
|---|
| 296 | if ( 'false' !== $column_index || 'false' !== $column_label ) { |
|---|
| 297 | $enable_controls = true; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | if ( 3 === $count ) { |
|---|
| 301 | $this->_renderSidebar(); |
|---|
| 302 | $this->_renderChartBox( $placeholder_id, $chart['id'], $enable_controls ); |
|---|
| 303 | } else { |
|---|
| 304 | $this->_renderChartBox( $placeholder_id, $chart['id'], $enable_controls ); |
|---|
| 305 | } |
|---|
| 306 | } |
|---|
| 307 | // show the sidebar if there are less than 3 charts. |
|---|
| 308 | if ( $count < 3 ) { |
|---|
| 309 | $this->_renderSidebar(); |
|---|
| 310 | } |
|---|
| 311 | echo '</div>'; |
|---|
| 312 | } else { |
|---|
| 313 | echo '<div id="visualizer-library" class="visualizer-clearfix">'; |
|---|
| 314 | echo '<div class="items"><div class="visualizer-chart">'; |
|---|
| 315 | echo '<div class="visualizer-chart-canvas visualizer-nochart-canvas">'; |
|---|
| 316 | echo '<div class="visualizer-notfound">', esc_html__( 'No charts found', 'visualizer' ), '<p><h2><a href="javascript:;" class="add-new-h2 add-new-chart">', esc_html__( 'Add New', 'visualizer' ), '</a></h2></p></div>'; |
|---|
| 317 | echo '</div>'; |
|---|
| 318 | echo '<div class="visualizer-chart-footer visualizer-clearfix">'; |
|---|
| 319 | echo '<div class="visualizer-action-group visualizer-nochart">'; |
|---|
| 320 | echo '<span class="visualizer-chart-action visualizer-nochart-delete"><span class="dashicons dashicons-trash"></span></span>'; |
|---|
| 321 | echo '<span class="visualizer-chart-action visualizer-nochart-shortcode"><span class="dashicons dashicons-shortcode"></span></span>'; |
|---|
| 322 | echo '<span class="visualizer-chart-action visualizer-nochart-image"><span class="dashicons dashicons-format-image"></span></span>'; |
|---|
| 323 | echo '<span class="visualizer-chart-action visualizer-nochart-export"><span class="dashicons dashicons-download"></span></span>'; |
|---|
| 324 | echo '<span class="visualizer-chart-action visualizer-nochart-clone"><span class="dashicons dashicons-admin-page"></span></span>'; |
|---|
| 325 | echo '<span class="visualizer-chart-action visualizer-nochart-edit"><span class="dashicons dashicons-admin-generic"></span></span>'; |
|---|
| 326 | echo '</div>'; |
|---|
| 327 | echo '</div>'; |
|---|
| 328 | echo '</div></div>'; |
|---|
| 329 | $this->_renderSidebar(); |
|---|
| 330 | echo '</div>'; |
|---|
| 331 | } |
|---|
| 332 | echo '</div>'; |
|---|
| 333 | if ( is_array( $this->pagination ) ) { |
|---|
| 334 | echo '<ul class=" subsubsub">'; |
|---|
| 335 | foreach ( $this->pagination as $page ) { |
|---|
| 336 | echo '<li class="all">', $page, '</li>'; |
|---|
| 337 | } |
|---|
| 338 | echo '</ul>'; |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | /** |
|---|
| 343 | * Renders chart's box block. |
|---|
| 344 | * |
|---|
| 345 | * @since 1.0.0 |
|---|
| 346 | * |
|---|
| 347 | * @access private |
|---|
| 348 | * |
|---|
| 349 | * @param string $placeholder_id The placeholder's id for the chart. |
|---|
| 350 | * @param int $chart_id The id of the chart. |
|---|
| 351 | */ |
|---|
| 352 | private function _renderChartBox( $placeholder_id, $chart_id, $with_filter = false ) { |
|---|
| 353 | $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS ); |
|---|
| 354 | $title = '#' . $chart_id; |
|---|
| 355 | if ( ! empty( $settings[0]['title'] ) ) { |
|---|
| 356 | $title = $settings[0]['title']; |
|---|
| 357 | } |
|---|
| 358 | // for ChartJS, title is an array. |
|---|
| 359 | if ( is_array( $title ) && isset( $title['text'] ) ) { |
|---|
| 360 | $title = $title['text']; |
|---|
| 361 | } |
|---|
| 362 | if ( ! empty( $settings[0]['backend-title'] ) ) { |
|---|
| 363 | $title = $settings[0]['backend-title']; |
|---|
| 364 | } |
|---|
| 365 | if ( empty( $title ) ) { |
|---|
| 366 | $title = '#' . $chart_id; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | $ajax_url = admin_url( 'admin-ajax.php' ); |
|---|
| 370 | $delete_url = esc_url( |
|---|
| 371 | add_query_arg( |
|---|
| 372 | array( |
|---|
| 373 | 'action' => Visualizer_Plugin::ACTION_DELETE_CHART, |
|---|
| 374 | 'nonce' => wp_create_nonce(), |
|---|
| 375 | 'chart' => $chart_id, |
|---|
| 376 | ), |
|---|
| 377 | $ajax_url |
|---|
| 378 | ) |
|---|
| 379 | ); |
|---|
| 380 | $clone_url = esc_url( |
|---|
| 381 | add_query_arg( |
|---|
| 382 | array( |
|---|
| 383 | 'action' => Visualizer_Plugin::ACTION_CLONE_CHART, |
|---|
| 384 | 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_CLONE_CHART ), |
|---|
| 385 | 'chart' => $chart_id, |
|---|
| 386 | 'type' => $this->type, |
|---|
| 387 | ), |
|---|
| 388 | $ajax_url |
|---|
| 389 | ) |
|---|
| 390 | ); |
|---|
| 391 | $export_link = esc_url( |
|---|
| 392 | add_query_arg( |
|---|
| 393 | array( |
|---|
| 394 | 'action' => Visualizer_Plugin::ACTION_EXPORT_DATA, |
|---|
| 395 | 'chart' => $chart_id, |
|---|
| 396 | 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_EXPORT_DATA . Visualizer_Plugin::VERSION ), |
|---|
| 397 | ), |
|---|
| 398 | admin_url( 'admin-ajax.php' ) |
|---|
| 399 | ) |
|---|
| 400 | ); |
|---|
| 401 | $chart_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); |
|---|
| 402 | |
|---|
| 403 | $types = ['area', 'geo', 'column', 'bubble', 'scatter', 'gauge', 'candlestick', 'timeline', 'combo', 'polarArea', 'radar' ]; |
|---|
| 404 | |
|---|
| 405 | $pro_class = ''; |
|---|
| 406 | |
|---|
| 407 | if ( ! empty( $chart_type ) && in_array( $chart_type, $types, true ) ) { |
|---|
| 408 | $pro_class = 'viz-is-pro-chart'; |
|---|
| 409 | } |
|---|
| 410 | |
|---|
| 411 | $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!' ); |
|---|
| 412 | if ( ! empty( $chart_status['error'] ) ) { |
|---|
| 413 | $chart_status['icon'] = 'error dashicons-dismiss'; |
|---|
| 414 | $chart_status['title'] = __( 'Click to view the error', 'visualizer' ); |
|---|
| 415 | } |
|---|
| 416 | $shortcode = sprintf( '[visualizer id="%s" class=""]', $chart_id ); |
|---|
| 417 | echo '<div class="items"><div class="visualizer-chart"><div class="visualizer-chart-title">', esc_html( $title ), '</div>'; |
|---|
| 418 | if ( Visualizer_Module::is_pro() && $with_filter ) { |
|---|
| 419 | echo '<div id="chart_wrapper_' . $placeholder_id . '">'; |
|---|
| 420 | echo '<div id="control_wrapper_' . $placeholder_id . '" class="vz-library-chart-filter"></div>'; |
|---|
| 421 | } |
|---|
| 422 | echo '<div id="', $placeholder_id, '" class="visualizer-chart-canvas">'; |
|---|
| 423 | echo '<img src="', VISUALIZER_ABSURL, 'images/ajax-loader.gif" class="loader">'; |
|---|
| 424 | echo '</div>'; |
|---|
| 425 | if ( Visualizer_Module::is_pro() && $with_filter ) { |
|---|
| 426 | echo '</div>'; |
|---|
| 427 | } |
|---|
| 428 | echo '<div class="visualizer-chart-footer visualizer-clearfix">'; |
|---|
| 429 | echo '<div class="visualizer-action-group">'; |
|---|
| 430 | 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_attr__( 'Delete', 'visualizer' ) . '</span></a>'; |
|---|
| 431 | 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_attr__( 'Copy Shortcode', 'visualizer' ) . '</span></a>'; |
|---|
| 432 | if ( $this->can_chart_have_action( 'image', $chart_id ) ) { |
|---|
| 433 | echo '<a class="visualizer-chart-action visualizer-chart-image ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="visualizer-', $chart_id, '" data-chart-title="', $title, '"><span class="dashicons dashicons-format-image ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_attr__( 'Download PNG', 'visualizer' ) . '</span></a>'; |
|---|
| 434 | } |
|---|
| 435 | 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_attr__( 'Export CSV', 'visualizer' ) . '</span></a>'; |
|---|
| 436 | 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_attr__( 'Duplicate', 'visualizer' ) . '</span></a>'; |
|---|
| 437 | echo '<a class="visualizer-chart-action visualizer-chart-edit ' . esc_attr( $pro_class ) . '" href="javascript:;" data-chart="', $chart_id, '"><span class="dashicons dashicons-admin-generic ' . esc_attr( $pro_class ) . '"></span><span class="tooltip-text">' . esc_attr__( 'Edit', 'visualizer' ) . '</span></a>'; |
|---|
| 438 | echo '</div>'; |
|---|
| 439 | do_action( 'visualizer_chart_languages', $chart_id ); |
|---|
| 440 | 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>'; |
|---|
| 441 | echo '</div>'; |
|---|
| 442 | echo '</div></div>'; |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | /** |
|---|
| 446 | * Render 2-col sidebar |
|---|
| 447 | */ |
|---|
| 448 | private function _renderSidebar() { |
|---|
| 449 | if ( ! Visualizer_Module::is_pro() ) { |
|---|
| 450 | echo '<div class="items">'; |
|---|
| 451 | echo '<div class="viz-pro">'; |
|---|
| 452 | echo '<div id="visualizer-sidebar" class="one-columns">'; |
|---|
| 453 | echo '<div class="visualizer-sidebar-box">'; |
|---|
| 454 | echo '<h3>' . __( 'Discover the power of PRO!', 'visualizer' ) . '</h3><ul>'; |
|---|
| 455 | if ( Visualizer_Module_Admin::proFeaturesLocked() ) { |
|---|
| 456 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( '6 more chart types', 'visualizer' ); |
|---|
| 457 | } else { |
|---|
| 458 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( '11 more chart types', 'visualizer' ) . '</li>'; |
|---|
| 459 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Synchronize Data Periodically', 'visualizer' ) . '</li>'; |
|---|
| 460 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'ChartJS Charts', 'visualizer' ) . '</li>'; |
|---|
| 461 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Table Google chart', 'visualizer' ) . '</li>'; |
|---|
| 462 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Frontend Actions(Print, Export, Copy, Download)', 'visualizer' ) . '</li>'; |
|---|
| 463 | } |
|---|
| 464 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Spreadsheet like editor', 'visualizer' ) . '</li>'; |
|---|
| 465 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Import from other charts', 'visualizer' ) . '</li>'; |
|---|
| 466 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Use database query to create charts', 'visualizer' ) . '</li>'; |
|---|
| 467 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Create charts from WordPress tables', 'visualizer' ) . '</li>'; |
|---|
| 468 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Frontend editor', 'visualizer' ) . '</li>'; |
|---|
| 469 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Private charts', 'visualizer' ) . '</li>'; |
|---|
| 470 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'WPML support for translating charts', 'visualizer' ) . '</li>'; |
|---|
| 471 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Integration with Woocommerce Data endpoints', 'visualizer' ) . '</li>'; |
|---|
| 472 | echo '<li><svg class="icon list-icon"><use xlink:href="#list-icon"></use></svg>' . __( 'Auto-sync with online files', 'visualizer' ) . '</li></ul>'; |
|---|
| 473 | echo '<p class="vz-sidebar-box-action"><a href="' . tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'sidebarMenuUpgrade', 'index' ) . '#pro-features" target="_blank" class="button button-secondary">' . __( 'View more features', 'visualizer' ) . '</a><a href="' . tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'sidebarMenuUpgrade', 'index' ) . '#pricing" target="_blank" class="button button-primary">' . __( 'Upgrade Now', 'visualizer' ) . '</a></p>'; |
|---|
| 474 | echo '</div>'; |
|---|
| 475 | echo '</div>'; |
|---|
| 476 | echo '</div>'; |
|---|
| 477 | echo '</div>'; |
|---|
| 478 | } |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | } |
|---|