MyBB Community Forums

Full Version: showing last OS in user profile
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am looking for a plugin that extracts the last users logged in OS info, and displays it in their profile (for everyone). It could be simply defined as little as something like Windows 7, Windows 10, Linux, Mac, etc. 

There are a 2 plugins that do 2 different things, but i think meshing them together would create what i am looking for. Each plugin is a sole php file in the plugins directory. 

extend user info...which displays a ton of info in the profile, but to only admins, including the OS info.
<?php
// Main Plugin file for the plugin Extended Useradmininfos
// © 2013-2015 Flobo x3
// Last change: 2015-03-25

if(!defined('IN_MYBB')) {
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('global_end', 'extendeduseradmininfos_set_info');
$plugins->add_hook('member_profile_start', 'extendeduseradmininfos_get_info');

function extendeduseradmininfos_info() {
global $lang, $db;
$lang->load('extendeduseradmininfo');

$info = array(
"name" => $lang->extendeduseradmininfo_name,
"description" => $lang->extendeduseradmininfo_desc,
"website" => 'http://forum.mybboard.de/user-9022.html',
"author" => 'Florian Berger',
"authorsite" => 'http://florian-berger.info',
"version" => '2.0.2',
"compatibility" => '16*,18*',
"guid" => '138867d0b45740bce59f3e48dc72c893',
"codename" => 'berger_florian_useradmininfo'
);

// show hint if last_ip field still exists
$result = $db->query("SHOW COLUMNS FROM `" . TABLE_PREFIX . "users` LIKE 'last_ip'");
if ($result->num_rows > 0)
$info["description"] .= "<br /><br />" . $lang->extendeduseradmininfo_dbchanged;

return $info;
}

function extendeduseradmininfos_activate() {
global $db;

$templateset = array(
  "prefix" => "extendeduseradmininfo",
  "title" => "Extended Useradmininfo",
   );
$db->insert_query("templategroups", $templateset);


// Create a template
$templatearray = array(
       "title" => "extendeduseradmininfo_view",
       "template" => "
<br />
       <table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder\">
       <tr>
       <td colspan=\"2\" class=\"thead\"><strong>{\$lang->extendeduseradmininfo_tableheader}</strong></td>
       </tr>
       <tr>
       <td class=\"trow1\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_ip}</strong></td>
       <td class=\"trow1\">___LASTIP___</td>
       </tr>
       <tr>
       <td class=\"trow2\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_useragent}</strong></td>
       <td class=\"trow2\">___AGENT___</td>
       </tr>
       <tr>
       <td class=\"trow1\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_browser}</strong></td>
       <td class=\"trow1\">___BROWSER___</td>
       </tr>
       <tr>
       <td class=\"trow2\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_operatingsystem}</strong></td>
       <td class=\"trow2\">___OS___</td>
       </tr>
       </table>
",
"sid" => -2
);
$db->insert_query("templates", $templatearray);

$templatearray = array(
       "title" => "extendeduseradmininfo_geo_info",
       "template" => "
<br />
       <table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder\">
       <tr>
       <td colspan=\"2\" class=\"thead\"><strong>{\$lang->extendeduseradmininfo_geo_header}</strong></td>
       </tr>
       <tr>
       <td class=\"trow1\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_geo_country}</strong></td>
       <td class=\"trow1\">___COUNTRY______COUNTRYCODE___</td>
       </tr>
       <tr>
       <td class=\"trow2\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_geo_city}</strong></td>
       <td class=\"trow2\">___POSTALCODE______CITY___</td>
       </tr>
       <tr>
       <td class=\"trow1\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_geo_region}</strong></td>
       <td class=\"trow1\">___REGION___</td>
       </tr>
       <tr>
       <td class=\"trow1\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_geo_continentcode}</strong></td>
       <td class=\"trow1\">___CONTINENTCODE___</td>
       </tr>
       <tr>
       <td class=\"trow1\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_geo_latitude}</strong></td>
       <td class=\"trow1\">___LATITUDE___</td>
       </tr>
       <tr>
       <td class=\"trow2\" width=\"40%\"><strong>{\$lang->extendeduseradmininfo_geo_longitude}</strong></td>
       <td class=\"trow2\">___LONGITUDE___</td>
       </tr>
       </table>
",
"sid" => -2
);
$db->insert_query("templates", $templatearray);

$templatearray = array(
"title" => 'extendeduseradmininfo_view_noinfos',
"template" => "
<br />
       <table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder\">
       <tr>
       <td colspan=\"2\" class=\"thead\"><strong>{\$lang->extendeduseradmininfo_tableheader}</strong></td>
       </tr>
       <tr>
       <td class=\"trow1\" >{\$lang->extendeduseradmininfo_no_informations_saved}</td>
       </tr>
       </table>
",
"sid" => -2
);
$db->insert_query("templates",$templatearray);

$templatearray = array(
"title" => 'extendeduseradmininfo_view_nogeoinfos',
"template" => "
<br />
       <table border=\"0\" cellspacing=\"{\$theme[\'borderwidth\']}\" cellpadding=\"{\$theme[\'tablespace\']}\" class=\"tborder\">
       <tr>
       <td colspan=\"2\" class=\"thead\"><strong>{\$lang->extendeduseradmininfo_geo_header}</strong></td>
       </tr>
       <tr>
       <td class=\"trow1\" >{\$lang->extendeduseradmininfo_no_geo_ipv6}</td>
       </tr>
       </table>
",
"sid" => -2
);
$db->insert_query("templates",$templatearray);


// Edit AdministratorOptions Template
require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets('member_profile_adminoptions', '#</table>#', '</table>{$advInfo}{$geoInfo}');
}

function extendeduseradmininfos_deactivate() {
global $db;

require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
find_replace_templatesets('member_profile_adminoptions', '#\{\$advInfo\}#', '', 0);
find_replace_templatesets('member_profile_adminoptions', '#\{\$geoInfo\}#', '', 0);

// refresh database structure -> remove plugin added field for last ip and use mybb own field
$result = $db->query("SHOW COLUMNS FROM `" . TABLE_PREFIX . "users` LIKE 'last_ip'");
if ($result->num_rows > 0)
$db->query("ALTER TABLE `" . TABLE_PREFIX . "users` DROP COLUMN last_ip");

// Delete the template
$templatearray = array(
       "extendeduseradmininfo_view",
"extendeduseradmininfo_view_noinfos",
"extendeduseradmininfo_geo_info",
"extendeduseradmininfo_view_nogeoinfos"
   );
$deltemplates = implode("','", $templatearray);

$db->delete_query("templates", "title in ('{$deltemplates}')");
$db->delete_query("templategroups", "prefix IN('extendeduseradmininfo')");
}

function extendeduseradmininfos_install() {
global $db;

$sQry = "ALTER TABLE `" . TABLE_PREFIX . "users` ADD last_useragent VARCHAR(255)";
$db->query($sQry);
}

function extendeduseradmininfos_is_installed() {
global $db;
        
if($db->field_exists("last_useragent", "users"))
return true;

return false; 
}

function extendeduseradmininfos_uninstall() {
global $db;

$sQry = "ALTER TABLE `" . TABLE_PREFIX . "users`
DROP COLUMN last_useragent";
$db->write_query($sQry);
}

function extendeduseradmininfos_set_info() {
global $db, $mybb;
$uid = $mybb->user['uid'];

if ($uid > 0) {
$useragent =  $db->escape_string($_SERVER['HTTP_USER_AGENT']);
$ip = $db->escape_string($_SERVER['REMOTE_ADDR']);

$sQry = "UPDATE " . TABLE_PREFIX . "users SET last_useragent='$useragent' WHERE uid=" . $uid;
$db->write_query($sQry);
}
}

function extendeduseradmininfos_get_info() {
   global $lang, $db, $mybb, $templates, $theme, $infoTable, $advInfo, $geoTable, $geoInfo;
   $lang->load('extendeduseradmininfo');

$userid = intval($mybb->input['uid']);

$query = $db->simple_select("users", "*", "uid='{$userid}'");
$infomember = $db->fetch_array($query);

   $lastip = my_inet_ntop($db->unescape_binary($infomember['lastip']));
   $lastagent = $infomember['last_useragent'];
   if ($lastagent != "") {
require_once("inc/functions_extendeduseradmininfos.php");
       $browser = getBrowser($lastagent);
        
if ($infoTable == '') {
eval("\$infoTable = \"".$templates->get("extendeduseradmininfo_view")."\";");
}
    
       if ($lastip != "") {
           $ipadress  = $lastip;
       } else {
           $ipadress = $lang->extendeduseradmininfo_unknown;
       }
        
       if ($lastagent != "") {
           $useragent = htmlspecialchars($lastagent, ENT_QUOTES);
       } else {
           $useragent = $lang->extendeduseradmininfo_unknown;
       }
        
       if ($browser['browser'] != "") {
           $browsername = $browser['browser'] . " " . $browser['version'];
       } else {
           $browsername = $lang->extendeduseradmininfo_unknown;
       }
        
       if ($browser['platform'] != "") {
           $operatingsys = $browser['platform'];
       } else {
           $operatingsys = $lang->extendeduseradmininfo_unknown;
       }

       $temp = str_replace(array('___LASTIP___', '___AGENT___', '___BROWSER___', '___OS___'), array($ipadress, $useragent, $browsername, $operatingsys), $infoTable);
   } else {
if ($infoTable == '') {
eval("\$infoTable = \"".$templates->get("extendeduseradmininfo_view_noinfos")."\";");
}

$temp = $infoTable;
}
   $advInfo = $temp;

$geoTemp = "";
if (filter_var($lastip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
// Wenn IPv4, dann Standort bestimmen
require_once("inc/functions_extendeduseradmininfos.php");
$geo = getGeoInformations($lastip);

if ($geoTable == '') {
eval("\$geoTable = \"".$templates->get("extendeduseradmininfo_geo_info")."\";");
}

if ($geo['Country'] == "")
           $geo['Country'] = $lang->extendeduseradmininfo_unknown;

if ($geo['CountryCode'] != "")
           $geo['CountryCode'] = " (" . $geo['CountryCode'] . ")";

if ($geo['City'] == "")
           $geo['City'] = $lang->extendeduseradmininfo_unknown;

if ($geo['Latitude'] == "")
           $geo['Latitude'] = $lang->extendeduseradmininfo_unknown;

if ($geo['Longitude'] == "")
           $geo['Longitude'] = $lang->extendeduseradmininfo_unknown;

if ($geo['Region'] == "")
           $geo['Region'] = $lang->extendeduseradmininfo_unknown;

if ($geo['ContinentCode'] == "")
           $geo['ContinentCode'] = $lang->extendeduseradmininfo_unknown;

if ($geo['PostalCode'] != "")
$geo['PostalCode'] .= " ";

$geoTemp = str_replace(
array('___COUNTRY___', '___COUNTRYCODE___', '___CITY___', '___LATITUDE___', '___LONGITUDE___', '___POSTALCODE___', '___REGION___', '___CONTINENTCODE___'), 
array($geo['Country'], $geo['CountryCode'], $geo['City'], $geo['Latitude'], $geo['Longitude'], $geo['PostalCode'], $geo['Region'], $geo['ContinentCode']),
 $geoTable);
} else {
if ($geoTable == '') {
eval("\$geoTable = \"".$templates->get("extendeduseradmininfo_view_nogeoinfos")."\";");
}

$geoTemp = $geoTable;
}
$geoInfo = $geoTemp;
}

?>


group in profile....shows the usergroup in profile
<?php



if(!defined('IN_MYBB'))

    die('This file cannot be accessed directly.');



$plugins->add_hook('member_profile_end', 'grpinprof_run');



function grpinprof_info()

{

    return array(

        'name'          => 'Memberships in Profile',

        'description'   => 'Displays what usergroups a user is in on their profile page.',

        'website'       => 'http://mybbhacks.zingaburga.com/',

        'author'        => 'ZiNgA BuRgA',

        'authorsite'    => 'http://zingaburga.com/',

        'version'       => '1.0',

        'compatibility' => '1*',

        'guid'          => ''

    );

}



// need to add {$pmy_group} and {$sec_groups} to member_profile template



function grpinprof_activate()
{

    require MYBB_ROOT.'inc/adminfunctions_templates.php';

    find_replace_templatesets('member_profile', '#\{\$memregdate\}\<br /\>#', '$0<strong>Group           Memberships</strong>: <strong>{$pmy_group}</strong>{$sec_groups}<br />');

}



function grpinprof_deactivate()

{

    require MYBB_ROOT.'inc/adminfunctions_templates.php';
    
    find_replace_templatesets('member_profile', '#'.preg_quote('<strong>Group Memberships</strong>:      <strong>{$pmy_group}</strong>{$sec_groups}<br />').'#', '', 0);

}



function grpinprof_run()

{

    global $groupscache, $pmy_group, $sec_groups, $memprofile;

    if(!is_array($groupscache))
    
    {
    
        global $cache;

        $groupscache = $cache->read('usergroups');

    }

    $ug = &$groupscache[$memprofile['usergroup']];

    $pmy_group = format_name($ug['title'], $ug['gid'], 0);



    $sec_groups = $comma = '';

    $sug = array_unique(explode(',',$memprofile['additionalgroups']));

    foreach($sug as $gid)

    {

        $ug = &$groupscache[$gid];

        if(!isset($ug)) continue;

        $sec_groups .= $comma.format_name($ug['title'], $ug['gid'], 0);

        if(!$comma) $comma = ', ';

    }

    if($sec_groups)

    {

        $sec_groups = ', '.$sec_groups;

    }

}



?>

Im looking at the first one, and im not sure how to
1) show the same info to admins only
2) but allow a second entry to show to everyone for the OS only.