getEmpty(); $config->fields = array_merge($config->fields, \Config::getConfigurationValues('butterfly')); self::$_cache = $config->fields; } if (isset(self::$_cache[$name]) && self::$_cache[$name] !== '') { return self::$_cache[$name]; } return $defaultValue; } function getTabNameForItem(\CommonGLPI $item, $withtemplate = 0) { switch (get_class($item)) { case 'Config': return [1 => t_butterfly('Butterfly')]; default: return ''; } } static function displayTabContentForItem(\CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch (get_class($item)) { case 'Config': $config = new self(); $config->showFormDisplay(); break; } return true; } protected static function checkPicture($name, $input, $old, $width = 0, $height = 0, $max_size = 500) { $blank = "_blank_$name"; $new = "_$name"; if (isset($input[$blank]) && $input[$blank]) { unset($input[$blank]); if (isset($old[$name]) && $old[$name]) { Toolbox::deletePicture($old[$name]); } $input[$name] = ''; } else if (isset($input[$new]) && !empty($input[$new]) && !empty($input[$new][0])) { $picName = array_shift($input[$new]); // Use GLPI temp directory if available, fallback to system temp $glpiTmpConstant = 'GLPI_TMP_DIR'; $tmpDir = (defined($glpiTmpConstant) && constant($glpiTmpConstant)) ? constant($glpiTmpConstant) : sys_get_temp_dir(); $picPath = $tmpDir . '/' . $picName; $picResizedPath = $tmpDir . '/resized_' . $picName; if ($width || $height) { if (Toolbox::resizePicture($picPath, $picResizedPath, $width, $height, 0, 0, 0, 0, $max_size)) { $picPath = $picResizedPath; } } if ($dest = Toolbox::savePicture($picPath)) { $input[$name] = $dest; } else { \Session::addMessageAfterRedirect(__('Unable to save picture file.'), true, ERROR); } if (isset($old[$name]) && $old[$name]) { Toolbox::deletePicture($old[$name]); } } unset($input["_$name"]); unset($input["_prefix_$name"]); unset($input["_prefix_new_$name"]); unset($input["_tag_$name"]); unset($input["_tag_new_$name"]); unset($input["_uploader_$name"]); unset($input["new_$name"]); unset($input[$blank]); unset($input[$new]); return $input; } protected static function checkCSS($name, $label, $input, $old) { $fullName = "{$name}_css_custom"; $type = "{$name}_css_type"; if (!isset($input[$type])) { $input[$type] = 'css'; } if (isset($input[$fullName])) { $input[$fullName] = html_entity_decode($input[$fullName]); $input[$fullName] = preg_replace('/\\\\r\\\\n/', "\n", $input[$fullName]); $input[$fullName] = preg_replace('/\\\\n/', "\n", $input[$fullName]); if ($input[$type] === 'scss' && Scss::hasScssSuport()) { try { $variables = []; $variables['butterfly_timestamp'] = Toolbox::getTimestamp(); Scss::compileScss($input[$fullName], $variables); } catch (\Throwable $th) { $message = sprintf(t_butterfly('Unable to compile the SCSS (%1$s). Message: '), $label); \Session::addMessageAfterRedirect($message . $th->getMessage(), true, ERROR); } } } return $input; } static function configUpdate($input) { $old = \Config::getConfigurationValues('butterfly'); unset($input['_no_history']); $input = self::checkPicture('favicon_picture', $input, $old, 192, 192, 192); $input = self::checkPicture('login_picture', $input, $old, 145, 80, 300); $input = self::checkPicture('internal_picture', $input, $old, 100, 55, 300); $input = self::checkPicture('login_background_picture', $input, $old); $input = self::checkCSS('login', t_butterfly('Login Page'), $input, $old); $input = self::checkCSS('internal', t_butterfly('Internal Page'), $input, $old); foreach ($input as $key => $value) { if ($value && strpos($key, '_blank_') === 0) { $name = substr($key, 7); $input[$name] = ''; } } $input['timestamp'] = time(); Toolbox::setTimestamp($input['timestamp']); \Session::addMessageAfterRedirect(__('Item successfully updated'), false, INFO); return $input; } function getEmpty() { $defaultCss = 'css'; if (Scss::hasScssSuport()) { $defaultCss = 'scss'; } $this->fields = [ 'favicon_picture' => '', 'page_title' => '', 'page_footer_display' => 'original', 'page_footer_text' => '', 'login_picture' => '', 'login_picture_max_width' => '240px', 'login_picture_max_height' => '130px', 'login_css_custom' => '', 'login_css_type' => $defaultCss, 'login_theme' => '', 'internal_picture' => '', 'internal_picture_width' => '100px', 'internal_picture_height' => '55px', 'internal_css_custom' => '', 'internal_css_type' => $defaultCss, ]; } protected function buildPictureLine($name, $recommendedSize = null) { if (!empty($this->fields[$name])) { echo '