Not compatible with SweetAlerts

13 Aug 2020
#1
This issue is marked as solved
Bankpipe is showing json output when using the plugin

https://community.mybb.com/mods.php?acti...w&pid=1306

Best answer

Shade 14 Aug 2020
Ah, it replaces things on the server side with a str_replace(). That's a bit basic and prone to issues. I'd need your board URL to see where's failing, but I'd recommend getting rid of the plugin entirely, load Swal.js on your own and use a front-end override for jGrowl. For example, I came up with the following function loaded in headerinclude template:

// Override jGrowl
        $.jGrowl = function(m, o) {
            
            var status = 'success';
            if (typeof o !== 'undefined' && o.theme.indexOf('error') != -1) {
                status = 'danger';
            }
            
            var label = (status == 'success') ? 'Success' : 'Error';
            var icon = (status == 'success') ? 'check' : 'close';
            
            var message = "<div class='uk-grid uk-grid-small uk-child-width-expand uk-flex-middle'>" +
                                "<i uk-icon='icon: " + icon + "' class='uk-width-auto'></i>" +
                                "<div>" +
                                    "<b class='uk-text-uppercase uk-text-small'>" + label + "</b>" +
                                    "<div>" + m + "</div>" +
                                "</div>" +
                            "</div>";
            
            $.notification = UIkit.notification(message, {
                status: status,
                 pos: 'bottom-right'
            });
            
        };
It's tailored to MyBBoost's framework (UIKit) but you get the idea. You basically redeclare $.jGrowl and return your own message handler instead of jGrowl's.

All replies

Shade 13 Aug 2020
#2
Hi, unfortunately I don’t support third party plugins unless they are widely used (eg: DVZ Shoutbox, MyAlerts). This sounds like an incompatibility with the way that plugin hijacks jGrowl, but I am not sure as I haven’t had a look at the plugin.
ProX 14 Aug 2020
#3
Hi, unfortunately I don’t support third party plugins unless they are widely used (eg: DVZ Shoutbox, MyAlerts). This sounds like an incompatibility with the way that plugin hijacks jGrowl, but I am not sure as I haven’t had a look at the plugin.
Shade (13 Aug 2020)
I guess it's this part.

/**
     * Replace all lines containing jGrowl with SweetAlert's code.
     *
     * @param string $fileName The name of the file.
     *
     * @author Skryptec <[email protected]>
     */
    public function replaceFilesWithSwal(string $fileName) {
        file_put_contents($fileName, implode('',
            array_map(function($data) {
                $match = stristr($data, '$.jGrowl');

                if($match) {
                    $filtered = explode(', ', trim(
                                    str_replace(
                                    [
                                        "{theme:'jgrowl_",
                                        "'});",
                                        '$.jGrowl('
                                    ], '', $match)
                                ));
                    
                    $title = ucfirst($filtered[1]) . '!';

                    $swal = "/** MySweetAlert2 */\nSwal.fire('$title', $filtered[0], '$filtered[1]');\n";

                    return $swal;
                }

                return $data;
            }, file($fileName))
        ));
    }
Especially this Swal.fire('$title', $filtered[0], '$filtered[1]'), how much of a change would it require to fit bankpipe?
Shade 14 Aug 2020
#4
Ah, it replaces things on the server side with a str_replace(). That's a bit basic and prone to issues. I'd need your board URL to see where's failing, but I'd recommend getting rid of the plugin entirely, load Swal.js on your own and use a front-end override for jGrowl. For example, I came up with the following function loaded in headerinclude template:

// Override jGrowl
        $.jGrowl = function(m, o) {
            
            var status = 'success';
            if (typeof o !== 'undefined' && o.theme.indexOf('error') != -1) {
                status = 'danger';
            }
            
            var label = (status == 'success') ? 'Success' : 'Error';
            var icon = (status == 'success') ? 'check' : 'close';
            
            var message = "<div class='uk-grid uk-grid-small uk-child-width-expand uk-flex-middle'>" +
                                "<i uk-icon='icon: " + icon + "' class='uk-width-auto'></i>" +
                                "<div>" +
                                    "<b class='uk-text-uppercase uk-text-small'>" + label + "</b>" +
                                    "<div>" + m + "</div>" +
                                "</div>" +
                            "</div>";
            
            $.notification = UIkit.notification(message, {
                status: status,
                 pos: 'bottom-right'
            });
            
        };
It's tailored to MyBBoost's framework (UIKit) but you get the idea. You basically redeclare $.jGrowl and return your own message handler instead of jGrowl's.
ProX 14 Aug 2020 Edited
#5
Yeah, your approach is so much better and works.