Skip to content

Commit 2e3f0dd

Browse files
authored
Release
2 parents dc8dc62 + d4d3409 commit 2e3f0dd

File tree

6 files changed

+232
-53
lines changed

6 files changed

+232
-53
lines changed

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: 5 additions & 0 deletions
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(
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();

css/media.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

js/mce.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* global tinymce */
2+
/* jshint unused:false */
3+
(function($) {
4+
tinymce.PluginManager.add('visualizer_mce_button', function( editor, url ) {
5+
editor.addButton( 'visualizer_mce_button', {
6+
title: editor.getLang( 'visualizer_tinymce_plugin.plugin_label' ),
7+
label: editor.getLang( 'visualizer_tinymce_plugin.plugin_label' ),
8+
icon: 'visualizer-icon',
9+
onclick: function() {
10+
$('#insert-media-button').trigger('click');
11+
}
12+
});
13+
});
14+
15+
})(jQuery);

js/media/view.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,18 @@
5959
settings.height = self.options.height;
6060

6161
table = new gv.DataTable({cols: series});
62-
chart = type === 'gauge' ? 'Gauge' : type.charAt(0).toUpperCase() + type.slice(1) + 'Chart';
62+
63+
switch (type) {
64+
case "gauge":
65+
case "table":
66+
case "timeline":
67+
chart = type.charAt(0).toUpperCase() + type.slice(1);
68+
break;
69+
default:
70+
chart = type.charAt(0).toUpperCase() + type.slice(1) + 'Chart';
71+
break;
72+
}
73+
6374
chart = new gv[chart](self.el);
6475

6576
switch (type) {

0 commit comments

Comments
 (0)