Beispiel #1
0
 /**
  * Create CSV File Export
  * @since 1.4
  * @version 1.0.1
  */
 public function download_export_log()
 {
     if (!isset($_REQUEST['mycred-export']) || $_REQUEST['mycred-export'] != 'do') {
         return;
     }
     // Must be logged in
     if (!is_user_logged_in()) {
         return;
     }
     // Make sure current user can export
     if (!apply_filters('mycred_user_can_export', false) && !$this->core->can_edit_creds()) {
         return;
     }
     // Security for front export
     if (apply_filters('mycred_allow_front_export', false) === true) {
         if (!isset($_REQUEST['token']) || !wp_verify_nonce($_REQUEST['token'], 'mycred-run-log-export')) {
             return;
         }
     } else {
         check_admin_referer('mycred-run-log-export', 'token');
     }
     $type = '';
     $data = array();
     // Sanitize the log query
     foreach ((array) $_POST as $key => $value) {
         if ($key == 'action') {
             continue;
         }
         $_value = sanitize_text_field($value);
         if ($_value != '') {
             $data[$key] = $_value;
         }
     }
     // Get exports
     $exports = mycred_get_log_exports();
     if (empty($exports)) {
         return;
     }
     // Identify the export type by the action button
     foreach ($exports as $id => $info) {
         if ($info['label'] == $_POST['action']) {
             $type = $id;
             break;
         }
     }
     // Act according to type
     switch ($type) {
         case 'all':
             $old_data = $data;
             unset($data);
             $data = array();
             $data['ctype'] = $old_data['ctype'];
             $data['number'] = -1;
             break;
         case 'search':
             $data['number'] = -1;
             break;
         case 'displayed':
         default:
             $data = apply_filters('mycred_export_log_args', $data);
             break;
     }
     // Custom Exports
     if (has_action('mycred_export_' . $type)) {
         do_action('mycred_export_' . $type, $data);
     } else {
         // Query the log
         $log = new myCRED_Query_Log($data, true);
         // If there are entries
         if ($log->have_entries()) {
             $export = array();
             // Loop though results
             foreach ($log->results as $entry) {
                 // Remove the row id
                 unset($entry['id']);
                 // Make sure entry and data does not contain any commas that could brake this
                 $entry['entry'] = str_replace(',', '', $entry['entry']);
                 $entry['data'] = str_replace(',', '.', $entry['data']);
                 // Add to export array
                 $export[] = $entry;
             }
             $log->reset_query();
             // Load parseCSV
             require_once myCRED_ASSETS_DIR . 'libs/parsecsv.lib.php';
             $csv = new parseCSV();
             // Run output and lets create a CSV file
             $date = date_i18n('Y-m-d');
             $csv->output(true, 'mycred-log-' . $date . '.csv', $export, array('ref', 'ref_id', 'user_id', 'creds', 'ctype', 'time', 'entry', 'data'));
             die;
         }
         $log->reset_query();
     }
 }
Beispiel #2
0
        /**
         * Exporter
         * Displays all available export options.
         * @since 0.1
         * @version 1.0
         */
        public function exporter($title = '', $is_profile = false)
        {
            // Must be logged in
            if (!is_user_logged_in()) {
                return;
            }
            // Make sure current user can export
            if (!apply_filters('mycred_user_can_export', false) && !$this->core->can_edit_creds()) {
                return;
            }
            // Check if we allow export from front end. Disallowed by default
            if (!apply_filters('mycred_allow_front_export', false) && !is_admin()) {
                return;
            }
            // Export options
            $exports = mycred_get_log_exports();
            // A difference in the default aguments should show us "search results"
            if (empty($this->diff) || !empty($this->diff) && $this->max_num_pages < 2) {
                unset($exports['search']);
            }
            // Entire log export is not available when viewing our own history
            if ($is_profile) {
                unset($exports['all']);
            }
            ?>

<div style="display:none;" class="clear" id="export-log-history">
	<?php 
            if (!empty($title)) {
                ?>
<h3 class="group-title"><?php 
                echo $title;
                ?>
</h3><?php 
            }
            ?>
	<form action="<?php 
            echo add_query_arg(array('mycred-export' => 'do'));
            ?>
" method="post">
		<input type="hidden" name="token" value="<?php 
            echo wp_create_nonce('mycred-run-log-export');
            ?>
" />
<?php 
            if (!empty($exports)) {
                foreach ((array) $this->args as $arg_key => $arg_value) {
                    echo '<input type="hidden" name="' . $arg_key . '" value="' . $arg_value . '" />';
                }
                foreach ((array) $exports as $id => $data) {
                    // Label
                    if ($is_profile) {
                        $label = $data['my_label'];
                    } else {
                        $label = $data['label'];
                    }
                    echo '<input type="submit" class="' . $data['class'] . '" name="action" value="' . $label . '" /> ';
                }
                ?>
	</form>
	<p><span class="description"><?php 
                _e('Log entries are exported to a CSV file and depending on the number of entries selected, the process may take a few seconds.', 'mycred');
                ?>
</span></p>
<?php 
            } else {
                echo '<p>' . __('No export options available.', 'mycred') . '</p>';
            }
            ?>
</div>
<script type="text/javascript">
jQuery(function($) {
	$( '.toggle-exporter' ).click(function(){
		$( '#export-log-history' ).toggle();
	});
});
</script>
<?php 
        }