Advertisement
rainbowdash28

Zählen-Thread Signatur

Aug 27th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.22 KB | None | 0 0
  1. <?php
  2. Header('Content-type: image/png');
  3.  
  4. /**
  5.  * First the parse process~
  6.  * $buffer contains a part of the stats website of the counter thread
  7. **/
  8.  
  9. $parser = fopen('http://www.bronies.de/misc.php?action=whoposted&tid=1880', 'r');
  10.  
  11. while(!feof($parser)) {
  12.    
  13.     /**
  14.      * First gets the "all" count~
  15.     **/
  16.      
  17.     $buffer = fgets($parser, 4096);
  18.     if(preg_match('/<strong>Gesamtanzahl der Beitr.*ge: ([^<]*)<\/strong>/', $buffer)) $all = $buffer;
  19.    
  20.     if(isset($next)) {
  21.         $user = $buffer;
  22.         unset($next);
  23.     }
  24.    
  25.     /**
  26.      * Get username by UID
  27.     **/
  28.    
  29.     if(isset($_REQUEST['uid'])) {
  30.        
  31.         // don't overwrite the username again if it's set already
  32.         if(isset($username) && strlen($username) > 0) continue;
  33.        
  34.         if(preg_match('/uid='.$_REQUEST['uid'].'"/', $buffer)) {
  35.             // get username
  36.             preg_match('/false;">(.*?)<\//', $buffer, $username);
  37.             // check if strong is still founded if so - it's a mod+
  38.             if(!empty($username[1])) {
  39.                 if(preg_match('/<strong>/', $username[1])) {
  40.                     $username = explode('<strong>', $username[1]);
  41.                 }
  42.                
  43.                 $username = $username[1];
  44.             }
  45.         }
  46.    
  47.     }  
  48.     /**
  49.      * else get it by .. well .. username
  50.     **/
  51.     elseif(isset($_REQUEST['usr'])) {
  52.         $username = $_REQUEST['usr'];
  53.     }
  54.    
  55.     /**
  56.      * get user count by username
  57.     **/
  58.     if(isset($username) && is_string($username)) {
  59.         if(preg_match('/>('.$username.')</', $buffer)) {
  60.             $next = TRUE;
  61.         }
  62.     } else {
  63.         $username = NULL;
  64.     }
  65.        
  66. }
  67.  
  68. fclose($parser);
  69.  
  70. /**
  71.  * get count numbers by the rough parsed informations
  72. **/
  73. if(isset($user))
  74.     preg_match('/">((?!<a))(.*?)<\//', $user, $cur_count);
  75.     preg_match('/e: (.*?)<\//', $all, $all_count);
  76.  
  77. // set $v to the used version - if nothing given use v1
  78. $v = (isset($_REQUEST['v'])) ? (int)$_REQUEST['v'] : 1;
  79.  
  80. switch($v) {
  81.     case '1':
  82.         $png = imagecreatefrompng('./userbar.png');
  83.         $font = 'Impact.ttf';
  84.         $size = 8;
  85.         $pos = array('x' => 10, 'y' => 14);
  86.         if(isset($cur_count) && !isset($_REQUEST['col'])) {
  87.             if($cur_count[1] <= 1000) $text_color = imagecolorallocate($png, 229, 163, 98);
  88.             if($cur_count[1] <= 600) $text_color = imagecolorallocate($png, 221, 229, 98);
  89.             if($cur_count[1] <= 300) $text_color = imagecolorallocate($png, 196, 196, 196);
  90.             if($cur_count[1] > 1000)$text_color = imagecolorallocate($png, 163, 229, 98);
  91.         }
  92.         break;
  93.     case '2':
  94.         switch($username) {
  95.             case 'Demonheart':
  96.                 $png = imagecreatefrompng('./userbar2_violet.png');
  97.                 break;
  98.             case 'Land':
  99.                 $png = imagecreatefrompng('./userbar2_red.png');
  100.                 break;
  101.             default:
  102.                 $png = imagecreatefrompng('./userbar2.png');
  103.                 break;
  104.         }
  105.         $font = 'Lato-Regular.ttf';
  106.         $size = 9;
  107.         $pos = array('x' => 8, 'y' => 17);
  108.         break;
  109. }
  110.  
  111. // set text it will be exactly the same on both versions
  112. if(isset($cur_count) && is_array($cur_count)) {
  113.     $text = '#'.$all_count[1].'  ( '.$cur_count[2].' )  '.$username;
  114. } else {
  115.     $text = '#'.$all_count[1];
  116. }
  117. // set text color default to white if no specific is given
  118. if(!isset($text_color))
  119. $text_color = imagecolorallocate($png, 255,255,255);
  120. // set text on the image
  121. imagettftext($png, $size, 0, $pos['x'], $pos['y'], $text_color, $font, $text);
  122.  
  123. /**
  124.  * print image and destroy it for less resource usage
  125. **/
  126. imagepng($png);
  127. imagedestroy($png);
  128.  
  129. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement