From 580be5feca3716b77bae84a307877680b0cb317e Mon Sep 17 00:00:00 2001
From: Hanne Moa <hanne.moa@uninett.no>
Date: Tue, 13 Sep 2016 13:57:52 +0200
Subject: [PATCH] Get rid of the mtype-function

For #454, #455
---
 .../templates/frontpage_federation.tpl.php    | 36 ++-----------------
 modules/core/www/frontpage_federation.php     | 18 ++++++++--
 2 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/modules/core/templates/frontpage_federation.tpl.php b/modules/core/templates/frontpage_federation.tpl.php
index b0b7ca22b..2d4c84957 100644
--- a/modules/core/templates/frontpage_federation.tpl.php
+++ b/modules/core/templates/frontpage_federation.tpl.php
@@ -10,41 +10,11 @@ if ($this->data['isadmin']) {
         $this->t('{core:frontpage:login_as_admin}').'</a></p>';
 }
 
-function mtype($set)
-{
-    switch ($set) {
-        case 'saml20-sp-remote':
-            return '{admin:metadata_saml20-sp}';
-        case 'saml20-sp-hosted':
-            return '{admin:metadata_saml20-sp}';
-        case 'saml20-idp-remote':
-            return '{admin:metadata_saml20-idp}';
-        case 'saml20-idp-hosted':
-            return '{admin:metadata_saml20-idp}';
-        case 'shib13-sp-remote':
-            return '{admin:metadata_shib13-sp}';
-        case 'shib13-sp-hosted':
-            return '{admin:metadata_shib13-sp}';
-        case 'shib13-idp-remote':
-            return '{admin:metadata_shib13-idp}';
-        case 'shib13-idp-hosted':
-            return '{admin:metadata_shib13-idp}';
-        case 'adfs-sp-remote':
-            return '{admin:metadata_adfs-sp}';
-        case 'adfs-sp-hosted':
-            return '{admin:metadata_adfs-sp}';
-        case 'adfs-idp-remote':
-            return '{admin:metadata_adfs-idp}';
-        case 'adfs-idp-hosted':
-            return '{admin:metadata_adfs-idp}';
-    }
-}
-
 $now = time();
 echo '<dl>';
 if (is_array($this->data['metaentries']['hosted']) && count($this->data['metaentries']['hosted']) > 0) {
     foreach ($this->data['metaentries']['hosted'] as $hm) {
-        echo '<dt>'.$this->t(mtype($hm['metadata-set'])).'</dt>';
+        echo '<dt>'.$this->t($this->data['mtype'][$hm['metadata-set']]).'</dt>';
         echo '<dd>';
         echo '<p>Entity ID: '.$hm['entityid'];
         if (isset($hm['deprecated']) && $hm['deprecated']) {
@@ -74,7 +44,7 @@ echo '</dl>';
 if (is_array($this->data['metaentries']['remote']) && count($this->data['metaentries']['remote']) > 0) {
     foreach ($this->data['metaentries']['remote'] as $setkey => $set) {
 
-        echo '<fieldset class="fancyfieldset"><legend>'.$this->t(mtype($setkey)).' (Trusted)</legend>';
+        echo '<fieldset class="fancyfieldset"><legend>'.$this->t($this->data['mtype'][$setkey]).' (Trusted)</legend>';
         echo '<ul>';
         foreach ($set as $entry) {
             echo '<li>';
@@ -128,7 +98,7 @@ if (is_array($this->data['metaentries']['remote']) && count($this->data['metaent
                 <select name="set"><?php
             if (is_array($this->data['metaentries']['remote']) && count($this->data['metaentries']['remote']) > 0) {
                 foreach ($this->data['metaentries']['remote'] as $setkey => $set) {
-                    echo '<option value="'.htmlspecialchars($setkey).'">'.$this->t(mtype($setkey)).'</option>';
+                    echo '<option value="'.htmlspecialchars($setkey).'">'.$this->t($this->data['mtype'][$setkey]).'</option>';
                 }
             }
 ?>
diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php
index 35f31d432..e7c1196db 100644
--- a/modules/core/www/frontpage_federation.php
+++ b/modules/core/www/frontpage_federation.php
@@ -109,8 +109,21 @@ foreach ($metaentries['remote'] as $key => $value) {
 	}
 }
 
-
-
+# look up translated string
+$mtype = array(
+    'saml20-sp-remote' => $t->noop('{admin:metadata_saml20-sp}'),
+    'saml20-sp-hosted' => $t->noop('{admin:metadata_saml20-sp}'),
+    'saml20-idp-remote' => $t->noop('{admin:metadata_saml20-idp}'),
+    'saml20-idp-hosted' => $t->noop('{admin:metadata_saml20-idp}'),
+    'shib13-sp-remote' => $t->noop('{admin:metadata_shib13-sp}'),
+    'shib13-sp-hosted' => $t->noop('{admin:metadata_shib13-sp}'),
+    'shib13-idp-remote' => $t->noop('{admin:metadata_shib13-idp}'),
+    'shib13-idp-hosted' => $t->noop('{admin:metadata_shib13-idp}'),
+    'adfs-sp-remote' => $t->noop('{admin:metadata_adfs-sp}'),
+    'adfs-sp-hosted' => $t->noop('{admin:metadata_adfs-sp}'),
+    'adfs-idp-remote' => $t->noop('{admin:metadata_adfs-idp}'),
+    'adfs-idp-hosted' => $t->noop('{admin:metadata_adfs-idp}'),
+);
 
 $t = new SimpleSAML_XHTML_Template($config, 'core:frontpage_federation.tpl.php');
 $t->data['pageid'] = 'frontpage_federation';
@@ -127,6 +140,7 @@ $t->data['links_federation'] = $links_federation;
 
 
 $t->data['metaentries'] = $metaentries;
+$t->data['mtype'] = $mtype;
 
 
 $t->show();
-- 
GitLab