decir/posting.php
author Dan
Thu, 29 Nov 2007 21:48:02 -0500
changeset 11 5585ac341820
parent 6 3f66ec435f08
permissions -rw-r--r--
SECURITY: fix stupid XSS vulnerability on initial post submit; add in support for the new search API
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     1
<?php
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     2
/*
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     3
 * Decir
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     4
 * Version 0.1
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     5
 * Copyright (C) 2007 Dan Fuhry
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     6
 * posting.php - post topics and replies
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     7
 *
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    10
 *
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    13
 */
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    14
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    15
require('common.php');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    16
require('bbcode.php');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    17
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    18
//
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    19
// Set mode and parameters
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    20
//
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    21
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    22
$mode = 'topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    23
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    24
if ( $paths->getParam(1) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    25
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    26
  $n = strtolower($paths->getParam(1));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    27
  if ( $n == 'reply' || $n == 'post' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    28
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    29
    $mode = 'reply';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    30
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    31
  elseif ( $n == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    32
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    33
    $mode = 'quote';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    34
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    35
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    36
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    37
// Set the parameters for posting, then encrypt it so we don't have to do authorization checks again
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    38
// Why? Because it's better than going through some session system for postings where the data is stored on the server
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    39
// We already have AES encryption - might as well use it ;-)
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    40
$aes = new AESCrypt(AES_BITS, AES_BLOCKSIZE);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    41
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    42
$do_preview = false;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    43
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    44
if ( isset($_GET['act']) && $_GET['act'] == 'post' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    45
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    46
  if ( !is_array($_POST['do']) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    47
    die('Hacking attempt');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    48
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    49
  if ( isset($_POST['do']['preview']) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    50
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    51
    $do_preview = true;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    52
    $parms  = $_POST['authorization'];
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    53
    $parms2 = $aes->decrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    54
    if ( !$parms2 || substr($parms2, 0, 1) != 'a' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    55
    {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    56
      die('Hacking attempt: ' . $parms2);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    57
    }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    58
    $parms2 = unserialize($parms2);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    59
    $mode = 'already_taken_care_of';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    60
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    61
  else if ( isset($_POST['do']['post']) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    62
  {
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    63
    $errors = Array();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    64
    
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    65
    // Decrypt authorization array
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    66
    $parms = $aes->decrypt($_POST['authorization'], $session->private_key, ENC_HEX);
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    67
    if ( !$parms )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    68
      $errors[] = 'Could not decrypt authorization key.';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    69
    $parms = unserialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    70
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    71
    // Perform a little input validation
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    72
    if ( empty($_POST['post_text']) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    73
      $errors[] = 'Please enter a post.';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    74
    if ( empty($_POST['subject']) && $parms['mode'] == 'topic' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    75
      $errors[] = 'Please enter a topic title.';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    76
    // It's OK to trust this! The auth key is encrypted with the site's private key.
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    77
    if ( !$parms['authorized'] )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    78
      $errors[] = 'Invalid authorization key';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    79
    
3
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    80
    // If the user isn't logged in, check the CAPTCHA code
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    81
    if ( !$session->user_logged_in )
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    82
    {
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    83
      $captcha_hash = $_POST['captcha_hash'];
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    84
      $captcha_code = $_POST['captcha_code'];
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    85
      $real_code = $session->get_captcha($captcha_hash);
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    86
      if ( $real_code != $captcha_code )
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    87
        $errors[] = 'The confirmation code you entered was incorrect.';
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    88
    }
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
    89
    
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    90
    if ( sizeof($errors) < 1 )
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    91
    {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    92
      // Collect other options
11
5585ac341820 SECURITY: fix stupid XSS vulnerability on initial post submit; add in support for the new search API
Dan
parents: 6
diff changeset
    93
      $post_text = trim(htmlspecialchars($_POST['post_text']));
5585ac341820 SECURITY: fix stupid XSS vulnerability on initial post submit; add in support for the new search API
Dan
parents: 6
diff changeset
    94
      $post_subject = trim(htmlspecialchars($_POST['subject']));
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    95
      
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    96
      // Submit post
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    97
      if ( $parms['mode'] == 'reply' || $parms['mode'] == 'quote' )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    98
      {
11
5585ac341820 SECURITY: fix stupid XSS vulnerability on initial post submit; add in support for the new search API
Dan
parents: 6
diff changeset
    99
        $result = decir_submit_post($parms['topic_in'], $post_subject, $post_text, $post_id);
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   100
        if ( $result )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   101
        {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   102
          // update forum stats
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   103
          $user = $db->escape($session->username);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   104
          $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_posts = num_posts+1, last_post_id = $post_id, last_post_topic = {$parms['topic_in']}, last_post_user = $session->user_id WHERE forum_id={$parms['forum_in']};");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   105
          if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   106
          {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   107
            $db->_die('Decir posting.php under Submit post [reply]');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   108
          }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   109
          $url = makeUrlNS('Special', 'Forum/Topic/' . $parms['topic_in'], false, true);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   110
          redirect($url, 'Post submitted', 'Your post has been submitted successfully.', 4);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   111
        }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   112
      }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   113
      else if ( $parms['mode'] == 'topic' )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   114
      {
11
5585ac341820 SECURITY: fix stupid XSS vulnerability on initial post submit; add in support for the new search API
Dan
parents: 6
diff changeset
   115
        $result = decir_submit_topic($parms['forum_id'], $post_subject, $post_text, $topic_id, $post_id);
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   116
        if ( $result )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   117
        {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   118
          // update forum stats
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   119
          $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_posts = num_posts+1, num_topics = num_topics+1, last_post_id = $post_id, last_post_topic = $topic_id, last_post_user = $session->user_id WHERE forum_id={$parms['forum_id']};");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   120
          if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   121
          {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   122
            $db->_die('Decir posting.php under Submit post [topic]');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   123
          }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   124
          $url = makeUrlNS('Special', 'Forum/Topic/' . $topic_id, false, true);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   125
          redirect($url, 'Post submitted', 'Your post has been submitted successfully.', 4);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   126
        }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   127
      }
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   128
      return;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   129
    }
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   130
    $mode = 'already_taken_care_of';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   131
    $parms2 = $parms;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   132
    $parms = htmlspecialchars($_POST['authorization']);
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   133
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   134
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   135
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   136
if ( $mode == 'reply' || $mode == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   137
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   138
  if ( $mode == 'reply' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   139
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   140
    $message = '';
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   141
    $subject = '';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   142
    // Validate topic ID
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   143
    $topic_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   144
    if ( empty($topic_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   145
      die_friendly('Error', '<p>Invalid topic ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   146
    $title = 'Reply to topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   147
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   148
  else if ( $mode == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   149
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   150
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   151
    /**
3
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   152
     * @FIXME: validate read permissions
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   153
     */
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   154
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   155
    $post_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   156
    if ( empty($post_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   157
      die_friendly('Error', '<p>Invalid post ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   158
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   159
    // Get post text and topic ID
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   160
    $q = $db->sql_query('SELECT p.topic_id,t.post_text,t.bbcode_uid,p.poster_name,p.post_subject FROM '.table_prefix.'decir_posts AS p
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   161
                           LEFT JOIN '.table_prefix.'decir_posts_text AS t
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   162
                             ON ( p.post_id = t.post_id )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   163
                           WHERE p.post_id=' . $post_id . ';');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   164
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   165
    if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   166
      $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   167
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   168
    if ( $db->numrows() < 1 )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   169
      die_friendly('Error', '<p>The post you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   170
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   171
    $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   172
    $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   173
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   174
    $message = '[quote="' . $row['poster_name'] . '"]' . bbcode_strip_uid( $row['post_text'], $row['bbcode_uid'] ) . '[/quote]';
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   175
    $subject = 'Re: ' . htmlspecialchars($row['post_subject']);
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   176
    $quote_poster = $row['poster_name'];
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   177
    $topic_id = intval($row['topic_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   178
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   179
    $title = 'Reply to topic with quote';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   180
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   181
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   182
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   183
  // Topic ID is good, verify topic status
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   184
  $q = $db->sql_query('SELECT topic_id,forum_id,topic_type,topic_locked,topic_moved FROM '.table_prefix.'decir_topics WHERE topic_id=' . $topic_id . ';');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   185
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   186
  if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   187
    $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   188
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   189
  $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   190
  $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   191
  
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   192
  $forum_perms = $session->fetch_page_acl($row['forum_id'], 'DecirForum');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   193
  $topic_perms = $session->fetch_page_acl($row['topic_id'], 'DecirTopic');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   194
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   195
  if ( !$forum_perms->get_permissions('decir_see_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   196
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   197
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   198
  if ( !$topic_perms->get_permissions('decir_reply') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   199
    die_friendly('Access denied', '<p>You are not allowed to post replies in this topic.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   200
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   201
  $forum_in = intval($row['forum_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   202
  $topic_in = intval($row['topic_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   203
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   204
  $parms = Array(
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   205
      'mode' => $mode,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   206
      'forum_in' => $forum_in,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   207
      'topic_in' => $topic_in,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   208
      'timestamp' => time(),
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   209
      'authorized' => true
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   210
    );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   211
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   212
  $parms = serialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   213
  $parms = $aes->encrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   214
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   215
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   216
else if ( $mode == 'topic' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   217
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   218
  $message = '';
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   219
  $subject = '';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   220
  // Validate topic ID
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   221
  $forum_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   222
  if ( empty($forum_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   223
    die_friendly('Error', '<p>Invalid forum ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   224
  $title = 'Post new topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   225
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   226
  // Topic ID is good, verify topic status
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   227
  $q = $db->sql_query('SELECT forum_id, forum_name FROM '.table_prefix.'decir_forums WHERE forum_id=' . $forum_id . ';');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   228
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   229
  if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   230
    $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   231
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   232
  if ( $db->numrows() < 1 )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   233
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   234
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   235
  $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   236
  $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   237
  
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   238
  $forum_perms = $session->fetch_page_acl($row['forum_id'], 'DecirForum');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   239
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   240
  if ( !$forum_perms->get_permissions('decir_see_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   241
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   242
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   243
  $parms = Array(
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   244
      'mode' => $mode,
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   245
      'forum_id' => $forum_id,
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   246
      'timestamp' => time(),
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   247
      'authorized' => true
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   248
    );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   249
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   250
  $parms = serialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   251
  $parms = $aes->encrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   252
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   253
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   254
else if ( $mode == 'already_taken_care_of' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   255
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   256
  $mode = $parms2['mode'];
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   257
  $title = ( $mode == 'topic' ) ? 'Post new topic' : ( ( $mode == 'reply' ) ? 'Reply to topic' : ( $mode  == 'quote' ) ? 'Reply to topic with quote' : 'Duh...' );
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   258
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   259
else
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   260
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   261
  die_friendly('Invalid request', '<p>Invalid action defined</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   262
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   263
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   264
$template->tpl_strings['PAGE_NAME'] = $title;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   265
$template->add_header('<!-- DECIR BEGIN -->
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   266
    <script type="text/javascript" src="' . scriptPath . '/decir/js/bbcedit.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   267
    <script type="text/javascript" src="' . scriptPath . '/decir/js/colorpick/jquery.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   268
    <script type="text/javascript" src="' . scriptPath . '/decir/js/colorpick/farbtastic.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   269
    <link rel="stylesheet" type="text/css" href="' . scriptPath . '/decir/js/bbcedit.css" />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   270
    <link rel="stylesheet" type="text/css" href="' . scriptPath . '/decir/js/colorpick/farbtastic.css" />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   271
    <!-- DECIR END -->');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   272
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   273
$template->header();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   274
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   275
if ( isset($errors) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   276
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   277
  echo '<div class="error-box" style="margin: 10px 0;">
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   278
          <b>Your post could not be submitted.</b>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   279
          <ul>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   280
            <li>' . implode("</li>\n            <li>", $errors) . '</li>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   281
          </ul>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   282
        </div>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   283
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   284
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   285
if ( $do_preview )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   286
{
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   287
  $message = $_POST['post_text'];
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   288
  $subject = htmlspecialchars($_POST['subject']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   289
  $message_render = render_bbcode($message);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   290
  $message_render = RenderMan::smilieyize($message_render);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   291
  echo '<div style="border: 1px solid #222222; background-color: #F0F0F0; padding: 10px; max-height: 300px; clip: rect(0px,auto,auto,0px); overflow: auto; margin: 10px 0;">
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   292
          <h2>Post preview</h2>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   293
          <p>' . $message_render . '</p>
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   294
        </div>';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   295
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   296
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   297
$url = makeUrlNS('Special', 'Forum/New', 'act=post', true);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   298
echo '<br />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   299
      <form action="' . $url . '" method="post" enctype="multipart/form-data">';
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   300
echo '<div class="tblholder">
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   301
        <table border="0" cellspacing="1" cellpadding="4">';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   302
echo '<tr><td class="row2">Post subject:</td><td class="row1"><input name="subject" type="text" size="50" style="width: 100%;" value="' . $subject . '" /></td>';
3
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   303
if ( !$session->user_logged_in )
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   304
{
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   305
  $hash = $session->make_captcha();
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   306
  $captcha_url = makeUrlNS('Special', 'Captcha/' . $hash);
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   307
  $captcha_img = "<img alt=\"If you cannot read this image please contact the site administrator for assistance.\" src=\"$captcha_url\" onclick=\"this.src=this.src+'/a';\" style=\"cursor: pointer;\" />";
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   308
  echo '<tr><td class="row2" rowspan="2">Image verification:</td><td class="row1">' . $captcha_img . '</td></tr>';
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   309
  echo '<tr><td class="row1">Please input the code you see in the image: <input type="hidden" name="captcha_hash" value="' . $hash . '" /><input type="text" name="captcha_code" size="8" /></td></tr>';
88b85b9b9272 What can I say? More progress. Mostly bugfixes and ACL stuff now. Which reminds me - don't use this release, there are quite a few access bugs in it right now.
Dan
parents: 1
diff changeset
   310
}
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   311
echo '<tr><td class="row3" colspan="2">';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   312
echo '<textarea name="post_text" class="bbcode" rows="20" cols="80">' . $message . '</textarea>';
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   313
echo '</td></tr>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   314
echo '
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   315
      <!-- This authorization code is encrypted with '.AES_BITS.'-bit AES. -->
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   316
      ';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   317
echo '<tr><th colspan="2" class="subhead"><input type="hidden" name="authorization" value="' . $parms . '" />';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   318
echo '<input type="submit" name="do[post]" value="Submit post" style="font-weight: bold;" />&nbsp;<input type="submit" name="do[preview]" value="Show preview" /></th></tr>';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   319
echo '</table></div>';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   320
echo '</form>';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   321
6
3f66ec435f08 Some basic admin implemented
Dan
parents: 3
diff changeset
   322
decir_show_footers();
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   323
$template->footer();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   324
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   325
?>