Server : Apache/2.4.41 (Ubuntu) System : Linux journalup 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/lib/pkp/classes/file/ |
<?php /** * @file classes/file/EditableFile.inc.php * * Copyright (c) 2014-2020 Simon Fraser University * Copyright (c) 2000-2020 John Willinsky * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. * * @class EditableFile * @ingroup file * * @brief Helper for editing XML files without losing formatting and comments * (i.e. unparsed editing). */ class EditableFile { /** @var string File contents */ var $contents; /** @var string Filename */ var $filename; /** * Constructor * @param $filename string Filename */ function __construct($filename) { import('lib.pkp.classes.file.FileWrapper'); $this->filename = $filename; $wrapper = FileWrapper::wrapper($this->filename); $this->setContents($wrapper->contents()); } /** * Determine whether the file exists. * @return boolean */ function exists() { return file_exists($this->filename); } /** * Get the file contents. * @return string */ function getContents() { return $this->contents; } /** * Set the file contents. * @param $contents string */ function setContents($contents) { $this->contents = $contents; } /** * Write the file. * @return boolean True iff success */ function write() { $fp = fopen($this->filename, 'w+'); if ($fp === false) return false; fwrite($fp, $this->getContents()); fclose($fp); return true; } /** * Perform XML escaping. (This should not be used for anything outside * of locale file editing in a fairly trusted environment. It is done * this way to preserve formatting as much as possible.) * @param $value string * @return string "Escaped" string for inclusion in XML file. */ function xmlEscape($value) { $escapedValue = XMLNode::xmlentities($value, ENT_NOQUOTES); if ($value !== $escapedValue) return "<![CDATA[$value]]>"; return $value; } }