edit
4 weeks ago
Widget.php
4 weeks ago
edit.js
1 year ago
editor.css
4 years ago
widget.js
4 weeks ago
widget.js
222 lines
| 1 | import icons from '../icons'; |
| 2 | import { WPPWidgetBlockEdit } from './edit/edit'; |
| 3 | |
| 4 | const { registerBlockType } = wp.blocks; |
| 5 | const { __ } = wp.i18n; |
| 6 | |
| 7 | registerBlockType('wordpress-popular-posts/widget', { |
| 8 | title: 'WP Popular Posts', |
| 9 | category: 'widgets', |
| 10 | icon: icons.flame, |
| 11 | description: __('A highly customizable block that displays your most popular posts.', 'wordpress-popular-posts'), |
| 12 | keywords: ['popular', 'posts', 'trending', 'popularity'], |
| 13 | |
| 14 | attributes: { |
| 15 | _editMode: { |
| 16 | type: 'boolean', |
| 17 | default: true |
| 18 | }, |
| 19 | _isSelected: { |
| 20 | type: 'boolean', |
| 21 | default: false |
| 22 | }, |
| 23 | title: { |
| 24 | type: 'string', |
| 25 | }, |
| 26 | limit: { |
| 27 | type: 'number', |
| 28 | default: 10 |
| 29 | }, |
| 30 | offset: { |
| 31 | type: 'number', |
| 32 | default: 0 |
| 33 | }, |
| 34 | order_by: { |
| 35 | type: 'string', |
| 36 | default: 'views' |
| 37 | }, |
| 38 | range: { |
| 39 | type: 'string', |
| 40 | default: 'last24hours' |
| 41 | }, |
| 42 | time_quantity: { |
| 43 | type: 'number', |
| 44 | default: 24 |
| 45 | }, |
| 46 | time_unit: { |
| 47 | type: 'string', |
| 48 | default: 'hour' |
| 49 | }, |
| 50 | freshness: { |
| 51 | type: 'boolean', |
| 52 | default: false |
| 53 | }, |
| 54 | /* filters */ |
| 55 | post_type: { |
| 56 | type: 'string', |
| 57 | default: 'post' |
| 58 | }, |
| 59 | pid: /* Deprecated */ { |
| 60 | type: 'string', |
| 61 | default: '' |
| 62 | }, |
| 63 | exclude: { |
| 64 | type: 'string', |
| 65 | default: '' |
| 66 | }, |
| 67 | author: { |
| 68 | type: 'string', |
| 69 | default: '' |
| 70 | }, |
| 71 | tax: { |
| 72 | type: 'string', |
| 73 | default: '' |
| 74 | }, |
| 75 | term_id: { |
| 76 | type: 'string', |
| 77 | default: '' |
| 78 | }, |
| 79 | /* post settings */ |
| 80 | shorten_title: { |
| 81 | type: 'boolean', |
| 82 | default: false |
| 83 | }, |
| 84 | title_length: { |
| 85 | type: 'number', |
| 86 | default: 0 |
| 87 | }, |
| 88 | title_by_words: { |
| 89 | type: 'number', |
| 90 | default: 0 |
| 91 | }, |
| 92 | display_post_excerpt: { |
| 93 | type: 'boolean', |
| 94 | default: false |
| 95 | }, |
| 96 | excerpt_format: { |
| 97 | type: 'boolean', |
| 98 | default: false |
| 99 | }, |
| 100 | excerpt_length: { |
| 101 | type: 'number', |
| 102 | default: 0 |
| 103 | }, |
| 104 | excerpt_by_words: { |
| 105 | type: 'number', |
| 106 | default: 0 |
| 107 | }, |
| 108 | display_post_thumbnail: { |
| 109 | type: 'boolean', |
| 110 | default: false |
| 111 | }, |
| 112 | thumbnail_width: { |
| 113 | type: 'number', |
| 114 | default: 0 |
| 115 | }, |
| 116 | thumbnail_height: { |
| 117 | type: 'number', |
| 118 | default: 0 |
| 119 | }, |
| 120 | thumbnail_build: { |
| 121 | type: 'string', |
| 122 | default: 'manual' |
| 123 | }, |
| 124 | thumbnail_size: { |
| 125 | type: 'string', |
| 126 | default: '' |
| 127 | }, |
| 128 | rating: { |
| 129 | type: 'boolean', |
| 130 | default: false |
| 131 | }, |
| 132 | /* stats tag settings */ |
| 133 | stats_comments: { |
| 134 | type: 'boolean', |
| 135 | default: false |
| 136 | }, |
| 137 | stats_views: { |
| 138 | type: 'boolean', |
| 139 | default: true |
| 140 | }, |
| 141 | stats_author: { |
| 142 | type: 'boolean', |
| 143 | default: false |
| 144 | }, |
| 145 | stats_date: { |
| 146 | type: 'boolean', |
| 147 | default: false |
| 148 | }, |
| 149 | stats_date_format: { |
| 150 | type: 'string', |
| 151 | default: 'F j, Y' |
| 152 | }, |
| 153 | stats_taxonomy: { |
| 154 | type: 'boolean', |
| 155 | default: false |
| 156 | }, |
| 157 | taxonomy: { |
| 158 | type: 'string', |
| 159 | default: '' |
| 160 | }, |
| 161 | /* HTML markup settings */ |
| 162 | custom_html: { |
| 163 | type: 'boolean', |
| 164 | default: false |
| 165 | }, |
| 166 | header_start: { |
| 167 | type: 'string', |
| 168 | default: '<h2>' |
| 169 | }, |
| 170 | header_end: { |
| 171 | type: 'string', |
| 172 | default: '</h2>' |
| 173 | }, |
| 174 | wpp_start: { |
| 175 | type: 'string', |
| 176 | default: '<ul class="wpp-list">' |
| 177 | }, |
| 178 | wpp_end: { |
| 179 | type: 'string', |
| 180 | default: '</ul>' |
| 181 | }, |
| 182 | post_html: { |
| 183 | type: 'string', |
| 184 | default: '<li class="{current_class}">{thumb} {title} <span class="wpp-meta post-stats">{stats}</span></li>' |
| 185 | }, |
| 186 | theme: { |
| 187 | type: 'string', |
| 188 | default: '' |
| 189 | }, |
| 190 | }, |
| 191 | supports: { |
| 192 | anchor: true, |
| 193 | align: true, |
| 194 | html: false |
| 195 | }, |
| 196 | example: { |
| 197 | attributes: { |
| 198 | _editMode: false, |
| 199 | title: 'Popular Posts', |
| 200 | limit: 3, |
| 201 | range: 'last7days', |
| 202 | display_post_excerpt: true, |
| 203 | excerpt_length: 75, |
| 204 | display_post_thumbnail: true, |
| 205 | thumbnail_width: 75, |
| 206 | thumbnail_height: 75, |
| 207 | stats_views: false, |
| 208 | stats_taxonomy: true, |
| 209 | custom_html: true, |
| 210 | wpp_start: '<ul class="wpp-list wpp-cards">', |
| 211 | post_html: '<li>{thumb_img} <div class="wpp-item-data"><div class="taxonomies">{taxonomy}</div>{title} <p class="wpp-excerpt">{excerpt}</p></div></li>', |
| 212 | theme: 'cards' |
| 213 | } |
| 214 | }, |
| 215 | |
| 216 | edit: WPPWidgetBlockEdit, |
| 217 | |
| 218 | save: () => { |
| 219 | return null; |
| 220 | } |
| 221 | }); |
| 222 |