Plugin Directory

Changeset 2643129


Ignore:
Timestamp:
12/12/2021 10:31:26 PM (4 years ago)
Author:
qlstudio
Message:

Update to version 2.2.1 from GitHub

Location:
export-user-data
Files:
14 added
6 deleted
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • export-user-data/tags/2.2.1/CHANGELOG.md

    r2372271 r2643129  
    11## Changelog ##
     2
     3*** 2.2.1 ***
     4
     5* New: cleanup export methods, improvied sanitization
     6* New: array and object data is now passed in JSON_ENCODED string object
     7
     8*** 2.2.0 ***
     9
     10* New: Move to cleaner OOP pattern and PHP version bump to 7.0
     11* Update: Tested on WP 5.6
    212
    313*** 2.1.3 ***
    414
    5 * FIX - wrong name for our own plugin :( thanks @kgagne !
     15* FIX: wrong name for our own plugin :( thanks @kgagne !
    616
    717*** 2.1.2 ***
  • export-user-data/tags/2.2.1/export-user-data.php

    r2372271 r2643129  
    11<?php
    22
    3 /*
     3/**
     4 * Export User Data
     5 *
     6 * @package         Export User Data
     7 * @author          Q Studio <[email protected]>
     8 * @license         GPL-2.0+
     9 * @copyright       2020 Q Studio
     10 *
     11 * @wordpress-plugin
    412 * Plugin Name:     Export User Data
     13 * Plugin URI:      http://qstudio.us/releases/export-user-data
    514 * Description:     Export User data and metadata.
    6  * Version:         2.1.3
     15 * Version:         2.2.1
    716 * Author:          Q Studio
    8  * Author URI:      http://qstudio.us/
    9  * License:         GPL2
    10  * Class:           q_export_user_data
    11  * Text Domain:     q-export-user-data
     17 * Author URI:      https://qstudio.us
     18 * License:         GPL-2.0+
     19 * Requires PHP:    7.0
     20 * Copyright:       Q Studio
     21 * Namespace:       q\eud
     22 * API:             export_user_data
     23 * Text Domain:     export-user-data
     24 * Domain Path:     /languages
    1225 * GitHub Plugin URI: qstudio/export-user-data
    1326*/
    1427
    15 defined( 'ABSPATH' ) OR exit;
     28// namespace plugin ##
     29namespace q\eud;
    1630
    17 if ( ! class_exists( 'q_export_user_data' ) ) {
    18    
    19     // instatiate plugin via WP plugins_loaded - init is too late for CPT ##
    20     add_action( 'init', array ( 'q_export_user_data', 'get_instance' ), 1000000 );
    21    
    22     class q_export_user_data {
    23                
    24         // Refers to a single instance of this class. ##
    25         private static $instance = null;
    26                        
    27         // Plugin Settings
    28         const version = '2.1.3';
    29         static $debug = false;
    30         const text_domain = 'q-export-user-data'; // for translation ##
    31        
    32         /* properties */
    33         public static $q_eud_exports = ''; // export settings ##
    34         public static $usermeta_saved_fields = array();
    35         public static $bp_fields_saved_fields = array();
    36         public static $bp_fields_update_time_saved_fields = array();
    37         public static $role = '';
    38         public static $roles = '0';
    39         public static $user_fields = '1';
    40         public static $groups = '0';
    41         public static $start_date = '';
    42         public static $end_date = '';
    43         public static $limit_offset = '';
    44         public static $limit_total = '';
    45         public static $updated_since_date = '';
    46         public static $field_updated_since = '';
    47         public static $format = '';
    48         public static $bp_data_available = false;
    49         public static $allowed_tags = '';
     31// import ##
     32use q\eud;
     33use q\eud\core\helper as h;
    5034
    51         // api ##
    52         public static $api_admin_fields = false;
     35// If this file is called directly, Bulk!
     36if ( ! defined( 'ABSPATH' ) ) {
     37    return;
     38}
    5339
    54         /**
    55          * Creates or returns an instance of this class.
    56          *
    57          * @return  Foo     A single instance of this class.
    58          */
    59         public static function get_instance()
    60         {
     40// plugin activation hook to store current application and plugin state ##
     41\register_activation_hook( __FILE__, [ '\\q\\eud\\plugin', 'activation_hook' ] );
    6142
    62             if ( null == self::$instance ) {
    63                 self::$instance = new self;
    64             }
     43// plugin deactivation hook - clear stored data ##
     44\register_deactivation_hook( __FILE__, [ '\\q\\eud\\plugin', 'deactivation_hook' ] );
    6545
    66             return self::$instance;
     46// required bits to get set-up ##
     47require_once __DIR__ . '/library/api/function.php';
     48require_once __DIR__ . '/autoload.php';
     49require_once __DIR__ . '/plugin.php';
     50require_once __DIR__ . '/vendor/PHP_XLSXWriter/xlsxwriter.class.php';
    6751
    68         }
    69        
    70        
    71         /**
    72          * Instatiate Class
    73          *
    74          * @since       0.2
    75          * @return      void
    76          */
    77         private function __construct()
    78         {
    79            
    80             // activation ##
    81             register_activation_hook( __FILE__, array ( $this, 'register_activation_hook' ) );
     52// get plugin instance ##
     53$plugin = plugin::get_instance();
    8254
    83             // deactvation ##
    84             register_deactivation_hook( __FILE__, array ( $this, 'register_deactivation_hook' ) );
     55// validate instance ##
     56if( ! ( $plugin instanceof \q\eud\plugin ) ) {
    8557
    86             // set text domain ##
    87             add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
    88            
    89             // load libraries ##
    90             self::load_libraries();
     58    error_log( 'Error in Export User Data plugin instance' );
    9159
    92         }
    93 
    94 
    95         // the form for sites have to be 1-column-layout
    96         public function register_activation_hook() {
    97 
    98             \add_option( 'q_eud_configured' );
    99 
    100             // flush rewrites ##
    101             #global $wp_rewrite;
    102             #$wp_rewrite->flush_rules();
    103 
    104         }
    105 
    106 
    107         public function register_deactivation_hook() {
    108 
    109             \delete_option( 'q_eud_configured' );
    110 
    111         }
    112 
    113 
    114        
    115         /**
    116          * Load Text Domain for translations
    117          *
    118          * @since       1.7.0
    119          *
    120          */
    121         public function load_plugin_textdomain()
    122         {
    123            
    124             // set text-domain ##
    125             $domain = self::text_domain;
    126            
    127             // The "plugin_locale" filter is also used in load_plugin_textdomain()
    128             $locale = apply_filters('plugin_locale', get_locale(), $domain);
    129 
    130             // try from global WP location first ##
    131             load_textdomain( $domain, WP_LANG_DIR.'/plugins/'.$domain.'-'.$locale.'.mo' );
    132            
    133             // try from plugin last ##
    134             load_plugin_textdomain( $domain, FALSE, plugin_dir_path( __FILE__ ).'library/languages/' );
    135            
    136         }
    137        
    138        
    139        
    140         /**
    141          * Get Plugin URL
    142          *
    143          * @since       0.1
    144          * @param       string      $path   Path to plugin directory
    145          * @return      string      Absoulte URL to plugin directory
    146          */
    147         public static function get_plugin_url( $path = '' )
    148         {
    149 
    150             return plugins_url( $path, __FILE__ );
    151 
    152         }
    153        
    154        
    155         /**
    156          * Get Plugin Path
    157          *
    158          * @since       0.1
    159          * @param       string      $path   Path to plugin directory
    160          * @return      string      Absoulte URL to plugin directory
    161          */
    162         public static function get_plugin_path( $path = '' )
    163         {
    164 
    165             return plugin_dir_path( __FILE__ ).$path;
    166 
    167         }
    168        
    169 
    170         /**
    171         * Load Libraries
    172         *
    173         * @since        2.0
    174         */
    175         private static function load_libraries()
    176         {
    177 
    178             // vendor ##
    179             require_once self::get_plugin_path( 'vendor/PHP_XLSXWriter/xlsxwriter.class.php' );
    180 
    181             // methods ##
    182             require_once self::get_plugin_path( 'library/core/helper.php' );
    183             require_once self::get_plugin_path( 'library/core/core.php' );
    184             require_once self::get_plugin_path( 'library/core/user.php' );
    185             require_once self::get_plugin_path( 'library/core/buddypress.php' );
    186             // require_once self::get_plugin_path( 'library/core/excel2003.php' );
    187             require_once self::get_plugin_path( 'library/core/export.php' );
    188             require_once self::get_plugin_path( 'library/core/filters.php' );
    189 
    190             // api ##
    191             require_once self::get_plugin_path( 'library/api/admin.php' );
    192 
    193             // backend ##
    194             require_once self::get_plugin_path( 'library/admin/admin.php' );
    195            
    196         }
    197 
    198     }
     60    // nothing else to do here ##
     61    return;
    19962
    20063}
     64
     65// fire hooks - build log, helper and config objects and translations ##
     66\add_action( 'init', function() use( $plugin ){
     67
     68    // set text domain on init hook ##
     69    \add_action( 'init', [ $plugin, 'load_plugin_textdomain' ], 1 );
     70   
     71    // check debug settings ##
     72    \add_action( 'plugins_loaded', [ $plugin, 'debug' ], 11 );
     73
     74}, 0 );
     75
     76// build export object ##
     77$export = new eud\core\export( $plugin );
     78
     79// build filters object ##
     80$filters = new eud\core\filters( $plugin );
     81
     82// build user object ##
     83$user = new eud\core\user( $plugin );
     84
     85// build admin object ##
     86$admin = new eud\admin\render( $plugin, $user );
     87
     88// build buddypress object ##
     89// $buddypress = new eud\core\buddypress();
     90
     91if ( \is_admin() ){
     92
     93    // run export ##
     94    \add_action( 'admin_init', [ $export, 'render' ], 1000003 );
     95
     96    // load BP ##
     97    // \add_action( 'admin_init', [ $buddypress, 'load' ], 1000001 );
     98
     99    // EUD - filter key shown ##
     100    \add_filter( 'q/eud/admin/display_key', [ $filters, 'display_key' ], 1, 1 );
     101
     102    // user option ##
     103    \add_action( 'admin_init', [ $user, 'load' ], 1000002 );
     104
     105    // add export menu inside admin ##
     106    \add_action( 'admin_menu', [ $admin, 'add_menu' ] );
     107
     108    // UI style and functionality ##
     109    \add_action( 'admin_enqueue_scripts', [ $admin, 'admin_enqueue_scripts' ], 1 );
     110    \add_action( 'admin_footer', [ $admin, 'jquery' ], 100000 );
     111    \add_action( 'admin_footer', [ $admin, 'css' ], 100000 );
     112
     113}
  • export-user-data/tags/2.2.1/library/api/admin.php

    r2371571 r2643129  
    33namespace q\eud\api;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
    7 
    8 // load it up ##
    9 #\q\eud\api\admin::run();
    10 
    11 class admin extends \q_export_user_data {
    12 
    13     public static function run()
    14     {
    15 
    16         if ( \is_admin() ) {
    17 
    18             // load standard fields ##
    19             #\add_action( 'admin_init', array( get_class(), 'load' ), 1 );
    20 
    21         }
    22 
    23     }
    24 
    25 
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin;
     8use q\eud\core\core;
     9use q\eud\core\helper as h;
     10
     11class admin {
     12
     13    private $plugin;
     14
     15    function __construct(){
     16
     17        $this->plugin = plugin::get_instance();
     18
     19    }
    2620
    2721    /**
     
    3125    * @return      HTML
    3226    */
    33     public static function render( $array = null )
    34     {
     27    function render( $array = null ){
    3528
    3629        // check if we have any fields to show ##
     
    4033        ) {
    4134
    42             #helper::log( 'No fields found' );
    43 
    44             return false;
    45 
    46         }
    47 
    48         #helper::log( $array );
     35            #h::log( 'No fields found' );
     36
     37            return false;
     38
     39        }
     40
     41        #h::log( $array );
    4942
    5043        // check that we have all required arrays ##
     
    5649        ) {
    5750
    58             #helper::log( 'Missing data' );
     51            #h::log( 'Missing data' );
    5952
    6053            return false;
     
    6861        $array['label'] = \sanitize_key( $array['label'] );
    6962
    70         #helper::log( $array['options'] );
     63        #h::log( $array['options'] );
    7164
    7265        // build out options ##
    7366        if ( ! self::has_options( $array ) ) {
    7467           
    75             #helper::log( 'Missing options for: '.$array['label'] );
     68            #h::log( 'Missing options for: '.$array['label'] );
    7669
    7770            return false;
     
    10497    }
    10598
    106 
    107     public static function has_options( $array = null )
    108     {
     99    public static function has_options( $array = null ){
    109100
    110101        if (
     
    128119    }
    129120
    130 
    131 
    132     public static function build_options( $array = null )
    133     {
     121    public static function build_options( $array = null ){
    134122
    135123        if (
     
    139127        ) {
    140128
    141             #helper::log( 'Error building options for: '.$array['label'] );
     129            #h::log( 'Error building options for: '.$array['label'] );
    142130
    143131            return false;
     
    163151    }
    164152
    165 
    166 
    167     public static function field_select( $array = null )
    168     {
     153    public static function field_select( $array = null ){
    169154
    170155        if (
     
    179164        ) {
    180165
    181             #helper::log( 'Error building select options for: '.$array['label'] );
    182 
    183             return false;
    184 
    185         }
    186 
    187         #helper::log( 'Building select options for: '.$array['label'] );
     166            #h::log( 'Error building select options for: '.$array['label'] );
     167
     168            return false;
     169
     170        }
     171
     172        #h::log( 'Building select options for: '.$array['label'] );
    188173
    189174        // is this a multiselect ? ##
     
    228213    }
    229214
    230 
    231215}
  • export-user-data/tags/2.2.1/library/core/buddypress.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
    79
    8 // load it up ##
    9 \q\eud\core\buddypress::run();
     10class buddypress {
    1011
    11 class buddypress extends \q_export_user_data {
     12    private $plugin;
    1213
    13     public static function run()
    14     {
     14    function __construct(){
    1515
    16         if ( \is_admin() ) {
     16        $this->plugin = plugin::get_instance();
    1717
    18             // load BP ##
    19             \add_action( 'admin_init', array( get_class(), 'load' ), 1000001 );
    20 
    21         }
    22 
    23     }
    24 
     18    }
    2519   
    2620    /**
     
    2923    * @since    2.0.0
    3024    */
    31     public static function get_fields()
    32     {
     25    public static function get_fields(){
    3326
    3427        // buddypress support deprecated for now ##
     
    6154    }
    6255
    63 
    64 
    6556    /**
    6657    * Load up saved exports for this user
     
    7061    * @return      Array of saved exports
    7162    */
    72     public static function load()
    73     {
     63    public static function load(){
    7464
    7565        // do we have a bp object in the globals ##
     
    8070        ) {
    8171
    82             helper::log( 'BP not loaded - calling buddypress()' );
     72            h::log( 'BP not loaded - calling buddypress()' );
    8373
    8474            // call BP
    85             buddypress();
     75            \buddypress();
    8676
    8777            return true;
     
    9585    }
    9686
    97 
    98 
    9987}
  • export-user-data/tags/2.2.1/library/core/config.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
    79
    8 // load it up ##
    9 // \q\eud\core\config::run();
     10class config {
    1011
    11 class config extends \q_export_user_data {
     12    private $plugin;
    1213
    13     public static function run()
    14     {
     14    function __construct(){
    1515
    16         if ( \is_admin() ) {
     16        $this->plugin = plugin::get_instance();
    1717
    18             // load standard fields ##
    19             \add_action( 'admin_init', array( get_class(), 'load' ), 1 );
    20 
    21         }
    22 
    23     }
    24 
    25 
     18    }
    2619
    2720    /**
     
    3225    * @return      Array of saved exports
    3326    */
    34     public static function load()
    35     {
     27    public static function load(){
    3628
    3729        // load api admin fields ##
     
    4335    }
    4436
    45 
    46 
    4737    /**
    4838    * Load up saved exports for this user
     
    5242    * @return      Array of saved exports
    5343    */
    54     public static function get_admin_fields()
    55     {
     44    public function get_admin_fields(){
    5645
    5746        // build array ##
    58         $array = array(
    59             'program' => array(
     47        $array = [
     48            'program' => [
    6049                'title'             => \_e( 'Programs', 'export-user-data' ),
    6150                'label'             => 'program',
    6251                'description'       => \__( 'Select the program that you wish to export.', 'export-user-data' ),
    6352                'label_select'      => \__( 'All Programs', 'export-user-data' ),
    64                 'options'           => \get_posts( array( 'post_type'=> 'program', 'posts_per_page' => -1 ) ),
     53                'options'           => \get_posts([ 'post_type'=> 'program', 'posts_per_page' => -1 ]),
    6554                'options_ID'        => 'ID',
    6655                'options_title'     => 'post_title'
    67             )
    68         );
     56            ]
     57        ];
    6958
    7059        // test it ##
    7160        #self::log( $array );
    7261
    73         // add to static property ##
    74         self::$api_admin_fields = $array;
    75 
    7662        // filter and return ##
    77         apply_filters( 'q/eud/api/admin_fields', self::$api_admin_fields );
     63        apply_filters( 'q/eud/api/admin_fields', $array );
    7864
    7965        // test it ##
    80         self::log( self::$api_admin_fields );
     66        // h::log( $array );
     67       
     68        // add to static property ##
     69        // self::$api_admin_fields = $array;
     70        $this->plugin->set( '_api_admin_fields', $array );
    8171
    82         // kick it back ##
     72        // kick back true ##
    8373        return true;
    8474
    8575    }
    8676
    87 
    8877}
  • export-user-data/tags/2.2.1/library/core/export.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
    7 // use q\eud\core\excel2003 as excel2003;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
     9use q\eud\core\method;
    810use XLSXWriter;
    911
    10 // load it up ##
    11 \q\eud\core\export::run();
    12 
    13 class export extends \q_export_user_data {
    14 
    15     public static function run()
    16     {
    17 
    18         if ( \is_admin() ) {
    19 
    20             // run export ##
    21             \add_action( 'admin_init', array( get_class(), 'render' ), 1000003 );
    22 
    23         }
    24 
    25     }
    26 
     12class export {
     13
     14    private $plugin;
     15
     16    function __construct( \q\eud\plugin $plugin ){
     17
     18        $this->plugin = $plugin;
     19
     20    }
    2721
    2822    /**
    29     * Attempt to generate the export file based on the passed arguements
    30     *
    31     * @since 0.1
    32     * @return Mixes
    33     **/
    34     public static function render()
    35     {
     23     * Attempt to generate the export file based on the passed arguements
     24     *
     25     * @since   0.1
     26     * @return  mixed
     27     */
     28    public function render(){
    3629
    3730        // Check if the user clicked on the Save, Load, or Delete Settings buttons ##
     
    5851            'fields'    => ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) ?
    5952                            'all' :
    60                             array( 'ID' ), // exclude standard wp_users fields from get_users query ##
     53                            [ 'ID' ], // exclude standard wp_users fields from get_users query ##
    6154            'role'      => \sanitize_text_field( $_POST['role'] )
    6255        );
     
    7568
    7669                // test it ##
    77                 helper::log( $args );
     70                // h::log( $args );
    7871
    7972            }
     
    8477        $args = \apply_filters( 'q/eud/export/args', $args );
    8578
    86         #helper::log( $args );
     79        #h::log( $args );
    8780
    8881        // pre_user query ##
    89         \add_action( 'pre_user_query', array( get_class(), 'pre_user_query' ) );
     82        \add_action( 'pre_user_query', [ $this, 'pre_user_query' ] );
    9083        $users = \get_users( $args );
    91         \remove_action( 'pre_user_query', array( get_class(), 'pre_user_query' ) );
     84        \remove_action( 'pre_user_query', [ $this, 'pre_user_query' ] );
    9285
    9386        // test args ##
    94         #if ( self::$debug ) helper::log ( $users );
     87        #h::log ( $users );
    9588
    9689        // no users found, so chuck an error into the args array and exit the export ##
     
    202195                $doc_end    = "";
    203196
    204                 $writer = new XLSXWriter();
     197                $writer = new \XLSXWriter();
    205198               
    206199            break;
     
    211204        // check for selected usermeta fields ##
    212205        $usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: '';
    213         #helper::log( $usermeta );
    214         $usermeta_fields = array();
     206        #h::log( $usermeta );
     207        $usermeta_fields = [];
    215208
    216209        // loop over each field and sanitize ## @todo - user array_map ##
     
    221214        }
    222215
    223         #helper::log( $usermeta_fields );
     216        #h::log( $usermeta_fields );
    224217        #exit;
    225218
     
    262255
    263256        // debug ##
    264         #helper::log( 'merging array' );
     257        #h::log( 'merging array' );
    265258
    266259        // compile final fields list ##
    267260        $fields = array_merge(
    268                 core::get_user_fields() // standard wp_user fields ##
    269             ,   core::get_special_fields() // 'special' fields - which are controlled via dedicated checks ##
     261                get::user_fields() // standard wp_user fields ##
     262            ,   get::special_fields() // 'special' fields - which are controlled via dedicated checks ##
    270263            ,   $usermeta_fields // wp_user_meta fields ##
    271             ,   $bp_fields_passed // selected buddypress fields ##
    272             ,   $bp_fields_update_passed // update date for buddypress fields ##
     264            // ,    $bp_fields_passed // selected buddypress fields ##
     265            // ,    $bp_fields_update_passed // update date for buddypress fields ##
    273266        );
    274267
    275268        // test field array ##
    276         #helper::log( $fields );
     269        #h::log( $fields );
    277270
    278271        // build the document headers ##
     
    281274        foreach ( $fields as $key => $field ) {
    282275
    283             #helper::log( 'Field: '. $field );
     276            #h::log( 'Field: '. $field );
    284277
    285278            // filter field name ##
     
    287280
    288281            // grab fields to exclude from exports - filterable ##
    289             if ( in_array( $fields[$key], core::get_exclude_fields() ) ) {
    290 
    291                 #helper::log( 'Dump Field: '. $fields[$key] );
     282            if ( in_array( $fields[$key], get::exclude_fields() ) ) {
     283
     284                #h::log( 'Dump Field: '. $fields[$key] );
    292285
    293286                // ditch 'em ##
     
    311304
    312305        // quick check ##
    313         #helper::log( $fields );
    314         #if ( self::$debug ) #helper::log( $bp_fields_passed );
     306        #h::log( $fields );
     307        #h::log( $bp_fields_passed );
    315308
    316309        // no more buffering while spitting back the export data ##
     
    319312        // get the value in bytes allocated for Memory via php.ini ##
    320313        // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue
    321         $memory_limit = core::return_bytes( ini_get('memory_limit') ) * .75;
     314        $memory_limit = helper::return_bytes( ini_get('memory_limit') ) * .75;
    322315
    323316        // we need to disable caching while exporting because we export so much data that it could blow the memory cache
     
    339332        }
    340333
    341 
    342         if ($export_method !== "excel2007") {
     334        if ( $export_method !== "excel2007" ) {
    343335            // open doc wrapper.. ##
    344336            echo $doc_begin;
     
    347339            echo $pre . implode( $seperator, $headers ) . $breaker;
    348340
    349             #helper::log( $users );
     341            #h::log( $users );
    350342        } else {
    351343
    352             $xlsx_header = array_flip($headers);
     344            $xlsx_header = array_flip( $headers );
    353345
    354346            foreach($xlsx_header as $k => $v) {
     
    356348            }
    357349
    358             $writer->writeSheetHeader('Sheet1', $xlsx_header);
     350            $writer->writeSheetHeader('Sheet1', $xlsx_header);
     351           
    359352        }
    360353
     
    362355        foreach ( $users as $user ) {
    363356
    364             #helper::log( $user );
     357            #h::log( $user );
    365358
    366359            // check if we're hitting any Memory limits, if so flush them out ##
     
    375368            // BP loaded ? ##
    376369            if (
    377                 ! self::$bp_data_available
     370                ! $this->plugin->get( '_bp_data_available' )
    378371                && function_exists ( 'bp_is_active' )
    379372                && \bp_is_active( 'xprofile' )
     
    383376            ) {
    384377
    385                 helper::log( 'XProfile Accessible' );
    386                 self::$bp_data_available = true; // we only need to check for BP once ##
     378                // h::log( 'XProfile Accessible' );
     379                $this->plugin->set( '_bp_data_available', true ); // we only need to check for BP once ##
    387380
    388381            }
     
    390383            // grab all user data ##
    391384            if (
    392                 self::$bp_data_available
     385                $this->plugin->get( '_bp_data_available' )
    393386                && ! $bp_data = \BP_XProfile_ProfileData::get_all_for_user( $user->ID )
    394387            ) {
     
    397390                $bp_data = false;
    398391
    399                 helper::log( 'XProfile returned no data ID#: '.$user->ID );
     392                // h::log( 'XProfile returned no data ID#: '.$user->ID );
    400393
    401394            }
     
    403396            // single query method - get all user_meta data ##
    404397            $get_user_meta = (array)\get_user_meta( $user->ID );
    405             #helper::log( $get_user_meta );
     398            #h::log( $get_user_meta );
    406399
    407400            // loop over each field ##
     
    443436
    444437                // check if this is a BP field we want the updated date for ##
    445                 }
    446                 elseif ( in_array( $field, $bp_fields_update_passed ) )
    447                 {
     438                } elseif ( in_array( $field, $bp_fields_update_passed ) ) {
    448439
    449440                    global $bp;
     
    464455
    465456                // include the user's role in the export ##
    466                 }
    467                 elseif ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] && $field == 'roles' )
    468                 {
     457                } elseif ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] && $field == 'roles' ) {
    469458
    470459                    // empty array ##
     
    482471
    483472                    // test ##
    484                     // helper::log( $user_roles );
    485 
    486                      // empty value if no role found - or flat array of user roles ##
    487                     $value = ! empty( $user_roles ) ? implode( $user_roles, '|' ) : '';
     473                    // h::log( $user_roles );
     474
     475                    // empty value if no role found - or flat array of user roles ##
     476                    $value =
     477                        ! empty( $user_roles ) ?
     478                        helper::json_encode( $user_roles ) /*implode( '|', $user_roles )*/ :
     479                        '';
    488480
    489481                // include the user's BP group in the export ##
    490                 }
    491                 elseif ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] && $field == 'groups' )
    492                 {
     482                } elseif ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] && $field == 'groups' ) {
    493483
    494484                    if ( function_exists( 'groups_get_user_groups' ) ) {
     
    497487                        $group_ids = \groups_get_user_groups( $user->ID );
    498488
    499                         #$this->pr( $group_ids );
    500                         #wp_die( pr( 'loaded group data.' ));
     489                        #h::log( $group_ids );
    501490
    502491                        if ( ! $group_ids || $group_ids == '' ) {
     
    517506
    518507                            // implode it ##
    519                             $value = implode( $groups, '|' );
     508                            // $value = implode( $groups, '|' );
     509                            $value = helper::json_encode( $groups );
    520510
    521511                        }
     
    527517                    }
    528518
    529                 }
    530                 elseif ( $field == 'bp_latest_update' || $field == 'last_activity' )
    531                 {
     519                /*
     520                } elseif (
     521                    ( $field == 'bp_latest_update' && function_exists( 'bp_get_user_last_activity' ) )
     522                    || $field == 'last_activity'
     523                ){
    532524
    533525                    // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ##
    534526                    $value = \bp_get_user_last_activity( $user->ID );
     527                */
    535528
    536529                // user or usermeta field ##
    537                 }
    538                 else
    539                 {
     530                } else {
    540531
    541532                    // the user_meta key isset ##
    542                     if ( isset( $get_user_meta[$field] ) ) {
     533                    if (
     534                        isset( $get_user_meta[$field] )
     535                        && is_array( $get_user_meta[$field] )
     536                    ){
    543537
    544538                        // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ##
     
    553547                    }
    554548
    555 
    556                     // the $value might be serialized ##
    557                     $value = core::unserialize( $value );
    558 
    559                     // the value is an array ##
    560                     if ( is_array ( $value ) ) {
    561 
    562                         // recursive implode it ##
    563                         $value = core::recursive_implode( $value );
    564 
    565                     }
    566 
    567                     // sanitize ##
    568                     #$value = $this->sanitize($value);
    569 
    570549                }
    571550
     551                // ---------- cleanup and format the value, before exporting ##
     552
     553                // the $value might be serialized, so try to unserialize ##
     554                $value = helper::unserialize( $value );
     555
     556                // the value is an array ##
     557                if (
     558                    is_array ( $value )
     559                    || is_object ( $value )
     560                ){
     561
     562                    helper::log( 'is_array || is_object' );
     563                    helper::log( $value );
     564
     565                    // recursive implode it ##
     566                    // $value = helper::recursive_implode( $value );
     567
     568                    // json_encode value to object
     569                    $value = helper::json_encode( $value );
     570
     571                // } else {
     572
     573                }
     574
     575                    // sanitize string value ##
     576                    $value = helper::sanitize( $value );
     577
     578                // }
     579
    572580                // filter $value ##
    573                 $value = \apply_filters( 'q/eud/export/value', $value, $field );
     581                // $value = \apply_filters( 'q/eud/export/value', $value, $field );
    574582
    575583                // sanitize ##
    576                 $value = core::sanitize( $value );
     584                // $value = helper::sanitize( $value );
     585
     586                // if no filter is added, apply default sanitiziation ##
     587                // if( has_filter( 'q/eud/export/value' ) ){
     588
     589                    // $value = \apply_filters( 'q/eud/export/value', $value );
     590
     591                // } else {
     592
     593                    // $value = helper::format_value( $value );
     594
     595                // }   
     596
     597                // helper::log( $value );
    577598
    578599                // wrap values in quotes and add to array ##
    579600                if ( $is_csv ) {
    580601
    581                     $data[] = '"' . str_replace( '"', '""', core::format_value( $value ) ) . '"';
     602                    // replace single-double quotes with double-double quotes, if not dealing with a JSON string ###
     603                    // if( ! helper::is_json( $value ) ) {
     604                   
     605                        // $value = str_replace( '"', '\"', $value );
     606
     607                    // }
     608
     609                    // wrap value in double quotes ##
     610                    $value = '"' . $value . '"';
     611
     612                    // helper::log( $value );
     613
     614                    // add value to $data array  ##
     615                    $data[] = $value;
    582616
    583617                // just add to array ##
    584618                } else {
    585619
    586                     $data[] = core::format_value( $value );
     620                    $data[] = $value;
     621
    587622                }
    588623
    589624            }
    590625
    591             if ($export_method !== "excel2007") {
    592                 // echo row data ##
    593                 echo $pre . implode( $seperator, $data ) . $breaker;
     626            if ( $export_method !== "excel2007" ) {
     627               
     628                // echo row data ##
     629                echo $pre . implode( $seperator, $data ) . $breaker;
     630               
    594631            } else {
    595                 $writer->writeSheetRow('Sheet1', $data);
    596             }
    597 
    598         }
    599 
    600         if ($export_method !== "excel2007") {
     632
     633                $writer->writeSheetRow( 'Sheet1', $data );
     634               
     635            }
     636
     637        }
     638
     639        if ( $export_method !== "excel2007" ) {
     640
    601641            // close doc wrapper..
    602             echo $doc_end;
     642            echo $doc_end;
     643           
    603644        } else {
    604             //$writer->writeSheet($rows,'Sheet1', $header); //or write the whole sheet in 1 call
    605             //$writer->writeToFile('xlsx-simple.xlsx');
    606             //$writer->writeToStdOut();
    607             echo $writer->writeToString();
     645           
     646            echo $writer->writeToString();
     647           
    608648        }
    609649
     
    612652
    613653    }
    614 
    615 
    616    
    617654   
    618655    /**
     
    621658    * @since        2.0.0
    622659    */
    623     public static function pre_user_query( $user_search = null )
    624     {
     660    function pre_user_query( $user_search = null ){
    625661
    626662        global $wpdb;
     
    652688        ) {
    653689
    654             $last_updated_date = new \DateTime( \sanitize_text_field ( $_POST['updated_since_date'] ) . ' 00:00:00' );
    655             self::$updated_since_date = $last_updated_date->format( 'Y-m-d H:i:s' );
    656             self::$field_updated_since = \sanitize_text_field ( $_POST['bp_field_updated_since'] );
    657             $field_updated_since_id = \BP_Xprofile_Field::get_id_from_name( self::$field_updated_since );
    658             $user_search->query_from .=  " JOIN `wp_bp_xprofile_data` XP ON XP.user_id = wp_users.ID ";
    659             $where .= $wpdb->prepare( " AND XP.field_id = %s AND XP.last_updated >= %s", $field_updated_since_id, self::$updated_since_date );
     690            // get last update string ##
     691            $last_updated_date = new \DateTime( \sanitize_text_field ( $_POST['updated_since_date'] ) . ' 00:00:00' );
     692           
     693            // set date ##
     694            $this->plugin->set( '_updated_since_date', $last_updated_date->format( 'Y-m-d H:i:s' ) );
     695           
     696            // set field ##
     697            $this->plugin->set( '_field_updated_since', \sanitize_text_field ( $_POST['bp_field_updated_since'] ) );
     698            $field_updated_since_id = \BP_Xprofile_Field::get_id_from_name( $this->plugin->get( '_field_updated_since' ) );
     699            $user_search->query_from .=  " JOIN `wp_bp_xprofile_data` XP ON XP.user_id = wp_users.ID ";
     700           
     701            // set where string ##
     702            $where .= $wpdb->prepare( " AND XP.field_id = %s AND XP.last_updated >= %s", $field_updated_since_id, $this->plugin->get( '_updated_since_date' ) );
    660703
    661704        }
     
    667710        }
    668711
    669         #wp_die( self::$pr( $user_search ) );
     712        #h::log( $user_search ) );
    670713        return $user_search;
    671714
    672715    }
    673716
    674 
    675 
    676717}
  • export-user-data/tags/2.2.1/library/core/filters.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
    79
    8 // load it up ##
    9 \q\eud\core\filters::run();
     10class filters {
    1011
    11 class filters extends \q_export_user_data {
     12    private $plugin;
    1213
    13     public static function run()
    14     {
     14    function __construct( \q\eud\plugin $plugin ){
    1515
    16         if ( \is_admin() ) {
     16        $this->plugin = $plugin;
    1717
    18             // EUD - filter key shown ##
    19             \add_filter( 'q/eud/admin/display_key', [ get_class(), 'display_key' ], 1, 1 );
    20 
    21         }
    22 
    23     }
    24 
     18    }
    2519
    2620    /**
     
    2923    * @since 2.0.0
    3024    */
    31     public static function display_key( $string = null )
    32     {
     25    public static function display_key( $string = null ){
    3326
    3427        #helper::log( 'string from filter: '.$string );
  • export-user-data/tags/2.2.1/library/core/helper.php

    r2371571 r2643129  
    88 * @package   q_eud\core
    99 */
    10 class helper extends \q_export_user_data {
    11 
    12      
     10class helper {
     11
    1312    /**
    1413     * Write to WP Error Log
     
    1716     * @return      void
    1817     */
    19     public static function log( $log )
    20     {
    21 
    22         if ( true === WP_DEBUG ) {
     18    public static function log( $log ){
     19
     20        if ( true === \WP_DEBUG ) {
    2321
    2422            $trace = debug_backtrace();
    25             $caller = $trace[1];
     23            $caller = $trace[0];
    2624
    2725            $suffix = sprintf(
     
    4341    }
    4442
     43   
     44    /**
     45    * Return Byte count of $val
     46    *
     47    * @link        http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
     48    * @since       0.9.6
     49    */
     50    public static function return_bytes( $val ){
     51
     52        $val = trim( $val );
     53        $last = strtolower($val[strlen($val)-1]);
     54        switch( $last ) {
     55
     56            // The 'G' modifier is available since PHP 5.1.0
     57            case 'g':
     58
     59                $val *= 1024;
     60
     61            case 'm':
     62
     63                $val *= 1024;
     64
     65            case 'k':
     66
     67                $val *= 1024;
     68
     69        }
     70
     71        return $val;
     72
     73    }
     74
     75    /**
     76    * Recursively implodes an array
     77    *
     78    * @since    1.0.1
     79    * @access   public
     80    * @param    array       $array          multi-dimensional array to recursively implode
     81    * @param    string      $glue           value that glues elements together
     82    * @param    bool        $include_keys   include keys before their values
     83    * @param    bool        $trim_all       trim ALL whitespace from string
     84    * @return   string      imploded array
     85    */
     86    public static function recursive_implode( $array, $return = null, $glue = '|' ){
     87
     88        // unserialize ##
     89        $array = self::unserialize( $array );
     90
     91        // kick it back ##
     92        if ( is_null ( $return ) && ! is_array( $array ) ) {
     93
     94            return $array;
     95
     96        }
     97
     98        // empty return ##
     99        if ( is_null ( $return ) ) {
     100
     101            $return = '';
     102
     103        } else {
     104
     105            if ( "||" == $glue ) {
     106
     107                $glue = '|||';
     108
     109            } else if ( "|" == $glue ) {
     110
     111                $glue = '||';
     112
     113            }
     114
     115        }
     116
     117        // loop ##
     118        foreach( $array as $key => $value ) {
     119
     120            // unserialize ##
     121            $value = self::unserialize( $value );
     122
     123            if( is_array( $value ) ) {
     124
     125                $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
     126               
     127            // add @2.1.0 from issue #4 - https://github.com/qstudio/export-user-data/issues/4
     128            } elseif(is_object($value)) {
     129
     130                $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
     131
     132            } else {
     133
     134                $return .= $glue . $key . $glue . $value;
     135
     136            }
     137           
     138
     139        }
     140
     141        // Removes first $glue from string ##
     142        if ( $glue && $return && $return[0] == '|' ) {
     143
     144            $return = ltrim( $return, '|' );
     145
     146        }
     147
     148        // Trim ALL whitespace ##
     149        if ( $return ) {
     150
     151            $return = preg_replace( "/(\s)/ixsm", '', $return );
     152
     153        }
     154
     155        // kick it back ##
     156        return $return;
     157
     158    }
     159
     160    /**
     161    * Save Unserializer
     162    *
     163    * @since       1.1.4
     164    */
     165    public static function unserialize( $value = null ){
     166
     167        // the $value is serialized ##
     168        if ( \is_serialized( $value ) ) {
     169
     170            // unserliaze to new variable ##
     171            $unserialized = @unserialize( $value );
     172
     173            // test if unserliazing produced errors ##
     174            if (
     175                $unserialized !== false
     176                && $value !== 'b:0;'
     177            ){
     178
     179                h::log( $unserialized );
     180
     181                #$value = 'UNSERIALIZED_'.$unserialized;
     182                $value = $unserialized;
     183
     184            } else {
     185
     186                // failed to unserialize - data potentially corrupted in db ##
     187                #$value = 'NOT_SERIALIZED_'.$value;
     188                $value = $value;
     189
     190            }
     191
     192        }
     193
     194        // kick it back ##
     195        return $value;
     196
     197    }
     198
     199    /**
     200    * Encode special characters
     201    *
     202    * @param        type        $string
     203    * @return       string      Encoding string
     204    * @since        1.2.3
     205    */
     206    public static function format_value( string $value = null )
     207    {
     208
     209        // sanity check ##
     210        if ( is_null( $value ) ) {
     211
     212            return false;
     213
     214        }
     215
     216        if( has_filter( 'q/eud/export/value' ) ){
     217
     218            $value = \apply_filters( 'q/eud/export/value', $value );
     219
     220        } else {
     221
     222            $value = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
     223
     224        }
     225
     226        // if value is a JSON_ENCODE'd string, then do not sanitize ##
     227        // if( self::is_json( $value ) ){
     228
     229            // do we need to apply some escpaping ?? ##
     230
     231            // return $value;
     232
     233        // }
     234
     235        // sanitize ##
     236        // $value = self::sanitize( $value );
     237
     238        // if no filter is added, apply default sanitiziation ##
     239        // if( ! has_filter( 'q/eud/export/value' ) ){
     240
     241       
     242
     243        // }
     244
     245        // self::log( $value );
     246       
     247        // kick it back via a filter to allow custom formatting ##
     248        return $value;
     249
     250    }
     251
     252    /**
     253     * Encode array values to JSON string
     254     *
     255     * @since 2.2.1
     256     * @param   mixed
     257     * @return  mixed   string|null
     258    */
     259    public static function json_encode( array $value ):?string
     260    {
     261
     262        if ( ! is_array( $value ) ){
     263
     264            return $value;
     265
     266        }
     267
     268        // cleanup array ##
     269        $value = array_values( $value );
     270
     271        // encode and escape ##
     272        $value = htmlspecialchars( json_encode( $value, JSON_FORCE_OBJECT ) );
     273
     274        // self::log( $value );
     275
     276        // kick back JSON encoded string ##
     277        return $value;
     278
     279    }
     280
     281    /**
     282    * Quote array elements and separate with commas
     283    *
     284    * @since       0.9.6
     285    * @return      String
     286    */
     287    public static function quote_array( $array ){
     288
     289        $prefix = ''; // starts empty ##
     290        $string = '';
     291
     292        if ( is_array( $array ) ) {
     293       
     294            foreach( $array as $element ) {
     295       
     296                $string .= $prefix . "'" . $element . "'";
     297                $prefix = ','; // prefix all remaining items with a comma ##
     298       
     299            }
     300       
     301        }
     302
     303        // kick back string to function caller ##
     304        return( $string );
     305
     306    }
     307
     308    /**
     309    * Export Date Options
     310    *
     311    * @since       0.9.6
     312    * @global      type    $wpdb
     313    * @return      Array of objects
     314    * @todo         Remove max date, as this makes little sense for exports not based on user reg dates.. ??   
     315    */
     316    public static function get_user_registered_dates(){
     317
     318        // invite in global objects ##
     319        global $wpdb;
     320
     321        // query user table for oldest and newest registration ##
     322        $range =
     323            $wpdb->get_results (
     324                #$wpdb->prepare (
     325                    "
     326                    SELECT
     327                        MIN( user_registered ) AS first,
     328                        MAX( user_registered ) AS last
     329                    FROM
     330                        {$wpdb->users}
     331                    "
     332                #)
     333            );
     334
     335        return $range;
     336
     337    }
     338
     339    /**
     340    * Sanitize data
     341    *
     342    * @since 1.2.8
     343    * @return string
     344    */
     345    public static function sanitize_value( $value ){
     346
     347        // if value is a JSON_ENCODE'd string, then do not sanitize ##
     348        // if( self::is_json( $value ) ){
     349
     350        //  // do we need to apply some escpaping ?? ##
     351
     352        //  return $value;
     353
     354        // }
     355
     356        // self::log( 'sanitize: '.$value );
     357
     358        if( has_filter( 'q/eud/export/value' ) ){
     359
     360            $value = \apply_filters( 'q/eud/export/value', $value );
     361
     362        } else {
     363
     364            $value = htmlentities( $value, ENT_COMPAT|ENT_COMPAT, 'UTF-8' );
     365            // $value = \esc_attr( $value );
     366
     367        }
     368
     369        // remove line breaks ##
     370        // $value = str_replace("\r", '', $value);
     371        // $value = str_replace("\n", '', $value);
     372        // $value = str_replace("\t", '', $value);
     373
     374        // with wp_kses ##
     375        // $value = \wp_kses( $value, self::get_allowed_tags() );
     376
     377        // return value ##
     378        return $value;
     379
     380    }
     381
     382    public static function sanitize( $value ) {
     383
     384        if ( is_array( $value ) ) {
     385
     386            array_walk_recursive( $value, [ __CLASS__, 'sanitize_value' ] );
     387
     388        } else {
     389
     390            self::sanitize_value( $value );
     391
     392        }
     393
     394        return $value;
     395
     396    }
     397
     398    /**
     399     * Check if a string is JSON
     400     *
     401     * @since 2.0.2
     402    */
     403    public static function is_json( $string )
     404    {
     405   
     406        json_decode( $string );
     407
     408        if ( json_last_error() === JSON_ERROR_NONE ){
     409
     410            // self::log( 'is_json: '.$string );
     411
     412            return true;
     413
     414        }
     415
     416        // self::log( 'is not json: '.$string );
     417
     418        return false;
     419   
     420    }
     421
     422    /**
     423    * Get allowed tags for wp_kses
     424    *
     425    * @since  1.2.8
     426    * @return Array
     427    */
     428    public static function get_allowed_tags(){
     429
     430        $allowed_tags = [
     431            'a' => [
     432                'href' => [],
     433                'title' => []
     434            ],
     435            'br' => [],
     436            'em' => [],
     437            'strong' => [],
     438        ];
     439
     440        // kick back via filter ##
     441        return \apply_filters( 'q/eud/export/allowed_tags', $allowed_tags );
     442
     443    }
    45444
    46445}
  • export-user-data/tags/2.2.1/library/core/user.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
    7 
    8 // load it up ##
    9 \q\eud\core\user::run();
    10 
    11 class user extends \q_export_user_data {
    12 
    13     public static function run()
    14     {
    15 
    16         if ( \is_admin() ) {
    17 
    18             // load user options ##
    19             \add_action( 'admin_init', array( get_class(), 'load' ), 1000002 );
    20 
    21         }
    22 
    23     }
    24 
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
     9
     10class user {
     11
     12    private $plugin;
     13
     14    public function __construct( \q\eud\plugin $plugin ){
     15
     16        $this->plugin = $plugin;
     17
     18    }
    2519
    2620    /**
     
    3125    * @return      Array of saved exports
    3226    */
    33     public static function load()
    34     {
     27    public function load(){
    3528
    3629        // convert outdated stored meta from q_report to q_eud_exports ##
     
    5245
    5346        // test #
    54         // helper::log( \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) );
    55 
    56         return self::$q_eud_exports =
    57             \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ?
    58             \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) :
    59             array() ;
     47        // h::log( \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) );
     48
     49        // get array ##
     50        $array =
     51            \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ?
     52            \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) :
     53            [] ;
     54
     55        // set prop ##
     56        $this->plugin->set( '_q_eud_exports', $array );
     57
     58        // return bool ##
     59        return true;
    6060           
    6161    }
    6262
    63 
    64 
    65 
    6663    /**
    6764    * Get list of saved exports for this user
     
    7067    * @return      Array of saved exports
    7168    */
    72     public static function get_user_options()
    73     {
     69    function get_user_options(){
     70
     71        // get props ##
     72        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
    7473
    7574        // get the stored options - filter empty array items ##
    76         $q_eud_exports = array_filter( self::$q_eud_exports );
     75        $_q_eud_exports = array_filter( $_q_eud_exports );
    7776
    7877        // quick check if the array is empty ##
    79         if ( empty ( $q_eud_exports ) ) {
     78        if ( empty ( $_q_eud_exports ) ) {
    8079
    8180            return false;
     
    8483
    8584        // test the array of saved exports ##
    86         #$this->pr( $q_eud_exports );
     85        #h::log( $_q_eud_exports );
    8786
    8887        // start with an empty array ##
    89         $exports = array();
     88        $exports = [];
    9089
    9190        // loop over each saved export and grab each key ##
    92         foreach ( $q_eud_exports as $key => $value ) {
     91        foreach ( $_q_eud_exports as $key => $value ) {
    9392
    9493            $exports[] = $key;
     
    101100    }
    102101
    103 
    104102    /**
    105103    * Check for and load stored user options
     
    108106    * @return      void
    109107    */
    110     public static function get_user_options_by_export( $export = null )
    111     {
     108    function get_user_options_by_export( $export = null ){
    112109
    113110        // sanity check ##
    114         if ( is_null ( $export ) ) { return false; }
    115 
    116         if ( isset( self::$q_eud_exports[$export] ) ) {
    117 
    118             self::$usermeta_saved_fields = self::$q_eud_exports[$export]['usermeta_saved_fields'];
    119             self::$bp_fields_saved_fields = self::$q_eud_exports[$export]['bp_fields_saved_fields'];
    120             self::$bp_fields_update_time_saved_fields = self::$q_eud_exports[$export]['bp_fields_update_time_saved_fields'];
    121             self::$updated_since_date = isset( self::$q_eud_exports[$export]['updated_since_date'] ) ? self::$q_eud_exports[$export]['updated_since_date'] : null ;
    122             self::$field_updated_since = isset( self::$q_eud_exports[$export]['field_updated_since'] ) ? self::$q_eud_exports[$export]['field_updated_since'] : null ;
    123             self::$role = self::$q_eud_exports[$export]['role'];
    124             self::$roles = self::$q_eud_exports[$export]['roles'];
    125             self::$groups = self::$q_eud_exports[$export]['groups'];
    126             self::$user_fields = isset( self::$q_eud_exports[$export]['user_fields'] ) ? self::$q_eud_exports[$export]['user_fields'] : null ;
    127             self::$start_date = self::$q_eud_exports[$export]['start_date'];
    128             self::$end_date = self::$q_eud_exports[$export]['end_date'];
    129             self::$limit_offset = self::$q_eud_exports[$export]['limit_offset'];
    130             self::$limit_total = self::$q_eud_exports[$export]['limit_total'];
    131             self::$format = self::$q_eud_exports[$export]['format'];
     111        if ( is_null ( $export ) ) { return false; }
     112       
     113        // get props ##
     114        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
     115
     116        if ( isset( $_q_eud_exports[$export] ) ) {
     117
     118            $_usermeta_saved_fields = $_q_eud_exports[$export]['usermeta_saved_fields'];
     119            // $_bp_fields_saved_fields = $_q_eud_exports[$export]['bp_fields_saved_fields'];
     120            // $_bp_fields_update_time_saved_fields = $_q_eud_exports[$export]['bp_fields_update_time_saved_fields'];
     121            $_updated_since_date = $_q_eud_exports[$export]['updated_since_date'] ?? null ;
     122            $_field_updated_since = $_q_eud_exports[$export]['field_updated_since'] ?? null ;
     123            $_role = $_q_eud_exports[$export]['role'];
     124            $_roles = $_q_eud_exports[$export]['roles'];
     125            $_groups = $_q_eud_exports[$export]['groups'];
     126            $_user_fields = $_q_eud_exports[$export]['user_fields'] ?? null ;
     127            $_start_date = $_q_eud_exports[$export]['start_date'];
     128            $_end_date = $_q_eud_exports[$export]['end_date'];
     129            $_limit_offset = $_q_eud_exports[$export]['limit_offset'];
     130            $_limit_total = $_q_eud_exports[$export]['limit_total'];
     131            $_format = $_q_eud_exports[$export]['format'];
    132132
    133133        } else {
    134134
    135             self::$usermeta_saved_fields = array();
    136             self::$bp_fields_saved_fields = array();
    137             self::$bp_fields_update_time_saved_fields = array();
    138             self::$updated_since_date = '';
    139             self::$field_updated_since = '';
    140             self::$role = '';
    141             self::$user_fields = '1';
    142             self::$roles = '1';
    143             self::$groups = '1';
    144             self::$start_date = '';
    145             self::$end_date = '';
    146             self::$limit_offset = '';
    147             self::$limit_total = '';
    148             self::$format = '';
    149 
    150         }
    151 
    152     }
    153 
     135            $_usermeta_saved_fields = [];
     136            // $_bp_fields_saved_fields = [];
     137            // $_bp_fields_update_time_saved_fields = [];
     138            $_updated_since_date = '';
     139            $_field_updated_since = '';
     140            $_role = '';
     141            $_user_fields = '1';
     142            $_roles = '1';
     143            $_groups = '1';
     144            $_start_date = '';
     145            $_end_date = '';
     146            $_limit_offset = '';
     147            $_limit_total = '';
     148            $_format = '';
     149
     150        }
     151       
     152        // set props ##
     153        $this->plugin->set( '_usermeta_saved_fields', $_usermeta_saved_fields );
     154        // $this->plugin->set( '_bp_fields_saved_fields', $_bp_fields_saved_fields );
     155        // $this->plugin->set( '_bp_fields_update_time_saved_fields', $_bp_fields_update_time_saved_fields );
     156        $this->plugin->set( '_updated_since_date', $_updated_since_date );
     157        $this->plugin->set( '_field_updated_since', $_field_updated_since );
     158        $this->plugin->set( '_role', $_role );
     159        $this->plugin->set( '_user_fields', $_user_fields );
     160        $this->plugin->set( '_roles', $_roles );
     161        $this->plugin->set( '_groups', $_groups );
     162        $this->plugin->set( '_start_date', $_start_date );
     163        $this->plugin->set( '_end_date', $_end_date );
     164        $this->plugin->set( '_limit_offset', $_limit_offset );
     165        $this->plugin->set( '_limit_total', $_limit_total );
     166        $this->plugin->set( '_format', $_format );
     167
     168    }
    154169
    155170    /**
     
    161176    * @return      void
    162177    */
    163     public static function set_user_options( $key = null, $options = null )
    164     {
     178    function set_user_options( $key = null, $options = null ){
    165179
    166180        // sanity check ##
    167181        if ( is_null ( $key ) || is_null ( $options ) ) {
    168182
    169             #$this->pr( 'missing save values' );
     183            #h::log( 'missing save values' );
    170184            return false;
    171185
    172186        }
    173187
    174         #$this->pr( $key );
    175         #$this->pr( $options );
     188        #h::log( $key );
     189        #h::log( $options );
     190
     191        // get prop ##
     192        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
    176193
    177194        // for now, I'm simply allowing keys to be resaved - but this is not so logical ##
    178         if ( array_key_exists( $key, self::$q_eud_exports ) ) {
    179 
    180             #$this->pr( 'key exists, skipping save' );
     195        if ( array_key_exists( $key, $_q_eud_exports ) ) {
     196
     197            #h::log( 'key exists, skipping save' );
    181198            #return false;
    182199
     
    206223
    207224            // assign the sanitized array of values to the class property $q_eud_exports as a new array with key $key ##
    208             self::$q_eud_exports[$key] = $options;
     225            $_q_eud_exports[$key] = $options;
     226           
     227            // set prop ##
     228            $this->plugin->set( '_q_eud_exports', $_q_eud_exports );
    209229
    210230            // update stored user_meta values, if previous key found ##
    211             if ( \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) !== false ) {
    212 
    213                 #update_option( 'q_eud_exports', $this->q_eud_exports );
    214                 \update_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
     231            if ( false !== \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ) {
     232
     233                \update_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
    215234
    216235            // create new user meta key ##
    217236            } else {
    218237
    219                 #add_option( 'q_eud_exports', $this->q_eud_exports, $deprecated, $autoload );
    220                 \add_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
     238                \add_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
    221239
    222240            }
     
    225243
    226244    }
    227 
    228245
    229246    /**
     
    234251    * @return      void
    235252    */
    236     public static function delete_user_options( $key = null )
    237     {
     253    function delete_user_options( $key = null ){
     254
     255        // get prop ##
     256        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
    238257
    239258        // sanity check ##
    240         if ( is_null ( $key ) || ! array_key_exists( $key, self::$q_eud_exports ) ) { return false; }
     259        if ( is_null ( $key ) || ! array_key_exists( $key, $_q_eud_exports ) ) { return false; }
    241260
    242261        // clean it up ##
     
    244263
    245264        // check it out ##
    246         #$this->pr( $key );
     265        #h::log( $key );
    247266
    248267        // drop the array by it's key name from the class property ##
    249         unset( self::$q_eud_exports[$key] );
     268        unset( $_q_eud_exports[$key] );
    250269
    251270        // update the saved data ##
    252         \update_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
    253 
    254     }
    255 
    256 
     271        \update_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
     272       
     273        // set prop ##
     274        $this->plugin->set( '_q_eud_exports', $_q_eud_exports );
     275
     276        // done ##
     277        return true;
     278
     279    }
    257280
    258281}
  • export-user-data/tags/2.2.1/package.json

    r2372271 r2643129  
    11{
    22    "name": "export-user-data",
    3     "version": "2.1.3",
     3    "version": "2.2.1",
    44    "description": "Q Plugins ~ Export User data and metadata",
    55    "author": "Q Studio",
  • export-user-data/tags/2.2.1/readme.md

    r2372271 r2643129  
    55**Requires PHP:** 6.0 
    66**Requires at least:** 5.0 
    7 **Tested up to:** 5.5 
    8 **Stable tag:** 2.1.3 
     7**Tested up to:** 5.6 
     8**Stable tag:** 2.2.1 
    99**License:** GPLv2 
    1010
  • export-user-data/tags/2.2.1/readme.txt

    r2372271 r2643129  
    22Contributors: qlstudio
    33Tags: users, export, usermeta, excel   
    4 Requires PHP: 6.0 
     4Requires PHP: 7.0 
    55Requires at least: 4.8 
    6 Tested up to: 5.5 
    7 Stable tag: 2.1.3   
     6Tested up to: 5.6 
     7Stable tag: 2.2.0   
    88License: GPLv2 
    99
  • export-user-data/trunk/CHANGELOG.md

    r2372271 r2643129  
    11## Changelog ##
     2
     3*** 2.2.1 ***
     4
     5* New: cleanup export methods, improvied sanitization
     6* New: array and object data is now passed in JSON_ENCODED string object
     7
     8*** 2.2.0 ***
     9
     10* New: Move to cleaner OOP pattern and PHP version bump to 7.0
     11* Update: Tested on WP 5.6
    212
    313*** 2.1.3 ***
    414
    5 * FIX - wrong name for our own plugin :( thanks @kgagne !
     15* FIX: wrong name for our own plugin :( thanks @kgagne !
    616
    717*** 2.1.2 ***
  • export-user-data/trunk/export-user-data.php

    r2372271 r2643129  
    11<?php
    22
    3 /*
     3/**
     4 * Export User Data
     5 *
     6 * @package         Export User Data
     7 * @author          Q Studio <[email protected]>
     8 * @license         GPL-2.0+
     9 * @copyright       2020 Q Studio
     10 *
     11 * @wordpress-plugin
    412 * Plugin Name:     Export User Data
     13 * Plugin URI:      http://qstudio.us/releases/export-user-data
    514 * Description:     Export User data and metadata.
    6  * Version:         2.1.3
     15 * Version:         2.2.1
    716 * Author:          Q Studio
    8  * Author URI:      http://qstudio.us/
    9  * License:         GPL2
    10  * Class:           q_export_user_data
    11  * Text Domain:     q-export-user-data
     17 * Author URI:      https://qstudio.us
     18 * License:         GPL-2.0+
     19 * Requires PHP:    7.0
     20 * Copyright:       Q Studio
     21 * Namespace:       q\eud
     22 * API:             export_user_data
     23 * Text Domain:     export-user-data
     24 * Domain Path:     /languages
    1225 * GitHub Plugin URI: qstudio/export-user-data
    1326*/
    1427
    15 defined( 'ABSPATH' ) OR exit;
     28// namespace plugin ##
     29namespace q\eud;
    1630
    17 if ( ! class_exists( 'q_export_user_data' ) ) {
    18    
    19     // instatiate plugin via WP plugins_loaded - init is too late for CPT ##
    20     add_action( 'init', array ( 'q_export_user_data', 'get_instance' ), 1000000 );
    21    
    22     class q_export_user_data {
    23                
    24         // Refers to a single instance of this class. ##
    25         private static $instance = null;
    26                        
    27         // Plugin Settings
    28         const version = '2.1.3';
    29         static $debug = false;
    30         const text_domain = 'q-export-user-data'; // for translation ##
    31        
    32         /* properties */
    33         public static $q_eud_exports = ''; // export settings ##
    34         public static $usermeta_saved_fields = array();
    35         public static $bp_fields_saved_fields = array();
    36         public static $bp_fields_update_time_saved_fields = array();
    37         public static $role = '';
    38         public static $roles = '0';
    39         public static $user_fields = '1';
    40         public static $groups = '0';
    41         public static $start_date = '';
    42         public static $end_date = '';
    43         public static $limit_offset = '';
    44         public static $limit_total = '';
    45         public static $updated_since_date = '';
    46         public static $field_updated_since = '';
    47         public static $format = '';
    48         public static $bp_data_available = false;
    49         public static $allowed_tags = '';
     31// import ##
     32use q\eud;
     33use q\eud\core\helper as h;
    5034
    51         // api ##
    52         public static $api_admin_fields = false;
     35// If this file is called directly, Bulk!
     36if ( ! defined( 'ABSPATH' ) ) {
     37    return;
     38}
    5339
    54         /**
    55          * Creates or returns an instance of this class.
    56          *
    57          * @return  Foo     A single instance of this class.
    58          */
    59         public static function get_instance()
    60         {
     40// plugin activation hook to store current application and plugin state ##
     41\register_activation_hook( __FILE__, [ '\\q\\eud\\plugin', 'activation_hook' ] );
    6142
    62             if ( null == self::$instance ) {
    63                 self::$instance = new self;
    64             }
     43// plugin deactivation hook - clear stored data ##
     44\register_deactivation_hook( __FILE__, [ '\\q\\eud\\plugin', 'deactivation_hook' ] );
    6545
    66             return self::$instance;
     46// required bits to get set-up ##
     47require_once __DIR__ . '/library/api/function.php';
     48require_once __DIR__ . '/autoload.php';
     49require_once __DIR__ . '/plugin.php';
     50require_once __DIR__ . '/vendor/PHP_XLSXWriter/xlsxwriter.class.php';
    6751
    68         }
    69        
    70        
    71         /**
    72          * Instatiate Class
    73          *
    74          * @since       0.2
    75          * @return      void
    76          */
    77         private function __construct()
    78         {
    79            
    80             // activation ##
    81             register_activation_hook( __FILE__, array ( $this, 'register_activation_hook' ) );
     52// get plugin instance ##
     53$plugin = plugin::get_instance();
    8254
    83             // deactvation ##
    84             register_deactivation_hook( __FILE__, array ( $this, 'register_deactivation_hook' ) );
     55// validate instance ##
     56if( ! ( $plugin instanceof \q\eud\plugin ) ) {
    8557
    86             // set text domain ##
    87             add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
    88            
    89             // load libraries ##
    90             self::load_libraries();
     58    error_log( 'Error in Export User Data plugin instance' );
    9159
    92         }
    93 
    94 
    95         // the form for sites have to be 1-column-layout
    96         public function register_activation_hook() {
    97 
    98             \add_option( 'q_eud_configured' );
    99 
    100             // flush rewrites ##
    101             #global $wp_rewrite;
    102             #$wp_rewrite->flush_rules();
    103 
    104         }
    105 
    106 
    107         public function register_deactivation_hook() {
    108 
    109             \delete_option( 'q_eud_configured' );
    110 
    111         }
    112 
    113 
    114        
    115         /**
    116          * Load Text Domain for translations
    117          *
    118          * @since       1.7.0
    119          *
    120          */
    121         public function load_plugin_textdomain()
    122         {
    123            
    124             // set text-domain ##
    125             $domain = self::text_domain;
    126            
    127             // The "plugin_locale" filter is also used in load_plugin_textdomain()
    128             $locale = apply_filters('plugin_locale', get_locale(), $domain);
    129 
    130             // try from global WP location first ##
    131             load_textdomain( $domain, WP_LANG_DIR.'/plugins/'.$domain.'-'.$locale.'.mo' );
    132            
    133             // try from plugin last ##
    134             load_plugin_textdomain( $domain, FALSE, plugin_dir_path( __FILE__ ).'library/languages/' );
    135            
    136         }
    137        
    138        
    139        
    140         /**
    141          * Get Plugin URL
    142          *
    143          * @since       0.1
    144          * @param       string      $path   Path to plugin directory
    145          * @return      string      Absoulte URL to plugin directory
    146          */
    147         public static function get_plugin_url( $path = '' )
    148         {
    149 
    150             return plugins_url( $path, __FILE__ );
    151 
    152         }
    153        
    154        
    155         /**
    156          * Get Plugin Path
    157          *
    158          * @since       0.1
    159          * @param       string      $path   Path to plugin directory
    160          * @return      string      Absoulte URL to plugin directory
    161          */
    162         public static function get_plugin_path( $path = '' )
    163         {
    164 
    165             return plugin_dir_path( __FILE__ ).$path;
    166 
    167         }
    168        
    169 
    170         /**
    171         * Load Libraries
    172         *
    173         * @since        2.0
    174         */
    175         private static function load_libraries()
    176         {
    177 
    178             // vendor ##
    179             require_once self::get_plugin_path( 'vendor/PHP_XLSXWriter/xlsxwriter.class.php' );
    180 
    181             // methods ##
    182             require_once self::get_plugin_path( 'library/core/helper.php' );
    183             require_once self::get_plugin_path( 'library/core/core.php' );
    184             require_once self::get_plugin_path( 'library/core/user.php' );
    185             require_once self::get_plugin_path( 'library/core/buddypress.php' );
    186             // require_once self::get_plugin_path( 'library/core/excel2003.php' );
    187             require_once self::get_plugin_path( 'library/core/export.php' );
    188             require_once self::get_plugin_path( 'library/core/filters.php' );
    189 
    190             // api ##
    191             require_once self::get_plugin_path( 'library/api/admin.php' );
    192 
    193             // backend ##
    194             require_once self::get_plugin_path( 'library/admin/admin.php' );
    195            
    196         }
    197 
    198     }
     60    // nothing else to do here ##
     61    return;
    19962
    20063}
     64
     65// fire hooks - build log, helper and config objects and translations ##
     66\add_action( 'init', function() use( $plugin ){
     67
     68    // set text domain on init hook ##
     69    \add_action( 'init', [ $plugin, 'load_plugin_textdomain' ], 1 );
     70   
     71    // check debug settings ##
     72    \add_action( 'plugins_loaded', [ $plugin, 'debug' ], 11 );
     73
     74}, 0 );
     75
     76// build export object ##
     77$export = new eud\core\export( $plugin );
     78
     79// build filters object ##
     80$filters = new eud\core\filters( $plugin );
     81
     82// build user object ##
     83$user = new eud\core\user( $plugin );
     84
     85// build admin object ##
     86$admin = new eud\admin\render( $plugin, $user );
     87
     88// build buddypress object ##
     89// $buddypress = new eud\core\buddypress();
     90
     91if ( \is_admin() ){
     92
     93    // run export ##
     94    \add_action( 'admin_init', [ $export, 'render' ], 1000003 );
     95
     96    // load BP ##
     97    // \add_action( 'admin_init', [ $buddypress, 'load' ], 1000001 );
     98
     99    // EUD - filter key shown ##
     100    \add_filter( 'q/eud/admin/display_key', [ $filters, 'display_key' ], 1, 1 );
     101
     102    // user option ##
     103    \add_action( 'admin_init', [ $user, 'load' ], 1000002 );
     104
     105    // add export menu inside admin ##
     106    \add_action( 'admin_menu', [ $admin, 'add_menu' ] );
     107
     108    // UI style and functionality ##
     109    \add_action( 'admin_enqueue_scripts', [ $admin, 'admin_enqueue_scripts' ], 1 );
     110    \add_action( 'admin_footer', [ $admin, 'jquery' ], 100000 );
     111    \add_action( 'admin_footer', [ $admin, 'css' ], 100000 );
     112
     113}
  • export-user-data/trunk/library/api/admin.php

    r2371571 r2643129  
    33namespace q\eud\api;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
    7 
    8 // load it up ##
    9 #\q\eud\api\admin::run();
    10 
    11 class admin extends \q_export_user_data {
    12 
    13     public static function run()
    14     {
    15 
    16         if ( \is_admin() ) {
    17 
    18             // load standard fields ##
    19             #\add_action( 'admin_init', array( get_class(), 'load' ), 1 );
    20 
    21         }
    22 
    23     }
    24 
    25 
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin;
     8use q\eud\core\core;
     9use q\eud\core\helper as h;
     10
     11class admin {
     12
     13    private $plugin;
     14
     15    function __construct(){
     16
     17        $this->plugin = plugin::get_instance();
     18
     19    }
    2620
    2721    /**
     
    3125    * @return      HTML
    3226    */
    33     public static function render( $array = null )
    34     {
     27    function render( $array = null ){
    3528
    3629        // check if we have any fields to show ##
     
    4033        ) {
    4134
    42             #helper::log( 'No fields found' );
    43 
    44             return false;
    45 
    46         }
    47 
    48         #helper::log( $array );
     35            #h::log( 'No fields found' );
     36
     37            return false;
     38
     39        }
     40
     41        #h::log( $array );
    4942
    5043        // check that we have all required arrays ##
     
    5649        ) {
    5750
    58             #helper::log( 'Missing data' );
     51            #h::log( 'Missing data' );
    5952
    6053            return false;
     
    6861        $array['label'] = \sanitize_key( $array['label'] );
    6962
    70         #helper::log( $array['options'] );
     63        #h::log( $array['options'] );
    7164
    7265        // build out options ##
    7366        if ( ! self::has_options( $array ) ) {
    7467           
    75             #helper::log( 'Missing options for: '.$array['label'] );
     68            #h::log( 'Missing options for: '.$array['label'] );
    7669
    7770            return false;
     
    10497    }
    10598
    106 
    107     public static function has_options( $array = null )
    108     {
     99    public static function has_options( $array = null ){
    109100
    110101        if (
     
    128119    }
    129120
    130 
    131 
    132     public static function build_options( $array = null )
    133     {
     121    public static function build_options( $array = null ){
    134122
    135123        if (
     
    139127        ) {
    140128
    141             #helper::log( 'Error building options for: '.$array['label'] );
     129            #h::log( 'Error building options for: '.$array['label'] );
    142130
    143131            return false;
     
    163151    }
    164152
    165 
    166 
    167     public static function field_select( $array = null )
    168     {
     153    public static function field_select( $array = null ){
    169154
    170155        if (
     
    179164        ) {
    180165
    181             #helper::log( 'Error building select options for: '.$array['label'] );
    182 
    183             return false;
    184 
    185         }
    186 
    187         #helper::log( 'Building select options for: '.$array['label'] );
     166            #h::log( 'Error building select options for: '.$array['label'] );
     167
     168            return false;
     169
     170        }
     171
     172        #h::log( 'Building select options for: '.$array['label'] );
    188173
    189174        // is this a multiselect ? ##
     
    228213    }
    229214
    230 
    231215}
  • export-user-data/trunk/library/core/buddypress.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
    79
    8 // load it up ##
    9 \q\eud\core\buddypress::run();
     10class buddypress {
    1011
    11 class buddypress extends \q_export_user_data {
     12    private $plugin;
    1213
    13     public static function run()
    14     {
     14    function __construct(){
    1515
    16         if ( \is_admin() ) {
     16        $this->plugin = plugin::get_instance();
    1717
    18             // load BP ##
    19             \add_action( 'admin_init', array( get_class(), 'load' ), 1000001 );
    20 
    21         }
    22 
    23     }
    24 
     18    }
    2519   
    2620    /**
     
    2923    * @since    2.0.0
    3024    */
    31     public static function get_fields()
    32     {
     25    public static function get_fields(){
    3326
    3427        // buddypress support deprecated for now ##
     
    6154    }
    6255
    63 
    64 
    6556    /**
    6657    * Load up saved exports for this user
     
    7061    * @return      Array of saved exports
    7162    */
    72     public static function load()
    73     {
     63    public static function load(){
    7464
    7565        // do we have a bp object in the globals ##
     
    8070        ) {
    8171
    82             helper::log( 'BP not loaded - calling buddypress()' );
     72            h::log( 'BP not loaded - calling buddypress()' );
    8373
    8474            // call BP
    85             buddypress();
     75            \buddypress();
    8676
    8777            return true;
     
    9585    }
    9686
    97 
    98 
    9987}
  • export-user-data/trunk/library/core/config.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
    79
    8 // load it up ##
    9 // \q\eud\core\config::run();
     10class config {
    1011
    11 class config extends \q_export_user_data {
     12    private $plugin;
    1213
    13     public static function run()
    14     {
     14    function __construct(){
    1515
    16         if ( \is_admin() ) {
     16        $this->plugin = plugin::get_instance();
    1717
    18             // load standard fields ##
    19             \add_action( 'admin_init', array( get_class(), 'load' ), 1 );
    20 
    21         }
    22 
    23     }
    24 
    25 
     18    }
    2619
    2720    /**
     
    3225    * @return      Array of saved exports
    3326    */
    34     public static function load()
    35     {
     27    public static function load(){
    3628
    3729        // load api admin fields ##
     
    4335    }
    4436
    45 
    46 
    4737    /**
    4838    * Load up saved exports for this user
     
    5242    * @return      Array of saved exports
    5343    */
    54     public static function get_admin_fields()
    55     {
     44    public function get_admin_fields(){
    5645
    5746        // build array ##
    58         $array = array(
    59             'program' => array(
     47        $array = [
     48            'program' => [
    6049                'title'             => \_e( 'Programs', 'export-user-data' ),
    6150                'label'             => 'program',
    6251                'description'       => \__( 'Select the program that you wish to export.', 'export-user-data' ),
    6352                'label_select'      => \__( 'All Programs', 'export-user-data' ),
    64                 'options'           => \get_posts( array( 'post_type'=> 'program', 'posts_per_page' => -1 ) ),
     53                'options'           => \get_posts([ 'post_type'=> 'program', 'posts_per_page' => -1 ]),
    6554                'options_ID'        => 'ID',
    6655                'options_title'     => 'post_title'
    67             )
    68         );
     56            ]
     57        ];
    6958
    7059        // test it ##
    7160        #self::log( $array );
    7261
    73         // add to static property ##
    74         self::$api_admin_fields = $array;
    75 
    7662        // filter and return ##
    77         apply_filters( 'q/eud/api/admin_fields', self::$api_admin_fields );
     63        apply_filters( 'q/eud/api/admin_fields', $array );
    7864
    7965        // test it ##
    80         self::log( self::$api_admin_fields );
     66        // h::log( $array );
     67       
     68        // add to static property ##
     69        // self::$api_admin_fields = $array;
     70        $this->plugin->set( '_api_admin_fields', $array );
    8171
    82         // kick it back ##
     72        // kick back true ##
    8373        return true;
    8474
    8575    }
    8676
    87 
    8877}
  • export-user-data/trunk/library/core/export.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
    7 // use q\eud\core\excel2003 as excel2003;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
     9use q\eud\core\method;
    810use XLSXWriter;
    911
    10 // load it up ##
    11 \q\eud\core\export::run();
    12 
    13 class export extends \q_export_user_data {
    14 
    15     public static function run()
    16     {
    17 
    18         if ( \is_admin() ) {
    19 
    20             // run export ##
    21             \add_action( 'admin_init', array( get_class(), 'render' ), 1000003 );
    22 
    23         }
    24 
    25     }
    26 
     12class export {
     13
     14    private $plugin;
     15
     16    function __construct( \q\eud\plugin $plugin ){
     17
     18        $this->plugin = $plugin;
     19
     20    }
    2721
    2822    /**
    29     * Attempt to generate the export file based on the passed arguements
    30     *
    31     * @since 0.1
    32     * @return Mixes
    33     **/
    34     public static function render()
    35     {
     23     * Attempt to generate the export file based on the passed arguements
     24     *
     25     * @since   0.1
     26     * @return  mixed
     27     */
     28    public function render(){
    3629
    3730        // Check if the user clicked on the Save, Load, or Delete Settings buttons ##
     
    5851            'fields'    => ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) ?
    5952                            'all' :
    60                             array( 'ID' ), // exclude standard wp_users fields from get_users query ##
     53                            [ 'ID' ], // exclude standard wp_users fields from get_users query ##
    6154            'role'      => \sanitize_text_field( $_POST['role'] )
    6255        );
     
    7568
    7669                // test it ##
    77                 helper::log( $args );
     70                // h::log( $args );
    7871
    7972            }
     
    8477        $args = \apply_filters( 'q/eud/export/args', $args );
    8578
    86         #helper::log( $args );
     79        #h::log( $args );
    8780
    8881        // pre_user query ##
    89         \add_action( 'pre_user_query', array( get_class(), 'pre_user_query' ) );
     82        \add_action( 'pre_user_query', [ $this, 'pre_user_query' ] );
    9083        $users = \get_users( $args );
    91         \remove_action( 'pre_user_query', array( get_class(), 'pre_user_query' ) );
     84        \remove_action( 'pre_user_query', [ $this, 'pre_user_query' ] );
    9285
    9386        // test args ##
    94         #if ( self::$debug ) helper::log ( $users );
     87        #h::log ( $users );
    9588
    9689        // no users found, so chuck an error into the args array and exit the export ##
     
    202195                $doc_end    = "";
    203196
    204                 $writer = new XLSXWriter();
     197                $writer = new \XLSXWriter();
    205198               
    206199            break;
     
    211204        // check for selected usermeta fields ##
    212205        $usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: '';
    213         #helper::log( $usermeta );
    214         $usermeta_fields = array();
     206        #h::log( $usermeta );
     207        $usermeta_fields = [];
    215208
    216209        // loop over each field and sanitize ## @todo - user array_map ##
     
    221214        }
    222215
    223         #helper::log( $usermeta_fields );
     216        #h::log( $usermeta_fields );
    224217        #exit;
    225218
     
    262255
    263256        // debug ##
    264         #helper::log( 'merging array' );
     257        #h::log( 'merging array' );
    265258
    266259        // compile final fields list ##
    267260        $fields = array_merge(
    268                 core::get_user_fields() // standard wp_user fields ##
    269             ,   core::get_special_fields() // 'special' fields - which are controlled via dedicated checks ##
     261                get::user_fields() // standard wp_user fields ##
     262            ,   get::special_fields() // 'special' fields - which are controlled via dedicated checks ##
    270263            ,   $usermeta_fields // wp_user_meta fields ##
    271             ,   $bp_fields_passed // selected buddypress fields ##
    272             ,   $bp_fields_update_passed // update date for buddypress fields ##
     264            // ,    $bp_fields_passed // selected buddypress fields ##
     265            // ,    $bp_fields_update_passed // update date for buddypress fields ##
    273266        );
    274267
    275268        // test field array ##
    276         #helper::log( $fields );
     269        #h::log( $fields );
    277270
    278271        // build the document headers ##
     
    281274        foreach ( $fields as $key => $field ) {
    282275
    283             #helper::log( 'Field: '. $field );
     276            #h::log( 'Field: '. $field );
    284277
    285278            // filter field name ##
     
    287280
    288281            // grab fields to exclude from exports - filterable ##
    289             if ( in_array( $fields[$key], core::get_exclude_fields() ) ) {
    290 
    291                 #helper::log( 'Dump Field: '. $fields[$key] );
     282            if ( in_array( $fields[$key], get::exclude_fields() ) ) {
     283
     284                #h::log( 'Dump Field: '. $fields[$key] );
    292285
    293286                // ditch 'em ##
     
    311304
    312305        // quick check ##
    313         #helper::log( $fields );
    314         #if ( self::$debug ) #helper::log( $bp_fields_passed );
     306        #h::log( $fields );
     307        #h::log( $bp_fields_passed );
    315308
    316309        // no more buffering while spitting back the export data ##
     
    319312        // get the value in bytes allocated for Memory via php.ini ##
    320313        // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue
    321         $memory_limit = core::return_bytes( ini_get('memory_limit') ) * .75;
     314        $memory_limit = helper::return_bytes( ini_get('memory_limit') ) * .75;
    322315
    323316        // we need to disable caching while exporting because we export so much data that it could blow the memory cache
     
    339332        }
    340333
    341 
    342         if ($export_method !== "excel2007") {
     334        if ( $export_method !== "excel2007" ) {
    343335            // open doc wrapper.. ##
    344336            echo $doc_begin;
     
    347339            echo $pre . implode( $seperator, $headers ) . $breaker;
    348340
    349             #helper::log( $users );
     341            #h::log( $users );
    350342        } else {
    351343
    352             $xlsx_header = array_flip($headers);
     344            $xlsx_header = array_flip( $headers );
    353345
    354346            foreach($xlsx_header as $k => $v) {
     
    356348            }
    357349
    358             $writer->writeSheetHeader('Sheet1', $xlsx_header);
     350            $writer->writeSheetHeader('Sheet1', $xlsx_header);
     351           
    359352        }
    360353
     
    362355        foreach ( $users as $user ) {
    363356
    364             #helper::log( $user );
     357            #h::log( $user );
    365358
    366359            // check if we're hitting any Memory limits, if so flush them out ##
     
    375368            // BP loaded ? ##
    376369            if (
    377                 ! self::$bp_data_available
     370                ! $this->plugin->get( '_bp_data_available' )
    378371                && function_exists ( 'bp_is_active' )
    379372                && \bp_is_active( 'xprofile' )
     
    383376            ) {
    384377
    385                 helper::log( 'XProfile Accessible' );
    386                 self::$bp_data_available = true; // we only need to check for BP once ##
     378                // h::log( 'XProfile Accessible' );
     379                $this->plugin->set( '_bp_data_available', true ); // we only need to check for BP once ##
    387380
    388381            }
     
    390383            // grab all user data ##
    391384            if (
    392                 self::$bp_data_available
     385                $this->plugin->get( '_bp_data_available' )
    393386                && ! $bp_data = \BP_XProfile_ProfileData::get_all_for_user( $user->ID )
    394387            ) {
     
    397390                $bp_data = false;
    398391
    399                 helper::log( 'XProfile returned no data ID#: '.$user->ID );
     392                // h::log( 'XProfile returned no data ID#: '.$user->ID );
    400393
    401394            }
     
    403396            // single query method - get all user_meta data ##
    404397            $get_user_meta = (array)\get_user_meta( $user->ID );
    405             #helper::log( $get_user_meta );
     398            #h::log( $get_user_meta );
    406399
    407400            // loop over each field ##
     
    443436
    444437                // check if this is a BP field we want the updated date for ##
    445                 }
    446                 elseif ( in_array( $field, $bp_fields_update_passed ) )
    447                 {
     438                } elseif ( in_array( $field, $bp_fields_update_passed ) ) {
    448439
    449440                    global $bp;
     
    464455
    465456                // include the user's role in the export ##
    466                 }
    467                 elseif ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] && $field == 'roles' )
    468                 {
     457                } elseif ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] && $field == 'roles' ) {
    469458
    470459                    // empty array ##
     
    482471
    483472                    // test ##
    484                     // helper::log( $user_roles );
    485 
    486                      // empty value if no role found - or flat array of user roles ##
    487                     $value = ! empty( $user_roles ) ? implode( $user_roles, '|' ) : '';
     473                    // h::log( $user_roles );
     474
     475                    // empty value if no role found - or flat array of user roles ##
     476                    $value =
     477                        ! empty( $user_roles ) ?
     478                        helper::json_encode( $user_roles ) /*implode( '|', $user_roles )*/ :
     479                        '';
    488480
    489481                // include the user's BP group in the export ##
    490                 }
    491                 elseif ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] && $field == 'groups' )
    492                 {
     482                } elseif ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] && $field == 'groups' ) {
    493483
    494484                    if ( function_exists( 'groups_get_user_groups' ) ) {
     
    497487                        $group_ids = \groups_get_user_groups( $user->ID );
    498488
    499                         #$this->pr( $group_ids );
    500                         #wp_die( pr( 'loaded group data.' ));
     489                        #h::log( $group_ids );
    501490
    502491                        if ( ! $group_ids || $group_ids == '' ) {
     
    517506
    518507                            // implode it ##
    519                             $value = implode( $groups, '|' );
     508                            // $value = implode( $groups, '|' );
     509                            $value = helper::json_encode( $groups );
    520510
    521511                        }
     
    527517                    }
    528518
    529                 }
    530                 elseif ( $field == 'bp_latest_update' || $field == 'last_activity' )
    531                 {
     519                /*
     520                } elseif (
     521                    ( $field == 'bp_latest_update' && function_exists( 'bp_get_user_last_activity' ) )
     522                    || $field == 'last_activity'
     523                ){
    532524
    533525                    // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ##
    534526                    $value = \bp_get_user_last_activity( $user->ID );
     527                */
    535528
    536529                // user or usermeta field ##
    537                 }
    538                 else
    539                 {
     530                } else {
    540531
    541532                    // the user_meta key isset ##
    542                     if ( isset( $get_user_meta[$field] ) ) {
     533                    if (
     534                        isset( $get_user_meta[$field] )
     535                        && is_array( $get_user_meta[$field] )
     536                    ){
    543537
    544538                        // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ##
     
    553547                    }
    554548
    555 
    556                     // the $value might be serialized ##
    557                     $value = core::unserialize( $value );
    558 
    559                     // the value is an array ##
    560                     if ( is_array ( $value ) ) {
    561 
    562                         // recursive implode it ##
    563                         $value = core::recursive_implode( $value );
    564 
    565                     }
    566 
    567                     // sanitize ##
    568                     #$value = $this->sanitize($value);
    569 
    570549                }
    571550
     551                // ---------- cleanup and format the value, before exporting ##
     552
     553                // the $value might be serialized, so try to unserialize ##
     554                $value = helper::unserialize( $value );
     555
     556                // the value is an array ##
     557                if (
     558                    is_array ( $value )
     559                    || is_object ( $value )
     560                ){
     561
     562                    helper::log( 'is_array || is_object' );
     563                    helper::log( $value );
     564
     565                    // recursive implode it ##
     566                    // $value = helper::recursive_implode( $value );
     567
     568                    // json_encode value to object
     569                    $value = helper::json_encode( $value );
     570
     571                // } else {
     572
     573                }
     574
     575                    // sanitize string value ##
     576                    $value = helper::sanitize( $value );
     577
     578                // }
     579
    572580                // filter $value ##
    573                 $value = \apply_filters( 'q/eud/export/value', $value, $field );
     581                // $value = \apply_filters( 'q/eud/export/value', $value, $field );
    574582
    575583                // sanitize ##
    576                 $value = core::sanitize( $value );
     584                // $value = helper::sanitize( $value );
     585
     586                // if no filter is added, apply default sanitiziation ##
     587                // if( has_filter( 'q/eud/export/value' ) ){
     588
     589                    // $value = \apply_filters( 'q/eud/export/value', $value );
     590
     591                // } else {
     592
     593                    // $value = helper::format_value( $value );
     594
     595                // }   
     596
     597                // helper::log( $value );
    577598
    578599                // wrap values in quotes and add to array ##
    579600                if ( $is_csv ) {
    580601
    581                     $data[] = '"' . str_replace( '"', '""', core::format_value( $value ) ) . '"';
     602                    // replace single-double quotes with double-double quotes, if not dealing with a JSON string ###
     603                    // if( ! helper::is_json( $value ) ) {
     604                   
     605                        // $value = str_replace( '"', '\"', $value );
     606
     607                    // }
     608
     609                    // wrap value in double quotes ##
     610                    $value = '"' . $value . '"';
     611
     612                    // helper::log( $value );
     613
     614                    // add value to $data array  ##
     615                    $data[] = $value;
    582616
    583617                // just add to array ##
    584618                } else {
    585619
    586                     $data[] = core::format_value( $value );
     620                    $data[] = $value;
     621
    587622                }
    588623
    589624            }
    590625
    591             if ($export_method !== "excel2007") {
    592                 // echo row data ##
    593                 echo $pre . implode( $seperator, $data ) . $breaker;
     626            if ( $export_method !== "excel2007" ) {
     627               
     628                // echo row data ##
     629                echo $pre . implode( $seperator, $data ) . $breaker;
     630               
    594631            } else {
    595                 $writer->writeSheetRow('Sheet1', $data);
    596             }
    597 
    598         }
    599 
    600         if ($export_method !== "excel2007") {
     632
     633                $writer->writeSheetRow( 'Sheet1', $data );
     634               
     635            }
     636
     637        }
     638
     639        if ( $export_method !== "excel2007" ) {
     640
    601641            // close doc wrapper..
    602             echo $doc_end;
     642            echo $doc_end;
     643           
    603644        } else {
    604             //$writer->writeSheet($rows,'Sheet1', $header); //or write the whole sheet in 1 call
    605             //$writer->writeToFile('xlsx-simple.xlsx');
    606             //$writer->writeToStdOut();
    607             echo $writer->writeToString();
     645           
     646            echo $writer->writeToString();
     647           
    608648        }
    609649
     
    612652
    613653    }
    614 
    615 
    616    
    617654   
    618655    /**
     
    621658    * @since        2.0.0
    622659    */
    623     public static function pre_user_query( $user_search = null )
    624     {
     660    function pre_user_query( $user_search = null ){
    625661
    626662        global $wpdb;
     
    652688        ) {
    653689
    654             $last_updated_date = new \DateTime( \sanitize_text_field ( $_POST['updated_since_date'] ) . ' 00:00:00' );
    655             self::$updated_since_date = $last_updated_date->format( 'Y-m-d H:i:s' );
    656             self::$field_updated_since = \sanitize_text_field ( $_POST['bp_field_updated_since'] );
    657             $field_updated_since_id = \BP_Xprofile_Field::get_id_from_name( self::$field_updated_since );
    658             $user_search->query_from .=  " JOIN `wp_bp_xprofile_data` XP ON XP.user_id = wp_users.ID ";
    659             $where .= $wpdb->prepare( " AND XP.field_id = %s AND XP.last_updated >= %s", $field_updated_since_id, self::$updated_since_date );
     690            // get last update string ##
     691            $last_updated_date = new \DateTime( \sanitize_text_field ( $_POST['updated_since_date'] ) . ' 00:00:00' );
     692           
     693            // set date ##
     694            $this->plugin->set( '_updated_since_date', $last_updated_date->format( 'Y-m-d H:i:s' ) );
     695           
     696            // set field ##
     697            $this->plugin->set( '_field_updated_since', \sanitize_text_field ( $_POST['bp_field_updated_since'] ) );
     698            $field_updated_since_id = \BP_Xprofile_Field::get_id_from_name( $this->plugin->get( '_field_updated_since' ) );
     699            $user_search->query_from .=  " JOIN `wp_bp_xprofile_data` XP ON XP.user_id = wp_users.ID ";
     700           
     701            // set where string ##
     702            $where .= $wpdb->prepare( " AND XP.field_id = %s AND XP.last_updated >= %s", $field_updated_since_id, $this->plugin->get( '_updated_since_date' ) );
    660703
    661704        }
     
    667710        }
    668711
    669         #wp_die( self::$pr( $user_search ) );
     712        #h::log( $user_search ) );
    670713        return $user_search;
    671714
    672715    }
    673716
    674 
    675 
    676717}
  • export-user-data/trunk/library/core/filters.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
    79
    8 // load it up ##
    9 \q\eud\core\filters::run();
     10class filters {
    1011
    11 class filters extends \q_export_user_data {
     12    private $plugin;
    1213
    13     public static function run()
    14     {
     14    function __construct( \q\eud\plugin $plugin ){
    1515
    16         if ( \is_admin() ) {
     16        $this->plugin = $plugin;
    1717
    18             // EUD - filter key shown ##
    19             \add_filter( 'q/eud/admin/display_key', [ get_class(), 'display_key' ], 1, 1 );
    20 
    21         }
    22 
    23     }
    24 
     18    }
    2519
    2620    /**
     
    2923    * @since 2.0.0
    3024    */
    31     public static function display_key( $string = null )
    32     {
     25    public static function display_key( $string = null ){
    3326
    3427        #helper::log( 'string from filter: '.$string );
  • export-user-data/trunk/library/core/helper.php

    r2371571 r2643129  
    88 * @package   q_eud\core
    99 */
    10 class helper extends \q_export_user_data {
    11 
    12      
     10class helper {
     11
    1312    /**
    1413     * Write to WP Error Log
     
    1716     * @return      void
    1817     */
    19     public static function log( $log )
    20     {
    21 
    22         if ( true === WP_DEBUG ) {
     18    public static function log( $log ){
     19
     20        if ( true === \WP_DEBUG ) {
    2321
    2422            $trace = debug_backtrace();
    25             $caller = $trace[1];
     23            $caller = $trace[0];
    2624
    2725            $suffix = sprintf(
     
    4341    }
    4442
     43   
     44    /**
     45    * Return Byte count of $val
     46    *
     47    * @link        http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
     48    * @since       0.9.6
     49    */
     50    public static function return_bytes( $val ){
     51
     52        $val = trim( $val );
     53        $last = strtolower($val[strlen($val)-1]);
     54        switch( $last ) {
     55
     56            // The 'G' modifier is available since PHP 5.1.0
     57            case 'g':
     58
     59                $val *= 1024;
     60
     61            case 'm':
     62
     63                $val *= 1024;
     64
     65            case 'k':
     66
     67                $val *= 1024;
     68
     69        }
     70
     71        return $val;
     72
     73    }
     74
     75    /**
     76    * Recursively implodes an array
     77    *
     78    * @since    1.0.1
     79    * @access   public
     80    * @param    array       $array          multi-dimensional array to recursively implode
     81    * @param    string      $glue           value that glues elements together
     82    * @param    bool        $include_keys   include keys before their values
     83    * @param    bool        $trim_all       trim ALL whitespace from string
     84    * @return   string      imploded array
     85    */
     86    public static function recursive_implode( $array, $return = null, $glue = '|' ){
     87
     88        // unserialize ##
     89        $array = self::unserialize( $array );
     90
     91        // kick it back ##
     92        if ( is_null ( $return ) && ! is_array( $array ) ) {
     93
     94            return $array;
     95
     96        }
     97
     98        // empty return ##
     99        if ( is_null ( $return ) ) {
     100
     101            $return = '';
     102
     103        } else {
     104
     105            if ( "||" == $glue ) {
     106
     107                $glue = '|||';
     108
     109            } else if ( "|" == $glue ) {
     110
     111                $glue = '||';
     112
     113            }
     114
     115        }
     116
     117        // loop ##
     118        foreach( $array as $key => $value ) {
     119
     120            // unserialize ##
     121            $value = self::unserialize( $value );
     122
     123            if( is_array( $value ) ) {
     124
     125                $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
     126               
     127            // add @2.1.0 from issue #4 - https://github.com/qstudio/export-user-data/issues/4
     128            } elseif(is_object($value)) {
     129
     130                $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
     131
     132            } else {
     133
     134                $return .= $glue . $key . $glue . $value;
     135
     136            }
     137           
     138
     139        }
     140
     141        // Removes first $glue from string ##
     142        if ( $glue && $return && $return[0] == '|' ) {
     143
     144            $return = ltrim( $return, '|' );
     145
     146        }
     147
     148        // Trim ALL whitespace ##
     149        if ( $return ) {
     150
     151            $return = preg_replace( "/(\s)/ixsm", '', $return );
     152
     153        }
     154
     155        // kick it back ##
     156        return $return;
     157
     158    }
     159
     160    /**
     161    * Save Unserializer
     162    *
     163    * @since       1.1.4
     164    */
     165    public static function unserialize( $value = null ){
     166
     167        // the $value is serialized ##
     168        if ( \is_serialized( $value ) ) {
     169
     170            // unserliaze to new variable ##
     171            $unserialized = @unserialize( $value );
     172
     173            // test if unserliazing produced errors ##
     174            if (
     175                $unserialized !== false
     176                && $value !== 'b:0;'
     177            ){
     178
     179                h::log( $unserialized );
     180
     181                #$value = 'UNSERIALIZED_'.$unserialized;
     182                $value = $unserialized;
     183
     184            } else {
     185
     186                // failed to unserialize - data potentially corrupted in db ##
     187                #$value = 'NOT_SERIALIZED_'.$value;
     188                $value = $value;
     189
     190            }
     191
     192        }
     193
     194        // kick it back ##
     195        return $value;
     196
     197    }
     198
     199    /**
     200    * Encode special characters
     201    *
     202    * @param        type        $string
     203    * @return       string      Encoding string
     204    * @since        1.2.3
     205    */
     206    public static function format_value( string $value = null )
     207    {
     208
     209        // sanity check ##
     210        if ( is_null( $value ) ) {
     211
     212            return false;
     213
     214        }
     215
     216        if( has_filter( 'q/eud/export/value' ) ){
     217
     218            $value = \apply_filters( 'q/eud/export/value', $value );
     219
     220        } else {
     221
     222            $value = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
     223
     224        }
     225
     226        // if value is a JSON_ENCODE'd string, then do not sanitize ##
     227        // if( self::is_json( $value ) ){
     228
     229            // do we need to apply some escpaping ?? ##
     230
     231            // return $value;
     232
     233        // }
     234
     235        // sanitize ##
     236        // $value = self::sanitize( $value );
     237
     238        // if no filter is added, apply default sanitiziation ##
     239        // if( ! has_filter( 'q/eud/export/value' ) ){
     240
     241       
     242
     243        // }
     244
     245        // self::log( $value );
     246       
     247        // kick it back via a filter to allow custom formatting ##
     248        return $value;
     249
     250    }
     251
     252    /**
     253     * Encode array values to JSON string
     254     *
     255     * @since 2.2.1
     256     * @param   mixed
     257     * @return  mixed   string|null
     258    */
     259    public static function json_encode( array $value ):?string
     260    {
     261
     262        if ( ! is_array( $value ) ){
     263
     264            return $value;
     265
     266        }
     267
     268        // cleanup array ##
     269        $value = array_values( $value );
     270
     271        // encode and escape ##
     272        $value = htmlspecialchars( json_encode( $value, JSON_FORCE_OBJECT ) );
     273
     274        // self::log( $value );
     275
     276        // kick back JSON encoded string ##
     277        return $value;
     278
     279    }
     280
     281    /**
     282    * Quote array elements and separate with commas
     283    *
     284    * @since       0.9.6
     285    * @return      String
     286    */
     287    public static function quote_array( $array ){
     288
     289        $prefix = ''; // starts empty ##
     290        $string = '';
     291
     292        if ( is_array( $array ) ) {
     293       
     294            foreach( $array as $element ) {
     295       
     296                $string .= $prefix . "'" . $element . "'";
     297                $prefix = ','; // prefix all remaining items with a comma ##
     298       
     299            }
     300       
     301        }
     302
     303        // kick back string to function caller ##
     304        return( $string );
     305
     306    }
     307
     308    /**
     309    * Export Date Options
     310    *
     311    * @since       0.9.6
     312    * @global      type    $wpdb
     313    * @return      Array of objects
     314    * @todo         Remove max date, as this makes little sense for exports not based on user reg dates.. ??   
     315    */
     316    public static function get_user_registered_dates(){
     317
     318        // invite in global objects ##
     319        global $wpdb;
     320
     321        // query user table for oldest and newest registration ##
     322        $range =
     323            $wpdb->get_results (
     324                #$wpdb->prepare (
     325                    "
     326                    SELECT
     327                        MIN( user_registered ) AS first,
     328                        MAX( user_registered ) AS last
     329                    FROM
     330                        {$wpdb->users}
     331                    "
     332                #)
     333            );
     334
     335        return $range;
     336
     337    }
     338
     339    /**
     340    * Sanitize data
     341    *
     342    * @since 1.2.8
     343    * @return string
     344    */
     345    public static function sanitize_value( $value ){
     346
     347        // if value is a JSON_ENCODE'd string, then do not sanitize ##
     348        // if( self::is_json( $value ) ){
     349
     350        //  // do we need to apply some escpaping ?? ##
     351
     352        //  return $value;
     353
     354        // }
     355
     356        // self::log( 'sanitize: '.$value );
     357
     358        if( has_filter( 'q/eud/export/value' ) ){
     359
     360            $value = \apply_filters( 'q/eud/export/value', $value );
     361
     362        } else {
     363
     364            $value = htmlentities( $value, ENT_COMPAT|ENT_COMPAT, 'UTF-8' );
     365            // $value = \esc_attr( $value );
     366
     367        }
     368
     369        // remove line breaks ##
     370        // $value = str_replace("\r", '', $value);
     371        // $value = str_replace("\n", '', $value);
     372        // $value = str_replace("\t", '', $value);
     373
     374        // with wp_kses ##
     375        // $value = \wp_kses( $value, self::get_allowed_tags() );
     376
     377        // return value ##
     378        return $value;
     379
     380    }
     381
     382    public static function sanitize( $value ) {
     383
     384        if ( is_array( $value ) ) {
     385
     386            array_walk_recursive( $value, [ __CLASS__, 'sanitize_value' ] );
     387
     388        } else {
     389
     390            self::sanitize_value( $value );
     391
     392        }
     393
     394        return $value;
     395
     396    }
     397
     398    /**
     399     * Check if a string is JSON
     400     *
     401     * @since 2.0.2
     402    */
     403    public static function is_json( $string )
     404    {
     405   
     406        json_decode( $string );
     407
     408        if ( json_last_error() === JSON_ERROR_NONE ){
     409
     410            // self::log( 'is_json: '.$string );
     411
     412            return true;
     413
     414        }
     415
     416        // self::log( 'is not json: '.$string );
     417
     418        return false;
     419   
     420    }
     421
     422    /**
     423    * Get allowed tags for wp_kses
     424    *
     425    * @since  1.2.8
     426    * @return Array
     427    */
     428    public static function get_allowed_tags(){
     429
     430        $allowed_tags = [
     431            'a' => [
     432                'href' => [],
     433                'title' => []
     434            ],
     435            'br' => [],
     436            'em' => [],
     437            'strong' => [],
     438        ];
     439
     440        // kick back via filter ##
     441        return \apply_filters( 'q/eud/export/allowed_tags', $allowed_tags );
     442
     443    }
    45444
    46445}
  • export-user-data/trunk/library/core/user.php

    r2371571 r2643129  
    33namespace q\eud\core;
    44
    5 use q\eud\core\core as core;
    6 use q\eud\core\helper as helper;
    7 
    8 // load it up ##
    9 \q\eud\core\user::run();
    10 
    11 class user extends \q_export_user_data {
    12 
    13     public static function run()
    14     {
    15 
    16         if ( \is_admin() ) {
    17 
    18             // load user options ##
    19             \add_action( 'admin_init', array( get_class(), 'load' ), 1000002 );
    20 
    21         }
    22 
    23     }
    24 
     5// import classes ##
     6use q\eud;
     7use q\eud\plugin as plugin;
     8use q\eud\core\helper as h;
     9
     10class user {
     11
     12    private $plugin;
     13
     14    public function __construct( \q\eud\plugin $plugin ){
     15
     16        $this->plugin = $plugin;
     17
     18    }
    2519
    2620    /**
     
    3125    * @return      Array of saved exports
    3226    */
    33     public static function load()
    34     {
     27    public function load(){
    3528
    3629        // convert outdated stored meta from q_report to q_eud_exports ##
     
    5245
    5346        // test #
    54         // helper::log( \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) );
    55 
    56         return self::$q_eud_exports =
    57             \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ?
    58             \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) :
    59             array() ;
     47        // h::log( \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) );
     48
     49        // get array ##
     50        $array =
     51            \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ?
     52            \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) :
     53            [] ;
     54
     55        // set prop ##
     56        $this->plugin->set( '_q_eud_exports', $array );
     57
     58        // return bool ##
     59        return true;
    6060           
    6161    }
    6262
    63 
    64 
    65 
    6663    /**
    6764    * Get list of saved exports for this user
     
    7067    * @return      Array of saved exports
    7168    */
    72     public static function get_user_options()
    73     {
     69    function get_user_options(){
     70
     71        // get props ##
     72        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
    7473
    7574        // get the stored options - filter empty array items ##
    76         $q_eud_exports = array_filter( self::$q_eud_exports );
     75        $_q_eud_exports = array_filter( $_q_eud_exports );
    7776
    7877        // quick check if the array is empty ##
    79         if ( empty ( $q_eud_exports ) ) {
     78        if ( empty ( $_q_eud_exports ) ) {
    8079
    8180            return false;
     
    8483
    8584        // test the array of saved exports ##
    86         #$this->pr( $q_eud_exports );
     85        #h::log( $_q_eud_exports );
    8786
    8887        // start with an empty array ##
    89         $exports = array();
     88        $exports = [];
    9089
    9190        // loop over each saved export and grab each key ##
    92         foreach ( $q_eud_exports as $key => $value ) {
     91        foreach ( $_q_eud_exports as $key => $value ) {
    9392
    9493            $exports[] = $key;
     
    101100    }
    102101
    103 
    104102    /**
    105103    * Check for and load stored user options
     
    108106    * @return      void
    109107    */
    110     public static function get_user_options_by_export( $export = null )
    111     {
     108    function get_user_options_by_export( $export = null ){
    112109
    113110        // sanity check ##
    114         if ( is_null ( $export ) ) { return false; }
    115 
    116         if ( isset( self::$q_eud_exports[$export] ) ) {
    117 
    118             self::$usermeta_saved_fields = self::$q_eud_exports[$export]['usermeta_saved_fields'];
    119             self::$bp_fields_saved_fields = self::$q_eud_exports[$export]['bp_fields_saved_fields'];
    120             self::$bp_fields_update_time_saved_fields = self::$q_eud_exports[$export]['bp_fields_update_time_saved_fields'];
    121             self::$updated_since_date = isset( self::$q_eud_exports[$export]['updated_since_date'] ) ? self::$q_eud_exports[$export]['updated_since_date'] : null ;
    122             self::$field_updated_since = isset( self::$q_eud_exports[$export]['field_updated_since'] ) ? self::$q_eud_exports[$export]['field_updated_since'] : null ;
    123             self::$role = self::$q_eud_exports[$export]['role'];
    124             self::$roles = self::$q_eud_exports[$export]['roles'];
    125             self::$groups = self::$q_eud_exports[$export]['groups'];
    126             self::$user_fields = isset( self::$q_eud_exports[$export]['user_fields'] ) ? self::$q_eud_exports[$export]['user_fields'] : null ;
    127             self::$start_date = self::$q_eud_exports[$export]['start_date'];
    128             self::$end_date = self::$q_eud_exports[$export]['end_date'];
    129             self::$limit_offset = self::$q_eud_exports[$export]['limit_offset'];
    130             self::$limit_total = self::$q_eud_exports[$export]['limit_total'];
    131             self::$format = self::$q_eud_exports[$export]['format'];
     111        if ( is_null ( $export ) ) { return false; }
     112       
     113        // get props ##
     114        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
     115
     116        if ( isset( $_q_eud_exports[$export] ) ) {
     117
     118            $_usermeta_saved_fields = $_q_eud_exports[$export]['usermeta_saved_fields'];
     119            // $_bp_fields_saved_fields = $_q_eud_exports[$export]['bp_fields_saved_fields'];
     120            // $_bp_fields_update_time_saved_fields = $_q_eud_exports[$export]['bp_fields_update_time_saved_fields'];
     121            $_updated_since_date = $_q_eud_exports[$export]['updated_since_date'] ?? null ;
     122            $_field_updated_since = $_q_eud_exports[$export]['field_updated_since'] ?? null ;
     123            $_role = $_q_eud_exports[$export]['role'];
     124            $_roles = $_q_eud_exports[$export]['roles'];
     125            $_groups = $_q_eud_exports[$export]['groups'];
     126            $_user_fields = $_q_eud_exports[$export]['user_fields'] ?? null ;
     127            $_start_date = $_q_eud_exports[$export]['start_date'];
     128            $_end_date = $_q_eud_exports[$export]['end_date'];
     129            $_limit_offset = $_q_eud_exports[$export]['limit_offset'];
     130            $_limit_total = $_q_eud_exports[$export]['limit_total'];
     131            $_format = $_q_eud_exports[$export]['format'];
    132132
    133133        } else {
    134134
    135             self::$usermeta_saved_fields = array();
    136             self::$bp_fields_saved_fields = array();
    137             self::$bp_fields_update_time_saved_fields = array();
    138             self::$updated_since_date = '';
    139             self::$field_updated_since = '';
    140             self::$role = '';
    141             self::$user_fields = '1';
    142             self::$roles = '1';
    143             self::$groups = '1';
    144             self::$start_date = '';
    145             self::$end_date = '';
    146             self::$limit_offset = '';
    147             self::$limit_total = '';
    148             self::$format = '';
    149 
    150         }
    151 
    152     }
    153 
     135            $_usermeta_saved_fields = [];
     136            // $_bp_fields_saved_fields = [];
     137            // $_bp_fields_update_time_saved_fields = [];
     138            $_updated_since_date = '';
     139            $_field_updated_since = '';
     140            $_role = '';
     141            $_user_fields = '1';
     142            $_roles = '1';
     143            $_groups = '1';
     144            $_start_date = '';
     145            $_end_date = '';
     146            $_limit_offset = '';
     147            $_limit_total = '';
     148            $_format = '';
     149
     150        }
     151       
     152        // set props ##
     153        $this->plugin->set( '_usermeta_saved_fields', $_usermeta_saved_fields );
     154        // $this->plugin->set( '_bp_fields_saved_fields', $_bp_fields_saved_fields );
     155        // $this->plugin->set( '_bp_fields_update_time_saved_fields', $_bp_fields_update_time_saved_fields );
     156        $this->plugin->set( '_updated_since_date', $_updated_since_date );
     157        $this->plugin->set( '_field_updated_since', $_field_updated_since );
     158        $this->plugin->set( '_role', $_role );
     159        $this->plugin->set( '_user_fields', $_user_fields );
     160        $this->plugin->set( '_roles', $_roles );
     161        $this->plugin->set( '_groups', $_groups );
     162        $this->plugin->set( '_start_date', $_start_date );
     163        $this->plugin->set( '_end_date', $_end_date );
     164        $this->plugin->set( '_limit_offset', $_limit_offset );
     165        $this->plugin->set( '_limit_total', $_limit_total );
     166        $this->plugin->set( '_format', $_format );
     167
     168    }
    154169
    155170    /**
     
    161176    * @return      void
    162177    */
    163     public static function set_user_options( $key = null, $options = null )
    164     {
     178    function set_user_options( $key = null, $options = null ){
    165179
    166180        // sanity check ##
    167181        if ( is_null ( $key ) || is_null ( $options ) ) {
    168182
    169             #$this->pr( 'missing save values' );
     183            #h::log( 'missing save values' );
    170184            return false;
    171185
    172186        }
    173187
    174         #$this->pr( $key );
    175         #$this->pr( $options );
     188        #h::log( $key );
     189        #h::log( $options );
     190
     191        // get prop ##
     192        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
    176193
    177194        // for now, I'm simply allowing keys to be resaved - but this is not so logical ##
    178         if ( array_key_exists( $key, self::$q_eud_exports ) ) {
    179 
    180             #$this->pr( 'key exists, skipping save' );
     195        if ( array_key_exists( $key, $_q_eud_exports ) ) {
     196
     197            #h::log( 'key exists, skipping save' );
    181198            #return false;
    182199
     
    206223
    207224            // assign the sanitized array of values to the class property $q_eud_exports as a new array with key $key ##
    208             self::$q_eud_exports[$key] = $options;
     225            $_q_eud_exports[$key] = $options;
     226           
     227            // set prop ##
     228            $this->plugin->set( '_q_eud_exports', $_q_eud_exports );
    209229
    210230            // update stored user_meta values, if previous key found ##
    211             if ( \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) !== false ) {
    212 
    213                 #update_option( 'q_eud_exports', $this->q_eud_exports );
    214                 \update_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
     231            if ( false !== \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ) {
     232
     233                \update_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
    215234
    216235            // create new user meta key ##
    217236            } else {
    218237
    219                 #add_option( 'q_eud_exports', $this->q_eud_exports, $deprecated, $autoload );
    220                 \add_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
     238                \add_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
    221239
    222240            }
     
    225243
    226244    }
    227 
    228245
    229246    /**
     
    234251    * @return      void
    235252    */
    236     public static function delete_user_options( $key = null )
    237     {
     253    function delete_user_options( $key = null ){
     254
     255        // get prop ##
     256        $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
    238257
    239258        // sanity check ##
    240         if ( is_null ( $key ) || ! array_key_exists( $key, self::$q_eud_exports ) ) { return false; }
     259        if ( is_null ( $key ) || ! array_key_exists( $key, $_q_eud_exports ) ) { return false; }
    241260
    242261        // clean it up ##
     
    244263
    245264        // check it out ##
    246         #$this->pr( $key );
     265        #h::log( $key );
    247266
    248267        // drop the array by it's key name from the class property ##
    249         unset( self::$q_eud_exports[$key] );
     268        unset( $_q_eud_exports[$key] );
    250269
    251270        // update the saved data ##
    252         \update_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
    253 
    254     }
    255 
    256 
     271        \update_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
     272       
     273        // set prop ##
     274        $this->plugin->set( '_q_eud_exports', $_q_eud_exports );
     275
     276        // done ##
     277        return true;
     278
     279    }
    257280
    258281}
  • export-user-data/trunk/package.json

    r2372271 r2643129  
    11{
    22    "name": "export-user-data",
    3     "version": "2.1.3",
     3    "version": "2.2.1",
    44    "description": "Q Plugins ~ Export User data and metadata",
    55    "author": "Q Studio",
  • export-user-data/trunk/readme.md

    r2372271 r2643129  
    55**Requires PHP:** 6.0 
    66**Requires at least:** 5.0 
    7 **Tested up to:** 5.5 
    8 **Stable tag:** 2.1.3 
     7**Tested up to:** 5.6 
     8**Stable tag:** 2.2.1 
    99**License:** GPLv2 
    1010
  • export-user-data/trunk/readme.txt

    r2372271 r2643129  
    22Contributors: qlstudio
    33Tags: users, export, usermeta, excel   
    4 Requires PHP: 6.0 
     4Requires PHP: 7.0 
    55Requires at least: 4.8 
    6 Tested up to: 5.5 
    7 Stable tag: 2.1.3   
     6Tested up to: 5.6 
     7Stable tag: 2.2.0   
    88License: GPLv2 
    99
Note: See TracChangeset for help on using the changeset viewer.