Browse Source

Добавлен Модуль Навигация по документам рубрики

master
SVarlamov 9 years ago
commit
ad1628c685
  1. 15
      README.md
  2. 124
      class.rubnav.php
  3. 21
      lang/ru.txt
  4. 143
      module.php
  5. 44
      sql.php
  6. 173
      templates/admin_config.tpl

15
README.md

@ -0,0 +1,15 @@
## rubnav
# Модуль Навигация по документам рубрики v1.1.2
## Навигация по документам в пределах рубрики (следущая-предыдущая)
* Инструкция:<br />[mod_rubnav:next] - следущая<br />[mod_rubnav:prev] - предыдущая
## Перед копированием модуля в папку modules, удалите файл README.md, копируйте только корневую папку rubnav со всем ее содержимым внутри!
## Changelog:
05.05.2014 - версия 1.1.2

124
class.rubnav.php

@ -0,0 +1,124 @@
<?php
/**
* AVE.cms - Навигация по рубрике
*
* @filesource
*/
/**
* Класс работы с Навигация по рубрике
*
* @package AVE.cms
* @subpackage module_RubNav
*/
class rubnav
{
/**
* Путь к директории с шаблонами модуля
*
* @var string
*/
var $_tpl_dir;
/**
* Путь к языковому файлу
*
* @var string
*/
var $_lang_file;
/**
* Конструктор
*
* @param string $tpl_dir путь к директории с шаблонами модуля
* @param string $lang_file путь к языковому файлу
* @return Login
*/
function RubNav($tpl_dir, $lang_file)
{
$this->_tpl_dir = $tpl_dir;
$this->_lang_file = $lang_file;
}
/**
* Управление модулем Навигация по рубрике
*
*/
function _rubnavSettingsGet($field = '')
{
global $AVE_DB;
static $settings = null;
if ($settings === null)
{
$settings = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_rubnav
WHERE Id = 1
")->FetchAssocArray();
}
if ($field == '') return $settings;
return (isset($settings[$field]) ? $settings[$field] : null);
}
function _rubnavRubricsGet()
{
global $AVE_DB, $AVE_Template;
$rubrics = array();
$sql = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_rubrics");
while ($result = $sql->FetchRow())
{
array_push($rubrics, $result);
}
$AVE_Template->assign('rubrics', $rubrics);
}
function rubnavSettingsEdit()
{
global $AVE_DB, $AVE_Template;
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save')
{
$sql = $AVE_DB->Query("
UPDATE " . PREFIX . "_module_rubnav
SET
rubnav_tmpl_next = '" . $_REQUEST['rubnav_tmpl_next'] . "',
rubnav_tmpl_prev = '" . $_REQUEST['rubnav_tmpl_prev'] . "'
WHERE
id = 1
");
if ($sql->_result === false) {
$message = $AVE_Template->get_config_vars('RUBNAV_MODULE_SAVED_ERR');
$header = $AVE_Template->get_config_vars('RUBNAV_MODULE_ERROR');
$theme = 'error';
}else{
$message = $AVE_Template->get_config_vars('RUBNAV_MODULE_SAVED');
$header = $AVE_Template->get_config_vars('RUBNAV_MODULE_SUCCESS');
$theme = 'accept';
}
if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] = '1') {
echo json_encode(array('message' => $message, 'header' => $header, 'theme' => $theme));
} else {
$AVE_Template->assign('message', $message);
header('Location:index.php?do=modules&action=modedit&mod=rubnav&moduleaction=1&cp=' . SESSION);
}
exit;
}
$row = $this->_rubnavSettingsGet();
$AVE_Template->assign($row);
$AVE_Template->config_load($this->_lang_file, 'showconfig');
$AVE_Template->assign('content', $AVE_Template->fetch($this->_tpl_dir . 'admin_config.tpl'));
}
}
?>

21
lang/ru.txt

@ -0,0 +1,21 @@
RUBNAV_MODULE = "Навигация по рубрике"
RUBNAV_MODULE_INFO = "В данном разделе Вы можете выполнить настройку модуля в соответствии с требуемыми параметрами"
RUBNAV_MODULE_SETUP = "Управление модулем"
RUBNAV_MODULE_YES = "Да"
RUBNAV_MODULE_NO = "Нет"
RUBNAV_MODULE_OR = "или"
RUBNAV_MODULE_SAVE = "Сохранить"
RUBNAV_MODULE_SAVE_NEXT = "Применить (CTRL + S)"
RubNavLink = "Тег, определяющий адрес для перехода"
RubNavLinkName = "Тег, определяющий название ссылки, которое будет отображено"
RubNavTeplNext = "Шаблон для ссылки на следущую страницу"
RubNavTeplPrev = "Шаблон для ссылки на предыдущую страницу"
RUBNAV_MODULE_SAVED = "Успешно сохранено"
RUBNAV_MODULE_SAVED_ERR = "Не удалось сохранить.<br />Попробуйте еще раз."
RUBNAV_MODULE_ERROR = "Ошибка"
RUBNAV_MODULE_SUCCESS = "Выполнено"

143
module.php

@ -0,0 +1,143 @@
<?php
/**
* AVE.cms - Модуль Навигация по документам рубрики
*
* @package AVE.cms
* @subpackage module_Rubnav
* @filesource
*/
if(!defined('BASE_DIR')) exit;
if (defined('ACP'))
{
$modul['ModuleName'] = 'Навигация по рубрике';
$modul['ModuleSysName'] = 'rubnav';
$modul['ModuleVersion'] = '1.1.2';
$modul['ModuleDescription'] = 'Навигация по документам в пределах рубрики (следущая-предыдущая)<br />Инструкция:<br />[mod_rubnav:next] - следущая<br />[mod_rubnav:prev] - предыдущая';
$modul['ModuleAutor'] = 'AVE.CMS Team';
$modul['ModuleCopyright'] = '&copy; 2007-2014 AVE.cms';
$modul['ModuleIsFunction'] = 1;
$modul['ModuleAdminEdit'] = 1;
$modul['ModuleFunction'] = 'mod_rubnav';
$modul['ModuleTag'] = '[mod_rubnav:XXX]';
$modul['ModuleTagLink'] = null;
$modul['ModuleAveTag'] = '#\\\[mod_rubnav:([a-zA-Z0-9]+)]#';
$modul['ModulePHPTag'] = "<?php mod_rubnav(''$1''); ?>";
}
/**
* Обработка тэга модуля
*
*/
function mod_rubnav($data)
{
global $AVE_DB, $AVE_Core;
$row_templ = $AVE_DB->Query("
SELECT *
FROM " . PREFIX . "_module_rubnav
WHERE Id = 1
")->FetchRow();
if ($data == "next")
{
$next_link = '';
$row = $AVE_DB->Query("
SELECT
Id,
document_alias,
document_title
FROM " . PREFIX . "_documents
WHERE
Id != '1'
AND Id != '" . PAGE_NOT_FOUND_ID . "'
AND Id != '" . $AVE_Core->curentdoc->Id . "'
AND rubric_id = '" . $AVE_Core->curentdoc->rubric_id . "'
AND document_published >= '" . $AVE_Core->curentdoc->document_published . "'
AND (document_expire = 0 || document_expire > UNIX_TIMESTAMP())
AND (document_published = 0 || document_published < UNIX_TIMESTAMP())
AND document_deleted = '0'
AND document_status = '1'
ORDER BY document_published ASC
LIMIT 0,1
")
->fetchRow();
if ($row)
{
$search = array('[tag:link]','[tag:linkname]');
$replace = array(
rewrite_link('index.php?id=' . $row->Id . '&amp;doc=' . (empty($row->document_alias) ? prepare_url($row->document_title) : $row->document_alias)),
stripslashes(htmlspecialchars_decode($row->document_title))
);
$next_link = str_replace($search, $replace, $row_templ->rubnav_tmpl_next);
}
echo $next_link;
}
else if ($data == "prev")
{
//Функция перехода на предыдущую страницу в данной рубрике
$prev_link = '';
$row = $AVE_DB->Query("
SELECT
Id,
document_alias,
document_title
FROM " . PREFIX . "_documents
WHERE
Id != '1'
AND Id != '" . PAGE_NOT_FOUND_ID . "'
AND Id != '" . $AVE_Core->curentdoc->Id . "'
AND rubric_id = '" . $AVE_Core->curentdoc->rubric_id . "'
AND document_published <= '" . $AVE_Core->curentdoc->document_published . "'
AND (document_expire = 0 || document_expire > UNIX_TIMESTAMP())
AND (document_published = 0 || document_published < UNIX_TIMESTAMP())
AND document_deleted = '0'
AND document_status = '1'
ORDER BY document_published DESC
LIMIT 0,1
")
->fetchRow();
if ($row)
{
$search = array('[tag:link]','[tag:linkname]');
$replace = array(
rewrite_link('index.php?id=' . $row->Id . '&amp;doc=' . (empty($row->document_alias) ? prepare_url($row->document_title) : $row->document_alias)),
stripslashes(htmlspecialchars_decode($row->document_title))
);
$prev_link = str_replace($search, $replace, $row_templ->rubnav_tmpl_prev);
}
echo $prev_link;
}
}
/**
* Администрирование
*/
if (defined('ACP') && !empty($_REQUEST['moduleaction']))
{
global $rubric_list;
$tpl_dir = BASE_DIR . '/modules/rubnav/templates/';
$lang_file = BASE_DIR . '/modules/rubnav/lang/' . $_SESSION['admin_language'] . '.txt';
if (! @require(BASE_DIR . '/modules/rubnav/class.rubnav.php')) module_error();
$rubric_list = new RubNav($tpl_dir, $lang_file);
$AVE_Template->config_load($lang_file);
$config_vars = $AVE_Template->get_config_vars();
$AVE_Template->assign('config_vars', $config_vars);
switch($_REQUEST['moduleaction'])
{
case '1':
$rubric_list->rubnavSettingsEdit();
break;
}
}
?>

44
sql.php

@ -0,0 +1,44 @@
<?php
/**
* AVE.cms - Навигация по рубрике
*
* @package AVE.cms
* @subpackage module_RubNav
* @filesource
*/
/**
* mySQL-запросы для установки, обновления и удаления модуля
*/
$module_sql_install = array();
$module_sql_deinstall = array();
$module_sql_update = array();
//Удаление модуля
$module_sql_deinstall[] = "DROP TABLE IF EXISTS CPPREFIX_module_rubnav;";
//Установка модуля
$module_sql_install[] = "CREATE TABLE CPPREFIX_module_rubnav (
`id` mediumint(5) unsigned NOT NULL auto_increment,
`rubnav_tmpl_next` longtext NOT NULL,
`rubnav_tmpl_prev` longtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$module_sql_install[] = "INSERT INTO `CPPREFIX_module_rubnav` VALUES (1, '<a href=\"[tag:link]\">[tag:linkname]</a>', '<a href=\"[tag:link]\">[tag:linkname]</a>');";
// Обновление модуля
$module_sql_update[] = "
UPDATE
`CPPREFIX_module`
SET
ModuleAveTag = '" . $modul['ModuleAveTag'] . "',
ModulePHPTag = '" . $modul['ModulePHPTag'] . "',
ModuleVersion = '" . $modul['ModuleVersion'] . "'
WHERE
ModuleSysName = '" . $modul['ModuleSysName'] . "'
LIMIT 1;
";
?>

173
templates/admin_config.tpl

@ -0,0 +1,173 @@
<link rel="stylesheet" href="{$ABS_PATH}admin/codemirror/lib/codemirror.css">
<script src="{$ABS_PATH}admin/codemirror/lib/codemirror.js" type="text/javascript"></script>
<script src="{$ABS_PATH}admin/codemirror/mode/xml/xml.js"></script>
<script src="{$ABS_PATH}admin/codemirror/mode/javascript/javascript.js"></script>
<script src="{$ABS_PATH}admin/codemirror/mode/css/css.js"></script>
<script src="{$ABS_PATH}admin/codemirror/mode/clike/clike.js"></script>
<script src="{$ABS_PATH}admin/codemirror/mode/php/php.js"></script>
{literal}
<style type="text/css">
.activeline {background: #e8f2ff !important;}
.CodeMirror-scroll {height: 150px;}
</style>
{/literal}
<div class="title"><h5>{#RUBNAV_MODULE#}</h5></div>
<div class="widget" style="margin-top: 0px;">
<div class="body">
{#RUBNAV_MODULE_INFO#}
</div>
</div>
<div class="breadCrumbHolder module">
<div class="breadCrumb module">
<ul>
<li class="firstB"><a href="index.php" title="{#MAIN_PAGE#}">{#MAIN_PAGE#}</a></li>
<li><a href="index.php?do=modules&amp;cp={$sess}">{#MODULES_SUB_TITLE#}</a></li>
<li>{#RUBNAV_MODULE_SETUP#}</li>
<li><strong class="code">{#RUBNAV_MODULE#}</strong></li>
</ul>
</div>
</div>
<div class="widget first">
<div class="head"><h5 class="iFrames">{#RUBNAV_MODULE_SETUP#}</h5></div>
<form method="post" action="index.php?do=modules&action=modedit&mod=rubnav&moduleaction=1&cp={$sess}&sub=save" class="mainForm" id="save_rubnav">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<tr class="noborder">
<td colspan="2"><strong>{#RubNavTeplNext#}</strong></td>
</tr>
<tr>
<td><strong><a class="rightDir" title="{#RubNavLink#}" href="javascript:void(0);" onclick="textSelection('[tag:link]', '');">[tag:link]</a></strong></td>
<td rowspan="2">
<textarea style="width:400px; height:100px" name="rubnav_tmpl_next" id="rubnav_tmpl_next">{$rubnav_tmpl_next}</textarea>
</td>
</tr>
<tr>
<td><strong><a class="rightDir" title="{#RubNavLinkName#}" href="javascript:void(0);" onclick="textSelection('[tag:linkname]', '');">[tag:linkname]</a></strong></td>
</tr>
<tr>
<td>HTML tags</td>
<td>
|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<ol>', '</ol>');"><strong>OL</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<ul>', '</ul>');"><strong>UL</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<li>', '</li>');"><strong>LI</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<p class=&quot;&quot;>', '</p>');"><strong>P</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<strong>', '</strong>');"><strong>B</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<em>', '</em>');"><strong>I</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<h1>', '</h1>');"><strong>H1</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<h2>', '</h2>');"><strong>H2</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<h3>', '</h3>');"><strong>H3</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<h4>', '</h4>');"><strong>H4</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<h5>', '</h5>');"><strong>H5</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<div class=&quot;&quot; id=&quot;&quot;>', '</div>');"><strong>DIV</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<a href=&quot;&quot; title=&quot;&quot;>', '</a>');"><strong>A</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<img src=&quot;&quot; alt=&quot;&quot; />', '');"><strong>IMG</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<span>', '</span>');"><strong>SPAN</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<pre>', '</pre>');"><strong>PRE</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('<br />', '');"><strong>BR</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection('\t', '');"><strong>TAB</strong></a>&nbsp;|
</td>
</tr>
<tr>
<td colspan="2"><strong>{#RubNavTeplPrev#}</strong></td>
</tr>
<tr>
<td><strong><a class="rightDir" title="{#RubNavLink#}" href="javascript:void(0);" onclick="textSelection2('[tag:link]', '');">[tag:link]</a></strong></td>
<td rowspan="2">
<textarea style="width:400px; height:100px" name="rubnav_tmpl_prev" id="rubnav_tmpl_prev">{$rubnav_tmpl_prev}</textarea>
</td>
</tr>
<tr>
<td><strong><a class="rightDir" title="{#RubNavLinkName#}" href="javascript:void(0);" onclick="textSelection2('[tag:linkname]', '');">[tag:linkname]</a></strong></td>
</tr>
<tr>
<td>HTML tags</td>
<td>
|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<ol>', '</ol>');"><strong>OL</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<ul>', '</ul>');"><strong>UL</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<li>', '</li>');"><strong>LI</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<p class=&quot;&quot;>', '</p>');"><strong>P</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<strong>', '</strong>');"><strong>B</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<em>', '</em>');"><strong>I</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<h1>', '</h1>');"><strong>H1</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<h2>', '</h2>');"><strong>H2</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<h3>', '</h3>');"><strong>H3</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<h4>', '</h4>');"><strong>H4</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<h5>', '</h5>');"><strong>H5</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<div class=&quot;&quot; id=&quot;&quot;>', '</div>');"><strong>DIV</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<a href=&quot;&quot; title=&quot;&quot;>', '</a>');"><strong>A</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<img src=&quot;&quot; alt=&quot;&quot; />', '');"><strong>IMG</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<span>', '</span>');"><strong>SPAN</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<pre>', '</pre>');"><strong>PRE</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('<br />', '');"><strong>BR</strong></a>&nbsp;|&nbsp;
<a href="javascript:void(0);" onclick="textSelection2('\t', '');"><strong>TAB</strong></a>&nbsp;|
</td>
</tr>
</table>
<div class="rowElem" id="saveBtn">
<div class="saveBtn">
<input name="submit" type="submit" class="basicBtn" value="{#RUBNAV_MODULE_SAVE#}" />
{#RUBNAV_MODULE_OR#}
<input type="submit" class="blackBtn SaveEdit" name="next_edit" value="{#RUBNAV_MODULE_SAVE_NEXT#}" />
</div>
</div>
</form>
</div>
<script language="javascript">
var sett_options = {ldelim}
url: 'index.php?do=modules&action=modedit&mod=rubnav&moduleaction=1&sub=save&ajax=1&cp={$sess}',
dataType: 'json',
beforeSubmit: Request,
success: Response
{rdelim}
function Request(){ldelim}
$.alerts._overlay('show');
{rdelim}
function Response(data){ldelim}
$.alerts._overlay('hide');
$.jGrowl(data['message'], {ldelim}
header: data['header'],
theme: data['theme']
{rdelim});
{rdelim}
$(document).ready(function(){ldelim}
Mousetrap.bind(['ctrl+s', 'meta+s'], function(e) {ldelim}
if (e.preventDefault) {ldelim}
e.preventDefault();
{rdelim} else {ldelim}
e.returnValue = false;
{rdelim}
$("#save_rubnav").ajaxSubmit(sett_options);
return false;
{rdelim});
$(".SaveEdit").click(function(e){ldelim}
if (e.preventDefault) {ldelim}
e.preventDefault();
{rdelim} else {ldelim}
e.returnValue = false;
{rdelim}
$("#save_rubnav").ajaxSubmit(sett_options);
return false;
{rdelim});
{rdelim});
</script>
{include file="$codemirror_connect"}
{include file="$codemirror_editor" conn_id="" textarea_id='rubnav_tmpl_next' ctrls='$("#save_rubnav").ajaxSubmit(sett_options);' height=100}
{include file="$codemirror_editor" conn_id="2" textarea_id='rubnav_tmpl_prev' ctrls='$("#save_rubnav").ajaxSubmit(sett_options);' height=100}
Loading…
Cancel
Save