Skip to content

Commit 73b94f1

Browse files
authored
Merge pull request #235 from Codeinwp/development
Fix UTF-8 support while saving the data. Improve editing experience. Improves compatibility with Premium version. Adds chart button into TinyMCE editor.
2 parents e86745f + 71c8825 commit 73b94f1

File tree

12 files changed

+268
-70
lines changed

12 files changed

+268
-70
lines changed

classes/Visualizer/Module.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ private function _getExcel( $rows, $filename ) {
257257
if ( class_exists( 'PHPExcel' ) ) {
258258
$doc = new PHPExcel();
259259
$doc->getActiveSheet()->fromArray( $rows, null, 'A1' );
260-
$doc->getActiveSheet()->setTitle( $chart );
260+
$doc->getActiveSheet()->setTitle( sanitize_title( $chart ) );
261261
$doc = apply_filters( 'visualizer_excel_doc', $doc );
262262
$writer = PHPExcel_IOFactory::createWriter( $doc, 'Excel2007' );
263263
ob_start();

classes/Visualizer/Module/Admin.php

Lines changed: 116 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,59 @@ public function __construct( Visualizer_Plugin $plugin ) {
6161
$this->_addFilter( 'visualizer_logger_data', 'getLoggerData' );
6262
$this->_addFilter( 'visualizer_get_chart_counts', 'getChartCountsByTypeAndMeta' );
6363
$this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' );
64+
65+
$this->_addAction( 'admin_init', 'init' );
66+
}
67+
68+
/**
69+
* Admin init.
70+
*
71+
* @access public
72+
*/
73+
public function init() {
74+
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
75+
$this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
76+
$this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
77+
$this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
78+
}
79+
}
80+
81+
/**
82+
* Load plugin translation for - TinyMCE API
83+
*
84+
* @access public
85+
* @param array $arr The tinymce_lang array.
86+
* @return array
87+
*/
88+
public function add_tinymce_lang( $arr ) {
89+
$ui_lang = VISUALIZER_ABSPATH . '/classes/Visualizer/Module/Language.php';
90+
$ui_lang = apply_filters( 'visualizer_ui_lang_filter', $ui_lang );
91+
$arr[] = $ui_lang;
92+
return $arr;
93+
}
94+
95+
/**
96+
* Load custom js options - TinyMCE API
97+
*
98+
* @access public
99+
* @param array $plugin_array The tinymce plugin array.
100+
* @return array
101+
*/
102+
public function tinymce_plugin( $plugin_array ) {
103+
$plugin_array['visualizer_mce_button'] = VISUALIZER_ABSURL . 'js/mce.js';
104+
return $plugin_array;
105+
}
106+
107+
/**
108+
* Register new button in the editor
109+
*
110+
* @access public
111+
* @param array $buttons The tinymce buttons array.
112+
* @return array
113+
*/
114+
public function register_mce_button( $buttons ) {
115+
array_push( $buttons, 'visualizer_mce_button' );
116+
return $buttons;
64117
}
65118

66119
/**
@@ -121,6 +174,7 @@ public function enqueueMediaScripts() {
121174
* @return array The extended array of media view strings.
122175
*/
123176
public function setupMediaViewStrings( $strings ) {
177+
$chart_types = self::_getChartTypesLocalized( true, true, true );
124178
$strings['visualizer'] = array(
125179
'actions' => array(
126180
'get_charts' => Visualizer_Plugin::ACTION_GET_CHARTS,
@@ -134,8 +188,8 @@ public function setupMediaViewStrings( $strings ) {
134188
'create' => esc_html__( 'Create New', 'visualizer' ),
135189
),
136190
'library' => array(
137-
'filters' => self::_getChartTypesLocalized( true, true ),
138-
'types' => array_keys( self::_getChartTypesLocalized( true, true ) ),
191+
'filters' => $chart_types,
192+
'types' => array_keys( $chart_types ),
139193
),
140194
'nonce' => wp_create_nonce(),
141195
'buildurl' => add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ),
@@ -153,57 +207,67 @@ public function setupMediaViewStrings( $strings ) {
153207
* @access private
154208
* @return array The associated array of chart types with localized names.
155209
*/
156-
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false ) {
157-
$types = array(
158-
'pie' => array(
159-
'name' => esc_html__( 'Pie', 'visualizer' ),
160-
'enabled' => true,
161-
),
162-
'line' => array(
163-
'name' => esc_html__( 'Line', 'visualizer' ),
164-
'enabled' => true,
165-
),
166-
'area' => array(
167-
'name' => esc_html__( 'Area', 'visualizer' ),
168-
'enabled' => true,
169-
),
170-
'geo' => array(
171-
'name' => esc_html__( 'Geo', 'visualizer' ),
172-
'enabled' => true,
173-
),
174-
'bar' => array(
175-
'name' => esc_html__( 'Bar', 'visualizer' ),
176-
'enabled' => true,
177-
),
178-
'column' => array(
179-
'name' => esc_html__( 'Column', 'visualizer' ),
180-
'enabled' => true,
181-
),
182-
'gauge' => array(
183-
'name' => esc_html__( 'Gauge', 'visualizer' ),
184-
'enabled' => true,
185-
),
186-
'scatter' => array(
187-
'name' => esc_html__( 'Scatter', 'visualizer' ),
210+
public static function _getChartTypesLocalized( $enabledOnly = false, $get2Darray = false, $add_select = false ) {
211+
$additional = array();
212+
if ( $add_select ) {
213+
$additional['select'] = array(
214+
'name' => esc_html__( 'All', 'visualizer' ),
188215
'enabled' => true,
189-
),
190-
'candlestick' => array(
191-
'name' => esc_html__( 'Candlestick', 'visualizer' ),
192-
'enabled' => true,
193-
),
194-
// pro types
195-
'table' => array(
196-
'name' => esc_html__( 'Table', 'visualizer' ),
197-
'enabled' => false,
198-
),
199-
'timeline' => array(
200-
'name' => esc_html__( 'Timeline', 'visualizer' ),
201-
'enabled' => false,
202-
),
203-
'combo' => array(
204-
'name' => esc_html__( 'Combo', 'visualizer' ),
205-
'enabled' => false,
206-
),
216+
);
217+
}
218+
219+
$types = array_merge(
220+
$additional, array(
221+
'pie' => array(
222+
'name' => esc_html__( 'Pie', 'visualizer' ),
223+
'enabled' => true,
224+
),
225+
'line' => array(
226+
'name' => esc_html__( 'Line', 'visualizer' ),
227+
'enabled' => true,
228+
),
229+
'area' => array(
230+
'name' => esc_html__( 'Area', 'visualizer' ),
231+
'enabled' => true,
232+
),
233+
'geo' => array(
234+
'name' => esc_html__( 'Geo', 'visualizer' ),
235+
'enabled' => true,
236+
),
237+
'bar' => array(
238+
'name' => esc_html__( 'Bar', 'visualizer' ),
239+
'enabled' => true,
240+
),
241+
'column' => array(
242+
'name' => esc_html__( 'Column', 'visualizer' ),
243+
'enabled' => true,
244+
),
245+
'gauge' => array(
246+
'name' => esc_html__( 'Gauge', 'visualizer' ),
247+
'enabled' => true,
248+
),
249+
'scatter' => array(
250+
'name' => esc_html__( 'Scatter', 'visualizer' ),
251+
'enabled' => true,
252+
),
253+
'candlestick' => array(
254+
'name' => esc_html__( 'Candlestick', 'visualizer' ),
255+
'enabled' => true,
256+
),
257+
// pro types
258+
'table' => array(
259+
'name' => esc_html__( 'Table', 'visualizer' ),
260+
'enabled' => false,
261+
),
262+
'timeline' => array(
263+
'name' => esc_html__( 'Timeline', 'visualizer' ),
264+
'enabled' => false,
265+
),
266+
'combo' => array(
267+
'name' => esc_html__( 'Combo', 'visualizer' ),
268+
'enabled' => false,
269+
),
270+
)
207271
);
208272
$types = apply_filters( 'visualizer_pro_chart_types', $types );
209273
if ( $enabledOnly ) {

classes/Visualizer/Module/Chart.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public function getCharts() {
8383
),
8484
);
8585
$filter = filter_input( INPUT_GET, 's', FILTER_SANITIZE_STRING );
86+
if ( empty( $filter ) ) {
87+
// 'filter' is from the modal from the add media button.
88+
$filter = filter_input( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
89+
}
90+
8691
if ( $filter && in_array( $filter, Visualizer_Plugin::getChartTypes() ) ) {
8792
$query_args['meta_query'] = array(
8893
array(
@@ -262,9 +267,14 @@ public function renderChartPages() {
262267
// dispatch pages
263268
$this->_chart = get_post( $chart_id );
264269
$tab = isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ? $_GET['tab'] : 'visualizer';
270+
271+
// skip chart type pages only for existing charts.
272+
if ( VISUALIZER_SKIP_CHART_TYPE_PAGE && 'auto-draft' !== $this->_chart->post_status ) {
273+
$tab = 'settings';
274+
}
275+
265276
switch ( $tab ) {
266277
case 'settings':
267-
// changed by Ash/Upwork
268278
$this->_handleDataAndSettingsPage();
269279
break;
270280
case 'type': // fall through.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* The Language function file for tinymce.
4+
*
5+
* @link http://themeisle.com
6+
* @since 3.0.0
7+
*/
8+
/**
9+
*
10+
* SECURITY : Exit if accessed directly
11+
*/
12+
if ( ! defined( 'ABSPATH' ) ) {
13+
die( 'Direct access not allowed!' );
14+
}
15+
16+
/**
17+
*
18+
* Translation for TinyMCE
19+
*/
20+
21+
if ( ! class_exists( '_WP_Editors' ) ) {
22+
require( ABSPATH . WPINC . '/class-wp-editor.php' );
23+
}
24+
25+
/**
26+
* The module for all languages stuff.
27+
*
28+
* @category Visualizer
29+
* @package Module
30+
*
31+
* @since 1.0.0
32+
*/
33+
class Visualizer_Module_Language extends Visualizer_Module {
34+
35+
/**
36+
* The strings for translation.
37+
*
38+
* @access protected
39+
* @var array $strings The ID of this plugin.
40+
*/
41+
protected $strings;
42+
43+
/**
44+
* Initialize the class and set its properties.
45+
*
46+
* @since 3.0.0
47+
* @access public
48+
*/
49+
public function __construct() {
50+
$this->strings = array(
51+
'plugin_label' => __( 'Insert Chart', 'visualizer' ),
52+
'plugin_title' => __( 'Insert Chart', 'visualizer' ),
53+
);
54+
}
55+
56+
/**
57+
*
58+
* The method that returns the translation array
59+
*
60+
* @access public
61+
* @return string
62+
*/
63+
public function tinymce_translation() {
64+
65+
$locale = _WP_Editors::$mce_locale;
66+
$translated = 'tinyMCE.addI18n("' . $locale . '.visualizer_tinymce_plugin", ' . json_encode( $this->strings ) . ");\n";
67+
68+
return $translated;
69+
}
70+
71+
}
72+
73+
$visualizerLangClass = new Visualizer_Module_Language();
74+
$strings = $visualizerLangClass->tinymce_translation();

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Visualizer_Plugin {
2929

3030
const NAME = 'visualizer';
31-
const VERSION = '3.0.5';
31+
const VERSION = '3.0.6';
3232

3333
// custom post types
3434
const CPT_VISUALIZER = 'visualizer';

classes/Visualizer/Render/Page/Data.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class="visualizer-select">
159159
</li>
160160
</ul>
161161
</li>
162-
<li class="viz-group <?php echo apply_filters( 'visualizer_pro_upsell_class', '' ); ?> ">
162+
<li class="viz-group <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
163163
<h2 class="viz-group-title viz-sub-group"
164164
data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
165165
class="dashicons dashicons-lock"></span></h2>
@@ -216,9 +216,13 @@ class="dashicons dashicons-lock"></span></h2>
216216
</div>
217217
</li>
218218

219-
<li class="viz-group <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
219+
<?php
220+
// we will auto-open the manual data feature but only when pro is active.
221+
$pro_class = apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' );
222+
?>
223+
<li class="viz-group <?php echo $pro_class; ?> <?php echo empty( $pro_class ) ? 'open' : ''; ?> ">
220224
<h2 class="viz-group-title viz-sub-group visualizer-editor-tab"
221-
data-current="chart"><?php _e( 'Add data manually', 'visualizer' ); ?><span
225+
data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?><span
222226
class="dashicons dashicons-lock"></span></h2>
223227
<form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
224228
<input type="hidden" id="chart-data" name="chart_data">
@@ -401,15 +405,16 @@ class="dashicons dashicons-lock"></span>', '', apply_filters( 'visualizer_pro_up
401405
* @access protected
402406
*/
403407
protected function _renderToolbar() {
404-
// changed by Ash/Upwork
405-
echo '<div class="toolbar-div">';
406-
echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">';
407-
esc_html_e( 'Back', 'visualizer' );
408-
echo '</a>';
409-
echo '</div>';
408+
// don't show back button at all.
409+
// 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.
410+
if ( ! VISUALIZER_SKIP_CHART_TYPE_PAGE ) {
411+
echo '<div class="toolbar-div">';
412+
echo '<a class="button button-large" href="', add_query_arg( 'tab', 'types' ), '">';
413+
esc_html_e( 'Back', 'visualizer' );
414+
echo '</a>';
415+
echo '</div>';
416+
}
410417
echo '<input type="submit" id="settings-button" class="button button-primary button-large push-right" value="', $this->button, '">';
411-
echo '</div>';
412-
413418
}
414419

415420
}

classes/Visualizer/Source.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ protected function _normalizeData( $data ) {
221221
);
222222
}
223223
break;
224+
case 'string':
225+
$data[ $i ] = utf8_encode( $data[ $i ] );
226+
break;
224227
}
225228
}
226229

css/media.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Version: 3.0.5
2+
Version: 3.0.6
33
*/
44
#visualizer-library-view {
55
padding: 30px 10px 10px 30px;
@@ -162,3 +162,13 @@ a.visualizer-library-pagination-page:hover {
162162
z-index: 1001;
163163
background: url(../images/ajax-loader.gif) no-repeat center center;
164164
}
165+
166+
167+
/* TinyMCE button */
168+
i.mce-i-visualizer-icon:before {
169+
content: "\f184";
170+
display: inline-block;
171+
-webkit-font-smoothing: antialiased;
172+
font: 400 20px/1 dashicons;
173+
vertical-align: top;
174+
}

0 commit comments

Comments
 (0)