PluginProbe
Import WP – CSV & XML Import Export for WordPress / trunk
Import WP – CSV & XML Import Export for WordPress vtrunk
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 trunk 0.1.6 All 142 releases
jc-importer / class / Common / Exporter / File / File.php

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

110 lines 2.5 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 use ImportWP\Container;
7
8 class File
9 {
10 /**
11 * @var bool|resource
12 */
13 protected $fh;
14
15 /**
16 * @var ExporterModel $exporter
17 */
18 protected $exporter;
19
20 /**
21 * EWP_File constructor.
22 *
23 * @param ExporterModel $exporter
24 *
25 * @throws Exception
26 */
27 public function __construct($exporter)
28 {
29 $this->exporter = $exporter;
30
31 $file_path = $this->get_file_path();
32 $this->fh = fopen($file_path, 'a+');
33 }
34
35 public function wipe()
36 {
37 fclose($this->fh);
38 $file_path = $this->get_file_path();
39 $this->fh = fopen($file_path, 'w');
40 }
41
42 public function getFieldLabel($field)
43 {
44 $label = '';
45 if (isset($field['label']) && !empty($field['label'])) {
46 $label = $field['label'];
47 } elseif (isset($field['selection']) && !empty($field['selection'])) {
48 $label = $field['selection'];
49 }
50 return $label;
51 }
52
53 public function getValue($item, $data)
54 {
55 $value = isset($data[$item['id']]) ? $data[$item['id']] : '';
56 if (is_array($value)) {
57 return implode(',', $value);
58 }
59
60 return $value;
61 }
62
63 public function get_file_name()
64 {
65 throw new \Exception("get_file_name");
66 }
67
68 public function get_file_path()
69 {
70 /**
71 * @var \ImportWP\Common\Filesystem\Filesystem $filesystem
72 */
73 $filesystem = Container::getInstance()->get('filesystem');
74
75 $path = wp_normalize_path($filesystem->get_temp_directory(false, 'exportwp'));
76 if (!file_exists($path)) {
77 mkdir($path);
78 }
79
80 if (!file_exists($path . '/.htaccess')) {
81 file_put_contents($path . '/.htaccess', "# Apache 2.4+
82 <IfModule mod_authz_core.c>
83 Require all denied
84 </IfModule>
85
86 # Apache 2.2 and older (or when mod_authz_core isn't available)
87 <IfModule !mod_authz_core.c>
88 Deny from all
89 </IfModule>");
90 }
91
92 if (!file_exists($path . '/index.html')) {
93 touch($path . '/index.html');
94 }
95
96 return $path . '/' . $this->get_file_name();
97 }
98
99 public function get_file_url()
100 {
101 /**
102 * @var \ImportWP\Common\Filesystem\Filesystem $filesystem
103 */
104 $filesystem = Container::getInstance()->get('filesystem');
105 $url = $filesystem->get_temp_directory(true, 'exportwp');
106
107 return $url . '/' . $this->get_file_name();
108 }
109 }
110