Skip to content

Commit

Permalink
Merged changes for MDL-25394
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jun 8, 2011
2 parents 9bf5d89 + e5824bb commit 7bff544
Show file tree
Hide file tree
Showing 12 changed files with 583 additions and 121 deletions.
2 changes: 2 additions & 0 deletions admin/settings/appearance.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
$temp->add(new admin_setting_configcheckbox('allowuserblockhiding', get_string('allowuserblockhiding', 'admin'), get_string('configallowuserblockhiding', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('allowblockstodock', get_string('allowblockstodock', 'admin'), get_string('configallowblockstodock', 'admin'), 1));
$temp->add(new admin_setting_configtextarea('custommenuitems', get_string('custommenuitems', 'admin'), get_string('configcustommenuitems', 'admin'), '', PARAM_TEXT, '50', '10'));
$temp->add(new admin_setting_configcheckbox('enabledevicedetection', get_string('enabledevicedetection', 'admin'), get_string('configenabledevicedetection', 'admin'), 1));
$temp->add(new admin_setting_devicedetectregex('devicedetectregex', get_string('devicedetectregex', 'admin'), get_string('devicedetectregex_desc', 'admin'), ''));
$ADMIN->add('themes', $temp);
$ADMIN->add('themes', new admin_externalpage('themeselector', get_string('themeselector','admin'), $CFG->wwwroot . '/theme/index.php'));

Expand Down
10 changes: 10 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
$string['configdeleteincompleteusers'] = 'After this period, old not fully setup accounts are deleted.';
$string['configdeleteunconfirmed'] = 'If you are using email authentication, this is the period within which a response will be accepted from users. After this period, old unconfirmed accounts are deleted.';
$string['configdenyemailaddresses'] = 'To deny email addresses from particular domains list them here in the same way. All other domains will be accepted. To deny subdomains add the domain with a preceding \'.\'. eg <strong>hotmail.com yahoo.co.uk .live.com</strong>';
$string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.';
$string['configdigestmailtime'] = 'People who choose to have emails sent to them in digest form will be emailed the digest daily. This setting controls which time of day the daily mail will be sent (the next cron that runs after this hour will send it).';
$string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.';
$string['configdisplayloginfailures'] = 'This will display information to selected users about previous failed logins.';
Expand Down Expand Up @@ -450,6 +451,12 @@
$string['density'] = 'Density';
$string['denyemailaddresses'] = 'Denied email domains';
$string['development'] = 'Development';
$string['devicedetectregex'] = 'Device detection regular expressions';
$string['devicedetectregex_desc'] = '<p>By default, Moodle can detect devices of the type default (desktop PCs, laptops, etc), mobile (phones and small hand held devices), tablet (iPads, Android tablets) and legacy (Internet Explorer 6 users). The theme selector can be used to apply separate themes to all of these. This setting allows regular expressions that allow the detection of extra device types (these take precedence over the default types).</p>
<p>For example, you could enter the regular expression \'/(MIDP-1.0|Maemo|Windows CE)/\' to detect some commonly used feasture phones add the return value \'featurephone\'. This adds \'featurephone\' on the theme selector that would allow you to add a theme that would be used on these devices. Other phones would still use the theme selected for the mobile device type.</p>';
$string['devicedetectregexexpression'] = 'Regular expression';
$string['devicedetectregexvalue'] = 'Return value';
$string['devicetype'] = 'Device type';
$string['digestmailtime'] = 'Hour to send digest emails';
$string['disableuserimages'] = 'Disable user profile images';
$string['displayerrorswarning'] = 'Enabling the PHP setting <em>display_errors</em> is not recommended on production sites because some error messages may reveal sensitive information about your server.';
Expand Down Expand Up @@ -491,6 +498,7 @@
$string['enablecourseajax'] = 'Enable AJAX course editing';
$string['enablecourseajax_desc'] = 'Allow AJAX when editing main course pages. Note that the course format and the theme must support AJAX editing and the user has to enable AJAX in their profiles, too.';
$string['enablecourserequests'] = 'Enable course requests';
$string['enabledevicedetection'] = 'Enable device detection';
$string['enableglobalsearch'] = 'Enable global search';
$string['enablegroupmembersonly'] = 'Enable group members only';
$string['enablehtmlpurifier'] = 'Enable HTML Purifier';
Expand Down Expand Up @@ -993,7 +1001,9 @@
$string['tabselectedtofronttext'] = 'Bring selected tab row to front';
$string['themedesignermode'] = 'Theme designer mode';
$string['themelist'] = 'Theme list';
$string['themenoselected'] = 'No theme selected';
$string['themeresetcaches'] = 'Clear theme caches';
$string['themeselect'] = 'Select theme';
$string['themeselector'] = 'Theme selector';
$string['themesettings'] = 'Theme settings';
$string['therewereerrors'] = 'There were errors in your data';
Expand Down
1 change: 1 addition & 0 deletions lang/en/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
$string['invalidcoursenameshort'] = 'Invalid short course name';
$string['invaliddata'] = 'Data submitted is invalid';
$string['invaliddatarootpermissions'] = 'Invalid permissions detected in $CFG->dataroot directory, administrator has to fix permissions.';
$string['invaliddevicetype'] = 'Invalid device type';
$string['invalidelementid'] = 'Incorrect element id!';
$string['invalidentry'] = 'This is not valid entry!';
$string['invalidevent'] = 'Invalid event';
Expand Down
6 changes: 3 additions & 3 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,6 @@
$string['layouttable'] = 'Layout table';
$string['leavetokeep'] = 'Leave blank to keep current password';
$string['legacythemeinuse'] = 'This site is being displayed to you in compatibility mode because your browser is too old.';
$string['legacythemesaved'] = 'New legacy theme saved';
$string['license'] = 'Licence';
$string['licenses'] = 'Licences';
$string['liketologin'] = 'Would you like to log in now with a full user account?';
Expand Down Expand Up @@ -1603,6 +1602,8 @@
$string['summary_help'] = 'The idea of a summary is a short text to prepare students for the activities within the topic or week. The text is shown on the course page under the section name.';
$string['summaryof'] = 'Summary of {$a}';
$string['supplyinfo'] = 'More details';
$string['switchdevicedefault'] = 'Switch to the standard theme';
$string['switchdevicerecommended'] = 'Switch to the recommended theme for your device';
$string['switchrolereturn'] = 'Return to my normal role';
$string['switchroleto'] = 'Switch role to...';
$string['tag'] = 'Tag';
Expand Down Expand Up @@ -1692,8 +1693,6 @@
$string['url'] = 'URL';
$string['used'] = 'Used';
$string['usedinnplaces'] = 'Used in {$a} places';
$string['useformaintheme'] = 'Use for modern browsers';
$string['useforlegacytheme'] = 'Use for old browsers';
$string['usemessageform'] = 'or use the form below to send a message to the selected students';
$string['user'] = 'User';
$string['userconfirmed'] = 'Confirmed {$a}';
Expand Down Expand Up @@ -1723,6 +1722,7 @@
$string['useruploadtype'] = 'User upload type: {$a}';
$string['userviewingsettings'] = 'Profile settings for {$a}';
$string['userzones'] = 'User zones';
$string['usetheme'] = 'Use theme';
$string['usingexistingcourse'] = 'Using existing course';
$string['valuealreadyused'] = 'This value has already been used.';
$string['version'] = 'Version';
Expand Down
192 changes: 191 additions & 1 deletion lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7335,9 +7335,199 @@ public function output_html($data, $query = '') {
$content .= html_writer::end_tag('div');
return format_admin_setting($this, $this->visiblename, $content, $this->description, false, '', $this->get_defaultsetting(), $query);
}

}

/**
* Administration interface for user specified regular expressions for device detection.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_devicedetectregex extends admin_setting {

/**
* Calls parent::__construct with specific args
*
* @param string $name
* @param string $visiblename
* @param string $description
* @param mixed $defaultsetting
*/
public function __construct($name, $visiblename, $description, $defaultsetting = '') {
global $CFG;
parent::__construct($name, $visiblename, $description, $defaultsetting);
}

/**
* Return the current setting(s)
*
* @return array Current settings array
*/
public function get_setting() {
global $CFG;

$config = $this->config_read($this->name);
if (is_null($config)) {
return null;
}

return $this->prepare_form_data($config);
}

/**
* Save selected settings
*
* @param array $data Array of settings to save
* @return bool
*/
public function write_setting($data) {
if (empty($data)) {
$data = array();
}

if ($this->config_write($this->name, $this->process_form_data($data))) {
return ''; // success
} else {
return get_string('errorsetting', 'admin') . $this->visiblename . html_writer::empty_tag('br');
}
}

/**
* Return XHTML field(s) for regexes
*
* @param array $data Array of options to set in HTML
* @return string XHTML string for the fields and wrapping div(s)
*/
public function output_html($data, $query='') {
global $OUTPUT;

$out = html_writer::start_tag('table', array('border' => 1, 'class' => 'generaltable'));
$out .= html_writer::start_tag('thead');
$out .= html_writer::start_tag('tr');
$out .= html_writer::tag('th', get_string('devicedetectregexexpression', 'admin'));
$out .= html_writer::tag('th', get_string('devicedetectregexvalue', 'admin'));
$out .= html_writer::end_tag('tr');
$out .= html_writer::end_tag('thead');
$out .= html_writer::start_tag('tbody');

if (empty($data)) {
$looplimit = 1;
} else {
$looplimit = (count($data)/2)+1;
}

for ($i=0; $i<$looplimit; $i++) {
$out .= html_writer::start_tag('tr');

$expressionname = 'expression'.$i;

if (!empty($data[$expressionname])){
$expression = $data[$expressionname];
} else {
$expression = '';
}

$out .= html_writer::tag('td',
html_writer::empty_tag('input',
array(
'type' => 'text',
'class' => 'form-text',
'name' => $this->get_full_name().'[expression'.$i.']',
'value' => $expression,
)
), array('class' => 'c'.$i)
);

$valuename = 'value'.$i;

if (!empty($data[$valuename])){
$value = $data[$valuename];
} else {
$value= '';
}

$out .= html_writer::tag('td',
html_writer::empty_tag('input',
array(
'type' => 'text',
'class' => 'form-text',
'name' => $this->get_full_name().'[value'.$i.']',
'value' => $value,
)
), array('class' => 'c'.$i)
);

$out .= html_writer::end_tag('tr');
}

$out .= html_writer::end_tag('tbody');
$out .= html_writer::end_tag('table');

return format_admin_setting($this, $this->visiblename, $out, $this->description, false, '', null, $query);
}

/**
* Converts the string of regexes
*
* @see self::process_form_data()
* @param $regexes string of regexes
* @return array of form fields and their values
*/
protected function prepare_form_data($regexes) {

$regexes = json_decode($regexes);

$form = array();

$i = 0;

foreach ($regexes as $value => $regex) {
$expressionname = 'expression'.$i;
$valuename = 'value'.$i;

$form[$expressionname] = $regex;
$form[$valuename] = $value;
$i++;
}

return $form;
}

/**
* Converts the data from admin settings form into a string of regexes
*
* @see self::prepare_form_data()
* @param array $data array of admin form fields and values
* @return false|string of regexes
*/
protected function process_form_data(array $form) {

$count = count($form); // number of form field values

if ($count % 2) {
// we must get five fields per expression
return false;
}

$regexes = array();
for ($i = 0; $i < $count / 2; $i++) {
$expressionname = "expression".$i;
$valuename = "value".$i;

$expression = trim($form['expression'.$i]);
$value = trim($form['value'.$i]);

if (empty($expression)){
continue;
}

$regexes[$value] = $expression;
}

$regexes = json_encode($regexes);

return $regexes;
}
}

/**
* Multiselect for current modules
Expand Down
2 changes: 1 addition & 1 deletion lib/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6521,4 +6521,4 @@ function xmldb_main_upgrade($oldversion) {
// 1/ drop block_pinned_old table here and in install.xml
// 2/ drop block_instance_old table here and in install.xml

//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow"
//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow"
Loading

0 comments on commit 7bff544

Please sign in to comment.