From 3ba23b793c14465b6d9b8d4c3c8a67885f40e6dd Mon Sep 17 00:00:00 2001 From: Fernando Fernandes Date: Tue, 21 Nov 2023 19:50:12 -0300 Subject: [PATCH] Add new art casting block --- build/feedland-art/block.json | 30 +++++ build/{ => feedland-art}/index.asset.php | 2 +- build/feedland-art/index.js | 1 + build/feedland-art/render.php | 45 +++++++ build/feedland-art/style-index.css | 1 + build/{ => feedland-category}/block.json | 0 build/feedland-category/index.asset.php | 1 + build/{ => feedland-category}/index.js | 2 +- build/{ => feedland-category}/render.php | 0 build/{ => feedland-category}/style-index.css | 0 feedland.php | 5 +- package.json | 2 +- src/feedland-art/block.json | 30 +++++ src/feedland-art/edit.js | 125 ++++++++++++++++++ src/{ => feedland-art}/editor.scss | 0 src/{ => feedland-art}/index.js | 0 src/feedland-art/render.php | 45 +++++++ src/feedland-art/style.scss | 4 + src/{ => feedland-category}/block.json | 0 src/{ => feedland-category}/edit.js | 0 .../editor.scss} | 0 src/feedland-category/index.js | 33 +++++ src/{ => feedland-category}/render.php | 0 src/feedland-category/style.scss | 4 + 24 files changed, 325 insertions(+), 5 deletions(-) create mode 100644 build/feedland-art/block.json rename build/{ => feedland-art}/index.asset.php (61%) create mode 100644 build/feedland-art/index.js create mode 100644 build/feedland-art/render.php create mode 100644 build/feedland-art/style-index.css rename build/{ => feedland-category}/block.json (100%) create mode 100644 build/feedland-category/index.asset.php rename build/{ => feedland-category}/index.js (95%) rename build/{ => feedland-category}/render.php (100%) rename build/{ => feedland-category}/style-index.css (100%) create mode 100644 src/feedland-art/block.json create mode 100644 src/feedland-art/edit.js rename src/{ => feedland-art}/editor.scss (100%) rename src/{ => feedland-art}/index.js (100%) create mode 100644 src/feedland-art/render.php create mode 100644 src/feedland-art/style.scss rename src/{ => feedland-category}/block.json (100%) rename src/{ => feedland-category}/edit.js (100%) rename src/{style.scss => feedland-category/editor.scss} (100%) create mode 100644 src/feedland-category/index.js rename src/{ => feedland-category}/render.php (100%) create mode 100644 src/feedland-category/style.scss diff --git a/build/feedland-art/block.json b/build/feedland-art/block.json new file mode 100644 index 0000000..6e83510 --- /dev/null +++ b/build/feedland-art/block.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "feedland/art", + "version": "0.1.0", + "title": "FeedLand Artcasting", + "category": "art", + "icon": "rss", + "description": "Displays entries from FeedLand.", + "example": {}, + "supports": { + "align": true, + "html": false + }, + "textdomain": "feedland", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css", + "render": "file:./render.php", + "attributes": { + "readingListUrl": { + "type": "string", + "default": "https://lists.feedcorps.org/artshow.opml" + }, + "itemsToShow": { + "type": "number", + "default": 5 + } + } +} \ No newline at end of file diff --git a/build/index.asset.php b/build/feedland-art/index.asset.php similarity index 61% rename from build/index.asset.php rename to build/feedland-art/index.asset.php index 89591d8..8f8bc18 100644 --- a/build/index.asset.php +++ b/build/feedland-art/index.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '0316aaf3bc83e0522b00'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => 'f17fc4504b3661c93502'); diff --git a/build/feedland-art/index.js b/build/feedland-art/index.js new file mode 100644 index 0000000..c438bd9 --- /dev/null +++ b/build/feedland-art/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e,t={639:(e,t,n)=>{const r=window.wp.blocks,l=window.React,a=window.wp.blockEditor,o=window.wp.components,i=window.wp.element,d=window.wp.i18n,c=window.wp.primitives,s=(0,l.createElement)(c.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,l.createElement)(c.Path,{d:"M5 10.2h-.8v1.5H5c1.9 0 3.8.8 5.1 2.1 1.4 1.4 2.1 3.2 2.1 5.1v.8h1.5V19c0-2.3-.9-4.5-2.6-6.2-1.6-1.6-3.8-2.6-6.1-2.6zm10.4-1.6C12.6 5.8 8.9 4.2 5 4.2h-.8v1.5H5c3.5 0 6.9 1.4 9.4 3.9s3.9 5.8 3.9 9.4v.8h1.5V19c0-3.9-1.6-7.6-4.4-10.4zM4 20h3v-3H4v3z"})),m=(0,l.createElement)(c.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,l.createElement)(c.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})),p=window.wp.serverSideRender;var u=n.n(p);const w=JSON.parse('{"u2":"feedland/art"}');(0,r.registerBlockType)(w.u2,{edit:function({attributes:e,setAttributes:t}){const[n,r]=(0,i.useState)(!e.readingListUrl),{readingListUrl:c,itemsToShow:p}=e,w=(0,a.useBlockProps)();if(n)return(0,l.createElement)("div",{...w},(0,l.createElement)(o.Placeholder,{icon:s,label:"FeedLand"},(0,l.createElement)("form",{onSubmit:function(e){e.preventDefault(),c&&(t({readingListUrl:c}),r(!1))},className:"wp-block-feedland-art__placeholder-form"},(0,l.createElement)(o.__experimentalHStack,{wrap:!0},(0,l.createElement)(o.__experimentalInputControl,{__next40pxDefaultSize:!0,placeholder:(0,d.__)("Enter reading list URL here…","feedland"),value:c,onChange:e=>t({readingListUrl:e}),className:"wp-block-feedland-art__placeholder-input"}),(0,l.createElement)(o.Button,{__next40pxDefaultSize:!0,variant:"primary",type:"submit"},(0,d.__)("Done","feedland"))))));const v=[{icon:m,title:(0,d.__)("Edit reading list URL","feedland"),onClick:()=>r(!0)}];return(0,l.createElement)(l.Fragment,null,(0,l.createElement)(a.BlockControls,null,(0,l.createElement)(o.ToolbarGroup,{controls:v})),(0,l.createElement)(a.InspectorControls,null,(0,l.createElement)(o.PanelBody,{title:(0,d.__)("Settings","feedland")},(0,l.createElement)(o.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,d.__)("Number of items","feedland"),value:p,onChange:e=>t({itemsToShow:e}),min:1,max:20,required:!0}))),(0,l.createElement)("div",{...w},(0,l.createElement)(o.Disabled,null,(0,l.createElement)(u(),{block:"feedland/art",attributes:e}))))}})}},n={};function r(e){var l=n[e];if(void 0!==l)return l.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.m=t,e=[],r.O=(t,n,l,a)=>{if(!n){var o=1/0;for(s=0;s=a)&&Object.keys(r.O).every((e=>r.O[e](n[d])))?n.splice(d--,1):(i=!1,a0&&e[s-1][2]>a;s--)e[s]=e[s-1];e[s]=[n,l,a]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={518:0,209:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var l,a,[o,i,d]=n,c=0;if(o.some((t=>0!==e[t]))){for(l in i)r.o(i,l)&&(r.m[l]=i[l]);if(d)var s=d(r)}for(t&&t(n);cr(639)));l=r.O(l)})(); \ No newline at end of file diff --git a/build/feedland-art/render.php b/build/feedland-art/render.php new file mode 100644 index 0000000..cd76f41 --- /dev/null +++ b/build/feedland-art/render.php @@ -0,0 +1,45 @@ +%s', + esc_html__( 'Error loading feed.', 'feedland' ) + ); + return; + } else { + set_transient( $transient_key, $response, MINUTE_IN_SECONDS ); + } +} + +$body = json_decode( wp_remote_retrieve_body( $response ) ); +$feed_items = array_slice( array_merge( ...wp_list_pluck( $body->feeds, 'items' ) ), 0, $attributes['itemsToShow'] ); +$list_items = ''; + +foreach ( $feed_items as $item ) { + $title = esc_html( trim( wp_strip_all_tags( substr( $item->description, 0, strpos( $item->description, 'enclosure ) { + $enclosure = sprintf( + '
%2$s
%2$s
', + esc_url( $item->enclosure->url ), + esc_attr( $title ), + esc_html( $title ) + ); + } + + $list_items .= "{$enclosure}"; +} + +$wrapper_attributes = get_block_wrapper_attributes(); + +printf( '
', $wrapper_attributes, $list_items ); diff --git a/build/feedland-art/style-index.css b/build/feedland-art/style-index.css new file mode 100644 index 0000000..d806c7a --- /dev/null +++ b/build/feedland-art/style-index.css @@ -0,0 +1 @@ +.wp-block-feedland-art{list-style:none;padding:0} diff --git a/build/block.json b/build/feedland-category/block.json similarity index 100% rename from build/block.json rename to build/feedland-category/block.json diff --git a/build/feedland-category/index.asset.php b/build/feedland-category/index.asset.php new file mode 100644 index 0000000..6347d6c --- /dev/null +++ b/build/feedland-category/index.asset.php @@ -0,0 +1 @@ + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-server-side-render'), 'version' => '904b201b201e51a002d4'); diff --git a/build/index.js b/build/feedland-category/index.js similarity index 95% rename from build/index.js rename to build/feedland-category/index.js index c2623d3..d5c58a2 100644 --- a/build/index.js +++ b/build/feedland-category/index.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={286:(e,t,n)=>{const r=window.wp.blocks,a=window.React,l=window.wp.blockEditor,o=window.wp.components,c=window.wp.element,i=window.wp.i18n,d=window.wp.primitives,s=(0,a.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(d.Path,{d:"M5 10.2h-.8v1.5H5c1.9 0 3.8.8 5.1 2.1 1.4 1.4 2.1 3.2 2.1 5.1v.8h1.5V19c0-2.3-.9-4.5-2.6-6.2-1.6-1.6-3.8-2.6-6.1-2.6zm10.4-1.6C12.6 5.8 8.9 4.2 5 4.2h-.8v1.5H5c3.5 0 6.9 1.4 9.4 3.9s3.9 5.8 3.9 9.4v.8h1.5V19c0-3.9-1.6-7.6-4.4-10.4zM4 20h3v-3H4v3z"})),m=(0,a.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(d.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})),p=window.wp.serverSideRender;var u=n.n(p);const f=JSON.parse('{"u2":"feedland/feedviewer"}');(0,r.registerBlockType)(f.u2,{edit:function({attributes:e,setAttributes:t}){const[n,r]=(0,c.useState)(!(e.screenname&&e.category)),{displayDate:d,displayExcerpt:p,excerptLength:f,screenname:_,category:w,itemsToShow:v}=e;function h(n){return()=>{const r=e[n];t({[n]:!r})}}const g=(0,l.useBlockProps)();if(n)return(0,a.createElement)("div",{...g},(0,a.createElement)(o.Placeholder,{icon:s,label:"FeedLand"},(0,a.createElement)("form",{onSubmit:function(e){e.preventDefault(),_&&w&&(t({screenname:_,category:w}),r(!1))},className:"wp-block-feedland-feedviewer__placeholder-form"},(0,a.createElement)(o.__experimentalHStack,{wrap:!0},(0,a.createElement)(o.__experimentalInputControl,{__next40pxDefaultSize:!0,placeholder:(0,i.__)("Enter screenname here…","feedland"),value:_,onChange:e=>t({screenname:e}),className:"wp-block-feedland-feedviewer__placeholder-input"}),(0,a.createElement)(o.__experimentalInputControl,{__next40pxDefaultSize:!0,placeholder:(0,i.__)("Enter category here…","feedland"),value:w,onChange:e=>t({category:e}),className:"wp-block-feedland-feedviewer__placeholder-input"}),(0,a.createElement)(o.Button,{__next40pxDefaultSize:!0,variant:"primary",type:"submit"},(0,i.__)("Done","feedland"))))));const x=[{icon:m,title:(0,i.__)("Edit category and screenname","feedland"),onClick:()=>r(!0)}];return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(l.BlockControls,null,(0,a.createElement)(o.ToolbarGroup,{controls:x})),(0,a.createElement)(l.InspectorControls,null,(0,a.createElement)(o.PanelBody,{title:(0,i.__)("Settings","feedland")},(0,a.createElement)(o.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Number of items","feedland"),value:v,onChange:e=>t({itemsToShow:e}),min:1,max:20,required:!0}),(0,a.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Display date","feedland"),checked:d,onChange:h("displayDate")}),(0,a.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Display excerpt","feedland"),checked:p,onChange:h("displayExcerpt")}),p&&(0,a.createElement)(o.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Max number of words in excerpt","feedland"),value:f,onChange:e=>t({excerptLength:e}),min:10,max:100,required:!0}))),(0,a.createElement)("div",{...g},(0,a.createElement)(o.Disabled,null,(0,a.createElement)(u(),{block:"feedland/feedviewer",attributes:e}))))}})}},n={};function r(e){var a=n[e];if(void 0!==a)return a.exports;var l=n[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,n,a,l)=>{if(!n){var o=1/0;for(s=0;s=l)&&Object.keys(r.O).every((e=>r.O[e](n[i])))?n.splice(i--,1):(c=!1,l0&&e[s-1][2]>l;s--)e[s]=e[s-1];e[s]=[n,a,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={826:0,431:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var a,l,[o,c,i]=n,d=0;if(o.some((t=>0!==e[t]))){for(a in c)r.o(c,a)&&(r.m[a]=c[a]);if(i)var s=i(r)}for(t&&t(n);dr(286)));a=r.O(a)})(); \ No newline at end of file +(()=>{"use strict";var e,t={401:(e,t,n)=>{const r=window.wp.blocks,a=window.React,l=window.wp.blockEditor,o=window.wp.components,c=window.wp.element,i=window.wp.i18n,d=window.wp.primitives,s=(0,a.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(d.Path,{d:"M5 10.2h-.8v1.5H5c1.9 0 3.8.8 5.1 2.1 1.4 1.4 2.1 3.2 2.1 5.1v.8h1.5V19c0-2.3-.9-4.5-2.6-6.2-1.6-1.6-3.8-2.6-6.1-2.6zm10.4-1.6C12.6 5.8 8.9 4.2 5 4.2h-.8v1.5H5c3.5 0 6.9 1.4 9.4 3.9s3.9 5.8 3.9 9.4v.8h1.5V19c0-3.9-1.6-7.6-4.4-10.4zM4 20h3v-3H4v3z"})),m=(0,a.createElement)(d.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,a.createElement)(d.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})),p=window.wp.serverSideRender;var u=n.n(p);const f=JSON.parse('{"u2":"feedland/feedviewer"}');(0,r.registerBlockType)(f.u2,{edit:function({attributes:e,setAttributes:t}){const[n,r]=(0,c.useState)(!(e.screenname&&e.category)),{displayDate:d,displayExcerpt:p,excerptLength:f,screenname:_,category:w,itemsToShow:v}=e;function h(n){return()=>{const r=e[n];t({[n]:!r})}}const g=(0,l.useBlockProps)();if(n)return(0,a.createElement)("div",{...g},(0,a.createElement)(o.Placeholder,{icon:s,label:"FeedLand"},(0,a.createElement)("form",{onSubmit:function(e){e.preventDefault(),_&&w&&(t({screenname:_,category:w}),r(!1))},className:"wp-block-feedland-feedviewer__placeholder-form"},(0,a.createElement)(o.__experimentalHStack,{wrap:!0},(0,a.createElement)(o.__experimentalInputControl,{__next40pxDefaultSize:!0,placeholder:(0,i.__)("Enter screenname here…","feedland"),value:_,onChange:e=>t({screenname:e}),className:"wp-block-feedland-feedviewer__placeholder-input"}),(0,a.createElement)(o.__experimentalInputControl,{__next40pxDefaultSize:!0,placeholder:(0,i.__)("Enter category here…","feedland"),value:w,onChange:e=>t({category:e}),className:"wp-block-feedland-feedviewer__placeholder-input"}),(0,a.createElement)(o.Button,{__next40pxDefaultSize:!0,variant:"primary",type:"submit"},(0,i.__)("Done","feedland"))))));const x=[{icon:m,title:(0,i.__)("Edit category and screenname","feedland"),onClick:()=>r(!0)}];return(0,a.createElement)(a.Fragment,null,(0,a.createElement)(l.BlockControls,null,(0,a.createElement)(o.ToolbarGroup,{controls:x})),(0,a.createElement)(l.InspectorControls,null,(0,a.createElement)(o.PanelBody,{title:(0,i.__)("Settings","feedland")},(0,a.createElement)(o.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Number of items","feedland"),value:v,onChange:e=>t({itemsToShow:e}),min:1,max:20,required:!0}),(0,a.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Display date","feedland"),checked:d,onChange:h("displayDate")}),(0,a.createElement)(o.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Display excerpt","feedland"),checked:p,onChange:h("displayExcerpt")}),p&&(0,a.createElement)(o.RangeControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Max number of words in excerpt","feedland"),value:f,onChange:e=>t({excerptLength:e}),min:10,max:100,required:!0}))),(0,a.createElement)("div",{...g},(0,a.createElement)(o.Disabled,null,(0,a.createElement)(u(),{block:"feedland/feedviewer",attributes:e}))))}})}},n={};function r(e){var a=n[e];if(void 0!==a)return a.exports;var l=n[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.m=t,e=[],r.O=(t,n,a,l)=>{if(!n){var o=1/0;for(s=0;s=l)&&Object.keys(r.O).every((e=>r.O[e](n[i])))?n.splice(i--,1):(c=!1,l0&&e[s-1][2]>l;s--)e[s]=e[s-1];e[s]=[n,a,l]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={163:0,388:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var a,l,[o,c,i]=n,d=0;if(o.some((t=>0!==e[t]))){for(a in c)r.o(c,a)&&(r.m[a]=c[a]);if(i)var s=i(r)}for(t&&t(n);dr(401)));a=r.O(a)})(); \ No newline at end of file diff --git a/build/render.php b/build/feedland-category/render.php similarity index 100% rename from build/render.php rename to build/feedland-category/render.php diff --git a/build/style-index.css b/build/feedland-category/style-index.css similarity index 100% rename from build/style-index.css rename to build/feedland-category/style-index.css diff --git a/feedland.php b/feedland.php index de4b435..46340b5 100644 --- a/feedland.php +++ b/feedland.php @@ -4,7 +4,7 @@ * Description: Displays your FeedLand items. * Requires at least: 6.1 * Requires PHP: 7.0 - * Version: 0.1.0 + * Version: 0.1.1 * Author: WordPress.com Special Projects * Author URI: https://wpspecialprojects.wordpress.com * License: GPL-2.0-or-later @@ -26,6 +26,7 @@ * @see https://developer.wordpress.org/reference/functions/register_block_type/ */ function feedland_block_init() { - register_block_type( __DIR__ . '/build' ); + register_block_type( __DIR__ . '/build/feedland-category' ); + register_block_type( __DIR__ . '/build/feedland-art' ); } add_action( 'init', 'feedland_block_init' ); diff --git a/package.json b/package.json index 2b6f105..2194b78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "feedland", - "version": "0.1.0", + "version": "0.1.1", "description": "A custom block to display your FeedLand feed on your site.", "author": { "name": "WordPress.com Special Projects Team", diff --git a/src/feedland-art/block.json b/src/feedland-art/block.json new file mode 100644 index 0000000..acc24c4 --- /dev/null +++ b/src/feedland-art/block.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 3, + "name": "feedland/art", + "version": "0.1.0", + "title": "FeedLand Artcasting", + "category": "art", + "icon": "rss", + "description": "Displays entries from FeedLand.", + "example": {}, + "supports": { + "align": true, + "html": false + }, + "textdomain": "feedland", + "editorScript": "file:./index.js", + "editorStyle": "file:./index.css", + "style": "file:./style-index.css", + "render": "file:./render.php", + "attributes": { + "readingListUrl": { + "type": "string", + "default": "https://lists.feedcorps.org/artshow.opml" + }, + "itemsToShow": { + "type": "number", + "default": 5 + } + } +} diff --git a/src/feedland-art/edit.js b/src/feedland-art/edit.js new file mode 100644 index 0000000..e23f92f --- /dev/null +++ b/src/feedland-art/edit.js @@ -0,0 +1,125 @@ +/** + * WordPress dependencies + */ +import { + BlockControls, + InspectorControls, + useBlockProps, +} from '@wordpress/block-editor'; +import { + Button, + Disabled, + PanelBody, + Placeholder, + RangeControl, + ToolbarGroup, + __experimentalHStack as HStack, + __experimentalInputControl as InputControl, +} from '@wordpress/components'; +import { useState } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { edit, rss } from '@wordpress/icons'; +import ServerSideRender from '@wordpress/server-side-render'; + +const DEFAULT_MIN_ITEMS = 1; +const DEFAULT_MAX_ITEMS = 20; + +export default function Edit( { attributes, setAttributes } ) { + const [ isEditing, setIsEditing ] = useState( ! attributes.readingListUrl ); + + const { readingListUrl, itemsToShow } = attributes; + + function toggleAttribute( propName ) { + return () => { + const value = attributes[ propName ]; + + setAttributes( { [ propName ]: ! value } ); + }; + } + + function onSubmitURL( event ) { + event.preventDefault(); + + if ( readingListUrl ) { + setAttributes( { readingListUrl: readingListUrl } ); + setIsEditing( false ); + } + } + + const blockProps = useBlockProps(); + + if ( isEditing ) { + return ( +
+ +
+ + + setAttributes( { readingListUrl: value } ) + } + className="wp-block-feedland-art__placeholder-input" + /> + + +
+
+
+ ); + } + + const toolbarControls = [ + { + icon: edit, + title: __( 'Edit reading list URL', 'feedland' ), + onClick: () => setIsEditing( true ), + }, + ]; + + return ( + <> + + + + + + + setAttributes( { itemsToShow: value } ) + } + min={ DEFAULT_MIN_ITEMS } + max={ DEFAULT_MAX_ITEMS } + required + /> + + +
+ + + +
+ + ); +} diff --git a/src/editor.scss b/src/feedland-art/editor.scss similarity index 100% rename from src/editor.scss rename to src/feedland-art/editor.scss diff --git a/src/index.js b/src/feedland-art/index.js similarity index 100% rename from src/index.js rename to src/feedland-art/index.js diff --git a/src/feedland-art/render.php b/src/feedland-art/render.php new file mode 100644 index 0000000..cd76f41 --- /dev/null +++ b/src/feedland-art/render.php @@ -0,0 +1,45 @@ +%s', + esc_html__( 'Error loading feed.', 'feedland' ) + ); + return; + } else { + set_transient( $transient_key, $response, MINUTE_IN_SECONDS ); + } +} + +$body = json_decode( wp_remote_retrieve_body( $response ) ); +$feed_items = array_slice( array_merge( ...wp_list_pluck( $body->feeds, 'items' ) ), 0, $attributes['itemsToShow'] ); +$list_items = ''; + +foreach ( $feed_items as $item ) { + $title = esc_html( trim( wp_strip_all_tags( substr( $item->description, 0, strpos( $item->description, 'enclosure ) { + $enclosure = sprintf( + '
%2$s
%2$s
', + esc_url( $item->enclosure->url ), + esc_attr( $title ), + esc_html( $title ) + ); + } + + $list_items .= "{$enclosure}"; +} + +$wrapper_attributes = get_block_wrapper_attributes(); + +printf( '
', $wrapper_attributes, $list_items ); diff --git a/src/feedland-art/style.scss b/src/feedland-art/style.scss new file mode 100644 index 0000000..2f27fa4 --- /dev/null +++ b/src/feedland-art/style.scss @@ -0,0 +1,4 @@ +.wp-block-feedland-art { + list-style: none; + padding: 0; +} diff --git a/src/block.json b/src/feedland-category/block.json similarity index 100% rename from src/block.json rename to src/feedland-category/block.json diff --git a/src/edit.js b/src/feedland-category/edit.js similarity index 100% rename from src/edit.js rename to src/feedland-category/edit.js diff --git a/src/style.scss b/src/feedland-category/editor.scss similarity index 100% rename from src/style.scss rename to src/feedland-category/editor.scss diff --git a/src/feedland-category/index.js b/src/feedland-category/index.js new file mode 100644 index 0000000..d82621b --- /dev/null +++ b/src/feedland-category/index.js @@ -0,0 +1,33 @@ +/** + * Registers a new block provided a unique name and an object defining its behavior. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. + * All files containing `style` keyword are bundled together. The code used + * gets applied both to the front of your site and to the editor. + * + * @see https://www.npmjs.com/package/@wordpress/scripts#using-css + */ +import './style.scss'; + +/** + * Internal dependencies + */ +import Edit from './edit'; +import metadata from './block.json'; + +/** + * Every block starts by registering a new block type definition. + * + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/ + */ +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit, +} ); diff --git a/src/render.php b/src/feedland-category/render.php similarity index 100% rename from src/render.php rename to src/feedland-category/render.php diff --git a/src/feedland-category/style.scss b/src/feedland-category/style.scss new file mode 100644 index 0000000..8d16a56 --- /dev/null +++ b/src/feedland-category/style.scss @@ -0,0 +1,4 @@ +.wp-block-feedland-feedviewer { + list-style: none; + padding: 0; +}