| Total Complexity | 74 | 
| Total Lines | 589 | 
| Duplicated Lines | 0 % | 
| Changes | 7 | ||
| Bugs | 0 | Features | 1 | 
Complex classes like UIElements often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UIElements, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 32 | class UIElements extends \core\common\Entity { | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * the custom displayable variant of the term 'federation'  | 
            ||
| 36 | *  | 
            ||
| 37 | * @var string  | 
            ||
| 38 | */  | 
            ||
| 39 | public $nomenclatureFed;  | 
            ||
| 40 | |||
| 41 | /**  | 
            ||
| 42 | * the custom displayable variant of the term 'institution'  | 
            ||
| 43 | *  | 
            ||
| 44 | * @var string  | 
            ||
| 45 | */  | 
            ||
| 46 | public $nomenclatureIdP;  | 
            ||
| 47 | |||
| 48 | /**  | 
            ||
| 49 | * the custom displayable variant of the term 'hotspot'  | 
            ||
| 50 | *  | 
            ||
| 51 | * @var string  | 
            ||
| 52 | */  | 
            ||
| 53 | public $nomenclatureHotspot;  | 
            ||
| 54 | |||
| 55 | /**  | 
            ||
| 56 | * the custom displayable variant of the term 'hotspot'  | 
            ||
| 57 | *  | 
            ||
| 58 | * @var string  | 
            ||
| 59 | */  | 
            ||
| 60 | public $nomenclatureParticipant;  | 
            ||
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * Initialises the class.  | 
            ||
| 64 | *  | 
            ||
| 65 | * Mainly fetches various nomenclature from the config and attempts to translate those into local language. Needs pre-loading some terms.  | 
            ||
| 66 | */  | 
            ||
| 67 |     public function __construct() { | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 | /**  | 
            ||
| 78 | * provides human-readable text for the various option names as stored in DB.  | 
            ||
| 79 | *  | 
            ||
| 80 | * @param string $input raw text in need of a human-readable display variant  | 
            ||
| 81 | * @return string the human-readable variant  | 
            ||
| 82 | * @throws \Exception  | 
            ||
| 83 | */  | 
            ||
| 84 |     public function displayName($input) { | 
            ||
| 85 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 86 |         $ssidText = _("SSID"); | 
            ||
| 87 |         $passpointOiText = _("HS20 Consortium OI"); | 
            ||
| 88 | |||
| 89 |         if (!empty(\config\ConfAssistant::CONSORTIUM['interworking-consortium-oi']) && count(\config\ConfAssistant::CONSORTIUM['interworking-consortium-oi']) > 0) { | 
            ||
| 90 |             $passpointOiText = _("Additional HS20 Consortium OI"); | 
            ||
| 91 | }  | 
            ||
| 92 | |||
| 93 |         $displayNames = [_("Support: Web") => "support:url", | 
            ||
| 94 |             _("Support: EAP Types") => "support:eap_types", | 
            ||
| 95 |             _("Support: Phone") => "support:phone", | 
            ||
| 96 |             _("Support: E-Mail") => "support:email", | 
            ||
| 97 |             sprintf(_("%s Name"), $this->nomenclatureParticipant) => "general:instname", | 
            ||
| 98 |             sprintf(_("%s Acronym"), $this->nomenclatureParticipant) => "general:instshortname", | 
            ||
| 99 |             _("Location") => "general:geo_coordinates", | 
            ||
| 100 |             _("Logo URL") => "general:logo_url", | 
            ||
| 101 |             _("Logo image") => "general:logo_file", | 
            ||
| 102 |             _("Configure Wired Ethernet") => "media:wired", | 
            ||
| 103 |             _("Name (CN) of Authentication Server") => "eap:server_name", | 
            ||
| 104 |             _("Valid until") => "eap:ca_vailduntil", | 
            ||
| 105 |             _("Enable device assessment") => "eap:enable_nea", | 
            ||
| 106 |             _("Terms of Use") => "support:info_file", | 
            ||
| 107 |             _("CA Certificate URL") => "eap:ca_url", | 
            ||
| 108 |             _("CA Certificate File") => "eap:ca_file", | 
            ||
| 109 |             _("Profile Display Name") => "profile:name", | 
            ||
| 110 |             _("Production-Ready") => "profile:production", | 
            ||
| 111 |             _("Admin Accepted IdP Terms of Use") => 'hiddenprofile:tou_accepted', | 
            ||
| 112 |             _("Admin Accepted SP Terms of Use") => 'hiddenmanagedsp:tou_accepted', | 
            ||
| 113 |             _("Extra text on downloadpage for device") => "device-specific:customtext", | 
            ||
| 114 |             _("Redirection Target") => "device-specific:redirect", | 
            ||
| 115 |             _("Extra text on downloadpage for EAP method") => "eap-specific:customtext", | 
            ||
| 116 |             _("Turn on selection of EAP-TLS User-Name") => "eap-specific:tls_use_other_id", | 
            ||
| 117 |             _("Use GEANTlink for TTLS (Windows 8 and 10)") => "device-specific:geantlink", | 
            ||
| 118 |             _("Show the dedicated geteduroam download page for this device") => "device-specific:geteduroam", | 
            ||
| 119 |             _("Profile Description") => "profile:description", | 
            ||
| 120 |             _("Custom Installer Name Suffix") => "profile:customsuffix", | 
            ||
| 121 |             _("OpenRoaming") => "media:openroaming", | 
            ||
| 122 |             sprintf(_("%s Administrator"), $this->nomenclatureFed) => "user:fedadmin", | 
            ||
| 123 |             _("Real Name") => "user:realname", | 
            ||
| 124 |             _("E-Mail Address") => "user:email", | 
            ||
| 125 |             _("Remove/Disable SSID") => "media:remove_SSID", | 
            ||
| 126 |             _("Mandatory Content Filtering Proxy") => "media:force_proxy", | 
            ||
| 127 |             _("Custom CSS file for User Area") => "fed:css_file", | 
            ||
| 128 |             sprintf(_("%s Logo"), $this->nomenclatureFed) => "fed:logo_file", | 
            ||
| 129 |             _("Preferred Skin for User Area") => "fed:desired_skin", | 
            ||
| 130 |             sprintf(_("Include %s branding in installers"), $this->nomenclatureFed) => "fed:include_logo_installers", | 
            ||
| 131 |             sprintf(_("%s Name"), $this->nomenclatureFed) => "fed:realname", | 
            ||
| 132 |             sprintf(_("%s Homepage"), $this->nomenclatureFed) => "fed:url", | 
            ||
| 133 |             sprintf(_("Custom text in %s Invitations"), $this->nomenclatureParticipant) => "fed:custominvite", | 
            ||
| 134 |             sprintf(_("Enable %s"), \config\ConfAssistant::SILVERBULLET['product_name']) => "fed:silverbullet", | 
            ||
| 135 |             sprintf(_("%s: Do not terminate EAP"), \core\ProfileSilverbullet::PRODUCTNAME) => "fed:silverbullet-noterm", | 
            ||
| 136 |             sprintf(_("%s: max users per profile"), \core\ProfileSilverbullet::PRODUCTNAME) => "fed:silverbullet-maxusers", | 
            ||
| 137 |             sprintf(_("Mint %s with CA on creation"), $this->nomenclatureIdP) => "fed:minted_ca_file", | 
            ||
| 138 |             sprintf(_("OpenRoaming: Allow %s Opt-In"),$this->nomenclatureParticipant) => "fed:openroaming", | 
            ||
| 139 |             _("OpenRoaming: Custom NAPTR Target") => "fed:openroaming_customtarget", | 
            ||
| 140 | $ssidText => "media:SSID",  | 
            ||
| 141 | $passpointOiText => "media:consortium_OI",  | 
            ||
| 142 |             _("VLAN for own users") => "managedsp:vlan", | 
            ||
| 143 |             _("Realm to be considered own users") => "managedsp:realmforvlan", | 
            ||
| 144 |             _("Custom Operator-Name attribute") => "managedsp:operatorname", | 
            ||
| 145 | ];  | 
            ||
| 146 | |||
| 147 | $find = array_keys($displayNames, $input, TRUE);  | 
            ||
| 148 | |||
| 149 |         if (count($find) == 0) { // this is an error! throw an Exception | 
            ||
| 150 |             throw new \Exception("The translation of an option name was requested, but the option is not known to the system: " . htmlentities($input)); | 
            ||
| 151 | }  | 
            ||
| 152 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 153 | // none of the strings have HTML in them, only translators can provide own text for it -> no threat, but complained about by the security review  | 
            ||
| 154 | return htmlspecialchars($find[0]);  | 
            ||
| 155 | }  | 
            ||
| 156 | |||
| 157 | /**  | 
            ||
| 158 | * creates an HTML information block with a list of options from a given category and level  | 
            ||
| 159 | * @param array $optionlist list of options  | 
            ||
| 160 | * @param string $class option class of interest  | 
            ||
| 161 | * @param string $level option level of interest  | 
            ||
| 162 | * @return string HTML code  | 
            ||
| 163 | */  | 
            ||
| 164 |     public function infoblock(array $optionlist, string $class, string $level) { | 
            ||
| 165 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 166 | $locationMarkers = [];  | 
            ||
| 167 | $retval = "";  | 
            ||
| 168 | $optioninfo = \core\Options::instance();  | 
            ||
| 169 | |||
| 170 |         foreach ($optionlist as $option) { | 
            ||
| 171 | $type = $optioninfo->optionType($option['name']);  | 
            ||
| 172 |             if (preg_match('/^' . $class . '/', $option['name']) && $option['level'] == "$level") { | 
            ||
| 173 | // all non-multilang attribs get this assignment ...  | 
            ||
| 174 | $language = "";  | 
            ||
| 175 | $content = $option['value'];  | 
            ||
| 176 | // ... override them with multilang tags if needed  | 
            ||
| 177 |                 if ($type["flag"] == "ML") { | 
            ||
| 178 |                     $language = _("default/other languages"); | 
            ||
| 179 |                     if ($option['lang'] != 'C') { | 
            ||
| 180 | $language = \config\Master::LANGUAGES[$option['lang']]['display'] ?? "(unsupported language)";  | 
            ||
| 181 | }  | 
            ||
| 182 | }  | 
            ||
| 183 | |||
| 184 |                 switch ($type["type"]) { | 
            ||
| 185 | case "coordinates":  | 
            ||
| 186 | $coords = json_decode($option['value'], true);  | 
            ||
| 187 | $locationMarkers[] = $coords;  | 
            ||
| 188 | break;  | 
            ||
| 189 | case "file":  | 
            ||
| 190 | $retval .= "<tr><td>" . $this->displayName($option['name']) . "</td><td>$language</td><td>";  | 
            ||
| 191 |                         switch ($option['name']) { | 
            ||
| 192 | case "general:logo_file":  | 
            ||
| 193 | case "fed:logo_file":  | 
            ||
| 194 |                                 $retval .= $this->previewImageinHTML('ROWID-' . $option['level'] . '-' . $option['row_id']); | 
            ||
| 195 | break;  | 
            ||
| 196 | case "eap:ca_file":  | 
            ||
| 197 | // fall-through intended: display both the same way  | 
            ||
| 198 | case "fed:minted_ca_file":  | 
            ||
| 199 |                                 $retval .= $this->previewCAinHTML('ROWID-' . $option['level'] . '-' . $option['row_id']); | 
            ||
| 200 | break;  | 
            ||
| 201 | case "support:info_file":  | 
            ||
| 202 |                                 $retval .= $this->previewInfoFileinHTML('ROWID-' . $option['level'] . '-' . $option['row_id']); | 
            ||
| 203 | break;  | 
            ||
| 204 | default:  | 
            ||
| 205 | }  | 
            ||
| 206 | break;  | 
            ||
| 207 | case "boolean":  | 
            ||
| 208 |                         if ($option['name'] == "fed:silverbullet" && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_SILVERBULLET'] == "LOCAL" && \config\Master::FUNCTIONALITY_LOCATIONS['CONFASSISTANT_RADIUS'] != "LOCAL") { | 
            ||
| 209 | // do not display the option at all; it gets auto-set by the ProfileSilverbullet constructor and doesn't have to be seen  | 
            ||
| 210 | break;  | 
            ||
| 211 | }  | 
            ||
| 212 |                         $retval .= "<tr><td>" . $this->displayName($option['name']) . "</td><td>$language</td><td><strong>" . ($content == "on" ? _("on") : _("off") ) . "</strong></td></tr>"; | 
            ||
| 213 | break;  | 
            ||
| 214 | default:  | 
            ||
| 215 | $retval .= "<tr><td>" . $this->displayName($option['name']) . "</td><td>$language</td><td><strong>$content</strong></td></tr>";  | 
            ||
| 216 | }  | 
            ||
| 217 | }  | 
            ||
| 218 | }  | 
            ||
| 219 |         if (count($locationMarkers)) { | 
            ||
| 220 | $marker = '<markers>';  | 
            ||
| 221 | $locationCount = 0;  | 
            ||
| 222 |             foreach ($locationMarkers as $g) { | 
            ||
| 223 | $locationCount++;  | 
            ||
| 224 | $marker .= '<marker name="' . $locationCount . '" lat="' . $g['lat'] . '" lng="' . $g['lon'] . '" />';  | 
            ||
| 225 | }  | 
            ||
| 226 | $marker .= '<\/markers>'; // some validator says this should be escaped  | 
            ||
| 227 | $jMarker = json_encode($locationMarkers);  | 
            ||
| 228 | $retval .= '<tr><td><script>markers=\'' . $marker . '\'; jmarkers = \'' . $jMarker . '\';</script></td><td></td><td></td></tr>';  | 
            ||
| 229 | }  | 
            ||
| 230 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 231 | return $retval;  | 
            ||
| 232 | }  | 
            ||
| 233 | |||
| 234 | /**  | 
            ||
| 235 | * creates HTML code to display all information boxes for an IdP  | 
            ||
| 236 | *  | 
            ||
| 237 | * @param \core\IdP $myInst the IdP in question  | 
            ||
| 238 | * @return string HTML code  | 
            ||
| 239 | */  | 
            ||
| 240 |     public function instLevelInfoBoxes(\core\IdP $myInst) { | 
            ||
| 241 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 242 | $idpoptions = $myInst->getAttributes();  | 
            ||
| 243 | $retval = "<div class='infobox'>  | 
            ||
| 244 |         <h2>" . sprintf(_("General %s details"), $this->nomenclatureParticipant) . "</h2> | 
            ||
| 245 | <table>  | 
            ||
| 246 | <tr>  | 
            ||
| 247 | <td>  | 
            ||
| 248 |                     " . _("Country:") . " | 
            ||
| 249 | </td>  | 
            ||
| 250 | <td>  | 
            ||
| 251 | </td>  | 
            ||
| 252 | <td>  | 
            ||
| 253 | <strong>";  | 
            ||
| 254 | $myFed = new \core\Federation($myInst->federation);  | 
            ||
| 255 | $retval .= $myFed->name;  | 
            ||
| 256 | $retval .= "</strong>  | 
            ||
| 257 | </td>  | 
            ||
| 258 | </tr>" . $this->infoblock($idpoptions, "general", "IdP") . "  | 
            ||
| 259 | </table>  | 
            ||
| 260 | </div>";  | 
            ||
| 261 | |||
| 262 |         $blocks = [["support", _("Global Helpdesk Details")], ["media", _("Media Properties")]]; | 
            ||
| 263 |         foreach ($blocks as $block) { | 
            ||
| 264 | $retval .= "<div class='infobox'>  | 
            ||
| 265 | <h2>" . $block[1] . "</h2>  | 
            ||
| 266 | <table>" .  | 
            ||
| 267 | $this->infoblock($idpoptions, $block[0], "IdP") .  | 
            ||
| 268 | "</table>  | 
            ||
| 269 | </div>";  | 
            ||
| 270 | }  | 
            ||
| 271 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 272 | return $retval;  | 
            ||
| 273 | }  | 
            ||
| 274 | |||
| 275 | /**  | 
            ||
| 276 | * pretty-prints a file size number in SI "bi" units  | 
            ||
| 277 | * @param int $number the size of the file  | 
            ||
| 278 | * @return string the pretty-print representation of the file size  | 
            ||
| 279 | */  | 
            ||
| 280 |     private function displaySize(int $number) { | 
            ||
| 288 | }  | 
            ||
| 289 | |||
| 290 | /**  | 
            ||
| 291 | *  | 
            ||
| 292 | * @param string $table the database table  | 
            ||
| 293 | * @param integer $rowindex the database row_id  | 
            ||
| 294 | * @param boolean $checkpublic should we check if the requested piece of data is public?  | 
            ||
| 295 | * @return string|boolean the requested data, or FALSE if something went wrong  | 
            ||
| 296 | */  | 
            ||
| 297 |     public static function getBlobFromDB($table, $rowindex, $checkpublic) { | 
            ||
| 327 | }  | 
            ||
| 328 | |||
| 329 | /**  | 
            ||
| 330 | * creates HTML code to display a nice UI representation of a CA  | 
            ||
| 331 | *  | 
            ||
| 332 | * @param string $cAReference ROWID pointer to the CA to display  | 
            ||
| 333 | * @return string HTML code  | 
            ||
| 334 | */  | 
            ||
| 335 |     public function previewCAinHTML($cAReference) { | 
            ||
| 336 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 337 | $validator = new \web\lib\common\InputValidation();  | 
            ||
| 338 | $ref = $validator->databaseReference($cAReference);  | 
            ||
| 339 | $caExpiryTrashhold = 5184000; // 60 days  | 
            ||
| 340 | $rawResult = UIElements::getBlobFromDB($ref['table'], $ref['rowindex'], FALSE);  | 
            ||
| 341 |         if (is_bool($rawResult)) { // we didn't actually get a CA! | 
            ||
| 342 |             $retval = "<div class='ca-summary'>" . _("There was an error while retrieving the certificate from the database!") . "</div>"; | 
            ||
| 343 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 344 | return $retval;  | 
            ||
| 345 | }  | 
            ||
| 346 | $cAblob = base64_decode($rawResult);  | 
            ||
| 347 | |||
| 348 | $func = new \core\common\X509;  | 
            ||
| 349 | $details = $func->processCertificate($cAblob);  | 
            ||
| 350 |         if ($details === FALSE) { | 
            ||
| 351 |             $retval = _("There was an error processing the certificate!"); | 
            ||
| 352 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 353 | return $retval;  | 
            ||
| 354 | }  | 
            ||
| 355 | |||
| 356 |         $details['name'] = preg_replace('/(.)\/(.)/', "$1<br/>$2", $details['name']); | 
            ||
| 357 |         $details['name'] = preg_replace('/\//', "", $details['name']); | 
            ||
| 358 | $certstatus = ( $details['root'] == 1 ? "R" : "I");  | 
            ||
| 359 |         $certTooltip = ( $details['root'] == 1 ? _("Root CA") : _("Intermediate CA")); | 
            ||
| 360 | $mainbgColor = "#ccccff";  | 
            ||
| 361 | $innerbgColor = "#0000ff";  | 
            ||
| 362 | $message = "";  | 
            ||
| 363 |         if ($details['ca'] == 0 && $details['root'] != 1) { | 
            ||
| 364 | $mainbgColor = "red";  | 
            ||
| 365 | $innerbgColor = "maroon";  | 
            ||
| 366 |             $message = _("This is a <strong>SERVER</strong> certificate!") . "<br/>"; | 
            ||
| 367 | $retval = "<div class='ca-summary' style='background-color:$mainbgColor'><div style='position:absolute; right: 0px; width:20px; height:20px; background-color:$innerbgColor; border-radius:10px; text-align: center;'><div style='padding-top:3px; font-weight:bold; color:#ffffff;'>S</div></div>" . $message . $details['name'] . "</div>";  | 
            ||
| 368 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 369 | return $retval;  | 
            ||
| 370 | }  | 
            ||
| 371 | |||
| 372 |         if (time() > $details['full_details']['validTo_time_t']) { | 
            ||
| 373 | $mainbgColor = "red";  | 
            ||
| 374 | $innerbgColor = "maroon";  | 
            ||
| 375 |             $message = _("Certificate expired!") . "<br>"; | 
            ||
| 376 |         } elseif(time() > $details['full_details']['validTo_time_t'] - $caExpiryTrashhold) { | 
            ||
| 377 | $mainbgColor = "yellow";  | 
            ||
| 378 | $innerbgColor = "#0000ff";  | 
            ||
| 379 |             $message = _("Certificate close to expiry!") . "<br>";             | 
            ||
| 380 | }  | 
            ||
| 381 | |||
| 382 |         if ($details['root'] == 1 && $details['basicconstraints_set'] == 0) { | 
            ||
| 383 |             if ($mainbgColor == "#ccccff") { | 
            ||
| 384 | $mainbgColor = "yellow";  | 
            ||
| 385 | }  | 
            ||
| 386 |             $message .= "<div style='max-width: 25em'><strong>" . _("Improper root certificate, required critical CA extension missing, will not reliably install!") . "</strong><br><a target='_blank' href=''>". _("more info")."</a></div><br>"; | 
            ||
| 387 | }  | 
            ||
| 388 | |||
| 389 |         $retval =     "<div class='ca-summary' style='background-color:$mainbgColor'><div style='position:absolute; right: 0px; width:20px; height:20px; background-color:$innerbgColor; border-radius:10px; text-align: center;'><div title='$certTooltip' style='padding-top:3px; font-weight:bold; color:#ffffff;'>$certstatus</div></div>" . $message . $details['name'] . "<br>" . $this->displayName('eap:ca_vailduntil') . " " . gmdate('Y-m-d H:i:s', $details['full_details']['validTo_time_t']) . " UTC</div>"; | 
            ||
| 390 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 391 | return $retval;  | 
            ||
| 392 | }  | 
            ||
| 393 | |||
| 394 | /**  | 
            ||
| 395 | * creates HTML code to display a nice UI representation of an image  | 
            ||
| 396 | *  | 
            ||
| 397 | * @param string $imageReference ROWID pointer to the image to display  | 
            ||
| 398 | * @return string HTML code  | 
            ||
| 399 | */  | 
            ||
| 400 |     public function previewImageinHTML($imageReference) { | 
            ||
| 401 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 402 |         $retval = "<img style='max-width:150px' src='inc/filepreview.php?id=" . $imageReference . "' alt='" . _("Preview of logo file") . "'/>"; | 
            ||
| 403 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 404 | return $retval;  | 
            ||
| 405 | }  | 
            ||
| 406 | |||
| 407 | /**  | 
            ||
| 408 | * creates HTML code to display a nice UI representation of a TermsOfUse file  | 
            ||
| 409 | *  | 
            ||
| 410 | * @param string $fileReference ROWID pointer to the file to display  | 
            ||
| 411 | * @return string HTML code  | 
            ||
| 412 | */  | 
            ||
| 413 |     public function previewInfoFileinHTML($fileReference) { | 
            ||
| 414 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 415 | $validator = new \web\lib\common\InputValidation();  | 
            ||
| 416 | $ref = $validator->databaseReference($fileReference);  | 
            ||
| 417 | $fileBlob = UIElements::getBlobFromDB($ref['table'], $ref['rowindex'], FALSE);  | 
            ||
| 418 |         if (is_bool($fileBlob)) { // we didn't actually get a file! | 
            ||
| 419 |             $retval = "<div class='ca-summary'>" . _("There was an error while retrieving the file from the database!") . "</div>"; | 
            ||
| 420 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 421 | return $retval;  | 
            ||
| 422 | }  | 
            ||
| 423 | $decodedFileBlob = base64_decode($fileBlob);  | 
            ||
| 424 | $fileinfo = new \finfo();  | 
            ||
| 425 |         $retval = "<div class='ca-summary'>" . _("File exists") . " (" . $fileinfo->buffer($decodedFileBlob, FILEINFO_MIME_TYPE) . ", " . $this->displaySize(strlen($decodedFileBlob)) . ")<br/><a href='inc/filepreview.php?id=$fileReference'>" . _("Preview") . "</a></div>"; | 
            ||
| 426 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 427 | return $retval;  | 
            ||
| 428 | }  | 
            ||
| 429 | |||
| 430 | /**  | 
            ||
| 431 | * creates HTML code for a UI element which informs the user about something.  | 
            ||
| 432 | *  | 
            ||
| 433 | * @param int $level what kind of information is to be displayed?  | 
            ||
| 434 | * @param string $text the text to display  | 
            ||
| 435 | * @param string $caption the caption to display  | 
            ||
| 436 | * @param bool $omittabletags the output usually has tr/td table tags, this option suppresses them  | 
            ||
| 437 | * @return string  | 
            ||
| 438 | */  | 
            ||
| 439 |     public function boxFlexible(int $level, string $text = NULL, string $caption = NULL, bool $omittabletags = FALSE) { | 
            ||
| 440 | \core\common\Entity::intoThePotatoes();  | 
            ||
| 441 | $uiMessages = [  | 
            ||
| 442 |             \core\common\Entity::L_OK => ['icon' => '../resources/images/icons/Quetto/check-icon.png', 'text' => _("OK")], | 
            ||
| 443 |             \core\common\Entity::L_REMARK => ['icon' => '../resources/images/icons/Quetto/info-icon.png', 'text' => _("Remark")], | 
            ||
| 444 |             \core\common\Entity::L_WARN => ['icon' => '../resources/images/icons/Quetto/danger-icon.png', 'text' => _("Warning!")], | 
            ||
| 445 |             \core\common\Entity::L_ERROR => ['icon' => '../resources/images/icons/Quetto/no-icon.png', 'text' => _("Error!")], | 
            ||
| 446 | ];  | 
            ||
| 447 | |||
| 448 | $retval = "";  | 
            ||
| 449 |         if (!$omittabletags) { | 
            ||
| 450 | $retval .= "<tr><td>";  | 
            ||
| 451 | }  | 
            ||
| 452 | $finalCaption = ($caption !== NULL ? $caption : $uiMessages[$level]['text']);  | 
            ||
| 453 | $retval .= "<img class='icon' src='" . $uiMessages[$level]['icon'] . "' alt='" . $finalCaption . "' title='" . $finalCaption . "'/>";  | 
            ||
| 454 |         if (!$omittabletags) { | 
            ||
| 455 | $retval .= "</td><td>";  | 
            ||
| 456 | }  | 
            ||
| 457 |         if ($text !== NULL) { | 
            ||
| 458 | $retval .= $text;  | 
            ||
| 459 | }  | 
            ||
| 460 |         if (!$omittabletags) { | 
            ||
| 461 | $retval .= "</td></tr>";  | 
            ||
| 462 | }  | 
            ||
| 463 | \core\common\Entity::outOfThePotatoes();  | 
            ||
| 464 | return $retval;  | 
            ||
| 465 | }  | 
            ||
| 466 | |||
| 467 | /**  | 
            ||
| 468 | * creates HTML code to display an "all is okay" message  | 
            ||
| 469 | *  | 
            ||
| 470 | * @param string $text the text to display  | 
            ||
| 471 | * @param string $caption the caption to display  | 
            ||
| 472 | * @param bool $omittabletags the output usually has tr/td table tags, this option suppresses them  | 
            ||
| 473 | * @return string HTML: the box  | 
            ||
| 474 | */  | 
            ||
| 475 |     public function boxOkay(string $text = NULL, string $caption = NULL, bool $omittabletags = FALSE) { | 
            ||
| 476 | return $this->boxFlexible(\core\common\Entity::L_OK, $text, $caption, $omittabletags);  | 
            ||
| 477 | }  | 
            ||
| 478 | |||
| 479 | /**  | 
            ||
| 480 | * creates HTML code to display a "smartass comment" message  | 
            ||
| 481 | *  | 
            ||
| 482 | * @param string $text the text to display  | 
            ||
| 483 | * @param string $caption the caption to display  | 
            ||
| 484 | * @param bool $omittabletags the output usually has tr/td table tags, this option suppresses them  | 
            ||
| 485 | * @return string HTML: the box  | 
            ||
| 486 | */  | 
            ||
| 487 |     public function boxRemark(string $text = NULL, string $caption = NULL, bool $omittabletags = FALSE) { | 
            ||
| 488 | return $this->boxFlexible(\core\common\Entity::L_REMARK, $text, $caption, $omittabletags);  | 
            ||
| 489 | }  | 
            ||
| 490 | |||
| 491 | /**  | 
            ||
| 492 | * creates HTML code to display a "something's a bit wrong" message  | 
            ||
| 493 | *  | 
            ||
| 494 | * @param string $text the text to display  | 
            ||
| 495 | * @param string $caption the caption to display  | 
            ||
| 496 | * @param bool $omittabletags the output usually has tr/td table tags, this option suppresses them  | 
            ||
| 497 | * @return string HTML: the box  | 
            ||
| 498 | */  | 
            ||
| 499 |     public function boxWarning(string $text = NULL, string $caption = NULL, bool $omittabletags = FALSE) { | 
            ||
| 500 | return $this->boxFlexible(\core\common\Entity::L_WARN, $text, $caption, $omittabletags);  | 
            ||
| 501 | }  | 
            ||
| 502 | |||
| 503 | /**  | 
            ||
| 504 | * creates HTML code to display a "Whoa! Danger, Will Robinson!" message  | 
            ||
| 505 | *  | 
            ||
| 506 | * @param string $text the text to display  | 
            ||
| 507 | * @param string $caption the caption to display  | 
            ||
| 508 | * @param bool $omittabletags the output usually has tr/td table tags, this option suppresses them  | 
            ||
| 509 | * @return string HTML: the box  | 
            ||
| 510 | */  | 
            ||
| 511 |     public function boxError(string $text = NULL, string $caption = NULL, bool $omittabletags = FALSE) { | 
            ||
| 513 | }  | 
            ||
| 514 | |||
| 515 | const QRCODE_PIXELS_PER_SYMBOL = 12;  | 
            ||
| 516 | |||
| 517 | /**  | 
            ||
| 518 | * Injects the consortium logo in the middle of a given PNG.  | 
            ||
| 519 | *  | 
            ||
| 520 | * Usually used on QR code PNGs - the parameters inform about the structure of  | 
            ||
| 521 | * the QR code so that the logo does not prevent parsing of the QR code.  | 
            ||
| 522 | *  | 
            ||
| 523 | * @param string $inputpngstring the PNG to edit  | 
            ||
| 524 | * @param int $symbolsize size in pixels of one QR "pixel"  | 
            ||
| 525 | * @param int $marginsymbols size in pixels of border around the actual QR  | 
            ||
| 526 | * @return string the image with logo centered in the middle  | 
            ||
| 527 | */  | 
            ||
| 528 |     public function pngInjectConsortiumLogo(string $inputpngstring, int $symbolsize, int $marginsymbols = 4) { | 
            ||
| 568 | }  | 
            ||
| 569 | |||
| 570 | /**  | 
            ||
| 571 | * Something went wrong. We display the error cause and then throw an Exception.  | 
            ||
| 572 | *  | 
            ||
| 573 | * @param string $headerDisplay error to put in the page header  | 
            ||
| 574 | * @param string $uiDisplay error string to display  | 
            ||
| 575 | * @return void direct output  | 
            ||
| 576 | * @throws Exception  | 
            ||
| 577 | */  | 
            ||
| 578 |     public function errorPage($headerDisplay, $uiDisplay) { | 
            ||
| 584 | }  | 
            ||
| 585 | |||
| 586 | /**  | 
            ||
| 587 | * creates the HTML code displaying the result of a test that was run previously  | 
            ||
| 588 | *  | 
            ||
| 589 | * @param \core\SanityTests $test the test that was run  | 
            ||
| 590 | * @return string  | 
            ||
| 591 | * @throws Exception  | 
            ||
| 592 | */  | 
            ||
| 593 |     public function sanityTestResultHTML($test) { | 
            ||
| 621 | }  | 
            ||
| 622 | |||
| 624 |