[pmwiki-devel] Embed script immediately after body

0 views
Skip to first unread message

Simon

unread,
Sep 5, 2021, 5:11:36 AM9/5/21
to PmWiki Devel Mailing List
Does PmWiki have the ability to specify scripts to be added to a page directly after the body tag?

This would be useful to hel[ implement Page Plugin - Social Plugins (facebook.com) as a receipt

thanks

Simon

Petko Yotov

unread,
Sep 5, 2021, 1:04:55 PM9/5/21
to Simon, PmWiki Devel Mailing List
On 05/09/2021 11:10, Simon wrote:
> Does PmWiki have the ability to specify scripts to be added to a page
> directly after the body tag?

$HTMLFooterFmt is intended for this:

$HTMLFooterFmt['my-recipe'] =
'<script src="$FarmPubDirUrl/my-recipe.js"></script>';

Or possibly, if you want to allow customization:

SDVA($HTMLFooterFmt, array('my-recipe' => '<script ...>'));


BTW, this is not added "after" the </body> tag but just before it. After
it would be invalid HTML.

Petko

_______________________________________________
pmwiki-devel mailing list
pmwiki...@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-devel

Simon

unread,
Sep 5, 2021, 4:27:41 PM9/5/21
to Petko Yotov, PmWiki Devel Mailing List
Thanks very much, my wording was very loose.

The instructions say" Include the JavaScript SDK on your page once, ideally right after the opening body tag."

ngā mihi

SImon

Petko Yotov

unread,
Sep 6, 2021, 1:46:55 AM9/6/21
to Simon, PmWiki Devel Mailing List
On 05/09/2021 22:26, Simon wrote:
> Thanks very much, my wording was very loose.
>
> The instructions say" Include the JavaScript SDK on your page once,
> ideally
> right after the opening body tag."

This can be added in the skin template file, right after the opening
body tag.

Alternatively, you may want to create a markup rule and place that in
your GroupHeader page. It will not be right after the opening <body> tag
but close, and will be more configurable from within the wiki.

Their SDK script has the attributes "async" and "defer", that means it
is run in very low priority, and not at any precise point in time.

I see that you can embed the posts in a simpler iframe, see attached
screenshot. It may be easier to maintain this way, and no need for the
full SDK.

Something like this may work:

Markup('fbpost', 'directives', '/\\(:fbpost (.*?):\\)/', 'FmtFBPost');
function FmtFBPost($m) {
$fmt = '<iframe
src="https://www.facebook.com/plugins/post.php?href='
. '{$url}&amp;width=500&amp;show_text=true&amp;height=273&amp;appId"
width="500" height="273" style="border:none;overflow:hidden"
scrolling="no" frameborder="0" allowfullscreen="true"
allow="clipboard-write; encrypted-media; picture-in-picture;
web-share">'
.'</iframe>';

$url = trim($m[1]));
$html = str_replace('{$url}', rawurlencode($url), $fmt);
return Keep($html);
}

Then in a wiki page, you use:

(:fbpost https://[full url of the post]:)

From their example, I only escaped the special character & to &amp; and
removed the "autoplay" permission. You can probably start from here.

Petko
fb-SocialPlugins-iframe.png

Simon

unread,
Sep 8, 2021, 1:33:27 AM9/8/21
to Petko Yotov, PmWiki Devel Mailing List
Awesome, thank you
Reply all
Reply to author
Forward
0 new messages