7

Im using CKeditor however i test it on a staging environment. Then i move it to production. The problem is when im linking i dont want to use mysite.com because then it will only work on staging or production but not on both. Instead i would like to use my basepath php variable which will auto determine to use mysite.com/ or staging.mysite.com

Is there any way to do this with the CKeditor URL link option. I have tried setting it to:

/myfolder/mypage.php

Using the other protocol, however it sets the URL as http///myfolder/mypage.php

Is this possible or is there an addon that can do this for me?

My config.js file as requested:

CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
};

I did find out how to change the basepath for Ckeditor but this is just where ckeditor install path is, i need to set a different path which is just the basepath

Just to clarify as a picture speaks a thousand words and all:

Its this create a link option in the Ckeditor toolbar that allows you to create a URL link that i am referring to

enter image description here

user1547410
  • 863
  • 7
  • 27
  • 58

5 Answers5

2

Have a look at this page of the ckeditor documentation.

Here they say that you can set the basepath using this syntax:

<script>
    var CKEDITOR_BASEPATH = '/ckeditor/';
</script>    
<script src="all_my_scripts.js"></script>

I don't really understand what your issue really is. If you just set the basepath as a relative path like this you will never need to change it changing the environment. Just replicate the folder structure between development and production!

Alex
  • 8,461
  • 6
  • 37
  • 49
Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
  • Isn't that the ckeditor basepath? I am referring to the toolbar option which allows you to create a URL link in the editor. When you select that there are a couple of different URL protocols, email, url, ftp I want to link to a URL lets say google.com/mypage/1. But im testing on staging.google.com so in staging the link is broken. I am hoping for a way to add a new custom protocol that will allow me to link to = basepath ?>/mypage/1 I apologize i havent explained it the best. Feel free to ask more questions if i can help.Maybe there is an add on that does this but i couldnt find it – user1547410 Oct 26 '15 at 19:48
2

I know this isn't ideal as it's a hack, but you can go to ckeditor/plugins/link/dialogs/link.js find this in the code:

label:i.protocol,"default":"http://",items:[["http://‎","http://"],["https://‎","https://"],["ftp://‎","ftp://"],["news://‎","news://"],[b.other,""]]

Then just add another option in the items array like ["Base URL","/"].

I did find this solution that may also suit your needs: http://ckeditor.com/forums/CKEditor-3.x/internal-pages-dropdown-link-dialog

Hope that helps.

Michael
  • 2,016
  • 5
  • 35
  • 51
1

Set the 'baseHref' of the ckeditor configuration to the current url of the environment you are currently on , 'http://staging.google.com' for instance . You can start using links relative to such path in your editor. If for instance you have url pointing to an image 'http://staging.google/images/example.jpg' you just insert '/images/example.jpg' in the editor and this should display the actual image. Hope this helps.

Wakeel
  • 4,272
  • 2
  • 13
  • 14
1

I believe Mario Wakeel has the nearest answer so far (note that you need to be looking at baseHref and not basePath):

http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-baseHref

If you need to set this variable programmatically, I'm guessing you'd need to use some simple server-side code to check which domain the editor is being accessed from (before the config is loaded).

Morris
  • 218
  • 1
  • 10
1

If you take a look at the ckeditor.js you will see this line:

Please set the global variable "CKEDITOR_BASEPATH" before creating editor instances.

So if you want to set the base path so that all upload file and link have the correct path, just prepend this line into ckeditor.js file

CKEDITOR_BASEPATH=your_relative_path

or you can set global variable like this

var CKEDITOR_BASEPATH = your_relative_path;

before you include ckeditor.js

thinh.lam
  • 288
  • 4
  • 10