Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
166 lines (140 sloc) 5.38 KB
<?php
declare(strict_types=1);
defined('IN_MYBB') or die('Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.');
defined('PLUGINLIBRARY') or define('PLUGINLIBRARY', MYBB_ROOT . "inc/plugins/pluginlibrary.php");
$plugins->add_hook('index_end', 'teamcontact_index_end');
function teamcontact_info()
{
return [
'name' => 'Team contact',
'description' => 'Team contact',
'author' => 'Adrian \'Qwizi\' Ciołek',
'authorsite' => 'https://github.com/Qwizi',
'version' => '1.0',
'compatibility' => '18*',
'codename' => 'teamcontact',
];
}
function teamcontact_install()
{
global $db, $PL;
if (!file_exists(PLUGINLIBRARY)) {
flash_message("PluginLibrary is missing.", "error");
admin_redirect("index.php?module=config-plugins");
}
$PL or require_once PLUGINLIBRARY;
$PL->settings(
'teamcontact',
'Team contact',
'Settings of Team contact',
[
'groups' => [
'title' => 'User groups to display',
'description' => 'User groups to display',
'optionscode' => 'groupselect',
'value' => '4'
],
'email' => [
'title' => 'E-mail',
'description' => 'Show user email?',
'optionscode' => 'yesno',
'value' => 'yes'
],
'pm' => [
'title' => 'Allow users to send pms?',
'description' => 'send user pm',
'optionscode' => 'yesno',
'value' => 'yes'
],
'fields' => [
'title' => 'Fields',
'description' => 'Fields',
'optionscode' => 'text',
'value' => ''
]
]
);
}
function teamcontact_uninstall()
{
global $PL;
$PL or require_once PLUGINLIBRARY;
$PL->settings_delete('teamcontact');
}
function teamcontact_is_installed()
{
global $db;
$query = $db->simple_select('settinggroups', 'gid', "name='teamcontact'");
return (bool) $db->num_rows($query);
}
function teamcontact_index_end()
{
global $db, $mybb, $groupscache, $templates, $teamcontact;
$timesearch = TIME_NOW - $mybb->settings['wolcutoffmins'] * 60;
$teamcontactGroups = '';
if (!empty($mybb->settings['teamcontact_groups'])) {
$teamcontactGroups = "WHERE u.usergroup IN ({$mybb->settings['teamcontact_groups']})";
}
$teamContactEmail = '';
if ($mybb->settings['teamcontact_email']) {
$teamContactEmail = ", u.email";
}
$teamContactCustomFields = '';
if (!empty($mybb->settings['teamcontact_fields'])) {
$fieldsExplode = explode(',', $mybb->settings['teamcontact_fields']);
$fieldsArray = [];
$fieldsQuery = $db->simple_select('profilefields', 'fid, name');
while ($row = $db->fetch_array($fieldsQuery)) {
$fieldsArray[] = $row;
}
if (is_array($fieldsExplode) && is_array($fieldsArray)) {
foreach ($fieldsExplode as $key => $value) {
foreach ($fieldsArray as &$v) {
if ($v['fid'] == $value) {
$teamContactCustomFields .= ", f.fid{$value}";
}
}
}
}
}
$userQuery = $db->query("SELECT u.uid, u.avatar, u.username, u.usergroup, u.displaygroup, s.time {$teamContactCustomFields} {$teamContactEmail}
FROM " . TABLE_PREFIX . "users u
LEFT JOIN " . TABLE_PREFIX . "userfields f ON(f.ufid=u.uid)
LEFT JOIN " . TABLE_PREFIX . "sessions s ON (s.uid=u.uid)
{$teamcontactGroups}
");
$user = [];
$teamcontact_row = '';
while ($row = $db->fetch_array($userQuery)) {
$user['uid'] = $row['uid'];
$user['avatar'] = format_avatar($row['avatar']);
$user['username'] = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
$user['online'] = $row['time'] > $timesearch ? 'tak' : 'nie';
$teamcontact_field_row = '';
if (is_array($fieldsExplode) && is_array($fieldsArray)) {
foreach ($fieldsExplode as $key => $value) {
foreach ($fieldsArray as &$v) {
if ($v['fid'] == $value) {
$fieldName = $v['name'];
$fieldValue = $row['fid' . $value];
if (!empty($fieldName) && !empty($fieldValue)) {
eval("\$teamcontact_field_row .= \"" . $templates->get("teamcontact_field_row") . "\";");
}
}
}
}
}
if (!empty($mybb->settings['teamcontact_email'])) {
$fieldName = 'Email';
$fieldValue = $row['email'];
eval("\$teamcontact_field_row .= \"" . $templates->get("teamcontact_field_row") . "\";");
}
if ($mybb->settings['teamcontact_pm']) {
$fieldName = 'Pm';
$fieldValue = "<a href=\"{$mybb->settings['bburl']}/private.php?action=send&amp;uid={$user['uid']}\">Send pm</a>";
eval("\$teamcontact_field_row .= \"" . $templates->get("teamcontact_field_row") . "\";");
}
eval("\$teamcontact_row .= \"" . $templates->get("teamcontact_row") . "\";");
}
eval("\$teamcontact = \"" . $templates->get("teamcontact") . "\";");
}
You can’t perform that action at this time.