사이트 메뉴 전체를 가져오기
몇 일 전 디씨처럼 게시판 검색을 할 위젯이 없냐는 질문이 있었는데,
(근데 이게 실수요가 있나요?)
암튼 검색을 하려면 일단 목록을 만들어야 해서 사이트 메뉴 전체를 가져오는 소스를 짜봤습니다.
(위젯 클래스 파일로요)
function proc($args)
{
$widget_info = new stdClass();
$widget_info->menu_list = array();
$menus = executeQueryArray('menu.getMenus');
$index_menu_srl = executeQuery('widgets.widget_folder_name.getIndexMenuSrl')->data->index_menu_srl; // 첨부된 쿼리 xml 파일(getIndexMenuSrl.xml)을 위젯의 queries폴더에 저장할 것
if ( $menus->data )
{
foreach ( $menus->data as $key => $val )
{
if ( $val->menu_srl === $index_menu_srl )
{
$key = -1;
}
$widget_info->menu_list[$key] = new stdClass();
$php_file = sprintf(_XE_PATH_.'files/cache/menu/%s.php', $val->menu_srl);
include($php_file);
$widget_info->menu_list[$key]->menu_srl = $val->menu_srl;
$widget_info->menu_list[$key]->title = $val->title;
$widget_info->menu_list[$key]->list = $menu->list;
}
ksort($widget_info->menu_list);
}
// 위젯 스킨에 변수 전달
Context::set('widget_info', $widget_info);
// 템플릿의 스킨 경로를 지정 (skin, colorset에 따른 값을 설정)
$tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin);
// 템플릿 파일을 지정
$tpl_file = 'search';
// 템플릿 컴파일
$oTemplate = &TemplateHandler::getInstance();
$output = $oTemplate->compile($tpl_path, $tpl_file);
return $output;
}
{
$widget_info = new stdClass();
$widget_info->menu_list = array();
$menus = executeQueryArray('menu.getMenus');
$index_menu_srl = executeQuery('widgets.widget_folder_name.getIndexMenuSrl')->data->index_menu_srl; // 첨부된 쿼리 xml 파일(getIndexMenuSrl.xml)을 위젯의 queries폴더에 저장할 것
if ( $menus->data )
{
foreach ( $menus->data as $key => $val )
{
if ( $val->menu_srl === $index_menu_srl )
{
$key = -1;
}
$widget_info->menu_list[$key] = new stdClass();
$php_file = sprintf(_XE_PATH_.'files/cache/menu/%s.php', $val->menu_srl);
include($php_file);
$widget_info->menu_list[$key]->menu_srl = $val->menu_srl;
$widget_info->menu_list[$key]->title = $val->title;
$widget_info->menu_list[$key]->list = $menu->list;
}
ksort($widget_info->menu_list);
}
// 위젯 스킨에 변수 전달
Context::set('widget_info', $widget_info);
// 템플릿의 스킨 경로를 지정 (skin, colorset에 따른 값을 설정)
$tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin);
// 템플릿 파일을 지정
$tpl_file = 'search';
// 템플릿 컴파일
$oTemplate = &TemplateHandler::getInstance();
$output = $oTemplate->compile($tpl_path, $tpl_file);
return $output;
}
이렇게 하면 사이트 메뉴 전체 출력이 가능해집니다.
메뉴 트리 구조에 맞춰 (제 사이트 기준으로) 대강 아래와 같이 나오네요.
... 그런데 이것은 팁인가, 토픽인가;;;
예전엔 '작업기'라는 게시판이 있었는데, 암튼 "동력이 생겨" 메뉴 검색 및 검색어 자동완성도 만들게 되면 또 소식 전하겠습니다ㅎㅎ

윤삼
Lv. 19
아무래도 중급 초반 수준의 코딩 오타쿠인 것 같습니다.
댓글 6
감사해요!
초기 화면이야 트리 구조를 그대로 보여주더라도 검색 결과 화면은 그냥 병렬 구조라든가...
캐시 폴더에 있는 메뉴 php 파일들을 가져오는 것이기 때문에 '사이트 메뉴 편집'에서 각 메뉴의 '권한' 설정에 있는 '메뉴 노출 대상'에 따라 노출/비노출이 자동으로 감지될 겁니다.
=> 확인해보니 그러네요ㅎㅎ
바로가기 메뉴의 selected 실종 문제만 빼면 xe의 메뉴 구조는 거의 완벽!