From dda05728eb46cce76e140e11a6682fee99aba2bb Mon Sep 17 00:00:00 2001 From: Aashay Date: Wed, 29 Jun 2016 17:09:06 +0530 Subject: [PATCH] MSFTMPP-545: Support for Microsoft Forms in oEmbed plug-in and addition of 'My Forms' to the Microsoft Block --- classes/provider/officeforms.php | 77 ++++++++++++++++++++++++++++++++ filter.php | 2 +- lang/en/filter_oembed.php | 1 + 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 classes/provider/officeforms.php diff --git a/classes/provider/officeforms.php b/classes/provider/officeforms.php new file mode 100644 index 0000000..505d08f --- /dev/null +++ b/classes/provider/officeforms.php @@ -0,0 +1,77 @@ +. + +/** + * @package filter_oembed + * @author Aashay Zajriya + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @copyright (C) 2016 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/) + */ + +namespace filter_oembed\provider; +/** + * oEmbed provider implementation for Microsoft Forms + */ +class officeforms extends base { + /** + * Get the replacement oembed HTML. + * + * @param array $matched Matched URL. + * @return string The replacement text/HTML. + */ + public function get_replacement($matched) { + if (!empty($matched)) { + $url = $matched[1].$matched[3].'/'.$matched[4].'/ResponsePage.aspx?id='.$matched[6].'&embed=true'; + $embedhtml = $this->getembedhtml($url); + return $embedhtml; + } + return $matched[0]; + } + + /** + * Filter the text. + * + * @param string $text Incoming text. + * @return string Filtered text. + */ + public function filter($text) { + $search = '/]*href="(https?:\/\/(www\.)?)(forms\.office\.com)\/(.+?)\/(DesignPage\.aspx)#FormId=(.+?)"(.*?)>(.*?)<\/a>/is'; + return preg_replace_callback($search, [$this, 'get_replacement'], $text); + } + + /** + * Return the HTML content to be embedded. + * + * @param string $embedurl Additional parameters to include in the embed URL. + * @return string The HTML content to be embedded in the page. + */ + private function getembedhtml($embedurl) { + $iframeattrs = [ + 'src' => $embedurl, + 'height' => '768px', + 'width' => '99%', + 'frameborder' => '0', + 'marginwidth' => '0', + 'marginheight' => '0', + 'style' => 'border: none; max-width: 100%; max-height: 100vh', + 'allowfullscreen' => 'true', + 'webkitallowfullscreen' => 'true', + 'mozallowfullscreen' => 'true', + 'msallowfullscreen' => 'true', + ]; + return \html_writer::tag('iframe', ' ', $iframeattrs); + } +} diff --git a/filter.php b/filter.php index 67f3b11..366f0a2 100644 --- a/filter.php +++ b/filter.php @@ -163,7 +163,7 @@ public function filter($text, array $options = array()) { */ public static function get_supported_providers() { return [ - 'docsdotcom', 'powerbi' + 'docsdotcom', 'powerbi', 'officeforms' ]; } } diff --git a/lang/en/filter_oembed.php b/lang/en/filter_oembed.php index 8b52b16..872bfa1 100644 --- a/lang/en/filter_oembed.php +++ b/lang/en/filter_oembed.php @@ -44,3 +44,4 @@ $string['o365video'] = 'Office 365 Video'; $string['provider_docsdotcom'] = 'Docs.com'; $string['provider_powerbi'] = 'Power BI'; +$string['provider_officeforms'] = 'Forms';