위젯
위젯은 화면에서 데이터를 출력하는 데 사용되는 컴포넌트입니다. 위젯은 최신 글과 회원 정보 같은 기존 모듈이나 외부 API로부터 추출한 데이터와 함께 연동할 수 있습니다. 위젯은 모든 종류의 페이지에 추가할 수 있으며 레이아웃에 직접 추가할 수도 있습니다. 위젯을 통해 출력되는 콘텐츠를 쉽게 커스터마이즈할 수 있습니다.
위젯은 관리자가 수동으로 페이지 모듈에 입력하고 <img/> 요소에 저장합니다. 출력할 웹 페이지를 호출할 때 widgetController::triggerWidgetCompile() 트리거가 widgetproc()를 사용해서 <img/> 요소의 코드를 실행하고 올바른 HTML 코드로 변환합니다.
info.xml 파일은 위젯 제작자와 버전, 기타 설정 변수에 관한 정보를 저장합니다. 다음과 같이 작성합니다.
<?xml version="1.0" encoding="UTF-8"?>
<widget version="0.2">
<title xml:lang="en">Widget title</title>
<description xml:lang="en">Widget description</description>
<version>Widget version</version>
<date>Widget creation date</date>
<author email_address="..." link="...">
<name xml:lang="en">Author name</name>
</author>
<extra_vars>
<var id="extensionVariableName">
<name xml:lang="en">Extension variable name</name>
<type>Type of extension variable: text | textarea | select | select-multi-order | mid | mid-list | menu </type>
</var>
</extra_vars>
</widget>
위젯이 무슨 기능을 하는지는 widgetName.class.php라는 클래스 파일에 구현합니다. 위젯을 구현하는 모든 클래스는 WidgetHandler를 상속해서 proc() 메서드를 구현해야 합니다.
<?php
class myWidget extends WidgetHandler {
function proc($args) {
// .. Widget implementation ..
// Template, specify the path of the skin (skin, colorset according to the value)
$tpl_path = sprintf('%sskins/%s', $this->widget_path, $args-> skin);
Context::set ('colorset', $args->colorset);
// Template file name
$tpl_file = 'HTML template file except the extension ';
// Template compilation
$oTemplate = &TemplateHandler::getInstance();
return $oTemplate->compile($tpl_path, $tpl_file);
}
}
?>
확장 변수는 위젯을 페이지에 삽입하기 직전에 위젯의 관리 부분에서 데이터를 가져오기 위해 사용합니다. 페이지에서 자동으로 생성될 각 변수의 값을 얻기 위해 변수별로 입력 타입을 설정할 수 있다. 위젯의 확장 변수는 다음과 같습니다.
- text: 일반 문자열 타입
- textarea: 문단을 포함한 문자열 타입
- select: 여러 내용 중 하나를 선택
-
select-multi-order: 다음 그림과 같이 선택 요소를 결정하고 순서를 바꾸는 경우 사용
- mid: 모듈을 하나만 선택
- mid_list: 모듈을 여러 개 선택
- menu: 사이트 메뉴 중 하나를 선택