Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-8357

allow <span>...</span> in multilang block

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8
    • Fix Version/s: DEV backlog
    • Component/s: Filters
    • Labels:
    • Affected Branches:
      MOODLE_18_STABLE

      Description

      Hi filter fans,

      I would like to suggest an improvement to the multilang filter which would allow <span>...</span> WITHIN the start and finish tags for the language blocks.

      Currently, it is not possible to include <span>...</span> tags within a language block, because the RegEx to match the language blocks will terminate the block on the first matching </span> tag.

      The solution is short and does not require changing a lot of lines of code.

      Looking solely at the RegEx for the "new syntax" in "filter/multilang/filter.php", I suggest changing the following line (around line 46).

      Change this:

      ============
      $search = '/(<span lang="[a-zA-Z0-9_-]+" class="multilang">.?<\/span>)(\s<span lang="[a-zA-Z0-9_-]" class="multilang">.*?<\/span>)/is';
      ============

      to this:

      ============
      $search = '/(<(div|span) lang="[a-zA-Z0-9_-]+" class="multilang">.?<\/\2>)(\s<\2 lang="[a-zA-Z0-9_-]" class="multilang">.*?<\/\2>)/is';
      ============

      Notice the use of "\2". Instead of looking for the closing </span> tag in ALL cases, the RegEx will look for the closing tag of whatever type of tag it was the opened the language block.

      You could go further and make the type of tag a config variable, $CFG->filter_multilang_tagtypes, that could be modifiable via "filter/multilang/filterconfig.html". The the RegEx would become:

      ============
      $search = '/(<('.$CFG->filter_multilang_tagtypes.') lang="[a-zA-Z0-9_-]+" class="multilang">.?<\/\2>)(\s<\2 lang="[a-zA-Z0-9_-]" class="multilang">.*?<\/\2>)/is';
      ============

      A corresponding change would also be needed to "multilang_filter_impl" function (around line 72).

      Change this:

      ============
      $searchtosplit = '/<span lang="([a-zA-Z0-9_-]+)" class="multilang">(.*?)<\/span>/is';
      ============

      To this:

      ============
      $searchtosplit = '/<('.$CFG->filter_multilang_tagtypes.') lang="([a-zA-Z0-9_-]+)" class="multilang">(.*?)<\/\1>/is';
      ============

      The above change would in turn require incrementing the indexes on the "$rawlanglist" array (around lines 81-84).

      Change this:

      ============
      foreach ($rawlanglist[1] as $index=>$lang) {
      $lang = str_replace('utf8', '', str_replace('-','',strtolower($lang))); // normalize languages
      $langlist[$lang] = $rawlanglist[2][$index];
      }
      ============

      to this:

      ============
      foreach ($rawlanglist[2] as $index=>$lang) {
      $lang = str_replace('utf8', '', str_replace('-','',strtolower($lang))); // normalize languages
      $langlist[$lang] = $rawlanglist[3][$index];
      }
      ============

      As I said, these are small changes, with no hit on performance, no ill-effects on current sites, but a big increase in flexibility :-D

      best regards
      Gordon

      P.S. Similar changes could be made to "old syntax" RegEx statements, to allow the same flexibility to Moodle 1.7 and earlier

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                13 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated: