decir/posting.php
author Dan
Wed, 17 Oct 2007 20:23:51 -0400
changeset 1 6f8b7c6fac02
parent 0 0417a5a0c7be
child 3 88b85b9b9272
permissions -rw-r--r--
Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
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
    
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
    80
    if ( sizeof($errors) < 1 )
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    81
    {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    82
      // Collect other options
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    83
      
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
    84
      // 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
    85
      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
    86
      {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
    87
        $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
    88
        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
    89
        {
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
          // 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
    91
          $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
    92
          $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
    93
          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
    94
          {
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
            $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
    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
          $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
    98
          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
    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
      }
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
      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
   102
      {
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
        $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
   104
        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
   105
        {
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
          // 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
   107
          $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
   108
          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
   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
            $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
   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
          $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
   113
          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
   114
        }
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
      }
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   116
      return;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   117
    }
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
   118
    $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
   119
    $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
   120
    $parms = htmlspecialchars($_POST['authorization']);
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   121
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   122
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   123
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   124
if ( $mode == 'reply' || $mode == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   125
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   126
  if ( $mode == 'reply' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   127
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   128
    $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
   129
    $subject = '';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   130
    // Validate topic ID
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   131
    $topic_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   132
    if ( empty($topic_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   133
      die_friendly('Error', '<p>Invalid topic ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   134
    $title = 'Reply to topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   135
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   136
  else if ( $mode == 'quote' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   137
  {
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   138
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   139
    /**
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   140
     * @TODO: validate read permissions
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   141
     */
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   142
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   143
    $post_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   144
    if ( empty($post_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   145
      die_friendly('Error', '<p>Invalid post ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   146
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   147
    // 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
   148
    $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
   149
                           LEFT JOIN '.table_prefix.'decir_posts_text AS t
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   150
                             ON ( p.post_id = t.post_id )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   151
                           WHERE p.post_id=' . $post_id . ';');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   152
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   153
    if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   154
      $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   155
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   156
    if ( $db->numrows() < 1 )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   157
      die_friendly('Error', '<p>The post you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   158
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   159
    $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   160
    $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   161
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   162
    $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
   163
    $subject = 'Re: ' . htmlspecialchars($row['post_subject']);
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   164
    $quote_poster = $row['poster_name'];
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   165
    $topic_id = intval($row['topic_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   166
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   167
    $title = 'Reply to topic with quote';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   168
    
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   169
  }
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   170
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   171
  // Topic ID is good, verify topic status
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   172
  $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
   173
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   174
  if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   175
    $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   176
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   177
  $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   178
  $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   179
  
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
   180
  $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
   181
  $topic_perms = $session->fetch_page_acl($row['topic_id'], 'DecirTopic');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   182
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   183
  if ( !$forum_perms->get_permissions('decir_see_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   184
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   185
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   186
  if ( !$topic_perms->get_permissions('decir_reply') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   187
    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
   188
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   189
  $forum_in = intval($row['forum_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   190
  $topic_in = intval($row['topic_id']);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   191
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   192
  $parms = Array(
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   193
      'mode' => $mode,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   194
      'forum_in' => $forum_in,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   195
      'topic_in' => $topic_in,
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   196
      'timestamp' => time(),
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   197
      'authorized' => true
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   198
    );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   199
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   200
  $parms = serialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   201
  $parms = $aes->encrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   202
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   203
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   204
else if ( $mode == 'topic' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   205
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   206
  $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
   207
  $subject = '';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   208
  // Validate topic ID
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   209
  $forum_id = intval($paths->getParam(2));
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   210
  if ( empty($forum_id) )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   211
    die_friendly('Error', '<p>Invalid forum ID</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   212
  $title = 'Post new topic';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   213
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   214
  // 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
   215
  $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
   216
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   217
  if ( !$q )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   218
    $db->_die();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   219
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   220
  if ( $db->numrows() < 1 )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   221
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   222
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   223
  $row = $db->fetchrow();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   224
  $db->free_result();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   225
  
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
   226
  $forum_perms = $session->fetch_page_acl($row['forum_id'], 'DecirForum');
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   227
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   228
  if ( !$forum_perms->get_permissions('decir_see_forum') )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   229
    die_friendly('Error', '<p>The forum you requested does not exist.</p>');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   230
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   231
  $parms = Array(
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   232
      '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
   233
      'forum_id' => $forum_id,
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   234
      'timestamp' => time(),
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   235
      'authorized' => true
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   236
    );
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   237
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   238
  $parms = serialize($parms);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   239
  $parms = $aes->encrypt($parms, $session->private_key, ENC_HEX);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   240
  
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   241
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   242
else if ( $mode == 'already_taken_care_of' )
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   243
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   244
  $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
   245
  $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
   246
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   247
else
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   248
{
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   249
  die_friendly('Invalid request', '<p>Invalid action defined</p>');
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
$template->tpl_strings['PAGE_NAME'] = $title;
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   253
$template->add_header('<!-- DECIR BEGIN -->
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   254
    <script type="text/javascript" src="' . scriptPath . '/decir/js/bbcedit.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   255
    <script type="text/javascript" src="' . scriptPath . '/decir/js/colorpick/jquery.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   256
    <script type="text/javascript" src="' . scriptPath . '/decir/js/colorpick/farbtastic.js"></script>
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   257
    <link rel="stylesheet" type="text/css" href="' . scriptPath . '/decir/js/bbcedit.css" />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   258
    <link rel="stylesheet" type="text/css" href="' . scriptPath . '/decir/js/colorpick/farbtastic.css" />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   259
    <!-- DECIR END -->');
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   260
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   261
$template->header();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   262
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
   263
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
   264
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   265
  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
   266
          <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
   267
          <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
   268
            <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
   269
          </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
   270
        </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
   271
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   272
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   273
if ( $do_preview )
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
  $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
   276
  $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
   277
  $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
   278
  $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
   279
  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
   280
          <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
   281
          <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
   282
        </div>';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   283
}
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   284
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   285
$url = makeUrlNS('Special', 'Forum/New', 'act=post', true);
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   286
echo '<br />
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   287
      <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
   288
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
   289
        <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
   290
echo '<tr><td class="row2">Post subject:</td><td class="row1"><input name="subject" type="text" size="50" style="width: 100%;" value="' . $subject . '" /></td>';
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 '<tr><td class="row3" colspan="2">';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   292
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
   293
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
   294
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
   295
      <!-- 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
   296
      ';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents: 0
diff changeset
   297
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
   298
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
   299
echo '</table></div>';
0
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   300
echo '</form>';
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   301
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   302
$template->footer();
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   303
0417a5a0c7be Initial repository population
dan@fuhry
parents:
diff changeset
   304
?>