FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » sync up group members with wow roster [Works with armory as of Feb 04, 2009]
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
sync up group members with wow roster [Works with armory as of Feb 04, 2009] [message #158144] Thu, 05 February 2009 00:13
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
add to buddy list
ignore all messages by this user
Please note this may be outdated at any moment as blizzard often makes changes to the xml content of the armory.

So basically, this works just like my wow roster version of the tool in that it synchronizes group members with the official wow armory for a specified group. This group is defined in fudforum to provide guild membership with access to members-only content.

This version is written to be run manually by an admin from a link within the admin control panel. Somewhere in admpanel.php:
<a href="armorysync.php?<?php echo __adm_rsid; ?>">Synchronize Members to Armory</a><br />
You may also use cron to execute this tool on a regular basis. I prefer not doing this, but if you do, don't set it to a ridiculous interval. Daily should be fine if you have a lot of recruitment activity, if you have a high turn-around, or if your members often change their game names. If you are really paranoid, maybe 4 times a day would be okay. Just don't hammer the armory site with automated queries and the world... of warcraft... won't hate you.

In order to use cron, you must uncomment the cron define at the top of the source. Then add the script to your crontab using wget or curl, redirecting output to null. See crontab(1) and crontab(5) or consult your web host documentation for automated tasks.

Grab the code below and save it, naming it whatever you want, e.g. armorysync.php. Place it in your forum's public adm directory, e.g. public_html/forums/adm/ unless you are using cron, in which case, you should place the file in your forum's public directories where there exists a GLOBALS.php.

For cron use, I highly recommend making use of htaccess to prevent a DoS between the web host and the armory, e.g., someone decides to hammer the script. You should create sub directory in somewhere in your forums public root, e.g. public_html/forums/adm/cron/, create a symbolic link to GLOBALS.php, e.g., ln -s ../GLOBALS.php GLOBALS.php, then use htaccess to limit access to localhost and to your ip address for testing, e.g., create and edit the .htaccess file and add the following:
allow from localhost
allow from 127.0.0.1
allow from what.is.my.ip
deny from all
Use http://www.whatismyip.com/ to get your correct IP address. Use your web browser to test the script and then remove your IP address from .htaccess.

If you wish to use both methods, then use two copies of the file and follow the appropriate instructions for each copy.

In this version you will find several defines at the top of the source; change them to your liking.

The first two, realm and guild, are obvious. When working with names strangely formatted and those with spaces, the best thing to do is grab the URL after you search and click on your guild in the armory. Copy the part between the '=' and the '&' for each part. For example: guild-info.xml?r=Blackwater+Raiders&n=Elitist+Jerks&p=1. Take the Blackwater+Raiders and the Elitist+Jerks and place them in the defines exactly as they are.

The default options are 378639. The quick way to find out which options you need is to select a user, set the options you want, and then grab the resulting number from the database. I assume you can do this since you are even bothering to use this tool. You may also calculate the permissions and add 65536 to them, search these forums for instructions on calculating permissions.

The default group is 1. You can see the number of the group by looking at the 'edit' url next to the group in question in the admin land group editor. Any existing member of the group will be overridden with the new options as defined above, excluding anyone with higher level access.

As soon as I am done writing it, this version will support removal of group members who are not listed in the armory guild profile. This includes people who have changed their game names. They must request that their forum names be changed to match their new game names or they lose access.

This version also supports UTF-8 names, e.g., Rênê. The forum account name must be created using the alt+keypad method, e.g., in Rênê, ALT+0234 is used twice.

The code without member removal support:
<?php

define('realm', 'Aggramar');
define('guild', 'Fae+Victus');
define('options', 378639);
define('group', 97);
//define('cron', 1);

/*****************************************************************/
/* Do not change anything below this line unless you are s-m-r-t */
/*****************************************************************/

define('xmlpath', '/page/guildInfo/guild/members/character');
$URL = 'http://www.wowarmory.com/guild-info.xml?r='.realm.'&n='.guild.'&p=1';

set_time_limit(600);
define('forum_debug', 1);
if (defined('cron')) unset($_SERVER['REMOTE_ADDR']);

require('./GLOBALS.php');
if (!defined('cron')) {
    fud_use('adm.inc', true);
    fud_use('glob.inc', true);
}

if (!($FUD_OPT_1 & 1))
    exit("Forum is currently disabled.\n");

fud_use('forum_adm.inc', true);
fud_use('groups_adm.inc', true);
fud_use('err.inc');
fud_use('db.inc');
fud_use('post_proc.inc');
fud_use('is_perms.inc');
fud_use('users.inc');
fud_use('groups.inc');
fud_use('users_reg.inc');
fud_use('users_adm.inc', true);
fud_use('scripts_common.inc', true);

if (!defined('cron')) {
    require($WWW_ROOT_DISK . 'adm/admpanel.php');
?>
<h2>Synchronize Members to Armory</h2>
<div class="alert">
Please only use this once when new members are added to the guild. Spamming it
could result in tripping spam filters at the armory which could render this
application useless.
</div>
<p><?php
} /* end if defined cron */

define('sql_p', $GLOBALS['DBHOST_TBL_PREFIX']);

list($GLOBALS['usr']->lang, $locale) = db_saq("SELECT lang, locale FROM ".sql_p."themes WHERE theme_opt=1|2 LIMIT 1");

$GLOBALS['good_locale'] = setlocale(LC_ALL, $locale);


define('agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008121622 Firefox/3.0.5');
$armory = curl_init();
curl_setopt($armory, CURLOPT_USERAGENT, agent);
curl_setopt($armory, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($armory, CURLOPT_URL, $URL);
$xml = curl_exec($armory);
curl_close($armory);

$parsed = simplexml_load_string($xml);

function getinfo($member) {
    $info = array();
    foreach($member->attributes() as $key => $value) {
        $info[$key] = (string)$value;
    }
    return $info;
}

function xmlEntities($s){
    /*build first an assoc. array with the entities we want to match*/
    $table1 = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);

    /*now build another assoc. array with the entities we want to replace (numeric entities)*/
    foreach ($table1 as $k=>$v){
        $table1[$k] = "/$v/";
        $c = htmlentities($k,ENT_QUOTES,"UTF-8");
        $table2[$c] = "&#".ord($k).";";
    }

    $s = preg_replace($table1,$table2,$s);
    return $s;
}

$members = $parsed->xpath(xmlpath);
foreach($members as $member) {
    $info = getinfo($member);
    $login = xmlEntities(htmlentities(utf8_decode($info['name'])));
    $id = get_id_by_login($login);
    if ( ! empty ( $id ) ) {
        print ( $login . ' - ' . $id . ': ' );
        $r = q('SELECT id,group_members_opt,group_id FROM fud26_group_members WHERE group_id='.group.' AND user_id='.$id);
        $e = db_rowarr($r);
        if ( ! empty ( $e ) ) {
            print_r ( $e );
            print ( ' ' );
            if ( $e[1] < options ) {
                grp_delete_member('.group.', $id);
                q('INSERT INTO fud26_group_members (group_members_opt, user_id, group_id) VALUES ('.options.', '.$id.', '.group.')'); /* 313103 + 65536 */
                grp_rebuild_cache(array($id));
                print ( "Updating Member!<br>\n" );
            } else {
                print ( "Skipping Member!<br>\n" );
            }
        } else {
            q('INSERT INTO fud26_group_members (group_members_opt, user_id, group_id) VALUES ('.options.', '.$id.', '.group.')'); /* 313103 + 65536 */
            grp_rebuild_cache(array($id));
            print ( "Adding Member!<br>\n" );
        }
    }
}

//} /* end if $is_a */
?>
<?php
if (!defined('cron')) {
?></p><?php
    require($WWW_ROOT_DISK . 'adm/admclose.html');
}
?>

[Updated on: Thu, 05 February 2009 02:32]

Report message to a moderator

Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: sync up group members with wow roster [Works with 1.7.x]
Next Topic: select all and deselect all in thread view [For 2.7.7]
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Oct 23 07:52:14 EDT 2017

Total time taken to generate the page: 0.00680 seconds