2016-06-20, 11:12 AM
Dear mybb members and users.
I am using the plugin DVZ Mentions, However i would like to change it from @username to @uid how do i do this?
I have done everything i can but nothing changes it.
I am not such a great programmer so any help is appreciated
I think this is the file the changes are supposed to happen.
Thanks in advance.
I am using the plugin DVZ Mentions, However i would like to change it from @username to @uid how do i do this?
I have done everything i can but nothing changes it.
I am not such a great programmer so any help is appreciated
I think this is the file the changes are supposed to happen.
Thanks in advance.
<?php
/* by Tomasz 'Devilshakerz' Mlynski [devilshakerz.com]; Copyright (C) 2014-2016
released under Creative Commons BY-NC-SA 4.0 license: https://creativecommons.org/licenses/by-nc-sa/4.0/ */
namespace DVZMentions;
class Links
{
static $global = true;
static $usernames = [];
static $placeholders = [];
static $correction = 0;
static function parse(&$message)
{
$matches = Parser::getCalls($message);
self::$usernames = Parser::getUsernamesFromMatchSet($matches, self::$usernames);
if (self::$global) {
self::insertPlaceholders($message, $matches);
} else {
self::insertUsernames($message, $matches, Config::$queryLimit);
}
return $message;
}
static function insertUsernames(&$message, $matches, $queryLimit = 10000)
{
if (count(self::$usernames) <= $queryLimit) {
$users = Parser::getUsersByUsername(self::$usernames, 'uid,username' . (Config::$color ? ',usergroup,displaygroup' : null));
} else {
$users = [];
}
self::$correction = 0; // offset correction
foreach ($matches as $index => $match) {
$user = &$users[ mb_strtolower($match['username']) ];
if (isset($user)) {
$username = Config::$color
? format_name($user['username'], $user['usergroup'], $user['displaygroup'])
: $user['username'];
$replacement = (Config::$keepPrefix ? '@' : null) . build_profile_link($username, $user['uid']);
} else {
$replacement = false;
}
if ($replacement) {
self::replace($message, $match, $replacement);
}
}
return $message;
}
static function insertPlaceholders(&$message, $matches)
{
self::$correction = 0; // offset correction
foreach ($matches as $index => $match) {
$placeholder = [
'username' => $match['username'],
'quotes' => $match['quotes'],
];
$placeholderNo = array_search($placeholder, self::$placeholders);
if (!$placeholderNo) {
self::$placeholders[] = $placeholder;
$placeholderNo = count(self::$placeholders) - 1;
}
$replacement = '<DVZ_ME#' . $placeholderNo . '>';
if ($replacement) {
self::replace($message, $match, $replacement);
}
}
}
static function fillPlaceholders(&$content)
{
if (self::$placeholders) {
// query limit
if (!Config::$queryLimit || count(self::$placeholders) <= Config::$queryLimit) {
// get user data
$users = Parser::getUsersByUsername(self::$usernames, 'uid,username' . (Config::$color ? ',usergroup,displaygroup' : null));
} else {
$users = [];
}
// replace mentions
foreach (self::$placeholders as $index => $placeholder) {
$user = &$users[ mb_strtolower($placeholder['username']) ];
if (isset($user)) {
$username = Config::$color
? format_name($user['username'], $user['usergroup'], $user['displaygroup'])
: $user['username'];
$replacement = (Config::$keepPrefix ? '@' : null) . build_profile_link($username, $user['uid']);
} else {
$replacement = '@' . ($placeholder['quotes'] ? $placeholder['quotes'] . $placeholder['username'] . $placeholder['quotes'] : $placeholder['username']);
}
$content = str_replace('<DVZ_ME#' . $index . '>', $replacement, $content);
}
}
return $content;
}
static function replace(&$message, $match, $replacement)
{
// offset, call character, correction
$start = $match['offset'] - 1 + self::$correction;
// call character, quotation marks, match length
$length = 1 + ($match['quotes'] ? 2 : 0) + strlen($match['username']);
$message = substr_replace($message, $replacement, $start, $length);
self::$correction += strlen($replacement) - $length;
}
}