widget.js
218 lines
| 1 | import icons from '../icons'; |
| 2 | import { WPPWidgetBlockEdit } from './edit'; |
| 3 | |
| 4 | const { registerBlockType } = wp.blocks; |
| 5 | const { __ } = wp.i18n; |
| 6 | |
| 7 | registerBlockType('wordpress-popular-posts/widget', { |
| 8 | title: 'WordPress 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: { |
| 60 | type: 'string', |
| 61 | default: '' |
| 62 | }, |
| 63 | author: { |
| 64 | type: 'string', |
| 65 | default: '' |
| 66 | }, |
| 67 | tax: { |
| 68 | type: 'string', |
| 69 | default: '' |
| 70 | }, |
| 71 | term_id: { |
| 72 | type: 'string', |
| 73 | default: '' |
| 74 | }, |
| 75 | /* post settings */ |
| 76 | shorten_title: { |
| 77 | type: 'boolean', |
| 78 | default: false |
| 79 | }, |
| 80 | title_length: { |
| 81 | type: 'number', |
| 82 | default: 0 |
| 83 | }, |
| 84 | title_by_words: { |
| 85 | type: 'number', |
| 86 | default: 0 |
| 87 | }, |
| 88 | display_post_excerpt: { |
| 89 | type: 'boolean', |
| 90 | default: false |
| 91 | }, |
| 92 | excerpt_format: { |
| 93 | type: 'boolean', |
| 94 | default: false |
| 95 | }, |
| 96 | excerpt_length: { |
| 97 | type: 'number', |
| 98 | default: 0 |
| 99 | }, |
| 100 | excerpt_by_words: { |
| 101 | type: 'number', |
| 102 | default: 0 |
| 103 | }, |
| 104 | display_post_thumbnail: { |
| 105 | type: 'boolean', |
| 106 | default: false |
| 107 | }, |
| 108 | thumbnail_width: { |
| 109 | type: 'number', |
| 110 | default: 0 |
| 111 | }, |
| 112 | thumbnail_height: { |
| 113 | type: 'number', |
| 114 | default: 0 |
| 115 | }, |
| 116 | thumbnail_build: { |
| 117 | type: 'string', |
| 118 | default: 'manual' |
| 119 | }, |
| 120 | thumbnail_size: { |
| 121 | type: 'string', |
| 122 | default: '' |
| 123 | }, |
| 124 | rating: { |
| 125 | type: 'boolean', |
| 126 | default: false |
| 127 | }, |
| 128 | /* stats tag settings */ |
| 129 | stats_comments: { |
| 130 | type: 'boolean', |
| 131 | default: false |
| 132 | }, |
| 133 | stats_views: { |
| 134 | type: 'boolean', |
| 135 | default: true |
| 136 | }, |
| 137 | stats_author: { |
| 138 | type: 'boolean', |
| 139 | default: false |
| 140 | }, |
| 141 | stats_date: { |
| 142 | type: 'boolean', |
| 143 | default: false |
| 144 | }, |
| 145 | stats_date_format: { |
| 146 | type: 'string', |
| 147 | default: 'F j, Y' |
| 148 | }, |
| 149 | stats_taxonomy: { |
| 150 | type: 'boolean', |
| 151 | default: false |
| 152 | }, |
| 153 | taxonomy: { |
| 154 | type: 'string', |
| 155 | default: '' |
| 156 | }, |
| 157 | /* HTML markup settings */ |
| 158 | custom_html: { |
| 159 | type: 'boolean', |
| 160 | default: false |
| 161 | }, |
| 162 | header_start: { |
| 163 | type: 'string', |
| 164 | default: '<h2>' |
| 165 | }, |
| 166 | header_end: { |
| 167 | type: 'string', |
| 168 | default: '</h2>' |
| 169 | }, |
| 170 | wpp_start: { |
| 171 | type: 'string', |
| 172 | default: '<ul class="wpp-list">' |
| 173 | }, |
| 174 | wpp_end: { |
| 175 | type: 'string', |
| 176 | default: '</ul>' |
| 177 | }, |
| 178 | post_html: { |
| 179 | type: 'string', |
| 180 | default: '<li>{thumb} {title} <span class="wpp-meta post-stats">{stats}</span></li>' |
| 181 | }, |
| 182 | theme: { |
| 183 | type: 'string', |
| 184 | default: '' |
| 185 | }, |
| 186 | }, |
| 187 | supports: { |
| 188 | anchor: true, |
| 189 | align: true, |
| 190 | html: false |
| 191 | }, |
| 192 | example: { |
| 193 | attributes: { |
| 194 | _editMode: false, |
| 195 | title: 'Popular Posts', |
| 196 | limit: 3, |
| 197 | range: 'last7days', |
| 198 | display_post_excerpt: true, |
| 199 | excerpt_length: 75, |
| 200 | display_post_thumbnail: true, |
| 201 | thumbnail_width: 75, |
| 202 | thumbnail_height: 75, |
| 203 | stats_views: false, |
| 204 | stats_taxonomy: true, |
| 205 | custom_html: true, |
| 206 | wpp_start: '<ul class="wpp-list wpp-cards">', |
| 207 | post_html: '<li>{thumb_img} <div class="wpp-item-data"><div class="taxonomies">{taxonomy}</div>{title} <p class="wpp-excerpt">{excerpt}</p></div></li>', |
| 208 | theme: 'cards' |
| 209 | } |
| 210 | }, |
| 211 | |
| 212 | edit: WPPWidgetBlockEdit, |
| 213 | |
| 214 | save: () => { |
| 215 | return null; |
| 216 | } |
| 217 | }); |
| 218 |