обновление полей Документы из рубрики (Поиск), Документы из рубрики (Checkbox), Документы из рубрики (Дерево), Документы из рубрики (Список), Ссылка на документ ---- теперь для всех этих полей доступны теги [tag:parametr:Х] в общем шаблоне поля

This commit is contained in:
2025-12-17 17:31:37 +05:00
parent cbc4aa4b7f
commit 40f8bb95a4
5 changed files with 351 additions and 506 deletions

View File

@@ -4,7 +4,7 @@
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @version 4.x
* @filesource
* @copyright © 2007-2015 AVE.cms, http://www.ave-cms.ru
*
@@ -31,7 +31,6 @@
switch ($action)
{
case 'edit':
if (!empty($default))
{
$parent = $AVE_DB->Query("
@@ -72,94 +71,78 @@
}
else
{
// Этот блок выполняется, если $default пуст.
$AVE_Template->assign('error', $AVE_Template->get_config_vars('error'));
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
$AVE_Template->assign('subtpl', $tpl_dir."list.tpl");
return $AVE_Template->fetch($tpl_file);
break;
case 'doc':
$field_value_array = explode('|', $field_value);
$field_value_array = array_values(array_diff($field_value_array, array('')));
if ($field_value_array != false)
{
foreach ($field_value_array as $list_item)
{
if ($list_item)
{
if ($tpl_empty)
{
$list_item = $AVE_DB->Query("
SELECT
Id,
document_title,
document_alias,
document_breadcrum_title
FROM
".PREFIX."_documents
WHERE
Id = '" . $list_item . "'
")->FetchAssocArray();
}
}
$res[] = $list_item;
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'doc', $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('default', $default);
return $AVE_Template->fetch($tpl_file);
}
return (!empty($res)) ? implode(PHP_EOL, $res) : $tpl;
break;
case 'req':
$field_value_array = explode('|', $field_value);
$field_value_array = array_values(array_diff($field_value_array, array('')));
if ($field_value_array != false)
if (!empty($field_value_array))
{
foreach ($field_value_array as $list_item)
{
if ($list_item)
{
if ($tpl_empty)
// Получаем расширенные данные документа
$sql_doc = $AVE_DB->Query("
SELECT
Id,
document_title,
document_alias,
document_breadcrum_title
FROM
".PREFIX."_documents
WHERE
Id = '" . (int)$list_item . "'
LIMIT 1
");
$doc_row = $sql_doc->FetchRow();
if ($doc_row)
{
$list_item = $AVE_DB->Query("
SELECT
Id,
document_title,
document_alias,
document_breadcrum_title
FROM
".PREFIX."_documents
WHERE
Id = '" . $list_item . "'
")->FetchAssocArray();
// Индексированный массив для тегов [tag:parametr:X]
$doc_data_indexed = array(
$doc_row->Id,
$doc_row->document_title,
$doc_row->document_alias,
$doc_row->document_breadcrum_title
);
if (!$tpl_empty && !empty($tpl))
{
// Режим текстового оформления из админки
$current_tpl = $tpl;
foreach ($doc_data_indexed as $idx => $val) {
$current_tpl = str_ireplace('[tag:parametr:' . $idx . ']', $val, $current_tpl);
}
$res[] = $current_tpl;
}
else
{
// Режим работы через .tpl файл (Smarty)
$res[] = array(
'Id' => $doc_row->Id,
'document_title' => $doc_row->document_title,
'document_alias' => $doc_row->document_alias,
'document_breadcrum_title' => $doc_row->document_breadcrum_title
);
}
}
}
$res[] = $list_item;
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'req', $_tpl);
$tpl_file = get_field_tpl($tpl_dir, $field_id, $action, $_tpl);
if ($tpl_empty && $tpl_file)
if ($tpl_empty && $tpl_file && !empty($res))
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
@@ -179,7 +162,6 @@
case 'name' :
return $AVE_Template->get_config_vars('name');
break;
}
return ($res ? $res : $field_value);

View File

@@ -4,14 +4,14 @@
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @version 4.x
* @filesource
* @copyright © 2007-2015 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
// Документ из рубрики
// Документ из рубрики (Список/Select)
function get_field_doc_from_rub_list($field_value, $action, $field_id=0, $tpl='', $tpl_empty=0, &$maxlength=null, $document_fields=array(), $rubric_id=0, $default=null, $_tpl=null)
{
global $AVE_DB, $AVE_Template;
@@ -25,12 +25,11 @@
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
$res = 0;
$res = array();
switch ($action)
{
case 'edit':
if (!empty($default))
{
$sql = $AVE_DB->Query("
@@ -41,13 +40,13 @@
WHERE
rubric_id IN (" . $default . ")
ORDER BY
document_title DESC
document_title ASC
");
$cats = [];
while ($cat = $sql->FetchAssocArray())
array_push($cats, $cat);
$cats = array();
while ($cat = $sql->FetchAssocArray()) {
$cats[] = $cat;
}
$AVE_Template->assign('fields', $cats);
$AVE_Template->assign('field_id', $field_id);
@@ -56,87 +55,64 @@
}
else
{
// Если $default пуст, выводим ошибку, а не выполняем SQL
$AVE_Template->assign('error', $AVE_Template->get_config_vars('error'));
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
return $AVE_Template->fetch($tpl_file);
break;
case 'doc':
$document = get_document($field_value);
if ($tpl_empty)
{
$field_value = isset($document['document_title']) ? $document['document_title'] : '';
$field_value = clean_php($field_value);
$field_value = stripcslashes($field_value);
$field_value = htmlspecialchars_decode($field_value);
}
else
{
$field_param = explode('|', $field_value);
$field_value = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'doc', $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $field_value);
$AVE_Template->assign('document', $document);
return $AVE_Template->fetch($tpl_file);
}
$res = $field_value;
break;
case 'req':
$document = get_document($field_value);
// Получаем данные документа
$sql_doc = $AVE_DB->Query("
SELECT Id, document_title, document_alias, document_breadcrum_title
FROM ".PREFIX."_documents
WHERE Id = '" . (int)$field_value . "'
LIMIT 1
");
$doc_row = $sql_doc->FetchRow();
if ($tpl_empty)
if ($doc_row)
{
$field_value = $document['document_title'];
$field_value = clean_php($field_value);
$field_value = stripcslashes($field_value);
$field_value = htmlspecialchars_decode($field_value);
}
else
// Готовим данные для тегов
$doc_data_indexed = array(
$doc_row->Id,
$doc_row->document_title,
$doc_row->document_alias,
$doc_row->document_breadcrum_title
);
if (!$tpl_empty && !empty($tpl))
{
$field_param = explode('|', $field_value);
$field_value = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
// (Оформление поля)
$field_value = $tpl;
foreach ($doc_data_indexed as $idx => $val) {
$field_value = str_ireplace('[tag:parametr:' . $idx . ']', $val, $field_value);
}
}
elseif ($tpl_empty)
{
// Если оформления нет, отдаем чистый заголовок (как и было)
$field_value = htmlspecialchars_decode(stripcslashes($doc_row->document_title));
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'req', $_tpl);
$tpl_file = get_field_tpl($tpl_dir, $field_id, $action, $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $field_value);
$AVE_Template->assign('document', $document);
return $AVE_Template->fetch($tpl_file);
if ($tpl_empty && $tpl_file)
{
// Работаем с .tpl файл
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $field_value);
$AVE_Template->assign('document', (array)$doc_row);
return $AVE_Template->fetch($tpl_file);
}
}
else {
$field_value = '';
}
$res = $field_value;
return $field_value;
break;
case 'api':
@@ -147,6 +123,6 @@
return $AVE_Template->get_config_vars('name');
break;
}
return ($res ? $res : $field_value);
return $field_value;
}
?>

View File

@@ -1,259 +1,190 @@
<?php
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2015 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
/**
* AVE.cms
*
* @package AVE.cms
* @version 4.x
* @filesource
* @copyright © 2007-2015 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
// Документы из рубрик (Поиск)
function get_field_doc_from_rub_search($field_value, $action, $field_id=0, $tpl='', $tpl_empty=0, &$maxlength = '', $doc_fields=array(), $rubric_id=0, $default=null, $_tpl=null)
{
global $AVE_DB, $AVE_Template;
// Документы из рубрик (Поиск)
function get_field_doc_from_rub_search($field_value, $action, $field_id=0, $tpl='', $tpl_empty=0, &$maxlength = '', $doc_fields=array(), $rubric_id=0, $default=null, $_tpl=null)
{
global $AVE_DB, $AVE_Template;
$fld_dir = dirname(__FILE__) . '/';
$tpl_dir = $fld_dir . 'tpl/';
$fld_name = basename($fld_dir);
$fld_dir = dirname(__FILE__) . '/';
$tpl_dir = $fld_dir . 'tpl/';
$fld_name = basename($fld_dir);
$lang_file = $fld_dir . 'lang/' . (defined('ACP') ? $_SESSION['admin_language'] : $_SESSION['user_language']) . '.txt';
$lang_file = $fld_dir . 'lang/' . (defined('ACP') ? $_SESSION['admin_language'] : $_SESSION['user_language']) . '.txt';
$AVE_Template->config_load($lang_file, 'lang');
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
$AVE_Template->config_load($lang_file, 'lang');
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
$res = array();
$res = array();
switch ($action)
{
case 'edit':
switch ($action)
{
case 'edit':
$items = array();
if ($field_value != '' && $field_value != $default)
{
$items = explode('|', $field_value);
$items = array_values(array_diff($items, array('')));
}
$items = array();
if ($field_value != '' && $field_value != $default)
{
$items = explode('|', $field_value);
$items = array_values(array_diff($items, array('')));
}
if (! empty($items))
{
foreach($items as $k => $v)
{
$list[$k]['param'] = htmlspecialchars(get_document($v, 'document_title'), ENT_QUOTES);
$list[$k]['value'] = $v;
}
$items = $list;
}
else
{
$items[0]['param'] = '';
$items[0]['value'] = '';
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
$AVE_Template->assign('doc_id', isset($_REQUEST['Id']) ? (int)$_REQUEST['Id'] : 0);
$AVE_Template->assign('items', $items);
$AVE_Template->assign('field_dir', $fld_name);
$AVE_Template->assign('field_id', $field_id);
return $AVE_Template->fetch($tpl_file);
case 'save':
foreach ($field_value as $v)
{
if (! empty($v['value']))
{
$field_value_new[] = $v['value'];
}
}
if (isset($field_value_new))
{
return '|' . implode('|', $field_value_new) . '|';
}
else
{
return $field_value_new = '';
}
break;
case 'doc':
$field_value_array = explode('|', $field_value);
$field_value_array = array_values(array_diff($field_value_array, array('')));
if ($field_value_array != false)
{
foreach ($field_value_array as $list_item)
{
if ($list_item)
{
if ($tpl_empty)
{
$list_item = $AVE_DB->Query("
SELECT
Id,
document_title,
document_alias,
document_breadcrum_title
FROM
".PREFIX."_documents
WHERE
Id = '" . $list_item . "'
")->FetchAssocArray();
}
}
$res[] = $list_item;
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'doc', $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('default', $default);
return $AVE_Template->fetch($tpl_file);
}
return (! empty($res)) ? implode(PHP_EOL, $res) : $tpl;
break;
case 'req':
$field_value_array = explode('|', $field_value);
$field_value_array = array_values(array_diff($field_value_array, array('')));
if ($field_value_array != false)
{
foreach ($field_value_array as $list_item)
{
if ($list_item)
{
if ($tpl_empty)
{
$list_item = $AVE_DB->Query("
SELECT
Id,
document_title,
document_alias,
document_breadcrum_title
FROM
".PREFIX."_documents
WHERE
Id = '" . $list_item . "'
")->FetchAssocArray();
}
}
$res[] = $list_item;
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'req', $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('default', $default);
return $AVE_Template->fetch($tpl_file);
}
return (! empty($res)) ? implode(PHP_EOL, $res) : $tpl;
break;
case 'api' :
$items = [];
if ($field_value != '' && $field_value != $default)
{
$items = explode('|', $field_value);
$items = array_values(array_diff($items, array('')));
}
if (! empty($items))
{
foreach($items as $k => $v)
{
$list[$k]['param'] = htmlspecialchars_decode(get_document($v, 'document_title'), ENT_QUOTES);
$list[$k]['value'] = $v;
}
$items = $list;
}
else
{
$items[0]['param'] = '';
$items[0]['value'] = '';
}
return $items;
break;
case 'name' :
return $AVE_Template->get_config_vars('name');
break;
case 'search':
$default = get_field_default_value($_REQUEST['field_id']);
// Проверяем, что ID рубрик существуют.
// Если $default пуст, выходим, чтобы не создавать невалидный запрос.
if (empty($default)) {
echo json_encode(array());
exit;
if (!empty($items))
{
foreach($items as $k => $v)
{
$list[$k]['param'] = htmlspecialchars(get_document($v, 'document_title'), ENT_QUOTES);
$list[$k]['value'] = $v;
}
$items = $list;
}
else
{
$items[0]['param'] = '';
$items[0]['value'] = '';
}
$sql = $AVE_DB->Query("
SELECT
doc.Id,
doc.document_title,
rub.rubric_title
FROM
" . PREFIX . "_documents AS doc
JOIN
" . PREFIX . "_rubrics AS rub
ON doc.rubric_id = rub.Id
WHERE
doc.rubric_id IN (" . $default . ")
AND
doc.document_status = 1
AND
UPPER (doc.document_title) LIKE UPPER('%" . $_REQUEST['q'] . "%')
GROUP BY
doc.Id
LIMIT
0,5
");
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
$AVE_Template->assign('doc_id', isset($_REQUEST['Id']) ? (int)$_REQUEST['Id'] : 0);
$AVE_Template->assign('items', $items);
$AVE_Template->assign('field_dir', $fld_name);
$AVE_Template->assign('field_id', $field_id);
$doc_finded = array();
return $AVE_Template->fetch($tpl_file);
while ($row = $sql->FetchRow())
{
$doc_finded[] = array(
'doc_id' => $row->Id,
'doc_title' => $row->document_title,
'doc_rubric' => $row->rubric_title
);
}
case 'save':
$field_value_new = array();
if (is_array($field_value)) {
foreach ($field_value as $v) {
if (!empty($v['value'])) $field_value_new[] = $v['value'];
}
}
echo json_encode($doc_finded);
exit;
if (!empty($field_value_new)) {
return '|' . implode('|', $field_value_new) . '|';
} else {
return '';
}
break;
default:
return $field_value;
}
case 'doc':
case 'req':
$field_value_array = explode('|', $field_value);
$field_value_array = array_values(array_diff($field_value_array, array('')));
return ($res ? $res : $field_value);
}
if (!empty($field_value_array))
{
foreach ($field_value_array as $list_item)
{
if ($list_item)
{
$sql_doc = $AVE_DB->Query("
SELECT Id, document_title, document_alias, document_breadcrum_title
FROM ".PREFIX."_documents
WHERE Id = '" . (int)$list_item . "'
LIMIT 1
");
$doc_row = $sql_doc->FetchRow();
if ($doc_row)
{
// Формируем массив для замены тегов [tag:parametr:X]
$doc_data_indexed = array(
$doc_row->Id,
$doc_row->document_title,
$doc_row->document_alias,
$doc_row->document_breadcrum_title
);
if (!$tpl_empty && !empty($tpl))
{
// Режим оформления через админку
$current_tpl = $tpl;
foreach ($doc_data_indexed as $idx => $val) {
$current_tpl = str_ireplace('[tag:parametr:' . $idx . ']', $val, $current_tpl);
}
$res[] = $current_tpl;
}
else
{
// Режим шаблона .tpl
$res[] = array(
'Id' => $doc_row->Id,
'document_title' => $doc_row->document_title,
'document_alias' => $doc_row->document_alias,
'document_breadcrum_title' => $doc_row->document_breadcrum_title
);
}
}
}
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, $action, $_tpl);
if ($tpl_empty && $tpl_file && !empty($res))
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('default', $default);
return $AVE_Template->fetch($tpl_file);
}
return (!empty($res)) ? implode(PHP_EOL, $res) : $tpl;
break;
case 'api' :
$items = array();
if ($field_value != '' && $field_value != $default) {
$items = explode('|', $field_value);
$items = array_values(array_diff($items, array('')));
}
if (!empty($items)) {
foreach($items as $k => $v) {
$list[$k]['param'] = htmlspecialchars_decode(get_document($v, 'document_title'), ENT_QUOTES);
$list[$k]['value'] = $v;
}
$items = $list;
}
return $items;
case 'name' :
return $AVE_Template->get_config_vars('name');
case 'search':
$default = get_field_default_value($_REQUEST['field_id']);
if (empty($default)) { echo json_encode(array()); exit; }
$sql = $AVE_DB->Query("
SELECT doc.Id, doc.document_title, rub.rubric_title
FROM " . PREFIX . "_documents AS doc
JOIN " . PREFIX . "_rubrics AS rub ON doc.rubric_id = rub.Id
WHERE doc.rubric_id IN (" . $default . ")
AND doc.document_status = 1
AND UPPER (doc.document_title) LIKE UPPER('%" . $_REQUEST['q'] . "%')
GROUP BY doc.Id LIMIT 0,5
");
$doc_finded = array();
while ($row = $sql->FetchRow()) {
$doc_finded[] = array('doc_id' => $row->Id, 'doc_title' => $row->document_title, 'doc_rubric' => $row->rubric_title);
}
echo json_encode($doc_finded);
exit;
default:
return $field_value;
}
}
?>

View File

@@ -11,7 +11,7 @@
* @license GPL v.2
*/
// Документ из рубрики
// Документ из рубрики (Дерево)
function get_field_doc_from_rub_tree($field_value, $action, $field_id=0, $tpl='', $tpl_empty=0, &$maxlength=null, $document_fields=array(), $rubric_id=0, $default=null, $_tpl=null)
{
global $AVE_DB, $AVE_Template;
@@ -25,15 +25,13 @@
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
$res = 0;
$res = array();
switch ($action)
{
case 'edit':
// !!! ИСПРАВЛЕНИЕ: Проверяем, что $default НЕ ПУСТ (isset и !empty)
case 'edit':
if (!empty($default))
{
// SQL-запрос 1: Получение минимального родителя
$parent = $AVE_DB->Query("
SELECT
MIN(document_parent) AS min
@@ -43,7 +41,6 @@ case 'edit':
rubric_id IN (" . $default . ")
")->GetCell();
// SQL-запрос 2: Получение списка документов
$sql = $AVE_DB->Query("
SELECT
Id, document_parent, document_title
@@ -54,10 +51,8 @@ case 'edit':
");
$cats = array();
while ($cat = $sql->FetchAssocArray())
{
$cats_ID[$cat['Id']][] = $cat;
$cats[$cat['document_parent']][$cat['Id']] = $cat;
}
@@ -69,87 +64,64 @@ case 'edit':
}
else
{
// Если $default пуст, мы выводим ошибку, как и в оригинальном коде
$AVE_Template->assign('error', $AVE_Template->get_config_vars('error'));
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
return $AVE_Template->fetch($tpl_file);
break;
case 'doc':
$document = get_document($field_value);
if ($tpl_empty)
{
$field_value = isset($document['document_title']) ? $document['document_title'] : '';
$field_value = clean_php($field_value);
$field_value = stripcslashes($field_value);
$field_value = htmlspecialchars_decode($field_value);
}
else
{
$field_param = explode('|', $field_value);
$field_value = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'doc', $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $field_value);
$AVE_Template->assign('document', $document);
return $AVE_Template->fetch($tpl_file);
}
$res = $field_value;
break;
case 'req':
$document = get_document($field_value);
// Получаем основные данные документа по ID
$sql_doc = $AVE_DB->Query("
SELECT Id, document_title, document_alias, document_breadcrum_title
FROM ".PREFIX."_documents
WHERE Id = '" . (int)$field_value . "'
LIMIT 1
");
$doc_row = $sql_doc->FetchRow();
if ($tpl_empty)
if ($doc_row)
{
$field_value = $document['document_title'];
$field_value = clean_php($field_value);
$field_value = stripcslashes($field_value);
$field_value = htmlspecialchars_decode($field_value);
}
else
// Индексированный массив для тегов [tag:parametr:X]
$doc_data_indexed = array(
$doc_row->Id,
$doc_row->document_title,
$doc_row->document_alias,
$doc_row->document_breadcrum_title
);
if (!$tpl_empty && !empty($tpl))
{
$field_param = explode('|', $field_value);
$field_value = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
// Обработка текстового оформления (Screenshot 2)
$field_value = $tpl;
foreach ($doc_data_indexed as $idx => $val) {
$field_value = str_ireplace('[tag:parametr:' . $idx . ']', $val, $field_value);
}
}
elseif ($tpl_empty)
{
// Стандартный вывод заголовка, если шаблон пуст
$field_value = htmlspecialchars_decode(stripcslashes($doc_row->document_title));
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'req', $_tpl);
$tpl_file = get_field_tpl($tpl_dir, $field_id, $action, $_tpl);
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $field_value);
$AVE_Template->assign('document', $document);
return $AVE_Template->fetch($tpl_file);
if ($tpl_empty && $tpl_file)
{
// Для работы через .tpl (Smarty)
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $field_value);
$AVE_Template->assign('document', (array)$doc_row);
return $AVE_Template->fetch($tpl_file);
}
}
else {
$field_value = '';
}
$res = $field_value;
return $field_value;
break;
case 'api':
@@ -160,14 +132,14 @@ case 'edit':
return $AVE_Template->get_config_vars('name');
break;
}
return ($res ? $res : $field_value);
return $field_value;
}
if (! function_exists('doc_from_rub_tree'))
{
function doc_from_rub_tree($cats, $parent)
{
$array = array();
if (is_array($cats) and isset($cats[$parent]))
{
foreach($cats[$parent] as $cat)
@@ -178,10 +150,9 @@ case 'edit':
}
}
else
{
return null;
}
{
return null;
}
return $array;
}
}

View File

@@ -4,9 +4,9 @@
* AVE.cms - Поле "Ссылка на документ"
*
* @package AVE.cms
* @version 3.x
* @version 4.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
* @copyright © 2007-2015 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
@@ -29,7 +29,6 @@
switch ($action)
{
case 'edit':
$field_value = clean_php($field_value);
$field_param = explode('|', $field_value);
@@ -38,7 +37,7 @@
$clean_field_value .= '|' . $field_param[1];
}
$doc_id = 0;
$doc_id = 0;
$document_name_to_display = '';
if (preg_match('/id=([0-9]+)/i', $clean_field_value, $matches)) {
@@ -53,98 +52,85 @@
$document_name_to_display = 'Главная страница';
}
}
$AVE_Template->assign('display_value', $document_name_to_display);
$AVE_Template->assign('display_value', $document_name_to_display);
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $clean_field_value);
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
return $AVE_Template->fetch($tpl_file);
break;
case 'doc':
case 'doc':
case 'req':
$field_value = clean_php($field_value);
$field_param = explode('|', $field_value);
$doc_id = 0;
if (preg_match('/id=([0-9]+)/i', $field_param[0], $matches)) {
$doc_id = (int)$matches[1];
}
$url_href = '';
$anchor = '';
$title = '';
$alias = '';
$title = '';
$bread = '';
$user_anchor = isset($field_param[1]) ? $field_param[1] : '';
if ($doc_id > 0)
{
$document_data = get_document($doc_id);
if ($document_data)
{
$alias = isset($document_data['document_alias']) ? $document_data['document_alias'] : '';
$title = isset($document_data['document_title']) ? $document_data['document_title'] : '';
$bread = isset($document_data['document_breadcrum_title']) ? $document_data['document_breadcrum_title'] : '';
// Формируем готовую ссылку (URL)
if ($alias === '/') {
$url_href = '/';
} else {
$url_href = '/' . trim($alias, '/');
if (defined('URL_SUFF') && URL_SUFF) {
$url_href .= URL_SUFF;
}
}
if (!empty($user_anchor) && $user_anchor !== $field_param[0]) {
$anchor = $user_anchor;
} elseif (!empty($title)) {
$anchor = $title;
} elseif ($alias === '/') {
$anchor = 'Главная';
} else {
$anchor = '';
}
// Формируем Анкор (текст ссылки)
$anchor = !empty($user_anchor) ? $user_anchor : (!empty($title) ? $title : $url_href);
}
}
if ($doc_id === 0) {
else
{
// Если внешняя ссылка
$url_href = $field_param[0];
$anchor = isset($field_param[1]) ? $field_param[1] : $field_param[0];
$url_href = str_replace('//', '/', $url_href);
$url_href = str_replace('https:/', 'https://', $url_href);
$url_href = str_replace('http:/', 'http://', $url_href);
$anchor = !empty($user_anchor) ? $user_anchor : $field_param[0];
$url_href = str_replace(array('http:/', 'https:/'), array('http://', 'https://'), str_replace('//', '/', $url_href));
}
$action_is_req = ($action === 'req');
$use_inline_tpl = ($action_is_req && isset($document_fields[$rubric_id]['tpl_req_empty'])) || (!$action_is_req && $tpl_empty);
if ($use_inline_tpl)
if (!$tpl_empty && !empty($tpl))
{
$field_value = ' <a target="_self" href="' . $url_href . '">' . $anchor . '</a>';
$res = $tpl;
// СТРОГОЕ СОБЛЮДЕНИЕ ОБЩЕГО СТАНДАРТА + ДОП. ПАРАМЕТРЫ
$doc_data_indexed = array(
$doc_id, // 0 - ID
$title, // 1 - Название
$alias, // 2 - Алиас
$bread, // 3 - Крошки
$url_href, // 4 - Готовый URL
$anchor // 5 - Текст ссылки (Анкор)
);
foreach ($doc_data_indexed as $idx => $val) {
$res = str_ireplace('[tag:parametr:' . $idx . ']', $val, $res);
}
}
else
{
$field_value = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($anchor, $url_href)
{
return $anchor;
},
$tpl
);
$res = '<a href="' . $url_href . '">' . $anchor . '</a>';
}
$maxlength = null;
$res = $field_value;
return $res;
break;
case 'api' :
@@ -154,7 +140,6 @@
case 'name' :
return $AVE_Template->get_config_vars('name');
break;
}
return ($res ? $res : $field_value);
}