Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Working

By: a guest on Jan 4th, 2012  |  syntax: PHP  |  size: 3.50 KB  |  views: 119  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. //Added this function to emulate the one native in PHP 5.3
  3. function get_called_class ()
  4. {
  5.     $t = debug_backtrace(); $t = $t[0];
  6.     if ( isset( $t['object'] ) && $t['object'] instanceof $t['class'] )
  7.         return get_class( $t['object'] );
  8.     return false;
  9. }
  10.  
  11. abstract class A_UserExporter{
  12.     protected $users;
  13.     protected $filename;
  14.    
  15.     protected $cols = array();
  16.     protected $descriptions = array();
  17.    
  18.    
  19.     public abstract static function getFileExtension();
  20.    
  21.     public abstract static function getFileExtensionDescription();
  22.    
  23.     protected abstract function printHeader();
  24.    
  25.     protected abstract function printFooter();
  26.    
  27.     protected abstract function printUser($user);
  28.    
  29.     public function __construct(array $users, $filename = ''){
  30.         $_cols = array();
  31.         $wpue_config = wpue_getConfig();
  32.         if(isset($_POST['userdata']))
  33.             foreach ($_POST['userdata'] as $col){
  34.                 $_cols[] = $col;
  35.                 $this->descriptions[$col] = $wpue_config->userdata[$col];
  36.             }
  37.            
  38.         if(isset($_POST['metadata']))
  39.             foreach ($_POST['metadata'] as $col){
  40.                 $_cols[] = $col;
  41.                 $this->descriptions[$col] = $wpue_config->metadata[$col];
  42.             }
  43.            
  44.         if(wpue_isBP()){
  45.                 $bp_fields = wpue_bp_getProfileFields();
  46.                 foreach ($wpue_config->bp_fields as $field_id)
  47.                         if(isset($_POST['bp_fields']) && in_array($field_id, $_POST['bp_fields'])){
  48.                                 $col = 'bp_'.$field_id;
  49.                                 $_cols[] = $col;
  50.                                 $this->descriptions[$col] = $bp_fields[$field_id]->name;
  51.                         }
  52.                                
  53.         }
  54.            
  55.         $this->users = $users;
  56.         $this->filename = $filename ? $filename : 'users-'.date('Y-m-d');
  57.        
  58.         foreach($_POST['display_order'] as $field)
  59.             if(in_array($field, $_cols))
  60.                 $this->cols[] = $field;
  61.     }
  62.    
  63.     public final function export(){
  64.         $this->printHeader();
  65.         $keys = array_keys($this->users);
  66.          
  67.         foreach ($keys as $user_id){
  68.             $user = $this->users[$user_id];
  69.             $this->printUser($user);
  70.             unset($this->users[$user_id]);
  71.         }
  72.         $this->printFooter();
  73.        
  74.         die;
  75.     }
  76.    
  77.    
  78.     public final static function activate(){
  79.         $class = get_called_class();
  80.         eval('$default = '.$class.'::getDefaultOptions();');
  81.         $option = $class.'-options';
  82.         if($default){
  83.             if(get_option($option))
  84.                 delete_option($option);
  85.                
  86.             add_option($option, $default);
  87.         }
  88.     }
  89.    
  90.     public static function deactivate(){
  91.         $option = get_called_class().'-options';
  92.         if(get_option($option))
  93.             delete_option($option);
  94.     }
  95.  
  96.     //Then rewrite this to revent parse error in PHP < 5.3
  97.     public static function saveOptions(){
  98.        $class = get_called_class();
  99.        $str = '$class::getPostedOptions()';
  100.        eval("\$options = \"$str\";");
  101.        $option = $class.'-options';
  102.        if($options)
  103.            update_option($option, $options);
  104.     }
  105.    
  106.     public static function getOptions(){
  107.         $option = get_called_class().'-options';
  108.         return get_option($option);
  109.     }
  110.    
  111.     public static function printOptionsForm(){}
  112.     public static function getPostedOptions(){return null;}
  113.     public static function getDefaultOptions(){return null;}
  114. }