Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 2d2313b

Browse files
committed
Resolve problem with Sideeffects (PSR1.Files.SideEffects)
1 parent 44bd566 commit 2d2313b

File tree

17 files changed

+461
-409
lines changed

17 files changed

+461
-409
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
2121
#### Fixed
2222
- Fixed wrong dictionary name in post.php
2323
- Removed unnecessary include
24+
- Resolve problem with Sideeffects (PSR1.Files.SideEffects)
2425

2526
## [v3.5.2]
2627
#### Fixed

lib/Consent.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace SimpleSAML\Module\perun;
4+
5+
use SimpleSAML\Utils\Random;
6+
7+
/**
8+
* Class Consent
9+
* @package SimpleSAML\Module\perun
10+
*
11+
* @author Pavel Vyskocil <[email protected]>
12+
*/
13+
class Consent
14+
{
15+
public static function perunPresentAttributes($t, $attributes, $nameParent, $labelCol = 5)
16+
{
17+
$translator = $t->getTranslator();
18+
19+
if (strlen($nameParent) > 0) {
20+
$parentStr = strtolower($nameParent) . '_';
21+
$str = '<ul class="perun-attributes">';
22+
} else {
23+
$parentStr = '';
24+
$str = '<ul id="perun-table_with_attributes" class="perun-attributes">';
25+
}
26+
27+
foreach ($attributes as $name => $value) {
28+
$nameraw = $name;
29+
$name = $translator->getAttributeTranslation($parentStr . $nameraw);
30+
31+
if (preg_match('/^child_/', $nameraw)) {
32+
// insert child table
33+
throw new Exception('Unsupported');
34+
} else {
35+
// insert values directly
36+
$str .= "\n" . '<li>'
37+
. '<div class="row"><div class="col-sm-' . $labelCol
38+
. '"><h2 class="perun-attrname h4">'
39+
. htmlspecialchars(str_replace("domovksé", "domovské", $name)) . '</h2></div>';
40+
41+
$str .= '<div class="perun-attrcontainer col-sm-' . (12 - $labelCol) . '">';
42+
$isHidden = in_array($nameraw, $t->data['hiddenAttributes'], true);
43+
if ($isHidden) {
44+
$hiddenId = Random::generateID();
45+
$str .= '<span class="perun-attrvalue hidden" id="hidden_' . $hiddenId . '">';
46+
} else {
47+
$str .= '<span class="perun-attrvalue">';
48+
}
49+
50+
if (count($value) > 0) {
51+
$str .= '<ul class="perun-attrlist">';
52+
foreach ($value as $listitem) {
53+
$str .= '<li>' . self::presentAttributesPhotoOrValue($nameraw, $listitem) . '</li>';
54+
}
55+
$str .= '</ul>';
56+
}
57+
$str .= '</span>';
58+
59+
if ($isHidden) {
60+
$str .= '<div class="perun-attrvalue consent_showattribute" id="visible_' . $hiddenId . '">';
61+
$str .= '&#8230; ';
62+
$str .= '<a class="consent_showattributelink" href="javascript:SimpleSAML_show(\'hidden_';
63+
$str .= $hiddenId;
64+
$str .= '\'); SimpleSAML_hide(\'visible_' . $hiddenId . '\');">';
65+
$str .= $t->t('{consent:consent:show_attribute}');
66+
$str .= '</a>';
67+
$str .= '</div>';
68+
}
69+
70+
$str .= '</div><!-- .perun-attrcontainer --></div><!-- .row --></li>';
71+
} // end else: not child table
72+
} // end foreach
73+
$str .= isset($attributes) ? '</ul>' : '';
74+
return $str;
75+
}
76+
77+
public static function presentAttributesPhotoOrValue($nameraw, $listitem)
78+
{
79+
if ($nameraw === 'jpegPhoto') {
80+
return '<img src="data:image/jpeg;base64,' . htmlspecialchars($listitem) . '" alt="User photo" />';
81+
} else {
82+
return htmlspecialchars($listitem);
83+
}
84+
}
85+
}

lib/Disco.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,171 @@ public function removeAuthContextClassRefWithPrefix(&$state)
373373
= $array;
374374
}
375375
}
376+
377+
public static function buildEntry(DiscoTemplate $t, $idp, $favourite = false)
378+
{
379+
380+
$extra = ($favourite ? 'favourite' : '');
381+
$html = '<a class="metaentry ' . $extra . ' list-group-item" ' .
382+
' href="' . $t->getContinueUrl($idp['entityid']) . '">';
383+
384+
$html .= '<strong>' . htmlspecialchars($t->getTranslatedEntityName($idp)) . '</strong>';
385+
$html .= '</a>';
386+
387+
return $html;
388+
}
389+
390+
/**
391+
* @param DiscoTemplate $t
392+
* @param array $metadata
393+
* @param bool $favourite
394+
* @return string html
395+
*/
396+
public static function showEntry($t, $metadata, $favourite = false)
397+
{
398+
399+
if (isset($metadata['tags']) &&
400+
(in_array('social', $metadata['tags']) || in_array('preferred', $metadata['tags']))) {
401+
return self::showTaggedEntry($t, $metadata);
402+
}
403+
404+
$extra = ($favourite ? ' favourite' : '');
405+
$html = '<a class="metaentry' . $extra . ' list-group-item" href="' .
406+
$t->getContinueUrl($metadata['entityid']) . '">';
407+
408+
$html .= '<strong>' . $t->getTranslatedEntityName($metadata) . '</strong>';
409+
410+
$html .= '</a>';
411+
412+
return $html;
413+
}
414+
415+
/**
416+
* @param DiscoTemplate $t
417+
* @param array $metadata
418+
* @param bool $showSignInWith
419+
*
420+
* @return string html
421+
*/
422+
public static function showTaggedEntry($t, $metadata, $showSignInWith = false)
423+
{
424+
425+
$bck = 'white';
426+
if (!empty($metadata['color'])) {
427+
$bck = $metadata['color'];
428+
}
429+
430+
$html = '<a class="metaentry btn btn-block tagged" href="' . $t->getContinueUrl($metadata['entityid']) .
431+
'" style="background: ' . $bck . '">';
432+
433+
$html .= '<img src="' . $metadata['icon'] . '">';
434+
435+
if (isset($metadata['fullDisplayName'])) {
436+
$html .= '<strong>' . $metadata['fullDisplayName'] . '</strong>';
437+
} elseif ($showSignInWith) {
438+
$html .= '<strong>' . $t->t('{perun:disco:sign_in_with}') . $t->getTranslatedEntityName($metadata) .
439+
'</strong>';
440+
} else {
441+
$html .= '<strong>' . $t->getTranslatedEntityName($metadata) . '</strong>';
442+
}
443+
444+
$html .= '</a>';
445+
446+
return $html;
447+
}
448+
449+
public static function getOr()
450+
{
451+
$or = '<div class="hrline">';
452+
$or .= ' <span>or</span>';
453+
$or .= '</div>';
454+
return $or;
455+
}
456+
457+
public static function showAllTaggedIdPs($t)
458+
{
459+
$html = '';
460+
$html .= self::showTaggedIdPs($t, 'preferred');
461+
$html .= self::showTaggedIdPs($t, 'social', true);
462+
return $html;
463+
}
464+
465+
466+
public static function showTaggedIdPs($t, $tag, $showSignInWith = false)
467+
{
468+
$html = '';
469+
$idps = $t->getIdPs($tag);
470+
$idpCount = count($idps);
471+
$counter = 0;
472+
473+
$fullRowCount = floor($idpCount / 3);
474+
for ($i = 0; $i < $fullRowCount; $i++) {
475+
$html .= '<div class="row">';
476+
for ($j = 0; $j < 3; $j++) {
477+
$html .= '<div class="col-md-4">';
478+
$html .= '<div class="metalist list-group">';
479+
$html .= self::showTaggedEntry($t, $idps[array_keys($idps)[$counter]], $showSignInWith);
480+
$html .= '</div>';
481+
$html .= '</div>';
482+
$counter++;
483+
}
484+
$html .= '</div>';
485+
}
486+
if (($idpCount % 3) !== 0) {
487+
$html .= '<div class="row">';
488+
for ($i = 0; $i < $idpCount % 3; $i++) {
489+
$html .= '<div class="col-md-' . (12 / ($idpCount % 3)) . '">';
490+
$html .= '<div class="metalist list-group">';
491+
$html .= showTaggedEntry($t, $idps[array_keys($idps)[$counter]], $showSignInWith);
492+
$html .= '</div>';
493+
$html .= '</div>';
494+
$counter++;
495+
}
496+
$html .= '</div>';
497+
}
498+
499+
return $html;
500+
}
501+
502+
public static function showEntriesScript()
503+
{
504+
$script = '<script type="text/javascript">
505+
$(document).ready(function() {
506+
$("#showEntries").click(function() {
507+
$("#entries").show();
508+
$("#showEntries").hide();
509+
});
510+
});
511+
</script>';
512+
return $script;
513+
}
514+
515+
public static function searchScript()
516+
{
517+
518+
$script = '<script type="text/javascript">
519+
520+
$(document).ready(function() {
521+
$("#query").liveUpdate("#list");
522+
});
523+
524+
</script>';
525+
526+
return $script;
527+
}
528+
529+
public static function setFocus()
530+
{
531+
$script = '<script type="text/javascript">
532+
533+
$(document).ready(function() {
534+
if ($("#last-used-idp")) {
535+
$("#last-used-idp .metaentry").focus();
536+
}
537+
});
538+
539+
</script>';
540+
541+
return $script;
542+
}
376543
}

lib/ListOfSps.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
namespace SimpleSAML\Module\perun;
3+
4+
class ListOfSps
5+
{
6+
public static function sortByName($a, $b)
7+
{
8+
return strcmp(strtolower($a['facility']->getName()), strtolower($b['facility']->getName()));
9+
}
10+
11+
public static function getClass($attribute)
12+
{
13+
if ($attribute['type'] === 'java.lang.String' || $attribute['type'] === 'java.lang.LargeString') {
14+
return 'string';
15+
} elseif ($attribute['type'] === 'java.lang.Integer') {
16+
return 'integer';
17+
} elseif ($attribute['type'] === 'java.lang.Boolean') {
18+
return 'boolean';
19+
} elseif ($attribute['type'] === 'java.util.ArrayList' || $attribute['type'] === 'java.util.LargeArrayList') {
20+
return 'array';
21+
} elseif ($attribute['type'] === 'java.util.LinkedHashMap') {
22+
return 'map';
23+
} else {
24+
return '';
25+
}
26+
}
27+
28+
public static function printServiceName($service)
29+
{
30+
if (empty($service['loginURL']['value'])
31+
) {
32+
return $service['facility']->getName();
33+
}
34+
35+
return "<a class='customLink' href='" . $service['loginURL']['value'] . "'>" .
36+
$service['facility']->getName() . "</a>";
37+
}
38+
39+
public static function printAttributeValue($attribute, $service, $attr)
40+
{
41+
$value = $attribute['value'];
42+
if (empty($value) && $attribute['type'] !== 'java.lang.Boolean') {
43+
return "<td class='center'>&horbar;</td>";
44+
}
45+
$string = '';
46+
if ($attribute['type'] === 'java.lang.String' || $attribute['type'] === 'java.lang.LargeString') {
47+
if (filter_var($value, FILTER_VALIDATE_URL)) {
48+
$string = '<a class="customLink" href="' . $value . '">' . $value . '</a>';
49+
} else {
50+
$string = $value;
51+
}
52+
} elseif ($attribute['type'] === 'java.lang.Integer') {
53+
$string = $value;
54+
} elseif ($attribute['type'] === 'java.lang.Boolean') {
55+
if ($value !== null && $value) {
56+
$string = '&#x2714;';
57+
} else {
58+
$string = '&#x2715;';
59+
}
60+
} elseif ($attribute['type'] === 'java.util.ArrayList' || $attribute['type'] === 'java.lang.LargeArrayList') {
61+
$string = '<ul>';
62+
foreach ($value as $v) {
63+
$string .= '<li>' . $v . '</li>';
64+
}
65+
$string .= '</ul>';
66+
} elseif ($attribute['type'] === 'java.util.LinkedHashMap') {
67+
$string = '<ul>';
68+
foreach ($value as $k => $v) {
69+
$string .= '<li>' . $k . ' &rarr; ' . $v . '</li>';
70+
}
71+
$string .= '</ul>';
72+
}
73+
if (!empty($string)) {
74+
return '<td class="' . self::getClass($service['facilityAttributes'][$attr]) . '">' . $string . '</td>';
75+
} else {
76+
return '<td/>';
77+
}
78+
}
79+
}

lib/Post.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace SimpleSAML\Module\perun;
4+
5+
/**
6+
* Class Post
7+
* @package SimpleSAML\Module\perun
8+
*
9+
* @author Pavel Vyskocil <[email protected]>
10+
*/
11+
class Post
12+
{
13+
/**
14+
* Write out one or more INPUT elements for the given name-value pair.
15+
*
16+
* If the value is a string, this function will write a single INPUT element.
17+
* If the value is an array, it will write multiple INPUT elements to
18+
* recreate the array.
19+
*
20+
* @param string $name The name of the element.
21+
* @param string|array $value The value of the element.
22+
*/
23+
public static function printItem($name, $value)
24+
{
25+
assert(is_string($name));
26+
assert(is_string($value) || is_array($value));
27+
28+
if (is_string($value)) {
29+
echo '<input type="hidden" name="' . htmlspecialchars($name) .
30+
'" value="' . htmlspecialchars($value) . '" />';
31+
return;
32+
}
33+
34+
// This is an array...
35+
foreach ($value as $index => $item) {
36+
self::printItem($name . '[' . $index . ']', $item);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)