1. <?php
  2. /*
  3. * Project: EQdkp-Plus
  4. * License: Creative Commons - Attribution-Noncommercial-Share Alike 3.0 Unported
  5. * Link: http://creativecommons.org/licenses/by-nc-sa/3.0/
  6. * -----------------------------------------------------------------------
  7. * Began: 2010
  8. * Date: $Date: 2011-11-01 13:38:39 +0100 (Tue, 01 Nov 2011) $
  9. * -----------------------------------------------------------------------
  10. * @author $Author: hoofy $
  11. * @copyright 2006-2011 EQdkp-Plus Developer Team
  12. * @link http://eqdkp-plus.com
  13. * @package eqdkp-plus
  14. * @version $Rev: 11419 $
  15. *
  16. * $Id: wowhead.class.php 11419 2011-11-01 12:38:39Z hoofy $
  17. */
  18. include_once('itt_parser.aclass.php');
  19. if(!class_exists('wowhead')) {
  20. class wowhead extends itt_parser {
  21. public static $shortcuts = array('pdl', 'puf' => 'urlfetcher');
  22. public $supported_games = array('wow');
  23. public $av_langs = array('en' => 'en_US', 'de' => 'de_DE', 'fr' => 'fr_FR', 'ru' => 'ru_RU', 'es' => 'es_ES');
  24. public $settings = array(
  25. 'itt_icon_loc' => array('name' => 'itt_icon_loc',
  26. 'language' => 'pk_itt_icon_loc',
  27. 'fieldtype' => 'text',
  28. 'size' => false,
  29. 'options' => false,
  30. 'default' => 'https://db.rising-gods.de/static/images/wow/icons/large/'),
  31. 'itt_icon_ext' => array('name' => 'itt_icon_ext',
  32. 'language' => 'pk_itt_icon_ext',
  33. 'fieldtype' => 'text',
  34. 'size' => false,
  35. 'options' => false,
  36. 'default' => '.jpg'),
  37. 'itt_default_icon' => array('name' => 'itt_default_icon',
  38. 'language' => 'pk_itt_default_icon',
  39. 'fieldtype' => 'text',
  40. 'size' => false,
  41. 'options' => false,
  42. 'default' => 'inv_misc_questionmark')
  43. );
  44. private $searched_langs = array();
  45. public function __destruct(){
  46. unset($this->searched_langs);
  47. parent::__destruct();
  48. }
  49. protected function searchItemID($itemname, $lang, $searchagain=0) {
  50. $searchagain++;
  51. $this->pdl->log('infotooltip', 'wowhead->searchItemID called: itemname: '.$itemname.', lang: '.$lang.', searchagain: '.$searchagain);
  52. $item_id = 0;
  53. // Ignore blank names.
  54. $name = trim($itemname);
  55. if (empty($name)) { return null; }
  56. $encoded_name = urlencode($name);
  57. $encoded_name = str_replace('+' , '%20' , $encoded_name);
  58. $url = 'https://db.rising-gods.de/?item='.$encoded_name.'&xml';
  59. $this->pdl->log('infotooltip', 'Search for ItemID at '.$url);
  60. $item_data = $this->puf->fetch($url);
  61. $xml = simplexml_load_string($item_data);
  62. if(is_object($xml)) {
  63. $item_id = (int)$xml->item->attributes()->id;
  64. } else {
  65. $this->pdl->log('infotooltip', 'Invalid XML');
  66. }
  67. //search in other languages
  68. if(!$item_id AND $searchagain < count($this->av_langs)) {
  69. $this->pdl->log('infotooltip', 'No Items found.');
  70. if(count($this->config['lang_prio']) >= $searchagain) {
  71. $this->pdl->log('infotooltip', 'Search again in other language.');
  72. $this->searched_langs[] = $lang;
  73. foreach($this->config['lang_prio'] as $slang) {
  74. if(!in_array($slang, $this->searched_langs)) {
  75. return $this->searchItemID($itemname, $slang, $searchagain);
  76. }
  77. }
  78. }
  79. }
  80. $debug_out = ($item_id > 0) ? 'Item-ID found: '.$item_id : 'No Item-ID found';
  81. $this->pdl->log('infotooltip', $debug_out);
  82. return array($item_id, 'items');
  83. }
  84. protected function getItemData($item_id, $lang, $itemname='', $type='items'){
  85. settype($item_id, 'int');
  86. if(!$item_id) {
  87. $item['baditem'] = true;
  88. return $item;
  89. }
  90. $item = array('id' => $item_id);
  91. $url = ($lang == 'en') ? 'www' : $lang;
  92. $item['link'] = 'https://db.rising-gods.de/?item='.$item['id'].'&xml';
  93. $this->pdl->log('infotooltip', 'fetch item-data from: '.$item['link']);
  94. $itemxml = $this->puf->fetch($item['link'], array('Cookie: cookieLangId="'.$lang.'";'));
  95. if($itemxml AND $itemxml != 'ERROR') $itemxml = simplexml_load_string($itemxml);
  96. $item['name'] = ((!is_numeric($itemname) AND strlen($itemname) > 0) OR !is_object($itemxml)) ? $itemname : trim($itemxml->item->name);
  97. $item['lang'] = $lang;
  98. //filter baditems
  99. if(!is_object($itemxml) OR !isset($itemxml->item->htmlTooltip) OR strlen($itemxml->item->htmlTooltip) < 5) {
  100. $this->pdl->log('infotooltip', 'no xml-object returned');
  101. $item['baditem'] = true;
  102. return $item;
  103. }
  104. //build itemhtml
  105. $html = str_replace('"', "'", $itemxml->item->htmlTooltip);
  106. $template_html = trim(file_get_contents($this->root_path.'infotooltip/includes/parser/templates/wow_popup.tpl'));
  107. $item['html'] = str_replace('{ITEM_HTML}', stripslashes($html), $template_html);
  108. $item['lang'] = $lang;
  109. $item['icon'] = (string) strtolower($itemxml->item->icon);
  110. $item['color'] = 'q'.$this->convert_color((string) $itemxml->item->quality);
  111. return $item;
  112. }
  113. /*
  114. * Translate Old-Colors to new css-classes
  115. */
  116. private function convert_color($color) {
  117. if(is_numeric($color)) return $color;
  118. $color_array = array(
  119. 'Verbreitet' => 1,
  120. 'Common' => 1,
  121. 'Común' => 1,
  122. 'Classique' => 1,
  123. 'Обычный' => 1,
  124. 'Selten' => 2,
  125. 'Uncommon' => 2,
  126. 'Bonne' => 2,
  127. 'Poco Común' => 2,
  128. 'Необычный' => 2,
  129. 'Rar' => 3,
  130. 'Rare' => 3,
  131. 'Raro' => 3,
  132. 'Редкий' => 3,
  133. 'Episch' => 4,
  134. 'Epic' => 4,
  135. 'Épica' => 4,
  136. 'Épique' => 4,
  137. 'Эпический' => 4,
  138. 'Legendär' => 5,
  139. 'Legendary' => 5,
  140. 'Légendaire' => 5,
  141. 'Legendaria' => 5,
  142. 'Легендарный' => 5
  143. );
  144. return $color_array[$color];
  145. }
  146. }
  147. }
  148. if(version_compare(PHP_VERSION, '5.3.0', '<')) registry::add_const('short_wowhead', wowhead::$shortcuts);
  149. ?>