special labels

special labels

by Daniele Cordella -
Number of replies: 43
Picture of Core developers Picture of Plugin developers
I know I ignore... so I ask.

Background ----------------------------------------------
Inside a topic I can add a link to a PDF. If I make a backup of my course and then I restore it to a different server the PDF is still well linked.
Good. This is important.

Now I add a label in which I write an img tag. Inside the src attribute I write http://myFirstServer/bla_bla_bla
Now I make a backup and I restore the course to mySecondServer.
Into the label on the restored course (on mySecondServer) I can still read: http://myFirstServer/bla_bla_bla
instead of
http://mySecondServer/bla_bla_bla
see bug 4888.
Of course... it is a label!!!!!!!!!!!!!!!!!!!!!!!

Final objective ----------------------------------------------
I would like to add a new item to the resource menu of each topic giving me the possibility to add "special labels". Why do I ask for a special label? For two reasons:
1) Because I want to save the src attribute of the img tag in the db not like a string but in the same way Moodle saves the path of a linked PDF. (read backgroung section of this post)
2) Because I want to see the image inside the course (as I see labels) and not a like a link to it.

Conclusions ----------------------------------------------
Any hint? Did you face the same problem in your past? Did you ever read infos about this?

Thank you in advance.
Average of ratings: -
In reply to Daniele Cordella

Re: special labels

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hello Daniele,

I have put links to images inside my labels and done backup of my course and restored it on a different server and the link to the images is correctly re-written to point to the new server without any problem. Using Moodle 1.6, Windows XP, Firefox.

Here is the detailed process, which you might try to follow and see if it works for you too.

1- On server myFirstServer, Add a Resource -> Insert a Label

2- Add label text. In HTML editor, type e.g. This is a label test; then click on the Insert Image icon in the HTML editor toolbar; browse your files and select a previously uploaded image (or upload an image from your computer). Click OK. View the text + image in your newly created label in your course view.

3- Backup your course. For a quick test, in the Course backup window, only select the label which you have just created (easy in Moodle 1.6). Also select Course Files (so that you backup the image(s) used in your label(s). Download backup file to your computer.

4- On server mySecondServer, as admin or teacher, do a Restore.

5- Result: your labels are displayed with their images, and the images address points to mySecondServer.

Hope that helps,

Joseph

In reply to Joseph Rézeau

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Thank you Joseph for your detailed process.
I did it but what you write
> 5- Result: your labels are displayed with their images, and the images address points to mySecondServer.
is only partially correct.
It is true: my labels are displayed correctly with their images but... the image address points to myFirstServer
So, the label is displayed correctly only because the myFirstServer is turned on.

Do you agree?
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Daniele,

I have found that links work as you require when the image file is uploaded to the files area in advance and then inserted using the HTML Editor toolbar icon functionality.

If the browse and upload options displayed when the Insert Image icon on the HTML Editor toolbar are used to upload the image to the files area then the links remain absolute.

If anyone else has found this, it's probably time to enter it a s a bog.
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Thank you Ray.

Actually the problem is quite delicate.
To fix our ideas, let me say I want to add myPicture.gif to the course ID=50.
If I store the picture inside the folder 50 and than I backup and restore the course to a different server... most probably my restored course ID will change to a different value so... my image path will become incorrect.

To face this problem I can choose to save my picture into the moddledata/1 folder... but the HTML editor toolbar doesn't allow me to point an image file that is not in the folder of the course (/50) so... I need to write the path manually: moodle/file.php/1/myPicture.gif... and the backup... will not work any more because it doesn't include the 1 folder.

I believe I'll give up.
I feel the problem is bigger than I thought. Any ideas?
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Hi Daniele,

The example you mention is exactly the one I have encountered. In my experience NOT uploading via the HTML editor (see below) solves this issue. Upload the image files separately to the files area and THEN insert using the HTML editor. I've done this a lot lately with labels and it works. smile

Attachment upload.png
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
explain me better.
> Upload the image files separately to the file area
whre? into "1" folder or "50" folder?

"50" folder, I believe... otherwise the backup doesn't work.
"50" folder, I believe... otherwise the HTML editor doesn't "see" it.
Did I understand it correctly?

I go to try it now.

No! I tried it now and it doesn't work.
I am creating a course on my own local mac and I upload the file through the file system (by dragging the icon).
Then I inserted the image into a course label through the HTML Editor buttons but... the written path is absolute.
Maybe is this a problem of the Macintosh html editor? shy


In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
"50" folder, I believe... otherwise the backup doesn't work.

Yes, that's what I meant.

Try this backup file... from 1.5.3+ to 1.6 (different server and domains) with no problems. From course 28 to course 8.

In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Hei the restore of your course is working fine. smile
You destroyed my thesis.
So... which was the reason of my mispointing path?
I try to investigate more.
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
on the basis of your intervention and of the Joseph's one, I did this:
I made a bakup of a previous created course.
I restored the copy to my own PC.
I removed houndred of MBytes of resources.
I added a label with two istances of the same image, one from folder 1 and one from folder 66.
I made a backup.
I restored my backup to a far server.
I found that the bug was reproduced.
so,
I opened the moodle.xml file on my local PC and I found that the Joseph raccomandation is not verified into my backup.

What I founf is this:
    <SECTIONS>
      <SECTION>
        <ID>593</ID>
        <NUMBER>0</NUMBER>
        <SUMMARY>&lt;table border=&quot;1&quot;&gt; &lt;tbody&gt;
  &lt;tr&gt;
    &lt;td style=&quot;vertical-align: bottom;&quot;&gt;
      &lt;p class=&quot;t2Corso&quot;&gt;Img from folder 1:
      &lt;/p&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;p class=&quot;tCorso&quot;&gt;
        &lt;img title=&quot;orientarsi&quot; alt=&quot;orientarsi&quot; src=&quot;http://daniele-ure.local/%7Edaniele/moodle16/file.php/1/imgs/orientiamoci.gif&quot; border=&quot;0&quot; height=&quot;64&quot; hspace=&quot;0&quot; vspace=&quot;0&quot; width=&quot;64&quot; /&gt;
      &lt;/p&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td colspan=&quot;2&quot;&gt;
      &lt;hr /&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td style=&quot;vertical-align: bottom;&quot;&gt;
      &lt;p class=&quot;t2Corso&quot;&gt;Img from folder 66 (on my PC):
      &lt;/p&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;p class=&quot;tCorso&quot;&gt;
        &lt;img title=&quot;orientiamoci&quot; alt=&quot;orientiamoci&quot; src=&quot;http://daniele-ure.local/%7Edaniele/moodle16/file.php/66/risorse/orientiamoci.gif&quot; border=&quot;0&quot; height=&quot;64&quot; hspace=&quot;0&quot; vspace=&quot;0&quot; width=&quot;64&quot; /&gt;
      &lt;/p&gt;
    &lt;/td&gt;
  &lt;/tr&gt; &lt;/tbody&gt;
&lt;/table&gt;</SUMMARY>
Now, and only now by reaing the moodle.xml, I understand that what I call label... is not handled as a label from Moodle because it is the summary of the first argument of the course. May be this the reason of the problem/mismatch?

Waiting for your news. I do believe I did all I was able and supposed to test and do.

In the meantime I try to add the same "first argument summary" as a real label to test its behaviour during the restore process.
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Hi Daniele,

There are no labels in this back up only a forum. The images are in the summary of topic 0.

I assume that the course you were backing up was number 66 on your site. The back up will not include the files from Site Files because that is another course i.e. course 1 - course backups are course specific.
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
> There are no labels in this back up only a forum. The images are in the summary of topic 0.
Yes, this is what I noticed too.

> The back up will not include the files from Site Files because that is another course i.e. course 1 - course backups are course specific.

No... be carefull. I added two istances of the same picture. One from folder "1" and one from folder "66". So, I believe, that the picture from folder "66" should be restored.
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
One from folder "1" and one from folder "66". So, I believe, that the picture from folder "66" should be restored.

Yes, indeed. From the backed up course (66) not from course 1 though.
In reply to Ray Lawrence

Re: special labels

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Daniele,
I confirm what Daniele says, there are no labels in this backup file: backup-persstudy-20060710-0839.zip
Joseph
In reply to Joseph Rézeau

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
I do confirm it, too.
I thought the key of the problem was in the difference between "label" and "course summary" as I wrote in red... but this is not true.
I made a second post with the same "HTML code" into the course summary and into a label but... the problem is still alive.
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
I added the same "html code" to a real label... and the bug is still where it was.
Try the attached backup of my second trial.
I still have the same problem.
I thought the difference between "argument summay" and "label" was the key of this problem but... this is not true. sad
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Did you start from the beginning with this or did you just cut and paste? (The label and summary are identical).

I updated the link to this on my test site (course 30).

In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
I just made a copy and paste from the "topic 0 summary" HTML editor to the label HTML editor.

> I updated the link to this on my test site (course 30)
What does it means? Did you reproduce the problem/bug with my course bakup?
Maybe I am not undestanding in deep of what you wrote.
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
To update the image path I did the following:
  • Opened the label for editing
  • Clicked where the placeholder for the missing image was
  • Clicked on the Insert Image icon in the HTML tool bar
  • In the pop up window, clicked on the link which is the name of the image file I wanted to insert (from the Course files pane in this pop up)
  • Clicked OK
  • Save changes

In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
> To update the image path I did the following:
So... this means that you found my same problem!!!
Did you find it on the picture coming from folder "66"?

If you found it too, well: this is my problem and I can't find a way to workaround it.

Why was your backup well written and not my one?
Whare is the difference between mine and yours?
Please let me understand?
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Please explain step by step how you insert an image into a label (or anywhere else you use the HTML editor).

What are your slasharuments settings? (Admin > Variables)

In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
first:
> Please explain step by step how you insert an image into a label
1. select "Insert a label" from the "Add a resource" menu;
2. push the frame button from the HTML button bar
3. select my picture file
4. add an alternate text
5. push the ok button
6. save changes from the main window

Why do you believe the way to enter html code is important?

Second:
- my slasharguments on my local PC is file.php/1/pic.jpg
- my far production server has: file.php/pic.jpg
May be this THE problem?
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Steps: This seems ok to me.
Slasharguments:  Let us know when you've experimented with the settings. smile
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
PLEASE LET ME UNDERSTAND!!!!!!!!!
Into my production server I have slasharguments = "file.php/pic.jpg"
I made a backup of the course of "our" working course and I got this:
if (slasharguments == "file.php/pic.jpg") {
  /* so if I make a backup from my production server */

  if the img src filepath points to an existing file {
    moodle.xml is well written so (src=&quot;$@FILEPHP@$/risorse/orientiamoci.gif&quot;)
  } else {
    moodle.xml is NOT well written so (src=&quot;http://www.eduiss.it/file.php/1/imgs/orientiamoci.gif&quot;)
  }
} else {
  /* so if I make a backup from my local PC */
  moodle.xml is NEVER well written so (src=&quot;http://www.eduiss.it/file.php/1/imgs/orientiamoci.gif&quot; or
src=&quot;http://www.eduiss.it/file.php/66/imgs/orientiamoci.gif&quot;)
}

This is what I read. I didn't try to restore the backup because I believe moodle.xml content is enought to understand the outcome of the restore.

How can I change my slasharguments? What does slasharguments depends from?
Why haven't I the option "file.php/pic.jpg" into my local PC for slasharguments?
On my local PC I only have "file.php?file=/1/pic.jpg" as first option and "file.php/1/pic.jpg" as second one.


I read http://docs.moodle.org/en/Installation_FAQ#Uploaded_files_give_.22File_not_found.22

but i didn't find answers to my problems!!!!!!!!
In reply to Daniele Cordella

Re: special labels

by Paolo Oprandi -
Daniele,
Slash arguments is a field variable in your admin -> configuration -> variables -> operating system page.
I haven't had time to follow your discussion completely, but when restoring a course on a new server I search the moodle.xml file and replace all instances of the old server address (wwwroot) with the new server address and rezip making sure that the permissions on the file are the same, however, I agree that the links to internal site files (or modules, as discussed here) should always be relative.
Ciao, Paolo
p.s.I dont think you've mentioned what version of Moodle you are using.
In reply to Paolo Oprandi

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Ciao Paolo (are you italian?)
I am using 1.6+
and I am investigating to have a backup process doing automatically what you explain in detail.
I believe something is not perfectly working or is not clear enought.
In reply to Daniele Cordella

Re: special labels

by Paolo Oprandi -
Ciao Daniele,
Si, sono mezzo Italian e mezzo inglese.
Penso che deba andare al tuo wwwroot/admin/config.php ed cambiare slasharguments.
Paolo
In reply to Paolo Oprandi

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Thank you Paolo.
I have no idea about slasharguments options.
Do you know:
1) where can I find information about
2) why do slasharguments can assume a strange values, different from its best?
In reply to Daniele Cordella

Re: special labels

by Paolo Oprandi -
I don't know the answer to either of your questions, but I have seen several threads about it in the past. It could be that slashargument's best is different on your first and second server due to different configurations?

If you haven't already, I should try changing slasharguments to the 'other' option and seeing if it solves your problem.
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Hei Ray
any other suggestion?
In reply to Daniele Cordella

Re: special labels

by Ray Lawrence -
Sadly not.  sad

I noticed that you've been using 1.6+. I'd not been using this version to create my backup files but I've just tested this with 1.6+ and it still works fine for me (try the file attached).

(if you have a moment try restoring to a new course when logged in as a course creator and see if you are successful - I get an error message when logged in as a course creator, if you do too can you comment on bug 6084)
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Happly yes.
Yesterday the particularly helpful Moodlers Andrea Bicciolo found the solution.

The problem was due to an unencoded char I had into my $CFG->wwwroot.
During the backup process Moodle try to parse the path it founds into src images of labels with the content of the variable $CFG->wwwroot.
But if the variable has a unencoded char in the config.php file, Moodle is not able to recognize the $CFG->wwwroot into the label path so it doen't substitute the path with $@FILEPHP@$.

Example:
I had:
$CFG->wwwroot = 'http://daniele-ure.local/~daniele/moodle16'
and into my scr picture labels I had:

This was not allowing Moodle to work properly. Moodle didn't recognize the path and didn't replae it.

I changed my $CFG->wwwroot into my config.php file to 'http://daniele-ure.local/%7Edaniele/moodle16' (alias I encoded it) and... the problem doesn't exist any more.

Grazie Andrea per il tuo fondamentale contributo.
In reply to Ray Lawrence

Re: special labels

by Steve Power -

Ray

Do you have to do this to images once you have restored a backup to a new course? If so this is what I have described as a failure of the backup/restore process. Having to visit every image in a course to relink it is not really ideal.

I am sorry I have not had a chance yet to look into the structure of the backups I have created and used.

Regards
Steve

In reply to Steve Power

Re: special labels

by Ray Lawrence -
Hi Steve,

Do you have to do this to images once you have restored a backup to a new course? If so this is what I have described as a failure of the backup/restore process. Having to visit every image in a course to relink it is not really ideal.

No, not normally. Only to fix problems restores. As mentioned earlier, we have encountered this when uploading a file and linking all from within the HTML editor as absolute links were created (I don't know why, we just stopped doing things that way and the issue went away).

In reply to Daniele Cordella

Re: special labels

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Daniele >Then I inserted the image into a course label through the HTML Editor buttons but... the written path is absolute.

What makes you say that the image path is absolute? Of course it is absolute when you look at it when viewing your course. But could you check that it has been made relative in the backup XML file.

Example (with an image called 2006.jpg inside a label)

1- Server 1 (http://cursus.uhb.fr, my university)

<img src="http://cursus.uhb.fr/file.php/464/JR/images/2006.jpg" />

Course is then backed up.

2- Inside backup XML file:

...
<MODULES>
  <MOD>
    <ID>847</ID>
      <MODTYPE>label</MODTYPE>
      <NAME>a sample label with image:
      </NAME>
      <CONTENT>&lt;img src=&quot;$@FILEPHP@$/JR/images/2006.jpg&quot; /&gt;</CONTENT>

    <TIMEMODIFIED>1152280048</TIMEMODIFIED>
  </MOD>
</MODULES>
...

3- Restored on my local installation
<img src="http://localhost/moodle16/moodle/file.php/37/JR/images/2006.jpg" />

Do you get the $@FILEPHP@$ in your backup file? If no, what do you see there?

Joseph

In reply to Joseph Rézeau

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Yes, this  is what I get by backing up the Ray's course once restored to my local PC.
    <MODULES>
      <MOD>
        <ID>250</ID>
        <MODTYPE>label</MODTYPE>
        <NAME></NAME>
        <CONTENT>&lt;img width=&quot;265&quot; vspace=&quot;0&quot; hspace=&quot;0&quot; height=&quot;127&quot; border=&quot;0&quot; title=&quot;upload&quot; alt=&quot;upload&quot; src=&quot;$@FILEPHP@$/upload.png&quot; /&gt;&lt;br /&gt;</CONTENT>
        <TIMEMODIFIED>1152280561</TIMEMODIFIED>
      </MOD>
    </MODULES>

Ok, is seems that you and Ray are definitly proofing the error I raised up doesn't exist. thoughtful
I am going to attach to my next post the part of the course that generates my described error when I do make a backup on my local PC and a restore to a far production server.
In reply to Joseph Rézeau

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Hi Joseph
I added two post with a course backup attached. Both of them don't use the $@FILEPHP@$ variable. See the answer to Ray in this thread.
In reply to Ray Lawrence

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
And then...
if you restore a course in which labels are pointing to not existing files (src="http://myFirstServer/moodle/file.php/50/myPicture.gif")... Moodle doesn't allow you to change the path manually into labels because Moodle doesn't save changes when a picture path is incorrect... locking the course into an hybrid status. I fall into in this situation and I escaped by changing mySQL tables directly.
In reply to Ray Lawrence

Re: special labels

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Ray,

I've just tried inserting an image in a label through uploading the image via the HTML Editor, then done a backup and restore of the course with that label from server1 to server2, and the image gets its new relative address OK.

I see no reason why things should behave differently: if an image is uploaded from the HTML interface, it is really uploaded to the current Files folder of the current course, this is no different from uploading it separately through Administration/Files/Upload a file.

So as far as I can see there is no need for a bug report here.

Joseph

PS I still do not understand the reason for Daniele's problem.

In reply to Joseph Rézeau

Re: special labels

by Ray Lawrence -
I see no reason why things should behave differently...

Nor do I, but this solved the problem we were having.
In reply to Joseph Rézeau

Re: special labels

by Steve Power -

Joseph

Labels are stored differently in the database than "html" pages.

I have exactly the same problem that Daniele describes when I move courses from my development server to my production server (and the other way). I believe it is because moodle stores the links as absolute rather than relative and this absolute storage involves both the url of the site and the course/user id.

If the database is moved in its entirety with a backup and restore I use an sql script to rename all links in web pages. As I said Labels are stored differenmtly and I have not managed to script changes of these as yet.

If a course is backed up and restored to a new course on the same server the links in the new course refer to the original. I did this most recently to split a course by making a duplicate and then removing elements of the original. When this is done the links in the copy course stop working bacause the resourse referred to is in the original course.

Re reading that I think I may just have muddied the water I was trying to help clear smile.

Regards
Steve

Edit

Just seen Ray's post come in and re-read your post Joseph. I had mis read your post and though you were talking about the issue I was puzzling over!

In reply to Steve Power

Re: special labels

by Ray Lawrence -
Hi Steve,

If a course is backed up and restored to a new course on the same server the links in the new course refer to the original. I did this most recently to split a course by making a duplicate and then removing elements of the original. When this is done the links in the copy course stop working because the resource referred to is in the original course.

That shouldn't be the case.... Could you try restoring the course attached here?

Ray

Edit: Just musing, this isn't a slashargumants issue is it?
In reply to Joseph Rézeau

Re: special labels

by Daniele Cordella -
Picture of Core developers Picture of Plugin developers
Thank you Joseph.
I did a lot of times what you suggest but... my problem is that into my backup moodle.xml the <CONTENT> tag doesn't contain the $@FILEPHP@$ into the src attribute but the real absolute path (http://myFirstServer/bla bla bla).

I did the same backup process on a different sever with different slasharguments value and... there the bakup process worked properly.

Here I am. What do I have to do with slash arguments? Which is the list of their possible values? What do they change into moodle except this behavior? (see this post)

Is this really a slasharguments related problem or not? Is this problem ONLY a slasharguments related problem?
Here I am.

Any suggestion is welcome.