plugins/Nuggie.php
author Dan
Tue, 11 Dec 2007 02:03:54 -0500
changeset 0 a09fb41e48d5
child 2 4e7762863437
permissions -rw-r--r--
First commit! Woohoo! Basic status of things is in extended description. * You can write blog posts and view them in a standard blog-like index page * All blogs are per-user and blogs can be made public or private * Setting permissions on a per-blog/per-post basis should work except for some inheritance issues * Planets are not in any way implemented * Tagging posts does not work * Basically the only thing you can do is write and display posts and make comments. It's basic, but it works. More to come very soon!
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
Plugin Name: Nuggie
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     4
Plugin URI: http://enanocms.org/Nuggie
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     5
Description: Nuggie provides a complete blogging suite for Enano-based websites. Named after Scottish water sprites.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     6
Author: Dan Fuhry
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     7
Version: 0.1
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     8
Author URI: http://enanocms.org/
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
     9
*/
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
/*
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    12
 * Nuggie
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    13
 * Version 0.1
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    14
 * Copyright (C) 2007 Dan Fuhry
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
 * 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
    17
 * 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
    18
 *
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    19
 * 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
    20
 * 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
    21
 */
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
global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    24
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    25
if ( getConfig('nuggie_installed') != '1' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    26
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    27
  $plugins->attachHook('base_classes_initted', '
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    28
      $paths->add_page(Array(
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    29
        \'name\'=>\'Install Nuggie\',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    30
        \'urlname\'=>\'NuggieInstall\',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    31
        \'namespace\'=>\'Special\',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    32
        \'special\'=>0,\'visible\'=>0,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    33
        ));
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    34
    ');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    35
  require( ENANO_ROOT . '/plugins/nuggie/install.php' );
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
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    38
$plugins->attachHook('base_classes_initted', '
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    39
    list($page_id, $namespace) = RenderMan::strToPageId($paths->get_pageid_from_url());
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    40
    
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    41
    if ( $page_id == "Preferences" && $namespace == "Special" )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    42
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    43
      require( ENANO_ROOT . "/plugins/nuggie/usercp.php" );
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
  ');
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
$plugins->attachHook('acl_rule_init', 'nuggie_namespace_setup();');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    48
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    49
function nuggie_namespace_setup()
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
  global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    52
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    53
  // Insert additional namespaces
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
  $paths->create_namespace('Blog', 'Blog:');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    56
  $paths->create_namespace('Planet', 'Planet:');
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
  // Create custom permissions for Nuggie
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    59
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    60
  $session->register_acl_type('nuggie_post', AUTH_DISALLOW, 'Post blog entries or create blog', Array(), 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    61
  $session->register_acl_type('nuggie_edit_own', AUTH_DISALLOW, 'Edit own blog posts', Array(), 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    62
  $session->register_acl_type('nuggie_edit_other', AUTH_DISALLOW, 'Edit others\' blog posts', Array(), 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    63
  $session->register_acl_type('nuggie_create_planet', AUTH_DISALLOW, 'Create new planets', Array(), 'Planet');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    64
  $session->register_acl_type('nuggie_publicize_planet', AUTH_DISALLOW, 'Make own planets searchable', Array('nuggie_create_planet'), 'Planet');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    65
  $session->register_acl_type('nuggie_protect_planet', AUTH_DISALLOW, 'Protect planets from public modification', Array(), 'Planet');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    66
  $session->register_acl_type('nuggie_edit_planet_own', AUTH_DISALLOW, 'Edit own planets', Array(), 'Planet');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    67
  $session->register_acl_type('nuggie_edit_planet_other', AUTH_DISALLOW, 'Edit others\' planets', Array(), 'Planet');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    68
  $session->register_acl_type('nuggie_even_when_protected', AUTH_DISALLOW, 'Override protection on editing planets', Array(), 'Planet');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    69
  $session->register_acl_type('nuggie_see_non_public', AUTH_DISALLOW, 'See non-public blogs', Array(), 'Blog');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    70
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    71
  // Extend the core permission set
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
  $session->acl_extend_scope('read', 'Blog|Planet', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    74
  $session->acl_extend_scope('edit_comments', 'Blog', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    75
  $session->acl_extend_scope('post_comments', 'Blog', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    76
  $session->acl_extend_scope('mod_comments', 'Blog', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    77
}
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
$plugins->attachHook('page_type_string_set', 'nuggie_set_page_string();');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    80
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    81
function nuggie_set_page_string()
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
  global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    84
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    85
  if ( $paths->namespace == 'Blog' )
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
    $paths->cpage['comments_on'] = 0;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    88
    $template->namespace_string = 'blog';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    89
    if ( strstr($paths->cpage['urlname_nons'], '/') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    90
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    91
      $paths->cpage['comments_on'] = 1;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    92
      $template->namespace_string = 'blog post';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    93
    }
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
  else if ( $paths->namespace == 'Planet' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    96
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    97
    $paths->cpage['comments_on'] = 0;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    98
    $template->namespace_string = 'planet';
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
}
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
$plugins->attachHook('page_not_found', 'nuggie_handle_namespace($this);');
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
function nuggie_handle_namespace($processor)
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
  global $db, $session, $paths, $template, $plugins; // Common objects
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
  if ( $processor->namespace == 'Blog' )
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
    require( ENANO_ROOT . '/plugins/nuggie/postbit.php' );
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   111
    $result = nuggie_blog_uri_handler($processor->page_id);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   112
    if ( $result === '_err_access_denied' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   113
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   114
      $processor->err_access_denied();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   115
      return true;
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
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   118
  else if ( $processor->namespace == 'Planet' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   119
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   120
    $result = nuggie_planet_uri_handler($processor->page_id);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   121
    if ( $result === '_err_access_denied' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   122
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   123
      $processor->err_access_denied();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   124
      return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   125
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   126
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   127
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   128
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   129
/**
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   130
 * Sanitizes a string for a Nuggie permalink.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   131
 * @param string String to sanitize
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   132
 * @return string
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   133
 */
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
function nuggie_sanitize_title($title)
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   136
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   137
  // Placeholder for now - this may become more elaborate in the future, we'll see
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   138
  return sanitize_page_id($title);
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
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   141
?>