%PDF- %PDF- 403WebShell
403Webshell
Server IP : 37.220.80.31  /  Your IP : 18.224.54.120
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/web/dom/

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/web/dom/cssparser.php
<?php
namespace Bitrix\Main\Web\DOM;


class CssParser
{
	public static function parseDocument(Document $document, $sort = false)
	{
		$css = static::findDocumentCss($document);

		return static::parse($css, $sort);
	}

	public static function parse($css, $sort = false)
	{
		$result = static::parseCss($css);
		if($sort)
		{
			return static::sortSelectors($result);
		}
		else
		{
			return $result;
		}
	}

	public static function parseCss($css)
	{
		$result = array();

		// remove comments
		$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!','', $css);
		// remove keyframes rules
		$css = preg_replace('/@[-|keyframes].*?\{.*?\}[ \r\n]*?/s', '', $css);
		$css = trim($css);
		foreach(explode("}", $css) as $declarationBlock)
		{
			$declarationBlock = trim($declarationBlock);
			if(!$declarationBlock)
			{
				continue;
			}

			$declarationBlockExploded = explode("{", $declarationBlock);
			$selectorList = $declarationBlockExploded[0];
			$declaration = $declarationBlockExploded[1];
			$declaration = trim(trim($declaration), ";");

			foreach(explode(',', $selectorList) as $selector)
			{
				$selector = trim($selector);
				$result[] = array(
					'SELECTOR' => $selector,
					'STYLE' => static::getDeclarationArray($declaration),
				);
			}
		}

		return $result;
	}

	/**
	 * @param Document $document
	 * @return string
	 */
	public static function findDocumentCss(Document $document)
	{
		if(!$document->getHead())
		{
			return '';
		}

		if(!$document->getHead()->hasChildNodes())
		{
			return '';
		}

		$cssList = array();
		foreach($document->getHead()->getChildNodes() as $child)
		{
			/** @var $child Element */
			if($child->getNodeName() === "STYLE" && $child->getAttribute('media') !== 'print')
			{
				$cssList[] = $child->getTextContent();
				//$child->getParentNode()->removeChild($child);
			}
		}

		return implode("\n", $cssList);
	}

	public static function getDeclarationArray($declarationBlock, $singleStyle = true)
	{
		$styleList = array();
		$declarationBlock = trim($declarationBlock);
		if($declarationBlock)
		{
			// fix image urls in data:URL format with base64 encoding
			$declarationBlock = str_replace(';base64', '__base64', $declarationBlock);
			foreach(explode(";", $declarationBlock) as $declaration)
			{
				$declaration = str_replace('__base64', ';base64', $declaration);
				$declaration = trim($declaration);
				if(!$declaration)
				{
					continue;
				}

				// check declaration
				if (!preg_match('#^([-a-z0-9\*]+):(.*)$#i', $declaration, $matches))
				{
					continue;
				}

				if(!isset($matches[0], $matches[1], $matches[2]))
				{
					continue;
				}

				$matches[1] = trim($matches[1]);

				if ($singleStyle)
				{
					$styleList[$matches[1]] = trim($matches[2]);
				}
				else
				{
					if (!isset($styleList[$matches[1]]))
					{
						$styleList[$matches[1]] = [];
					}
					$styleList[$matches[1]][] = trim($matches[2]);
				}
			}
		}

		return $styleList;
	}

	public static function getDeclarationString($declarationList)
	{
		$result = '';
		foreach($declarationList as $property => $value)
		{
			if (is_array($value))
			{
				foreach ($value as $valueChunk)
				{
					$result .= trim($property) . ': ' . trim($valueChunk) . ';';
				}
			}
			else
			{
				$result .= trim($property) . ': ' . trim($value) . ';';
			}
		}

		return $result;
	}


	public static function sortSelectors($styleList)
	{
		foreach($styleList as $k => $v)
		{
			$styleList[$k]['SORT'] = static::getSelectorSort($v['SELECTOR']);
			$styleList[$k]['SORT'][] = $k;
		}

		usort($styleList, function ($first, $second)
		{
			$a = $first['SORT'];
			$b = $second['SORT'];

			for($i = 0; $i < 4; $i++)
			{
				if($a[$i] !== $b[$i])
				{
					return $a[$i] < $b[$i] ? -1 : 1;
				}
			}

			return -1; // last class have more priority
		});

		foreach($styleList as $k => $v)
		{
			unset($styleList[$k]['SORT']);
		}

		return array_reverse($styleList);
	}

	public static function getSelectorSort($selector)
	{
		return array(
			preg_match_all('/#\w/i', $selector, $result),
			preg_match_all('/\.\w/i', $selector, $result),
			preg_match_all('/^\w|\ \w|\(\w|\:[^not]/i', $selector, $result)
		);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit