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
52 changes: 52 additions & 0 deletions src/Core/InlinePresentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/

namespace BigBlueButton\Core;

use BigBlueButton\Util\SimpleXMLElementExtended;

class InlinePresentation extends Presentation
{
public function __construct(private readonly string $content, string $filename)
{
$this->filename = $filename;
}

public function getArrayKey(): string
{
return $this->filename;
}

public function addDocumentToXML(SimpleXMLElementExtended $module): ?SimpleXMLElementExtended
{
$document = parent::addDocumentToXML($module);

/* @phpstan-ignore-next-line */
$document[0] = base64_encode($this->content);

if (isset($this->filename)) {
$document->addAttribute('name', $this->filename);
}

return $document;
}
}
105 changes: 105 additions & 0 deletions src/Core/Presentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/

namespace BigBlueButton\Core;

use BigBlueButton\Util\SimpleXMLElementExtended;

abstract class Presentation
{
protected ?string $filename = null;

protected ?bool $current = null;

protected ?bool $downloadable = null;

protected ?bool $removable = null;

public function addDocumentToXML(SimpleXMLElementExtended $module): ?SimpleXMLElementExtended
{
$document = $module->addChild('document');

if (\is_bool($this->downloadable)) {
$document->addAttribute('downloadable', $this->downloadable ? 'true' : 'false');
}

if (\is_bool($this->removable)) {
$document->addAttribute('removable', $this->removable ? 'true' : 'false');
}

if (\is_bool($this->current)) {
$document->addAttribute('current', $this->current ? 'true' : 'false');
}

return $document;
}

abstract public function getArrayKey(): string;

public function getFilename(): ?string
{
return $this->filename;
}

public function setFilename(string $filename): self
{
$this->filename = $filename;

return $this;
}

public function getCurrent(): ?bool
{
return $this->current;
}

public function setCurrent(bool $current): self
{
$this->current = $current;

return $this;
}

public function getDownloadable(): ?bool
{
return $this->downloadable;
}

public function setDownloadable(bool $downloadable): self
{
$this->downloadable = $downloadable;

return $this;
}

public function getRemovable(): ?bool
{
return $this->removable;
}

public function setRemovable(bool $removable): self
{
$this->removable = $removable;

return $this;
}
}
49 changes: 49 additions & 0 deletions src/Core/UrlPresentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
*
* Copyright (c) 2016-2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*/

namespace BigBlueButton\Core;

use BigBlueButton\Util\SimpleXMLElementExtended;

class UrlPresentation extends Presentation
{
public function __construct(private readonly string $url)
{
}

public function getArrayKey(): string
{
return $this->url;
}

public function addDocumentToXML(SimpleXMLElementExtended $module): ?SimpleXMLElementExtended
{
$document = parent::addDocumentToXML($module);
$document->addAttribute('url', $this->url);

if (isset($this->filename)) {
$document->addAttribute('filename', $this->filename);
}

return $document;
}
}
50 changes: 30 additions & 20 deletions src/Parameters/CreateMeetingParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

namespace BigBlueButton\Parameters;

use BigBlueButton\Core\InlinePresentation;
use BigBlueButton\Core\Presentation;
use BigBlueButton\Core\UrlPresentation;
use BigBlueButton\Enum\Feature;
use BigBlueButton\Enum\GuestPolicy;
use BigBlueButton\Enum\MeetingLayout;
Expand Down Expand Up @@ -247,9 +250,7 @@ class CreateMeetingParameters extends MetaParameters
protected ?bool $allowOverrideClientSettingsOnCreateCall = null;
protected ?string $clientSettingsOverride = null;

/**
* @var array<string,string>
*/
/** @var array<string,Presentation> */
private array $presentations = [];

public function __construct(protected string $meetingID, protected string $name)
Expand Down Expand Up @@ -351,12 +352,30 @@ public function setGuestPolicyAlwaysAccept(): self
return $this;
}

public function addPresentation(string $nameOrUrl, ?string $content = null, ?string $filename = null): self
/**
* @return $this
*/
public function addPresentation(string|Presentation $nameOrUrlOrPresentation, ?string $content = null, ?string $filename = null): self
{
if (!$filename) {
$this->presentations[$nameOrUrl] = !$content ?: base64_encode($content);
if ($nameOrUrlOrPresentation instanceof Presentation) {
$this->presentations[$nameOrUrlOrPresentation->getArrayKey()] = $nameOrUrlOrPresentation;

return $this;
}

@trigger_error(\sprintf('Calling addPresentation in "%s" with any parameters other than a single Presentation object is deprecated and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED);

if ($content) {
$presentation = new InlinePresentation($content, $nameOrUrlOrPresentation);
$this->presentations[$presentation->getArrayKey()] = $presentation;
} else {
$this->presentations[$nameOrUrl] = $filename;
$presentation = new UrlPresentation($nameOrUrlOrPresentation);

if ($filename != null) {
$presentation->setFilename($filename);
}

$this->presentations[$presentation->getArrayKey()] = $presentation;
}

return $this;
Expand All @@ -382,7 +401,7 @@ public function addBreakoutRoomsGroup(string $id, ?string $name, array $roster):
return $this;
}

/** @return array<string,string> */
/** @return array<string,Presentation> */
public function getPresentations(): array
{
return $this->presentations;
Expand Down Expand Up @@ -423,18 +442,9 @@ public function addPresentationsModule(SimpleXMLElementExtended $xml): void
$module = $xml->addChild('module');
$module->addAttribute('name', 'presentation');

foreach ($this->presentations as $nameOrUrl => $content) {
if (str_starts_with($nameOrUrl, 'http')) {
$presentation = $module->addChild('document');
$presentation->addAttribute('url', $nameOrUrl);
if (\is_string($content)) {
$presentation->addAttribute('filename', $content);
}
} else {
$document = $module->addChild('document');
$document->addAttribute('name', $nameOrUrl);
/* @phpstan-ignore-next-line */
$document[0] = $content;
foreach ($this->presentations as $data) {
if ($data instanceof Presentation) {
$data->addDocumentToXML($module);
}
}
}
Expand Down
50 changes: 31 additions & 19 deletions src/Parameters/InsertDocumentParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,46 @@

namespace BigBlueButton\Parameters;

use BigBlueButton\Core\Presentation;
use BigBlueButton\Core\UrlPresentation;
use BigBlueButton\Util\SimpleXMLElementExtended;

/**
* @method string getMeetingID()
* @method $this setMeetingID(string $id)
*/
final class InsertDocumentParameters extends MetaParameters
{
/** @var array<string,array{filename: string, downloadable: bool|null, removable: bool|null}> */
/** @var array<string,Presentation> */
private array $presentations = [];

public function __construct(protected string $meetingID)
{
}

public function addPresentation(string $url, string $filename, ?bool $downloadable = null, ?bool $removable = null): self
public function addPresentation(string|Presentation $urlOrPresentation, ?string $filename = null, ?bool $downloadable = null, ?bool $removable = null): self
{
$this->presentations[$url] = [
'filename' => $filename,
'downloadable' => $downloadable,
'removable' => $removable,
];
if ($urlOrPresentation instanceof Presentation) {
$this->presentations[$urlOrPresentation->getArrayKey()] = $urlOrPresentation;

return $this;
}

@trigger_error(\sprintf('Calling addPresentation in "%s" with any parameters other than a single Presentation object is deprecated and will throw an exception in 7.0.', self::class), \E_USER_DEPRECATED);

$presentation = new UrlPresentation($urlOrPresentation);

if ($filename !== null) {
$presentation->setFilename($filename);
}
if ($downloadable !== null) {
$presentation->setDownloadable($downloadable);
}
if ($removable !== null) {
$presentation->setRemovable($removable);
}

$this->presentations[$presentation->getArrayKey()] = $presentation;

return $this;
}
Expand All @@ -57,21 +77,13 @@ public function getPresentationsAsXML(): string|false
$result = '';

if (!empty($this->presentations)) {
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><modules/>');
$xml = new SimpleXMLElementExtended('<?xml version="1.0" encoding="UTF-8"?><modules/>');
$module = $xml->addChild('module');
$module->addAttribute('name', 'presentation');

foreach ($this->presentations as $url => $content) {
$presentation = $module->addChild('document');
$presentation->addAttribute('url', $url);
$presentation->addAttribute('filename', $content['filename']);

if (\is_bool($content['downloadable'])) {
$presentation->addAttribute('downloadable', $content['downloadable'] ? 'true' : 'false');
}

if (\is_bool($content['removable'])) {
$presentation->addAttribute('removable', $content['removable'] ? 'true' : 'false');
foreach ($this->presentations as $content) {
if ($content instanceof Presentation) {
$content->addDocumentToXML($module);
}
}
$result = $xml->asXML();
Expand Down
Loading