2222 */
2323namespace OCA \Theming \Service ;
2424
25+ use OCA \Theming \ITheme ;
2526use OCA \Theming \Themes \DefaultTheme ;
2627use OCA \Theming \Util ;
2728use OCP \IConfig ;
@@ -48,14 +49,15 @@ public function __construct(IURLGenerator $urlGenerator,
4849 $ this ->defaultTheme = $ defaultTheme ;
4950 $ this ->util = $ util ;
5051 $ this ->config = $ config ;
52+
5153 if ($ userSession ->getUser () !== null ) {
5254 $ this ->userId = $ userSession ->getUser ()->getUID ();
5355 } else {
5456 $ this ->userId = null ;
5557 }
5658 }
5759
58- public function injectHeaders () {
60+ public function injectHeaders (): void {
5961 $ themes = $ this ->themesService ->getThemes ();
6062 $ defaultTheme = $ themes [$ this ->defaultTheme ->getId ()];
6163 $ mediaThemes = array_filter ($ themes , function ($ theme ) {
@@ -64,11 +66,11 @@ public function injectHeaders() {
6466 });
6567
6668 // Default theme fallback
67- $ this ->addThemeHeader ($ defaultTheme-> getId () );
69+ $ this ->addThemeHeaders ($ defaultTheme );
6870
6971 // Themes applied by media queries
7072 foreach ($ mediaThemes as $ theme ) {
71- $ this ->addThemeHeader ($ theme-> getId () , true , $ theme ->getMediaQuery ());
73+ $ this ->addThemeHeaders ($ theme , true , $ theme ->getMediaQuery ());
7274 }
7375
7476 // Themes
@@ -77,20 +79,23 @@ public function injectHeaders() {
7779 if ($ theme ->getId () === $ this ->defaultTheme ->getId ()) {
7880 continue ;
7981 }
80- $ this ->addThemeHeader ($ theme-> getId () , false );
82+ $ this ->addThemeHeaders ($ theme , false );
8183 }
84+
85+ // Meta headers
86+ $ this ->addThemeMetaHeaders ($ themes );
8287 }
8388
8489 /**
8590 * Inject theme header into rendered page
8691 *
87- * @param string $themeId the theme ID
92+ * @param ITheme $theme the theme
8893 * @param bool $plain request the :root syntax
8994 * @param string $media media query to use in the <link> element
9095 */
91- private function addThemeHeader ( string $ themeId , bool $ plain = true , string $ media = null ) {
96+ private function addThemeHeaders ( ITheme $ theme , bool $ plain = true , string $ media = null ): void {
9297 $ linkToCSS = $ this ->urlGenerator ->linkToRoute ('theming.Theming.getThemeStylesheet ' , [
93- 'themeId ' => $ themeId ,
98+ 'themeId ' => $ theme -> getId () ,
9499 'plain ' => $ plain ,
95100 'v ' => $ this ->util ->getCacheBuster (),
96101 ]);
@@ -101,4 +106,36 @@ private function addThemeHeader(string $themeId, bool $plain = true, string $med
101106 'class ' => 'theme '
102107 ]);
103108 }
109+
110+ /**
111+ * Inject meta headers into rendered page
112+ *
113+ * @param ITheme[] $themes the theme
114+ */
115+ private function addThemeMetaHeaders (array $ themes ): void {
116+ $ metaHeaders = [];
117+
118+ // Meta headers
119+ foreach ($ this ->themesService ->getThemes () as $ theme ) {
120+ if (!empty ($ theme ->getMeta ())) {
121+ foreach ($ theme ->getMeta () as $ meta ) {
122+ if (!isset ($ meta ['name ' ]) || !isset ($ meta ['content ' ])) {
123+ continue ;
124+ }
125+
126+ if (!isset ($ metaHeaders [$ meta ['name ' ]])) {
127+ $ metaHeaders [$ meta ['name ' ]] = [];
128+ }
129+ $ metaHeaders [$ meta ['name ' ]][] = $ meta ['content ' ];
130+ }
131+ }
132+ }
133+
134+ foreach ($ metaHeaders as $ name => $ content ) {
135+ \OCP \Util::addHeader ('meta ' , [
136+ 'name ' => $ name ,
137+ 'content ' => join (' ' , array_unique ($ content )),
138+ ]);
139+ }
140+ }
104141}
0 commit comments