<?php

class TwitterFollowers {
    private 
$xml "";
    private 
$maxFollowersCount 0;
    private 
$originalFollowers 0;
    private 
$toRemove = array();
    
    function 
TwitterFollowers($file$maxFollowersCount) {
        
$this->loadXml($file);
        
$this->maxFollowersCount $maxFollowersCount;
        
$this->originalFollowers $this->followerCount();
    }
    
    function 
loadXml($file) {
        
$this->xml simplexml_load_file($file);
    }
    
    function 
updateFollowerList() {
        
$this->checkFollowers();
        
$this->removeFollowers();
    }
    
    function 
checkFollowers() {
        foreach (
$this->xml->user as $user) {
            if (
$user->followers_count $this->maxFollowersCount) {
                
array_push($this->toRemove$user);
            }
        }
    }
    
    function 
removeFollowers() {
        foreach (
$this->toRemove as $user) {
            
$oNode dom_import_simplexml($user);
            
$oNode->parentNode->removeChild($oNode);
        }
    }
    
    function 
followerCount() {
        return 
count($this->xml->user);
    }

    function 
addChanges() {
        
$this->xml->addChild('changes');
        
$this->xml->changes->addAttribute('before'$this->originalFollowers);
        
$this->xml->changes->addAttribute('after'$this->followerCount());
    }
    
    function 
saveFollowerList($file) {
        
$this->xml->asXML($file);
    }
}

$friendList = new TwitterFollowers("http://twitter.com/statuses/friends.xml?screen_name=dremex"2000);
$friendList->updateFollowerList();
$friendList->addChanges();
$friendList->saveFollowerList("updatedFollowers.xml");

?>