decir/functions.php
author Dan
Wed, 17 Oct 2007 21:52:27 -0400
changeset 2 253118325c65
parent 1 6f8b7c6fac02
child 3 88b85b9b9272
permissions -rw-r--r--
Pagination on topics and a whole crapload of other stuff.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     1
<?php
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     2
/*
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     3
 * Decir
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     4
 * Version 0.1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     5
 * Copyright (C) 2007 Dan Fuhry
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     6
 * functions.php - Utility functions used by most Decir modules
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     7
 *
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
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
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    10
 *
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    13
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    14
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    15
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    16
 * Inserts a post in reply to a topic. Does NOT check any type of authorization at all.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    17
 * @param int Topic ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    18
 * @param string Post subject
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    19
 * @param string Post text
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    20
 * @param reference Will be set to the new post ID.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    21
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    22
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    23
function decir_submit_post($topic_id, $post_subject, $post_text, &$post_id = false)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    24
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    25
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    26
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    27
  if ( !is_int($topic_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    28
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    29
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    30
  $poster_id = $session->user_id;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    31
  $poster_name = ( $session->user_logged_in ) ? $db->escape($session->username) : 'Anonymous';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    32
  $timestamp = time();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    33
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    34
  $post_text = bbcode_inject_uid($post_text, $bbcode_uid);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    35
  $post_text = $db->escape($post_text);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    36
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    37
  $post_subject = $db->escape($post_subject);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    38
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    39
  $q = $db->sql_query('INSERT INTO '.table_prefix."decir_posts(topic_id,poster_id,poster_name,post_subject,timestamp) VALUES($topic_id, $poster_id, '$poster_name', '$post_subject', $timestamp);");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    40
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    41
    $db->_die('Decir functions.php in decir_submit_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    42
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    43
  $post_id = $db->insert_id();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    44
  $q = $db->sql_query('INSERT INTO '.table_prefix."decir_posts_text(post_id, post_text, bbcode_uid) VALUES($post_id, '$post_text', '$bbcode_uid');");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    45
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    46
    $db->_die('Decir functions.php in decir_submit_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    47
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    48
  return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    49
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    50
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    51
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    52
 * Registers a new topic. Does not perform any type of authorization checks at all.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    53
 * @param int Forum ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    54
 * @param string Post subject
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    55
 * @param string Post text
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    56
 * @param reference Will be set to the new topic ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    57
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    58
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    59
function decir_submit_topic($forum_id, $post_subject, $post_text, &$topic_id = false, &$post_id = false)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    60
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    61
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    62
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    63
  if ( !is_int($forum_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    64
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    65
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    66
  $poster_id = $session->user_id;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    67
  $timestamp = time();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    68
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    69
  $topic_subject = $db->escape($post_subject);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    70
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    71
  $q = $db->sql_query('INSERT INTO ' . table_prefix . "decir_topics(forum_id, topic_title, topic_starter, timestamp) VALUES( $forum_id, '$topic_subject', $poster_id, $timestamp );");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    72
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    73
    $db->_die('Decir functions.php in decir_submit_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    74
  $topic_id = $db->insert_id();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    75
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    76
  // Submit the post
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    77
  $postsub = decir_submit_post($topic_id, $post_subject, $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:
diff changeset
    78
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    79
  if ( !$postsub )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    80
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    81
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    82
  // Update "last post"
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    83
  $q = $db->sql_query('UPDATE '.table_prefix."decir_topics SET last_post=$post_id WHERE topic_id=$topic_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    84
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    85
    $db->_die('Decir functions.php in decir_submit_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    86
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    87
  return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    88
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    89
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    90
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    91
 * Modifies a post's text. Does not perform any type of authorization checks at all.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    92
 * @param int Post ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    93
 * @param string Post subject
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    94
 * @param string Post text
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    95
 * @param string Reason for editing
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    96
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    97
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    98
function decir_edit_post($post_id, $subject, $message, $reason)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
    99
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   100
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   101
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   102
  if ( !is_int($post_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   103
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   104
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   105
  $last_edited_by = $session->user_id;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   106
  $edit_reason = $db->escape($reason);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   107
  $post_subject = $db->escape($subject);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   108
  $post_text = bbcode_inject_uid($message, $bbcode_uid);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   109
  $post_text = $db->escape($post_text);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   110
  
2
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   111
  // grace period: if the user is editing his/her own post 10 minutes or less after they originally submitted it, don't mark it as edited
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   112
  $grace = time() - ( 10 * 60 );
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   113
  $q = $db->sql_query('UPDATE '.table_prefix."decir_posts SET post_subject='$post_subject', edit_count = edit_count + 1, edit_reason='$edit_reason', last_edited_by=$last_edited_by WHERE post_id=$post_id AND timestamp < $grace;");
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   114
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   115
    $db->_die('Decir functions.php in decir_edit_post()');
2
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   116
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   117
  $q = $db->sql_query('UPDATE '.table_prefix."decir_posts_text SET post_text='$post_text' WHERE post_id=$post_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
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:
diff changeset
   119
    $db->_die('Decir functions.php in decir_edit_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   120
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   121
  return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   122
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   123
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   124
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   125
 * Deletes a post, or a topic if the post is the first topic in the thread. Does not perform any type of authorization checks at all.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   126
 * @param int Post id
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   127
 * @param string Reason for deletion
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   128
 * @param bool If true, removes the post physically from the database instead of "soft" deleting it
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   129
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   130
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   131
function decir_delete_post($post_id, $del_reason, $for_real = false)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   132
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   133
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   134
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   135
  if ( !is_int($post_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   136
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   137
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   138
  // Is this the first post in the thread?
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   139
  $q = $db->sql_query('SELECT topic_id FROM '.table_prefix."decir_posts WHERE post_id = $post_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   140
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   141
    $db->_die('Decir functions.php in decir_delete_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   142
  if ( $db->numrows() < 1 )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   143
    // Post doesn't exist
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   144
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   145
  $row = $db->fetchrow();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   146
  $db->free_result();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   147
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   148
  $topic_id = intval($row['topic_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   149
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   150
  // while we're at it, also get the forum id
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   151
  $q = $db->sql_query('SELECT p.post_id, t.forum_id FROM '.table_prefix."decir_posts AS p
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   152
                         LEFT JOIN ".table_prefix."decir_topics AS t
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   153
                           ON ( t.topic_id = p.topic_id )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   154
                         WHERE p.topic_id = $topic_id ORDER BY p.timestamp ASC LIMIT 1;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   155
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   156
    $db->_die('Decir functions.php in decir_delete_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   157
  $row = $db->fetchrow();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   158
  $db->free_result();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   159
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   160
  $forum_id = intval($row['forum_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   161
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   162
  if ( $row['post_id'] == $post_id )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   163
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   164
    // first post in the thread
2
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   165
    return decir_delete_topic($topic_id, $del_reason, $for_real);
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   166
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   167
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   168
  $del_reason = $db->escape($del_reason);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   169
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   170
  if ( $for_real )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   171
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   172
    $q = $db->sql_query('DELETE FROM '.table_prefix."decir_posts_text WHERE post_id = $post_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   173
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   174
      $db->_die('Decir functions.php in decir_delete_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   175
    $q = $db->sql_query('DELETE FROM '.table_prefix."decir_posts WHERE post_id = $post_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   176
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   177
      $db->_die('Decir functions.php in decir_delete_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   178
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   179
  else
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   180
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   181
    // Delete the post
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   182
    $q = $db->sql_query('UPDATE '.table_prefix."decir_posts SET post_deleted = 1, last_edited_by = $session->user_id, edit_reason = '$del_reason' WHERE post_id = $post_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   183
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   184
      $db->_die('Decir functions.php in decir_delete_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   185
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   186
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   187
  // update forum stats
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   188
  $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_posts = num_posts - 1 WHERE forum_id = $forum_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   189
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   190
      $db->_die('Decir functions.php in decir_delete_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   191
    
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   192
  // update last post and topic
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   193
  decir_update_forum_stats($forum_id);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   194
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   195
  return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   196
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   197
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   198
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   199
 * Deletes a topic. Does not perform any type of authorization checks at all.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   200
 * @param int Topic ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   201
 * @param string Reason for deleting the topic
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   202
 * @param bool If true, physically removes the topic from the database; else, just turns on the delete switch
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   203
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   204
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   205
function decir_delete_topic($topic_id, $del_reason, $unlink = false)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   206
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   207
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   208
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   209
  if ( !is_int($topic_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   210
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   211
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   212
  // Obtain a list of posts in the topic
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   213
  $q = $db->sql_query('SELECT post_id FROM '.table_prefix.'decir_posts WHERE topic_id = ' . $topic_id . ';');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   214
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   215
    $db->_die('Decir functions.php in decir_delete_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   216
  if ( $db->numrows() < 1 )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   217
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   218
  $posts = array();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   219
  while ( $row = $db->fetchrow() )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   220
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   221
    $posts[] = $row['post_id'];
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   222
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   223
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   224
  // Obtain forum ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   225
  $q = $db->sql_query('SELECT forum_id FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   226
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   227
    $db->_die('Decir functions.php in decir_delete_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   228
  list($forum_id) = $db->fetchrow_num();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   229
  $db->free_result();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   230
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   231
  // Perform delete
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   232
  if ( $unlink )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   233
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   234
    // Remove all posts from the database
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   235
    $post_list = implode(' OR post_id=', $posts);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   236
    $q = $db->sql_query('DELETE FROM '.table_prefix."decir_posts_text WHERE $post_list;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   237
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   238
      $db->_die('Decir functions.php in decir_delete_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   239
    $q = $db->sql_query('DELETE FROM '.table_prefix."decir_posts WHERE $post_list;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   240
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   241
      $db->_die('Decir functions.php in decir_delete_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   242
    // Remove the topic itself
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   243
    $q = $db->sql_query('DELETE FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   244
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   245
      $db->_die('Decir functions.php in decir_delete_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   246
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   247
  else
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   248
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   249
    $reason = $db->escape($del_reason);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   250
    $topic_deletor = $session->user_id;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   251
    $q = $db->sql_query('UPDATE ' . table_prefix . "decir_topics SET topic_deleted = 1, topic_deletor = $topic_deletor, topic_delete_reason = '$reason' WHERE topic_id = $topic_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   252
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   253
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   254
  // Update forum stats
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   255
  $post_count = count($posts);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   256
  $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_topics = num_topics - 1, num_posts = num_posts - $post_count WHERE forum_id = $forum_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   257
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   258
    $db->_die('Decir functions.php in decir_delete_topic()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   259
  decir_update_forum_stats($forum_id);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   260
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   261
  return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   262
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   263
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   264
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   265
 * Updates the last post information for the specified forum.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   266
 * @param int Forum ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   267
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   268
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   269
function decir_update_forum_stats($forum_id)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   270
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   271
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   272
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   273
  if ( !is_int($forum_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   274
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   275
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   276
  $sql = 'SELECT p.post_id, p.poster_id, p.topic_id FROM ' . table_prefix . "decir_posts AS p
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   277
            LEFT JOIN ".table_prefix."decir_topics AS t
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   278
              ON ( t.topic_id = p.topic_id )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   279
            WHERE t.forum_id = $forum_id
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   280
              AND p.post_deleted != 1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   281
            ORDER BY p.timestamp DESC
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   282
            LIMIT 1;";
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   283
  $q = $db->sql_query($sql);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   284
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   285
    $db->_die('Decir functions.php in decir_update_forum_stats()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   286
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   287
  if ( $db->numrows() < 1 )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   288
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   289
    $last_post_id = 'NULL';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   290
    $last_post_topic = 'NULL';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   291
    $last_post_user = 'NULL';
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   292
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   293
  else
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   294
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   295
    $row = $db->fetchrow();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   296
    $last_post_id = intval($row['post_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   297
    $last_post_topic = intval($row['topic_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   298
    $last_post_user = intval($row['poster_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   299
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   300
  $db->free_result();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   301
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   302
  $sql = 'UPDATE ' . table_prefix . "decir_forums SET last_post_id = $last_post_id, last_post_topic = $last_post_topic,
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   303
            last_post_user = $last_post_user WHERE forum_id = $forum_id;";
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   304
  if ( $db->sql_query($sql) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   305
    return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   306
  else
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   307
    $db->_die('Decir functions.php in decir_update_forum_stats()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   308
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   309
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   310
/**
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   311
 * Un-deletes a post so that the public can see it.
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   312
 * @param int Post ID
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   313
 */
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   314
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   315
function decir_restore_post($post_id)
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   316
{
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   317
  global $db, $session, $paths, $template, $plugins; // Common objects
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   318
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   319
  if ( !is_int($post_id) )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   320
    return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   321
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   322
  $q = $db->sql_query('UPDATE ' . table_prefix . "decir_posts SET post_deleted = 0, edit_count = 0, last_edited_by = NULL, edit_reason = '' WHERE post_id = $post_id AND post_deleted = 1;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   323
  if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   324
    $db->_die('Decir functions.php in decir_restore_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   325
  
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   326
  if ( $db->sql_affectedrows() > 0 )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   327
  {
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   328
    // get forum id
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   329
    $q = $db->sql_query('SELECT t.forum_id FROM '.table_prefix."decir_posts AS p
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   330
                           LEFT JOIN ".table_prefix."decir_topics AS t
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   331
                             ON ( p.topic_id = t.topic_id )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   332
                           WHERE p.post_id = $post_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   333
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   334
      $db->_die('Decir functions.php in decir_restore_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   335
    $row = $db->fetchrow();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   336
    $db->free_result();
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   337
    $forum_id = intval($row['forum_id']);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   338
    // Update forum stats
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   339
    $q = $db->sql_query('UPDATE ' . table_prefix . "decir_forums SET num_posts = num_posts + 1 WHERE forum_id = $forum_id;");
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   340
    if ( !$q )
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   341
      $db->_die('Decir functions.php in decir_restore_post()');
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   342
    decir_update_forum_stats($forum_id);
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   343
    return true;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   344
  }
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   345
  return false;
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   346
}
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   347
2
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   348
/**
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   349
 * Un-deletes a topic so that the public can see it.
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   350
 * @param int Topic ID
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   351
 */
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   352
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   353
function decir_restore_topic($topic_id)
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   354
{
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   355
  global $db, $session, $paths, $template, $plugins; // Common objects
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   356
  
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   357
  if ( !is_int($topic_id) )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   358
    return false;
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   359
  
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   360
  // Obtain a list of posts in the topic
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   361
  $q = $db->sql_query('SELECT post_id FROM '.table_prefix.'decir_posts WHERE topic_id = ' . $topic_id . ';');
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   362
  if ( !$q )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   363
    $db->_die('Decir functions.php in decir_delete_topic()');
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   364
  if ( $db->numrows() < 1 )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   365
    return false;
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   366
  $posts = array();
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   367
  while ( $row = $db->fetchrow() )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   368
  {
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   369
    $posts[] = $row['post_id'];
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   370
  }
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   371
  
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   372
  // Obtain forum ID
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   373
  $q = $db->sql_query('SELECT forum_id FROM '.table_prefix."decir_topics WHERE topic_id = $topic_id;");
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   374
  if ( !$q )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   375
    $db->_die('Decir functions.php in decir_restore_topic()');
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   376
  list($forum_id) = $db->fetchrow_num();
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   377
  $db->free_result();
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   378
  
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   379
  $q = $db->sql_query('UPDATE ' . table_prefix . "decir_topics SET topic_deleted = 0, topic_deletor = NULL, topic_delete_reason = NULL WHERE topic_id = $topic_id;");
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   380
  
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   381
  // Update forum stats
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   382
  $post_count = count($posts);
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   383
  $q = $db->sql_query('UPDATE '.table_prefix."decir_forums SET num_topics = num_topics + 1, num_posts = num_posts + $post_count WHERE forum_id = $forum_id;");
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   384
  if ( !$q )
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   385
    $db->_die('Decir functions.php in decir_restore_topic()');
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   386
  decir_update_forum_stats($forum_id);
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   387
  
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   388
  return true;
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   389
}
253118325c65 Pagination on topics and a whole crapload of other stuff.
Dan
parents: 1
diff changeset
   390
1
6f8b7c6fac02 Let's just say: major progress and still only 20% complete. So many changes I forgot to commit.
Dan
parents:
diff changeset
   391
?>