PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 6.0.0
WP Popular Posts v6.0.0
7.4.1 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Block / Widget / edit.js
wordpress-popular-posts / src / Block / Widget Last commit date
Widget.php 4 years ago edit.js 4 years ago editor.css 4 years ago widget.js 4 years ago
edit.js
756 lines
1 import { escape_html, unescape_html } from '../utils';
2
3 const { serverSideRender: ServerSideRender } = wp;
4 const { Component, Fragment } = wp.element;
5 const { BlockControls } = wp.blockEditor;
6 const { CheckboxControl, Disabled, SelectControl, Spinner, TextareaControl, TextControl, Toolbar, ToolbarButton } = wp.components;
7 const { __ } = wp.i18n;
8 const endpoint = 'wordpress-popular-posts/v1';
9
10 export class WPPWidgetBlockEdit extends Component
11 {
12 constructor(props)
13 {
14 super(props);
15
16 this.state = {
17 error: null,
18 editMode: true,
19 themes: null,
20 imgSizes: null,
21 taxonomies: null
22 }
23 }
24
25 componentDidMount()
26 {
27 const { attributes } = this.props;
28
29 this.getThemes();
30 this.getImageSizes();
31 this.getTaxonomies();
32
33 this.setState({ editMode: attributes._editMode });
34 }
35
36 getThemes()
37 {
38 wp.apiFetch({ path: endpoint + '/themes' })
39 .then(
40 ( themes ) => {
41 this.setState({
42 themes
43 });
44 },
45 ( error ) => {
46 this.setState({
47 error,
48 themes: null
49 });
50 }
51 );
52 }
53
54 getImageSizes()
55 {
56 wp.apiFetch({ path: endpoint + '/thumbnails' })
57 .then(
58 ( imgSizes ) => {
59 this.setState({
60 imgSizes
61 });
62 },
63 ( error ) => {
64 this.setState({
65 error,
66 imgSizes: null
67 });
68 }
69 );
70 }
71
72 getTaxonomies()
73 {
74 const { attributes } = this.props;
75
76 wp.apiFetch({ path: endpoint + '/taxonomies' })
77 .then(
78 ( taxonomies ) => {
79 if ( taxonomies ) {
80 let tax = attributes.tax.split(';'),
81 term_id = attributes.term_id.split(';');
82
83 if ( tax.length && tax.length == term_id.length ) {
84 let selected_taxonomies = {};
85
86 for( var t = 0; t < tax.length; t++ ) {
87 selected_taxonomies[tax[t]] = term_id[t];
88 }
89
90 for( const tax in taxonomies ) {
91 taxonomies[tax]._terms = 'undefined' != typeof selected_taxonomies[tax] ? selected_taxonomies[tax] : '';
92 }
93 }
94 }
95
96 this.setState({
97 taxonomies
98 });
99 },
100 ( error ) => {
101 this.setState({
102 error,
103 taxonomies: null
104 });
105 }
106 );
107 }
108
109 getBlockControls()
110 {
111 const { setAttributes } = this.props;
112 const _self = this;
113
114 function onPreviewChange()
115 {
116 let editMode = ! _self.state.editMode;
117 _self.setState({ editMode: editMode });
118 setAttributes({ _editMode: editMode });
119 }
120
121 return (
122 <BlockControls>
123 <Toolbar label="{ __('Settings') }">
124 <ToolbarButton
125 label={ this.state.editMode ? __('Preview', 'wordpress-popular-posts') : __('Edit', 'wordpress-popular-posts') }
126 icon={ this.state.editMode ? "format-image" : "edit" }
127 onClick={onPreviewChange}
128 />
129 </Toolbar>
130 </BlockControls>
131 );
132 }
133
134 getMainFields()
135 {
136 const { attributes, setAttributes } = this.props;
137
138 function onTitleChange(value)
139 {
140 value = escape_html(unescape_html(value));
141 setAttributes({ title: value });
142 }
143
144 function onLimitChange(value)
145 {
146 let limit = Number.isInteger(Number(value)) && Number(value) > 0 ? value : 10;
147 setAttributes({ limit: Number(limit) });
148 }
149
150 function onOrderByChange(value)
151 {
152 setAttributes({ order_by: value });
153 }
154
155 function onTimeRangeChange(value)
156 {
157 setAttributes({ range: value });
158 }
159
160 function onTimeQuantityChange(value) {
161 let qty = Number.isInteger(Number(value)) && Number(value) > 0 ? value : 24;
162 setAttributes({ time_quantity: Number(qty) });
163 }
164
165 function onTimeUnitChange(value) {
166 setAttributes({ time_unit: value });
167 }
168
169 function onFreshnessChange(value)
170 {
171 setAttributes({ freshness: value });
172 }
173
174 return <Fragment>
175 <TextControl
176 label={__('Title', 'wordpress-popular-posts')}
177 value={attributes.title}
178 onChange={onTitleChange}
179 />
180 <TextControl
181 label={__('Limit', 'wordpress-popular-posts')}
182 value={attributes.limit}
183 onChange={onLimitChange}
184 />
185 <SelectControl
186 label={__('Sort posts by', 'wordpress-popular-posts')}
187 value={attributes.order_by}
188 options={[
189 {label: __('Total views', 'wordpress-popular-posts'), value: 'views'},
190 {label: __('Avg. daily views', 'wordpress-popular-posts'), value: 'avg'},
191 {label: __('Comments', 'wordpress-popular-posts'), value: 'comments'}
192 ]}
193 onChange={onOrderByChange}
194 />
195 <SelectControl
196 label={__('Time Range', 'wordpress-popular-posts')}
197 value={attributes.range}
198 options={[
199 {label: __('Last 24 Hours', 'wordpress-popular-posts'), value: 'last24hours'},
200 {label: __('Last 7 days', 'wordpress-popular-posts'), value: 'last7days'},
201 {label: __('Last 30 days', 'wordpress-popular-posts'), value: 'last30days'},
202 {label: __('All-time', 'wordpress-popular-posts'), value: 'all'},
203 {label: __('Custom', 'wordpress-popular-posts'), value: 'custom'},
204 ]}
205 onChange={onTimeRangeChange}
206 />
207 { 'custom' == attributes.range &&
208 <div className='option-subset'>
209 <TextControl
210 label={__('Time Quantity', 'wordpress-popular-posts')}
211 value={attributes.time_quantity}
212 onChange={onTimeQuantityChange}
213 />
214 <SelectControl
215 label={__('Time Unit', 'wordpress-popular-posts')}
216 value={attributes.time_unit}
217 options={[
218 {label: __('Minute(s)', 'wordpress-popular-posts'), value: 'minute'},
219 {label: __('Hour(s)', 'wordpress-popular-posts'), value: 'hour'},
220 {label: __('Day(s)', 'wordpress-popular-posts'), value: 'day'}
221 ]}
222 onChange={onTimeUnitChange}
223 />
224 </div>
225 }
226 <CheckboxControl
227 label={__('Display only posts published within the selected Time Range', 'wordpress-popular-posts')}
228 checked={attributes.freshness}
229 onChange={onFreshnessChange}
230 />
231 </Fragment>;
232 }
233
234 getFiltersFields()
235 {
236 const { attributes, setAttributes } = this.props;
237 const _self = this;
238
239 function onPostTypeChange(value)
240 {
241 let new_value = value.replace(/[^a-z0-9-_\,]+/gi, '');
242 setAttributes({ post_type: new_value });
243 }
244
245 function onPostIDExcludeChange(value)
246 {
247 let new_value = value.replace(/[^0-9\,]/g, '');
248 setAttributes({ pid: new_value });
249 }
250
251 function onAuthorChange(value)
252 {
253 let new_value = value.replace(/[^0-9\,]/g, '');
254 setAttributes({ author: new_value });
255 }
256
257 function onTaxChange(taxonomy_name, terms)
258 {
259 let taxonomies = _self.state.taxonomies;
260
261 terms = terms.replace(/[^0-9-\,]/g, '');
262
263 if ( taxonomies && 'undefined' != typeof taxonomies[taxonomy_name] ) {
264 taxonomies[taxonomy_name]._terms = terms;
265 _self.setState({ taxonomies: taxonomies });
266 }
267 }
268
269 function onTaxBlur(taxonomy_name)
270 {
271 let taxonomies = _self.state.taxonomies;
272
273 if ( taxonomies && 'undefined' != typeof taxonomies[taxonomy_name] ) {
274 let terms_arr = taxonomies[taxonomy_name]._terms.split(',');
275
276 // Remove invalid values
277 if ( terms_arr.length )
278 terms_arr = terms_arr.map((term) => term.trim())
279 .filter((term) => '' != term && '-' != term);
280
281 // Remove duplicates
282 if ( terms_arr.length )
283 terms_arr = Array.from(new Set(terms_arr));
284
285 taxonomies[taxonomy_name]._terms = terms_arr.join(',');
286
287 _self.setState({ taxonomies });
288
289 let tax = '',
290 term_id = '';
291
292 for ( let key in _self.state.taxonomies ) {
293 if ( _self.state.taxonomies.hasOwnProperty(key) ) {
294
295 if ( ! _self.state.taxonomies[key]._terms.length )
296 continue;
297
298 tax += key + ';';
299 term_id += _self.state.taxonomies[key]._terms + ';';
300 }
301 }
302
303 // Remove trailing semicolon
304 if ( tax && term_id ) {
305 tax = tax.replace(new RegExp(';$'), '');
306 term_id = term_id.replace(new RegExp(';$'), '');
307 }
308
309 setAttributes({ tax: tax, term_id: term_id });
310 }
311 }
312
313 let taxonomies = [];
314
315 if ( this.state.taxonomies ) {
316 for( const tax in this.state.taxonomies ) {
317 taxonomies.push(
318 {
319 name: this.state.taxonomies[tax].name,
320 label: this.state.taxonomies[tax].labels.singular_name + ' (' + this.state.taxonomies[tax].name + ')',
321 terms: this.state.taxonomies[tax]._terms
322 }
323 );
324 }
325 }
326
327 return <Fragment>
328 <p className='not-a-legend'><strong>{__('Filters', 'wordpress-popular-posts')}</strong></p>
329 <TextControl
330 label={__('Post type(s)', 'wordpress-popular-posts')}
331 help={__('Post types must be comma separated.', 'wordpress-popular-posts')}
332 value={attributes.post_type}
333 onChange={onPostTypeChange}
334 />
335 <TextControl
336 label={__('Post ID(s) to exclude', 'wordpress-popular-posts')}
337 help={__('IDs must be comma separated.', 'wordpress-popular-posts')}
338 value={attributes.pid}
339 onChange={onPostIDExcludeChange}
340 />
341 <TextControl
342 label={__('Author ID(s)', 'wordpress-popular-posts')}
343 help={__('IDs must be comma separated.', 'wordpress-popular-posts')}
344 value={attributes.author}
345 onChange={onAuthorChange}
346 />
347 { taxonomies && taxonomies.filter((tax) => 'post_format' != tax.name).map((tax) =>
348 {
349 return (
350 <TextControl
351 label={tax.label}
352 help={__('Term IDs must be comma separated, prefix a minus sign to exclude.', 'wordpress-popular-posts')}
353 value={tax.terms}
354 onChange={(terms) => onTaxChange(tax.name, terms)}
355 onBlur={() => onTaxBlur(tax.name)}
356 />
357 );
358 }
359 )}
360 </Fragment>;
361 }
362
363 getPostSettingsFields()
364 {
365 const { attributes, setAttributes } = this.props;
366 const _self = this;
367
368 function onShortenTitleChange(value) {
369 if ( false == value )
370 setAttributes({ title_length: 0, title_by_words: 0, shorten_title: value });
371 else
372 setAttributes({ shorten_title: value, title_length: 25 });
373 }
374
375 function onTitleLengthChange(value)
376 {
377 let length = Number.isInteger(Number(value)) && Number(value) >= 0 ? value : 0;
378 setAttributes({ title_length: Number(length) });
379 }
380
381 function onDisplayExcerptChange(value) {
382 if ( false == value )
383 setAttributes({ excerpt_length: 0, excerpt_by_words: 0, display_post_excerpt: value });
384 else
385 setAttributes({ display_post_excerpt: value, excerpt_length: 55 });
386 }
387
388 function onExcerptLengthChange(value)
389 {
390 let length = Number.isInteger(Number(value)) && Number(value) >= 0 ? value : 0;
391 setAttributes({ excerpt_length: Number(length) });
392 }
393
394 function onDisplayThumbnailChange(value) {
395 if ( false == value )
396 setAttributes({ thumbnail_width: 0, thumbnail_height: 0, display_post_thumbnail: value });
397 else
398 setAttributes({ thumbnail_width: 75, thumbnail_height: 75, display_post_thumbnail: value });
399 }
400
401 function onThumbnailDimChange(dim, value)
402 {
403 let width = Number.isInteger(Number(value)) && Number(value) >= 0 ? value : 0;
404 setAttributes(( 'width' == dim ? { thumbnail_width: Number(width) } : { thumbnail_height: Number(width) } ));
405 }
406
407 function onThumbnailBuildChange(value)
408 {
409 if ( 'predefined' == value ) {
410 let fallback = 0;
411
412 setAttributes({
413 thumbnail_width: _self.state.imgSizes[sizes[fallback].value].width,
414 thumbnail_height: _self.state.imgSizes[sizes[fallback].value].height,
415 thumbnail_size: sizes[fallback].value
416 });
417 }
418 setAttributes({ thumbnail_build: value });
419 }
420
421 function onThumbnailSizeChange(value) {
422 setAttributes({
423 thumbnail_width: _self.state.imgSizes[value].width,
424 thumbnail_height: _self.state.imgSizes[value].height,
425 thumbnail_size: value
426 });
427 }
428
429 let sizes = [];
430
431 if ( this.state.imgSizes ) {
432 for( const size in this.state.imgSizes ) {
433 sizes.push(
434 {
435 label: size,
436 value: size
437 },
438 );
439 }
440 }
441
442 return <Fragment>
443 <p className='not-a-legend'><strong>{__('Posts settings', 'wordpress-popular-posts')}</strong></p>
444 <CheckboxControl
445 label={__('Shorten title', 'wordpress-popular-posts')}
446 checked={attributes.shorten_title}
447 onChange={onShortenTitleChange}
448 />
449 { attributes.shorten_title &&
450 <div className='option-subset'>
451 <TextControl
452 label={__('Shorten title to', 'wordpress-popular-posts')}
453 value={attributes.title_length}
454 onChange={onTitleLengthChange}
455 />
456 <SelectControl
457 value={attributes.title_by_words}
458 options={[
459 { label: __('characters', 'wordpress-popular-posts'), value: 0 },
460 { label: __('words', 'wordpress-popular-posts'), value: 1 },
461 ]}
462 onChange={(value) => setAttributes({ title_by_words: Number(value) })}
463 />
464 </div>
465 }
466 <CheckboxControl
467 label={__('Display post excerpt', 'wordpress-popular-posts')}
468 checked={attributes.display_post_excerpt}
469 onChange={onDisplayExcerptChange}
470 />
471 { attributes.display_post_excerpt &&
472 <div className='option-subset'>
473 <CheckboxControl
474 label={__('Keep text format and links', 'wordpress-popular-posts')}
475 checked={attributes.excerpt_format}
476 onChange={(value) => setAttributes({ excerpt_format: value })}
477 />
478 <TextControl
479 label={__('Excerpt length', 'wordpress-popular-posts')}
480 value={attributes.excerpt_length}
481 onChange={onExcerptLengthChange}
482 />
483 <SelectControl
484 value={attributes.excerpt_by_words}
485 options={[
486 { label: __('characters', 'wordpress-popular-posts'), value: 0 },
487 { label: __('words', 'wordpress-popular-posts'), value: 1 },
488 ]}
489 onChange={(value) => setAttributes({ excerpt_by_words: Number(value) })}
490 />
491 </div>
492 }
493 <CheckboxControl
494 label={__('Display post thumbnail', 'wordpress-popular-posts')}
495 checked={attributes.display_post_thumbnail}
496 onChange={onDisplayThumbnailChange}
497 />
498 { attributes.display_post_thumbnail &&
499 <div className='option-subset'>
500 <SelectControl
501 value={attributes.thumbnail_build}
502 options={[
503 { label: __('Set size manually', 'wordpress-popular-posts'), value: 'manual' },
504 { label: __('Use predefined size', 'wordpress-popular-posts'), value: 'predefined' },
505 ]}
506 onChange={onThumbnailBuildChange}
507 />
508 { 'manual' == attributes.thumbnail_build &&
509 <Fragment>
510 <TextControl
511 label={__('Thumbnail width', 'wordpress-popular-posts')}
512 help={__('Size in px units (pixels)', 'wordpress-popular-posts')}
513 value={attributes.thumbnail_width}
514 onChange={(value) => onThumbnailDimChange('width', value)}
515 />
516 <TextControl
517 label={__('Thumbnail height', 'wordpress-popular-posts')}
518 help={__('Size in px units (pixels)', 'wordpress-popular-posts')}
519 value={attributes.thumbnail_height}
520 onChange={(value) => onThumbnailDimChange('height', value)}
521 />
522 </Fragment>
523 }
524 { 'predefined' == attributes.thumbnail_build &&
525 <Fragment>
526 <SelectControl
527 value={attributes.thumbnail_size}
528 options={sizes}
529 onChange={onThumbnailSizeChange}
530 />
531 </Fragment>
532 }
533 </div>
534 }
535 </Fragment>;
536 }
537
538 getStatsTagFields()
539 {
540 const { attributes, setAttributes } = this.props;
541
542 let taxonomies = [];
543
544 if ( this.state.taxonomies ) {
545 for( const tax in this.state.taxonomies ) {
546 taxonomies.push(
547 {
548 label: this.state.taxonomies[tax].labels.singular_name + ' (' + this.state.taxonomies[tax].name + ')',
549 value: this.state.taxonomies[tax].name
550 },
551 );
552 }
553 }
554
555 return <Fragment>
556 <p className='not-a-legend'><strong>{__('Stats Tag settings', 'wordpress-popular-posts')}</strong></p>
557 <CheckboxControl
558 label={__('Display comments count', 'wordpress-popular-posts')}
559 checked={attributes.stats_comments}
560 onChange={(value) => setAttributes({ stats_comments: value })}
561 />
562 <CheckboxControl
563 label={__('Display views', 'wordpress-popular-posts')}
564 checked={attributes.stats_views}
565 onChange={(value) => setAttributes({ stats_views: value })}
566 />
567 <CheckboxControl
568 label={__('Display author', 'wordpress-popular-posts')}
569 checked={attributes.stats_author}
570 onChange={(value) => setAttributes({ stats_author: value })}
571 />
572 <CheckboxControl
573 label={__('Display date', 'wordpress-popular-posts')}
574 checked={attributes.stats_date}
575 onChange={(value) => setAttributes({ stats_date: value })}
576 />
577 { attributes.stats_date &&
578 <div className='option-subset'>
579 <SelectControl
580 label={__('Date Format', 'wordpress-popular-posts')}
581 value={attributes.stats_date_format}
582 options={[
583 { label: __('Relative', 'wordpress-popular-posts'), value: 'relative' },
584 { label: __('Month Day, Year', 'wordpress-popular-posts'), value: 'F j, Y' },
585 { label: __('yyyy/mm/dd', 'wordpress-popular-posts'), value: 'Y/m/d' },
586 { label: __('mm/dd/yyyy', 'wordpress-popular-posts'), value: 'm/d/Y' },
587 { label: __('dd/mm/yyyy', 'wordpress-popular-posts'), value: 'd/m/Y' },
588 { label: __('WordPress Date Format', 'wordpress-popular-posts'), value: 'wp_date_format' },
589 ]}
590 onChange={(value) => setAttributes({ stats_date_format: value })}
591 />
592 </div>
593 }
594 <CheckboxControl
595 label={__('Display taxonomy', 'wordpress-popular-posts')}
596 checked={attributes.stats_taxonomy}
597 onChange={(value) => setAttributes({ stats_taxonomy: value })}
598 />
599 { attributes.stats_taxonomy &&
600 <div className='option-subset'>
601 <SelectControl
602 label={__('Taxonomy', 'wordpress-popular-posts')}
603 value={attributes.taxonomy}
604 options={taxonomies}
605 onChange={(value) => setAttributes({ taxonomy: value })}
606 />
607 </div>
608 }
609 </Fragment>;
610 }
611
612 getHTMLMarkupFields()
613 {
614 const { attributes, setAttributes } = this.props;
615 const _self = this;
616
617 function onThemeChange(value)
618 {
619 if ( 'undefined' != typeof _self.state.themes[value] ) {
620 let config = _self.state.themes[value].json.config;
621
622 setAttributes({
623 shorten_title: config.shorten_title.active,
624 title_length: config.shorten_title.length,
625 title_by_words: config.shorten_title.words ? 1 : 0,
626 display_post_excerpt: config['post-excerpt'].active,
627 excerpt_format: config['post-excerpt'].format,
628 excerpt_length: config['post-excerpt'].length,
629 excerpt_by_words: config['post-excerpt'].words ? 1 : 0,
630 display_post_thumbnail: config.thumbnail.active,
631 thumbnail_build: config.thumbnail.build,
632 thumbnail_width: config.thumbnail.width,
633 thumbnail_height: config.thumbnail.height,
634 stats_comments: config.stats_tag.comment_count,
635 stats_views: config.stats_tag.views,
636 stats_author: config.stats_tag.author,
637 stats_date: config.stats_tag.date.active,
638 stats_date_format: config.stats_tag.date.format,
639 stats_taxonomy: config.stats_tag.taxonomy.active,
640 taxonomy: config.stats_tag.taxonomy.name,
641 custom_html: true,
642 wpp_start: config.markup['wpp-start'],
643 wpp_end: config.markup['wpp-end'],
644 post_html: config.markup['post-html'],
645 theme: value
646 });
647 } else {
648 setAttributes({ theme: value });
649 }
650 }
651
652 let themes = [
653 {
654 label: __('None', 'wordpress-popular-posts'),
655 value: ''
656 },
657 ];
658
659 if ( this.state.themes ) {
660 for( const theme in this.state.themes ) {
661 themes.push(
662 {
663 label: this.state.themes[theme].json.name,
664 value: theme
665 },
666 );
667 }
668 }
669
670 return <Fragment>
671 <p className='not-a-legend'><strong>{__('HTML Markup settings', 'wordpress-popular-posts')}</strong></p>
672 <CheckboxControl
673 label={__('Use custom HTML Markup', 'wordpress-popular-posts')}
674 checked={attributes.custom_html}
675 onChange={(value) => setAttributes({ custom_html: value })}
676 />
677 { attributes.custom_html &&
678 <div className='option-subset'>
679 <TextareaControl
680 rows="1"
681 label={__('Before title', 'wordpress-popular-posts')}
682 value={attributes.header_start}
683 onChange={(value) => setAttributes({ header_start: value })}
684 />
685 <TextareaControl
686 rows="1"
687 label={__('After title', 'wordpress-popular-posts')}
688 value={attributes.header_end}
689 onChange={(value) => setAttributes({ header_end: value })}
690 />
691 <TextareaControl
692 rows="1"
693 label={__('Before popular posts', 'wordpress-popular-posts')}
694 value={attributes.wpp_start}
695 onChange={(value) => setAttributes({ wpp_start: value })}
696 />
697 <TextareaControl
698 rows="1"
699 label={__('After popular posts', 'wordpress-popular-posts')}
700 value={attributes.wpp_end}
701 onChange={(value) => setAttributes({ wpp_end: value })}
702 />
703 <TextareaControl
704 label={__('Post HTML markup', 'wordpress-popular-posts')}
705 value={attributes.post_html}
706 onChange={(value) => setAttributes({ post_html: value })}
707 />
708 </div>
709 }
710 <SelectControl
711 label={__('Theme', 'wordpress-popular-posts')}
712 value={attributes.theme}
713 options={themes}
714 onChange={onThemeChange}
715 />
716 </Fragment>;
717 }
718
719 render()
720 {
721 if ( ! this.state.taxonomies || ! this.state.themes || ! this.state.imgSizes )
722 return <Spinner />;
723
724 const { isSelected, className, attributes } = this.props;
725
726 let classes = className;
727 classes += this.state.editMode ? ' in-edit-mode' : ' in-preview-mode';
728 classes += isSelected ? ' is-selected' : '';
729
730 return ([
731 this.getBlockControls(),
732 <div className={classes}>
733 { this.state.editMode &&
734 <Fragment>
735 {this.getMainFields()}
736 {this.getFiltersFields()}
737 {this.getPostSettingsFields()}
738 {this.getStatsTagFields()}
739 {this.getHTMLMarkupFields()}
740 </Fragment>
741 }
742 { ! this.state.editMode &&
743 <Disabled>
744 <ServerSideRender
745 block={this.props.name}
746 className={className}
747 attributes={attributes}
748 urlQueryArgs={{isSelected: isSelected}}
749 />
750 </Disabled>
751 }
752 </div>
753 ]);
754 }
755 }
756