decir/posting.php
author Dan
Tue, 13 Nov 2007 19:39:50 -0500
changeset 6 3f66ec435f08
parent 3 88b85b9b9272
child 11 5585ac341820
permissions -rw-r--r--
Some basic admin implemented
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
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    93
      
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    94
      // 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
    95
      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
    96
      {
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
        $result = decir_submit_post($parms['topic_in'], $_POST['subject'], $_POST['post_text'], $post_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
    98
        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
    99
        {
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
          // 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
   101
          $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
   102
          $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
   103
          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
   104
          {
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
            $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
   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
          $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
   108
          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
   109
        }
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
      }
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
      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
   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
        $result = decir_submit_topic($parms['forum_id'], $_POST['subject'], $_POST['post_text'], $topic_id, $post_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
   114
        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
   115
        {
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
          // 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
   117
          $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
   118
          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
   119
          {
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
            $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
   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
          $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
   123
          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
   124
        }
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
      }
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   126
      return;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   127
    }
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
   128
    $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
   129
    $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
   130
    $parms = htmlspecialchars($_POST['authorization']);
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   131
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   132
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   133
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   134
if ( $mode == 'reply' || $mode == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   135
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   136
  if ( $mode == 'reply' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   137
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   138
    $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
   139
    $subject = '';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   140
    // Validate topic ID
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   141
    $topic_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   142
    if ( empty($topic_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   143
      die_friendly('Error', '<p>Invalid topic ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   144
    $title = 'Reply to topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   145
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   146
  else if ( $mode == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   147
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   148
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   149
    /**
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
   150
     * @FIXME: validate read permissions
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   151
     */
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   152
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   153
    $post_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   154
    if ( empty($post_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   155
      die_friendly('Error', '<p>Invalid post ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   156
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   157
    // 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
   158
    $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
   159
                           LEFT JOIN '.table_prefix.'decir_posts_text AS t
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   160
                             ON ( p.post_id = t.post_id )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   161
                           WHERE p.post_id=' . $post_id . ';');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   162
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   163
    if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   164
      $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   165
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   166
    if ( $db->numrows() < 1 )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   167
      die_friendly('Error', '<p>The post you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   168
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   169
    $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   170
    $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   171
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   172
    $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
   173
    $subject = 'Re: ' . htmlspecialchars($row['post_subject']);
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   174
    $quote_poster = $row['poster_name'];
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   175
    $topic_id = intval($row['topic_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   176
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   177
    $title = 'Reply to topic with quote';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   178
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   179
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   180
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   181
  // Topic ID is good, verify topic status
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   182
  $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
   183
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   184
  if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   185
    $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   186
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   187
  $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   188
  $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   189
  
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
   190
  $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
   191
  $topic_perms = $session->fetch_page_acl($row['topic_id'], 'DecirTopic');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   192
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   193
  if ( !$forum_perms->get_permissions('decir_see_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   194
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   195
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   196
  if ( !$topic_perms->get_permissions('decir_reply') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   197
    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
   198
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   199
  $forum_in = intval($row['forum_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   200
  $topic_in = intval($row['topic_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   201
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   202
  $parms = Array(
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   203
      'mode' => $mode,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   204
      'forum_in' => $forum_in,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   205
      'topic_in' => $topic_in,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   206
      'timestamp' => time(),
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   207
      'authorized' => true
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   208
    );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   209
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   210
  $parms = serialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   211
  $parms = $aes->encrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   212
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   213
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   214
else if ( $mode == 'topic' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   215
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   216
  $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
   217
  $subject = '';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   218
  // Validate topic ID
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   219
  $forum_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   220
  if ( empty($forum_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   221
    die_friendly('Error', '<p>Invalid forum ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   222
  $title = 'Post new topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   223
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   224
  // 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
   225
  $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
   226
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   227
  if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   228
    $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   229
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   230
  if ( $db->numrows() < 1 )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   231
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   232
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   233
  $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   234
  $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   235
  
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
   236
  $forum_perms = $session->fetch_page_acl($row['forum_id'], 'DecirForum');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   237
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   238
  if ( !$forum_perms->get_permissions('decir_see_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   239
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   240
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   241
  $parms = Array(
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   242
      '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
   243
      'forum_id' => $forum_id,
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   244
      'timestamp' => time(),
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   245
      'authorized' => true
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   246
    );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   247
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   248
  $parms = serialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   249
  $parms = $aes->encrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   250
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   251
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   252
else if ( $mode == 'already_taken_care_of' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   253
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   254
  $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
   255
  $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
   256
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   257
else
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   258
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   259
  die_friendly('Invalid request', '<p>Invalid action defined</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   260
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   261
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   262
$template->tpl_strings['PAGE_NAME'] = $title;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   263
$template->add_header('<!-- DECIR BEGIN -->
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   264
    <script type="text/javascript" src="' . scriptPath . '/decir/js/bbcedit.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   265
    <script type="text/javascript" src="' . scriptPath . '/decir/js/colorpick/jquery.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   266
    <script type="text/javascript" src="' . scriptPath . '/decir/js/colorpick/farbtastic.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   267
    <link rel="stylesheet" type="text/css" href="' . scriptPath . '/decir/js/bbcedit.css" />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   268
    <link rel="stylesheet" type="text/css" href="' . scriptPath . '/decir/js/colorpick/farbtastic.css" />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   269
    <!-- DECIR END -->');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   270
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   271
$template->header();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   272
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
   273
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
   274
{
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
  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
   276
          <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
   277
          <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
   278
            <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
   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
        </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
   281
}
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
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   283
if ( $do_preview )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   284
{
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
   285
  $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
   286
  $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
   287
  $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
   288
  $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
   289
  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
   290
          <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
   291
          <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
   292
        </div>';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   293
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   294
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   295
$url = makeUrlNS('Special', 'Forum/New', 'act=post', true);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   296
echo '<br />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   297
      <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
   298
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
   299
        <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
   300
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
   301
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
   302
{
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
  $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
   304
  $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
   305
  $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
   306
  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
   307
  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
   308
}
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
   309
echo '<tr><td class="row3" colspan="2">';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   310
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
   311
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
   312
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
   313
      <!-- 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
   314
      ';
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
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
   316
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
   317
echo '</table></div>';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   318
echo '</form>';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   319
6
3f66ec435f08 Some basic admin implemented
Dan
parents: 3
diff changeset
   320
decir_show_footers();
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   321
$template->footer();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   322
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   323
?>