%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.188.43.246
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64
User : www-root ( 1010)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/main/lib/xmlwriter.php
<?php
namespace Bitrix\Main;

class XmlWriter
{
	private $file = '';
	private $charset = '';
	private $tab = 0;
	private $f = null;
	private $lowercaseTag = false;
	private $errors = array();

	/**
	 * Constructor.
	 * @param array $params Array of settings.
	 */
	public function __construct(array $params)
	{
		if (isset($params['file']))
		{
			$server = \Bitrix\Main\Application::getInstance()->getContext()->getServer();
			$this->file = $server->getDocumentRoot() . trim($params['file']);
			// create new file
			if (
				isset($params['create_file']) &&
				$params['create_file'] === true &&
				is_writable($this->file)
			)
			{
				unlink($this->file);
			}
		}
		if (isset($params['charset']))
		{
			$this->charset = trim($params['charset']);
		}
		else
		{
			$this->charset = SITE_CHARSET;
		}
		if (isset($params['lowercase']) && $params['lowercase'] === true)
		{
			$this->lowercaseTag = true;
		}
		if (isset($params['tab']))
		{
			$this->tab = (int)$params['tab'];
		}
	}

	/**
	 * Prepare tag for write.
	 * @param string $tag Code of tag.
	 * @return string
	 */
	private function prepareTag($tag)
	{
		if ($this->lowercaseTag)
		{
			$tag = mb_strtolower($tag);
		}
		return $tag;
	}

	/**
	 * Prepare value for write.
	 * @param string $value Value.
	 * @return string
	 */
	private function prepareValue($value)
	{
		$value = strtr(
				$value,
				array(
					'<' => '&lt;',
					'>' => '&gt;',
					'"' => '&quot;',
					'\'' => '&apos;',
					'&' => '&amp;',
				)
			);
		$value = preg_replace('/[\x01-\x08\x0B-\x0C\x0E-\x1F]/', '', $value);
		return $value;
	}

	/**
	 * Write begin tag to file.
	 * @param string $code Code of tag.
	 * @return void
	 */
	public function writeBeginTag($code)
	{
		if ($this->f)
		{
			fwrite($this->f, str_repeat("\t", $this->tab) . '<' . $this->prepareTag($code) . '>' . PHP_EOL);
			$this->tab++;
		}
	}

	/**
	 * Write end tag to file.
	 * @param string $code Code of tag.
	 * @return void
	 */
	public function writeEndTag($code)
	{
		if ($this->f)
		{
			$this->tab--;
			fwrite($this->f, str_repeat("\t", $this->tab) . '</' . $this->prepareTag($code) . '>' . PHP_EOL);
		}
	}

	/**
	 * Write full tag to file.
	 * @param string $code Code of tag.
	 * @param string $value Code for tag.
	 * @return void
	 */
	public function writeFullTag($code, $value)
	{
		if ($this->f)
		{
			$code = $this->prepareTag($code);
			fwrite($this->f,
							str_repeat("\t", $this->tab) .
							(
								trim($value) == ''
								? '<' . $code . ' />' . PHP_EOL
								:   '<' . $code . '>' .
										$this->prepareValue($value) .
									'</' . $code . '>' . PHP_EOL
							)
					);
		}
	}

	/**
	 * Add one more error.
	 * @param mixed $message Text of error.
	 * @param mixed $code Code of error.
	 * @return void
	 */
	private function addError($message, $code)
	{
		$this->errors[] = new Error($message, $code);
	}

	/**
	 * Return errors if exists.
	 * @return array
	 */
	public function getErrors()
	{
		return $this->errors;
	}

	/**
	 * Open file for write, start write xml.
	 * @return void
	 */
	public function openFile()
	{
		if ($this->file == '')
		{
			$this->addError('File not accessible.', 'XML_FILE_NOT_ACCESSIBLE');
		}
		else
		{
			\CheckDirPath($this->file);
			$newFile = !file_exists($this->file);
			if (file_exists($this->file) && !is_writable($this->file))
			{
				chmod($this->file, BX_FILE_PERMISSIONS);
			}
			if (($this->f = fopen($this->file, 'ab')))
			{
				chmod($this->file, BX_FILE_PERMISSIONS);
				if ($newFile)
				{
					fwrite($this->f, '<?xml version="1.0" encoding="'. $this->charset .'"?>' . PHP_EOL);
				}
			}
			else
			{
				$this->addError('File not accessible.', 'XML_FILE_NOT_ACCESSIBLE');
			}
		}
	}

	/**
	 * Close the open file.
	 * @return void
	 */
	public function closeFile()
	{
		if ($this->f)
		{
			fclose($this->f);
		}
	}

	/**
	 * Write one chunk in xml file.
	 * @param array $item Data for write.
	 * @param string $wrapperTag If != '' wrapper the array in this tag.
	 * @return void
	 */
	public function writeItem(array $item, $wrapperTag = '')
	{
		if ($wrapperTag != '')
		{
			$this->writeBeginTag($wrapperTag);
		}
		foreach ($item as $tag => $value)
		{
			if (is_array($value))
			{
				$this->writeItem($value, $tag);
			}
			else
			{
				$this->writeFullTag($tag, $value);
			}
		}
		if ($wrapperTag != '')
		{
			$this->writeEndTag($wrapperTag);
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit