/libs/spell_lib.php

https://github.com/DarkTerror/MiniManager · PHP · 194 lines · 159 code · 27 blank · 8 comment · 32 complexity · 983b1d55015f0f0563c0db1b92754754 MD5 · raw file

  1. <?php
  2. //#############################################################################
  3. //get spell name by its id
  4. function spell_get_name($id, &$sqlm)
  5. {
  6. $spell_name = $sqlm->fetch_assoc($sqlm->query('SELECT field_142 FROM dbc_spell WHERE id='.$id.' LIMIT 1'));
  7. return $spell_name['field_142'];
  8. }
  9. //#############################################################################
  10. //get spell icon - if icon not exists in item_icons folder D/L it from web.
  11. function spell_get_icon($auraid, &$sqlm)
  12. {
  13. global $proxy_cfg, $get_icons_from_web, $item_icons;
  14. // Commented this part while i find the correct solution.
  15. $result = $sqlm->query('SELECT field_139 FROM dbc_spell WHERE id = '.$auraid.' LIMIT 1');
  16. if ($result)
  17. $displayid = $sqlm->result($result, 0, 'field_139');
  18. else
  19. $displayid = 0;
  20. if ($displayid)
  21. {
  22. $result = $sqlm->query('SELECT name FROM dbc_spellicon WHERE id = '.$displayid.' LIMIT 1');
  23. if($result)
  24. {
  25. $aura_uppercase = $sqlm->result($result, 0, 'name');
  26. $aura = strtolower($aura_uppercase);
  27. if ($aura)
  28. {
  29. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  30. {
  31. if (filesize(''.$item_icons.'/'.$aura.'.jpg') > 349)
  32. {
  33. return ''.$item_icons.'/'.$aura.'.jpg';
  34. }
  35. else
  36. {
  37. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  38. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  39. unlink(''.$item_icons.'/'.$aura.'.jpg');
  40. $aura = '';
  41. }
  42. }
  43. else
  44. $aura = '';
  45. }
  46. else
  47. $aura = '';
  48. }
  49. else
  50. $aura = '';
  51. }
  52. else
  53. $aura = '';
  54. if($get_icons_from_web)
  55. {
  56. $xmlfilepath='http://www.wowhead.com/spell=';
  57. $proxy = $proxy_cfg['addr'];
  58. $port = $proxy_cfg['port'];
  59. if (empty($proxy_cfg['addr']))
  60. {
  61. $proxy = 'www.wowhead.com';
  62. $xmlfilepath = 'spell=';
  63. $port = 80;
  64. }
  65. if ($aura == '')
  66. {
  67. //get the icon name
  68. $fp = @fsockopen($proxy, $port, $errno, $errstr, 0.5);
  69. if ($fp);
  70. else
  71. return 'img/INV/INV_blank_32.gif';
  72. $out = "GET /$xmlfilepath$auraid HTTP/1.0\r\nHost: www.wowhead.com\r\n";
  73. if (isset($proxy_cfg['user']))
  74. $out .= "Proxy-Authorization: Basic ". base64_encode ("{$proxy_cfg['user']}:{$proxy_cfg['pass']}")."\r\n";
  75. $out .="Connection: Close\r\n\r\n";
  76. $temp = '';
  77. fwrite($fp, $out);
  78. while ($fp && !feof($fp))
  79. $temp .= fgets($fp, 4096);
  80. fclose($fp);
  81. $wowhead_string = $temp;
  82. $temp_string1 = strstr($wowhead_string, 'Icon.create(');
  83. $temp_string2 = substr($temp_string1, 12, 50);
  84. $temp_string3 = strtok($temp_string2, ',');
  85. $temp_string4 = substr($temp_string3, 1, strlen($temp_string3) - 2);
  86. $aura_icon_name = $temp_string4;
  87. $aura_uppercase = $aura_icon_name;
  88. $aura = strtolower($aura_uppercase);
  89. }
  90. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  91. {
  92. if (filesize(''.$item_icons.'/'.$aura.'.jpg') > 349)
  93. {
  94. $sqlm->query('REPLACE INTO dbc_spellicon (id, name) VALUES (\''.$displayid.'\', \''.$aura.'\')');
  95. return ''.$item_icons.'/'.$aura.'.jpg';
  96. }
  97. else
  98. {
  99. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  100. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  101. unlink(''.$item_icons.'/'.$aura.'.jpg');
  102. }
  103. }
  104. //get the icon itself
  105. if (empty($proxy_cfg['addr']))
  106. {
  107. $proxy = 'static.wowhead.com';
  108. $port = 80;
  109. }
  110. $fp = @fsockopen($proxy, $port, $errno, $errstr, 0.5);
  111. if ($fp);
  112. else
  113. return 'img/INV/INV_blank_32.gif';
  114. $iconfilename = strtolower($aura);
  115. $file = 'http://static.wowhead.com/images/wow/icons/medium/'.$iconfilename.'.jpg';
  116. $out = "GET $file HTTP/1.0\r\nHost: static.wowhead.com\r\n";
  117. if (isset($proxy_cfg['user']))
  118. $out .= "Proxy-Authorization: Basic ". base64_encode ("{$proxy_cfg['user']}:{$proxy_cfg['pass']}")."\r\n";
  119. $out .="Connection: Close\r\n\r\n";
  120. fwrite($fp, $out);
  121. //remove header
  122. while ($fp && !feof($fp))
  123. {
  124. $headerbuffer = fgets($fp, 4096);
  125. if (urlencode($headerbuffer) == '%0D%0A')
  126. break;
  127. }
  128. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  129. {
  130. if (filesize(''.$item_icons.'/'.$aura.'.jpg') > 349)
  131. {
  132. $sqlm->query('REPLACE INTO dbc_spellicon (id, name) VALUES (\''.$displayid.'\', \''.$aura.'\')');
  133. return ''.$item_icons.'/'.$aura.'.jpg';
  134. }
  135. else
  136. {
  137. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  138. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  139. unlink(''.$item_icons.'/'.$aura.'.jpg');
  140. }
  141. }
  142. $img_file = fopen(''.$item_icons.'/'.$aura.'.jpg', 'wb');
  143. while (!feof($fp))
  144. fwrite($img_file,fgets($fp, 4096));
  145. fclose($fp);
  146. fclose($img_file);
  147. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  148. {
  149. if (filesize(''.$item_icons.'/'.$aura.'.jpg') > 349)
  150. {
  151. $sqlm->query('REPLACE INTO dbc_spellicon (id, name) VALUES (\''.$displayid.'\', \''.$aura.'\')');
  152. return ''.$item_icons.'/'.$aura.'.jpg';
  153. }
  154. else
  155. {
  156. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  157. if (file_exists(''.$item_icons.'/'.$aura.'.jpg'))
  158. unlink(''.$item_icons.'/'.$aura.'.jpg');
  159. }
  160. }
  161. else
  162. return 'img/INV/INV_blank_32.gif';
  163. }
  164. else
  165. return 'img/INV/INV_blank_32.gif';
  166. }
  167. ?>