Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
file_updater.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\install\helper\file_updater;
015
016 use phpbb\filesystem\exception\filesystem_exception;
017 use phpbb\filesystem\filesystem;
018 use phpbb\install\exception\file_updater_failure_exception;
019
020 /**
021 * File updater for direct filesystem access
022 */
023 class file_updater implements file_updater_interface
024 {
025 /**
026 * @var filesystem
027 */
028 protected $filesystem;
029
030 /**
031 * @var string
032 */
033 protected $phpbb_root_path;
034
035 /**
036 * Constructor
037 *
038 * @param filesystem $filesystem
039 * @param string $phpbb_root_path
040 */
041 public function __construct(filesystem $filesystem, $phpbb_root_path)
042 {
043 $this->filesystem = $filesystem;
044 $this->phpbb_root_path = $phpbb_root_path;
045 }
046
047 /**
048 * {@inheritdoc}
049 *
050 * @throws file_updater_failure_exception When the file is not writable
051 * @throws filesystem_exception When the filesystem class fails
052 */
053 public function delete_file($path_to_file)
054 {
055 $this->filesystem->remove($this->phpbb_root_path . $path_to_file);
056 }
057
058 /**
059 * {@inheritdoc}
060 *
061 * @throws file_updater_failure_exception When the file is not writable
062 * @throws filesystem_exception When the filesystem class fails
063 */
064 public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
065 {
066 $path_to_file_to_create = $this->phpbb_root_path . $path_to_file_to_create;
067
068 $dir = dirname($path_to_file_to_create);
069 if (!$this->filesystem->exists($dir))
070 {
071 $this->make_dir($dir);
072 }
073
074 $original_dir_perms = false;
075
076 if (!$this->filesystem->is_writable($dir))
077 {
078 // Extract last 9 bits we actually need
079 $original_dir_perms = @fileperms($dir) & 511;
080 $this->filesystem->phpbb_chmod($dir, filesystem::CHMOD_ALL);
081 }
082
083 if (!$create_from_content)
084 {
085 try
086 {
087 $this->filesystem->copy($source, $path_to_file_to_create);
088 }
089 catch (filesystem_exception $e)
090 {
091 $this->write_file($path_to_file_to_create, $source, $create_from_content);
092 }
093 }
094 else
095 {
096 $this->write_file($path_to_file_to_create, $source, $create_from_content);
097 }
098
099 if ($original_dir_perms !== false)
100 {
101 $this->filesystem->phpbb_chmod($dir, $original_dir_perms);
102 }
103 }
104
105 /**
106 * {@inheritdoc}
107 *
108 * @throws file_updater_failure_exception When the file is not writable
109 * @throws filesystem_exception When the filesystem class fails
110 */
111 public function update_file($path_to_file_to_update, $source, $create_from_content = false)
112 {
113 $path_to_file_to_update = $this->phpbb_root_path . $path_to_file_to_update;
114 $original_file_perms = false;
115
116 // Maybe necessary for binary files
117 $dir = dirname($path_to_file_to_update);
118 if (!$this->filesystem->exists($dir))
119 {
120 $this->make_dir($dir);
121 }
122
123 if (!$this->filesystem->is_writable($path_to_file_to_update))
124 {
125 // Extract last 9 bits we actually need
126 $original_file_perms = @fileperms($path_to_file_to_update) & 511;
127 $this->filesystem->phpbb_chmod($path_to_file_to_update, filesystem::CHMOD_WRITE);
128 }
129
130 if (!$create_from_content)
131 {
132 try
133 {
134 $this->filesystem->copy($source, $path_to_file_to_update, true);
135 }
136 catch (filesystem_exception $e)
137 {
138 $this->write_file($path_to_file_to_update, $source, $create_from_content);
139 }
140 }
141 else
142 {
143 $this->write_file($path_to_file_to_update, $source, $create_from_content);
144 }
145
146 if ($original_file_perms !== false)
147 {
148 $this->filesystem->phpbb_chmod($path_to_file_to_update, $original_file_perms);
149 }
150 }
151
152 /**
153 * Creates directory structure
154 *
155 * @param string $path Path to the directory where the file should be placed (and non-existent)
156 */
157 private function make_dir($path)
158 {
159 if (is_dir($path))
160 {
161 return;
162 }
163
164 $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
165 $this->filesystem->mkdir($path, 493); // 493 === 0755
166 }
167
168 /**
169 * Fallback function for file writing
170 *
171 * @param string $path_to_file Path to the file's location
172 * @param string $source Path to file to copy or string with the new file's content
173 * @param bool|false $create_from_content Whether or not to use $source as the content, false by default
174 *
175 * @throws file_updater_failure_exception When the file is not writable
176 */
177 private function write_file($path_to_file, $source, $create_from_content = false)
178 {
179 if (!$create_from_content)
180 {
181 $source = @file_get_contents($source);
182 }
183
184 $file_pointer = @fopen($path_to_file, 'w');
185
186 if (!is_resource($file_pointer))
187 {
188 throw new file_updater_failure_exception();
189 }
190
191 @fwrite($file_pointer, $source);
192 @fclose($file_pointer);
193 }
194
195 /**
196 * {@inheritdoc}
197 */
198 public function get_method_name()
199 {
200 return 'direct_file';
201 }
202 }
203