Permalink
Browse files

MDL-25394 Improved support for mobile and device themes

  • Loading branch information...
1 parent 16b5541 commit 37959dd471ba94988dfdbd9834d395a5ce893125 @anthonyforth anthonyforth committed with Sam Hemelryk May 31, 2011
Showing with 534 additions and 70 deletions.
  1. +2 −0 admin/settings/appearance.php
  2. +10 −0 lang/en/admin.php
  3. +3 −3 lang/en/moodle.php
  4. +186 −0 lib/adminlib.php
  5. +6 −0 lib/db/upgrade.php
  6. +175 −0 lib/moodlelib.php
  7. +42 −1 lib/outputrenderers.php
  8. +20 −35 lib/pagelib.php
  9. +62 −30 theme/index.php
  10. +27 −0 theme/switch.php
  11. +1 −1 version.php
@@ -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'));
View
@@ -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.';
@@ -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.';
@@ -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';
@@ -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';
View
@@ -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?';
@@ -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';
@@ -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}';
@@ -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';
View
@@ -7307,7 +7307,193 @@ 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
+ */
+ 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;
+ }
}
View
@@ -6112,6 +6112,12 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011052300.02);
}
+ //set enable theme detection to the new themes setting.
+ if ($oldversion < 2011052500.00) {
+ set_config('enabledevicedetection', 1);
+
+ upgrade_main_savepoint(true, 2011052500.00);
+ }
return true;
}
Oops, something went wrong.

0 comments on commit 37959dd

Please sign in to comment.