PageRenderTime 83ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/update.lib.php

http://wowroster.googlecode.com/
PHP | 2299 lines | 1855 code | 211 blank | 233 comment | 208 complexity | 97767d60d9a600c4104ae5e4becfa728 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * WoWRoster.net WoWRoster
  4. *
  5. * LUA updating library
  6. *
  7. *
  8. * @copyright 2002-2011 WoWRoster.net
  9. * @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
  10. * @version SVN: $Id: update.lib.php 2351 2011-09-13 19:45:48Z ulminia@gmail.com $
  11. * @link http://www.wowroster.net
  12. * @since File available since Release 1.8.0
  13. * @package WoWRoster
  14. * @subpackage LuaUpdate
  15. */
  16. if ( !defined('IN_ROSTER') )
  17. {
  18. exit('Detected invalid access to this file!');
  19. }
  20. /**
  21. * Lua Update handler
  22. *
  23. * @package WoWRoster
  24. * @subpackage LuaUpdate
  25. */
  26. class update
  27. {
  28. var $textmode = false;
  29. var $uploadData;
  30. var $addons = array();
  31. var $files = array();
  32. var $locale;
  33. var $blinds = array();
  34. var $processTime; // time() starting timestamp for enforceRules
  35. var $messages = array();
  36. var $errors = array();
  37. var $assignstr = '';
  38. var $assigngem = ''; // 2nd tracking property since we build a gem list while building an items list
  39. var $membersadded = 0;
  40. var $membersupdated = 0;
  41. var $membersremoved = 0;
  42. var $current_region = '';
  43. var $current_realm = '';
  44. var $current_guild = '';
  45. var $current_member = '';
  46. var $talent_build_urls = array();
  47. /**
  48. * Collect info on what files are used
  49. */
  50. function fetchAddonData()
  51. {
  52. global $roster;
  53. // Add roster-used tables
  54. // $this->files[] = 'characterprofiler';
  55. $this->files[] = 'wowroster';
  56. if( !$roster->config['use_update_triggers'] )
  57. {
  58. return;
  59. }
  60. if( !empty($roster->addon_data) )
  61. {
  62. foreach( $roster->addon_data as $row )
  63. {
  64. $hookfile = ROSTER_ADDONS . $row['basename'] . DIR_SEP . 'inc' . DIR_SEP . 'update_hook.php';
  65. if( file_exists($hookfile) )
  66. {
  67. // Check if this addon is in the process of an upgrade and deny access if it hasn't yet been upgraded
  68. $installfile = ROSTER_ADDONS . $row['basename'] . DIR_SEP . 'inc' . DIR_SEP . 'install.def.php';
  69. $install_class = $row['basename'] . 'Install';
  70. if( file_exists($installfile) )
  71. {
  72. include_once($installfile);
  73. if( class_exists($install_class) )
  74. {
  75. $addonstuff = new $install_class;
  76. // -1 = overwrote newer version
  77. // 0 = same version
  78. // 1 = upgrade available
  79. if( version_compare($addonstuff->version,$row['version']) )
  80. {
  81. $this->setError(sprintf($roster->locale->act['addon_upgrade_notice'],$row['basename']),$roster->locale->act['addon_error']);
  82. continue;
  83. }
  84. unset($addonstuff);
  85. }
  86. }
  87. $addon = getaddon($row['basename']);
  88. include_once($hookfile);
  89. $updateclass = $row['basename'] . 'Update';
  90. // Save current locale array
  91. // Since we add all locales for localization, we save the current locale array
  92. // This is in case one addon has the same locale strings as another, and keeps them from overwritting one another
  93. $localetemp = $roster->locale->wordings;
  94. foreach( $roster->multilanguages as $lang )
  95. {
  96. $roster->locale->add_locale_file(ROSTER_ADDONS . $addon['basename'] . DIR_SEP . 'locale' . DIR_SEP . $lang . '.php',$lang);
  97. }
  98. $addon['fullname'] = ( isset($roster->locale->act[$addon['fullname']]) ? $roster->locale->act[$addon['fullname']] : $addon['fullname'] );
  99. if( class_exists($updateclass) )
  100. {
  101. $this->addons[$row['basename']] = new $updateclass($addon);
  102. $this->files = array_merge($this->files,$this->addons[$row['basename']]->files);
  103. }
  104. else
  105. {
  106. $this->setError('Failed to load update trigger for ' . $row['basename'] . ': Update class did not exist',$roster->locale->act['addon_error']);
  107. }
  108. // Restore our locale array
  109. $roster->locale->wordings = $localetemp;
  110. unset($localetemp);
  111. }
  112. }
  113. }
  114. // Remove duplicates
  115. $this->files = array_unique($this->files);
  116. // Make all the file names requested lower case
  117. $this->files = array_flip($this->files);
  118. $this->files = array_change_key_case($this->files);
  119. $this->files = array_flip($this->files);
  120. }
  121. /**
  122. *
  123. * file error upload handler
  124. * returns true/false | sets error message with file name
  125. */
  126. function upload_error_check($file)
  127. {
  128. global $roster;
  129. switch($file['error'])
  130. {
  131. case UPLOAD_ERR_OK: // Value: 0; There is no error, the file uploaded with success.
  132. return true;
  133. break;
  134. case UPLOAD_ERR_INI_SIZE: // Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
  135. $this->setError('The uploaded file exceeds the upload_max_filesize directive in php.ini.','File Error ['.$file['name'].']');
  136. case UPLOAD_ERR_FORM_SIZE: // Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
  137. $this->setError('The uploaded file exceeds the server maximum filesize allowed.','File Error ['.$file['name'].']');
  138. return false;
  139. break;
  140. case UPLOAD_ERR_PARTIAL: // Value: 3; The uploaded file was only partially uploaded.
  141. $this->setError('The uploaded file was only partially uploaded.','File Error ['.$file['name'].']');
  142. return false;
  143. break;
  144. case UPLOAD_ERR_NO_FILE: // Value: 4; No file was uploaded.
  145. $this->setError('No file was uploaded.','File Error ['.$file['name'].']');
  146. return false;
  147. break;
  148. case UPLOAD_ERR_NO_TMP_DIR: // Value: 6; Missing a temporary folder.
  149. $output .= '<li>Missing a temporary folder. Please contact the admin.</li>';
  150. return false;
  151. break;
  152. case UPLOAD_ERR_CANT_WRITE: // Value: 7; Failed to write file to disk.
  153. $output .= '<li>Failed to write file to disk. Please contact the admin.</li>';
  154. return false;
  155. break;
  156. }
  157. }
  158. /**
  159. * Parses the files and put it in $uploadData
  160. *
  161. * @return string $output | Output messages
  162. */
  163. function parseFiles( )
  164. {
  165. global $roster;
  166. if( !is_array($_FILES) )
  167. {
  168. return '<span class="red">Upload failed: No files present</span>' . "<br />\n";
  169. }
  170. require_once(ROSTER_LIB . 'luaparser.php');
  171. $output = $roster->locale->act['parsing_files'] . "<br />\n<ul>";
  172. foreach( $_FILES as $file )
  173. {
  174. if( !empty($file['name']) && $this->upload_error_check($file))
  175. {
  176. $filename = explode('.',$file['name']);
  177. $filebase = strtolower($filename[0]);
  178. if( in_array($filebase,$this->files))
  179. {
  180. // Get start of parse time
  181. $parse_starttime = format_microtime();
  182. $luahandler = new lua();
  183. $data = $luahandler->luatophp( $file['tmp_name'], isset($this->blinds[$filebase]) ? $this->blinds[$filebase] : array() );
  184. // Calculate parse time
  185. $parse_totaltime = round((format_microtime() - $parse_starttime), 2);
  186. if( $data )
  187. {
  188. $output .= '<li>' . sprintf($roster->locale->act['parsed_time'],$filename[0],$parse_totaltime) . "</li>\n";
  189. $this->uploadData[$filebase] = $data;
  190. }
  191. else
  192. {
  193. $output .= '<li>' . sprintf($roster->locale->act['error_parsed_time'],$filename[0],$parse_totaltime) . "</li>\n";
  194. $output .= ($luahandler->error() != '' ? '<li>' . $luahandler->error() . "</li>\n" : '');
  195. }
  196. unset($luahandler);
  197. }
  198. else
  199. {
  200. $output .= '<li>' . sprintf($roster->locale->act['upload_not_accept'],$file['name']) . "</li>\n";
  201. }
  202. }
  203. else
  204. {
  205. $output .= '<li>' . sprintf($roster->locale->act['error_parsed_time'],$file['name'],'0') . "</li>\n";
  206. }
  207. }
  208. $output .= "</ul><br />\n";
  209. return $output;
  210. }
  211. /**
  212. * Process the files
  213. *
  214. * @return string $output | Output messages
  215. */
  216. function processFiles()
  217. {
  218. global $roster;
  219. $this->processTime = time();
  220. if( !is_array($this->uploadData) )
  221. {
  222. return '';
  223. }
  224. $output = $roster->locale->act['processing_files'] . "<br />\n";
  225. $gotfiles = array_keys($this->uploadData);
  226. // if( in_array('characterprofiler',$gotfiles) || in_array('wowroster',$gotfiles) )
  227. if( in_array('wowroster',$gotfiles) )
  228. {
  229. if( $roster->auth->getAuthorized($roster->config['gp_user_level']) )
  230. {
  231. $output .= $this->processGuildRoster();
  232. $output .= "<br />\n";
  233. if( $roster->config['enforce_rules'] == '3' )
  234. {
  235. $this->enforceRules($this->processTime);
  236. }
  237. }
  238. if( $roster->auth->getAuthorized($roster->config['cp_user_level']) )
  239. {
  240. $output .= $this->processMyProfile();
  241. if( $roster->config['enforce_rules'] == '2' )
  242. {
  243. $this->enforceRules($this->processTime);
  244. }
  245. }
  246. }
  247. if( $roster->auth->getAuthorized($roster->config['lua_user_level']) )
  248. {
  249. if( is_array($this->addons) && count($this->addons) > 0 )
  250. {
  251. foreach( array_keys($this->addons) as $addon )
  252. {
  253. if( count(array_intersect($gotfiles, $this->addons[$addon]->files)) > 0 )
  254. {
  255. if( file_exists($this->addons[$addon]->data['trigger_file']) )
  256. {
  257. $this->addons[$addon]->reset_messages();
  258. if( method_exists($this->addons[$addon], 'update') )
  259. {
  260. $result = $this->addons[$addon]->update();
  261. if( $result )
  262. {
  263. $output .= $this->addons[$addon]->messages;
  264. }
  265. else
  266. {
  267. $output .= sprintf($roster->locale->act['error_addon'],$this->addons[$addon]->data['fullname'],'update') . "<br />\n"
  268. . $roster->locale->act['addon_messages'] . "<br />\n" . $this->addons[$addon]->messages;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. }
  275. if( $roster->config['enforce_rules'] == '1' )
  276. {
  277. $this->enforceRules($this->processTime);
  278. }
  279. }
  280. return $output;
  281. }
  282. /**
  283. * Run trigger
  284. */
  285. function addon_hook( $mode , $data , $memberid = '0' )
  286. {
  287. global $roster;
  288. $output = '';
  289. foreach( array_keys($this->addons) as $addon )
  290. {
  291. if( file_exists($this->addons[$addon]->data['trigger_file']) )
  292. {
  293. $this->addons[$addon]->reset_messages();
  294. if( method_exists($this->addons[$addon], $mode) )
  295. {
  296. $result = $this->addons[$addon]->{$mode}($data , $memberid);
  297. if( $result )
  298. {
  299. if( $mode == 'guild' )
  300. {
  301. $output .= '<li>' . $this->addons[$addon]->messages . "</li>\n";
  302. }
  303. else
  304. {
  305. $output .= $this->addons[$addon]->messages . "<br />\n";
  306. }
  307. }
  308. else
  309. {
  310. if( $mode == 'guild' )
  311. {
  312. $output .= '<li>' . sprintf($roster->locale->act['error_addon'],$this->addons[$addon]->data['fullname'],$mode) . "<br />\n"
  313. . $roster->locale->act['addon_messages'] . "<br />\n" . $this->addons[$addon]->messages . "</li>\n";
  314. }
  315. else
  316. {
  317. $output .= sprintf($roster->locale->act['error_addon'],$this->addons[$addon]->data['fullname'],$mode) . "<br />\n"
  318. . $roster->locale->act['addon_messages'] . "<br />\n" . $this->addons[$addon]->messages . "<br />\n";
  319. }
  320. }
  321. }
  322. }
  323. }
  324. return $output;
  325. }
  326. /**
  327. * Process character data
  328. */
  329. function processMyProfile()
  330. {
  331. global $roster;
  332. /**
  333. * Rule #1 Deny everything
  334. * Rule #2 If it breaks, Zanix did it
  335. * Rule #3 This works for both new and old CPs lol
  336. * Rule #4 If Zanix yells at you, you deserve it
  337. */
  338. /* if ( isset($this->uploadData['characterprofiler']['myProfile']) )
  339. {
  340. $myProfile = $this->uploadData['characterprofiler']['myProfile'];
  341. }
  342. else
  343. */
  344. if ( isset($this->uploadData['wowroster']['cpProfile']) )
  345. {
  346. $myProfile = $this->uploadData['wowroster']['cpProfile'];
  347. }
  348. else
  349. {
  350. return;
  351. }
  352. $output = '';
  353. $this->resetMessages();
  354. foreach( $myProfile as $realm_name => $realm )
  355. {
  356. $this->current_realm = $realm_name;
  357. if( isset($realm['Character']) && is_array($realm['Character']) )
  358. {
  359. $characters = $realm['Character'];
  360. // Start update triggers
  361. if( $roster->config['use_update_triggers'] )
  362. {
  363. $output .= $this->addon_hook('char_pre', $characters);
  364. }
  365. foreach( $characters as $char_name => $char )
  366. {
  367. $this->current_member = $char_name;
  368. // CP Version Detection, don't allow lower than minVer
  369. if( version_compare($char['CPversion'], $roster->config['minCPver'], '>=') )
  370. {
  371. // Get the region
  372. if( isset($char['timestamp']['init']['datakey']) )
  373. {
  374. list($region) = explode(':',$char['timestamp']['init']['datakey']);
  375. $region = strtoupper($region);
  376. }
  377. else
  378. {
  379. $region = '';
  380. }
  381. // Official realms don't trigger this. I looked up and verified the asian ones as well.
  382. if( strlen($region) > 2 )
  383. {
  384. roster_die('You are not playing on an official realm, and your data is incompatible with WoWRoster<br /><br />'
  385. . 'This message exists because we are getting annoyed by the occasional person who can\'t get WoWRoster to work with a private server, '
  386. . 'when we clearly state that WoWRoster will not work on private servers.<br />'
  387. . 'You are on your own if you want WoWRoster to work with a private server. Good luck fixing it!'
  388. ,'Invalid Region/Realm');
  389. }
  390. $this->current_region = $region;
  391. // Get the CP timestamp
  392. $timestamp = $char['timestamp']['init']['DateUTC'];
  393. $realm_escape = $roster->db->escape($realm_name);
  394. // Is this char already in the members table?
  395. $query = "SELECT `guild_id`, `member_id`"
  396. . " FROM `" . $roster->db->table('members') . "`"
  397. . " WHERE `name` = '" . $char_name . "'"
  398. . " AND `server` = '" . $realm_escape . "'"
  399. . " AND `region` = '" . $region . "';";
  400. if( !$roster->db->query_first($query) )
  401. {
  402. // Allowed char detection
  403. $query = "SELECT `type`, COUNT(`rule_id`)"
  404. . " FROM `" . $roster->db->table('upload') . "`"
  405. . " WHERE (`type` = 2 OR `type` = 3)"
  406. . " AND '" . $char_name . "' LIKE `name`"
  407. . " AND '" . $realm_escape . "' LIKE `server`"
  408. . " AND '" . $region."' LIKE `region`"
  409. . " GROUP BY `type`"
  410. . " ORDER BY `type` DESC;";
  411. /**
  412. * This might need explaining. The query potentially returns 2 rows:
  413. * First the number of matching deny rows, then the number of matching
  414. * accept rows. If there are deny rows, `type`=3 in the first row, and
  415. * we reject the upload. If there are no deny rows, but there are accept
  416. * rows, `type`=2 in the first row, and we accept the upload. If there are
  417. * no relevant rows at all, query_first will return false, and we reject
  418. * the upload.
  419. */
  420. if( $roster->db->query_first($query) !== '2' )
  421. {
  422. $output .= '<span class="red">' . sprintf($roster->locale->act['not_accepted'], $roster->locale->act['character'], $char_name, $region, $realm_name) . "</span><br />\n";
  423. continue;
  424. }
  425. else
  426. {
  427. // Fabricate a guild update
  428. // We can probably use the $char['Guild'] block for this info instead of Guildless I suppose....
  429. $guilddata['Faction'] = $char['FactionEn'];
  430. $guilddata['FactionEn'] = $char['FactionEn'];
  431. $guilddata['Locale'] = $char['Locale'];
  432. $guilddata['Info'] = '';
  433. $guildId = $this->update_guild($realm_name, 'GuildLess-' . substr($char['FactionEn'],0,1), strtotime($timestamp), $guilddata, $region);
  434. unset($guilddata);
  435. // Copy the array so we can set Online to 1 until I can find a better way to set last online time
  436. // We could probably get away with just setting 'Online' in the $char array, but I dont wanna risk tainting the data
  437. $chartemp = $char;
  438. $chartemp['Online'] = '1';
  439. $this->update_guild_member($guildId, $char_name, $realm_name, $region, $chartemp, strtotime($timestamp), array());
  440. unset($chartemp);
  441. array_pop($this->messages);
  442. }
  443. }
  444. else
  445. {
  446. $guildId = $roster->db->query_first($query);
  447. }
  448. $time = $roster->db->query_first("SELECT `dateupdatedutc` FROM `" . $roster->db->table('players') . "`"
  449. . " WHERE '" . $char_name . "' LIKE `name`"
  450. . " AND '" . $realm_escape . "' LIKE `server`"
  451. . " AND '" . $region . "' LIKE `region`;");
  452. // Check if the profile is old
  453. if( $time != '' && ( strtotime($time) - strtotime($timestamp) ) > 0 )
  454. {
  455. $current = date($roster->locale->act['phptimeformat'], strtotime($time));
  456. $update = date($roster->locale->act['phptimeformat'], strtotime($timestamp));
  457. $output .= '<span class="red">' . sprintf($roster->locale->act['not_update_char_time'], $char_name, $update, $current) . "</span><br />\n";
  458. continue;
  459. }
  460. $output .= '<strong>' . sprintf($roster->locale->act['upload_data'], $roster->locale->act['character'], $char_name, $realm_name, $region) . "</strong>\n";
  461. $memberid = $this->update_char($guildId, $region, $realm_name, $char_name, $char);
  462. $output .= "<ul>\n" . $this->getMessages() . "</ul>\n";
  463. $this->resetMessages();
  464. // Start update triggers
  465. if( $memberid !== false && $roster->config['use_update_triggers'] )
  466. {
  467. $output .= $this->addon_hook('char', $char, $memberid);
  468. }
  469. }
  470. else // CP Version not new enough
  471. {
  472. $output .= '<span class="red">' . sprintf($roster->locale->act['not_updating'], 'WoWRoster-Profiler', $char_name, $char['CPversion']) . "</span><br />\n";
  473. $output .= sprintf($roster->locale->act['CPver_err'], $roster->config['minCPver']) . "\n";
  474. }
  475. }
  476. // Start update triggers
  477. if( $roster->config['use_update_triggers'] )
  478. {
  479. $output .= $this->addon_hook('char_post', $characters);
  480. }
  481. }
  482. }
  483. return $output;
  484. }
  485. /**
  486. * Process guild data
  487. */
  488. function processGuildRoster()
  489. {
  490. global $roster;
  491. /*
  492. if ( isset($this->uploadData['characterprofiler']['myProfile']) )
  493. {
  494. $myProfile = $this->uploadData['characterprofiler']['myProfile'];
  495. }
  496. else
  497. */
  498. if ( isset($this->uploadData['wowroster']['cpProfile']) )
  499. {
  500. $myProfile = $this->uploadData['wowroster']['cpProfile'];
  501. }
  502. else
  503. {
  504. return;
  505. }
  506. $output = '';
  507. $this->resetMessages();
  508. if( is_array($myProfile) )
  509. {
  510. foreach( $myProfile as $realm_name => $realm )
  511. {
  512. $this->current_realm = $realm_name;
  513. if( isset($realm['Guild']) && is_array($realm['Guild']) )
  514. {
  515. foreach( $realm['Guild'] as $guild_name => $guild )
  516. {
  517. $this->current_guild = $guild_name;
  518. // GP Version Detection, don't allow lower than minVer
  519. if( version_compare($guild['GPversion'], $roster->config['minGPver'], '>=') )
  520. {
  521. // Get the region
  522. if( isset($guild['timestamp']['init']['datakey']) )
  523. {
  524. list($region) = explode(':',$guild['timestamp']['init']['datakey']);
  525. $region = strtoupper($region);
  526. }
  527. else
  528. {
  529. $region = '';
  530. }
  531. $this->current_region = $region;
  532. $guild_escape = $roster->db->escape($guild_name);
  533. $realm_escape = $roster->db->escape($realm_name);
  534. // Allowed guild detection
  535. $query = "SELECT `type`, COUNT(`rule_id`)"
  536. . " FROM `" . $roster->db->table('upload') . "`"
  537. . " WHERE (`type` = 0 OR `type` = 1)"
  538. . " AND '" . $guild_escape . "' LIKE `name`"
  539. . " AND '" . $realm_escape . "' LIKE `server`"
  540. . " AND '" . $region . "' LIKE `region`"
  541. . " GROUP BY `type`"
  542. . " ORDER BY `type` DESC;";
  543. /**
  544. * This might need explaining. The query potentially returns 2 rows:
  545. * First the number of matching deny rows, then the number of matching
  546. * accept rows. If there are deny rows, `type`=1 in the first row, and
  547. * we reject the upload. If there are no deny rows, but there are accept
  548. * rows, `type`=0 in the first row, and we accept the upload. If there are
  549. * no relevant rows at all, query_first will return false, and we reject
  550. * the upload.
  551. */
  552. if( $roster->db->query_first($query) !== '0' )
  553. {
  554. $output .= '<span class="red">' . sprintf($roster->locale->act['not_accepted'], $roster->locale->act['guild'], $guild_name, $region, $realm_name) . "</span><br />\n";
  555. continue;
  556. }
  557. if( count($guild['Members']) > 0 )
  558. {
  559. // take the current time and get the offset. Upload must occur same day that roster was obtained
  560. $currentTimestamp = strtotime($guild['timestamp']['init']['DateUTC']);
  561. $time = $roster->db->query_first("SELECT `update_time` FROM `" . $roster->db->table('guild')
  562. . "` WHERE '" . $guild_escape . "' LIKE `guild_name`"
  563. . " AND '" . $realm_escape . "' LIKE `server`"
  564. . " AND '" . $region . "' LIKE `region`;");
  565. // Check if the profile is old
  566. if( $time != '' && ( strtotime($time) - $currentTimestamp ) > 0 )
  567. {
  568. $current = date($roster->locale->act['phptimeformat'], strtotime($time));
  569. $update = date($roster->locale->act['phptimeformat'], $currentTimestamp);
  570. $output .= '<span class="red">' . sprintf($roster->locale->act['not_update_guild_time'], $guild_name, $update, $current) . "</span><br />\n";
  571. continue;
  572. }
  573. // Update the guild
  574. $guildId = $this->update_guild($realm_name, $guild_name, $currentTimestamp, $guild, $region);
  575. $guild['guild_id'] = $guildId;
  576. $guildMembers = $guild['Members'];
  577. $guild_output = '';
  578. // Start update triggers
  579. if( $roster->config['use_update_triggers'] )
  580. {
  581. $guild_output .= $this->addon_hook('guild_pre', $guild);
  582. }
  583. // update the list of guild members
  584. $guild_output .= "<ul><li><strong>" . $roster->locale->act['update_members'] . "</strong>\n<ul>\n";
  585. foreach(array_keys($guildMembers) as $char_name)
  586. {
  587. $this->current_member = $char_name;
  588. $char = $guildMembers[$char_name];
  589. $memberid = $this->update_guild_member($guildId, $char_name, $realm_name, $region, $char, $currentTimestamp, $guild);
  590. $guild_output .= $this->getMessages();
  591. $this->resetMessages();
  592. // Start update triggers
  593. if( $memberid !== false && $roster->config['use_update_triggers'] )
  594. {
  595. $guild_output .= $this->addon_hook('guild', $char, $memberid);
  596. }
  597. }
  598. // Remove the members who were not in this list
  599. $this->remove_guild_members($guildId, $currentTimestamp);
  600. $guild_output .= $this->getMessages()."</ul></li>\n";
  601. $this->resetMessages();
  602. $guild_output .= "</ul>\n";
  603. // Start update triggers
  604. if( $roster->config['use_update_triggers'] )
  605. {
  606. $guild_output .= $this->addon_hook('guild_post', $guild);
  607. }
  608. $output .= '<strong>' . sprintf($roster->locale->act['upload_data'],$roster->locale->act['guild'],$guild_name,$realm_name,$region) . "</strong>\n<ul>\n";
  609. $output .= '<li><strong>' . $roster->locale->act['memberlog'] . "</strong>\n<ul>\n"
  610. . '<li>' . $roster->locale->act['updated'] . ': ' . $this->membersupdated . "</li>\n"
  611. . '<li>' . $roster->locale->act['added'] . ': ' . $this->membersadded . "</li>\n"
  612. . '<li>' . $roster->locale->act['removed'] . ': ' . $this->membersremoved . "</li>\n"
  613. . "</ul></li></ul>\n";
  614. $output .= $guild_output;
  615. // Reset these since we might process another guild
  616. $this->membersupdated = $this->membersadded = $this->membersremoved = 0;
  617. }
  618. else
  619. {
  620. $output .= '<span class="red">' . sprintf($roster->locale->act['not_update_guild'], $guild_name, $realm_name, $region) . "</span><br />\n";
  621. $output .= $roster->locale->act['no_members'];
  622. }
  623. }
  624. else
  625. // GP Version not new enough
  626. {
  627. $output .= '<span class="red">' . sprintf($roster->locale->act['not_updating'], 'WoWRoster-GuildProfiler', $guild_name, $guild['GPversion']) . "</span><br />\n";
  628. $output .= sprintf($roster->locale->act['GPver_err'], $roster->config['minGPver']);
  629. }
  630. }
  631. }
  632. else
  633. {
  634. $output .= '<span class="red">' . $roster->locale->act['guild_addonNotFound'] . '</span><br />';
  635. }
  636. }
  637. }
  638. return $output;
  639. }
  640. /**
  641. * Returns the file input fields for all addon files we need.
  642. *
  643. * @return string $filefields | The HTML, without border
  644. */
  645. function makeFileFields($blockname='file_fields')
  646. {
  647. global $roster;
  648. if( !is_array($this->files) || (count($this->files) == 0) ) // Just in case
  649. {
  650. $roster->tpl->assign_block_vars($blockname, array(
  651. 'TOOLTIP' => '',
  652. 'FILE' => 'No files accepted!'
  653. ));
  654. }
  655. $account_dir = '<i>*WOWDIR*</i>\\\\WTF\\\\Account\\\\<i>*ACCOUNT_NAME*</i>\\\\SavedVariables\\\\';
  656. foreach( $this->files as $file )
  657. {
  658. $roster->tpl->assign_block_vars($blockname, array(
  659. 'TOOLTIP' => makeOverlib($account_dir . $file . '.lua', $file . '.lua Location', '', 2, '', ',WRAP'),
  660. 'FILE' => $file
  661. ));
  662. }
  663. }
  664. /**
  665. * Adds a message to the $messages array
  666. *
  667. * @param string $message
  668. */
  669. function setMessage($message)
  670. {
  671. $this->messages[] = $message;
  672. }
  673. /**
  674. * Returns all messages
  675. *
  676. * @return string
  677. */
  678. function getMessages()
  679. {
  680. return implode("\n",$this->messages) . "\n";
  681. }
  682. /**
  683. * Resets the stored messages
  684. *
  685. */
  686. function resetMessages()
  687. {
  688. $this->messages = array();
  689. }
  690. /**
  691. * Adds an error to the $errors array
  692. *
  693. * @param string $message
  694. */
  695. function setError( $message , $error )
  696. {
  697. $this->errors[] = array($message=>$error);
  698. }
  699. /**
  700. * Gets the errors in wowdb
  701. * Return is based on $mode
  702. *
  703. * @param string $mode
  704. * @return mixed
  705. */
  706. function getErrors( $mode='' )
  707. {
  708. if( $mode == 'a' )
  709. {
  710. return $this->errors;
  711. }
  712. $output = '';
  713. $errors = $this->errors;
  714. if( !empty($errors) )
  715. {
  716. $output = '<table width="100%" cellspacing="0">';
  717. $steps = 0;
  718. foreach( $errors as $errorArray )
  719. {
  720. foreach( $errorArray as $message => $error )
  721. {
  722. if( $steps == 1 )
  723. {
  724. $steps = 2;
  725. }
  726. else
  727. {
  728. $steps = 1;
  729. }
  730. $output .= "<tr><td class=\"membersRowRight$steps\">$error<br />\n"
  731. . "$message</td></tr>\n";
  732. }
  733. }
  734. $output .= '</table>';
  735. }
  736. return $output;
  737. }
  738. /**
  739. * DB insert code (former WoWDB)
  740. */
  741. /**
  742. * Resets the SQL insert/update string holder
  743. */
  744. function reset_values()
  745. {
  746. $this->assignstr = '';
  747. }
  748. /**
  749. * Add a value to an INSERT or UPDATE SQL string
  750. *
  751. * @param string $row_name
  752. * @param string $row_data
  753. */
  754. function add_value( $row_name , $row_data )
  755. {
  756. global $roster;
  757. if( $this->assignstr != '' )
  758. {
  759. $this->assignstr .= ',';
  760. }
  761. // str_replace added to get rid of non breaking spaces in cp.lua tooltips
  762. $row_data = str_replace(chr(194) . chr(160), ' ', $row_data);
  763. $row_data = stripslashes($row_data);
  764. $row_data = $roster->db->escape($row_data);
  765. $this->assignstr .= " `$row_name` = '$row_data'";
  766. }
  767. /**
  768. * Verifies existance of variable before attempting add_value
  769. *
  770. * @param array $array
  771. * @param string $key
  772. * @param string $field
  773. * @param string $default
  774. * @return boolean
  775. */
  776. function add_ifvalue( $array , $key , $field=false , $default=false )
  777. {
  778. if( $field === false )
  779. {
  780. $field = $key;
  781. }
  782. if( isset($array[$key]) )
  783. {
  784. $this->add_value($field, $array[$key]);
  785. return true;
  786. }
  787. else
  788. {
  789. if( $default !== false )
  790. {
  791. $this->add_value($field, $default);
  792. }
  793. return false;
  794. }
  795. }
  796. /**
  797. * Add a gem to an INSERT or UPDATE SQL string
  798. * (clone of add_value method--this functions as a 2nd SQL insert placeholder)
  799. *
  800. * @param string $row_name
  801. * @param string $row_data
  802. */
  803. function add_gem( $row_name , $row_data )
  804. {
  805. global $roster;
  806. if( $this->assigngem != '' )
  807. {
  808. $this->assigngem .= ',';
  809. }
  810. $row_data = "'" . $roster->db->escape($row_data) . "'";
  811. $this->assigngem .= " `$row_name` = $row_data";
  812. }
  813. /**
  814. * Add a time value to an INSERT or UPDATE SQL string
  815. *
  816. * @param string $row_name
  817. * @param array $date
  818. */
  819. function add_time( $row_name , $date )
  820. {
  821. // 2000-01-01 23:00:00.000
  822. $row_data = $date['year'] . '-' . $date['mon'] . '-' . $date['mday'] . ' ' . $date['hours'] . ':' . $date['minutes'] . ':' . $date['seconds'];
  823. $this->add_value($row_name,$row_data);
  824. }
  825. /**
  826. * Add a time value to an INSERT or UPDATE SQL string
  827. *
  828. * @param string $row_name
  829. * @param string $date | UNIX TIMESTAMP
  830. */
  831. function add_timestamp( $row_name , $date )
  832. {
  833. $date = date('Y-m-d H:i:s',$date);
  834. $this->add_value($row_name,$date);
  835. }
  836. /**
  837. * Add a rating (base, buff, debuff, total)
  838. *
  839. * @param string $row_name will be appended _d, _b, _c for debuff, buff, total
  840. * @param string $data colon-separated data
  841. */
  842. function add_rating( $row_name , $data )
  843. {
  844. $data = explode(':',$data);
  845. $data[0] = ( isset($data[0]) && $data[0] != '' ? $data[0] : 0 );
  846. $data[1] = ( isset($data[1]) && $data[1] != '' ? $data[1] : 0 );
  847. $data[2] = ( isset($data[2]) && $data[2] != '' ? $data[2] : 0 );
  848. $this->add_value($row_name, round($data[0]));
  849. $this->add_value($row_name . '_c', round($data[0]+$data[1]+$data[2]));
  850. $this->add_value($row_name . '_b', round($data[1]));
  851. $this->add_value($row_name . '_d', round($data[2]));
  852. }
  853. /**
  854. * Turn the WoW internal icon format into the one used by us
  855. * All lower case and spaces converted into _
  856. *
  857. * @param string $icon_name
  858. * @return string
  859. */
  860. function fix_icon( $icon_name )
  861. {
  862. $icon_name = basename($icon_name);
  863. return strtolower(str_replace(' ','_',$icon_name));
  864. }
  865. /**
  866. * Format tooltips for insertion to the db
  867. *
  868. * @param mixed $tipdata
  869. * @return string
  870. */
  871. function tooltip( $tipdata )
  872. {
  873. $tooltip = '';
  874. if( is_array($tipdata) )
  875. {
  876. $tooltip = implode("\n",$tipdata);
  877. }
  878. else
  879. {
  880. $tooltip = str_replace('<br>',"\n",$tipdata);
  881. }
  882. return $tooltip;
  883. }
  884. /**
  885. * Inserts an reagent into the database
  886. *
  887. * @param string $item
  888. * @return bool
  889. */
  890. function insert_reagent( $memberId , $reagents , $locale )
  891. {
  892. global $roster;
  893. //echo'<pre>';
  894. //print_r($reagents);
  895. foreach ($reagents as $ind => $reagent)
  896. {
  897. $this->reset_values();
  898. $this->add_value('member_id', $memberId);
  899. $this->add_value('reagent_id', $reagent['Item']);
  900. $this->add_ifvalue($reagent, 'Name', 'reagent_name');
  901. $this->add_ifvalue($reagent, 'Count', 'reagent_count');
  902. $this->add_ifvalue($reagent, 'Color', 'reagent_color');
  903. // Fix icon
  904. if( !empty($reagent['Icon']) )
  905. {
  906. $reagent['Icon'] = $this->fix_icon($reagent['Icon']);
  907. }
  908. else
  909. {
  910. $reagent['Icon'] = 'inv_misc_questionmark';
  911. }
  912. // Fix tooltip
  913. if( !empty($reagent['Tooltip']) )
  914. {
  915. $reagent['item_tooltip'] = $this->tooltip($reagent['Tooltip']);
  916. }
  917. else
  918. {
  919. $reagent['item_tooltip'] = $reagent['Name'];
  920. }
  921. $this->add_value('reagent_texture', $reagent['Icon']);
  922. $this->add_value('reagent_tooltip', $reagent['Tooltip']);
  923. $this->add_value('locale', $locale);
  924. /* $level = array();
  925. if( isset($reagent_data['reqLevel']) && !is_null($reagent_data['reqLevel']) )
  926. {
  927. $this->add_value('level', $reagent_data['reqLevel']);
  928. }
  929. else if( preg_match($roster->locale->wordings[$locale]['requires_level'],$reagent['item_tooltip'],$level))
  930. {
  931. $this->add_value('level', $level[1]);
  932. }
  933. // gotta see of the reagent is in the db already....
  934. */
  935. $querystra = "SELECT * FROM `" . $roster->db->table('recipes_reagents') . "` WHERE `reagent_id` = " . $reagent['Item'] . ";";
  936. $resulta = $roster->db->query($querystra);
  937. $num = $roster->db->num_rows($resulta);
  938. if ($num < '1')
  939. {
  940. $querystr = "INSERT INTO `" . $roster->db->table('recipes_reagents') . "` SET " . $this->assignstr . ";";
  941. $result = $roster->db->query($querystr);
  942. if( !$result )
  943. {
  944. $this->setError('Item [' . $reagent['Name'] . '] could not be inserted',$roster->db->error());
  945. }
  946. }
  947. }
  948. }
  949. /**
  950. * Inserts an item into the database
  951. *
  952. * @param string $item
  953. * @return bool
  954. */
  955. function insert_item( $item , $locale )
  956. {
  957. global $roster;
  958. // echo '<pre>';
  959. //print_r($item);
  960. $this->reset_values();
  961. $this->add_ifvalue($item, 'member_id');
  962. $this->add_ifvalue($item, 'item_name');
  963. $this->add_ifvalue($item, 'item_parent');
  964. $this->add_ifvalue($item, 'item_slot');
  965. $this->add_ifvalue($item, 'item_color');
  966. $this->add_ifvalue($item, 'item_id');
  967. $this->add_ifvalue($item, 'item_texture');
  968. $this->add_ifvalue($item, 'item_quantity');
  969. $this->add_ifvalue($item, 'item_tooltip');
  970. $this->add_ifvalue($item, 'item_level');
  971. $this->add_ifvalue($item, 'item_type');
  972. $this->add_ifvalue($item, 'item_subtype');
  973. $this->add_ifvalue($item, 'item_rarity');
  974. $this->add_value('locale', $locale);
  975. /*
  976. $level = array();
  977. if( isset($item_data['reqLevel']) && !is_null($item_data['reqLevel']) )
  978. {
  979. $this->add_value('level', $item_data['reqLevel']);
  980. }
  981. else if( preg_match($roster->locale->wordings[$locale]['requires_level'],$item['item_tooltip'],$level))
  982. {
  983. $this->add_value('level', $level[1]);
  984. }
  985. */
  986. $querystr = "INSERT INTO `" . $roster->db->table('items') . "` SET " . $this->assignstr . ";";
  987. $result = $roster->db->query($querystr);
  988. if( !$result )
  989. {
  990. $this->setError('Item [' . $item['item_name'] . '] could not be inserted',$roster->db->error());
  991. }
  992. }
  993. /**
  994. * Inserts a gem into the database
  995. *
  996. * @param array $gem
  997. * @return bool | true on success, false if error
  998. */
  999. function insert_gem( $gem )
  1000. {
  1001. global $roster;
  1002. $this->assigngem='';
  1003. $this->add_gem('gem_id', $gem['gem_id']);
  1004. $this->add_gem('gem_name', $gem['gem_name']);
  1005. $this->add_gem('gem_color', $gem['gem_color']);
  1006. $this->add_gem('gem_tooltip', $gem['gem_tooltip']);
  1007. $this->add_gem('gem_bonus', $gem['gem_bonus']);
  1008. $this->add_gem('gem_socketid', $gem['gem_socketid']);
  1009. $this->add_gem('gem_texture', $gem['gem_texture']);
  1010. $this->add_gem('locale', $this->locale);
  1011. $querystr = "REPLACE INTO `" . $roster->db->table('gems') . "` SET ".$this->assigngem . ";";
  1012. $result = $roster->db->query($querystr);
  1013. if ( !$result )
  1014. {
  1015. return false;
  1016. }
  1017. else
  1018. {
  1019. return true;
  1020. }
  1021. }
  1022. /**
  1023. * Inserts mail into the Database
  1024. *
  1025. * @param array $mail
  1026. */
  1027. function insert_mail( $mail )
  1028. {
  1029. global $roster;
  1030. $this->reset_values();
  1031. $this->add_ifvalue($mail, 'member_id');
  1032. $this->add_ifvalue($mail, 'mail_slot', 'mailbox_slot');
  1033. $this->add_ifvalue($mail, 'mail_icon', 'mailbox_icon');
  1034. $this->add_ifvalue($mail, 'mail_coin', 'mailbox_coin');
  1035. $this->add_ifvalue($mail, 'mail_coin_icon', 'mailbox_coin_icon');
  1036. $this->add_ifvalue($mail, 'mail_days', 'mailbox_days');
  1037. $this->add_ifvalue($mail, 'mail_sender', 'mailbox_sender');
  1038. $this->add_ifvalue($mail, 'mail_subject', 'mailbox_subject');
  1039. $querystr = "INSERT INTO `" . $roster->db->table('mailbox') . "` SET " . $this->assignstr . ";";
  1040. $result = $roster->db->query($querystr);
  1041. if( !$result )
  1042. {
  1043. $this->setError('Mail [' . $mail['mail_subject'] . '] could not be inserted',$roster->db->error());
  1044. }
  1045. }
  1046. /**
  1047. * Inserts a recipe into the Database
  1048. *
  1049. * @param array $recipe
  1050. * @param string $locale
  1051. */
  1052. function insert_recipe( $recipe , $locale )
  1053. {
  1054. global $roster;
  1055. $this->reset_values();
  1056. $this->add_ifvalue($recipe, 'member_id');
  1057. $this->add_ifvalue($recipe, 'recipe_id');
  1058. $this->add_ifvalue($recipe, 'item_id');
  1059. $this->add_ifvalue($recipe, 'recipe_name');
  1060. $this->add_ifvalue($recipe, 'recipe_type');
  1061. $this->add_ifvalue($recipe, 'skill_name');
  1062. $this->add_ifvalue($recipe, 'difficulty');
  1063. $this->add_ifvalue($recipe, 'item_color');
  1064. $this->add_ifvalue($recipe, 'reagent_list','reagents');
  1065. $this->add_ifvalue($recipe, 'recipe_texture');
  1066. $this->add_ifvalue($recipe, 'recipe_tooltip');
  1067. $level = array();
  1068. if( preg_match($roster->locale->wordings[$locale]['requires_level'],$recipe['recipe_tooltip'],$level))
  1069. {
  1070. $this->add_value('level',$level[1]);
  1071. }
  1072. $querystra = "SELECT * FROM `" . $roster->db->table('recipes') . "` WHERE `member_id` = '" . $recipe['member_id'] . "' and `recipe_name` = '".addslashes($recipe['recipe_name'])."' and `skill_name` = '".addslashes($recipe['skill_name'])."';";
  1073. $resulta = $roster->db->query($querystra);
  1074. $num = $roster->db->num_rows($resulta);
  1075. if ($num <=0)
  1076. {
  1077. $querystr = "INSERT INTO `" . $roster->db->table('recipes') . "` SET " . $this->assignstr . ";";
  1078. $result = $roster->db->query($querystr);
  1079. if( !$result )
  1080. {
  1081. $this->setError('Recipe [' . $recipe['recipe_name'] . '] could not be inserted',$roster->db->error());
  1082. }
  1083. }
  1084. }
  1085. /**
  1086. * Formats quest data and inserts into the DB
  1087. *
  1088. * @param array $quest
  1089. * @param int $member_id
  1090. * @param string $zone
  1091. * @param array $data
  1092. */
  1093. function insert_quest( $quest , $member_id , $zone , $slot , $data )
  1094. {
  1095. global $roster;
  1096. // Fix quest name since many 'quest' addons cause the level number to be added to title
  1097. while( substr($quest['Title'],0,1) == '[' )
  1098. {
  1099. $quest['Title'] = ltrim(substr($quest['Title'],strpos($quest['Title'],']')+1));
  1100. }
  1101. // Insert this quest into the quest data table, db normalization is great huh?
  1102. $this->reset_values();
  1103. $this->add_ifvalue($quest, 'QuestId', 'quest_id');
  1104. $this->add_value('quest_name', $quest['Title']);
  1105. $this->add_ifvalue($quest, 'Level', 'quest_level');
  1106. $this->add_ifvalue($quest, 'Tag', 'quest_tag');
  1107. $this->add_ifvalue($quest, 'Group', 'group');
  1108. $this->add_ifvalue($quest, 'Daily', 'daily');
  1109. $this->add_ifvalue($quest, 'RewardMoney', 'reward_money');
  1110. if( isset($quest['Description']) )
  1111. {
  1112. $description = str_replace('\n',"\n",$quest['Description']);
  1113. $description = str_replace($data['Class'],'<class>',$description);
  1114. $description = str_replace($data['Name'],'<name>',$description);
  1115. $this->add_value('description', $description);
  1116. unset($description);
  1117. }
  1118. if( isset($quest['Objective']) )
  1119. {
  1120. $objective = str_replace('\n',"\n",$quest['Objective']);
  1121. $objective = str_replace($data['Class'],'<class>',$objective);
  1122. $objective = str_replace($data['Name'],'<name>',$objective);
  1123. $this->add_value('objective', $objective);
  1124. unset($objective);
  1125. }
  1126. $this->add_value('zone', $zone);
  1127. $this->add_value('locale', $data['Locale']);
  1128. $querystr = "REPLACE INTO `" . $roster->db->table('quest_data') . "` SET " . $this->assignstr . ";";
  1129. $result = $roster->db->query($querystr);
  1130. if( !$result )
  1131. {
  1132. $this->setError('Quest Data [' . $quest['QuestId'] . ' : ' . $quest['Title'] . '] could not be inserted',$roster->db->error());
  1133. }
  1134. /*
  1135. // Now process tasks
  1136. NOT PROCESSING, BUT CODE AND TABLE LAYOUT IS HERE FOR LATER
  1137. The reason is that the task number is in the name
  1138. and this is not good for a normalized table
  1139. # --------------------------------------------------------
  1140. ### Quest Tasks
  1141. DROP TABLE IF EXISTS `renprefix_quest_task_data`;
  1142. CREATE TABLE `renprefix_quest_task_data` (
  1143. `quest_id` int(11) NOT NULL default '0',
  1144. `task_id` int(11) NOT NULL default '0',
  1145. `note` varchar(128) NOT NULL default '',
  1146. `type` varchar(32) NOT NULL default '',
  1147. `locale` varchar(4) NOT NULL default '',
  1148. PRIMARY KEY (`quest_id`,`task_id`,`locale`)
  1149. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  1150. if( isset($quest['Tasks']) && !empty($quest['Tasks']) && is_array($quest['Tasks']) )
  1151. {
  1152. $tasks = $quest['Tasks'];
  1153. foreach( array_keys($tasks) as $task )
  1154. {
  1155. $taskInfo = $tasks[$task];
  1156. $this->reset_values();
  1157. $this->add_ifvalue($quest, 'QuestId', 'quest_id');
  1158. $this->add_value('task_id', $task);
  1159. if( isset($taskInfo['Note']) )
  1160. {
  1161. $note = explode(':',$taskInfo['Note']);
  1162. $this->add_value('note', $note[0]);
  1163. unset($note);
  1164. }
  1165. $this->add_ifvalue($taskInfo, 'Type', 'type');
  1166. $this->add_value('locale', $data['Locale']);
  1167. $querystr = "REPLACE INTO `" . $roster->db->table('quest_task_data') . "` SET " . $this->assignstr . ";";
  1168. $result = $roster->db->query($querystr);
  1169. if( !$result )
  1170. {
  1171. $this->setError('Quest Task [' . $taskInfo['Note'] . '] for Quest Data [' . $quest['QuestId'] . ' : ' . $quest['Title'] . '] could not be inserted',$roster->db->error());
  1172. }
  1173. }
  1174. }
  1175. */
  1176. // Insert this quest id for the character
  1177. $this->reset_values();
  1178. $this->add_value('member_id', $member_id);
  1179. $this->add_ifvalue($quest, 'QuestId', 'quest_id');
  1180. $this->add_value('quest_index', $slot);
  1181. $this->add_ifvalue($quest, 'Difficulty', 'difficulty');
  1182. $this->add_ifvalue($quest, 'Complete', 'is_complete');
  1183. $querystr = "INSERT INTO `" . $roster->db->table('quests') . "` SET " . $this->assignstr . ";";
  1184. $result = $roster->db->query($querystr);
  1185. if( !$result )
  1186. {
  1187. $this->setError('Quest [' . $quest['Title'] . '] could not be inserted',$roster->db->error());
  1188. }
  1189. }
  1190. /**
  1191. * Formats mail data to be inserted to the db
  1192. *
  1193. * @param array $mail_data
  1194. * @param int $memberId
  1195. * @param string $slot_num
  1196. * @return array
  1197. */
  1198. function make_mail( $mail_data , $memberId , $slot_num )
  1199. {
  1200. $mail = array();
  1201. $mail['member_id'] = $memberId;
  1202. $mail['mail_slot'] = $slot_num;
  1203. $mail['mail_icon'] = $this->fix_icon($mail_data['MailIcon']);
  1204. $mail['mail_coin'] = ( isset($mail_data['Coin']) ? $mail_data['Coin'] : 0 );
  1205. $mail['mail_coin_icon'] = ( isset($mail_data['CoinIcon']) ? $this->fix_icon($mail_data['CoinIcon']) : '' );
  1206. $mail['mail_days'] = $mail_data['Days'];
  1207. $mail['mail_sender'] = $mail_data['Sender'];
  1208. $mail['mail_subject'] = $mail_data['Subject'];
  1209. return $mail;
  1210. }
  1211. /**
  1212. * Formats item data to be inserted into the db
  1213. *
  1214. * @param array $item_data
  1215. * @param int $memberId
  1216. * @param string $parent
  1217. * @param string $slot_name
  1218. * @return array
  1219. */
  1220. function make_item( $item_data , $memberId , $parent , $slot_name )
  1221. {
  1222. $item = array();
  1223. $item['member_id'] = $memberId;
  1224. $item['item_name'] = $item_data['Name'];
  1225. $item['item_parent'] = $parent;
  1226. $item['item_slot'] = $slot_name;
  1227. $item['item_color'] = ( isset($item_data['Color']) ? $item_data['Color'] : 'ffffff' );
  1228. $item['item_id'] = ( isset($item_data['Item']) ? $item_data['Item'] : '0:0:0:0:0:0:0:0' );
  1229. $item['item_texture'] = ( isset($item_data['Icon']) ? $this->fix_icon($item_data['Icon']) : 'inv_misc_questionmark' );
  1230. $item['item_quantity'] = ( isset($item_data['Quantity']) ? $item_data['Quantity'] : 1 );
  1231. $item['level'] = ( isset($item_data['reqLevel']) ? $item_data['reqLevel'] : null );
  1232. $item['item_level'] = ( isset($item_data['iLevel']) ? $item_data['iLevel'] : '' );
  1233. $item['item_type'] = ( isset($item_data['Type']) ? $item_data['Type'] : '' );
  1234. $item['item_subtype'] = ( isset($item_data['SubType']) ? $item_data['SubType'] : '' );
  1235. $item['item_rarity'] = ( isset($item_data['Rarity']) ? $item_data['Rarity'] : '' );
  1236. if( !empty($item_data['Tooltip']) )
  1237. {
  1238. $item['item_tooltip'] = $this->tooltip($item_data['Tooltip']);
  1239. }
  1240. else
  1241. {
  1242. $item['item_tooltip'] = $item_data['Name'];
  1243. }
  1244. if( !empty($item_data['Gem']))
  1245. {
  1246. $this->do_gems($item_data['Gem'], $item_data['Item']);
  1247. }
  1248. return $item;
  1249. }
  1250. /**
  1251. * Formats gem data to be inserted into the database
  1252. *
  1253. * @param array $gem_data
  1254. * @param int $socket_id
  1255. * @return array $gem if successful else returns false
  1256. */
  1257. function make_gem( $gem_data , $socket_id )
  1258. {
  1259. global $roster;
  1260. $gemtt = explode( '<br>', $gem_data['Tooltip'] );
  1261. if( $gemtt[0] !== '' )
  1262. {
  1263. foreach( $gemtt as $line )
  1264. {
  1265. $colors = array();
  1266. $line = preg_replace('/\|c[a-f0-9]{8}(.+?)\|r/i','$1',$line); // CP error? strip out color
  1267. // -- start the parsing
  1268. if( preg_match('/'.$roster->locale->wordings[$this->locale]['tooltip_boss'] . '|' . $roster->locale->wordings[$this->locale]['tooltip_source'] . '|' . $roster->locale->wordings[$this->locale]['tooltip_droprate'].'/', $line) )
  1269. {
  1270. continue;
  1271. }
  1272. elseif( preg_match('/%|\+|'.$roster->locale->wordings[$this->locale]['tooltip_chance'].'/', $line) ) // if the line has a + or % or the word Chance assume it's bonus line.
  1273. {
  1274. $gem_bonus = $line;
  1275. }
  1276. elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_meta'], $line) )
  1277. {
  1278. $gem_color = 'meta';
  1279. }
  1280. elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_multicolor'], $line, $colors) )
  1281. {
  1282. if( $colors[1] == $roster->locale->wordings[$this->locale]['gem_colors']['red'] && $colors[2] == $roster->locale->wordings[$this->locale]['gem_colors']['blue'] || $colors[1] == $roster->locale->wordings[$this->locale]['gem_colors']['blue'] && $colors[2] == $roster->locale->wordings[$this->locale]['gem_colors']['red'] )
  1283. {
  1284. $gem_color = 'purple';
  1285. }
  1286. elseif( $colors[1] == $roster->locale->wordings[$this->locale]['gem_colors']['yellow'] && $colors[2] == $roster->locale->wordings[$this->locale]['gem_colors']['red'] || $colors[1] == $roster->locale->wordings[$this->locale]['gem_colors']['red'] && $colors[2] == $roster->locale->wordings[$this->locale]['gem_colors']['yellow'] )
  1287. {
  1288. $gem_color = 'orange';
  1289. }
  1290. elseif( $colors[1] == $roster->locale->wordings[$this->locale]['gem_colors']['yellow'] && $colors[2] == $roster->locale->wordings[$this->locale]['gem_colors']['blue'] || $colors[1] == $roster->locale->wordings[$this->locale]['gem_colors']['blue'] && $colors[2] == $roster->locale->wordings[$this->locale]['gem_colors']['yellow'] )
  1291. {
  1292. $gem_color = 'green';
  1293. }
  1294. }
  1295. elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_singlecolor'], $line, $colors) )
  1296. {
  1297. $tmp = array_flip($roster->locale->wordings[$this->locale]['gem_colors']);
  1298. $gem_color = $tmp[$colors[1]];
  1299. }
  1300. elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_prismatic'], $line) )
  1301. {
  1302. $gem_color = 'prismatic';
  1303. }
  1304. }
  1305. //get gemid and remove the junk
  1306. list($gemid) = explode(':', $gem_data['Item']);
  1307. $gem = array();
  1308. $gem['gem_name'] = $gem_data['Name'];
  1309. $gem['gem_tooltip'] = $this->tooltip($gem_data['Tooltip']);
  1310. $gem['gem_bonus'] = $gem_bonus;
  1311. $gem['gem_socketid']= $gem_data['gemID'];//$socket_id; // the ID the gem holds when socketed in an item.
  1312. $gem['gem_id'] = $gemid; // the ID of gem when not socketed.
  1313. $gem['gem_texture'] = $this->fix_icon($gem_data['Icon']);
  1314. $gem['gem_color'] = $gem_color; //meta, prismatic, red, blue, yellow, purple, green, orange.
  1315. return $gem;
  1316. }
  1317. else
  1318. {
  1319. return false;
  1320. }
  1321. }
  1322. /**
  1323. * Formats recipe data to be inserted into the db
  1324. *
  1325. * @param array $recipe_data
  1326. * @param int $memberId
  1327. * @param string $parent
  1328. * @param string $recipe_type
  1329. * @param string $recipe_name
  1330. * @return array
  1331. */
  1332. function make_recipe( $recipe_data , $memberId , $parent , $recipe_type , $recipe_name )
  1333. {
  1334. $recipe = array();
  1335. $recipe['member_id'] = $memberId;
  1336. $recipe['recipe_name'] = $recipe_name;
  1337. $recipe['recipe_type'] = $recipe_type;
  1338. $recipe['skill_name'] = $parent;
  1339. // Fix Difficulty since it's now a string field
  1340. if( !is_numeric($recipe_data['Difficulty']) )
  1341. {
  1342. switch($recipe_data['Difficulty'])
  1343. {
  1344. case 'difficult':
  1345. $recipe['difficulty'] = 5;
  1346. break;
  1347. case 'optimal':
  1348. $recipe['difficulty'] = 4;
  1349. break;
  1350. case 'medium':
  1351. $recipe['difficulty'] = 3;
  1352. break;
  1353. case 'easy':
  1354. $recipe['difficulty'] = 2;
  1355. break;
  1356. case 'trivial':
  1357. default:
  1358. $recipe['difficulty'] = 1;
  1359. break;
  1360. }
  1361. }
  1362. else
  1363. {
  1364. $recipe['difficulty'] = $recipe_data['Difficulty'];
  1365. }
  1366. $recipe['item_color'] = isset($recipe_data['Color']) ? $recipe_data['Color'] : '';
  1367. $recipe['item_id'] = isset($recipe_data['Item']) ? $recipe_data['Item'] : '';
  1368. $recipe['recipe_id'] = isset($recipe_data['RecipeID']) ? $recipe_data['RecipeID'] : '';
  1369. $recipe['reagent_data'] = $recipe_data['Reagents'];
  1370. $recipe['reagent_list'] = array();
  1371. foreach( $recipe_data['Reagents'] as $d => $reagent )
  1372. {
  1373. //aprint($reagent);
  1374. $id = explode(':', $reagent['Item']);
  1375. if(isset($reagent['Quantity']))
  1376. {
  1377. $count = $reagent['Quantity'];
  1378. }
  1379. elseif (isset($reagent['Count']))
  1380. {
  1381. $count = $reagent['Count'];
  1382. }
  1383. else
  1384. {
  1385. $count = '1';
  1386. }
  1387. $recipe['reagent_list'][] = $id[0] . ':' . $count;
  1388. }
  1389. $recipe['reagent_list'] = implode('|',$recipe['reagent_list']);
  1390. $recipe['recipe_texture'] = $this->fix_icon($recipe_data['Icon']);
  1391. if( !empty($recipe_data['Tooltip']) )
  1392. {
  1393. $recipe['recipe_tooltip'] = $this->tooltip( $recipe_data['Tooltip'] );
  1394. }
  1395. else
  1396. {
  1397. $recipe['recipe_tooltip'] = $recipe_name;
  1398. }
  1399. return $recipe;
  1400. }
  1401. /**
  1402. * Handles formating and insertion of buff data
  1403. *
  1404. * @param array $data
  1405. * @param int $memberId
  1406. */
  1407. function do_buffs( $data , $memberId )
  1408. {
  1409. global $roster;
  1410. // Delete the stale data
  1411. $querystr = "DELETE FROM `" . $roster->db->table('buffs') . "` WHERE `member_id` = '$memberId';";
  1412. if( !$roster->db->query($querystr) )
  1413. {
  1414. $this->setError('Buffs could not be deleted',$roster->db->error());
  1415. return;
  1416. }
  1417. if( isset($data['Attributes']['Buffs']) )
  1418. {
  1419. $buffs = $data['Attributes']['Buffs'];
  1420. }
  1421. if( !empty($buffs) && is_array($buffs) )
  1422. {
  1423. // Then process buffs
  1424. $buffsnum = 0;
  1425. foreach( $buffs as $buff )
  1426. {
  1427. if( is_null($buff) || !is_array($buff) || empty($buff) )
  1428. {
  1429. continue;
  1430. }
  1431. $this->reset_values();
  1432. $this->add_value('member_id', $memberId);
  1433. $this->add_ifvalue($buff, 'Name', 'name');
  1434. if( isset($buff['Icon']) )
  1435. {
  1436. $this->add_value('icon', $this->fix_icon($buff['Icon']));
  1437. }
  1438. $this->add_ifvalue($buff, 'Rank', 'rank');
  1439. $this->add_ifvalue($buff, 'Count', 'count');
  1440. if( !empty($buff['Tooltip']) )
  1441. {
  1442. $this->add_value('tooltip', $this->tooltip($buff['Tooltip']));
  1443. }
  1444. else
  1445. {
  1446. $this->add_ifvalue($buff, 'Name', 'tooltip');
  1447. }
  1448. $querystr = "INSERT INTO `" . $roster->db->table('buffs') . "` SET " . $this->assignstr . ";";
  1449. $result = $roster->db->query($querystr);
  1450. if( !$result )
  1451. {
  1452. $this->setError('Buff [' . $buff['Name'] . '] could not be inserted',$roster->db->error());
  1453. }
  1454. $buffsnum++;
  1455. }
  1456. $this->setMessage('<li>Updating Buffs: ' . $buffsnum . '</li>');
  1457. }
  1458. else
  1459. {
  1460. $this->setMessage('<li>No Buffs</li>');
  1461. }
  1462. }
  1463. /**
  1464. * Handles formating and ins…

Large files files are truncated, but you can click here to view the full file