Changeset 2643129
- Timestamp:
- 12/12/2021 10:31:26 PM (4 years ago)
- Location:
- export-user-data
- Files:
-
- 14 added
- 6 deleted
- 24 edited
- 1 copied
-
tags/2.2.1 (copied) (copied from export-user-data/trunk)
-
tags/2.2.1/CHANGELOG.md (modified) (1 diff)
-
tags/2.2.1/autoload.php (added)
-
tags/2.2.1/export-user-data.php (modified) (1 diff)
-
tags/2.2.1/library/admin/admin.php (deleted)
-
tags/2.2.1/library/admin/render.php (added)
-
tags/2.2.1/library/api/admin.php (modified) (11 diffs)
-
tags/2.2.1/library/api/function.php (added)
-
tags/2.2.1/library/core/.__excel2003.php (added)
-
tags/2.2.1/library/core/.__method.php (added)
-
tags/2.2.1/library/core/buddypress.php (modified) (6 diffs)
-
tags/2.2.1/library/core/config.php (modified) (4 diffs)
-
tags/2.2.1/library/core/core.php (deleted)
-
tags/2.2.1/library/core/excel2003.php (deleted)
-
tags/2.2.1/library/core/export.php (modified) (32 diffs)
-
tags/2.2.1/library/core/filters.php (modified) (2 diffs)
-
tags/2.2.1/library/core/get.php (added)
-
tags/2.2.1/library/core/helper.php (modified) (3 diffs)
-
tags/2.2.1/library/core/user.php (modified) (12 diffs)
-
tags/2.2.1/package.json (modified) (1 diff)
-
tags/2.2.1/plugin.php (added)
-
tags/2.2.1/readme.md (modified) (1 diff)
-
tags/2.2.1/readme.txt (modified) (1 diff)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/autoload.php (added)
-
trunk/export-user-data.php (modified) (1 diff)
-
trunk/library/admin/admin.php (deleted)
-
trunk/library/admin/render.php (added)
-
trunk/library/api/admin.php (modified) (11 diffs)
-
trunk/library/api/function.php (added)
-
trunk/library/core/.__excel2003.php (added)
-
trunk/library/core/.__method.php (added)
-
trunk/library/core/buddypress.php (modified) (6 diffs)
-
trunk/library/core/config.php (modified) (4 diffs)
-
trunk/library/core/core.php (deleted)
-
trunk/library/core/excel2003.php (deleted)
-
trunk/library/core/export.php (modified) (32 diffs)
-
trunk/library/core/filters.php (modified) (2 diffs)
-
trunk/library/core/get.php (added)
-
trunk/library/core/helper.php (modified) (3 diffs)
-
trunk/library/core/user.php (modified) (12 diffs)
-
trunk/package.json (modified) (1 diff)
-
trunk/plugin.php (added)
-
trunk/readme.md (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
export-user-data/tags/2.2.1/CHANGELOG.md
r2372271 r2643129 1 1 ## 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 2 12 3 13 *** 2.1.3 *** 4 14 5 * FIX -wrong name for our own plugin :( thanks @kgagne !15 * FIX: wrong name for our own plugin :( thanks @kgagne ! 6 16 7 17 *** 2.1.2 *** -
export-user-data/tags/2.2.1/export-user-data.php
r2372271 r2643129 1 1 <?php 2 2 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 4 12 * Plugin Name: Export User Data 13 * Plugin URI: http://qstudio.us/releases/export-user-data 5 14 * Description: Export User data and metadata. 6 * Version: 2. 1.315 * Version: 2.2.1 7 16 * 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 12 25 * GitHub Plugin URI: qstudio/export-user-data 13 26 */ 14 27 15 defined( 'ABSPATH' ) OR exit; 28 // namespace plugin ## 29 namespace q\eud; 16 30 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 ## 32 use q\eud; 33 use q\eud\core\helper as h; 50 34 51 // api ## 52 public static $api_admin_fields = false; 35 // If this file is called directly, Bulk! 36 if ( ! defined( 'ABSPATH' ) ) { 37 return; 38 } 53 39 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' ] ); 61 42 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' ] ); 65 45 66 return self::$instance; 46 // required bits to get set-up ## 47 require_once __DIR__ . '/library/api/function.php'; 48 require_once __DIR__ . '/autoload.php'; 49 require_once __DIR__ . '/plugin.php'; 50 require_once __DIR__ . '/vendor/PHP_XLSXWriter/xlsxwriter.class.php'; 67 51 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(); 82 54 83 // deactvation##84 register_deactivation_hook( __FILE__, array ( $this, 'register_deactivation_hook' ) ); 55 // validate instance ## 56 if( ! ( $plugin instanceof \q\eud\plugin ) ) { 85 57 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' ); 91 59 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; 199 62 200 63 } 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 91 if ( \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 3 3 namespace q\eud\api; 4 4 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 ## 6 use q\eud; 7 use q\eud\plugin; 8 use q\eud\core\core; 9 use q\eud\core\helper as h; 10 11 class admin { 12 13 private $plugin; 14 15 function __construct(){ 16 17 $this->plugin = plugin::get_instance(); 18 19 } 26 20 27 21 /** … … 31 25 * @return HTML 32 26 */ 33 public static function render( $array = null ) 34 { 27 function render( $array = null ){ 35 28 36 29 // check if we have any fields to show ## … … 40 33 ) { 41 34 42 #h elper::log( 'No fields found' );43 44 return false; 45 46 } 47 48 #h elper::log( $array );35 #h::log( 'No fields found' ); 36 37 return false; 38 39 } 40 41 #h::log( $array ); 49 42 50 43 // check that we have all required arrays ## … … 56 49 ) { 57 50 58 #h elper::log( 'Missing data' );51 #h::log( 'Missing data' ); 59 52 60 53 return false; … … 68 61 $array['label'] = \sanitize_key( $array['label'] ); 69 62 70 #h elper::log( $array['options'] );63 #h::log( $array['options'] ); 71 64 72 65 // build out options ## 73 66 if ( ! self::has_options( $array ) ) { 74 67 75 #h elper::log( 'Missing options for: '.$array['label'] );68 #h::log( 'Missing options for: '.$array['label'] ); 76 69 77 70 return false; … … 104 97 } 105 98 106 107 public static function has_options( $array = null ) 108 { 99 public static function has_options( $array = null ){ 109 100 110 101 if ( … … 128 119 } 129 120 130 131 132 public static function build_options( $array = null ) 133 { 121 public static function build_options( $array = null ){ 134 122 135 123 if ( … … 139 127 ) { 140 128 141 #h elper::log( 'Error building options for: '.$array['label'] );129 #h::log( 'Error building options for: '.$array['label'] ); 142 130 143 131 return false; … … 163 151 } 164 152 165 166 167 public static function field_select( $array = null ) 168 { 153 public static function field_select( $array = null ){ 169 154 170 155 if ( … … 179 164 ) { 180 165 181 #h elper::log( 'Error building select options for: '.$array['label'] );182 183 return false; 184 185 } 186 187 #h elper::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'] ); 188 173 189 174 // is this a multiselect ? ## … … 228 213 } 229 214 230 231 215 } -
export-user-data/tags/2.2.1/library/core/buddypress.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 5 use q\eud\core\core as core; 6 use q\eud\core\helper as helper; 5 // import classes ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 7 9 8 // load it up ## 9 \q\eud\core\buddypress::run(); 10 class buddypress { 10 11 11 class buddypress extends \q_export_user_data { 12 private $plugin; 12 13 13 public static function run() 14 { 14 function __construct(){ 15 15 16 if ( \is_admin() ) { 16 $this->plugin = plugin::get_instance(); 17 17 18 // load BP ## 19 \add_action( 'admin_init', array( get_class(), 'load' ), 1000001 ); 20 21 } 22 23 } 24 18 } 25 19 26 20 /** … … 29 23 * @since 2.0.0 30 24 */ 31 public static function get_fields() 32 { 25 public static function get_fields(){ 33 26 34 27 // buddypress support deprecated for now ## … … 61 54 } 62 55 63 64 65 56 /** 66 57 * Load up saved exports for this user … … 70 61 * @return Array of saved exports 71 62 */ 72 public static function load() 73 { 63 public static function load(){ 74 64 75 65 // do we have a bp object in the globals ## … … 80 70 ) { 81 71 82 h elper::log( 'BP not loaded - calling buddypress()' );72 h::log( 'BP not loaded - calling buddypress()' ); 83 73 84 74 // call BP 85 buddypress();75 \buddypress(); 86 76 87 77 return true; … … 95 85 } 96 86 97 98 99 87 } -
export-user-data/tags/2.2.1/library/core/config.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 5 use q\eud\core\core as core; 6 use q\eud\core\helper as helper; 5 // import classes ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 7 9 8 // load it up ## 9 // \q\eud\core\config::run(); 10 class config { 10 11 11 class config extends \q_export_user_data { 12 private $plugin; 12 13 13 public static function run() 14 { 14 function __construct(){ 15 15 16 if ( \is_admin() ) { 16 $this->plugin = plugin::get_instance(); 17 17 18 // load standard fields ## 19 \add_action( 'admin_init', array( get_class(), 'load' ), 1 ); 20 21 } 22 23 } 24 25 18 } 26 19 27 20 /** … … 32 25 * @return Array of saved exports 33 26 */ 34 public static function load() 35 { 27 public static function load(){ 36 28 37 29 // load api admin fields ## … … 43 35 } 44 36 45 46 47 37 /** 48 38 * Load up saved exports for this user … … 52 42 * @return Array of saved exports 53 43 */ 54 public static function get_admin_fields() 55 { 44 public function get_admin_fields(){ 56 45 57 46 // build array ## 58 $array = array(59 'program' => array(47 $array = [ 48 'program' => [ 60 49 'title' => \_e( 'Programs', 'export-user-data' ), 61 50 'label' => 'program', 62 51 'description' => \__( 'Select the program that you wish to export.', 'export-user-data' ), 63 52 '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 ]), 65 54 'options_ID' => 'ID', 66 55 'options_title' => 'post_title' 67 ) 68 );56 ] 57 ]; 69 58 70 59 // test it ## 71 60 #self::log( $array ); 72 61 73 // add to static property ##74 self::$api_admin_fields = $array;75 76 62 // filter and return ## 77 apply_filters( 'q/eud/api/admin_fields', self::$api_admin_fields);63 apply_filters( 'q/eud/api/admin_fields', $array ); 78 64 79 65 // 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 ); 81 71 82 // kick it back##72 // kick back true ## 83 73 return true; 84 74 85 75 } 86 76 87 88 77 } -
export-user-data/tags/2.2.1/library/core/export.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 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 ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 9 use q\eud\core\method; 8 10 use XLSXWriter; 9 11 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 12 class export { 13 14 private $plugin; 15 16 function __construct( \q\eud\plugin $plugin ){ 17 18 $this->plugin = $plugin; 19 20 } 27 21 28 22 /** 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(){ 36 29 37 30 // Check if the user clicked on the Save, Load, or Delete Settings buttons ## … … 58 51 'fields' => ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) ? 59 52 'all' : 60 array( 'ID' ), // exclude standard wp_users fields from get_users query ##53 [ 'ID' ], // exclude standard wp_users fields from get_users query ## 61 54 'role' => \sanitize_text_field( $_POST['role'] ) 62 55 ); … … 75 68 76 69 // test it ## 77 helper::log( $args );70 // h::log( $args ); 78 71 79 72 } … … 84 77 $args = \apply_filters( 'q/eud/export/args', $args ); 85 78 86 #h elper::log( $args );79 #h::log( $args ); 87 80 88 81 // 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' ] ); 90 83 $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' ] ); 92 85 93 86 // test args ## 94 # if ( self::$debug ) helper::log ( $users );87 #h::log ( $users ); 95 88 96 89 // no users found, so chuck an error into the args array and exit the export ## … … 202 195 $doc_end = ""; 203 196 204 $writer = new XLSXWriter();197 $writer = new \XLSXWriter(); 205 198 206 199 break; … … 211 204 // check for selected usermeta fields ## 212 205 $usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: ''; 213 #h elper::log( $usermeta );214 $usermeta_fields = array();206 #h::log( $usermeta ); 207 $usermeta_fields = []; 215 208 216 209 // loop over each field and sanitize ## @todo - user array_map ## … … 221 214 } 222 215 223 #h elper::log( $usermeta_fields );216 #h::log( $usermeta_fields ); 224 217 #exit; 225 218 … … 262 255 263 256 // debug ## 264 #h elper::log( 'merging array' );257 #h::log( 'merging array' ); 265 258 266 259 // compile final fields list ## 267 260 $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 ## 270 263 , $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 ## 273 266 ); 274 267 275 268 // test field array ## 276 #h elper::log( $fields );269 #h::log( $fields ); 277 270 278 271 // build the document headers ## … … 281 274 foreach ( $fields as $key => $field ) { 282 275 283 #h elper::log( 'Field: '. $field );276 #h::log( 'Field: '. $field ); 284 277 285 278 // filter field name ## … … 287 280 288 281 // grab fields to exclude from exports - filterable ## 289 if ( in_array( $fields[$key], core::get_exclude_fields() ) ) {290 291 #h elper::log( 'Dump Field: '. $fields[$key] );282 if ( in_array( $fields[$key], get::exclude_fields() ) ) { 283 284 #h::log( 'Dump Field: '. $fields[$key] ); 292 285 293 286 // ditch 'em ## … … 311 304 312 305 // quick check ## 313 #h elper::log( $fields );314 # if ( self::$debug ) #helper::log( $bp_fields_passed );306 #h::log( $fields ); 307 #h::log( $bp_fields_passed ); 315 308 316 309 // no more buffering while spitting back the export data ## … … 319 312 // get the value in bytes allocated for Memory via php.ini ## 320 313 // @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; 322 315 323 316 // we need to disable caching while exporting because we export so much data that it could blow the memory cache … … 339 332 } 340 333 341 342 if ($export_method !== "excel2007") { 334 if ( $export_method !== "excel2007" ) { 343 335 // open doc wrapper.. ## 344 336 echo $doc_begin; … … 347 339 echo $pre . implode( $seperator, $headers ) . $breaker; 348 340 349 #h elper::log( $users );341 #h::log( $users ); 350 342 } else { 351 343 352 $xlsx_header = array_flip( $headers);344 $xlsx_header = array_flip( $headers ); 353 345 354 346 foreach($xlsx_header as $k => $v) { … … 356 348 } 357 349 358 $writer->writeSheetHeader('Sheet1', $xlsx_header); 350 $writer->writeSheetHeader('Sheet1', $xlsx_header); 351 359 352 } 360 353 … … 362 355 foreach ( $users as $user ) { 363 356 364 #h elper::log( $user );357 #h::log( $user ); 365 358 366 359 // check if we're hitting any Memory limits, if so flush them out ## … … 375 368 // BP loaded ? ## 376 369 if ( 377 ! self::$bp_data_available370 ! $this->plugin->get( '_bp_data_available' ) 378 371 && function_exists ( 'bp_is_active' ) 379 372 && \bp_is_active( 'xprofile' ) … … 383 376 ) { 384 377 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 ## 387 380 388 381 } … … 390 383 // grab all user data ## 391 384 if ( 392 self::$bp_data_available385 $this->plugin->get( '_bp_data_available' ) 393 386 && ! $bp_data = \BP_XProfile_ProfileData::get_all_for_user( $user->ID ) 394 387 ) { … … 397 390 $bp_data = false; 398 391 399 helper::log( 'XProfile returned no data ID#: '.$user->ID );392 // h::log( 'XProfile returned no data ID#: '.$user->ID ); 400 393 401 394 } … … 403 396 // single query method - get all user_meta data ## 404 397 $get_user_meta = (array)\get_user_meta( $user->ID ); 405 #h elper::log( $get_user_meta );398 #h::log( $get_user_meta ); 406 399 407 400 // loop over each field ## … … 443 436 444 437 // 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 ) ) { 448 439 449 440 global $bp; … … 464 455 465 456 // 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' ) { 469 458 470 459 // empty array ## … … 482 471 483 472 // 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 ''; 488 480 489 481 // 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' ) { 493 483 494 484 if ( function_exists( 'groups_get_user_groups' ) ) { … … 497 487 $group_ids = \groups_get_user_groups( $user->ID ); 498 488 499 #$this->pr( $group_ids ); 500 #wp_die( pr( 'loaded group data.' )); 489 #h::log( $group_ids ); 501 490 502 491 if ( ! $group_ids || $group_ids == '' ) { … … 517 506 518 507 // implode it ## 519 $value = implode( $groups, '|' ); 508 // $value = implode( $groups, '|' ); 509 $value = helper::json_encode( $groups ); 520 510 521 511 } … … 527 517 } 528 518 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 ){ 532 524 533 525 // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ## 534 526 $value = \bp_get_user_last_activity( $user->ID ); 527 */ 535 528 536 529 // user or usermeta field ## 537 } 538 else 539 { 530 } else { 540 531 541 532 // 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 ){ 543 537 544 538 // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ## … … 553 547 } 554 548 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 570 549 } 571 550 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 572 580 // filter $value ## 573 $value = \apply_filters( 'q/eud/export/value', $value, $field );581 // $value = \apply_filters( 'q/eud/export/value', $value, $field ); 574 582 575 583 // 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 ); 577 598 578 599 // wrap values in quotes and add to array ## 579 600 if ( $is_csv ) { 580 601 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; 582 616 583 617 // just add to array ## 584 618 } else { 585 619 586 $data[] = core::format_value( $value ); 620 $data[] = $value; 621 587 622 } 588 623 589 624 } 590 625 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 594 631 } 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 601 641 // close doc wrapper.. 602 echo $doc_end; 642 echo $doc_end; 643 603 644 } 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 608 648 } 609 649 … … 612 652 613 653 } 614 615 616 617 654 618 655 /** … … 621 658 * @since 2.0.0 622 659 */ 623 public static function pre_user_query( $user_search = null ) 624 { 660 function pre_user_query( $user_search = null ){ 625 661 626 662 global $wpdb; … … 652 688 ) { 653 689 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' ) ); 660 703 661 704 } … … 667 710 } 668 711 669 # wp_die( self::$pr( $user_search ) );712 #h::log( $user_search ) ); 670 713 return $user_search; 671 714 672 715 } 673 716 674 675 676 717 } -
export-user-data/tags/2.2.1/library/core/filters.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 5 use q\eud\core\core as core; 6 use q\eud\core\helper as helper; 5 // import classes ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 7 9 8 // load it up ## 9 \q\eud\core\filters::run(); 10 class filters { 10 11 11 class filters extends \q_export_user_data { 12 private $plugin; 12 13 13 public static function run() 14 { 14 function __construct( \q\eud\plugin $plugin ){ 15 15 16 if ( \is_admin() ) { 16 $this->plugin = $plugin; 17 17 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 } 25 19 26 20 /** … … 29 23 * @since 2.0.0 30 24 */ 31 public static function display_key( $string = null ) 32 { 25 public static function display_key( $string = null ){ 33 26 34 27 #helper::log( 'string from filter: '.$string ); -
export-user-data/tags/2.2.1/library/core/helper.php
r2371571 r2643129 8 8 * @package q_eud\core 9 9 */ 10 class helper extends \q_export_user_data { 11 12 10 class helper { 11 13 12 /** 14 13 * Write to WP Error Log … … 17 16 * @return void 18 17 */ 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 ) { 23 21 24 22 $trace = debug_backtrace(); 25 $caller = $trace[ 1];23 $caller = $trace[0]; 26 24 27 25 $suffix = sprintf( … … 43 41 } 44 42 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 } 45 444 46 445 } -
export-user-data/tags/2.2.1/library/core/user.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 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 ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 9 10 class user { 11 12 private $plugin; 13 14 public function __construct( \q\eud\plugin $plugin ){ 15 16 $this->plugin = $plugin; 17 18 } 25 19 26 20 /** … … 31 25 * @return Array of saved exports 32 26 */ 33 public static function load() 34 { 27 public function load(){ 35 28 36 29 // convert outdated stored meta from q_report to q_eud_exports ## … … 52 45 53 46 // 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; 60 60 61 61 } 62 62 63 64 65 66 63 /** 67 64 * Get list of saved exports for this user … … 70 67 * @return Array of saved exports 71 68 */ 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' ); 74 73 75 74 // 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 ); 77 76 78 77 // quick check if the array is empty ## 79 if ( empty ( $ q_eud_exports ) ) {78 if ( empty ( $_q_eud_exports ) ) { 80 79 81 80 return false; … … 84 83 85 84 // test the array of saved exports ## 86 # $this->pr( $q_eud_exports );85 #h::log( $_q_eud_exports ); 87 86 88 87 // start with an empty array ## 89 $exports = array();88 $exports = []; 90 89 91 90 // 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 ) { 93 92 94 93 $exports[] = $key; … … 101 100 } 102 101 103 104 102 /** 105 103 * Check for and load stored user options … … 108 106 * @return void 109 107 */ 110 public static function get_user_options_by_export( $export = null ) 111 { 108 function get_user_options_by_export( $export = null ){ 112 109 113 110 // 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']; 132 132 133 133 } else { 134 134 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 } 154 169 155 170 /** … … 161 176 * @return void 162 177 */ 163 public static function set_user_options( $key = null, $options = null ) 164 { 178 function set_user_options( $key = null, $options = null ){ 165 179 166 180 // sanity check ## 167 181 if ( is_null ( $key ) || is_null ( $options ) ) { 168 182 169 # $this->pr( 'missing save values' );183 #h::log( 'missing save values' ); 170 184 return false; 171 185 172 186 } 173 187 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' ); 176 193 177 194 // 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' ); 181 198 #return false; 182 199 … … 206 223 207 224 // 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 ); 209 229 210 230 // 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 ); 215 234 216 235 // create new user meta key ## 217 236 } else { 218 237 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 ); 221 239 222 240 } … … 225 243 226 244 } 227 228 245 229 246 /** … … 234 251 * @return void 235 252 */ 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' ); 238 257 239 258 // 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; } 241 260 242 261 // clean it up ## … … 244 263 245 264 // check it out ## 246 # $this->pr( $key );265 #h::log( $key ); 247 266 248 267 // 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] ); 250 269 251 270 // 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 } 257 280 258 281 } -
export-user-data/tags/2.2.1/package.json
r2372271 r2643129 1 1 { 2 2 "name": "export-user-data", 3 "version": "2. 1.3",3 "version": "2.2.1", 4 4 "description": "Q Plugins ~ Export User data and metadata", 5 5 "author": "Q Studio", -
export-user-data/tags/2.2.1/readme.md
r2372271 r2643129 5 5 **Requires PHP:** 6.0 6 6 **Requires at least:** 5.0 7 **Tested up to:** 5. 58 **Stable tag:** 2. 1.37 **Tested up to:** 5.6 8 **Stable tag:** 2.2.1 9 9 **License:** GPLv2 10 10 -
export-user-data/tags/2.2.1/readme.txt
r2372271 r2643129 2 2 Contributors: qlstudio 3 3 Tags: users, export, usermeta, excel 4 Requires PHP: 6.04 Requires PHP: 7.0 5 5 Requires at least: 4.8 6 Tested up to: 5. 57 Stable tag: 2. 1.36 Tested up to: 5.6 7 Stable tag: 2.2.0 8 8 License: GPLv2 9 9 -
export-user-data/trunk/CHANGELOG.md
r2372271 r2643129 1 1 ## 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 2 12 3 13 *** 2.1.3 *** 4 14 5 * FIX -wrong name for our own plugin :( thanks @kgagne !15 * FIX: wrong name for our own plugin :( thanks @kgagne ! 6 16 7 17 *** 2.1.2 *** -
export-user-data/trunk/export-user-data.php
r2372271 r2643129 1 1 <?php 2 2 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 4 12 * Plugin Name: Export User Data 13 * Plugin URI: http://qstudio.us/releases/export-user-data 5 14 * Description: Export User data and metadata. 6 * Version: 2. 1.315 * Version: 2.2.1 7 16 * 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 12 25 * GitHub Plugin URI: qstudio/export-user-data 13 26 */ 14 27 15 defined( 'ABSPATH' ) OR exit; 28 // namespace plugin ## 29 namespace q\eud; 16 30 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 ## 32 use q\eud; 33 use q\eud\core\helper as h; 50 34 51 // api ## 52 public static $api_admin_fields = false; 35 // If this file is called directly, Bulk! 36 if ( ! defined( 'ABSPATH' ) ) { 37 return; 38 } 53 39 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' ] ); 61 42 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' ] ); 65 45 66 return self::$instance; 46 // required bits to get set-up ## 47 require_once __DIR__ . '/library/api/function.php'; 48 require_once __DIR__ . '/autoload.php'; 49 require_once __DIR__ . '/plugin.php'; 50 require_once __DIR__ . '/vendor/PHP_XLSXWriter/xlsxwriter.class.php'; 67 51 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(); 82 54 83 // deactvation##84 register_deactivation_hook( __FILE__, array ( $this, 'register_deactivation_hook' ) ); 55 // validate instance ## 56 if( ! ( $plugin instanceof \q\eud\plugin ) ) { 85 57 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' ); 91 59 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; 199 62 200 63 } 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 91 if ( \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 3 3 namespace q\eud\api; 4 4 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 ## 6 use q\eud; 7 use q\eud\plugin; 8 use q\eud\core\core; 9 use q\eud\core\helper as h; 10 11 class admin { 12 13 private $plugin; 14 15 function __construct(){ 16 17 $this->plugin = plugin::get_instance(); 18 19 } 26 20 27 21 /** … … 31 25 * @return HTML 32 26 */ 33 public static function render( $array = null ) 34 { 27 function render( $array = null ){ 35 28 36 29 // check if we have any fields to show ## … … 40 33 ) { 41 34 42 #h elper::log( 'No fields found' );43 44 return false; 45 46 } 47 48 #h elper::log( $array );35 #h::log( 'No fields found' ); 36 37 return false; 38 39 } 40 41 #h::log( $array ); 49 42 50 43 // check that we have all required arrays ## … … 56 49 ) { 57 50 58 #h elper::log( 'Missing data' );51 #h::log( 'Missing data' ); 59 52 60 53 return false; … … 68 61 $array['label'] = \sanitize_key( $array['label'] ); 69 62 70 #h elper::log( $array['options'] );63 #h::log( $array['options'] ); 71 64 72 65 // build out options ## 73 66 if ( ! self::has_options( $array ) ) { 74 67 75 #h elper::log( 'Missing options for: '.$array['label'] );68 #h::log( 'Missing options for: '.$array['label'] ); 76 69 77 70 return false; … … 104 97 } 105 98 106 107 public static function has_options( $array = null ) 108 { 99 public static function has_options( $array = null ){ 109 100 110 101 if ( … … 128 119 } 129 120 130 131 132 public static function build_options( $array = null ) 133 { 121 public static function build_options( $array = null ){ 134 122 135 123 if ( … … 139 127 ) { 140 128 141 #h elper::log( 'Error building options for: '.$array['label'] );129 #h::log( 'Error building options for: '.$array['label'] ); 142 130 143 131 return false; … … 163 151 } 164 152 165 166 167 public static function field_select( $array = null ) 168 { 153 public static function field_select( $array = null ){ 169 154 170 155 if ( … … 179 164 ) { 180 165 181 #h elper::log( 'Error building select options for: '.$array['label'] );182 183 return false; 184 185 } 186 187 #h elper::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'] ); 188 173 189 174 // is this a multiselect ? ## … … 228 213 } 229 214 230 231 215 } -
export-user-data/trunk/library/core/buddypress.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 5 use q\eud\core\core as core; 6 use q\eud\core\helper as helper; 5 // import classes ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 7 9 8 // load it up ## 9 \q\eud\core\buddypress::run(); 10 class buddypress { 10 11 11 class buddypress extends \q_export_user_data { 12 private $plugin; 12 13 13 public static function run() 14 { 14 function __construct(){ 15 15 16 if ( \is_admin() ) { 16 $this->plugin = plugin::get_instance(); 17 17 18 // load BP ## 19 \add_action( 'admin_init', array( get_class(), 'load' ), 1000001 ); 20 21 } 22 23 } 24 18 } 25 19 26 20 /** … … 29 23 * @since 2.0.0 30 24 */ 31 public static function get_fields() 32 { 25 public static function get_fields(){ 33 26 34 27 // buddypress support deprecated for now ## … … 61 54 } 62 55 63 64 65 56 /** 66 57 * Load up saved exports for this user … … 70 61 * @return Array of saved exports 71 62 */ 72 public static function load() 73 { 63 public static function load(){ 74 64 75 65 // do we have a bp object in the globals ## … … 80 70 ) { 81 71 82 h elper::log( 'BP not loaded - calling buddypress()' );72 h::log( 'BP not loaded - calling buddypress()' ); 83 73 84 74 // call BP 85 buddypress();75 \buddypress(); 86 76 87 77 return true; … … 95 85 } 96 86 97 98 99 87 } -
export-user-data/trunk/library/core/config.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 5 use q\eud\core\core as core; 6 use q\eud\core\helper as helper; 5 // import classes ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 7 9 8 // load it up ## 9 // \q\eud\core\config::run(); 10 class config { 10 11 11 class config extends \q_export_user_data { 12 private $plugin; 12 13 13 public static function run() 14 { 14 function __construct(){ 15 15 16 if ( \is_admin() ) { 16 $this->plugin = plugin::get_instance(); 17 17 18 // load standard fields ## 19 \add_action( 'admin_init', array( get_class(), 'load' ), 1 ); 20 21 } 22 23 } 24 25 18 } 26 19 27 20 /** … … 32 25 * @return Array of saved exports 33 26 */ 34 public static function load() 35 { 27 public static function load(){ 36 28 37 29 // load api admin fields ## … … 43 35 } 44 36 45 46 47 37 /** 48 38 * Load up saved exports for this user … … 52 42 * @return Array of saved exports 53 43 */ 54 public static function get_admin_fields() 55 { 44 public function get_admin_fields(){ 56 45 57 46 // build array ## 58 $array = array(59 'program' => array(47 $array = [ 48 'program' => [ 60 49 'title' => \_e( 'Programs', 'export-user-data' ), 61 50 'label' => 'program', 62 51 'description' => \__( 'Select the program that you wish to export.', 'export-user-data' ), 63 52 '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 ]), 65 54 'options_ID' => 'ID', 66 55 'options_title' => 'post_title' 67 ) 68 );56 ] 57 ]; 69 58 70 59 // test it ## 71 60 #self::log( $array ); 72 61 73 // add to static property ##74 self::$api_admin_fields = $array;75 76 62 // filter and return ## 77 apply_filters( 'q/eud/api/admin_fields', self::$api_admin_fields);63 apply_filters( 'q/eud/api/admin_fields', $array ); 78 64 79 65 // 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 ); 81 71 82 // kick it back##72 // kick back true ## 83 73 return true; 84 74 85 75 } 86 76 87 88 77 } -
export-user-data/trunk/library/core/export.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 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 ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 9 use q\eud\core\method; 8 10 use XLSXWriter; 9 11 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 12 class export { 13 14 private $plugin; 15 16 function __construct( \q\eud\plugin $plugin ){ 17 18 $this->plugin = $plugin; 19 20 } 27 21 28 22 /** 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(){ 36 29 37 30 // Check if the user clicked on the Save, Load, or Delete Settings buttons ## … … 58 51 'fields' => ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) ? 59 52 'all' : 60 array( 'ID' ), // exclude standard wp_users fields from get_users query ##53 [ 'ID' ], // exclude standard wp_users fields from get_users query ## 61 54 'role' => \sanitize_text_field( $_POST['role'] ) 62 55 ); … … 75 68 76 69 // test it ## 77 helper::log( $args );70 // h::log( $args ); 78 71 79 72 } … … 84 77 $args = \apply_filters( 'q/eud/export/args', $args ); 85 78 86 #h elper::log( $args );79 #h::log( $args ); 87 80 88 81 // 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' ] ); 90 83 $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' ] ); 92 85 93 86 // test args ## 94 # if ( self::$debug ) helper::log ( $users );87 #h::log ( $users ); 95 88 96 89 // no users found, so chuck an error into the args array and exit the export ## … … 202 195 $doc_end = ""; 203 196 204 $writer = new XLSXWriter();197 $writer = new \XLSXWriter(); 205 198 206 199 break; … … 211 204 // check for selected usermeta fields ## 212 205 $usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: ''; 213 #h elper::log( $usermeta );214 $usermeta_fields = array();206 #h::log( $usermeta ); 207 $usermeta_fields = []; 215 208 216 209 // loop over each field and sanitize ## @todo - user array_map ## … … 221 214 } 222 215 223 #h elper::log( $usermeta_fields );216 #h::log( $usermeta_fields ); 224 217 #exit; 225 218 … … 262 255 263 256 // debug ## 264 #h elper::log( 'merging array' );257 #h::log( 'merging array' ); 265 258 266 259 // compile final fields list ## 267 260 $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 ## 270 263 , $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 ## 273 266 ); 274 267 275 268 // test field array ## 276 #h elper::log( $fields );269 #h::log( $fields ); 277 270 278 271 // build the document headers ## … … 281 274 foreach ( $fields as $key => $field ) { 282 275 283 #h elper::log( 'Field: '. $field );276 #h::log( 'Field: '. $field ); 284 277 285 278 // filter field name ## … … 287 280 288 281 // grab fields to exclude from exports - filterable ## 289 if ( in_array( $fields[$key], core::get_exclude_fields() ) ) {290 291 #h elper::log( 'Dump Field: '. $fields[$key] );282 if ( in_array( $fields[$key], get::exclude_fields() ) ) { 283 284 #h::log( 'Dump Field: '. $fields[$key] ); 292 285 293 286 // ditch 'em ## … … 311 304 312 305 // quick check ## 313 #h elper::log( $fields );314 # if ( self::$debug ) #helper::log( $bp_fields_passed );306 #h::log( $fields ); 307 #h::log( $bp_fields_passed ); 315 308 316 309 // no more buffering while spitting back the export data ## … … 319 312 // get the value in bytes allocated for Memory via php.ini ## 320 313 // @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; 322 315 323 316 // we need to disable caching while exporting because we export so much data that it could blow the memory cache … … 339 332 } 340 333 341 342 if ($export_method !== "excel2007") { 334 if ( $export_method !== "excel2007" ) { 343 335 // open doc wrapper.. ## 344 336 echo $doc_begin; … … 347 339 echo $pre . implode( $seperator, $headers ) . $breaker; 348 340 349 #h elper::log( $users );341 #h::log( $users ); 350 342 } else { 351 343 352 $xlsx_header = array_flip( $headers);344 $xlsx_header = array_flip( $headers ); 353 345 354 346 foreach($xlsx_header as $k => $v) { … … 356 348 } 357 349 358 $writer->writeSheetHeader('Sheet1', $xlsx_header); 350 $writer->writeSheetHeader('Sheet1', $xlsx_header); 351 359 352 } 360 353 … … 362 355 foreach ( $users as $user ) { 363 356 364 #h elper::log( $user );357 #h::log( $user ); 365 358 366 359 // check if we're hitting any Memory limits, if so flush them out ## … … 375 368 // BP loaded ? ## 376 369 if ( 377 ! self::$bp_data_available370 ! $this->plugin->get( '_bp_data_available' ) 378 371 && function_exists ( 'bp_is_active' ) 379 372 && \bp_is_active( 'xprofile' ) … … 383 376 ) { 384 377 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 ## 387 380 388 381 } … … 390 383 // grab all user data ## 391 384 if ( 392 self::$bp_data_available385 $this->plugin->get( '_bp_data_available' ) 393 386 && ! $bp_data = \BP_XProfile_ProfileData::get_all_for_user( $user->ID ) 394 387 ) { … … 397 390 $bp_data = false; 398 391 399 helper::log( 'XProfile returned no data ID#: '.$user->ID );392 // h::log( 'XProfile returned no data ID#: '.$user->ID ); 400 393 401 394 } … … 403 396 // single query method - get all user_meta data ## 404 397 $get_user_meta = (array)\get_user_meta( $user->ID ); 405 #h elper::log( $get_user_meta );398 #h::log( $get_user_meta ); 406 399 407 400 // loop over each field ## … … 443 436 444 437 // 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 ) ) { 448 439 449 440 global $bp; … … 464 455 465 456 // 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' ) { 469 458 470 459 // empty array ## … … 482 471 483 472 // 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 ''; 488 480 489 481 // 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' ) { 493 483 494 484 if ( function_exists( 'groups_get_user_groups' ) ) { … … 497 487 $group_ids = \groups_get_user_groups( $user->ID ); 498 488 499 #$this->pr( $group_ids ); 500 #wp_die( pr( 'loaded group data.' )); 489 #h::log( $group_ids ); 501 490 502 491 if ( ! $group_ids || $group_ids == '' ) { … … 517 506 518 507 // implode it ## 519 $value = implode( $groups, '|' ); 508 // $value = implode( $groups, '|' ); 509 $value = helper::json_encode( $groups ); 520 510 521 511 } … … 527 517 } 528 518 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 ){ 532 524 533 525 // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ## 534 526 $value = \bp_get_user_last_activity( $user->ID ); 527 */ 535 528 536 529 // user or usermeta field ## 537 } 538 else 539 { 530 } else { 540 531 541 532 // 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 ){ 543 537 544 538 // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ## … … 553 547 } 554 548 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 570 549 } 571 550 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 572 580 // filter $value ## 573 $value = \apply_filters( 'q/eud/export/value', $value, $field );581 // $value = \apply_filters( 'q/eud/export/value', $value, $field ); 574 582 575 583 // 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 ); 577 598 578 599 // wrap values in quotes and add to array ## 579 600 if ( $is_csv ) { 580 601 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; 582 616 583 617 // just add to array ## 584 618 } else { 585 619 586 $data[] = core::format_value( $value ); 620 $data[] = $value; 621 587 622 } 588 623 589 624 } 590 625 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 594 631 } 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 601 641 // close doc wrapper.. 602 echo $doc_end; 642 echo $doc_end; 643 603 644 } 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 608 648 } 609 649 … … 612 652 613 653 } 614 615 616 617 654 618 655 /** … … 621 658 * @since 2.0.0 622 659 */ 623 public static function pre_user_query( $user_search = null ) 624 { 660 function pre_user_query( $user_search = null ){ 625 661 626 662 global $wpdb; … … 652 688 ) { 653 689 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' ) ); 660 703 661 704 } … … 667 710 } 668 711 669 # wp_die( self::$pr( $user_search ) );712 #h::log( $user_search ) ); 670 713 return $user_search; 671 714 672 715 } 673 716 674 675 676 717 } -
export-user-data/trunk/library/core/filters.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 5 use q\eud\core\core as core; 6 use q\eud\core\helper as helper; 5 // import classes ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 7 9 8 // load it up ## 9 \q\eud\core\filters::run(); 10 class filters { 10 11 11 class filters extends \q_export_user_data { 12 private $plugin; 12 13 13 public static function run() 14 { 14 function __construct( \q\eud\plugin $plugin ){ 15 15 16 if ( \is_admin() ) { 16 $this->plugin = $plugin; 17 17 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 } 25 19 26 20 /** … … 29 23 * @since 2.0.0 30 24 */ 31 public static function display_key( $string = null ) 32 { 25 public static function display_key( $string = null ){ 33 26 34 27 #helper::log( 'string from filter: '.$string ); -
export-user-data/trunk/library/core/helper.php
r2371571 r2643129 8 8 * @package q_eud\core 9 9 */ 10 class helper extends \q_export_user_data { 11 12 10 class helper { 11 13 12 /** 14 13 * Write to WP Error Log … … 17 16 * @return void 18 17 */ 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 ) { 23 21 24 22 $trace = debug_backtrace(); 25 $caller = $trace[ 1];23 $caller = $trace[0]; 26 24 27 25 $suffix = sprintf( … … 43 41 } 44 42 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 } 45 444 46 445 } -
export-user-data/trunk/library/core/user.php
r2371571 r2643129 3 3 namespace q\eud\core; 4 4 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 ## 6 use q\eud; 7 use q\eud\plugin as plugin; 8 use q\eud\core\helper as h; 9 10 class user { 11 12 private $plugin; 13 14 public function __construct( \q\eud\plugin $plugin ){ 15 16 $this->plugin = $plugin; 17 18 } 25 19 26 20 /** … … 31 25 * @return Array of saved exports 32 26 */ 33 public static function load() 34 { 27 public function load(){ 35 28 36 29 // convert outdated stored meta from q_report to q_eud_exports ## … … 52 45 53 46 // 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; 60 60 61 61 } 62 62 63 64 65 66 63 /** 67 64 * Get list of saved exports for this user … … 70 67 * @return Array of saved exports 71 68 */ 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' ); 74 73 75 74 // 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 ); 77 76 78 77 // quick check if the array is empty ## 79 if ( empty ( $ q_eud_exports ) ) {78 if ( empty ( $_q_eud_exports ) ) { 80 79 81 80 return false; … … 84 83 85 84 // test the array of saved exports ## 86 # $this->pr( $q_eud_exports );85 #h::log( $_q_eud_exports ); 87 86 88 87 // start with an empty array ## 89 $exports = array();88 $exports = []; 90 89 91 90 // 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 ) { 93 92 94 93 $exports[] = $key; … … 101 100 } 102 101 103 104 102 /** 105 103 * Check for and load stored user options … … 108 106 * @return void 109 107 */ 110 public static function get_user_options_by_export( $export = null ) 111 { 108 function get_user_options_by_export( $export = null ){ 112 109 113 110 // 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']; 132 132 133 133 } else { 134 134 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 } 154 169 155 170 /** … … 161 176 * @return void 162 177 */ 163 public static function set_user_options( $key = null, $options = null ) 164 { 178 function set_user_options( $key = null, $options = null ){ 165 179 166 180 // sanity check ## 167 181 if ( is_null ( $key ) || is_null ( $options ) ) { 168 182 169 # $this->pr( 'missing save values' );183 #h::log( 'missing save values' ); 170 184 return false; 171 185 172 186 } 173 187 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' ); 176 193 177 194 // 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' ); 181 198 #return false; 182 199 … … 206 223 207 224 // 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 ); 209 229 210 230 // 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 ); 215 234 216 235 // create new user meta key ## 217 236 } else { 218 237 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 ); 221 239 222 240 } … … 225 243 226 244 } 227 228 245 229 246 /** … … 234 251 * @return void 235 252 */ 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' ); 238 257 239 258 // 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; } 241 260 242 261 // clean it up ## … … 244 263 245 264 // check it out ## 246 # $this->pr( $key );265 #h::log( $key ); 247 266 248 267 // 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] ); 250 269 251 270 // 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 } 257 280 258 281 } -
export-user-data/trunk/package.json
r2372271 r2643129 1 1 { 2 2 "name": "export-user-data", 3 "version": "2. 1.3",3 "version": "2.2.1", 4 4 "description": "Q Plugins ~ Export User data and metadata", 5 5 "author": "Q Studio", -
export-user-data/trunk/readme.md
r2372271 r2643129 5 5 **Requires PHP:** 6.0 6 6 **Requires at least:** 5.0 7 **Tested up to:** 5. 58 **Stable tag:** 2. 1.37 **Tested up to:** 5.6 8 **Stable tag:** 2.2.1 9 9 **License:** GPLv2 10 10 -
export-user-data/trunk/readme.txt
r2372271 r2643129 2 2 Contributors: qlstudio 3 3 Tags: users, export, usermeta, excel 4 Requires PHP: 6.04 Requires PHP: 7.0 5 5 Requires at least: 4.8 6 Tested up to: 5. 57 Stable tag: 2. 1.36 Tested up to: 5.6 7 Stable tag: 2.2.0 8 8 License: GPLv2 9 9
Note: See TracChangeset
for help on using the changeset viewer.