Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param int $repositoryid repository instance id
  * @param int|stdClass $context a context id or context object
  * @param array $options repository options
  * @param int $readonly indicate this repo is readonly or not
  */
 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0)
 {
     parent::__construct($repositoryid, $context, $options, $readonly);
     $this->httpclient = new \local_o365\httpclient();
     $this->clientdata = \local_o365\oauth2\clientdata::instance_from_oidc();
     $this->onedriveconfigured = \local_o365\rest\onedrive::is_configured();
     $this->unifiedconfigured = \local_o365\rest\unified::is_configured();
     $this->sharepointconfigured = \local_o365\rest\sharepoint::is_configured();
 }
/**
 * 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];
}