Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relative URLs and Ckeditor
#1
I'm building a site locally on my PC (XAMPP) which I then want to move onto the server once it's working as required. The wiki rightly suggests that I should use relative URLs. However, ckeditor insists on giving full URLs for inserted images - so they all refer to http://localhost/ which won't work when uploaded to the server.

Is there any way to configure ckeditor (and particularly the "Browse Server" part of loading an image) to use relative URLs? Or do I have to always switch to source view and change the URLs manually?

Thanks for any help.
Reply
#2
Try with basehref
http://docs.cksource.com/ckeditor_api/sy...#.baseHref
Addons: blue business theme, Online Visitors, Notepad
Reply
#3
Alternatively, if you know what domain it will run on once you're ready:

go to your hosts file in C:\Windows\System32\drivers\etc\ and add a line like this:

Code:
127.0.0.1 domainname.com

Then install / configure GetSimple with this url and you can still use it while trying it out locally.
When you're ready to upload, remove it from your hosts file and install as normal! Smile
gSvoren Design - http://gsvoren.net
Reply
#4
I tried with baseHref, either in gsconfig.php or on the custom config-file

both times it did not work
there are only postings in the ckeditor forum where it does not work
I keep on searching
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#5
Thanks for the replies. I tried setting baseHref, but it didn't work for me either. So it looks like I'll have to use the hosts file method.
Reply
#6
Try with a different approach.
Just do a batch edit of all pages, and change the links inside them.
You can use on of below apps, or search for other batch find->edit file editors
http://www.multiplefindreplace.com/
http://download.cnet.com/Multiple-Text-F...09910.html

have fun Wink
Addons: blue business theme, Online Visitors, Notepad
Reply
#7
I just ran in to this problem too and I finally figured out a reasonable workaround with a little help from this forum post (http://get-simple.info/forum/topic/487/c...-ckeditor/)

in edit.php the default baseHref for CKEditor has been set $SITEURL

The actual problem isn't with CKEditor but with the image browser which resolves the image path separately. What you need to do is change line 23 in filebrowser.php to match the default that is set in edit.php, like so:

previous line 23:
$sitepath = suggest_site_path();

new line 23:
$sitepath = $SITEURL;

Now when I set my site url to '/', I get the correct image links when I drop them in to CKEditor with the browse tool. This saves having to do the tedious batch replace method suggested by yojoe Smile

Edit: And when you do that, any baseHref that you may have added to the CKEditor config file will now be applied as expected since the image url no longer contains http://yourdomain.com/...
Reply
#8
Hello LogicalOctopus,

you are a real nineOpus ;=)

That is a great information you gave us. I will add this to the WIKI / Editor edition and I will describe it in our tipps'n'tricks-section at get-simple.de (referring to your post for sure)

Thanks a lot!

Cheers, Connie
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#9
I am glad someone found that useful Smile
Reply
#10
I tested without success:

filebrowser.php:
Code:
$sitepath = $SITEURL;

in gsconfig.php:
Code:
define('GSEDITOROPTIONS', "baseHref : 'http://www.domainname.de/folderofGetSimple/', forceSimpleAmpersand:true,customConfig : '../../../../theme/gs.js',skin: 'v2'
");
Quote:Now when I set my site url to '/'
where? I think this is my problem ;=(

did I miss something?
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#11
I think he means in admin/configuration Connie

I test it (just filebrowser.php and my config url in relative in local) and it seems to work when I transfer the test page online (got a relative url on edit and the correct url front-end)

now that might deserve further testing because I didn't update filebrowser.php on my server web, nor I'd had put option on gsconfig.php...
plus the two site are in a folder with the same name and at the same level of their root

I leave you to more testing, I just come here by seeing something about relative url and I knew you could do them with link, so i read and test
Sorry my English is poor, I'm working on it
Reply
#12
Hello,

I think I've cracked this small but important issue with image paths being relative from within CKEDITOR.

The key to this issue was confirmed to me in LogicalOctopus statement.

Quote:The actual problem isn't with CKEditor but with the image browser which resolves the image path separately.

When you select an image after clicking the "Browse Server" button the full URL path was transferred into the image dialog box. CKEDITOR just used whatever was in the box and placed it in the source code.

The solution that I found but may need to be tested by others for confirmation.

Change line 24 of filebrowser.php from

$fullPath = $sitepath . "data/uploads/";

to

$fullPath = "data/uploads/";

I know line 23 was mentioned but changing line 24 so the $sitepath was omitted completly seemed to work great.

No other changes need to be done to GS. Leave all config files as they are in repsect to baseurl etc.

This solution is not "Upgrade friendly" but it seems to work in both Admin and Frontends of LOCALHOST and Live Domains (and I imagine if GS was installed into a subfolder).

I don't know if there could be a more permanent solution or if there is another reason why $sitepath was added to this line in filebrowser.php. All my testing seems to indicate that having a relavtive path is better than hardcoding the full site's URL in the source code.

I noticed that 3.1 also has this line in filebrowser.php (line 26)

On a sidenote using CKEDITOR with CKFINDER places a relative URL in the Source code which works both in LOCALHOST and the live domain.

Let me know if this works on other peoples environments.

I think moving GS websites around from local PC's, demo locations and Live Domains etc is fairly common and just being able to ZIP up the whole thing an locate it elsewhere fully in-tact without doing a massive Find and Repalce for every image or PDF link could be very handy.
Reply
#13
stryker Wrote:Change line 24 of filebrowser.php from

$fullPath = $sitepath . "data/uploads/";

to

$fullPath = "data/uploads/";

I think this will only work with fancy URLs off, if the path does not start with a slash.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#14
Hi mvlec,

I had the fancy URL's ticked when trying this solution. Just unticked it to see what would happen and still seem to keep the image path intact and image displayed OK in ADMIN and Front end.

Interesting to see if other issue surface though because of this change?
Reply
#15
stryker Wrote:I had the fancy URL's ticked when trying this solution.

Does it really work with second level pages with URLs like /parent-page/child-page?
Top level pages won't be a problem.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#16
Still a bit new to GS when it comes to "Parent / Child" pages. Logically looking at it if you had a child page at http://domain.com/parent/child.html then having an image path src="data/uploads/image.jpg" wouldn't work so in this scenero it may not be suitable. I tried creating this type of stucture but probably missing something somewhere.

All my pages load from the root directory and I am using the following settings.

Fancy Url's in the settings area as well as the following Permalink structure set as "%slug%.html". I have the following statement in my .htaccess file.

RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]

For my localhost config I also have the following statement in my .htaccess file
RewriteBase /folder/

which I change to "/" when moving to the live domain.

These settings are from the Wiki I believe

I don't know if having a parent / child structure is mainstream but if your pages are just loaded from the root directory then the relative path should work OK.

I'll keep on testing and see if there are any more issues / ramifications because of this change.
Reply
#17
Quote:I don't know if having a parent / child structure is mainstream but if your pages are just loaded from the root directory then the relative path should work OK.

your structure is not so unusual ;=) I guess 99% sites use more than one level...

as long as we don't find a way to tell CKeditor the root-directory and it can construct the paths in relation to that absolute URL, you will need absolute paths for the images

you will notice that when you add an internal link in the editor, that link gets translated to an absolute path as well

so you should not waste your time investigating GS, better try to find a solution at ckeditor-website / documentation / forum and if you find a solution, suggestion there, test it and tell us the result

I will be very happy with a working solution, but the clue lies in a configuration of the editor, not in GS
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#18
It seems to work for me OK but I suppose there are a lot of scenerios where the relative path may not work and I didn't think of internal links that will need to get changed manaully as well.

Will see how it goes and if I come accross anything in CKEDITOR I will comment here.
Reply
#19
AFAIK CKEditor inserts the given URL always verbatim, i.e. it doesn't transform the URL as e.g. tinyMCE does depending on the settings for "relative_url", "convert_urls", "remove_script_host" etc. You might check this by transforming the URL returned from the filebrowser manually.

If so, it seems the filebrowser has to be modified. And, without testing, strykers suggestion to remove $sitepath from $fullpath seems reasonable, if this works in admin and normal mode. Probably it should work even if GetSimple is installed to a subfolder of the webroot (perhaps CKEditor's baseHref has to be set accordingly).
Reply
#20
Edit: I recommend against doing the following, it's more a hack than anything and it seems to break custom field image paths.

This was annoying me too but I managed to force paths only for both images AND local links.

So instead of
Code:
<a href="http://domain.com/about/team/">Our Team</a>
<img src="http://domain.com/data/uploads/image.jpg">
I get
Code:
<a href="/about/team/">Our Team</a>
<img src="/data/uploads/image.jpg">
Unfortunately it involved editing core files (filebrowser.php and template_functions.php) and I'm pretty sure this will only work if your install is a root install (not in a folder). Surely a minor tweak could remedy this though.

Anyway, to fix image paths, in /admin/filebrowser.php
Code:
25. --- $sitepath = suggest_site_path();
25. +++ $sitepath = tsl(suggest_site_path(true));
...and to fix links to local pages, in /admin/inc/template_functions.php
Code:
726. --- array_push($pageList, array( $dash . $page['title'], find_url($page['url'],$page['parent'])));
726. +++ array_push($pageList, array( $dash . $page['title'], find_url($page['url'],$page['parent'],'abs')));
Modern UI Admin for GetSimple
Watch the demo. Install this plugin. Use this CSS. Enjoy.
Reply
#21
Hello my friends,

My question is if anyone, through last years has found a solution for the problem mentioned in this topic ?

I am looking for the best solution, so I would not have to put absolute paths in my img src fields.

Have a nice day...
Reply
#22
There is actually another thread on this issue, with solutions, more recent than this.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#23
There are also some plugins that filter the urls after the fact.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#24
I think you can use one of these plugins:

http://get-simple.info/extend/plugin/ts-...lacer/799/

http://get-simple.info/extend/plugin/ts-...lacer/801/

Don't know exactly what the difference is, but there's a small description about it on the support forum of ts-fastreplacer: http://get-simple.info/forums/showthread.php?tid=6221

Maybe this plugin is also relevant:
http://get-simple.info/extend/plugin/abs...fixer/743/
Reply




Users browsing this thread: 1 Guest(s)