| @@ -91,8 +91,16 @@ | ||
| 91 | 91 | */ |
| 92 | 92 | protected $_supportsAnimation = true; |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | + * Which library does this this chart implement? | |
| 96 | + * | |
| 97 | + * @access protected | |
| 98 | + * @var string | |
| 99 | + */ | |
| 100 | + protected $_library = null; | |
| 101 | + | |
| 102 | + /** | |
| 95 | 103 | * Constructor. |
| 96 | 104 | * |
| 97 | 105 | * @since 1.0.0 |
| 98 | 106 | * |
| @@ -123,8 +131,10 @@ | ||
| 123 | 131 | '' => '', |
| 124 | 132 | '1' => esc_html__( 'Yes', 'visualizer' ), |
| 125 | 133 | '0' => esc_html__( 'No', 'visualizer' ), |
| 126 | 134 | ); |
| 135 | + | |
| 136 | + $this->hooks(); | |
| 127 | 137 | } |
| 128 | 138 | |
| 129 | 139 | /** |
| 130 | 140 | * Renders chart title settings. |
| @@ -164,9 +174,9 @@ | ||
| 164 | 174 | self::_renderGroupEnd(); |
| 165 | 175 | |
| 166 | 176 | self::_renderGroupStart( esc_html__( 'Manual Configuration', 'visualizer' ) ); |
| 167 | 177 | self::_renderSectionStart(); |
| 168 | - self::_renderSectionDescription( __( 'Configure the graph by providing configuration variables right from the', 'visualizer' ) . ' <a href="https://developers.google.com/chart/interactive/docs/reference" target="_blank">Google Visualization</a> API.' ); | |
| 178 | + self::_renderSectionDescription( '<span class="viz-gvlink">' . sprintf( __( 'Configure the graph by providing configuration variables right from the %1$sGoogle Visualization API%2$s. You can refer to to some examples %3$shere%4$s.', 'visualizer' ), '<a href="https://developers.google.com/chart/interactive/docs/gallery/?#configuration-options" target="_blank">', '</a>', '<a href="https://docs.themeisle.com/article/728-manual-configuration" target="_blank">', '</a>' ) . '</span>' ); | |
| 169 | 179 | |
| 170 | 180 | $example = ' |
| 171 | 181 | { |
| 172 | 182 | "vAxis": { |
| @@ -182,9 +192,10 @@ | ||
| 182 | 192 | esc_html__( 'Configuration', 'visualizer' ), |
| 183 | 193 | 'manual', |
| 184 | 194 | $this->manual, |
| 185 | 195 | sprintf( |
| 186 | - esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), '<br><code>' . $example . '</code>' | |
| 196 | + esc_html__( 'One per line in valid JSON (key:value) format e.g. %s', 'visualizer' ), | |
| 197 | + '<br><code>' . $example . '</code>' | |
| 187 | 198 | ), |
| 188 | 199 | '', |
| 189 | 200 | array( 'rows' => 5 ) |
| 190 | 201 | ); |
| @@ -205,27 +216,27 @@ | ||
| 205 | 216 | self::_renderSectionStart( esc_html__( 'Actions', 'visualizer' ), false ); |
| 206 | 217 | self::_renderCheckboxItem( |
| 207 | 218 | esc_html__( 'Print', 'visualizer' ), |
| 208 | 219 | 'actions[]', |
| 209 | - isset( $this->actions ) && in_array( 'print', $this->actions ) ? true : false, | |
| 220 | + isset( $this->actions ) && in_array( 'print', $this->actions, true ) ? true : false, | |
| 210 | 221 | 'print', |
| 211 | - $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable printing the data.', 'visualizer' ), | |
| 222 | + $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable printing the chart/data.', 'visualizer' ), | |
| 212 | 223 | $disable_actions |
| 213 | 224 | ); |
| 214 | 225 | self::_renderCheckboxItem( |
| 215 | 226 | esc_html__( 'CSV', 'visualizer' ), |
| 216 | 227 | 'actions[]', |
| 217 | - isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions ) ? true : false, | |
| 228 | + isset( $this->actions ) && in_array( 'csv;application/csv', $this->actions, true ) ? true : false, | |
| 218 | 229 | 'csv;application/csv', |
| 219 | 230 | $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as a CSV.', 'visualizer' ), |
| 220 | 231 | $disable_actions |
| 221 | 232 | ); |
| 222 | 233 | |
| 223 | - $disabled = ! ( class_exists( 'PHPExcel' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && version_compare( PHP_VERSION, '5.2.0', '>' ) ); | |
| 234 | + $disabled = ! self::is_excel_enabled(); | |
| 224 | 235 | self::_renderCheckboxItem( |
| 225 | 236 | esc_html__( 'Excel', 'visualizer' ), |
| 226 | 237 | 'actions[]', |
| 227 | - isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions ) ? true : false, | |
| 238 | + isset( $this->actions ) && in_array( 'xls;application/vnd.ms-excel', $this->actions, true ) ? true : false, | |
| 228 | 239 | 'xls;application/vnd.ms-excel', |
| 229 | 240 | $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : ( $disabled ? '<span class="viz-section-error">' . esc_html__( 'Enable the ZIP and XML extensions to use this setting.', 'visualizer' ) . '</span>' : esc_html__( 'To enable downloading the data as an Excel spreadsheet.', 'visualizer' ) ), |
| 230 | 241 | $disable_actions || $disabled |
| 231 | 242 | ); |
| @@ -231,9 +242,9 @@ | ||
| 231 | 242 | ); |
| 232 | 243 | self::_renderCheckboxItem( |
| 233 | 244 | esc_html__( 'Copy', 'visualizer' ), |
| 234 | 245 | 'actions[]', |
| 235 | - isset( $this->actions ) && in_array( 'copy', $this->actions ) ? true : false, | |
| 246 | + isset( $this->actions ) && in_array( 'copy', $this->actions, true ) ? true : false, | |
| 236 | 247 | 'copy', |
| 237 | 248 | $disable_actions ? '<span class="viz-section-error">' . esc_html__( 'Upgrade to at least WordPress 4.7 to use this.', 'visualizer' ) . '</span>' : esc_html__( 'To enable copying the data to the clipboard.', 'visualizer' ), |
| 238 | 249 | $disable_actions |
| 239 | 250 | ); |
| @@ -240,8 +251,20 @@ | ||
| 240 | 251 | self::_renderSectionEnd(); |
| 241 | 252 | } |
| 242 | 253 | |
| 243 | 254 | /** |
| 255 | + * Checks if the Excel module can be enabled. | |
| 256 | + */ | |
| 257 | + private static function is_excel_enabled() { | |
| 258 | + $vendor_file = VISUALIZER_ABSPATH . '/vendor/autoload.php'; | |
| 259 | + if ( is_readable( $vendor_file ) ) { | |
| 260 | + include_once( $vendor_file ); | |
| 261 | + } | |
| 262 | + | |
| 263 | + return class_exists( 'PhpOffice\PhpSpreadsheet\Spreadsheet' ) && extension_loaded( 'zip' ) && extension_loaded( 'xml' ) && extension_loaded( 'fileinfo' ) && version_compare( PHP_VERSION, '5.6.0', '>' ); | |
| 264 | + } | |
| 265 | + | |
| 266 | + /** | |
| 244 | 267 | * Renders chart general settings group. |
| 245 | 268 | * |
| 246 | 269 | * @since 1.0.0 |
| 247 | 270 | * |
| @@ -339,9 +362,9 @@ | ||
| 339 | 362 | |
| 340 | 363 | self::_renderCheckboxItem( |
| 341 | 364 | esc_html__( 'Animate on startup', 'visualizer' ), |
| 342 | 365 | 'animation[startup]', |
| 343 | - $this->animation['startup'], | |
| 366 | + isset( $this->animation['startup'] ) ? $this->animation['startup'] : 0, | |
| 344 | 367 | true, |
| 345 | 368 | esc_html__( 'Determines if the chart will animate on the initial draw.', 'visualizer' ) |
| 346 | 369 | ); |
| 347 | 370 | |
| @@ -541,9 +564,9 @@ | ||
| 541 | 564 | echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 542 | 565 | echo '<b>', $title, '</b>'; |
| 543 | 566 | echo '<select class="control-select ', implode( ' ', $classes ) , '" name="', $name, '" ', ( $multiple ? 'multiple' : '' ), ' ' , $atts, '>'; |
| 544 | 567 | foreach ( $options as $key => $label ) { |
| 545 | - $extra = $multiple && is_array( $value ) ? ( in_array( $key, $value ) ? 'selected' : '' ) : selected( $key, $value, false ); | |
| 568 | + $extra = $multiple && is_array( $value ) ? ( in_array( $key, $value, true ) ? 'selected' : '' ) : selected( $key, $value, false ); | |
| 546 | 569 | echo '<option value="', $key, '"', $extra, '>'; |
| 547 | 570 | echo $label; |
| 548 | 571 | echo '</option>'; |
| 549 | 572 | } |
| @@ -724,9 +747,9 @@ | ||
| 724 | 747 | protected static function _renderCheckboxItem( $title, $name, $value, $default, $desc, $disabled = false ) { |
| 725 | 748 | echo '<div class="viz-section-item">'; |
| 726 | 749 | echo '<a class="more-info" href="javascript:;">[?]</a>'; |
| 727 | 750 | echo '<b>', $title, '</b>'; |
| 728 | - echo '<input type="checkbox" class="control-check" value="', $default, '" name="', $name, '" ', ( $value == $default ? 'checked' : '' ), ' ', ( $disabled ? 'disabled=disabled' : '' ), '>'; | |
| 751 | + echo '<input type="checkbox" class="control-check" value="', $default, '" name="', $name, '" ', ( $value === $default ? 'checked' : '' ), ' ', ( $disabled ? 'disabled=disabled' : '' ), '>'; | |
| 729 | 752 | echo '<p class="viz-section-description">', $desc, '</p>'; |
| 730 | 753 | echo '</div>'; |
| 731 | 754 | } |
| 732 | 755 | |
| @@ -745,7 +768,14 @@ | ||
| 745 | 768 | echo '<b>', $title, '</b>'; |
| 746 | 769 | echo '<textarea class="control-text" ', $attributes, ' name="', $name, '" placeholder="', $placeholder, '">', $value, '</textarea>'; |
| 747 | 770 | echo '<p class="viz-section-description">', $desc, '</p>'; |
| 748 | 771 | echo '</div>'; |
| 772 | + } | |
| 773 | + | |
| 774 | + /** | |
| 775 | + * Returns the library this chart implements. | |
| 776 | + */ | |
| 777 | + public function getLibrary() { | |
| 778 | + return $this->_library; | |
| 749 | 779 | } |
| 750 | 780 | |
| 751 | 781 | } |