SCEditor Advice - autosave and other bugs (SMFPacks WYSIWYG)

Started by Melonking, February 13, 2023, 07:56:03 AM

Previous topic - Next topic

Melonking

Hi Im wondering if anyone here who is familiar with the SCEditor (included with 2.1 as standard) and also possibly the SMFPacks WYSIWYG/AdvancedEditor (its an SECeditor wrapper for 2.0).

Im running on 2.0.19 with the SMFPacks version of the editor, but Iv not really been able to get any meaningful help from the developer; so hopefully here!

Firstly - the autosave plugin included with SCEditor uses this string to identify unique pages on the forum "storageKey: 'sce-autodraft-' + location.pathname + location.search" - I wondered if there is a more appropriate string to use for SMF because this one causes issues! (like when num_replies is in the url)

Secondly - does anyone know how I can disable the editor for some textareas? Particularly on pages where there are multiple text areas (like profile pages) - this causes a huge issue!

Finally Im just having all sorts of wild issues with the SCEditor in general.
  • When previewing a post sometimes the editor will just erase itself.
  • When editing a selected word, often the cursor will jump to the end of the message and put the text in the wrong place.
  • Sometimes the undo just deletes the entire message, or does nothing at all!
  • The editor ignores members WYSIWYG user setting (how can I fix this?)

Its kinda just a mess and Im not really sure how to fix it at this point! Any advice would be welcome!

The version of SCEditor included with SMFPacks is 2.1.2 - I tried updating it to 3 and 3.1.1 - this vaguely helped some issues, but it also caused a whole bunch of others.

Arantor

The version of the editor in 2.1 is quite a bit different to the one shipped with Nibogo's mod, and honestly... can't say I'm surprised you didn't get a lot of help with it, that's normal for Nibogo.

Unfortunately, as it's a paid mod, there's a limit to how much help we can give - especially with it being so very different to how SMF uses it (2.1 doesn't splatter the editor everywhere, doesn't use the autosave like that and generally just works)

Honestly, since you seen to have a small site, would it not be worth contemplating an upgrade to 2.1 now that's out where these things *do* work properly?
Holder of controversial views, all of which my own.


Melonking

My forum theme is based off a classic theme that was patched to 2.0 and has since been very modified - ducktape code is not the word.. its held together with chewing gum.. trying to jump it over to 2.1 I'm not sure is possible!

On top of that mods like, Ultimate Profile, Simple Awards System, Drafts, Colorised Posts - all cerca 2006-2009 mods that people on my forum love (it is a retro themed community after all). Its been so much work just getting them to function - bringing them over to 2.1 seems like it might be unrealistic.

So unless there's a clear and doable upgrade path that basically just lets me drag and drop all of that into a 2.1 forum without weeks of reengineering.. Im just not sure its worth it! The impression Iv gotten so far is that is not the case, so I might be with 2.0 for as long as it remains functional :-X

Arantor

Honestly? I don't expect SMF 2.0 to make it through to PHP 9 which is likely next year's release. Which means you're on borrowed time.
Holder of controversial views, all of which my own.


Melonking

Borrowed time is relative - Im still on PHP 7.4 - in a few years I'll upgrade to 8 - after that I suspect that'll be the end of it - then I have about 10 years to work on a new 2.1 forum before it really becomes unstable - finally when I launch my 2.1 forum, 3.1 will come out and we will be having this conversation again  ;D

Arantor

You mean the PHP 7.4 that already doesn't get support from the PHP team and that most hosts are forcing people onto PHP 8?
Holder of controversial views, all of which my own.


Melonking

Yes that one! It works great and I use a VPS, so hosts are not my concern :P Id perfer not to bring this post too much off topic though; so if you wanna debate the upgrade rat race with me, lets do that in another thread  :laugh:

Melonking

Ok a little bit of an update!

I found that while updating SCEditor too much causes issues - it can be updated to 2.1.3 without issue - so that must help some things! I also updated jQuery site-wide from 1.8.2 to 3.6.3 and it seems to be working without issues  :) Between these two, a lot of the really weird issues like cursor jumping have been resolved.

So the big issue is the autosave url I mentioned in the top post - if anyone is interested in figuring it out with me here is the documentation - https://www.sceditor.com/documentation/plugins/autosave/

Its a script right? Sooo maybe PHP could generate a safe saving url - embed it in a page and the the script could reference that url instead of the window address! Im gonna give that a try - but any suggestions about how to generate a url that is both unique for each page, but also does not change unexpectedly (like when previewing a topic) that would be a vast help!

Example:
URL when making a new topic: "https://forum.melonland.net/index.php?action=post;board=19.0"
URL after pressing preview: "https://forum.melonland.net/index.php?action=post2;start=0;board=19"
These need to be formatted into an equal string - same for replying to topics.

Would a pretty url mod help with this?

We can do it!  ;D

Melonking

Following this up - Pretty URLs don't help as they don't modify the bit of the url causing issues.

However I created this simple (if clunky) script
$pageIdentifiers = array(
'melonid_',
((strpos($context['current_action'], 'post') !== false) ? '' : $context['current_action']),
((isset($context['member']['id'])) ? '_member-' . $context['member']['id'] : ''),
((isset($context['menu_item_selected'])) ? '_area-' . $context['menu_item_selected'] : ''),
((isset($context['conversation']['id_conversation'])) ? '_conversation-' . $context['conversation']['id_conversation'] : ''),
((isset($context['current_board'])) ? '_board-' . $context['current_board'] : ''),
((isset($context['current_topic'])) ? '_topic-' . $context['current_topic'] : '')
);
$pageIdentityString = "";
foreach($pageIdentifiers as $pageIdentifier) {
$pageIdentityString .= $pageIdentifier;
}

It produces unique strings for each topic, including their post page - along with other actions e.g.
?action=post;topic=827.0;last_msg=7694 becomes melonid__board-24_topic-1037
?topic=827.0 also becomes melonid__board-24_topic-1037
This allows quick posts and full posts to sync via autosave seamlessly.

It also converts profile pages to things like melonid_profile_member-307_area-summary - a great start!

Im still figuring out how to solve the last issue (ignoring WISIWIG settings) - but It cant be that hard!

If anyone has a better solution to this please let me know, Im not sure if this will function in all situations.

live627

You have that script pushing the compiled string to the autosave plugin?

live627

Quote from: Melonking on February 13, 2023, 07:56:03 AMSecondly - does anyone know how I can disable the editor for some textareas? Particularly on pages where there are multiple text areas (like profile pages) - this causes a huge issue!
SMFPacks Editor has a setting for this I think—a comma-separated list of actions.

Melonking

Quote from: live627 on February 15, 2023, 09:12:11 PMYou have that script pushing the compiled string to the autosave plugin?

Yep, the script is output by a php page (AdvancedEditor.php) so its an easy include:
storageKey: "sce-autodraft-' . $pageIdentityString . '",
However I found that this didn't actually fix all situations - If you tried to modify a message, it would recognise that as a new post and erase your origonal messages text. I had to add an extra test to the index.template.php (I also made it disable on profile pages because that was causing issues)

// Melon Params System
    $autosaveSwitch = true;
    if(isset($context['page_title_html_safe']) && strpos($context['page_title_html_safe'], 'Modify message') !== false)
        $autosaveSwitch = false;
    if(isset($context['current_action']) && strpos($context['current_action'], 'profile') !== false)
        $autosaveSwitch = false;
   
    echo '<script id="melon-params">';
    echo '  var melonParamAutoSave = '. ($autosaveSwitch ? 'true' : 'false') . ';';
    echo '</script>';

This is then referenced in the sceditor options:
let enableAutoSave = "";
                if(melonParamAutoSave != undefined && melonParamAutoSave) {
                    enableAutoSave = ",autosave";
                }

plugins: "undo,plaintext" + enableAutoSave,
Its a bit messy, but it seems to work well - it did break the quote button though, I fixed that by hacking in quotes via javascript using the SuperQuotes mod (It basically inserts single quotes as if they were multi quotes); its a bad solution, but it works well enough for now and no one is complaining!

Quote from: live627 on February 15, 2023, 09:19:57 PMSMFPacks Editor has a setting for this I think—a comma-separated list of actions.
The issue is that its per action and the profile action actually covers like 3 separate editor pages on my forum so its not granular at all - I have one text box thats supposed to be for CSS, so the editor is confusing and a bit problematic to have on that particular text area.

Writing this I have a plan though! I'll give it a unique id and test for that id in the setup script - again its all getting really messy, but if it works it works!

live627

Yea h, that seems to be the solution—exclude based on certain request parameters.

Advertisement: