Return the internal translator object used by this template.
public getTranslator ( ) : |
||
Résultat | The translator that will be used with this template. |
function present_attributes(SimpleSAML_XHTML_Template $t, $attributes, $nameParent) { $alternate = array('odd', 'even'); $i = 0; $parentStr = strlen($nameParent) > 0 ? strtolower($nameParent) . '_' : ''; $str = strlen($nameParent) > 0 ? '<table class="attributes" summary="attribute overview">' : '<table id="table_with_attributes" class="attributes" summary="attribute overview">'; foreach ($attributes as $name => $value) { $nameraw = $name; $name = $t->getTranslator()->getAttributeTranslation($parentStr . $nameraw); if (preg_match('/^child_/', $nameraw)) { $parentName = preg_replace('/^child_/', '', $nameraw); foreach ($value as $child) { $str .= '<tr class="odd"><td colspan="2" style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; } } else { if (sizeof($value) > 1) { $str .= '<tr class="' . $alternate[$i++ % 2] . '"><td class="attrname">'; if ($nameraw !== $name) { $str .= htmlspecialchars($name) . '<br/>'; } $str .= '<tt>' . htmlspecialchars($nameraw) . '</tt>'; $str .= '</td><td class="attrvalue"><ul>'; foreach ($value as $listitem) { if ($nameraw === 'jpegPhoto') { $str .= '<li><img src="data:image/jpeg;base64,' . htmlspecialchars($listitem) . '" /></li>'; } else { $str .= '<li>' . present_assoc($listitem) . '</li>'; } } $str .= '</ul></td></tr>'; } elseif (isset($value[0])) { $str .= '<tr class="' . $alternate[$i++ % 2] . '"><td class="attrname">'; if ($nameraw !== $name) { $str .= htmlspecialchars($name) . '<br/>'; } $str .= '<tt>' . htmlspecialchars($nameraw) . '</tt>'; $str .= '</td>'; if ($nameraw === 'jpegPhoto') { $str .= '<td class="attrvalue"><img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" /></td></tr>'; } else { $str .= '<td class="attrvalue">' . htmlspecialchars($value[0]) . '</td></tr>'; } } } $str .= "\n"; } $str .= '</table>'; return $str; }
/** * Recursive attribute array listing function * * @param SimpleSAML_XHTML_Template $t Template object * @param array $attributes Attributes to be presented * @param string $nameParent Name of parent element * * @return string HTML representation of the attributes */ function present_attributes($t, $attributes, $nameParent) { $translator = $t->getTranslator(); $alternate = array('odd', 'even'); $i = 0; $summary = 'summary="' . $t->t('{consent:consent:table_summary}') . '"'; if (strlen($nameParent) > 0) { $parentStr = strtolower($nameParent) . '_'; $str = '<table class="attributes" ' . $summary . '>'; } else { $parentStr = ''; $str = '<table id="table_with_attributes" class="attributes" ' . $summary . '>'; $str .= "\n" . '<caption>' . $t->t('{consent:consent:table_caption}') . '</caption>'; } foreach ($attributes as $name => $value) { $nameraw = $name; $name = $translator->getAttributeTranslation($parentStr . $nameraw); if (preg_match('/^child_/', $nameraw)) { // insert child table $parentName = preg_replace('/^child_/', '', $nameraw); foreach ($value as $child) { $str .= "\n" . '<tr class="odd"><td style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; } } else { // insert values directly $str .= "\n" . '<tr class="' . $alternate[$i++ % 2] . '"><td><span class="attrname">' . htmlspecialchars($name) . '</span>'; $isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true); if ($isHidden) { $hiddenId = SimpleSAML\Utils\Random::generateID(); $str .= '<div class="attrvalue" style="display: none;" id="hidden_' . $hiddenId . '">'; } else { $str .= '<div class="attrvalue">'; } if (sizeof($value) > 1) { // we hawe several values $str .= '<ul>'; foreach ($value as $listitem) { if ($nameraw === 'jpegPhoto') { $str .= '<li><img src="data:image/jpeg;base64,' . htmlspecialchars($listitem) . '" alt="User photo" /></li>'; } else { $str .= '<li>' . htmlspecialchars($listitem) . '</li>'; } } $str .= '</ul>'; } elseif (isset($value[0])) { // we hawe only one value if ($nameraw === 'jpegPhoto') { $str .= '<img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" alt="User photo" />'; } else { $str .= htmlspecialchars($value[0]); } } // end of if multivalue $str .= '</div>'; if ($isHidden) { $str .= '<div class="attrvalue consent_showattribute" id="visible_' . $hiddenId . '">'; $str .= '... '; $str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_' . $hiddenId; $str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">'; $str .= $t->t('{consent:consent:show_attribute}'); $str .= '</a>'; $str .= '</div>'; } $str .= '</td></tr>'; } // end else: not child table } // end foreach $str .= isset($attributes) ? '</table>' : ''; return $str; }
$template = new SimpleSAML_XHTML_Template($config, 'consentAdmin:consentadminajax.php', 'consentAdmin:consentadmin'); $template->data['res'] = $res; $template->show(); exit; } // Get all consents for user $user_consent_list = $consent_storage->getConsents($hashed_user_id); // Parse list of consents $user_consent = array(); foreach ($user_consent_list as $c) { $user_consent[$c[0]] = $c[1]; } $template_sp_content = array(); // Init template $template = new SimpleSAML_XHTML_Template($config, 'consentAdmin:consentadmin.php', 'consentAdmin:consentadmin'); $translator = $template->getTranslator(); $sp_empty_name = $translator->getTag('sp_empty_name'); $sp_empty_description = $translator->getTag('sp_empty_description'); // Process consents for all SP foreach ($all_sp_metadata as $sp_entityid => $sp_values) { // Get metadata for SP $sp_metadata = $metadata->getMetaData($sp_entityid, 'saml20-sp-remote'); // Run attribute filters list($targeted_id, $attribute_hash, $attributes_new) = driveProcessingChain($idp_metadata, $source, $sp_metadata, $sp_entityid, $attributes, $userid, $hashAttributes); // Check if consent exists if (array_key_exists($targeted_id, $user_consent)) { $sp_status = "changed"; SimpleSAML\Logger::info('consentAdmin: changed'); // Check if consent is valid. (Possible that attributes has changed) if ($user_consent[$targeted_id] == $attribute_hash) { SimpleSAML\Logger::info('consentAdmin: ok');
function present_attributes(SimpleSAML_XHTML_Template $t, $attributes, $nameParent) { $alternate = array('odd', 'even'); $i = 0; $parentStr = strlen($nameParent) > 0 ? strtolower($nameParent) . '_' : ''; $str = strlen($nameParent) > 0 ? '<table class="attributes" summary="attribute overview">' : '<table id="table_with_attributes" class="attributes" summary="attribute overview">'; foreach ($attributes as $name => $value) { $nameraw = $name; $name = $t->getTranslator()->getAttributeTranslation($parentStr . $nameraw); if (preg_match('/^child_/', $nameraw)) { $parentName = preg_replace('/^child_/', '', $nameraw); foreach ($value as $child) { $str .= '<tr class="odd"><td colspan="2" style="padding: 2em">' . present_attributes($t, $child, $parentName) . '</td></tr>'; } } else { if (sizeof($value) > 1) { $str .= '<tr class="' . $alternate[$i++ % 2] . '"><td class="attrname">'; if ($nameraw !== $name) { $str .= htmlspecialchars($name) . '<br/>'; } $str .= '<tt>' . htmlspecialchars($nameraw) . '</tt>'; $str .= '</td><td class="attrvalue"><ul>'; foreach ($value as $listitem) { if ($nameraw === 'jpegPhoto') { $str .= '<li><img src="data:image/jpeg;base64,' . htmlspecialchars($listitem) . '" /></li>'; } else { $str .= '<li>' . present_assoc($listitem) . '</li>'; } } $str .= '</ul></td></tr>'; } elseif (isset($value[0])) { $str .= '<tr class="' . $alternate[$i++ % 2] . '"><td class="attrname">'; if ($nameraw !== $name) { $str .= htmlspecialchars($name) . '<br/>'; } $str .= '<tt>' . htmlspecialchars($nameraw) . '</tt>'; $str .= '</td>'; if ($nameraw === 'jpegPhoto') { $str .= '<td class="attrvalue"><img src="data:image/jpeg;base64,' . htmlspecialchars($value[0]) . '" /></td></tr>'; } elseif (is_a($value[0], 'DOMNodeList')) { // try to see if we have a NameID here $n = $value[0]->length; for ($idx = 0; $idx < $n; $idx++) { $elem = $value[0]->item($idx); /* @var DOMElement $elem */ if (!($elem->localName === 'NameID' && $elem->namespaceURI === \SAML2\Constants::NS_SAML)) { continue; } $nameID = new \SAML2\XML\saml\NameID($elem); $eptid = array('NameID' => array($nameID->value)); if (!empty($nameID->Format)) { $eptid['Format'] = array($nameID->Format); } if (!empty($nameID->NameQualifier)) { $eptid['NameQualifier'] = array($nameID->NameQualifier); } if (!empty($nameID->SPNameQualifier)) { $eptid['SPNameQualifier'] = array($nameID->SPNameQualifier); } $str .= '<td class="attrvalue">'; $str .= present_assoc($eptid); break; // we only support one NameID here } $str .= '</td></tr>'; } else { $str .= '<td class="attrvalue">' . htmlspecialchars($value[0]) . '</td></tr>'; } } } $str .= "\n"; } $str .= '</table>'; return $str; }