Created
May 20, 2014 13:04
-
-
Save bitbrain/4f2421e922ae76b70eef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Script which generates valid JSON for the website in order to display all current members | |
* | |
* @author Miguel Gonzalez <[email protected]> | |
* @since 1.0 | |
* @version 1.0 | |
*/ | |
// Connect to phpBB | |
define('IN_PHPBB', true); | |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; | |
$phpEx = substr(strrchr(__FILE__, '.'), 1); | |
include($phpbb_root_path . 'common.' . $phpEx); | |
include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); | |
// Fetch the data | |
$sql = 'select * from `phpbb_raid_groups` order by `order`'; | |
$result = $db->sql_query($sql); | |
$row = $db->sql_fetchrow($result); | |
$data = array(); | |
$data['groups'] = array(); | |
function grab_custom_field($db, $id, $user_fields, $name) { | |
if ($user_fields != null) { | |
$fields = $user_fields[$id][$name]; | |
$value = $fields['value'] - 1; | |
$customData = $fields['data']; | |
$query = 'select * from `phpbb_profile_fields_lang` where field_id=' . $customData['field_id'] . ' and lang_id=' . $customData['lang_id'] . ' and option_id=' . $value . ' and field_type=' . $customData['field_type']; | |
$res = $db->sql_fetchrow($db->sql_query($query)); | |
//if ($name == 'path') { | |
//return $query; | |
//} else { | |
return $res['lang_value']; | |
//} | |
} else { | |
if ($name == 'class') { | |
return 'warrior'; | |
} else if ($name == 'spec') { | |
return 'dd'; | |
} else if ($name == 'path') { | |
return 'settler'; | |
} else { | |
return 'chua'; | |
} | |
} | |
} | |
// Build json | |
while ($row != null) { | |
$row['members'] = array(); | |
$memberSQL = 'select * from phpbb_users u | |
join phpbb_raid_users ru on u.user_id = ru.user_id | |
join phpbb_raid_groups rg on rg.id = ru.group_id | |
where ru.group_id = ' . $row['id'] . ' order by u.username ASC'; | |
$memberResult = $db->sql_query($memberSQL); | |
$memberData = array(); | |
while (($memberRow = $db->sql_fetchrow($memberResult)) != null) { | |
// Get custom fields | |
$cp = new custom_profile(); | |
$user_fields = $cp->generate_profile_fields_template('grab', $memberRow['user_id']); | |
$member = array(); | |
$member['name'] = $memberRow['username']; | |
$member['class'] = grab_custom_field($db, $memberRow['user_id'], $user_fields, 'class'); | |
$member['spec'] = grab_custom_field($db, $memberRow['user_id'], $user_fields, 'spec'); | |
$member['path'] = grab_custom_field($db, $memberRow['user_id'], $user_fields, 'path'); | |
$member['race'] = grab_custom_field($db, $memberRow['user_id'], $user_fields, 'race'); | |
$member['color'] = $memberRow['user_colour']; | |
array_push($memberData, $member); | |
} | |
unset($row['id']); | |
$row['members'] = $memberData; | |
array_push($data['groups'], $row); | |
$row = $db->sql_fetchrow($result); | |
} | |
// Show the content | |
header('Content-type: application/json'); | |
echo json_encode($data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment