diff --git a/functions.php b/functions.php index ac0f58c..913a2d1 100644 --- a/functions.php +++ b/functions.php @@ -507,6 +507,44 @@ function cbsonline_wpforo_edit_topic_data_filter($args) return $args; } +// - accept to delete topics by anonymous user +add_action('wp_ajax_nopriv_wpforo_delete_ajax', 'cbsonline_wpforo_nopriv_delete'); +function cbsonline_wpforo_nopriv_delete() +{ + if (is_user_logged_in()) { + return; + } + + $resp = []; + $return = 0; + if ('topic' === $_POST['status']) { + if (WPF()->topic->delete(intval($_POST['postid']))) { + $forumid = (int) wpfval($_POST, 'forumid'); + $resp = [ + 'postid' => intval($_POST['postid']), + 'location' => $forumid ? WPF()->forum->get_forum_url($forumid) : wpforo_home_url(), + ]; + $return = 1; + } + } elseif ('reply' === $_POST['status']) { + $root = WPF()->post->get_root($_POST['postid']); + if (WPF()->post->delete(intval($_POST['postid']))) { + $root_replies_count = WPF()->post->get_root_replies_count($root); + $resp = [ + 'postid' => intval($_POST['postid']), + 'root' => intval($root), + 'root_count' => intval($root_replies_count), + ]; + $return = 1; + } + } + + $resp['stat'] = $return; + $resp['notice'] = WPF()->notice->get_notices(); + echo json_encode($resp); + exit(); +} + // - set hostname if annoymous user add topic data add_filter('wpforo_add_topic_data_filter', 'cbsonline_wpforo_add_topic_data_filter'); function cbsonline_wpforo_add_topic_data_filter($args) diff --git a/wpforo/layouts/2/post.php b/wpforo/layouts/2/post.php index 46f37ba..fe70866 100644 --- a/wpforo/layouts/2/post.php +++ b/wpforo/layouts/2/post.php @@ -34,6 +34,19 @@ $buttons = array( 'solved', 'sticky', 'private', 'close', 'report', 'delete', 'link' ); }else{ $buttons = array( 'report', 'delete', 'link' ); + } + if (!is_user_logged_in()) { + $forumid = (isset($forum['forumid'])) ? $forum['forumid'] : 0; + $topicid = (isset($topic['topicid'])) ? $topic['topicid'] : 0; + $is_topic = (bool) wpfval($post, 'is_first_post'); + $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']); + if (WPF()->perm->forum_can(($is_topic ? 'dt' : 'dr' ), $forumid) + && (WPF()->perm->forum_can( ($is_topic ? 'dot' : 'dor'), $forumid) + || $diff < WPF()->post->options[($is_topic ? 'dot' : 'dor').'_durr'])) { + $a = ( $is_topic ) ? 'wpftopicdelete' : 'wpfreplydelete'; + $b = ( $is_topic ) ? $topicid : $postid; + echo ''.wpforo_phrase('Delete', false).''; + } } wpforo_post_buttons( 'icon-text', $buttons, $forum, $topic, $post ); ?>