<commit_before><?php

/**
 * Tag IMG
 * @package Parser
 * @subpackage Filters
 * @author wookieb
 * @version 1.1
 */
class BbCodeFilterImage {
	/**
	 * Maksymalna szerokosc zdjecia
	 * @var int
	 */
	public $imageMaxWidth = 100;
	/**
	 * Maksymalna wysokosc zdjecia
	 * @var int
	 */
	public $imageMaxHeight = 100;
	/**
	 * Minimalna szerokosc zdjecia
	 * @var int
	 */
	public $imageMinWidth = 30;
	/**
	 * Minimalna wysokosc zdjecia
	 * @var int
	 */
	public $imageMinHeight = 60;
	/**
	 * Czy sprawdzac prawdziwy rozmiar zdjecia
	 * @var bool
	 */
	public $checkRealImageSize = false;
	/**
	 * Maksymalny czas pobierania pliku
	 * @var int
	 */
	public $socketTimeout = 5;
	public $tags = array(
		'img' => array(
			'open' => 'img alt=""',
			'close' => 'img',
			'notallowed_childs' => 'all',
			'hide_body_in_cut_text' => true,
			'parse_body' => 'checkImg',
			'attributes' => array(
				'img' => array(
					'attr' => '',
					'type' => 'string'
				),
				'src' => array(
					'attr' => 'src',
					'tag_no_show' => 1
				),
				'width' => array(
					'no_changeable' => 1,
					'attr' => 'width',
					'tag_no_show' => 1
				),
				'height' => array(
					'no_changeable' => 1,
					'attr' => 'height',
					'tag_no_show' => 1
				)
			)
		)
	);

	/**
	 * Parsuje IMG
	 * @param array $tag
	 * @param array $openNode
	 * @param array $body
	 * @param array $cNode
	 * @param BbCodeSettings $settings
	 */
	public function checkImg($tag, &$openNode, &$body, &$cNode, $settings) {
		require_once dirname(__FILE__).'/../DataValidator.php';

		$bodyStr = '';
		foreach ($body as $el)
			$bodyStr.=$el['text'];
		$str = DataValidator::checkUrl($bodyStr);

		if ($str == false) {
			$openNode = $settings->removeNode($openNode, $settings->removeInvalidTags);
			$cNode = $settings->removeNode($cNode, $settings->removeInvalidTags);
			return false;
		}

		$openNode['attributes']['tag_attributes']['src'] = $str;
		unset($el);

		if (isset($openNode['attributes']['tag_attributes']['img'])) {
			$tagSizes = explode('x', $openNode['attributes']['tag_attributes']['img']);

			if (is_array($tagSizes)) {
				$tagSizes = array_map('trim', $tagSizes);

				if (isset($tagSizes[0]) && is_numeric($tagSizes[0])) {
					$openNode['attributes']['tag_attributes']['width'] = round($tagSizes[0]);
				}
				if (isset($tagSizes[1]) && is_numeric($tagSizes[1])) {
					$openNode['attributes']['tag_attributes']['height'] = round($tagSizes[1]);
				}
			}
		}

		// wlaczona kontrola wielkosci zdjecia i czy zawsze mozemy taką kontrolę przeprowadzic
		if (($this->imageMaxWidth > 0
				|| $this->imageMaxHeight > 0
				|| $this->imageMinHeight > 0
				|| $this->imageMinHeight > 0
		)) {
			if (ini_get('allow_url_fopen') && $this->checkRealImageSize) {
				// ustawienie maksymalnego czasu pobierania info o zdjeciu
				$oldDefaultSocketTimeout = ini_get('default_socket_timeout');
				$socketTimeout = 5;
				if (isset($this->socketTimeout) && $this->socketTimeout >= 0)
					$socketTimeout = $this->socketTimeout;<commit_msg>added ALT attribute for images<commit_after><?php

/**
 * Tag IMG
 * @package Parser
 * @subpackage Filters
 * @author wookieb
 * @version 1.1
 */
class BbCodeFilterImage {
	/**
	 * Maksymalna szerokosc zdjecia
	 * @var int
	 */
	public $imageMaxWidth = 100;
	/**
	 * Maksymalna wysokosc zdjecia
	 * @var int
	 */
	public $imageMaxHeight = 100;
	/**
	 * Minimalna szerokosc zdjecia
	 * @var int
	 */
	public $imageMinWidth = 30;
	/**
	 * Minimalna wysokosc zdjecia
	 * @var int
	 */
	public $imageMinHeight = 60;
	/**
	 * Czy sprawdzac prawdziwy rozmiar zdjecia
	 * @var bool
	 */
	public $checkRealImageSize = false;
	/**
	 * Maksymalny czas pobierania pliku
	 * @var int
	 */
	public $socketTimeout = 5;
	public $tags = array(
		'img' => array(
			'open' => 'img',
			'close' => 'img',
			'notallowed_childs' => 'all',
			'hide_body_in_cut_text' => true,
			'parse_body' => 'checkImg',
			'attributes' => array(
				'img' => array(
					'attr' => '',
					'type' => 'string'
				),
				'src' => array(
					'attr' => 'src',
					'tag_no_show' => 1
				),
				'width' => array(
					'no_changeable' => 1,
					'attr' => 'width',
					'tag_no_show' => 1
				),
				'height' => array(
					'no_changeable' => 1,
					'attr' => 'height',
					'tag_no_show' => 1
				),
				'alt' => array(
					'attr' => 'alt',
					'default_value' => ''
				)
			)
		)
	);

	/**
	 * Parsuje IMG
	 * @param array $tag
	 * @param array $openNode
	 * @param array $body
	 * @param array $cNode
	 * @param BbCodeSettings $settings
	 */
	public function checkImg($tag, &$openNode, &$body, &$cNode, $settings) {
		require_once dirname(__FILE__).'/../DataValidator.php';

		$src = '';
		if (isset($openNode['attributes']['tag_attributes']['img'])) {
			$src = DataValidator::checkUrl($openNode['attributes']['tag_attributes']['img']);
		}

		$bodyStr = '';
		foreach ($body as $el)
			$bodyStr.=$el['text'];

		$bodyUrl = DataValidator::checkUrl($bodyStr);
		if ($bodyUrl) {
			$openNode['attributes']['tag_attributes']['img'] = $bodyUrl;
		} else if ($bodyStr) {
			$openNode['attributes']['tag_attributes']['alt'] = $bodyStr;
		}

		if ($src == false) {
			$openNode = $settings->removeNode($openNode, $settings->removeInvalidTags);
			$cNode = $settings->removeNode($cNode, $settings->removeInvalidTags);
			return false;
		}

		$openNode['attributes']['tag_attributes']['src'] = $src;
		unset($el);

		if (isset($openNode['attributes']['tag_attributes']['img'])) {
			$tagSizes = explode('x', $openNode['attributes']['tag_attributes']['img']);

			if (is_array($tagSizes)) {
				$tagSizes = array_map('trim', $tagSizes);

				if (isset($tagSizes[0]) && is_numeric($tagSizes[0])) {
					$openNode['attributes']['tag_attributes']['width'] = round($tagSizes[0]);
				}
				if (isset($tagSizes[1]) && is_numeric($tagSizes[1])) {
					$openNode['attributes']['tag_attributes']['height'] = round($tagSizes[1]);
				}
			}
		}

		// wlaczona kontrola wielkosci zdjecia i czy zawsze mozemy taką kontrolę przeprowadzic
		if (($this->imageMaxWidth > 0
				|| $this->imageMaxHeight > 0
				|| $this->imageMinHeight > 0
				|| $this->imageMinHeight > 0
		)) {
			if (ini_get('allow_url_fopen') && $this->checkRealImageSize) {
				// ustawienie maksymalnego czasu pobierania info o zdjeciu
				$oldDefaultSocketTimeout = ini_get('default_socket_timeout');
				$socketTimeout = 5;
				if (isset($this->socketTimeout) && $this->socketTimeout >= 0)
					$socketTimeout = $this->socketTimeout;
{'fraction_non_alphanumeric': 0.18607164916615196, 'fraction_numerical': 0.00926497838171711, 'mean_word_length': 3.5293706293706295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7522971', 'n_tokens_mistral': 2762, 'n_tokens_neox': 2322, 'n_words': 455}