Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 4.59 KB | None | 0 0
  1. <?php
  2.  
  3. global $tmp, $cache, $host, $user, $pass, $db, $realm_name;
  4. $realm_status = new cache('realm_status', 30);
  5. $output = $realm_status->get_cache();
  6.  
  7. //Remake cache
  8. if(!$output)
  9. {
  10.    
  11.     //Let's make some statistics! :D
  12.     $stat['accs'] = 0;²
  13.     $stat['on']   = 0;
  14.     $stat['char'] = 0;
  15.     $stat['hor']  = 0; //Get your mind out of the gutter, young boy! :P
  16.     $stat['all']  = 0; //Beats hordies 24/7, fosho!
  17.    
  18.     //Total Accounts:
  19.     $account = new mysql;
  20.     $account->connect($host['realm'], $user['realm'], $pass['realm'], true, $db['accounts']);
  21.     $count = $account->query("SELECT count(*) FROM accounts");
  22.     $count = $account->fetch_array($count);
  23.     $stat['accs'] = $count['count(*)']; //Bampf, total accounts!
  24.    
  25.     //Online/Total characters:
  26.     $characters = new MySQL();
  27.     $characters->connect($host['realm'], $user['realm'], $pass['realm'], true, $db['characters']);
  28.     $count = $characters->query("SELECT race, online FROM characters");
  29.     while($row = $characters->fetch_array($count)) {
  30.         if($row['online'] == '1') $stat['on']++; //Total Online
  31.        
  32.         if(($row['race'] == 1 || $row['race'] == 3 || $row['race'] == 4 || $row['race'] == 7 || $row['race'] == 11)) //Online Alliance
  33.             $stat['all']++;
  34.        
  35.         $stat['char']++; //Total characters
  36.     }
  37.    
  38.     //This way, we're not wasting time on the hordies
  39.     $stat['hor'] = $stat['char'] - $stat['all'];
  40.  
  41.     //Let's make sure we don't get errors
  42.     foreach($stat as $key => $val) {
  43.         $stat[$key] = ($val) ? $val : '0';
  44.     }
  45.    
  46.     //Now, let's make a nice little percentage
  47.     $percent = $stat['on'] / 1000;   //Then, make it the length of the bar
  48.     $percent = round( $percent, 2);  //We need to round it, so that it doesn't look messy
  49.     if($percent > 95) $percent = 95; //The design can't take more than 95%, so this 'fixes' it
  50.    
  51.     //Alright, now let's cache all this junk.. in yo trunk.. 'Choo gonna do with all that junk, all that junk - in yo trunk?
  52.     $output = "{$stat['on']}|{$stat['char']}|{$stat['hor']}|{$stat['all']}|{$percent}|{$stat['accs']}";
  53.     $realm_status->set_cache($output);
  54. }
  55.  
  56. //Cached? Well we need to ready this guy up!
  57. else {
  58.     $output = explode('|', $output);
  59.    
  60.     $stat['accs']  = $output[5]; //Total Characters
  61.     $stat['on']   = $output[0]; //Online players
  62.     $stat['char'] = $output[1]; //Total Characters
  63.     $stat['hor']  = $output[2]; //Total Hordies
  64.     $stat['all']  = $output[3]; //Total Alliances
  65.     $percent      = $output[4]; //Percent bar
  66. }
  67.  
  68. //And let's set dem vars! :)
  69. $tmp->set_var('total_accounts', $stat['accs']);
  70. $tmp->set_var('online_players', $stat['on']);
  71. $tmp->set_var('total_chars', $stat['char']);
  72. $tmp->set_var('total_hors', $stat['hor']);
  73. $tmp->set_var('total_alls', $stat['all']);
  74. $tmp->set_var('percent', $percent);
  75.  
  76. #Shoutbox
  77. global $site, $tmp, $cache, $username;
  78. $shout_msg = ' ';
  79. $shout_color = 'red';
  80.  
  81. //If a user has posted a shout
  82. if(isset($_POST['submit_shout']))
  83. {
  84.     //Check the user is logged in
  85.     if(@isset($_SESSION['ulogged_in']) and $_SESSION['ulogged_in'] === true)
  86.     {
  87.         //Let's make sure the shout isn't empty
  88.         if(!empty($_POST['shoutmsg']))
  89.         {
  90.        
  91.             //Let's set some vars!
  92.             $time = @date("Y-m-d");
  93.             $shout = mysql_real_escape_string($_POST['shoutmsg']);
  94.            
  95.             //And now, put it in the database
  96.             $site->query("INSERT INTO shoutbox (user, shout, time, ip) VALUES ('{$username}', '{$shout}', '{$time}', '{$_SERVER['REMOTE_ADDR']}')");
  97.            
  98.             //Update status
  99.             $shout_msg = 'Message submitted';
  100.             $shout_color = 'green';
  101.            
  102.             //Now, we clear the cache
  103.             @unlink('cache/shoutbox.cache');
  104.         } else $shout_msg = 'Your shout is empty!';
  105.     } else $shout_msg = 'You must be logged in for this!';
  106. }
  107.  
  108. //Get shouts
  109. $shoutbox = new cache('shoutbox', 30);
  110. $output = $shoutbox->get_cache();
  111.  
  112. //Same drill, if no cache:
  113. if(!$output)
  114. {
  115.     $query = $site->query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 5");
  116.  
  117.     //Found any shouts?
  118.     if($site->num_rows($query) > 0)
  119.     {
  120.         //Let's display dem mon!
  121.         while($row = $site->fetch_array($query))
  122.         {
  123.             $output .= '<div class="shout"><img src="template/RedemptionWoW/images/bullet.png" width="5" height="5" alt="bullet" />';
  124.             $output .= ' [<span class="blue">'.$row['time'].'</span>] '.$row['user'].' shouts:<br />';
  125.             $output .= '<span class="shoutmsg">'.nl2br($row['shout']).'</span></div>';
  126.         }
  127.  
  128.     }
  129.  
  130.     //No shouts? Well, let's post up a message!
  131.     else
  132.     {
  133.         $output .= '<div class="shout"><img src="template/RedemptionWoW/images/bullet.png" width="5" height="5" alt="bullet" />';
  134.         $output .= 'There are no shouts!</div>'; // :'(
  135.     }
  136. }
  137.  
  138. $tmp->set_var('shoutbox', $output);
  139. $tmp->set_var('shout_msg', $shout_msg);
  140. $tmp->set_var('shout_color', $shout_color);
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement