From be515f5150f20c773371f680efad58f2d0fcaaf0 Mon Sep 17 00:00:00 2001 From: Benjamin Peter Date: Sat, 9 Dec 2017 23:44:47 +0100 Subject: Added multple translation tracks with configurable endpoints and labels --- index.php | 12 ++++--- model/Conferences.php | 38 ++++++++++++++++------ model/Room.php | 53 ++++++++++++++++++++++++++----- model/RoomSelection.php | 16 ++++++---- model/Stream.php | 12 +++++-- template/assemblies/switcher/audio.phtml | 20 +++++++----- template/assemblies/switcher/slides.phtml | 12 ++++--- template/assemblies/switcher/video.phtml | 28 +++++++++------- view/room.php | 10 ++++-- 9 files changed, 142 insertions(+), 59 deletions(-) diff --git a/index.php b/index.php index 3c814f9..43a704e 100644 --- a/index.php +++ b/index.php @@ -285,12 +285,12 @@ try { require('view/room.php'); } - else if(preg_match('@^([^/]+)/translated$@', $route, $m)) + else if(preg_match('@^([^/]+)/i18n/([^/]+)$@', $route, $m)) { $_GET = array( 'room' => $m[1], 'selection' => '', - 'language' => 'translated', + 'language' => $m[2], ); require('view/room.php'); } @@ -305,17 +305,19 @@ try { require('view/room.php'); } - else if(preg_match('@^([^/]+)/(sd|audio|slides|dash)/translated$@', $route, $m)) + else if(preg_match('@^([^/]+)/(sd|audio|slides|dash)/i18n/([^/]+)$@', $route, $m)) { $_GET = array( 'room' => $m[1], 'selection' => $m[2], - 'language' => 'translated', + 'language' => $m[3], ); require('view/room.php'); } - else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|translated|stereo)(/no-autoplay)?$@', $route, $m)) + // TODO use dynamic i18n parameter + // TODO change to no-autoplay query parameter? + else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|translated|translated2|stereo)(/no-autoplay)?$@', $route, $m)) { $_GET = array( 'room' => $m[1], diff --git a/model/Conferences.php b/model/Conferences.php index f7276ac..eb07327 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -72,16 +72,34 @@ class Conferences return in_array($mandator, Conferences::listConferences()); } - public static function loadConferenceConfig($mandator) { - $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; - $config = include($configfile); - - if(!is_array($config)) { - throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); - } - - return $config; - } + public static function loadConferenceConfig($mandator) { + $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; + $config = include($configfile); + + if(!is_array($config)) { + throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); + } + + // Allow setting TRANSLATION simply to true and fill in default values for uniformity + $rooms = $config['ROOMS']; + foreach ($rooms as $slug => $room) { + if (!isset($room['TRANSLATION'])) { + $config['ROOMS'][$slug]['TRANSLATION'] = []; + } + elseif (! is_array($room['TRANSLATION'])) { + if ($room['TRANSLATION'] === true) { + $config['ROOMS'][$slug]['TRANSLATION'] = [[ + 'endpoint' => 'translated', + 'label' => 'Translated' + ]]; + } + else { + $config['ROOMS'][$slug]['TRANSLATION'] = []; + } + } + } + return $config; + } public static function getConference($mandator) { return new Conference(Conferences::loadConferenceConfig($mandator), $mandator); diff --git a/model/Room.php b/model/Room.php index 4b251cd..56dab4c 100644 --- a/model/Room.php +++ b/model/Room.php @@ -175,10 +175,40 @@ class Room return 'Adaptive multi-format-multi-bitrate-Stream to rule the World!!1elf'; } - public function hasTranslation() { + public function getTranslations() { return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); } + private function getTranslationEndpoints() { + return array_map( + function ($translation) { + return $translation['endpoint']; + }, + $this->getTranslations() + ); + } + + private function isTranslationEndpoint($endpoint) { + return in_array($endpoint, $this->getTranslationEndpoints()); + } + + private function findTranslationLabel($language) { + foreach($this->getTranslations() as $translation) { + if ($translation['endpoint'] === $language) { + return $translation['label']; + } + } + return null; + } + + public function hasTranslation() { + return count($this->getTranslations()) > 0; + } + + public function isValidLanguage($language) { + return ($language === 'native' || $this->isTranslationEndpoint($language)); + } + public function getSelectionNames() { $selections = array(); @@ -284,8 +314,9 @@ class Room foreach ($selections as $selection) { $streams[] = $this->createStreamObject($selection, 'native'); - if($this->hasTranslation()) - $streams[] = $this->createStreamObject($selection, 'translated'); + foreach ($this->getTranslations() as $translation) { + $streams[] = $this->createStreamObject($selection, $translation['endpoint'], $translation['label']); + } } return $streams; @@ -305,17 +336,23 @@ class Room if(!in_array($selection, $selections)) throw new NotFoundException('Selection '.$selection.' in Room '.$this->getSlug()); - if($language == 'translated' && !$this->hasTranslation()) - throw new NotFoundException('Translated Streams of Room '.$this->getSlug()); + $translation_label = null; + if (substr($language, 0, strlen('native')) !== 'native') { + if (!$this->hasTranslation()) { + throw new NotFoundException('Translated Streams of Room '.$this->getSlug()); + } + + $translation_label = $this->findTranslationLabel($language); + } - return $this->createStreamObject($selection, $language); + return $this->createStreamObject($selection, $language, $translation_label); } - public function createStreamObject($selection, $language = 'native') + public function createStreamObject($selection, $language = 'native', $languageLabel = null) { if($language == 'native' && $this->hasStereo()) $language = 'stereo'; - return new Stream($this, $selection, $language); + return new Stream($this, $selection, $language, $languageLabel); } } diff --git a/model/RoomSelection.php b/model/RoomSelection.php index 9211c31..a83b5c6 100644 --- a/model/RoomSelection.php +++ b/model/RoomSelection.php @@ -18,20 +18,24 @@ class RoomSelection return $this->selection; } - public function getLink() - { + private function getSelectionPath() { $path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()]; $selection = $this->getRoom()->getSelectionNames(); - if($selection[0] != $this->getSelection()) + if ($selection[0] != $this->getSelection()) $path[] = $this->getSelection(); - return joinpath($path).url_params(); + return joinpath($path); + } + + public function getLink() + { + return $this->getSelectionPath() . url_params(); } - public function getTranslatedLink() + public function getTranslatedLink($translation_endpoint) { - return joinpath([$this->getLink(), 'translated']); + return joinpath([$this->getSelectionPath(), 'i18n', $translation_endpoint]) . url_params(); } public function getDisplay() diff --git a/model/Stream.php b/model/Stream.php index daed17f..a4dcf72 100644 --- a/model/Stream.php +++ b/model/Stream.php @@ -2,11 +2,12 @@ class Stream { - public function __construct(Room $room, $selection, $language) + public function __construct(Room $room, $selection, $language, $translation_label = null) { $this->room = $room; $this->selection = $selection; $this->language = $language; + $this->translation_label = (empty($translation_label)) ? $language : $translation_label; } public function getRoom() @@ -24,9 +25,14 @@ class Stream return $this->language; } + public function getTranslationLabel() + { + return $this->translation_label; + } + public function isTranslated() { - return $this->getLanguage() == 'translated'; + return !empty($this->getLanguage()) && $this->getLanguage() !== 'native'; } public function getVideoSize() @@ -98,7 +104,7 @@ class Stream } if($this->isTranslated()) - $display .= ' (Translation)'; + $display .= ' ('. $this->getTranslationLabel() .')'; return $display; } diff --git a/template/assemblies/switcher/audio.phtml b/template/assemblies/switcher/audio.phtml index 182572e..eab77fb 100644 --- a/template/assemblies/switcher/audio.phtml +++ b/template/assemblies/switcher/audio.phtml @@ -10,12 +10,14 @@ - native + Native - + getTranslations() as $translation): ?> + - translated + + @@ -39,12 +41,14 @@ - native - - - - translated + Native + getTranslations() as $translation): ?> + + + + + diff --git a/template/assemblies/switcher/slides.phtml b/template/assemblies/switcher/slides.phtml index dfbc26d..ba70c5f 100644 --- a/template/assemblies/switcher/slides.phtml +++ b/template/assemblies/switcher/slides.phtml @@ -10,12 +10,14 @@ - native - - - - translated + Native + getTranslations() as $translation): ?> + + + + + diff --git a/template/assemblies/switcher/video.phtml b/template/assemblies/switcher/video.phtml index 3877128..ae2815f 100644 --- a/template/assemblies/switcher/video.phtml +++ b/template/assemblies/switcher/video.phtml @@ -12,18 +12,20 @@ - native - - - - translated + Native + getTranslations() as $translation): ?> + + + + + - video + Video @@ -51,18 +53,20 @@ - native - - - - translated + Native + getTranslations() as $translation): ?> + + + + + - video + Video diff --git a/view/room.php b/view/room.php index d586248..c63f9ec 100644 --- a/view/room.php +++ b/view/room.php @@ -1,8 +1,14 @@ getRoom($_GET['room']); -$stream = $room->selectStream( - $_GET['selection'], $_GET['language']); +$selection = $_GET['selection']; +$language = $_GET['language']; + +if (! $room->isValidLanguage($language)) { + throw new NotFoundException('Language not found'); +} + +$stream = $room->selectStream($selection, $language); echo $tpl->render(array( 'page' => 'room', -- cgit v1.2.3 From eed207f8dfd68117715518c83fc32d3ae9e1e094 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Sun, 10 Dec 2017 18:02:48 +0100 Subject: Allowed multi translation for embedding, fixed autoplay option --- assets/js/lustiges-script.js | 8 +++++++- index.php | 4 +--- model/Room.php | 9 ++++++--- model/Stream.php | 4 +++- template/assemblies/embed-form.phtml | 2 +- view/embed.php | 17 +++++++++++++++-- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/assets/js/lustiges-script.js b/assets/js/lustiges-script.js index c14de15..22c4e04 100644 --- a/assets/js/lustiges-script.js +++ b/assets/js/lustiges-script.js @@ -374,7 +374,13 @@ $(function() { if(!originalsrc) originalsrc = $iframe.attr('src'); - var src = originalsrc + (autoplay ? '' : 'no-autoplay/'); + var src = originalsrc; + if (! autoplay) { + if (src.slice(-1) !== '/') { + src += '/'; + } + src += 'no-autoplay' + } $iframe.attr({width: selected[0], height: selected[1]}); $iframe.attr({src: src}); diff --git a/index.php b/index.php index 43a704e..a526b06 100644 --- a/index.php +++ b/index.php @@ -315,9 +315,7 @@ try { require('view/room.php'); } - // TODO use dynamic i18n parameter - // TODO change to no-autoplay query parameter? - else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|translated|translated2|stereo)(/no-autoplay)?$@', $route, $m)) + else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|stereo|[^/]+)(/no-autoplay)?$@', $route, $m)) { $_GET = array( 'room' => $m[1], diff --git a/model/Room.php b/model/Room.php index 56dab4c..27a8d97 100644 --- a/model/Room.php +++ b/model/Room.php @@ -337,9 +337,12 @@ class Room throw new NotFoundException('Selection '.$selection.' in Room '.$this->getSlug()); $translation_label = null; - if (substr($language, 0, strlen('native')) !== 'native') { - if (!$this->hasTranslation()) { - throw new NotFoundException('Translated Streams of Room '.$this->getSlug()); + if ($language !== 'native' && $language !== 'stereo') { + if (! $this->hasTranslation()) { + throw new NotFoundException('Translated Streams of Room '. $this->getSlug()); + } + if (! $this->isValidLanguage($language)) { + throw new NotFoundException('Selected translation'); } $translation_label = $this->findTranslationLabel($language); diff --git a/model/Stream.php b/model/Stream.php index a4dcf72..28cb0f8 100644 --- a/model/Stream.php +++ b/model/Stream.php @@ -32,7 +32,9 @@ class Stream public function isTranslated() { - return !empty($this->getLanguage()) && $this->getLanguage() !== 'native'; + return !empty($this->getLanguage()) && + $this->getLanguage() !== 'native' && + $this->getLanguage() !== 'stereo'; } public function getVideoSize() diff --git a/template/assemblies/embed-form.phtml b/template/assemblies/embed-form.phtml index 721d886..020a22f 100644 --- a/template/assemblies/embed-form.phtml +++ b/template/assemblies/embed-form.phtml @@ -20,7 +20,7 @@
diff --git a/view/embed.php b/view/embed.php index eb7caee..aaf203d 100644 --- a/view/embed.php +++ b/view/embed.php @@ -1,11 +1,24 @@ getRoom($_GET['room']); + if(!$room->hasEmbed()) throw new NotFoundException('Embedding is not enabled in this room'); -$stream = $room->selectStream( - $_GET['selection'], $_GET['language']); +$selection = $_GET['selection']; +$language = $_GET['language']; + +if ($language !== 'native' && $language !== 'stereo') { + if (! $room->hasTranslation()) { + throw new NotFoundException('Not translated'); + } + + if (! $room->isValidLanguage($language)) { + throw new NotFoundException('Language not found'); + } +} + +$stream = $room->selectStream($selection, $language); echo $tpl->render(array( 'page' => 'embed', -- cgit v1.2.3 From b25046267febba28dec4479be91522f577f953b2 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Sun, 10 Dec 2017 18:21:34 +0100 Subject: Removed dash and music translations from the api because its wrong --- model/Room.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/model/Room.php b/model/Room.php index 27a8d97..dd63038 100644 --- a/model/Room.php +++ b/model/Room.php @@ -233,6 +233,11 @@ class Room return $selections; } + public function isSelectionTranslated($selection) { + # dash is special, has langs included + return $selection !== 'dash' && $selection !== 'music'; + } + public function getTabNames() { $tabs = array(); @@ -314,9 +319,11 @@ class Room foreach ($selections as $selection) { $streams[] = $this->createStreamObject($selection, 'native'); - foreach ($this->getTranslations() as $translation) { - $streams[] = $this->createStreamObject($selection, $translation['endpoint'], $translation['label']); - } + if ($this->isSelectionTranslated($selection)) { + foreach ($this->getTranslations() as $translation) { + $streams[] = $this->createStreamObject($selection, $translation['endpoint'], $translation['label']); + } + } } return $streams; -- cgit v1.2.3 From a6c2f11312f76329231a63bfc2a3be8ba664051f Mon Sep 17 00:00:00 2001 From: dedeibel Date: Sun, 10 Dec 2017 19:12:52 +0100 Subject: Added known users of the api section --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7aa9378..8bcbe12 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ see [deploy.sh](deploy.sh) ## JSON-API -Unter der URL http://streaming.media.ccc.de/streams/v2.json bietet die +Unter der URL [http://streaming.media.ccc.de/streams/v2.json](http://streaming.media.ccc.de/streams/v2.json) bietet die Steaming-Webseite eine Übersicht über alle konfigurierten Räume und Streams in einem maschinenlesbaren Format an. Dieses kann z.B. genutzt werden, um in den diversen Anwendungen, die sich rund um das Konferenzgeschehen entwickelt haben, @@ -83,3 +83,9 @@ der `v2.json` keine Felder *entfernt werden* oder ihre *Bedeutung ändern* – e können aber durchaus *neue Felder* hinzukommen. Eine formalere Spezifikation des JSON-Formats ist tbd. Ein Beispiel kann [hier betrachtet](https://gist.github.com/MaZderMind/a91f242efb2f446a2237d4596896efd6) werden. + +### Bekannte Nutzer der API + + - [Kodi media.ccc.de Plugin](https://github.com/cccc/plugin.video.media-ccc-de) + - v2 + - [API Kompatiblitätstest](https://github.com/cccc/plugin.video.media-ccc-de/blob/master/resources/lib/test_stream.py) \ No newline at end of file -- cgit v1.2.3 From 1dec8c28a05683477541b0887e6241fd8dafe8a0 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Sun, 10 Dec 2017 19:14:08 +0100 Subject: Added documentation section for multi translation in last congress and from the readme linked configuration --- configs/conferences/33c3/config.php | 19 +++++++++++++++++++ configs/conferences/nixcon15/config.php | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/configs/conferences/33c3/config.php b/configs/conferences/33c3/config.php index f60df38..c5429ff 100644 --- a/configs/conferences/33c3/config.php +++ b/configs/conferences/33c3/config.php @@ -173,6 +173,25 @@ $CONFIG['ROOMS'] = array( * Wenn diese Zeile auskommentiert oder auf false gesetzt ist werden nur * die native-Streams verwendet, andernfalls wird native und translated * angeboten und auch für beide Tonspuren eine Player-Seite angezeigt. + * + * Betrifft video sd / hd, slides, audio + * + * Ein Label für die Übersetzung oder mehrere Übersetzungsspuren können + * wie folgt konfiguriert werden: + * + * 'TRANSLATION' => [ + * ['endpoint' => 'translated', 'label' => 'Translated1'], + * ['endpoint' => 'translated2', 'label' => 'Translated2'] + * ], + * + * Ein einfaches true entsprich dabei folgendem: + * + * 'TRANSLATION' => [ + * ['endpoint' => 'translated', 'label' => 'Translated'] + * ], + * + * Sollte die Sprache während der Veranstaltung Konstant sein, kann eine + * Sprache fest konfiguriert werden z.B. 'label' => 'English'. */ 'TRANSLATION' => true, diff --git a/configs/conferences/nixcon15/config.php b/configs/conferences/nixcon15/config.php index abf67f7..d5ad008 100644 --- a/configs/conferences/nixcon15/config.php +++ b/configs/conferences/nixcon15/config.php @@ -164,6 +164,26 @@ $CONFIG['ROOMS'] = array( * Wenn diese Zeile auskommentiert oder auf false gesetzt ist werden nur * die native-Streams verwendet, andernfalls wird native und translated * angeboten und auch für beide Tonspuren eine Player-Seite angezeigt. + * + * Betrifft video sd / hd, slides, audio + * + * Ein Label für die Übersetzung oder mehrere Übersetzungsspuren können + * wie folgt konfiguriert werden: + * + * 'TRANSLATION' => [ + * ['endpoint' => 'translated', 'label' => 'Translated1'], + * ['endpoint' => 'translated2', 'label' => 'Translated2'] + * ], + * + * Ein einfaches true entsprich dabei folgendem: + * + * 'TRANSLATION' => [ + * ['endpoint' => 'translated', 'label' => 'Translated'] + * ], + * + * Sollte die Sprache während der Veranstaltung Konstant sein, kann eine + * Sprache fest konfiguriert werden z.B. 'label' => 'English'. + */ */ 'TRANSLATION' => false, -- cgit v1.2.3 From 0036e54d08b1c898eb0b2ad8c1c999a8d5ca6cd3 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Mon, 11 Dec 2017 09:21:34 +0100 Subject: Default second translation endpoint changed to translated-2 in the documentation, fixed comment error in nixcon config --- configs/conferences/33c3/config.php | 10 +++++----- configs/conferences/nixcon15/config.php | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/configs/conferences/33c3/config.php b/configs/conferences/33c3/config.php index c5429ff..eb4d18b 100644 --- a/configs/conferences/33c3/config.php +++ b/configs/conferences/33c3/config.php @@ -180,18 +180,18 @@ $CONFIG['ROOMS'] = array( * wie folgt konfiguriert werden: * * 'TRANSLATION' => [ - * ['endpoint' => 'translated', 'label' => 'Translated1'], - * ['endpoint' => 'translated2', 'label' => 'Translated2'] + * ['endpoint' => 'translated', 'label' => 'Translated1'], + * ['endpoint' => 'translated-2', 'label' => 'Translated2'] * ], * - * Ein einfaches true entsprich dabei folgendem: + * Ein einfaches true entspricht dabei folgendem: * * 'TRANSLATION' => [ * ['endpoint' => 'translated', 'label' => 'Translated'] * ], * - * Sollte die Sprache während der Veranstaltung Konstant sein, kann eine - * Sprache fest konfiguriert werden z.B. 'label' => 'English'. + * Sollte die Sprache während der Veranstaltung Konstant sein, kann ein + * Label auch spezifisch konfiguriert werden z.B. 'label' => 'English'. */ 'TRANSLATION' => true, diff --git a/configs/conferences/nixcon15/config.php b/configs/conferences/nixcon15/config.php index d5ad008..69545f6 100644 --- a/configs/conferences/nixcon15/config.php +++ b/configs/conferences/nixcon15/config.php @@ -171,19 +171,18 @@ $CONFIG['ROOMS'] = array( * wie folgt konfiguriert werden: * * 'TRANSLATION' => [ - * ['endpoint' => 'translated', 'label' => 'Translated1'], - * ['endpoint' => 'translated2', 'label' => 'Translated2'] + * ['endpoint' => 'translated', 'label' => 'Translated1'], + * ['endpoint' => 'translated-2', 'label' => 'Translated2'] * ], * - * Ein einfaches true entsprich dabei folgendem: + * Ein einfaches true entspricht dabei folgendem: * * 'TRANSLATION' => [ * ['endpoint' => 'translated', 'label' => 'Translated'] * ], * - * Sollte die Sprache während der Veranstaltung Konstant sein, kann eine - * Sprache fest konfiguriert werden z.B. 'label' => 'English'. - */ + * Sollte die Sprache während der Veranstaltung Konstant sein, kann ein + * Label auch spezifisch konfiguriert werden z.B. 'label' => 'English'. */ 'TRANSLATION' => false, -- cgit v1.2.3 From 0d3b8468e30426bcde5e59834a04e0b7dcd84257 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Mon, 11 Dec 2017 19:47:22 +0100 Subject: Added an editorconfig --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..94148b4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +end_of_line = lf + +[*.{html,phtml,sh}] +indent_style = tab + +[*.{php,js}] +indent_style = tab +trim_trailing_whitespace = true + -- cgit v1.2.3 From 46852c4f9c77ab77b9bcc18c901f9f8640d9f305 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Mon, 11 Dec 2017 19:50:55 +0100 Subject: Explained config migration with more detail --- model/Conferences.php | 67 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/model/Conferences.php b/model/Conferences.php index eb07327..575759e 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -72,34 +72,45 @@ class Conferences return in_array($mandator, Conferences::listConferences()); } - public static function loadConferenceConfig($mandator) { - $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; - $config = include($configfile); - - if(!is_array($config)) { - throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); - } - - // Allow setting TRANSLATION simply to true and fill in default values for uniformity - $rooms = $config['ROOMS']; - foreach ($rooms as $slug => $room) { - if (!isset($room['TRANSLATION'])) { - $config['ROOMS'][$slug]['TRANSLATION'] = []; - } - elseif (! is_array($room['TRANSLATION'])) { - if ($room['TRANSLATION'] === true) { - $config['ROOMS'][$slug]['TRANSLATION'] = [[ - 'endpoint' => 'translated', - 'label' => 'Translated' - ]]; - } - else { - $config['ROOMS'][$slug]['TRANSLATION'] = []; - } - } - } - return $config; - } + private static function migrateTranslationConfiguration($config) { + // Allow setting TRANSLATION simply to true and fill in default values for uniformity + $rooms = $config['ROOMS']; + foreach ($rooms as $slug => $room) { + // Translation is commented out, equaivalent of false + if (!isset($room['TRANSLATION'])) { + $config['ROOMS'][$slug]['TRANSLATION'] = []; + } + // Translation is present but not an array + elseif (! is_array($room['TRANSLATION'])) { + // Translation is true, set default values + if ($room['TRANSLATION'] === true) { + $config['ROOMS'][$slug]['TRANSLATION'] = [[ + 'endpoint' => 'translated', + 'label' => 'Translated' + ]]; + } + // Translation is false or garbage + else { + $config['ROOMS'][$slug]['TRANSLATION'] = []; + } + } + } + + return $config; + } + + public static function loadConferenceConfig($mandator) { + $configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; + $config = include($configfile); + + if(!is_array($config)) { + throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?"); + } + + $config = Conferences::migrateTranslationConfiguration($config); + + return $config; + } public static function getConference($mandator) { return new Conference(Conferences::loadConferenceConfig($mandator), $mandator); -- cgit v1.2.3 From 0b73843d5e0d0ac22a46db28090e707566668ae4 Mon Sep 17 00:00:00 2001 From: dedeibel Date: Mon, 11 Dec 2017 20:03:35 +0100 Subject: Leading Spaces to Tabs --- model/Room.php | 70 ++++++++++++++++++++++++------------------------- model/RoomSelection.php | 6 ++--- model/Stream.php | 6 ++--- view/embed.php | 12 ++++----- view/room.php | 2 +- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/model/Room.php b/model/Room.php index dd63038..24d87cb 100644 --- a/model/Room.php +++ b/model/Room.php @@ -179,35 +179,35 @@ class Room return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); } - private function getTranslationEndpoints() { - return array_map( - function ($translation) { - return $translation['endpoint']; - }, - $this->getTranslations() - ); - } - - private function isTranslationEndpoint($endpoint) { - return in_array($endpoint, $this->getTranslationEndpoints()); - } - - private function findTranslationLabel($language) { - foreach($this->getTranslations() as $translation) { - if ($translation['endpoint'] === $language) { - return $translation['label']; - } - } - return null; - } + private function getTranslationEndpoints() { + return array_map( + function ($translation) { + return $translation['endpoint']; + }, + $this->getTranslations() + ); + } + + private function isTranslationEndpoint($endpoint) { + return in_array($endpoint, $this->getTranslationEndpoints()); + } + + private function findTranslationLabel($language) { + foreach($this->getTranslations() as $translation) { + if ($translation['endpoint'] === $language) { + return $translation['label']; + } + } + return null; + } public function hasTranslation() { return count($this->getTranslations()) > 0; } - public function isValidLanguage($language) { - return ($language === 'native' || $this->isTranslationEndpoint($language)); - } + public function isValidLanguage($language) { + return ($language === 'native' || $this->isTranslationEndpoint($language)); + } public function getSelectionNames() { @@ -343,17 +343,17 @@ class Room if(!in_array($selection, $selections)) throw new NotFoundException('Selection '.$selection.' in Room '.$this->getSlug()); - $translation_label = null; - if ($language !== 'native' && $language !== 'stereo') { - if (! $this->hasTranslation()) { - throw new NotFoundException('Translated Streams of Room '. $this->getSlug()); - } - if (! $this->isValidLanguage($language)) { - throw new NotFoundException('Selected translation'); - } - - $translation_label = $this->findTranslationLabel($language); - } + $translation_label = null; + if ($language !== 'native' && $language !== 'stereo') { + if (! $this->hasTranslation()) { + throw new NotFoundException('Translated Streams of Room '. $this->getSlug()); + } + if (! $this->isValidLanguage($language)) { + throw new NotFoundException('Selected translation'); + } + + $translation_label = $this->findTranslationLabel($language); + } return $this->createStreamObject($selection, $language, $translation_label); } diff --git a/model/RoomSelection.php b/model/RoomSelection.php index a83b5c6..c21ea7e 100644 --- a/model/RoomSelection.php +++ b/model/RoomSelection.php @@ -18,15 +18,15 @@ class RoomSelection return $this->selection; } - private function getSelectionPath() { + private function getSelectionPath() { $path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()]; $selection = $this->getRoom()->getSelectionNames(); if ($selection[0] != $this->getSelection()) $path[] = $this->getSelection(); - return joinpath($path); - } + return joinpath($path); + } public function getLink() { diff --git a/model/Stream.php b/model/Stream.php index 28cb0f8..99abaf1 100644 --- a/model/Stream.php +++ b/model/Stream.php @@ -32,9 +32,9 @@ class Stream public function isTranslated() { - return !empty($this->getLanguage()) && - $this->getLanguage() !== 'native' && - $this->getLanguage() !== 'stereo'; + return !empty($this->getLanguage()) && + $this->getLanguage() !== 'native' && + $this->getLanguage() !== 'stereo'; } public function getVideoSize() diff --git a/view/embed.php b/view/embed.php index aaf203d..97df148 100644 --- a/view/embed.php +++ b/view/embed.php @@ -9,13 +9,13 @@ $selection = $_GET['selection']; $language = $_GET['language']; if ($language !== 'native' && $language !== 'stereo') { - if (! $room->hasTranslation()) { - throw new NotFoundException('Not translated'); - } + if (! $room->hasTranslation()) { + throw new NotFoundException('Not translated'); + } - if (! $room->isValidLanguage($language)) { - throw new NotFoundException('Language not found'); - } + if (! $room->isValidLanguage($language)) { + throw new NotFoundException('Language not found'); + } } $stream = $room->selectStream($selection, $language); diff --git a/view/room.php b/view/room.php index c63f9ec..d035219 100644 --- a/view/room.php +++ b/view/room.php @@ -5,7 +5,7 @@ $selection = $_GET['selection']; $language = $_GET['language']; if (! $room->isValidLanguage($language)) { - throw new NotFoundException('Language not found'); + throw new NotFoundException('Language not found'); } $stream = $room->selectStream($selection, $language); -- cgit v1.2.3