Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
MSFTMPP-545: Support for Microsoft Forms in oEmbed plug-in and additi…
Browse files Browse the repository at this point in the history
…on of 'My Forms' to the Microsoft Block
  • Loading branch information
Aashay authored and James McQuillan committed Jul 14, 2016
1 parent 4a360dd commit cb792e8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
77 changes: 77 additions & 0 deletions classes/provider/officeforms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: 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.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* @package filter_oembed
* @author Aashay Zajriya<[email protected]>
* @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 = '/<a\s[^>]*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);
}
}
2 changes: 1 addition & 1 deletion filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function filter($text, array $options = array()) {
*/
public static function get_supported_providers() {
return [
'docsdotcom', 'powerbi'
'docsdotcom', 'powerbi', 'officeforms'
];
}
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/filter_oembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
$string['o365video'] = 'Office 365 Video';
$string['provider_docsdotcom'] = 'Docs.com';
$string['provider_powerbi'] = 'Power BI';
$string['provider_officeforms'] = 'Forms';

0 comments on commit cb792e8

Please sign in to comment.