-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: Remove references to stylesheets setting - refs BT#21621
- Loading branch information
Showing
7 changed files
with
2 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
* | ||
|
@@ -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. | ||
|
@@ -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. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.