редактирование постов на ajax git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@131 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
nanosimbiot 2011-07-24 10:21:24 +00:00
commit fd0a216a89
6 changed files with 200 additions and 40 deletions

View file

@ -17,7 +17,6 @@ if (file_exists(BB_DISABLED))
switch ($ajax->action)
{
case 'view_post':
case 'view_message':
require(INC_DIR .'bbcode.php');
break;
@ -72,7 +71,6 @@ class ajax_common
'change_torrent' => array('user'),
'view_post' => array('guest'),
'view_message' => array('guest'),
'view_torrent' => array('guest'),
'user_register' => array('guest'),
'posts' => array('guest'),
@ -372,16 +370,6 @@ class ajax_common
require(AJAX_DIR .'view_post.php');
}
function view_message ()
{
global $lang;
$message = (string) $this->request['message'];
if(!trim($message)) $this->ajax_die($lang['EMPTY_MESSAGE']);
$message = bbcode2html($message);
$this->response['html'] = $message;
}
function change_tor_status ()
{
require(AJAX_DIR .'change_tor_status.php');

View file

@ -30,7 +30,7 @@ if (!defined('WORD_LIST_OBTAINED'))
switch($this->request['type'])
{ case 'delete';
if(!$post) bb_die('not post');
if(!$post) $this->ajax_die('not post');
$is_auth = auth(AUTH_ALL, $post['forum_id'], $userdata, $post);
@ -43,14 +43,14 @@ switch($this->request['type'])
$this->response['hide'] = true;
$this->response['post_id'] = $post_id; }
else
{ bb_die(sprintf($lang['SORRY_AUTH_DELETE'], strip_tags($is_auth['auth_delete_type']))); }
{ $this->ajax_die(sprintf($lang['SORRY_AUTH_DELETE'], strip_tags($is_auth['auth_delete_type']))); }
break;
case 'quote';
if(!$post) bb_die('not post');
case 'reply';
if(!$post) $this->ajax_die('not post');
if(bf($userdata['user_opt'], 'user_opt', 'allow_post'))
{
bb_die($lang['RULES_REPLY_CANNOT']);
$this->ajax_die($lang['RULES_REPLY_CANNOT']);
}
// Use trim to get rid of spaces placed there by MS-SQL 2000
@ -73,8 +73,133 @@ switch($this->request['type'])
$this->response['message'] = $message;
break;
case 'add':
$this->ajax_die('off');
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;
break;
case 'edit':
case 'editor':
if(!$post) $this->ajax_die('not post');
if(mb_strlen($post['post_text'], 'UTF-8') > 1000)
{ $this->response['redirect'] = make_url('posting.php?mode=editpost&p='. $post_id); }
else if($this->request['type'] == 'editor')
{
$text = (string) $this->request['text'];
$text = prepare_message($text);
if(mb_strlen($text) > 2)
{
if($text != $post['post_text'])
{
if($bb_cfg['max_smilies'])
{
$count_smilies = substr_count(bbcode2html($text), '<img class="smile" src="'. $bb_cfg['smilies_path']);
if($count_smilies > $bb_cfg['max_smilies'])
{
$this->ajax_die(sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies']));
}
}
DB()->query("UPDATE ". BB_POSTS_TEXT ." SET post_text = '". DB()->escape($text) ."' WHERE post_id = $post_id LIMIT 1");
add_search_words($post_id, stripslashes($text), stripslashes($post['topic_title']));
update_post_html(array(
'post_id' => $post_id,
'post_text' => $text,
));
}
}
else $this->ajax_die($lang['EMPTY_MESSAGE']);
$this->response['html'] = bbcode2html($text);
}
else
{
$is_auth = auth(AUTH_ALL, $post['forum_id'], $userdata, $post);
if ($post['topic_status'] == TOPIC_LOCKED && !$is_auth['auth_mod'])
{
$this->ajax_die($lang['TOPIC_LOCKED']);
}
else if(!$is_auth['auth_edit'])
{
$this->ajax_die(sprintf($lang['SORRY_AUTH_EDIT'], strip_tags($is_auth['auth_edit_type'])));
}
// Запрет на редактирование раздачи юзером
if ($post['allow_reg_tracker'] && ($post['topic_first_post_id'] == $post_id) && !IS_AM)
{
$tor_status = DB()->fetch_row("SELECT tor_status FROM ". BB_BT_TORRENTS ." WHERE topic_id = {$post['topic_id']} LIMIT 1", 'tor_status');
if ($tor_status != false)
{
// по статусу раздачи
if (isset($bb_cfg['tor_cannot_edit'][$tor_status]))
{
$this->ajax_die("Вы не можете редактировать сообщение со статусом {$lang['tor_status'][$tor_status]}");
}
// проверенный, через время
if ($tor_status == TOR_APPROVED)
{
$days_after_last_edit = $bb_cfg['dis_edit_tor_after_days'];
$last_edit_time = max($post['post_time'], $post['post_edit_time']) + 86400*$days_after_last_edit;
$disallowed_by_forum_perm = in_array($post['forum_id'], $bb_cfg['dis_edit_tor_forums']);
$disallowed_by_user_opt = bf($user->opt, 'user_opt', 'dis_edit_release');
if ($last_edit_time < TIMENOW && ($disallowed_by_forum_perm || $disallowed_by_user_opt))
{
$how_msg = ($disallowed_by_user_opt) ? 'Вам запрещено' : 'Вы не можете';
$this->ajax_die("$how_msg редактировать сообщение со статусом <b>{$lang['tor_status'][$tor_status]}</b> по прошествии $days_after_last_edit дней");
}
}
}
}
$this->response['text'] = '
<form action="posting.php" method="post" name="post">
<input type="hidden" name="mode" value="reply" />
<input type="hidden" name="t" value="'. $post['topic_id'] .'" />
<div class="buttons mrg_4">
<input type="button" value=" B " name="codeB" title="Bold (Ctrl+B)" style="font-weight: bold; width: 30px;" />
<input type="button" value=" i " name="codeI" title="Italic (Ctrl+I)" style="width: 30px; font-style: italic;" />
<input type="button" value=" u " name="codeU" title="Underline (Ctrl+U)" style="width: 30px; text-decoration: underline;" />
<input type="button" value=" s " name="codeS" title="Strikeout (Ctrl+S)" style="width: 30px; text-decoration: line-through;" />&nbsp;&nbsp;
<input type="button" value="Quote" name="codeQuote" title="Quote (Ctrl+Q)" style="width: 50px;" />
<input type="button" value="Img" name="codeImg" title="Image (Ctrl+R)" style="width: 40px;" />
<input type="button" value="URL" name="codeUrl" title="URL (Ctrl+W)" style="width: 40px; text-decoration: underline;" /><input type="hidden" name="codeUrl2" />&nbsp;
<input type="button" value="Code" name="codeCode" title="Code (Ctrl+K)" style="width: 46px;" />
<input type="button" value="List" name="codeList" title="List (Ctrl+L)" style="width: 46px;" />
<input type="button" value="1." name="codeOpt" title="List item (Ctrl+0)" style="width: 30px;" />&nbsp;
<input type="button" value="Quote selected" name="quoteselected" title="{L_QUOTE_SELECTED}" style="width: 100px;" onmouseout="bbcode.refreshSelection(false);" onmouseover="bbcode.refreshSelection(true);" onclick="bbcode.onclickQuoteSel();" />&nbsp;
<input type="button" value="Translit" name="Translit" title="Перевести выделение из транслита на русский" style="width: 60px;" onclick="transliterate(document.post.message, this);" /> <a href="#" onclick="toggle_block(\'translit_opt\'); return false"><span style="color: darkred"><b>?</b></span></a>
</div>
<textarea id="message-'. $post_id .'" class="editor mrg_4" name="message" rows="18" cols="92">'. $post['post_text'] .'</textarea>
<div class="mrg_4 tCenter">
<input title="Alt+Enter" type="submit" name="preview" value="'. $lang['PREVIEW'] .'">
<input type="button" onclick="edit_post('. $post_id .');" value="'. $lang['CANCEL'] .'">
<input type="button" onclick="edit_post('. $post_id .', \'editor\', $(\'#message-'. $post_id .'\').val()); return false;" class="bold" value="'. $lang['EDIT_POST'] .'">
</div><hr>
<script type="text/javascript">
var bbcode = new BBCode("message-'. $post_id .'");
var ctrl = "ctrl";
bbcode.addTag("codeB", "b", null, "B", ctrl);
bbcode.addTag("codeI", "i", null, "I", ctrl);
bbcode.addTag("codeU", "u", null, "U", ctrl);
bbcode.addTag("codeS", "s", null, "S", ctrl);
bbcode.addTag("codeQuote", "quote", null, "Q", ctrl);
bbcode.addTag("codeImg", "img", null, "R", ctrl);
bbcode.addTag("codeUrl", "url", "/url", "", ctrl);
bbcode.addTag("codeUrl2", "url=", "/url", "W", ctrl);
bbcode.addTag("codeCode", "code", null, "K", ctrl);
bbcode.addTag("codeList", "list", null, "L", ctrl);
bbcode.addTag("codeOpt", "*", "", "0", ctrl);
</script>
</form>';
}
$this->response['post_id'] = $post_id;
break;
default:

View file

@ -57,8 +57,8 @@ $bb_cfg['css_ver'] = 1;
// Increase number of revision after update
$bb_cfg['tp_version'] = '2.0.2';
$bb_cfg['tp_release_state'] = 'TP II r127';
$bb_cfg['tp_release_date'] = '23-07-2011';
$bb_cfg['tp_release_state'] = 'TP II r131';
$bb_cfg['tp_release_date'] = '24-07-2011';
$bb_cfg['board_disabled_msg'] = 'форум временно отключен'; // 'forums temporarily disabled'; // show this msg if board has been disabled via ON/OFF trigger
$bb_cfg['srv_overloaded_msg'] = "Извините, в данный момент сервер перегружен\nПопробуйте повторить запрос через несколько минут";

View file

@ -1,5 +1,9 @@
// BBCode control. (based on bbcode.js from http://forum.dklab.ru)
function BBCode(textarea) { this.construct(textarea) }
function BBCode(obj)
{
textarea = document.getElementById(obj);
this.construct(textarea);
}
BBCode.prototype = {
VK_TAB: 9,
VK_ENTER: 13,

View file

@ -1,5 +1,16 @@
<!-- IF QUICK_REPLY -->
<!-- ELSE -->
<script type="text/javascript">
ajax.callback.posts = function(data){
if(data.message_html){
$('#view_message').show();
$('.view-message').html(data.message_html);
initPostBBCode('.view-message');
var maxH = screen.height - 490;
$('.view-message').css({ maxHeight: maxH });
}
};
</script>
<div class="mrg_4" style="padding-left:2px;">
<select name="fontFace">
<option style="font-family: Verdana" value="-1" selected="selected">{L_FONT_SEL}:</option>
@ -82,7 +93,7 @@
</div>
<textarea
class="editor mrg_4" name="message" rows="18" cols="92"
class="editor mrg_4" name="message" id="message" rows="18" cols="92"
<!-- IF SHOW_VIRTUAL_KEYBOARD -->
onkeypress = "if(use_kb) return decode(event);"
<!-- ENDIF -->
@ -138,7 +149,7 @@
<div class="pad_4">{CAPTCHA_HTML}</div>
<input title="Alt+Enter" type="submit" name="preview" value="{L_PREVIEW}" id="post-preview-btn" onclick="$('#post-submit').remove();" />&nbsp;&nbsp;
<input title="Ctrl+Enter" type="submit" name="post" class="bold" value="{L_SUBMIT}" id="post-submit-btn" />
<input type="button" value="Быстрый предпросмотр" onclick="ajax.exec({ action: 'view_message', message: $('textarea.editor').val() });">
<input type="button" value="Быстрый предпросмотр" onclick="ajax.exec({ action: 'posts', type: 'view_message', message: $('textarea.editor').val()});">
<div id="post-js-warn">Для отправки сообщений необходимo включить JavaScript</div>
</div>
@ -169,7 +180,7 @@ $(document).ready(function(){
</script>
<script type="text/javascript">
var bbcode = new BBCode(document.post.message);
var bbcode = new BBCode("message");
var ctrl = "ctrl";
bbcode.addTag("codeB", "b", null, "B", ctrl);
@ -201,15 +212,6 @@ bbcode.addTag("codeAlign", function(e) { var v=e.value; e.selectedIndex=0; retur
</script>
<!-- ENDIF -->
<script type="text/javascript">
ajax.callback.view_message = function(data){
$('#view_message').show();
$('.view-message').html(data.html);
initPostBBCode('.view-message');
var maxH = screen.height - 490;
$('.view-message').css({ maxHeight: maxH });
};
</script>
<style type="text/css">
.view-message { border: 1px #A5AFB4 solid; padding: 4px; margin: 6px; overflow: auto; }
</style>

View file

@ -14,12 +14,49 @@
<!-- ENDIF -->
<!-- ENDIF / LOGGED_IN -->
<!-- IF $bb_cfg['use_ajax_posts'] && (AUTH_DELETE || AUTH_REPLY) -->
<!-- IF $bb_cfg['use_ajax_posts'] && (AUTH_DELETE || AUTH_REPLY || AUTH_EDIT) -->
<script type="text/javascript">
ajax.callback.posts = function(data) {
ajax.open_edit = false;
function edit_post(post_id, type, text) {
if(ajax.open_edit && ajax.open_edit != post_id) {
alert('У вас уже открыто одно быстрое редактирование!');
} else{
if(ajax.open_edit && !text){
$('#pp_'+ post_id).show();
$('#pe_'+ post_id).hide();
} else{
$('#pp_'+ post_id).hide();
$('#pe_'+ post_id).show();
ajax.exec({
action : 'posts',
post_id : post_id,
text : text,
type : type
});
}
ajax.open_edit = false;
}
}
ajax.callback.posts = function(data) { if(data.html){
$('#pp_'+ data.post_id).show().html(data.html);
initPostBBCode('#pp_'+ data.post_id);
$('#pe_'+ data.post_id).hide();
ajax.open_edit = false;
} else if(data.text){
ajax.open_edit = data.post_id;
$('#pe_'+ data.post_id).html(data.text);
}
if(data.redirect) document.location.href = data.redirect;
if(data.hide) $('tbody#post_'+ data.post_id).hide();
if(data.quote) $('textarea.editor').attr('value', $('textarea.editor').val() + data.message +' ').focus();
if(data.quote) $('textarea#message').attr('value', $('textarea#message').val() + data.message +' ').focus();
if(data.message_html){
$('#view_message').show();
$('.view-message').html(data.message_html);
initPostBBCode('.view-message');
var maxH = screen.height - 490;
$('.view-message').css({ maxHeight: maxH });
}
};
</script>
<!-- ENDIF -->
@ -213,8 +250,8 @@ function set_hid_chbox (id)
<!-- IF postrow.MOD_CHECKBOX --><input type="checkbox" class="select_post" onclick="set_hid_chbox('{postrow.POST_ID}');"><!-- ENDIF -->
<p style="float: right;<!-- IF TEXT_BUTTONS --> padding: 3px 2px 4px;<!-- ELSE --> padding: 1px 6px 2px;<!-- ENDIF -->" class="post_btn_1">
<!-- IF postrow.QUOTE --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="ajax.exec({ action: 'posts', post_id: {postrow.POST_ID}, type: 'quote'}); return false;<!-- ELSE -->{QUOTE_URL}{postrow.POST_ID}<!-- ENDIF -->">{QUOTE_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
<!-- IF postrow.EDIT --><a class="txtb" href="{EDIT_POST_URL}{postrow.POST_ID}">{EDIT_POST_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
<!-- IF postrow.QUOTE --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="ajax.exec({ action: 'posts', post_id: {postrow.POST_ID}, type: 'reply'}); return false;<!-- ELSE -->{QUOTE_URL}{postrow.POST_ID}<!-- ENDIF -->">{QUOTE_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
<!-- IF postrow.EDIT --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="edit_post({postrow.POST_ID}, 'edit'); return false;<!-- ELSE -->{EDIT_POST_URL}{postrow.POST_ID}<!-- ENDIF -->">{EDIT_POST_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
<!-- IF postrow.DELETE --><a class="txtb" href="<!-- IF $bb_cfg['use_ajax_posts'] -->" onclick="ajax.exec({ action: 'posts', post_id: {postrow.POST_ID}, type: 'delete'}); return false;<!-- ELSE -->{DELETE_POST_URL}{postrow.POST_ID}<!-- ENDIF -->">{DELETE_POST_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
<!-- IF postrow.IP --><a class="txtb" href="{IP_POST_URL}{postrow.POST_ID}&amp;t={TOPIC_ID}">{IP_POST_IMG}</a>{POST_BTN_SPACER}<!-- ENDIF -->
<!-- IF postrow.REPORT -->{postrow.REPORT}{POST_BTN_SPACER}<!-- ENDIF -->
@ -226,7 +263,11 @@ function set_hid_chbox (id)
</div>
<div class="post_wrap">
<div class="post_body">{postrow.MESSAGE}{postrow.ATTACHMENTS}</div><!--/post_body-->
<div class="post_body">
<span id="pp_{postrow.POST_ID}">{postrow.MESSAGE}</span>
<span id="pe_{postrow.POST_ID}"></span>
{postrow.ATTACHMENTS}
</div><!--/post_body-->
<!-- IF postrow.SIGNATURE -->{postrow.SIGNATURE}<!-- ENDIF -->
<!-- IF postrow.EDITED_MESSAGE --><div class="last_edited">{postrow.EDITED_MESSAGE}</div><!-- ENDIF -->
</div><!--/post_wrap-->