PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/archieve_lib.php

https://github.com/punzzer/Minimanager-for-TrinityCore
PHP | 292 lines | 183 code | 38 blank | 71 comment | 35 complexity | 859129b4bbe7f3c9cf0c74e4d1df5764 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright (C) 2010-2011 TrinityScripts <http://www.trinityscripts.xe.cx/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. /*
  20. //#############################################################################
  21. //get achievement name by its id
  22. function achieve_get_name($id, &$sqlm)
  23. {
  24. $achievement_name = $sqlm->fetch_assoc($sqlm->query('SELECT name01 FROM dbc_achievement WHERE id= '.$id.' LIMIT 1'));
  25. return $achievement_name['name01'];
  26. }
  27. //#############################################################################
  28. //get achievement reward name by its id
  29. function achieve_get_reward($id, &$sqlm)
  30. {
  31. $achievement_reward = $sqlm->fetch_assoc($sqlm->query('SELECT rewarddesc01 FROM dbc_achievement WHERE id ='.$id.' LIMIT 1'));
  32. return $achievement_reward['rewarddesc01'];
  33. }
  34. //#############################################################################
  35. //get achievement points name by its id
  36. function achieve_get_points($id, &$sqlm)
  37. {
  38. $achievement_points = $sqlm->fetch_assoc($sqlm->query('SELECT rewpoints FROM dbc_achievement WHERE id = '.$id.' LIMIT 1'));
  39. return $achievement_points['rewpoints'];
  40. }
  41. //#############################################################################
  42. //get achievement category name by its id
  43. function achieve_get_category($id, &$sqlm)
  44. {
  45. $category_id= $sqlm->fetch_assoc($sqlm->query('SELECT categoryid FROM dbc_achievement WHERE id = '.$id.' LIMIT 1'));
  46. $category_name = $sqlm->fetch_assoc($sqlm->query('SELECT name01 FROM dbc_achievement_category WHERE id = '.$category_id['categoryid'].' LIMIT 1'));
  47. return $category_name['name01'];
  48. }
  49. */
  50. //#############################################################################
  51. //get achievements by category id
  52. function achieve_get_id_category($id, &$sqlm)
  53. {
  54. $achieve_cat = array();
  55. $result = ($sqlm->query('SELECT id, name01, description01, rewarddesc01, rewpoints FROM dbc_achievement WHERE categoryid = \''.$id.'\' ORDER BY `order` DESC'));
  56. while ($achieve_cat[] = $sqlm->fetch_assoc($result));
  57. return $achieve_cat;
  58. }
  59. //#############################################################################
  60. //get achievement main category
  61. function achieve_get_main_category(&$sqlm)
  62. {
  63. $main_cat = array();
  64. $result = $sqlm->query('SELECT id, name01 FROM dbc_achievement_category WHERE parentid = -1 and id != 1 ORDER BY `order` ASC');
  65. while ($main_cat[] = $sqlm->fetch_assoc($result));
  66. return $main_cat;
  67. }
  68. //#############################################################################
  69. //get achievement sub category
  70. function achieve_get_sub_category(&$sqlm)
  71. {
  72. $sub_cat = array();
  73. $result = $sqlm->query('SELECT id, parentid, name01 FROM dbc_achievement_category WHERE parentid != -1 ORDER BY `order` ASC');
  74. $temp = $sqlm->fetch_assoc($result);
  75. while ($sub_cat[$temp['parentid']][$temp['id']] = $temp['name01'])
  76. $temp = $sqlm->fetch_assoc($result);
  77. return $sub_cat;
  78. }
  79. //#############################################################################
  80. //get achievement details by its id
  81. function achieve_get_details($id, &$sqlm)
  82. {
  83. $result = ($sqlm->query('SELECT id, name01, description01, rewarddesc01, rewpoints FROM dbc_achievement WHERE id = \''.$id.'\' LIMIT 1'));
  84. $details = $sqlm->fetch_assoc($result);
  85. return $details;
  86. }
  87. //#############################################################################
  88. //get achievement icon - if icon not exists in item_icons folder D/L it from web.
  89. function achieve_get_icon($achieveid, &$sqlm)
  90. {
  91. global $proxy_cfg, $get_icons_from_web, $item_icons;
  92. $result = $sqlm->query('SELECT field_42 FROM dbc_achievement WHERE id = \''.$achieveid.'\' LIMIT 1');
  93. if ($result)
  94. $displayid = $sqlm->result($result, 0);
  95. else
  96. $displayid = 0;
  97. if ($displayid)
  98. {
  99. $result = $sqlm->query('SELECT field_1 FROM dbc_spellicon WHERE id = '.$displayid.' LIMIT 1');
  100. if($result)
  101. {
  102. $achieve_uppercase = $sqlm->result($result, 0);
  103. $achieve = strtolower($achieve_uppercase);
  104. if ($achieve)
  105. {
  106. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  107. {
  108. if (filesize(''.$item_icons.'/'.$achieve.'.jpg') > 349)
  109. {
  110. return ''.$item_icons.'/'.$achieve.'.jpg';
  111. }
  112. else
  113. {
  114. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  115. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  116. unlink(''.$item_icons.'/'.$achieve.'.jpg');
  117. $achieve = '';
  118. }
  119. }
  120. else
  121. $achieve = '';
  122. }
  123. else
  124. $achieve = '';
  125. }
  126. else
  127. $achieve = '';
  128. }
  129. else
  130. $achieve = '';
  131. if($get_icons_from_web)
  132. {
  133. $xmlfilepath='http://www.wowhead.com/achievement=';
  134. $proxy = $proxy_cfg['addr'];
  135. $port = $proxy_cfg['port'];
  136. if (empty($proxy_cfg['addr']))
  137. {
  138. $proxy = 'www.wowhead.com';
  139. $xmlfilepath = 'achievement=';
  140. $port = 80;
  141. }
  142. if ($achieve == '')
  143. {
  144. //get the icon name
  145. $fp = @fsockopen($proxy, $port, $errno, $errstr, 0.5);
  146. if ($fp);
  147. else
  148. return 'img/INV/INV_blank_32.gif';
  149. $out = "GET /$xmlfilepath$achieveid HTTP/1.0\r\nHost: www.wowhead.com\r\n";
  150. if (isset($proxy_cfg['user']))
  151. $out .= "Proxy-Authorization: Basic ". base64_encode ("{$proxy_cfg['user']}:{$proxy_cfg['pass']}")."\r\n";
  152. $out .="Connection: Close\r\n\r\n";
  153. $temp = '';
  154. fwrite($fp, $out);
  155. while ($fp && !feof($fp))
  156. $temp .= fgets($fp, 4096);
  157. fclose($fp);
  158. $wowhead_string = $temp;
  159. $temp_string1 = strstr($wowhead_string, 'Icon.create(');
  160. $temp_string2 = substr($temp_string1, 12, 50);
  161. $temp_string3 = strtok($temp_string2, ',');
  162. $temp_string4 = substr($temp_string3, 1, strlen($temp_string3) - 2);
  163. $achieve_icon_name = $temp_string4;
  164. $achieve_uppercase = $achieve_icon_name;
  165. $achieve = strtolower($achieve_uppercase);
  166. }
  167. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  168. {
  169. if (filesize(''.$item_icons.'/'.$achieve.'.jpg') > 349)
  170. {
  171. $sqlm->query('REPLACE INTO dbc_spellicon (id, field_1) VALUES (\''.$displayid.'\', \''.$achieve.'\')');
  172. return ''.$item_icons.'/'.$achieve.'.jpg';
  173. }
  174. else
  175. {
  176. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  177. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  178. unlink(''.$item_icons.'/'.$achieve.'.jpg');
  179. }
  180. }
  181. //get the icon itself
  182. if (empty($proxy_cfg['addr']))
  183. {
  184. $proxy = 'static.wowhead.com';
  185. $port = 80;
  186. }
  187. $fp = @fsockopen($proxy, $port, $errno, $errstr, 0.5);
  188. if ($fp);
  189. else
  190. return 'img/INV/INV_blank_32.gif';
  191. $iconfilename = strtolower($achieve);
  192. $file = 'http://static.wowhead.com/images/icons/medium/'.$iconfilename.'.jpg';
  193. $out = "GET $file HTTP/1.0\r\nHost: static.wowhead.com\r\n";
  194. if (isset($proxy_cfg['user']))
  195. $out .= "Proxy-Authorization: Basic ". base64_encode ("{$proxy_cfg['user']}:{$proxy_cfg['pass']}")."\r\n";
  196. $out .="Connection: Close\r\n\r\n";
  197. fwrite($fp, $out);
  198. //remove header
  199. while ($fp && !feof($fp))
  200. {
  201. $headerbuffer = fgets($fp, 4096);
  202. if (urlencode($headerbuffer) == '%0D%0A')
  203. break;
  204. }
  205. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  206. {
  207. if (filesize(''.$item_icons.'/'.$achieve.'.jpg') > 349)
  208. {
  209. $sqlm->query('REPLACE INTO dbc_spellicon (id, field_1) VALUES (\''.$displayid.'\', \''.$achieve.'\')');
  210. return ''.$item_icons.'/'.$achieve.'.jpg';
  211. }
  212. else
  213. {
  214. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  215. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  216. unlink(''.$item_icons.'/'.$achieve.'.jpg');
  217. }
  218. }
  219. $img_file = fopen(''.$item_icons.'/'.$achieve.'.jpg', 'wb');
  220. while (!feof($fp))
  221. fwrite($img_file,fgets($fp, 4096));
  222. fclose($fp);
  223. fclose($img_file);
  224. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  225. {
  226. if (filesize(''.$item_icons.'/'.$achieve.'.jpg') > 349)
  227. {
  228. $sqlm->query('REPLACE INTO dbc_spellicon (id, field_1) VALUES (\''.$displayid.'\', \''.$achieve.'\')');
  229. return ''.$item_icons.'/'.$achieve.'.jpg';
  230. }
  231. else
  232. {
  233. $sqlm->query('DELETE FROM dbc_spellicon WHERE id = '.$displayid.'');
  234. if (file_exists(''.$item_icons.'/'.$achieve.'.jpg'))
  235. unlink(''.$item_icons.'/'.$achieve.'.jpg');
  236. }
  237. }
  238. else
  239. return 'img/INV/INV_blank_32.gif';
  240. }
  241. else
  242. return 'img/INV/INV_blank_32.gif';
  243. }
  244. ?>