? Success

User tests: Successful: Unsuccessful:

avatar addondev
addondev
20 Jul 2015

I think, it would be reasonable to start an image path with a slash. When I developed an extension, I found that the links which had been added in the frontend declaration from the media manager were interpreted by JavaScript as relative. As a result, I got 404 errors, because the paths to the files were incorrect.

avatar addondev addondev - open - 20 Jul 2015
avatar addondev addondev - change - 20 Jul 2015
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 20 Jul 2015
Labels Added: ?
avatar brianteeman
brianteeman - comment - 20 Jul 2015

And what happens if Joomla is installed in a subdirectory?

avatar Fedik
Fedik - comment - 20 Jul 2015

@addondev your fix is incorrect, as @brianteeman mentioned, your changes will break images for the sites located in subdirectory ... and there no need any changes at all, "System plugin SEF" will replace it to the right path ...
I think you did something wrong in your extension

avatar brianteeman
brianteeman - comment - 20 Jul 2015

Closing

avatar brianteeman brianteeman - change - 20 Jul 2015
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2015-07-20 07:57:44
Closed_By brianteeman
avatar brianteeman brianteeman - close - 20 Jul 2015
avatar brianteeman brianteeman - close - 20 Jul 2015
avatar addondev
addondev - comment - 20 Jul 2015

"System plugin SEF" will replace it to the right path ...

No, it will not. And all the relative links are interpreted as relative ones.

avatar addondev
addondev - comment - 20 Jul 2015

I think the SEF plugin does not work if you do the following:

$image = $this->params->get("image_src");
JFactory::getDocument()->addScriptDeclaration("
    var image = new Image();
    image.src = '$image';
");
avatar Fedik
Fedik - comment - 20 Jul 2015

@addondev true, here SEF plugin do not work,
but as it the part of your extension, then I see no problem to attach the right image path,
eg: JUri::root(true) . '/' . $image :smile:

avatar brianteeman
brianteeman - comment - 20 Jul 2015

but your extension will still break if it is used with joomla in a
subdirectory

On 20 July 2015 at 12:47, Fedir Zinchuk notifications@github.com wrote:

@addondev https://github.com/addondev true, here SEF plugin do not
work,
but as it the part of your extension, then I see no problem to attach the
right image path,
eg: JUri::root(true) . '/' . $image [image: :smile:]


Reply to this email directly or view it on GitHub
#7478 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar addondev
addondev - comment - 20 Jul 2015

but as it the part of your extension, then I see no problem to attach the right image path,
eg: JUri::root(true) . '/' . $image :smile:

@Fedik, yes, this would be a solution if a user could not directly enter a link in a field. Imagine, a user enters a link http://mysite.com/image.jpg. The output will be the following:

$image = "http://mysite.com/image.jpg";
$path = JUri::root(true) . '/' . $image;
echo $path; 

Output: subdir/http://mysite.com/image.jpg

img

@brianteeman
I see this point. Therefore, I think we should find a different solution. I have reported a bug, you can think how to fix it.

Sorry for any inconvenience.
Yours faithfully,
Philip Sorokin.

avatar brianteeman
brianteeman - comment - 20 Jul 2015

Sorry but thats not how it works.

On 20 July 2015 at 15:07, Philip Sorokin notifications@github.com wrote:

but as it the part of your extension, then I see no problem to attach the
right image path,
eg: JUri::root(true) . '/' . $image [image: :smile:]

@Fedik https://github.com/Fedik, yes, this would be a solution if a
user could not directly enter a link in a field. Imagine, a user enters a
link http://mysite.com/image.jpg. The output will be the following:

$image = http://mysite.com/image.jpg;
$path = JUri::root(true) . '/' . $image;
echo $path;

Output: subdir/http://mysite.com/image.jpg

[image: -1]
https://cloud.githubusercontent.com/assets/11632367/8777448/b450cc7c-2f00-11e5-8f3c-f58f4e5ab763.jpg

@brianteeman https://github.com/brianteeman
I see this point. Therefore, I think we should find a different solution.
I have reported a bug, you can think how to fix it.

Sorry for any inconvenience.
Yours faithfully,
Philip Sorokin.


Reply to this email directly or view it on GitHub
#7478 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar addondev
addondev - comment - 20 Jul 2015

@brianteeman, could you, please, recommend me a solution? Can I ask you to explain what you mean saying that it works in a different way, because I can directly enter any URL in the field.

avatar Fedik
Fedik - comment - 20 Jul 2015

Imagine, a user enters a link http://mysite.com/image.jpg.

difficult to imagine the reason for this, if it not the external image :smile:

Note:
When work with images in Joomla, keep in mind that all paths is relative to the root, this will save you a lot of time

upd: in your case just add check for external resource before call JUri::root(true) . '/' . $image;

avatar addondev
addondev - comment - 20 Jul 2015

Note:
When work with images in Joomla, keep in mind that all paths is relative to the root, this will save you a lot of time

I keep in mind that, but I am not sure a user does. A user can enter any url with or without a protocol and hostname. Indeed, I had to add in my script a regular expression operation to parse the incoming URL, but I think it is not clear and looks like a hack.

avatar brianteeman
brianteeman - comment - 20 Jul 2015

Why are you parsing the URL at all

avatar addondev
addondev - comment - 20 Jul 2015

Why are you parsing the URL at all

Because I need to be sure that the incoming URL is not a relative one. JavaScript will add to the relative path a protocol, host and subdirectory:

echo "relative/path/image.jpg";

JavaScript will interpret the URL like this:

http://mysite.com/current/directory/current/subdirectory/relative/path/image.jpg

instead of

http://mysite.com/relative/path/image.jpg
avatar brianteeman
brianteeman - comment - 20 Jul 2015

Then thats a problem in your javascript and not the core.

Everytime you store a url in the database with an absolute path like that
you make it impossible for user to move the site to another domain or
location (just like wordpress does).

This really is not a core problem - sorry.

On 20 July 2015 at 17:09, Philip Sorokin notifications@github.com wrote:

Why are you parsing the URL at all

Because I need to be sure that the incoming URL is not a relative one.
JavaScript will add to the relative path a protocol, host and subdirectory:

echo "relative/path/image.jpg";

JavaScript will interpret the URL like this:

http://mysite.com/current/directory/current/subdirectory/relative/path/image.jpg

instead of

http://mysite.com/relative/path/image.jpg


Reply to this email directly or view it on GitHub
#7478 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

avatar addondev
addondev - comment - 20 Jul 2015

Then thats a problem in your javascript and not the core.

OK. I understand your point, but I think there is a proplem in JavaScript, not in my JavaScript. Because I cannot prevent it from adding a protocol and a host to a relative path.

I understand your point and apologize for disturbing you.

avatar addondev
addondev - comment - 21 Jul 2015

Dear participants,
I think, I have found another solution. Can I make a new pull request to discuss this issue?

avatar brianteeman
brianteeman - comment - 21 Jul 2015

of course

On 21 July 2015 at 12:22, Philip Sorokin notifications@github.com wrote:

Dear participants,
I think, I have found another solution. Can I make a new pull request to
discuss this issue?


Reply to this email directly or view it on GitHub
#7478 (comment).

Brian Teeman
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/

Add a Comment

Login with GitHub to post a comment