PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.9.0
Import WP – CSV & XML Import Export for WordPress v2.9.0
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / class / Common / Exporter / File / File.php

File.php in Import WP – CSV & XML Import Export for WordPress 2.9.0, at class/Common/Exporter/File/File.php

82 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Exporter\File;
4
5 use ImportWP\Common\Model\ExporterModel;
6
7 class File
8 {
9 /**
10 * @var bool|resource
11 */
12 protected $fh;
13
14 /**
15 * @var ExporterModel $exporter
16 */
17 protected $exporter;
18
19 /**
20 * EWP_File constructor.
21 *
22 * @param ExporterModel $exporter
23 *
24 * @throws Exception
25 */
26 public function __construct($exporter)
27 {
28 $this->exporter = $exporter;
29
30 $file_path = $this->get_file_path();
31 $this->fh = fopen($file_path, 'a+');
32 }
33
34 public function wipe()
35 {
36 fclose($this->fh);
37 $file_path = $this->get_file_path();
38 $this->fh = fopen($file_path, 'w');
39 }
40
41 public function getFieldLabel($field)
42 {
43 $label = '';
44 if (isset($field['label']) && !empty($field['label'])) {
45 $label = $field['label'];
46 } elseif (isset($field['selection']) && !empty($field['selection'])) {
47 $label = $field['selection'];
48 }
49 return $label;
50 }
51
52 public function getValue($item, $data)
53 {
54 $value = isset($data[$item['id']]) ? $data[$item['id']] : '';
55 if (is_array($value)) {
56 return implode(',', $value);
57 }
58
59 return $value;
60 }
61
62 public function get_file_name()
63 {
64 throw new \Exception("get_file_name");
65 }
66
67 public function get_file_path()
68 {
69 $path = wp_normalize_path(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'exportwp' . DIRECTORY_SEPARATOR);
70 if (!file_exists($path)) {
71 mkdir($path);
72 }
73
74 return $path . $this->get_file_name();
75 }
76
77 public function get_file_url()
78 {
79 return content_url('/uploads/exportwp/' . $this->get_file_name());
80 }
81 }
82