MDL-21590 fixed icons in navigation lib + clean up of modinfo (planned removeal of...
authorPetr Skoda <skodak@moodle.org>
Sun, 14 Feb 2010 20:18:10 +0000 (20:18 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 14 Feb 2010 20:18:10 +0000 (20:18 +0000)
15 files changed:
auth/mnet/auth.php
course/lib.php
course/report/log/lib.php
course/report/progress/index.php
filter/activitynames/filter.php
lib/datalib.php
lib/db/upgrade.php
lib/moodlelib.php
lib/navigationlib.php
lib/weblib.php
mod/label/lib.php
mod/page/lib.php
mod/resource/lib.php
mod/url/lib.php
version.php

index 254687a..82abd33 100644 (file)
@@ -797,7 +797,7 @@ class auth_plugin_mnet extends auth_plugin_base {
                     unset($hostlog->modinfo);
                     $modulearray = array();
                     foreach($modinfo as $module) {
-                        $modulearray[$module->cm] = urldecode($module->name);
+                        $modulearray[$module->cm] = $module->name;
                     }
                     $hostlog->resource_name = $modulearray[$hostlog->cmid];
                 } else {
index 131238d..3d5eab2 100644 (file)
@@ -1105,13 +1105,16 @@ function get_array_of_activities($courseid) {
                            if (!empty($info->icon)) {
                                $mod[$seq]->icon = $info->icon;
                            }
+                           if (!empty($info->iconcomponent)) {
+                               $mod[$seq]->iconcomponent = $info->iconcomponent;
+                           }
                            if (!empty($info->name)) {
-                               $mod[$seq]->name = urlencode($info->name);
+                               $mod[$seq]->name = $info->name;
                            }
                        }
                    }
                    if (!isset($mod[$seq]->name)) {
-                       $mod[$seq]->name = urlencode($DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance)));
+                       $mod[$seq]->name = $DB->get_field($rawmods[$seq]->modname, "name", array("id"=>$rawmods[$seq]->instance));
                    }
                }
             }
index e263c29..53495e0 100644 (file)
@@ -186,7 +186,7 @@ function print_mnet_log_selector_form($hostid, $course, $selecteduser=0, $select
                 $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
             }
             $section = $mod->section;
-            $mod->name = strip_tags(format_string(urldecode($mod->name),true));
+            $mod->name = strip_tags(format_string($mod->name, true));
             if (strlen($mod->name) > 55) {
                 $mod->name = substr($mod->name, 0, 50)."...";
             }
@@ -410,7 +410,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
                 $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
             }
             $section = $mod->section;
-            $mod->name = strip_tags(format_string(urldecode($mod->name),true));
+            $mod->name = strip_tags(format_string($mod->name, true));
             if (strlen($mod->name) > 55) {
                 $mod->name = substr($mod->name, 0, 50)."...";
             }
index b45fb3a..589b6c2 100644 (file)
@@ -190,7 +190,7 @@ foreach($activities as $activity) {
     }
 
     // Some names (labels) come URL-encoded and can be very long, so shorten them
-    $activity->name=shorten_text(urldecode($activity->name));
+    $activity->name = shorten_text($activity->name);
 
     if($csv) {
         print $sep.csv_quote(strip_tags($activity->name)).$sep.csv_quote($datetext);
index 0a79203..35cd7a2 100644 (file)
@@ -49,8 +49,8 @@ class activitynames_filter extends moodle_text_filter {
                 foreach ($modinfo as $activity) {
                     //Exclude labels, hidden activities and activities for group members only
                     if ($activity->mod != "label" and $activity->visible and empty($activity->groupmembersonly)) {
-                        $title = s(trim(strip_tags(urldecode($activity->name))));
-                        $currentname = trim(urldecode($activity->name));
+                        $title = s(trim(strip_tags($activity->name)));
+                        $currentname = trim($activity->name);
                         $entitisedname  = s($currentname);
                         /// Avoid empty or unlinkable activity names
                         if (!empty($title)) {
index e399ce2..ec38018 100644 (file)
@@ -1898,7 +1898,7 @@ function get_all_instances_in_courses($modulename, $courses, $userid=NULL, $incl
             }
             $instance = $rawmods[$cm->id];
             if (!empty($cm->extra)) {
-                $instance->extra = urlencode($cm->extra); // bc compatibility
+                $instance->extra = $cm->extra;
             }
             $outputarray[] = $instance;
         }
index 0602680..06c2371 100644 (file)
@@ -3039,6 +3039,13 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
         upgrade_main_savepoint($result, 2010020301);
     }
 
+    if ($result && $oldversion < 2010021400) {
+    /// Changes to modinfo mean we need to rebuild course cache
+        require_once($CFG->dirroot . '/course/lib.php');
+        rebuild_course_cache(0, true);
+        upgrade_main_savepoint($result, 2010021400);
+    }
+
     return $result;
 }
 
index fde7200..8e5968a 100644 (file)
@@ -2809,7 +2809,7 @@ function &get_fast_modinfo(&$course, $userid=0) {
         $cm->instance         = $mod->id;
         $cm->course           = $course->id;
         $cm->modname          = $mod->mod;
-        $cm->name             = urldecode($mod->name);
+        $cm->name             = $mod->name;
         $cm->visible          = $mod->visible;
         $cm->sectionnum       = $mod->section;
         $cm->groupmode        = $mod->groupmode;
@@ -2817,8 +2817,9 @@ function &get_fast_modinfo(&$course, $userid=0) {
         $cm->groupmembersonly = $mod->groupmembersonly;
         $cm->indent           = $mod->indent;
         $cm->completion       = $mod->completion;
-        $cm->extra            = isset($mod->extra) ? urldecode($mod->extra) : '';
+        $cm->extra            = isset($mod->extra) ? $mod->extra : '';
         $cm->icon             = isset($mod->icon) ? $mod->icon : '';
+        $cm->iconcomponent    = isset($mod->iconcomponent) ? $mod->iconcomponent : '';
         $cm->uservisible      = true;
         if(!empty($CFG->enableavailability)) {
             // We must have completion information from modinfo. If it's not
@@ -2855,17 +2856,16 @@ function &get_fast_modinfo(&$course, $userid=0) {
                 $minimalmodinfo=new stdClass();
                 $minimalmodinfo->cms=array();
                 foreach($info as $mod) {
-                    $minimalcm=new stdClass();
-                    $minimalcm->id=$mod->cm;
-                    $minimalcm->name=urldecode($mod->name);
+                    $minimalcm = new stdClass();
+                    $minimalcm->id = $mod->cm;
+                    $minimalcm->name = $mod->name;
                     $minimalmodinfo->cms[$minimalcm->id]=$minimalcm;
                 }
             }
 
             // Get availability information
             $ci = new condition_info($cm);
-            $cm->available=$ci->is_available($cm->availableinfo,true,$userid,
-                $minimalmodinfo);
+            $cm->available=$ci->is_available($cm->availableinfo, true, $userid, $minimalmodinfo);
         } else {
             $cm->available=true;
         }
index 0d022d2..9226b28 100644 (file)
@@ -1249,7 +1249,6 @@ class global_navigation extends navigation_node {
         }
         $modinfo =  $this->cache->{'modinfo'.$course->id};
 
-        $resources = array('resource', 'label');
         if (!$this->cache->cached('canviewhiddenactivities')) {
             $this->cache->canviewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $this->context);
         }
@@ -1264,30 +1263,14 @@ class global_navigation extends navigation_node {
                 continue;
             }
             $icon = null;
-            if (!in_array($module->modname, $resources)) {
-                if ($module->icon == '') {
-                    $icon = new pix_icon('icon', '', $module->modname);
-                }
-                $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
-                $type = navigation_node::TYPE_ACTIVITY;
+            if ($module->icon) {
+                $icon = new pix_icon($module->icon, '', $module->iconcomponent);
             } else {
-                //TODO: this is not nice and should be probably changed on the module level ;-)
-                /*
-                $url = null;
-                $type = navigation_node::TYPE_RESOURCE;
-                if ($module->modname != 'label') {
-                    $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
-                } else {
-                    if (preg_match('#^\s*<(p|div)>(?<extra>.*?)</\1>\s*$#i', $module->extra, $matches)) {
-                        $module->extra = $matches['extra'];
-                    }
-                    $module->name = format_text($module->extra, FORMAT_HTML, $labelformatoptions);
-                }
-                if ($module->icon!=='') {
-                    $icon = $OUTPUT->pix_url(preg_replace('#\.(png|gif)$#i','',$module->icon));
-                }
-                */
+                $icon = new pix_icon('icon', '', $module->modname);
             }
+            $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
+            $type = navigation_node::TYPE_ACTIVITY; // TODO: add some new fast test for resource types
+
             $this->add_to_path($keys, $module->id, $module->name, $module->name, $type, $url, $icon);
             $child = $this->find_child($module->id, $type);
             if ($child != false) {
@@ -1323,8 +1306,6 @@ class global_navigation extends navigation_node {
         }
         $sections = $this->cache->{'coursesections'.$course->id};
 
-        $resources = array('resource', 'label');
-
         if (!$this->cache->cached('canviewhiddenactivities')) {
             $this->cache->canviewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $this->context);
         }
@@ -1339,30 +1320,14 @@ class global_navigation extends navigation_node {
                 continue;
             }
             $icon = null;
-            if (!in_array($module->modname, $resources)) {
-                if ($module->icon=='') {
-                    $icon = new pix_icon('icon', '', $module->modname);
-                }
-                $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
-                $type = navigation_node::TYPE_ACTIVITY;
+            if ($module->icon) {
+                $icon = new pix_icon($module->icon, '', $module->iconcomponent);
             } else {
-                //TODO: this is not nice and should be probably changed on the module level ;-)
-                /*
-                $url = null;
-                $type = navigation_node::TYPE_RESOURCE;
-                if ($module->modname!='label') {
-                    $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
-                } else {
-                    if (preg_match('#^\s*<(p|div)>(?<extra>.*?)</\1>\s*$#i', $module->extra, $matches)) {
-                        $module->extra = $matches['extra'];
-                    }
-                    $module->name = format_text($module->extra, FORMAT_HTML, $labelformatoptions);
-                }
-                if ($module->icon!=='') {
-                    $icon = $OUTPUT->pix_url(preg_replace('#\.(png|gif)$#i','',$module->icon));
-                }
-                */
+                $icon = new pix_icon('icon', '', $module->modname);
             }
+            $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
+            $type = navigation_node::TYPE_ACTIVITY; // TODO: add some new fast test for resource types
+
             $path = $keys;
             if ($course->id !== SITEID) {
                 $path[] = $sections[$module->sectionnum]->id;
@@ -2216,8 +2181,6 @@ class limited_global_navigation extends global_navigation {
 
         $modinfo = get_fast_modinfo($course);
 
-        $resources = array('resource', 'label');
-
         if (!$this->cache->cached('canviewhiddenactivities')) {
             $this->cache->canviewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $this->context);
         }
@@ -2228,25 +2191,14 @@ class limited_global_navigation extends global_navigation {
                 continue;
             }
             $icon = null;
-            if (!in_array($module->modname, $resources)) {
-                if ($module->icon=='') {
-                    $icon = new pix_icon('icon', '', $module->modname);
-                }
-                $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
-                $type = navigation_node::TYPE_ACTIVITY;
+            if ($module->icon) {
+                $icon = new pix_icon($module->icon, '', $module->iconcomponent);
             } else {
-                //TODO: this is not nice and should be probably changed on the module level ;-)
-                /*
-                $url = null;
-                $type = navigation_node::TYPE_RESOURCE;
-                if ($module->modname!='label') {
-                    $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
-                }
-                if ($module->icon!=='') {
-                    $icon = $OUTPUT->pix_url(preg_replace('#\.(png|gif)$#i','',$module->icon));
-                }
-                */
+                $icon = new pix_icon('icon', '', $module->modname);
             }
+            $url = new moodle_url('/mod/'.$module->modname.'/view.php', array('id'=>$module->id));
+            $type = navigation_node::TYPE_ACTIVITY; // TODO: add some new fast test for resource types
+
             $this->add_to_path($keys, $module->id, $module->name, $module->name, $type, $url, $icon);
             $child = $this->find_child($module->id, $type);
             if ($child != false) {
@@ -3563,6 +3515,8 @@ class navigation_xml {
                     } else {
                         $xml .= ' '.$key.'="false"';
                     }
+                } else if ($value instanceof pix_icon) {
+                    $xml .= ' '.$key.'="'.$OUTPUT->pix_url($value->pix, $value->component).'"';
                 } else if ($value !== null) {
                     $xml .= ' '.$key.'="'.$value.'"';
                 }
index bc0774d..24e8a4e 100644 (file)
@@ -2370,7 +2370,7 @@ function navmenulist($course, $sections, $modinfo, $strsection, $strjumpto, $wid
         }
 
         $url = $mod->modname .'/view.php?id='. $mod->id;
-        $mod->name = strip_tags(format_string(urldecode($mod->name),true));
+        $mod->name = strip_tags(format_string($mod->name ,true));
         if (strlen($mod->name) > ($width+5)) {
             $mod->name = substr($mod->name, 0, $width).'...';
         }
index a049b7c..b45282d 100644 (file)
@@ -141,8 +141,8 @@ function label_get_coursemodule_info($coursemodule) {
         }
         $info = new object();
         // no filtering hre because this info is cached and filtered later
-        $info->extra = urlencode(format_module_intro('label', $label, $coursemodule->id, false));
-        $info->name  = urlencode($label->name);
+        $info->extra = format_module_intro('label', $label, $coursemodule->id, false);
+        $info->name  = $label->name;
         return $info;
     } else {
         return null;
index d873c72..87928d2 100644 (file)
@@ -248,23 +248,23 @@ function page_get_coursemodule_info($coursemodule) {
     global $CFG, $DB;
     require_once("$CFG->libdir/resourcelib.php");
 
+    $info = new object();
+    $info->name = $page->name;
+
     if (!$page = $DB->get_record('page', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions')) {
         return NULL;
     }
 
     if ($page->display != RESOURCELIB_DISPLAY_POPUP) {
-        return null;
+        return $info;
     }
 
-    $info = new object();
-    $info->name = $page->name;
-
     $fullurl = "$CFG->wwwroot/mod/page/view.php?id=$coursemodule->id&amp;inpopup=1";
     $options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions);
     $width  = empty($options['popupwidth'])  ? 620 : $options['popupwidth'];
     $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
     $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
-    $info->extra = urlencode("onclick=\"window.open('$fullurl', '', '$wh'); return false;\"");
+    $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";
 
     return $info;
 }
index 0ccd7a3..1e839f0 100644 (file)
@@ -289,22 +289,22 @@ function resource_get_coursemodule_info($coursemodule) {
         $width  = empty($options['popupwidth'])  ? 620 : $options['popupwidth'];
         $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
         $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
-        $info->extra = urlencode("onclick=\"window.open('$fullurl', '', '$wh'); return false;\"");
+        $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";
 
     } else if ($display == RESOURCELIB_DISPLAY_NEW) {
         $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
-        $info->extra = urlencode("onclick=\"window.open('$fullurl'); return false;\"");
+        $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
 
     } else if ($display == RESOURCELIB_DISPLAY_OPEN) {
         $fullurl = "$CFG->wwwroot/mod/resource/view.php?id=$coursemodule->id&amp;redirect=1";
-        $info->extra = urlencode("onclick=\"window.location.href ='$fullurl';return false;\"");
+        $info->extra = "onclick=\"window.location.href ='$fullurl';return false;\"";
 
     } else if ($display == RESOURCELIB_DISPLAY_DOWNLOAD) {
         // do not open any window because it would be left there after download
         $context = get_context_instance(CONTEXT_MODULE, $coursemodule->id);
         $path = '/'.$context->id.'/resource_content/'.$resource->revision.$resource->mainfile;
         $fullurl = addslashes_js(file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, true));
-        $info->extra = urlencode("onclick=\"window.open('$fullurl'); return false;\"");
+        $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
     }
 
     return $info;
index 9f10db5..aea861b 100644 (file)
@@ -272,15 +272,15 @@ function url_get_coursemodule_info($coursemodule) {
         $width  = empty($options['popupwidth'])  ? 620 : $options['popupwidth'];
         $height = empty($options['popupheight']) ? 450 : $options['popupheight'];
         $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes";
-        $info->extra = urlencode("onclick=\"window.open('$fullurl', '', '$wh'); return false;\"");
+        $info->extra = "onclick=\"window.open('$fullurl', '', '$wh'); return false;\"";
 
     } else if ($display == RESOURCELIB_DISPLAY_NEW) {
         $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&amp;redirect=1";
-        $info->extra = urlencode("onclick=\"window.open('$fullurl'); return false;\"");
+        $info->extra = "onclick=\"window.open('$fullurl'); return false;\"";
 
     } else if ($display == RESOURCELIB_DISPLAY_OPEN) {
         $fullurl = "$CFG->wwwroot/mod/url/view.php?id=$coursemodule->id&amp;redirect=1";
-        $info->extra = urlencode("onclick=\"window.location.href ='$fullurl';return false;\"");
+        $info->extra = "onclick=\"window.location.href ='$fullurl';return false;\"";
     }
 
     return $info;
index 0dc41bd..95bd65b 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-    $version = 2010020701;  // YYYYMMDD   = date of the last version bump
+    $version = 2010021400;  // YYYYMMDD   = date of the last version bump
                             //         XX = daily increments
 
     $release = '2.0 dev (Build: 20100214)';  // Human-friendly version name