getAttributeTranslation() public method

Deprecation: This method will be removed in SSP 2.0. Please use \SimpleSAML\Locale\Language::getLanguage() instead.
public getAttributeTranslation ( $name ) : string
$name
return string
/**
 * Recursiv 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)
{
    $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 = $t->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_Utilities::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 . '\'); 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;
}