XE:일반 회원 특수 태그 허용

Hunter Hall
Madker (토론 | 기여)님의 2019년 4월 22일 (월) 01:39 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
이동: 둘러보기, 검색

xe/classes/security/Purifier.class.php 의 _setConfig() 를 아래와 같이 편집한다.

	private function _setConfig()
	{
		$whiteDomainRegex = $this->_getWhiteDomainRegx();
		//$allowdClasses = array('emoticon');

		$this->_config = HTMLPurifier_Config::createDefault();
		$this->_config->set('HTML.TidyLevel', 'light');
		$this->_config->set('Output.FlashCompat', TRUE);
		$this->_config->set('HTML.SafeObject', TRUE);
		$this->_config->set('HTML.SafeEmbed', TRUE);
		$this->_config->set('HTML.SafeIframe', TRUE);
		$this->_config->set('URI.SafeIframeRegexp', $whiteDomainRegex);
		$this->_config->set('Cache.SerializerPath', $this->_cacheDir);
		$this->_config->set('Attr.AllowedFrameTargets', array('_blank'));
		//$this->_config->set('Attr.AllowedClasses', $allowdClasses);

		$this->_def = $this->_config->getHTMLDefinition(TRUE);
		
		$this->_def->addElement('ruby', 'Inline', 'Flow', 'Common', array());
        $this->_def->addElement('rp', 'Inline', 'Inline', 'Common', array());
        $this->_def->addElement('rt', 'Inline', 'Inline', 'Common', array());
        $this->_def->addElement('rb', 'Inline', 'Inline', 'Common', array());
        $this->_def->addElement('hide-contents', 'Block', 'Flow', 'Common', array());
		
	}

여기서는 ruby, rb, rp, rt, hide-contents 태그를 허용하도록 설정했다. 다른 태그를 허용하도록 설정하려면 addElement() 를 활용하도록 한다.[1]

추가적으로, xe/config/func.inc.php의 purifierHtml()에서 구문을 아래와 같이 수정한다.


이전

        if($logged_info->is_admin !== 'Y') {
                $oPurifier->setConfig('HTML.Nofollow', true);
        }

이후

        if($logged_info->is_admin !== 'Y') {
                //$oPurifier->setConfig('HTML.Nofollow', true);
        }

같은 효과를 적용하기 위해, xe/classes/security/Purifier.class.php 의 _setConfig() 를 아래와 같이 편집한다.


        private function _setConfig()
        {
                $whiteDomainRegex = $this->_getWhiteDomainRegx();
                //$allowdClasses = array('emoticon');

                $this->_config = HTMLPurifier_Config::createDefault();
                $this->_config->autoFinalize = false;
                $this->_config->set('HTML.TidyLevel', 'light');
                $this->_config->set('Output.FlashCompat', TRUE);
                $this->_config->set('HTML.SafeObject', TRUE);
                $this->_config->set('HTML.SafeEmbed', TRUE);
                $this->_config->set('HTML.SafeIframe', TRUE);
                $this->_config->set('URI.SafeIframeRegexp', $whiteDomainRegex);
                $this->_config->set('Cache.SerializerPath', $this->_cacheDir);
                $this->_config->set('Attr.AllowedFrameTargets', array('_blank'));

                // @see https://github.com/xpressengine/xe-core/issues/2138
                $this->_config->set('Attr.IDPrefix', 'user_content_');

                $this->_config->set('HTML.Nofollow', TRUE);
                $this->_def = $this->_config->getHTMLDefinition(TRUE);
                $this->_def->addAttribute('iframe', 'allowfullscreen', 'Text');

                $this->_def->addElement('ruby', 'Inline', 'Flow', 'Common', array());
                $this->_def->addElement('rp', 'Inline', 'Inline', 'Common', array());
                $this->_def->addElement('rt', 'Inline', 'Inline', 'Common', array());
                $this->_def->addElement('rb', 'Inline', 'Inline', 'Common', array());
                $this->_def->addElement('hide-contents', 'Block', 'Flow', 'Common', array());
	}