/** * Validate that a given SharePoint url is accessible with the given client data. * * @param string $uncleanurl Uncleaned, unvalidated URL to check. * @param \local_o365\oauth2\clientdata $clientdata oAuth2 Credentials * @param \local_o365\httpclientinterface $httpclient An HttpClient to use for transport. * @return string One of: * "invalid" : The URL is not a usable SharePoint url. * "notempty" : The URL is a usable SharePoint url, and the SharePoint site exists. * "valid" : The URL is a usable SharePoint url, and the SharePoint site doesn't exist. */ public static function validate_site($uncleanurl, \local_o365\oauth2\clientdata $clientdata, \local_o365\httpclientinterface $httpclient) { $siteinfo = static::parse_site_url($uncleanurl); if (empty($siteinfo)) { return 'invalid'; } $token = \local_o365\oauth2\systemtoken::get_for_new_resource(null, $siteinfo['resource'], $clientdata, $httpclient); if (empty($token)) { return 'invalid'; } $sharepoint = new \local_o365\rest\sharepoint($token, $httpclient); $sharepoint->override_resource($siteinfo['resource']); // Try to get the / site's info to validate we can communicate with this parent Sharepoint site. try { $mainsiteinfo = $sharepoint->get_site(); } catch (\Exception $e) { return 'invalid'; } if ($siteinfo['subsiteurl'] === '/') { // We just successfully got the / site's info, so if we're going to use that, it's obviously not empty. return 'notempty'; } $subsiteexists = $sharepoint->site_exists($siteinfo['subsiteurl']); return $subsiteexists === true ? 'notempty' : 'valid'; }
/** * Looks for links pointing to Office 365 Video content and processes them. * * @param $link HTML tag containing a link * @return string HTML content after processing. */ function filter_oembed_o365videocallback($link) { if (empty($link[3])) { return $link[0]; } $link[3] = preg_replace("/&/", "&", $link[3]); $values = array(); parse_str($link[3], $values); if (empty($values['chid']) || empty($values['vid'])) { return $link[0]; } if (!\local_o365\rest\sharepoint::is_configured()) { \local_o365\utils::debug('filter_oembed share point is not configured', 'filter_oembed_o365videocallback'); return $link[0]; } try { $spresource = \local_o365\rest\sharepoint::get_resource(); if (!empty($spresource)) { $httpclient = new \local_o365\httpclient(); $clientdata = \local_o365\oauth2\clientdata::instance_from_oidc(); $sptoken = \local_o365\oauth2\systemtoken::instance(null, $spresource, $clientdata, $httpclient); if (!empty($sptoken)) { $sharepoint = new \local_o365\rest\sharepoint($sptoken, $httpclient); // Retrieve api url for video service. $url = $sharepoint->videoservice_discover(); if (!empty($url)) { $sharepoint->override_resource($url); $width = 640; if (!empty($values['width'])) { $width = $values['width']; } $height = 360; if (!empty($values['height'])) { $height = $values['height']; } // Retrieve embed code. return $sharepoint->get_video_embed_code($values['chid'], $values['vid'], $width, $height); } } } } catch (\Exception $e) { \local_o365\utils::debug('filter_oembed share point execption: ' . $e->getMessage(), 'filter_oembed_o365videocallback'); } return $link[0]; }