plugins/nuggie/postbit.php
author Dan
Tue, 29 Jul 2008 06:48:19 -0600
changeset 13 421242ebbece
parent 8 160f1170aa32
child 14 58840db7b472
permissions -rw-r--r--
Added backend RSS2 support, as long as Feed Me is there somewhere
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
  /**
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    90
   * The name of the planet referred, if any. Defaults to false.
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    91
   * @var string
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    92
   */
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    93
  
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    94
  var $referring_planet = false;
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    95
  
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
    96
  /**
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    97
   * Renders the post.
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
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   100
  function render_post()
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
    global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   103
    
4
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
   104
    if ( empty($template->theme) )
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
   105
      $template->load_theme();
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
   106
    
f50742368f90 Fixed a few bugs.
Dan
parents: 2
diff changeset
   107
    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
   108
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   109
      $parser = $template->makeParser('blog_post.tpl');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   110
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   111
    else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   112
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   113
      $tpl_code = <<<TPLBLOCK
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   114
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   115
      <!-- Start of blog post -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   116
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   117
      <div class="blog-post">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   118
        <div class="blog-post-header">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   119
          <div class="blog-post-datemark">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   120
            {DATE_D} {DATE_j}<br />
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   121
            {DATE_M} {DATE_Y}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   122
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   123
          <h3><a href="{PERMALINK}">{POST_TITLE}</a></h3>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   124
          <div class="blog-post-author">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   125
            Posted by {USER_LINK} on {TIMESTAMP}
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 class="blog-post-buttons">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   128
          <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
   129
          <!-- BEGIN auth_edit -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   130
          &bull;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   131
          <a href="{EDIT_LINK}">Edit this post</a>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   132
          <!-- END auth_edit -->
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   133
          </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   134
        </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   135
        <div class="blog-post-body">
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   136
          {POST_TEXT}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   137
        </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   138
      </div>
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   139
      
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   140
      <!-- Finish blog post -->
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
TPLBLOCK;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   143
      $parser = $template->makeParserText($tpl_code);
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
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   146
    $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
   147
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   148
    // List of valid characters for date()
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   149
    $date_chars = 'dDjlNSwzWFmMntLoYyaABgGhHiseIOTZcrU';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   150
    $date_chars = enano_str_split($date_chars);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   151
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   152
    $strings = array();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   153
    foreach ( $date_chars as $char )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   154
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   155
      $strings["DATE_$char"] = date($char, $this->post_timestamp);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   156
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   157
    
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   158
    $permalink_params = '';
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   159
    if ( $this->referring_planet )
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   160
    {
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   161
      $permalink_params = "planet=" . sanitize_page_id($this->referring_planet);
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   162
    }
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   163
    
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   164
    $strings['POST_TITLE'] = htmlspecialchars($this->post_title);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   165
    $strings['POST_TEXT'] = RenderMan::render($this->post_text);
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   166
    $strings['PERMALINK'] = makeUrlNS('Blog', $this->post_author . date('/Y/n/j/', $this->post_timestamp) . $this->post_title_clean, $permalink_params, true);
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   167
    $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
   168
    
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   169
    // 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
   170
    if ( method_exists($session, 'get_user_rank') )
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   171
    {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   172
      $rank_data = $session->get_user_rank($this->post_author);
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   173
      $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
   174
    }
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   175
    else
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   176
    {
13
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   177
      $strings['USER_LINK'] = '<a href="' . makeUrlNS('User', $this->post_author, false, true) . '">' . htmlspecialchars($this->post_author) . '</a>';
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   178
    }
1
6e76ca311f2d Put a placeholder into that user link part so I don't forget to fix it ;-)
Dan
parents: 0
diff changeset
   179
    
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   180
    if ( $this->num_comments == 0 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   181
      $comment_string = 'No comments';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   182
    else if ( $this->num_comments == 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   183
      $comment_string = '1 comment';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   184
    else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   185
      $comment_string = intval($this->num_comments) . ' comments';
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
    $strings['COMMENT_STRING'] = $comment_string;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   188
    $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
   189
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   190
    $parser->assign_vars($strings);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   191
    $parser->assign_bool(array(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   192
        'auth_edit' => ( $this->auth_edit )
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
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   195
    return $parser->run();
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
   * 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
   199
   * @access private
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
  function paginate_handler($_, $row)
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
    global $db, $session, $paths, $template, $plugins; // Common objects
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
    if ( !is_object($this->blog_perms) )
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->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
   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
    $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
   212
    $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
   213
    
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   214
    // if the row has information about the blog's access configuration, process it here.
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   215
    // this is only done from within planets...
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   216
    if ( isset($row['blog_type']) && isset($row['allowed_users']) )
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   217
    {
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   218
      if ( $row['blog_type'] == 'private' )
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   219
      {
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   220
        $users = unserialize($row['allowed_users']);
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   221
        if ( !in_array($session->user_id, $users) && !$perms->get_permissions('nuggie_see_non_public') && $row['post_author'] !== $session->user_id )
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   222
        {
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   223
          return ' ';
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   224
        }
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   225
      }
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   226
    }
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   227
    
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   228
    if ( !$perms->get_permissions('read') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   229
    {
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   230
      return ' ';
0
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
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   233
    $this->post_id = intval($row['post_id']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   234
    $this->post_title = $row['post_title'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   235
    $this->post_text = $row['post_text'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   236
    $this->post_author = $row['username'];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   237
    $this->post_timestamp = intval($row['post_timestamp']);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   238
    $this->num_comments = intval($row['num_comments']);
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   239
    $this->referring_planet = ( isset($row['referring_planet']) ) ? $row['referring_planet'] : false;
0
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
    return $this->render_post();
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
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   244
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   245
function nuggie_blog_uri_handler($page)
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   246
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   247
  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
   248
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   249
  $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
   250
  
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   251
  $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
   252
  if ( strstr($uri, '/') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   253
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   254
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   255
    // Permalinked post
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   256
    //
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   257
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   258
    // Split and parse URI
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   259
    $particles = explode('/', $uri);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   260
    if ( count($particles) < 5 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   261
      return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   262
    $sz = count($particles);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   263
    for ( $i = 5; $i < $sz; $i++ )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   264
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   265
      $particles[4] .= '/' . $particles[$i];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   266
      unset($particles[$i]);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   267
    }
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
    $particles[4] = nuggie_sanitize_title($particles[4]);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   270
    $poster =& $particles[0];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   271
    $year =& $particles[1];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   272
    $month =& $particles[2];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   273
    $day =& $particles[3];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   274
    $post_title_clean =& $particles[4];
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   275
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   276
    $particlecomp = $db->escape(implode('/', $particles));
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
    $year = intval($year);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   279
    $month = intval($month);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   280
    $day = intval($day);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   281
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   282
    $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
   283
    $time_max = $time_min + 86400;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   284
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   285
    $ptc = $db->escape($post_title_clean);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   286
    $uname = $db->escape(dirtify_page_id($poster));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   287
    
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   288
    $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
   289
                      . "      FROM " . table_prefix . "blog_posts AS p\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   290
                      . "  LEFT JOIN " . table_prefix . "users AS u\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   291
                      . "    ON ( u.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   292
                      . "  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
   293
                      . "    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
   294
                      . "  GROUP BY p.post_id;");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   295
    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
   296
      $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
   297
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   298
    if ( $db->numrows() < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   299
      return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   300
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   301
    if ( $db->numrows() > 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   302
    {
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   303
      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
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   304
                                               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
   305
    }
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
    $row = $db->fetchrow();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   308
    
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   309
    $realpost = new PageProcessor($row['post_id'], 'BlogPost');
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   310
    $realpost->send_headers = true;
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   311
    
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   312
    // 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
   313
    // 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
   314
    $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
   315
    if ( !isset($paths->pages[$paths->nslist['BlogPost'] . $row['post_id']]) )
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   316
    {
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   317
      $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
   318
          '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
   319
          '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
   320
          '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
   321
          '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
   322
          '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
   323
          '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
   324
          '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
   325
          '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
   326
        );
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   327
    }
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   328
    $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
   329
    // 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
   330
      
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   331
    $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
   332
    $realpost->send();
0
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
    return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   335
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   336
  else
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   337
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   338
    return nuggie_blog_index($uri);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   339
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   340
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   341
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   342
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
   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
  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
   345
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   346
  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
   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
    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
   349
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   350
  
13
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   351
  $template->add_header('<link rel="stylesheet" type="text/css" href="' . scriptPath . '/plugins/nuggie/style.css" />');
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   352
  
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   353
  // 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
   354
  $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
   355
                    . "       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
   356
                    . "      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
   357
                    . "  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
   358
                    . "    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
   359
                    . "  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
   360
                    . "    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
   361
                    . "  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
   362
                    . "    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
   363
                    . "  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
   364
                    . "  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
   365
  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
   366
    $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
   367
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   368
  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
   369
    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
   370
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   371
  $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
   372
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   373
  //
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   374
  // 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
   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
  // 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
   378
  // 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
   379
  // 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
   380
  $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
   381
  $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
   382
  $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
   383
  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
   384
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   385
  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
   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
    $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
   388
    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
   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
      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
   391
    }
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
  $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
   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
  if ( !$perms->get_permissions('read') )
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   397
  {
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   398
    return $page->err_access_denied();
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   399
  }
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   400
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   401
  // 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
   402
  $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
   403
  // 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
   404
  $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
   405
      '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
   406
    ));
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   407
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   408
  // 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
   409
  $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
   410
  $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
   411
  $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
   412
  $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
   413
  $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
   414
  $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
   415
  $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
   416
  $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
   417
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   418
  $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
   419
  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
   420
  {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   421
    $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
   422
        '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
   423
      ));
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   424
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   425
  else
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   426
  {
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   427
    $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
   428
  }
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   429
  
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   430
  $template->header();
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   431
  if ( isset($_GET['planet']) )
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   432
  {
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   433
    echo '&lt; <a href="' . makeUrlNS('Planet', $_GET['planet']) . '">' . htmlspecialchars($_GET['planet']) . '</a>';
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   434
  }
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   435
  else
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   436
  {
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   437
    echo '&lt; <a href="' . makeUrlNS('Blog', $row['username']) . '">' . htmlspecialchars($row['blog_name']) . '</a>';
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   438
  }
7
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   439
  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
   440
  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
   441
  $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
   442
}
cd46e29ae699 Started work on planet system. From this point onward, enano-1.1 rev 571 or later required.
Dan
parents: 6
diff changeset
   443
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   444
function nuggie_blog_index($username)
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
  global $db, $session, $paths, $template, $plugins; // Common objects
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
  $username_esc = $db->escape($username);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   449
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   450
  // 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
   451
  $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
   452
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   453
    $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
   454
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   455
  if ( $db->numrows() < 1 )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   456
    return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   457
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   458
  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
   459
  $db->free_result();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   460
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   461
  $perms = $session->fetch_page_acl($username, 'Blog');
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 ( $blog_type == 'private' )
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
    $allowed_users = unserialize($allowed_users);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   466
    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
   467
    {
8
160f1170aa32 First commit with working planet presentation code. No UI written for planet management yet.
Dan
parents: 7
diff changeset
   468
      return $page->err_access_denied();
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   469
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   470
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   471
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   472
  // Determine number of posts and prefetch ACL info
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   473
  $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
   474
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   475
    $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
   476
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   477
  $count = $db->numrows();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   478
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   479
  while ( $row = $db->fetchrow($q) )
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
    $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
   482
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   483
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   484
  $db->free_result($q);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   485
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   486
  $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
   487
                    . "       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
   488
                    . "      FROM " . table_prefix . "blog_posts AS p\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   489
                    . "  LEFT JOIN " . table_prefix . "blogs AS b\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   490
                    . "    ON ( b.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   491
                    . "  LEFT JOIN " . table_prefix . "users AS u\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   492
                    . "    ON ( u.user_id = p.post_author )\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   493
                    . "  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
   494
                    . "    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
   495
                    . "  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
   496
                    . "  GROUP BY p.post_id\n"
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   497
                    . "  ORDER BY p.post_timestamp DESC;");
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   498
  if ( !$q )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   499
    $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
   500
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   501
  if ( $count < 1 )
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
    // 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
   504
    return false;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   505
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   506
  
13
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   507
  // RSS check - do we have support for Feed Me and did the user request an RSS feed?
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   508
  $do_rss = defined('ENANO_FEEDBURNER_INCLUDED') && ( isset($_GET['feed']) && $_GET['feed'] === 'rss2' );
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   509
  
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   510
  // RSS feed?
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   511
  if ( $do_rss )
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   512
  {
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   513
    header('Content-type: text/xml; charset=utf-8');
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   514
    global $aggressive_optimize_html;
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   515
    $aggressive_optimize_html = false;
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   516
    $rss = new RSS(
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   517
      $blog_name,
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   518
      $blog_subtitle,
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   519
      makeUrlComplete('Blog', $username)
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   520
    );
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   521
    while ( $row = $db->fetchrow($q) )
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   522
    {
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   523
      $permalink = makeUrlNS('Blog', sanitize_page_id($row['username']) . date('/Y/n/j/', intval($row['post_timestamp'])) . $row['post_title_clean'], false, true);
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   524
      $post = RenderMan::render($row['post_text']);
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   525
      $rss->add_item($row['post_title'], $permalink, $post, intval($row['post_timestamp']));
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   526
    }
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   527
    echo $rss->render();
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   528
    return;
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   529
  }
421242ebbece Added backend RSS2 support, as long as Feed Me is there somewhere
Dan
parents: 8
diff changeset
   530
  
6
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   531
  $page_name = htmlspecialchars($blog_name) . ' &raquo; ' . htmlspecialchars($blog_subtitle);
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   532
  if ( method_exists($template, 'assign_vars') )
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   533
  {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   534
    $template->assign_vars(array(
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   535
        'PAGE_NAME' => $page_name
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   536
      ));
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   537
  }
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   538
  else
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   539
  {
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   540
    $template->tpl_strings['PAGE_NAME'] = $page_name;
c51809bdf6af Updated for compatibility with 1.1.4
Dan
parents: 4
diff changeset
   541
  }
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   542
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   543
  $postbit = new NuggiePostbit();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   544
  // $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
   545
  $html = paginate(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   546
      $q,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   547
      '{post_id}',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   548
      $count,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   549
      makeUrlNS('Blog', $username, "start=%s", true),
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   550
      0,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   551
      10,
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   552
      array( 'post_id' => array($postbit, 'paginate_handler') ),
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   553
      '<span class="menuclear"></span>'
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   554
    );
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   555
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   556
  $template->header();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   557
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   558
  echo $html;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   559
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   560
  $template->footer();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   561
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   562
  return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   563
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   564
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   565
?>