From a27b3d76368b8bc3034dd45d6c5617cee1fee8c2 Mon Sep 17 00:00:00 2001 From: TommusRhodus Date: Fri, 15 Nov 2024 13:30:18 +0000 Subject: [PATCH] Coding standards fixes across entire plugin --- .phpcs.xml | 69 ++++++++++++++++--- assets/js/build/editor.asset.php | 2 +- assets/js/build/editor.js | 2 +- assets/js/build/theme-install.asset.php | 2 +- assets/js/build/theme-install.js | 2 +- assets/js/src/components/video-block.js | 6 +- assets/js/src/theme-install.js | 7 +- composer.json | 4 +- functions.php | 50 ++++++++++++-- includes/assets.php | 43 ------------ includes/block-functions.php | 46 ++++++++++--- includes/tag-functions.php | 14 +++- includes/tumblr-theme-language/blocks.php | 5 ++ includes/tumblr-theme-language/lang.php | 5 ++ .../tumblr-theme-language/missing-blocks.php | 5 ++ .../tumblr-theme-language/missing-tags.php | 5 ++ includes/tumblr-theme-language/modifiers.php | 5 ++ includes/tumblr-theme-language/options.php | 5 ++ includes/tumblr-theme-language/tags.php | 5 ++ src/Customizer.php | 14 +++- src/Hooks.php | 5 ++ src/Parser.php | 12 ++-- src/Plugin.php | 5 ++ src/Processor.php | 5 ++ src/ThemeGarden.php | 41 ++++++++--- theme/tumblr3/comments.php | 3 + theme/tumblr3/functions.php | 1 + theme/tumblr3/index.php | 6 ++ 28 files changed, 276 insertions(+), 98 deletions(-) delete mode 100644 includes/assets.php diff --git a/.phpcs.xml b/.phpcs.xml index 1f2b170..28ca98f 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,25 +1,72 @@ - - - + + + + + + + + */bin/* + */tests/* + */vendor/* + */node_modules/* + */*.asset.php + */dependencies/* + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + - - - + + + + + + + + + - - node_modules/* - vendor/* - tests/* + + + + + diff --git a/assets/js/build/editor.asset.php b/assets/js/build/editor.asset.php index 7d5b959..ecc70a9 100644 --- a/assets/js/build/editor.asset.php +++ b/assets/js/build/editor.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'bb58f17b4511295bda87'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-hooks', 'wp-i18n', 'wp-plugins'), 'version' => 'c1726964d95efb0f9880'); diff --git a/assets/js/build/editor.js b/assets/js/build/editor.js index 2e75763..6daf77a 100644 --- a/assets/js/build/editor.js +++ b/assets/js/build/editor.js @@ -1,2 +1,2 @@ (()=>{"use strict";const e=window.React,t=window.wp.plugins,a=window.wp.editor,l=window.wp.i18n,c=window.wp.data,o=window.wp.components,r=window.wp.blockEditor,i=window.wp.blocks,n=[{id:"standard",caption:(0,l.__)("Text"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 20.8 13"},(0,e.createElement)("path",{d:"M.1 13h2.8l.9-3h4.7l.8 3h2.9L7.7 0h-3L.1 13zm6-10.1l2 5.1H4.2l1.9-5.1zM20 10V6c0-1.1-.2-1.9-1-2.3-.7-.5-1.7-.7-2.7-.7-1.6 0-2.7.4-3.4 1.2-.4.5-.6 1.2-.7 2h2.4c.1-.4.2-.6.4-.8.2-.3.6-.4 1.2-.4.5 0 .9.1 1.2.2.3.1.4.4.4.8 0 .3-.2.5-.5.7-.2.1-.5.2-1 .2l-.9.1c-1 .1-1.7.3-2.2.6-.9.5-1.4 1.3-1.4 2.5 0 .9.3 1.6.8 2 .6.5 1.3.9 2.2.9.7 0 1.2-.3 1.7-.6.4-.2.8-.6 1.2-.9 0 .2 0 .4.1.6 0 .2.1.8.2 1h2.7v-.8c-.1-.1-.3-.2-.4-.3.1-.3-.3-1.7-.3-2zm-2.2-1.1c0 .8-.3 1.4-.7 1.7-.4.3-1 .5-1.5.5-.3 0-.6-.1-.9-.3-.2-.2-.4-.5-.4-.9 0-.5.2-.8.6-1 .2-.1.6-.2 1.1-.3l.6-.1c.3-.1.5-.1.7-.2.2-.1.3-.1.5-.2v.8z"}))},{id:"image",caption:(0,l.__)("Image"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 17 15"},(0,e.createElement)("path",{d:"M14.6 1h-2.7l-.6-1h-6l-.6 1H2.4C1.1 1 0 2 0 3.3v9.3C0 13.9 1.1 15 2.4 15h12.2c1.3 0 2.4-1.1 2.4-2.4V3.3C17 2 15.9 1 14.6 1zM8.3 13.1c-2.9 0-5.2-2.3-5.2-5.1s2.3-5.1 5.2-5.1c2.9 0 5.2 2.3 5.2 5.1s-2.3 5.1-5.2 5.1zm5.9-8.3c-.6 0-1.1-.5-1.1-1.1 0-.6.5-1.1 1.1-1.1s1.1.5 1.1 1.1c0 .6-.5 1.1-1.1 1.1zm-10 3.1c0 1.2.5 2.2 1.3 3 0-.2 0-.4-.1-.6 0-2.2 1.8-4 4.1-4 1.1 0 2 .4 2.8 1.1-.3-2-2-3.4-4-3.4-2.2-.1-4.1 1.7-4.1 3.9z"}))},{id:"gallery",caption:(0,l.__)("Gallery"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 24 24"},(0,e.createElement)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M16 3H4C3.44772 3 3 3.44772 3 4V16C3 16.5523 3.44772 17 4 17C4.55229 17 5 16.5523 5 16V8C5 6.34315 6.34315 5 8 5H16C16.5523 5 17 4.55228 17 4C17 3.44772 16.5523 3 16 3ZM20 5C19.4477 5 19 4.55228 19 4C19 2.34315 17.6569 1 16 1H4C2.34315 1 1 2.34315 1 4V16C1 17.6569 2.34315 19 4 19C4.55229 19 5 19.4477 5 20C5 21.6569 6.34315 23 8 23H20C21.6569 23 23 21.6569 23 20V8C23 6.34315 21.6569 5 20 5ZM14 10C14 11.1046 13.1046 12 12 12C10.8954 12 10 11.1046 10 10C10 8.89543 10.8954 8 12 8C13.1046 8 14 8.89543 14 10ZM7 17.6829C7 17.4082 7.11304 17.1455 7.31257 16.9567L8.79638 15.5522C9.54271 14.8457 10.7029 14.8198 11.48 15.4923L12.4939 16.3698C12.9005 16.7216 13.5125 16.689 13.8794 16.2959L16.3619 13.636C17.1761 12.7637 18.568 12.7938 19.3437 13.7005L20.7599 15.3557C20.9148 15.5368 21 15.7674 21 16.0058V20C21 20.5523 20.5523 21 20 21H8C7.44772 21 7 20.5523 7 20V17.6829Z"}))},{id:"quote",caption:(0,l.__)("Quote"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 17 13"},(0,e.createElement)("path",{d:"M3.5 5.5C4 3.7 5.8 2.4 7.2 1.3L5.9 0C3 1.8 0 5 0 8.5 0 11 1.3 13 4 13c2 0 3.7-1.5 3.7-3.6C7.7 7 6 5.5 3.5 5.5zm9.3 0c.4-1.8 2.2-3.1 3.7-4.2L15.2 0c-2.8 1.8-5.9 5-5.9 8.5 0 2.4 1.3 4.5 4 4.5 2 0 3.7-1.5 3.7-3.6 0-2.4-1.7-3.9-4.2-3.9z"}))},{id:"link",caption:(0,l.__)("Link"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 17 17"},(0,e.createElement)("path",{d:"M9.9 5.1c-.2.3-.5 1.4-.6 2.6l1.1-.1c.7-.1 1.3-.3 1.5-.5.6-.6.6-1.4 0-2-.6-.5-1.4-.5-2 0zM8.5 0C3.8 0 0 3.8 0 8.5S3.8 17 8.5 17 17 13.2 17 8.5 13.2 0 8.5 0zm4.4 8.2c-.5.5-1.5.8-2.5.9l-1.2.2c-.1 1.3-.4 2.9-1 3.6-1.1 1.1-3 1.2-4.1 0-1.1-1.1-1.1-3 0-4.1.5-.5 1.5-.8 2.6-.9v1.5c-1.2.3-1.5.5-1.6.5-.6.6-.6 1.4 0 2 .5.5 1.4.5 2 0 .2-.2.5-1.1.6-2.5l.1-.9c0-1.3.2-3.6 1-4.4 1.1-1.1 3-1.2 4.1 0 1.2 1.1 1.2 2.9 0 4.1z"}))},{id:"chat",caption:(0,l.__)("Chat"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 18.7 17"},(0,e.createElement)("path",{d:"M16 6.1V2.6C16 .8 15 0 13.1 0H2.9C1 0 0 1.1 0 3.3v10.4C0 15.9 1 17 2.9 17h10.2c1.9 0 2.9-.8 2.9-2.6v-2.9l2.7-2.9c0-.1-2.7-2.5-2.7-2.5zm-4.5-.7c0-.5.3-.8.7-.8s.8.3.8.8v1.7l-.3 2.5c0 .3-.2.4-.4.4s-.4-.1-.4-.4l-.3-2.5V5.4zm-3.8 6.4c0 .4-.1.8-.7.8-.5 0-.7-.4-.7-.8V9.1C6.3 8.4 6 8 5.4 8c-.5 0-1 .4-1 1.2v2.6c0 .4-.1.8-.7.8s-.7-.4-.7-.8V5.4c0-.5.3-.8.7-.8.4 0 .7.3.7.8v2.1c.3-.4.7-.8 1.5-.8s1.7.5 1.7 2c.1.1.1 3.1.1 3.1zm2.5 0c0 .4-.1.8-.7.8-.5 0-.7-.4-.7-.8V7.5c0-.4.1-.8.7-.8.5 0 .7.4.7.8v4.3zm-.7-5.6c-.4 0-.7-.4-.7-.8s.3-.8.7-.8c.4 0 .7.4.7.8s-.3.8-.7.8zm2.8 6.3c-.4 0-.8-.4-.8-.9s.3-.9.8-.9.8.4.8.9-.4.9-.8.9z"}))},{id:"audio",caption:(0,l.__)("Audio"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 19 16"},(0,e.createElement)("path",{d:"M17.7 7.3c-.4-4.4-4-7.3-8.3-7.3-4.3 0-7.9 2.9-8.3 7.4C.5 7.4 0 8 0 8.6v5c0 .8.6 1.4 1.3 1.4H4c.2.4.8 1 1.2 1 .6 0 .8-1 .8-1.6V7.8c0-.5-.2-1.6-.8-1.6-.4 0-1 .8-1.2 1.1H2.9c.4-3.5 3.2-5.6 6.5-5.6s6.2 2.1 6.5 5.6H15c0-.3-.7-1.1-1.1-1.1-.6 0-.9 1-.9 1.6v6.6c0 .5.3 1.6.9 1.6.4 0 1.1-.6 1.2-1h2.6c.7 0 1.3-.6 1.3-1.3v-5c0-.8-.6-1.3-1.3-1.4zM3 8.5v1l-2 1.3V8.5h2zm15 .9l-2 1.3V8.5h2v.9zm-6.4.3l-1.6.5V6.4c0-.1-.1-.2-.2-.2s-.2 0-.2.1L7.2 12v.2c.1.1.1.1.2.1L9 12v3.8c0 .1-.2.2-.1.2h.3c.1 0 .2 0 .2-.1l2.4-5.9v-.2c-.1-.1-.2-.1-.2-.1z"}))},{id:"video",caption:(0,l.__)("Video"),icon:(0,e.createElement)("svg",{height:"35",width:"40",viewBox:"0 0 16 15"},(0,e.createElement)("path",{d:"M15.7 7.8c-.2-.1-.5 0-.6.1l-2.9 2.2c-.1.1-.1.1-.2.1V8H0v3h2v3.2c0 .4.3.8.8.8h8.4c.5 0 .8-.4.8-.8V12c0 .1.1.2.2.2l2.9 2.2c.2.2.4.2.6.1.2-.1.3-.3.3-.5V8.4c0-.2-.1-.5-.3-.6zM2.8 6.9c.3 0 .8.1 1.1.1h5.5c.3 0 .8-.1 1-.1 1.6-.3 2.8-1.7 2.8-3.4 0-1.9-1.6-3.5-3.5-3.5-1.2 0-2.4.6-3 1.7h-.1C5.9.6 4.8 0 3.6 0 1.6 0 0 1.6 0 3.5c0 1.7 1.2 3 2.8 3.4zM9 4.2c1 0 1.8-.8 1.8-1.8v-.3c.4.3.6.8.6 1.4 0 1-.8 1.8-1.8 1.8-.9 0-1.6-.6-1.8-1.5.3.3.7.4 1.2.4zm-6.2.1c1 0 1.8-.8 1.8-1.8v-.3c.4.2.6.7.6 1.3 0 1-.8 1.8-1.8 1.8-.9 0-1.6-.6-1.8-1.5.3.3.7.5 1.2.5z"}))}];(0,t.registerPlugin)("tumblr3-updated-postformat-ui",{render:()=>{const{editPost:t}=(0,c.useDispatch)("core/editor"),d=(0,c.useSelect)((e=>e("core/editor").getEditedPostAttribute("format")),[]),s=(0,c.useSelect)((e=>e(r.store).getBlocks()),[]),m=(e=>{if(e.length>2)return null;let t;if(1===e.length&&(t=e[0].name,"core/embed"===t)){const a=e[0].attributes?.providerNameSlug;["youtube","vimeo"].includes(a)?t="core/video":["spotify","soundcloud"].includes(a)&&(t="core/audio")}switch(2===e.length&&"core/paragraph"===e[1].name&&(t=e[0].name),t){case"core/image":return"image";case"core/quote":case"core/pullquote":return"quote";case"core/gallery":return"gallery";case"core/video":return"video";case"core/audio":return"audio";default:return null}})(s),u=e=>{if(t({format:e}),!(s.length>1||1===s.length&&"core/paragraph"!==s[0].name))switch(e){case"image":(0,c.dispatch)("core/block-editor").insertBlocks((0,i.createBlock)("core/image"),0);break;case"quote":(0,c.dispatch)("core/block-editor").insertBlocks((0,i.createBlock)("core/quote"),0);break;case"gallery":(0,c.dispatch)("core/block-editor").insertBlocks((0,i.createBlock)("core/gallery"),0);break;case"video":(0,c.dispatch)("core/block-editor").insertBlocks((0,i.createBlock)("core/video"),0);break;case"audio":(0,c.dispatch)("core/block-editor").insertBlocks((0,i.createBlock)("core/audio"),0)}};return(0,e.createElement)(a.PluginPostStatusInfo,null,(0,e.createElement)("div",{className:"tumblr3-post-format-selector"},(0,e.createElement)("p",null,(0,e.createElement)("strong",null,(0,l.__)("Post Formats","tumblr3"))),n.map((({id:t,caption:a,icon:l})=>(0,e.createElement)(o.Button,{key:t,onClick:()=>u(t),className:`post-format-${t} ${t===d?"active":""}`,align:"center"},l,a))),(0,e.createElement)("span",null),m&&m!==d&&(0,e.createElement)("p",{className:"editor-post-format__suggestion"},(0,e.createElement)(o.Button,{__next40pxDefaultSize:!0,variant:"link",onClick:()=>u(m),style:{width:"100%"}},(0,l.sprintf)(/* translators: %s: post format */ /* translators: %s: post format */ -(0,l.__)("Apply suggested format: %s","tumblr3"),m)))))}});const d=window.wp.hooks,s=window.wp.compose;(0,d.addFilter)("blocks.registerBlockType","tumblr3/extend-audio-block",((e,t)=>(void 0!==e.attributes&&"core/audio"===t&&(e.attributes=Object.assign(e.attributes,{mediaURL:{type:"string",default:""},mediaTitle:{type:"string",default:""},mediaArtist:{type:"string",default:""},mediaAlbum:{type:"string",default:""},poster:{type:"object",default:{}}})),e))),(0,d.addFilter)("editor.BlockEdit","tumblr3/extend-audio-block",(0,s.createHigherOrderComponent)((t=>a=>{const{attributes:l,setAttributes:c,isSelected:i}=a,{src:n,mediaURL:d,mediaTitle:s,mediaArtist:m,mediaAlbum:u,poster:p}=l;return n&&n!==d&&c({mediaURL:n}),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(t,{...a}),i&&"core/audio"===a.name&&(0,e.createElement)(r.InspectorControls,null,(0,e.createElement)(o.PanelBody,{title:"Media Information",initialOpen:!0},(0,e.createElement)(o.TextControl,{label:"Media Title",value:s,onChange:e=>c({mediaTitle:e})}),(0,e.createElement)(o.TextControl,{label:"Media Artist",value:m,onChange:e=>c({mediaArtist:e})}),(0,e.createElement)(o.TextControl,{label:"Media Album",value:u,onChange:e=>c({mediaAlbum:e})}),(0,e.createElement)(r.MediaUploadCheck,null,(0,e.createElement)(r.MediaUpload,{onSelect:e=>c({poster:{url:e.url,alt:e.alt}}),allowedTypes:["image"],render:({open:t})=>(0,e.createElement)(o.Button,{onClick:t,variant:"secondary"},p.url?"Replace Poster Image":"Upload Poster Image")}),p.url&&(0,e.createElement)("div",null,(0,e.createElement)("img",{src:p.url,alt:p.alt||"Poster Image",style:{maxWidth:"100%"}}),(0,e.createElement)(o.Button,{isDestructive:!0,onClick:()=>c({poster:{}})},"Remove Poster Image"))))))}),"enhanced-audio-block")),(0,d.addFilter)("blocks.registerBlockType","tumblr3/extend-video-block",((e,t)=>(void 0!==e.attributes&&"core/video"===t&&(e.attributes=Object.assign(e.attributes,{url:{type:"string",default:""},media:{type:"object",default:{}},provider:{type:"string",default:""},embed_html:{type:"string",default:""},embed_iframe:{type:"object",default:{}},embed_url:{type:"string",default:""},metadata:{type:"object",default:{}},attribution:{type:"object",default:{}},can_autoplay_on_cellular:{type:"boolean",default:!1},duration:{type:"number",default:0}})),e))),(0,d.addFilter)("editor.BlockEdit","tumblr3/extend-video-block",(0,s.createHigherOrderComponent)((t=>a=>{const{attributes:l,setAttributes:c,isSelected:i}=a,{src:n,url:d,provider:s,poster:m}=l;return n&&n!==d&&c({url:n}),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(t,{...a}),i&&"core/video"===a.name&&(0,e.createElement)(r.InspectorControls,null,(0,e.createElement)(o.PanelBody,{title:"Media Information",initialOpen:!0},(0,e.createElement)(o.TextControl,{label:"URL",value:d,onChange:e=>c({url:e})}),(0,e.createElement)(o.TextControl,{label:"Content provider",value:s,onChange:e=>c({provider:e})}))))}),"enhanced-video-block"))})(); \ No newline at end of file +(0,l.__)("Apply suggested format: %s","tumblr3"),m)))))}});const d=window.wp.hooks,s=window.wp.compose;(0,d.addFilter)("blocks.registerBlockType","tumblr3/extend-audio-block",((e,t)=>(void 0!==e.attributes&&"core/audio"===t&&(e.attributes=Object.assign(e.attributes,{mediaURL:{type:"string",default:""},mediaTitle:{type:"string",default:""},mediaArtist:{type:"string",default:""},mediaAlbum:{type:"string",default:""},poster:{type:"object",default:{}}})),e))),(0,d.addFilter)("editor.BlockEdit","tumblr3/extend-audio-block",(0,s.createHigherOrderComponent)((t=>a=>{const{attributes:l,setAttributes:c,isSelected:i}=a,{src:n,mediaURL:d,mediaTitle:s,mediaArtist:m,mediaAlbum:u,poster:p}=l;return n&&n!==d&&c({mediaURL:n}),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(t,{...a}),i&&"core/audio"===a.name&&(0,e.createElement)(r.InspectorControls,null,(0,e.createElement)(o.PanelBody,{title:"Media Information",initialOpen:!0},(0,e.createElement)(o.TextControl,{label:"Media Title",value:s,onChange:e=>c({mediaTitle:e})}),(0,e.createElement)(o.TextControl,{label:"Media Artist",value:m,onChange:e=>c({mediaArtist:e})}),(0,e.createElement)(o.TextControl,{label:"Media Album",value:u,onChange:e=>c({mediaAlbum:e})}),(0,e.createElement)(r.MediaUploadCheck,null,(0,e.createElement)(r.MediaUpload,{onSelect:e=>c({poster:{url:e.url,alt:e.alt}}),allowedTypes:["image"],render:({open:t})=>(0,e.createElement)(o.Button,{onClick:t,variant:"secondary"},p.url?"Replace Poster Image":"Upload Poster Image")}),p.url&&(0,e.createElement)("div",null,(0,e.createElement)("img",{src:p.url,alt:p.alt||"Poster Image",style:{maxWidth:"100%"}}),(0,e.createElement)(o.Button,{isDestructive:!0,onClick:()=>c({poster:{}})},"Remove Poster Image"))))))}),"enhanced-audio-block")),(0,d.addFilter)("blocks.registerBlockType","tumblr3/extend-video-block",((e,t)=>(void 0!==e.attributes&&"core/video"===t&&(e.attributes=Object.assign(e.attributes,{url:{type:"string",default:""},media:{type:"object",default:{}},provider:{type:"string",default:""},embed_html:{type:"string",default:""},embed_iframe:{type:"object",default:{}},embed_url:{type:"string",default:""},metadata:{type:"object",default:{}},attribution:{type:"object",default:{}},can_autoplay_on_cellular:{type:"boolean",default:!1},duration:{type:"number",default:0}})),e))),(0,d.addFilter)("editor.BlockEdit","tumblr3/extend-video-block",(0,s.createHigherOrderComponent)((t=>a=>{const{attributes:l,setAttributes:c,isSelected:i}=a,{src:n,url:d,provider:s}=l;return n&&n!==d&&c({url:n}),(0,e.createElement)(e.Fragment,null,(0,e.createElement)(t,{...a}),i&&"core/video"===a.name&&(0,e.createElement)(r.InspectorControls,null,(0,e.createElement)(o.PanelBody,{title:"Media Information",initialOpen:!0},(0,e.createElement)(o.TextControl,{label:"URL",value:d,onChange:e=>c({url:e})}),(0,e.createElement)(o.TextControl,{label:"Content provider",value:s,onChange:e=>c({provider:e})}))))}),"enhanced-video-block"))})(); \ No newline at end of file diff --git a/assets/js/build/theme-install.asset.php b/assets/js/build/theme-install.asset.php index d9d7ec3..87f99b6 100644 --- a/assets/js/build/theme-install.asset.php +++ b/assets/js/build/theme-install.asset.php @@ -1 +1 @@ - array(), 'version' => '3145422ea2aa5e4a5ad2'); + array(), 'version' => 'ef159c714f95891e50d5'); diff --git a/assets/js/build/theme-install.js b/assets/js/build/theme-install.js index 3f7c53b..6ec8b56 100644 --- a/assets/js/build/theme-install.js +++ b/assets/js/build/theme-install.js @@ -1 +1 @@ -console.log(T3_Install.themeGardenUrl),window.addEventListener("DOMContentLoaded",(function(){const t=document.getElementById("wpbody-content").getElementsByClassName("filter-links"),e=function(){window.location=T3_Install.browseUrl};if(t[0]&&"ul"===t[0].tagName.toLowerCase()){const n=t[0],l=document.createElement("li"),o=document.createElement("button");document.createElement("img"),l.setAttribute("class","tumblr-theme-garden-list-item"),o.setAttribute("title",T3_Install.buttonText),o.addEventListener("click",e),o.setAttribute("class","tumblr-theme-garden-link"),l.appendChild(o),n.appendChild(l)}}),!1); \ No newline at end of file +window.addEventListener("DOMContentLoaded",(function(){const t=document.getElementById("wpbody-content").getElementsByClassName("filter-links"),e=function(){window.location=t3Install.browseUrl};if(t[0]&&"ul"===t[0].tagName.toLowerCase()){const n=t[0],l=document.createElement("li"),i=document.createElement("button");l.setAttribute("class","tumblr-theme-garden-list-item"),i.setAttribute("title",t3Install.buttonText),i.addEventListener("click",e),i.setAttribute("class","tumblr-theme-garden-link"),l.appendChild(i),n.appendChild(l)}}),!1); \ No newline at end of file diff --git a/assets/js/src/components/video-block.js b/assets/js/src/components/video-block.js index ea86a4d..6f39984 100644 --- a/assets/js/src/components/video-block.js +++ b/assets/js/src/components/video-block.js @@ -1,5 +1,5 @@ -import { InspectorControls, MediaUpload, MediaUploadCheck } from '@wordpress/block-editor'; -import { PanelBody, TextControl, Button } from '@wordpress/components'; +import { InspectorControls } from '@wordpress/block-editor'; +import { PanelBody, TextControl } from '@wordpress/components'; import { addFilter } from '@wordpress/hooks'; import { createHigherOrderComponent } from '@wordpress/compose'; @@ -64,7 +64,7 @@ addFilter( createHigherOrderComponent( BlockEdit => { return props => { const { attributes, setAttributes, isSelected } = props; - const { src, url, provider, poster } = attributes; + const { src, url, provider } = attributes; // Sync mediaURL with src if they differ if ( src && src !== url ) { diff --git a/assets/js/src/theme-install.js b/assets/js/src/theme-install.js index 3acdd75..4fa09c2 100644 --- a/assets/js/src/theme-install.js +++ b/assets/js/src/theme-install.js @@ -1,4 +1,4 @@ -console.log( T3_Install.themeGardenUrl ); +/* global t3Install */ window.addEventListener( 'DOMContentLoaded', function () { @@ -6,16 +6,15 @@ window.addEventListener( const filterLinks = body.getElementsByClassName( 'filter-links' ); const handleClick = function () { - window.location = T3_Install.browseUrl; + window.location = t3Install.browseUrl; }; if ( filterLinks[ 0 ] && filterLinks[ 0 ].tagName.toLowerCase() === 'ul' ) { const list = filterLinks[ 0 ]; const listItem = document.createElement( 'li' ); const link = document.createElement( 'button' ); - const img = document.createElement( 'img' ); listItem.setAttribute( 'class', 'tumblr-theme-garden-list-item' ); - link.setAttribute( 'title', T3_Install.buttonText ); + link.setAttribute( 'title', t3Install.buttonText ); link.addEventListener( 'click', handleClick ); link.setAttribute( 'class', 'tumblr-theme-garden-link' ); listItem.appendChild( link ); diff --git a/composer.json b/composer.json index 0eeb1c1..9d60588 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,8 @@ "wp": "vendor/bin/wp", "phpunit": "vendor/bin/phpunit", "generate-autoloader": "@composer dump-autoload -o", - "format:php": "phpcbf --standard=./.phpcs.xml --basepath=. --extensions=php . -v", - "lint:php": "phpcs --standard=./.phpcs.xml --basepath=. --extensions=php . -v -s", + "format:php": "phpcbf --standard=./.phpcs.xml --basepath=. . -v", + "lint:php": "phpcs --standard=./.phpcs.xml --basepath=. . -v -s", "internationalize": [ "@makepot", "@updatepo", diff --git a/functions.php b/functions.php index dc295a0..19d4780 100644 --- a/functions.php +++ b/functions.php @@ -1,4 +1,9 @@ array() ); // Ensure 'dependencies' key exists. + } else { + $asset_meta = array( + 'dependencies' => array(), + 'version' => filemtime( $asset_path ), + ); + if ( false === $asset_meta['version'] ) { // Safeguard against filemtime() returning false. + $asset_meta['version'] = TUMBLR3_METADATA['Version']; + } + } + + if ( is_array( $extra_dependencies ) ) { + $asset_meta['dependencies'] = array_merge( $asset_meta['dependencies'], $extra_dependencies ); + $asset_meta['dependencies'] = array_unique( $asset_meta['dependencies'] ); + } + + return $asset_meta; +} + /** * We need a custom do_shortcode implementation because do_shortcodes_in_html_tags() * is run before running reguular shortcodes, which means that things like link hrefs @@ -99,9 +144,6 @@ function tumblr3_normalize_option_name( $name ): string { ); } -// Enqueue the plugin's assets. -require TUMBLR3_PATH . 'includes/assets.php'; - -// Include tag and block hydration functions. +// Include tag and block hydration functions for each Tumblr Theme tag|block. require TUMBLR3_PATH . 'includes/block-functions.php'; require TUMBLR3_PATH . 'includes/tag-functions.php'; diff --git a/includes/assets.php b/includes/assets.php deleted file mode 100644 index aa9d70e..0000000 --- a/includes/assets.php +++ /dev/null @@ -1,43 +0,0 @@ - array() ); // Ensure 'dependencies' key exists. - } else { - $asset_meta = array( - 'dependencies' => array(), - 'version' => filemtime( $asset_path ), - ); - if ( false === $asset_meta['version'] ) { // Safeguard against filemtime() returning false. - $asset_meta['version'] = TUMBLR3_METADATA['Version']; - } - } - - if ( is_array( $extra_dependencies ) ) { - $asset_meta['dependencies'] = array_merge( $asset_meta['dependencies'], $extra_dependencies ); - $asset_meta['dependencies'] = array_unique( $asset_meta['dependencies'] ); - } - - return $asset_meta; -} diff --git a/includes/block-functions.php b/includes/block-functions.php index 53e2430..2468bcd 100644 --- a/includes/block-functions.php +++ b/includes/block-functions.php @@ -1,4 +1,9 @@ post_content ); + $url = ''; + + foreach ( $blocks as $block ) { + // capture each paragraph in the chat post as a chat block line. + if ( 'core/media-text' === $block['blockName'] ) { + $url = $block['attrs']['mediaLink']; + + break; + } + } + + tumblr3_set_parse_context( + 'link', + array( + 'url' => $url, + ) + ); + + // Parse the content of the chat block before resetting the context. + $content = tumblr3_do_shortcode( $content ); + + tumblr3_set_parse_context( 'theme', true ); + + return $content; } add_shortcode( 'block_link', 'tumblr3_block_link' ); @@ -1145,7 +1177,6 @@ function tumblr3_block_video( $atts, $content = '' ): string { } $blocks = parse_blocks( $post->post_content ); - $media_id = null; $thumbnail = ''; $url = ''; $media = array(); @@ -1163,7 +1194,6 @@ function tumblr3_block_video( $atts, $content = '' ): string { // Stop on the first video block. if ( 'core/video' === $block['blockName'] ) { - $media_id = isset( $block['attrs']['id'] ) ? $block['attrs']['id'] : 0; $url = isset( $block['attrs']['url'] ) ? $block['attrs']['url'] : ''; $media = isset( $block['attrs']['media'] ) ? $block['attrs']['media'] : array(); $provider = isset( $block['attrs']['providerNameSlug'] ) ? $block['attrs']['providerNameSlug'] : ''; @@ -1278,7 +1308,6 @@ function tumblr3_block_photo( $atts, $content = '' ): string { $highres_sizes = array( 'large', 'full' ); $image_id = 0; $link_dest = 'none'; - $caption = ''; $lightbox = false; // Handle all blocks in the post content. @@ -1545,7 +1574,6 @@ function tumblr3_block_photoset( $atts, $content = '' ): string { $blocks = parse_blocks( $post->post_content ); $gallery = ''; - $caption = ''; $photocount = 0; $photos = array(); diff --git a/includes/tag-functions.php b/includes/tag-functions.php index 71cb307..c7953ea 100644 --- a/includes/tag-functions.php +++ b/includes/tag-functions.php @@ -1,4 +1,9 @@ get_attribute( 'content' ); + $condition = (string) $processor->get_attribute( 'content' ); $label = substr( $name, strlen( 'if:' ) ); // Option names need to be lowercase and without spaces. @@ -457,7 +462,7 @@ public function theme_specific_options( $wp_customize ): void { $name, array( 'capability' => 'edit_theme_options', - 'default' => '', + 'default' => '1' === $condition ? '1' : '', 'sanitize_callback' => 'sanitize_text_field', ) ); @@ -472,6 +477,11 @@ public function theme_specific_options( $wp_customize ): void { ) ); + // If it doesn't exist, load the default value into the theme mod. + if ( ! get_theme_mod( $name ) ) { + set_theme_mod( $name, '1' === $condition ? '1' : '' ); + } + continue; } diff --git a/src/Hooks.php b/src/Hooks.php index 3de7a62..8fac297 100644 --- a/src/Hooks.php +++ b/src/Hooks.php @@ -1,4 +1,9 @@ block_openers ) === $block ) { - - // Log the error. + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( $block . ' is a duplicate block opener. Found at position ' . $this->position . PHP_EOL, 3, @@ -325,7 +329,7 @@ public function language_helper( $key ): string { /** * Helper function to convert Tumblr boolean blocks into a custom shortcode. * - * @param string $raw_tag The raw tag. + * @param string $boolean The boolean block. * * @return string The converted tag. */ diff --git a/src/Plugin.php b/src/Plugin.php index a6c2141..751be1a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -1,4 +1,9 @@ selected_category = ( isset( $_GET['category'] ) ) ? sanitize_text_field( $_GET['category'] ) : ''; + $this->selected_category = ( isset( $_GET['category'] ) ) ? sanitize_text_field( wp_unslash( $_GET['category'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is verified in maybe_activate_theme. - $this->search = ( isset( $_GET['search'] ) ) ? sanitize_text_field( $_GET['search'] ) : ''; + $this->search = ( isset( $_GET['search'] ) ) ? sanitize_text_field( wp_unslash( $_GET['search'] ) ) : ''; } /** @@ -70,7 +93,7 @@ public function enqueue_assets( string $hook ): void { ); wp_add_inline_script( 'tumblr-theme-install', - 'const T3_Install = ' . wp_json_encode( + 'const t3Install = ' . wp_json_encode( array( 'browseUrl' => admin_url( 'admin.php?page=tumblr-themes' ), 'buttonText' => __( 'Browse Tumblr themes', 'tumblr3' ), @@ -128,13 +151,13 @@ public function maybe_show_notice(): void { * @return void */ public function maybe_activate_theme(): void { - if ( empty( $_GET['activate_tumblr_theme'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'activate_tumblr_theme' ) ) { + if ( empty( $_GET['activate_tumblr_theme'] ) || ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'activate_tumblr_theme' ) ) { return; } // During development, we don't want to be so limited by cache. So we'll send a cache invalidator to every request. // TODO: remove once we are confident that api response will be stable. - $response = wp_remote_get( self::THEME_GARDEN_ENDPOINT . '/theme/' . esc_attr( $_GET['activate_tumblr_theme'] ) . '?time=' . time() ); + $response = wp_remote_get( self::THEME_GARDEN_ENDPOINT . '/theme/' . sanitize_text_field( wp_unslash( $_GET['activate_tumblr_theme'] ) ) . '?time=' . time() ); $status = wp_remote_retrieve_response_code( $response ); if ( 200 !== $status ) { @@ -154,7 +177,7 @@ public function maybe_activate_theme(): void { // Save all external theme details to an option. $external_theme_details = array( - 'id' => $_GET['activate_tumblr_theme'], + 'id' => sanitize_text_field( wp_unslash( $_GET['activate_tumblr_theme'] ) ), 'title' => isset( $body->response->title ) ? $body->response->title : '', 'thumbnail' => isset( $body->response->thumbnail ) ? $body->response->thumbnail : '', 'author_name' => isset( $body->response->author->name ) ? $body->response->author->name : '', diff --git a/theme/tumblr3/comments.php b/theme/tumblr3/comments.php index 00fd3d1..03634bf 100644 --- a/theme/tumblr3/comments.php +++ b/theme/tumblr3/comments.php @@ -3,7 +3,10 @@ * The template for displaying Comments. * * The area of the page that contains comments and the comment form. + * + * @package Tumblr3 */ + defined( 'ABSPATH' ) || exit; /* diff --git a/theme/tumblr3/functions.php b/theme/tumblr3/functions.php index 37383ee..ecc07b7 100644 --- a/theme/tumblr3/functions.php +++ b/theme/tumblr3/functions.php @@ -4,6 +4,7 @@ * * @package Tumblr3 */ + defined( 'ABSPATH' ) || exit; /** diff --git a/theme/tumblr3/index.php b/theme/tumblr3/index.php index bbe9d10..8cf5608 100644 --- a/theme/tumblr3/index.php +++ b/theme/tumblr3/index.php @@ -1,4 +1,9 @@ ', $tumblr3_footer . '', $tumblr3_theme ); // @todo: Sanitize the theme output?! +// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $tumblr3_theme;