Links in javascript

0

Good morning, I'm having a problem when calling a link in javascript, in php I have a rule where everytime I put # URL # link .... it replaces it with the server address. Example # URL # public it replaces for link , in javascript I could not get it to work. If anyone can give me a help, I'll put my rule in php, and below the javascript where I need to adjust.

php.config

date_default_timezone_set('America/Sao_Paulo');
error_reporting(E_ALL);
ini_set('display_errors',true);
define('URL','http://'.$_SERVER['HTTP_HOST'].'/sistema/');
define('DS', DIRECTORY_SEPARATOR);
define('PATH', getcwd().DS );
define('TEMPLATE', PATH.'view'.DS.'template.html');

Javascript that needs to be adjusted

CKEDITOR.editorConfig = function(config) {
    config.filebrowserBrowseUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/browse.php';
    config.filebrowserImageBrowseUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/browse.php?type=images';
    config.filebrowserFlashBrowseUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/browse.php?type=flash';
    config.filebrowserUploadUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/upload.php?type=files';
    config.filebrowserImageUploadUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/upload.php?type=images';
    config.filebrowserFlashUploadUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/upload.php?type=flash';
};
    
asked by anonymous 02.03.2016 / 12:09

2 answers

0

I was able to solve it this way.

CKEDITOR.editorConfig = function(config) {
        config.filebrowserBrowseUrl = url+'public/plugin/ckeditor/kcfinder/browse.php';
        config.filebrowserImageBrowseUrl = url+'public/plugin/ckeditor/kcfinder/browse.php?type=images';
        config.filebrowserFlashBrowseUrl = url+'public/plugin/ckeditor/kcfinder/browse.php?type=flash';
        config.filebrowserUploadUrl = url+'public/plugin/ckeditor/kcfinder/upload.php?type=files';
        config.filebrowserImageUploadUrl = url+'public/plugin/ckeditor/kcfinder/upload.php?type=images';
        config.filebrowserFlashUploadUrl = url+'public/plugin/ckeditor/kcfinder/upload.php?type=flash';
    };
    
02.03.2016 / 13:35
1

On the page where the CKEditor script loads, put this

<script type="text/javascript">
ckeditor_global_url = <?php echo URL;?>;
</script>

Some other script that uses an equal name variable may conflict. So, in this example we use a name that would hardly conflict with another one in use.

Something more elegant and "secure" would apply namespace, but the example would become more complicated. If you are interested in improving your scripts, look for object-oriented javascript.

Continuing, in the CKEditor script, I would switch to this:

CKEDITOR.editorConfig = function(config) {
    config.baseHref = ckeditor_global_url;
    config.filebrowserBrowseUrl = 'public/plugin/ckeditor/kcfinder/browse.php';
    config.filebrowserImageBrowseUrl = 'public/plugin/ckeditor/kcfinder/browse.php?type=images';
    config.filebrowserFlashBrowseUrl = 'public/plugin/ckeditor/kcfinder/browse.php?type=flash';
    config.filebrowserUploadUrl = 'public/plugin/ckeditor/kcfinder/upload.php?type=files';
    config.filebrowserImageUploadUrl = 'public/plugin/ckeditor/kcfinder/upload.php?type=images';
    config.filebrowserFlashUploadUrl = 'public/plugin/ckeditor/kcfinder/upload.php?type=flash';
};

Here we just set a value for the config.baseHref property.

Finally, there are different ways to solve. As you have not given much detail on how your pages are, what the circumstances, etc., it is unfeasible to palpitate the best mode or at least which is the most appropriate mode for your case.

    
02.03.2016 / 12:54