Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [skrypt] sygnaturki - v2, skrypt do robienia sygnaturek
Jim
post 16.10.2005, 16:22:41
Post #1





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 27.07.2005

Ostrzeżenie: (0%)
-----


Odświerzyłem ten skrypt - Teraz można pobrać z listy "Weekly Top Artist" w profilu www.last.fm artystę z pierwszego miejsca i wyświetlić.
Poniżej jest to zrobione dla mojego konta z loginem "bolomas". Wystarczy to zamienić na swój login.


Źródło:
  1. <?
  2. $cytaty = array (
  3. "Co masz zrobic zaraz, zrob jutro",
  4. "Komu w droge temu kaloryfer",
  5. "dzieci + zapalki = ogien  wiec  ogien - zapalki = dzieci"
  6. );
  7. // Aby użyć listy cytatów należy uzyc
  8. // "text_main" => $cycaty[rand( 0, count( $cycaty )-1)]
  9.  
  10.  
  11. // $dane : zawiera dane o wszystkich projektach do wyswietlenia na liscie
  12. $dane = array (
  13. array( 
  14. "text_main" =>  "Weekly Top Artist",
  15. "kolor" =>  array( 100, 10, 0 ) ),
  16. array( 
  17. "text_main" =>  "Moja galeria, blog i cos tam jeszcze" , 
  18. "progress" =>  85 , 
  19. "text_short" => "ostatnie poprawki" ),
  20. array( 
  21. "text_main" =>  "Jakis tam drugi projekt" , 
  22. "progress" =>  14 , 
  23. "text_short" => "projektowanie" ),
  24. array( 
  25. "text_main" =>  ":[ php 5.0.5 ]:[ MYSQL 5.0.16 ]:[ ALWAYS VALID HTML & CSS ]:[ SMARTY ]:" , 
  26. "kolor" =>  array( 0, 10, 80 ) )
  27. );
  28.  
  29. $kolory = array (
  30. // podstawowe kolory do całego obrazka
  31. array ( 255, 255, 255 ), // background
  32. array ( 245, 245, 245 ), // very_light
  33. array ( 230, 230, 230 ), // light
  34. array ( 180, 180, 180 ), // normal
  35. array ( 0, 0, 0 ), // ramka dla paska postepu
  36. array ( 0, 0, 0 ) // text
  37. );
  38.  
  39.  
  40.  
  41.  
  42.  
  43. for ($i=-1; $i<=count($dane); $i++) {
  44. if ($dane[$i]["text_main"] == "Weekly Top Artist") {
  45.  
  46. // Weekly Top Artist - pobierane ze strony profilu last.fm
  47. $file = fopen("sygnaturka.tmp","r");
  48. list ($wta['time'], $wta['artist']) = explode ("||", @fgets( $file, 1024 ));
  49. fclose($file);
  50. if ( (time()-604800) > $wta['time'] OR empty($wta['time']) ) {//604800 - tydzień w sek.
  51. $file = fopen("http://www.last.fm/user/bolomas/charts/&charttype=weekly","r");
  52. while ( $line = @fgets($file, 1024) ) {
  53. if ( strpos($line, '<span class="position star">1</span>') >=) {
  54. $line = @fgets($file, 2048);
  55. preg_match('/<.*?a.*?href=s*?['"].*?['"].*?>(.+)</.*?a.*?>/i', $line, $match); // <?
  56. $wta['artist'] = $match[1];
  57. break;
  58. }
  59. } 
  60. $file = fopen("sygnaturka.tmp","w");
  61. fwrite ($file, time()."||".$wta['artist']);
  62. fclose($file);
  63. }
  64. $dane[$i] ["text_main"] .= " - ".$wta['artist'];
  65.  
  66. break;
  67. }
  68. }
  69.  
  70.  
  71. header("Content-type: image/png");
  72. $im_height = count($dane) * 15 + 10;
  73. $im_width = 480;
  74. $im = ImageCreate( $im_width , $im_height);
  75.  
  76. //ustawiam potrzebne kolory
  77. $background = ImageColorAllocate($im, $kolory[0][0], $kolory[0][1], $kolory[0][2]);
  78. $very_light = ImageColorAllocate($im, $kolory[1][0], $kolory[1][1], $kolory[1][2]);
  79. $light =  ImageColorAllocate($im, $kolory[2][0], $kolory[2][1], $kolory[2][2]);
  80. $normal = ImageColorAllocate($im, $kolory[3][0], $kolory[3][1], $kolory[3][2]);
  81. $black =  ImageColorAllocate($im, $kolory[4][0], $kolory[4][1], $kolory[4][2]);
  82. $text =  ImageColorAllocate($im, $kolory[5][0], $kolory[5][1], $kolory[5][2]);
  83.  
  84.  
  85. foreach ( $dane as $projekt ) {
  86. $y = 5 + 15 * $item;
  87. // podľwietlenie linijki
  88. ImagefilledRectangle($im, 0, $y + 2, $im_width , $y + 11, $very_light);
  89. ImagefilledRectangle($im, 0, $y + 11, $im_width , $y + 12, $light);
  90.  
  91. if ($projekt["text_align_right"]) {
  92. if (empty($projekt["progress"])) {
  93. for ( $i=1; $i <= 79 - strlen( $projekt["text_main"] ); $i++ )
  94. $tmp .= " ";
  95. } else {
  96. for ( $i=1; $i <= 36 - strlen( $projekt["text_main"] ); $i++ )
  97. $tmp .= " ";
  98. }
  99. $projekt["text_main"] = $tmp . $projekt["text_main"];
  100. unset( $tmp );
  101. }
  102.  
  103. // jesli jest ustawiony specjalny kolor dla danego projektu to go ustaw
  104. if ( !empty($projekt["kolor"]) ) {
  105. $text_spec = ImageColorAllocate($im, $projekt["kolor"][0], $projekt["kolor"][1], $projekt["kolor"][2]);
  106. // wyľwieta nazwę / opis projektu
  107. ImageString($im, 2, 5, $y, $projekt["text_main"], $text_spec);
  108. } else 
  109. ImageString($im, 2, 5, $y, $projekt["text_main"], $text);
  110.  
  111.  
  112. if ( !empty($projekt["progress"]) ) {
  113. // tło pod pasek postępu
  114. ImageFilledRectangle($im, 230, $y + 2, 330, $y + 11, $light);
  115. ImageRectangle($im, 230, $y + 2, 330 , $y + 11, $normal);
  116.  
  117. /* ustawiam kolor paska postępu
  118.  W zależnoľci od podanej w $dane liczby ustawiane jest nasycenie barw
  119.  czerwonej i zielonej. Tzn im większy procent tym więcej zielonego, a mniej
  120.  czerwonego. W rezultacie 100% = kolor zielony, a np 1% = kolor czerwony. */
  121. $red = round( 255 - $projekt["progress"] * 255 / 100, true);
  122. $green = round( $projekt["progress"] * 255 / 100 , true);
  123. $kolor_paska = ImageColorAllocate($im, $red, $green, 0);
  124.  
  125. // pasek postępu
  126. ImageFilledRectangle($im, 230, $y + 2, 230 + $projekt["progress"], $y + 11, $kolor_paska);
  127. ImageRectangle($im, 230, $y + 2, 230 + $projekt["progress"], $y + 11, $black);
  128.  
  129. /* wyľwietla procent i dodatkowy tekst, 
  130.  a te małe if'y sš po to żeby kolumny zawsze były równo*/
  131. if ( $projekt["progress"] <= 9 ) 
  132. $projekt["progress"] = " " . $projekt["progress"];
  133. if ( $projekt["progress"] == 100 )
  134. $offset = 5;
  135. if ( !empty($projekt["kolor"]) )
  136. ImageString($im, 2, 340 - $offset, $y, $projekt["progress"] ."% ". $projekt["text_short"], $text_spec);
  137. else
  138. ImageString($im, 2, 340 - $offset, $y, $projekt["progress"] ."% ". $projekt["text_short"], $text);
  139. $offset = 0;
  140. }
  141.  
  142. $item++;
  143. }
  144. // rysuje ramkę
  145. ImageRectangle($im, 0, 0, $im_width - 1, $im_height - 1, $light);
  146.  
  147. //Imagepng($im,"sygnaturka.png");
  148. Imagepng($im);
  149. ImageDestroy($im);
  150. ?>


A tak to wygląda w akcji (link może działać wolno albo wcale)

Piszcie co myślicie... :roll2:

Ten post edytował Jim 17.03.2006, 16:29:10
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 20.06.2025 - 22:27