If you're modifying with a script that's executed within Joomla so it has access to Joomla API then it's easy enough to just call CBs API to get the unread count. Ideally you should be using a Joomla plugin acting on Joomla menu events to modify the menu which would allow for this. Otherwise your only option is to establish a database connection and query for the unread count. Below is the query being used internally.
Code:
public function getPMSunreadCount( $userId )
{
global $_CB_database;
if ( UddeIM::isUddeIM() ) {
return UddeIM::getPMSunreadCount( $userId );
}
static $cache = array();
if ( ! isset( $cache[$userId] ) ) {
$query = "SELECT COUNT(*)"
. "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_messages' ) . " AS m"
. "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler_plugin_messages_read' ) . " AS r"
. " ON r." . $_CB_database->NameQuote( 'to_user' ) . " = " . (int) $userId
. " AND r." . $_CB_database->NameQuote( 'message' ) . " = m." . $_CB_database->NameQuote( 'id' )
. "\n WHERE ( ( m." . $_CB_database->NameQuote( 'from_user' ) . " != " . (int) $userId
. " AND m." . $_CB_database->NameQuote( 'to_user' ) . " = 0 )"
. " OR ( m." . $_CB_database->NameQuote( 'to_user' ) . " = " . (int) $userId
. " AND m." . $_CB_database->NameQuote( 'to_user_delete' ) . " = 0 ) )"
. "\n AND r." . $_CB_database->NameQuote( 'id' ) . " IS NULL";
$_CB_database->setQuery( $query );
$cache[$userId] = (int) $_CB_database->loadResult();
}
return $cache[$userId];
}
That's just the PHP function for it. You'll need to extract the SQL out for your needs from this.