plugins/Newsboy.php
author Dan
Mon, 21 Jan 2008 11:52:07 -0500
changeset 4 bf5589120afb
parent 3 8ae9acb2e919
child 5 fed61fc8895b
permissions -rw-r--r--
Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     1
<?php
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     2
/*
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     3
Plugin Name: Newsboy
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     4
Plugin URI: javascript: // No URL yet, stay tuned!
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     5
Description: Newsboy adds a news management system to Enano. It can integrate with the Feed Me plugin to provide an additional RSS feed. 
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     6
Author: Dan Fuhry
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     7
Version: 0.1
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     8
Author URI: http://www.enanocms.org/
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
     9
*/
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    10
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    11
/*
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    12
 * Newsboy
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    13
 * Version 0.1
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    14
 * Copyright (C) 2007 Dan Fuhry
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    15
 *
9f29b32e5224 Initial repository population
dan@fuhry
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
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    17
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    18
 *
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    19
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    20
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    21
 */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    22
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    23
// Insert our News namespace
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    24
$plugins->attachHook('acl_rule_init', 'NewsBoy_namespace_setup($this);');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    25
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    26
// Hook into page rendering
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    27
$plugins->attachHook('page_not_found', 'NewsBoy_namespace_handler();');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    28
$plugins->attachHook('send_page_footers', 'NewsBoy_PortalLink();');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    29
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    30
// String to determine page type string
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    31
$plugins->attachHook('page_type_string_set', 'NewsBoy_set_page_string();');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    32
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    33
// Attach to the Feed Me plugin, if it's loaded (if not, the feed handler simply won't get called)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    34
$plugins->attachHook('feed_me_request', 'NewsBoy_feed_handler($mode);');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    35
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    36
function NewsBoy_namespace_setup(&$paths)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    37
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    38
  $paths->create_namespace('NewsBoy', 'News:');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    39
  $paths->addAdminNode('Newsboy portal', 'Configuration', 'NewsboyConfiguration');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    40
  $paths->addAdminNode('Newsboy portal', 'Manage news items', 'NewsboyItemManager');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    41
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    42
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    43
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    44
  $session->acl_extend_scope('read',                   'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    45
  $session->acl_extend_scope('post_comments',          'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    46
  $session->acl_extend_scope('edit_comments',          'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    47
  $session->acl_extend_scope('edit_page',              'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    48
  $session->acl_extend_scope('view_source',            'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    49
  $session->acl_extend_scope('mod_comments',           'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    50
  $session->acl_extend_scope('history_view',           'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    51
  $session->acl_extend_scope('history_rollback',       'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    52
  $session->acl_extend_scope('history_rollback_extra', 'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    53
  $session->acl_extend_scope('protect',                'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    54
  $session->acl_extend_scope('rename',                 'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    55
  $session->acl_extend_scope('clear_logs',             'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    56
  $session->acl_extend_scope('vote_delete',            'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    57
  $session->acl_extend_scope('vote_reset',             'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    58
  $session->acl_extend_scope('delete_page',            'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    59
  $session->acl_extend_scope('set_wiki_mode',          'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    60
  $session->acl_extend_scope('password_set',           'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    61
  $session->acl_extend_scope('password_reset',         'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    62
  $session->acl_extend_scope('mod_misc',               'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    63
  $session->acl_extend_scope('edit_cat',               'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    64
  $session->acl_extend_scope('even_when_protected',    'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    65
  $session->acl_extend_scope('upload_files',           'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    66
  $session->acl_extend_scope('upload_new_version',     'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    67
  $session->acl_extend_scope('create_page',            'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    68
  $session->acl_extend_scope('php_in_pages',           'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    69
  $session->acl_extend_scope('edit_acl',               'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    70
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    71
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    72
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    73
function NewsBoy_namespace_handler()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    74
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    75
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    76
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    77
  if ( defined('ENANO_FEEDBURNER_INCLUDED') )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    78
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    79
    $template->add_header('<link rel="alternate" title="'.getConfig('site_name').' News feed" href="'.makeUrlNS('Special', 'RSS/news', null, true).'" type="application/rss+xml" />');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    80
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    81
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    82
  if ( $paths->namespace != 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    83
    return;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    84
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    85
  $chk = $paths->page;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    86
  $chk1 = substr($chk, 0, ( strlen($paths->nslist['NewsBoy']) + 8 ));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    87
  $chk2 = substr($chk, 0, ( strlen($paths->nslist['NewsBoy']) + 7 ));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    88
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    89
  if ( $paths->cpage['urlname_nons'] == 'Portal' || $paths->cpage['urlname_nons'] == 'Archive' || $chk1 == $paths->nslist['NewsBoy'] . 'Archive/' || $chk2 == $paths->nslist['NewsBoy'] . 'Archive' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    90
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    91
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    92
    // Add admin opener Javascript function
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    93
    $template->add_header('<!-- NewsBoy: admin panel nav function -->
4
bf5589120afb Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents: 3
diff changeset
    94
    <enano:no-opt>
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    95
    <script type="text/javascript">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    96
      function newsboy_open_admin()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    97
      {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    98
        if ( auth_level < USER_LEVEL_ADMIN )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    99
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   100
          ajaxPromptAdminAuth(function(k) {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   101
            ENANO_SID = k;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   102
            auth_level = USER_LEVEL_ADMIN;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   103
            var loc = String(window.location + \'\');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   104
            window.location = append_sid(loc);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   105
            var loc = makeUrlNS(\'Special\', \'Administration\', \'module=\' + namespace_list[\'Admin\'] + \'NewsboyItemManager\');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   106
            if ( (ENANO_SID + \' \').length > 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   107
              window.location = loc;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   108
          }, 9);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   109
          return false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   110
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   111
        var loc = makeUrlNS(\'Special\', \'Administration\', \'module=\' + namespace_list[\'Admin\'] + \'NewsboyItemManager\');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   112
        window.location = loc;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   113
      }
4
bf5589120afb Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents: 3
diff changeset
   114
    </script>
bf5589120afb Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents: 3
diff changeset
   115
    </enano:no-opt>');
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   116
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   117
    $x = getConfig('nb_portal_title');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   118
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   119
    $template->tpl_strings['PAGE_NAME'] = ( $paths->cpage['urlname_nons'] == 'Portal' ) ?
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   120
          ( ( empty($x) ) ?
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   121
              'Welcome to ' . getConfig('site_name') :
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   122
              $x ) :
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   123
          'News Archive';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   124
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   125
    if ( !$session->get_permissions('read') )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   126
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   127
      die_friendly('Access denied', '<div class="error-box"><b>Access to this page is denied.</b><br />This may be because you are not logged in or you have not met certain criteria for viewing this page.</div>');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   128
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   129
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   130
    $paths->cpage['comments_on'] = 0;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   131
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   132
    $template->header();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   133
    ( $paths->cpage['urlname_nons'] == 'Portal' ) ? NewsBoy_portal() : NewsBoy_archive();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   134
    $template->footer();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   135
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   136
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   137
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   138
function NewsBoy_set_page_string()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   139
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   140
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   141
  if ( $paths->namespace == 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   142
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   143
    if ( $paths->cpage['urlname_nons'] == 'Portal' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   144
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   145
      $template->namespace_string = 'portal';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   146
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   147
      // block editing
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   148
      $perm_arr = Array('edit_page' => AUTH_DENY, 'view_source' => AUTH_DENY);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   149
      $session->acl_merge_with_current($perm_arr, false, 2);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   150
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   151
    else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   152
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   153
      $template->namespace_string = 'news item';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   154
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   155
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   156
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   157
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   158
function NewsBoy_format_title($title)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   159
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   160
  $title = strtolower($title);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   161
  $title = preg_replace('/\W/', '-', $title);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   162
  $title = preg_replace('/([-]+)/', '-', $title);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   163
  $title = trim($title, '-');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   164
  return $title;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   165
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   166
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   167
function NewsBoy_feed_handler($mode)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   168
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   169
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   170
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   171
  if ( $mode != 'news' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   172
    return;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   173
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   174
  $limit = ( $x = $paths->getParam(1) ) ? $x : 20;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   175
  $limit = intval($limit);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   176
  if ( $limit > 50 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   177
    $limit = 50;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   178
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   179
  $title = getConfig('site_name') . ': Site news';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   180
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   181
  $x = getConfig('nb_portal_title');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   182
  $desc = ( empty($x) ) ? 'Welcome to ' . getConfig('site_name') : $x;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   183
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   184
  $link = makeUrlComplete('NewsBoy', 'Portal');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   185
  $generator = 'Enano CMS ' . enano_version() . ' - NewsBoy plugin';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   186
  $email = getConfig('contact_email');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   187
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   188
  $rss = new RSS($title, $desc, $link, $generator, $email);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   189
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   190
  $sql = 'SELECT p.*, l.time_id, l.author, u.user_level,COUNT(c.comment_id) AS num_comments,t.page_text FROM '.table_prefix.'pages AS p
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   191
         LEFT JOIN '.table_prefix.'comments AS c
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   192
           ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   193
         LEFT JOIN '.table_prefix.'logs AS l
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   194
           ON ( l.page_id=p.urlname AND l.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   195
         LEFT JOIN '.table_prefix.'users AS u
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   196
           ON ( u.username=l.author )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   197
         LEFT JOIN '.table_prefix.'page_text AS t
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   198
           ON ( t.page_id=p.urlname AND t.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   199
         WHERE p.namespace=\'NewsBoy\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   200
           AND l.action=\'create\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   201
           AND p.urlname REGEXP \'^([0-9]+)$\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   202
           AND p.visible=1
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   203
         GROUP BY p.urlname
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   204
         ORDER BY urlname DESC
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   205
         LIMIT '.$limit.';';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   206
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   207
  $q = $db->sql_unbuffered_query($sql);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   208
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   209
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   210
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   211
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   212
  $formatter = new NewsBoyFormatter();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   213
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   214
  if ( $row = $db->fetchrow() )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   215
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   216
    do {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   217
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   218
      $title = $row['name'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   219
      $link = makeUrlComplete('NewsBoy', $row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   220
      $desc = RenderMan::render($row['page_text']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   221
      $time = intval($row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   222
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   223
      $rss->add_item($title, $link, $desc, $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   224
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   225
    } while ( $row = $db->fetchrow() );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   226
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   227
  else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   228
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   229
    $rss->add_item('Error', $link, 'No news items yet.', time());
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   230
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   231
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   232
  echo $rss->render();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   233
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   234
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   235
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   236
function NewsBoy_portal()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   237
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   238
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   239
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   240
  $news_template = <<<TPLCODE
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   241
  <div class="tblholder news">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   242
    <table border="0" cellspacing="1" cellpadding="4" style="width: 100%;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   243
      <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   244
        <th><a href="{LINK}" style="color: inherit;">{TITLE}</a></th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   245
      </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   246
      <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   247
        <td class="row3">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   248
          {CONTENT}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   249
        </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   250
      </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   251
      <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   252
        <th class="subhead" style="font-weight: normal; font-size: 67%;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   253
          Posted by {USER_LINK} on {DATE}<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   254
          [ {NUM_COMMENTS} comment{COMMENT_S} | {COMMENT_LINK} ]
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   255
        </th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   256
      </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   257
    </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   258
  </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   259
TPLCODE;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   260
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   261
  /*
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   262
  $p = RenderMan::strToPageID(getConfig('main_page'));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   263
  if ( $p[1] != 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   264
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   265
    echo RenderMan::getPage($p[0], $p[1]);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   266
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   267
  else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   268
  { */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   269
    /*
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   270
    $s = $paths->nslist['NewsBoy'] . 'Announce';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   271
    if ( isPage($s) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   272
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   273
      $p = RenderMan::getPage('Announce', 'NewsBoy');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   274
      echo $p;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   275
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   276
  /* } */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   277
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   278
  $s = $paths->nslist['NewsBoy'] . 'Announce';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   279
  $announce_page = getConfig('nb_announce_page');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   280
  if ( !empty($announce_page) && isPage($announce_page) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   281
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   282
    $s = $announce_page;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   283
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   284
  else if ( !isPage($s) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   285
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   286
    $s = false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   287
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   288
  if ( $s )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   289
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   290
    $stuff = RenderMan::strToPageID($s);
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   291
    // Hackish fix to prevent the categorization button and other stuff from being displayed
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   292
    $paths->pages[$s]['special'] = 1;
1
540d077b7612 Fix stupid announcement link bug; replace getPage call with PageProcessor
Dan
parents: 0
diff changeset
   293
    $page = new PageProcessor($stuff[0], $stuff[1]);
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   294
    $content = $page->fetch_text();
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   295
    $content = '?>' . RenderMan::render($content);
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   296
    eval($content);
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   297
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   298
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   299
  echo '<h2>Latest news</h2>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   300
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   301
  $q = $db->sql_unbuffered_query('SELECT p.*, COUNT(c.comment_id) AS num_comments, t.page_text, l.time_id, l.author, u.user_level FROM '.table_prefix.'pages AS p
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   302
         LEFT JOIN '.table_prefix.'comments AS c
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   303
           ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   304
         LEFT JOIN '.table_prefix.'page_text AS t
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   305
           ON ( t.page_id=p.urlname AND t.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   306
         LEFT JOIN '.table_prefix.'logs AS l
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   307
           ON ( l.page_id=p.urlname AND l.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   308
         LEFT JOIN '.table_prefix.'users AS u
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   309
           ON ( u.username=l.author OR u.user_id=1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   310
         WHERE p.namespace=\'NewsBoy\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   311
           AND l.action=\'create\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   312
           AND p.urlname!=\'Announce\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   313
           AND p.visible=1
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   314
         GROUP BY p.urlname
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   315
         ORDER BY urlname DESC;');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   316
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   317
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   318
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   319
  if ( $row = $db->fetchrow() )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   320
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   321
    $i = 0;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   322
    $parser = $template->makeParserText($news_template);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   323
    do
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   324
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   325
      if ( $i < 5 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   326
      {
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   327
        $content = $row['page_text'];
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   328
        
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   329
        $trimmed = false;
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   330
        if ( $pos = strpos($content, '<!--BREAK-->' ) )
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   331
        {
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   332
          $content = substr($content, 0, $pos);
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   333
          $trimmed = true;
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   334
        }
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   335
        
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   336
        $title = htmlspecialchars($row['name']);
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   337
        $content = RenderMan::render($content);
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   338
        
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   339
        if ( strlen($content) > 400 && !$trimmed )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   340
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   341
          $content = nb_trim_paragraph($content, 400, $trimmed);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   342
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   343
        if ( $trimmed )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   344
        {
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   345
          $link = ' <a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '">Read more...</a>';
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   346
          $content = preg_replace('/(.+?)<\/(p|ul|table|div|pre)>([\s]*?)$/Usi', '\\1' . $link . '</\\2>\\3', $content, 1);
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   347
          if ( !strstr($content, $link) )
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   348
          {
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   349
            $content .= $link;
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   350
          }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   351
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   352
        $user_link = nb_make_username_link($row['author'], $row['user_level']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   353
        $date = date('F d, Y h:i:s a', $row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   354
        $num_comments = $row['num_comments'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   355
        $comment_s = ( $num_comments == 1 ) ? '' : 's';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   356
        $comment_link = '<a href="' . makeUrlNS('NewsBoy', $row['urlname'], false, true) . '#do:comments" style="color: inherit;">add a comment</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   357
        $parser->assign_vars(array(
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   358
            'TITLE' => $title,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   359
            'LINK' => makeUrlNS('NewsBoy', $row['urlname']),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   360
            'CONTENT' => $content,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   361
            'USER_LINK' => $user_link,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   362
            'DATE' => $date,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   363
            'NUM_COMMENTS' => $num_comments,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   364
            'COMMENT_S' => $comment_s,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   365
            'COMMENT_LINK' => $comment_link
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   366
          ));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   367
        echo $parser->run();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   368
      }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   369
      else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   370
      {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   371
        echo '<p><a href="'.makeUrlNS('NewsBoy', 'Archive').'">Older news...</a></p>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   372
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   373
      }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   374
      $i++;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   375
    } while ( $row = $db->fetchrow() );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   376
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   377
  else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   378
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   379
    echo '<p>No news items yet.</p>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   380
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   381
  if ( $session->user_level >= USER_LEVEL_ADMIN )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   382
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   383
    echo '<div class="tblholder" style="margin: 10px auto 0 auto; display: table;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   384
            <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   385
              <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   386
                <th>Administrative tools:</th>
3
8ae9acb2e919 Re-implement announcement link fix, blame it on my bad Hg repo management
Dan
parents: 2
diff changeset
   387
                <td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS($stuff[1], $stuff[0], '', true) . '#do:edit">Edit announcement &raquo;</a></td>
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   388
                <td class="row3" style="text-align: center;"><a style="color: inherit;" href="' . makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'NewsboyItemManager', true) . '" onclick="newsboy_open_admin(); return false;">Portal Administration</a></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   389
              </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   390
            </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   391
          </div><br />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   392
  }
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   393
  show_category_info();
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   394
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   395
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   396
/**
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   397
 * Formats row data in the archive.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   398
 * @package Enano
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   399
 * @subpackage Newsboy
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   400
 * @license GNU General Public License
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   401
 */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   402
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   403
class NewsBoyFormatter
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   404
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   405
  function article_link($name, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   406
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   407
    $article_link = '<a href="' . makeUrlNS('NewsBoy', $row['urlname']) . '">' . $row['name'] . '</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   408
    return $article_link;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   409
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   410
  function format_date($date, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   411
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   412
    $date = date('Y-m-j g:m', intval ( $date ));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   413
    return $date;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   414
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   415
  function format_username($x, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   416
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   417
    $ul = intval($row['user_level']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   418
    $author = nb_make_username_link($row['author'], $ul);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   419
    return $author;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   420
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   421
  function format_commentlink($x, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   422
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   423
    $comments = '<a href="' . makeUrlNS('NewsBoy', $row['urlname']) . '#do:comments">' . $row['num_comments'] . '</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   424
    return $comments;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   425
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   426
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   427
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   428
function NewsBoy_archive()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   429
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   430
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   431
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   432
  $lower_limit = ( isset($_GET['start']) ) ? intval($_GET['start']) : ( ( $xx = $paths->getParam(0) ) ? intval($xx) : 0 );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   433
  $entries_per_page = 50;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   434
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   435
  $row_count = $entries_per_page + 1;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   436
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   437
  // Determine number of total news entries
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   438
  $q = $db->sql_query('SELECT urlname FROM '.table_prefix.'pages WHERE namespace=\'NewsBoy\' AND urlname REGEXP \'^([0-9]+)$\' AND visible=1;');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   439
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   440
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   441
  $r = $db->fetchrow();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   442
  $num_total = intval($db->numrows());
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   443
  $db->free_result();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   444
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   445
  if ( $lower_limit >= $num_total )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   446
    $lower_limit = 0;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   447
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   448
  $sql = 'SELECT p.*, l.time_id, l.author, u.user_level,COUNT(c.comment_id) AS num_comments FROM '.table_prefix.'pages AS p
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   449
         LEFT JOIN '.table_prefix.'comments AS c
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   450
           ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   451
         LEFT JOIN '.table_prefix.'logs AS l
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   452
           ON ( l.page_id=p.urlname AND l.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   453
         LEFT JOIN '.table_prefix.'users AS u
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   454
           ON ( u.username=l.author )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   455
         WHERE p.namespace=\'NewsBoy\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   456
           AND l.action=\'create\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   457
           AND p.urlname REGEXP \'^([0-9]+)$\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   458
           AND p.visible=1
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   459
         GROUP BY p.urlname
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   460
         ORDER BY urlname DESC;';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   461
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   462
  $q = $db->sql_unbuffered_query($sql);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   463
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   464
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   465
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   466
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   467
  $formatter = new NewsBoyFormatter();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   468
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   469
  $callers = Array(
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   470
      'name' => Array($formatter, 'article_link'),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   471
      'urlname' => Array($formatter, 'format_date'),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   472
      'author' => Array($formatter, 'format_username'),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   473
      'num_comments' => Array($formatter, 'format_commentlink')
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   474
    );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   475
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   476
  $head = '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   477
          <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   478
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   479
              <th>Article</th><th>Date</th><th>Author</th><th>Comments</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   480
            </tr>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   481
  $foot = "</table></div>";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   482
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   483
  $content = paginate($q, "\n".'<tr><td class="{_css_class}">{name}</td><td class="{_css_class}">{urlname}</td><td class="{_css_class}">{author}</td><td class="{_css_class}">{num_comments}</td></tr>',
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   484
                      $num_total, makeUrlNS('NewsBoy', 'Archive/%s'), $lower_limit, 20, $callers, $head, $foot);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   485
  echo $content;  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   486
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   487
  $code = $plugins->setHook('send_page_footers');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   488
  foreach ( $code as $cmd )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   489
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   490
    eval($cmd);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   491
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   492
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   493
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   494
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   495
function nb_make_username_link($username, $user_level)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   496
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   497
  $color = '#0000AA';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   498
  $user_level = intval($user_level);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   499
  if ( $user_level < USER_LEVEL_MEMBER ) return $username;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   500
  if ( $user_level >= USER_LEVEL_MOD ) $color = '#00AA00';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   501
  if ( $user_level >= USER_LEVEL_ADMIN ) $color = '#AA0000';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   502
  $link = '<a style="color: ' . $color . '" href="' . makeUrlNS('User', str_replace(' ', '_', $username) ) . '">' . $username . '</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   503
  return $link;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   504
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   505
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   506
function NewsBoy_PortalLink()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   507
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   508
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   509
  if ( $paths->namespace == 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   510
    echo '<div class="tblholder"><table border="0" style="width: 100%;" cellspacing="1" cellpadding="4"><tr><th><a style="color: inherit;" href="' . makeUrlNS('NewsBoy', 'Portal') . '">&laquo; Return to News Portal</a></th></tr></table></div><br />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   511
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   512
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   513
// Administration panel
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   514
function page_Admin_NewsboyItemManager()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   515
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   516
  global $db, $session, $paths, $template, $plugins; if($session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN) { redirect(makeUrlNS('Special', 'Administration', 'noheaders', true), '', '', 0); die('Hacking attempt'); }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   517
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   518
  $done = false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   519
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   520
  if ( isset( $_GET['act'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   521
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   522
    switch ( $_GET['act'] )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   523
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   524
      case 'edit':
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   525
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   526
        // Error list
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   527
        $errors = Array();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   528
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   529
        if ( isset ( $_POST['submitting'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   530
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   531
          // Generate timestamp
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   532
          $year = intval($_POST['pub_year']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   533
          $month = intval($_POST['pub_month']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   534
          $day = intval($_POST['pub_day']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   535
          $hour = intval($_POST['pub_hour']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   536
          $minute = intval($_POST['pub_minute']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   537
          $second = intval($_POST['pub_second']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   538
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   539
          // Validation
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   540
          if ( $year < 1500 || $year > 10000 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   541
            $errors[] = 'Invalid year.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   542
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   543
          if ( $month < 1 || $month > 12 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   544
            $errors[] = 'Invalid month.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   545
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   546
          if ( $day < 1 || $day > 31 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   547
            $errors[] = 'Invalid day.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   548
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   549
          if ( $hour < 0 || $hour > 23 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   550
            $errors[] = 'Invalid hour.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   551
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   552
          if ( $minute < 0 || $minute > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   553
            $errors[] = 'Invalid minute.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   554
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   555
          if ( $second < 0 || $second > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   556
            $errors[] = 'Invalid second.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   557
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   558
          $name = $_POST['article_name'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   559
          $name = $db->escape($name);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   560
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   561
          $author = $_POST['author'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   562
          $author = $db->escape($author);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   563
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   564
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   565
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   566
            $time = mktime($hour, $minute, $second, $month, $day, $year);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   567
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   568
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   569
          if ( isset($paths->pages[ $paths->nslist['NewsBoy'] . $time ]) && $paths->pages[ $paths->nslist['NewsBoy'] . $time ] != $paths->pages[ $paths->nslist['NewsBoy'] . $_POST['page_id'] ] )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   570
            $errors[] = 'You cannot have two news articles with the same publish time.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   571
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   572
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   573
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   574
            $publ = ( isset($_POST['published']) ) ? '1' : '0';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   575
            $sql = 'UPDATE '.table_prefix.'pages SET name=\'' . $name . '\',visible='.$publ.',urlname=\''.$time.'\' WHERE urlname=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   576
            $q = $db->sql_query($sql);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   577
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   578
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   579
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   580
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   581
            // Update author
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   582
            $q = $db->sql_query('UPDATE '.table_prefix.'logs SET author=\'' . $author . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\' AND action=\'create\';');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   583
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   584
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   585
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   586
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   587
            // Update other tables with urlname info
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   588
            $q = $db->sql_query('UPDATE '.table_prefix.'logs SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   589
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   590
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   591
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   592
            $q = $db->sql_query('UPDATE '.table_prefix.'comments SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   593
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   594
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   595
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   596
            $q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   597
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   598
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   599
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   600
            $q = $db->sql_query('UPDATE '.table_prefix.'categories SET page_id=\'' . $time . '\' WHERE page_id=\'' . $db->escape($_POST['page_id']) . '\' AND namespace=\'NewsBoy\';');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   601
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   602
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   603
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   604
            echo '<div class="info-box">Your changes have been saved.</div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   605
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   606
            break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   607
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   608
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   609
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   610
        if ( count($errors) > 0 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   611
          echo '<div class="warning-box">Errors encountered while saving data:<ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   612
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   613
        // Obtain page information
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   614
        if ( !isset($paths->pages[ $paths->nslist['NewsBoy'] . $_GET['id'] ]) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   615
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   616
          echo 'Invalid ID';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   617
          return false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   618
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   619
        $page_info =& $paths->pages[ $paths->nslist['NewsBoy'] . $_GET['id'] ];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   620
        $time = intval($page_info['urlname_nons']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   621
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   622
        // Get author
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   623
        $q = $db->sql_query('SELECT author FROM '.table_prefix.'logs WHERE page_id=\'' . $db->escape($page_info['urlname_nons']) . '\' AND namespace=\'NewsBoy\' AND action=\'create\' ORDER BY time_id DESC LIMIT 1;');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   624
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   625
        if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   626
          $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   627
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   628
        $row = $db->fetchrow();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   629
        $author = ( isset($row['author']) ) ? $row['author'] : '';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   630
        if ( empty($author) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   631
          $author = 'Anonymous';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   632
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   633
        // Set date & time
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   634
        $month  = date('n', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   635
        $year   = date('Y', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   636
        $day    = date('j', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   637
        $hour   = date('G', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   638
        $minute = date('m', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   639
        $second = date('s', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   640
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   641
        echo '<form id="nb_edit_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&amp;' : '') .'module='.$paths->cpage['module'] . '&act=edit').'" method="post" onsubmit="if ( !submitAuthorized ) return false;">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   642
        echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   643
                <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   644
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   645
                    <th colspan="2">Editing news article</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   646
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   647
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   648
                    <td class="row1">Article name:</td><td class="row2"><input name="article_name" value="' . htmlspecialchars($page_info['name']) . '" /></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   649
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   650
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   651
                    <td class="row1">Published date:</td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   652
                    <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   653
                      <input name="pub_year" type="text" size="5" value="'.$year.'" />-<select name="pub_month">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   654
       for ( $i = 1; $i <= 12; $i++ )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   655
       {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   656
         $m = "[$i] ";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   657
         switch ( $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   658
         {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   659
           case 1:  $m .= 'January'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   660
           case 2:  $m .= 'February'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   661
           case 3:  $m .= 'March'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   662
           case 4:  $m .= 'April'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   663
           case 5:  $m .= 'May'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   664
           case 6:  $m .= 'June'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   665
           case 7:  $m .= 'July'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   666
           case 8:  $m .= 'August'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   667
           case 9:  $m .= 'September'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   668
           case 10: $m .= 'October'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   669
           case 11: $m .= 'November'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   670
           case 12: $m .= 'December'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   671
           default: $m .= 'Fuhrober'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   672
         }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   673
         if ( $month == $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   674
           echo '         <option selected="selected" value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   675
         else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   676
           echo '         <option value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   677
       }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   678
       echo '         </select>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   679
                      <input name="pub_day" type="text" size="3" value="' . $day . '" />, time:
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   680
                      <input name="pub_hour" type="text" size="3" value="' . $hour . '" />&nbsp;:&nbsp;<input name="pub_minute" type="text" size="3" value="' . $minute . '" />&nbsp;:&nbsp;<input name="pub_second" type="text" size="3" value="' . $second . '" /><br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   681
                      <small>Note: Hours are in 24-hour format.</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   682
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   683
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   684
                  <!-- Inline developer blog, episode 1:
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   685
                       Right about the time I got here, I started sneezing like crazy. Must have caught it Friday night. Great... now
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   686
                       my life is officially stuck on pause for the next 3 days. I\'d swear here but (a) Mommy taught me better, and
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   687
                       (b) I wouldn\'t want to offend you hackers. (j/k)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   688
                       
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   689
                       Oh crap. And no, I don\'t give towels with my showers.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   690
                       
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   691
                       -Dan
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   692
                       -->
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   693
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   694
                    <td class="row1">Publish article:</td><td class="row2"><label><input name="published" type="checkbox" ' . ( $page_info['visible'] == 1 ? 'checked="checked"' : '' ) . ' /> Article is published (shown to the public)</label></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   695
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   696
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   697
                    <td class="row1">Article author:</td><td class="row2">' . $template->username_field('author', $author) . '</td></tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   698
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   699
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   700
                    <td class="row3" style="text-align: center;" colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   701
                      <a href="#" onclick="var frm = document.getElementById(\'nb_edit_form\'); frm.submit(); return false;">Save changes</a>&nbsp;&nbsp;<a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Return to main menu</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   702
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   703
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   704
                </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   705
              </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   706
              <input type="hidden" name="submitting" value="yes" />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   707
              <input type="hidden" name="page_id" value="' . $_GET['id'] . '" />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   708
        echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   709
        $done = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   710
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   711
      case 'del':
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   712
        if ( isset( $_POST['confirmed'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   713
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   714
          $page_id = $_POST['page_id'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   715
          $namespace = 'NewsBoy';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   716
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   717
          $e = $db->sql_query('INSERT INTO '.table_prefix.'logs(time_id,date_string,log_type,action,page_id,namespace,author) VALUES('.time().', \''.date('d M Y h:i a').'\', \'page\', \'delete\', \''.$page_id.'\', \''.$namespace.'\', \''.$session->username.'\')');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   718
          if(!$e) $db->_die('The page log entry could not be inserted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   719
          $e = $db->sql_query('DELETE FROM '.table_prefix.'categories WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   720
          if(!$e) $db->_die('The page categorization entries could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   721
          $e = $db->sql_query('DELETE FROM '.table_prefix.'comments WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   722
          if(!$e) $db->_die('The page comments could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   723
          $e = $db->sql_query('DELETE FROM '.table_prefix.'page_text WHERE page_id=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   724
          if(!$e) $db->_die('The page text entry could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   725
          $e = $db->sql_query('DELETE FROM '.table_prefix.'pages WHERE urlname=\''.$page_id.'\' AND namespace=\''.$namespace.'\'');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   726
          if(!$e) $db->_die('The page entry could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   727
          $e = $db->sql_query('DELETE FROM '.table_prefix.'files WHERE page_id=\''.$page_id.'\'');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   728
          if(!$e) $db->_die('The file entry could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   729
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   730
          $result = 'This page has been deleted. Note that there is still a log of edits and actions in the database, and anyone with admin rights can raise this page from the dead unless the log is cleared. If the deleted file is an image, there may still be cached thumbnails of it in the cache/ directory, which is inaccessible to users.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   731
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   732
          echo $result . '<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   733
               <br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   734
               <a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Return to Newsboy</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   735
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   736
        else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   737
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   738
          echo '<form id="nb_delete_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&amp;' : '') .'module='.$paths->cpage['module'] . '&act=del').'" method="post">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   739
          echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   740
                  <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   741
                    <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   742
                      <th>Confirm deletion</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   743
                     </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   744
                     <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   745
                       <td class="row1" style="text-align: center;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   746
                         <p>Are you sure you want to delete this news article?</p>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   747
                       </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   748
                     </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   749
                     <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   750
                       <td class="row3" style="text-align: center;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   751
                         <a href="#" onclick="var frm = document.getElementById(\'nb_delete_form\'); frm.submit(); return false;">Delete</a>&nbsp;&nbsp;<a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Cancel</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   752
                       </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   753
                     </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   754
                  </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   755
                </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   756
                <input type="hidden" name="confirmed" value="yes" />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   757
                <input type="hidden" name="page_id" value="' . intval ( $_GET['id'] ) . '" />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   758
          echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   759
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   760
        $done = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   761
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   762
      case 'create':
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   763
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   764
        // Error list
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   765
        $errors = Array();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   766
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   767
        if ( isset ( $_POST['submitting'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   768
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   769
          // Generate timestamp
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   770
          $year = intval($_POST['pub_year']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   771
          $month = intval($_POST['pub_month']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   772
          $day = intval($_POST['pub_day']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   773
          $hour = intval($_POST['pub_hour']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   774
          $minute = intval($_POST['pub_minute']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   775
          $second = intval($_POST['pub_second']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   776
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   777
          // Validation
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   778
          if ( $year < 1500 || $year > 10000 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   779
            $errors[] = 'Invalid year.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   780
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   781
          if ( $month < 1 || $month > 12 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   782
            $errors[] = 'Invalid month.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   783
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   784
          if ( $day < 1 || $day > 31 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   785
            $errors[] = 'Invalid day.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   786
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   787
          if ( $hour < 0 || $hour > 23 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   788
            $errors[] = 'Invalid hour.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   789
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   790
          if ( $minute < 0 || $minute > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   791
            $errors[] = 'Invalid minute.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   792
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   793
          if ( $second < 0 || $second > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   794
            $errors[] = 'Invalid second.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   795
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   796
          $name = $_POST['article_name'];
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   797
          // This is db-escaped by PageUtils
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   798
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   799
          $author = $_POST['author'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   800
          $author = $db->escape($author);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   801
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   802
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   803
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   804
            $time = mktime($hour, $minute, $second, $month, $day, $year);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   805
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   806
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   807
          if ( isset($paths->pages[ $paths->nslist['NewsBoy'] . $time ]) && $paths->pages[ $paths->nslist['NewsBoy'] . $time ] != $paths->pages[ $paths->nslist['NewsBoy'] . $_POST['page_id'] ] )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   808
            $errors[] = 'You cannot have two news articles with the same publish time.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   809
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   810
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   811
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   812
            $publ = ( isset($_POST['published']) ) ? 1 : 0;
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   813
            
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   814
            $result = PageUtils::createpage( (string)$time, 'NewsBoy', $name, $publ );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   815
            
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   816
            if ( $result == 'good' )
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   817
            {
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   818
              // Set content
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   819
              $content = RenderMan::preprocess_text($_POST['content'], true); // this also SQL-escapes it
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   820
              
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   821
              $q = $db->sql_query('UPDATE '.table_prefix.'page_text SET page_text=\'' . $content . '\' WHERE page_id=\'' . $time . '\' AND namespace=\'NewsBoy\';');
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   822
              if ( !$q )
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   823
                $db->_die();
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   824
              
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   825
              if ( $result )
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   826
                echo '<div class="info-box">Your changes have been saved.</div>';
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   827
              else
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   828
                $errors[] = 'PageUtils::createpage returned an error.';
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   829
            }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   830
            else
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   831
            {
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   832
              $errors[] = 'PageUtils::createpage returned an error: ' . htmlspecialchars($result);
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   833
            }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   834
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   835
            break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   836
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   837
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   838
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   839
        if ( count($errors) > 0 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   840
          echo '<div class="warning-box">Errors encountered while preparing data:<ul><li>' . implode('</li><li>', $errors) . '</li></ul></div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   841
        
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   842
        $time = time();
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   843
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   844
        // Get author
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   845
        $author = $session->username;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   846
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   847
        if ( empty($author) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   848
          $author = 'Anonymous';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   849
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   850
        // Set date & time
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   851
        $month  = date('n', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   852
        $year   = date('Y', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   853
        $day    = date('j', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   854
        $hour   = date('G', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   855
        $minute = date('m', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   856
        $second = date('s', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   857
        
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   858
        echo '<form id="nb_create_form" action="'.makeUrlNS('Special', 'Administration', (( isset($_GET['sqldbg'])) ? 'sqldbg&' : '') .'module='.$paths->cpage['module'] . '&act=create').'" method="post" onsubmit="if ( !submitAuthorized ) return false;">';
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   859
        echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   860
                <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   861
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   862
                    <th colspan="2">Creating news article</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   863
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   864
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   865
                    <td class="row1">Article name:</td><td class="row2"><input name="article_name" value="" /></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   866
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   867
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   868
                    <td class="row1">Published datestamp:</td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   869
                    <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   870
                      <input name="pub_year" type="text" size="5" value="'.$year.'" />-<select name="pub_month">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   871
       for ( $i = 1; $i <= 12; $i++ )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   872
       {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   873
         $m = "[$i] ";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   874
         switch ( $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   875
         {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   876
           case 1:  $m .= 'January'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   877
           case 2:  $m .= 'February'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   878
           case 3:  $m .= 'March'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   879
           case 4:  $m .= 'April'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   880
           case 5:  $m .= 'May'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   881
           case 6:  $m .= 'June'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   882
           case 7:  $m .= 'July'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   883
           case 8:  $m .= 'August'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   884
           case 9:  $m .= 'September'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   885
           case 10: $m .= 'October'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   886
           case 11: $m .= 'November'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   887
           case 12: $m .= 'December'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   888
           default: $m .= 'Fuhrober'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   889
         }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   890
         if ( $month == $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   891
           echo '         <option selected="selected" value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   892
         else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   893
           echo '         <option value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   894
       }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   895
       echo '         </select>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   896
                      <input name="pub_day" type="text" size="3" value="' . $day . '" />, time:
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   897
                      <input name="pub_hour" type="text" size="3" value="' . $hour . '" />&nbsp;:&nbsp;<input name="pub_minute" type="text" size="3" value="' . $minute . '" />&nbsp;:&nbsp;<input name="pub_second" type="text" size="3" value="' . $second . '" /><br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   898
                      <small>Note: Hours are in 24-hour format.</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   899
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   900
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   901
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   902
                    <td class="row1">Publish article:</td><td class="row2"><label><input name="published" type="checkbox" /> Article is published (shown to the public)</label></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   903
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   904
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   905
                    <td class="row1">Article author:</td><td class="row2">' . $template->username_field('author', $author) . '</td></tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   906
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   907
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   908
                    <td class="row1">Initial content:<br /><small>You can always edit this later.</small></td><td class="row2"><textarea name="content" rows="15" cols="60" style="width: 100%;"></textarea></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   909
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   910
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   911
                    <td class="row3" style="text-align: center;" colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   912
                      <a href="#" onclick="var frm = document.getElementById(\'nb_create_form\'); frm.submit(); return false;">Create article</a>&nbsp;&nbsp;<a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\');">Return to main menu</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   913
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   914
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   915
                </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   916
              </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   917
              <input type="hidden" name="submitting" value="yes" />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   918
        echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   919
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   920
        $done = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   921
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   922
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   923
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   924
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   925
  if ( !$done )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   926
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   927
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   928
    // Start output
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   929
    echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   930
      <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   931
        <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   932
          <th>Name</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   933
          <th>Date published</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   934
          <th colspan="3">Actions</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   935
        </tr>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   936
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   937
    $row_class = 'row2';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   938
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   939
    // List existing news entries
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   940
    $q = $db->sql_query('SELECT name,urlname FROM '.table_prefix.'pages WHERE namespace="NewsBoy" AND urlname!="Announce" ORDER BY name ASC;');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   941
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   942
    if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   943
      $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   944
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   945
    if ( $row = $db->fetchrow($q) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   946
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   947
      do {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   948
        $row_class = ( $row_class == 'row1' ) ? 'row2' : 'row1';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   949
        $ts = intval($row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   950
        $date = date('F d, Y h:i a', $ts);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   951
        $edit_url = makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=edit&id={$row['urlname']}", true);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   952
        $dele_url = makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=del&id={$row['urlname']}", true);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   953
        $page_url = makeUrlNS('NewsBoy', $row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   954
        echo "<tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   955
                <td class='$row_class' style='width: 50%;'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   956
                  {$row['name']}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   957
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   958
                <td class='$row_class' style='width: 40%;'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   959
                  $date
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   960
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   961
                <td class='$row_class'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   962
                  <a href='$edit_url'>Settings</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   963
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   964
                <td class='$row_class'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   965
                  <a href='$page_url' onclick='window.open(this.href); return false;'>Page</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   966
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   967
                <td class='$row_class'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   968
                  <a href='$dele_url'>Delete</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   969
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   970
              </tr>";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   971
      } while ( $row = $db->fetchrow($q) );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   972
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   973
    else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   974
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   975
      echo '<tr><td class="row3" colspan="5" style="text-align: center;">No news items yet.</td></tr>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   976
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   977
    echo '<tr><th class="subhead" colspan="5"><a href="' . makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=create", true) . '" style="color: inherit;">Create new entry</a></th></tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   978
          </table></div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   979
    $db->free_result();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   980
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   981
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   982
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   983
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   984
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   985
function page_Admin_NewsboyConfiguration()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   986
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   987
  global $db, $session, $paths, $template, $plugins; if($session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN) { redirect(makeUrlNS('Special', 'Administration', 'noheaders', true), '', '', 0); die('Hacking attempt'); }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   988
  if ( isset($_POST['submit']) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   989
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   990
    setConfig('nb_portal_title', $_POST['portal_name']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   991
    if ( isPage($_POST['announce_page']) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   992
      setConfig('nb_announce_page', $_POST['announce_page']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   993
    else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   994
      setConfig('nb_announce_page', '');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   995
    // Submit
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   996
    echo '<div class="info-box">Your changes have been saved.</div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   997
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   998
  echo '<form name="main" action="'.htmlspecialchars(makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module'])).'" method="post">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   999
  echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1000
          <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1001
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1002
              <th colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1003
                Newsboy portal: General configuration
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1004
              </th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1005
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1006
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1007
              <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1008
                Portal title:<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1009
                <small>This is the text that will be shown as the page title on the<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1010
                portal. If you don\'t enter anything here, a default will be used.</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1011
              </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1012
              <td class="row1"><input type="text" size="30" name="portal_name" value="' . htmlspecialchars(getConfig('nb_portal_title')) . '"></td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1013
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1014
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1015
              <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1016
                Page to embed as announcement:<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1017
                <small>The page you enter here will always be shown at the top of the<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1018
                portal. The default is "' . $paths->nslist['NewsBoy'] . 'Announce".</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1019
              </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1020
              <td class="row1">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1021
                ' . $template->pagename_field('announce_page', htmlspecialchars(getConfig('nb_announce_page'))) . '
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1022
              </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1023
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1024
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1025
              <th class="subhead" colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1026
                <input type="submit" name="submit" value="Save changes" />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1027
              </th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1028
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1029
          </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1030
        </div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1031
  echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1032
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1033
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1034
/**
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1035
 * Trims a wad of text to the specified length.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1036
 * @todo make HTML friendly (don't break tags)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1037
 * @param string The text to trim
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1038
 * @param int The maximum length to trim the text to.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1039
 * @param bool Reference. Set to true if the text was trimmed, otherwise set to false.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1040
 */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1041
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
  1042
function nb_trim_paragraph($text, $len = 500, &$trimmed)
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1043
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1044
  $trimmed = false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1045
  if ( strlen($text) <= $len )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1046
    return $text;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1047
  $trimmed = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1048
  $text = substr($text, 0, $len);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1049
  for ( $i = $len; $i > 0; $i-- )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1050
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1051
    $chr = $text{$i-1};
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1052
    if ( preg_match('/[\s]/', $chr) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1053
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1054
      $text = substr($text, 0, $i - 1);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1055
      $text .= '...';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1056
      return $text;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1057
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1058
    $text = substr($text, 0, $i);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1059
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1060
  return $text;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1061
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1062
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1063
?>