MyBB Community Forums

Full Version: problems with newpoints plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I have several problems with the newpoints...

1- Despite the fact that I create and comment on posts in my forum, it is not giving me the points it should give me, I tried it from several accounts and it does not give me any, I made posts, I responded to posts and nothing... for each post and answer I put that I should give you 5, 10, 20 points, and even then it doesn't work.

 2- When I assign points to myself or to a user, and that user uses those points to unlock publications, the points do not decrease, it is as if they were infinite.

      
      Things that I did:

      1- Uninstall and install the plugin from the mybb panel.
      2- Delete all plugin folders from the root directory and put them back.
      3- I tried different types of configurations.
I know this is several months old now, but I'm posting here, because I'm getting similar results. Points are not given to me when I create threads or post replies - and while they are given when I make a donation, they are not taken from me.

After testing this in several different versions of PHP, I discovered that it's working fine in PHP 7.4 and earlier - but in PHP 8.0 and later, I get the above issues. So, it seems something changed in PHP 8.0 that's broken this plugin. (If you want, you could run PHP 7.4 or earlier so that you can use this plugin; however, PHP 7.4 is EOL as of November 2022, and thus is no longer receiving security fixes - so, do that at your own risk!

For reference, here is the error.log file that was generated when I set my test board to PHP 8.0.28, and posted a reply with NewPoints enabled:

Quote:<error>
<dateline>1683115963</dateline>
<script>inc/plugins/newpoints.php</script>
<line>715</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Trying to access array offset on value of type bool</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/plugins/newpoints.php:715]
#2  newpoints_load_plugins() called at [/inc/plugins/newpoints/core/hooks.php:196]
#3  newpoints_plugins_start() called at [/inc/class_plugins.php:142]
#4  pluginSystem->run_hooks() called at [/global.php:100]
#5  require_once() called at [/index.php:18]
</back_trace>
</error>

<error>
<dateline>1683115963</dateline>
<script>inc/class_plugins.php</script>
<line>129</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Undefined array key "file"</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/class_plugins.php:129]
#2  pluginSystem->run_hooks() called at [/global.php:1276]
#3  require_once() called at [/index.php:18]
</back_trace>
</error>

<error>
<dateline>1683115963</dateline>
<script>inc/class_plugins.php</script>
<line>129</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Undefined array key "file"</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/class_plugins.php:129]
#2  pluginSystem->run_hooks() called at [/inc/functions_forumlist.php:62]
#3  build_forumbits() called at [/index.php:463]
</back_trace>
</error>

<error>
<dateline>1683115963</dateline>
<script>inc/class_plugins.php</script>
<line>129</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Undefined array key "file"</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/class_plugins.php:129]
#2  pluginSystem->run_hooks() called at [/inc/functions_forumlist.php:62]
#3  build_forumbits() called at [/inc/functions_forumlist.php:163]
#4  build_forumbits() called at [/index.php:463]
</back_trace>
</error>

<error>
<dateline>1683115963</dateline>
<script>inc/class_plugins.php</script>
<line>129</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Undefined array key "file"</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/class_plugins.php:129]
#2  pluginSystem->run_hooks() called at [/inc/functions.php:24]
#3  output_page() called at [/index.php:469]
</back_trace>
</error>

<error>
<dateline>1683115963</dateline>
<script>inc/class_plugins.php</script>
<line>129</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Undefined array key "file"</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/class_plugins.php:129]
#2  pluginSystem->run_hooks() called at [/inc/functions.php:24]
#3  output_page() called at [/index.php:469]
</back_trace>
</error>

<error>
<dateline>1683115963</dateline>
<script>inc/functions.php</script>
<line>2710</line>
<type>2</type>
<friendly_type>Warning</friendly_type>
<message>Trying to access array offset on value of type bool</message>
<back_trace>#0  errorHandler->error() called at [/inc/class_error.php:153]
#1  errorHandler->error_callback() called at [/inc/functions.php:2710]
#2  get_server_load() called at [/inc/functions.php:45]
#3  output_page() called at [/index.php:469]
</back_trace>
</error>

Now, I'm not expecting an official fix for this, because NewPoints is no longer officially supported by its developer. However, I'm hoping this will help someone reading this to do an unofficial fix (I'd do it myself, but I'm not a PHP developer, so it's beyond my paygrade Sad !)

Would be a real shame if this was the end of NewPoints (because it can only be used with outdated versions of PHP). It's an excellent plugin...
Well, I did some more digging - and I was able to isolate the problem to line 378 of inc/plugins/newpoints.php:

Quote:if ($isstring) // where username
$db->write_query("UPDATE ".TABLE_PREFIX."users SET newpoints=newpoints+'".floatval(round($points*$forumrate*$grouprate, intval($mybb->settings['newpoints_main_decimal'])))."' WHERE username='".$db->escape_string($uid)."'");
else // where uid
{
// if immediate, run the query now otherwise add it to shutdown to avoid slow down
if ($immediate)
$db->write_query("UPDATE ".TABLE_PREFIX."users SET newpoints=newpoints+'".floatval(round($points*$forumrate*$grouprate, intval($mybb->settings['newpoints_main_decimal'])))."' WHERE uid='".intval($uid)."'");
else
{
$userpoints[intval($uid)] += floatval(round($points*$forumrate*$grouprate, intval($mybb->settings['newpoints_main_decimal'])));
}
}

The bolded line was throwing an "undefined array key" error. When a user posts, this code is supposed to modify the user's "$userpoints" value: for example, my account has user ID = 1, so this would be modifying $userpoints[1]. But the value of $userpoints[1] hasn't been initialised anywhere - which wasn't a problem in PHP 7.x, but now throws an error from PHP 8.x onwards. Unfortunately, not being a PHP developer, I didn't know what the correct fix was Sad .

But the good news is... I was able to bypass this code Smile . I simply set "$immediate" from false to true. Now, the bolded code isn't even being executed: instead, it's running the SQL query immediately above it, which doesn't have any undefined array keys in it. After doing this, I once again get points when posting, and the donation system works correctly too Smile .

This won't make the plugin entirely compatible with PHP 8.x: I did also find other errors elsewhere. But if you just want to get the essentials working, without having to resort to running an outdated version of PHP - then, this looks like the way to go.