/lib/update.lib.php
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
- <?php
- /**
- * WoWRoster.net WoWRoster
- *
- * LUA updating library
- *
- *
- * @copyright 2002-2011 WoWRoster.net
- * @license http://www.gnu.org/licenses/gpl.html Licensed under the GNU General Public License v3.
- * @version SVN: $Id: update.lib.php 2351 2011-09-13 19:45:48Z ulminia@gmail.com $
- * @link http://www.wowroster.net
- * @since File available since Release 1.8.0
- * @package WoWRoster
- * @subpackage LuaUpdate
- */
- if ( !defined('IN_ROSTER') )
- {
- exit('Detected invalid access to this file!');
- }
- /**
- * Lua Update handler
- *
- * @package WoWRoster
- * @subpackage LuaUpdate
- */
- class update
- {
- var $textmode = false;
- var $uploadData;
- var $addons = array();
- var $files = array();
- var $locale;
- var $blinds = array();
- var $processTime; // time() starting timestamp for enforceRules
- var $messages = array();
- var $errors = array();
- var $assignstr = '';
- var $assigngem = ''; // 2nd tracking property since we build a gem list while building an items list
- var $membersadded = 0;
- var $membersupdated = 0;
- var $membersremoved = 0;
- var $current_region = '';
- var $current_realm = '';
- var $current_guild = '';
- var $current_member = '';
- var $talent_build_urls = array();
- /**
- * Collect info on what files are used
- */
- function fetchAddonData()
- {
- global $roster;
- // Add roster-used tables
- // $this->files[] = 'characterprofiler';
- $this->files[] = 'wowroster';
- if( !$roster->config['use_update_triggers'] )
- {
- return;
- }
- if( !empty($roster->addon_data) )
- {
- foreach( $roster->addon_data as $row )
- {
- $hookfile = ROSTER_ADDONS . $row['basename'] . DIR_SEP . 'inc' . DIR_SEP . 'update_hook.php';
- if( file_exists($hookfile) )
- {
- // Check if this addon is in the process of an upgrade and deny access if it hasn't yet been upgraded
- $installfile = ROSTER_ADDONS . $row['basename'] . DIR_SEP . 'inc' . DIR_SEP . 'install.def.php';
- $install_class = $row['basename'] . 'Install';
- if( file_exists($installfile) )
- {
- include_once($installfile);
- if( class_exists($install_class) )
- {
- $addonstuff = new $install_class;
- // -1 = overwrote newer version
- // 0 = same version
- // 1 = upgrade available
- if( version_compare($addonstuff->version,$row['version']) )
- {
- $this->setError(sprintf($roster->locale->act['addon_upgrade_notice'],$row['basename']),$roster->locale->act['addon_error']);
- continue;
- }
- unset($addonstuff);
- }
- }
- $addon = getaddon($row['basename']);
- include_once($hookfile);
- $updateclass = $row['basename'] . 'Update';
- // Save current locale array
- // Since we add all locales for localization, we save the current locale array
- // This is in case one addon has the same locale strings as another, and keeps them from overwritting one another
- $localetemp = $roster->locale->wordings;
- foreach( $roster->multilanguages as $lang )
- {
- $roster->locale->add_locale_file(ROSTER_ADDONS . $addon['basename'] . DIR_SEP . 'locale' . DIR_SEP . $lang . '.php',$lang);
- }
- $addon['fullname'] = ( isset($roster->locale->act[$addon['fullname']]) ? $roster->locale->act[$addon['fullname']] : $addon['fullname'] );
- if( class_exists($updateclass) )
- {
- $this->addons[$row['basename']] = new $updateclass($addon);
- $this->files = array_merge($this->files,$this->addons[$row['basename']]->files);
- }
- else
- {
- $this->setError('Failed to load update trigger for ' . $row['basename'] . ': Update class did not exist',$roster->locale->act['addon_error']);
- }
- // Restore our locale array
- $roster->locale->wordings = $localetemp;
- unset($localetemp);
- }
- }
- }
- // Remove duplicates
- $this->files = array_unique($this->files);
- // Make all the file names requested lower case
- $this->files = array_flip($this->files);
- $this->files = array_change_key_case($this->files);
- $this->files = array_flip($this->files);
- }
- /**
- *
- * file error upload handler
- * returns true/false | sets error message with file name
- */
-
- function upload_error_check($file)
- {
- global $roster;
- switch($file['error'])
- {
- case UPLOAD_ERR_OK: // Value: 0; There is no error, the file uploaded with success.
- return true;
- break;
-
- case UPLOAD_ERR_INI_SIZE: // Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
- $this->setError('The uploaded file exceeds the upload_max_filesize directive in php.ini.','File Error ['.$file['name'].']');
-
- case UPLOAD_ERR_FORM_SIZE: // Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
- $this->setError('The uploaded file exceeds the server maximum filesize allowed.','File Error ['.$file['name'].']');
- return false;
- break;
-
- case UPLOAD_ERR_PARTIAL: // Value: 3; The uploaded file was only partially uploaded.
- $this->setError('The uploaded file was only partially uploaded.','File Error ['.$file['name'].']');
- return false;
- break;
-
- case UPLOAD_ERR_NO_FILE: // Value: 4; No file was uploaded.
- $this->setError('No file was uploaded.','File Error ['.$file['name'].']');
- return false;
- break;
-
- case UPLOAD_ERR_NO_TMP_DIR: // Value: 6; Missing a temporary folder.
- $output .= '<li>Missing a temporary folder. Please contact the admin.</li>';
- return false;
- break;
-
- case UPLOAD_ERR_CANT_WRITE: // Value: 7; Failed to write file to disk.
- $output .= '<li>Failed to write file to disk. Please contact the admin.</li>';
- return false;
- break;
- }
- }
-
-
- /**
- * Parses the files and put it in $uploadData
- *
- * @return string $output | Output messages
- */
- function parseFiles( )
- {
- global $roster;
- if( !is_array($_FILES) )
- {
- return '<span class="red">Upload failed: No files present</span>' . "<br />\n";
- }
- require_once(ROSTER_LIB . 'luaparser.php');
- $output = $roster->locale->act['parsing_files'] . "<br />\n<ul>";
- foreach( $_FILES as $file )
- {
- if( !empty($file['name']) && $this->upload_error_check($file))
- {
- $filename = explode('.',$file['name']);
- $filebase = strtolower($filename[0]);
-
- if( in_array($filebase,$this->files))
- {
- // Get start of parse time
- $parse_starttime = format_microtime();
- $luahandler = new lua();
- $data = $luahandler->luatophp( $file['tmp_name'], isset($this->blinds[$filebase]) ? $this->blinds[$filebase] : array() );
- // Calculate parse time
- $parse_totaltime = round((format_microtime() - $parse_starttime), 2);
- if( $data )
- {
- $output .= '<li>' . sprintf($roster->locale->act['parsed_time'],$filename[0],$parse_totaltime) . "</li>\n";
- $this->uploadData[$filebase] = $data;
- }
- else
- {
- $output .= '<li>' . sprintf($roster->locale->act['error_parsed_time'],$filename[0],$parse_totaltime) . "</li>\n";
- $output .= ($luahandler->error() != '' ? '<li>' . $luahandler->error() . "</li>\n" : '');
- }
- unset($luahandler);
- }
- else
- {
- $output .= '<li>' . sprintf($roster->locale->act['upload_not_accept'],$file['name']) . "</li>\n";
- }
- }
- else
- {
- $output .= '<li>' . sprintf($roster->locale->act['error_parsed_time'],$file['name'],'0') . "</li>\n";
- }
- }
- $output .= "</ul><br />\n";
- return $output;
- }
- /**
- * Process the files
- *
- * @return string $output | Output messages
- */
- function processFiles()
- {
- global $roster;
- $this->processTime = time();
- if( !is_array($this->uploadData) )
- {
- return '';
- }
- $output = $roster->locale->act['processing_files'] . "<br />\n";
- $gotfiles = array_keys($this->uploadData);
- // if( in_array('characterprofiler',$gotfiles) || in_array('wowroster',$gotfiles) )
- if( in_array('wowroster',$gotfiles) )
- {
- if( $roster->auth->getAuthorized($roster->config['gp_user_level']) )
- {
- $output .= $this->processGuildRoster();
- $output .= "<br />\n";
- if( $roster->config['enforce_rules'] == '3' )
- {
- $this->enforceRules($this->processTime);
- }
- }
- if( $roster->auth->getAuthorized($roster->config['cp_user_level']) )
- {
- $output .= $this->processMyProfile();
- if( $roster->config['enforce_rules'] == '2' )
- {
- $this->enforceRules($this->processTime);
- }
- }
- }
- if( $roster->auth->getAuthorized($roster->config['lua_user_level']) )
- {
- if( is_array($this->addons) && count($this->addons) > 0 )
- {
- foreach( array_keys($this->addons) as $addon )
- {
- if( count(array_intersect($gotfiles, $this->addons[$addon]->files)) > 0 )
- {
- if( file_exists($this->addons[$addon]->data['trigger_file']) )
- {
- $this->addons[$addon]->reset_messages();
- if( method_exists($this->addons[$addon], 'update') )
- {
- $result = $this->addons[$addon]->update();
- if( $result )
- {
- $output .= $this->addons[$addon]->messages;
- }
- else
- {
- $output .= sprintf($roster->locale->act['error_addon'],$this->addons[$addon]->data['fullname'],'update') . "<br />\n"
- . $roster->locale->act['addon_messages'] . "<br />\n" . $this->addons[$addon]->messages;
- }
- }
- }
- }
- }
- }
- if( $roster->config['enforce_rules'] == '1' )
- {
- $this->enforceRules($this->processTime);
- }
- }
- return $output;
- }
- /**
- * Run trigger
- */
- function addon_hook( $mode , $data , $memberid = '0' )
- {
- global $roster;
- $output = '';
- foreach( array_keys($this->addons) as $addon )
- {
- if( file_exists($this->addons[$addon]->data['trigger_file']) )
- {
- $this->addons[$addon]->reset_messages();
- if( method_exists($this->addons[$addon], $mode) )
- {
- $result = $this->addons[$addon]->{$mode}($data , $memberid);
- if( $result )
- {
- if( $mode == 'guild' )
- {
- $output .= '<li>' . $this->addons[$addon]->messages . "</li>\n";
- }
- else
- {
- $output .= $this->addons[$addon]->messages . "<br />\n";
- }
- }
- else
- {
- if( $mode == 'guild' )
- {
- $output .= '<li>' . sprintf($roster->locale->act['error_addon'],$this->addons[$addon]->data['fullname'],$mode) . "<br />\n"
- . $roster->locale->act['addon_messages'] . "<br />\n" . $this->addons[$addon]->messages . "</li>\n";
- }
- else
- {
- $output .= sprintf($roster->locale->act['error_addon'],$this->addons[$addon]->data['fullname'],$mode) . "<br />\n"
- . $roster->locale->act['addon_messages'] . "<br />\n" . $this->addons[$addon]->messages . "<br />\n";
- }
- }
- }
- }
- }
- return $output;
- }
- /**
- * Process character data
- */
- function processMyProfile()
- {
- global $roster;
- /**
- * Rule #1 Deny everything
- * Rule #2 If it breaks, Zanix did it
- * Rule #3 This works for both new and old CPs lol
- * Rule #4 If Zanix yells at you, you deserve it
- */
- /* if ( isset($this->uploadData['characterprofiler']['myProfile']) )
- {
- $myProfile = $this->uploadData['characterprofiler']['myProfile'];
- }
- else
- */
- if ( isset($this->uploadData['wowroster']['cpProfile']) )
- {
- $myProfile = $this->uploadData['wowroster']['cpProfile'];
- }
- else
- {
- return;
- }
- $output = '';
- $this->resetMessages();
- foreach( $myProfile as $realm_name => $realm )
- {
- $this->current_realm = $realm_name;
- if( isset($realm['Character']) && is_array($realm['Character']) )
- {
- $characters = $realm['Character'];
- // Start update triggers
- if( $roster->config['use_update_triggers'] )
- {
- $output .= $this->addon_hook('char_pre', $characters);
- }
- foreach( $characters as $char_name => $char )
- {
- $this->current_member = $char_name;
- // CP Version Detection, don't allow lower than minVer
- if( version_compare($char['CPversion'], $roster->config['minCPver'], '>=') )
- {
- // Get the region
- if( isset($char['timestamp']['init']['datakey']) )
- {
- list($region) = explode(':',$char['timestamp']['init']['datakey']);
- $region = strtoupper($region);
- }
- else
- {
- $region = '';
- }
- // Official realms don't trigger this. I looked up and verified the asian ones as well.
- if( strlen($region) > 2 )
- {
- roster_die('You are not playing on an official realm, and your data is incompatible with WoWRoster<br /><br />'
- . 'This message exists because we are getting annoyed by the occasional person who can\'t get WoWRoster to work with a private server, '
- . 'when we clearly state that WoWRoster will not work on private servers.<br />'
- . 'You are on your own if you want WoWRoster to work with a private server. Good luck fixing it!'
- ,'Invalid Region/Realm');
- }
- $this->current_region = $region;
- // Get the CP timestamp
- $timestamp = $char['timestamp']['init']['DateUTC'];
- $realm_escape = $roster->db->escape($realm_name);
- // Is this char already in the members table?
- $query = "SELECT `guild_id`, `member_id`"
- . " FROM `" . $roster->db->table('members') . "`"
- . " WHERE `name` = '" . $char_name . "'"
- . " AND `server` = '" . $realm_escape . "'"
- . " AND `region` = '" . $region . "';";
- if( !$roster->db->query_first($query) )
- {
- // Allowed char detection
- $query = "SELECT `type`, COUNT(`rule_id`)"
- . " FROM `" . $roster->db->table('upload') . "`"
- . " WHERE (`type` = 2 OR `type` = 3)"
- . " AND '" . $char_name . "' LIKE `name`"
- . " AND '" . $realm_escape . "' LIKE `server`"
- . " AND '" . $region."' LIKE `region`"
- . " GROUP BY `type`"
- . " ORDER BY `type` DESC;";
- /**
- * This might need explaining. The query potentially returns 2 rows:
- * First the number of matching deny rows, then the number of matching
- * accept rows. If there are deny rows, `type`=3 in the first row, and
- * we reject the upload. If there are no deny rows, but there are accept
- * rows, `type`=2 in the first row, and we accept the upload. If there are
- * no relevant rows at all, query_first will return false, and we reject
- * the upload.
- */
- if( $roster->db->query_first($query) !== '2' )
- {
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_accepted'], $roster->locale->act['character'], $char_name, $region, $realm_name) . "</span><br />\n";
- continue;
- }
- else
- {
- // Fabricate a guild update
- // We can probably use the $char['Guild'] block for this info instead of Guildless I suppose....
- $guilddata['Faction'] = $char['FactionEn'];
- $guilddata['FactionEn'] = $char['FactionEn'];
- $guilddata['Locale'] = $char['Locale'];
- $guilddata['Info'] = '';
- $guildId = $this->update_guild($realm_name, 'GuildLess-' . substr($char['FactionEn'],0,1), strtotime($timestamp), $guilddata, $region);
- unset($guilddata);
- // Copy the array so we can set Online to 1 until I can find a better way to set last online time
- // We could probably get away with just setting 'Online' in the $char array, but I dont wanna risk tainting the data
- $chartemp = $char;
- $chartemp['Online'] = '1';
- $this->update_guild_member($guildId, $char_name, $realm_name, $region, $chartemp, strtotime($timestamp), array());
- unset($chartemp);
- array_pop($this->messages);
- }
- }
- else
- {
- $guildId = $roster->db->query_first($query);
- }
- $time = $roster->db->query_first("SELECT `dateupdatedutc` FROM `" . $roster->db->table('players') . "`"
- . " WHERE '" . $char_name . "' LIKE `name`"
- . " AND '" . $realm_escape . "' LIKE `server`"
- . " AND '" . $region . "' LIKE `region`;");
- // Check if the profile is old
- if( $time != '' && ( strtotime($time) - strtotime($timestamp) ) > 0 )
- {
- $current = date($roster->locale->act['phptimeformat'], strtotime($time));
- $update = date($roster->locale->act['phptimeformat'], strtotime($timestamp));
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_update_char_time'], $char_name, $update, $current) . "</span><br />\n";
- continue;
- }
- $output .= '<strong>' . sprintf($roster->locale->act['upload_data'], $roster->locale->act['character'], $char_name, $realm_name, $region) . "</strong>\n";
- $memberid = $this->update_char($guildId, $region, $realm_name, $char_name, $char);
- $output .= "<ul>\n" . $this->getMessages() . "</ul>\n";
- $this->resetMessages();
- // Start update triggers
- if( $memberid !== false && $roster->config['use_update_triggers'] )
- {
- $output .= $this->addon_hook('char', $char, $memberid);
- }
- }
- else // CP Version not new enough
- {
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_updating'], 'WoWRoster-Profiler', $char_name, $char['CPversion']) . "</span><br />\n";
- $output .= sprintf($roster->locale->act['CPver_err'], $roster->config['minCPver']) . "\n";
- }
- }
- // Start update triggers
- if( $roster->config['use_update_triggers'] )
- {
- $output .= $this->addon_hook('char_post', $characters);
- }
- }
- }
- return $output;
- }
- /**
- * Process guild data
- */
- function processGuildRoster()
- {
- global $roster;
- /*
- if ( isset($this->uploadData['characterprofiler']['myProfile']) )
- {
- $myProfile = $this->uploadData['characterprofiler']['myProfile'];
- }
- else
- */
- if ( isset($this->uploadData['wowroster']['cpProfile']) )
- {
- $myProfile = $this->uploadData['wowroster']['cpProfile'];
- }
- else
- {
- return;
- }
- $output = '';
- $this->resetMessages();
- if( is_array($myProfile) )
- {
- foreach( $myProfile as $realm_name => $realm )
- {
- $this->current_realm = $realm_name;
- if( isset($realm['Guild']) && is_array($realm['Guild']) )
- {
- foreach( $realm['Guild'] as $guild_name => $guild )
- {
- $this->current_guild = $guild_name;
- // GP Version Detection, don't allow lower than minVer
- if( version_compare($guild['GPversion'], $roster->config['minGPver'], '>=') )
- {
- // Get the region
- if( isset($guild['timestamp']['init']['datakey']) )
- {
- list($region) = explode(':',$guild['timestamp']['init']['datakey']);
- $region = strtoupper($region);
- }
- else
- {
- $region = '';
- }
- $this->current_region = $region;
- $guild_escape = $roster->db->escape($guild_name);
- $realm_escape = $roster->db->escape($realm_name);
- // Allowed guild detection
- $query = "SELECT `type`, COUNT(`rule_id`)"
- . " FROM `" . $roster->db->table('upload') . "`"
- . " WHERE (`type` = 0 OR `type` = 1)"
- . " AND '" . $guild_escape . "' LIKE `name`"
- . " AND '" . $realm_escape . "' LIKE `server`"
- . " AND '" . $region . "' LIKE `region`"
- . " GROUP BY `type`"
- . " ORDER BY `type` DESC;";
- /**
- * This might need explaining. The query potentially returns 2 rows:
- * First the number of matching deny rows, then the number of matching
- * accept rows. If there are deny rows, `type`=1 in the first row, and
- * we reject the upload. If there are no deny rows, but there are accept
- * rows, `type`=0 in the first row, and we accept the upload. If there are
- * no relevant rows at all, query_first will return false, and we reject
- * the upload.
- */
- if( $roster->db->query_first($query) !== '0' )
- {
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_accepted'], $roster->locale->act['guild'], $guild_name, $region, $realm_name) . "</span><br />\n";
- continue;
- }
- if( count($guild['Members']) > 0 )
- {
- // take the current time and get the offset. Upload must occur same day that roster was obtained
- $currentTimestamp = strtotime($guild['timestamp']['init']['DateUTC']);
- $time = $roster->db->query_first("SELECT `update_time` FROM `" . $roster->db->table('guild')
- . "` WHERE '" . $guild_escape . "' LIKE `guild_name`"
- . " AND '" . $realm_escape . "' LIKE `server`"
- . " AND '" . $region . "' LIKE `region`;");
- // Check if the profile is old
- if( $time != '' && ( strtotime($time) - $currentTimestamp ) > 0 )
- {
- $current = date($roster->locale->act['phptimeformat'], strtotime($time));
- $update = date($roster->locale->act['phptimeformat'], $currentTimestamp);
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_update_guild_time'], $guild_name, $update, $current) . "</span><br />\n";
- continue;
- }
- // Update the guild
- $guildId = $this->update_guild($realm_name, $guild_name, $currentTimestamp, $guild, $region);
- $guild['guild_id'] = $guildId;
- $guildMembers = $guild['Members'];
- $guild_output = '';
- // Start update triggers
- if( $roster->config['use_update_triggers'] )
- {
- $guild_output .= $this->addon_hook('guild_pre', $guild);
- }
- // update the list of guild members
- $guild_output .= "<ul><li><strong>" . $roster->locale->act['update_members'] . "</strong>\n<ul>\n";
- foreach(array_keys($guildMembers) as $char_name)
- {
- $this->current_member = $char_name;
- $char = $guildMembers[$char_name];
- $memberid = $this->update_guild_member($guildId, $char_name, $realm_name, $region, $char, $currentTimestamp, $guild);
- $guild_output .= $this->getMessages();
- $this->resetMessages();
- // Start update triggers
- if( $memberid !== false && $roster->config['use_update_triggers'] )
- {
- $guild_output .= $this->addon_hook('guild', $char, $memberid);
- }
- }
- // Remove the members who were not in this list
- $this->remove_guild_members($guildId, $currentTimestamp);
- $guild_output .= $this->getMessages()."</ul></li>\n";
- $this->resetMessages();
- $guild_output .= "</ul>\n";
- // Start update triggers
- if( $roster->config['use_update_triggers'] )
- {
- $guild_output .= $this->addon_hook('guild_post', $guild);
- }
- $output .= '<strong>' . sprintf($roster->locale->act['upload_data'],$roster->locale->act['guild'],$guild_name,$realm_name,$region) . "</strong>\n<ul>\n";
- $output .= '<li><strong>' . $roster->locale->act['memberlog'] . "</strong>\n<ul>\n"
- . '<li>' . $roster->locale->act['updated'] . ': ' . $this->membersupdated . "</li>\n"
- . '<li>' . $roster->locale->act['added'] . ': ' . $this->membersadded . "</li>\n"
- . '<li>' . $roster->locale->act['removed'] . ': ' . $this->membersremoved . "</li>\n"
- . "</ul></li></ul>\n";
- $output .= $guild_output;
- // Reset these since we might process another guild
- $this->membersupdated = $this->membersadded = $this->membersremoved = 0;
- }
- else
- {
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_update_guild'], $guild_name, $realm_name, $region) . "</span><br />\n";
- $output .= $roster->locale->act['no_members'];
- }
- }
- else
- // GP Version not new enough
- {
- $output .= '<span class="red">' . sprintf($roster->locale->act['not_updating'], 'WoWRoster-GuildProfiler', $guild_name, $guild['GPversion']) . "</span><br />\n";
- $output .= sprintf($roster->locale->act['GPver_err'], $roster->config['minGPver']);
- }
- }
- }
- else
- {
- $output .= '<span class="red">' . $roster->locale->act['guild_addonNotFound'] . '</span><br />';
- }
- }
- }
- return $output;
- }
- /**
- * Returns the file input fields for all addon files we need.
- *
- * @return string $filefields | The HTML, without border
- */
- function makeFileFields($blockname='file_fields')
- {
- global $roster;
- if( !is_array($this->files) || (count($this->files) == 0) ) // Just in case
- {
- $roster->tpl->assign_block_vars($blockname, array(
- 'TOOLTIP' => '',
- 'FILE' => 'No files accepted!'
- ));
- }
- $account_dir = '<i>*WOWDIR*</i>\\\\WTF\\\\Account\\\\<i>*ACCOUNT_NAME*</i>\\\\SavedVariables\\\\';
- foreach( $this->files as $file )
- {
- $roster->tpl->assign_block_vars($blockname, array(
- 'TOOLTIP' => makeOverlib($account_dir . $file . '.lua', $file . '.lua Location', '', 2, '', ',WRAP'),
- 'FILE' => $file
- ));
- }
- }
- /**
- * Adds a message to the $messages array
- *
- * @param string $message
- */
- function setMessage($message)
- {
- $this->messages[] = $message;
- }
- /**
- * Returns all messages
- *
- * @return string
- */
- function getMessages()
- {
- return implode("\n",$this->messages) . "\n";
- }
- /**
- * Resets the stored messages
- *
- */
- function resetMessages()
- {
- $this->messages = array();
- }
- /**
- * Adds an error to the $errors array
- *
- * @param string $message
- */
- function setError( $message , $error )
- {
- $this->errors[] = array($message=>$error);
- }
- /**
- * Gets the errors in wowdb
- * Return is based on $mode
- *
- * @param string $mode
- * @return mixed
- */
- function getErrors( $mode='' )
- {
- if( $mode == 'a' )
- {
- return $this->errors;
- }
- $output = '';
- $errors = $this->errors;
- if( !empty($errors) )
- {
- $output = '<table width="100%" cellspacing="0">';
- $steps = 0;
- foreach( $errors as $errorArray )
- {
- foreach( $errorArray as $message => $error )
- {
- if( $steps == 1 )
- {
- $steps = 2;
- }
- else
- {
- $steps = 1;
- }
- $output .= "<tr><td class=\"membersRowRight$steps\">$error<br />\n"
- . "$message</td></tr>\n";
- }
- }
- $output .= '</table>';
- }
- return $output;
- }
- /**
- * DB insert code (former WoWDB)
- */
- /**
- * Resets the SQL insert/update string holder
- */
- function reset_values()
- {
- $this->assignstr = '';
- }
- /**
- * Add a value to an INSERT or UPDATE SQL string
- *
- * @param string $row_name
- * @param string $row_data
- */
- function add_value( $row_name , $row_data )
- {
- global $roster;
- if( $this->assignstr != '' )
- {
- $this->assignstr .= ',';
- }
- // str_replace added to get rid of non breaking spaces in cp.lua tooltips
- $row_data = str_replace(chr(194) . chr(160), ' ', $row_data);
- $row_data = stripslashes($row_data);
- $row_data = $roster->db->escape($row_data);
- $this->assignstr .= " `$row_name` = '$row_data'";
- }
- /**
- * Verifies existance of variable before attempting add_value
- *
- * @param array $array
- * @param string $key
- * @param string $field
- * @param string $default
- * @return boolean
- */
- function add_ifvalue( $array , $key , $field=false , $default=false )
- {
- if( $field === false )
- {
- $field = $key;
- }
- if( isset($array[$key]) )
- {
- $this->add_value($field, $array[$key]);
- return true;
- }
- else
- {
- if( $default !== false )
- {
- $this->add_value($field, $default);
- }
- return false;
- }
- }
- /**
- * Add a gem to an INSERT or UPDATE SQL string
- * (clone of add_value method--this functions as a 2nd SQL insert placeholder)
- *
- * @param string $row_name
- * @param string $row_data
- */
- function add_gem( $row_name , $row_data )
- {
- global $roster;
- if( $this->assigngem != '' )
- {
- $this->assigngem .= ',';
- }
- $row_data = "'" . $roster->db->escape($row_data) . "'";
- $this->assigngem .= " `$row_name` = $row_data";
- }
- /**
- * Add a time value to an INSERT or UPDATE SQL string
- *
- * @param string $row_name
- * @param array $date
- */
- function add_time( $row_name , $date )
- {
- // 2000-01-01 23:00:00.000
- $row_data = $date['year'] . '-' . $date['mon'] . '-' . $date['mday'] . ' ' . $date['hours'] . ':' . $date['minutes'] . ':' . $date['seconds'];
- $this->add_value($row_name,$row_data);
- }
- /**
- * Add a time value to an INSERT or UPDATE SQL string
- *
- * @param string $row_name
- * @param string $date | UNIX TIMESTAMP
- */
- function add_timestamp( $row_name , $date )
- {
- $date = date('Y-m-d H:i:s',$date);
- $this->add_value($row_name,$date);
- }
- /**
- * Add a rating (base, buff, debuff, total)
- *
- * @param string $row_name will be appended _d, _b, _c for debuff, buff, total
- * @param string $data colon-separated data
- */
- function add_rating( $row_name , $data )
- {
- $data = explode(':',$data);
- $data[0] = ( isset($data[0]) && $data[0] != '' ? $data[0] : 0 );
- $data[1] = ( isset($data[1]) && $data[1] != '' ? $data[1] : 0 );
- $data[2] = ( isset($data[2]) && $data[2] != '' ? $data[2] : 0 );
- $this->add_value($row_name, round($data[0]));
- $this->add_value($row_name . '_c', round($data[0]+$data[1]+$data[2]));
- $this->add_value($row_name . '_b', round($data[1]));
- $this->add_value($row_name . '_d', round($data[2]));
- }
- /**
- * Turn the WoW internal icon format into the one used by us
- * All lower case and spaces converted into _
- *
- * @param string $icon_name
- * @return string
- */
- function fix_icon( $icon_name )
- {
- $icon_name = basename($icon_name);
- return strtolower(str_replace(' ','_',$icon_name));
- }
- /**
- * Format tooltips for insertion to the db
- *
- * @param mixed $tipdata
- * @return string
- */
- function tooltip( $tipdata )
- {
- $tooltip = '';
- if( is_array($tipdata) )
- {
- $tooltip = implode("\n",$tipdata);
- }
- else
- {
- $tooltip = str_replace('<br>',"\n",$tipdata);
- }
- return $tooltip;
- }
- /**
- * Inserts an reagent into the database
- *
- * @param string $item
- * @return bool
- */
- function insert_reagent( $memberId , $reagents , $locale )
- {
- global $roster;
- //echo'<pre>';
- //print_r($reagents);
- foreach ($reagents as $ind => $reagent)
- {
- $this->reset_values();
- $this->add_value('member_id', $memberId);
- $this->add_value('reagent_id', $reagent['Item']);
- $this->add_ifvalue($reagent, 'Name', 'reagent_name');
- $this->add_ifvalue($reagent, 'Count', 'reagent_count');
- $this->add_ifvalue($reagent, 'Color', 'reagent_color');
- // Fix icon
- if( !empty($reagent['Icon']) )
- {
- $reagent['Icon'] = $this->fix_icon($reagent['Icon']);
- }
- else
- {
- $reagent['Icon'] = 'inv_misc_questionmark';
- }
- // Fix tooltip
- if( !empty($reagent['Tooltip']) )
- {
- $reagent['item_tooltip'] = $this->tooltip($reagent['Tooltip']);
- }
- else
- {
- $reagent['item_tooltip'] = $reagent['Name'];
- }
- $this->add_value('reagent_texture', $reagent['Icon']);
- $this->add_value('reagent_tooltip', $reagent['Tooltip']);
- $this->add_value('locale', $locale);
- /* $level = array();
- if( isset($reagent_data['reqLevel']) && !is_null($reagent_data['reqLevel']) )
- {
- $this->add_value('level', $reagent_data['reqLevel']);
- }
- else if( preg_match($roster->locale->wordings[$locale]['requires_level'],$reagent['item_tooltip'],$level))
- {
- $this->add_value('level', $level[1]);
- }
- // gotta see of the reagent is in the db already....
- */
- $querystra = "SELECT * FROM `" . $roster->db->table('recipes_reagents') . "` WHERE `reagent_id` = " . $reagent['Item'] . ";";
- $resulta = $roster->db->query($querystra);
- $num = $roster->db->num_rows($resulta);
- if ($num < '1')
- {
- $querystr = "INSERT INTO `" . $roster->db->table('recipes_reagents') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Item [' . $reagent['Name'] . '] could not be inserted',$roster->db->error());
- }
- }
- }
- }
- /**
- * Inserts an item into the database
- *
- * @param string $item
- * @return bool
- */
- function insert_item( $item , $locale )
- {
- global $roster;
- // echo '<pre>';
- //print_r($item);
- $this->reset_values();
- $this->add_ifvalue($item, 'member_id');
- $this->add_ifvalue($item, 'item_name');
- $this->add_ifvalue($item, 'item_parent');
- $this->add_ifvalue($item, 'item_slot');
- $this->add_ifvalue($item, 'item_color');
- $this->add_ifvalue($item, 'item_id');
- $this->add_ifvalue($item, 'item_texture');
- $this->add_ifvalue($item, 'item_quantity');
- $this->add_ifvalue($item, 'item_tooltip');
- $this->add_ifvalue($item, 'item_level');
- $this->add_ifvalue($item, 'item_type');
- $this->add_ifvalue($item, 'item_subtype');
- $this->add_ifvalue($item, 'item_rarity');
- $this->add_value('locale', $locale);
- /*
- $level = array();
- if( isset($item_data['reqLevel']) && !is_null($item_data['reqLevel']) )
- {
- $this->add_value('level', $item_data['reqLevel']);
- }
- else if( preg_match($roster->locale->wordings[$locale]['requires_level'],$item['item_tooltip'],$level))
- {
- $this->add_value('level', $level[1]);
- }
- */
- $querystr = "INSERT INTO `" . $roster->db->table('items') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Item [' . $item['item_name'] . '] could not be inserted',$roster->db->error());
- }
- }
- /**
- * Inserts a gem into the database
- *
- * @param array $gem
- * @return bool | true on success, false if error
- */
- function insert_gem( $gem )
- {
- global $roster;
- $this->assigngem='';
- $this->add_gem('gem_id', $gem['gem_id']);
- $this->add_gem('gem_name', $gem['gem_name']);
- $this->add_gem('gem_color', $gem['gem_color']);
- $this->add_gem('gem_tooltip', $gem['gem_tooltip']);
- $this->add_gem('gem_bonus', $gem['gem_bonus']);
- $this->add_gem('gem_socketid', $gem['gem_socketid']);
- $this->add_gem('gem_texture', $gem['gem_texture']);
- $this->add_gem('locale', $this->locale);
- $querystr = "REPLACE INTO `" . $roster->db->table('gems') . "` SET ".$this->assigngem . ";";
- $result = $roster->db->query($querystr);
- if ( !$result )
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- /**
- * Inserts mail into the Database
- *
- * @param array $mail
- */
- function insert_mail( $mail )
- {
- global $roster;
- $this->reset_values();
- $this->add_ifvalue($mail, 'member_id');
- $this->add_ifvalue($mail, 'mail_slot', 'mailbox_slot');
- $this->add_ifvalue($mail, 'mail_icon', 'mailbox_icon');
- $this->add_ifvalue($mail, 'mail_coin', 'mailbox_coin');
- $this->add_ifvalue($mail, 'mail_coin_icon', 'mailbox_coin_icon');
- $this->add_ifvalue($mail, 'mail_days', 'mailbox_days');
- $this->add_ifvalue($mail, 'mail_sender', 'mailbox_sender');
- $this->add_ifvalue($mail, 'mail_subject', 'mailbox_subject');
- $querystr = "INSERT INTO `" . $roster->db->table('mailbox') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Mail [' . $mail['mail_subject'] . '] could not be inserted',$roster->db->error());
- }
- }
- /**
- * Inserts a recipe into the Database
- *
- * @param array $recipe
- * @param string $locale
- */
- function insert_recipe( $recipe , $locale )
- {
- global $roster;
- $this->reset_values();
- $this->add_ifvalue($recipe, 'member_id');
- $this->add_ifvalue($recipe, 'recipe_id');
- $this->add_ifvalue($recipe, 'item_id');
- $this->add_ifvalue($recipe, 'recipe_name');
- $this->add_ifvalue($recipe, 'recipe_type');
- $this->add_ifvalue($recipe, 'skill_name');
- $this->add_ifvalue($recipe, 'difficulty');
- $this->add_ifvalue($recipe, 'item_color');
- $this->add_ifvalue($recipe, 'reagent_list','reagents');
- $this->add_ifvalue($recipe, 'recipe_texture');
- $this->add_ifvalue($recipe, 'recipe_tooltip');
- $level = array();
- if( preg_match($roster->locale->wordings[$locale]['requires_level'],$recipe['recipe_tooltip'],$level))
- {
- $this->add_value('level',$level[1]);
- }
- $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'])."';";
- $resulta = $roster->db->query($querystra);
- $num = $roster->db->num_rows($resulta);
- if ($num <=0)
- {
- $querystr = "INSERT INTO `" . $roster->db->table('recipes') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Recipe [' . $recipe['recipe_name'] . '] could not be inserted',$roster->db->error());
- }
- }
- }
- /**
- * Formats quest data and inserts into the DB
- *
- * @param array $quest
- * @param int $member_id
- * @param string $zone
- * @param array $data
- */
- function insert_quest( $quest , $member_id , $zone , $slot , $data )
- {
- global $roster;
- // Fix quest name since many 'quest' addons cause the level number to be added to title
- while( substr($quest['Title'],0,1) == '[' )
- {
- $quest['Title'] = ltrim(substr($quest['Title'],strpos($quest['Title'],']')+1));
- }
- // Insert this quest into the quest data table, db normalization is great huh?
- $this->reset_values();
- $this->add_ifvalue($quest, 'QuestId', 'quest_id');
- $this->add_value('quest_name', $quest['Title']);
- $this->add_ifvalue($quest, 'Level', 'quest_level');
- $this->add_ifvalue($quest, 'Tag', 'quest_tag');
- $this->add_ifvalue($quest, 'Group', 'group');
- $this->add_ifvalue($quest, 'Daily', 'daily');
- $this->add_ifvalue($quest, 'RewardMoney', 'reward_money');
- if( isset($quest['Description']) )
- {
- $description = str_replace('\n',"\n",$quest['Description']);
- $description = str_replace($data['Class'],'<class>',$description);
- $description = str_replace($data['Name'],'<name>',$description);
- $this->add_value('description', $description);
- unset($description);
- }
- if( isset($quest['Objective']) )
- {
- $objective = str_replace('\n',"\n",$quest['Objective']);
- $objective = str_replace($data['Class'],'<class>',$objective);
- $objective = str_replace($data['Name'],'<name>',$objective);
- $this->add_value('objective', $objective);
- unset($objective);
- }
- $this->add_value('zone', $zone);
- $this->add_value('locale', $data['Locale']);
- $querystr = "REPLACE INTO `" . $roster->db->table('quest_data') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Quest Data [' . $quest['QuestId'] . ' : ' . $quest['Title'] . '] could not be inserted',$roster->db->error());
- }
- /*
- // Now process tasks
- NOT PROCESSING, BUT CODE AND TABLE LAYOUT IS HERE FOR LATER
- The reason is that the task number is in the name
- and this is not good for a normalized table
- # --------------------------------------------------------
- ### Quest Tasks
- DROP TABLE IF EXISTS `renprefix_quest_task_data`;
- CREATE TABLE `renprefix_quest_task_data` (
- `quest_id` int(11) NOT NULL default '0',
- `task_id` int(11) NOT NULL default '0',
- `note` varchar(128) NOT NULL default '',
- `type` varchar(32) NOT NULL default '',
- `locale` varchar(4) NOT NULL default '',
- PRIMARY KEY (`quest_id`,`task_id`,`locale`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- if( isset($quest['Tasks']) && !empty($quest['Tasks']) && is_array($quest['Tasks']) )
- {
- $tasks = $quest['Tasks'];
- foreach( array_keys($tasks) as $task )
- {
- $taskInfo = $tasks[$task];
- $this->reset_values();
- $this->add_ifvalue($quest, 'QuestId', 'quest_id');
- $this->add_value('task_id', $task);
- if( isset($taskInfo['Note']) )
- {
- $note = explode(':',$taskInfo['Note']);
- $this->add_value('note', $note[0]);
- unset($note);
- }
- $this->add_ifvalue($taskInfo, 'Type', 'type');
- $this->add_value('locale', $data['Locale']);
- $querystr = "REPLACE INTO `" . $roster->db->table('quest_task_data') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Quest Task [' . $taskInfo['Note'] . '] for Quest Data [' . $quest['QuestId'] . ' : ' . $quest['Title'] . '] could not be inserted',$roster->db->error());
- }
- }
- }
- */
- // Insert this quest id for the character
- $this->reset_values();
- $this->add_value('member_id', $member_id);
- $this->add_ifvalue($quest, 'QuestId', 'quest_id');
- $this->add_value('quest_index', $slot);
- $this->add_ifvalue($quest, 'Difficulty', 'difficulty');
- $this->add_ifvalue($quest, 'Complete', 'is_complete');
- $querystr = "INSERT INTO `" . $roster->db->table('quests') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Quest [' . $quest['Title'] . '] could not be inserted',$roster->db->error());
- }
- }
- /**
- * Formats mail data to be inserted to the db
- *
- * @param array $mail_data
- * @param int $memberId
- * @param string $slot_num
- * @return array
- */
- function make_mail( $mail_data , $memberId , $slot_num )
- {
- $mail = array();
- $mail['member_id'] = $memberId;
- $mail['mail_slot'] = $slot_num;
- $mail['mail_icon'] = $this->fix_icon($mail_data['MailIcon']);
- $mail['mail_coin'] = ( isset($mail_data['Coin']) ? $mail_data['Coin'] : 0 );
- $mail['mail_coin_icon'] = ( isset($mail_data['CoinIcon']) ? $this->fix_icon($mail_data['CoinIcon']) : '' );
- $mail['mail_days'] = $mail_data['Days'];
- $mail['mail_sender'] = $mail_data['Sender'];
- $mail['mail_subject'] = $mail_data['Subject'];
- return $mail;
- }
- /**
- * Formats item data to be inserted into the db
- *
- * @param array $item_data
- * @param int $memberId
- * @param string $parent
- * @param string $slot_name
- * @return array
- */
- function make_item( $item_data , $memberId , $parent , $slot_name )
- {
- $item = array();
- $item['member_id'] = $memberId;
- $item['item_name'] = $item_data['Name'];
- $item['item_parent'] = $parent;
- $item['item_slot'] = $slot_name;
- $item['item_color'] = ( isset($item_data['Color']) ? $item_data['Color'] : 'ffffff' );
- $item['item_id'] = ( isset($item_data['Item']) ? $item_data['Item'] : '0:0:0:0:0:0:0:0' );
- $item['item_texture'] = ( isset($item_data['Icon']) ? $this->fix_icon($item_data['Icon']) : 'inv_misc_questionmark' );
- $item['item_quantity'] = ( isset($item_data['Quantity']) ? $item_data['Quantity'] : 1 );
- $item['level'] = ( isset($item_data['reqLevel']) ? $item_data['reqLevel'] : null );
- $item['item_level'] = ( isset($item_data['iLevel']) ? $item_data['iLevel'] : '' );
- $item['item_type'] = ( isset($item_data['Type']) ? $item_data['Type'] : '' );
- $item['item_subtype'] = ( isset($item_data['SubType']) ? $item_data['SubType'] : '' );
- $item['item_rarity'] = ( isset($item_data['Rarity']) ? $item_data['Rarity'] : '' );
- if( !empty($item_data['Tooltip']) )
- {
- $item['item_tooltip'] = $this->tooltip($item_data['Tooltip']);
- }
- else
- {
- $item['item_tooltip'] = $item_data['Name'];
- }
- if( !empty($item_data['Gem']))
- {
- $this->do_gems($item_data['Gem'], $item_data['Item']);
- }
- return $item;
- }
- /**
- * Formats gem data to be inserted into the database
- *
- * @param array $gem_data
- * @param int $socket_id
- * @return array $gem if successful else returns false
- */
- function make_gem( $gem_data , $socket_id )
- {
- global $roster;
- $gemtt = explode( '<br>', $gem_data['Tooltip'] );
- if( $gemtt[0] !== '' )
- {
- foreach( $gemtt as $line )
- {
- $colors = array();
- $line = preg_replace('/\|c[a-f0-9]{8}(.+?)\|r/i','$1',$line); // CP error? strip out color
- // -- start the parsing
- 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) )
- {
- continue;
- }
- 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.
- {
- $gem_bonus = $line;
- }
- elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_meta'], $line) )
- {
- $gem_color = 'meta';
- }
- elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_multicolor'], $line, $colors) )
- {
- 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'] )
- {
- $gem_color = 'purple';
- }
- 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'] )
- {
- $gem_color = 'orange';
- }
- 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'] )
- {
- $gem_color = 'green';
- }
- }
- elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_singlecolor'], $line, $colors) )
- {
- $tmp = array_flip($roster->locale->wordings[$this->locale]['gem_colors']);
- $gem_color = $tmp[$colors[1]];
- }
- elseif( preg_match($roster->locale->wordings[$this->locale]['gem_preg_prismatic'], $line) )
- {
- $gem_color = 'prismatic';
- }
- }
- //get gemid and remove the junk
- list($gemid) = explode(':', $gem_data['Item']);
- $gem = array();
- $gem['gem_name'] = $gem_data['Name'];
- $gem['gem_tooltip'] = $this->tooltip($gem_data['Tooltip']);
- $gem['gem_bonus'] = $gem_bonus;
- $gem['gem_socketid']= $gem_data['gemID'];//$socket_id; // the ID the gem holds when socketed in an item.
- $gem['gem_id'] = $gemid; // the ID of gem when not socketed.
- $gem['gem_texture'] = $this->fix_icon($gem_data['Icon']);
- $gem['gem_color'] = $gem_color; //meta, prismatic, red, blue, yellow, purple, green, orange.
- return $gem;
- }
- else
- {
- return false;
- }
- }
- /**
- * Formats recipe data to be inserted into the db
- *
- * @param array $recipe_data
- * @param int $memberId
- * @param string $parent
- * @param string $recipe_type
- * @param string $recipe_name
- * @return array
- */
- function make_recipe( $recipe_data , $memberId , $parent , $recipe_type , $recipe_name )
- {
- $recipe = array();
- $recipe['member_id'] = $memberId;
- $recipe['recipe_name'] = $recipe_name;
- $recipe['recipe_type'] = $recipe_type;
- $recipe['skill_name'] = $parent;
- // Fix Difficulty since it's now a string field
- if( !is_numeric($recipe_data['Difficulty']) )
- {
- switch($recipe_data['Difficulty'])
- {
- case 'difficult':
- $recipe['difficulty'] = 5;
- break;
- case 'optimal':
- $recipe['difficulty'] = 4;
- break;
- case 'medium':
- $recipe['difficulty'] = 3;
- break;
- case 'easy':
- $recipe['difficulty'] = 2;
- break;
- case 'trivial':
- default:
- $recipe['difficulty'] = 1;
- break;
- }
- }
- else
- {
- $recipe['difficulty'] = $recipe_data['Difficulty'];
- }
- $recipe['item_color'] = isset($recipe_data['Color']) ? $recipe_data['Color'] : '';
- $recipe['item_id'] = isset($recipe_data['Item']) ? $recipe_data['Item'] : '';
- $recipe['recipe_id'] = isset($recipe_data['RecipeID']) ? $recipe_data['RecipeID'] : '';
- $recipe['reagent_data'] = $recipe_data['Reagents'];
- $recipe['reagent_list'] = array();
- foreach( $recipe_data['Reagents'] as $d => $reagent )
- {
- //aprint($reagent);
- $id = explode(':', $reagent['Item']);
- if(isset($reagent['Quantity']))
- {
- $count = $reagent['Quantity'];
- }
- elseif (isset($reagent['Count']))
- {
- $count = $reagent['Count'];
- }
- else
- {
- $count = '1';
- }
- $recipe['reagent_list'][] = $id[0] . ':' . $count;
- }
- $recipe['reagent_list'] = implode('|',$recipe['reagent_list']);
- $recipe['recipe_texture'] = $this->fix_icon($recipe_data['Icon']);
- if( !empty($recipe_data['Tooltip']) )
- {
- $recipe['recipe_tooltip'] = $this->tooltip( $recipe_data['Tooltip'] );
- }
- else
- {
- $recipe['recipe_tooltip'] = $recipe_name;
- }
- return $recipe;
- }
- /**
- * Handles formating and insertion of buff data
- *
- * @param array $data
- * @param int $memberId
- */
- function do_buffs( $data , $memberId )
- {
- global $roster;
- // Delete the stale data
- $querystr = "DELETE FROM `" . $roster->db->table('buffs') . "` WHERE `member_id` = '$memberId';";
- if( !$roster->db->query($querystr) )
- {
- $this->setError('Buffs could not be deleted',$roster->db->error());
- return;
- }
- if( isset($data['Attributes']['Buffs']) )
- {
- $buffs = $data['Attributes']['Buffs'];
- }
- if( !empty($buffs) && is_array($buffs) )
- {
- // Then process buffs
- $buffsnum = 0;
- foreach( $buffs as $buff )
- {
- if( is_null($buff) || !is_array($buff) || empty($buff) )
- {
- continue;
- }
- $this->reset_values();
- $this->add_value('member_id', $memberId);
- $this->add_ifvalue($buff, 'Name', 'name');
- if( isset($buff['Icon']) )
- {
- $this->add_value('icon', $this->fix_icon($buff['Icon']));
- }
- $this->add_ifvalue($buff, 'Rank', 'rank');
- $this->add_ifvalue($buff, 'Count', 'count');
- if( !empty($buff['Tooltip']) )
- {
- $this->add_value('tooltip', $this->tooltip($buff['Tooltip']));
- }
- else
- {
- $this->add_ifvalue($buff, 'Name', 'tooltip');
- }
- $querystr = "INSERT INTO `" . $roster->db->table('buffs') . "` SET " . $this->assignstr . ";";
- $result = $roster->db->query($querystr);
- if( !$result )
- {
- $this->setError('Buff [' . $buff['Name'] . '] could not be inserted',$roster->db->error());
- }
- $buffsnum++;
- }
- $this->setMessage('<li>Updating Buffs: ' . $buffsnum . '</li>');
- }
- else
- {
- $this->setMessage('<li>No Buffs</li>');
- }
- }
- /**
- * Handles formating and ins…
Large files files are truncated, but you can click here to view the full file