Plugin Directory

Changeset 2338987


Ignore:
Timestamp:
07/11/2020 07:36:38 AM (6 years ago)
Author:
qrac
Message:

Update to version 1.0.1 from GitHub

Location:
qroko-blocks
Files:
12 added
12 deleted
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • qroko-blocks/assets/banner-1544x500.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • qroko-blocks/assets/banner-772x250.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • qroko-blocks/assets/icon-128x128.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • qroko-blocks/assets/icon-256x256.png

    • Property svn:mime-type changed from application/octet-stream to image/png
  • qroko-blocks/tags/1.0.1/build/editors.asset.php

    r2337723 r2338987  
    1 <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '06debe0a59944065a9c31cc9ad06f7d8');
     1<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '76525cd346420eb23b2e047470c64592');
  • qroko-blocks/tags/1.0.1/build/editors.js

    r2337723 r2338987  
    44  Licensed under the MIT License (MIT), see
    55  http://jedwatson.github.io/classnames
    6 */!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var n=typeof a;if("string"===n||"number"===n)e.push(a);else if(Array.isArray(a)&&a.length){var c=l.apply(null,a);c&&e.push(c)}else if("object"===n)for(var r in a)o.call(a,r)&&a[r]&&e.push(r)}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t,o){},,function(e,t,o){"use strict";o.r(t);var a=o(0),l=o(2),n=o(5),c=o(4),r=o(1),i=o(3),s=o.n(i),m=(o(6),[{label:"左",value:"left"},{label:"右",value:"right"}]),b=[{label:"広げる",value:"cover"},{label:"収める",value:"contain"}];Object(n.registerBlockType)("qroko-blocks/blog-card",{title:Object(l.__)("ブログカード","qroko-blocks"),description:Object(l.__)("カード型のリンクを作るブロック。リンク先URLからOpen Graphを取得した後に編集もできます。","qroko-blocks"),category:"qroko",icon:Object(a.createElement)("svg",{viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M14.5 3h-13a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h13a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M3 5.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3 8a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9A.5.5 0 0 1 3 8zm0 2.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5z"})),attributes:{url:{type:"string",default:""},title:{type:"string",default:""},description:{type:"string",default:""},imageID:{type:"number",default:0},imageURL:{type:"string",default:""},imageAlt:{type:"string",default:""},imagePosition:{type:"string",default:"left"},imageFit:{type:"string",default:"cover"},ogDomain:{type:"string",default:""},ogTitleCharacterCount:{type:"number",default:50},ogDescriptionCharacterCount:{type:"number",default:60},ogImageURL:{type:"string",default:""},externalLink:{type:"boolean",default:!0}},edit:function(e){var t=e.attributes,o=e.className,n=e.setAttributes,i=e.isSelected,g=function(e){var o,a,c,r=new URL(e.url),i=r.hostname,s=location.hostname,m=function(){var o=t.ogTitleCharacterCount;return e.title.length>=o?e.title.substr(0,o)+" ...":e.title};n({title:m(),description:(c=t.ogDescriptionCharacterCount,e.description.length>=c?e.description.substr(0,c)+" ...":e.description),imageID:0,imageURL:"",imageAlt:m(),ogDomain:i,ogImageURL:(o="https:"===location.protocol,a=r.protocol,o&&"https:"!==a?(console.log(Object(l.__)("取得先の画像URLがhttpのため、Mixed contentとなるパスを防ぎました。","qroko-blocks")),""):e.image),externalLink:i!=s})};return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},Object(a.createElement)(c.InspectorControls,null,Object(a.createElement)(r.PanelBody,{title:Object(l.__)("タイトル","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.title,onChange:function(e){n({title:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogTitleCharacterCount,label:Object(l.__)("取得文字数","qroko-blocks"),min:1,max:200,initialPosition:50,allowReset:!0,onChange:function(e){n({ogTitleCharacterCount:e||50})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("概要","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.description,onChange:function(e){n({description:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogDescriptionCharacterCount,label:Object(l.__)("取得文字数","qroko-blocks"),min:1,max:200,initialPosition:60,allowReset:!0,onChange:function(e){n({ogDescriptionCharacterCount:e||60})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("画像","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(c.MediaUpload,{onSelect:function(e){n({imageID:e.id,imageURL:e.url,imageAlt:e.alt})},type:"image",value:t.imageID,render:function(e){var o,c=e.open;return o=c,t.imageURL||t.ogImageURL?Object(a.createElement)("div",null,Object(a.createElement)(r.Button,{onClick:o,className:"qroko-blocks-blog-card-image-preview"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt})),Object(a.createElement)(r.Button,{onClick:function(){n({imageID:0,imageURL:"",imageAlt:"",ogImageURL:""})},className:"button"},Object(l.__)("画像を削除","qroko-blocks"))):Object(a.createElement)(r.Button,{onClick:o,className:"button"},Object(l.__)("画像を追加","qroko-blocks"))}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("画像位置","qroko-blocks"),selected:t.imagePosition,options:m,onChange:function(e){n({imagePosition:e})}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("画像の収め方","qroko-blocks"),selected:t.imageFit,options:b,onChange:function(e){n({imageFit:e})}})))),t.title&&Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},i&&Object(a.createElement)((function(){return Object(a.createElement)("button",{className:"qroko-blocks-blog-card-delete-image-button",type:"button",onClick:function(){return n({imageID:0,imageAlt:"",imageURL:"",ogImageURL:""})}},Object(a.createElement)("svg",{className:"icon",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"})))}),null),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))),(i||!t.title)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-columns is-padding is-gap is-bottom"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-grow"},Object(a.createElement)(r.TextControl,{label:Object(l.__)("リンク先URL","qroko-blocks"),value:t.url,onChange:function(e){n({url:e})},className:"is-margin-bottom-none"})),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)(r.Button,{onClick:function(){return e=t.url,(o=new FormData).append("action","open_graph"),o.append("target_url",e),void fetch(ajaxurl,{method:"POST",body:o,cache:"no-cache"}).then((function(e){return e.json()})).then((function(e){g(e[0])})).catch((function(e){console.log(e)}));var e,o},className:"button is-small"},Object(l.__)("情報を取得","qroko-blocks")))))},save:function(e){var t=e.attributes,o=e.className;return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},t.externalLink?Object(a.createElement)("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"qroko-blocks-blog-card-link"}):Object(a.createElement)("a",{href:t.url,className:"qroko-blocks-blog-card-link"}),Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))))}})}]);
     6*/!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var n=typeof a;if("string"===n||"number"===n)e.push(a);else if(Array.isArray(a)&&a.length){var c=l.apply(null,a);c&&e.push(c)}else if("object"===n)for(var r in a)o.call(a,r)&&a[r]&&e.push(r)}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t,o){},,function(e,t,o){"use strict";o.r(t);var a=o(0),l=o(2),n=o(5),c=o(4),r=o(1),i=o(3),s=o.n(i),m=(o(6),[{label:Object(l.__)("Left","qroko-blocks"),value:"left"},{label:Object(l.__)("Right","qroko-blocks"),value:"right"}]),b=[{label:Object(l.__)("Cover","qroko-blocks"),value:"cover"},{label:Object(l.__)("Contain","qroko-blocks"),value:"contain"}];Object(n.registerBlockType)("qroko-blocks/blog-card",{title:Object(l.__)("Blog Card","qroko-blocks"),description:Object(l.__)("Block to create a card link. You can also edit it after getting the Open Graph from the link URL.","qroko-blocks"),category:"qroko",icon:Object(a.createElement)("svg",{viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M14.5 3h-13a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h13a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M3 5.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3 8a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9A.5.5 0 0 1 3 8zm0 2.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5z"})),attributes:{url:{type:"string",default:""},title:{type:"string",default:""},description:{type:"string",default:""},imageID:{type:"number",default:0},imageURL:{type:"string",default:""},imageAlt:{type:"string",default:""},imagePosition:{type:"string",default:"left"},imageFit:{type:"string",default:"cover"},ogDomain:{type:"string",default:""},ogTitleCharacterCount:{type:"number",default:50},ogDescriptionCharacterCount:{type:"number",default:60},ogImageURL:{type:"string",default:""},externalLink:{type:"boolean",default:!0}},edit:function(e){var t=e.attributes,o=e.className,n=e.setAttributes,i=e.isSelected,g=function(e){var o,a=new URL(e.url).hostname,l=location.hostname,c=function(){var o=t.ogTitleCharacterCount;return(e.title?e.title.length:0)>=o?e.title.substr(0,o)+" ...":e.title};n({title:c(),description:(o=t.ogDescriptionCharacterCount,(e.description?e.description.length:0)>=o?e.description.substr(0,o)+" ...":e.description),imageID:0,imageURL:"",imageAlt:c(),ogDomain:a,ogImageURL:e.image,externalLink:a!=l})};return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},Object(a.createElement)(c.InspectorControls,null,Object(a.createElement)(r.PanelBody,{title:Object(l.__)("Title","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.title,onChange:function(e){n({title:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogTitleCharacterCount,label:Object(l.__)("Number of characters","qroko-blocks"),min:1,max:200,initialPosition:50,allowReset:!0,onChange:function(e){n({ogTitleCharacterCount:e||50})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("Description","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.description,onChange:function(e){n({description:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogDescriptionCharacterCount,label:Object(l.__)("Number of characters","qroko-blocks"),min:1,max:200,initialPosition:60,allowReset:!0,onChange:function(e){n({ogDescriptionCharacterCount:e||60})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("Image","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(c.MediaUpload,{onSelect:function(e){n({imageID:e.id,imageURL:e.url,imageAlt:e.alt})},type:"image",value:t.imageID,render:function(e){var o,c=e.open;return o=c,t.imageURL||t.ogImageURL?Object(a.createElement)("div",null,Object(a.createElement)(r.Button,{onClick:o,className:"qroko-blocks-blog-card-image-preview"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt})),Object(a.createElement)(r.Button,{onClick:function(){n({imageID:0,imageURL:"",imageAlt:"",ogImageURL:""})},className:"button"},Object(l.__)("Delete image","qroko-blocks"))):Object(a.createElement)(r.Button,{onClick:o,className:"button"},Object(l.__)("Add Image","qroko-blocks"))}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("Image position","qroko-blocks"),selected:t.imagePosition,options:m,onChange:function(e){n({imagePosition:e})}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("Image Fit","qroko-blocks"),selected:t.imageFit,options:b,onChange:function(e){n({imageFit:e})}})))),t.title&&Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},i&&Object(a.createElement)((function(){return Object(a.createElement)("button",{className:"qroko-blocks-blog-card-delete-image-button",type:"button",onClick:function(){return n({imageID:0,imageAlt:"",imageURL:"",ogImageURL:""})}},Object(a.createElement)("svg",{className:"icon",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"})))}),null),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))),(i||!t.title)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-columns is-padding is-gap is-bottom"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-grow"},Object(a.createElement)(r.TextControl,{label:Object(l.__)("Link URL","qroko-blocks"),value:t.url,onChange:function(e){n({url:e})},className:"is-margin-bottom-none"})),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)(r.Button,{onClick:function(){return e=t.url,(o=new FormData).append("action","open_graph"),o.append("target_url",e),void fetch(ajaxurl,{method:"POST",body:o,cache:"no-cache"}).then((function(e){return e.json()})).then((function(e){g(e[0])})).catch((function(e){console.log(e)}));var e,o},className:"button is-small"},Object(l.__)("Load","qroko-blocks")))))},save:function(e){var t=e.attributes,o=e.className;return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},t.externalLink?Object(a.createElement)("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"qroko-blocks-blog-card-link"}):Object(a.createElement)("a",{href:t.url,className:"qroko-blocks-blog-card-link"}),Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))))}})}]);
  • qroko-blocks/tags/1.0.1/functions/open-graph.php

    r2337723 r2338987  
    11<?php
    2 /*
    3   Copyright 2010 Scott MacVicar
    4    Licensed under the Apache License, Version 2.0 (the "License");
    5    you may not use this file except in compliance with the License.
    6    You may obtain a copy of the License at
    7        http://www.apache.org/licenses/LICENSE-2.0
    8    Unless required by applicable law or agreed to in writing, software
    9    distributed under the License is distributed on an "AS IS" BASIS,
    10    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11    See the License for the specific language governing permissions and
    12    limitations under the License.
    13 
    14   Original can be found at https://github.com/scottmac/opengraph/blob/master/OpenGraph.php
    15 
    16 */
    17 
    18 class OpenGraph implements Iterator
    19 {
     2/**
     3 * Copyright 2010 Scott MacVicar
     4 * Licensed under the Apache License, Version 2.0 (the "License");
     5 * you may not use this file except in compliance with the License.
     6 * You may obtain a copy of the License at
     7 * http://www.apache.org/licenses/LICENSE-2.0
     8 * Unless required by applicable law or agreed to in writing, software
     9 * distributed under the License is distributed on an "AS IS" BASIS,
     10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11 * See the License for the specific language governing permissions and
     12 * limitations under the License.
     13 * Original can be found at https://github.com/scottmac/opengraph/blob/master/OpenGraph.php
     14 */
     15
     16class OpenGraph implements Iterator {
    2017  /**
    2118   * There are base schema's based on type, this is just
     
    4845   */
    4946  static public function fetch($URI) {
    50         $response = wp_remote_get($URI);
    51 
    52         if (!empty($response)) {
    53             return self::_parse($response['body']);
    54         } else {
    55             return false;
    56         }
     47    $response = wp_remote_get($URI);
     48
     49    if (!empty($response)) {
     50      return self::_parse($response['body']);
     51    } else {
     52      return false;
     53    }
    5754  }
    5855
     
    8481
    8582    foreach ($tags AS $tag) {
    86       if ($tag->hasAttribute('property') &&
    87           strpos($tag->getAttribute('property'), 'og:') === 0) {
     83      if ($tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) {
    8884        $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
    8985        $page->_values[$key] = $tag->getAttribute('content');
    9086      }
    9187
    92       //Added this if loop to retrieve description values from sites like the New York Times who have malformed it.
    93       if ($tag ->hasAttribute('value') && $tag->hasAttribute('property') &&
    94           strpos($tag->getAttribute('property'), 'og:') === 0) {
     88      // Added this if loop to retrieve description values from sites like the New York Times who have malformed it.
     89      if ($tag ->hasAttribute('value') && $tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) {
    9590        $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
    9691        $page->_values[$key] = $tag->getAttribute('value');
    9792      }
    98       //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
     93
     94      // Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
    9995      if ($tag->hasAttribute('name') && $tag->getAttribute('name') === 'description') {
    100                 $nonOgDescription = $tag->getAttribute('content');
    101             }
    102 
    103     }
    104     //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
     96        $nonOgDescription = $tag->getAttribute('content');
     97      }
     98    }
     99
     100    // Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
    105101    if (!isset($page->_values['title'])) {
    106             $titles = $doc->getElementsByTagName('title');
    107             if ($titles->length > 0) {
    108                 $page->_values['title'] = $titles->item(0)->textContent;
    109             }
     102      $titles = $doc->getElementsByTagName('title');
     103      if ($titles->length > 0) {
     104        $page->_values['title'] = $titles->item(0)->textContent;
     105      }
     106    }
     107
     108    if (!isset($page->_values['description']) && $nonOgDescription) {
     109      $page->_values['description'] = $nonOgDescription;
     110    }
     111
     112    // Fallback to use image_src if ogp::image isn't set.
     113    if (!isset($page->values['image'])) {
     114      $domxpath = new DOMXPath($doc);
     115      $elements = $domxpath->query("//link[@rel='image_src']");
     116
     117      if ($elements->length > 0) {
     118        $domattr = $elements->item(0)->attributes->getNamedItem('href');
     119        if ($domattr) {
     120          $page->_values['image'] = $domattr->value;
     121          $page->_values['image_src'] = $domattr->value;
    110122        }
    111         if (!isset($page->_values['description']) && $nonOgDescription) {
    112             $page->_values['description'] = $nonOgDescription;
    113         }
    114 
    115         //Fallback to use image_src if ogp::image isn't set.
    116         if (!isset($page->values['image'])) {
    117             $domxpath = new DOMXPath($doc);
    118             $elements = $domxpath->query("//link[@rel='image_src']");
    119 
    120             if ($elements->length > 0) {
    121                 $domattr = $elements->item(0)->attributes->getNamedItem('href');
    122                 if ($domattr) {
    123                     $page->_values['image'] = $domattr->value;
    124                     $page->_values['image_src'] = $domattr->value;
    125                 }
    126             }
    127         }
     123      }
     124    }
    128125
    129126    if (empty($page->_values)) { return false; }
     
    212209  $og_type = $graph->type;
    213210
     211  $esc_og_title = esc_html($og_title);
     212  $esc_og_description = esc_html($og_description);
     213  $esc_og_url = esc_url($og_url);
     214  $esc_og_image = esc_url($og_image);
     215  $esc_og_type = esc_html($og_type);
     216
     217  $merge_esc_url = ($esc_og_url === null) ? $esc_target_url : $esc_og_url;
     218
     219  $match_protocol = is_ssl() ? '|^https://.*$|' : '|^https?://.*$|';
     220  $filter_esc_image = preg_match($match_protocol, $esc_og_image) ? $esc_og_image : null;
     221
    214222  $records[] = array(
    215     'title' => $og_title,
    216     'description' => $og_description,
    217     'url' => $og_url,
    218     'image' => $og_image,
    219     'type' => $og_type
     223    'title' => $esc_og_title,
     224    'description' => $esc_og_description,
     225    'url' => $merge_esc_url,
     226    'image' => $filter_esc_image,
     227    'type' => $esc_og_type
    220228  );
     229
     230  // Debug: Chrome
     231  //include '../debug/ChromePhp.php';
     232  //ChromePhp::log(json_encode($records));
    221233
    222234  echo json_encode($records);
  • qroko-blocks/tags/1.0.1/qroko-blocks.php

    r2337723 r2338987  
    66 * Author: qrac
    77 * Author URI: https://qrac.jp/
    8  * Version: 1.0.0
     8 * Version: 1.0.1
     9 * Text Domain: qroko-blocks
     10 * Domain Path: /languages
    911 * License: GPL2+
    1012 * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     
    2224
    2325function qroko_blocks_load_textdomain() {
    24   load_plugin_textdomain( 'qroko-blocks', false, basename( __DIR__ ) . '/languages' );
     26  load_plugin_textdomain( 'qroko-blocks', false, basename( dirname( __FILE__ ) ) . '/languages' );
    2527}
    2628add_action( 'init', 'qroko_blocks_load_textdomain' );
     
    5961  // Setting Translations
    6062  if ( function_exists( 'wp_set_script_translations' ) ) {
    61     wp_set_script_translations( 'qroko-blocks', 'qroko-blocks' );
     63    wp_set_script_translations( 'qroko-blocks-editors', 'qroko-blocks',
     64    plugin_dir_path( __FILE__ ) . 'languages/' );
    6265  }
    6366
  • qroko-blocks/tags/1.0.1/readme.txt

    r2337723 r2338987  
    55Requires at least: 5.4
    66Tested up to: 5.4
    7 Stable tag: 1.0.0
    8 Requires PHP: 7.4.1
     7Stable tag: 1.0.1
     8Requires PHP: 5.6
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1414== Description ==
    1515
    16 Qroko Blocks は Gutenberg にカスタムブロックを追加するプラグインです。
     16Qroko Blocks is a plugin to add custom blocks to Gutenberg. It is listed in the official WordPress plugin directory.
    1717
    18 「日本語環境で Gutenberg を使った場合に執筆が快適であること」を主眼として開発。主に、WordPress を headless CMS として使うテーマ「Qroko」での利用を想定していますが、他のテーマでも使えるよう依存性のない設計を心がけています。
     18Our main goal was to make writing on Gutenberg easier. Mainly used with the theme "Qroko", which uses WordPress as a headless CMS. However, we have tried to design it so that it is not dependent on other themes as well.
    1919
    20 Qroko:https://github.com/qrac/qroko
     20The motif is a kabuki kuroko, which will play an active role offstage in your website production.
    2121
    22 モチーフは歌舞伎の黒子です。Web サイト制作の舞台袖で活躍してくれることでしょう。
     22* Qroko: https://github.com/qrac/qroko
     23* Qroko Blocks: https://github.com/qrac/qroko-blocks
    2324
    2425== Detail ==
    2526
    26 * ブログカード
     27* Blog Card
    2728
    2829== Frequently Asked Questions ==
    2930
    30 = どのテーマでも使えますか? =
     31= Can I use it with any theme? =
    3132
    32 はい。Gutenberg を有効化しているすべてのテーマで使えます。
     33Yes, you can use it with any theme that has Gutenberg enabled.
    3334
    3435== Screenshots ==
    3536
    36 1. screenshot-1.png
    37 2. screenshot-2.png
     371. Blog Card (Editor)
     382. Blog Card (Front)
    3839
    3940== Changelog ==
    4041
    41 = 1.0.0 =
    42 * First release
    43 
    44 == Upgrade Notice ==
     42= 1.0.1 =
     43* Fix Blog Card: Works without Open Graph
     44* Translation support
    4545
    4646= 1.0.0 =
  • qroko-blocks/trunk/build/editors.asset.php

    r2337723 r2338987  
    1 <?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '06debe0a59944065a9c31cc9ad06f7d8');
     1<?php return array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '76525cd346420eb23b2e047470c64592');
  • qroko-blocks/trunk/build/editors.js

    r2337723 r2338987  
    44  Licensed under the MIT License (MIT), see
    55  http://jedwatson.github.io/classnames
    6 */!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var n=typeof a;if("string"===n||"number"===n)e.push(a);else if(Array.isArray(a)&&a.length){var c=l.apply(null,a);c&&e.push(c)}else if("object"===n)for(var r in a)o.call(a,r)&&a[r]&&e.push(r)}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t,o){},,function(e,t,o){"use strict";o.r(t);var a=o(0),l=o(2),n=o(5),c=o(4),r=o(1),i=o(3),s=o.n(i),m=(o(6),[{label:"左",value:"left"},{label:"右",value:"right"}]),b=[{label:"広げる",value:"cover"},{label:"収める",value:"contain"}];Object(n.registerBlockType)("qroko-blocks/blog-card",{title:Object(l.__)("ブログカード","qroko-blocks"),description:Object(l.__)("カード型のリンクを作るブロック。リンク先URLからOpen Graphを取得した後に編集もできます。","qroko-blocks"),category:"qroko",icon:Object(a.createElement)("svg",{viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M14.5 3h-13a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h13a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M3 5.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3 8a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9A.5.5 0 0 1 3 8zm0 2.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5z"})),attributes:{url:{type:"string",default:""},title:{type:"string",default:""},description:{type:"string",default:""},imageID:{type:"number",default:0},imageURL:{type:"string",default:""},imageAlt:{type:"string",default:""},imagePosition:{type:"string",default:"left"},imageFit:{type:"string",default:"cover"},ogDomain:{type:"string",default:""},ogTitleCharacterCount:{type:"number",default:50},ogDescriptionCharacterCount:{type:"number",default:60},ogImageURL:{type:"string",default:""},externalLink:{type:"boolean",default:!0}},edit:function(e){var t=e.attributes,o=e.className,n=e.setAttributes,i=e.isSelected,g=function(e){var o,a,c,r=new URL(e.url),i=r.hostname,s=location.hostname,m=function(){var o=t.ogTitleCharacterCount;return e.title.length>=o?e.title.substr(0,o)+" ...":e.title};n({title:m(),description:(c=t.ogDescriptionCharacterCount,e.description.length>=c?e.description.substr(0,c)+" ...":e.description),imageID:0,imageURL:"",imageAlt:m(),ogDomain:i,ogImageURL:(o="https:"===location.protocol,a=r.protocol,o&&"https:"!==a?(console.log(Object(l.__)("取得先の画像URLがhttpのため、Mixed contentとなるパスを防ぎました。","qroko-blocks")),""):e.image),externalLink:i!=s})};return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},Object(a.createElement)(c.InspectorControls,null,Object(a.createElement)(r.PanelBody,{title:Object(l.__)("タイトル","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.title,onChange:function(e){n({title:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogTitleCharacterCount,label:Object(l.__)("取得文字数","qroko-blocks"),min:1,max:200,initialPosition:50,allowReset:!0,onChange:function(e){n({ogTitleCharacterCount:e||50})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("概要","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.description,onChange:function(e){n({description:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogDescriptionCharacterCount,label:Object(l.__)("取得文字数","qroko-blocks"),min:1,max:200,initialPosition:60,allowReset:!0,onChange:function(e){n({ogDescriptionCharacterCount:e||60})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("画像","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(c.MediaUpload,{onSelect:function(e){n({imageID:e.id,imageURL:e.url,imageAlt:e.alt})},type:"image",value:t.imageID,render:function(e){var o,c=e.open;return o=c,t.imageURL||t.ogImageURL?Object(a.createElement)("div",null,Object(a.createElement)(r.Button,{onClick:o,className:"qroko-blocks-blog-card-image-preview"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt})),Object(a.createElement)(r.Button,{onClick:function(){n({imageID:0,imageURL:"",imageAlt:"",ogImageURL:""})},className:"button"},Object(l.__)("画像を削除","qroko-blocks"))):Object(a.createElement)(r.Button,{onClick:o,className:"button"},Object(l.__)("画像を追加","qroko-blocks"))}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("画像位置","qroko-blocks"),selected:t.imagePosition,options:m,onChange:function(e){n({imagePosition:e})}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("画像の収め方","qroko-blocks"),selected:t.imageFit,options:b,onChange:function(e){n({imageFit:e})}})))),t.title&&Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},i&&Object(a.createElement)((function(){return Object(a.createElement)("button",{className:"qroko-blocks-blog-card-delete-image-button",type:"button",onClick:function(){return n({imageID:0,imageAlt:"",imageURL:"",ogImageURL:""})}},Object(a.createElement)("svg",{className:"icon",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"})))}),null),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))),(i||!t.title)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-columns is-padding is-gap is-bottom"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-grow"},Object(a.createElement)(r.TextControl,{label:Object(l.__)("リンク先URL","qroko-blocks"),value:t.url,onChange:function(e){n({url:e})},className:"is-margin-bottom-none"})),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)(r.Button,{onClick:function(){return e=t.url,(o=new FormData).append("action","open_graph"),o.append("target_url",e),void fetch(ajaxurl,{method:"POST",body:o,cache:"no-cache"}).then((function(e){return e.json()})).then((function(e){g(e[0])})).catch((function(e){console.log(e)}));var e,o},className:"button is-small"},Object(l.__)("情報を取得","qroko-blocks")))))},save:function(e){var t=e.attributes,o=e.className;return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},t.externalLink?Object(a.createElement)("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"qroko-blocks-blog-card-link"}):Object(a.createElement)("a",{href:t.url,className:"qroko-blocks-blog-card-link"}),Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))))}})}]);
     6*/!function(){"use strict";var o={}.hasOwnProperty;function l(){for(var e=[],t=0;t<arguments.length;t++){var a=arguments[t];if(a){var n=typeof a;if("string"===n||"number"===n)e.push(a);else if(Array.isArray(a)&&a.length){var c=l.apply(null,a);c&&e.push(c)}else if("object"===n)for(var r in a)o.call(a,r)&&a[r]&&e.push(r)}}return e.join(" ")}e.exports?(l.default=l,e.exports=l):void 0===(a=function(){return l}.apply(t,[]))||(e.exports=a)}()},function(e,t){!function(){e.exports=this.wp.blockEditor}()},function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t,o){},,function(e,t,o){"use strict";o.r(t);var a=o(0),l=o(2),n=o(5),c=o(4),r=o(1),i=o(3),s=o.n(i),m=(o(6),[{label:Object(l.__)("Left","qroko-blocks"),value:"left"},{label:Object(l.__)("Right","qroko-blocks"),value:"right"}]),b=[{label:Object(l.__)("Cover","qroko-blocks"),value:"cover"},{label:Object(l.__)("Contain","qroko-blocks"),value:"contain"}];Object(n.registerBlockType)("qroko-blocks/blog-card",{title:Object(l.__)("Blog Card","qroko-blocks"),description:Object(l.__)("Block to create a card link. You can also edit it after getting the Open Graph from the link URL.","qroko-blocks"),category:"qroko",icon:Object(a.createElement)("svg",{viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M14.5 3h-13a.5.5 0 0 0-.5.5v9a.5.5 0 0 0 .5.5h13a.5.5 0 0 0 .5-.5v-9a.5.5 0 0 0-.5-.5zm-13-1A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h13a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-13z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M3 5.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3 8a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9A.5.5 0 0 1 3 8zm0 2.5a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5z"})),attributes:{url:{type:"string",default:""},title:{type:"string",default:""},description:{type:"string",default:""},imageID:{type:"number",default:0},imageURL:{type:"string",default:""},imageAlt:{type:"string",default:""},imagePosition:{type:"string",default:"left"},imageFit:{type:"string",default:"cover"},ogDomain:{type:"string",default:""},ogTitleCharacterCount:{type:"number",default:50},ogDescriptionCharacterCount:{type:"number",default:60},ogImageURL:{type:"string",default:""},externalLink:{type:"boolean",default:!0}},edit:function(e){var t=e.attributes,o=e.className,n=e.setAttributes,i=e.isSelected,g=function(e){var o,a=new URL(e.url).hostname,l=location.hostname,c=function(){var o=t.ogTitleCharacterCount;return(e.title?e.title.length:0)>=o?e.title.substr(0,o)+" ...":e.title};n({title:c(),description:(o=t.ogDescriptionCharacterCount,(e.description?e.description.length:0)>=o?e.description.substr(0,o)+" ...":e.description),imageID:0,imageURL:"",imageAlt:c(),ogDomain:a,ogImageURL:e.image,externalLink:a!=l})};return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},Object(a.createElement)(c.InspectorControls,null,Object(a.createElement)(r.PanelBody,{title:Object(l.__)("Title","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.title,onChange:function(e){n({title:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogTitleCharacterCount,label:Object(l.__)("Number of characters","qroko-blocks"),min:1,max:200,initialPosition:50,allowReset:!0,onChange:function(e){n({ogTitleCharacterCount:e||50})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("Description","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.TextareaControl,{value:t.description,onChange:function(e){n({description:e})}}),Object(a.createElement)(r.RangeControl,{value:t.ogDescriptionCharacterCount,label:Object(l.__)("Number of characters","qroko-blocks"),min:1,max:200,initialPosition:60,allowReset:!0,onChange:function(e){n({ogDescriptionCharacterCount:e||60})}}))),Object(a.createElement)(r.PanelBody,{title:Object(l.__)("Image","qroko-blocks")},Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(c.MediaUpload,{onSelect:function(e){n({imageID:e.id,imageURL:e.url,imageAlt:e.alt})},type:"image",value:t.imageID,render:function(e){var o,c=e.open;return o=c,t.imageURL||t.ogImageURL?Object(a.createElement)("div",null,Object(a.createElement)(r.Button,{onClick:o,className:"qroko-blocks-blog-card-image-preview"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt})),Object(a.createElement)(r.Button,{onClick:function(){n({imageID:0,imageURL:"",imageAlt:"",ogImageURL:""})},className:"button"},Object(l.__)("Delete image","qroko-blocks"))):Object(a.createElement)(r.Button,{onClick:o,className:"button"},Object(l.__)("Add Image","qroko-blocks"))}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("Image position","qroko-blocks"),selected:t.imagePosition,options:m,onChange:function(e){n({imagePosition:e})}})),Object(a.createElement)(r.BaseControl,null,Object(a.createElement)(r.RadioControl,{label:Object(l.__)("Image Fit","qroko-blocks"),selected:t.imageFit,options:b,onChange:function(e){n({imageFit:e})}})))),t.title&&Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},i&&Object(a.createElement)((function(){return Object(a.createElement)("button",{className:"qroko-blocks-blog-card-delete-image-button",type:"button",onClick:function(){return n({imageID:0,imageAlt:"",imageURL:"",ogImageURL:""})}},Object(a.createElement)("svg",{className:"icon",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg"},Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M11.854 4.146a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708-.708l7-7a.5.5 0 0 1 .708 0z"}),Object(a.createElement)("path",{"fill-rule":"evenodd",d:"M4.146 4.146a.5.5 0 0 0 0 .708l7 7a.5.5 0 0 0 .708-.708l-7-7a.5.5 0 0 0-.708 0z"})))}),null),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))),(i||!t.title)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-columns is-padding is-gap is-bottom"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-grow"},Object(a.createElement)(r.TextControl,{label:Object(l.__)("Link URL","qroko-blocks"),value:t.url,onChange:function(e){n({url:e})},className:"is-margin-bottom-none"})),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)(r.Button,{onClick:function(){return e=t.url,(o=new FormData).append("action","open_graph"),o.append("target_url",e),void fetch(ajaxurl,{method:"POST",body:o,cache:"no-cache"}).then((function(e){return e.json()})).then((function(e){g(e[0])})).catch((function(e){console.log(e)}));var e,o},className:"button is-small"},Object(l.__)("Load","qroko-blocks")))))},save:function(e){var t=e.attributes,o=e.className;return Object(a.createElement)("div",{className:s()(o,"qroko-blocks-blog-card")},t.externalLink?Object(a.createElement)("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"qroko-blocks-blog-card-link"}):Object(a.createElement)("a",{href:t.url,className:"qroko-blocks-blog-card-link"}),Object(a.createElement)("div",{className:s()("qroko-blocks-blog-card-columns","right"===t.imagePosition?"is-reverse":"")},(t.imageURL||t.ogImageURL)&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-flex-none"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-container"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-image-wrap"},Object(a.createElement)("img",{src:t.imageURL?t.imageURL:t.ogImageURL?t.ogImageURL:"",alt:t.imageAlt,className:s()("qroko-blocks-blog-card-image","is-"+t.imageFit)})))),Object(a.createElement)("div",{className:"qroko-blocks-blog-card-column is-padding is-flex-grow"},Object(a.createElement)("div",{className:"qroko-blocks-blog-card-meta"},t.title&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-heading"},t.title),t.description&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-description"},t.description),t.ogDomain&&Object(a.createElement)("div",{className:"qroko-blocks-blog-card-domain"},t.ogDomain)))))}})}]);
  • qroko-blocks/trunk/functions/open-graph.php

    r2337723 r2338987  
    11<?php
    2 /*
    3   Copyright 2010 Scott MacVicar
    4    Licensed under the Apache License, Version 2.0 (the "License");
    5    you may not use this file except in compliance with the License.
    6    You may obtain a copy of the License at
    7        http://www.apache.org/licenses/LICENSE-2.0
    8    Unless required by applicable law or agreed to in writing, software
    9    distributed under the License is distributed on an "AS IS" BASIS,
    10    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11    See the License for the specific language governing permissions and
    12    limitations under the License.
    13 
    14   Original can be found at https://github.com/scottmac/opengraph/blob/master/OpenGraph.php
    15 
    16 */
    17 
    18 class OpenGraph implements Iterator
    19 {
     2/**
     3 * Copyright 2010 Scott MacVicar
     4 * Licensed under the Apache License, Version 2.0 (the "License");
     5 * you may not use this file except in compliance with the License.
     6 * You may obtain a copy of the License at
     7 * http://www.apache.org/licenses/LICENSE-2.0
     8 * Unless required by applicable law or agreed to in writing, software
     9 * distributed under the License is distributed on an "AS IS" BASIS,
     10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11 * See the License for the specific language governing permissions and
     12 * limitations under the License.
     13 * Original can be found at https://github.com/scottmac/opengraph/blob/master/OpenGraph.php
     14 */
     15
     16class OpenGraph implements Iterator {
    2017  /**
    2118   * There are base schema's based on type, this is just
     
    4845   */
    4946  static public function fetch($URI) {
    50         $response = wp_remote_get($URI);
    51 
    52         if (!empty($response)) {
    53             return self::_parse($response['body']);
    54         } else {
    55             return false;
    56         }
     47    $response = wp_remote_get($URI);
     48
     49    if (!empty($response)) {
     50      return self::_parse($response['body']);
     51    } else {
     52      return false;
     53    }
    5754  }
    5855
     
    8481
    8582    foreach ($tags AS $tag) {
    86       if ($tag->hasAttribute('property') &&
    87           strpos($tag->getAttribute('property'), 'og:') === 0) {
     83      if ($tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) {
    8884        $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
    8985        $page->_values[$key] = $tag->getAttribute('content');
    9086      }
    9187
    92       //Added this if loop to retrieve description values from sites like the New York Times who have malformed it.
    93       if ($tag ->hasAttribute('value') && $tag->hasAttribute('property') &&
    94           strpos($tag->getAttribute('property'), 'og:') === 0) {
     88      // Added this if loop to retrieve description values from sites like the New York Times who have malformed it.
     89      if ($tag ->hasAttribute('value') && $tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) {
    9590        $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_');
    9691        $page->_values[$key] = $tag->getAttribute('value');
    9792      }
    98       //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
     93
     94      // Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
    9995      if ($tag->hasAttribute('name') && $tag->getAttribute('name') === 'description') {
    100                 $nonOgDescription = $tag->getAttribute('content');
    101             }
    102 
    103     }
    104     //Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
     96        $nonOgDescription = $tag->getAttribute('content');
     97      }
     98    }
     99
     100    // Based on modifications at https://github.com/bashofmann/opengraph/blob/master/src/OpenGraph/OpenGraph.php
    105101    if (!isset($page->_values['title'])) {
    106             $titles = $doc->getElementsByTagName('title');
    107             if ($titles->length > 0) {
    108                 $page->_values['title'] = $titles->item(0)->textContent;
    109             }
     102      $titles = $doc->getElementsByTagName('title');
     103      if ($titles->length > 0) {
     104        $page->_values['title'] = $titles->item(0)->textContent;
     105      }
     106    }
     107
     108    if (!isset($page->_values['description']) && $nonOgDescription) {
     109      $page->_values['description'] = $nonOgDescription;
     110    }
     111
     112    // Fallback to use image_src if ogp::image isn't set.
     113    if (!isset($page->values['image'])) {
     114      $domxpath = new DOMXPath($doc);
     115      $elements = $domxpath->query("//link[@rel='image_src']");
     116
     117      if ($elements->length > 0) {
     118        $domattr = $elements->item(0)->attributes->getNamedItem('href');
     119        if ($domattr) {
     120          $page->_values['image'] = $domattr->value;
     121          $page->_values['image_src'] = $domattr->value;
    110122        }
    111         if (!isset($page->_values['description']) && $nonOgDescription) {
    112             $page->_values['description'] = $nonOgDescription;
    113         }
    114 
    115         //Fallback to use image_src if ogp::image isn't set.
    116         if (!isset($page->values['image'])) {
    117             $domxpath = new DOMXPath($doc);
    118             $elements = $domxpath->query("//link[@rel='image_src']");
    119 
    120             if ($elements->length > 0) {
    121                 $domattr = $elements->item(0)->attributes->getNamedItem('href');
    122                 if ($domattr) {
    123                     $page->_values['image'] = $domattr->value;
    124                     $page->_values['image_src'] = $domattr->value;
    125                 }
    126             }
    127         }
     123      }
     124    }
    128125
    129126    if (empty($page->_values)) { return false; }
     
    212209  $og_type = $graph->type;
    213210
     211  $esc_og_title = esc_html($og_title);
     212  $esc_og_description = esc_html($og_description);
     213  $esc_og_url = esc_url($og_url);
     214  $esc_og_image = esc_url($og_image);
     215  $esc_og_type = esc_html($og_type);
     216
     217  $merge_esc_url = ($esc_og_url === null) ? $esc_target_url : $esc_og_url;
     218
     219  $match_protocol = is_ssl() ? '|^https://.*$|' : '|^https?://.*$|';
     220  $filter_esc_image = preg_match($match_protocol, $esc_og_image) ? $esc_og_image : null;
     221
    214222  $records[] = array(
    215     'title' => $og_title,
    216     'description' => $og_description,
    217     'url' => $og_url,
    218     'image' => $og_image,
    219     'type' => $og_type
     223    'title' => $esc_og_title,
     224    'description' => $esc_og_description,
     225    'url' => $merge_esc_url,
     226    'image' => $filter_esc_image,
     227    'type' => $esc_og_type
    220228  );
     229
     230  // Debug: Chrome
     231  //include '../debug/ChromePhp.php';
     232  //ChromePhp::log(json_encode($records));
    221233
    222234  echo json_encode($records);
  • qroko-blocks/trunk/qroko-blocks.php

    r2337723 r2338987  
    66 * Author: qrac
    77 * Author URI: https://qrac.jp/
    8  * Version: 1.0.0
     8 * Version: 1.0.1
     9 * Text Domain: qroko-blocks
     10 * Domain Path: /languages
    911 * License: GPL2+
    1012 * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     
    2224
    2325function qroko_blocks_load_textdomain() {
    24   load_plugin_textdomain( 'qroko-blocks', false, basename( __DIR__ ) . '/languages' );
     26  load_plugin_textdomain( 'qroko-blocks', false, basename( dirname( __FILE__ ) ) . '/languages' );
    2527}
    2628add_action( 'init', 'qroko_blocks_load_textdomain' );
     
    5961  // Setting Translations
    6062  if ( function_exists( 'wp_set_script_translations' ) ) {
    61     wp_set_script_translations( 'qroko-blocks', 'qroko-blocks' );
     63    wp_set_script_translations( 'qroko-blocks-editors', 'qroko-blocks',
     64    plugin_dir_path( __FILE__ ) . 'languages/' );
    6265  }
    6366
  • qroko-blocks/trunk/readme.txt

    r2337723 r2338987  
    55Requires at least: 5.4
    66Tested up to: 5.4
    7 Stable tag: 1.0.0
    8 Requires PHP: 7.4.1
     7Stable tag: 1.0.1
     8Requires PHP: 5.6
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1414== Description ==
    1515
    16 Qroko Blocks は Gutenberg にカスタムブロックを追加するプラグインです。
     16Qroko Blocks is a plugin to add custom blocks to Gutenberg. It is listed in the official WordPress plugin directory.
    1717
    18 「日本語環境で Gutenberg を使った場合に執筆が快適であること」を主眼として開発。主に、WordPress を headless CMS として使うテーマ「Qroko」での利用を想定していますが、他のテーマでも使えるよう依存性のない設計を心がけています。
     18Our main goal was to make writing on Gutenberg easier. Mainly used with the theme "Qroko", which uses WordPress as a headless CMS. However, we have tried to design it so that it is not dependent on other themes as well.
    1919
    20 Qroko:https://github.com/qrac/qroko
     20The motif is a kabuki kuroko, which will play an active role offstage in your website production.
    2121
    22 モチーフは歌舞伎の黒子です。Web サイト制作の舞台袖で活躍してくれることでしょう。
     22* Qroko: https://github.com/qrac/qroko
     23* Qroko Blocks: https://github.com/qrac/qroko-blocks
    2324
    2425== Detail ==
    2526
    26 * ブログカード
     27* Blog Card
    2728
    2829== Frequently Asked Questions ==
    2930
    30 = どのテーマでも使えますか? =
     31= Can I use it with any theme? =
    3132
    32 はい。Gutenberg を有効化しているすべてのテーマで使えます。
     33Yes, you can use it with any theme that has Gutenberg enabled.
    3334
    3435== Screenshots ==
    3536
    36 1. screenshot-1.png
    37 2. screenshot-2.png
     371. Blog Card (Editor)
     382. Blog Card (Front)
    3839
    3940== Changelog ==
    4041
    41 = 1.0.0 =
    42 * First release
    43 
    44 == Upgrade Notice ==
     42= 1.0.1 =
     43* Fix Blog Card: Works without Open Graph
     44* Translation support
    4545
    4646= 1.0.0 =
Note: See TracChangeset for help on using the changeset viewer.