From e5e634b31f6c091646e856e757d6f1d7e2e88f97 Mon Sep 17 00:00:00 2001 From: Eduardo Humberto Date: Fri, 11 Jan 2019 19:52:06 -0200 Subject: [PATCH] Start export vocabulary (ref. #180) --- src/exporter/class-tainacan-term-exporter.php | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/exporter/class-tainacan-term-exporter.php diff --git a/src/exporter/class-tainacan-term-exporter.php b/src/exporter/class-tainacan-term-exporter.php new file mode 100644 index 000000000..886f149bf --- /dev/null +++ b/src/exporter/class-tainacan-term-exporter.php @@ -0,0 +1,157 @@ + 'Export Terms', + 'progress_label' => 'Exporting terms', + 'callback' => 'exporting_terms' + ] + ]; + + public function __construct($attributes = array()){ + parent::__construct($attributes); + $this->set_accepted_mapping_methods('any'); // set all method to mapping + $this->accept_no_mapping = true; + + $this->set_default_options([ + 'delimiter' => ',', + 'enclosure' => '"' + ]); + } + + /** + * When exporter is finished, gets the final output + */ + public function get_output() { + $files = $this->get_output_files(); + + if ( is_array($files) && isset($files['termcsvexporter.csv'])) { + $file = $files['termcsvexporter.csv']; + + $message = __('Your CSV file is ready! Access it in the link below:', 'tainacan'); + $message .= '

'; + $message .= 'Download'; + + return $message; + + } else { + $this->add_error_log('Output file not found! Maybe you need to correct the permissions of your upload folder'); + } + } + + function str_putcsv($item, $delimiter = ',', $enclosure = '"') { + // Open a memory "file" for read/write... + $fp = fopen('php://temp', 'r+'); + + fputcsv($fp, $item, $delimiter, $enclosure); + rewind($fp); + //Getting detailed stats to check filesize: + $fstats = fstat($fp); + $data = fread($fp, $fstats['size']); + fclose($fp); + return rtrim($data, "\n"); + } + + public function options_form() { + ob_start(); + ?> +
+ + + + + + + +
+
+
+
+
+

+
+
+
+
+ +
+
+ +
+ + + + + + + +
+
+
+
+
+

+

+
+
+
+
+
+ + +
+ +
+ +
+ + get_option('select_taxonomy') == '' ) { + $this->abort(); + $this->add_error_log('No taxonomy selected'); + return false; + } + + $tax = new Entities\Taxonomy($this->get_option('select_taxonomy')); + $term_repo = Repositories\Terms::get_instance(); + + //TODO: Retrieve all terms from hierarchy + } +} \ No newline at end of file