Merge branch 'MDL-31245-master-1' of git://git.luns.net.uk/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 24 Jan 2012 17:45:29 +0000 (18:45 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 24 Jan 2012 17:45:29 +0000 (18:45 +0100)
184 files changed:
admin/blocks.php
admin/cli/install.php
admin/cli/mysql_engine.php
admin/enrol.php
admin/index.php
admin/modules.php
admin/qbehaviours.php
admin/qtypes.php
admin/renderer.php
admin/roles/lib.php
admin/settings/subsystems.php
admin/tool/innodb/index.php
admin/tool/timezoneimport/index.php
admin/tool/unittest/ex_reporter.php
admin/user.php
backup/restorelib.php
backup/util/helper/restore_decode_processor.class.php
backup/util/helper/restore_decode_rule.class.php
backup/util/loggers/file_logger.class.php
blocks/admin_bookmarks/block_admin_bookmarks.php
blocks/comments/block_comments.php
blocks/glossary_random/block_glossary_random.php
blocks/html/edit_form.php
blocks/login/block_login.php
blocks/mentees/block_mentees.php
blocks/navigation/block_navigation.php
blocks/navigation/renderer.php
blocks/private_files/block_private_files.php
blocks/settings/block_settings.php
blocks/tags/block_tags.php
calendar/lib.php
config-dist.php
course/edit_form.php
course/format/weeks/format.php
course/index.php
course/lib.php
enrol/externallib.php
enrol/imsenterprise/lib.php
grade/grading/lib.php
grade/grading/pick.php
grade/report/grader/styles.css
group/autogroup.php
group/externallib.php
install/lang/az/moodle.php
install/lang/he/install.php
install/lang/tt/langconfig.php [new file with mode: 0644]
lang/en/admin.php
lang/en/moodle.php
lang/en/question.php
lib/accesslib.php
lib/adminlib.php
lib/ajax/ajaxlib.php
lib/ajax/section_classes.js
lib/blocklib.php
lib/csslib.php [new file with mode: 0644]
lib/datalib.php
lib/db/install.xml
lib/db/upgrade.php
lib/filelib.php
lib/filterlib.php
lib/form/password.php
lib/form/passwordunmask.php
lib/formslib.php
lib/moodlelib.php
lib/navigationlib.php
lib/outputcomponents.php
lib/outputrequirementslib.php
lib/portfoliolib.php
lib/simpletest/fixtures/gradetest.php
lib/simpletest/testcompletionlib.php
lib/simpletest/testcsslib.php [new file with mode: 0644]
lib/simpletest/testfilterconfig.php
lib/simpletest/testtextlib.php
lib/simpletest/testweblib.php
lib/textlib.class.php
lib/timezone.txt
lib/upgradelib.php
lib/weblib.php
login/index.php
message/lib.php
mod/chat/lib.php
mod/feedback/lib.php
mod/forum/lib.php
mod/forum/post.php
mod/glossary/lib.php
mod/lesson/format.php
mod/lesson/lib.php
mod/lesson/pagetypes/essay.php
mod/quiz/attempt.php
mod/quiz/attemptlib.php
mod/quiz/db/install.xml
mod/quiz/db/upgrade.php
mod/quiz/edit.php
mod/quiz/editlib.php
mod/quiz/lang/en/quiz.php
mod/quiz/lib.php
mod/quiz/locallib.php
mod/quiz/renderer.php
mod/quiz/report/overview/overview_table.php
mod/quiz/report/reportlib.php
mod/quiz/report/statistics/version.php
mod/quiz/simpletest/testquizobj.php
mod/quiz/startattempt.php
mod/quiz/styles.css
mod/quiz/version.php
mod/scorm/datamodels/scorm_13.js.php
mod/survey/lib.php
mod/workshop/form/accumulative/backup/moodle1/lib.php
mod/workshop/form/comments/backup/moodle1/lib.php
mod/workshop/form/numerrors/backup/moodle1/lib.php
mod/workshop/form/rubric/backup/moodle1/lib.php
question/behaviour/adaptive/simpletest/testwalkthrough.php
question/behaviour/deferredcbm/renderer.php
question/behaviour/immediatecbm/simpletest/testwalkthrough.php
question/behaviour/interactive/simpletest/testwalkthrough.php
question/editlib.php
question/engine/questionattempt.php
question/engine/questionusage.php
question/engine/renderer.php
question/engine/simpletest/helpers.php
question/format/blackboard_six/format.php
question/preview.php
question/previewlib.php
question/type/calculated/lang/en/qtype_calculated.php
question/type/calculated/questiontype.php
question/type/calculated/simpletest/helper.php
question/type/calculated/simpletest/testquestion.php
question/type/calculated/simpletest/testquestiontype.php [new file with mode: 0644]
question/type/match/backup/moodle1/lib.php
question/type/numerical/question.php
question/type/numerical/questiontype.php
question/type/numerical/simpletest/helper.php
question/type/numerical/simpletest/testquestion.php
question/type/numerical/simpletest/testquestiontype.php
question/type/questionbase.php
question/type/randomsamatch/questiontype.php
question/type/shortanswer/questiontype.php
question/type/shortanswer/simpletest/helper.php [new file with mode: 0644]
question/type/shortanswer/simpletest/testquestion.php
question/type/shortanswer/simpletest/testquestiontype.php
question/type/truefalse/simpletest/testquestiontype.php
report/participation/index.php
report/questioninstances/index.php
repository/lib.php
theme/afterburner/config.php
theme/afterburner/style/afterburner_dock.css
theme/afterburner/style/afterburner_settings.css [new file with mode: 0644]
theme/afterburner/style/afterburner_styles.css
theme/arialist/config.php
theme/arialist/style/pagelayout.css
theme/base/style/dock.css
theme/canvas/style/core.css
theme/formal_white/config.php
theme/formal_white/lang/en/theme_formal_white.php
theme/formal_white/layout/embedded.php
theme/formal_white/layout/frontpage.php
theme/formal_white/layout/general.php
theme/formal_white/layout/report.php [new file with mode: 0755]
theme/formal_white/lib.php
theme/formal_white/settings.php
theme/formal_white/style/formal_white.css
theme/formal_white/style/frame.css
theme/formal_white/style/quiz.css
theme/formal_white/version.php
theme/magazine/config.php
theme/magazine/style/colors.css
theme/magazine/style/core.css
theme/sky_high/config.php
theme/sky_high/layout/frontpage.php
theme/sky_high/layout/general.php
theme/sky_high/style/admin.css [new file with mode: 0644]
theme/sky_high/style/core.css
theme/sky_high/style/report.css
theme/sky_high/style/settings.css [new file with mode: 0644]
theme/splash/style/sl.css
theme/styles.php
theme/styles_debug.php
theme/yui_combo.php
user/externallib.php
user/index.php
user/selector/lib.php
version.php
webservice/rest/locallib.php
webservice/simpletest/testwebservice.php

index ca9633d..b1c53df 100644 (file)
         } else {
             uninstall_plugin('block', $block->name);
 
+            $a = new stdClass();
             $a->block = $strblockname;
             $a->directory = $CFG->dirroot.'/blocks/'.$block->name;
             notice(get_string('blockdeletefiles', '', $a), 'blocks.php');
index facda35..b812aaf 100644 (file)
@@ -337,12 +337,7 @@ $CFG->httpswwwroot  = $CFG->wwwroot;
 
 
 //We need dataroot before lang download
-$dataroot = clean_param($options['dataroot'], PARAM_PATH);
-if ($dataroot !== $options['dataroot']) {
-    $a = (object)array('option' => 'dataroot', 'value' => $options['dataroot']);
-    cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
-}
-$CFG->dataroot = $dataroot;
+$CFG->dataroot = $options['dataroot'];
 if ($interactive) {
     cli_separator();
     $i=0;
index 53c4b84..c6d7c6e 100644 (file)
@@ -76,7 +76,7 @@ if (!empty($options['engine'])) {
         }
         echo str_pad($table->name, 40). " - ";
 
-        $DB->change_database_structure("ALTER TABLE {$table->name} TYPE = $engine");
+        $DB->change_database_structure("ALTER TABLE {$table->name} ENGINE = $engine");
         echo "DONE\n";
         $converted++;
     }
index 2d53db9..ab14a23 100644 (file)
@@ -31,6 +31,7 @@ $enrol   = required_param('enrol', PARAM_PLUGIN);
 $confirm = optional_param('confirm', 0, PARAM_BOOL);
 
 $PAGE->set_url('/admin/enrol.php');
+$PAGE->set_context(context_system::instance());
 
 require_login();
 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
@@ -112,6 +113,7 @@ switch ($action) {
             uninstall_plugin('enrol', $enrol);
             $syscontext->mark_dirty(); // resets all enrol caches
 
+            $a = new stdClass();
             $a->plugin = $strplugin;
             $a->directory = "$CFG->dirroot/enrol/$enrol";
             echo $OUTPUT->notification(get_string('uninstalldeletefiles', 'enrol', $a), 'notifysuccess');
index b4bcff7..7e8a6fc 100644 (file)
@@ -190,6 +190,15 @@ if ($version > $CFG->version) {  // upgrade
     $PAGE->set_pagelayout('maintenance');
     $PAGE->set_popup_notification_allowed(false);
 
+    if (upgrade_stale_php_files_present()) {
+        $PAGE->set_title($stradministration);
+        $PAGE->set_cacheable(false);
+
+        $output = $PAGE->get_renderer('core', 'admin');
+        echo $output->upgrade_stale_php_files_page();
+        die();
+    }
+
     if (empty($confirmupgrade)) {
         $a->oldversion = "$CFG->release ($CFG->version)";
         $a->newversion = "$release ($version)";
index 45f7a57..2290612 100644 (file)
@@ -92,6 +92,7 @@
             }
 
             uninstall_plugin('mod', $delete);
+            $a = new stdClass();
             $a->module = $strmodulename;
             $a->directory = "$CFG->dirroot/mod/$delete";
             echo $OUTPUT->notification(get_string("moduledeletefiles", "", $a), 'notifysuccess');
index 2ae5f08..ce81b13 100644 (file)
@@ -191,6 +191,7 @@ if (($delete = optional_param('delete', '', PARAM_PLUGIN)) && confirm_sesskey())
     // Remove event handlers and dequeue pending events
     events_uninstall('qbehaviour_' . $delete);
 
+    $a = new stdClass();
     $a->behaviour = $behaviourname;
     $a->directory = get_plugin_directory('qbehaviour', $delete);
     echo $OUTPUT->box(get_string('qbehaviourdeletefiles', 'question', $a), 'generalbox', 'notice');
index 79bcf68..cbe828f 100644 (file)
@@ -171,6 +171,7 @@ if (($delete = optional_param('delete', '', PARAM_PLUGIN)) && confirm_sesskey())
     // Remove event handlers and dequeue pending events
     events_uninstall('qtype_' . $delete);
 
+    $a = new stdClass();
     $a->qtype = $qtypename;
     $a->directory = $qtypes[$delete]->plugin_dir();
     echo $OUTPUT->box(get_string('qtypedeletefiles', 'question', $a), 'generalbox', 'notice');
index d823e0e..cecd725 100644 (file)
@@ -57,6 +57,26 @@ class core_admin_renderer extends plugin_renderer_base {
         return $output;
     }
 
+    /**
+     * Display page explaining proper upgrade process,
+     * there can not be any PHP file leftovers...
+     *
+     * @return string HTML to output.
+     */
+    public function upgrade_stale_php_files_page() {
+        $output = '';
+        $output .= $this->header();
+        $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
+        $output .= $this->box_start('generalbox', 'notice');
+        $output .= get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading'));
+        $output .= html_writer::empty_tag('br');
+        $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
+        $output .= $this->box_end();
+        $output .= $this->footer();
+
+        return $output;
+    }
+
     /**
      * Display the 'environment check' page that is displayed during install.
      * @param int $maturity
@@ -339,8 +359,10 @@ class core_admin_renderer extends plugin_renderer_base {
             return '';
         }
 
-        return $this->warning(get_string('sitemaintenancewarning2', 'admin',
-                new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'))));
+        $url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
+        $url = $url->out(); // get_string() does not support objects in params
+
+        return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
     }
 
     /**
@@ -597,8 +619,7 @@ class core_admin_renderer extends plugin_renderer_base {
 
             if (is_null($otherplugin)) {
                 $ok = false;
-            }
-            if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
+            } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
                 $ok = false;
             }
 
index 68a3c8b..d2dbaba 100644 (file)
@@ -1044,10 +1044,9 @@ class potential_assignees_below_course extends role_assign_user_selector_base {
         $sql   = " FROM {user} u
                   WHERE u.id IN ($enrolsql) $wherecondition
                         AND u.id NOT IN (
-                           SELECT u.id
-                             FROM {role_assignments} r, {user} u
+                           SELECT r.userid
+                             FROM {role_assignments} r
                             WHERE r.contextid = :contextid
-                                  AND u.id = r.userid
                                   AND r.roleid = :roleid)";
         $order = ' ORDER BY lastname ASC, firstname ASC';
 
@@ -1096,10 +1095,9 @@ class potential_assignees_course_and_above extends role_assign_user_selector_bas
         $sql = " FROM {user}
                 WHERE $wherecondition
                       AND id NOT IN (
-                         SELECT u.id
-                           FROM {role_assignments} r, {user} u
+                         SELECT r.userid
+                           FROM {role_assignments} r
                           WHERE r.contextid = :contextid
-                                AND u.id = r.userid
                                 AND r.roleid = :roleid)";
         $order = ' ORDER BY lastname ASC, firstname ASC';
 
index 27e9511..00ffb21 100644 (file)
@@ -43,4 +43,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
     $checkbox->set_affects_modinfo(true);
 
     $optionalsubsystems->add(new admin_setting_configcheckbox('enableplagiarism', new lang_string('enableplagiarism','plagiarism'), new lang_string('configenableplagiarism','plagiarism'), 0));
-}
+
+    $optionalsubsystems->add(new admin_setting_configcheckbox('enablecssoptimiser', new lang_string('enablecssoptimiser','admin'), new lang_string('enablecssoptimiser_desc','admin'), 0));
+}
\ No newline at end of file
index faaea89..bbe4d85 100644 (file)
@@ -50,7 +50,7 @@ if (data_submitted() and $confirm and confirm_sesskey()) {
         $DB->set_debug(true);
         foreach ($tables as $table) {
             $fulltable = $DB->get_prefix().$table;
-            $DB->change_database_structure("ALTER TABLE $fulltable TYPE=INNODB");
+            $DB->change_database_structure("ALTER TABLE $fulltable ENGINE=INNODB");
         }
         $DB->set_debug(false);
     }
index 8319f83..478ca4c 100644 (file)
 /// That's it!
 
     if ($importdone) {
-        $a = null;
+        $a = new stdClass();
         $a->count = count($timezones);
         $a->source  = $importdone;
         echo $OUTPUT->heading(get_string('importtimezonescount', 'tool_timezoneimport', $a), 3);
index 995bebd..5d440f3 100644 (file)
@@ -289,4 +289,9 @@ class ExHtmlReporter extends HtmlReporter {
     function get_string($identifier, $a = NULL) {
         return get_string($identifier, 'tool_unittest', $a);
     }
+
+    function _htmlEntities($message) {
+        // Override subclass message that breaks UTF8.
+        return s($message);
+    }
 }
index 1ccb69f..56e457e 100644 (file)
     $users = get_users_listing($sort, $dir, $page*$perpage, $perpage, '', '', '',
             $extrasql, $params, $context);
     $usercount = get_users(false);
-    $usersearchcount = get_users(false, '', true, null, "", '', '', '', '', '*', $extrasql, $params);
+    $usersearchcount = get_users(false, '', false, null, "", '', '', '', '', '*', $extrasql, $params);
 
     if ($extrasql !== '') {
         echo $OUTPUT->heading("$usersearchcount / $usercount ".get_string('users'));
index 654a87f..6eba776 100644 (file)
                         }
 
                         //Now build the EVENT record structure
+                        $eve = new stdClass();
                         $eve->name = backup_todb($info['EVENT']['#']['NAME']['0']['#']);
                         $eve->description = backup_todb($info['EVENT']['#']['DESCRIPTION']['0']['#']);
                         $eve->format = backup_todb($info['EVENT']['#']['FORMAT']['0']['#']);
index 8716029..66dfbef 100644 (file)
@@ -63,7 +63,7 @@ class restore_decode_processor {
 
     public function add_rule($rule) {
         if (!$rule instanceof restore_decode_rule) {
-            throw new restore_decode_processor_exception('incorrect_restore_decode_rule', get_class($content));
+            throw new restore_decode_processor_exception('incorrect_restore_decode_rule', get_class($rule));
         }
         $rule->set_restoreid($this->restoreid);
         $rule->set_wwwroots($this->sourcewwwroot, $this->targetwwwroot);
index 52e6f63..ded4126 100644 (file)
@@ -151,7 +151,7 @@ class restore_decode_rule {
         $countma = count($mappings);
         // Check mappings number matches placeholders
         if ($countph != $countma) {
-            $msg = new stdclass();
+            $a = new stdClass();
             $a->placeholders = $countph;
             $a->mappings     = $countma;
             throw new restore_decode_rule_exception('decode_rule_mappings_incorrect_count', $a);
index b183767..e4ab4b1 100644 (file)
@@ -61,7 +61,7 @@ class file_logger extends base_logger {
     public function __wakeup() {
         if ($this->level > backup::LOG_NONE) { // Only create the file if we are going to log something
             if (! $this->fhandle = fopen($this->fullpath, 'a')) {
-                throw new base_logger_exception('error_opening_file', $fullpath);
+                throw new base_logger_exception('error_opening_file', $this->fullpath);
             }
         }
     }
index 856b9b8..331f353 100644 (file)
@@ -79,6 +79,7 @@ class block_admin_bookmarks extends block_base {
         if ($this->contentgenerated === true) {
             return $this->content;
         }
+        $this->content = new stdClass();
 
         if (get_user_preferences('admin_bookmarks')) {
             require_once($CFG->libdir.'/adminlib.php');
index a00cd09..527d020 100644 (file)
@@ -48,21 +48,23 @@ class block_comments extends block_base {
 
     function get_content() {
         global $CFG, $PAGE;
+        if ($this->content !== NULL) {
+            return $this->content;
+        }
         if (!$CFG->usecomments) {
+            $this->content = new stdClass();
             $this->content->text = '';
             if ($this->page->user_is_editing()) {
                 $this->content->text = get_string('disabledcomments');
             }
             return $this->content;
         }
-        if ($this->content !== NULL) {
-            return $this->content;
-        }
-        if (empty($this->instance)) {
-            return null;
-        }
+        $this->content = new stdClass();
         $this->content->footer = '';
         $this->content->text = '';
+        if (empty($this->instance)) {
+            return $this->content;
+        }
         list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
 
         $args = new stdClass;
index 72fc75b..649cd77 100644 (file)
@@ -119,6 +119,7 @@ class block_glossary_random extends block_base {
         global $USER, $CFG, $DB;
 
         if (empty($this->config->glossary)) {
+            $this->content = new stdClass();
             $this->content->text   = get_string('notyetconfigured','block_glossary_random');
             $this->content->footer = '';
             return $this->content;
@@ -153,7 +154,7 @@ class block_glossary_random extends block_base {
             return $this->content;
         }
 
-        $this->content = new stdClass;
+        $this->content = new stdClass();
         $this->content->text = $this->config->cache;
 
         // place link to glossary in the footer if the glossary is visible
index 30c005d..aa7b466 100644 (file)
@@ -72,6 +72,9 @@ class block_html_edit_form extends block_edit_form {
         unset($this->block->config->text);
         parent::set_data($defaults);
         // restore $text
+        if (!isset($this->block->config)) {
+            $this->block->config = new stdClass();
+        }
         $this->block->config->text = $text;
         if (isset($title)) {
             // Reset the preserved title
index 516a5fa..2d92009 100644 (file)
@@ -43,6 +43,7 @@ class block_login extends block_base {
 
         $username = get_moodle_cookie();
 
+        $this->content = new stdClass();
         $this->content->footer = '';
         $this->content->text = '';
 
index 45d9463..aa340af 100644 (file)
@@ -25,6 +25,8 @@ class block_mentees extends block_base {
             return $this->content;
         }
 
+        $this->content = new stdClass();
+
         // get all the mentees, i.e. users you have a direct assignment to
         if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, u.firstname, u.lastname
                                                     FROM {role_assignments} ra, {context} c, {user} u
index 79b8086..00f06cf 100644 (file)
@@ -195,6 +195,7 @@ class block_navigation extends block_base {
         
         // Grab the items to display
         $renderer = $this->page->get_renderer('block_navigation');
+        $this->content = new stdClass();
         $this->content->text = $renderer->navigation_tree($navigation, $expansionlimit, $options);
 
         // Set content generated to true so that we know it has been done
index e28ac28..b62d4db 100644 (file)
@@ -30,12 +30,14 @@ class block_navigation_renderer extends plugin_renderer_base {
             $isexpandable = (empty($expansionlimit) || ($item->type > navigation_node::TYPE_ACTIVITY || $item->type < $expansionlimit) || ($item->contains_active_node() && $item->children->count() > 0));
             $isbranch = $isexpandable && ($item->children->count() > 0 || ($item->has_children() && (isloggedin() || $item->type <= navigation_node::TYPE_CATEGORY)));
 
-            $hasicon = ((!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY )&& $item->icon instanceof renderable);
+            $hasicon = ((!$isbranch || $item->type == navigation_node::TYPE_ACTIVITY || $item->type == navigation_node::TYPE_RESOURCE) && $item->icon instanceof renderable);
 
             if ($hasicon) {
                 $icon = $this->output->render($item->icon);
-                $content = $icon.$content; // use CSS for spacing of icons
+            } else {
+                $icon = '';
             }
+            $content = $icon.$content; // use CSS for spacing of icons
             if ($item->helpbutton !== null) {
                 $content = trim($item->helpbutton).html_writer::tag('span', $content, array('class'=>'clearhelpbutton'));
             }
@@ -57,6 +59,7 @@ class block_navigation_renderer extends plugin_renderer_base {
             } else if ($item->action instanceof action_link) {
                 //TODO: to be replaced with something else
                 $link = $item->action;
+                $link->text = $icon.$link->text;
                 $link->attributes = array_merge($link->attributes, $attributes);
                 $content = $this->output->render($link);
                 $linkrendered = true;
index a552dd9..32e1282 100644 (file)
@@ -51,6 +51,7 @@ class block_private_files extends block_base {
             return null;
         }
 
+        $this->content = new stdClass();
         $this->content->text = '';
         $this->content->footer = '';
         if (isloggedin() && !isguestuser()) {   // Show the block
index 89706f6..3e2aea8 100644 (file)
@@ -129,6 +129,7 @@ class block_settings extends block_base {
         }
 
         $renderer = $this->page->get_renderer('block_settings');
+        $this->content = new stdClass();
         $this->content->text = $renderer->settings_tree($this->page->settingsnav);
 
         // only do search if you have moodle/site:config
index 0a35df1..b7a35fd 100644 (file)
@@ -47,6 +47,10 @@ class block_tags extends block_base {
             return $this->content;
         }
 
+        if (!isset($this->config)) {
+            $this->config = new stdClass();
+        }
+
         if (empty($this->config->numberoftags)) {
             $this->config->numberoftags = 80;
         }
index c60e6b6..046c0a9 100644 (file)
@@ -1540,6 +1540,7 @@ function calendar_set_event_type_display($type, $display = null, $user = null) {
 
 function calendar_get_allowed_types(&$allowed, $course = null) {
     global $USER, $CFG, $DB;
+    $allowed = new stdClass();
     $allowed->user = has_capability('moodle/calendar:manageownentries', get_system_context());
     $allowed->groups = false; // This may change just below
     $allowed->courses = false; // This may change just below
@@ -1795,7 +1796,7 @@ class calendar_event {
      * @return stdClass
      */
     protected function calculate_context(stdClass $data) {
-        global $USER;
+        global $USER, $DB;
 
         $context = null;
         if (isset($data->courseid) && $data->courseid > 0) {
index c41b795..dbc732c 100644 (file)
@@ -385,6 +385,32 @@ $CFG->admin = 'admin';
 //
 //     $CFG->extramemorylimit = 1G;
 //
+// The CSS files the Moodle produces can be extremely large and complex, especially
+// if you are using a custom theme that builds upon several other themes.
+// In Moodle 2.3 a CSS optimiser was added as an experimental feature for advanced
+// users. The CSS optimiser organises the CSS in order to reduce the overall number
+// of rules and styles being sent to the client. It does this by collating the
+// CSS before it is cached removing excess styles and rules and stripping out any
+// extraneous content such as comments and empty rules.
+// The following settings are used to enable and control the optimisation.
+//
+// Enable the CSS optimiser. This will only optimise the CSS if themedesignermode
+// is not enabled. This can be set through the UI however it is noted here as well
+// because the other CSS optimiser settings can not be set through the UI.
+//
+//      $CFG->enablecssoptimiser = true;
+//
+// If set the CSS optimiser will add stats about the optimisation to the top of
+// the optimised CSS file. You can then inspect the CSS to see the affect the CSS
+// optimiser is having.
+//
+//      $CFG->cssoptimiserstats = true;
+//
+// If set the CSS that is optimised will still retain a minimalistic formatting
+// so that anyone wanting to can still clearly read it.
+//
+//      $CFG->cssoptimiserpretty = true;
+//
 //=========================================================================
 // 8. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!!
 //=========================================================================
index a5bad50..d87c9d1 100644 (file)
@@ -270,7 +270,15 @@ class course_edit_form extends moodleform {
                 }
 
                 $mods = array(0=>get_string('allownone'));
-                $mods += $DB->get_records_menu('modules', array('visible'=>1), 'name', 'id, name');
+                $allmods = $DB->get_records_menu('modules', array('visible' => 1),
+                        'name', 'id, name');
+                foreach ($allmods as $key => $value) {
+                    // Add module to list unless it cannot be added by users anyway
+                    if (plugin_supports('mod', $value, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER) !==
+                            MOD_ARCHETYPE_SYSTEM) {
+                        $mods[$key] = get_string('pluginname', $value);
+                    }
+                }
                 $mform->addElement('select', 'allowedmods', get_string('to'), $mods, array('multiple'=>'multiple', 'size'=>'10'));
                 $mform->disabledIf('allowedmods', 'restrictmodules', 'eq', 0);
                 // defaults are already in $course
index 74fb964..c5c78fa 100644 (file)
@@ -141,7 +141,7 @@ defined('MOODLE_INTERNAL') || die();
             $thissection = $sections[$section];
 
         } else {
-            unset($thissection);
+            $thissection = new stdClass();
             $thissection->course = $course->id;   // Create a new week structure
             $thissection->section = $section;
             $thissection->name    = null;
index f0a0c10..e873128 100644 (file)
@@ -373,6 +373,7 @@ function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $
         echo '</td>';
         echo '</tr>';
     } else {
+        $category = new stdClass();
         $category->id = '0';
     }
 
index c186422..d34d9ec 100644 (file)
@@ -49,6 +49,11 @@ define('MOD_CLASS_RESOURCE', 1);
 function make_log_url($module, $url) {
     switch ($module) {
         case 'course':
+            if (strpos($url, 'report/') === 0) {
+                // there is only one report type, course reports are deprecated
+                $url = "/$url";
+                break;
+            }
         case 'file':
         case 'login':
         case 'lib':
@@ -145,6 +150,7 @@ function build_mnet_logs_array($hostid, $course, $user=0, $date=0, $order="l.tim
     $groupid = 0;
 
     $joins = array();
+    $where = '';
 
     $qry = "SELECT l.*, u.firstname, u.lastname, u.picture
               FROM {mnet_log} l
@@ -812,7 +818,7 @@ function print_log_ods($course, $user, $date, $order='l.time DESC', $modname,
 
         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
 
-        $myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $context)));
+        $myxls->write_string($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)));
         $myxls->write_date($row, 1, $log->time);
         $myxls->write_string($row, 2, $log->ip);
         $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
@@ -1069,6 +1075,7 @@ function get_array_of_activities($courseid) {
                    if (empty($rawmods[$seq])) {
                        continue;
                    }
+                   $mod[$seq] = new stdClass();
                    $mod[$seq]->id               = $rawmods[$seq]->instance;
                    $mod[$seq]->cm               = $rawmods[$seq]->id;
                    $mod[$seq]->mod              = $rawmods[$seq]->modname;
@@ -1853,6 +1860,8 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
             $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
             if ($archetype == MOD_ARCHETYPE_RESOURCE) {
                 $resources[$urlbase.$modname] = $modnamestr;
+            } else if ($archetype === MOD_ARCHETYPE_SYSTEM) {
+                // System modules cannot be added by user, do not add to dropdown
             } else {
                 // all other archetypes are considered activity
                 $activities[$urlbase.$modname] = $modnamestr;
@@ -2120,6 +2129,7 @@ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentsli
         }
 
     } else {
+        $category = new stdClass();
         $category->id = "0";
     }
 
@@ -2493,7 +2503,7 @@ function print_course($course, $highlightterms = '') {
     echo html_writer::end_tag('div'); // End of info div
 
     echo html_writer::start_tag('div', array('class'=>'summary'));
-    $options = NULL;
+    $options = new stdClass();
     $options->noclean = true;
     $options->para = false;
     $options->overflowdiv = true;
@@ -2640,7 +2650,7 @@ function print_remote_course($course, $width="100%") {
         . format_string($course->cat_name) . ' : '
         . format_string($course->shortname). '</div>';
     echo '</div><div class="summary">';
-    $options = NULL;
+    $options = new stdClass();
     $options->noclean = true;
     $options->para = false;
     $options->overflowdiv = true;
@@ -3099,11 +3109,12 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
         $str->duplicate      = get_string("duplicate");
         $str->hide           = get_string("hide");
         $str->show           = get_string("show");
-        $str->clicktochange  = get_string("clicktochange");
-        $str->forcedmode     = get_string("forcedmode");
-        $str->groupsnone     = get_string("groupsnone");
-        $str->groupsseparate = get_string("groupsseparate");
-        $str->groupsvisible  = get_string("groupsvisible");
+        $str->groupsnone     = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsnone"));
+        $str->groupsseparate = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsseparate"));
+        $str->groupsvisible  = get_string('clicktochangeinbrackets', 'moodle', get_string("groupsvisible"));
+        $str->forcedgroupsnone     = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsnone"));
+        $str->forcedgroupsseparate = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsseparate"));
+        $str->forcedgroupsvisible  = get_string('forcedmodeinbrackets', 'moodle', get_string("groupsvisible"));
     }
 
     $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
@@ -3220,16 +3231,19 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
         if ($mod->groupmode == SEPARATEGROUPS) {
             $groupmode = 0;
             $grouptitle = $str->groupsseparate;
+            $forcedgrouptitle = $str->forcedgroupsseparate;
             $groupclass = 'editing_groupsseparate';
             $groupimage = 't/groups';
         } else if ($mod->groupmode == VISIBLEGROUPS) {
             $groupmode = 1;
             $grouptitle = $str->groupsvisible;
+            $forcedgrouptitle = $str->forcedgroupsvisible;
             $groupclass = 'editing_groupsvisible';
             $groupimage = 't/groupv';
         } else {
             $groupmode = 2;
             $grouptitle = $str->groupsnone;
+            $forcedgrouptitle = $str->forcedgroupsnone;
             $groupclass = 'editing_groupsnone';
             $groupimage = 't/groupn';
         }
@@ -3238,10 +3252,10 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele
                 new moodle_url($baseurl, array('id' => $mod->id, 'groupmode' => $groupmode)),
                 new pix_icon($groupimage, $grouptitle, 'moodle', array('class' => 'iconsmall')),
                 null,
-                array('class' => $groupclass, 'title' => $grouptitle.' ('.$str->clicktochange.')')
+                array('class' => $groupclass, 'title' => $grouptitle)
             );
         } else {
-            $actions[] = new pix_icon($groupimage, $grouptitle, 'moodle', array('title' => $grouptitle.' ('.$str->forcedmode.')', 'class' => 'iconsmall'));
+            $actions[] = new pix_icon($groupimage, $forcedgrouptitle, 'moodle', array('title' => $forcedgrouptitle, 'class' => 'iconsmall'));
         }
     }
 
index 9e186ce..123f438 100644 (file)
@@ -172,26 +172,8 @@ class core_enrol_external extends external_api {
             }
         }
 
-        // to overwrite this parameter, you need role:review capability
-        if ($withcapability) {
-            require_capability('moodle/role:review', $coursecontext);
-        }
-        // need accessallgroups capability if you want to overwrite this option
-        if (!empty($groupid) && groups_is_member($groupid)) {
-            require_capability('moodle/site:accessallgroups', $context);
-        }
-        // to overwrite this option, you need course:enrolereview permission
-        if ($onlyactive) {
-            require_capability('moodle/course:enrolreview', $coursecontext);
-        }
-
-        list($coursectxselect, $coursectxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
-        $coursesql = "SELECT c.* $coursectxselect
-                        FROM {course} c $coursectxjoin
-                       WHERE c.id = $courseid";
-        $course = $DB->get_record_sql($coursesql);
-        context_instance_preload($course);
-        $coursecontext = get_context_instance(CONTEXT_COURSE, $params['courseid']);
+        $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
+        $coursecontext = get_context_instance(CONTEXT_COURSE, $courseid);
         if ($courseid == SITEID) {
             $context = get_system_context();
         } else {
@@ -206,9 +188,26 @@ class core_enrol_external extends external_api {
             throw new moodle_exception(get_string('errorcoursecontextnotvalid' , 'webservice', $exceptionparam));
         }
 
+        if ($courseid == SITEID) {
+            require_capability('moodle/site:viewparticipants', $context);
+        } else {
+            require_capability('moodle/course:viewparticipants', $context);
+        }
+        // to overwrite this parameter, you need role:review capability
+        if ($withcapability) {
+            require_capability('moodle/role:review', $coursecontext);
+        }
+        // need accessallgroups capability if you want to overwrite this option
+        if (!empty($groupid) && groups_is_member($groupid)) {
+            require_capability('moodle/site:accessallgroups', $coursecontext);
+        }
+        // to overwrite this option, you need course:enrolereview permission
+        if ($onlyactive) {
+            require_capability('moodle/course:enrolreview', $coursecontext);
+        }
+
         list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
         list($ctxselect, $ctxjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
-        $records = $DB->get_records_sql($enrolledsql, $enrolledparams);
         $sqlparams['courseid'] = $courseid;
         $sql = "SELECT u.* $ctxselect
                   FROM {user} u $ctxjoin
@@ -217,9 +216,6 @@ class core_enrol_external extends external_api {
         $enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams);
         $users = array();
         foreach ($enrolledusers as $user) {
-            if (!empty($user->deleted)) {
-                continue;
-            }
             context_instance_preload($user);
             if ($userdetails = user_get_user_details($user, $course, $userfields)) {
                 $users[] = $userdetails;
index ace7435..284608a 100644 (file)
@@ -590,6 +590,8 @@ function process_membership_tag($tagcontents){
     // In order to reduce the number of db queries required, group name/id associations are cached in this array:
     $groupids = array();
 
+    $ship = new stdClass();
+
     if(preg_match('{<sourcedid>.*?<id>(.+?)</id>.*?</sourcedid>}is', $tagcontents, $matches)){
         $ship->coursecode = ($truncatecoursecodes > 0)
                                  ? substr(trim($matches[1]), 0, intval($truncatecoursecodes))
@@ -601,8 +603,8 @@ function process_membership_tag($tagcontents){
         $courseobj->id = $ship->courseid;
 
         foreach($membermatches as $mmatch){
-            unset($member);
-            unset($memberstoreobj);
+            $member = new stdClass();
+            $memberstoreobj = new stdClass();
             if(preg_match('{<sourcedid>.*?<id>(.+?)</id>.*?</sourcedid>}is', $mmatch[1], $matches)){
                 $member->idnumber = trim($matches[1]);
             }
@@ -622,6 +624,7 @@ function process_membership_tag($tagcontents){
               //echo "<p>process_membership_tag: unenrolling member due to recstatus of 3</p>";
             }
 
+            $timeframe = new stdClass();
             $timeframe->begin = 0;
             $timeframe->end = 0;
             if(preg_match('{<role\b.*?<timeframe>(.+?)</timeframe>.*?</role>}is', $mmatch[1], $matches)){
@@ -680,6 +683,7 @@ function process_membership_tag($tagcontents){
                                 $groupids[$member->groupname] = $groupid; // Store ID in cache
                             } else {
                                 // Attempt to create the group
+                                $group = new stdClass();
                                 $group->name = $member->groupname;
                                 $group->courseid = $ship->courseid;
                                 $group->timecreated = time();
@@ -752,6 +756,7 @@ function log_line($string){
 * Process the INNER contents of a <timeframe> tag, to return beginning/ending dates.
 */
 function decode_timeframe($string){ // Pass me the INNER CONTENTS of a <timeframe> tag - beginning and/or ending is returned, in unix time, zero indicating not specified
+    $ret = new stdClass();
     $ret->begin = $ret->end = 0;
     // Explanatory note: The matching will ONLY match if the attribute restrict="1"
     // because otherwise the time markers should be ignored (participation should be
index a2c2d26..e27a4ec 100644 (file)
@@ -461,7 +461,7 @@ class grading_manager {
      * @return grading_controller
      */
     public function get_controller($method) {
-        global $CFG;
+        global $CFG, $DB;
 
         $this->ensure_isset(array('context', 'component', 'area'));
 
index fd4d6ef..779e95c 100644 (file)
@@ -144,8 +144,7 @@ if ($searchdata = $searchform->get_data()) {
 }
 
 // construct the SQL to find all matching templates
-$sql = "SELECT DISTINCT gd.id, gd.areaid, gd.name, gd.description, gd.descriptionformat, gd.timecreated,
-                        gd.usercreated, gd.timemodified, gd.usermodified
+$sql = "SELECT DISTINCT gd.id, gd.areaid, gd.name, gd.usercreated
           FROM {grading_definitions} gd
           JOIN {grading_areas} ga ON (gd.areaid = ga.id)
           JOIN {context} cx ON (ga.contextid = cx.id)";
index 20c78ed..4730ba5 100644 (file)
@@ -342,10 +342,6 @@ text-align:center;
 clear:both;
 }
 
-.path-grade-report-grader form {
-text-align:center;
-}
-
 .path-grade-report-grader input.center {
 margin:10px auto 0;
 }
index a575c33..42fc1dc 100644 (file)
@@ -172,11 +172,10 @@ if ($editform->is_cancelled()) {
 
         // prepare grouping
         if (!empty($data->grouping)) {
-            $groupingname = trim($data->groupingname);
             if ($data->grouping < 0) {
                 $grouping = new stdClass();
                 $grouping->courseid = $COURSE->id;
-                $grouping->name     = $groupingname;
+                $grouping->name     = trim($data->groupingname);
                 $grouping->id = groups_create_grouping($grouping);
                 $createdgrouping = $grouping->id;
             } else {
index 160dcbf..7ff57d5 100644 (file)
@@ -267,7 +267,6 @@ class core_group_external extends external_api {
 
         $transaction = $DB->start_delegated_transaction();
 
-// TODO: this is problematic because the DB rollback does not handle deleting of group images!
         foreach ($params['groupids'] as $groupid) {
             // validate params
             $groupid = validate_param($groupid, PARAM_INTEGER);
index c413982..f503f4d 100644 (file)
@@ -31,3 +31,6 @@
 defined('MOODLE_INTERNAL') || die();
 
 $string['language'] = 'Dil';
+$string['next'] = 'Növbəti';
+$string['previous'] = 'Əvvələ';
+$string['reload'] = 'Yenilə';
index e279c29..1d18b13 100644 (file)
@@ -34,6 +34,9 @@ $string['admindirname'] = 'ספריית מנהל המערכת';
 $string['availablelangs'] = 'חבילות שפה זמינות';
 $string['chooselanguagehead'] = 'בחר שפה';
 $string['chooselanguagesub'] = 'אנא בחר שפה עבור ההתקנה בלבד. תוכל לבחור בשפה שונה לאתר ולמשתמש באחד מהמסכים הבאים.';
+$string['clialreadyconfigured'] = 'קובץ config.php כבר קיים, אנא השתמש ב
+admin/cli/install_database.php
+אם ברצונך להתקין את אתר זה.';
 $string['clialreadyinstalled'] = 'קובץ ה-config.php קיים כבר, אנא השתמש ב- admin/cli/upgrade.php
 אם ברצונך לשדרג את האתר שלך.';
 $string['cliinstallheader'] = 'תוכנית התקנת Moodle {$a} בשורת הפקודה';
@@ -41,6 +44,7 @@ $string['databasehost'] = 'מסד הנתונים המארח (host)';
 $string['databasename'] = 'שם מסד הנתונים';
 $string['databasetypehead'] = 'בחר התקן מסד הנתונים';
 $string['dataroot'] = 'ספריית הנתונים';
+$string['datarootpermission'] = 'הרשאות תיקיות bתונים (data)';
 $string['dbprefix'] = 'Tables prefix';
 $string['dirroot'] = 'ספריית ה-Moodle';
 $string['environmenthead'] = 'בודק את הסביבה שלך...';
diff --git a/install/lang/tt/langconfig.php b/install/lang/tt/langconfig.php
new file mode 100644 (file)
index 0000000..813287a
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Automatically generated strings for Moodle 2.3dev installer
+ *
+ * Do not edit this file manually! It contains just a subset of strings
+ * needed during the very first steps of installation. This file was
+ * generated automatically by export-installer.php (which is part of AMOS
+ * {@link http://docs.moodle.org/dev/Languages/AMOS}) using the
+ * list of strings defined in /install/stringnames.txt.
+ *
+ * @package   installer
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$string['thislanguage'] = 'татар теле';
index ba6d8f7..153dcb7 100644 (file)
@@ -330,7 +330,7 @@ For example:  standard,orangewhite.';
 $string['configtimezone'] = 'You can set the default timezone here.  This is the only the DEFAULT timezone for displaying dates - each user can override this by setting their own in their profile. "Server time" here will make Moodle default to the server\'s operating system setting, but "Server time" in the user profile will make the user default to this timezone setting.  Cronjobs that depend on a time of day to run will use this timezone.';
 $string['configunzip'] = 'Indicate the location of your unzip program (Unix only, optional).  If specified, this will be used to unpack zip archives on the server.  If you leave this blank, then Moodle will use internal routines.';
 $string['configuseblogassociations'] = 'Should users be able to organize their blog by associating entries with courses and course modules?';
-$string['configuseexternalyui'] = 'Instead of using local files, use online files available on Yahoo&#145;s servers. WARNING: This requires an internet connection, or no AJAX will work on your site.';
+$string['configuseexternalyui'] = 'Instead of using local files, use online files available on Yahoo&#145;s servers. WARNING: This requires an internet connection, or no AJAX will work on your site. This setting is not compatible with sites using https.';
 $string['configusesitenameforsitepages'] = 'If enabled the site\'s shortname will be used for the site pages node in the navigation rather than the string \'Site pages\'';
 $string['configusetags'] = 'Should tags functionality across the site be enabled?';
 $string['configvariables'] = 'Variables';
@@ -466,6 +466,8 @@ $string['enablecomments'] = 'Enable comments';
 $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['enablecssoptimiser'] = 'Enable CSS optimiser';
+$string['enablecssoptimiser_desc'] = 'When enabled CSS will be run through an optimisation process before being cached. The optimiser processes the CSS removing duplicate rules and styles, as well as white space removeable and reformatting. Please note turning this on at the same time as theme designer mode is aweful for performance but will help theme designers create optimised CSS.';
 $string['enabledevicedetection'] = 'Enable device detection';
 $string['enablegravatar'] = 'Enable Gravatar';
 $string['enablegravatar_help'] = 'When enabled Moodle will attempt to fetch a user profile picture from Gravatar if the user has not uploaded an image.';
@@ -971,6 +973,8 @@ $string['upgradelogs'] = 'For full functionality, your old logs need to be upgra
 $string['upgradelogsinfo'] = 'Some changes have recently been made in the way logs are stored.  To be able to view all of your old logs on a per-activity basis, your old logs need to be upgraded.  Depending on your site this can take a long time (eg several hours) and can be quite taxing on the database for large sites.  Once you start this process you should let it finish (by keeping the browser window open).  Don\'t worry - your site will work fine for other people while the logs are being upgraded.<br /><br />Do you want to upgrade your logs now?';
 $string['upgradesettings'] = 'New settings';
 $string['upgradesettingsintro'] = 'The settings shown below were added during your last Moodle upgrade. Make any changes necessary to the defaults and then click the &quot;Save changes&quot; button at the bottom of this page.';
+$string['upgradestalefiles'] = 'Invalid installation files detected, upgrade cannot continue';
+$string['upgradestalefilesinfo'] = 'Some old PHP scripts have been detected which may indicate that you installed this version over an older one. Please fix the installation directory by removing all old scripts (except config.php) before installing the new version and then try the upgrade again. You can find more information in upgrade documentation at <a href="{$a}">{$a}</a>';
 $string['upgradesure'] = 'Your Moodle files have been changed, and you are about to automatically upgrade your server to this version: <br /><br />
 <strong>{$a}</strong> <br /><br />
 Once you do this you can not go back again. <br /><br />
index 7f8fb12..28e82c6 100644 (file)
@@ -236,7 +236,7 @@ $string['clear'] = 'Clear';
 $string['clickhelpiconformoreinfo'] = '... continues ... Click on the help icon to read the full article';
 $string['clickhere'] = 'Click here ...';
 $string['clicktohideshow'] = 'Click to expand or collapse';
-$string['clicktochange'] = 'Click to change';
+$string['clicktochangeinbrackets'] = '{$a} (Click to change)';
 $string['closewindow'] = 'Close this window';
 $string['collapseall'] = 'Collapse all';
 $string['commentincontext'] = 'Find this comment in context';
@@ -672,7 +672,7 @@ $string['folderopened'] = 'Opened folder';
 $string['followingoptional'] = 'The following items are optional';
 $string['followingrequired'] = 'The following items are required';
 $string['force'] = 'Force';
-$string['forcedmode'] = 'forced mode';
+$string['forcedmodeinbrackets'] = '{$a} (forced mode)';
 $string['forcelanguage'] = 'Force language';
 $string['forceno'] = 'Do not force';
 $string['forcepasswordchange'] = 'Force password change';
index 1d82d23..48a68b7 100644 (file)
@@ -99,6 +99,7 @@ $string['deletequestioncheck'] = 'Are you absolutely sure you want to delete \'{
 $string['deletequestionscheck'] = 'Are you absolutely sure you want to delete the following questions?<br /><br />{$a}';
 $string['deletingbehaviour'] = 'Deleting question behaviour \'{$a}\'';
 $string['deletingqtype'] = 'Deleting question type \'{$a}\'';
+$string['didnotmatchanyanswer'] = '[Did not match any answer]';
 $string['disabled'] = 'Disabled';
 $string['disterror'] = 'The distribution {$a} caused problems';
 $string['donothing'] = 'Don\'t copy or move files or change links.';
index 18edded..88ee394 100644 (file)
@@ -1002,6 +1002,7 @@ function get_empty_accessdata() {
     $accessdata['rdef_lcc']   = 0;       // rdef_count during the last compression
     $accessdata['loaded']     = array(); // loaded course contexts
     $accessdata['time']       = time();
+    $accessdata['rsw']        = array();
 
     return $accessdata;
 }
@@ -1149,7 +1150,7 @@ function reload_all_capabilities() {
 
     // copy switchroles
     $sw = array();
-    if (isset($USER->access['rsw'])) {
+    if (!empty($USER->access['rsw'])) {
         $sw = $USER->access['rsw'];
     }
 
@@ -3859,22 +3860,21 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
     // Note the result can be used directly as a context (we are going to), the course
     // fields are just appended.
 
+    $contextpreload = context_helper::get_preload_record_columns_sql('x');
+
     $courses = array();
-    $rs = $DB->get_recordset_sql("SELECT x.*, c.id AS courseid $fieldlist
+    $rs = $DB->get_recordset_sql("SELECT c.id $fieldlist, $contextpreload
                                     FROM {course} c
-                                   INNER JOIN {context} x
-                                         ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
+                                    JOIN {context} x ON (c.id=x.instanceid AND x.contextlevel=".CONTEXT_COURSE.")
                                 $orderby");
     // Check capability for each course in turn
-    foreach ($rs as $coursecontext) {
-        if (has_capability($capability, $coursecontext, $userid, $doanything)) {
+    foreach ($rs as $course) {
+        context_helper::preload_from_record($course);
+        $context = context_course::instance($course->id);
+        if (has_capability($capability, $context, $userid, $doanything)) {
             // We've got the capability. Make the record look like a course record
             // and store it
-            $coursecontext->id = $coursecontext->courseid;
-            unset($coursecontext->courseid);
-            unset($coursecontext->contextlevel);
-            unset($coursecontext->instanceid);
-            $courses[] = $coursecontext;
+            $courses[] = $course;
         }
     }
     $rs->close();
@@ -3941,16 +3941,14 @@ function role_switch($roleid, context $context) {
     //
     // Note: it is not possible to switch to roles that do not have course:view
 
-    // Add the switch RA
-    if (!isset($USER->access['rsw'])) {
-        $USER->access['rsw'] = array();
+    if (!isset($USER->access)) {
+        load_all_capabilities();
     }
 
+
+    // Add the switch RA
     if ($roleid == 0) {
         unset($USER->access['rsw'][$context->path]);
-        if (empty($USER->access['rsw'])) {
-            unset($USER->access['rsw']);
-        }
         return true;
     }
 
index 4eaaecb..72d6df3 100644 (file)
@@ -3051,7 +3051,7 @@ class admin_setting_bloglevel extends admin_setting_configselect {
      */
     public function write_setting($data) {
         global $DB, $CFG;
-        if ($data['bloglevel'] == 0) {
+        if ($data == 0) {
             $blogblocks = $DB->get_records_select('block', "name LIKE 'blog_%' AND visible = 1");
             foreach ($blogblocks as $block) {
                 $DB->set_field('block', 'visible', 0, array('id' => $block->id));
@@ -7896,6 +7896,8 @@ class admin_setting_devicedetectregex extends admin_setting {
  * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class admin_setting_configmultiselect_modules extends admin_setting_configmultiselect {
+    private $excludesystem;
+
     /**
      * Calls parent::__construct - note array $choices is not required
      *
@@ -7903,9 +7905,12 @@ class admin_setting_configmultiselect_modules extends admin_setting_configmultis
      * @param string $visiblename localised setting name
      * @param string $description setting description
      * @param array $defaultsetting a plain array of default module ids
+     * @param bool $excludesystem If true, excludes modules with 'system' archetype
      */
-    public function __construct($name, $visiblename, $description, $defaultsetting = array()) {
+    public function __construct($name, $visiblename, $description, $defaultsetting = array(),
+            $excludesystem = true) {
         parent::__construct($name, $visiblename, $description, $defaultsetting, null);
+        $this->excludesystem = $excludesystem;
     }
 
     /**
@@ -7922,8 +7927,14 @@ class admin_setting_configmultiselect_modules extends admin_setting_configmultis
         global $CFG, $DB;
         $records = $DB->get_records('modules', array('visible'=>1), 'name');
         foreach ($records as $record) {
+            // Exclude modules if the code doesn't exist
             if (file_exists("$CFG->dirroot/mod/$record->name/lib.php")) {
-                $this->choices[$record->id] = $record->name;
+                // Also exclude system modules (if specified)
+                if (!($this->excludesystem &&
+                        plugin_supports('mod', $record->name, FEATURE_MOD_ARCHETYPE) ===
+                        MOD_ARCHETYPE_SYSTEM)) {
+                    $this->choices[$record->id] = $record->name;
+                }
             }
         }
         return true;
index 37d0f29..f7d378f 100644 (file)
@@ -149,10 +149,9 @@ class jsportal {
         $output .= "    main.portal.strings['moveleft']='".addslashes_js(get_string('moveleft'))."';\n";
         $output .= "    main.portal.strings['moveright']='".addslashes_js(get_string('moveright'))."';\n";
         $output .= "    main.portal.strings['update']='".addslashes_js(get_string('update'))."';\n";
-        $output .= "    main.portal.strings['groupsnone']='".addslashes_js(get_string('groupsnone'))."';\n";
-        $output .= "    main.portal.strings['groupsseparate']='".addslashes_js(get_string('groupsseparate'))."';\n";
-        $output .= "    main.portal.strings['groupsvisible']='".addslashes_js(get_string('groupsvisible'))."';\n";
-        $output .= "    main.portal.strings['clicktochange']='".addslashes_js(get_string('clicktochange'))."';\n";
+        $output .= "    main.portal.strings['groupsnone']='".addslashes_js(get_string('clicktochangeinbrackets', 'moodle', get_string('groupsnone')))."';\n";
+        $output .= "    main.portal.strings['groupsseparate']='".addslashes_js(get_string('clicktochangeinbrackets', 'moodle', get_string('groupsseparate')))."';\n";
+        $output .= "    main.portal.strings['groupsvisible']='".addslashes_js(get_string('clicktochangeinbrackets', 'moodle', get_string('groupsvisible')))."';\n";
         $output .= "    main.portal.strings['deletecheck']='".addslashes_js(get_string('deletecheckfull','','_var_'))."';\n";
         $output .= "    main.portal.strings['resource']='".addslashes_js(get_string('resource'))."';\n";
         $output .= "    main.portal.strings['activity']='".addslashes_js(get_string('activity'))."';\n";
index cac7cec..c787e3f 100644 (file)
@@ -620,9 +620,9 @@ resource_class.prototype.init_buttons = function() {
     }
 
     // Language strings.
-    var strgroupsnone = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
-    var strgroupsseparate = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
-    var strgroupsvisible = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
+    var strgroupsnone = main.portal.strings['groupsnone'];
+    var strgroupsseparate = main.portal.strings['groupsseparate'];
+    var strgroupsvisible = main.portal.strings['groupsvisible'];
 
     this.commandContainer = commandContainer;
     var buttons = commandContainer.getElementsByTagName('a');
@@ -864,13 +864,13 @@ resource_class.prototype.toggle_groupmode = function() {
 
     switch (this.groupmode) {
         case 0:
-            newtitle = main.portal.strings['groupsnone']+' ('+main.portal.strings['clicktochange']+')';
+            newtitle = main.portal.strings['groupsnone'];
             break;
         case 1:
-            newtitle = main.portal.strings['groupsseparate']+' ('+main.portal.strings['clicktochange']+')';
+            newtitle = main.portal.strings['groupsseparate'];
             break;
         case 2:
-            newtitle = main.portal.strings['groupsvisible']+' ('+main.portal.strings['clicktochange']+')';
+            newtitle = main.portal.strings['groupsvisible'];
             break;
     }
 
index 508b94c..90d990c 100644 (file)
@@ -1675,7 +1675,7 @@ function generate_page_type_patterns($pagetype, $parentcontext = null, $currentc
 
     // Ensure that the * pattern is always available if editing block 'at distance', so
     // we always can 'bring back' it to the original context. MDL-30340
-    if ($currentcontext->id != $parentcontext->id && !isset($patterns['*'])) {
+    if ((!isset($currentcontext) or !isset($parentcontext) or $currentcontext->id != $parentcontext->id) && !isset($patterns['*'])) {
         // TODO: We could change the string here, showing its 'bring back' meaning
         $patterns['*'] = get_string('page-x', 'pagetype');
     }
diff --git a/lib/csslib.php b/lib/csslib.php
new file mode 100644 (file)
index 0000000..379ce16
--- /dev/null
@@ -0,0 +1,3584 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains CSS related class, and function for the CSS optimiser
+ *
+ * Please see the {@see css_optimiser} class for greater detail.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * Stores CSS in a file at the given path.
+ *
+ * This function either succeeds or throws an exception.
+ *
+ * @param theme_config $theme The theme that the CSS belongs to.
+ * @param string $csspath The path to store the CSS at.
+ * @param array $cssfiles The CSS files to store.
+ */
+function css_store_css(theme_config $theme, $csspath, array $cssfiles) {
+    global $CFG;
+
+    if (!empty($CFG->enablecssoptimiser)) {
+        // This is an experimental feature introduced in Moodle 2.3
+        // The CSS optimiser organises the CSS in order to reduce the overall number
+        // of rules and styles being sent to the client. It does this by collating
+        // the CSS before it is cached removing excess styles and rules and stripping
+        // out any extraneous content such as comments and empty rules.
+        $optimiser = new css_optimiser;
+        $css = '';
+        foreach ($cssfiles as $file) {
+            $css .= file_get_contents($file)."\n";
+        }
+        $css = $theme->post_process($css);
+        $css = $optimiser->process($css);
+
+        // If cssoptimisestats is set then stats from the optimisation are collected
+        // and output at the beginning of the CSS
+        if (!empty($CFG->cssoptimiserstats)) {
+            $css = $optimiser->output_stats_css().$css;
+        }
+    } else {
+        // This is the default behaviour.
+        // The cssoptimise setting was introduced in Moodle 2.3 and will hopefully
+        // in the future be changed from an experimental setting to the default.
+        // The css_minify_css will method will use the Minify library remove
+        // comments, additional whitespace and other minor measures to reduce the
+        // the overall CSS being sent.
+        // However it has the distinct disadvantage of having to minify the CSS
+        // before running the post process functions. Potentially things may break
+        // here if theme designers try to push things with CSS post processing.
+        $css = $theme->post_process(css_minify_css($cssfiles));
+    }
+
+    check_dir_exists(dirname($csspath));
+    $fp = fopen($csspath, 'w');
+    fwrite($fp, $css);
+    fclose($fp);
+}
+
+/**
+ * Sends IE specific CSS
+ *
+ * In writing the CSS parser I have a theory that we could optimise the CSS
+ * then split it based upon the number of selectors to ensure we dont' break IE
+ * and that we include only as many sub-stylesheets as we require.
+ * Of course just a theory but may be fun to code.
+ *
+ * @param string $themename The name of the theme we are sending CSS for.
+ * @param string $rev The revision to ensure we utilise the cache.
+ */
+function css_send_ie_css($themename, $rev) {
+    $lifetime = 60*60*24*30; // 30 days
+
+    $css  = "/** Unfortunately IE6/7 does not support more than 4096 selectors in one CSS file, which means we have to use some ugly hacks :-( **/";
+    $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=plugins);";
+    $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=parents);";
+    $css .= "\n@import url(styles.php?theme=$themename&rev=$rev&type=theme);";
+
+    header('Etag: '.md5($rev));
+    header('Content-Disposition: inline; filename="styles.php"');
+    header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
+    header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
+    header('Pragma: ');
+    header('Cache-Control: max-age='.$lifetime);
+    header('Accept-Ranges: none');
+    header('Content-Type: text/css; charset=utf-8');
+    header('Content-Length: '.strlen($css));
+
+    echo $css;
+    die;
+}
+
+/**
+ * Sends a cached CSS file
+ *
+ * This function sends the cached CSS file. Remember it is generated on the first
+ * request, then optimised/minified, and finally cached for serving.
+ *
+ * @param string $csspath The path to the CSS file we want to serve.
+ * @param string $rev The revision to make sure we utilise any caches.
+ */
+function css_send_cached_css($csspath, $rev) {
+    $lifetime = 60*60*24*30; // 30 days
+
+    header('Content-Disposition: inline; filename="styles.php"');
+    header('Last-Modified: '. gmdate('D, d M Y H:i:s', filemtime($csspath)) .' GMT');
+    header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
+    header('Pragma: ');
+    header('Cache-Control: max-age='.$lifetime);
+    header('Accept-Ranges: none');
+    header('Content-Type: text/css; charset=utf-8');
+    if (!min_enable_zlib_compression()) {
+        header('Content-Length: '.filesize($csspath));
+    }
+
+    readfile($csspath);
+    die;
+}
+
+/**
+ * Sends CSS directly without caching it.
+ *
+ * This function takes a raw CSS string, optimises it if required, and then
+ * serves it.
+ * Turning both themedesignermode and CSS optimiser on at the same time is aweful
+ * for performance because of the optimiser running here. However it was done so
+ * that theme designers could utilise the optimised output during development to
+ * help them optimise their CSS... not that they should write lazy CSS.
+ *
+ * @param string CSS
+ */
+function css_send_uncached_css($css) {
+    global $CFG;
+
+    header('Content-Disposition: inline; filename="styles_debug.php"');
+    header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
+    header('Expires: '. gmdate('D, d M Y H:i:s', time() + THEME_DESIGNER_CACHE_LIFETIME) .' GMT');
+    header('Pragma: ');
+    header('Accept-Ranges: none');
+    header('Content-Type: text/css; charset=utf-8');
+
+    if (is_array($css)) {
+        $css = implode("\n\n", $css);
+    }
+
+    if (!empty($CFG->enablecssoptimiser)) {
+        $css = str_replace("\n", "\r\n", $css);
+
+        $optimiser = new css_optimiser;
+        $css = $optimiser->process($css);
+        if (!empty($CFG->cssoptimiserstats)) {
+            $css = $optimiser->output_stats_css().$css;
+        }
+    }
+
+    echo $css;
+
+    die;
+}
+
+/**
+ * Sends a 404 message about CSS not being found.
+ */
+function css_send_css_not_found() {
+    header('HTTP/1.0 404 not found');
+    die('CSS was not found, sorry.');
+}
+
+/**
+ * Uses the minify library to compress CSS.
+ *
+ * This is used if $CFG->enablecssoptimiser has been turned off. This was
+ * the original CSS optimisation library.
+ * It removes whitespace and shrinks things but does no apparent optimisation.
+ * Note the minify library is still being used for JavaScript.
+ *
+ * @param array $files An array of files to minify
+ * @return string The minified CSS
+ */
+function css_minify_css($files) {
+    global $CFG;
+
+    set_include_path($CFG->libdir . '/minify/lib' . PATH_SEPARATOR . get_include_path());
+    require_once('Minify.php');
+
+    if (0 === stripos(PHP_OS, 'win')) {
+        Minify::setDocRoot(); // IIS may need help
+    }
+    // disable all caching, we do it in moodle
+    Minify::setCache(null, false);
+
+    $options = array(
+        'bubbleCssImports' => false,
+        // Don't gzip content we just want text for storage
+        'encodeOutput' => false,
+        // Maximum age to cache, not used but required
+        'maxAge' => (60*60*24*20),
+        // The files to minify
+        'files' => $files,
+        // Turn orr URI rewriting
+        'rewriteCssUris' => false,
+        // This returns the CSS rather than echoing it for display
+        'quiet' => true
+    );
+    $result = Minify::serve('Files', $options);
+    return $result['content'];
+}
+
+/**
+ * Determines if the given value is a valid CSS colour.
+ *
+ * A CSS colour can be one of the following:
+ *    - Hex colour:  #AA66BB
+ *    - RGB colour:  rgb(0-255, 0-255, 0-255)
+ *    - RGBA colour: rgba(0-255, 0-255, 0-255, 0-1)
+ *    - HSL colour:  hsl(0-360, 0-100%, 0-100%)
+ *    - HSLA colour: hsla(0-360, 0-100%, 0-100%, 0-1)
+ *
+ * Or a recognised browser colour mapping {@see css_optimiser::$htmlcolours}
+ *
+ * @param string $value The colour value to check
+ * @return bool
+ */
+function css_is_colour($value) {
+    $value = trim($value);
+    if (in_array(strtolower($value), array('inherit'))) {
+        return true;
+    } else if (preg_match('/^#([a-fA-F0-9]{1,3}|[a-fA-F0-9]{6})$/', $value)) {
+        return true;
+    } else if (in_array(strtolower($value), array_keys(css_optimiser::$htmlcolours))) {
+        return true;
+    } else if (preg_match('#^rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$#i', $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
+        // It is an RGB colour
+        return true;
+    } else if (preg_match('#^rgba\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1}(\.\d+)?)\s*\)$#i', $value, $m) && $m[1] < 256 && $m[2] < 256 && $m[3] < 256) {
+        // It is an RGBA colour
+        return true;
+    } else if (preg_match('#^hsl\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\%\s*,\s*(\d{1,3})\%\s*\)$#i', $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
+        // It is an HSL colour
+        return true;
+    } else if (preg_match('#^hsla\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\%\s*,\s*(\d{1,3})\%\s*,\s*(\d{1}(\.\d+)?)\s*\)$#i', $value, $m) && $m[1] <= 360 && $m[2] <= 100 && $m[3] <= 100) {
+        // It is an HSLA colour
+        return true;
+    }
+    // Doesn't look like a colour.
+    return false;
+}
+
+/**
+ * Returns true is the passed value looks like a CSS width.
+ * In order to pass this test the value must be purely numerical or end with a
+ * valid CSS unit term.
+ *
+ * @param string|int $value
+ * @return boolean
+ */
+function css_is_width($value) {
+    $value = trim($value);
+    if (in_array(strtolower($value), array('auto', 'inherit'))) {
+        return true;
+    }
+    if (preg_match('#^(\-\s*)?(\d*\.)?(\d+)\s*(em|px|pt|%|in|cm|mm|ex|pc)?$#i', $value)) {
+        return true;
+    }
+    return false;
+}
+
+/**
+ * A simple sorting function to sort two array values on the number of items they contain
+ *
+ * @param array $a
+ * @param array $b
+ * @return int
+ */
+function css_sort_by_count(array $a, array $b) {
+    $a = count($a);
+    $b = count($b);
+    if ($a == $b) {
+        return 0;
+    }
+    return ($a > $b) ? -1 : 1;
+}
+
+/**
+ * A basic CSS optimiser that strips out unwanted things and then processing the
+ * CSS organising styles and moving duplicates and useless CSS.
+ *
+ * This CSS optimiser works by reading through a CSS string one character at a
+ * time and building an object structure of the CSS.
+ * As part of that processing styles are expanded out as much as they can be to
+ * ensure we collect all mappings, at the end of the processing those styles are
+ * then combined into an optimised form to keep them as short as possible.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_optimiser {
+
+    /**
+     * Used when the processor is about to start processing.
+     * Processing states. Used internally.
+     */
+    const PROCESSING_START = 0;
+
+    /**
+     * Used when the processor is currently processing a selector.
+     * Processing states. Used internally.
+     */
+    const PROCESSING_SELECTORS = 0;
+
+    /**
+     * Used when the processor is currently processing a style.
+     * Processing states. Used internally.
+     */
+    const PROCESSING_STYLES = 1;
+
+    /**
+     * Used when the processor is currently processing a comment.
+     * Processing states. Used internally.
+     */
+    const PROCESSING_COMMENT = 2;
+
+    /**
+     * Used when the processor is currently processing an @ rule.
+     * Processing states. Used internally.
+     */
+    const PROCESSING_ATRULE = 3;
+
+    /**
+     * The raw string length before optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $rawstrlen = 0;
+
+    /**
+     * The number of comments that were removed during optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $commentsincss = 0;
+
+    /**
+     * The number of rules in the CSS before optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $rawrules = 0;
+
+    /**
+     * The number of selectors using in CSS rules before optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $rawselectors = 0;
+
+    /**
+     * The string length after optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $optimisedstrlen = 0;
+
+    /**
+     * The number of rules after optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $optimisedrules = 0;
+
+    /**
+     * The number of selectors used in rules after optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $optimisedselectors = 0;
+
+    /**
+     * The start time of the optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $timestart = 0;
+
+    /**
+     * The end time of the optimisation.
+     * Stats variables set during and after processing
+     * @var int
+     */
+    protected $timecomplete = 0;
+
+    /**
+     * Will be set to any errors that may have occured during processing.
+     * This is updated only at the end of processing NOT during.
+     *
+     * @var array
+     */
+    protected $errors = array();
+
+    /**
+     * Processes incoming CSS optimising it and then returning it.
+     *
+     * @param string $css The raw CSS to optimise
+     * @return string The optimised CSS
+     */
+    public function process($css) {
+        global $CFG;
+
+        $this->reset_stats();
+        $this->timestart = microtime(true);
+        $this->rawstrlen = strlen($css);
+
+        // First up we need to remove all line breaks - this allows us to instantly
+        // reduce our processing requirements and as we will process everything
+        // into a new structure there's really nothing lost.
+        $css = preg_replace('#\r?\n#', ' ', $css);
+
+        // Next remove the comments... no need to them in an optimised world and
+        // knowing they're all gone allows us to REALLY make our processing simpler
+        $css = preg_replace('#/\*(.*?)\*/#m', '', $css, -1, $this->commentsincss);
+
+        $medias = array(
+            'all' => new css_media()
+        );
+        $imports = array();
+        $charset = false;
+
+        $currentprocess = self::PROCESSING_START;
+        $currentrule = css_rule::init();
+        $currentselector = css_selector::init();
+        $inquotes = false;      // ' or "
+        $inbraces = false;      // {
+        $inbrackets = false;    // [
+        $inparenthesis = false; // (
+        $currentmedia = $medias['all'];
+        $currentatrule = null;
+        $suspectatrule = false;
+
+        $buffer = '';
+        $char = null;
+
+        // Next we are going to iterate over every single character in $css.
+        // This is why we removed line breaks and comments!
+        for ($i = 0; $i < $this->rawstrlen; $i++) {
+            $lastchar = $char;
+            $char = substr($css, $i, 1);
+            if ($char == '@' && $buffer == '') {
+                $suspectatrule = true;
+            }
+            switch ($currentprocess) {
+                // Start processing an at rule e.g. @media, @page
+                case self::PROCESSING_ATRULE:
+                    switch ($char) {
+                        case ';':
+                            if (!$inbraces) {
+                                $buffer .= $char;
+                                if ($currentatrule == 'import') {
+                                    $imports[] = $buffer;
+                                    $currentprocess = self::PROCESSING_SELECTORS;
+                                } else if ($currentatrule == 'charset') {
+                                    $charset = $buffer;
+                                    $currentprocess = self::PROCESSING_SELECTORS;
+                                }
+                            }
+                            $buffer = '';
+                            $currentatrule = false;
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case '{':
+                            if ($currentatrule == 'media' && preg_match('#\s*@media\s*([a-zA-Z0-9]+(\s*,\s*[a-zA-Z0-9]+)*)#', $buffer, $matches)) {
+                                $mediatypes = str_replace(' ', '', $matches[1]);
+                                if (!array_key_exists($mediatypes, $medias)) {
+                                    $medias[$mediatypes] = new css_media($mediatypes);
+                                }
+                                $currentmedia = $medias[$mediatypes];
+                                $currentprocess = self::PROCESSING_SELECTORS;
+                                $buffer = '';
+                            }
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                    }
+                    break;
+                // Start processing selectors
+                case self::PROCESSING_START:
+                case self::PROCESSING_SELECTORS:
+                    switch ($char) {
+                        case '[':
+                            $inbrackets ++;
+                            $buffer .= $char;
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case ']':
+                            $inbrackets --;
+                            $buffer .= $char;
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case ' ':
+                            if ($inbrackets) {
+                                // continue 1: The switch processing chars
+                                // continue 2: The switch processing the state
+                                // continue 3: The for loop
+                                continue 3;
+                            }
+                            if (!empty($buffer)) {
+                                if ($suspectatrule && preg_match('#@(media|import|charset)\s*#', $buffer, $matches)) {
+                                    $currentatrule = $matches[1];
+                                    $currentprocess = self::PROCESSING_ATRULE;
+                                    $buffer .= $char;
+                                } else {
+                                    $currentselector->add($buffer);
+                                    $buffer = '';
+                                }
+                            }
+                            $suspectatrule = false;
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case '{':
+                            if ($inbrackets) {
+                                // continue 1: The switch processing chars
+                                // continue 2: The switch processing the state
+                                // continue 3: The for loop
+                                continue 3;
+                            }
+
+                            $currentselector->add($buffer);
+                            $currentrule->add_selector($currentselector);
+                            $currentselector = css_selector::init();
+                            $currentprocess = self::PROCESSING_STYLES;
+
+                            $buffer = '';
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case '}':
+                            if ($inbrackets) {
+                                // continue 1: The switch processing chars
+                                // continue 2: The switch processing the state
+                                // continue 3: The for loop
+                                continue 3;
+                            }
+                            if ($currentatrule == 'media') {
+                                $currentmedia = $medias['all'];
+                                $currentatrule = false;
+                                $buffer = '';
+                            }
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case ',':
+                            if ($inbrackets) {
+                                // continue 1: The switch processing chars
+                                // continue 2: The switch processing the state
+                                // continue 3: The for loop
+                                continue 3;
+                            }
+                            $currentselector->add($buffer);
+                            $currentrule->add_selector($currentselector);
+                            $currentselector = css_selector::init();
+                            $buffer = '';
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                    }
+                    break;
+                // Start processing styles
+                case self::PROCESSING_STYLES:
+                    if ($char == '"' || $char == "'") {
+                        if ($inquotes === false) {
+                            $inquotes = $char;
+                        }
+                        if ($inquotes === $char && $lastchar !== '\\') {
+                            $inquotes = false;
+                        }
+                    }
+                    if ($inquotes) {
+                        $buffer .= $char;
+                        continue 2;
+                    }
+                    switch ($char) {
+                        case ';':
+                            $currentrule->add_style($buffer);
+                            $buffer = '';
+                            $inquotes = false;
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                        case '}':
+                            $currentrule->add_style($buffer);
+                            $this->rawselectors += $currentrule->get_selector_count();
+
+                            $currentmedia->add_rule($currentrule);
+
+                            $currentrule = css_rule::init();
+                            $currentprocess = self::PROCESSING_SELECTORS;
+                            $this->rawrules++;
+                            $buffer = '';
+                            $inquotes = false;
+                            // continue 1: The switch processing chars
+                            // continue 2: The switch processing the state
+                            // continue 3: The for loop
+                            continue 3;
+                    }
+                    break;
+            }
+            $buffer .= $char;
+        }
+
+        $css = '';
+        if (!empty($charset)) {
+            $imports[] = $charset;
+        }
+        if (!empty($imports)) {
+            $css .= implode("\n", $imports);
+            $css .= "\n\n";
+        }
+        foreach ($medias as $media) {
+            $media->organise_rules_by_selectors();
+            $this->optimisedrules += $media->count_rules();
+            $this->optimisedselectors +=  $media->count_selectors();
+            if ($media->has_errors()) {
+                $this->errors[] = $media->get_errors();
+            }
+            $css .= $media->out();
+        }
+        $this->optimisedstrlen = strlen($css);
+
+        $this->timecomplete = microtime(true);
+        return trim($css);
+    }
+
+    /**
+     * Returns an array of stats from the last processing run
+     * @return string
+     */
+    public function get_stats() {
+        $stats = array(
+            'timestart'             => $this->timestart,
+            'timecomplete'          => $this->timecomplete,
+            'timetaken'             => round($this->timecomplete - $this->timestart, 4),
+            'commentsincss'         => $this->commentsincss,
+            'rawstrlen'             => $this->rawstrlen,
+            'rawselectors'          => $this->rawselectors,
+            'rawrules'              => $this->rawrules,
+            'optimisedstrlen'       => $this->optimisedstrlen,
+            'optimisedrules'        => $this->optimisedrules,
+            'optimisedselectors'     => $this->optimisedselectors,
+            'improvementstrlen'     => round(100 - ($this->optimisedstrlen / $this->rawstrlen) * 100, 1).'%',
+            'improvementrules'      => round(100 - ($this->optimisedrules / $this->rawrules) * 100, 1).'%',
+            'improvementselectors'  => round(100 - ($this->optimisedselectors / $this->rawselectors) * 100, 1).'%',
+        );
+        return $stats;
+    }
+
+    /**
+     * Returns true if any errors have occured during processing
+     *
+     * @return bool
+     */
+    public function has_errors() {
+        return !empty($this->errors);
+    }
+
+    /**
+     * Returns an array of errors that have occured
+     *
+     * @return array
+     */
+    public function get_errors() {
+        return $this->errors;
+    }
+
+    /**
+     * Returns any errors as a string that can be included in CSS.
+     *
+     * @return string
+     */
+    public function output_errors_css() {
+        $computedcss  = "/****************************************\n";
+        $computedcss .= " *--- Errors found during processing ----\n";
+        foreach ($this->errors as $error) {
+            $computedcss .= preg_replace('#^#m', '* ', $error);
+        }
+        $computedcss .= " ****************************************/\n\n";
+        return $computedcss;
+    }
+
+    /**
+     * Returns a string to display stats about the last generation within CSS output
+     *
+     * @return string
+     */
+    public function output_stats_css() {
+        $stats = $this->get_stats();
+
+        $strlenimprovement = round(100 - ($this->optimisedstrlen / $this->rawstrlen) * 100, 1);
+        $ruleimprovement = round(100 - ($this->optimisedrules / $this->rawrules) * 100, 1);
+        $selectorimprovement = round(100 - ($this->optimisedselectors / $this->rawselectors) * 100, 1);
+        $timetaken = round($this->timecomplete - $this->timestart, 4);
+
+        $computedcss  = "/****************************************\n";
+        $computedcss .= " *------- CSS Optimisation stats --------\n";
+        $computedcss .= " *  ".date('r')."\n";
+        $computedcss .= " *  {$stats['commentsincss']}  \t comments removed\n";
+        $computedcss .= " *  Optimisation took {$stats['timetaken']} seconds\n";
+        $computedcss .= " *--------------- before ----------------\n";
+        $computedcss .= " *  {$stats['rawstrlen']}  \t chars read in\n";
+        $computedcss .= " *  {$stats['rawrules']}  \t rules read in\n";
+        $computedcss .= " *  {$stats['rawselectors']}  \t total selectors\n";
+        $computedcss .= " *---------------- after ----------------\n";
+        $computedcss .= " *  {$stats['optimisedstrlen']}  \t chars once optimized\n";
+        $computedcss .= " *  {$stats['optimisedrules']}  \t optimized rules\n";
+        $computedcss .= " *  {$stats['optimisedselectors']}  \t total selectors once optimized\n";
+        $computedcss .= " *---------------- stats ----------------\n";
+        $computedcss .= " *  {$stats['improvementstrlen']}  \t reduction in chars\n";
+        $computedcss .= " *  {$stats['improvementrules']}  \t reduction in rules\n";
+        $computedcss .= " *  {$stats['improvementselectors']}  \t reduction in selectors\n";
+        $computedcss .= " ****************************************/\n\n";
+
+        return $computedcss;
+    }
+
+    /**
+     * Resets the stats ready for another fresh processing
+     */
+    public function reset_stats() {
+        $this->commentsincss = 0;
+        $this->optimisedrules = 0;
+        $this->optimisedselectors = 0;
+        $this->optimisedstrlen = 0;
+        $this->rawrules = 0;
+        $this->rawselectors = 0;
+        $this->rawstrlen = 0;
+        $this->timecomplete = 0;
+        $this->timestart = 0;
+    }
+
+    /**
+     * An array of the common HTML colours that are supported by most browsers.
+     *
+     * This reference table is used to allow us to unify colours, and will aid
+     * us in identifying buggy CSS using unsupported colours.
+     *
+     * @staticvar array
+     * @var array
+     */
+    public static $htmlcolours = array(
+        'aliceblue' => '#F0F8FF',
+        'antiquewhite' => '#FAEBD7',
+        'aqua' => '#00FFFF',
+        'aquamarine' => '#7FFFD4',
+        'azure' => '#F0FFFF',
+        'beige' => '#F5F5DC',
+        'bisque' => '#FFE4C4',
+        'black' => '#000000',
+        'blanchedalmond' => '#FFEBCD',
+        'blue' => '#0000FF',
+        'blueviolet' => '#8A2BE2',
+        'brown' => '#A52A2A',
+        'burlywood' => '#DEB887',
+        'cadetblue' => '#5F9EA0',
+        'chartreuse' => '#7FFF00',
+        'chocolate' => '#D2691E',
+        'coral' => '#FF7F50',
+        'cornflowerblue' => '#6495ED',
+        'cornsilk' => '#FFF8DC',
+        'crimson' => '#DC143C',
+        'cyan' => '#00FFFF',
+        'darkblue' => '#00008B',
+        'darkcyan' => '#008B8B',
+        'darkgoldenrod' => '#B8860B',
+        'darkgray' => '#A9A9A9',
+        'darkgrey' => '#A9A9A9',
+        'darkgreen' => '#006400',
+        'darkKhaki' => '#BDB76B',
+        'darkmagenta' => '#8B008B',
+        'darkolivegreen' => '#556B2F',
+        'arkorange' => '#FF8C00',
+        'darkorchid' => '#9932CC',
+        'darkred' => '#8B0000',
+        'darksalmon' => '#E9967A',
+        'darkseagreen' => '#8FBC8F',
+        'darkslateblue' => '#483D8B',
+        'darkslategray' => '#2F4F4F',
+        'darkslategrey' => '#2F4F4F',
+        'darkturquoise' => '#00CED1',
+        'darkviolet' => '#9400D3',
+        'deeppink' => '#FF1493',
+        'deepskyblue' => '#00BFFF',
+        'dimgray' => '#696969',
+        'dimgrey' => '#696969',
+        'dodgerblue' => '#1E90FF',
+        'firebrick' => '#B22222',
+        'floralwhite' => '#FFFAF0',
+        'forestgreen' => '#228B22',
+        'fuchsia' => '#FF00FF',
+        'gainsboro' => '#DCDCDC',
+        'ghostwhite' => '#F8F8FF',
+        'gold' => '#FFD700',
+        'goldenrod' => '#DAA520',
+        'gray' => '#808080',
+        'grey' => '#808080',
+        'green' => '#008000',
+        'greenyellow' => '#ADFF2F',
+        'honeydew' => '#F0FFF0',
+        'hotpink' => '#FF69B4',
+        'indianred ' => '#CD5C5C',
+        'indigo ' => '#4B0082',
+        'ivory' => '#FFFFF0',
+        'khaki' => '#F0E68C',
+        'lavender' => '#E6E6FA',
+        'lavenderblush' => '#FFF0F5',
+        'lawngreen' => '#7CFC00',
+        'lemonchiffon' => '#FFFACD',
+        'lightblue' => '#ADD8E6',
+        'lightcoral' => '#F08080',
+        'lightcyan' => '#E0FFFF',
+        'lightgoldenrodyellow' => '#FAFAD2',
+        'lightgray' => '#D3D3D3',
+        'lightgrey' => '#D3D3D3',
+        'lightgreen' => '#90EE90',
+        'lightpink' => '#FFB6C1',
+        'lightsalmon' => '#FFA07A',
+        'lightseagreen' => '#20B2AA',
+        'lightskyblue' => '#87CEFA',
+        'lightslategray' => '#778899',
+        'lightslategrey' => '#778899',
+        'lightsteelblue' => '#B0C4DE',
+        'lightyellow' => '#FFFFE0',
+        'lime' => '#00FF00',
+        'limegreen' => '#32CD32',
+        'linen' => '#FAF0E6',
+        'magenta' => '#FF00FF',
+        'maroon' => '#800000',
+        'mediumaquamarine' => '#66CDAA',
+        'mediumblue' => '#0000CD',
+        'mediumorchid' => '#BA55D3',
+        'mediumpurple' => '#9370D8',
+        'mediumseagreen' => '#3CB371',
+        'mediumslateblue' => '#7B68EE',
+        'mediumspringgreen' => '#00FA9A',
+        'mediumturquoise' => '#48D1CC',
+        'mediumvioletred' => '#C71585',
+        'midnightblue' => '#191970',
+        'mintcream' => '#F5FFFA',
+        'mistyrose' => '#FFE4E1',
+        'moccasin' => '#FFE4B5',
+        'navajowhite' => '#FFDEAD',
+        'navy' => '#000080',
+        'oldlace' => '#FDF5E6',
+        'olive' => '#808000',
+        'olivedrab' => '#6B8E23',
+        'orange' => '#FFA500',
+        'orangered' => '#FF4500',
+        'orchid' => '#DA70D6',
+        'palegoldenrod' => '#EEE8AA',
+        'palegreen' => '#98FB98',
+        'paleturquoise' => '#AFEEEE',
+        'palevioletred' => '#D87093',
+        'papayawhip' => '#FFEFD5',
+        'peachpuff' => '#FFDAB9',
+        'peru' => '#CD853F',
+        'pink' => '#FFC0CB',
+        'plum' => '#DDA0DD',
+        'powderblue' => '#B0E0E6',
+        'purple' => '#800080',
+        'red' => '#FF0000',
+        'rosybrown' => '#BC8F8F',
+        'royalblue' => '#4169E1',
+        'saddlebrown' => '#8B4513',
+        'salmon' => '#FA8072',
+        'sandybrown' => '#F4A460',
+        'seagreen' => '#2E8B57',
+        'seashell' => '#FFF5EE',
+        'sienna' => '#A0522D',
+        'silver' => '#C0C0C0',
+        'skyblue' => '#87CEEB',
+        'slateblue' => '#6A5ACD',
+        'slategray' => '#708090',
+        'slategrey' => '#708090',
+        'snow' => '#FFFAFA',
+        'springgreen' => '#00FF7F',
+        'steelblue' => '#4682B4',
+        'tan' => '#D2B48C',
+        'teal' => '#008080',
+        'thistle' => '#D8BFD8',
+        'tomato' => '#FF6347',
+        'transparent' => 'transparent',
+        'turquoise' => '#40E0D0',
+        'violet' => '#EE82EE',
+        'wheat' => '#F5DEB3',
+        'white' => '#FFFFFF',
+        'whitesmoke' => '#F5F5F5',
+        'yellow' => '#FFFF00',
+        'yellowgreen' => '#9ACD32'
+    );
+}
+
+/**
+ * Used to prepare CSS strings
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class css_writer {
+
+    /**
+     * The current indent level
+     * @var int
+     */
+    protected static $indent = 0;
+
+    /**
+     * Returns true if the output should still maintain minimum formatting.
+     * @return bool
+     */
+    protected static function is_pretty() {
+        global $CFG;
+        return (!empty($CFG->cssoptimiserpretty));
+    }
+
+    /**
+     * Returns the indenting char to use for indenting things nicely.
+     * @return string
+     */
+    protected static function get_indent() {
+        if (self::is_pretty()) {
+            return str_repeat("  ", self::$indent);
+        }
+        return '';
+    }
+
+    /**
+     * Increases the current indent
+     */
+    protected static function increase_indent() {
+        self::$indent++;
+    }
+
+    /**
+     * Decreases the current indent
+     */
+    protected static function decrease_indent() {
+        self::$indent--;
+    }
+
+    /**
+     * Returns the string to use as a separator
+     * @return string
+     */
+    protected static function get_separator() {
+        return (self::is_pretty())?"\n":' ';
+    }
+
+    /**
+     * Returns CSS for media
+     *
+     * @param string $typestring
+     * @param array $rules An array of css_rule objects
+     * @return string
+     */
+    public static function media($typestring, array &$rules) {
+        $nl = self::get_separator();
+
+        $output = '';
+        if ($typestring !== 'all') {
+            $output .= $nl.$nl."@media {$typestring} {".$nl;
+            self::increase_indent();
+        }
+        foreach ($rules as $rule) {
+            $output .= $rule->out().$nl;
+        }
+        if ($typestring !== 'all') {
+            self::decrease_indent();
+            $output .= '}';
+        }
+        return $output;
+    }
+
+    /**
+     * Returns CSS for a rule
+     *
+     * @param string $selector
+     * @param string $styles
+     * @return string
+     */
+    public static function rule($selector, $styles) {
+        $css = self::get_indent()."{$selector}{{$styles}}";
+        return $css;
+    }
+
+    /**
+     * Returns CSS for the selectors of a rule
+     *
+     * @param array $selectors Array of css_selector objects
+     * @return string
+     */
+    public static function selectors(array $selectors) {
+        $nl = self::get_separator();
+        $selectorstrings = array();
+        foreach ($selectors as $selector) {
+            $selectorstrings[] = $selector->out();
+        }
+        return join(','.$nl, $selectorstrings);
+    }
+
+    /**
+     * Returns a selector given the components that make it up.
+     *
+     * @param array $components
+     * @return string
+     */
+    public static function selector(array $components) {
+        return trim(join(' ', $components));
+    }
+
+    /**
+     * Returns a CSS string for the provided styles
+     *
+     * @param array $styles Array of css_style objects
+     * @return string
+     */
+    public static function styles(array $styles) {
+        $bits = array();
+        foreach ($styles as $style) {
+            $bits[] = $style->out();
+        }
+        return join('', $bits);
+    }
+
+    /**
+     * Returns a style CSS
+     *
+     * @param string $name
+     * @param string $value
+     * @param bool $important
+     * @return string
+     */
+    public static function style($name, $value, $important = false) {
+        if ($important && strpos($value, '!important') === false) {
+            $value .= ' !important';
+        }
+        return "{$name}:{$value};";
+    }
+}
+
+/**
+ * A structure to represent a CSS selector.
+ *
+ * The selector is the classes, id, elements, and psuedo bits that make up a CSS
+ * rule.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_selector {
+
+    /**
+     * An array of selector bits
+     * @var array
+     */
+    protected $selectors = array();
+
+    /**
+     * The number of selectors.
+     * @var int
+     */
+    protected $count = 0;
+
+    /**
+     * Initialises a new CSS selector
+     * @return css_selector
+     */
+    public static function init() {
+        return new css_selector();
+    }
+
+    /**
+     * CSS selectors can only be created through the init method above.
+     */
+    protected function __construct() {}
+
+    /**
+     * Adds a selector to the end of the current selector
+     * @param string $selector
+     */
+    public function add($selector) {
+        $selector = trim($selector);
+        $count = 0;
+        $count += preg_match_all('/(\.|#)/', $selector, $matchesarray);
+        if (strpos($selector, '.') !== 0 && strpos($selector, '#') !== 0) {
+            $count ++;
+        }
+        $this->count = $count;
+        $this->selectors[] = $selector;
+    }
+    /**
+     * Returns the number of individual components that make up this selector
+     * @return int
+     */
+    public function get_selector_count() {
+        return $this->count;
+    }
+
+    /**
+     * Returns the selector for use in a CSS rule
+     * @return string
+     */
+    public function out() {
+        return css_writer::selector($this->selectors);
+    }
+}
+
+/**
+ * A structure to represent a CSS rule.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_rule {
+
+    /**
+     * An array of CSS selectors {@see css_selector}
+     * @var array
+     */
+    protected $selectors = array();
+
+    /**
+     * An array of CSS styles {@see css_style}
+     * @var array
+     */
+    protected $styles = array();
+
+    /**
+     * Created a new CSS rule. This is the only way to create a new CSS rule externally.
+     * @return css_rule
+     */
+    public static function init() {
+        return new css_rule();
+    }
+
+    /**
+     * Constructs a new css rule.
+     *
+     * @param string $selector The selector or array of selectors that make up this rule.
+     * @param array $styles An array of styles that belong to this rule.
+     */
+    protected function __construct($selector = null, array $styles = array()) {
+        if ($selector != null) {
+            if (is_array($selector)) {
+                $this->selectors = $selector;
+            } else {
+                $this->selectors = array($selector);
+            }
+            $this->add_styles($styles);
+        }
+    }
+
+    /**
+     * Adds a new CSS selector to this rule
+     *
+     * e.g. $rule->add_selector('.one #two.two');
+     *
+     * @param css_selector $selector Adds a CSS selector to this rule.
+     */
+    public function add_selector(css_selector $selector) {
+        $this->selectors[] = $selector;
+    }
+
+    /**
+     * Adds a new CSS style to this rule.
+     *
+     * @param css_style|string $style Adds a new style to this rule
+     */
+    public function add_style($style) {
+        if (is_string($style)) {
+            $style = trim($style);
+            if (empty($style)) {
+                return;
+            }
+            $bits = explode(':', $style, 2);
+            if (count($bits) == 2) {
+                list($name, $value) = array_map('trim', $bits);
+            }
+            if (isset($name) && isset($value) && $name !== '' && $value !== '') {
+                $style = css_style::init($name, $value);
+            }
+        } else if ($style instanceof css_style) {
+            // Clone the style as it may be coming from another rule and we don't
+            // want references as it will likely be overwritten by proceeding
+            // rules
+            $style = clone($style);
+        }
+        if ($style instanceof css_style) {
+            $name = $style->get_name();
+            if (array_key_exists($name, $this->styles)) {
+                $this->styles[$name]->set_value($style->get_value());
+            } else {
+                $this->styles[$name] = $style;
+            }
+        } else if (is_array($style)) {
+            // We probably shouldn't worry about processing styles here but to
+            // be truthful it doesn't hurt.
+            foreach ($style as $astyle) {
+                $this->add_style($astyle);
+            }
+        }
+    }
+
+    /**
+     * An easy method of adding several styles at once. Just calls add_style.
+     *
+     * This method simply iterates over the array and calls {@see css_rule::add_style()}
+     * with each.
+     *
+     * @param array $styles Adds an array of styles
+     */
+    public function add_styles(array $styles) {
+        foreach ($styles as $style) {
+            $this->add_style($style);
+        }
+    }
+
+    /**
+     * Returns the array of selectors
+     *
+     * @return array
+     */
+    public function get_selectors() {
+        return $this->selectors;
+    }
+
+    /**
+     * Returns the array of styles
+     *
+     * @return array
+     */
+    public function get_styles() {
+        return $this->styles;
+    }
+
+    /**
+     * Outputs this rule as a fragment of CSS
+     *
+     * @return string
+     */
+    public function out() {
+        $selectors = css_writer::selectors($this->selectors);
+        $styles = css_writer::styles($this->get_consolidated_styles());
+        return css_writer::rule($selectors, $styles);
+    }
+
+    /**
+     * Consolidates all styles associated with this rule
+     *
+     * @return array An array of consolidated styles
+     */
+    public function get_consolidated_styles() {
+        $finalstyles = array();
+        $consolidate = array();
+        foreach ($this->styles as $style) {
+            $consolidatetoclass = $style->consolidate_to();
+            if ($style->is_valid() && !empty($consolidatetoclass) && class_exists('css_style_'.$consolidatetoclass)) {
+                $class = 'css_style_'.$consolidatetoclass;
+                if (!array_key_exists($class, $consolidate)) {
+                    $consolidate[$class] = array();
+                }
+                $consolidate[$class][] = $style;
+            } else {
+                $finalstyles[] = $style;
+            }
+        }
+
+        foreach ($consolidate as $class => $styles) {
+            $styles = $class::consolidate($styles);
+            foreach ($styles as $style) {
+                $finalstyles[] = $style;
+            }
+        }
+        return $finalstyles;
+    }
+
+    /**
+     * Splits this rules into an array of CSS rules. One for each of the selectors
+     * that make up this rule.
+     *
+     * @return array(css_rule)
+     */
+    public function split_by_selector() {
+        $return = array();
+        foreach ($this->selectors as $selector) {
+            $return[] = new css_rule($selector, $this->styles);
+        }
+        return $return;
+    }
+
+    /**
+     * Splits this rule into an array of rules. One for each of the styles that
+     * make up this rule
+     *
+     * @return array Array of css_rule objects
+     */
+    public function split_by_style() {
+        $return = array();
+        foreach ($this->styles as $style) {
+            $return[] = new css_rule($this->selectors, array($style));
+        }
+        return $return;
+    }
+
+    /**
+     * Gets a hash for the styles of this rule
+     *
+     * @return string
+     */
+    public function get_style_hash() {
+        return md5(css_writer::styles($this->styles));
+    }
+
+    /**
+     * Gets a hash for the selectors of this rule
+     *
+     * @return string
+     */
+    public function get_selector_hash() {
+        return md5(css_writer::selectors($this->selectors));
+    }
+
+    /**
+     * Gets the number of selectors that make up this rule.
+     *
+     * @return int
+     */
+    public function get_selector_count() {
+        $count = 0;
+        foreach ($this->selectors as $selector) {
+            $count += $selector->get_selector_count();
+        }
+        return $count;
+    }
+
+    /**
+     * Returns true if there are any errors with this rule.
+     *
+     * @return bool
+     */
+    public function has_errors() {
+        foreach ($this->styles as $style) {
+            if ($style->has_error()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns the error strings that were recorded when processing this rule.
+     *
+     * Before calling this function you should first call {@see css_rule::has_errors()}
+     * to make sure there are errors (hopefully there arn't).
+     *
+     * @return string
+     */
+    public function get_error_string() {
+        $css = $this->out();
+        $errors = array();
+        foreach ($this->styles as $style) {
+            if ($style->has_error()) {
+                $errors[] = "  * ".$style->get_last_error();
+            }
+        }
+        return $css." has the following errors:\n".join("\n", $errors);
+
+    }
+}
+
+/**
+ * A media class to organise rules by the media they apply to.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_media {
+
+    /**
+     * An array of the different media types this instance applies to.
+     * @var array
+     */
+    protected $types = array();
+
+    /**
+     * An array of rules within this media instance
+     * @var array
+     */
+    protected $rules = array();
+
+    /**
+     * Initalises a new media instance
+     *
+     * @param string $for The media that the contained rules are destined for.
+     */
+    public function __construct($for = 'all') {
+        $types = explode(',', $for);
+        $this->types = array_map('trim', $types);
+    }
+
+    /**
+     * Adds a new CSS rule to this media instance
+     *
+     * @param css_rule $newrule
+     */
+    public function add_rule(css_rule $newrule) {
+        foreach ($newrule->split_by_selector() as $rule) {
+            $hash = $rule->get_selector_hash();
+            if (!array_key_exists($hash, $this->rules)) {
+                $this->rules[$hash] = $rule;
+            } else {
+                $this->rules[$hash]->add_styles($rule->get_styles());
+            }
+        }
+    }
+
+    /**
+     * Returns the rules used by this
+     *
+     * @return array
+     */
+    public function get_rules() {
+        return $this->rules;
+    }
+
+    /**
+     * Organises rules by gropuing selectors based upon the styles and consolidating
+     * those selectors into single rules.
+     *
+     * @return bool True if the CSS was optimised by this method
+     */
+    public function organise_rules_by_selectors() {
+        $optimised = array();
+        $beforecount = count($this->rules);
+        foreach ($this->rules as $rule) {
+            $hash = $rule->get_style_hash();
+            if (!array_key_exists($hash, $optimised)) {
+                $optimised[$hash] = clone($rule);
+            } else {
+                foreach ($rule->get_selectors() as $selector) {
+                    $optimised[$hash]->add_selector($selector);
+                }
+            }
+        }
+        $this->rules = $optimised;
+        $aftercount = count($this->rules);
+        return ($beforecount < $aftercount);
+    }
+
+    /**
+     * Returns the total number of rules that exist within this media set
+     *
+     * @return int
+     */
+    public function count_rules() {
+        return count($this->rules);
+    }
+
+    /**
+     * Returns the total number of selectors that exist within this media set
+     *
+     * @return int
+     */
+    public function count_selectors() {
+        $count = 0;
+        foreach ($this->rules as $rule) {
+            $count += $rule->get_selector_count();
+        }
+        return $count;
+    }
+
+    /**
+     * Returns the CSS for this media and all of its rules.
+     *
+     * @return string
+     */
+    public function out() {
+        return css_writer::media(join(',', $this->types), $this->rules);
+    }
+
+    /**
+     * Returns an array of media that this media instance applies to
+     *
+     * @return array
+     */
+    public function get_types() {
+        return $this->types;
+    }
+
+    /**
+     * Returns true if the media has any rules that have errors
+     *
+     * @return boolean
+     */
+    public function has_errors() {
+        foreach ($this->rules as $rule) {
+            if ($rule->has_errors()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns any errors that have happened within rules in this media set.
+     *
+     * @return string
+     */
+    public function get_errors() {
+        $errors = array();
+        foreach ($this->rules as $rule) {
+            if ($rule->has_errors()) {
+                $errors[] = $rule->get_error_string();
+            }
+        }
+        return join("\n", $errors);
+    }
+}
+
+/**
+ * An absract class to represent CSS styles
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+abstract class css_style {
+
+    /**
+     * The name of the style
+     * @var string
+     */
+    protected $name;
+
+    /**
+     * The value for the style
+     * @var mixed
+     */
+    protected $value;
+
+    /**
+     * If set to true this style was defined with the !important rule.
+     * Only trolls use !important.
+     * Don't hide under bridges.. its not good for your skin. Do the proper thing
+     * and fix the issue don't just force a fix that will undoubtedly one day
+     * lead to further frustration.
+     * @var bool
+     */
+    protected $important = false;
+
+    /**
+     * Gets set to true if this style has an error
+     * @var bool
+     */
+    protected $error = false;
+
+    /**
+     * The last error message that occured
+     * @var string
+     */
+    protected $errormessage = null;
+
+
+    /**
+     * Initialises a new style.
+     *
+     * This is the only public way to create a style to ensure they that appropriate
+     * style class is used if it exists.
+     *
+     * @param string $name The name of the style.
+     * @param string $value The value of the style.
+     * @return css_style_generic
+     */
+    public static function init($name, $value) {
+        $specificclass = 'css_style_'.preg_replace('#[^a-zA-Z0-9]+#', '', $name);
+        if (class_exists($specificclass)) {
+            return $specificclass::init($value);
+        }
+        return new css_style_generic($name, $value);
+    }
+
+    /**
+     * Creates a new style when given its name and value
+     *
+     * @param string $name The name of the style.
+     * @param string $value The value of the style.
+     */
+    protected function __construct($name, $value) {
+        $this->name = $name;
+        $this->set_value($value);
+    }
+
+    /**
+     * Sets the value for the style
+     *
+     * @param string $value
+     */
+    final public function set_value($value) {
+        $value = trim($value);
+        $important = preg_match('#(\!important\s*;?\s*)$#', $value, $matches);
+        if ($important) {
+            $value = substr($value, 0, -(strlen($matches[1])));
+        }
+        if (!$this->important || $important) {
+            $this->value = $this->clean_value($value);
+            $this->important = $important;
+        }
+        if (!$this->is_valid()) {
+            $this->set_error('Invalid value for '.$this->name);
+        }
+    }
+
+    /**
+     * Returns true if the value associated with this style is valid
+     *
+     * @return bool
+     */
+    public function is_valid() {
+        return true;
+    }
+
+    /**
+     * Returns the name for the style
+     *
+     * @return string
+     */
+    public function get_name() {
+        return $this->name;
+    }
+
+    /**
+     * Returns the value for the style
+     *
+     * @return string
+     */
+    public function get_value() {
+        $value = $this->value;
+        if ($this->important) {
+            $value .= ' !important';
+        }
+        return $value;
+    }
+
+    /**
+     * Returns the style ready for use in CSS
+     *
+     * @param string|null $value A value to use to override the value for this style.
+     * @return string
+     */
+    public function out($value = null) {
+        if (is_null($value)) {
+            $value = $this->get_value();
+        }
+        return css_writer::style($this->name, $value, $this->important);
+    }
+
+    /**
+     * This can be overridden by a specific style allowing it to clean its values
+     * consistently.
+     *
+     * @param mixed $value
+     * @return mixed
+     */
+    protected function clean_value($value) {
+        return $value;
+    }
+
+    /**
+     * If this particular style can be consolidated into another style this function
+     * should return the style that it can be consolidated into.
+     *
+     * @return string|null
+     */
+    public function consolidate_to() {
+        return null;
+    }
+
+    /**
+     * Sets the last error message.
+     *
+     * @param string $message
+     */
+    protected function set_error($message) {
+        $this->error = true;
+        $this->errormessage = $message;
+    }
+
+    /**
+     * Returns true if an error has occured
+     *
+     * @return bool
+     */
+    public function has_error() {
+        return $this->error;
+    }
+
+    /**
+     * Returns the last error that occured or null if no errors have happened.
+     *
+     * @return string
+     */
+    public function get_last_error() {
+        return $this->errormessage;
+    }
+}
+
+/**
+ * A generic CSS style class to use when a more specific class does not exist.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_generic extends css_style {
+
+    /**
+     * Cleans incoming values for typical things that can be optimised.
+     *
+     * @param mixed $value Cleans the provided value optimising it if possible
+     * @return string
+     */
+    protected function clean_value($value) {
+        if (trim($value) == '0px') {
+            $value = 0;
+        } else if (preg_match('/^#([a-fA-F0-9]{3,6})/', $value, $matches)) {
+            $value = '#'.strtoupper($matches[1]);
+        }
+        return $value;
+    }
+}
+
+/**
+ * A colour CSS style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_color extends css_style {
+
+    /**
+     * Creates a new colour style
+     *
+     * @param mixed $value Initialises a new colour style
+     * @return css_style_color
+     */
+    public static function init($value) {
+        return new css_style_color('color', $value);
+    }
+
+    /**
+     * Cleans the colour unifing it to a 6 char hash colour if possible
+     * Doing this allows us to associate identical colours being specified in
+     * different ways. e.g. Red, red, #F00, and #F00000
+     *
+     * @param mixed $value Cleans the provided value optimising it if possible
+     * @return string
+     */
+    protected function clean_value($value) {
+        $value = trim($value);
+        if (css_is_colour($value)) {
+            if (preg_match('/#([a-fA-F0-9]{6})/', $value, $matches)) {
+                $value = '#'.strtoupper($matches[1]);
+            } else if (preg_match('/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/', $value, $matches)) {
+                $value = $matches[1] . $matches[1] . $matches[2] . $matches[2] . $matches[3] . $matches[3];
+                $value = '#'.strtoupper($value);
+            } else if (array_key_exists(strtolower($value), css_optimiser::$htmlcolours)) {
+                $value = css_optimiser::$htmlcolours[strtolower($value)];
+            }
+        }
+        return $value;
+    }
+
+    /**
+     * Returns the colour style for use within CSS.
+     * Will return an optimised hash colour.
+     *
+     * e.g #123456
+     *     #123 instead of #112233
+     *     #F00 instead of red
+     *
+     * @param string $overridevalue If provided then this value will be used instead
+     *     of the styles current value.
+     * @return string
+     */
+    public function out($overridevalue = null) {
+        if ($overridevalue === null) {
+            $overridevalue = $this->value;
+        }
+        return parent::out(self::shrink_value($overridevalue));
+    }
+
+    /**
+     * Shrinks the colour value is possible.
+     *
+     * @param string $value Shrinks the current value to an optimial form if possible
+     * @return string
+     */
+    public static function shrink_value($value) {
+        if (preg_match('/#([a-fA-F0-9])\1([a-fA-F0-9])\2([a-fA-F0-9])\3/', $value, $matches)) {
+            return '#'.$matches[1].$matches[2].$matches[3];
+        }
+        return $value;
+    }
+
+    /**
+     * Returns true if the value is a valid colour.
+     *
+     * @return bool
+     */
+    public function is_valid() {
+        return css_is_colour($this->value);
+    }
+}
+
+/**
+ * A width style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_width extends css_style {
+
+    /**
+     * Checks if the width is valid
+     * @return bool
+     */
+    public function is_valid() {
+        return css_is_width($this->value);
+    }
+
+    /**
+     * Cleans the provided value
+     *
+     * @param mixed $value Cleans the provided value optimising it if possible
+     * @return string
+     */
+    protected function clean_value($value) {
+        if (!css_is_width($value)) {
+            // Note we don't actually change the value to something valid. That
+            // would be bad for futureproofing.
+            $this->set_error('Invalid width specified for '.$this->name);
+        } else if (preg_match('#^0\D+$#', $value)) {
+            $value = 0;
+        }
+        return trim($value);
+    }
+
+    /**
+     * Initialises a new width style
+     *
+     * @param mixed $value The value this style has
+     * @return css_style_width
+     */
+    public static function init($value) {
+        return new css_style_width('width', $value);
+    }
+}
+
+/**
+ * A margin style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_margin extends css_style_width {
+
+    /**
+     * Initialises a margin style.
+     *
+     * In this case we split the margin into several other margin styles so that
+     * we can properly condense overrides and then reconsolidate them later into
+     * an optimal form.
+     *
+     * @param string $value The value the style has
+     * @return array An array of margin values that can later be consolidated
+     */
+    public static function init($value) {
+        $important = '';
+        if (strpos($value, '!important') !== false) {
+            $important = ' !important';
+            $value = str_replace('!important', '', $value);
+        }
+
+        $value = preg_replace('#\s+#', ' ', trim($value));
+        $bits = explode(' ', $value, 4);
+
+        $top = $right = $bottom = $left = null;
+        if (count($bits) > 0) {
+            $top = $right = $bottom = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $right = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $bottom = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $left = array_shift($bits);
+        }
+        return array(
+            new css_style_margintop('margin-top', $top.$important),
+            new css_style_marginright('margin-right', $right.$important),
+            new css_style_marginbottom('margin-bottom', $bottom.$important),
+            new css_style_marginleft('margin-left', $left.$important)
+        );
+    }
+
+    /**
+     * Consolidates individual margin styles into a single margin style
+     *
+     * @param array $styles
+     * @return array An array of consolidated styles
+     */
+    public static function consolidate(array $styles) {
+        if (count($styles) != 4) {
+            return $styles;
+        }
+        $top = $right = $bottom = $left = null;
+        foreach ($styles as $style) {
+            switch ($style->get_name()) {
+                case 'margin-top' : $top = $style->get_value();break;
+                case 'margin-right' : $right = $style->get_value();break;
+                case 'margin-bottom' : $bottom = $style->get_value();break;
+                case 'margin-left' : $left = $style->get_value();break;
+            }
+        }
+        if ($top == $bottom && $left == $right) {
+            if ($top == $left) {
+                return array(new css_style_margin('margin', $top));
+            } else {
+                return array(new css_style_margin('margin', "{$top} {$left}"));
+            }
+        } else if ($left == $right) {
+            return array(new css_style_margin('margin', "{$top} {$right} {$bottom}"));
+        } else {
+            return array(new css_style_margin('margin', "{$top} {$right} {$bottom} {$left}"));
+        }
+    }
+}
+
+/**
+ * A margin top style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_margintop extends css_style_margin {
+
+    /**
+     * A simple init, just a single style
+     *
+     * @param string $value The value the style has
+     * @return css_style_margintop
+     */
+    public static function init($value) {
+        return new css_style_margintop('margin-top', $value);
+    }
+
+    /**
+     * This style can be consolidated into a single margin style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'margin';
+    }
+}
+
+/**
+ * A margin right style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_marginright extends css_style_margin {
+
+    /**
+     * A simple init, just a single style
+     *
+     * @param string $value The value the style has
+     * @return css_style_margintop
+     */
+    public static function init($value) {
+        return new css_style_marginright('margin-right', $value);
+    }
+
+    /**
+     * This style can be consolidated into a single margin style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'margin';
+    }
+}
+
+/**
+ * A margin bottom style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_marginbottom extends css_style_margin {
+
+    /**
+     * A simple init, just a single style
+     *
+     * @param string $value The value the style has
+     * @return css_style_margintop
+     */
+    public static function init($value) {
+        return new css_style_marginbottom('margin-bottom', $value);
+    }
+
+    /**
+     * This style can be consolidated into a single margin style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'margin';
+    }
+}
+
+/**
+ * A margin left style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_marginleft extends css_style_margin {
+
+    /**
+     * A simple init, just a single style
+     *
+     * @param string $value The value the style has
+     * @return css_style_margintop
+     */
+    public static function init($value) {
+        return new css_style_marginleft('margin-left', $value);
+    }
+
+    /**
+     * This style can be consolidated into a single margin style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'margin';
+    }
+}
+
+/**
+ * A border style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_border extends css_style {
+
+    /**
+     * Initalises the border style into an array of individual style compontents
+     *
+     * @param string $value The value the style has
+     * @return css_style_bordercolor
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 3);
+
+        $return = array();
+        if (count($bits) > 0) {
+            $width = array_shift($bits);
+            if (!css_is_width($width)) {
+                $width = '0';
+            }
+            $return[] = new css_style_borderwidth('border-top-width', $width);
+            $return[] = new css_style_borderwidth('border-right-width', $width);
+            $return[] = new css_style_borderwidth('border-bottom-width', $width);
+            $return[] = new css_style_borderwidth('border-left-width', $width);
+        }
+        if (count($bits) > 0) {
+            $style = array_shift($bits);
+            $return[] = new css_style_borderstyle('border-top-style', $style);
+            $return[] = new css_style_borderstyle('border-right-style', $style);
+            $return[] = new css_style_borderstyle('border-bottom-style', $style);
+            $return[] = new css_style_borderstyle('border-left-style', $style);
+        }
+        if (count($bits) > 0) {
+            $colour = array_shift($bits);
+            $return[] = new css_style_bordercolor('border-top-color', $colour);
+            $return[] = new css_style_bordercolor('border-right-color', $colour);
+            $return[] = new css_style_bordercolor('border-bottom-color', $colour);
+            $return[] = new css_style_bordercolor('border-left-color', $colour);
+        }
+        return $return;
+    }
+
+    /**
+     * Consolidates all border styles into a single style
+     *
+     * @param array $styles An array of border styles
+     * @return array An optimised array of border styles
+     */
+    public static function consolidate(array $styles) {
+
+        $borderwidths = array('top' => null, 'right' => null, 'bottom' => null, 'left' => null);
+        $borderstyles = array('top' => null, 'right' => null, 'bottom' => null, 'left' => null);
+        $bordercolors = array('top' => null, 'right' => null, 'bottom' => null, 'left' => null);
+
+        foreach ($styles as $style) {
+            switch ($style->get_name()) {
+                case 'border-top-width': $borderwidths['top'] = $style->get_value(); break;
+                case 'border-right-width': $borderwidths['right'] = $style->get_value(); break;
+                case 'border-bottom-width': $borderwidths['bottom'] = $style->get_value(); break;
+                case 'border-left-width': $borderwidths['left'] = $style->get_value(); break;
+
+                case 'border-top-style': $borderstyles['top'] = $style->get_value(); break;
+                case 'border-right-style': $borderstyles['right'] = $style->get_value(); break;
+                case 'border-bottom-style': $borderstyles['bottom'] = $style->get_value(); break;
+                case 'border-left-style': $borderstyles['left'] = $style->get_value(); break;
+
+                case 'border-top-color': $bordercolors['top'] = $style->get_value(); break;
+                case 'border-right-color': $bordercolors['right'] = $style->get_value(); break;
+                case 'border-bottom-color': $bordercolors['bottom'] = $style->get_value(); break;
+                case 'border-left-color': $bordercolors['left'] = $style->get_value(); break;
+            }
+        }
+
+        $uniquewidths = count(array_unique($borderwidths));
+        $uniquestyles = count(array_unique($borderstyles));
+        $uniquecolors = count(array_unique($bordercolors));
+
+        $nullwidths = in_array(null, $borderwidths, true);
+        $nullstyles = in_array(null, $borderstyles, true);
+        $nullcolors = in_array(null, $bordercolors, true);
+
+        $allwidthsthesame = ($uniquewidths === 1)?1:0;
+        $allstylesthesame = ($uniquestyles === 1)?1:0;
+        $allcolorsthesame = ($uniquecolors === 1)?1:0;
+
+        $allwidthsnull = $allwidthsthesame && $nullwidths;
+        $allstylesnull = $allstylesthesame && $nullstyles;
+        $allcolorsnull = $allcolorsthesame && $nullcolors;
+
+        $return = array();
+        if ($allwidthsnull && $allstylesnull && $allcolorsnull) {
+            // Everything is null still... boo
+            return array(new css_style_border('border', ''));
+
+        } else if ($allwidthsnull && $allstylesnull) {
+
+            self::consolidate_styles_by_direction($return, 'css_style_bordercolor', 'border-color', $bordercolors);
+            return $return;
+
+        } else if ($allwidthsnull && $allcolorsnull) {
+
+            self::consolidate_styles_by_direction($return, 'css_style_borderstyle', 'border-style', $borderstyles);
+            return $return;
+
+        } else if ($allcolorsnull && $allstylesnull) {
+
+            self::consolidate_styles_by_direction($return, 'css_style_borderwidth', 'border-width', $borderwidths);
+            return $return;
+
+        }
+
+        if ($allwidthsthesame + $allstylesthesame + $allcolorsthesame == 3) {
+
+            $return[] = new css_style_border('border', $borderwidths['top'].' '.$borderstyles['top'].' '.$bordercolors['top']);
+
+        } else if ($allwidthsthesame + $allstylesthesame + $allcolorsthesame == 2) {
+
+            if ($allwidthsthesame && $allstylesthesame && !$nullwidths && !$nullstyles) {
+
+                $return[] = new css_style_border('border', $borderwidths['top'].' '.$borderstyles['top']);
+                self::consolidate_styles_by_direction($return, 'css_style_bordercolor', 'border-color', $bordercolors);
+
+            } else if ($allwidthsthesame && $allcolorsthesame && !$nullwidths && !$nullcolors) {
+
+                $return[] = new css_style_border('border', $borderwidths['top'].' solid '.$bordercolors['top']);
+                self::consolidate_styles_by_direction($return, 'css_style_borderstyle', 'border-style', $borderstyles);
+
+            } else if ($allstylesthesame && $allcolorsthesame && !$nullstyles && !$nullcolors) {
+
+                $return[] = new css_style_border('border', '1px '.$borderstyles['top'].' '.$bordercolors['top']);
+                self::consolidate_styles_by_direction($return, 'css_style_borderwidth', 'border-width', $borderwidths);
+
+            } else {
+                self::consolidate_styles_by_direction($return, 'css_style_borderwidth', 'border-width', $borderwidths);
+                self::consolidate_styles_by_direction($return, 'css_style_borderstyle', 'border-style', $borderstyles);
+                self::consolidate_styles_by_direction($return, 'css_style_bordercolor', 'border-color', $bordercolors);
+            }
+
+        } else if (!$nullwidths && !$nullcolors && !$nullstyles && max(array_count_values($borderwidths)) == 3 && max(array_count_values($borderstyles)) == 3 && max(array_count_values($bordercolors)) == 3) {
+            $widthkeys = array();
+            $stylekeys = array();
+            $colorkeys = array();
+
+            foreach ($borderwidths as $key => $value) {
+                if (!array_key_exists($value, $widthkeys)) {
+                    $widthkeys[$value] = array();
+                }
+                $widthkeys[$value][] = $key;
+            }
+            usort($widthkeys, 'css_sort_by_count');
+            $widthkeys = array_values($widthkeys);
+
+            foreach ($borderstyles as $key => $value) {
+                if (!array_key_exists($value, $stylekeys)) {
+                    $stylekeys[$value] = array();
+                }
+                $stylekeys[$value][] = $key;
+            }
+            usort($stylekeys, 'css_sort_by_count');
+            $stylekeys = array_values($stylekeys);
+
+            foreach ($bordercolors as $key => $value) {
+                if (!array_key_exists($value, $colorkeys)) {
+                    $colorkeys[$value] = array();
+                }
+                $colorkeys[$value][] = $key;
+            }
+            usort($colorkeys, 'css_sort_by_count');
+            $colorkeys = array_values($colorkeys);
+
+            if ($widthkeys == $stylekeys && $stylekeys == $colorkeys) {
+                $key = $widthkeys[0][0];
+                self::build_style_string($return, 'css_style_border', 'border',  $borderwidths[$key], $borderstyles[$key], $bordercolors[$key]);
+                $key = $widthkeys[1][0];
+                self::build_style_string($return, 'css_style_border'.$key, 'border-'.$key,  $borderwidths[$key], $borderstyles[$key], $bordercolors[$key]);
+            } else {
+                self::build_style_string($return, 'css_style_bordertop', 'border-top', $borderwidths['top'], $borderstyles['top'], $bordercolors['top']);
+                self::build_style_string($return, 'css_style_borderright', 'border-right', $borderwidths['right'], $borderstyles['right'], $bordercolors['right']);
+                self::build_style_string($return, 'css_style_borderbottom', 'border-bottom', $borderwidths['bottom'], $borderstyles['bottom'], $bordercolors['bottom']);
+                self::build_style_string($return, 'css_style_borderleft', 'border-left', $borderwidths['left'], $borderstyles['left'], $bordercolors['left']);
+            }
+        } else {
+            self::build_style_string($return, 'css_style_bordertop', 'border-top', $borderwidths['top'], $borderstyles['top'], $bordercolors['top']);
+            self::build_style_string($return, 'css_style_borderright', 'border-right', $borderwidths['right'], $borderstyles['right'], $bordercolors['right']);
+            self::build_style_string($return, 'css_style_borderbottom', 'border-bottom', $borderwidths['bottom'], $borderstyles['bottom'], $bordercolors['bottom']);
+            self::build_style_string($return, 'css_style_borderleft', 'border-left', $borderwidths['left'], $borderstyles['left'], $bordercolors['left']);
+        }
+        foreach ($return as $key => $style) {
+            if ($style->get_value() == '') {
+                unset($return[$key]);
+            }
+        }
+        return $return;
+    }
+
+    /**
+     * Border styles get consolidated to a single border style.
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+
+    /**
+     * Consolidates a series of border styles into an optimised array of border
+     * styles by looking at the direction of the border and prioritising that
+     * during the optimisation.
+     *
+     * @param array $array An array to add styles into during consolidation. Passed by reference.
+     * @param string $class The class type to initalise
+     * @param string $style The style to create
+     * @param string|array $top The top value
+     * @param string $right The right value
+     * @param string $bottom The bottom value
+     * @param string $left The left value
+     * @return bool
+     */
+    public static function consolidate_styles_by_direction(&$array, $class, $style, $top, $right = null, $bottom = null, $left = null) {
+        if (is_array($top)) {
+            $right = $top['right'];
+            $bottom = $top['bottom'];
+            $left = $top['left'];
+            $top = $top['top'];
+        }
+
+        if ($top == $bottom && $left == $right && $top == $left) {
+            if (is_null($top)) {
+                $array[] = new $class($style, '');
+            } else {
+                $array[] =  new $class($style, $top);
+            }
+        } else if ($top == null || $right == null || $bottom == null || $left == null) {
+            if ($top !== null) {
+                $array[] = new $class(str_replace('border-', 'border-top-', $style), $top);
+            }
+            if ($right !== null) {
+                $array[] = new $class(str_replace('border-', 'border-right-', $style), $right);
+            }
+            if ($bottom !== null) {
+                $array[] = new $class(str_replace('border-', 'border-bottom-', $style), $bottom);
+            }
+            if ($left !== null) {
+                $array[] = new $class(str_replace('border-', 'border-left-', $style), $left);
+            }
+        } else if ($top == $bottom && $left == $right) {
+            $array[] = new $class($style, $top.' '.$right);
+        } else if ($left == $right) {
+            $array[] = new $class($style, $top.' '.$right.' '.$bottom);
+        } else {
+            $array[] = new $class($style, $top.' '.$right.' '.$bottom.' '.$left);
+        }
+        return true;
+    }
+
+    /**
+     * Builds a border style for a set of width, style, and colour values
+     *
+     * @param array $array An array into which the generated style is added
+     * @param string $class The class type to initialise
+     * @param string $cssstyle The style to use
+     * @param string $width The width of the border
+     * @param string $style The style of the border
+     * @param string $color The colour of the border
+     * @return bool
+     */
+    public static function build_style_string(&$array, $class, $cssstyle, $width = null, $style = null, $color = null) {
+        if (!is_null($width) && !is_null($style) && !is_null($color)) {
+            $array[] = new $class($cssstyle, $width.' '.$style.' '.$color);
+        } else if (!is_null($width) && !is_null($style) && is_null($color)) {
+            $array[] = new $class($cssstyle, $width.' '.$style);
+        } else if (!is_null($width) && is_null($style) && is_null($color)) {
+            $array[] = new $class($cssstyle, $width);
+        } else {
+            if (!is_null($width)) $array[] = new $class($cssstyle, $width);
+            if (!is_null($style)) $array[] = new $class($cssstyle, $style);
+            if (!is_null($color)) $array[] = new $class($cssstyle, $color);
+        }
+        return true;
+    }
+}
+
+/**
+ * A border colour style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_bordercolor extends css_style_color {
+
+    /**
+     * Creates a new border colour style
+     *
+     * Based upon the colour style
+     *
+     * @param mixed $value
+     * @return Array of css_style_bordercolor
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 4);
+
+        $top = $right = $bottom = $left = null;
+        if (count($bits) > 0) {
+            $top = $right = $bottom = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $right = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $bottom = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $left = array_shift($bits);
+        }
+        return array(
+            css_style_bordertopcolor::init($top),
+            css_style_borderrightcolor::init($right),
+            css_style_borderbottomcolor::init($bottom),
+            css_style_borderleftcolor::init($left)
+        );
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+
+    /**
+     * Cleans the value
+     *
+     * @param string $value Cleans the provided value optimising it if possible
+     * @return string
+     */
+    protected function clean_value($value) {
+        $values = explode(' ', $value);
+        $values = array_map('parent::clean_value', $values);
+        return join (' ', $values);
+    }
+
+    /**
+     * Outputs this style
+     *
+     * @param string $overridevalue
+     * @return string
+     */
+    public function out($overridevalue = null) {
+        if ($overridevalue === null) {
+            $overridevalue = $this->value;
+        }
+        $values = explode(' ', $overridevalue);
+        $values = array_map('css_style_color::shrink_value', $values);
+        return parent::out(join (' ', $values));
+    }
+}
+
+/**
+ * A border left style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderleft extends css_style_generic {
+
+    /**
+     * Initialises the border left style into individual components
+     *
+     * @param string $value
+     * @return array Array of css_style_borderleftwidth|css_style_borderleftstyle|css_style_borderleftcolor
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 3);
+
+        $return = array();
+        if (count($bits) > 0) {
+            $return[] = css_style_borderleftwidth::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_borderleftstyle::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_borderleftcolor::init(array_shift($bits));
+        }
+        return $return;
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border right style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderright extends css_style_generic {
+
+    /**
+     * Initialises the border right style into individual components
+     *
+     * @param string $value The value of the style
+     * @return array Array of css_style_borderrightwidth|css_style_borderrightstyle|css_style_borderrightcolor
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 3);
+
+        $return = array();
+        if (count($bits) > 0) {
+            $return[] = css_style_borderrightwidth::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_borderrightstyle::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_borderrightcolor::init(array_shift($bits));
+        }
+        return $return;
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border top style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_bordertop extends css_style_generic {
+
+    /**
+     * Initialises the border top style into individual components
+     *
+     * @param string $value The value of the style
+     * @return array Array of css_style_bordertopwidth|css_style_bordertopstyle|css_style_bordertopcolor
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 3);
+
+        $return = array();
+        if (count($bits) > 0) {
+            $return[] = css_style_bordertopwidth::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_bordertopstyle::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_bordertopcolor::init(array_shift($bits));
+        }
+        return $return;
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border bottom style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderbottom extends css_style_generic {
+
+    /**
+     * Initialises the border bottom style into individual components
+     *
+     * @param string $value The value of the style
+     * @return array Array of css_style_borderbottomwidth|css_style_borderbottomstyle|css_style_borderbottomcolor
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 3);
+
+        $return = array();
+        if (count($bits) > 0) {
+            $return[] = css_style_borderbottomwidth::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_borderbottomstyle::init(array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $return[] = css_style_borderbottomcolor::init(array_shift($bits));
+        }
+        return $return;
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border width style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderwidth extends css_style_width {
+
+    /**
+     * Creates a new border colour style
+     *
+     * Based upon the colour style
+     *
+     * @param string $value The value of the style
+     * @return array Array of css_style_border*width
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 4);
+
+        $top = $right = $bottom = $left = null;
+        if (count($bits) > 0) {
+            $top = $right = $bottom = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $right = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $bottom = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $left = array_shift($bits);
+        }
+        return array(
+            css_style_bordertopwidth::init($top),
+            css_style_borderrightwidth::init($right),
+            css_style_borderbottomwidth::init($bottom),
+            css_style_borderleftwidth::init($left)
+        );
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border style style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderstyle extends css_style_generic {
+
+    /**
+     * Creates a new border colour style
+     *
+     * Based upon the colour style
+     *
+     * @param string $value The value of the style
+     * @return array Array of css_style_border*style
+     */
+    public static function init($value) {
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value, 4);
+
+        $top = $right = $bottom = $left = null;
+        if (count($bits) > 0) {
+            $top = $right = $bottom = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $right = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $bottom = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $left = array_shift($bits);
+        }
+        return array(
+            css_style_bordertopstyle::init($top),
+            css_style_borderrightstyle::init($right),
+            css_style_borderbottomstyle::init($bottom),
+            css_style_borderleftstyle::init($left)
+        );
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border top colour style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_bordertopcolor extends css_style_bordercolor {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_bordertopcolor
+     */
+    public static function init($value) {
+        return new css_style_bordertopcolor('border-top-color', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border left colour style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderleftcolor extends css_style_bordercolor {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderleftcolor
+     */
+    public static function init($value) {
+        return new css_style_borderleftcolor('border-left-color', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border right colour style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderrightcolor extends css_style_bordercolor {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderrightcolor
+     */
+    public static function init($value) {
+        return new css_style_borderrightcolor('border-right-color', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border bottom colour style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderbottomcolor extends css_style_bordercolor {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderbottomcolor
+     */
+    public static function init($value) {
+        return new css_style_borderbottomcolor('border-bottom-color', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border width top style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_bordertopwidth extends css_style_borderwidth {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_bordertopwidth
+     */
+    public static function init($value) {
+        return new css_style_bordertopwidth('border-top-width', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border width left style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderleftwidth extends css_style_borderwidth {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderleftwidth
+     */
+    public static function init($value) {
+        return new css_style_borderleftwidth('border-left-width', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border width right style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderrightwidth extends css_style_borderwidth {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderrightwidth
+     */
+    public static function init($value) {
+        return new css_style_borderrightwidth('border-right-width', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border width bottom style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderbottomwidth extends css_style_borderwidth {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderbottomwidth
+     */
+    public static function init($value) {
+        return new css_style_borderbottomwidth('border-bottom-width', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border top style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_bordertopstyle extends css_style_borderstyle {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_bordertopstyle
+     */
+    public static function init($value) {
+        return new css_style_bordertopstyle('border-top-style', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border left style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderleftstyle extends css_style_borderstyle {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderleftstyle
+     */
+    public static function init($value) {
+        return new css_style_borderleftstyle('border-left-style', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border right style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderrightstyle extends css_style_borderstyle {
+
+    /**
+     * Initialises this style object
+     *
+     * @param string $value The value of the style
+     * @return css_style_borderrightstyle
+     */
+    public static function init($value) {
+        return new css_style_borderrightstyle('border-right-style', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A border bottom style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_borderbottomstyle extends css_style_borderstyle {
+
+    /**
+     * Initialises this style object
+     *
+     * @return css_style_borderbottomstyle
+     */
+    public static function init($value) {
+        return new css_style_borderbottomstyle('border-bottom-style', $value);
+    }
+
+    /**
+     * Consolidate this to a single border style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'border';
+    }
+}
+
+/**
+ * A background style
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_background extends css_style {
+
+    /**
+     * Initialises a background style
+     *
+     * @param type $value The value of the style
+     * @return array An array of background component.
+     */
+    public static function init($value) {
+        // colour - image - repeat - attachment - position
+
+        $imageurl = null;
+        if (preg_match('#url\(([^\)]+)\)#', $value, $matches)) {
+            $imageurl = trim($matches[1]);
+            $value = str_replace($matches[1], '', $value);
+        }
+
+        $value = preg_replace('#\s+#', ' ', $value);
+        $bits = explode(' ', $value);
+
+        $repeats = array('repeat', 'repeat-x', 'repeat-y', 'no-repeat', 'inherit');
+        $attachments = array('scroll' , 'fixed', 'inherit');
+
+        $return = array();
+        $unknownbits = array();
+
+        if (count($bits) > 0 && css_is_colour(reset($bits))) {
+            $return[] = new css_style_backgroundcolor('background-color', array_shift($bits));
+        }
+        if (count($bits) > 0 && preg_match('#(none|inherit|url\(\))#', reset($bits))) {
+            $image = array_shift($bits);
+            if ($image == 'url()') {
+                $image = "url({$imageurl})";
+            }
+            $return[] = new css_style_backgroundimage('background-image', $image);
+        }
+        if (count($bits) > 0 && in_array(reset($bits), $repeats)) {
+            $return[] = new css_style_backgroundrepeat('background-repeat', array_shift($bits));
+        }
+        if (count($bits) > 0 && in_array(reset($bits), $attachments)) {
+            // scroll , fixed, inherit
+            $return[] = new css_style_backgroundattachment('background-attachment', array_shift($bits));
+        }
+        if (count($bits) > 0) {
+            $widthbits = array();
+            foreach ($bits as $bit) {
+                if (in_array($bit, array('top', 'left', 'bottom', 'right', 'center')) || css_is_width($bit)) {
+                    $widthbits[] = $bit;
+                } else {
+                    $unknownbits[] = $bit;
+                }
+            }
+            $return[] = new css_style_backgroundposition('background-position', join(' ',$widthbits));
+        }
+        if (count($unknownbits)) {
+            foreach ($unknownbits as $bit) {
+                if (css_is_colour($bit)) {
+                    $return[] = new css_style_backgroundcolor('background-color', $bit);
+                } else if (in_array($bit, $repeats)) {
+                    $return[] = new css_style_backgroundrepeat('background-repeat', $bit);
+                } else if (in_array($bit, $attachments)) {
+                    $return[] = new css_style_backgroundattachment('background-attachment', $bit);
+                }
+            }
+        }
+        return $return;
+    }
+
+    /**
+     * Consolidates background styles into a single background style
+     *
+     * @param array $styles Consolidates the provided array of background styles
+     * @return array Consolidated optimised background styles
+     */
+    public static function consolidate(array $styles) {
+
+        if (count($styles) < 1) {
+            return $styles;
+        }
+
+        $color = $image = $repeat = $attachment = $position = null;
+        foreach ($styles as $style) {
+            switch ($style->get_name()) {
+                case 'background-color' : $color = css_style_color::shrink_value($style->get_value()); break;
+                case 'background-image' : $image = $style->get_value(); break;
+                case 'background-repeat' : $repeat = $style->get_value(); break;
+                case 'background-attachment' : $attachment = $style->get_value(); break;
+                case 'background-position' : $position = $style->get_value(); break;
+            }
+        }
+
+        if ((is_null($image) || is_null($position) || is_null($repeat)) && ($image!= null || $position != null || $repeat != null)) {
+            return $styles;
+        }
+
+        $value = array();
+        if (!is_null($color)) $value[] .= $color;
+        if (!is_null($image)) $value[] .= $image;
+        if (!is_null($repeat)) $value[] .= $repeat;
+        if (!is_null($attachment)) $value[] .= $attachment;
+        if (!is_null($position)) $value[] .= $position;
+        return array(new css_style_background('background', join(' ', $value)));
+    }
+}
+
+/**
+ * A background colour style.
+ *
+ * Based upon the colour style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_backgroundcolor extends css_style_color {
+
+    /**
+     * Creates a new background colour style
+     *
+     * @param string $value The value of the style
+     * @return css_style_backgroundcolor
+     */
+    public static function init($value) {
+        return new css_style_backgroundcolor('background-color', $value);
+    }
+
+    /**
+     * css_style_backgroundcolor consolidates to css_style_background
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'background';
+    }
+}
+
+/**
+ * A background image style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_backgroundimage extends css_style_generic {
+
+    /**
+     * Creates a new background colour style
+     *
+     * @param string $value The value of the style
+     * @return css_style_backgroundimage
+     */
+    public static function init($value) {
+        return new css_style_backgroundimage('background-image', $value);
+    }
+
+    /**
+     * Consolidates this style into a single background style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'background';
+    }
+}
+
+/**
+ * A background repeat style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_backgroundrepeat extends css_style_generic {
+
+    /**
+     * Creates a new background colour style
+     *
+     * @param string $value The value of the style
+     * @return css_style_backgroundrepeat
+     */
+    public static function init($value) {
+        return new css_style_backgroundrepeat('background-repeat', $value);
+    }
+
+    /**
+     * Consolidates this style into a single background style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'background';
+    }
+}
+
+/**
+ * A background attachment style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_backgroundattachment extends css_style_generic {
+
+    /**
+     * Creates a new background colour style
+     *
+     * @param string $value The value of the style
+     * @return css_style_backgroundattachment
+     */
+    public static function init($value) {
+        return new css_style_backgroundattachment('background-attachment', $value);
+    }
+
+    /**
+     * Consolidates this style into a single background style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'background';
+    }
+}
+
+/**
+ * A background position style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_backgroundposition extends css_style_generic {
+
+    /**
+     * Creates a new background colour style
+     *
+     * @param string $value The value of the style
+     * @return css_style_backgroundposition
+     */
+    public static function init($value) {
+        return new css_style_backgroundposition('background-position', $value);
+    }
+
+    /**
+     * Consolidates this style into a single background style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'background';
+    }
+}
+
+/**
+ * A padding style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_padding extends css_style_width {
+
+    /**
+     * Initialises this padding style into several individual padding styles
+     *
+     * @param string $value The value fo the style
+     * @return array An array of padding styles
+     */
+    public static function init($value) {
+        $important = '';
+        if (strpos($value, '!important') !== false) {
+            $important = ' !important';
+            $value = str_replace('!important', '', $value);
+        }
+
+        $value = preg_replace('#\s+#', ' ', trim($value));
+        $bits = explode(' ', $value, 4);
+
+        $top = $right = $bottom = $left = null;
+        if (count($bits) > 0) {
+            $top = $right = $bottom = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $right = $left = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $bottom = array_shift($bits);
+        }
+        if (count($bits) > 0) {
+            $left = array_shift($bits);
+        }
+        return array(
+            new css_style_paddingtop('padding-top', $top.$important),
+            new css_style_paddingright('padding-right', $right.$important),
+            new css_style_paddingbottom('padding-bottom', $bottom.$important),
+            new css_style_paddingleft('padding-left', $left.$important)
+        );
+    }
+
+    /**
+     * Consolidates several padding styles into a single style.
+     *
+     * @param array $styles Array of padding styles
+     * @return array Optimised+consolidated array of padding styles
+     */
+    public static function consolidate(array $styles) {
+        if (count($styles) != 4) {
+            return $styles;
+        }
+        $top = $right = $bottom = $left = null;
+        foreach ($styles as $style) {
+            switch ($style->get_name()) {
+                case 'padding-top' : $top = $style->get_value();break;
+                case 'padding-right' : $right = $style->get_value();break;
+                case 'padding-bottom' : $bottom = $style->get_value();break;
+                case 'padding-left' : $left = $style->get_value();break;
+            }
+        }
+        if ($top == $bottom && $left == $right) {
+            if ($top == $left) {
+                return array(new css_style_padding('padding', $top));
+            } else {
+                return array(new css_style_padding('padding', "{$top} {$left}"));
+            }
+        } else if ($left == $right) {
+            return array(new css_style_padding('padding', "{$top} {$right} {$bottom}"));
+        } else {
+            return array(new css_style_padding('padding', "{$top} {$right} {$bottom} {$left}"));
+        }
+    }
+}
+
+/**
+ * A padding top style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_paddingtop extends css_style_padding {
+
+    /**
+     * Initialises this style
+     *
+     * @param string $value The value of the style
+     * @return css_style_paddingtop
+     */
+    public static function init($value) {
+        return new css_style_paddingtop('padding-top', $value);
+    }
+
+    /**
+     * Consolidates this style into a single padding style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'padding';
+    }
+}
+
+/**
+ * A padding right style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_paddingright extends css_style_padding {
+
+    /**
+     * Initialises this style
+     *
+     * @param string $value The value of the style
+     * @return css_style_paddingright
+     */
+    public static function init($value) {
+        return new css_style_paddingright('padding-right', $value);
+    }
+
+    /**
+     * Consolidates this style into a single padding style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'padding';
+    }
+}
+
+/**
+ * A padding bottom style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_paddingbottom extends css_style_padding {
+
+    /**
+     * Initialises this style
+     *
+     * @param string $value The value of the style
+     * @return css_style_paddingbottom
+     */
+    public static function init($value) {
+        return new css_style_paddingbottom('padding-bottom', $value);
+    }
+
+    /**
+     * Consolidates this style into a single padding style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'padding';
+    }
+}
+
+/**
+ * A padding left style.
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_style_paddingleft extends css_style_padding {
+
+    /**
+     * Initialises this style
+     *
+     * @param string $value The value of the style
+     * @return css_style_paddingleft
+     */
+    public static function init($value) {
+        return new css_style_paddingleft('padding-left', $value);
+    }
+
+    /**
+     * Consolidates this style into a single padding style
+     *
+     * @return string
+     */
+    public function consolidate_to() {
+        return 'padding';
+    }
+}
\ No newline at end of file
index 91d97bd..7cc195e 100644 (file)
@@ -1260,7 +1260,7 @@ function get_my_remotehosts() {
 function make_default_scale() {
     global $DB;
 
-    $defaultscale = NULL;
+    $defaultscale = new stdClass();
     $defaultscale->courseid = 0;
     $defaultscale->userid = 0;
     $defaultscale->name  = get_string('separateandconnected');
index dc937ce..657814d 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20111214" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20120110" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="contextid"/>
       </KEYS>
       <INDEXES>
-        <INDEX NAME="sortorder" UNIQUE="false" FIELDS="sortorder"/>
+        <INDEX NAME="sortorder" UNIQUE="false" FIELDS="sortorder" NEXT="rolecontext"/>
+        <INDEX NAME="rolecontext" UNIQUE="false" FIELDS="roleid, contextid" COMMENT="Index on roleid and contextid" PREVIOUS="sortorder" NEXT="usercontextrole"/>
+        <INDEX NAME="usercontextrole" UNIQUE="false" FIELDS="userid, contextid, roleid" COMMENT="Index on userid, contextid and roleid" PREVIOUS="rolecontext"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="role_capabilities" COMMENT="permission has to be signed, overriding a capability for a particular role in a particular context" PREVIOUS="role_assignments" NEXT="role_names">
index ea92158..ca60e07 100644 (file)
@@ -112,6 +112,29 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2011120500.03);
     }
 
+    if ($oldversion < 2012020200.03) {
+
+        // Define index rolecontext (not unique) to be added to role_assignments
+        $table = new xmldb_table('role_assignments');
+        $index = new xmldb_index('rolecontext', XMLDB_INDEX_NOTUNIQUE, array('roleid', 'contextid'));
+
+        // Conditionally launch add index rolecontext
+        if (!$dbman->index_exists($table, $index)) {
+            $dbman->add_index($table, $index);
+        }
+
+        // Define index usercontextrole (not unique) to be added to role_assignments
+        $index = new xmldb_index('usercontextrole', XMLDB_INDEX_NOTUNIQUE, array('userid', 'contextid', 'roleid'));
+
+        // Conditionally launch add index usercontextrole
+        if (!$dbman->index_exists($table, $index)) {
+            $dbman->add_index($table, $index);
+        }
+
+        // Main savepoint reached
+        upgrade_main_savepoint(true, 2012020200.03);
+    }
+
     return true;
 }
 
index e3b4a22..1c3ddf3 100644 (file)
@@ -128,6 +128,9 @@ function file_prepare_standard_editor($data, $field, array $options, $context=nu
     if (is_null($itemid) or is_null($context)) {
         $contextid = null;
         $itemid = null;
+        if (!isset($data)) {
+            $data = new stdClass();
+        }
         if (!isset($data->{$field})) {
             $data->{$field} = '';
         }
@@ -3187,6 +3190,10 @@ function file_pluginfile($relativepath, $forcedownload) {
             print_error('siteblogdisable', 'blog');
         }
 
+        $entryid = (int)array_shift($args);
+        if (!$entry = $DB->get_record('post', array('module'=>'blog', 'id'=>$entryid))) {
+            send_file_not_found();
+        }
         if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
             require_login();
             if (isguestuser()) {
@@ -3198,10 +3205,6 @@ function file_pluginfile($relativepath, $forcedownload) {
                 }
             }
         }
-        $entryid = (int)array_shift($args);
-        if (!$entry = $DB->get_record('post', array('module'=>'blog', 'id'=>$entryid))) {
-            send_file_not_found();
-        }
 
         if ('publishstate' === 'public') {
             if ($CFG->forcelogin) {
index bb5ed88..3496f37 100644 (file)
@@ -829,6 +829,10 @@ function filter_get_all_local_settings($contextid) {
 function filter_get_active_in_context($context) {
     global $DB, $FILTERLIB_PRIVATE;
 
+    if (!isset($FILTERLIB_PRIVATE)) {
+        $FILTERLIB_PRIVATE = new stdClass();
+    }
+
     // Use cache (this is a within-request cache only) if available. See
     // function filter_preload_activities.
     if (isset($FILTERLIB_PRIVATE->active) &&
@@ -877,6 +881,10 @@ function filter_get_active_in_context($context) {
 function filter_preload_activities(course_modinfo $modinfo) {
     global $DB, $FILTERLIB_PRIVATE;
 
+    if (!isset($FILTERLIB_PRIVATE)) {
+        $FILTERLIB_PRIVATE = new stdClass();
+    }
+
     // Don't repeat preload
     if (!isset($FILTERLIB_PRIVATE->preloaded)) {
         $FILTERLIB_PRIVATE->preloaded = array();
index c157a47..cfe1d75 100644 (file)
@@ -19,9 +19,14 @@ class MoodleQuickForm_password extends HTML_QuickForm_password{
         if (empty($CFG->xmlstrictheaders)) {
             // no standard mform in moodle should allow autocomplete of passwords
             // this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0
-            $attributes = (array)$attributes;
-            if (!isset($attributes['autocomplete'])) {
+            if (empty($attributes)) {
+                $attributes = array('autocomplete'=>'off');
+            } else if (is_array($attributes)) {
                 $attributes['autocomplete'] = 'off';
+            } else {
+                if (strpos($attributes, 'autocomplete') === false) {
+                    $attributes .= ' autocomplete="off" ';
+                }
             }
         }
 
index 7210323..40e087e 100644 (file)
@@ -19,9 +19,14 @@ class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password {
         if (empty($CFG->xmlstrictheaders)) {
             // no standard mform in moodle should allow autocomplete of passwords
             // this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0
-            $attributes = (array)$attributes;
-            if (!isset($attributes['autocomplete'])) {
+            if (empty($attributes)) {
+                $attributes = array('autocomplete'=>'off');
+            } else if (is_array($attributes)) {
                 $attributes['autocomplete'] = 'off';
+            } else {
+                if (strpos($attributes, 'autocomplete') === false) {
+                    $attributes .= ' autocomplete="off" ';
+                }
             }
         }
         parent::MoodleQuickForm_password($elementName, $elementLabel, $attributes);
index e816da6..0818fbe 100644 (file)
@@ -143,9 +143,14 @@ abstract class moodleform {
         if (empty($CFG->xmlstrictheaders)) {
             // no standard mform in moodle should allow autocomplete with the exception of user signup
             // this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0
-            $attributes = (array)$attributes;
-            if (!isset($attributes['autocomplete'])) {
+            if (empty($attributes)) {
+                $attributes = array('autocomplete'=>'off');
+            } else if (is_array($attributes)) {
                 $attributes['autocomplete'] = 'off';
+            } else {
+                if (strpos($attributes, 'autocomplete') === false) {
+                    $attributes .= ' autocomplete="off" ';
+                }
             }
         }
 
@@ -2461,6 +2466,10 @@ class MoodleQuickForm_Rule_Required extends HTML_QuickForm_Rule {
         if (is_array($value) && array_key_exists('text', $value)) {
             $value = $value['text'];
         }
+        if (is_array($value)) {
+            // nasty guess - there has to be something in the array, hopefully nobody invents arrays in arrays
+            $value = implode('', $value);
+        }
         $stripvalues = array(
             '#</?(?!img|canvas|hr).*?>#im', // all tags except img, canvas and hr
             '#(\xc2|\xa0|\s|&nbsp;)#', //any whitespaces actually
index 2914205..57bc5d8 100644 (file)
@@ -417,6 +417,8 @@ define('MOD_ARCHETYPE_OTHER', 0);
 define('MOD_ARCHETYPE_RESOURCE', 1);
 /** Assignment module archetype */
 define('MOD_ARCHETYPE_ASSIGNMENT', 2);
+/** System (not user-addable) module archetype */
+define('MOD_ARCHETYPE_SYSTEM', 3);
 
 /**
  * Security token used for allowing access
@@ -1867,6 +1869,7 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0,
     $totalsecs = abs($totalsecs);
 
     if (!$str) {  // Create the str structure the slow way
+        $str = new stdClass();
         $str->day   = get_string('day');
         $str->days  = get_string('days');
         $str->hour  = get_string('hour');
@@ -2215,7 +2218,7 @@ function get_timezone_record($timezonename) {
     }
 
     return $cache[$timezonename] = $DB->get_record_sql('SELECT * FROM {timezone}
-                                                        WHERE name = ? ORDER BY year DESC', array($timezonename), true);
+                                                        WHERE name = ? ORDER BY year DESC', array($timezonename), IGNORE_MULTIPLE);
 }
 
 /**
@@ -3365,7 +3368,7 @@ function get_extra_user_fields($context, $already = array()) {
     }
 
     // Split showuseridentity on comma
-    if ($CFG->showuseridentity === '') {
+    if (empty($CFG->showuseridentity)) {
         // Explode gives wrong result with empty string
         $extra = array();
     } else {
@@ -5025,6 +5028,17 @@ function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $a
         return true;
     }
 
+    if (!validate_email($user->email)) {
+        // we can not send emails to invalid addresses - it might create security issue or confuse the mailer
+        $invalidemail = "User $user->id (".fullname($user).") email ($user->email) is invalid! Not sending.";
+        error_log($invalidemail);
+        if (CLI_SCRIPT) {
+            // do not print this in standard web pages
+            mtrace($invalidemail);
+        }
+        return false;
+    }
+
     if (over_bounce_threshold($user)) {
         $bouncemsg = "User $user->id (".fullname($user).") is over bounce threshold! Not sending.";
         error_log($bouncemsg);
@@ -5238,6 +5252,11 @@ function generate_email_supportuser() {
 function setnew_password_and_mail($user) {
     global $CFG, $DB;
 
+    // we try to send the mail in language the user understands,
+    // unfortunately the filter_string() does not support alternative langs yet
+    // so multilang will not work properly for site->fullname
+    $lang = empty($user->lang) ? $CFG->lang : $user->lang;
+
     $site  = get_site();
 
     $supportuser = generate_email_supportuser();
@@ -5254,9 +5273,9 @@ function setnew_password_and_mail($user) {
     $a->link        = $CFG->wwwroot .'/login/';
     $a->signoff     = generate_email_signoff();
 
-    $message = get_string('newusernewpasswordtext', '', $a);
+    $message = (string)new lang_string('newusernewpasswordtext', '', $a, $lang);
 
-    $subject = format_string($site->fullname) .': '. get_string('newusernewpasswordsubj');
+    $subject = format_string($site->fullname) .': '. (string)new lang_string('newusernewpasswordsubj', '', $a, $lang);
 
     //directly email rather than using the messaging system to ensure its not routed to a popup or jabber
     return email_to_user($user, $supportuser, $subject, $message);
@@ -10053,40 +10072,20 @@ function object_property_exists( $obj, $property ) {
  * Detect a custom script replacement in the data directory that will
  * replace an existing moodle script
  *
- * @param string $urlpath path to the original script
  * @return string|bool full path name if a custom script exists, false if no custom script exists
  */
-function custom_script_path($urlpath='') {
-    global $CFG;
+function custom_script_path() {
+    global $CFG, $SCRIPT;
 
-    // set default $urlpath, if necessary
-    if (empty($urlpath)) {
-        $urlpath = qualified_me(); // e.g. http://www.this-server.com/moodle/this-script.php
-    }
-
-    // $urlpath is invalid if it is empty or does not start with the Moodle wwwroot
-    if (empty($urlpath) or (strpos($urlpath, $CFG->wwwroot) === false )) {
+    if ($SCRIPT === null) {
+        // Probably some weird external script
         return false;
     }
 
-    // replace wwwroot with the path to the customscripts folder and clean path
-    $scriptpath = $CFG->customscripts . clean_param(substr($urlpath, strlen($CFG->wwwroot)), PARAM_PATH);
-
-    // remove the query string, if any
-    if (($strpos = strpos($scriptpath, '?')) !== false) {
-        $scriptpath = substr($scriptpath, 0, $strpos);
-    }
-
-    // remove trailing slashes, if any
-    $scriptpath = rtrim($scriptpath, '/\\');
-
-    // append index.php, if necessary
-    if (is_dir($scriptpath)) {
-        $scriptpath .= '/index.php';
-    }
+    $scriptpath = $CFG->customscripts . $SCRIPT;
 
     // check the custom script exists
-    if (file_exists($scriptpath)) {
+    if (file_exists($scriptpath) and is_file($scriptpath)) {
         return $scriptpath;
     } else {
         return false;
index 22a7f68..4f30b84 100644 (file)
@@ -1707,24 +1707,17 @@ class global_navigation extends navigation_node {
     /**
      * Loads all of the activities for a section into the navigation structure.
      *
-     * @todo 2.2 - $activities should always be an array and we should no longer check for it being a
-     *             course_modinfo object
-     *
      * @param navigation_node $sectionnode
      * @param int $sectionnumber
-     * @param course_modinfo $modinfo Object returned from {@see get_fast_modinfo()}
+     * @param array $activities An array of activites as returned by {@see global_navigation::generate_sections_and_activities()}
+     * @param stdClass $course The course object the section and activities relate to.
      * @return array Array of activity nodes
      */
-    protected function load_section_activities(navigation_node $sectionnode, $sectionnumber, $activities, $course = null) {
+    protected function load_section_activities(navigation_node $sectionnode, $sectionnumber, array $activities, $course = null) {
         global $CFG;
         // A static counter for JS function naming
         static $legacyonclickcounter = 0;
 
-        if ($activities instanceof course_modinfo) {
-            debugging('global_navigation::load_section_activities argument 3 should now recieve an array of activites. See that method for an example.', DEBUG_DEVELOPER);
-            list($sections, $activities) = $this->generate_sections_and_activities($activities->course);
-        }
-
         $activitynodes = array();
         if (empty($activities)) {
             return $activitynodes;
index 9699647..f87c4ac 100644 (file)
@@ -1199,7 +1199,7 @@ class html_writer {
                     $timeunits[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
                 }
                 $userdatetype = 'month';
-                $currentdate['month'] = $currentdate['mon'];
+                $currentdate['month'] = (int)$currentdate['mon'];
                 break;
             case 'days':
                 for ($i=1; $i<=31; $i++) {
index 0e31bdd..56fbe20 100644 (file)
@@ -132,7 +132,7 @@ class page_requirements_manager {
             $this->yui3loader->filter = null;
             $this->yui2loader->filter = null;
         }
-        if (!empty($CFG->useexternalyui)) {
+        if (!empty($CFG->useexternalyui) and strpos($CFG->httpswwwroot, 'https:') !== 0) {
             $this->yui3loader->base = 'http://yui.yahooapis.com/' . $CFG->yui3version . '/build/';
             $this->yui2loader->base = 'http://yui.yahooapis.com/' . $CFG->yui2version . '/build/';
             $this->yui3loader->comboBase = 'http://yui.yahooapis.com/combo?';
index c981d09..22f4544 100644 (file)
@@ -353,7 +353,7 @@ class portfolio_add_button {
                 $formoutput .= "\n" . '</form>';
             break;
             case PORTFOLIO_ADD_ICON_LINK:
-                $linkoutput .= '"><img class="portfolio-add-icon" src="' . $OUTPUT->pix_url('t/portfolioadd') . '" alt="' . $addstr .'" /></a>';
+                $linkoutput .= '"><img class="portfolio-add-icon iconsmall" src="' . $OUTPUT->pix_url('t/portfolioadd') . '" alt="' . $addstr .'" /></a>';
             break;
             case PORTFOLIO_ADD_TEXT_LINK:
                 $linkoutput .= '">' . $addstr .'</a>';
index ea5f4a3..614682c 100644 (file)
@@ -291,6 +291,7 @@ class grade_test extends UnitTestCaseUsingDatabase {
         global $DB;
         $course_module = new stdClass();
         $course_module->course = $this->courseid;
+        $quiz = new stdClass();
         $quiz->module = 1;
         $quiz->instance = 2;
         $course_module->id = $DB->insert_record('course_modules', $course_module);
index c78063b..1496494 100644 (file)
@@ -46,11 +46,11 @@ class fake_recordset implements Iterator {
     }
 
     function close() {
-        $closed=true;
+        $this->closed=true;
     }
 
     function was_closed() {
-        return $closed;
+        return $this->closed;
     }
 }
 
diff --git a/lib/simpletest/testcsslib.php b/lib/simpletest/testcsslib.php
new file mode 100644 (file)
index 0000000..b69a8a5
--- /dev/null
@@ -0,0 +1,706 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file contains the unittests for the css optimiser in csslib.php
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+if (!defined('MOODLE_INTERNAL')) {
+    die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
+}
+require_once($CFG->libdir . '/csslib.php');
+
+
+/**
+ * CSS optimiser test class
+ *
+ * @package core_css
+ * @category css
+ * @copyright 2012 Sam Hemelryk
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class css_optimiser_test extends UnitTestCase {
+
+    /**
+     * Sets up the test class
+     */
+    public function setUp() {
+        global $CFG;
+        parent::setUp();
+        // We need to disable these if they are enabled to that we can predict
+        // the output.
+        $CFG->cssoptimiserstats = false;
+        $CFG->cssoptimiserpretty = false;
+    }
+
+    /**
+     * Test the process method
+     */
+    public function test_process() {
+        $optimiser = new css_optimiser;
+
+        $this->check_background($optimiser);
+        $this->check_borders($optimiser);
+        $this->check_colors($optimiser);
+        $this->check_margins($optimiser);
+        $this->check_padding($optimiser);
+        $this->check_widths($optimiser);
+
+        $this->try_broken_css_found_in_moodle($optimiser);
+        $this->try_invalid_css_handling($optimiser);
+        $this->try_bulk_processing($optimiser);
+        $this->try_break_things($optimiser);
+    }
+
+    /**
+     * Background colour tests
+     * @param css_optimiser $optimiser
+     */
+    protected function check_background(css_optimiser $optimiser) {
+
+        $cssin = '.test {background-color: #123456;}';
+        $cssout = '.test{background:#123456;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {background-image: url(\'test.png\');}';
+        $cssout = '.test{background-image:url(\'test.png\');}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {background: #123456 url(\'test.png\') no-repeat top left;}';
+        $cssout = '.test{background:#123456 url(\'test.png\') no-repeat top left;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {background: url(\'test.png\') no-repeat top left;}.test{background-position: bottom right}.test {background-color:#123456;}';
+        $cssout = '.test{background:#123456 url(\'test.png\') no-repeat bottom right;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {background: url(   \'test.png\'    )}.test{background: bottom right}.test {background:#123456;}';
+        $cssout = '.test{background-image:url(\'test.png\');background-position:bottom right;background-color:#123456;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {background-color: #123456;background-repeat: repeat-x; background-position: 100% 0%;}';
+        $cssout = '.test{background-color:#123456;background-repeat:repeat-x;background-position:100% 0%;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.tree_item.branch {background-image: url([[pix:t/expanded]]);background-position: 0 10%;background-repeat: no-repeat;}
+                  .tree_item.branch.navigation_node {background-image:none;padding-left:0;}';
+        $cssout = '.tree_item.branch{background:url([[pix:t/expanded]]) no-repeat 0 10%;} .tree_item.branch.navigation_node{background-image:none;padding-left:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.block_tree .tree_item.emptybranch {background-image: url([[pix:t/collapsed_empty]]);background-position: 0% 5%;background-repeat: no-repeat;}
+                  .block_tree .collapsed .tree_item.branch {background-image: url([[pix:t/collapsed]]);}';
+        $cssout = '.block_tree .tree_item.emptybranch{background:url([[pix:t/collapsed_empty]]) no-repeat 0% 5%;} .block_tree .collapsed .tree_item.branch{background-image:url([[pix:t/collapsed]]);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * Border tests
+     * @param css_optimiser $optimiser
+     */
+    protected function check_borders(css_optimiser $optimiser) {
+        $cssin = '.test {border: 1px solid #654321} .test {border-bottom-color: #123456}';
+        $cssout = '.test{border:1px solid;border-color:#654321 #654321 #123456;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {border:1px solid red;}';
+        $cssout = '.one{border:1px solid #FF0000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {border:1px solid;} .one {border:2px dotted #DDD;}';
+        $cssout = '.one{border:2px dotted #DDDDDD;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {border:2px dotted #DDD;}.one {border:1px solid;} ';
+        $cssout = '.one{border:1px solid #DDDDDD;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one, .two {border:1px solid red;}';
+        $cssout = ".one, .two{border:1px solid #FF0000;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one, .two {border:0px;}';
+        $cssout = ".one, .two{border-width:0;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one, .two {border-top: 5px solid white;}';
+        $cssout = ".one, .two{border-top:5px solid #FFFFFF;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {border:1px solid red;} .two {border:1px solid red;}';
+        $cssout = ".one, .two{border:1px solid #FF0000;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {border:1px solid red;width:20px;} .two {border:1px solid red;height:20px;}';
+        $cssout = ".one{width:20px;border:1px solid #FF0000;} .two{height:20px;border:1px solid #FF0000;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border: 1px solid #123456;} .test {border-color: #654321}';
+        $cssout = '.test{border:1px solid #654321;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border-width: 1px; border-style: solid; border-color: #123456;}';
+        $cssout = '.test{border:1px solid #123456;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border:1px solid #123456;border-top:2px dotted #654321;}';
+        $cssout = '.test{border:1px solid #123456;border-top:2px dotted #654321;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border:1px solid #123456;border-left:2px dotted #654321;}';
+        $cssout = '.test{border:1px solid #123456;border-left:2px dotted #654321;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border-left:2px dotted #654321;border:1px solid #123456;}';
+        $cssout = '.test{border:1px solid #123456;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border:1px solid;border-top-color:#123456;}';
+        $cssout = '.test{border:1px solid;border-top-color:#123456;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border:1px solid;border-top-color:#111; border-bottom-color: #222;border-left-color: #333;}';
+        $cssout = '.test{border:1px solid;border-top-color:#111;border-bottom-color:#222;border-left-color:#333;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.test {border:1px solid;border-top-color:#111; border-bottom-color: #222;border-left-color: #333;border-right-color:#444;}';
+        $cssout = '.test{border:1px solid;border-color:#111 #444 #222 #333;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.generaltable .cell {border-color:#EEEEEE;} .generaltable .cell {border-width: 1px;border-style: solid;}';
+        $cssout = '.generaltable .cell{border:1px solid #EEEEEE;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '#page-admin-roles-override .rolecap {border:none;border-bottom:1px solid #CECECE;}';
+        $cssout = '#page-admin-roles-override .rolecap{border-top:0;border-right:0;border-bottom:1px solid #CECECE;border-left:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * Test colour styles
+     * @param css_optimiser $optimiser
+     */
+    protected function check_colors(css_optimiser $optimiser) {
+        $css = '.css{}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = '.css{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = '#some{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div.css{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div#some{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div[type=blah]{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div.css[type=blah]{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div#some[type=blah]{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = '#some.css[type=blah]{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = '#some .css[type=blah]{color:#123456;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $cssin = '.one {color:red;} .two {color:#F00;}';
+        $cssout = ".one, .two{color:#F00;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:#123;color:#321;}';
+        $cssout = '.one{color:#321;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:#123; color : #321 ;}';
+        $cssout = '.one{color:#321;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:#123;} .one {color:#321;}';
+        $cssout = '.one{color:#321;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:#123 !important;color:#321;}';
+        $cssout = '.one{color:#123 !important;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:#123 !important;} .one {color:#321;}';
+        $cssout = '.one{color:#123 !important;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:rgb(255, 128, 1)}';
+        $cssout = '.one{color:rgb(255, 128, 1);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:rgba(255, 128, 1, 0.5)}';
+        $cssout = '.one{color:rgba(255, 128, 1, 0.5);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:hsl(120, 65%, 75%)}';
+        $cssout = '.one{color:hsl(120, 65%, 75%);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {color:hsla(120,65%,75%,0.5)}';
+        $cssout = '.one{color:hsla(120,65%,75%,0.5);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Try some invalid colours to make sure we don't mangle them.
+        $css = 'div#some{color:#1;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div#some{color:#12;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div#some{color:#1234;}';
+        $this->assertEqual($css, $optimiser->process($css));
+
+        $css = 'div#some{color:#12345;}';
+        $this->assertEqual($css, $optimiser->process($css));
+    }
+
+    protected function check_widths(css_optimiser $optimiser) {
+        $cssin  = '.css {width:0}';
+        $cssout = '.css{width:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '.css {width:0px}';
+        $cssout = '.css{width:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '.css {width:0em}';
+        $cssout = '.css{width:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '.css {width:0pt}';
+        $cssout = '.css{width:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '.css {width:0mm}';
+        $cssout = '.css{width:0;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '.css {width:100px}';
+        $cssout = '.css{width:100px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * Test margin styles
+     * @param css_optimiser $optimiser
+     */
+    protected function check_margins(css_optimiser $optimiser) {
+        $cssin = '.one {margin: 1px 2px 3px 4px}';
+        $cssout = '.one{margin:1px 2px 3px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin-top:1px; margin-left:4px; margin-right:2px; margin-bottom: 3px;}';
+        $cssout = '.one{margin:1px 2px 3px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin-top:1px; margin-left:4px;}';
+        $cssout = '.one{margin-top:1px;margin-left:4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin:1px; margin-left:4px;}';
+        $cssout = '.one{margin:1px 1px 1px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin:1px; margin-bottom:4px;}';
+        $cssout = '.one{margin:1px 1px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one, .two, .one.two, .one .two {margin:0;} .one.two {margin:0 7px;}';
+        $cssout = '.one, .two, .one .two{margin:0;} .one.two{margin:0 7px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * Test padding styles
+     *
+     * @param css_optimiser $optimiser
+     */
+    protected function check_padding(css_optimiser $optimiser) {
+        $cssin = '.one {margin: 1px 2px 3px 4px}';
+        $cssout = '.one{margin:1px 2px 3px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin-top:1px; margin-left:4px; margin-right:2px; margin-bottom: 3px;}';
+        $cssout = '.one{margin:1px 2px 3px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin-top:1px; margin-left:4px;}';
+        $cssout = '.one{margin-top:1px;margin-left:4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin:1px; margin-left:4px;}';
+        $cssout = '.one{margin:1px 1px 1px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin:1px; margin-bottom:4px;}';
+        $cssout = '.one{margin:1px 1px 4px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {margin:0 !important;}';
+        $cssout = '.one{margin:0 !important;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {padding:0 !important;}';
+        $cssout = '.one{padding:0 !important;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one, .two, .one.two, .one .two {margin:0;} .one.two {margin:0 7px;}';
+        $cssout = '.one, .two, .one .two{margin:0;} .one.two{margin:0 7px;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * Test some totally invalid CSS optimisation
+     *
+     * @param css_optimiser $optimiser
+     */
+    protected function try_invalid_css_handling(css_optimiser $optimiser) {
+
+        $cssin = array(
+            '.one{}',
+            '.one {:}',
+            '.one {;}',
+            '.one {;;;;;}',
+            '.one {:;}',
+            '.one {:;:;:;:::;;;}',
+            '.one {!important}',
+            '.one {:!important}',
+            '.one {:!important;}',
+            '.one {;!important}'
+        );
+        $cssout = '.one{}';
+        foreach ($cssin as $css) {
+            $this->assertEqual($cssout, $optimiser->process($css));
+        }
+
+        $cssin = array(
+            '.one{background-color:red;}',
+            '.one {background-color:red;} .one {background-color:}',
+            '.one {background-color:red;} .one {background-color;}',
+            '.one {background-color:red;} .one {background-color}',
+            '.one {background-color:red;} .one {background-color:;}',
+            '.one {background-color:red;} .one {:blue;}',
+            '.one {background-color:red;} .one {:#00F}',
+        );
+        $cssout = '.one{background:#F00;}';
+        foreach ($cssin as $css) {
+            $this->assertEqual($cssout, $optimiser->process($css));
+        }
+
+        $cssin = '..one {background-color:color:red}';
+        $cssout = '..one{background-color:color:red;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '#.one {background-color:color:red}';
+        $cssout = '#.one{background-color:color:red;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '##one {background-color:color:red}';
+        $cssout = '##one{background-color:color:red;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {background-color:color:red}';
+        $cssout = '.one{background-color:color:red;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin = '.one {background-color:red;color;border-color:blue}';
+        $cssout = '.one{background:#F00;border-color:#00F;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '{background-color:#123456;color:red;}{color:green;}';
+        $cssout = "{color:#008000;background:#123456;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        $cssin  = '.one {color:red;} {color:green;} .one {background-color:blue;}';
+        $cssout = ".one{color:#F00;background:#00F;} {color:#008000;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * Try to break some things
+     * @param css_optimiser $optimiser
+     */
+    protected function try_break_things(css_optimiser $optimiser) {
+        // Wildcard test
+        $cssin  = '* {color: black;}';
+        $cssout = '*{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Wildcard test
+        $cssin  = '.one * {color: black;}';
+        $cssout = '.one *{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Wildcard test
+        $cssin  = '* .one * {color: black;}';
+        $cssout = '* .one *{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Wildcard test
+        $cssin  = '*,* {color: black;}';
+        $cssout = '*{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Wildcard test
+        $cssin  = '*, * .one {color: black;}';
+        $cssout = "*,\n* .one{color:#000;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Wildcard test
+        $cssin  = '*, *.one {color: black;}';
+        $cssout = "*,\n*.one{color:#000;}";
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Psedo test
+        $cssin  = '.one:before {color: black;}';
+        $cssout = '.one:before{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Psedo test
+        $cssin  = '.one:after {color: black;}';
+        $cssout = '.one:after{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Psedo test
+        $cssin  = '.one:onclick {color: black;}';
+        $cssout = '.one:onclick{color:#000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Test complex CSS rules that don't really exist but mimic other CSS rules
+        $cssin  = '.one {master-of-destruction: explode(\' \', "What madness";}';
+        $cssout = '.one{master-of-destruction:explode(\' \', "What madness";}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Test some complex IE css... I couldn't even think of a more complext solution
+        // than the CSS they came up with.
+        $cssin  = 'a { opacity: 0.5; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; filter: alpha(opacity=50); }';
+        $cssout = 'a{opacity:0.5;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";filter:alpha(opacity=50);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+
+    /**
+     * A bulk processing test
+     * @param css_optimiser $optimiser
+     */
+    protected function try_bulk_processing(css_optimiser $optimiser) {
+        global $CFG;
+        $cssin = <<<CSS
+.test .one {
+    margin:5px;
+    border:0;
+}
+.test .one {
+    margin: 10px;
+    color: red;
+}
+
+.test.one {
+    margin: 15px;
+}
+
+#test .one {margin:  20px;}
+#test #one {margin:  25px;}.test #one {margin:  30px;}
+  .test    .one      {     background-color: #123;     }
+.test.one{border:1px solid blue}.test.one{border-color:green;}
+
+@media print {
+    #test .one {margin: 35px;}
+}
+
+@media print {
+    #test .one {margin: 40px;color: #123456;}
+    #test #one {margin: 45px;}
+}
+
+@media print,screen {
+    #test .one {color: #654321;}
+}
+
+#test .one,
+#new.style {color:#000;}
+CSS;
+
+        $cssout = <<<CSS
+.test .one{color:#F00;margin:10px;border-width:0;background:#123;}
+.test.one{margin:15px;border:1px solid #008000;}
+#test .one{color:#000;margin:20px;}
+#test #one{margin:25px;}
+.test #one{margin:30px;}
+#new.style{color:#000;}
+
+
+@media print {
+  #test .one{color:#123456;margin:40px;}
+  #test #one{margin:45px;}
+}
+
+@media print,screen {
+  #test .one{color:#654321;}
+}
+CSS;
+        $CFG->cssoptimiserpretty = 1;
+        $this->assertEqual($optimiser->process($cssin), $cssout);
+    }
+
+    /**
+     * Test CSS colour matching
+     */
+    public function test_css_is_colour() {
+        // First lets test hex colours
+        $this->assertTrue(css_is_colour('#123456'));
+        $this->assertTrue(css_is_colour('#123'));
+        $this->assertTrue(css_is_colour('#ABCDEF'));
+        $this->assertTrue(css_is_colour('#ABC'));
+        $this->assertTrue(css_is_colour('#abcdef'));
+        $this->assertTrue(css_is_colour('#abc'));
+        $this->assertTrue(css_is_colour('#aBcDeF'));
+        $this->assertTrue(css_is_colour('#aBc'));
+        $this->assertTrue(css_is_colour('#1a2Bc3'));
+        $this->assertTrue(css_is_colour('#1Ac'));
+
+        // Note the following two colour's arn't really colours but browsers process
+        // them still.
+        $this->assertTrue(css_is_colour('#A'));
+        $this->assertTrue(css_is_colour('#12'));
+        // Having four or five characters however are not valid colours and
+        // browsers don't parse them. They need to fail so that broken CSS
+        // stays broken after optimisation.
+        $this->assertFalse(css_is_colour('#1234'));
+        $this->assertFalse(css_is_colour('#12345'));
+
+        $this->assertFalse(css_is_colour('#BCDEFG'));
+        $this->assertFalse(css_is_colour('#'));
+        $this->assertFalse(css_is_colour('#0000000'));
+        $this->assertFalse(css_is_colour('#132-245'));
+        $this->assertFalse(css_is_colour('#13 23 43'));
+        $this->assertFalse(css_is_colour('123456'));
+
+        // Next lets test real browser mapped colours
+        $this->assertTrue(css_is_colour('black'));
+        $this->assertTrue(css_is_colour('blue'));
+        $this->assertTrue(css_is_colour('BLACK'));
+        $this->assertTrue(css_is_colour('Black'));
+        $this->assertTrue(css_is_colour('bLACK'));
+        $this->assertTrue(css_is_colour('mediumaquamarine'));
+        $this->assertTrue(css_is_colour('mediumAquamarine'));
+        $this->assertFalse(css_is_colour('monkey'));
+        $this->assertFalse(css_is_colour(''));
+        $this->assertFalse(css_is_colour('not a colour'));
+
+        // Next lets test rgb(a) colours
+        $this->assertTrue(css_is_colour('rgb(255,255,255)'));
+        $this->assertTrue(css_is_colour('rgb(0, 0, 0)'));
+        $this->assertTrue(css_is_colour('RGB (255, 255   ,    255)'));
+        $this->assertTrue(css_is_colour('rgba(0,0,0,0)'));
+        $this->assertTrue(css_is_colour('RGBA(255,255,255,1)'));
+        $this->assertTrue(css_is_colour('rgbA(255,255,255,0.5)'));
+        $this->assertFalse(css_is_colour('rgb(-255,-255,-255)'));
+        $this->assertFalse(css_is_colour('rgb(256,-256,256)'));
+
+        // Now lets test HSL colours
+        $this->assertTrue(css_is_colour('hsl(0,0%,100%)'));
+        $this->assertTrue(css_is_colour('hsl(180, 0%, 10%)'));
+        $this->assertTrue(css_is_colour('hsl (360, 100%   ,    95%)'));
+
+        // Finally test the special values
+        $this->assertTrue(css_is_colour('inherit'));
+    }
+
+    /**
+     * Test the css_is_width function
+     */
+    public function test_css_is_width() {
+
+        $this->assertTrue(css_is_width('0'));
+        $this->assertTrue(css_is_width('0px'));
+        $this->assertTrue(css_is_width('0em'));
+        $this->assertTrue(css_is_width('199px'));
+        $this->assertTrue(css_is_width('199em'));
+        $this->assertTrue(css_is_width('199%'));
+        $this->assertTrue(css_is_width('-1'));
+        $this->assertTrue(css_is_width('-1px'));
+        $this->assertTrue(css_is_width('auto'));
+        $this->assertTrue(css_is_width('inherit'));
+
+        $this->assertFalse(css_is_width('-'));
+        $this->assertFalse(css_is_width('bananas'));
+        $this->assertFalse(css_is_width(''));
+        $this->assertFalse(css_is_width('top'));
+    }
+
+    /**
+     * This function tests some of the broken crazy CSS we have in Moodle.
+     * For each of these things the value needs to be corrected if we can be 100%
+     * certain what is going wrong, Or it needs to be left as is.
+     *
+     * @param css_optimiser $optimiser
+     */
+    public function try_broken_css_found_in_moodle(css_optimiser $optimiser) {
+        // Notice how things are out of order here but that they get corrected
+        $cssin = '.test {background:url([[pix:theme|pageheaderbgred]]) top center no-repeat}';
+        $cssout = '.test{background:url([[pix:theme|pageheaderbgred]]) no-repeat top center;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Cursor hand isn't valid
+        $cssin  = '.test {cursor: hand;}';
+        $cssout = '.test{cursor:hand;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Zoom property isn't valid
+        $cssin  = '.test {zoom: 1;}';
+        $cssout = '.test{zoom:1;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Left isn't a valid position property
+        $cssin  = '.test {position: left;}';
+        $cssout = '.test{position:left;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // The dark red color isn't a valid HTML color but has a standardised
+        // translation of #8B0000
+        $cssin  = '.test {color: darkred;}';
+        $cssout = '.test{color:#8B0000;}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // You can't use argb colours as border colors
+        $cssin  = '.test {border-bottom: 1px solid rgba(0,0,0,0.25);}';
+        $cssout = '.test{border-bottom:1px solid rgba(0,0,0,0.25);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+
+        // Opacity with annoying IE equivilants....
+        $cssin  = '.test {opacity: 0.5; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; filter: alpha(opacity=50);}';
+        $cssout = '.test{opacity:0.5;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";filter:alpha(opacity=50);}';
+        $this->assertEqual($cssout, $optimiser->process($cssin));
+    }
+}
\ No newline at end of file
index 63d174a..379fc11 100644 (file)
@@ -747,7 +747,7 @@ class filter_delete_config_test extends UnitTestCaseUsingDatabase {
         $expectedconfig = new stdClass;
         $expectedconfig->configname = 'Other config value';
         $this->assertEqual($expectedconfig, get_config('filter_other'));
-        $this->assertFalse(get_config('filter_name'));
+        $this->assertNull(get_config('filter_name'));
     }
 
     public function test_filter_delete_all_for_context() {
@@ -785,6 +785,7 @@ class filter_filter_set_applies_to_strings extends UnitTestCaseUsingDatabase {
     }
 
     public function tearDown() {
+        global $CFG;
         $CFG->stringfilters = $this->origcfgstringfilters;
         $CFG->filterall = $this->origcfgfilterall;
 
index 09f1458..2b86475 100644 (file)
@@ -83,6 +83,8 @@ class textlib_test extends UnitTestCase {
 
     public function test_substr() {
         $str = "Žluťoučký koníček";
+        $this->assertIdentical(textlib::substr($str, 0), $str);
+        $this->assertIdentical(textlib::substr($str, 1), 'luťoučký koníček');
         $this->assertIdentical(textlib::substr($str, 1, 3), 'luť');
         $this->assertIdentical(textlib::substr($str, 0, 100), $str);
         $this->assertIdentical(textlib::substr($str, -3, 2), 'če');
index 35caaca..bdcdd55 100644 (file)
@@ -127,6 +127,15 @@ class web_test extends UnitTestCase {
         $this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
     }
 
+    function test_out_as_local_url() {
+        $url1 = new moodle_url('/lib/simpletest/testweblib.php');
+        $this->assertEqual('/lib/simpletest/testweblib.php', $url1->out_as_local_url());
+
+        $url2 = new moodle_url('http://www.google.com/lib/simpletest/testweblib.php');
+        $this->expectException('coding_exception');
+        $url2->out_as_local_url();
+    }
+
     public function test_html_to_text_simple() {
         $this->assertEqual("\n\n_Hello_ WORLD!", html_to_text('<p><i>Hello</i> <b>world</b>!</p>'));
     }
index 558be5c..9702738 100644 (file)
@@ -182,7 +182,7 @@ class textlib {
     }
 
     /**
-     * Multibyte safe substr() function, uses iconv for utf-8, falls back to typo3.
+     * Multibyte safe substr() function, uses mbstring or iconv for UTF-8, falls back to typo3.
      *
      * @param string $text
      * @param int $start negative value means from end
@@ -194,18 +194,39 @@ class textlib {
         $charset = self::parse_charset($charset);
 
         if ($charset === 'utf-8') {
-            return iconv_substr($text, $start, $len, $charset);
+            if (function_exists('mb_substr')) {
+                // this is much faster than iconv - see MDL-31142
+                if ($len === null) {
+                    $oldcharset = mb_internal_encoding();
+                    mb_internal_encoding('UTF-8');
+                    $result = mb_substr($text, $start);
+                    mb_internal_encoding($oldcharset);
+                    return $result;
+                } else {
+                    return mb_substr($text, $start, $len, 'UTF-8');
+                }
+
+            } else {
+                if ($len === null) {
+                    $len = iconv_strlen($text, 'UTF-8');
+                }
+                return iconv_substr($text, $start, $len, 'UTF-8');
+            }
         }
 
         $oldlevel = error_reporting(E_PARSE);
-        $result = self::typo3()->substr($charset, $text, $start, $len);
+        if ($len === null) {
+            $result = self::typo3()->substr($charset, $text, $start);
+        } else {
+            $result = self::typo3()->substr($charset, $text, $start, $len);
+        }
         error_reporting($oldlevel);
 
         return $result;
     }
 
     /**
-     * Multibyte safe strlen() function, uses iconv for utf-8, falls back to typo3.
+     * Multibyte safe strlen() function, uses mbstring or iconv for UTF-8, falls back to typo3.
      *
      * @param string $text
      * @param string $charset encoding of the text
@@ -215,7 +236,11 @@ class textlib {
         $charset = self::parse_charset($charset);
 
         if ($charset === 'utf-8') {
-            return iconv_strlen($text, $charset);
+            if (function_exists('mb_strlen')) {
+                return mb_strlen($text, 'UTF-8');
+            } else {
+                return iconv_strlen($text, 'UTF-8');
+            }
         }
 
         $oldlevel = error_reporting(E_PARSE);
@@ -236,7 +261,7 @@ class textlib {
         $charset = self::parse_charset($charset);
 
         if ($charset === 'utf-8' and function_exists('mb_strtolower')) {
-            return mb_strtolower($text, $charset);
+            return mb_strtolower($text, 'UTF-8');
         }
 
         $oldlevel = error_reporting(E_PARSE);
@@ -257,7 +282,7 @@ class textlib {
         $charset = self::parse_charset($charset);
 
         if ($charset === 'utf-8' and function_exists('mb_strtoupper')) {
-            return mb_strtoupper($text, $charset);
+            return mb_strtoupper($text, 'UTF-8');
         }
 
         $oldlevel = error_reporting(E_PARSE);
@@ -268,7 +293,7 @@ class textlib {
     }
 
     /**
-     * UTF-8 ONLY safe strpos(), uses iconv..
+     * UTF-8 ONLY safe strpos(), uses mbstring, falls back to iconv.
      *
      * @param string $haystack
      * @param string $needle
@@ -276,18 +301,26 @@ class textlib {
      * @return string
      */
     public static function strpos($haystack, $needle, $offset=0) {
-        return iconv_strpos($haystack, $needle, $offset, 'utf-8');
+        if (function_exists('mb_strpos')) {
+            return mb_strpos($haystack, $needle, $offset, 'UTF-8');
+        } else {
+            return iconv_strpos($haystack, $needle, $offset, 'UTF-8');
+        }
     }
 
     /**
-     * UTF-8 ONLY safe strrpos(), uses iconv.
+     * UTF-8 ONLY safe strrpos(), uses mbstring, falls back to iconv.
      *
      * @param string $haystack
      * @param string $needle
      * @return string
      */
     public static function strrpos($haystack, $needle) {
-        return iconv_strrpos($haystack, $needle, 'utf-8');
+        if (function_exists('mb_strpos')) {
+            return mb_strrpos($haystack, $needle, null, 'UTF-8');
+        } else {
+            return iconv_strrpos($haystack, $needle, 'UTF-8');
+        }
     }
 
     /**
index 01df2c7..6818d2d 100644 (file)
@@ -103,2099 +103,2152 @@ id,name,year,tzrule,gmtoff,dstoff,dst_month,dst_startday,dst_weekday,dst_skipwee
 102,Africa/Khartoum,1972,Sudan,120,60,4,-1,0,0,02:00,10,15,-1,0,01:00
 103,Africa/Khartoum,1985,Sudan,120,0,4,-1,0,0,02:00,10,15,-1,0,01:00
 104,Africa/Khartoum,2000,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-105,Africa/Mbabane,1970,,120,0,0,0,0,0,00:00,0,0,0,0,00:00
-106,Africa/Dar_es_Salaam,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-107,Africa/Lome,1970,,0,0,0,0,0,0,00:00,0,0,0,0,00:00
-108,Africa/Tunis,1970,Tunisia,60,60,4,1,1,0,03:00,9,16,-1,0,00:00
-109,Africa/Tunis,1977,Tunisia,60,60,4,30,-1,0,01:00,9,24,-1,0,01:00
-110,Africa/Tunis,1978,Tunisia,60,60,5,1,-1,0,01:00,10,1,-1,0,01:00
-111,Africa/Tunis,1988,Tunisia,60,60,6,1,-1,0,01:00,9,-1,0,0,01:00
-112,Africa/Tunis,1989,Tunisia,60,60,3,26,-1,0,01:00,9,-1,0,0,01:00
-113,Africa/Tunis,1990,Tunisia,60,60,5,1,-1,0,01:00,9,-1,0,0,01:00
-114,Africa/Tunis,2005,Tunisia,60,60,5,1,-1,0,01:00,9,30,-1,0,02:00
-115,Africa/Tunis,2006,Tunisia,60,60,3,-1,0,0,03:00,10,-1,0,0,03:00
-116,Africa/Tunis,2008,Tunisia,60,0,3,-1,0,0,03:00,10,-1,0,0,03:00
-117,Africa/Kampala,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-118,Africa/Lusaka,1970,,120,0,0,0,0,0,00:00,0,0,0,0,00:00
-119,Africa/Harare,1970,,120,0,0,0,0,0,00:00,0,0,0,0,00:00
-120,Antarctica/Casey,1970,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-121,Antarctica/Casey,2009,,660,0,0,0,0,0,00:00,0,0,0,0,00:00
-122,Antarctica/Casey,2010,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-123,Antarctica/Davis,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-124,Antarctica/Davis,2009,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-125,Antarctica/Davis,2010,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-126,Antarctica/Mawson,1970,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-127,Antarctica/Mawson,2009,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-128,Antarctica/Macquarie,1970,ATAQ,600,60,10,-1,0,0,12:00,3,8,0,0,12:00
-129,Antarctica/Macquarie,1972,ATAQ,600,60,10,-1,0,0,12:00,2,-1,0,0,12:00
-130,Antarctica/Macquarie,1973,ATAQ,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-131,Antarctica/Macquarie,1982,ATAQ,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-132,Antarctica/Macquarie,1984,ATAQ,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-133,Antarctica/Macquarie,1986,ATAQ,600,60,10,15,0,0,12:00,3,1,0,0,12:00
-134,Antarctica/Macquarie,1987,ATAQ,600,60,10,22,0,0,12:00,3,15,0,0,12:00
-135,Antarctica/Macquarie,1988,ATAQ,600,60,10,-1,0,0,12:00,3,15,0,0,12:00
-136,Antarctica/Macquarie,1991,ATAQ,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-137,Antarctica/Macquarie,2000,ATAQ,600,60,8,-1,0,0,12:00,3,-1,0,0,12:00
-138,Antarctica/Macquarie,2001,ATAQ,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-139,Antarctica/Macquarie,2006,ATAQ,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-140,Antarctica/Macquarie,2007,ATAQ,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-141,Antarctica/Macquarie,2008,ATAQ,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-142,Antarctica/Macquarie,2010,,660,0,0,0,0,0,00:00,0,0,0,0,00:00
-143,Indian/Kerguelen,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-144,Antarctica/DumontDUrville,1970,,600,0,0,0,0,0,00:00,0,0,0,0,00:00
-145,Antarctica/Syowa,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-146,Antarctica/Vostok,1970,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-147,Antarctica/Rothera,1970,,0,0,0,0,0,0,00:00,0,0,0,0,00:00
-148,Antarctica/Rothera,1976,,-180,0,0,0,0,0,00:00,0,0,0,0,00:00
-149,Antarctica/Palmer,1970,ArgAQ,-180,0,12,31,-1,0,09:00,4,1,0,0,-4:00
-150,Antarctica/Palmer,1974,ArgAQ,-180,60,1,23,-1,0,-3:00,5,1,-1,0,-4:00
-151,Antarctica/Palmer,1975,ArgAQ,-180,0,1,23,-1,0,-3:00,5,1,-1,0,-4:00
-152,Antarctica/Palmer,1982,ChileAQ,-240,60,10,9,0,0,4:00,3,9,0,0,3:00
-153,Antarctica/Palmer,1987,ChileAQ,-240,60,10,9,0,0,4:00,4,12,-1,0,3:00
-154,Antarctica/Palmer,1988,ChileAQ,-240,60,10,1,0,0,4:00,3,9,0,0,3:00
-155,Antarctica/Palmer,1989,ChileAQ,-240,60,10,9,0,0,4:00,3,9,0,0,3:00
-156,Antarctica/Palmer,1990,ChileAQ,-240,60,9,16,-1,0,4:00,3,18,-1,0,3:00
-157,Antarctica/Palmer,1991,ChileAQ,-240,60,10,9,0,0,4:00,3,9,0,0,3:00
-158,Antarctica/Palmer,1997,ChileAQ,-240,60,10,9,0,0,4:00,3,30,-1,0,3:00
-159,Antarctica/Palmer,1998,ChileAQ,-240,60,9,27,-1,0,4:00,3,9,0,0,3:00
-160,Antarctica/Palmer,1999,ChileAQ,-240,60,10,9,0,0,4:00,4,4,-1,0,3:00
-161,Antarctica/Palmer,2000,ChileAQ,-240,60,10,9,0,0,4:00,3,9,0,0,3:00
-162,Antarctica/McMurdo,1970,NZAQ,720,0,0,0,0,0,00:00,0,0,0,0,00:00
-163,Antarctica/McMurdo,1974,NZAQ,720,60,11,3,-1,0,14:00,1,1,-1,0,23:00
-164,Antarctica/McMurdo,1975,NZAQ,720,60,10,-1,0,0,14:00,2,23,-1,0,14:00
-165,Antarctica/McMurdo,1976,NZAQ,720,60,10,-1,0,0,14:00,3,1,0,0,14:00
-166,Antarctica/McMurdo,1989,NZAQ,720,60,10,8,-1,0,14:00,3,1,0,0,14:00
-167,Antarctica/McMurdo,1990,NZAQ,720,60,10,1,0,0,14:00,3,15,0,0,14:00
-168,Antarctica/McMurdo,2007,NZAQ,720,60,9,-1,0,0,14:00,3,15,0,0,14:00
-169,Antarctica/McMurdo,2008,NZAQ,720,60,9,-1,0,0,14:00,4,1,0,0,14:00
-170,Asia/Kabul,1970,,270,0,0,0,0,0,00:00,0,0,0,0,00:00
-171,Asia/Yerevan,1970,RussiaAsia,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-172,Asia/Yerevan,1981,RussiaAsia,240,60,4,1,-1,0,04:00,10,1,-1,0,03:00
-173,Asia/Yerevan,1984,RussiaAsia,240,60,4,1,-1,0,04:00,9,-1,0,0,06:00
-174,Asia/Yerevan,1985,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-175,Asia/Yerevan,1991,RussiaAsia,180,60,3,-1,0,0,05:00,9,-1,0,0,05:00
-176,Asia/Yerevan,1992,RussiaAsia,180,60,3,-1,6,0,26:00,9,-1,6,0,25:00
-177,Asia/Yerevan,1993,RussiaAsia,180,60,3,-1,0,0,05:00,9,-1,0,0,05:00
-178,Asia/Yerevan,1995,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-179,Asia/Yerevan,1997,RussiaAsia,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-180,Asia/Baku,1970,RussiaAsia,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-181,Asia/Baku,1981,RussiaAsia,240,60,4,1,-1,0,04:00,10,1,-1,0,03:00
-182,Asia/Baku,1984,RussiaAsia,240,60,4,1,-1,0,04:00,9,-1,0,0,06:00
-183,Asia/Baku,1985,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-184,Asia/Baku,1991,RussiaAsia,180,60,3,-1,0,0,05:00,9,-1,0,0,05:00
-185,Asia/Baku,1992,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-186,Asia/Baku,1996,EUAsia,240,60,3,-1,0,0,1:00,10,-1,0,0,1:00
-187,Asia/Baku,1997,Azer,240,60,3,-1,0,0,08:00,10,-1,0,0,08:00
-188,Asia/Bahrain,1970,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-189,Asia/Bahrain,1972,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-190,Asia/Dhaka,1970,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-191,Asia/Dhaka,1971,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-192,Asia/Dhaka,2009,Dhaka,360,60,6,19,-1,0,29:00,12,31,-1,0,28:59
-193,Asia/Dhaka,2010,Dhaka,360,0,6,19,-1,0,29:00,12,31,-1,0,28:59
-194,Asia/Thimphu,1970,,330,0,0,0,0,0,00:00,0,0,0,0,00:00
-195,Asia/Thimphu,1987,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-196,Indian/Chagos,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-197,Indian/Chagos,1996,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-198,Asia/Brunei,1970,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-199,Asia/Rangoon,1970,,390,0,0,0,0,0,00:00,0,0,0,0,00:00
-200,Asia/Phnom_Penh,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-201,Asia/Harbin,1970,,510,0,0,0,0,0,00:00,0,0,0,0,00:00
-202,Asia/Harbin,1980,PRC,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-203,Asia/Harbin,1986,PRC,480,60,5,4,-1,0,08:00,9,11,0,0,07:00
-204,Asia/Harbin,1987,PRC,480,60,4,10,0,0,08:00,9,11,0,0,07:00
-205,Asia/Harbin,1991,PRC,480,0,4,10,0,0,08:00,9,11,0,0,07:00
-206,Asia/Shanghai,1970,PRC,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-207,Asia/Shanghai,1986,PRC,480,60,5,4,-1,0,08:00,9,11,0,0,07:00
-208,Asia/Shanghai,1987,PRC,480,60,4,10,0,0,08:00,9,11,0,0,07:00
-209,Asia/Shanghai,1991,PRC,480,0,4,10,0,0,08:00,9,11,0,0,07:00
-210,Asia/Chongqing,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-211,Asia/Chongqing,1980,PRC,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-212,Asia/Chongqing,1986,PRC,480,60,5,4,-1,0,08:00,9,11,0,0,07:00
-213,Asia/Chongqing,1987,PRC,480,60,4,10,0,0,08:00,9,11,0,0,07:00
-214,Asia/Chongqing,1991,PRC,480,0,4,10,0,0,08:00,9,11,0,0,07:00
-215,Asia/Urumqi,1970,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-216,Asia/Urumqi,1980,PRC,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-217,Asia/Urumqi,1986,PRC,480,60,5,4,-1,0,08:00,9,11,0,0,07:00
-218,Asia/Urumqi,1987,PRC,480,60,4,10,0,0,08:00,9,11,0,0,07:00
-219,Asia/Urumqi,1991,PRC,480,0,4,10,0,0,08:00,9,11,0,0,07:00
-220,Asia/Kashgar,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-221,Asia/Kashgar,1980,PRC,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-222,Asia/Kashgar,1986,PRC,480,60,5,4,-1,0,08:00,9,11,0,0,07:00
-223,Asia/Kashgar,1987,PRC,480,60,4,10,0,0,08:00,9,11,0,0,07:00
-224,Asia/Kashgar,1991,PRC,480,0,4,10,0,0,08:00,9,11,0,0,07:00
-225,Asia/Hong_Kong,1970,HK,480,60,4,16,0,0,11:30,10,16,0,0,10:30
-226,Asia/Hong_Kong,1973,HK,480,60,12,30,-1,0,11:30,10,16,0,0,10:30
-227,Asia/Hong_Kong,1974,HK,480,60,4,16,0,0,11:30,10,16,0,0,10:30
-228,Asia/Hong_Kong,1979,HK,480,60,5,8,0,0,11:30,10,16,0,0,10:30
-229,Asia/Hong_Kong,1980,HK,480,0,5,8,0,0,11:30,10,16,0,0,10:30
-230,Asia/Taipei,1970,Taiwan,480,60,6,1,-1,0,08:00,10,1,-1,0,07:00
-231,Asia/Taipei,1974,Taiwan,480,60,4,1,-1,0,08:00,10,1,-1,0,07:00
-232,Asia/Taipei,1979,Taiwan,480,60,6,30,-1,0,08:00,9,30,-1,0,07:00
-233,Asia/Taipei,1980,Taiwan,480,0,6,30,-1,0,08:00,9,30,-1,0,07:00
-234,Asia/Macau,1970,Macau,480,60,4,16,0,0,11:30,10,16,0,0,10:30
-235,Asia/Macau,1972,Macau,480,60,4,15,0,0,08:00,10,15,0,0,07:00
-236,Asia/Macau,1974,Macau,480,60,4,15,0,0,08:00,10,15,0,0,10:30
-237,Asia/Macau,1975,Macau,480,60,4,15,0,0,11:30,10,15,0,0,10:30
-238,Asia/Macau,1978,Macau,480,60,4,15,0,0,08:00,10,15,0,0,07:00
-239,Asia/Macau,1980,Macau,480,0,4,15,0,0,08:00,10,15,0,0,07:00
-240,Asia/Macau,1999,PRC,480,0,4,15,0,0,08:00,10,15,0,0,07:00
-241,Asia/Nicosia,1970,Cyprus,120,0,0,0,0,0,00:00,0,0,0,0,00:00
-242,Asia/Nicosia,1975,Cyprus,120,60,4,13,-1,0,02:00,10,12,-1,0,01:00
-243,Asia/Nicosia,1976,Cyprus,120,60,5,15,-1,0,02:00,10,11,-1,0,01:00
-244,Asia/Nicosia,1977,Cyprus,120,60,4,1,0,0,02:00,9,25,-1,0,01:00
-245,Asia/Nicosia,1978,Cyprus,120,60,4,1,0,0,02:00,10,2,-1,0,01:00
-246,Asia/Nicosia,1979,Cyprus,120,60,4,1,0,0,02:00,9,-1,0,0,01:00
-247,Asia/Nicosia,1981,Cyprus,120,60,3,-1,0,0,02:00,9,-1,0,0,01:00
-248,Asia/Nicosia,1998,EUAsia,120,60,3,-1,0,0,02:00,9,-1,0,0,01:00
-249,Asia/Tbilisi,1970,RussiaAsia,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-250,Asia/Tbilisi,1981,RussiaAsia,240,60,4,1,-1,0,04:00,10,1,-1,0,03:00
-251,Asia/Tbilisi,1984,RussiaAsia,240,60,4,1,-1,0,04:00,9,-1,0,0,06:00
-252,Asia/Tbilisi,1985,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-253,Asia/Tbilisi,1991,RussiaAsia,180,60,3,-1,0,0,05:00,9,-1,0,0,05:00
-254,Asia/Tbilisi,1992,E-EurAsia,180,60,3,-1,0,0,03:00,9,-1,0,0,02:00
-255,Asia/Tbilisi,1994,E-EurAsia,240,60,3,-1,0,0,04:00,9,-1,0,0,03:00
-256,Asia/Tbilisi,1995,E-EurAsia,240,0,12,31,-1,0,16:00,9,-1,0,0,03:00
-257,Asia/Tbilisi,1996,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-258,Asia/Tbilisi,1997,E-EurAsia,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-259,Asia/Tbilisi,2004,RussiaAsia,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-260,Asia/Tbilisi,2005,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-261,Asia/Dili,1970,,540,0,0,0,0,0,00:00,0,0,0,0,00:00
-262,Asia/Dili,1976,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-263,Asia/Dili,2000,,540,0,0,0,0,0,00:00,0,0,0,0,00:00
-264,Asia/Kolkata,1970,,330,0,0,0,0,0,00:00,0,0,0,0,00:00
-265,Asia/Jakarta,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-266,Asia/Pontianak,1970,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-267,Asia/Pontianak,1988,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-268,Asia/Makassar,1970,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-269,Asia/Jayapura,1970,,540,0,0,0,0,0,00:00,0,0,0,0,00:00
-270,Asia/Tehran,1970,,210,0,0,0,0,0,00:00,0,0,0,0,00:00
-271,Asia/Tehran,1977,Iran,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-272,Asia/Tehran,1978,Iran,240,60,3,21,-1,0,04:00,10,21,-1,0,03:00
-273,Asia/Tehran,1979,Iran,210,60,3,21,-1,0,03:30,9,19,-1,0,02:30
-274,Asia/Tehran,1980,Iran,210,60,3,21,-1,0,03:30,9,23,-1,0,02:30
-275,Asia/Tehran,1991,Iran,210,60,5,3,-1,0,03:30,9,22,-1,0,02:30
-276,Asia/Tehran,1992,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-277,Asia/Tehran,1996,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-278,Asia/Tehran,1997,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-279,Asia/Tehran,2000,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-280,Asia/Tehran,2001,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-281,Asia/Tehran,2004,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-282,Asia/Tehran,2005,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-283,Asia/Tehran,2008,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-284,Asia/Tehran,2009,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-285,Asia/Tehran,2012,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-286,Asia/Tehran,2013,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-287,Asia/Tehran,2016,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-288,Asia/Tehran,2017,Iran,210,60,3,22,-1,0,03:30,9,22,-1,0,02:30
-289,Asia/Tehran,2020,Iran,210,60,3,21,-1,0,03:30,9,21,-1,0,02:30
-290,Asia/Baghdad,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-291,Asia/Baghdad,1982,Iraq,180,60,5,1,-1,0,03:00,10,1,-1,0,02:00
-292,Asia/Baghdad,1983,Iraq,180,60,3,31,-1,0,03:00,10,1,-1,0,02:00
-293,Asia/Baghdad,1984,Iraq,180,60,4,1,-1,0,03:00,10,1,-1,0,02:00
-294,Asia/Baghdad,1985,Iraq,180,60,4,1,-1,0,03:00,9,-1,0,0,04:00
-295,Asia/Baghdad,1986,Iraq,180,60,3,-1,0,0,04:00,9,-1,0,0,04:00
-296,Asia/Baghdad,1991,Iraq,180,60,4,1,-1,0,06:00,10,1,-1,0,06:00
-297,Asia/Baghdad,2007,Iraq,180,0,4,1,-1,0,06:00,10,1,-1,0,06:00
-298,Asia/Jerusalem,1970,Zion,120,60,4,29,-1,0,04:00,9,22,-1,0,01:00
-299,Asia/Jerusalem,1974,Zion,120,60,7,7,-1,0,02:00,10,13,-1,0,01:00
-300,Asia/Jerusalem,1975,Zion,120,60,4,20,-1,0,02:00,8,31,-1,0,01:00
-301,Asia/Jerusalem,1985,Zion,120,60,4,14,-1,0,02:00,9,15,-1,0,01:00
-302,Asia/Jerusalem,1986,Zion,120,60,5,18,-1,0,02:00,9,7,-1,0,01:00
-303,Asia/Jerusalem,1987,Zion,120,60,4,15,-1,0,02:00,9,13,-1,0,01:00
-304,Asia/Jerusalem,1988,Zion,120,60,4,9,-1,0,02:00,9,3,-1,0,01:00
-305,Asia/Jerusalem,1989,Zion,120,60,4,30,-1,0,02:00,9,3,-1,0,01:00
-306,Asia/Jerusalem,1990,Zion,120,60,3,25,-1,0,02:00,8,26,-1,0,01:00
-307,Asia/Jerusalem,1991,Zion,120,60,3,24,-1,0,02:00,9,1,-1,0,01:00
-308,Asia/Jerusalem,1992,Zion,120,60,3,29,-1,0,02:00,9,6,-1,0,01:00
-309,Asia/Jerusalem,1993,Zion,120,60,4,2,-1,0,02:00,9,5,-1,0,01:00
-310,Asia/Jerusalem,1994,Zion,120,60,4,1,-1,0,02:00,8,28,-1,0,01:00
-311,Asia/Jerusalem,1995,Zion,120,60,3,31,-1,0,02:00,9,3,-1,0,01:00
-312,Asia/Jerusalem,1996,Zion,120,60,3,15,-1,0,02:00,9,16,-1,0,01:00
-313,Asia/Jerusalem,1997,Zion,120,60,3,21,-1,0,02:00,9,14,-1,0,01:00
-314,Asia/Jerusalem,1998,Zion,120,60,3,20,-1,0,02:00,9,6,-1,0,01:00
-315,Asia/Jerusalem,1999,Zion,120,60,4,2,-1,0,04:00,9,3,-1,0,03:00
-316,Asia/Jerusalem,2000,Zion,120,60,4,14,-1,0,04:00,10,6,-1,0,02:00
-317,Asia/Jerusalem,2001,Zion,120,60,4,9,-1,0,03:00,9,24,-1,0,02:00
-318,Asia/Jerusalem,2002,Zion,120,60,3,29,-1,0,03:00,10,7,-1,0,02:00
-319,Asia/Jerusalem,2003,Zion,120,60,3,28,-1,0,03:00,10,3,-1,0,02:00
-320,Asia/Jerusalem,2004,Zion,120,60,4,7,-1,0,03:00,9,22,-1,0,02:00
-321,Asia/Jerusalem,2005,Zion,120,60,4,1,-1,0,04:00,10,9,-1,0,03:00
-322,Asia/Jerusalem,2006,Zion,120,60,3,26,5,0,04:00,10,1,-1,0,03:00
-323,Asia/Jerusalem,2007,Zion,120,60,3,26,5,0,04:00,9,16,-1,0,03:00
-324,Asia/Jerusalem,2008,Zion,120,60,3,26,5,0,04:00,10,5,-1,0,03:00
-325,Asia/Jerusalem,2009,Zion,120,60,3,26,5,0,04:00,9,27,-1,0,03:00
-326,Asia/Jerusalem,2010,Zion,120,60,3,26,5,0,04:00,9,12,-1,0,03:00
-327,Asia/Jerusalem,2011,Zion,120,60,4,1,-1,0,04:00,10,2,-1,0,03:00
-328,Asia/Jerusalem,2012,Zion,120,60,3,26,5,0,04:00,9,23,-1,0,03:00
-329,Asia/Jerusalem,2013,Zion,120,60,3,26,5,0,04:00,9,8,-1,0,03:00
-330,Asia/Jerusalem,2014,Zion,120,60,3,26,5,0,04:00,9,28,-1,0,03:00
-331,Asia/Jerusalem,2015,Zion,120,60,3,26,5,0,04:00,9,20,-1,0,03:00
-332,Asia/Jerusalem,2016,Zion,120,60,4,1,-1,0,04:00,10,9,-1,0,03:00
-333,Asia/Jerusalem,2017,Zion,120,60,3,26,5,0,04:00,9,24,-1,0,03:00
-334,Asia/Jerusalem,2018,Zion,120,60,3,26,5,0,04:00,9,16,-1,0,03:00
-335,Asia/Jerusalem,2019,Zion,120,60,3,26,5,0,04:00,10,6,-1,0,03:00
-336,Asia/Jerusalem,2020,Zion,120,60,3,26,5,0,04:00,9,27,-1,0,03:00
-337,Asia/Tokyo,1970,Japan,540,0,5,1,0,0,11:00,9,8,6,0,10:00
-338,Asia/Amman,1970,Jordan,120,0,0,0,0,0,00:00,0,0,0,0,00:00
-339,Asia/Amman,1973,Jordan,120,60,6,6,-1,0,02:00,10,1,-1,0,01:00
-340,Asia/Amman,1974,Jordan,120,60,5,1,-1,0,02:00,10,1,-1,0,01:00
-341,Asia/Amman,1976,Jordan,120,60,5,1,-1,0,02:00,11,1,-1,0,01:00
-342,Asia/Amman,1977,Jordan,120,60,5,1,-1,0,02:00,10,1,-1,0,01:00
-343,Asia/Amman,1978,Jordan,120,60,4,30,-1,0,02:00,9,30,-1,0,01:00
-344,Asia/Amman,1985,Jordan,120,60,4,1,-1,0,02:00,10,1,-1,0,01:00
-345,Asia/Amman,1986,Jordan,120,60,4,1,5,0,02:00,10,1,5,0,01:00
-346,Asia/Amman,1989,Jordan,120,60,5,8,-1,0,02:00,10,1,5,0,01:00
-347,Asia/Amman,1990,Jordan,120,60,4,27,-1,0,02:00,10,1,5,0,01:00
-348,Asia/Amman,1991,Jordan,120,60,4,17,-1,0,02:00,9,27,-1,0,01:00
-349,Asia/Amman,1992,Jordan,120,60,4,10,-1,0,02:00,10,1,5,0,01:00
-350,Asia/Amman,1993,Jordan,120,60,4,1,5,0,02:00,10,1,5,0,01:00
-351,Asia/Amman,1994,Jordan,120,60,4,1,5,0,02:00,9,15,5,0,01:00
-352,Asia/Amman,1995,Jordan,120,60,4,1,5,0,02:00,9,15,5,0,02:00
-353,Asia/Amman,1999,Jordan,120,60,7,1,-1,0,02:00,9,-1,5,0,02:00
-354,Asia/Amman,2000,Jordan,120,60,3,-1,4,0,02:00,9,-1,5,0,02:00
-355,Asia/Amman,2002,Jordan,120,60,3,-1,4,0,26:00,9,-1,5,0,02:00
-356,Asia/Amman,2003,Jordan,120,60,3,-1,4,0,26:00,10,24,-1,0,02:00
-357,Asia/Amman,2004,Jordan,120,60,3,-1,4,0,26:00,10,15,-1,0,02:00
-358,Asia/Amman,2005,Jordan,120,60,3,-1,4,0,26:00,9,-1,5,0,02:00
-359,Asia/Amman,2006,Jordan,120,60,3,-1,4,0,26:00,10,-1,5,0,02:00
-360,Asia/Almaty,1970,RussiaAsia,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-361,Asia/Almaty,1981,RussiaAsia,360,60,4,1,-1,0,06:00,10,1,-1,0,05:00
-362,Asia/Almaty,1984,RussiaAsia,360,60,4,1,-1,0,06:00,9,-1,0,0,08:00
-363,Asia/Almaty,1985,RussiaAsia,360,60,3,-1,0,0,08:00,9,-1,0,0,08:00
-364,Asia/Almaty,1991,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-365,Asia/Almaty,1992,RussiaAsia,360,60,3,-1,6,0,29:00,9,-1,6,0,28:00
-366,Asia/Almaty,1993,RussiaAsia,360,60,3,-1,0,0,08:00,9,-1,0,0,08:00
-367,Asia/Almaty,1996,RussiaAsia,360,60,3,-1,0,0,08:00,10,-1,0,0,08:00
-368,Asia/Almaty,2005,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-369,Asia/Qyzylorda,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-370,Asia/Qyzylorda,1981,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-371,Asia/Qyzylorda,1982,RussiaAsia,300,60,4,1,-1,0,05:00,10,1,-1,0,04:00
-372,Asia/Qyzylorda,1984,RussiaAsia,300,60,4,1,-1,0,05:00,9,-1,0,0,07:00
-373,Asia/Qyzylorda,1985,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-374,Asia/Qyzylorda,1991,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-375,Asia/Qyzylorda,1992,RussiaAsia,360,60,3,-1,6,0,29:00,9,-1,6,0,28:00
-376,Asia/Qyzylorda,1993,RussiaAsia,360,60,3,-1,0,0,08:00,9,-1,0,0,08:00
-377,Asia/Qyzylorda,1996,RussiaAsia,360,60,3,-1,0,0,08:00,10,-1,0,0,08:00
-378,Asia/Qyzylorda,2005,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-379,Asia/Aqtobe,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-380,Asia/Aqtobe,1981,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-381,Asia/Aqtobe,1982,RussiaAsia,300,60,4,1,-1,0,05:00,10,1,-1,0,04:00
-382,Asia/Aqtobe,1984,RussiaAsia,300,60,4,1,-1,0,05:00,9,-1,0,0,07:00
-383,Asia/Aqtobe,1985,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-384,Asia/Aqtobe,1992,RussiaAsia,300,60,3,-1,6,0,28:00,9,-1,6,0,27:00
-385,Asia/Aqtobe,1993,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-386,Asia/Aqtobe,1996,RussiaAsia,300,60,3,-1,0,0,07:00,10,-1,0,0,07:00
-387,Asia/Aqtobe,2005,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-388,Asia/Aqtau,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-389,Asia/Aqtau,1981,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-390,Asia/Aqtau,1982,RussiaAsia,300,60,4,1,-1,0,05:00,10,1,-1,0,04:00
-391,Asia/Aqtau,1984,RussiaAsia,300,60,4,1,-1,0,05:00,9,-1,0,0,07:00
-392,Asia/Aqtau,1985,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-393,Asia/Aqtau,1992,RussiaAsia,300,60,3,-1,6,0,28:00,9,-1,6,0,27:00
-394,Asia/Aqtau,1993,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-395,Asia/Aqtau,1995,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-396,Asia/Aqtau,1996,RussiaAsia,240,60,3,-1,0,0,06:00,10,-1,0,0,06:00
-397,Asia/Aqtau,2005,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-398,Asia/Oral,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-399,Asia/Oral,1981,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-400,Asia/Oral,1982,RussiaAsia,300,60,4,1,-1,0,05:00,10,1,-1,0,04:00
-401,Asia/Oral,1984,RussiaAsia,300,60,4,1,-1,0,05:00,9,-1,0,0,07:00
-402,Asia/Oral,1985,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-403,Asia/Oral,1989,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-404,Asia/Oral,1992,RussiaAsia,240,60,3,-1,6,0,27:00,9,-1,6,0,26:00
-405,Asia/Oral,1993,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-406,Asia/Oral,1996,RussiaAsia,240,60,3,-1,0,0,06:00,10,-1,0,0,06:00
-407,Asia/Oral,2005,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-408,Asia/Bishkek,1970,RussiaAsia,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-409,Asia/Bishkek,1981,RussiaAsia,360,60,4,1,-1,0,06:00,10,1,-1,0,05:00
-410,Asia/Bishkek,1984,RussiaAsia,360,60,4,1,-1,0,06:00,9,-1,0,0,08:00
-411,Asia/Bishkek,1985,RussiaAsia,360,60,3,-1,0,0,08:00,9,-1,0,0,08:00
-412,Asia/Bishkek,1991,Kyrgyz,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-413,Asia/Bishkek,1992,Kyrgyz,300,60,4,7,0,0,05:00,9,-1,0,0,04:00
-414,Asia/Bishkek,1997,Kyrgyz,300,60,3,-1,0,0,07:30,10,-1,0,0,06:30
-415,Asia/Bishkek,2005,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-416,Asia/Seoul,1970,ROK,540,60,5,15,-1,0,09:00,9,13,-1,0,08:00
-417,Asia/Seoul,1987,ROK,540,60,5,8,0,0,09:00,10,8,0,0,08:00
-418,Asia/Seoul,1988,ROK,540,0,5,8,0,0,09:00,10,8,0,0,08:00
-419,Asia/Pyongyang,1970,,540,0,0,0,0,0,00:00,0,0,0,0,00:00
-420,Asia/Kuwait,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-421,Asia/Vientiane,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-422,Asia/Beirut,1970,Lebanon,120,60,5,1,-1,0,02:00,10,1,-1,0,01:00
-423,Asia/Beirut,1972,Lebanon,120,60,6,22,-1,0,02:00,10,1,-1,0,01:00
-424,Asia/Beirut,1973,Lebanon,120,60,5,1,-1,0,02:00,10,1,-1,0,01:00
-425,Asia/Beirut,1978,Lebanon,120,60,4,30,-1,0,02:00,9,30,-1,0,01:00
-426,Asia/Beirut,1984,Lebanon,120,60,5,1,-1,0,02:00,10,16,-1,0,01:00
-427,Asia/Beirut,1988,Lebanon,120,60,6,1,-1,0,02:00,10,16,-1,0,01:00
-428,Asia/Beirut,1989,Lebanon,120,60,5,10,-1,0,02:00,10,16,-1,0,01:00
-429,Asia/Beirut,1990,Lebanon,120,60,5,1,-1,0,02:00,10,16,-1,0,01:00
-430,Asia/Beirut,1992,Lebanon,120,60,5,1,-1,0,02:00,10,4,-1,0,01:00
-431,Asia/Beirut,1993,Lebanon,120,60,3,-1,0,0,02:00,9,-1,0,0,01:00
-432,Asia/Beirut,1999,Lebanon,120,60,3,-1,0,0,02:00,10,-1,0,0,01:00
-433,Asia/Kuala_Lumpur,1970,,450,0,0,0,0,0,00:00,0,0,0,0,00:00
-434,Asia/Kuala_Lumpur,1982,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-435,Asia/Kuching,1970,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-436,Asia/Kuching,1982,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-437,Indian/Maldives,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-438,Asia/Hovd,1970,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-439,Asia/Hovd,1978,Mongol,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-440,Asia/Hovd,1983,Mongol,420,60,4,1,-1,0,07:00,10,1,-1,0,06:00
-441,Asia/Hovd,1984,Mongol,420,60,4,1,-1,0,07:00,9,-1,0,0,06:00
-442,Asia/Hovd,1985,Mongol,420,60,3,-1,0,0,07:00,9,-1,0,0,06:00
-443,Asia/Hovd,2001,Mongol,420,60,4,-1,6,0,09:00,9,-1,6,0,08:00
-444,Asia/Hovd,2002,Mongol,420,60,3,-1,6,0,09:00,9,-1,6,0,08:00
-445,Asia/Hovd,2006,Mongol,420,0,3,-1,6,0,09:00,9,-1,6,0,08:00
-446,Asia/Ulaanbaatar,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-447,Asia/Ulaanbaatar,1978,Mongol,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-448,Asia/Ulaanbaatar,1983,Mongol,480,60,4,1,-1,0,08:00,10,1,-1,0,07:00
-449,Asia/Ulaanbaatar,1984,Mongol,480,60,4,1,-1,0,08:00,9,-1,0,0,07:00
-450,Asia/Ulaanbaatar,1985,Mongol,480,60,3,-1,0,0,08:00,9,-1,0,0,07:00
-451,Asia/Ulaanbaatar,2001,Mongol,480,60,4,-1,6,0,10:00,9,-1,6,0,09:00
-452,Asia/Ulaanbaatar,2002,Mongol,480,60,3,-1,6,0,10:00,9,-1,6,0,09:00
-453,Asia/Ulaanbaatar,2006,Mongol,480,0,3,-1,6,0,10:00,9,-1,6,0,09:00
-454,Asia/Choibalsan,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-455,Asia/Choibalsan,1978,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-456,Asia/Choibalsan,1983,Mongol,540,60,4,1,-1,0,09:00,10,1,-1,0,08:00
-457,Asia/Choibalsan,1984,Mongol,540,60,4,1,-1,0,09:00,9,-1,0,0,08:00
-458,Asia/Choibalsan,1985,Mongol,540,60,3,-1,0,0,09:00,9,-1,0,0,08:00
-459,Asia/Choibalsan,2001,Mongol,540,60,4,-1,6,0,11:00,9,-1,6,0,10:00
-460,Asia/Choibalsan,2002,Mongol,540,60,3,-1,6,0,11:00,9,-1,6,0,10:00
-461,Asia/Choibalsan,2006,Mongol,540,0,3,-1,6,0,11:00,9,-1,6,0,10:00
-462,Asia/Choibalsan,2008,Mongol,480,0,3,-1,6,0,10:00,9,-1,6,0,09:00
-463,Asia/Kathmandu,1970,,330,0,0,0,0,0,00:00,0,0,0,0,00:00
-464,Asia/Kathmandu,1986,,345,0,0,0,0,0,00:00,0,0,0,0,00:00
-465,Asia/Muscat,1970,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-466,Asia/Karachi,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-467,Asia/Karachi,1971,Pakistan,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-468,Asia/Karachi,2002,Pakistan,300,60,4,2,0,0,05:01,10,2,0,0,04:01
-469,Asia/Karachi,2008,Pakistan,300,60,6,1,-1,0,05:00,11,1,-1,0,04:00
-470,Asia/Karachi,2009,Pakistan,300,60,4,15,-1,0,05:00,11,1,-1,0,04:00
-471,Asia/Karachi,2010,Pakistan,300,0,4,15,-1,0,05:00,11,1,-1,0,04:00
-472,Asia/Gaza,1970,Zion,120,60,4,29,-1,0,04:00,9,22,-1,0,01:00
-473,Asia/Gaza,1974,Zion,120,60,7,7,-1,0,02:00,10,13,-1,0,01:00
-474,Asia/Gaza,1975,Zion,120,60,4,20,-1,0,02:00,8,31,-1,0,01:00
-475,Asia/Gaza,1985,Zion,120,60,4,14,-1,0,02:00,9,15,-1,0,01:00
-476,Asia/Gaza,1986,Zion,120,60,5,18,-1,0,02:00,9,7,-1,0,01:00
-477,Asia/Gaza,1987,Zion,120,60,4,15,-1,0,02:00,9,13,-1,0,01:00
-478,Asia/Gaza,1988,Zion,120,60,4,9,-1,0,02:00,9,3,-1,0,01:00
-479,Asia/Gaza,1989,Zion,120,60,4,30,-1,0,02:00,9,3,-1,0,01:00
-480,Asia/Gaza,1990,Zion,120,60,3,25,-1,0,02:00,8,26,-1,0,01:00
-481,Asia/Gaza,1991,Zion,120,60,3,24,-1,0,02:00,9,1,-1,0,01:00
-482,Asia/Gaza,1992,Zion,120,60,3,29,-1,0,02:00,9,6,-1,0,01:00
-483,Asia/Gaza,1993,Zion,120,60,4,2,-1,0,02:00,9,5,-1,0,01:00
-484,Asia/Gaza,1994,Zion,120,60,4,1,-1,0,02:00,8,28,-1,0,01:00
-485,Asia/Gaza,1995,Zion,120,60,3,31,-1,0,02:00,9,3,-1,0,01:00
-486,Asia/Gaza,1996,Jordan,120,60,4,1,5,0,02:00,9,15,5,0,02:00
-487,Asia/Gaza,1999,Palestine,120,60,4,15,5,0,02:00,10,15,5,0,01:00
-488,Asia/Gaza,2004,Palestine,120,60,4,15,5,0,02:00,10,1,-1,0,02:00
-489,Asia/Gaza,2005,Palestine,120,60,4,15,5,0,02:00,10,4,-1,0,03:00
-490,Asia/Gaza,2006,Palestine,120,60,4,1,-1,0,02:00,9,22,-1,0,01:00
-491,Asia/Gaza,2007,Palestine,120,60,4,1,-1,0,02:00,9,8,4,0,03:00
-492,Asia/Gaza,2008,Palestine,120,60,4,1,-1,0,02:00,8,-1,5,0,03:00
-493,Asia/Gaza,2009,Palestine,120,60,3,-1,5,0,02:00,9,1,5,0,03:00
-494,Asia/Gaza,2010,Palestine,120,60,3,-1,6,0,02:01,8,11,-1,0,01:00
-495,Asia/Gaza,2011,Palestine,120,0,3,-1,6,0,02:01,8,11,-1,0,01:00
-496,Asia/Manila,1970,Phil,480,60,4,12,-1,0,08:00,7,1,-1,0,07:00
-497,Asia/Manila,1978,Phil,480,60,3,22,-1,0,08:00,9,21,-1,0,07:00
-498,Asia/Manila,1979,Phil,480,0,3,22,-1,0,08:00,9,21,-1,0,07:00
-499,Asia/Qatar,1970,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-500,Asia/Qatar,1972,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-501,Asia/Riyadh,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-502,Asia/Singapore,1970,,450,0,0,0,0,0,00:00,0,0,0,0,00:00
-503,Asia/Singapore,1982,,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-504,Asia/Colombo,1970,,330,0,0,0,0,0,00:00,0,0,0,0,00:00
-505,Asia/Colombo,1996,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-506,Asia/Colombo,2006,,330,0,0,0,0,0,00:00,0,0,0,0,00:00
-507,Asia/Damascus,1970,Syria,120,60,5,1,-1,0,04:00,10,1,-1,0,03:00
-508,Asia/Damascus,1977,Syria,120,60,5,1,-1,0,04:00,9,1,-1,0,03:00
-509,Asia/Damascus,1983,Syria,120,60,4,9,-1,0,04:00,10,1,-1,0,03:00
-510,Asia/Damascus,1986,Syria,120,60,2,16,-1,0,04:00,10,9,-1,0,03:00
-511,Asia/Damascus,1987,Syria,120,60,3,1,-1,0,04:00,10,31,-1,0,03:00
-512,Asia/Damascus,1988,Syria,120,60,3,15,-1,0,04:00,10,31,-1,0,03:00
-513,Asia/Damascus,1989,Syria,120,60,3,31,-1,0,04:00,10,1,-1,0,03:00
-514,Asia/Damascus,1990,Syria,120,60,4,1,-1,0,04:00,9,30,-1,0,03:00
-515,Asia/Damascus,1991,Syria,120,60,4,1,-1,0,02:00,10,1,-1,0,01:00
-516,Asia/Damascus,1992,Syria,120,60,4,8,-1,0,02:00,10,1,-1,0,01:00
-517,Asia/Damascus,1993,Syria,120,60,3,26,-1,0,02:00,9,25,-1,0,01:00
-518,Asia/Damascus,1994,Syria,120,60,4,1,-1,0,02:00,10,1,-1,0,01:00
-519,Asia/Damascus,1997,Syria,120,60,3,-1,1,0,02:00,10,1,-1,0,01:00
-520,Asia/Damascus,1999,Syria,120,60,4,1,-1,0,02:00,10,1,-1,0,01:00
-521,Asia/Damascus,2006,Syria,120,60,4,1,-1,0,02:00,9,22,-1,0,01:00
-522,Asia/Damascus,2007,Syria,120,60,3,-1,5,0,02:00,11,1,5,0,01:00
-523,Asia/Damascus,2008,Syria,120,60,4,1,5,0,02:00,11,1,-1,0,01:00
-524,Asia/Damascus,2009,Syria,120,60,3,-1,5,0,02:00,10,-1,5,0,01:00
-525,Asia/Damascus,2010,Syria,120,60,4,1,5,0,02:00,10,-1,5,0,01:00
-526,Asia/Dushanbe,1970,RussiaAsia,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-527,Asia/Dushanbe,1981,RussiaAsia,360,60,4,1,-1,0,06:00,10,1,-1,0,05:00
-528,Asia/Dushanbe,1984,RussiaAsia,360,60,4,1,-1,0,06:00,9,-1,0,0,08:00
-529,Asia/Dushanbe,1985,RussiaAsia,360,60,3,-1,0,0,08:00,9,-1,0,0,08:00
-530,Asia/Dushanbe,1991,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-531,Asia/Bangkok,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-532,Asia/Ashgabat,1970,RussiaAsia,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-533,Asia/Ashgabat,1981,RussiaAsia,300,60,4,1,-1,0,05:00,10,1,-1,0,04:00
-534,Asia/Ashgabat,1984,RussiaAsia,300,60,4,1,-1,0,05:00,9,-1,0,0,07:00
-535,Asia/Ashgabat,1985,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-536,Asia/Ashgabat,1991,RussiaAsia,240,60,3,-1,0,0,06:00,9,-1,0,0,06:00
-537,Asia/Ashgabat,1992,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-538,Asia/Dubai,1970,,240,0,0,0,0,0,00:00,0,0,0,0,00:00
-539,Asia/Samarkand,1970,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-540,Asia/Samarkand,1981,,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-541,Asia/Samarkand,1982,RussiaAsia,300,60,4,1,-1,0,05:00,10,1,-1,0,04:00
-542,Asia/Samarkand,1984,RussiaAsia,300,60,4,1,-1,0,05:00,9,-1,0,0,07:00
-543,Asia/Samarkand,1985,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-544,Asia/Samarkand,1992,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-545,Asia/Tashkent,1970,RussiaAsia,360,0,0,0,0,0,00:00,0,0,0,0,00:00
-546,Asia/Tashkent,1981,RussiaAsia,360,60,4,1,-1,0,06:00,10,1,-1,0,05:00
-547,Asia/Tashkent,1984,RussiaAsia,360,60,4,1,-1,0,06:00,9,-1,0,0,08:00
-548,Asia/Tashkent,1985,RussiaAsia,360,60,3,-1,0,0,08:00,9,-1,0,0,08:00
-549,Asia/Tashkent,1991,RussiaAsia,300,60,3,-1,0,0,07:00,9,-1,0,0,07:00
-550,Asia/Tashkent,1992,,300,0,0,0,0,0,00:00,0,0,0,0,00:00
-551,Asia/Ho_Chi_Minh,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-552,Asia/Aden,1970,,180,0,0,0,0,0,00:00,0,0,0,0,00:00
-553,Australia/Darwin,1970,Aus,570,0,12,31,-1,0,21:30,3,-1,0,0,10:30
-554,Australia/Perth,1970,AW,480,0,0,0,0,0,00:00,0,0,0,0,00:00
-555,Australia/Perth,1974,AW,480,60,10,-1,0,0,10:00,1,1,-1,0,19:00
-556,Australia/Perth,1975,AW,480,0,12,31,-1,0,20:00,3,1,0,0,10:00
-557,Australia/Perth,1983,AW,480,60,10,-1,0,0,10:00,1,1,-1,0,19:00
-558,Australia/Perth,1984,AW,480,0,12,31,-1,0,20:00,3,1,0,0,10:00
-559,Australia/Perth,1991,AW,480,60,11,17,-1,0,10:00,1,1,-1,0,19:00
-560,Australia/Perth,1992,AW,480,0,12,31,-1,0,20:00,3,1,0,0,10:00
-561,Australia/Perth,2006,AW,480,60,12,3,-1,0,10:00,1,1,-1,0,19:00
-562,Australia/Perth,2007,AW,480,60,10,-1,0,0,10:00,3,-1,0,0,10:00
-563,Australia/Perth,2009,AW,480,0,12,31,-1,0,20:00,3,-1,0,0,10:00
-564,Australia/Eucla,1970,AW,525,0,0,0,0,0,00:00,0,0,0,0,00:00
-565,Australia/Eucla,1974,AW,525,60,10,-1,0,0,10:45,1,1,-1,0,19:45
-566,Australia/Eucla,1975,AW,525,0,12,31,-1,0,20:45,3,1,0,0,10:45
-567,Australia/Eucla,1983,AW,525,60,10,-1,0,0,10:45,1,1,-1,0,19:45
-568,Australia/Eucla,1984,AW,525,0,12,31,-1,0,20:45,3,1,0,0,10:45
-569,Australia/Eucla,1991,AW,525,60,11,17,-1,0,10:45,1,1,-1,0,19:45
-570,Australia/Eucla,1992,AW,525,0,12,31,-1,0,20:45,3,1,0,0,10:45
-571,Australia/Eucla,2006,AW,525,60,12,3,-1,0,10:45,1,1,-1,0,19:45
-572,Australia/Eucla,2007,AW,525,60,10,-1,0,0,10:45,3,-1,0,0,10:45
-573,Australia/Eucla,2009,AW,525,0,12,31,-1,0,20:45,3,-1,0,0,10:45
-574,Australia/Brisbane,1970,Aus,600,0,12,31,-1,0,22:00,3,-1,0,0,11:00
-575,Australia/Brisbane,1971,AQ,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-576,Australia/Brisbane,1972,AQ,600,0,12,31,-1,0,22:00,2,-1,0,0,12:00
-577,Australia/Brisbane,1989,AQ,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-578,Australia/Brisbane,1990,AQ,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-579,Australia/Brisbane,1992,AQ,600,0,12,31,-1,0,22:00,3,1,0,0,12:00
-580,Australia/Lindeman,1970,Aus,600,0,12,31,-1,0,22:00,3,-1,0,0,11:00
-581,Australia/Lindeman,1971,AQ,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-582,Australia/Lindeman,1972,AQ,600,0,12,31,-1,0,22:00,2,-1,0,0,12:00
-583,Australia/Lindeman,1989,AQ,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-584,Australia/Lindeman,1990,AQ,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-585,Australia/Lindeman,1992,Holiday,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-586,Australia/Lindeman,1993,Holiday,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-587,Australia/Lindeman,1994,Holiday,600,0,12,31,-1,0,22:00,3,1,0,0,12:00
-588,Australia/Adelaide,1970,Aus,570,0,12,31,-1,0,21:30,3,-1,0,0,10:30
-589,Australia/Adelaide,1971,AS,570,60,10,-1,0,0,11:30,1,1,-1,0,20:30
-590,Australia/Adelaide,1972,AS,570,60,10,-1,0,0,11:30,2,27,-1,0,11:30
-591,Australia/Adelaide,1973,AS,570,60,10,-1,0,0,11:30,3,1,0,0,11:30
-592,Australia/Adelaide,1986,AS,570,60,10,19,-1,0,11:30,3,15,0,0,11:30
-593,Australia/Adelaide,1987,AS,570,60,10,-1,0,0,11:30,3,15,0,0,11:30
-594,Australia/Adelaide,1991,AS,570,60,10,-1,0,0,11:30,3,3,-1,0,11:30
-595,Australia/Adelaide,1992,AS,570,60,10,-1,0,0,11:30,3,22,-1,0,11:30
-596,Australia/Adelaide,1993,AS,570,60,10,-1,0,0,11:30,3,7,-1,0,11:30
-597,Australia/Adelaide,1994,AS,570,60,10,-1,0,0,11:30,3,20,-1,0,11:30
-598,Australia/Adelaide,1995,AS,570,60,10,-1,0,0,11:30,3,-1,0,0,11:30
-599,Australia/Adelaide,2006,AS,570,60,10,-1,0,0,11:30,4,2,-1,0,11:30
-600,Australia/Adelaide,2007,AS,570,60,10,-1,0,0,11:30,3,-1,0,0,11:30
-601,Australia/Adelaide,2008,AS,570,60,10,1,0,0,11:30,4,1,0,0,11:30
-602,Australia/Hobart,1970,AT,600,60,10,-1,0,0,12:00,3,8,0,0,12:00
-603,Australia/Hobart,1972,AT,600,60,10,-1,0,0,12:00,2,-1,0,0,12:00
-604,Australia/Hobart,1973,AT,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-605,Australia/Hobart,1982,AT,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-606,Australia/Hobart,1984,AT,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-607,Australia/Hobart,1986,AT,600,60,10,15,0,0,12:00,3,1,0,0,12:00
-608,Australia/Hobart,1987,AT,600,60,10,22,0,0,12:00,3,15,0,0,12:00
-609,Australia/Hobart,1988,AT,600,60,10,-1,0,0,12:00,3,15,0,0,12:00
-610,Australia/Hobart,1991,AT,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-611,Australia/Hobart,2000,AT,600,60,8,-1,0,0,12:00,3,-1,0,0,12:00
-612,Australia/Hobart,2001,AT,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-613,Australia/Hobart,2006,AT,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-614,Australia/Hobart,2007,AT,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-615,Australia/Hobart,2008,AT,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-616,Australia/Currie,1970,Aus,600,0,12,31,-1,0,22:00,3,-1,0,0,11:00
-617,Australia/Currie,1971,AT,600,60,10,-1,0,0,12:00,3,8,0,0,12:00
-618,Australia/Currie,1972,AT,600,60,10,-1,0,0,12:00,2,-1,0,0,12:00
-619,Australia/Currie,1973,AT,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-620,Australia/Currie,1982,AT,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-621,Australia/Currie,1984,AT,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-622,Australia/Currie,1986,AT,600,60,10,15,0,0,12:00,3,1,0,0,12:00
-623,Australia/Currie,1987,AT,600,60,10,22,0,0,12:00,3,15,0,0,12:00
-624,Australia/Currie,1988,AT,600,60,10,-1,0,0,12:00,3,15,0,0,12:00
-625,Australia/Currie,1991,AT,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-626,Australia/Currie,2000,AT,600,60,8,-1,0,0,12:00,3,-1,0,0,12:00
-627,Australia/Currie,2001,AT,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-628,Australia/Currie,2006,AT,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-629,Australia/Currie,2007,AT,600,60,10,1,0,0,12:00,3,-1,0,0,12:00
-630,Australia/Currie,2008,AT,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-631,Australia/Melbourne,1970,Aus,600,0,12,31,-1,0,22:00,3,-1,0,0,11:00
-632,Australia/Melbourne,1971,AV,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-633,Australia/Melbourne,1972,AV,600,60,10,-1,0,0,12:00,2,-1,0,0,12:00
-634,Australia/Melbourne,1973,AV,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-635,Australia/Melbourne,1986,AV,600,60,10,15,0,0,12:00,3,15,0,0,12:00
-636,Australia/Melbourne,1988,AV,600,60,10,-1,0,0,12:00,3,15,0,0,12:00
-637,Australia/Melbourne,1991,AV,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-638,Australia/Melbourne,1995,AV,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-639,Australia/Melbourne,2000,AV,600,60,8,-1,0,0,12:00,3,-1,0,0,12:00
-640,Australia/Melbourne,2001,AV,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-641,Australia/Melbourne,2006,AV,600,60,10,-1,0,0,12:00,4,1,0,0,12:00
-642,Australia/Melbourne,2007,AV,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-643,Australia/Melbourne,2008,AV,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-644,Australia/Sydney,1970,Aus,600,0,12,31,-1,0,22:00,3,-1,0,0,11:00
-645,Australia/Sydney,1971,AN,600,60,10,-1,0,0,12:00,1,1,-1,0,21:00
-646,Australia/Sydney,1972,AN,600,60,10,-1,0,0,12:00,2,27,-1,0,12:00
-647,Australia/Sydney,1973,AN,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-648,Australia/Sydney,1982,AN,600,60,10,-1,0,0,12:00,4,1,0,0,12:00
-649,Australia/Sydney,1983,AN,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-650,Australia/Sydney,1986,AN,600,60,10,19,-1,0,12:00,3,15,0,0,12:00
-651,Australia/Sydney,1987,AN,600,60,10,-1,0,0,12:00,3,15,0,0,12:00
-652,Australia/Sydney,1990,AN,600,60,10,-1,0,0,12:00,3,1,0,0,12:00
-653,Australia/Sydney,1996,AN,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-654,Australia/Sydney,2000,AN,600,60,8,-1,0,0,12:00,3,-1,0,0,12:00
-655,Australia/Sydney,2001,AN,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-656,Australia/Sydney,2006,AN,600,60,10,-1,0,0,12:00,4,1,0,0,12:00
-657,Australia/Sydney,2007,AN,600,60,10,-1,0,0,12:00,3,-1,0,0,12:00
-658,Australia/Sydney,2008,AN,600,60,10,1,0,0,12:00,4,1,0,0,12:00
-659,Australia/Broken_Hill,1970,Aus,570,0,12,31,-1,0,21:30,3,-1,0,0,10:30
-660,Australia/Broken_Hill,1971,AN,570,60,10,-1,0,0,11:30,1,1,-1,0,20:30
-661,Australia/Broken_Hill,1972,AN,570,60,10,-1,0,0,11:30,2,27,-1,0,11:30
-662,Australia/Broken_Hill,1973,AN,570,60,10,-1,0,0,11:30,3,1,0,0,11:30
-663,Australia/Broken_Hill,1982,AN,570,60,10,-1,0,0,11:30,4,1,0,0,11:30
-664,Australia/Broken_Hill,1983,AN,570,60,10,-1,0,0,11:30,3,1,0,0,11:30
-665,Australia/Broken_Hill,1986,AN,570,60,10,19,-1,0,11:30,3,15,0,0,11:30
-666,Australia/Broken_Hill,1987,AN,570,60,10,-1,0,0,11:30,3,15,0,0,11:30
-667,Australia/Broken_Hill,1990,AN,570,60,10,-1,0,0,11:30,3,1,0,0,11:30
-668,Australia/Broken_Hill,1996,AN,570,60,10,-1,0,0,11:30,3,-1,0,0,11:30
-669,Australia/Broken_Hill,2000,AS,570,60,10,-1,0,0,11:30,3,-1,0,0,11:30
-670,Australia/Broken_Hill,2006,AS,570,60,10,-1,0,0,11:30,4,2,-1,0,11:30
-671,Australia/Broken_Hill,2007,AS,570,60,10,-1,0,0,11:30,3,-1,0,0,11:30
-672,Australia/Broken_Hill,2008,AS,570,60,10,1,0,0,11:30,4,1,0,0,11:30
-673,Australia/Lord_Howe,1970,,600,0,0,0,0,0,00:00,0,0,0,0,00:00
-674,Australia/Lord_Howe,1981,LH,630,60,10,-1,0,0,12:30,1,1,-1,0,21:30
-675,Australia/Lord_Howe,1982,LH,630,60,10,-1,0,0,12:30,3,1,0,0,11:30
-676,Australia/Lord_Howe,1985,LH,630,30,10,-1,0,0,12:30,3,1,0,0,11:30
-677,Australia/Lord_Howe,1986,LH,630,30,10,19,-1,0,12:30,3,15,0,0,11:30
-678,Australia/Lord_Howe,1987,LH,630,30,10,-1,0,0,12:30,3,15,0,0,11:30
-679,Australia/Lord_Howe,1990,LH,630,30,10,-1,0,0,12:30,3,1,0,0,11:30
-680,Australia/Lord_Howe,1996,LH,630,30,10,-1,0,0,12:30,3,-1,0,0,11:30
-681,Australia/Lord_Howe,2000,LH,630,30,8,-1,0,0,12:30,3,-1,0,0,11:30
-682,Australia/Lord_Howe,2001,LH,630,30,10,-1,0,0,12:30,3,-1,0,0,11:30
-683,Australia/Lord_Howe,2006,LH,630,30,10,-1,0,0,12:30,4,1,0,0,11:30
-684,Australia/Lord_Howe,2007,LH,630,30,10,-1,0,0,12:30,3,-1,0,0,11:30
-685,Australia/Lord_Howe,2008,LH,630,30,10,1,0,0,12:30,4,1,0,0,11:30
-686,Indian/Christmas,1970,,420,0,0,0,0,0,00:00,0,0,0,0,00:00
-687,Pacific/Rarotonga,1970,,-630,0,0,0,0,0,00:00,0,0,0,0,00:00
-688,Pacific/Rarotonga,1978,Cook,-600,30,11,12,-1,0,-10:00,1,1,-1,0,01:00
-689,Pacific/Rarotonga,1979,Cook,-600,30,10,-1,0,0,-10:00,3,1,0,0,-11:00
-690,Pacific/Rarotonga,1991,Cook,-600,0,12,31,-1,0,02:00,3,1,0,0,-11:00
-691,Indian/Cocos,1970,,390,0,0,0,0,0,00:00,0,0,0,0,00:00
-692,Pacific/Fiji,1970,Fiji,720,0,0,0,0,0,00:00,0,0,0,0,00:00
-693,Pacific/Fiji,1998,Fiji,720,60,11,1,0,0,14:00,1,1,-1,0,23:00
-694,Pacific/Fiji,1999,Fiji,720,60,11,1,0,0,14:00,2,-1,0,0,14:00
-695,Pacific/Fiji,2000,Fiji,720,0,12,31,-1,0,24:00,2,-1,0,0,14:00
-696,Pacific/Fiji,2009,Fiji,720,60,11,29,-1,0,14:00,1,1,-1,0,23:00
-697,Pacific/Fiji,2010,Fiji,720,60,10,24,-1,0,14:00,3,-1,0,0,14:00
-698,Pacific/Fiji,2011,Fiji,720,0,12,31,-1,0,24:00,3,1,0,0,14:00
-699,Pacific/Gambier,1970,,-540,0,0,0,0,0,00:00,0,0,0,0,00:00
-700,Pacific/Marquesas,1970,,-570,0,0,0,0,0,00:00,0,0,0,0,00:00
-701,Pacific/Tahiti,1970,,-600,0,0,0,0,0,00:00,0,0,0,0,00:00
-702,Pacific/Guam,1970,,600,0,0,0,0,0,00:00,0,0,0,0,00:00
-703,Pacific/Guam,2000,,600,0,0,0,0,0,00:00,0,0,0,0,00:00
-704,Pacific/Tarawa,1970,,720,0,0,0,0,0,00:00,0,0,0,0,00:00
-705,Pacific/Enderbury,1970,,-720,0,0,0,0,0,00:00,0,0,0,0,00:00
-706,Pacific/Enderbury,1979,,-660,0,0,0,0,0,00:00,0,0,0,0,00:00
-707,Pacific/Enderbury,1995,,780,0,0,0,0,0,00:00,0,0,0,0,00:00