비타주리 님 코드에서 이 코드의 의미는 뭘까요?

비타주리 님 코드에서 이 코드의 의미는 뭘까요?

QA

비타주리 님 코드에서 이 코드의 의미는 뭘까요?

본문

$add_html_tag -> addElement('input', 'Block', 'Flow', 'Common', ['type' => 'Text', 'id' => 'Text', 'name' => 'Text', 'value' => 'Text', 'checked' => 'Bool']);

 

각 자리의 의미와 각 자리에 올 수 있는 값들엔 어떤 것들이 있는지 궁금합니다.

 

이 질문에 댓글 쓰기 :

답변 2

이걸 직접 만든 사이트의 설명입니다.

http://htmlpurifier.org/docs/enduser-customize.html

여기에는 예제로 form 을 들고 있어요.

 

$form = $def->addElement(
  'form',   // name
  'Block',  // content set
  'Flow', // allowed children
  'Common', // attribute collection
  array( // attributes
    'action*' => 'URI',
    'method' => 'Enum#get|post',
    'name' => 'ID'
  )
);

 

위의 변수를 다시 네이밍하고 코드를 한 줄로 바꾸면서 주석을 빼고 배열을 대괄호 처리한 것입니다.

 

나머지 궁금한 부분도 이 페이지에 다 나와 있습니다.

예를 들어 content set 에는 Inline, Block, false 의 3종류가 있는데 각기 span형, div형, li형이 대표이구요.

사실 span 같은 경우도 <span style="display:block"> 를 주면 div 와 같아지는 것이라 편하게 div 형으로 통일한 것입니다.

 

참고로 'name' => 'ID' 를 저는 'name' => 'Text' 로 쓰는데 type 의 8가지 종류 중에

Bool 과 CDATA 2개로 충분하다는게 제 테스트의 결과이고 설명서에서 CDATA 는 Text 로 사용해도 상관없다고 나와 있어서 한글자라도 덜 쓰고 알아보기 쉬운 Text 를 쓰고 있어요.


 
    /**
     * Adds a custom element to your HTML definition
     *  HTMLPurifier_HTMLModule::addElement() for detailed
     *       parameter and return value descriptions.
     */
    public function addElement($element_name, $type, $contents, $attr_collections, $attributes = array())
    {
        $module = $this->getAnonymousModule();
        // assume that if the user is calling this, the element
        // is safe. This may not be a good idea
        $element = $module->addElement($element_name, $type, $contents, $attr_collections, $attributes);
        return $element;
    }
 

 


    public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array())
    {
        $this->elements[] = $element;
        // parse content_model
        list($content_model_type, $content_model) = $this->parseContents($contents);
        // merge in attribute inclusions
        $this->mergeInAttrIncludes($attr, $attr_includes);
        // add element to content sets
        if ($type) {
            $this->addElementToContentSet($element, $type);
        }
        // create element
        $this->info[$element] = HTMLPurifier_ElementDef::create(
            $content_model,
            $content_model_type,
            $attr
        );
        // literal object $contents means direct child manipulation
        if (!is_string($contents)) {
            $this->info[$element]->child = $contents;
        }
        return $this->info[$element];
    }
 
답변을 작성하시기 전에 로그인 해주세요.
전체 176
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT