В файл /classes/modules/content/__custom.php добавляем слудеющие методы
public function page($page_id, $template = 'default'){
if(!$template) $template = "default";
$hierarchy = umiHierarchy::getInstance(); // получаем экземпл¤р коллекции
$page = $hierarchy->getElement($page_id); // получаем umiHierarchyElement, либо false, если страница не существует
if (!$page instanceof umiHierarchyElement) {
throw new publicException(getLabel('error-page-does-not-exist')); // выбрасываем исключение
} else {
if($page->getIsActive()){
list($template_block) = def_module::loadTemplates("content/page/".$template, "page_block");
$block_arr = array('id' => $page_id);
return self::parseTemplate($template_block, $block_arr, $page_id);
} else {
return '';
}
}
}
public function pageAjax(){
$templater = cmsController::getInstance()->getCurrentTemplater();
$page_id = $_REQUEST["id"];
$template = $_REQUEST["template"];
$arResult = array();
if(!$page_id) {
$arResult['error'] = $templater->putLangs("%errors_undefined_page_id%");
die(json_encode($arReturn));
};
if(!$template) $template = "default";
$hierarchy = umiHierarchy::getInstance(); // получаем экземпл¤р коллекции
$page = $hierarchy->getElement($page_id); // получаем umiHierarchyElement, либо false, если страница не существует
if (!$page instanceof umiHierarchyElement) {
$arResult['error'] = $templater->putLangs("%error-page-does-not-exist%");
die(json_encode($arReturn));
} else {
if($page->getIsActive()){
list($template_block) = def_module::loadTemplates("content/page/".$template, "page_block");
$block_arr = array('id' => $page_id);
$arReturn['result'] = self::parseTemplate($template_block, $block_arr, $page_id);
die(json_encode($arReturn));
} else {
$arResult['error'] = $templater->putLangs("%error_page_is_unactive%");
die(json_encode($arReturn));
}
}
}
public function pageAjaxRequest(){
$templater = cmsController::getInstance()->getCurrentTemplater();
$page_id = $_REQUEST["id"];
$template = $_REQUEST["template"];
$arResult = array();
if(!$page_id) {
$arResult['error'] = $templater->putLangs("%errors_undefined_page_id%");
die(json_encode($arReturn));
};
if(!$template) $template = "default";
$hierarchy = umiHierarchy::getInstance(); // получаем экземпл¤р коллекции
$page = $hierarchy->getElement($page_id); // получаем umiHierarchyElement, либо false, если страница не существует
if (!$page instanceof umiHierarchyElement) {
$arResult['error'] = $templater->putLangs("%error-page-does-not-exist%");
die(json_encode($arReturn));
} else {
if($page->getIsActive()){
list($template_block) = def_module::loadTemplates("content/page/".$template, "page_block");
$block_arr = array('id' => $page_id);
if(isset($_REQUEST["amount"]) && $_REQUEST["amount"] > 0){
$block_arr["amount"] = (int)$_REQUEST["amount"];
} else {
$block_arr["amount"] = 1;
}
$arReturn['result'] = self::parseTemplate($template_block, $block_arr, $page_id);
die(json_encode($arReturn));
} else {
$arResult['error'] = $templater->putLangs("%error_page_is_unactive%");
die(json_encode($arReturn));
}
}
}
public function sectionPages($path, $template = 'default'){
if(!$template) $template = "default";
if(!$per_page) $per_page = $this->module->per_page;
$per_page = intval($per_page);
list($template_block, $template_block_empty, $template_line) = def_module::loadTemplates("/content/page/".$template, "pages_block", "pages_block_empty", "pages_item");
$curr_page = (int) getRequest('p');
if($ignore_paging) $curr_page = 0;
$parent_id = $this->module->analyzeRequiredPath($path);
if ($parent_id === false && $path != KEYWORD_GRAB_ALL) {
throw new publicException(getLabel('error-page-does-not-exist', null, $path));
}
$this->module->loadElements($parent_id);
$pages = new selector('pages');
if ($path != KEYWORD_GRAB_ALL) {
if (is_array($parent_id)) {
foreach ($parent_id as $parent) {
$pages->where('hierarchy')->page($parent)->childs(1);
}
} else {
$pages->where('hierarchy')->page($parent_id)->childs(1);
}
}
$pages->option('load-all-props')->value(true);
$pages->limit($curr_page * $per_page, $per_page);
$result = $pages->result();
$total = $pages->length();
$umiLinksHelper = umiLinksHelper::getInstance();
$umiHierarchy = umiHierarchy::getInstance();
if(($sz = sizeof($result)) > 0) {
$block_arr = Array();
$lines = Array();
foreach ($result as $element) {
if (!$element instanceof umiHierarchyElement) {
continue;
}
$line_arr = Array();
$element_id = $element->getId();
$line_arr['attribute:id'] = $element_id;
$line_arr['node:name'] = $element->getName();
$line_arr['attribute:link'] = $umiLinksHelper->getLinkByParts($element);
$line_arr['xlink:href'] = "upage://" . $element_id;
$line_arr['void:header'] = $lines_arr['name'] = $element->getName();
$lines[] = self::parseTemplate($template_line, $line_arr, $element_id);
umiHierarchy::getInstance()->unloadElement($element_id);
}
if (is_array($parent_id)) {
list($parent_id) = $parent_id;
}
$block_arr['subnodes:items'] = $block_arr['void:lines'] = $lines;
$parent = $umiHierarchy->getElement($parent_id);
$block_arr['total'] = $total;
$block_arr['per_page'] = $per_page;
$block_arr['category_id'] = $parent_id;
return self::parseTemplate($template_block, $block_arr, $parent_id);
} else {
return $template_block_empty;
}
}
В файл /classes/modules/content/permissions.custom.php добавляем слудеющee:
$permissions = Array(
'content' =>
Array('page', 'pageAjax', 'pageAjaxRequest', 'sectionPages')
);
В папке /tpls/content/ создаем папку page/. Отсюда будут браться шаблоны для методов 'page', 'pageAjax', 'pageAjaxRequest', 'sectionPages'. Ниже пример шаблона
$FORMS = Array(); $FORMS['page_block'] = <<%items% END; $FORMS['pages_block_empty'] = ""; $FORMS['pages_item'] = << %name% END;