|
3 | 3 | * Functions used to present a table of attributes and their values. |
4 | 4 | */ |
5 | 5 |
|
6 | | -function present_list($attr) { |
7 | | - if (is_array($attr) && count($attr) > 1) { |
8 | | - $str = '<ul>'; |
9 | | - foreach ($attr as $value) { |
10 | | - $str .= '<li>' . htmlspecialchars($attr) . '</li>'; |
11 | | - } |
12 | | - $str .= '</ul>'; |
13 | | - return $str; |
14 | | - } else { |
15 | | - return htmlspecialchars($attr[0]); |
16 | | - } |
| 6 | +function present_list($attr) |
| 7 | +{ |
| 8 | + if (is_array($attr) && count($attr) > 1) { |
| 9 | + $str = '<ul>'; |
| 10 | + foreach ($attr as $value) { |
| 11 | + $str .= '<li>'.htmlspecialchars($attr).'</li>'; |
| 12 | + } |
| 13 | + $str .= '</ul>'; |
| 14 | + return $str; |
| 15 | + } else { |
| 16 | + return htmlspecialchars($attr[0]); |
| 17 | + } |
17 | 18 | } |
18 | 19 |
|
19 | | -function present_assoc($attr) { |
20 | | - if (is_array($attr)) { |
21 | | - |
22 | | - $str = '<dl>'; |
23 | | - foreach ($attr AS $key => $value) { |
24 | | - $str .= "\n" . '<dt>' . htmlspecialchars($key) . '</dt><dd>' . present_list($value) . '</dd>'; |
25 | | - } |
26 | | - $str .= '</dl>'; |
27 | | - return $str; |
28 | | - } else { |
29 | | - return htmlspecialchars($attr); |
30 | | - } |
| 20 | +function present_assoc($attr) |
| 21 | +{ |
| 22 | + if (is_array($attr)) { |
| 23 | + $str = '<dl>'; |
| 24 | + foreach ($attr as $key => $value) { |
| 25 | + $str .= "\n".'<dt>'.htmlspecialchars($key).'</dt><dd>'.present_list($value).'</dd>'; |
| 26 | + } |
| 27 | + $str .= '</dl>'; |
| 28 | + return $str; |
| 29 | + } else { |
| 30 | + return htmlspecialchars($attr); |
| 31 | + } |
31 | 32 | } |
32 | 33 |
|
33 | | -function present_attributes(SimpleSAML_XHTML_Template $t, $attributes, $nameParent) { |
34 | | - $alternate = array('odd', 'even'); $i = 0; |
35 | | - |
36 | | - $parentStr = (strlen($nameParent) > 0)? strtolower($nameParent) . '_': ''; |
37 | | - $str = (strlen($nameParent) > 0)? '<table class="attributes" summary="attribute overview">': |
38 | | - '<table id="table_with_attributes" class="attributes" summary="attribute overview">'; |
| 34 | +function present_attributes(SimpleSAML_XHTML_Template $t, $attributes, $nameParent) |
| 35 | +{ |
| 36 | + $alternate = array('odd', 'even'); |
| 37 | + $i = 0; |
39 | 38 |
|
40 | | - foreach ($attributes as $name => $value) { |
41 | | - |
42 | | - $nameraw = $name; |
43 | | - $name = $t->getTranslator()->getAttributeTranslation($parentStr . $nameraw); |
| 39 | + $parentStr = (strlen($nameParent) > 0) ? strtolower($nameParent).'_' : ''; |
| 40 | + $str = (strlen($nameParent) > 0) ? '<table class="attributes" summary="attribute overview">' : |
| 41 | + '<table id="table_with_attributes" class="attributes" summary="attribute overview">'; |
44 | 42 |
|
45 | | - if (preg_match('/^child_/', $nameraw)) { |
46 | | - $parentName = preg_replace('/^child_/', '', $nameraw); |
47 | | - foreach($value AS $child) { |
48 | | - $str .= '<tr class="odd"><td colspan="2" style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; |
49 | | - } |
50 | | - } else { |
51 | | - if (sizeof($value) > 1) { |
52 | | - $str .= '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">'; |
| 43 | + foreach ($attributes as $name => $value) { |
| 44 | + $nameraw = $name; |
| 45 | + $name = $t->getTranslator()->getAttributeTranslation($parentStr.$nameraw); |
53 | 46 |
|
54 | | - if ($nameraw !== $name) |
55 | | - $str .= htmlspecialchars($name).'<br/>'; |
56 | | - $str .= '<tt>'.htmlspecialchars($nameraw).'</tt>'; |
57 | | - $str .= '</td><td class="attrvalue"><ul>'; |
58 | | - foreach ($value AS $listitem) { |
59 | | - if ($nameraw === 'jpegPhoto') { |
60 | | - $str .= '<li><img src="data:image/jpeg;base64,' . htmlspecialchars($listitem) . '" /></li>'; |
61 | | - } else { |
62 | | - $str .= '<li>' . present_assoc($listitem) . '</li>'; |
63 | | - } |
64 | | - } |
65 | | - $str .= '</ul></td></tr>'; |
66 | | - } elseif(isset($value[0])) { |
67 | | - $str .= '<tr class="' . $alternate[($i++ % 2)] . '"><td class="attrname">'; |
68 | | - if ($nameraw !== $name) |
69 | | - $str .= htmlspecialchars($name).'<br/>'; |
70 | | - $str .= '<tt>'.htmlspecialchars($nameraw).'</tt>'; |
71 | | - $str .= '</td>'; |
72 | | - if ($nameraw === 'jpegPhoto') { |
73 | | - $str .= '<td class="attrvalue"><img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" /></td></tr>'; |
74 | | - } elseif (is_a($value[0], 'DOMNodeList')) { |
75 | | - // try to see if we have a NameID here |
76 | | - $n = $value[0]->length; |
77 | | - for ($idx = 0; $idx < $n; $idx++) { |
78 | | - $elem = $value[0]->item($idx); |
79 | | - /* @var DOMElement $elem */ |
80 | | - if (!($elem->localName === 'NameID' && $elem->namespaceURI === \SAML2\Constants::NS_SAML)) { |
81 | | - continue; |
82 | | - } |
83 | | - $nameID = new \SAML2\XML\saml\NameID($elem); |
84 | | - $eptid = array( |
85 | | - 'NameID' => array($nameID->value), |
86 | | - ); |
87 | | - if (!empty($nameID->Format)) { |
88 | | - $eptid['Format'] = array($nameID->Format); |
89 | | - } |
90 | | - if (!empty($nameID->NameQualifier)) { |
91 | | - $eptid['NameQualifier'] = array($nameID->NameQualifier); |
92 | | - } |
93 | | - if (!empty($nameID->SPNameQualifier)) { |
94 | | - $eptid['SPNameQualifier'] = array($nameID->SPNameQualifier); |
95 | | - } |
96 | | - $str .= '<td class="attrvalue">'; |
97 | | - $str .= present_assoc($eptid); |
98 | | - break; // we only support one NameID here |
99 | | - } |
100 | | - $str .= '</td></tr>'; |
101 | | - } else { |
102 | | - $str .= '<td class="attrvalue">' . htmlspecialchars($value[0]) . '</td></tr>'; |
103 | | - } |
104 | | - } |
105 | | - } |
106 | | - $str .= "\n"; |
107 | | - } |
108 | | - $str .= '</table>'; |
109 | | - return $str; |
| 47 | + if (preg_match('/^child_/', $nameraw)) { |
| 48 | + $parentName = preg_replace('/^child_/', '', $nameraw); |
| 49 | + foreach ($value as $child) { |
| 50 | + $str .= '<tr class="odd"><td colspan="2" style="padding: 2em">'. |
| 51 | + present_attributes($t, $child, $parentName).'</td></tr>'; |
| 52 | + } |
| 53 | + } else { |
| 54 | + if (sizeof($value) > 1) { |
| 55 | + $str .= '<tr class="'.$alternate[($i++ % 2)].'"><td class="attrname">'; |
| 56 | + |
| 57 | + if ($nameraw !== $name) { |
| 58 | + $str .= htmlspecialchars($name).'<br/>'; |
| 59 | + } |
| 60 | + $str .= '<tt>'.htmlspecialchars($nameraw).'</tt>'; |
| 61 | + $str .= '</td><td class="attrvalue"><ul>'; |
| 62 | + foreach ($value as $listitem) { |
| 63 | + if ($nameraw === 'jpegPhoto') { |
| 64 | + $str .= '<li><img src="data:image/jpeg;base64,'.htmlspecialchars($listitem).'" /></li>'; |
| 65 | + } else { |
| 66 | + $str .= '<li>'.present_assoc($listitem).'</li>'; |
| 67 | + } |
| 68 | + } |
| 69 | + $str .= '</ul></td></tr>'; |
| 70 | + } elseif (isset($value[0])) { |
| 71 | + $str .= '<tr class="'.$alternate[($i++ % 2)].'"><td class="attrname">'; |
| 72 | + if ($nameraw !== $name) { |
| 73 | + $str .= htmlspecialchars($name).'<br/>'; |
| 74 | + } |
| 75 | + $str .= '<tt>'.htmlspecialchars($nameraw).'</tt>'; |
| 76 | + $str .= '</td>'; |
| 77 | + if ($nameraw === 'jpegPhoto') { |
| 78 | + $str .= '<td class="attrvalue"><img src="data:image/jpeg;base64,'.htmlspecialchars($value[0]). |
| 79 | + '" /></td></tr>'; |
| 80 | + } elseif (is_a($value[0], 'DOMNodeList')) { |
| 81 | + // try to see if we have a NameID here |
| 82 | + /** @var DOMNodeList $value[0] */ |
| 83 | + $n = $value[0]->length; |
| 84 | + for ($idx = 0; $idx < $n; $idx++) { |
| 85 | + $elem = $value[0]->item($idx); |
| 86 | + /* @var DOMElement $elem */ |
| 87 | + if (!($elem->localName === 'NameID' && $elem->namespaceURI === \SAML2\Constants::NS_SAML)) { |
| 88 | + continue; |
| 89 | + } |
| 90 | + $nameID = new \SAML2\XML\saml\NameID($elem); |
| 91 | + $eptid = array( |
| 92 | + 'NameID' => array($nameID->value), |
| 93 | + ); |
| 94 | + if (!empty($nameID->Format)) { |
| 95 | + $eptid['Format'] = array($nameID->Format); |
| 96 | + } |
| 97 | + if (!empty($nameID->NameQualifier)) { |
| 98 | + $eptid['NameQualifier'] = array($nameID->NameQualifier); |
| 99 | + } |
| 100 | + if (!empty($nameID->SPNameQualifier)) { |
| 101 | + $eptid['SPNameQualifier'] = array($nameID->SPNameQualifier); |
| 102 | + } |
| 103 | + $str .= '<td class="attrvalue">'; |
| 104 | + $str .= present_assoc($eptid); |
| 105 | + break; // we only support one NameID here |
| 106 | + } |
| 107 | + $str .= '</td></tr>'; |
| 108 | + } else { |
| 109 | + $str .= '<td class="attrvalue">'.htmlspecialchars($value[0]).'</td></tr>'; |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + $str .= "\n"; |
| 114 | + } |
| 115 | + $str .= '</table>'; |
| 116 | + return $str; |
110 | 117 | } |
0 commit comments