plugins/nuggie/postbit.php
author Dan
Mon, 16 Jun 2008 12:54:24 -0400
changeset 7 cd46e29ae699
parent 6 c51809bdf6af
child 8 160f1170aa32
permissions -rw-r--r--
Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
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
    
4
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
    97
    if ( empty($template->theme) )
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
    98
      $template->load_theme();
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
    99
    
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
   100
    if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/blog_post.tpl" ) )
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   101
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   102
      $parser = $template->makeParser('blog_post.tpl');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   103
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   104
    else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   105
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   106
      $tpl_code = <<<TPLBLOCK
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   107
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   108
      <!-- Start of blog post -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   109
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   110
      <div class="blog-post">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   111
        <div class="blog-post-header">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   112
          <div class="blog-post-datemark">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   113
            {DATE_D} {DATE_j}<br />
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   114
            {DATE_M} {DATE_Y}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   115
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   116
          <h3><a href="{PERMALINK}">{POST_TITLE}</a></h3>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   117
          <div class="blog-post-author">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   118
            Posted by {USER_LINK} on {TIMESTAMP}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   119
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   120
          <div class="blog-post-buttons">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   121
          <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
   122
          <!-- BEGIN auth_edit -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   123
          &bull;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   124
          <a href="{EDIT_LINK}">Edit this post</a>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   125
          <!-- END auth_edit -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   126
          </div>
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 class="blog-post-body">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   129
          {POST_TEXT}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   130
        </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   131
      </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   132
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   133
      <!-- Finish blog post -->
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
TPLBLOCK;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   136
      $parser = $template->makeParserText($tpl_code);
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
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   139
    $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
   140
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   141
    // List of valid characters for date()
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   142
    $date_chars = 'dDjlNSwzWFmMntLoYyaABgGhHiseIOTZcrU';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   143
    $date_chars = enano_str_split($date_chars);
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 = array();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   146
    foreach ( $date_chars as $char )
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["DATE_$char"] = date($char, $this->post_timestamp);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   149
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   150
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   151
    $strings['POST_TITLE'] = htmlspecialchars($this->post_title);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   152
    $strings['POST_TEXT'] = RenderMan::render($this->post_text);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   153
    $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
   154
    $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
   155
    
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   156
    // if we're on an enano with user rank support, cool. if not, just don't link
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   157
    if ( method_exists($session, 'get_user_rank') )
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   158
    {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   159
      $rank_data = $session->get_user_rank($this->post_author);
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   160
      $strings['USER_LINK'] = '<a href="' . makeUrlNS('User', $this->post_author, false, true) . '" style="' . $rank_data['rank_style'] . '" title="' . htmlspecialchars($rank_data['rank_title']) . '">' . htmlspecialchars($this->post_author) . '</a>';
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   161
    }
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   162
    else
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   163
    {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   164
      $strings['USER_LINK'] = '<a href="' . makeUrlNS('User', $this->post_author, false, true) . '" style="' . $rank_data['rank_style'] . '">' . htmlspecialchars($this->post_author) . '</a>';
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   165
    }
1
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   166
    
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   167
    if ( $this->num_comments == 0 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   168
      $comment_string = 'No comments';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   169
    else if ( $this->num_comments == 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   170
      $comment_string = '1 comment';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   171
    else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   172
      $comment_string = intval($this->num_comments) . ' comments';
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
    $strings['COMMENT_STRING'] = $comment_string;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   175
    $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
   176
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   177
    $parser->assign_vars($strings);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   178
    $parser->assign_bool(array(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   179
        'auth_edit' => ( $this->auth_edit )
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
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   182
    return $parser->run();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   183
  }
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
   * 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
   186
   * @access private
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   187
   */
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
  function paginate_handler($_, $row)
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   190
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   191
    global $db, $session, $paths, $template, $plugins; // Common objects
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
    if ( !is_object($this->blog_perms) )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   194
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   195
      $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
   196
    }
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
    $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
   199
    $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
   200
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   201
    /*
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   202
    if ( !$perms->get_permissions('read') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   203
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   204
      return "POST {$this->post_id} DENIED";
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   205
    }
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
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   208
    $this->post_id = intval($row['post_id']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   209
    $this->post_title = $row['post_title'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   210
    $this->post_text = $row['post_text'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   211
    $this->post_author = $row['username'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   212
    $this->post_timestamp = intval($row['post_timestamp']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   213
    $this->num_comments = intval($row['num_comments']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   214
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   215
    return $this->render_post();
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
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   219
function nuggie_blog_uri_handler($page)
0
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
  global $db, $session, $paths, $template, $plugins; // Common objects
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   222
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   223
  $uri = $page->page_id;
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   224
  
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   225
  $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
   226
  if ( strstr($uri, '/') )
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
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   229
    // Permalinked post
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
    // Split and parse URI
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   233
    $particles = explode('/', $uri);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   234
    if ( count($particles) < 5 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   235
      return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   236
    $sz = count($particles);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   237
    for ( $i = 5; $i < $sz; $i++ )
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
      $particles[4] .= '/' . $particles[$i];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   240
      unset($particles[$i]);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   241
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   242
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   243
    $particles[4] = nuggie_sanitize_title($particles[4]);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   244
    $poster =& $particles[0];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   245
    $year =& $particles[1];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   246
    $month =& $particles[2];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   247
    $day =& $particles[3];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   248
    $post_title_clean =& $particles[4];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   249
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   250
    $particlecomp = $db->escape(implode('/', $particles));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   251
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   252
    $year = intval($year);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   253
    $month = intval($month);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   254
    $day = intval($day);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   255
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   256
    $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
   257
    $time_max = $time_min + 86400;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   258
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   259
    $ptc = $db->escape($post_title_clean);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   260
    $uname = $db->escape(dirtify_page_id($poster));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   261
    
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   262
    $q = $db->sql_query("SELECT p.post_id\n"
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   263
                      . "      FROM " . table_prefix . "blog_posts AS p\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   264
                      . "  LEFT JOIN " . table_prefix . "users AS u\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   265
                      . "    ON ( u.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   266
                      . "  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
   267
                      . "    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
   268
                      . "  GROUP BY p.post_id;");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   269
    if ( !$q )
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   270
      $db->_die('Nuggie post handler doing name- and date-based lookup');
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   271
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   272
    if ( $db->numrows() < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   273
      return false;
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
    if ( $db->numrows() > 1 )
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
      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
   278
                                               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
   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
    $row = $db->fetchrow();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   282
    
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   283
    $realpost = new PageProcessor($row['post_id'], 'BlogPost');
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   284
    
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   285
    // huge hack
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   286
    // the goal here is to fool the page metadata system into thinking that comments are enabled.
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   287
    $paths->cpage['comments_on'] = 1;
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   288
    if ( !isset($paths->pages[$paths->nslist['BlogPost'] . $row['post_id']]) )
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   289
    {
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   290
      $paths->pages[$paths->nslist['BlogPost'] . $row['post_id']] = array(
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   291
          'urlname' => $paths->nslist['BlogPost'] . $row['post_id'],
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   292
          'urlname_nons' => $row['post_id'],
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   293
          'name' => 'determined at runtime',
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   294
          'comments_on' => 1,
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   295
          'special' => 0,
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   296
          'wiki_mode' => 0,
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   297
          'protected' => 1,
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   298
          'delvotes' => 0
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   299
        );
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   300
    }
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   301
    $realpost->page_exists = true;
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   302
    // end huge hack
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   303
      
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   304
    $template->init_vars($realpost);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   305
    $realpost->send();
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   306
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   307
    return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   308
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   309
  else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   310
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   311
    return nuggie_blog_index($uri);
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
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   314
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   315
function nuggie_blogpost_uri_handler($page)
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   316
{
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   317
  global $db, $session, $paths, $template, $plugins; // Common objects
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   318
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   319
  if ( !preg_match('/^[0-9]+$/', $page->page_id) )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   320
  {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   321
    return $page->err_page_not_existent();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   322
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   323
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   324
  // using page_id is SAFE. It's checked with a regex above.
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   325
  $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"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   326
                    . "       b.blog_subtitle, b.blog_type, b.allowed_users, u.username, u.user_level, COUNT(c.comment_id) AS num_comments\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   327
                    . "      FROM " . table_prefix . "blog_posts AS p\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   328
                    . "  LEFT JOIN " . table_prefix . "blogs AS b\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   329
                    . "    ON ( b.user_id = p.post_author )\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   330
                    . "  LEFT JOIN " . table_prefix . "users AS u\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   331
                    . "    ON ( u.user_id = p.post_author )\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   332
                    . "  LEFT JOIN " . table_prefix . "comments AS c\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   333
                    . "    ON ( ( c.page_id = '{$page->page_id}' AND c.namespace = 'BlogPost' ) OR ( c.page_id IS NULL AND c.namespace IS NULL ) )\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   334
                    . "  WHERE p.post_id = {$page->page_id}\n"
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   335
                    . "  GROUP BY p.post_id;");
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   336
  if ( !$q )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   337
    $db->_die('Nuggie post handler selecting main post data');
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   338
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   339
  if ( $db->numrows() < 1 )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   340
    return false;
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   341
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   342
  $row = $db->fetchrow();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   343
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   344
  //
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   345
  // Determine permissions
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   346
  //
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   347
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   348
  // The way we're doing this is first fetching permissions for the blog, and then merging them
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   349
  // with permissions specific to the post. This way the admin can set custom permissions for the
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   350
  // entire blog, and they'll be inherited unless individual posts have overriding permissions.
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   351
  $perms_blog = $session->fetch_page_acl($row['username'], 'Blog');
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   352
  $perms = $session->fetch_page_acl("{$row['post_timestamp']}_{$row['post_id']}", 'Blog');
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   353
  $perms->perms = $session->acl_merge($perms->perms, $perms_blog->perms);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   354
  unset($perms_blog);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   355
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   356
  if ( $row['blog_type'] == 'private' )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   357
  {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   358
    $allowed_users = unserialize($row['allowed_users']);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   359
    if ( !in_array($session->username, $allowed_users) && !$perms->get_permissions('nuggie_see_non_public') && $row['username'] != $session->username )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   360
    {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   361
      return $page->err_access_denied();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   362
    }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   363
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   364
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   365
  $acl_type = ( $row['post_author'] == $session->user_id ) ? 'nuggie_edit_own' : 'nuggie_edit_other';
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   366
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   367
  if ( !$perms->get_permissions('read') )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   368
    return $page->err_access_denied();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   369
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   370
  // enable comments
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   371
  $paths->cpage['comments_on'] = 1;
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   372
  // disable editing
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   373
  $session->acl_merge_with_current(array(
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   374
      'edit_page' => AUTH_DENY
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   375
    ));
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   376
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   377
  // We're validated - display post
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   378
  $postbit = new NuggiePostbit();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   379
  $postbit->post_id = intval($row['post_id']);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   380
  $postbit->post_title = $row['post_title'];
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   381
  $postbit->post_text = $row['post_text'];
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   382
  $postbit->post_author = $row['username'];
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   383
  $postbit->post_timestamp = intval($row['post_timestamp']);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   384
  $postbit->auth_edit = $perms->get_permissions($acl_type);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   385
  $postbit->num_comments = intval($row['num_comments']);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   386
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   387
  $page_name = htmlspecialchars($row['post_title']) . ' &laquo; ' . htmlspecialchars($row['blog_name']);
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   388
  if ( method_exists($template, 'assign_vars') )
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   389
  {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   390
    $template->assign_vars(array(
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   391
        'PAGE_NAME' => $page_name
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   392
      ));
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   393
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   394
  else
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   395
  {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   396
    $template->tpl_strings['PAGE_NAME'] = $page_name;
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   397
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   398
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   399
  $template->header();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   400
  echo '&lt; <a href="' . makeUrlNS('Blog', $row['username']) . '">' . htmlspecialchars($row['blog_name']) . '</a>';
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   401
  echo $postbit->render_post();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   402
  display_page_footers();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   403
  $template->footer();
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   404
}
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   405
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   406
function nuggie_blog_index($username)
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
  global $db, $session, $paths, $template, $plugins; // Common objects
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
  $username_esc = $db->escape($username);
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
  // 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
   413
  $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
   414
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   415
    $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
   416
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   417
  if ( $db->numrows() < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   418
    return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   419
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   420
  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
   421
  $db->free_result();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   422
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   423
  $perms = $session->fetch_page_acl($username, 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   424
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   425
  if ( $blog_type == 'private' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   426
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   427
    $allowed_users = unserialize($allowed_users);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   428
    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
   429
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   430
      return '_err_access_denied';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   431
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   432
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   433
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   434
  // Determine number of posts and prefetch ACL info
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   435
  $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
   436
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   437
    $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
   438
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   439
  $count = $db->numrows();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   440
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   441
  while ( $row = $db->fetchrow($q) )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   442
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   443
    $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
   444
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   445
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   446
  $db->free_result($q);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   447
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   448
  $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
   449
                    . "       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
   450
                    . "      FROM " . table_prefix . "blog_posts AS p\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   451
                    . "  LEFT JOIN " . table_prefix . "blogs AS b\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   452
                    . "    ON ( b.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   453
                    . "  LEFT JOIN " . table_prefix . "users AS u\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   454
                    . "    ON ( u.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   455
                    . "  LEFT JOIN " . table_prefix . "comments AS c\n"
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   456
                    . "    ON ( ( c.page_id = CAST(p.post_id AS char) AND c.namespace = 'BlogPost' ) OR ( c.page_id IS NULL AND c.namespace IS NULL ) )\n"
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   457
                    . "  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
   458
                    . "  GROUP BY p.post_id\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   459
                    . "  ORDER BY p.post_timestamp DESC;");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   460
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   461
    $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
   462
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   463
  if ( $count < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   464
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   465
    // 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
   466
    return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   467
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   468
  
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   469
  $page_name = htmlspecialchars($blog_name) . ' &raquo; ' . htmlspecialchars($blog_subtitle);
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   470
  if ( method_exists($template, 'assign_vars') )
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   471
  {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   472
    $template->assign_vars(array(
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   473
        'PAGE_NAME' => $page_name
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   474
      ));
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   475
  }
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   476
  else
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   477
  {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   478
    $template->tpl_strings['PAGE_NAME'] = $page_name;
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   479
  }
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   480
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   481
  $postbit = new NuggiePostbit();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   482
  // $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
   483
  $html = paginate(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   484
      $q,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   485
      '{post_id}',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   486
      $count,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   487
      makeUrlNS('Blog', $username, "start=%s", true),
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   488
      0,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   489
      10,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   490
      array( 'post_id' => array($postbit, 'paginate_handler') ),
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   491
      '<span class="menuclear"></span>'
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   492
    );
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   493
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   494
  $template->header();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   495
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   496
  echo $html;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   497
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   498
  $template->footer();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   499
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   500
  return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   501
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   502
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   503
?>