frostschutz / MyBB-Google-SEO

Search Engine Optimization plugin for MyBB.
https://community.mybb.com/thread-202483.html
GNU General Public License v3.0
30 stars 25 forks source link

Warnings in ACP->Config->Plugins (Warning [2] Illegal string offset) #82

Open mateuszfigas opened 1 year ago

mateuszfigas commented 1 year ago

I have some issues with this plugin and can't find resulution for this

Warning [2] Illegal string offset 'database' - Line: 110 - File: inc/plugins/google_seo/plugin.php PHP 5.6.40 (Linux)

File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/google_seo/plugin.php 110 errorHandler->error_callback
/inc/plugins/google_seo/plugin.php 68 google_seo_plugin_status
/inc/plugins/google_seo.php 56 google_seo_plugin_info
/inc/class_plugins.php 225 google_seo_info
/admin/modules/config/plugins.php 644 pluginSystem->is_compatible
/admin/modules/config/plugins.php 564 build_plugin_list
/admin/index.php 830 require

Warning [2] Illegal string offset 'encoding' - Line: 110 - File: inc/plugins/google_seo/plugin.php PHP 5.6.40 (Linux)

File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/google_seo/plugin.php 110 errorHandler->error_callback
/inc/plugins/google_seo/plugin.php 68 google_seo_plugin_status
/inc/plugins/google_seo.php 56 google_seo_plugin_info
/inc/class_plugins.php 225 google_seo_info
/admin/modules/config/plugins.php 644 pluginSystem->is_compatible
/admin/modules/config/plugins.php 564 build_plugin_list
/admin/index.php 830 require

Warning [2] Illegal string offset 'database' - Line: 113 - File: inc/plugins/google_seo/plugin.php PHP 5.6.40 (Linux)

File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/google_seo/plugin.php 113 errorHandler->error_callback
/inc/plugins/google_seo/plugin.php 68 google_seo_plugin_status
/inc/plugins/google_seo.php 56 google_seo_plugin_info
/inc/class_plugins.php 225 google_seo_info
/admin/modules/config/plugins.php 644 pluginSystem->is_compatible
/admin/modules/config/plugins.php 564 build_plugin_list
/admin/index.php 830 require

Warning [2] Illegal string offset 'encoding' - Line: 113 - File: inc/plugins/google_seo/plugin.php PHP 5.6.40 (Linux)

File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/google_seo/plugin.php 113 errorHandler->error_callback
/inc/plugins/google_seo/plugin.php 68 google_seo_plugin_status
/inc/plugins/google_seo.php 56 google_seo_plugin_info
/inc/class_plugins.php 225 google_seo_info
/admin/modules/config/plugins.php 644 pluginSystem->is_compatible
/admin/modules/config/plugins.php 564 build_plugin_list
/admin/index.php 830 require

Warning [2] Illegal string offset 'admin_dir' - Line: 153 - File: inc/plugins/google_seo/plugin.php PHP 5.6.40 (Linux)

File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/google_seo/plugin.php 153 errorHandler->error_callback
/inc/plugins/google_seo/plugin.php 68 google_seo_plugin_status
/inc/plugins/google_seo.php 56 google_seo_plugin_info
/inc/class_plugins.php 225 google_seo_info
/admin/modules/config/plugins.php 644 pluginSystem->is_compatible
/admin/modules/config/plugins.php 564 build_plugin_list
/admin/index.php 830 require

image

mateuszfigas commented 1 year ago

I seem to have a solution to this problem. The errors are gone, but it would be useful if someone else verified the operation of this code.

In _inc/plugins/googleseo/plugin.php Change this:

if($mybb->config['database']['encoding'] != 'utf8mb4')
    {
        $warning[] = $lang->sprintf($lang->googleseo_plugin_warn_encoding,
                                    $mybb->config['database']['encoding']);
    }

For:

if (isset($mybb->config['database']) && is_array($mybb->config['database']) &&
    isset($mybb->config['database']['encoding']) && $mybb->config['database']['encoding'] != 'utf8mb4')
{
    $warning[] = $lang->sprintf($lang->googleseo_plugin_warn_encoding, $mybb->config['database']['encoding']);
}

And change this:

if($settings['google_seo_redirect'])
    {
        $success[] = $lang->googleseo_plugin_redirect;

        if(!$settings['google_seo_url'])
        {
            $warning[] = $lang->googleseo_plugin_redirect_warn_url;
        }

        $current_url = google_seo_redirect_current_url();
        $pos = my_strpos($current_url, "/{$config['admin_dir']}/index.php");

        if($pos)
        {
            $current_url = my_substr($current_url, 0, $pos);
        }

        if(!$settings['bburl'] || $settings['bburl'] != $current_url)
        {
            $warning[] = $lang->sprintf($lang->googleseo_plugin_redirect_warn_bburl,
                                        htmlspecialchars($settings['bburl'], ENT_COMPAT, "UTF-8"),
                                        htmlspecialchars($current_url), ENT_COMPAT, "UTF-8");
        }
    }

    else
    {
        $error[] = $lang->googleseo_plugin_redirect;
    }

For this:

if(isset($settings['google_seo_redirect']) && is_array($settings['google_seo_redirect']))
{
    if($settings['google_seo_redirect'])
    {
        $success[] = $lang->googleseo_plugin_redirect;

        if(isset($settings['google_seo_url']) && !$settings['google_seo_url'])
        {
            $warning[] = $lang->googleseo_plugin_redirect_warn_url;
        }

        $current_url = google_seo_redirect_current_url();
        $pos = my_strpos($current_url, "/{$config['admin_dir']}/index.php");

        if($pos !== false)
        {
            $current_url = my_substr($current_url, 0, $pos);
        }

        if(isset($settings['bburl']) && (!$settings['bburl'] || $settings['bburl'] != $current_url))
        {
            $warning[] = $lang->sprintf($lang->googleseo_plugin_redirect_warn_bburl,
                                        htmlspecialchars($settings['bburl'], ENT_COMPAT, "UTF-8"),
                                        htmlspecialchars($current_url), ENT_COMPAT, "UTF-8");
        }
    }

    else
    {
        $error[] = $lang->googleseo_plugin_redirect;
    }
}