diff --git a/public/main/admin/settings.lib.php b/public/main/admin/settings.lib.php index abdde4942ad..59f5f2ae244 100644 --- a/public/main/admin/settings.lib.php +++ b/public/main/admin/settings.lib.php @@ -262,251 +262,6 @@ function handlePlugins() echo ''; } -/** - * This function allows the platform admin to choose the default stylesheet. - * - * @author Patrick Cool , Ghent University - * @author Julio Montoya , Chamilo - */ -function handleStylesheets() -{ - $is_style_changeable = isStyleChangeable(); - $allowedFileTypes = ['png']; - - $form = new FormValidator( - 'stylesheet_upload', - 'post', - 'settings.php?category=Stylesheets#tabs-3' - ); - $form->addElement( - 'text', - 'name_stylesheet', - get_lang('Name of the stylesheet'), - ['size' => '40', 'maxlength' => '40'] - ); - $form->addRule( - 'name_stylesheet', - get_lang('Required field'), - 'required' - ); - $form->addElement( - 'file', - 'new_stylesheet', - get_lang('New stylesheet file') - ); - $allowed_file_types = getAllowedFileTypes(); - - $form->addRule( - 'new_stylesheet', - get_lang('Invalid extension').' ('.implode(',', $allowed_file_types).')', - 'filetype', - $allowed_file_types - ); - $form->addRule( - 'new_stylesheet', - get_lang('Required field'), - 'required' - ); - $form->addButtonUpload(get_lang('Upload'), 'stylesheet_upload'); - - $show_upload_form = false; - $urlId = api_get_current_access_url_id(); - - if (!is_writable(CSS_UPLOAD_PATH)) { - echo Display::return_message( - CSS_UPLOAD_PATH.get_lang('is not writeable'), - 'error', - false - ); - } else { - // Uploading a new stylesheet. - if (1 == $urlId) { - $show_upload_form = true; - } else { - if ($is_style_changeable) { - $show_upload_form = true; - } - } - } - - // Stylesheet upload. - if (isset($_POST['stylesheet_upload'])) { - if ($form->validate()) { - $values = $form->exportValues(); - $picture_element = $form->getElement('new_stylesheet'); - $picture = $picture_element->getValue(); - $result = uploadStylesheet($values, $picture); - - // Add event to the system log. - $user_id = api_get_user_id(); - $category = $_GET['category']; - Event::addEvent( - LOG_CONFIGURATION_SETTINGS_CHANGE, - LOG_CONFIGURATION_SETTINGS_CATEGORY, - $category, - api_get_utc_datetime(), - $user_id - ); - - if ($result) { - echo Display::return_message(get_lang('The stylesheet has been added')); - } - } - } - - // Current style. - $selected = $currentStyle = api_get_setting('stylesheets'); - $styleFromDatabase = api_get_settings_params_simple( - ['variable = ? AND access_url = ?' => ['stylesheets', api_get_current_access_url_id()]] - ); - if ($styleFromDatabase) { - $selected = $currentStyle = $styleFromDatabase['selected_value']; - } - - if (isset($_POST['preview'])) { - $selected = $currentStyle = Security::remove_XSS($_POST['style']); - } - - $themeDir = Template::getThemeDir($selected); - $dir = api_get_path(SYS_PUBLIC_PATH).'css/'.$themeDir.'/images/'; - $url = api_get_path(WEB_CSS_PATH).'/'.$themeDir.'/images/'; - $logoFileName = 'header-logo.png'; - $newLogoFileName = 'header-logo-custom'.api_get_current_access_url_id().'.png'; - $webPlatformLogoPath = ChamiloApi::getPlatformLogoPath($selected); - - $logoForm = new FormValidator( - 'logo_upload', - 'post', - 'settings.php?category=Stylesheets#tabs-2' - ); - - $logoForm->addHtml( - Display::return_message( - sprintf( - get_lang('The logo must be of %s px in size and in %s format'), - '250 x 70', - 'PNG' - ), - 'info' - ) - ); - - if (null !== $webPlatformLogoPath) { - $logoForm->addLabel( - get_lang('Current logo'), - '' - ); - } - $logoForm->addFile('new_logo', get_lang('Update logo')); - if ($is_style_changeable) { - $logoGroup = [ - $logoForm->addButtonUpload(get_lang('Upload'), 'logo_upload', true), - $logoForm->addButtonCancel(get_lang('Reset'), 'logo_reset', true), - ]; - - $logoForm->addGroup($logoGroup); - } - - if (isset($_POST['logo_reset'])) { - if (is_file($dir.$newLogoFileName)) { - unlink($dir.$newLogoFileName); - echo Display::return_message(get_lang('Original logo recovered')); - echo ''; - } - } elseif (isset($_POST['logo_upload'])) { - $logoForm->addRule( - 'new_logo', - get_lang('Invalid extension').' ('.implode(',', $allowedFileTypes).')', - 'filetype', - $allowedFileTypes - ); - $logoForm->addRule( - 'new_logo', - get_lang('Required field'), - 'required' - ); - - if ($logoForm->validate()) { - $imageInfo = getimagesize($_FILES['new_logo']['tmp_name']); - $width = $imageInfo[0]; - $height = $imageInfo[1]; - if ($width <= 250 && $height <= 70) { - if (is_file($dir.$newLogoFileName)) { - unlink($dir.$newLogoFileName); - } - - $status = move_uploaded_file( - $_FILES['new_logo']['tmp_name'], - $dir.$newLogoFileName - ); - - if ($status) { - echo Display::return_message(get_lang('New logo uploaded')); - echo ''; - } else { - echo Display::return_message('Error - '.get_lang('No file was uploaded.'), 'error'); - } - } else { - Display::return_message('Error - '.get_lang('Image dimensions do not match the requirements. Please check the suggestions next to the image field.'), 'error'); - } - } - } - - if (isset($_POST['download'])) { - generateCSSDownloadLink($selected); - } - - $form_change = new FormValidator( - 'stylesheet_upload', - 'post', - api_get_self().'?category=Stylesheets', - null, - ['id' => 'stylesheets_id'] - ); - - $styles = $form_change->addSelectTheme( - 'style', - get_lang('Name of the stylesheet') - ); - $styles->setSelected($currentStyle); - - if ($is_style_changeable) { - $group = [ - $form_change->addButtonSave(get_lang('Save settings'), 'save', true), - $form_change->addButtonPreview(get_lang('Preview'), 'preview', true), - $form_change->addButtonDownload(get_lang('Download'), 'download', true), - ]; - - $form_change->addGroup($group); - - if ($show_upload_form) { - echo Display::tabs( - [get_lang('Update'), get_lang('Update logo'), get_lang('New stylesheet file')], - [$form_change->returnForm(), $logoForm->returnForm(), $form->returnForm()] - ); - } else { - $form_change->display(); - } - - // Little hack to update the logo image in update form when submiting - if (isset($_POST['logo_reset'])) { - echo ''; - } elseif (isset($_POST['logo_upload']) && is_file($dir.$newLogoFileName)) { - echo ''; - } - } else { - $form_change->freeze(); - } -} - /** * Creates the folder (if needed) and uploads the stylesheet in it. * @@ -708,27 +463,6 @@ function storePlugins() } } -/** - * This function allows the platform admin to choose which should be the default stylesheet. - * - * @author Patrick Cool , Ghent University - */ -function storeStylesheets() -{ - // Insert the stylesheet. - if (isStyle($_POST['style'])) { - api_set_setting( - 'stylesheets', - $_POST['style'], - null, - 'stylesheets', - api_get_current_access_url_id() - ); - } - - return true; -} - /** * This function checks if the given style is a recognize style that exists in the css directory as * a standalone directory. @@ -1896,28 +1630,6 @@ function generateCSSDownloadLink($style) } } -/** - * Helper function to tell if the style is changeable in the current URL. - * - * @return bool $changeable Whether the style can be changed in this URL or not - */ -function isStyleChangeable() -{ - $changeable = false; - $urlId = api_get_current_access_url_id(); - if ($urlId) { - $style_info = api_get_settings('stylesheets', '', 1, 0); - $url_info = api_get_access_url($urlId); - if (1 == $style_info[0]['access_url_changeable'] && 1 == $url_info['active']) { - $changeable = true; - } - } else { - $changeable = true; - } - - return $changeable; -} - /** * Get all settings of one category prepared for display in admin/settings.php. * diff --git a/public/main/admin/settings.php b/public/main/admin/settings.php index 6c5591f90bd..ab5038624e1 100644 --- a/public/main/admin/settings.php +++ b/public/main/admin/settings.php @@ -57,7 +57,7 @@ // Build the form. if (!empty($_GET['category']) && - !in_array($_GET['category'], ['Plugins', 'stylesheets', 'Search']) + !in_array($_GET['category'], ['Plugins', 'Search']) ) { $my_category = isset($_GET['category']) ? $_GET['category'] : null; $settings_array = getCategorySettings($my_category); diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 10330822d5d..875f7ec5a5d 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -2692,8 +2692,6 @@ function api_get_setting($variable, $isArray = false, $key = null) } return 'prod'; - case 'stylesheets': - $variable = 'platform.theme'; // deprecated settings // no break case 'openid_authentication': diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20170627122900.php b/src/CoreBundle/Migrations/Schema/V200/Version20170627122900.php index f94fd01cba9..ec8ca720f20 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20170627122900.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20170627122900.php @@ -96,7 +96,6 @@ public function up(Schema $schema): void 'registration' => 'required_profile_fields', 'profile' => 'changeable_options', 'timezone_value' => 'timezone', - 'stylesheets' => 'theme', 'platformLanguage' => 'platform_language', 'languagePriority1' => 'language_priority_1', 'languagePriority2' => 'language_priority_2', @@ -319,6 +318,7 @@ public function up(Schema $schema): void 'sso_force_redirect', 'activate_email_template', 'sso_authentication_subclass', + 'stylesheets', ]; foreach ($settings as $setting) { diff --git a/src/CoreBundle/Resources/config/settings.yml b/src/CoreBundle/Resources/config/settings.yml index b2c044e5265..6580ed6818f 100644 --- a/src/CoreBundle/Resources/config/settings.yml +++ b/src/CoreBundle/Resources/config/settings.yml @@ -193,8 +193,3 @@ services: class: Chamilo\CoreBundle\Settings\WebServiceSettingsSchema tags: - {name: sylius.settings_schema, alias: chamilo_core.settings.webservice, namespace: webservice} - - chamilo_core.settings.stylesheets: - class: Chamilo\CoreBundle\Settings\StylesheetsSettingsSchema - tags: - - { name: sylius.settings_schema, alias: chamilo_core.settings.stylesheets, namespace: stylesheets } diff --git a/src/CoreBundle/Settings/SettingsManager.php b/src/CoreBundle/Settings/SettingsManager.php index f598ef9175f..8b933c91baf 100644 --- a/src/CoreBundle/Settings/SettingsManager.php +++ b/src/CoreBundle/Settings/SettingsManager.php @@ -658,7 +658,6 @@ private function getVariablesAndCategories(): array // 'donotlistcampus' =>'null', 'show_email_addresses' => 'Platform', 'service_ppt2lp' => 'NULL', - 'stylesheets' => 'stylesheets', 'upload_extensions_list_type' => 'Security', 'upload_extensions_blacklist' => 'Security', 'upload_extensions_whitelist' => 'Security', @@ -920,7 +919,6 @@ private function renameVariable($variable) 'siteName' => 'site_name', 'InstitutionUrl' => 'institution_url', 'registration' => 'required_profile_fields', - 'stylesheets' => 'theme', 'platformLanguage' => 'platform_language', 'languagePriority1' => 'language_priority_1', 'languagePriority2' => 'language_priority_2', diff --git a/src/CoreBundle/Settings/StylesheetsSettingsSchema.php b/src/CoreBundle/Settings/StylesheetsSettingsSchema.php deleted file mode 100644 index fd0392f932d..00000000000 --- a/src/CoreBundle/Settings/StylesheetsSettingsSchema.php +++ /dev/null @@ -1,76 +0,0 @@ -parameterBag = $parameterBag; - } - - public function buildSettings(AbstractSettingsBuilder $builder): void - { - $builder - ->setDefaults( - [ - 'stylesheets' => 'chamilo', - ] - ) - ; - $allowedTypes = [ - 'stylesheets' => ['string'], - ]; - $this->setMultipleAllowedTypes($allowedTypes, $builder); - } - - public function buildForm(FormBuilderInterface $builder): void - { - $builder - ->add('stylesheets', ChoiceType::class, [ - 'choices' => $this->getThemeChoices(), - 'label' => 'Select Stylesheet Theme', - ]) - ; - - $this->updateFormFieldsFromSettingsInfo($builder); - } - - private function getThemeChoices(): array - { - $projectDir = $this->parameterBag->get('kernel.project_dir'); - $themesDirectory = $projectDir.'/assets/css/themes/'; - - $finder = new Finder(); - $choices = []; - - $finder->directories()->in($themesDirectory)->depth('== 0'); - if ($finder->hasResults()) { - foreach ($finder as $folder) { - $folderName = $folder->getRelativePathname(); - $choices[$this->formatFolderName($folderName)] = $folderName; - } - } - - return $choices; - } - - private function formatFolderName(string $name): string - { - return ucwords(str_replace('_', ' ', $name)); - } -}