Moodle
  1. Moodle
  2. MDL-25219

@@PLUGINFILE@@ replacing href link in HTML editor.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0.2
    • Component/s: HTML Editor (TinyMCE)
    • Labels:
      None
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      513

      Description

      Hi Petr,

      Would just like to add an issue I came across on one particular site but could not replicate on my own site.

      I spoke to Tim about this as it was occurring in the quiz module but he informed me it was an issue with the HTML editor and that you had the best knowledge on how it worked.

      Here is what was happening. Entries in a quiz question contained href links referencing a file on the server, such as href="draftfile.php/1/2/somefile.swf", however the link would be formatted with the term @@PLUGINFILE@@ when viewing the html source. Very odd. The solution was to edit the question and delete the URL (make it blank - href="") saving the changes, then re-editing the question and adding the URL again. The only way I can see why this is fixing the issue is if a bug caused these links to be saved incorrectly, and if not altered it is never updated.

      Sorry I can't be of more help on this issue.

      Regards,

      Mark

        Issue Links

          Activity

          Hide
          Petr Škoda added a comment -

          I can not reproduce this, sorry. The editor dos simple search replace before and after text editing, I do not think there is a bug in file and editor code.

          Show
          Petr Škoda added a comment - I can not reproduce this, sorry. The editor dos simple search replace before and after text editing, I do not think there is a bug in file and editor code.
          Hide
          Mark Nelson added a comment -

          Hi Petr,

          I started debugging the code myself as it was occurring too often and the fix I mentioned earlier was working sporadically. The questiontext column in the question table was being saved with @@PLUGINFILE@@ so I began looking through the code and saw that a few question types save_function called the parent function in the file question/type/questiontype.php. Here lies the issue, this uses a function called file_save_draft_area_files in lib\filelib.php. This is where the string '@@PLUGINFILE@@' is being inserted. I have not looked into this further as I was hoping someone from Moodle HQ with more familiarity with the filelib code would be able to discover if there is an issue in the actual code or not.

          Show
          Mark Nelson added a comment - Hi Petr, I started debugging the code myself as it was occurring too often and the fix I mentioned earlier was working sporadically. The questiontext column in the question table was being saved with @@PLUGINFILE@@ so I began looking through the code and saw that a few question types save_function called the parent function in the file question/type/questiontype.php. Here lies the issue, this uses a function called file_save_draft_area_files in lib\filelib.php. This is where the string '@@PLUGINFILE@@' is being inserted. I have not looked into this further as I was hoping someone from Moodle HQ with more familiarity with the filelib code would be able to discover if there is an issue in the actual code or not.
          Hide
          Mark Nelson added a comment -

          So far, commenting on the line //$text = str_ireplace($draftbase, '@@PLUGINFILE@@/', $text); in that function mentioned above is working, though I am not sure of the potential issues this may cause in other areas of the site!

          Show
          Mark Nelson added a comment - So far, commenting on the line //$text = str_ireplace($draftbase, '@@PLUGINFILE@@/', $text); in that function mentioned above is working, though I am not sure of the potential issues this may cause in other areas of the site!
          Hide
          Petr Škoda added a comment -

          The links to draft files must be replaced with the @@PLUGINFILE@@, so most probably the problem is that some code does not replace the plugin file marker before the display.

          Reassigning to author of original quiz/questions conversion.

          Show
          Petr Škoda added a comment - The links to draft files must be replaced with the @@PLUGINFILE@@, so most probably the problem is that some code does not replace the plugin file marker before the display. Reassigning to author of original quiz/questions conversion.
          Hide
          Mark Nelson added a comment -

          Hi Petr,

          Merry Christmas.

          Just wondering if there was any update on this?

          Show
          Mark Nelson added a comment - Hi Petr, Merry Christmas. Just wondering if there was any update on this?
          Hide
          Mark Nelson added a comment -

          I have investigated this issue more, and realised this issue occurs for the description question type, but the others I have tried work.

          I initially thought that in the file question/type/description/questiontype.php the line in the function print_question "$questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);" was not actually replacing the @@PLUGINFILE@@. However, inspecting other question types I noticed that the $question->questiontext variable should already have the correct URL. So the issue lies with not formatting $question->questiontext before it is passed to the print_question function.

          Show
          Mark Nelson added a comment - I have investigated this issue more, and realised this issue occurs for the description question type, but the others I have tried work. I initially thought that in the file question/type/description/questiontype.php the line in the function print_question "$questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);" was not actually replacing the @@PLUGINFILE@@. However, inspecting other question types I noticed that the $question->questiontext variable should already have the correct URL. So the issue lies with not formatting $question->questiontext before it is passed to the print_question function.
          Hide
          Mark Nelson added a comment - - edited

          Attached a patch: created by the one and only Sam Hemelryk - a patch that resolves this issue afaik.

          Show
          Mark Nelson added a comment - - edited Attached a patch: created by the one and only Sam Hemelryk - a patch that resolves this issue afaik.
          Hide
          Mark Nelson added a comment -

          Also, just thought I would add that the behaviour varies between the question types. Some save the URL in the database, where as the description (and possibly others) store the URL as @@PLUGINFILE@@ and are then responsible for filtering the URL when displayed. Why?

          Show
          Mark Nelson added a comment - Also, just thought I would add that the behaviour varies between the question types. Some save the URL in the database, where as the description (and possibly others) store the URL as @@PLUGINFILE@@ and are then responsible for filtering the URL when displayed. Why?
          Hide
          Dongsheng Cai added a comment -

          Mark

          Files and content are separated in moodle 2, moodle will find the related associated files by contextid, itemid, filearea and filename, @@PLUGINFILE@@ will be replaced by above parameters.

          Show
          Dongsheng Cai added a comment - Mark Files and content are separated in moodle 2, moodle will find the related associated files by contextid, itemid, filearea and filename, @@PLUGINFILE@@ will be replaced by above parameters.
          Hide
          Dongsheng Cai added a comment -

          Pull request submitted PULL-81

          Thanks to Sam's patch, it looks good.

          Show
          Dongsheng Cai added a comment - Pull request submitted PULL-81 Thanks to Sam's patch, it looks good.
          Hide
          David Mudrak added a comment -

          Tested. Dongsheng, please see the comment in the pull request.

          Show
          David Mudrak added a comment - Tested. Dongsheng, please see the comment in the pull request.

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: