| 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 chart data setup page. |
| 23 |
* |
| 24 |
* @category Visualizer |
| 25 |
* @package Render |
| 26 |
* @subpackage Page |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
*/ |
| 30 |
class Visualizer_Render_Page_Data extends Visualizer_Render_Page { |
| 31 |
|
| 32 |
/** |
| 33 |
* Renders page content. |
| 34 |
* |
| 35 |
* @since 1.0.0 |
| 36 |
* |
| 37 |
* @access protected |
| 38 |
*/ |
| 39 |
protected function _renderContent() { |
| 40 |
// Added by Ash/Upwork |
| 41 |
if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { |
| 42 |
Visualizer_Render_Layout::show( 'simple-editor-screen', $this->chart->ID ); |
| 43 |
} |
| 44 |
|
| 45 |
if ( Visualizer_Module::is_pro() ) { |
| 46 |
do_action( 'visualizer_add_editor_etc', $this->chart->ID ); |
| 47 |
|
| 48 |
if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) { |
| 49 |
global $Visualizer_Pro; |
| 50 |
$Visualizer_Pro->_addEditor( $this->chart->ID ); |
| 51 |
if ( method_exists( $Visualizer_Pro, '_addFilterWizard' ) ) { |
| 52 |
$Visualizer_Pro->_addFilterWizard( $this->chart->ID ); |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
$this->add_additional_content(); |
| 58 |
|
| 59 |
// Added by Ash/Upwork |
| 60 |
echo '<div id="canvas">'; |
| 61 |
echo '<img src="', VISUALIZER_ABSURL, 'images/ajax-loader.gif" class="loader">'; |
| 62 |
echo '</div>'; |
| 63 |
echo $this->custom_css; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Renders sidebar content. |
| 68 |
* |
| 69 |
* @since 1.0.0 |
| 70 |
* |
| 71 |
* @access protected |
| 72 |
*/ |
| 73 |
protected function _renderSidebarContent() { |
| 74 |
$upload_link = add_query_arg( |
| 75 |
array( |
| 76 |
'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA, |
| 77 |
'nonce' => wp_create_nonce(), |
| 78 |
'chart' => $this->chart->ID, |
| 79 |
), |
| 80 |
admin_url( 'admin-ajax.php' ) |
| 81 |
); |
| 82 |
|
| 83 |
// this will allow us to open the correct source tab by default. |
| 84 |
$source_of_chart = strtolower( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_SOURCE, true ) ); |
| 85 |
// both import from wp and import from db have the same source so we need to differentiate. |
| 86 |
$filter_config = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_FILTER_CONFIG, true ); |
| 87 |
// if filter config is present, then its import from wp. |
| 88 |
if ( ! empty( $filter_config ) ) { |
| 89 |
$source_of_chart .= '_wp'; |
| 90 |
} |
| 91 |
$editor_type = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_EDITOR, true ); |
| 92 |
if ( $editor_type ) { |
| 93 |
$source_of_chart = 'visualizer_source_manual'; |
| 94 |
} |
| 95 |
|
| 96 |
$type = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ); |
| 97 |
$lib = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true ); |
| 98 |
?> |
| 99 |
<span id="visualizer-chart-id" data-id="<?php echo $this->chart->ID; ?>" data-chart-source="<?php echo esc_attr( $source_of_chart ); ?>" data-chart-type="<?php echo esc_attr( $type ); ?>" data-chart-lib="<?php echo esc_attr( $lib ); ?>"></span> |
| 100 |
<iframe id="thehole" name="thehole"></iframe> |
| 101 |
<ul class="viz-group-wrapper full-height"> |
| 102 |
<li class="viz-group viz-group-category open" id="vz-chart-source"> |
| 103 |
<div class="viz-group-header"> |
| 104 |
<h2 class="viz-group-title viz-main-group"><?php _e( 'Chart Data', 'visualizer' ); ?></h2> |
| 105 |
</div> |
| 106 |
<ul class="viz-group-content"> |
| 107 |
<ul class="viz-group-wrapper"> |
| 108 |
<!-- import from file --> |
| 109 |
<li class="viz-group visualizer_source_csv"> |
| 110 |
<h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2> |
| 111 |
<div class="viz-group-content"> |
| 112 |
<p class="viz-group-description"><?php esc_html_e( 'Select and upload your data CSV file here. The first row of the CSV file should contain the column headings. The second one should contain series type (string, number, boolean, date, datetime, timeofday).', 'visualizer' ); ?></p> |
| 113 |
<p class="viz-group-description viz-info-msg"><b><?php echo sprintf( __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %1$s %2$s%3$s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $this->type . '.csv" target="_blank">', $this->type, '.csv</a>' ); ?></b></p> |
| 114 |
<form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post" |
| 115 |
target="thehole" enctype="multipart/form-data"> |
| 116 |
<input type="hidden" id="remote-data" name="remote_data"> |
| 117 |
<div class=""> |
| 118 |
<input type="file" id="csv-file" name="local_data"> |
| 119 |
</div> |
| 120 |
<input type="button" class="button button-primary" id="vz-import-file" |
| 121 |
value="<?php _e( 'Import', 'visualizer' ); ?>"> |
| 122 |
</form> |
| 123 |
</div> |
| 124 |
</li> |
| 125 |
<!-- import from url --> |
| 126 |
<li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json"> |
| 127 |
<h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2> |
| 128 |
<ul class="viz-group-content"> |
| 129 |
<!-- import from csv url --> |
| 130 |
<li class="viz-subsection"> |
| 131 |
<span class="viz-section-title"><?php _e( 'Import from CSV', 'visualizer' ); ?></span> |
| 132 |
<div class="viz-section-items section-items"> |
| 133 |
<p class="viz-group-description"><?php echo sprintf( __( 'You can use this to import data from a remote CSV file or %1$sGoogle Spreadsheet%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >', '</a>' ); ?> </p> |
| 134 |
<p class="viz-group-description viz-info-msg"><b><?php echo sprintf( __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %1$s %2$s%3$s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $this->type . '.csv" target="_blank">', $this->type, '.csv</a>' ); ?></b></p> |
| 135 |
<form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post" |
| 136 |
target="thehole" enctype="multipart/form-data"> |
| 137 |
<div class="remote-file-section"> |
| 138 |
<input type="url" id="vz-schedule-url" name="remote_data" value="<?php echo esc_attr( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_URL, true ) ); ?>" placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>" class="visualizer-input visualizer-remote-url"> |
| 139 |
</div> |
| 140 |
<select name="vz-import-time" id="vz-import-time" class="visualizer-select"> |
| 141 |
<?php |
| 142 |
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_CHART_SCHEDULE, true ); |
| 143 |
$schedules = apply_filters( |
| 144 |
'visualizer_chart_schedules', array( |
| 145 |
'-1' => __( 'One-time', 'visualizer' ), |
| 146 |
), |
| 147 |
'csv', |
| 148 |
$this->chart->ID |
| 149 |
); |
| 150 |
foreach ( $schedules as $num => $name ) { |
| 151 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 152 |
$extra = $num == $hours ? 'selected' : ''; |
| 153 |
?> |
| 154 |
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option> |
| 155 |
<?php |
| 156 |
} |
| 157 |
do_action( 'visualizer_chart_schedules_spl', 'csv', $this->chart->ID, 1 ); |
| 158 |
?> |
| 159 |
</select> |
| 160 |
|
| 161 |
<input type="button" id="view-remote-file" class="button <?php echo Visualizer_Module::is_pro() ? 'button-secondary' : 'button-primary'; ?>" value="<?php _e( 'Import', 'visualizer' ); ?>"> |
| 162 |
<?php |
| 163 |
if ( Visualizer_Module::is_pro() ) { |
| 164 |
?> |
| 165 |
<input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Save schedule', 'visualizer' ); ?>"> |
| 166 |
<?php |
| 167 |
} |
| 168 |
?> |
| 169 |
</form> |
| 170 |
</div> |
| 171 |
</li> |
| 172 |
<!-- import from json url --> |
| 173 |
<li class="viz-subsection"> |
| 174 |
<span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?> |
| 175 |
<span class="dashicons dashicons-lock"></span></span> |
| 176 |
<div class="viz-section-items section-items"> |
| 177 |
<p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a remote JSON source. For more info check <a href="https://docs.themeisle.com/article/1052-how-to-generate-charts-from-json-data-rest-endpoints" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p> |
| 178 |
<form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data"> |
| 179 |
<div class="remote-file-section"> |
| 180 |
<?php |
| 181 |
$bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' ); |
| 182 |
if ( Visualizer_Module::is_pro() ) { |
| 183 |
?> |
| 184 |
<p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p> |
| 185 |
<select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $this->chart->ID; ?>"> |
| 186 |
<?php |
| 187 |
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_JSON_SCHEDULE, true ); |
| 188 |
$schedules = apply_filters( |
| 189 |
'visualizer_chart_schedules', array( |
| 190 |
'-1' => __( 'One-time', 'visualizer' ), |
| 191 |
), |
| 192 |
'json', |
| 193 |
$this->chart->ID |
| 194 |
); |
| 195 |
foreach ( $schedules as $num => $name ) { |
| 196 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 197 |
$extra = $num == $hours ? 'selected' : ''; |
| 198 |
?> |
| 199 |
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option> |
| 200 |
<?php |
| 201 |
} |
| 202 |
do_action( 'visualizer_chart_schedules_spl', 'json', $this->chart->ID, 1 ); |
| 203 |
?> |
| 204 |
</select> |
| 205 |
<?php |
| 206 |
} |
| 207 |
?> |
| 208 |
</div> |
| 209 |
|
| 210 |
<input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle" |
| 211 |
value="<?php echo $bttn_label; ?>" data-current="chart" |
| 212 |
data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" |
| 213 |
data-t-chart="<?php echo $bttn_label; ?>"> |
| 214 |
<?php |
| 215 |
if ( Visualizer_Module::is_pro() ) { |
| 216 |
?> |
| 217 |
<input type="button" id="json-chart-save-button" class="button button-primary " |
| 218 |
value="<?php _e( 'Save Schedule', 'visualizer' ); ?>"> |
| 219 |
<?php |
| 220 |
} |
| 221 |
?> |
| 222 |
</form> |
| 223 |
</div> |
| 224 |
</li> |
| 225 |
</ul> |
| 226 |
</li> |
| 227 |
<!-- import from chart --> |
| 228 |
<li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>"> |
| 229 |
<li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>"> |
| 230 |
<h2 class="viz-group-title viz-sub-group" |
| 231 |
data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span |
| 232 |
class="dashicons dashicons-lock"></span></h2> |
| 233 |
<div class="viz-group-content edit-data-content"> |
| 234 |
<div> |
| 235 |
<p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p> |
| 236 |
<form> |
| 237 |
<select name="vz-import-from-chart" id="chart-id" class="visualizer-select"> |
| 238 |
<?php |
| 239 |
$fetch_link = add_query_arg( |
| 240 |
array( |
| 241 |
'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '', |
| 242 |
'nonce' => wp_create_nonce(), |
| 243 |
), |
| 244 |
admin_url( 'admin-ajax.php' ) |
| 245 |
); |
| 246 |
$query_args_charts = array( |
| 247 |
'post_type' => Visualizer_Plugin::CPT_VISUALIZER, |
| 248 |
'posts_per_page' => 300, |
| 249 |
'no_found_rows' => true, |
| 250 |
); |
| 251 |
$charts = array(); |
| 252 |
$query = new WP_Query( $query_args_charts ); |
| 253 |
while ( $query->have_posts() ) { |
| 254 |
$chart = $query->next_post(); |
| 255 |
$settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); |
| 256 |
|
| 257 |
$title = '#' . $chart->ID; |
| 258 |
if ( ! empty( $settings['title'] ) ) { |
| 259 |
$title = $settings['title']; |
| 260 |
} |
| 261 |
// for ChartJS, title is an array. |
| 262 |
if ( is_array( $title ) && isset( $title['text'] ) ) { |
| 263 |
$title = $title['text']; |
| 264 |
} |
| 265 |
if ( empty( $title ) ) { |
| 266 |
$title = '#' . $chart->ID; |
| 267 |
} |
| 268 |
|
| 269 |
?> |
| 270 |
<option value="<?php echo $chart->ID; ?>"><?php echo $title; ?></option> |
| 271 |
<?php |
| 272 |
} |
| 273 |
?> |
| 274 |
|
| 275 |
</select> |
| 276 |
</form> |
| 277 |
<input type="button" id="existing-chart" class="button button-primary" |
| 278 |
value="<?php _e( 'Import Chart', 'visualizer' ); ?>" |
| 279 |
data-viz-link="<?php echo $fetch_link; ?>"> |
| 280 |
<?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?> |
| 281 |
</div> |
| 282 |
</div> |
| 283 |
</li> |
| 284 |
|
| 285 |
<?php |
| 286 |
$save_filter = add_query_arg( |
| 287 |
array( |
| 288 |
'action' => Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY, |
| 289 |
'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION ), |
| 290 |
'chart' => $this->chart->ID, |
| 291 |
), admin_url( 'admin-ajax.php' ) |
| 292 |
); |
| 293 |
?> |
| 294 |
<!-- import from WordPress --> |
| 295 |
<li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ); ?> "> |
| 296 |
<h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span |
| 297 |
class="dashicons dashicons-lock"></span></h2> |
| 298 |
<div class="viz-group-content edit-data-content"> |
| 299 |
<div> |
| 300 |
<p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p> |
| 301 |
<form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole"> |
| 302 |
<p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p> |
| 303 |
<select name="refresh" id="vz-filter-import-time" class="visualizer-select"> |
| 304 |
<?php |
| 305 |
$bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' ); |
| 306 |
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_SCHEDULE, true ); |
| 307 |
$schedules = apply_filters( |
| 308 |
'visualizer_chart_schedules', array( |
| 309 |
'-1' => __( 'One-time', 'visualizer' ), |
| 310 |
), |
| 311 |
'wp', |
| 312 |
$this->chart->ID |
| 313 |
); |
| 314 |
foreach ( $schedules as $num => $name ) { |
| 315 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 316 |
$extra = $num == $hours ? 'selected' : ''; |
| 317 |
?> |
| 318 |
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option> |
| 319 |
<?php |
| 320 |
} |
| 321 |
do_action( 'visualizer_chart_schedules_spl', 'wp', $this->chart->ID, 1 ); |
| 322 |
?> |
| 323 |
</select> |
| 324 |
|
| 325 |
<input type="button" id="filter-chart-button" class="button button-secondary show-chart-toggle" value="<?php echo $bttn_label; ?>" data-current="chart" data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo $bttn_label; ?>"> |
| 326 |
<input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>"> |
| 327 |
<?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?> |
| 328 |
</form> |
| 329 |
<?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?> |
| 330 |
</div> |
| 331 |
</div> |
| 332 |
</li> |
| 333 |
|
| 334 |
<?php |
| 335 |
$save_query = add_query_arg( |
| 336 |
array( |
| 337 |
'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY, |
| 338 |
'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION ), |
| 339 |
'chart' => $this->chart->ID, |
| 340 |
), admin_url( 'admin-ajax.php' ) |
| 341 |
); |
| 342 |
?> |
| 343 |
<!-- import from db --> |
| 344 |
<li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>"> |
| 345 |
<h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span |
| 346 |
class="dashicons dashicons-lock"></span></h2> |
| 347 |
<div class="viz-group-content edit-data-content"> |
| 348 |
<div> |
| 349 |
<p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p> |
| 350 |
<form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole"> |
| 351 |
<p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p> |
| 352 |
<select name="refresh" id="vz-db-import-time" class="visualizer-select"> |
| 353 |
<?php |
| 354 |
$bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' ); |
| 355 |
$hours = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_SCHEDULE, true ); |
| 356 |
$schedules = apply_filters( |
| 357 |
'visualizer_chart_schedules', array( |
| 358 |
'-1' => __( 'One-time', 'visualizer' ), |
| 359 |
), |
| 360 |
'db', |
| 361 |
$this->chart->ID |
| 362 |
); |
| 363 |
foreach ( $schedules as $num => $name ) { |
| 364 |
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
| 365 |
$extra = $num == $hours ? 'selected' : ''; |
| 366 |
?> |
| 367 |
<option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option> |
| 368 |
<?php |
| 369 |
} |
| 370 |
do_action( 'visualizer_chart_schedules_spl', 'db', $this->chart->ID, 1 ); |
| 371 |
?> |
| 372 |
</select> |
| 373 |
<input type="hidden" name="params" id="viz-db-wizard-params"> |
| 374 |
|
| 375 |
<input type="button" id="db-chart-button" class="button button-secondary show-chart-toggle" value="<?php echo $bttn_label; ?>" data-current="chart" data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo $bttn_label; ?>"> |
| 376 |
<input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>"> |
| 377 |
<?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?> |
| 378 |
</form> |
| 379 |
</div> |
| 380 |
</div> |
| 381 |
</li> |
| 382 |
|
| 383 |
<!-- manual --> |
| 384 |
<li class="viz-group visualizer_source_manual"> |
| 385 |
<h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?> |
| 386 |
<span class="dashicons dashicons-lock"></span> |
| 387 |
</h2> |
| 388 |
<div class="viz-group-content edit-data-content"> |
| 389 |
<form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole"> |
| 390 |
<input type="hidden" id="chart-data" name="chart_data"> |
| 391 |
<input type="hidden" id="chart-data-src" name="chart_data_src"> |
| 392 |
|
| 393 |
<?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?> |
| 394 |
<div> |
| 395 |
<p class="viz-group-description viz-editor-selection"> |
| 396 |
<?php _e( 'Use the', 'visualizer' ); ?> |
| 397 |
<select name="editor-type" id="viz-editor-type"> |
| 398 |
<?php |
| 399 |
if ( empty( $editor_type ) ) { |
| 400 |
$editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text'; |
| 401 |
} |
| 402 |
foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) { |
| 403 |
?> |
| 404 |
<option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option> |
| 405 |
<?php } ?> |
| 406 |
</select> |
| 407 |
<?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?> |
| 408 |
</p> |
| 409 |
<input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>"> |
| 410 |
<input type="button" id="editor-button" class="button button-primary " |
| 411 |
value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart" |
| 412 |
data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>" |
| 413 |
data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>" |
| 414 |
> |
| 415 |
<p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p> |
| 416 |
</div> |
| 417 |
<?php } else { ?> |
| 418 |
<input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>"> |
| 419 |
<input type="button" id="editor-chart-button" class="button button-primary " |
| 420 |
value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart" |
| 421 |
data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>" |
| 422 |
data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>" |
| 423 |
> |
| 424 |
<p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p> |
| 425 |
<?php } ?> |
| 426 |
</form> |
| 427 |
</div> |
| 428 |
</li> |
| 429 |
</ul> |
| 430 |
</li> |
| 431 |
</ul> |
| 432 |
<li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-settings"> |
| 433 |
<h2><span class="dashicons dashicons-admin-tools"></span><?php _e( 'Advanced', 'visualizer' ); ?></h2> |
| 434 |
<div class="viz-group-header"> |
| 435 |
<button class="customize-section-back" tabindex="0"></button> |
| 436 |
<h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3> |
| 437 |
</div> |
| 438 |
<ul class="viz-group-content"> |
| 439 |
<form id="settings-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" |
| 440 |
method="post"> |
| 441 |
<?php echo $this->sidebar; ?> |
| 442 |
<input type="hidden" name="save" value="1"> |
| 443 |
</form> |
| 444 |
<form id="cancel-form" action="<?php echo add_query_arg( 'nonce', wp_create_nonce() ); ?>" method="post"> |
| 445 |
<input type="hidden" name="cancel" value="1"> |
| 446 |
</form> |
| 447 |
</ul> |
| 448 |
</li> |
| 449 |
|
| 450 |
<li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-docs"> |
| 451 |
<h2><span class="dashicons dashicons-editor-help"></span><a href="<?php echo VISUALIZER_MAIN_DOC; ?>" target="_blank"><?php _e( 'Docs', 'visualizer' ); ?></a></h2> |
| 452 |
</li> |
| 453 |
|
| 454 |
<?php $this->getPermissionsLink( $this->chart->ID ); ?> |
| 455 |
|
| 456 |
<li class="viz-group bottom-fixed" id="vz-chart-copyright">Visualizer © |
| 457 |
<?php |
| 458 |
// phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date, WordPress.DateTime.CurrentTimeTimestamp.Requested |
| 459 |
echo date( 'Y', current_time( 'timestamp' ) ); |
| 460 |
?> |
| 461 |
</li> |
| 462 |
</ul> |
| 463 |
<?php |
| 464 |
// changed by Ash/Upwork |
| 465 |
} |
| 466 |
|
| 467 |
/** |
| 468 |
* Generates the permissions link. |
| 469 |
* |
| 470 |
* @access private |
| 471 |
* @param int $id The chart id. |
| 472 |
*/ |
| 473 |
private function getPermissionsLink( $id ) { |
| 474 |
$permissions = apply_filters( 'visualizer_pro_get_permissions', null, $id ); |
| 475 |
if ( $permissions ) { |
| 476 |
foreach ( $permissions as $k => $v ) { |
| 477 |
$this->$k = $v; |
| 478 |
} |
| 479 |
} |
| 480 |
?> |
| 481 |
<li class="viz-group viz-group-category bottom-fixed sidebar-footer-link" id="vz-chart-permissions"> |
| 482 |
<h2><span class="dashicons dashicons-admin-users"></span><?php _e( 'Permissions', 'visualizer' ); ?></h2> |
| 483 |
<div class="viz-group-header"> |
| 484 |
<button class="customize-section-back" tabindex="0"></button> |
| 485 |
<h3 class="viz-group-title viz-main-group"><?php _e( 'Chart Settings', 'visualizer' ); ?></h3> |
| 486 |
</div> |
| 487 |
<ul class="viz-group-content"> |
| 488 |
<form id="permissions-form" target="thehole" action=" |
| 489 |
<?php |
| 490 |
echo add_query_arg( |
| 491 |
array( |
| 492 |
'nonce' => wp_create_nonce(), |
| 493 |
'tab' => 'permissions', |
| 494 |
), |
| 495 |
remove_query_arg( 'tab', $_SERVER['REQUEST_URI'] ) |
| 496 |
); |
| 497 |
?> |
| 498 |
" method="post"> |
| 499 |
<?php $this->permissionsSidebar(); ?> |
| 500 |
</form> |
| 501 |
</ul> |
| 502 |
</li> |
| 503 |
<?php |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Generates the permissions form. |
| 508 |
* |
| 509 |
* @access private |
| 510 |
*/ |
| 511 |
private function permissionsSidebar() { |
| 512 |
// ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect". |
| 513 |
if ( defined( 'WP_TESTS_DOMAIN' ) ) { |
| 514 |
return; |
| 515 |
} |
| 516 |
Visualizer_Render_Sidebar::_renderGroupStart( |
| 517 |
esc_html__( 'Who can see this chart?', 'visualizer' ) . '<span |
| 518 |
class="dashicons dashicons-lock"></span>', |
| 519 |
'', |
| 520 |
'viz-chart-perm-view ' . apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ) |
| 521 |
); |
| 522 |
Visualizer_Render_Sidebar::_renderSectionStart(); |
| 523 |
Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can view the chart on the front-end.', 'visualizer' ) ); |
| 524 |
|
| 525 |
if ( ! isset( $this->permissions['read'] ) ) { |
| 526 |
$this->permissions['read'] = 'all'; |
| 527 |
} |
| 528 |
|
| 529 |
Visualizer_Render_Sidebar::_renderSelectItem( |
| 530 |
'', |
| 531 |
'permissions[read]', |
| 532 |
$this->permissions['read'], |
| 533 |
array( |
| 534 |
'all' => esc_html__( 'All Users', 'visualizer' ), |
| 535 |
'users' => esc_html__( 'Select Users', 'visualizer' ), |
| 536 |
'roles' => esc_html__( 'Select Roles', 'visualizer' ), |
| 537 |
), |
| 538 |
'', |
| 539 |
false, |
| 540 |
array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-read' ), |
| 541 |
array( |
| 542 |
'permission-type' => 'read', |
| 543 |
) |
| 544 |
); |
| 545 |
|
| 546 |
$options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['read'] ) ? $this->permissions['read'] : 'roles' ); |
| 547 |
|
| 548 |
Visualizer_Render_Sidebar::_renderSelectItem( |
| 549 |
'', |
| 550 |
'permissions[read-specific][]', |
| 551 |
isset( $this->permissions['read-specific'] ) ? $this->permissions['read-specific'] : array(), |
| 552 |
$options, |
| 553 |
'', |
| 554 |
true, |
| 555 |
array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-read-specific' ) |
| 556 |
); |
| 557 |
Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) ); |
| 558 |
Visualizer_Render_Sidebar::_renderGroupEnd(); |
| 559 |
|
| 560 |
Visualizer_Render_Sidebar::_renderGroupStart( |
| 561 |
esc_html__( 'Who can edit this chart?', 'visualizer' ) . '<span |
| 562 |
class="dashicons dashicons-lock"></span>', |
| 563 |
'', |
| 564 |
'viz-chart-perm-edit ' . apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ) |
| 565 |
); |
| 566 |
Visualizer_Render_Sidebar::_renderSectionStart(); |
| 567 |
Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Select who can edit the chart on the front-end.', 'visualizer' ) ); |
| 568 |
|
| 569 |
if ( ! isset( $this->permissions['edit'] ) ) { |
| 570 |
$this->permissions['edit'] = 'roles'; |
| 571 |
$this->permissions['edit-specific'] = 'administrator'; |
| 572 |
} |
| 573 |
|
| 574 |
Visualizer_Render_Sidebar::_renderSelectItem( |
| 575 |
'', |
| 576 |
'permissions[edit]', |
| 577 |
$this->permissions['edit'], |
| 578 |
array( |
| 579 |
'all' => esc_html__( 'All Users', 'visualizer' ), |
| 580 |
'users' => esc_html__( 'Select Users', 'visualizer' ), |
| 581 |
'roles' => esc_html__( 'Select Roles', 'visualizer' ), |
| 582 |
), |
| 583 |
'', |
| 584 |
false, |
| 585 |
array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-edit' ), |
| 586 |
array( |
| 587 |
'permission-type' => 'edit', |
| 588 |
) |
| 589 |
); |
| 590 |
|
| 591 |
$options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $this->permissions['edit'] ) ? $this->permissions['edit'] : 'roles' ); |
| 592 |
|
| 593 |
Visualizer_Render_Sidebar::_renderSelectItem( |
| 594 |
'', |
| 595 |
'permissions[edit-specific][]', |
| 596 |
isset( $this->permissions['edit-specific'] ) ? $this->permissions['edit-specific'] : array(), |
| 597 |
$options, |
| 598 |
'', |
| 599 |
true, |
| 600 |
array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' ) |
| 601 |
); |
| 602 |
Visualizer_Render_Sidebar::_renderSectionEnd( apply_filters( 'visualizer_pro_upsell', 'only-pro-feature', 'chart-permissions' ) ); |
| 603 |
Visualizer_Render_Sidebar::_renderGroupEnd(); |
| 604 |
|
| 605 |
} |
| 606 |
|
| 607 |
/** |
| 608 |
* Renders toolbar content. |
| 609 |
* |
| 610 |
* @since 1.0.0 |
| 611 |
* |
| 612 |
* @access protected |
| 613 |
*/ |
| 614 |
protected function _renderToolbar() { |
| 615 |
// don't show back button at all. |
| 616 |
// NOTE: We can't be selective on the post_status here because when a new chart reaches the settings screen, its status changes to publish. |
| 617 |
if ( ! VISUALIZER_SKIP_CHART_TYPE_PAGE ) { |
| 618 |
echo '<div class="toolbar-div">'; |
| 619 |
echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">'; |
| 620 |
esc_html_e( 'Back', 'visualizer' ); |
| 621 |
echo '</a>'; |
| 622 |
echo '</div>'; |
| 623 |
} |
| 624 |
echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">'; |
| 625 |
if ( isset( $this->cancel_button ) ) { |
| 626 |
echo '<input type="submit" id="cancel-button" class="button button-secondary button-large push-right" value="', $this->cancel_button, '">'; |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
/** |
| 631 |
* Renders the additional content. |
| 632 |
* |
| 633 |
* @access private |
| 634 |
*/ |
| 635 |
private function add_additional_content() { |
| 636 |
$source = strtolower( get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_SOURCE, true ) ); |
| 637 |
$query = ''; |
| 638 |
if ( 'visualizer_source_query' === $source ) { |
| 639 |
$query = get_post_meta( $this->chart->ID, Visualizer_Plugin::CF_DB_QUERY, true ); |
| 640 |
} |
| 641 |
Visualizer_Render_Layout::show( 'db-query', $query, $this->chart->ID ); |
| 642 |
Visualizer_Render_Layout::show( 'json-screen', $this->chart->ID ); |
| 643 |
} |
| 644 |
|
| 645 |
} |
| 646 |
|