Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url convert to relative url #249

Closed
phungthien opened this issue Aug 25, 2016 · 16 comments
Closed

Url convert to relative url #249

phungthien opened this issue Aug 25, 2016 · 16 comments

Comments

@phungthien
Copy link

phungthien commented Aug 25, 2016

Hello,

I have issue when using multiline to edit content. The issue happens when I switch Wordpress default visual editor to Text mode (like image below)

screen shot 2016-08-25 at 23 40 17

and add text (include links and images) to MF multiline and hit Update. However, when I tried to see the html code in multiline, all urls were converted to relative urls - my domain name was changed to ../ (as image below)

screen shot 2016-08-25 at 23 44 57

This issue only happens when I edit content in multiline while the Wordpress default editor is in Text mode (not happen with Visual mode chosen).

Please help me if you have any ideas on this.
Thank you,
Thien Phung

@simkea
Copy link

simkea commented Aug 26, 2016

i can confirm this!

Uncaught Error: TypeError: Cannot read property 'getContent' of null
error @ load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,utils&ver=4.6
(anonymous function) @ mf_field_base.js?ver=4.6:23
[...]

After Save: the URL from mediafiles is relative "../wp-content/..."

if i toggle the main content area from text to visual, i get this error message:
tinymce.min.js?ver=4401-20160726:9
Uncaught Error: Could not find control by type: wplinkpreview

-Wordpress Version 4.6
-MagicFields 2.3.3
-(no other plugins)

br

@phungthien
Copy link
Author

@simkea have you found out the solutions yet?

@hunk
Copy link
Member

hunk commented Aug 27, 2016

Hello @simkea and @phungthien, can you update the file field_types/multiline_field/multiline_field.js with this version https://gist.github.com/hunk/63874b7cb35c552b5a900904aeb2cbc6 and check again. remember you need to add the URLs again 😞 because of the previous version store the relative URLs.

@phungthien
Copy link
Author

Haha, it works!!!
@hunk, thanks so much for your fix 👍

@simkea
Copy link

simkea commented Aug 28, 2016

There is still this bug: here is my patch...

diff --git a/html/wp-content/plugins/magic-fields-2/field_types/multiline_field/multiline_field.js b/html/wp-content/plugins/magic-fields-2/field_types/multiline_field/multiline_field.js
index a183c1f..4cc0e74 100644
--- a/html/wp-content/plugins/magic-fields-2/field_types/multiline_field/multiline_field.js
+++ b/html/wp-content/plugins/magic-fields-2/field_types/multiline_field/multiline_field.js
@@ -42,7 +42,9 @@ jQuery.mf_bind('before_save',function(){
   if('undefined' != typeof tinyMCEPreInit){
     jQuery(".multiline_custom_field .pre_editor").each(function(){
       var editor_text = jQuery(this).attr('id');
-      jQuery(jQuery('#'+editor_text)).attr('value', tinyMCE.get(editor_text).getContent());
+      if(tinyMCE.get(editor_text)) {
+        jQuery(jQuery('#' + editor_text)).attr('value', tinyMCE.get(editor_text).getContent());
+      }
     });
   }
 });

@phungthien
Copy link
Author

Hi @simkea, what is that bug?

@simkea
Copy link

simkea commented Aug 29, 2016

Uncaught Error: TypeError: Cannot read property 'getContent' of null
error @ load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-sortable,utils&ver=4.6
(anonymous function) @ mf_field_base.js?ver=4.6:23
[...]

if you have a custom-field (multiline) and the native post textarea ->
if you now toggle to text-mode on post textarea and then save entry you get this javascript error.
the tinyMCE is unloaded and can not be find...

@phungthien
Copy link
Author

Ah, I see it.
Thanks @simkea 👍

@simkea
Copy link

simkea commented Aug 31, 2016

Okay... this solution: https://gist.github.com/hunk/63874b7cb35c552b5a900904aeb2cbc6
this snippet kills the native tinymce from wordpress, ... i removed this code again and now all is correct... only the relative path rewrite on after "save"

@simkea
Copy link

simkea commented Sep 1, 2016

Here is my Workaround to fix the error "relative urls"

File: wp-content/plugins/magic-fields-2/admin/mf_tiny_mce.php
if ( $teeny ) { $plugins = apply_filters( 'teeny_mce_plugins', array('inlinepopups', 'fullscreen', 'wordpress', 'wpdialogs') ); $ext_plugins = ''; } else { $plugins = array( 'inlinepopups', 'spellchecker', 'tabfocus', 'paste', 'media', 'wordpress', 'wpfullscreen', 'wpeditimage', 'wpgallery', 'wpdialogs' );

Remove the 'wplink' in the array... this tinymce-plugin is not compatible with MF2 an the moment...

in File: wp-content/plugins/magic-fields-2/admin/mf_custom_fields.php
Line 53:
$this->options['option'][$k]['value'] = $v;
Remove the @ from begin of line

Line 185:
</tfoot>
fix it from tfood to tfoot

@phungthien
Copy link
Author

@simkea I thought the last fix of @hunk was working.

@hunk
Copy link
Member

hunk commented Sep 4, 2016

Hi @phungthien, @simkea I think I got it, here is the ultimate fix 😂 https://gist.github.com/hunk/0e50800ce90f82f130c8d56ae05205f7

and I added the fix of @simkea for "Uncaught Error: TypeError: Cannot read property 'getContent' of null"

@simkea with this fix you will not have the problem with native TinyMCE from WordPress, you can switch visual/HTML mode without a problem.

Can you test this and tell me if it works?

@simkea
Copy link

simkea commented Sep 5, 2016

Yes it works! Great!

i recommend to change the Code in follow file:
and fix the two bugs in the other files...

in File: wp-content/plugins/magic-fields-2/admin/mf_custom_fields.php
Line 53: $this->options['option'][$k]['value'] = $v; Remove the @ from begin of line

Line 185: </tfoot> fix it from tfood to tfoot

And add a condition to check wordpress version - >then >= 4.6
change the code:
/admin/mf_tiny_mce.php

        if ( $teeny ) {
                $plugins = apply_filters( 'teeny_mce_plugins', array('colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink') );
                $ext_plugins = '';
        } else {
                $plugins = array(
                    'charmap',
                    'colorpicker',
                    'hr',
                    'lists',
                    'media',
                    'paste',
                    'tabfocus',
                    'textcolor',
                    'fullscreen',
                    'wordpress',
                    'wpautoresize',
                    'wpeditimage',
                    'wpemoji',
                    'wpgallery',
                    'wplink',
                    'wpdialogs',
                    'wptextpattern',
                    'wpview',
                    'wpembed',
                );

like this -> /WordPress/wp-includes/class-wp-editor.php

Good job!

@simkea
Copy link

simkea commented Sep 5, 2016

i recommend...

`jQuery.mf_bind('add',function(){
if('undefined' != typeof tinyMCEPreInit) {

if (typeof tinymce !== 'undefined') {
  for (id in tinyMCEPreInit.mceInit) {
    if (tinyMCEPreInit.mceInit.hasOwnProperty(id)) {
      init = tinyMCEPreInit.mceInit[id];
      $wrap = tinymce.$('#wp-' + id + '-wrap');

      if ($wrap.hasClass('html-active')) {
        for (id in tinyMCEPreInit.mceInit) {
          if (tinyMCEPreInit.mceInit.hasOwnProperty(id)) {
            init = tinyMCEPreInit.mceInit[id];
            tinymce.init(init);
          }
        }
      }

      // yeah, I know, this is ugly but works :s
      setTimeout(function () {
        jQuery("button#content-html").click();
      }, 1500);
    }
  }
}

}

jQuery(".multiline_custom_field .add_editor_mf").each( function(index,value){
var editor_text = jQuery(this).attr('id');
tinyMCE.execCommand(mf_js.mf_mceAddString, false, editor_text);
jQuery(this).removeClass('add_editor_mf');
});
});`

pls add the if conditions to check hasOwnProperty() ... :) thx

@hunk
Copy link
Member

hunk commented Sep 10, 2016

I created this branch and I send almost all changes #251

@simkea two things:
-about /admin/mf_tiny_mce.php this file is not called anymore, https://github.com/magic-fields-team/Magic-Fields-2/blob/master/admin/mf_post.php#L460 I comment that functions in this commit

-about this line $this->options['option'][$k]['value'] = $v; I remember at beginning I have some errors when the options doesn't exist, but I don't remember well. I will make some test for see when this happened and change for a better way to handle this

@simkea
Copy link

simkea commented Sep 20, 2016

So currently it works with WordPress 4.6.x. Thank you so much!

@hunk hunk closed this as completed in 1d9b90c Mar 22, 2017
hunk added a commit that referenced this issue Mar 22, 2017
…line

fix Url convert to relative url, Fixes #249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants