plugins/nuggie/postbit.php
author Dan
Tue, 11 Dec 2007 19:05:43 -0500
changeset 1 6e76ca311f2d
parent 0 a09fb41e48d5
child 2 4e7762863437
permissions -rw-r--r--
Put a placeholder into that user link part so I don't forget to fix it ;-)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     1
<?php
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     2
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     3
/*
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     4
 * Nuggie
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     5
 * Version 0.1
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     6
 * Copyright (C) 2007 Dan Fuhry
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     7
 *
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
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
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
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.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    10
 *
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
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
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    13
 */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    14
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    15
/**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    16
 * Class for displaying a Nuggie blog post.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    17
 * @package Enano
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    18
 * @subpackage Nuggie
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    19
 */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    20
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    21
class NuggiePostbit
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    22
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    23
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    24
   * The unique row ID of the post. This can be false if
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    25
   * the post is being displayed as part of a preview or
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    26
   * otherwise doesn't actually exist in the database.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    27
   * @var int
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    28
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    29
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    30
  var $post_id = false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    31
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    32
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    33
   * The title of the post.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    34
   * @var string
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    35
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    36
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    37
  var $post_title;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    38
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    39
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    40
   * The cleaned title of the post. This is calculated
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    41
   * internally and need not be set.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    42
   * @var string
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    43
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    44
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    45
  var $post_title_clean;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    46
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    47
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    48
   * Who wrote this post (user ID).
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    49
   * @var int
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    50
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    51
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    52
  var $post_author = 1;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    53
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    54
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    55
   * When the post was posted. UNIX timestamp.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    56
   * @var int
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    57
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    58
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    59
  var $post_timestamp = 1;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    60
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    61
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    62
   * The actual content of the post.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    63
   * @var string
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    64
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    65
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    66
  var $post_text = '';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    67
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    68
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    69
   * Whether the user can edit the post or not.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    70
   * @var bool
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    71
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    72
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    73
  var $auth_edit = false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    74
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    75
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    76
   * The number of comments on the post
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    77
   * @var int
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    78
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    79
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    80
  var $num_comments = 0;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    81
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    82
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    83
   * The master permission set for the blog. Only used during pagination, don't worry about this
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    84
   * @var object
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    85
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    86
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    87
  var $blog_perms;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    88
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    89
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    90
   * Renders the post.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    91
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    92
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    93
  function render_post()
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    94
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    95
    global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    96
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    97
    if ( file_exists( ENANO_ROOT . "/themes/{$template->theme_id}/blog_post.tpl" ) )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    98
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    99
      $parser = $template->makeParser('blog_post.tpl');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   100
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   101
    else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   102
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   103
      $tpl_code = <<<TPLBLOCK
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   104
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   105
      <!-- Start of blog post -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   106
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   107
      <div class="blog-post">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   108
        <div class="blog-post-header">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   109
          <div class="blog-post-datemark">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   110
            {DATE_D} {DATE_j}<br />
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   111
            {DATE_M} {DATE_Y}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   112
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   113
          <h3><a href="{PERMALINK}">{POST_TITLE}</a></h3>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   114
          <div class="blog-post-author">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   115
            Posted by {USER_LINK} on {TIMESTAMP}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   116
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   117
          <div class="blog-post-buttons">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   118
          <a href="{PERMALINK}#do:comments" onclick="ajaxComments();">{COMMENT_STRING}</a>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   119
          <!-- BEGIN auth_edit -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   120
          &bull;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   121
          <a href="{EDIT_LINK}">Edit this post</a>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   122
          <!-- END auth_edit -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   123
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   124
        </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   125
        <div class="blog-post-body">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   126
          {POST_TEXT}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   127
        </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   128
      </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   129
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   130
      <!-- Finish blog post -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   131
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   132
TPLBLOCK;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   133
      $parser = $template->makeParserText($tpl_code);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   134
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   135
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   136
    $this->post_title_clean = nuggie_sanitize_title($this->post_title);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   137
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   138
    // List of valid characters for date()
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   139
    $date_chars = 'dDjlNSwzWFmMntLoYyaABgGhHiseIOTZcrU';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   140
    $date_chars = enano_str_split($date_chars);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   141
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   142
    $strings = array();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   143
    foreach ( $date_chars as $char )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   144
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   145
      $strings["DATE_$char"] = date($char, $this->post_timestamp);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   146
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   147
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   148
    $strings['POST_TITLE'] = htmlspecialchars($this->post_title);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   149
    $strings['POST_TEXT'] = RenderMan::render($this->post_text);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   150
    $strings['PERMALINK'] = makeUrlNS('Blog', $this->post_author . date('/Y/n/j/', $this->post_timestamp) . $this->post_title_clean, false, true);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   151
    $strings['EDIT_LINK'] = makeUrlNS('Special', "Preferences/Blog/Write/{$this->post_id}", false, true);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   152
    
1
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   153
    /*
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   154
     * FIXME: Make this a real colored userpage link
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   155
     */
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   156
    
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   157
    $strings['USER_LINK'] = '&lt;fixme&gt;' . htmlspecialchars($this->post_author) . '&lt;/fixme&gt;';
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   158
    
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   159
    if ( $this->num_comments == 0 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   160
      $comment_string = 'No comments';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   161
    else if ( $this->num_comments == 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   162
      $comment_string = '1 comment';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   163
    else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   164
      $comment_string = intval($this->num_comments) . ' comments';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   165
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   166
    $strings['COMMENT_STRING'] = $comment_string;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   167
    $strings['TIMESTAMP'] = date('l, F j, Y \a\t h:i <\s\m\a\l\l>A</\s\m\a\l\l>', $this->post_timestamp);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   168
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   169
    $parser->assign_vars($strings);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   170
    $parser->assign_bool(array(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   171
        'auth_edit' => ( $this->auth_edit )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   172
      ));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   173
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   174
    return $parser->run();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   175
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   176
  /**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   177
   * Don't worry about this, it's only called from the paginator.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   178
   * @access private
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   179
   */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   180
   
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   181
  function paginate_handler($_, $row)
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   182
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   183
    global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   184
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   185
    if ( !is_object($this->blog_perms) )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   186
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   187
      $this->blog_perms = $session->fetch_page_acl($row['username'], 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   188
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   189
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   190
    $perms = $session->fetch_page_acl("{$row['post_timestamp']}_{$row['post_id']}", 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   191
    $perms->perms = $session->acl_merge($this->blog_perms->perms, $perms->perms);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   192
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   193
    /*
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   194
    if ( !$perms->get_permissions('read') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   195
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   196
      return "POST {$this->post_id} DENIED";
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   197
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   198
    */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   199
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   200
    $this->post_id = intval($row['post_id']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   201
    $this->post_title = $row['post_title'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   202
    $this->post_text = $row['post_text'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   203
    $this->post_author = $row['username'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   204
    $this->post_timestamp = intval($row['post_timestamp']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   205
    $this->num_comments = intval($row['num_comments']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   206
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   207
    return $this->render_post();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   208
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   209
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   210
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   211
function nuggie_blog_uri_handler($uri)
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   212
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   213
  global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   214
  $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/nuggie/style.css" />');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   215
  if ( strstr($uri, '/') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   216
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   217
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   218
    // Permalinked post
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   219
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   220
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   221
    // Split and parse URI
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   222
    $particles = explode('/', $uri);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   223
    if ( count($particles) < 5 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   224
      return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   225
    $sz = count($particles);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   226
    for ( $i = 5; $i < $sz; $i++ )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   227
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   228
      $particles[4] .= '/' . $particles[$i];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   229
      unset($particles[$i]);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   230
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   231
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   232
    $particles[4] = nuggie_sanitize_title($particles[4]);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   233
    $poster =& $particles[0];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   234
    $year =& $particles[1];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   235
    $month =& $particles[2];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   236
    $day =& $particles[3];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   237
    $post_title_clean =& $particles[4];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   238
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   239
    $particlecomp = $db->escape(implode('/', $particles));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   240
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   241
    $year = intval($year);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   242
    $month = intval($month);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   243
    $day = intval($day);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   244
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   245
    $time_min = mktime(0, 0, 0, $month, $day, $year);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   246
    $time_max = $time_min + 86400;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   247
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   248
    $ptc = $db->escape($post_title_clean);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   249
    $uname = $db->escape(dirtify_page_id($poster));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   250
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   251
    $q = $db->sql_query("SELECT p.post_id, p.post_title, p.post_title_clean, p.post_author, p.post_timestamp, p.post_text, b.blog_name,\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   252
                      . "       b.blog_subtitle, b.blog_type, b.allowed_users, u.username, u.user_level, COUNT(c.comment_id) AS num_comments\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   253
                      . "      FROM " . table_prefix . "blog_posts AS p\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   254
                      . "  LEFT JOIN " . table_prefix . "blogs AS b\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   255
                      . "    ON ( b.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   256
                      . "  LEFT JOIN " . table_prefix . "users AS u\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   257
                      . "    ON ( u.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   258
                      . "  LEFT JOIN " . table_prefix . "comments AS c\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   259
                      . "    ON ( ( c.page_id = '{$particlecomp}' AND c.namespace = 'Blog' ) OR ( c.page_id IS NULL AND c.namespace IS NULL ) )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   260
                      . "  WHERE p.post_timestamp >= $time_min AND p.post_timestamp <= $time_max\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   261
                      . "    AND p.post_title_clean = '$ptc' AND u.username = '$uname'\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   262
                      . "  GROUP BY p.post_id;");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   263
    if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   264
      $db->_die('Nuggie post handler selecting main post data');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   265
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   266
    if ( $db->numrows() < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   267
      return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   268
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   269
    if ( $db->numrows() > 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   270
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   271
      die_friendly('Ambiguous blog posts', '<p>FIXME: You have two posts with the same title posted on the same day by the same user. I was
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   272
                                               not able to distinguish which post you wish to view.</p>');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   273
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   274
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   275
    $row = $db->fetchrow();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   276
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   277
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   278
    // Determine permissions
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   279
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   280
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   281
    // The way we're doing this is first fetching permissions for the blog, and then merging them
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   282
    // with permissions specific to the post. This way the admin can set custom permissions for the
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   283
    // entire blog, and they'll be inherited unless individual posts have overriding permissions.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   284
    $perms_blog = $session->fetch_page_acl($row['username'], 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   285
    $perms = $session->fetch_page_acl("{$row['post_timestamp']}_{$row['post_id']}", 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   286
    $perms->perms = $session->acl_merge($perms->perms, $perms_post->perms);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   287
    unset($perms_blog);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   288
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   289
    if ( $row['blog_type'] == 'private' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   290
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   291
      $allowed_users = unserialize($row['allowed_users']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   292
      if ( !in_array($session->username, $allowed_users) && !$perms->get_permissions('nuggie_see_non_public') && $row['username'] != $session->username )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   293
      {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   294
        return '_err_access_denied';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   295
      }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   296
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   297
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   298
    $acl_type = ( $row['post_author'] == $session->user_id ) ? 'nuggie_edit_own' : 'nuggie_edit_other';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   299
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   300
    if ( !$perms->get_permissions('read') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   301
      return '_err_access_denied';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   302
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   303
    // We're validated - display post
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   304
    $postbit = new NuggiePostbit();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   305
    $postbit->post_id = intval($row['post_id']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   306
    $postbit->post_title = $row['post_title'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   307
    $postbit->post_text = $row['post_text'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   308
    $postbit->post_author = $row['username'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   309
    $postbit->post_timestamp = intval($row['post_timestamp']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   310
    $postbit->auth_edit = $perms->get_permissions($acl_type);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   311
    $postbit->num_comments = intval($row['num_comments']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   312
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   313
    $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($row['post_title']) . ' &laquo; ' . htmlspecialchars($row['blog_name']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   314
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   315
    $template->header();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   316
    echo '&lt; <a href="' . makeUrlNS('Blog', $row['username']) . '">' . htmlspecialchars($row['blog_name']) . '</a>';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   317
    echo $postbit->render_post();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   318
    $template->footer();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   319
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   320
    return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   321
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   322
  else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   323
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   324
    return nuggie_blog_index($uri);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   325
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   326
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   327
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   328
function nuggie_blog_index($username)
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   329
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   330
  global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   331
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   332
  $username_esc = $db->escape($username);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   333
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   334
  // First look for the user's blog so we can get permissions
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   335
  $q = $db->sql_query('SELECT b.blog_type, b.allowed_users, b.user_id, b.blog_name, b.blog_subtitle FROM ' . table_prefix . "blogs AS b LEFT JOIN " . table_prefix . "users AS u ON ( u.user_id = b.user_id ) WHERE u.username = '$username_esc';");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   336
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   337
    $db->_die('Nuggie main blog page doing preliminary security check');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   338
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   339
  if ( $db->numrows() < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   340
    return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   341
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   342
  list($blog_type, $allowed_users, $user_id, $blog_name, $blog_subtitle) = $db->fetchrow_num();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   343
  $db->free_result();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   344
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   345
  $perms = $session->fetch_page_acl($username, 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   346
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   347
  if ( $blog_type == 'private' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   348
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   349
    $allowed_users = unserialize($allowed_users);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   350
    if ( !in_array($session->username, $allowed_users) && !$perms->get_permissions('nuggie_see_non_public') && $username != $session->username )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   351
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   352
      return '_err_access_denied';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   353
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   354
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   355
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   356
  // Determine number of posts and prefetch ACL info
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   357
  $q = $db->sql_query('SELECT post_timestamp, post_id FROM ' . table_prefix . 'blog_posts WHERE post_author = ' . $user_id . ' AND post_published = 1;');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   358
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   359
    $db->_die('Nuggie main blog page doing rowcount of blog posts');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   360
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   361
  $count = $db->numrows();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   362
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   363
  while ( $row = $db->fetchrow($q) )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   364
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   365
    $session->fetch_page_acl("{$row['post_timestamp']}_{$row['post_id']}", 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   366
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   367
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   368
  $db->free_result($q);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   369
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   370
  $q = $db->sql_unbuffered_query("SELECT p.post_id, p.post_title, p.post_title_clean, p.post_author, p.post_timestamp, p.post_text, b.blog_name,\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   371
                    . "       b.blog_subtitle, u.username, u.user_level, COUNT(c.comment_id) AS num_comments\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   372
                    . "      FROM " . table_prefix . "blog_posts AS p\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   373
                    . "  LEFT JOIN " . table_prefix . "blogs AS b\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   374
                    . "    ON ( b.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   375
                    . "  LEFT JOIN " . table_prefix . "users AS u\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   376
                    . "    ON ( u.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   377
                    . "  LEFT JOIN " . table_prefix . "comments AS c\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   378
                    . "    ON ( ( c.page_id REGEXP CONCAT('([0-9]+)/([0-9]+)/([0-9]+)/', p.post_title_clean) AND c.namespace = 'Blog' ) OR ( c.page_id IS NULL AND c.namespace IS NULL ) )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   379
                    . "  WHERE p.post_author = $user_id AND p.post_published = 1\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   380
                    . "  GROUP BY p.post_id\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   381
                    . "  ORDER BY p.post_timestamp DESC;");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   382
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   383
    $db->_die('Nuggie main blog page selecting the whole shebang');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   384
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   385
  if ( $count < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   386
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   387
    // Either the user hasn't created a blog yet, or he isn't even registered
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   388
    return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   389
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   390
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   391
  $template->tpl_strings['PAGE_NAME'] = htmlspecialchars($blog_name) . ' &raquo; ' . htmlspecialchars($blog_subtitle);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   392
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   393
  $postbit = new NuggiePostbit();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   394
  // $q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = ''
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   395
  $html = paginate(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   396
      $q,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   397
      '{post_id}',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   398
      $count,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   399
      makeUrlNS('Blog', $username, "start=%s", true),
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   400
      0,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   401
      10,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   402
      array( 'post_id' => array($postbit, 'paginate_handler') ),
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   403
      '<span class="menuclear"></span>'
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   404
    );
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   405
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   406
  $template->header();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   407
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   408
  echo $html;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   409
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   410
  $template->footer();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   411
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   412
  return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   413
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   414
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   415
?>