<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );

/* vim: set expandtab tabstop=4 shiftwidth=4: */

// ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) *****

// +----------------------------------------------------------------------+
// | phpBB 1.4.x Forum For MPN 188_8                                      |
// |                                                                      |
// | -> Forum Entry                                                       |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of phpBB 1.4.x Forum For MPN 188_8.                |
// |                                                                      |
// | phpBB 1.4.x Forum For MPN 188_8 is free software; you can            |
// | redistribute it and/or modify it under the terms of the GNU          |
// | General Public License as published by the Free Software Foundation; |
// | either version 2 of the License, or (at your option) any             |
// | later version.                                                       |
// |                                                                      |
// | phpBB 1.4.x Forum For MPN 188_8 is distributed in the hope that it   |
// | will be useful, but WITHOUT ANY WARRANTY; without even the implied   |
// | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     |
// | See the GNU General Public License for more details.                 |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with phpBB 1.4.x Forum For MPN 188_8; if not, write to the     |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place, Suite 330                                           |
// | Boston, MA 02111-1307  USA                                           |
// +----------------------------------------------------------------------+
// | AUTHOR(s):                                                           |
// |                                                                      |
// | The Original Code is the phpbb 1.4.4 Forum For MPN 188_8.            |
// | The Initial Developer of the Original Code is Eric Haddix.           |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | NOTES:                                                               |
// |   The MPN 188_8 forum is nearly a complete, and in some cases entire,|
// |   recode of the phpNuke 4.4 forum which was based on phpBB 1.4.x.    |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Modules
 * @subpackage forum
 * @version $Id: core_ForumEntry.php,v 1.1.2.21 2004/09/12 15:49:46 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Copyright (C) 2003 Eric Haddix
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 *
 * @tutorial
 * @filesource
 */

// ***** END LICENSE BLOCK ( DO NOT REMOVE ) *****


( include_once __ROOT__ . 'core_ForumProc.php' )
  OR goBack( translate( 'Include Error' ) );

// Forum Maint.

if ( _ADMIN_TRUSTED )
{
    @( include_once _DP_CLASS_PAR . 'core_LIB_ContMaint.baseclass.php' )
      OR goBack( translate( 'Include Error' ) );

    ( include_once _DP_CLASS_PAR . 'core_LIB_ForumMaint.subclass.php' )
      OR goBack( translate( 'Include Error' ) );

    if ( isset( $_POST['fmaint'] ) )
    {
        runForumMaint();
    }
}

// Process GET Request

if ( ! empty( $_REQUEST['qdoc'] ) )
{
    extractQuery( base64_decode( $_REQUEST['qdoc'] ), 'sg' );
    unset( $_REQUEST['qdoc'] );
}

// Redirect If Post Submission Is Canceled

if ( isset( $_REQUEST['cancel'] ) )
{
    $_SERVER['F_LIB'] -> redirectRequest( 'viewtopic.php?topic=' . $topic . '&forum=' . $forum . '&start=' . $start );
}

// Redirect To In-Page Link If Coming From Forum Navigation

if ( isset( $_REQUEST['forum'] ) && ( 0 === strpos( $_REQUEST['forum'], 'cat_' ) ) )
{
    $_SERVER['F_LIB'] -> redirectRequest( _MPN_ROOT_URI . 'forum.php#' . $_REQUEST['forum'] );
}

// Set The Global Values

$extStyle = 7;
$forumpage = 1;

$forum = ( isset( $_REQUEST['forum'] ) ) ? ( $_REQUEST['forum'] ) : ( NULL );
$topic = ( isset( $_REQUEST['topic'] ) && $_REQUEST['topic'] != '' )
       ? ( $_REQUEST['topic'] )
       : ( NULL );
$post_id = ( isset( $_REQUEST['post_id'] ) ) ? ( $_REQUEST['post_id'] ) : ( NULL );
$start = ( isset( $_REQUEST['start'] ) ) ? ( $_REQUEST['start'] ) : ( 0 );
$topic_subject = ( isset( $_POST['subject'] ) ) ? ( $_POST['subject'] ) : ( NULL );

define( '_FORUM_POST_TYPE_', ( isset( $_REQUEST['ld'] ) ) ? ( $_REQUEST['ld'] ) : ( 0 ) );

getModerators( $forum, TRUE );

if ( ! checkPageRequest() )
{
    goBack( translate( 'Invalid Request' ) );
}

$chkpage = (bool)FALSE;

// Check For Valid Request

if ( ! isset( $_POST['bbsearch'] ) && ! is_null( $forum ) )
{
    if ( ! is_null( $forum ) && ! getStats( $forum, 'exists', 'forum' ) )
    {
        goBack( translate( 'Invalid Request.  Could Not Find Requested Topic Or Forum' ) );
    }

    if ( ! is_null( $topic ) && ! getStats( $topic, 'exists', 'topic' ) )
    {
        goBack( translate( 'Invalid Request.  Could Not Find Requested Topic Or Forum' ) );
    }

    $chkpage = (bool)TRUE;
}

// Check For Locked Topic

if ( ( ! empty( $topic ) && ! empty( $_REQUEST['ld'] ) ) && getStats( $topic, 'locked', 'topic' ) )
{
    goBack( translate( 'Topic Is Locked, No Posting Allowed' ) );
}

( include_once __ROOT__ . 'core_ForumOutput.php' )
  OR goBack( translate( 'Include Error' ) );

// Check Access Rights

if ( $chkpage || isset( $_REQUEST['ld'] ) )
{
    if ( _FORUM_POST_TYPE_ == 3 && ! checkEditRights( $post_id ) )
    {
        goBack( translate( 'Insufficient Rights' ) );
    }

    checkPrivateForum( _FORUM_PAGE_ );
    $access_report = checkForumAccess();

    if ( _FORUM_POST_TYPE_ > 0 && ! _FORUM_ALLOW_POSTING_ )
    {
        $reply_report = checkReplyRights();

        if ( ! is_bool( $reply_report ) || (bool)FALSE == $reply_report )
        {
            getGlobalLoginPage( $reply_report );
            exit;
        }
    }

    if ( _FORUM_PAGE_ == 'viewtopic' || ( _FORUM_POST_TYPE_ > 1 && ( ! is_null( $topic ) && $topic != '' ) ) )
    {
        if ( ! is_null( $topic ) && $topic != '' )
        {
            @( $tmp = mysql_fetch_array( getResultSet( 4, $forum, $topic ) ) )
              OR goBack( 'Query Failed' . '**' . __FILE__ . '***' .  __LINE__ );

            if ( is_null( $topic_subject ) ) { $topic_subject = stripslashes( $tmp['topic_title'] ); }
            define( '_TOPIC_LOCKED_', ( ( $tmp['topic_status'] == 1 ) ? ( TRUE ) : ( FALSE ) ) );
        }

        unset( $tmp );
    }

    if ( ! defined( '_TOPIC_LOCKED_' ) ) { define( '_TOPIC_LOCKED_', (bool)FALSE ); }

    if ( ! defined( '_FORUM_ACCESS_' ) )
    {
        goBack( translate( 'Invalid Request.  Could Not Find Requested Topic Or Forum' ) );
    }

    // Process Post Submission

    if ( _FORUM_POST_TYPE_ > 1 )
    {
        if ( ( ! empty( $_POST ) && ! isset( $_POST['goback'] ) ) && is_null( $topic_subject ) )
        {
            goBack( translate( 'Empty Subject' ), TRUE, TRUE );
        }

        if ( isset( $_POST['submit'] ) || isset( $_POST['delete'] ) )
        {
            if ( ! is_null( $topic ) )
            {
                $total = getStats( $topic, 'count', 'topic' );

                if ( isset( $_POST['delete'] ) ) { $total--; }

                if ( ( $total + 1 ) > ( $start + $forumconfig['posts_per_page'] ) )
                {
                    $start = $start + $forumconfig['posts_per_page'];
                }
            }

            if ( isset( $_POST['delete'] ) ) { $_POST['action'] = 4; }
            savePost();
            exit;
        }
    }
}

?>