plugins/Nuggie.php
author Dan
Sat, 15 Mar 2008 15:21:47 -0400
changeset 5 172544257e2c
parent 3 a050ff3d4509
child 7 cd46e29ae699
permissions -rw-r--r--
Merging changes from Nighthawk - visual tweak to post manager
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
    {
3
a050ff3d4509 Added the post manager. It uses AJAX. And it's pretty. At least a little. And it rips Wordpress.
Dan
parents: 2
diff changeset
    43
      $template->add_header("<link rel=\"stylesheet\" type=\"text/css\" href=\"' . scriptPath . '/plugins/nuggie/client/usercp.css\" />");
0
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    44
      require( ENANO_ROOT . "/plugins/nuggie/usercp.php" );
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    45
    }
2
4e7762863437 Added search module
Dan
parents: 0
diff changeset
    46
    else if ( $page_id == "Search" && $namespace == "Special" )
4e7762863437 Added search module
Dan
parents: 0
diff changeset
    47
    {
4e7762863437 Added search module
Dan
parents: 0
diff changeset
    48
      require( ENANO_ROOT . "/plugins/nuggie/search.php" );
4e7762863437 Added search module
Dan
parents: 0
diff changeset
    49
    }
0
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
$plugins->attachHook('acl_rule_init', 'nuggie_namespace_setup();');
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
function nuggie_namespace_setup()
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    55
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    56
  global $db, $session, $paths, $template, $plugins; // Common objects
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
  // Insert additional namespaces
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
  $paths->create_namespace('Blog', 'Blog:');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    61
  $paths->create_namespace('Planet', 'Planet:');
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    62
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    63
  // Create custom permissions for Nuggie
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
  $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
    66
  $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
    67
  $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
    68
  $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
    69
  $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
    70
  $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
    71
  $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
    72
  $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
    73
  $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
    74
  $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
    75
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    76
  // Extend the core permission set
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
  $session->acl_extend_scope('read', 'Blog|Planet', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    79
  $session->acl_extend_scope('edit_comments', 'Blog', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    80
  $session->acl_extend_scope('post_comments', 'Blog', $paths);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    81
  $session->acl_extend_scope('mod_comments', 'Blog', $paths);
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
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    84
$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
    85
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    86
function nuggie_set_page_string()
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    87
{
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    88
  global $db, $session, $paths, $template, $plugins; // Common objects
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    89
  
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    90
  if ( $paths->namespace == 'Blog' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    91
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    92
    $paths->cpage['comments_on'] = 0;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    93
    $template->namespace_string = 'blog';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    94
    if ( strstr($paths->cpage['urlname_nons'], '/') )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    95
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    96
      $paths->cpage['comments_on'] = 1;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
    97
      $template->namespace_string = 'blog 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
  else if ( $paths->namespace == 'Planet' )
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
    $paths->cpage['comments_on'] = 0;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   103
    $template->namespace_string = 'planet';
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   104
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   105
}
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   106
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   107
$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
   108
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   109
function nuggie_handle_namespace($processor)
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
  global $db, $session, $paths, $template, $plugins; // Common objects
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
  if ( $processor->namespace == 'Blog' )
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
    require( ENANO_ROOT . '/plugins/nuggie/postbit.php' );
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   116
    $result = nuggie_blog_uri_handler($processor->page_id);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   117
    if ( $result === '_err_access_denied' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   118
    {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   119
      $processor->err_access_denied();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   120
      return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   121
    }
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
  else if ( $processor->namespace == 'Planet' )
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   124
  {
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   125
    $result = nuggie_planet_uri_handler($processor->page_id);
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   126
    if ( $result === '_err_access_denied' )
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
      $processor->err_access_denied();
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   129
      return true;
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   130
    }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   131
  }
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   132
}
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
 * Sanitizes a string for a Nuggie permalink.
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   136
 * @param string String to sanitize
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   137
 * @return string
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   138
 */
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   139
a09fb41e48d5 First commit! Woohoo! Basic status of things is in extended description.
Dan
parents:
diff changeset
   140
function nuggie_sanitize_title($title)
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
  // 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
   143
  return sanitize_page_id($title);
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
?>