<?php declare(strict_types=1); namespace EmbedFacebook; # if (!defined('PmWiki')) exit(); const EMBEDFBNAME = 'EmbedFacebook'; const EMBEDFBNEW = ''; # empty string for production version /* EmbedFacebook + Copyright 2022-present Simon Davis, Petko Yotov This software is written for PmWiki; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. See pmwiki.php for full details and lack of warranty. + See https://www.pmwiki.org/pipermail/pmwiki-devel/2021-September/002428.html Markup('fbpost', 'directives', '/\\(:fbpost (.*?):\\)/', 'FmtFBPost'); function FmtFBPost($m) { $fmt = '<iframe src="https://www.facebook.com/plugins/post.php?href=' . '{$url}&width=500&show_text=true&height=273&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); } From https://developers.facebook.com/docs/plugins/page-plugin/ The Page plugin lets you easily embed and promote any public Facebook Page on your website. Just like on Facebook, your visitors can like and share the Page without leaving your site. You can use the Page plugin for any Page that is not restricted, for example, by country or age. + Step 1: Include the JavaScript SDK on your page once, ideally right after the opening body tag. <div id="fb-root"></div> <script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v13.0" nonce="SCBTNHI9"> </script> + Step 2: Place this code wherever you want the plugin to appear on your page. <iframe src="https://www.facebook.com/plugins/page.php? href=https%3A%2F%2Fwww.facebook.com%2FTararuaTrampingClub%2F &tabs=timeline&width=340&height=500&small_header=false&adapt_container_width=true &hide_cover=false&show_facepile=true&appId" width="340" height="500" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share"></iframe> + Revision History <reverse chronological order please # 2024-04-10 update for PHP 8 warnings, fix undefined variable # 2024-01-01 refactor out dmsg # 2022-02-22 Initial version */ const NL = "\n"; const BR = '<br/>' . NL; const FBURL = 'https://www.facebook.com/'; const FBAPIURL = FBURL . 'plugins/page.php?'; # if (!function_exists('dmsg')) { if (!isset ($MessagesFmt[__NAMESPACE__])) $MessagesFmt[__NAMESPACE__] = []; # initialise function dmsg (string $smsgprefix, $smsgdata) { # local instance global $MessagesFmt; $MessagesFmt[__NAMESPACE__] [] = $smsgprefix . '= ' . (is_array ($smsgdata) ? implode (BR . $smsgprefix . '= ', \PHSC ($smsgdata)) : \PHSC ($smsgdata)); } } # insert into HTML <head> metadata element \SDV($HTMLStylesFmt[__NAMESPACE__], NL . '.embedfb {font-family: monospace;}' . NL); # set debug flag \SDV($EmbedFacebookDebug, false); # set default debug setting if not defined in a configuration file $EmbedFacebook_debugon = (bool) $EmbedFacebookDebug; # if on writes input and output to $MessagesFmt # Version date $RecipeInfo[EMBEDFBNAME]['Version'] = '2024-04-25' . EMBEDFBNEW; # PmWiki version numbering is done by date # recipe version page variable $FmtPV['$EmbedFacebookVersion'] = "'" . EMBEDFBNAME . ' version ' . $RecipeInfo[EMBEDFBNAME]['Version'] . "'"; // return version as a custom page variable if ($EmbedFacebook_debugon) dmsg('<hr>' . __FILE__, $RecipeInfo[EMBEDFBNAME]['Version']); # declare $EmbedFacebook for (:if enabled EmbedFacebook:) recipe installation check $EmbedFacebook = true; # enabled # // Initialise constants ## Add a PmWiki custom markup # (:EmbedFacebook name= height= width= tabs=timeline,events,messages header=false cover=false:) $markup_pattern = '/\\(:embedfacebook(?: (.*?))?:\\)/i'; # see https://regex101.com/r/HNkxC5/2 \Markup('embedfacebook', 'directives', $markup_pattern, __NAMESPACE__ . '\EmbedFacebook_Parse' ); # i = case insensitive # uses lazy evaluation, preserves leading and trailing white space // return; # completed EmbedFacebook replacement recipe setup /*-----------------------------------------------------------------------------------------------------------*/ # /** Main EmbedFacebook parser * /param arguments as documented above * /return The HTML-formatted information wrapped in a <article> of class "embedfacebook". */ function EmbedFacebook_Parse (array $m):string { global $EmbedFacebook_debugon; # import variables $opt = \ParseArgs(strtolower($m[1])); # case insensitive if ($EmbedFacebook_debugon) dmsg('m', $m); $retval = '<:block><section class="embedfacebook":>' . NL; # start a block-level element, i.e. break out of the paragraphs if(empty ($opt['name'])) { # no parameters supplied $retval .= EMBEDFBNAME . ' parameters are name= tabs={timeline,events,messages} width=340 height=500 header={true|false} cover={true|false}'; return \Keep($retval . '</section>'); } $width = "width=" . (array_key_exists ('width', $opt) ? intval($opt['width']) : '340'); # parameter $height = "height=" . (array_key_exists ('height', $opt) ? intval($opt['height']) : '500'); # parameter ## set up API call $src = FBAPIURL; $src .= 'href=' . rawurlencode(FBURL . \PHSC ($opt['name']) . '/'); # the URL of the Facebook Page $src .= '&tabs=' . (array_key_exists ('tabs', $opt) ? \PHSC ($opt['tabs']) : 'timeline'); # tabs to render $src .= '&' . $width; # pixel width of the plugin; min 180, max 500 $src .= '&' . $height; # pixel height of the plugin; min 70 $src .= '&adapt_container_width=true'; # try to fit inside the container width $src .= '&show_facepile=false'; # show profile photos when friends like this $src .= '&small_header=' . (array_key_exists ('header', $opt) ? ! var_export(! boolval($opt['header']), true) : 'true'); $src .= '&hide_cover=' . (array_key_exists ('cover', $opt) ? ! var_export(! boolval($opt['cover']), true) : 'true'); $src .= '&hide_cta=true'; # hide the custom call to action button (if available) $src .= '&lazy=true'; # use the browser's lazy-loading mechanism ## set up iframe, does not work with sandbox attribute $retval .= '<iframe src="' . $src . '" ' . $width . ' ' . $height; $retval .= ' style="border:none;overflow:hidden"'; $retval .= ' allow="clipboard-write; encrypted-media;"'; $retval .= ' allowfullscreen="true"'; $retval .= ' loading="lazy"></iframe>' . NL; $retval .= '</section>' . NL; if ($EmbedFacebook_debugon) dmsg('retval', $retval); return \Keep ($retval); } # end EmbedFacebook_Parse