Конструктор шаблонов для раздач (часть 1. подключение модулей) ALTER TABLE `bb_forums` ADD `forum_tpl_id` SMALLINT(6) NOT NULL DEFAULT '0'; git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@306 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
nanosimbiot 2011-11-09 13:27:26 +00:00
commit 8d6d35eecf
14 changed files with 1636 additions and 14 deletions

View file

@ -15,7 +15,7 @@ $mode = (string) request_var('mode', '');
if ($mode == 'templates')
{
$sql = "SELECT * FROM ". BB_TOPIC_TPL ." ORDER BY tpl_name";
$sql = "SELECT * FROM ". BB_TOPIC_TPL_OLD ." ORDER BY tpl_name";
foreach (DB()->fetch_rowset($sql) as $i => $row)
{
@ -40,7 +40,7 @@ else if ($mode == 'add' || $mode == 'edit')
{ $tpl_id = (int) request_var('tpl', '');
if(!$tpl_id) bb_die('');
$row = DB()->fetch_row("SELECT * FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id");
$row = DB()->fetch_row("SELECT * FROM ". BB_TOPIC_TPL_OLD ." WHERE tpl_id = $tpl_id");
if(!$row) bb_die('');
$template->assign_vars(array(
@ -67,7 +67,7 @@ else if ($mode == 'add' || $mode == 'edit')
if(isset($_POST['submit']))
{
if($mode == 'edit')
{ DB()->query("UPDATE ". BB_TOPIC_TPL ." SET
{ DB()->query("UPDATE ". BB_TOPIC_TPL_OLD ." SET
tpl_name = '". DB()->escape($tpl_name) ."',
tpl_script = '". DB()->escape($tpl_script) ."',
tpl_template = '". DB()->escape($tpl_template) ."',
@ -76,7 +76,7 @@ else if ($mode == 'add' || $mode == 'edit')
");
$message = 'изменено'; }
else
{ DB()->query("INSERT INTO ". BB_TOPIC_TPL ." (tpl_name, tpl_script, tpl_template, tpl_desc)
{ DB()->query("INSERT INTO ". BB_TOPIC_TPL_OLD ." (tpl_name, tpl_script, tpl_template, tpl_desc)
VALUES ('". DB()->escape($tpl_name) ."', '". DB()->escape($tpl_script) ."', '". DB()->escape($tpl_template) ."', '". DB()->escape($tpl_desc) ."')");
$message = 'добавлено'; }
@ -93,12 +93,12 @@ else if ($mode == 'delete')
if (isset($_POST['confirm']))
{
DB()->query("DELETE ". BB_TOPIC_TPL ." WHERE tpl_id IN(". join(',', $tpl_ids) .")");
DB()->query("DELETE ". BB_TOPIC_TPL_OLD ." WHERE tpl_id IN(". join(',', $tpl_ids) .")");
bb_die('Удалено');
}
else
{
$names = DB()->fetch_rowset("SELECT tpl_name FROM ". BB_TOPIC_TPL ." WHERE tpl_id IN(". join(',', $tpl_ids) .") ORDER BY tpl_name", 'tpl_name');
$names = DB()->fetch_rowset("SELECT tpl_name FROM ". BB_TOPIC_TPL_OLD ." WHERE tpl_id IN(". join(',', $tpl_ids) .") ORDER BY tpl_name", 'tpl_name');
print_confirmation(array(
'QUESTION' => 'Вы уверены, что хотите удалить?',
@ -120,7 +120,7 @@ else
$available_tpl_id = array(0);
$tpl_select = array($lang['TPL_NONE'] => 0);
$sql = "SELECT * FROM ". BB_TOPIC_TPL ." ORDER BY tpl_name";
$sql = "SELECT * FROM ". BB_TOPIC_TPL_OLD ." ORDER BY tpl_name";
foreach (DB()->fetch_rowset($sql) as $row)
{

View file

@ -70,6 +70,7 @@ class ajax_common
'change_tor_status' => array('mod'),
'mod_action' => array('mod'),
'topic_tpl' => array('mod'),
'gen_passkey' => array('user'),
'change_torrent' => array('user'),
@ -180,7 +181,6 @@ class ajax_common
function init ()
{
$this->request = $_POST;
$this->action =& $this->request['action'];
}
@ -493,5 +493,10 @@ class ajax_common
{
require(AJAX_DIR .'manage_user.php');
}
function topic_tpl()
{
require(AJAX_DIR .'topic_tpl.php');
}
}

View file

@ -93,8 +93,9 @@ switch($this->request['type'])
case 'view_message':
$message = (string) $this->request['message'];
if(!trim($message)) $this->ajax_die($lang['EMPTY_MESSAGE']);
$message = bbcode2html($message);
$this->response['message_html'] = $message;
$this->response['message_html'] = bbcode2html($message);
$this->response['res_id'] = $this->request['res_id'];
break;
case 'edit':

172
upload/ajax/topic_tpl.php Normal file
View file

@ -0,0 +1,172 @@
<?php
if (!defined('IN_AJAX')) die(basename(__FILE__));
global $userdata;
if (!IS_SUPER_ADMIN) $this->ajax_die('not auth');
array_deep($this->request, 'trim');
$mode = (string) $this->request['mode'];
$sql_error = false;
// установка / начальная валидация значений
switch ($mode)
{
case 'load':
case 'save':
if (!$tpl_id = (int) $this->request['tpl_id'])
{
$this->ajax_die('empty tpl_id');
}
if (!$tpl_data = DB()->fetch_row("SELECT * FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id LIMIT 1"))
{
$this->ajax_die("Шаблон [id: $tpl_id] не найден в БД");
}
break;
}
switch ($mode)
{
case 'save':
case 'new':
if (!$tpl_name = htmlCHR(str_compact($this->request['tpl_name'])))
{
$this->ajax_die('не заполнено название шаблона');
}
$tpl_name = substr($tpl_name, 0, 60);
if (!$tpl_src_form = htmlCHR($this->request['tpl_src_form']))
{
$this->ajax_die('не заполнен скрипт формы шаблона');
}
if (!$tpl_src_title = htmlCHR($this->request['tpl_src_title']))
{
$this->ajax_die('не заполнен формат названия темы');
}
$tpl_src_title = str_compact($tpl_src_title);
if (!$tpl_src_msg = htmlCHR($this->request['tpl_src_msg']))
{
$this->ajax_die('не заполнен формат создания сообщения');
}
$tpl_comment = htmlCHR($this->request['tpl_comment']);
preg_match('#\d+#', (string) $this->request['tpl_rules'], $m);
$tpl_rules_post_id = isset($m[0]) ? (int) $m[0] : 0;
$sql_args = array(
'tpl_name' => (string) $tpl_name,
'tpl_src_form' => (string) $tpl_src_form,
'tpl_src_title' => (string) $tpl_src_title,
'tpl_src_msg' => (string) $tpl_src_msg,
'tpl_comment' => (string) $tpl_comment,
'tpl_rules_post_id' => (int) $tpl_rules_post_id,
'tpl_last_edit_tm' => (int) TIMENOW,
'tpl_last_edit_by' => (int) $userdata['user_id'],
);
break;
}
// выполнение
switch ($mode)
{
// загрузка шаблона
case 'load':
$this->response['val']['tpl-name-save'] = $tpl_data['tpl_name'];
$this->response['val']['tpl-src-form'] = $tpl_data['tpl_src_form'];
$this->response['val']['tpl-src-title'] = $tpl_data['tpl_src_title'];
$this->response['val']['tpl-src-msg'] = $tpl_data['tpl_src_msg'];
$this->response['val']['tpl-comment-save'] = $tpl_data['tpl_comment'];
$this->response['val']['tpl-rules-save'] = $tpl_data['tpl_rules_post_id'];
array_deep($this->response['val'], 'html_ent_decode');
$this->response['val']['tpl-id-save'] = $tpl_id;
$this->response['val']['tpl-last-edit-tst'] = $tpl_data['tpl_last_edit_tm'];
$this->response['html']['tpl-name-old-save'] = $tpl_data['tpl_name'];
$this->response['html']['tpl-last-edit-time'] = bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i');
$this->response['html']['tpl-last-edit-by'] = get_username(intval($tpl_data['tpl_last_edit_by']));
$this->response['tpl_rules_href'] = POST_URL . $tpl_data['tpl_rules_post_id'] .'#'. $tpl_data['tpl_rules_post_id'];
break;
// включение / отключение шаблона в форуме
case 'assign':
if (!$tpl_id = (int) $this->request['tpl_id'])
{
$this->ajax_die('empty tpl_id');
}
if (!$forum_id = (int) $this->request['forum_id'])
{
$this->ajax_die('empty forum_id');
}
if (!forum_exists($forum_id))
{
$this->ajax_die("нет такого форума [id: $forum_id]");
}
// отключение
if ($tpl_id == -1)
{
$new_tpl_id = 0;
$this->response['msg'] = 'Шаблоны в этом форуме отключены';
}
// включение
else
{
if (!$tpl_name = DB()->fetch_row("SELECT tpl_name FROM ". BB_TOPIC_TPL ." WHERE tpl_id = $tpl_id LIMIT 1", 'tpl_name'))
{
$this->ajax_die("Шаблон [id: $tpl_id] не найден в БД");
}
$new_tpl_id = $tpl_id;
$this->response['msg'] = "Включен шаблон $tpl_name";
}
DB()->query("UPDATE ". BB_FORUMS ." SET forum_tpl_id = $new_tpl_id WHERE forum_id = $forum_id LIMIT 1");
break;
// сохранение изменений
case 'save':
if ($tpl_data['tpl_last_edit_tm'] > $this->request['tpl_l_ed_tst'] && $tpl_data['tpl_last_edit_by'] != $userdata['user_id'])
{
$last_edit_by_username = get_username(intval($tpl_data['tpl_last_edit_by']));
$msg = "Изменения не были сохранены!\n\n";
$msg .= 'Шаблон был отредактирован: '. html_entity_decode($last_edit_by_username) .', '. delta_time($tpl_data['tpl_last_edit_tm']) ." назад\n\n";
$this->ajax_die($msg);
}
$sql = "UPDATE ". BB_TOPIC_TPL ." SET ". DB()->build_array('UPDATE', $sql_args) ." WHERE tpl_id = $tpl_id LIMIT 1";
if (!@DB()->query($sql))
{
$sql_error = DB()->sql_error();
}
$this->response['tpl_id'] = $tpl_id;
$this->response['tpl_name'] = $tpl_name;
$this->response['html']['tpl-last-edit-time'] = bb_date(TIMENOW, 'd-M-y H:i');
$this->response['html']['tpl-last-edit-by'] = $userdata['username'];
break;
// создание нового шаблона
case 'new':
$sql = "INSERT INTO ". BB_TOPIC_TPL . DB()->build_array('INSERT', $sql_args);
if (!@DB()->query($sql))
{
$sql_error = DB()->sql_error();
}
break;
// ошибочный $mode
default:
$this->ajax_die("invalid mode: $mode");
}
// возможный дубль названия шаблона
if ($sql_error)
{
if ($sql_error['code'] == 1062) // Duplicate entry
{
$this->ajax_die('Шаблон с таким названием уже существует, выберите другое название');
}
$this->ajax_die("db error {$sql_error['code']}: {$sql_error['message']}");
}
// выход
$this->response['mode'] = $mode;
$this->response['timestamp'] = TIMENOW;

View file

@ -53,8 +53,8 @@ $bb_cfg = $tr_cfg = $page_cfg = array();
// Increase number of revision after update
$bb_cfg['tp_version'] = '2.2 Beta';
$bb_cfg['tp_release_state'] = 'R305';
$bb_cfg['tp_release_date'] = '05-11-2011';
$bb_cfg['tp_release_state'] = 'R306';
$bb_cfg['tp_release_date'] = '09-11-2011';
// Database
$charset = 'utf8';

View file

@ -667,6 +667,8 @@ function delta_time ($timestamp_1, $timestamp_2 = TIMENOW, $granularity = 'auto'
function get_select ($type)
{
global $lang;
$select_ary = array();
switch ($type)
@ -690,6 +692,16 @@ function get_select ($type)
}
$select_name = POST_GROUPS_URL;
break;
case 'forum_tpl':
$sql = "SELECT tpl_id, tpl_name FROM ". BB_TOPIC_TPL ." ORDER BY tpl_name";
$select_ary[$lang['SELECT']] = 0;
foreach (DB()->fetch_rowset($sql) as $row)
{
$select_ary[$row['tpl_name']] = $row['tpl_id'];
}
$select_name = 'forum_tpl_select';
break;
}
return ($select_ary) ? build_select($select_name, $select_ary) : '';
}

View file

@ -366,7 +366,8 @@ define('BB_SEARCH_REBUILD', 'bb_search_rebuild');
define('BB_SEARCH', 'bb_search_results');
define('BB_SESSIONS', 'bb_sessions');
define('BB_SMILIES', 'bb_smilies');
define('BB_TOPIC_TPL', 'bb_topic_templates');
define('BB_TOPIC_TPL_OLD', 'bb_topic_templates');
define('BB_TOPIC_TPL', 'bb_topic_tpl');
define('BB_TOPICS', 'bb_topics');
define('BB_TOPICS_WATCH', 'bb_topics_watch');
define('BB_USER_GROUP', 'bb_user_group');

View file

@ -0,0 +1,82 @@
<?php
if (!defined('BB_ROOT')) die(basename(__FILE__));
$can_edit_tpl = IS_SUPER_ADMIN;
$edit_tpl_mode = ($can_edit_tpl && !empty($_REQUEST['edit_tpl']));
// forum_data
$sql = "SELECT forum_name, allow_reg_tracker, forum_tpl_id FROM ". BB_FORUMS ." WHERE forum_id = $forum_id LIMIT 1";
if (!$forum_id OR !$f_data = DB()->fetch_row($sql))
{
bb_die('Форум не найден');
}
// tpl_data
$tpl_data = array();
$sql = "SELECT * FROM ". BB_TOPIC_TPL ." WHERE tpl_id = {$f_data['forum_tpl_id']} LIMIT 1";
if (!$f_data['forum_tpl_id'] OR !$tpl_data = DB()->fetch_row($sql))
{
if (!$edit_tpl_mode)
{
redirect(POSTING_URL. "?mode=newtopic&f=$forum_id");
}
}
$template->assign_vars(array(
'PAGE_TITLE' => 'Новый релиз',
'FORUM_NAME' => $f_data['forum_name'],
'FORUM_ID' => $forum_id,
'TPL_FORM_ACTION' => "posting.php?mode=newtopic&amp;f=$forum_id",
'REGULAR_TOPIC_HREF' => "posting.php?mode=newtopic&amp;f=$forum_id",
'TOR_REQUIRED' => $f_data['allow_reg_tracker'],
'EDIT_TPL' => $edit_tpl_mode,
'CAN_EDIT_TPL' => $can_edit_tpl,
'EDIT_TPL_URL' => "posting.php?mode=new_rel&amp;f=$forum_id&amp;edit_tpl=1",
));
if ($tpl_data)
{
// tpl_rules_html
$tpl_rules_html = '';
if ($tpl_data['tpl_rules_post_id'])
{
if (!$tpl_rules_html = get_posts_html($tpl_data['tpl_rules_post_id']))
{
$tpl_data['tpl_rules_post_id'] = 0;
DB()->query("UPDATE ". BB_TOPIC_TPL ." SET tpl_rules_post_id = 0 WHERE tpl_id = {$f_data['forum_tpl_id']} LIMIT 1");
}
}
$template->assign_vars(array(
'TPL_ID' => $tpl_data['tpl_id'],
'TPL_NAME' => $tpl_data['tpl_name'],
'TPL_SRC_FORM_VAL' => $tpl_data['tpl_src_form'],
'TPL_SRC_TITLE_VAL' => $tpl_data['tpl_src_title'],
'TPL_SRC_MSG_VAL' => $tpl_data['tpl_src_msg'],
'TPL_RULES_HTML' => $tpl_rules_html,
));
}
if ($edit_tpl_mode)
{
$template->assign_vars(array(
'NO_TPL_ASSIGNED' => !($f_data['forum_tpl_id']),
'TPL_SELECT' => get_select('forum_tpl', $f_data['forum_tpl_id']),
));
if ($tpl_data)
{
$template->assign_vars(array(
'TPL_COMMENT' => $tpl_data['tpl_comment'],
'TPL_RULES_POST_ID' => $tpl_data['tpl_rules_post_id'],
'TPL_LAST_EDIT_TIME' => bb_date($tpl_data['tpl_last_edit_tm'], 'd-M-y H:i'),
'TPL_LAST_EDIT_USER' => get_username(intval($tpl_data['tpl_last_edit_by'])),
'TPL_LAST_EDIT_TIMESTAMP' => $tpl_data['tpl_last_edit_tm'],
));
}
}
print_page('posting_tpl.tpl');

View file

@ -56,7 +56,7 @@ function tpl_func_screen_shots ($item, $val)
// get tpl data
$sql = "SELECT *
FROM ". BB_TOPIC_TPL ."
FROM ". BB_TOPIC_TPL_OLD ."
WHERE tpl_id = ". (int) $post_info['topic_tpl_id'];
if ($topic_tpl = DB()->fetch_row($sql))

View file

@ -0,0 +1 @@
posting_tpl_common_header.html

View file

@ -0,0 +1,175 @@
/*
-------------------------------------------------------------------------------------------------
-- el_attr --------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
*/
TPL.el_attr = {
/*
код_элемента = ID элемента в форме
все элементы имеют class "rel-input"
формат el_attr
код_элемента: [
[0] - тип
[1] - название
[2] - атрибуты элемента типа size,rows.. по умолчанию (в том же порядке как и опциональные для элемента)
[3] - атрибуты типа HEAD,req.. по умолчанию для формата сообщения
]
формат элементов в #tpl-src-form (включая все опциональные атрибуты типа maxlength..)
INP - input[name,maxlength,size]
TXT - textarea[name,rows]
SEL - select[name] -- значения для селектов находятся в TPL.selects
*/
audio_codec : [ 'SEL', 'Аудио кодек', '', '' ],
audio : [ 'INP', 'Аудио', '200,80', '' ],
casting : [ 'TXT', 'В ролях', '3', 'BR' ],
video_codec : [ 'SEL', 'Видео кодек', '', '' ],
video : [ 'INP', 'Видео', '200,80', '' ],
year : [ 'INP', 'Год выпуска', '4,5', 'num' ],
moreinfo : [ 'TXT', 'Доп. информация', '3', 'BR' ],
genre : [ 'INP', 'Жанр', '200,40', '' ],
video_quality : [ 'SEL', 'Качество видео', '', '' ],
title_rus : [ 'INP', 'Название', '90,80', 'HEAD,req' ],
description : [ 'TXT', 'Описание', '6', 'BR' ],
title_eng : [ 'INP', 'Оригинальное название', '90,80', 'HEAD' ],
translation : [ 'SEL', 'Перевод', '', '' ],
poster : [ 'INP', 'Постер', '200,80', 'img,POSTER' ],
playtime : [ 'INP', 'Продолжительность', '200,30', '' ],
director : [ 'INP', 'Режиссер', '200,50', '' ],
rus_sub : [ 'SEL', 'Русские субтитры', '', '' ],
screenshots : [ 'TXT', 'Скриншоты', '3', 'spoiler' ],
country : [ 'INP', 'Страна', '200,50', '' ],
studio : [ 'INP', 'Студия', '200,50', '' ],
video_format : [ 'SEL', 'Формат видео', '', '' ],
// dummy
dummy : ['','']
};
/*
-------------------------------------------------------------------------------------------------
-- el_id ----------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
*/
TPL.el_id = {
// ID контейнеров содержащих html элементов
load_pic_btn : 'Кнопка "Загрузить картинку"',
// ID элементов, для которых нужно создать скрытые элементы, содержащие аббревиатуры для подстановки в название
// Каждый элемент el_abr должен точно соответствовать el (translation_abr -> translation)
translation_abr : '[ABR] Перевод',
// dummy
dummy : ''
};
/*
-------------------------------------------------------------------------------------------------
-- selects --------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
*/
TPL.selects = {
// [0] всегда имеет value='' и если задан как '' (пустая строка) заменяется на "&raquo; Выбрать"
translation : [
'',
'Любительский (одноголосый)',
'Любительский (двухголосый)',
'Авторский (одноголосый)',
'Профессиональный (одноголосый)',
'Профессиональный (двухголосый)',
'Профессиональный (многоголосый, закадровый)',
'Профессиональный (полное дублирование)',
'Субтитры',
'Отсутствует',
'Не требуется'
],
translation_abr : [
' ',
'одноголосый (Л)', // 'Любительский (одноголосый)',
'двухголосый (Л)', // 'Любительский (двухголосый)',
'авторский', // 'Авторский (одноголосый)',
'одноголосый', // 'Профессиональный (одноголосый)',
'двухголосый', // 'Профессиональный (двухголосый)',
'многоголосый', // 'Профессиональный (многоголосый, закадровый)',
'дублированный', // 'Профессиональный (полное дублирование)',
'субтитры', // 'Субтитры',
'без перевода', // 'Отсутствует',
' ' // 'Не требуется'
],
rus_sub : ['', 'есть', 'нет'],
rus_sub_abr : ['', 'есть', 'нет'],
video_quality : [
'&raquo; Качество видео',
'DVDRip',
'DVD5',
'DVD5 (сжатый)',
'DVD9',
'HDTV',
'HDTVRip',
'TVRip',
'TeleCine',
'TeleSynch',
'CamRip',
'SATRip',
'VHSRip',
'HD-DVDRip',
'BDRip',
'DVDScreener'
],
video_format : [
'&raquo; Формат видео',
'AVI',
'DVD Video',
'OGM',
'MKV',
'WMV',
'MPEG',
'MP4',
'TS',
'M2TS'
],
video_codec : [
'&raquo; Видео кодек',
'DivX',
'XviD',
"Другой MPEG4",
'VPx',
'MPEG1',
'MPEG2',
'Windows Media',
'QuickTime',
'H.264',
'Flash'
],
audio_codec : [
'&raquo; Аудио кодек',
'MP3',
'APE',
'FLAC',
'WAVPack',
'WMA',
'OGG Vorbis',
'DTS',
'DVD-AUDIO',
'TTA',
'AAC',
'AC3',
'M4A',
'M4B'
],
// dummy
dummy : ['']
};

View file

@ -0,0 +1,24 @@
<div id="tpl-abr-box"></div>
<script type="text/javascript">
$(document).ready(function(){
$.each(TPL.el_id, function(el,desc){
var m = el.match(/^(.*)(_abr)$/);
if (m == null) {
return true; // continue
}
var el_abr = m[0];
var el_ref = m[1];
$('#tpl-abr-box').append('<div id="'+el_abr+'-hid">'+ TPL.build_select_el(el_abr) +'</div>');
TPL.submit_fn[el_abr] = function(){
if ( $('#'+el_ref).length ) {
$('#'+el_abr)[0].selectedIndex = $('#'+el_ref)[0].selectedIndex;
}
}
});
});
</script>
<!--load_pic_btn-->
<div id="load_pic_btn"><input type="button" style="width: 140px;" value="Загрузить картинку" onclick="window.open('http://ipicture.ru', '_blank'); return false;" /></div>
<!--/load_pic_btn-->

View file

@ -49,6 +49,12 @@ $tracking_forums = get_tracks('forum');
// Start session management
$user->session_start();
if ($mode == 'new_rel')
{
require(INC_DIR .'posting_tpl.php');
exit;
}
// What auth type do we need to check?
$is_auth = array();
switch ($mode)

File diff suppressed because it is too large Load diff