2011-06-27 21:23:51 +00:00
< ? php
2017-01-13 01:20:43 +03:00
/**
2018-06-23 21:50:13 +03:00
* TorrentPier – Bull - powered BitTorrent tracker engine
2017-01-13 01:20:43 +03:00
*
2023-12-12 22:14:01 +07:00
* @ copyright Copyright ( c ) 2005 - 2024 TorrentPier ( https :// torrentpier . com )
2018-06-23 21:50:13 +03:00
* @ link https :// github . com / torrentpier / torrentpier for the canonical source repository
* @ license https :// github . com / torrentpier / torrentpier / blob / master / LICENSE MIT License
2017-01-13 01:20:43 +03:00
*/
2011-06-27 21:23:51 +00:00
define ( 'BB_SCRIPT' , 'posting' );
2023-06-10 15:55:53 +07:00
2017-02-05 22:28:55 +03:00
require __DIR__ . '/common.php' ;
require INC_DIR . '/bbcode.php' ;
require ATTACH_DIR . '/attachment_mod.php' ;
2011-06-27 21:23:51 +00:00
2023-09-04 01:01:01 +07:00
$page_cfg [ 'load_tpl_vars' ] = [
'post_icons'
];
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
$submit = ( bool ) @ $_REQUEST [ 'post' ];
2024-02-08 23:17:09 +07:00
$refresh = $preview = ( bool ) @ $_REQUEST [ 'preview' ];
2017-01-13 01:20:43 +03:00
$delete = ( bool ) @ $_REQUEST [ 'delete' ];
2024-02-08 23:17:09 +07:00
$mode = ( string ) @ $_REQUEST [ 'mode' ];
$confirm = isset ( $_POST [ 'confirm' ]);
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
$forum_id = ( int ) @ $_REQUEST [ POST_FORUM_URL ];
$topic_id = ( int ) @ $_REQUEST [ POST_TOPIC_URL ];
$post_id = ( int ) @ $_REQUEST [ POST_POST_URL ];
2011-06-27 21:23:51 +00:00
// Set topic type
2017-01-13 01:20:43 +03:00
$topic_type = ( @ $_POST [ 'topictype' ]) ? ( int ) $_POST [ 'topictype' ] : POST_NORMAL ;
2023-09-04 01:01:01 +07:00
$topic_type = in_array ( $topic_type , [ POST_NORMAL , POST_STICKY , POST_ANNOUNCE ]) ? $topic_type : POST_NORMAL ;
2011-06-27 21:23:51 +00:00
2014-08-05 00:45:47 +06:00
$selected_rg = 0 ;
2014-08-27 17:26:20 +04:00
$switch_rg_sig = 0 ;
2014-08-05 01:11:03 +06:00
$switch_poster_rg_sig = 0 ;
2014-08-05 00:45:47 +06:00
2017-01-13 01:20:43 +03:00
if ( $mode == 'smilies' ) {
generate_smilies ( 'window' );
exit ;
2011-06-27 21:23:51 +00:00
}
$tracking_topics = get_tracks ( 'topic' );
$tracking_forums = get_tracks ( 'forum' );
// Start session management
$user -> session_start ();
2014-01-27 20:36:14 +00:00
set_die_append_msg ( $forum_id , $topic_id );
2011-06-27 21:23:51 +00:00
// What auth type do we need to check?
2023-09-04 01:01:01 +07:00
$is_auth = [];
2017-01-13 01:20:43 +03:00
switch ( $mode ) {
case 'newtopic' :
case 'new_rel' :
if ( bf ( $userdata [ 'user_opt' ], 'user_opt' , 'dis_topic' )) {
bb_die ( $lang [ 'RULES_POST_CANNOT' ]);
}
if ( $topic_type == POST_ANNOUNCE ) {
$is_auth_type = 'auth_announce' ;
} elseif ( $topic_type == POST_STICKY ) {
$is_auth_type = 'auth_sticky' ;
} else {
$is_auth_type = 'auth_post' ;
}
break ;
case 'reply' :
case 'quote' :
if ( bf ( $userdata [ 'user_opt' ], 'user_opt' , 'dis_post' )) {
bb_die ( $lang [ 'RULES_REPLY_CANNOT' ]);
}
$is_auth_type = 'auth_reply' ;
break ;
case 'editpost' :
if ( bf ( $userdata [ 'user_opt' ], 'user_opt' , 'dis_post_edit' )) {
bb_die ( $lang [ 'RULES_EDIT_CANNOT' ]);
}
$is_auth_type = 'auth_edit' ;
break ;
case 'delete' :
$is_auth_type = 'auth_delete' ;
break ;
default :
2017-06-12 15:15:04 +03:00
bb_simple_die ( $lang [ 'NO_POST_MODE' ]);
2017-01-13 01:20:43 +03:00
break ;
2011-06-27 21:23:51 +00:00
}
2017-06-12 15:15:04 +03:00
// Various lookups to find topic_id, forum_id, post_id etc
2011-06-27 21:23:51 +00:00
$error_msg = '' ;
2023-09-04 01:01:01 +07:00
$post_data = [];
2017-01-13 01:20:43 +03:00
switch ( $mode ) {
case 'newtopic' :
case 'new_rel' :
if ( ! $forum_id ) {
2017-06-12 15:15:04 +03:00
bb_simple_die ( $lang [ 'FORUM_NOT_EXIST' ]);
2017-01-13 01:20:43 +03:00
}
$sql = " SELECT * FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1 " ;
break ;
case 'reply' :
if ( ! $topic_id ) {
bb_die ( $lang [ 'NO_TOPIC_ID' ]);
}
$sql = " SELECT f.*, t.*
FROM " . BB_FORUMS . " f , " . BB_TOPICS . " t
2011-06-27 21:23:51 +00:00
WHERE t . topic_id = $topic_id
AND f . forum_id = t . forum_id
LIMIT 1 " ;
2017-01-13 01:20:43 +03:00
break ;
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
case 'quote' :
case 'editpost' :
case 'delete' :
if ( ! $post_id ) {
2017-06-12 15:15:04 +03:00
bb_simple_die ( $lang [ 'NO_POST_ID' ]);
2017-01-13 01:20:43 +03:00
}
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
$select_sql = 'SELECT f.*, t.*, p.*' ;
2024-04-10 18:35:55 +07:00
$select_sql .= ! $submit ? ', pt.*, u.username, u.user_id' : '' ;
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
$from_sql = " FROM " . BB_POSTS . " p, " . BB_TOPICS . " t, " . BB_FORUMS . " f " ;
2024-04-10 18:35:55 +07:00
$from_sql .= ! $submit ? " , " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u " : '' ;
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
$where_sql = "
2011-06-27 21:23:51 +00:00
WHERE p . post_id = $post_id
AND t . topic_id = p . topic_id
AND f . forum_id = p . forum_id
" ;
2017-01-13 01:20:43 +03:00
$where_sql .= ( ! $submit ) ? "
2011-06-27 21:23:51 +00:00
AND pt . post_id = p . post_id
AND u . user_id = p . poster_id
" : '';
2017-01-13 01:20:43 +03:00
$sql = " $select_sql $from_sql $where_sql LIMIT 1 " ;
break ;
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
default :
2017-06-12 15:15:04 +03:00
bb_simple_die ( $lang [ 'NO_VALID_MODE' ]);
2011-06-27 21:23:51 +00:00
}
2017-01-13 01:20:43 +03:00
if ( $post_info = DB () -> fetch_row ( $sql )) {
$forum_id = $post_info [ 'forum_id' ];
$forum_name = $post_info [ 'forum_name' ];
2017-06-12 15:15:04 +03:00
set_die_append_msg ( $forum_id );
2017-01-13 01:20:43 +03:00
$is_auth = auth ( AUTH_ALL , $forum_id , $userdata , $post_info );
if ( $post_info [ 'forum_status' ] == FORUM_LOCKED && ! $is_auth [ 'auth_mod' ]) {
bb_die ( $lang [ 'FORUM_LOCKED' ]);
} elseif ( $mode != 'newtopic' && $mode != 'new_rel' && $post_info [ 'topic_status' ] == TOPIC_LOCKED && ! $is_auth [ 'auth_mod' ]) {
bb_die ( $lang [ 'TOPIC_LOCKED' ]);
}
if ( $mode == 'editpost' || $mode == 'delete' ) {
$topic_id = $post_info [ 'topic_id' ];
$post_data [ 'poster_post' ] = ( $post_info [ 'poster_id' ] == $userdata [ 'user_id' ]);
$post_data [ 'first_post' ] = ( $post_info [ 'topic_first_post_id' ] == $post_id );
$post_data [ 'last_post' ] = ( $post_info [ 'topic_last_post_id' ] == $post_id );
$post_data [ 'last_topic' ] = ( $post_info [ 'forum_last_post_id' ] == $post_id );
$post_data [ 'topic_type' ] = $post_info [ 'topic_type' ];
$post_data [ 'poster_id' ] = $post_info [ 'poster_id' ];
$selected_rg = $post_info [ 'poster_rg_id' ];
2023-05-29 00:32:36 +07:00
$switch_rg_sig = ( bool ) $post_info [ 'attach_rg_sig' ];
2017-01-13 01:20:43 +03:00
// Can this user edit/delete the post?
if ( $post_info [ 'poster_id' ] != $userdata [ 'user_id' ] && ! $is_auth [ 'auth_mod' ]) {
$auth_err = ( $delete || $mode == 'delete' ) ? $lang [ 'DELETE_OWN_POSTS' ] : $lang [ 'EDIT_OWN_POSTS' ];
} elseif ( ! $post_data [ 'last_post' ] && ! $is_auth [ 'auth_mod' ] && ( $mode == 'delete' || $delete )) {
$auth_err = $lang [ 'CANNOT_DELETE_REPLIED' ];
}
if ( isset ( $auth_err )) {
bb_die ( $auth_err );
}
} else {
if ( $mode == 'quote' ) {
$topic_id = $post_info [ 'topic_id' ];
}
if ( $mode == 'newtopic' ) {
$post_data [ 'topic_type' ] = POST_NORMAL ;
}
$post_data [ 'first_post' ] = ( $mode == 'newtopic' );
$post_data [ 'last_post' ] = false ;
}
} else {
bb_die ( $lang [ 'NO_SUCH_POST' ]);
2011-06-27 21:23:51 +00:00
}
// The user is not authed, if they're not logged in then redirect
// them, else show them an error message
2017-01-13 01:20:43 +03:00
if ( ! $is_auth [ $is_auth_type ]) {
if ( ! IS_GUEST ) {
bb_die ( sprintf ( $lang [ 'SORRY_' . strtoupper ( $is_auth_type )], $is_auth [ $is_auth_type . '_type' ]));
}
2023-11-21 09:37:05 +07:00
switch ( $mode ) {
case 'newtopic' :
2024-05-01 12:36:06 +07:00
$redirect = " mode=newtopic& " . POST_FORUM_URL . " = $forum_id " ;
2023-11-21 09:37:05 +07:00
break ;
case 'new_rel' :
2024-05-01 12:36:06 +07:00
$redirect = " mode=new_rel& " . POST_FORUM_URL . " = $forum_id " ;
2023-11-21 09:37:05 +07:00
break ;
case 'reply' :
2024-05-01 12:36:06 +07:00
$redirect = " mode=reply& " . POST_TOPIC_URL . " = $topic_id " ;
2023-11-21 09:37:05 +07:00
break ;
case 'quote' :
case 'editpost' :
2024-05-01 12:36:06 +07:00
$redirect = " mode=quote& " . POST_POST_URL . " = $post_id " ;
2023-11-21 09:37:05 +07:00
break ;
default :
$redirect = '' ;
}
2017-01-13 01:20:43 +03:00
redirect ( LOGIN_URL . " ?redirect=/ " . POSTING_URL . " ? $redirect " );
2011-06-27 21:23:51 +00:00
}
2017-01-13 01:20:43 +03:00
if ( $mode == 'new_rel' ) {
2017-05-05 00:57:55 +03:00
if ( $tor_status = implode ( ',' , $bb_cfg [ 'tor_cannot_new' ])) {
2017-01-13 01:20:43 +03:00
$sql = DB () -> fetch_rowset ( " SELECT t.topic_title, t.topic_id, tor.tor_status
FROM " . BB_BT_TORRENTS . " tor , " . BB_TOPICS . " t
2011-07-30 14:21:57 +00:00
WHERE poster_id = { $userdata [ 'user_id' ]}
AND tor . topic_id = t . topic_id
AND tor . tor_status IN ( $tor_status )
2014-02-02 21:44:03 +00:00
ORDER BY tor . reg_time
2011-07-30 14:21:57 +00:00
" );
2017-01-13 01:20:43 +03:00
$topics = '' ;
foreach ( $sql as $row ) {
$topics .= $bb_cfg [ 'tor_icons' ][ $row [ 'tor_status' ]] . '<a href="' . TOPIC_URL . $row [ 'topic_id' ] . '">' . $row [ 'topic_title' ] . '</a><div class="spacer_12"></div>' ;
}
2018-06-24 20:43:19 +03:00
if ( $topics && ! ( IS_SUPER_ADMIN && ! empty ( $_REQUEST [ 'edit_tpl' ]))) {
2017-01-13 01:20:43 +03:00
bb_die ( $topics . $lang [ 'UNEXECUTED_RELEASE' ]);
}
}
2017-02-05 22:28:55 +03:00
require INC_DIR . '/posting_tpl.php' ;
2017-01-13 01:20:43 +03:00
exit ;
2011-06-27 21:23:51 +00:00
}
2023-12-31 01:28:21 +07:00
// Disallowed release editing with a certain status
if ( ! empty ( $bb_cfg [ 'tor_cannot_edit' ]) && $post_info [ 'allow_reg_tracker' ] && $post_data [ 'first_post' ] && ! IS_AM ) {
if ( $tor_status = DB () -> fetch_row ( " SELECT tor_status FROM " . BB_BT_TORRENTS . " WHERE topic_id = $topic_id AND forum_id = $forum_id AND tor_status IN( " . implode ( ',' , $bb_cfg [ 'tor_cannot_edit' ]) . " ) LIMIT 1 " )) {
bb_die ( $lang [ 'NOT_EDIT_TOR_STATUS' ] . ': <span title="' . $lang [ 'TOR_STATUS_NAME' ][ $tor_status [ 'tor_status' ]] . '">' . $bb_cfg [ 'tor_icons' ][ $tor_status [ 'tor_status' ]] . ' ' . $lang [ 'TOR_STATUS_NAME' ][ $tor_status [ 'tor_status' ]] . '</span>.' );
}
}
2024-08-18 20:34:38 +07:00
// Notify, allow robots indexing and anonymous mode
2024-08-18 21:10:56 +07:00
$anonymous_mode = $post_info [ 'post_anonymous' ] ? ? ( bool ) bf ( $userdata [ 'user_opt' ], 'user_opt' , 'user_anonymous' );
2024-08-18 17:18:46 +07:00
$robots_indexing = $post_info [ 'topic_allow_robots' ] ? ? true ;
2017-01-13 01:20:43 +03:00
if ( $submit || $refresh ) {
2024-08-18 21:03:54 +07:00
if ( ! IS_GUEST ) {
$anonymous_mode = ! empty ( $_POST [ 'anonymous' ]);
}
2024-08-18 17:18:46 +07:00
if ( IS_AM ) {
$robots_indexing = ! empty ( $_POST [ 'robots' ]);
}
2017-01-13 01:20:43 +03:00
$notify_user = ( int ) ! empty ( $_POST [ 'notify' ]);
} else {
$notify_user = bf ( $userdata [ 'user_opt' ], 'user_opt' , 'user_notify' );
if ( ! IS_GUEST && $mode != 'newtopic' && ! $notify_user ) {
$notify_user = ( int ) DB () -> fetch_row ( " SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = " . $userdata [ 'user_id' ]);
}
2011-06-27 21:23:51 +00:00
}
$update_post_time = ! empty ( $_POST [ 'update_post_time' ]);
execute_posting_attachment_handling ();
// если за время пока вы писали ответ, в топике появились новые сообщения, перед тем как ваше сообщение будет отправлено, выводится предупреждение с обзором этих сообщений
$topic_has_new_posts = false ;
2017-01-13 01:20:43 +03:00
if ( ! IS_GUEST && $mode != 'newtopic' && ( $submit || $preview || $mode == 'quote' || $mode == 'reply' ) && isset ( $_COOKIE [ COOKIE_TOPIC ])) {
2017-05-05 01:00:38 +03:00
if ( $topic_last_read = max (( int )( @ $tracking_topics [ $topic_id ]), ( int )( @ $tracking_forums [ $forum_id ]))) {
2017-01-13 01:20:43 +03:00
$sql = " SELECT p.*, pt.post_text, u.username, u.user_rank
FROM " . BB_POSTS . " p , " . BB_POSTS_TEXT . " pt , " . BB_USERS . " u
WHERE p . topic_id = " . (int) $topic_id . "
2011-06-27 21:23:51 +00:00
AND u . user_id = p . poster_id
AND pt . post_id = p . post_id
AND p . post_time > $topic_last_read
ORDER BY p . post_time
2017-01-13 01:20:43 +03:00
LIMIT " . $bb_cfg['posts_per_page'] ;
if ( $rowset = DB () -> fetch_rowset ( $sql )) {
$topic_has_new_posts = true ;
foreach ( $rowset as $i => $row ) {
2023-09-04 01:01:01 +07:00
$template -> assign_block_vars ( 'new_posts' , [
2017-01-13 01:20:43 +03:00
'ROW_CLASS' => ! ( $i % 2 ) ? 'row1' : 'row2' ,
'POSTER' => profile_url ( $row ),
'POSTER_NAME_JS' => addslashes ( $row [ 'username' ]),
2023-11-11 23:47:28 +07:00
'POST_DATE' => '<a class="small" href="' . POST_URL . $row [ 'post_id' ] . '#' . $row [ 'post_id' ] . '" title="' . $lang [ 'POST_LINK' ] . '">' . bb_date ( $row [ 'post_time' ], $bb_cfg [ 'post_date_format' ]) . '</a>' ,
2023-09-04 01:01:01 +07:00
'MESSAGE' => get_parsed_post ( $row )
]);
2017-01-13 01:20:43 +03:00
}
2023-09-04 01:01:01 +07:00
$template -> assign_vars ([ 'TPL_SHOW_NEW_POSTS' => true ]);
2017-01-13 01:20:43 +03:00
set_tracks ( COOKIE_TOPIC , $tracking_topics , $topic_id );
unset ( $rowset );
}
}
2011-06-27 21:23:51 +00:00
}
2017-06-12 15:15:04 +03:00
// Confirm deletion
2017-01-13 01:20:43 +03:00
if (( $delete || $mode == 'delete' ) && ! $confirm ) {
if ( isset ( $_POST [ 'cancel' ])) {
redirect ( POST_URL . " $post_id # $post_id " );
}
2023-09-04 01:01:01 +07:00
$hidden_fields = [
2024-05-04 12:58:51 +07:00
POST_POST_URL => $post_id ,
2023-09-04 01:01:01 +07:00
'mode' => 'delete'
];
print_confirmation ([
2017-01-13 01:20:43 +03:00
'QUESTION' => $lang [ 'CONFIRM_DELETE' ],
'FORM_ACTION' => POSTING_URL ,
2023-09-04 01:01:01 +07:00
'HIDDEN_FIELDS' => build_hidden_fields ( $hidden_fields )
]);
2017-01-13 01:20:43 +03:00
} elseif (( $submit || $confirm ) && ! $topic_has_new_posts ) {
//
// Submit post (newtopic, edit, reply, etc.)
//
$return_message = '' ;
$return_meta = '' ;
switch ( $mode ) {
case 'editpost' :
case 'newtopic' :
case 'reply' :
$username = ( ! empty ( $_POST [ 'username' ])) ? clean_username ( $_POST [ 'username' ]) : '' ;
$subject = ( ! empty ( $_POST [ 'subject' ])) ? clean_title ( $_POST [ 'subject' ]) : '' ;
$message = ( ! empty ( $_POST [ 'message' ])) ? prepare_message ( $_POST [ 'message' ]) : '' ;
2018-06-24 16:35:13 +03:00
$attach_rg_sig = ( isset ( $_POST [ 'attach_rg_sig' ], $_POST [ 'poster_rg' ]) && $_POST [ 'poster_rg' ] != - 1 ) ? 1 : 0 ;
2017-01-13 01:20:43 +03:00
$poster_rg_id = ( isset ( $_POST [ 'poster_rg' ]) && $_POST [ 'poster_rg' ] != - 1 ) ? ( int ) $_POST [ 'poster_rg' ] : 0 ;
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Post :: prepare_post ( $mode , $post_data , $error_msg , $username , $subject , $message );
2017-01-13 01:20:43 +03:00
if ( ! $error_msg ) {
$topic_type = ( isset ( $post_data [ 'topic_type' ]) && $topic_type != $post_data [ 'topic_type' ] && ! $is_auth [ 'auth_sticky' ] && ! $is_auth [ 'auth_announce' ]) ? $post_data [ 'topic_type' ] : $topic_type ;
2024-08-18 20:49:34 +07:00
\TorrentPier\Legacy\Post :: submit_post ( $mode , $post_data , $return_message , $return_meta , $forum_id , $topic_id , $post_id , $topic_type , DB () -> escape ( $username ), DB () -> escape ( $subject ), DB () -> escape ( $message ), $update_post_time , $poster_rg_id , $attach_rg_sig , ( int ) $robots_indexing , ( int ) $anonymous_mode );
2017-01-13 01:20:43 +03:00
$post_url = POST_URL . " $post_id # $post_id " ;
$post_msg = ( $mode == 'editpost' ) ? $lang [ 'EDITED' ] : $lang [ 'STORED' ];
$onclick = ( $mode == 'editpost' ) ? 'onclick="return post2url(this.href);"' : '' ;
$return_message .= $post_msg . ' < br />< br />
< a ' . $onclick . ' href = " ' . $post_url . ' " > ' . $lang[' POST_RETURN '] . ' </ a >
2014-01-27 20:36:14 +00:00
' ;
2017-01-13 01:20:43 +03:00
}
break ;
case 'delete' :
2023-04-05 16:35:10 +07:00
if ( ! $post_data [ 'first_post' ]) {
\TorrentPier\Legacy\Post :: delete_post ( $mode , $post_data , $return_message , $return_meta , $forum_id , $topic_id , $post_id );
} else {
2023-09-04 01:01:01 +07:00
redirect ( 'modcp.php?' . POST_TOPIC_URL . " = $topic_id &mode=delete&sid= " . $userdata [ 'session_id' ]);
2023-04-05 16:35:10 +07:00
}
2017-01-13 01:20:43 +03:00
break ;
}
if ( ! $error_msg ) {
2023-09-04 01:01:01 +07:00
if ( ! in_array ( $mode , [ 'editpost' , 'delete' ])) {
2017-01-13 01:20:43 +03:00
$user_id = ( $mode == 'reply' || $mode == 'newtopic' ) ? $userdata [ 'user_id' ] : $post_data [ 'poster_id' ];
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Post :: update_post_stats ( $mode , $post_data , $forum_id , $topic_id , $post_id , $user_id );
2017-01-13 01:20:43 +03:00
}
$attachment_mod [ 'posting' ] -> insert_attachment ( $post_id );
if ( ! $error_msg ) {
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Post :: user_notification ( $mode , $post_data , $post_info [ 'topic_title' ], $forum_id , $topic_id , $notify_user );
2017-01-13 01:20:43 +03:00
}
if ( $mode == 'newtopic' || $mode == 'reply' ) {
set_tracks ( COOKIE_TOPIC , $tracking_topics , $topic_id );
}
if ( defined ( 'TORRENT_ATTACH_ID' ) && $bb_cfg [ 'bt_newtopic_auto_reg' ] && ! $error_msg ) {
if ( ! DB () -> fetch_row ( " SELECT attach_id FROM " . BB_BT_TORRENTS . " WHERE attach_id = " . TORRENT_ATTACH_ID )) {
if ( $bb_cfg [ 'premod' ]) {
// Получение списка id форумов начиная с parent
$forum_parent = $forum_id ;
if ( $post_info [ 'forum_parent' ]) {
$forum_parent = $post_info [ 'forum_parent' ];
}
$count_rowset = DB () -> fetch_rowset ( " SELECT forum_id FROM " . BB_FORUMS . " WHERE forum_parent = $forum_parent " );
2023-09-04 01:01:01 +07:00
$sub_forums = [];
2017-01-13 01:20:43 +03:00
foreach ( $count_rowset as $count_row ) {
if ( $count_row [ 'forum_id' ] != $forum_id ) {
$sub_forums [] = $count_row [ 'forum_id' ];
}
}
$sub_forums [] = $forum_id ;
2017-05-05 00:57:55 +03:00
$sub_forums = implode ( ',' , $sub_forums );
2017-01-13 01:20:43 +03:00
// Подсчет проверенных релизов в форумах раздела
$count_checked_releases = DB () -> fetch_row ( "
2014-02-02 21:44:03 +00:00
SELECT COUNT ( * ) AS checked_releases
2017-01-13 01:20:43 +03:00
FROM " . BB_BT_TORRENTS . "
WHERE poster_id = " . $userdata['user_id'] . "
2014-02-02 21:44:03 +00:00
AND forum_id IN ( $sub_forums )
2017-01-13 01:20:43 +03:00
AND tor_status IN ( " . TOR_APPROVED . " , " . TOR_DOUBTFUL . " , " . TOR_TMP . " )
2014-02-02 21:44:03 +00:00
LIMIT 1
" , 'checked_releases');
2017-01-13 01:20:43 +03:00
if ( $count_checked_releases || IS_AM ) {
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Torrent :: tracker_register ( TORRENT_ATTACH_ID , 'newtopic' , TOR_NOT_APPROVED );
2017-01-13 01:20:43 +03:00
} else {
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Torrent :: tracker_register ( TORRENT_ATTACH_ID , 'newtopic' , TOR_PREMOD );
2017-01-13 01:20:43 +03:00
}
} else {
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Torrent :: tracker_register ( TORRENT_ATTACH_ID , 'newtopic' , TOR_NOT_APPROVED );
2017-01-13 01:20:43 +03:00
}
}
}
// Update atom feed
update_atom ( 'topic' , $topic_id );
if ( $mode == 'reply' && $post_info [ 'topic_status' ] == TOPIC_LOCKED ) {
$locked_warn = '
2011-06-27 21:23:51 +00:00
< div class = " warnColor1 " >
2017-01-13 01:20:43 +03:00
< b > ' . $lang[' LOCKED_WARN '] . ' </ b >
2011-06-27 21:23:51 +00:00
</ div >
< br />< hr />< br />
' ;
2017-01-13 01:20:43 +03:00
$return_message = $locked_warn . $return_message ;
}
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
bb_die ( $return_message );
}
2011-06-27 21:23:51 +00:00
}
2017-01-13 01:20:43 +03:00
if ( $refresh || $error_msg || ( $submit && $topic_has_new_posts )) {
$username = ( ! empty ( $_POST [ 'username' ])) ? clean_username ( $_POST [ 'username' ]) : '' ;
$subject = ( ! empty ( $_POST [ 'subject' ])) ? clean_title ( $_POST [ 'subject' ]) : '' ;
$message = ( ! empty ( $_POST [ 'message' ])) ? prepare_message ( $_POST [ 'message' ]) : '' ;
if ( $preview ) {
$preview_subject = $subject ;
$preview_username = $username ;
$preview_message = htmlCHR ( $message , false , ENT_NOQUOTES );
$preview_message = bbcode2html ( $preview_message );
2023-09-04 01:01:01 +07:00
$template -> assign_vars ([
2017-01-13 01:20:43 +03:00
'TPL_PREVIEW_POST' => true ,
2024-02-08 14:30:22 +07:00
'TOPIC_TITLE' => $preview_subject ,
2017-01-13 01:20:43 +03:00
'POST_SUBJECT' => $preview_subject ,
'POSTER_NAME' => $preview_username ,
'POST_DATE' => bb_date ( TIMENOW ),
2023-09-04 01:01:01 +07:00
'PREVIEW_MSG' => $preview_message
]);
2017-01-13 01:20:43 +03:00
}
} else {
// User default entry point
if ( $mode == 'newtopic' ) {
2024-04-10 18:35:55 +07:00
$username = ! IS_GUEST ? $userdata [ 'username' ] : '' ;
2017-01-13 01:20:43 +03:00
$subject = $message = '' ;
} elseif ( $mode == 'reply' ) {
2024-04-10 18:35:55 +07:00
$username = ! IS_GUEST ? $userdata [ 'username' ] : '' ;
2017-01-13 01:20:43 +03:00
$subject = $message = '' ;
} elseif ( $mode == 'quote' || $mode == 'editpost' ) {
$subject = ( $post_data [ 'first_post' ]) ? $post_info [ 'topic_title' ] : '' ;
$message = $post_info [ 'post_text' ];
if ( $mode == 'quote' ) {
if ( $post_info [ 'post_attachment' ] && ! IS_AM ) {
$message = $post_info [ 'topic_title' ];
}
$quote_username = ( $post_info [ 'post_username' ] != '' ) ? $post_info [ 'post_username' ] : $post_info [ 'username' ];
$message = '[quote="' . $quote_username . '"][qpost=' . $post_info [ 'post_id' ] . ']' . $message . '[/quote]' ;
// hide user passkey
2024-06-12 13:12:25 +07:00
$message = preg_replace ( '#(?<=[\?&;]' . $bb_cfg [ 'passkey_key' ] . '=)[a-zA-Z0-9]#' , 'passkey' , $message );
2017-01-13 01:20:43 +03:00
// hide sid
2024-02-08 23:17:09 +07:00
$message = preg_replace ( '#(?<=[\?&;]sid=)[a-zA-Z0-9]#' , 'sid' , $message );
2017-01-13 01:20:43 +03:00
2024-02-08 23:17:09 +07:00
$subject = $wordCensor -> censorString ( $subject );
$message = $wordCensor -> censorString ( $message );
2017-01-13 01:20:43 +03:00
2024-02-08 23:17:09 +07:00
if ( ! preg_match ( '/^Re:/' , $subject ) && ! empty ( $subject )) {
2017-01-13 01:20:43 +03:00
$subject = 'Re: ' . $subject ;
}
$mode = 'reply' ;
} else {
$username = ( $post_info [ 'user_id' ] == GUEST_UID && ! empty ( $post_info [ 'post_username' ])) ? $post_info [ 'post_username' ] : '' ;
}
}
2011-06-27 21:23:51 +00:00
}
2017-01-13 01:20:43 +03:00
if ( $error_msg ) {
2023-09-04 01:01:01 +07:00
$template -> assign_vars ([ 'ERROR_MESSAGE' => $error_msg ]);
2011-06-27 21:23:51 +00:00
}
2017-01-13 01:20:43 +03:00
if ( IS_GUEST || ( $mode == 'editpost' && $post_info [ 'poster_id' ] == GUEST_UID )) {
$template -> assign_var ( 'POSTING_USERNAME' );
2011-06-27 21:23:51 +00:00
}
// Notify checkbox
2017-01-13 01:20:43 +03:00
if ( ! IS_GUEST ) {
if ( $mode != 'editpost' || ( $mode == 'editpost' && $post_info [ 'poster_id' ] != GUEST_UID )) {
$template -> assign_var ( 'SHOW_NOTIFY_CHECKBOX' );
}
2011-06-27 21:23:51 +00:00
}
2024-08-18 20:36:29 +07:00
// Anonymous mode
2024-08-18 21:07:31 +07:00
if ( ! IS_GUEST ) {
$template -> assign_var ( 'SHOW_ANONYMOUS_CHECKBOX' );
}
2024-08-18 20:36:29 +07:00
2011-06-27 21:23:51 +00:00
$topic_type_toggle = '' ;
2017-01-13 01:20:43 +03:00
if ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data [ 'first_post' ])) {
2024-08-18 17:18:46 +07:00
// Allow robots indexing
if ( IS_AM ) {
$template -> assign_var ( 'SHOW_ROBOTS_CHECKBOX' );
}
// Topic type selection
2023-09-04 01:01:01 +07:00
$template -> assign_block_vars ( 'switch_type_toggle' , []);
2017-01-13 01:20:43 +03:00
if ( $is_auth [ 'auth_sticky' ]) {
$topic_type_toggle .= '<label><input type="radio" name="topictype" value="' . POST_STICKY . '"' ;
if ( isset ( $post_data [ 'topic_type' ]) && ( $post_data [ 'topic_type' ] == POST_STICKY || $topic_type == POST_STICKY )) {
2023-08-24 14:34:28 +07:00
$topic_type_toggle .= ' checked' ;
2017-01-13 01:20:43 +03:00
}
$topic_type_toggle .= ' /> ' . $lang [ 'POST_STICKY' ] . '</label> ' ;
}
if ( $is_auth [ 'auth_announce' ]) {
$topic_type_toggle .= '<label><input type="radio" name="topictype" value="' . POST_ANNOUNCE . '"' ;
if ( isset ( $post_data [ 'topic_type' ]) && ( $post_data [ 'topic_type' ] == POST_ANNOUNCE || $topic_type == POST_ANNOUNCE )) {
2023-08-24 14:34:28 +07:00
$topic_type_toggle .= ' checked' ;
2017-01-13 01:20:43 +03:00
}
$topic_type_toggle .= ' /> ' . $lang [ 'POST_ANNOUNCEMENT' ] . '</label> ' ;
}
if ( $topic_type_toggle != '' ) {
2023-08-24 14:34:28 +07:00
$topic_type_toggle = $lang [ 'POST_TOPIC_AS' ] . ': <label><input type="radio" name="topictype" value="' . POST_NORMAL . '"' . (( ! isset ( $post_data [ 'topic_type' ]) || $post_data [ 'topic_type' ] == POST_NORMAL || $topic_type == POST_NORMAL ) ? ' checked' : '' ) . ' /> ' . $lang [ 'POST_NORMAL' ] . '</label> ' . $topic_type_toggle ;
2017-01-13 01:20:43 +03:00
}
2011-06-27 21:23:51 +00:00
}
//bt
2018-06-24 15:18:35 +03:00
$topic_dl_type = $post_info [ 'topic_dl_type' ] ? ? 0 ;
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
if ( $post_info [ 'allow_reg_tracker' ] && $post_data [ 'first_post' ] && ( $topic_dl_type || $is_auth [ 'auth_mod' ])) {
$sql = "
2013-06-28 23:57:30 +00:00
SELECT tor . attach_id
2017-01-13 01:20:43 +03:00
FROM " . BB_POSTS . " p
LEFT JOIN " . BB_BT_TORRENTS . " tor ON ( p . post_id = tor . post_id )
2013-06-28 23:57:30 +00:00
WHERE p . post_id = $post_id
" ;
2017-01-13 01:20:43 +03:00
$result = DB () -> fetch_row ( $sql );
if ( ! empty ( $result [ 'attach_id' ])) {
if ( ! $topic_type_toggle ) {
$topic_type_toggle = $lang [ 'POST_TOPIC_AS' ] . ': ' ;
}
$dl_ds = $dl_ch = $dl_hid = '' ;
$dl_type_name = 'topic_dl_type' ;
2024-04-10 18:35:55 +07:00
$dl_type_val = $topic_dl_type ? 1 : 0 ;
2017-01-13 01:20:43 +03:00
if ( ! $post_info [ 'allow_reg_tracker' ] && ! $is_auth [ 'auth_mod' ]) {
2023-08-24 14:34:28 +07:00
$dl_ds = ' disabled ' ;
2017-01-13 01:20:43 +03:00
$dl_hid = '<input type="hidden" name="topic_dl_type" value="' . $dl_type_val . '" />' ;
$dl_type_name = '' ;
}
2023-08-24 14:34:28 +07:00
$dl_ch = ( $mode == 'editpost' && $post_data [ 'first_post' ] && $topic_dl_type ) ? ' checked ' : '' ;
2017-01-13 01:20:43 +03:00
$topic_type_toggle .= '<nobr><input type="checkbox" name="' . $dl_type_name . '" id="topic_dl_type_id" ' . $dl_ds . $dl_ch . ' /><label for="topic_dl_type_id"> ' . $lang [ 'POST_DOWNLOAD' ] . '</label></nobr>' ;
$topic_type_toggle .= $dl_hid ;
}
2011-06-27 21:23:51 +00:00
}
//bt end
2014-08-05 00:45:47 +06:00
// Get poster release group data
2017-01-13 01:20:43 +03:00
if ( $userdata [ 'user_level' ] == GROUP_MEMBER || IS_AM ) {
$poster_rgroups = '' ;
2014-08-27 14:32:54 +04:00
2017-01-13 01:20:43 +03:00
$sql = " SELECT ug.group_id, g.group_name, g.release_group
FROM " . BB_USER_GROUP . " ug
INNER JOIN " . BB_GROUPS . " g ON ( g . group_id = ug . group_id )
2014-08-27 14:32:54 +04:00
WHERE ug . user_id = { $userdata [ 'user_id' ]}
AND g . release_group = 1
ORDER BY g . group_name " ;
2017-01-13 01:20:43 +03:00
foreach ( DB () -> fetch_rowset ( $sql ) as $row ) {
$selected_opt = ( $row [ 'group_id' ] == $selected_rg ) ? 'selected' : '' ;
$poster_rgroups .= '<option value="' . $row [ 'group_id' ] . '" ' . $selected_opt . '>' . $row [ 'group_name' ] . '</option>' ;
}
2014-08-05 00:45:47 +06:00
}
2023-11-18 10:36:16 +07:00
// Assign posting title & hidden fields
$page_title = '' ;
2011-06-27 21:23:51 +00:00
$hidden_form_fields = '<input type="hidden" name="mode" value="' . $mode . '" />' ;
2017-01-13 01:20:43 +03:00
switch ( $mode ) {
case 'newtopic' :
$page_title = $lang [ 'POST_A_NEW_TOPIC' ];
$hidden_form_fields .= '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />' ;
break ;
case 'reply' :
$page_title = $lang [ 'POST_A_REPLY' ];
$hidden_form_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />' ;
break ;
case 'editpost' :
$page_title = $lang [ 'EDIT_POST' ];
$hidden_form_fields .= '<input type="hidden" name="' . POST_POST_URL . '" value="' . $post_id . '" />' ;
break ;
2011-06-27 21:23:51 +00:00
}
// Generate smilies listing for page output
generate_smilies ( 'inline' );
2023-09-04 01:01:01 +07:00
$template -> set_filenames ([ 'body' => 'posting.tpl' ]);
2011-06-27 21:23:51 +00:00
2013-05-22 20:06:05 +00:00
// Output the data to the template
2023-09-04 01:01:01 +07:00
$template -> assign_vars ([
2017-01-13 01:20:43 +03:00
'FORUM_NAME' => htmlCHR ( $forum_name ),
'PAGE_TITLE' => $page_title ,
'POSTING_TYPE_TITLE' => $page_title ,
'POSTING_TOPIC_ID' => ( $mode != 'newtopic' ) ? $topic_id : '' ,
2024-02-08 14:30:22 +07:00
'POSTING_TOPIC_TITLE' => ( $mode != 'newtopic' ) ? $post_info [ 'topic_title' ] : '' ,
2017-01-13 01:20:43 +03:00
'USERNAME' => @ $username ,
2023-08-24 14:34:28 +07:00
'CAPTCHA_HTML' => ( IS_GUEST && ! $bb_cfg [ 'captcha' ][ 'disabled' ]) ? bb_captcha ( 'get' ) : '' ,
2017-01-13 01:20:43 +03:00
'SUBJECT' => $subject ,
'MESSAGE' => $message ,
2024-04-10 18:35:55 +07:00
'POSTER_RGROUPS' => ! empty ( $poster_rgroups ) ? $poster_rgroups : '' ,
2024-08-18 17:18:46 +07:00
'ATTACH_RG_SIG' => $switch_rg_sig ? : false ,
2024-08-18 20:41:53 +07:00
'ANONYMOUS_MODE' => ( $mode == 'reply' ) ? $lang [ 'ANONYMOUS_REPLY' ] : $lang [ 'ANONYMOUS_TOPIC' ],
2017-01-13 01:20:43 +03:00
2024-08-18 20:34:38 +07:00
'U_VIEW_FORUM' => FORUM_URL . $forum_id ,
2023-09-04 01:01:01 +07:00
'U_VIEWTOPIC' => ( $mode == 'reply' ) ? TOPIC_URL . " $topic_id &postorder=desc " : '' ,
2017-01-13 01:20:43 +03:00
2024-08-18 17:18:46 +07:00
'S_NOTIFY_CHECKED' => $notify_user ? 'checked' : '' ,
'S_ROBOTS_CHECKED' => $robots_indexing ? 'checked' : '' ,
2024-08-18 20:34:38 +07:00
'S_ANONYMOUS_CHECKED' => $anonymous_mode ? 'checked' : '' ,
2017-01-13 01:20:43 +03:00
'S_TYPE_TOGGLE' => $topic_type_toggle ,
'S_TOPIC_ID' => $topic_id ,
'S_POST_ACTION' => POSTING_URL ,
'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields ,
2023-09-04 01:01:01 +07:00
]);
2011-06-27 21:23:51 +00:00
2017-01-13 01:20:43 +03:00
if ( $mode == 'newtopic' || $post_data [ 'first_post' ]) {
$template -> assign_var ( 'POSTING_SUBJECT' );
2013-05-22 20:06:05 +00:00
}
// Update post time
2017-01-13 01:20:43 +03:00
if ( $mode == 'editpost' && $post_data [ 'last_post' ] && ! $post_data [ 'first_post' ]) {
2023-09-04 01:01:01 +07:00
$template -> assign_vars ([
2017-01-13 01:20:43 +03:00
'SHOW_UPDATE_POST_TIME' => ( $is_auth [ 'auth_mod' ] || ( $post_data [ 'poster_post' ] && $post_info [ 'post_time' ] + 3600 * 3 > TIMENOW )),
'UPDATE_POST_TIME_CHECKED' => ( $post_data [ 'poster_post' ] && ( $post_info [ 'post_time' ] + 3600 * 2 > TIMENOW )),
2023-09-04 01:01:01 +07:00
]);
2013-05-22 20:06:05 +00:00
}
2011-06-27 21:23:51 +00:00
// Topic review
2017-01-13 01:20:43 +03:00
if ( $mode == 'reply' && $is_auth [ 'auth_read' ]) {
2018-06-24 14:13:56 +03:00
\TorrentPier\Legacy\Post :: topic_review ( $topic_id );
2011-06-27 21:23:51 +00:00
}
require ( PAGE_HEADER );
$template -> pparse ( 'body' );
2017-01-13 01:20:43 +03:00
require ( PAGE_FOOTER );