Commit 71487aa5 authored by Ruslan Kabalin's avatar Ruslan Kabalin

Introduce admin setting for controling HTML editor setting globally (bug #548225)

This makes possible to override user setting with global setting or letting
user to choose.

Change-Id: I7647fde82d8e06055e310cd04034cb58f1ca86e1
Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
parent eeb615aa
......@@ -102,9 +102,10 @@ $elements['friendscontrol'] = array(
);
$elements['wysiwyg'] = array(
'type' => 'checkbox',
'defaultvalue' => $prefs->wysiwyg,
'defaultvalue' => (get_config('wysiwyg')) ? get_config('wysiwyg') == 'enable' : $prefs->wysiwyg,
'title' => get_string('wysiwygdescr', 'account'),
'help' => true,
'disabled' => get_config('wysiwyg'),
);
$elements['maildisabled'] = array(
'type' => 'checkbox',
......
......@@ -450,6 +450,18 @@ $siteoptionform = array(
'defaultvalue' => get_config('allowmobileuploads'),
'disabled' => in_array('allowmobileuploads', $OVERRIDDEN),
),
'wysiwyg' => array(
'type' => 'select',
'title' => get_string('wysiwyg', 'admin'),
'description' => get_string('wysiwygdescription', 'admin'),
'defaultvalue' => get_config('wysiwyg'),
'options' => array(
'' => get_string('wysiwyguserdefined', 'admin'),
'disable' => get_string('disable'),
'enable' => get_string('enable'),
),
'help' => true,
),
),
),
)
......@@ -480,7 +492,7 @@ function siteoptions_submit(Pieform $form, $values) {
'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'disableexternalresources',
'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials',
'homepageinfo', 'showonlineuserssideblock', 'registerterms', 'allowmobileuploads',
'creategroups', 'createpublicgroups', 'allowgroupcategories',
'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg',
);
$oldlanguage = get_config('lang');
$oldtheme = get_config('theme');
......
......@@ -288,6 +288,9 @@ $string['whocancreategroups'] = 'Who can create Groups';
$string['whocancreategroupsdescription'] = 'Which users will be able to create new groups';
$string['whocancreatepublicgroups'] = 'Who can create Public Groups';
$string['whocancreatepublicgroupsdescription'] = 'Which users will be able to make groups that are viewable by the general public';
$string['wysiwyg'] = 'HTML editor';
$string['wysiwygdescription'] = 'Defines whether or not the HTML editor is enabled globally or whether users are allowed to enable/disable it themselves.';
$string['wysiwyguserdefined'] = 'User defined';
// Site content
$string['about'] = 'About';
......
<h3>HTML Editor</h3>
<p>An HTML editor is available for use on some sections of the site. This is known as a ‘What you see is what you get’ (WYSIWYG) editor. This allows you to apply formatting to your text eg: bolded or italic text. If the editor is turned off you can only enter plain text.</p>
<p><strong>Note:</strong> HTML editors may appear and work slightly differently in some browsers.</p>
<p>This setting might be disabled by site admin.</p>
<p><strong>Note:</strong>HTML editors may appear and work slightly differently in some browsers.</p>
<h3>HTML Editor</h3>
<p>This defines whether the HTML editor is used by default. If set to <b>User defined</b>, users will be allowed to choose whether to use the HTML editor in their personal settings, otherwise the specified setting will be used site-wide.</p>
......@@ -47,8 +47,7 @@ function pieform_element_tinywysiwyg_rule_required(Pieform $form, $value, $eleme
}
function pieform_element_tinywysiwyg_get_headdata() {
global $USER;
if ($USER->get_account_preference('wysiwyg') || defined('PUBLIC')) {
if (is_html_editor_enabled()) {
return array('tinytinymce');
}
return array();
......@@ -69,8 +68,7 @@ function pieform_element_tinywysiwyg_get_value(Pieform $form, $element) {
* @param array $element The element
*/
function pieform_element_tinywysiwyg_views_js(Pieform $form, $element) {
global $USER;
if ($USER->get_account_preference('wysiwyg') || defined('PUBLIC')) {
if (is_html_editor_enabled()) {
$formname = json_encode($form->get_name());
$editor = json_encode($form->get_name() . '_' . $element['name']);
return "\ntinyMCE.idCounter=0;"
......
......@@ -38,9 +38,9 @@ $_PIEFORM_WYSIWYGS = array();
* @return string The HTML for the element
*/
function pieform_element_wysiwyg(Pieform $form, $element) {
global $USER, $_PIEFORM_WYSIWYGS;
global $_PIEFORM_WYSIWYGS;
$_PIEFORM_WYSIWYGS[] = $form->get_name() . '_' . $element['name'];
if ($USER->get_account_preference('wysiwyg')) {
if (is_html_editor_enabled()) {
if (!$form->get_property('elementclasses')) {
$element['class'] = isset($element['class']) && $element['class'] !== '' ? $element['class'] . ' wysiwyg' : 'wysiwyg';
}
......@@ -69,7 +69,7 @@ function pieform_element_wysiwyg(Pieform $form, $element) {
}
$element['style'] = (isset($element['style'])) ? $style . $element['style'] : $style;
if ($USER->get_account_preference('wysiwyg')) {
if (is_html_editor_enabled()) {
$value = Pieform::hsc($form->get_value($element));
}
else {
......@@ -94,8 +94,8 @@ function pieform_element_wysiwyg_rule_required(Pieform $form, $value, $element,
}
function pieform_element_wysiwyg_get_headdata() {
global $USER, $_PIEFORM_WYSIWYGS;
if ($USER->get_account_preference('wysiwyg') || defined('PUBLIC')) {
global $_PIEFORM_WYSIWYGS;
if (is_html_editor_enabled()) {
$result = '<script type="text/javascript">'
. "\nvar editor_to_focus;"
. "\nPieformManager.connect('onsubmit', null, tinyMCE.triggerSave);"
......@@ -117,14 +117,13 @@ function pieform_element_wysiwyg_get_headdata() {
}
function pieform_element_wysiwyg_get_value(Pieform $form, $element) {
global $USER;
$global = ($form->get_property('method') == 'get') ? $_GET : $_POST;
if (isset($element['value'])) {
return $element['value'];
}
else if (isset($global[$element['name']])) {
$value = $global[$element['name']];
if (!get_account_preference($USER->get('id'), 'wysiwyg')) {
if (!is_html_editor_enabled()) {
$value = format_whitespace($value);
}
return $value;
......@@ -146,8 +145,7 @@ function pieform_element_wysiwyg_get_value(Pieform $form, $element) {
* @param array $element The element
*/
function pieform_element_wysiwyg_views_js(Pieform $form, $element) {
global $USER;
if ($USER->get_account_preference('wysiwyg') || defined('PUBLIC')) {
if (is_html_editor_enabled()) {
$formname = json_encode($form->get_name());
$editor = json_encode($form->get_name() . '_' . $element['name']);
return "\ntinyMCE.idCounter=0;"
......
......@@ -2638,4 +2638,16 @@ function mahara_log($logname, $string) {
error_log('[' . date("Y-m-d h:i:s") . "] $string\n", 3, get_config('dataroot') . 'log/' . $logname . '.log');
}
/**
* Check whether HTML editor can be used.
*
* @return bool
*/
function is_html_editor_enabled () {
global $USER;
return (!get_config('wysiwyg') && ($USER->get_account_preference('wysiwyg') || defined('PUBLIC'))) ||
get_config('wysiwyg') == 'enable';
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment