Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 19.42 KB | None | 0 0
  1. <?php
  2. /*
  3. Author: itsmeJAY
  4. Year: 2019
  5. Version tested: 1.8.21
  6. Contact and support exclusively in the MyBB.de Forum (German Community - https://www.mybb.de/).
  7. */
  8.  
  9.  
  10. if (!defined("IN_MYBB")) {
  11.     die("Direct initialization of this file is not allowed.");
  12. }
  13.  
  14. // Hooks and Functions
  15. $plugins->add_hook("member_profile_end", "steamprofile_curl");
  16. $plugins->add_hook("postbit", "steamprofile_showthread");
  17.  
  18. function steamprofile_info()
  19. {
  20.     global $db, $lang;
  21. // Sprachdatei laden
  22.     $lang->load("steamprofile");
  23.  
  24.     return array(
  25.         "name" => $db->escape_string($lang->sp_steamprofile_name),
  26.         "description" => $db->escape_string($lang->sp_steamprofile_desc),
  27.         "website" => "https://www.mybb.de/forum/user-10220.html",
  28.         "author" => "itsmeJAY",
  29.         "authorsite" => "https://www.mybb.de/forum/user-10220.html",
  30.         "version" => "1.1.0",
  31.         "guid" => "",
  32.         "codename" => "steamprofile",
  33.         "compatibility" => "18*"
  34.     );
  35. }
  36.  
  37. function steamprofile_install()
  38. {
  39.     global $db, $mybb, $lang, $cache;
  40. // Sprachdatei laden
  41.     $lang->load("steamprofile");
  42.  
  43.     $setting_group = array(
  44.         'name' => 'steamprofile',
  45.         'title' => $db->escape_string($lang->sp_steamprofile_name),
  46.         'description' => $db->escape_string($lang->sp_steamprofile_name_setting_desc),
  47.         'disporder' => 5,
  48.         'isdefault' => 0
  49.     );
  50.  
  51.     $gid = $db->insert_query("settinggroups", $setting_group);
  52.  
  53.     // Einstellungen
  54.  
  55.     $setting_array = array(
  56.         'steamprofile_api_key' => array(
  57.             'title' => $db->escape_string($lang->sp_steamapi_key),
  58.             'description' => $db->escape_string($lang->sp_steamapi_key_desc),
  59.             'optionscode' => 'text',
  60.             'value' => '0', // Default
  61.             'disporder' => 1
  62.         ),
  63.         'steamprofile_show_last_game' => array(
  64.             'title' => $db->escape_string($lang->sp_lastgame),
  65.             'description' => $db->escape_string($lang->sp_lastgame_desc),
  66.             'optionscode' => 'yesno',
  67.             'value' => 1, // Default
  68.             'disporder' => 2
  69.         ),
  70.         'steamprofile_show_steamname' => array(
  71.             'title' => $db->escape_string($lang->sp_steamname),
  72.             'description' => $db->escape_string($lang->sp_steamname_desc),
  73.             'optionscode' => 'yesno',
  74.             'value' => 1, // Default
  75.             'disporder' => 3
  76.         ),
  77.         'steamprofile_show_lastlogoff' => array(
  78.             'title' => $db->escape_string($lang->sp_lastlogoff),
  79.             'description' => $db->escape_string($lang->sp_lastlogoff_desc),
  80.             'optionscode' => 'yesno',
  81.             'value' => 1, // Default
  82.             'disporder' => 4
  83.         ),
  84.         'steamprofile_show_onlinestatus' => array(
  85.             'title' => $db->escape_string($lang->sp_showonline),
  86.             'description' => $db->escape_string($lang->sp_showonline_desc),
  87.             'optionscode' => 'yesno',
  88.             'value' => 1, // Default
  89.             'disporder' => 5
  90.         ),
  91.         'steamprofile_show_bitsteamid' => array(
  92.             'title' => $db->escape_string($lang->sp_steamid),
  93.             'description' => $db->escape_string($lang->sp_steamid),
  94.             'optionscode' => 'yesno',
  95.             'value' => 1, // Default
  96.             'disporder' => 6
  97.         ),
  98.         'steamprofile_show_accountcreated' => array(
  99.             'title' => $db->escape_string($lang->sp_accountcreated),
  100.             'description' => $db->escape_string($lang->sp_accountcreated_desc),
  101.             'optionscode' => 'yesno',
  102.             'value' => 1, // Default
  103.             'disporder' => 7
  104.         ),
  105.         'steamprofile_show_avatar' => array(
  106.             'title' => $db->escape_string($lang->sp_avatar),
  107.             'description' => $db->escape_string($lang->sp_avatar_desc),
  108.             'optionscode' => 'yesno',
  109.             'value' => 1, // Default
  110.             'disporder' => 8
  111.         ),
  112.         'steamprofile_show_ingame' => array(
  113.             'title' => $db->escape_string($lang->sp_ingame),
  114.             'description' => $db->escape_string($lang->sp_ingame_desc),
  115.             'optionscode' => 'yesno',
  116.             'value' => 1, // Default
  117.             'disporder' => 9
  118.         ),
  119.         'steamprofile_show_gamecount' => array(
  120.             'title' => $db->escape_string($lang->sp_gamecount),
  121.             'description' => $db->escape_string($lang->sp_gamecount_desc),
  122.             'optionscode' => 'yesno',
  123.             'value' => 1, // Default
  124.             'disporder' => 10
  125.         ),
  126.         'steamprofile_show_postbit' => array(
  127.             'title' => $db->escape_string($lang->sp_postbit),
  128.             'description' => $db->escape_string($lang->sp_postbit_desc),
  129.             'optionscode' => 'yesno',
  130.             'value' => 1, // Default
  131.             'disporder' => 11
  132.         ),
  133.     );
  134.  
  135.     // Einstellungen in Datenbank speichern
  136.     foreach ($setting_array as $name => $setting) {
  137.         $setting['name'] = $name;
  138.         $setting['gid'] = $gid;
  139.  
  140.         $db->insert_query('settings', $setting);
  141.     }
  142.  
  143.     //Erstelle neues Profilfeld
  144.  
  145.     $new_profile_field = array(
  146.         "name" => $db->escape_string($lang->sp_steamid_enter),
  147.         "description" => $db->escape_string($lang->sp_steamid_enter_desc),
  148.         "disporder" => 6,
  149.         "maxlength" => intval('60'),
  150.         "type" => 'text',
  151.         "required" => intval('0'),
  152.         "viewableby" => '-1',
  153.         "editableby" => '-1',
  154.         "regex" => ''
  155.     );
  156.  
  157.     $fid = $db->insert_query("profilefields", $new_profile_field);
  158.  
  159.     $db->write_query("ALTER TABLE " . TABLE_PREFIX . "userfields ADD fid{$fid} TEXT");
  160.  
  161.     // Rebuild Settings! :-)
  162.     rebuild_settings();
  163.  
  164.     //Cache Update
  165.     $cache->update_profilefields();
  166.  
  167. }
  168.  
  169. function steamprofile_is_installed()
  170. {
  171.     global $db;
  172.  
  173.     // Hole FID des Profilfeldes aus der Datenbank
  174.     $query = $db->simple_select("profilefields", "*", "name='SteamID'");
  175.     $profile_field = $db->fetch_array($query);
  176.  
  177.     if (!empty($profile_field)) {
  178.         return true;
  179.     } else {
  180.         return false;
  181.     }
  182. }
  183.  
  184. function steamprofile_activate()
  185. {
  186.     //Template ergänzen
  187.     require MYBB_ROOT . "/inc/adminfunctions_templates.php";
  188.     find_replace_templatesets("member_profile", "#" . preg_quote('{$contact_details}') . "#i", '{$contact_details}<br/>{$steamprofile}');
  189.     find_replace_templatesets("postbit", "#" . preg_quote('{$post[\'userstars\']}') . "#i", '{$post[\'userstars\']}<br/>{$post[\'steamprofile\']}');
  190. }
  191.  
  192. function steamprofile_deactivate()
  193. {
  194.     //Template ergänzen
  195.     require MYBB_ROOT . "/inc/adminfunctions_templates.php";
  196.     find_replace_templatesets("member_profile", "#" . preg_quote('<br/>{$steamprofile}') . "#i", '');
  197.     find_replace_templatesets("postbit", "#" . preg_quote('<br/>{$post[\'steamprofile\']}') . "#i", '');
  198. }
  199.  
  200. function steamprofile_uninstall()
  201. {
  202.     global $db;
  203.  
  204.     $db->delete_query('settings', "name IN ('steamprofile_api_key','steamprofile_show_last_game', 'steamprofile_show_steamname', 'steamprofile_show_lastlogoff', 'steamprofile_show_onlinestatus', 'steamprofile_show_bitsteamid', 'steamprofile_show_ingame', 'steamprofile_show_gamecount', 'steamprofile_show_postbit')");
  205.     $db->delete_query('settinggroups', "name = 'steamprofile'");
  206.  
  207.     // Hole FID des Profilfeldes aus der Datenbank
  208.     $query = $db->simple_select("profilefields", "*", "name='SteamID'");
  209.     $profile_field = $db->fetch_array($query);
  210.  
  211.     // Lösche das Profilfeld
  212.     if ($profile_field['fid']) {
  213.         $db->delete_query("profilefields", "fid='{$profile_field['fid']}'");
  214.         $db->write_query("ALTER TABLE " . TABLE_PREFIX . "userfields DROP fid{$profile_field['fid']}");
  215.     }
  216.     // Rebuild Settings! :-)
  217.     rebuild_settings();
  218.  
  219. }
  220.  
  221.  
  222. function steamprofile_curl()
  223. {
  224.     global $mybb, $steamprofile, $db, $lang, $userfields;
  225.  
  226.     // Sprachdatei laden
  227.     $lang->load("steamprofile");
  228.  
  229.     function request($url, $int, $api)
  230.     {
  231.         if ($int == 1) {
  232.             $curl = curl_init();
  233.             curl_setopt_array($curl, [
  234.                 CURLOPT_RETURNTRANSFER => 1,
  235.                 CURLOPT_URL => 'http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?key=' . $api . '&steamid=' . $url . '&format=json&count=1'
  236.             ]);
  237.             $result = curl_exec($curl);
  238.             curl_close($curl);
  239.         }
  240.  
  241.         if ($int == 2) {
  242.             $curl = curl_init();
  243.             curl_setopt_array($curl, [
  244.                 CURLOPT_RETURNTRANSFER => 1,
  245.                 CURLOPT_URL => 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $api . '&steamids=' . $url . '&format=json'
  246.             ]);
  247.             $result = curl_exec($curl);
  248.             curl_close($curl);
  249.         }
  250.  
  251.         if ($int == 3) {
  252.             $curl = curl_init();
  253.             curl_setopt_array($curl, [
  254.                 CURLOPT_RETURNTRANSFER => 1,
  255.                 CURLOPT_URL => 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=' . $api . '&steamid=' . $url . '&format=json'
  256.             ]);
  257.             $result = curl_exec($curl);
  258.             curl_close($curl);
  259.         }
  260.  
  261.         $result = json_decode($result, true);
  262.         return $result;
  263.  
  264.     }
  265.  
  266.     // Hole FID des Profilfeldes aus der Datenbank
  267.     $query = $db->simple_select("profilefields", "*", "name='SteamID'");
  268.     $profile_field = $db->fetch_array($query);
  269.     $fid = $profile_field['fid'];
  270.  
  271.     // Fülle Variable mit Tabelle
  272.  
  273.     $steamprofile = '<br/><table border="0" cellspacing="0" cellpadding="5" class="tborder tfixed">
  274.     <colgroup>
  275.     <col style="width: 30%;">
  276.     </colgroup>
  277.     <tbody><tr>
  278.         <td colspan="3" class="thead"><strong>' . $lang->sp_f_steamdetails . '</strong></td>
  279.     </tr>';
  280.  
  281.     // Zeige den Steamnamen an
  282.     if ($mybb->settings['steamprofile_show_steamname'] == 1 || $mybb->settings['steamprofile_show_lastlogoff'] == 1 || $mybb->settings['steamprofile_show_avatar'] == 1 || $mybb->settings['steamprofile_show_onlinestatus'] == 1 || $mybb->settings['steamprofile_show_bitsteamid'] == 1 || $mybb->settings['steamprofile_show_accountcreated'] || $mybb->settings['steamprofile_show_ingame'] == 1) {
  283.         $result = request($userfields['fid' . $fid], 2, $mybb->settings['steamprofile_api_key']);
  284.  
  285.         // Zeige Steam-Namen
  286.         if (!empty($result['response']['players']['0']['personaname']) && $mybb->settings['steamprofile_show_steamname'] == 1) {
  287.             $steamprofile .= '<tr>
  288. <td class="trow1"><strong>' . $lang->sp_f_steamname . '</strong></td>
  289. <td class="trow1">' . $result['response']['players']['0']['personaname'] . '</td>';
  290.  
  291.             // Zeige Profilbild an, sofern gewünscht.
  292.             if (!empty($result['response']['players']['0']['avatarfull']) && $mybb->settings['steamprofile_show_avatar'] == 1) {
  293.                 $steamprofile .= '<td rowspan="8" style="padding: 0; margin: 0; float: none; text-align: center;"><img align="right" alt="' . $lang->sp_f_avatar . '" height="184" width="184" style="border-radius: 50%; float: none; text-align: center;"  src="' . $result['response']['players']['0']['avatarfull'] . '"></td>';
  294.             }
  295.             $steamprofile .= "</tr>";
  296.         }
  297.  
  298.         // Zeige letzten Login
  299.         if (!empty($result['response']['players']['0']['lastlogoff']) && $mybb->settings['steamprofile_show_lastlogoff'] == 1) {
  300.             $steamprofile .= '<tr>
  301. <td class="trow1"><strong>' . $lang->sp_f_lastlogin . '</strong></td>
  302. <td class="trow1">' . date("d.m.Y - H:i", $result['response']['players']['0']['lastlogoff']) . '</td>
  303. </tr>';
  304.         }
  305.  
  306.         // Zeige Status
  307.         if ($mybb->settings['steamprofile_show_onlinestatus'] == 1) {
  308.             $status = "";
  309.  
  310.             switch ($result['response']['players']['0']['personastate']) {
  311.                 case 0:
  312.                     $status = '<span style="color: #ff0000;"><strong>Offline</strong></span>';
  313.                     break;
  314.                 case 1:
  315.                     $status = '<span style="color: #008000;"><strong>Online</strong></span>';
  316.                     break;
  317.                 case 2:
  318.                     $status = $lang->sp_f_busy;
  319.                     break;
  320.                 case 3:
  321.                     $status = $lang->sp_f_away;
  322.                     break;
  323.                 case 4:
  324.                     $status = $lang->sp_f_snooze;
  325.                     break;
  326.                 case 5:
  327.                     $status = $lang->sp_f_trade;
  328.                     break;
  329.                 case 6:
  330.                     $status = $lang->sp_f_play;
  331.                     break;
  332.                 default:
  333.                     $status = '<span style="color: #ff0000;"><strong>Offline</strong></span>';
  334.             }
  335.  
  336.             $steamprofile .= '<tr>
  337. <td class="trow1"><strong>' . $lang->sp_f_currentstatus . '</strong></td>
  338. <td class="trow1">' . $status . '</td>
  339. </tr>';
  340.         }
  341.  
  342.         // Zeige 64bit SteamID
  343.         if (!empty($result['response']['players']['0']['steamid']) && $mybb->settings['steamprofile_show_bitsteamid'] == 1) {
  344.             $steamprofile .= '<tr>
  345. <td class="trow1"><strong>' . $lang->sp_f_steamid . '</strong></td>
  346. <td class="trow1"><a href="' . $result['response']['players'][0]['profileurl'] . '">' . $result['response']['players']['0']['steamid'] . '</a></td>
  347. </tr>';
  348.         }
  349.  
  350.         // Zeige an, wann der Steam Account erstellt wurde
  351.         if (!empty($result['response']['players']['0']['timecreated']) && $mybb->settings['steamprofile_show_accountcreated'] == 1) {
  352.             $steamprofile .= '<tr>
  353. <td class="trow1"><strong>' . $lang->sp_f_acccreated . '</strong></td>
  354. <td class="trow1">' . date("d.m.Y - H:i:s", $result['response']['players']['0']['timecreated']) . '</td>
  355. </tr>';
  356.         }
  357.     }
  358.     // Zeige das letzte gespielte Spiel inklusive 16x16 Icon an!
  359.     if ($mybb->settings['steamprofile_show_last_game'] == 1) {
  360.         $result = request($userfields['fid' . $fid], 1, $mybb->settings['steamprofile_api_key']);
  361.         if (!empty($result['response']['games']['0']['name'])) {
  362.             $steamprofile .= '<tr>
  363. <td class="trow1"><strong>' . $lang->sp_f_lastplayed . '</strong></td>
  364. <td class="trow1"><img alt="Icon" height="16px" width="16px" src="http://media.steampowered.com/steamcommunity/public/images/apps/' . $result['response']['games'][0]['appid'] . '/' . $result['response']['games'][0]['img_icon_url'] . '.jpg" > ' . $result['response']['games']['0']['name'] . '<br/>
  365. (<em>' . $lang->sp_f_l2w . '</em> ' . number_format(round($result['response']['games'][0]['playtime_2weeks'] / 60, 2), '2', '.', ',') . ' ' . $lang->sp_f_hours . ')<br>
  366. (<em>' . $lang->sp_f_total . '</em> ' . number_format(round($result['response']['games'][0]['playtime_forever'] / 60, 2), 0, ".", ',') . '  ' . $lang->sp_f_hours . ')<br>
  367. </td>
  368. </tr>';
  369.         }
  370.     }
  371.  
  372.     // Zeige an, wie viele Spiele der Spieler hat
  373.     if ($mybb->settings['steamprofile_show_gamecount'] == 1) {
  374.         $result = request($userfields['fid' . $fid], 3, $mybb->settings['steamprofile_api_key']);
  375.         if (!empty($result['response']['game_count'])) {
  376.             $steamprofile .= '<tr>
  377. <td class="trow1"><strong>' . $lang->sp_f_gamescounted . '</strong></td>
  378. <td class="trow1">' . $result['response']['game_count'] . '</td>
  379. </tr>';
  380.         }
  381.     }
  382.  
  383.     // Zeige an, ob Spieler In-Game ist!
  384.     if ($mybb->settings['steamprofile_show_ingame'] == 1) {
  385.         $result = request($userfields['fid' . $fid], 2, $mybb->settings['steamprofile_api_key']);
  386.         if (!empty($result['response']['players']['0']['gameextrainfo'])) {
  387.             $steamprofile .= '<tr>
  388. <td class="trow1" colspan="3" style="text-align: center; background-color: #0066a2; color: #fff;"><strong>' . $lang->sp_f_currentlyplaying . ' ' . $result['response']['players']['0']['gameextrainfo'] . '</strong></td></td>
  389. </tr>';
  390.         }
  391.     }
  392.  
  393.     $steamprofile .= '</tbody></table>';
  394.  
  395.     if (empty($userfields['fid' . $fid]) || $userfields['fid' . $fid] == 0) {
  396.         $steamprofile = "";
  397.     }
  398. }
  399.  
  400. function steamprofile_showthread(&$post)
  401. {
  402.     global $mybb, $db, $lang;
  403.  
  404.     if ($mybb->settings['steamprofile_show_postbit'] == 1 && $mybb->settings['steamprofile_api_key'] != 0 && !empty($mybb->settings['steamprofile_api_key'])) {
  405.  
  406.         $lang->load("steamprofile");
  407.  
  408.         // Hole FID des Profilfeldes aus der Datenbank
  409.         $query = $db->simple_select("profilefields", "*", "name='SteamID'");
  410.         $profile_field = $db->fetch_array($query);
  411.         $fid = $profile_field['fid'];
  412.         $user = get_user($post['uid']);
  413.  
  414.         // Sende Request
  415.  
  416.         if (!empty($user['fid' . $fid]) && $user['fid' . $fid] != 0) {
  417.             $curl = curl_init();
  418.             curl_setopt_array($curl, [
  419.                 CURLOPT_RETURNTRANSFER => 1,
  420.                 CURLOPT_URL => 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' . $mybb->settings['steamprofile_api_key'] . '&steamids=' . $user['fid' . $fid] . '&format=json'
  421.             ]);
  422.             $result = curl_exec($curl);
  423.             curl_close($curl);
  424.             $result = json_decode($result, true);
  425.         }
  426.  
  427.         if (isset($result['response']['players']['0']['gameextrainfo']) && !empty($result['response']['players']['0']['gameextrainfo'])) {
  428.             $post['steamprofile'] = '<div class="mysteam_list_wrapper" style="width: 200px;" >
  429.     <div class="steam_avatar_in-game steam_avatar mysteam_list_avatar" >
  430.         <div >
  431.             <a href="' . $result['response']['players']['0']['profileurl'] . '" target="_blank" ><img src="' . $result['response']['players']['0']['avatar'] . '" ></a>
  432.         </div>
  433.     </div>
  434.     <span class="steam_in-game smalltext" >
  435.         <div class="mysteam_list_status">
  436.             <div class="mysteam_status_wrapper" >
  437.                 <a href="' . $result['response']['players']['0']['profileurl'] . '" target="_blank" >' . $result['response']['players']['0']['personaname'] . '</a><br>
  438.                 ' . $lang->sp_f_ingame_pb . '<br>
  439.                 ' . $result['response']['players']['0']['gameextrainfo'] . '<br>
  440.             </div>
  441.         </div>
  442.     </span>
  443. </div>';
  444.         } else if ($result['response']['players']['0']['personastate'] == 1 && !isset($result['response']['players']['0']['gameextrainfo'])) {
  445.             $post['steamprofile'] = '<div class="mysteam_list_wrapper" style="width: 200px" >
  446.     <div class="steam_avatar_online steam_avatar mysteam_list_avatar" >
  447.         <div >
  448.             <a href="' . $result['response']['players']['0']['profileurl'] . '" target="_blank" ><img src="' . $result['response']['players']['0']['avatar'] . '" ></a>
  449.         </div>
  450.     </div>
  451.     <span class="steam_online smalltext" >
  452.         <div class="mysteam_list_status">
  453.             <div class="mysteam_status_wrapper" >
  454.                 <a href="' . $result['response']['players']['0']['profileurl'] . '" target="_blank" >' . $result['response']['players']['0']['personaname'] . '</a><br>
  455.                 Online<br>
  456.             </div>
  457.         </div>
  458.     </span>
  459. </div>';
  460.         } else {
  461.             $post['steamprofile'] = '<div class="mysteam_list_wrapper" style="width: 200px" >
  462.     <div class="steam_avatar_offline steam_avatar mysteam_list_avatar" >
  463.         <div >
  464.             <a href="' . $result['response']['players']['0']['profileurl'] . '" target="_blank" ><img src="' . $result['response']['players']['0']['avatar'] . '" ></a>
  465.         </div>
  466.     </div>
  467.     <span class="steam_offline smalltext" >
  468.         <div class="mysteam_list_status">
  469.             <div class="mysteam_status_wrapper" >
  470.                 <a href="' . $result['response']['players']['0']['profileurl'] . '" target="_blank" >' . $result['response']['players']['0']['personaname'] . '</a><br>
  471.                 Offline<br>
  472.             </div>
  473.         </div>
  474.     </span>
  475. </div>';
  476.         }
  477.     }
  478. }
  479.  
  480. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement