Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 130 additions & 11 deletions blocks/microsoft/block_microsoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ protected function get_course_content() {
$items[] = html_writer::link(
$url,
$resourcename,
['target' => '_blank', 'class' => 'servicelink block_microsoft_' . $feature]
[
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_' . $feature,
]
);
}

Expand Down Expand Up @@ -342,7 +346,11 @@ protected function get_user_content_connected() {
$spsite = \local_o365\rest\sharepoint::get_tokenresource();
if (!empty($spsite)) {
$spurl = $spsite . '/' . $coursespsite->siteurl;
$spattrs = ['class' => 'servicelink block_microsoft_sharepoint', 'target' => '_blank'];
$spattrs = [
'class' => 'servicelink block_microsoft_sharepoint',
'target' => '_blank',
'rel' => 'noopener noreferrer',
];
$items[] = html_writer::link($spurl, $sharepointstr, $spattrs);
$items[] = '<hr/>';
}
Expand All @@ -352,22 +360,34 @@ protected function get_user_content_connected() {

// My Delve URL.
if (!empty($delveurl)) {
$delveattrs = ['class' => 'servicelink block_microsoft_delve', 'target' => '_blank'];
$delveattrs = [
'class' => 'servicelink block_microsoft_delve',
'target' => '_blank',
'rel' => 'noopener noreferrer',
];
$delvestr = get_string('linkmydelve', 'block_microsoft');
$items[] = html_writer::link($delveurl, $delvestr, $delveattrs);
}

// My email.
if (!empty($this->globalconfig->settings_showemail)) {
$emailurl = 'https://outlook.office365.com/';
$emailattrs = ['class' => 'servicelink block_microsoft_outlook', 'target' => '_blank'];
$emailattrs = [
'class' => 'servicelink block_microsoft_outlook',
'target' => '_blank',
'rel' => 'noopener noreferrer',
];
$emailstr = get_string('linkemail', 'block_microsoft');
$items[] = html_writer::link($emailurl, $emailstr, $emailattrs);
}

// My Forms URL.
if (!empty($this->globalconfig->settings_showmyforms)) {
$formsattrs = ['class' => 'servicelink block_microsoft_forms', 'target' => '_blank'];
$formsattrs = [
'class' => 'servicelink block_microsoft_forms',
'target' => '_blank',
'rel' => 'noopener noreferrer',
];
$formsstr = get_string('linkmyforms', 'block_microsoft');
$formsurl = get_string('settings_showmyforms_default', 'block_microsoft');
if (!empty($odburl)) {
Expand All @@ -382,6 +402,7 @@ protected function get_user_content_connected() {
if (!empty($this->globalconfig->settings_showonedrive)) {
$odbattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_onedrive',
];
$stronedrive = get_string('linkonedrive', 'block_microsoft');
Expand All @@ -393,14 +414,22 @@ protected function get_user_content_connected() {
// Microsoft Stream (on SharePoint).
if (!empty($this->globalconfig->settings_showmsstreamonsharepoint)) {
$streamurl = 'https://www.microsoft365.com/launch/stream';
$streamattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_msstream'];
$streamattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_msstream',
];
$items[] = html_writer::link($streamurl, get_string('linkmsstream', 'block_microsoft'), $streamattrs);
}

// Microsoft Stream (Classic).
if (!empty($this->globalconfig->settings_showmsstream)) {
$streamclassicurl = 'https://web.microsoftstream.com/?noSignUpCheck=1';
$streamclassicattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_msstream'];
$streamclassicattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_msstream',
];
$items[] = html_writer::link(
$streamclassicurl,
get_string('linkmsstreamclassic', 'block_microsoft'),
Expand All @@ -411,17 +440,99 @@ protected function get_user_content_connected() {
// Microsoft Teams.
if (!empty($this->globalconfig->settings_showmsteams)) {
$teamsurl = 'https://teams.microsoft.com';
$teamsattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_msteams'];
$teamsattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_msteams',
];
$items[] = html_writer::link($teamsurl, get_string('linkmsteams', 'block_microsoft'), $teamsattrs);
}

// My Sways.
if (!empty($this->globalconfig->settings_showsways) && !empty($userupn)) {
$swayurl = 'https://www.sway.com/my?auth_pvr=OrgId&auth_upn=' . $userupn;
$swayattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_sway'];
$swayattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_sway',
];
$items[] = html_writer::link($swayurl, get_string('linksways', 'block_microsoft'), $swayattrs);
}

// Additional Microsoft 365 and Viva apps, hidden by default.
$microsoft365apps = [
'word' => 'https://www.office.com/launch/word',
'excel' => 'https://www.office.com/launch/excel',
'powerpoint' => 'https://www.office.com/launch/powerpoint',
'vivaengage' => 'https://engage.cloud.microsoft/',
'vivaglint' => 'https://glint.cloud.microsoft/',
'vivagoals' => 'https://goals.microsoft.com',
'vivainsights' => 'https://insights.cloud.microsoft',
'vivapulse' => 'https://pulse.viva.cloud.microsoft/',
'linkedin' => 'https://www.linkedin.com/',
];
foreach ($microsoft365apps as $appkey => $appurl) {
if (!empty($this->globalconfig->{'settings_show' . $appkey})) {
$appattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_' . $appkey,
];
$items[] = html_writer::link($appurl, get_string('link' . $appkey, 'block_microsoft'), $appattrs);
}
}

// Viva Amplify. The URL is tenant-specific and configured by the site administrator.
if (!empty($this->globalconfig->settings_showvivaamplify)) {
$vivaamplifyurl = $this->globalconfig->settings_vivaamplifyurl ?? '';
if (!empty($vivaamplifyurl) && preg_match(BLOCK_MICROSOFT_VIVAAMPLIFY_URL_REGEX, $vivaamplifyurl)) {
$vivaamplifyattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_vivaamplify',
];
$items[] = html_writer::link(
$vivaamplifyurl,
get_string('linkvivaamplify', 'block_microsoft'),
$vivaamplifyattrs
);
}
}

// Viva Connections. The URL is tenant-specific and configured by the site administrator.
if (!empty($this->globalconfig->settings_showvivaconnections)) {
$vivaconnectionsurl = $this->globalconfig->settings_vivaconnectionsurl ?? '';
if (!empty($vivaconnectionsurl) && preg_match(BLOCK_MICROSOFT_VIVACONNECTIONS_URL_REGEX, $vivaconnectionsurl)) {
$vivaconnectionsattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_vivaconnections',
];
$items[] = html_writer::link(
$vivaconnectionsurl,
get_string('linkvivaconnections', 'block_microsoft'),
$vivaconnectionsattrs
);
}
}

// Viva Learning. The URL is tenant-specific and configured by the site administrator.
if (!empty($this->globalconfig->settings_showvivalearning)) {
$vivalearningurl = $this->globalconfig->settings_vivalearningurl ?? '';
if (!empty($vivalearningurl) && preg_match(BLOCK_MICROSOFT_VIVALEARNING_URL_REGEX, $vivalearningurl)) {
$vivalearningattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_vivalearning',
];
$items[] = html_writer::link(
$vivalearningurl,
get_string('linkvivalearning', 'block_microsoft'),
$vivalearningattrs
);
}
}

// Configure Outlook Sync.
if (!empty($this->globalconfig->settings_showoutlooksync)) {
$outlookurl = new url('/local/o365/ucp.php?action=calendar');
Expand Down Expand Up @@ -482,7 +593,11 @@ protected function get_user_content_connected() {

if ($hasaccesstocourserequest && !empty($this->globalconfig->settings_courserequest)) {
$courserequesturl = new url('/local/o365/courserequest.php');
$courserequestattrs = ['target' => '_blank', 'class' => 'servicelink block_microsoft_courserequest'];
$courserequestattrs = [
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => 'servicelink block_microsoft_courserequest',
];
$courserequeststr = get_string('linkcourserequest', 'block_microsoft');
$items[] = html_writer::link($courserequesturl, $courserequeststr, $courserequestattrs);
}
Expand Down Expand Up @@ -542,7 +657,11 @@ protected function get_content_o365download() {
html_writer::link(
$url,
$str,
['class' => 'servicelink block_microsoft_downloado365', 'target' => '_blank']
[
'class' => 'servicelink block_microsoft_downloado365',
'target' => '_blank',
'rel' => 'noopener noreferrer',
]
),
];
}
Expand Down
81 changes: 81 additions & 0 deletions blocks/microsoft/classes/admin_setting_required_url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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/>.

/**
* Admin setting for a URL that becomes mandatory once a companion checkbox setting is enabled.
*
* @package block_microsoft
* @author Lai Wei <lai.wei@enovation.ie>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2026 onwards Microsoft, Inc. (http://microsoft.com/)
*/

/**
* Admin setting for a URL that becomes mandatory once a companion checkbox setting is enabled.
*
Comment thread
weilai-irl marked this conversation as resolved.
* This must only be required (directly or indirectly) from settings.php, since admin_setting_configtext
* is only guaranteed to be loaded in the admin settings context.
*/
class block_microsoft_admin_setting_required_url extends admin_setting_configtext {
/** @var admin_setting_configcheckbox The checkbox setting that makes this URL mandatory when checked. */
protected $requiredifsetting;

/**
* Constructor.
*
* @param string $name Setting name, in the 'component/settingname' format.
* @param string $visiblename Localised setting name.
* @param string $description Localised setting description.
* @param string $defaultsetting Default value.
* @param string $paramtype PARAM_XXX type, or a '/regex/' string.
* @param admin_setting_configcheckbox $requiredifsetting The checkbox setting that makes this URL mandatory
* when checked.
*/
public function __construct(
$name,
$visiblename,
$description,
$defaultsetting,
$paramtype,
admin_setting_configcheckbox $requiredifsetting
) {
parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype);
$this->requiredifsetting = $requiredifsetting;
}

/**
* Validate the submitted URL, also requiring a non-empty value when the companion checkbox is checked.
*
* @param string $data
* @return string|true True if valid, otherwise an error message.
*/
public function validate($data) {
$parentvalidation = parent::validate($data);
if ($parentvalidation !== true) {
return $parentvalidation;
}

$checkboxname = $this->requiredifsetting->get_full_name();
$checkboxvalue = optional_param($checkboxname, $this->requiredifsetting->no, PARAM_RAW);
$ischecked = ((string) $checkboxvalue === (string) $this->requiredifsetting->yes);

if ($ischecked && trim((string) $data) === '') {
return get_string('error_urlrequiredwhenenabled', 'block_microsoft');
}

return true;
}
}
45 changes: 45 additions & 0 deletions blocks/microsoft/lang/en/block_microsoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$string['pluginname'] = 'Microsoft block';
$string['contactadmin'] = 'Contact administrator for more information.';
$string['error_nomoodlenotebook'] = 'Could not find your Moodle notebook.';
$string['error_urlrequiredwhenenabled'] = 'This URL must be configured, since the "Show" option above is enabled.';
$string['linkonedrive'] = 'My OneDrive';
$string['linkonenote'] = 'My OneNote Notebook';
$string['linksways'] = 'My Sways';
Expand Down Expand Up @@ -64,6 +65,20 @@
$string['connecttoo365'] = 'Connect to Microsoft 365';
$string['install_office'] = 'Install Office';

// Microsoft 365 and Viva apps.
$string['linkword'] = 'Word';
$string['linkexcel'] = 'Excel';
$string['linkpowerpoint'] = 'PowerPoint';
$string['linkvivaengage'] = 'Viva Engage';
$string['linkvivaamplify'] = 'Viva Amplify';
$string['linkvivaconnections'] = 'Viva Connections';
$string['linkvivaglint'] = 'Viva Glint';
$string['linkvivagoals'] = 'Viva Goals';
$string['linkvivainsights'] = 'Viva Insights';
$string['linkvivalearning'] = 'Viva Learning';
$string['linkvivapulse'] = 'Viva Pulse';
$string['linklinkedin'] = 'Microsoft LinkedIn';

// Configuration settings.
$string['settings_showemail'] = 'Show "My Email"';
$string['settings_showemail_desc'] = 'Enable or disable the "My Email" link in the block.';
Expand Down Expand Up @@ -102,6 +117,36 @@
$string['settings_geto365link'] = 'Install Office download URL';
$string['settings_geto365link_desc'] = 'The URL to use for the "Install Office" link.';
$string['settings_geto365link_default'] = 'https://portal.office.com/OLS/MySoftware.aspx';
$string['settings_showword'] = 'Show "Word"';
$string['settings_showword_desc'] = 'Enable or disable the "Word" link in the block.';
$string['settings_showexcel'] = 'Show "Excel"';
$string['settings_showexcel_desc'] = 'Enable or disable the "Excel" link in the block.';
$string['settings_showpowerpoint'] = 'Show "PowerPoint"';
$string['settings_showpowerpoint_desc'] = 'Enable or disable the "PowerPoint" link in the block.';
$string['settings_showvivaengage'] = 'Show "Viva Engage"';
$string['settings_showvivaengage_desc'] = 'Enable or disable the "Viva Engage" link in the block.';
$string['settings_showvivaamplify'] = 'Show "Viva Amplify"';
$string['settings_showvivaamplify_desc'] = 'Enable or disable the "Viva Amplify" link in the block. <br /><b>Note:</b> The Viva Amplify URL below must also be configured for the link to be shown.';
$string['settings_vivaamplifyurl'] = 'Viva Amplify URL';
$string['settings_vivaamplifyurl_desc'] = 'The URL of your organization\'s Viva Amplify experience, as configured by your Microsoft 365 tenant administrator, e.g. https://amplify.microsoft.com/. Only URLs on an amplify.microsoft.com or amplify.cloud.microsoft domain are accepted.';
$string['settings_showvivaconnections'] = 'Show "Viva Connections"';
$string['settings_showvivaconnections_desc'] = 'Enable or disable the "Viva Connections" link in the block. <br /><b>Note:</b> The Viva Connections URL below must also be configured for the link to be shown.';
$string['settings_vivaconnectionsurl'] = 'Viva Connections URL';
$string['settings_vivaconnectionsurl_desc'] = 'The URL of your organization\'s Viva Connections experience, as configured by your Microsoft 365 tenant administrator. This is typically your SharePoint home site, e.g. https://yourtenant.sharepoint.com/sites/yourhomesite. Only URLs on a *.sharepoint.com (or sovereign cloud equivalent) domain are accepted.';
$string['settings_showvivaglint'] = 'Show "Viva Glint"';
$string['settings_showvivaglint_desc'] = 'Enable or disable the "Viva Glint" link in the block.';
$string['settings_showvivagoals'] = 'Show "Viva Goals"';
$string['settings_showvivagoals_desc'] = 'Enable or disable the "Viva Goals" link in the block.';
$string['settings_showvivainsights'] = 'Show "Viva Insights"';
$string['settings_showvivainsights_desc'] = 'Enable or disable the "Viva Insights" link in the block.';
$string['settings_showvivalearning'] = 'Show "Viva Learning"';
$string['settings_showvivalearning_desc'] = 'Enable or disable the "Viva Learning" link in the block. <br /><b>Note:</b> The Viva Learning URL below must also be configured for the link to be shown.';
$string['settings_vivalearningurl'] = 'Viva Learning URL';
$string['settings_vivalearningurl_desc'] = 'The URL of your organization\'s Viva Learning experience, as configured by your Microsoft 365 tenant administrator, e.g. https://web.viva.microsoft.com/learning. Only URLs on a viva.microsoft.com or cloud.microsoft domain are accepted.';
$string['settings_showvivapulse'] = 'Show "Viva Pulse"';
$string['settings_showvivapulse_desc'] = 'Enable or disable the "Viva Pulse" link in the block.';
$string['settings_showlinkedin'] = 'Show "Microsoft LinkedIn"';
$string['settings_showlinkedin_desc'] = 'Enable or disable the "Microsoft LinkedIn" link in the block.';

$string['linkmydelve'] = 'My Delve';
$string['linkmyforms'] = 'My Forms';
Expand Down
Loading