Skip to content

Commit

Permalink
Internal: Remove references to stylesheets setting - refs BT#21621
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Jun 25, 2024
1 parent 032e42d commit 0395a69
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 375 deletions.
288 changes: 0 additions & 288 deletions public/main/admin/settings.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,251 +262,6 @@ function handlePlugins()
echo '</form>';
}

/**
* This function allows the platform admin to choose the default stylesheet.
*
* @author Patrick Cool <[email protected]>, Ghent University
* @author Julio Montoya <[email protected]>, 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'),
'<img id="header-logo-custom" src="'.$webPlatformLogoPath.'?'.time().'">'
);
}
$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 '<script>'
.'$("#header-logo").attr("src","'.$url.$logoFileName.'");'
.'</script>';
}
} 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 '<script>'
.'$("#header-logo").attr("src","'.$url.$newLogoFileName.'");'
.'</script>';
} 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 '<script>'
.'$("#header-logo-custom").attr("src","'.$url.$logoFileName.'");'
.'</script>';
} elseif (isset($_POST['logo_upload']) && is_file($dir.$newLogoFileName)) {
echo '<script>'
.'$("#header-logo-custom").attr("src","'.$url.$newLogoFileName.'");'
.'</script>';
}
} else {
$form_change->freeze();
}
}

/**
* Creates the folder (if needed) and uploads the stylesheet in it.
*
Expand Down Expand Up @@ -708,27 +463,6 @@ function storePlugins()
}
}

/**
* This function allows the platform admin to choose which should be the default stylesheet.
*
* @author Patrick Cool <[email protected]>, 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.
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion public/main/admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions public/main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -319,6 +318,7 @@ public function up(Schema $schema): void
'sso_force_redirect',
'activate_email_template',
'sso_authentication_subclass',
'stylesheets',
];

foreach ($settings as $setting) {
Expand Down
5 changes: 0 additions & 5 deletions src/CoreBundle/Resources/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 0 additions & 2 deletions src/CoreBundle/Settings/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 0395a69

Please sign in to comment.