plugins/Newsboy.php
author Dan Fuhry <dan@enanocms.org>
Sun, 18 Sep 2011 01:39:38 -0400
changeset 23 6a501b41907f
parent 22 7f0d9fa561f4
permissions -rw-r--r--
I'm pretty sure this fixes title issues
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
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
     4
Plugin URI: http://enanocms.org/plugin/newsboy
0
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
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
     8
Author URI: http://enanocms.org/
0
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
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
    13
 * Version 1.1.2
0
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
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
    27
$plugins->attachHook('page_not_found', 'NewsBoy_namespace_handler($this);');
0
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);
15
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
    68
  $session->acl_extend_scope('html_in_pages',          'NewsBoy', $paths);
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    69
  $session->acl_extend_scope('php_in_pages',           'NewsBoy', $paths);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    70
  $session->acl_extend_scope('edit_acl',               'NewsBoy', $paths);
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
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
    74
function NewsBoy_namespace_handler(&$page)
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    75
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    76
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    77
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    78
  if ( defined('ENANO_FEEDBURNER_INCLUDED') )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    79
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    80
    $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
    81
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    82
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    83
  if ( $paths->namespace != 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    84
    return;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    85
  
18
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
    86
  if ( $page->page_id == 'Portal' || preg_match('/^Archive(\/|$)/', $page->page_id) )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    87
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    88
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    89
    // Add admin opener Javascript function
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    90
    $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
    91
    <enano:no-opt>
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    92
    <script type="text/javascript">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    93
      function newsboy_open_admin()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    94
      {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    95
        if ( auth_level < USER_LEVEL_ADMIN )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    96
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    97
          ajaxPromptAdminAuth(function(k) {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    98
            ENANO_SID = k;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
    99
            auth_level = USER_LEVEL_ADMIN;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   100
            var loc = String(window.location + \'\');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   101
            window.location = append_sid(loc);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   102
            var loc = makeUrlNS(\'Special\', \'Administration\', \'module=\' + namespace_list[\'Admin\'] + \'NewsboyItemManager\');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   103
            if ( (ENANO_SID + \' \').length > 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   104
              window.location = loc;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   105
          }, 9);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   106
          return false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   107
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   108
        var loc = makeUrlNS(\'Special\', \'Administration\', \'module=\' + namespace_list[\'Admin\'] + \'NewsboyItemManager\');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   109
        window.location = loc;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   110
      }
4
bf5589120afb Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents: 3
diff changeset
   111
    </script>
bf5589120afb Fixed bad admin-nav function, which was rendered useless if aggressive_optimize_html is on
Dan
parents: 3
diff changeset
   112
    </enano:no-opt>');
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   113
    
18
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
   114
    $perms =& $page->perms;
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
   115
    if ( !$perms )
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
   116
      $perms = $session->fetch_page_acl($page->page_id, $page->namespace);
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
   117
    
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
   118
    if ( !$perms->get_permissions('read') )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   119
    {
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   120
      $page->err_access_denied();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   121
      return false;
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   122
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   123
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   124
    $paths->cpage['comments_on'] = 0;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   125
    
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   126
    if ( $page->page_id == 'Portal' )
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   127
    {
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   128
      $template->header();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   129
      NewsBoy_portal();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   130
      $template->footer();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   131
    }
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   132
    else if ( preg_match('/^Archive(\/|$)/', $page->page_id) )
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   133
    {
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   134
      $template->header();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   135
      NewsBoy_archive();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   136
      $template->footer();
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   137
    }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   138
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   139
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   140
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   141
// This is a 1.1.6-and-later thing.
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   142
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   143
if ( class_exists('Namespace_Default') )
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   144
{
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   145
  class Namespace_NewsBoy extends Namespace_Default
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   146
  {
13
4d8ce84092c9 Fixed a couple of bugs under 1.1.6.
Dan
parents: 12
diff changeset
   147
    public $perms, $password, $send_headers;
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   148
    
17
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   149
    function __construct($page_id, $namespace, $revision = 0)
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   150
    {
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   151
      global $db, $session, $paths, $template, $plugins; // Common objects
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   152
      
17
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   153
      if ( preg_match('#^Article/#', $page_id) )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   154
      {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   155
        $timestamp = NewsBoy_resolve_article_url($page_id);
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   156
        if ( $timestamp )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   157
        {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   158
          $page_id = strval($timestamp);
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   159
          $template->set_page($page_id, $namespace);
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   160
        }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   161
      }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   162
      
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   163
      parent::__construct($page_id, $namespace, $revision);
18
8205e4ca237e Whoops. NOW compatible with Enano rev. 953.
Dan
parents: 17
diff changeset
   164
    }
17
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   165
    
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   166
    function build_cdata()
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   167
    {
23
6a501b41907f I'm pretty sure this fixes title issues
Dan Fuhry <dan@enanocms.org>
parents: 22
diff changeset
   168
      list($page_id_base) = explode('/', $this->page_id);
6a501b41907f I'm pretty sure this fixes title issues
Dan Fuhry <dan@enanocms.org>
parents: 22
diff changeset
   169
      if ( $page_id_base == 'Portal' || $page_id_base == 'Article' || $page_id_base == 'Archive' )
17
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   170
      {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   171
        $config_title = getConfig('nb_portal_title');
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   172
        $this->cdata = array(
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   173
            'urlname' => $this->page_id,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   174
            'namespace' => $this->namespace,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   175
            'name' => $this->page_id == 'Portal' ? ( !empty($config_title) ? $config_title : "Welcome to " . getConfig('site_name') ) : 'News archive',
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   176
            'special' => 1,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   177
            'comments_on' => 0,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   178
            'protected' => 0,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   179
            'wiki_mode' => 0,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   180
            'visible' => 1,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   181
            'delvotes' => 0,
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   182
            'delvote_ips' => ''
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   183
          );
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   184
        $this->cdata = Namespace_Default::bake_cdata($this->cdata);
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   185
        $this->title =& $this->cdata['name'];
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   186
      }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   187
      else
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   188
      {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   189
        parent::build_cdata();
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   190
      }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   191
    }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   192
    
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   193
    function set_conds()
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   194
    {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   195
      parent::set_conds();
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   196
      if ( $this->page_id == 'Portal' || $this->page_id == 'Archive' )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   197
      {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   198
        $this->conds['edit'] = false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   199
        $this->conds['password'] = false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   200
        $this->conds['clearlogs'] = false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   201
      }
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   202
    }
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   203
    
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   204
    function send()
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   205
    {
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   206
      ob_start();
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   207
      NewsBoy_namespace_handler($this);
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   208
      if ( ob_get_contents() == '' )
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   209
      {
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   210
        parent::send();
15
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   211
      }
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   212
      // transfer OB to parent
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   213
      $c = ob_get_contents();
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   214
      ob_end_clean();
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   215
      echo $c;
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   216
    }
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   217
  }
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   218
}
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   219
17
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   220
function NewsBoy_resolve_article_url($url)
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   221
{
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   222
  global $db, $session, $paths, $template, $plugins; // Common objects
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   223
  
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   224
  if ( !preg_match('#^Article/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+?)$#', $url, $id_match) )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   225
  {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   226
    return false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   227
  }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   228
  // look around for this page
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   229
  // int mktime  ([ int $hour  [, int $minute  [, int $second  [, int $month  [, int $day  [, int $year  [, int $is_dst  ]]]]]]] )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   230
  $timestamp_min = gmmktime(0, 0, 0, intval($id_match[2]), intval($id_match[3]), intval($id_match[1]));
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   231
  $timestamp_max = $timestamp_min + 86400;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   232
  // mysql and postgresql friendly
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   233
  $integer_prepend = ( ENANO_DBLAYER == 'MYSQL' ) ? "unsigned" : '';
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   234
  $q = $db->sql_query('SELECT urlname, name FROM ' . table_prefix . "pages WHERE CAST(urlname AS $integer_prepend integer) >= $timestamp_min AND CAST(urlname AS $integer_prepend integer) <= $timestamp_max AND namespace = 'NewsBoy';");
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   235
  if ( !$q )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   236
    $db->_die();
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   237
  if ( $db->numrows() < 1 )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   238
    return false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   239
  // found a page
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   240
  $found_match = false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   241
  while ( $row = $db->fetchrow($q) )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   242
  {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   243
    if ( sanitize_page_id($row['name']) === $id_match[4] )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   244
    {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   245
      $found_match = true;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   246
      // we have a definitive match, send the page through
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   247
      return $row['urlname'];
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   248
    }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   249
  }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   250
  if ( !$found_match )
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   251
  {
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   252
    // can't find it.
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   253
    return false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   254
  }
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   255
  return false;
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   256
}
f6edf51a9479 Now compatible with Enano rev. 953.
Dan
parents: 16
diff changeset
   257
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   258
function NewsBoy_set_page_string()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   259
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   260
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   261
  if ( $paths->namespace == 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   262
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   263
    if ( $paths->cpage['urlname_nons'] == 'Portal' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   264
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   265
      $template->namespace_string = 'portal';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   266
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   267
      // block editing
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   268
      $perm_arr = Array('edit_page' => AUTH_DENY, 'view_source' => AUTH_DENY);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   269
      $session->acl_merge_with_current($perm_arr, false, 2);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   270
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   271
    else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   272
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   273
      $template->namespace_string = 'news item';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   274
    }
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
function NewsBoy_format_title($title)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   279
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   280
  $title = strtolower($title);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   281
  $title = preg_replace('/\W/', '-', $title);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   282
  $title = preg_replace('/([-]+)/', '-', $title);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   283
  $title = trim($title, '-');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   284
  return $title;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   285
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   286
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   287
function NewsBoy_feed_handler($mode)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   288
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   289
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   290
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   291
  if ( $mode != 'news' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   292
    return;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   293
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   294
  $limit = ( $x = $paths->getParam(1) ) ? $x : 20;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   295
  $limit = intval($limit);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   296
  if ( $limit > 50 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   297
    $limit = 50;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   298
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   299
  $title = getConfig('site_name') . ': Site news';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   300
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   301
  $x = getConfig('nb_portal_title');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   302
  $desc = ( empty($x) ) ? 'Welcome to ' . getConfig('site_name') : $x;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   303
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   304
  $link = makeUrlComplete('NewsBoy', 'Portal');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   305
  $generator = 'Enano CMS ' . enano_version() . ' - NewsBoy plugin';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   306
  $email = getConfig('contact_email');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   307
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   308
  $rss = new RSS($title, $desc, $link, $generator, $email);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   309
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   310
  $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
   311
         LEFT JOIN '.table_prefix.'comments AS c
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   312
           ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   313
         LEFT JOIN '.table_prefix.'logs AS l
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   314
           ON ( l.page_id=p.urlname AND l.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   315
         LEFT JOIN '.table_prefix.'users AS u
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   316
           ON ( u.username=l.author )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   317
         LEFT JOIN '.table_prefix.'page_text AS t
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   318
           ON ( t.page_id=p.urlname AND t.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   319
         WHERE p.namespace=\'NewsBoy\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   320
           AND l.action=\'create\'
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   321
           AND p.urlname '.(ENANO_DBLAYER == 'MYSQL'?'REGEXP':'~').' \'^([0-9]+)$\'
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   322
           AND p.visible=1
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   323
         GROUP BY p.urlname, p.page_order, p.name, p.namespace, p.special, p.visible, p.comments_on, p.page_format, p.protected,
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   324
           p.wiki_mode, p.delvotes, p.password, p.delvote_ips, l.time_id, l.author, u.user_level, t.page_text
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   325
         ORDER BY urlname DESC
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   326
         LIMIT '.$limit.';';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   327
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   328
  $q = $db->sql_unbuffered_query($sql);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   329
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   330
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   331
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   332
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   333
  $formatter = new NewsBoyFormatter();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   334
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   335
  if ( $row = $db->fetchrow() )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   336
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   337
    do {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   338
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   339
      $title = $row['name'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   340
      $link = makeUrlComplete('NewsBoy', $row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   341
      $desc = RenderMan::render($row['page_text']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   342
      $time = intval($row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   343
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   344
      $rss->add_item($title, $link, $desc, $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   345
      
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   346
    } while ( $row = $db->fetchrow() );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   347
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   348
  else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   349
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   350
    $rss->add_item('Error', $link, 'No news items yet.', time());
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   351
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   352
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   353
  echo $rss->render();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   354
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   355
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   356
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   357
function NewsBoy_portal()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   358
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   359
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   360
  
5
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   361
  if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-post.tpl" ) )
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   362
  {
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   363
    $parser = $template->makeParser("newsboy-post.tpl");
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   364
  }
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   365
  else
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   366
  {
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   367
    $news_template = <<<TPLCODE
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   368
    <div class="tblholder news">
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   369
      <table border="0" cellspacing="1" cellpadding="4" style="width: 100%;">
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   370
        <tr>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   371
          <th><a href="{LINK}" style="color: inherit;">{TITLE}</a></th>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   372
        </tr>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   373
        <tr>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   374
          <td class="row3">
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   375
            {CONTENT}
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   376
          </td>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   377
        </tr>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   378
        <tr>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   379
          <th class="subhead" style="font-weight: normal; font-size: 67%;">
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   380
            Posted by {USER_LINK} on {DATE}<br />
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   381
            [ {NUM_COMMENTS} comment{COMMENT_S} | {COMMENT_LINK} ]
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   382
          </th>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   383
        </tr>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   384
      </table>
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   385
    </div>
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   386
TPLCODE;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   387
  
5
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   388
    $parser = $template->makeParserText($news_template);
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   389
  }
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   390
  
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   391
  /*
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   392
  $p = RenderMan::strToPageID(getConfig('main_page'));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   393
  if ( $p[1] != 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   394
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   395
    echo RenderMan::getPage($p[0], $p[1]);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   396
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   397
  else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   398
  { */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   399
    /*
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   400
    $s = $paths->nslist['NewsBoy'] . 'Announce';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   401
    if ( isPage($s) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   402
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   403
      $p = RenderMan::getPage('Announce', 'NewsBoy');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   404
      echo $p;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   405
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   406
  /* } */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   407
  
6
432eed804b7f Fixed some logic bugs with the announcement page
Dan
parents: 5
diff changeset
   408
  $announce_page_default = $paths->nslist['NewsBoy'] . 'Announce';
432eed804b7f Fixed some logic bugs with the announcement page
Dan
parents: 5
diff changeset
   409
  $s = $announce_page_default;
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   410
  $announce_page = getConfig('nb_announce_page');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   411
  if ( !empty($announce_page) && isPage($announce_page) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   412
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   413
    $s = $announce_page;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   414
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   415
  else if ( !isPage($s) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   416
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   417
    $s = false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   418
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   419
  if ( $s )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   420
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   421
    $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
   422
    // 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
   423
    $paths->pages[$s]['special'] = 1;
1
540d077b7612 Fix stupid announcement link bug; replace getPage call with PageProcessor
Dan
parents: 0
diff changeset
   424
    $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
   425
    $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
   426
    $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
   427
    eval($content);
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   428
  }
6
432eed804b7f Fixed some logic bugs with the announcement page
Dan
parents: 5
diff changeset
   429
  else
432eed804b7f Fixed some logic bugs with the announcement page
Dan
parents: 5
diff changeset
   430
  {
432eed804b7f Fixed some logic bugs with the announcement page
Dan
parents: 5
diff changeset
   431
    $stuff = RenderMan::strToPageID($announce_page_default);
432eed804b7f Fixed some logic bugs with the announcement page
Dan
parents: 5
diff changeset
   432
  }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   433
  
5
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   434
  if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-pre.tpl" ) )
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   435
  {
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   436
    $parser_pre = $template->makeParser("newsboy-portal-pre.tpl");
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   437
    echo $parser_pre->run();
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   438
  }
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   439
  else
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   440
  {
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   441
    echo '<h2>Latest news</h2>';
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   442
  }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   443
    
19
93c01ea4366b Main portal query is now buffered (but limits selection size) to fix some 1.1.6 issues
Dan
parents: 18
diff changeset
   444
  $num_articles = intval(getConfig('nb_portal_num_articles', 5));
93c01ea4366b Main portal query is now buffered (but limits selection size) to fix some 1.1.6 issues
Dan
parents: 18
diff changeset
   445
  
93c01ea4366b Main portal query is now buffered (but limits selection size) to fix some 1.1.6 issues
Dan
parents: 18
diff changeset
   446
  $q = $db->sql_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
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   447
         LEFT JOIN '.table_prefix.'comments AS c
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   448
           ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   449
         LEFT JOIN '.table_prefix.'page_text AS t
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   450
           ON ( t.page_id=p.urlname AND t.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
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   454
           ON ( u.username=l.author )
0
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!=\'Announce\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   458
           AND p.visible=1
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   459
         GROUP BY p.urlname, p.page_order, p.name, p.namespace, p.special, p.visible, p.comments_on, p.page_format, p.protected,
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   460
           p.wiki_mode, p.delvotes, p.password, p.delvote_ips, t.page_text, l.time_id, l.author, u.user_level
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   461
         ORDER BY p.urlname DESC
19
93c01ea4366b Main portal query is now buffered (but limits selection size) to fix some 1.1.6 issues
Dan
parents: 18
diff changeset
   462
         LIMIT ' . ($num_articles + 1) . ';');
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   463
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   464
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   465
  
19
93c01ea4366b Main portal query is now buffered (but limits selection size) to fix some 1.1.6 issues
Dan
parents: 18
diff changeset
   466
  if ( $row = $db->fetchrow($q) )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   467
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   468
    $i = 0;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   469
    do
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   470
    {
16
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
   471
      if ( $i < $num_articles )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   472
      {
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   473
        $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
   474
        
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   475
        $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
   476
        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
   477
        {
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   478
          $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
   479
          $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
   480
        }
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   481
        
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   482
        $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
   483
        $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
   484
        
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   485
        if ( strlen($content) > 400 && !$trimmed )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   486
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   487
          $content = nb_trim_paragraph($content, 400, $trimmed);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   488
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   489
        if ( $trimmed )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   490
        {
14
a5263dadedf3 "Read more" links use the new syntax now.
Dan
parents: 13
diff changeset
   491
          $link = ' <a href="' . nb_make_article_url($row['urlname'], $row['name']) . '">Read more...</a>';
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   492
          $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
   493
          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
   494
          {
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   495
            $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
   496
          }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   497
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   498
        $user_link = nb_make_username_link($row['author'], $row['user_level']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   499
        $date = date('F d, Y h:i:s a', $row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   500
        $num_comments = $row['num_comments'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   501
        $comment_s = ( $num_comments == 1 ) ? '' : 's';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   502
        $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
   503
        $parser->assign_vars(array(
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   504
            'TITLE' => $title,
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   505
            'LINK' => nb_make_article_url($row['urlname'], $row['name']),
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   506
            'CONTENT' => $content,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   507
            'USER_LINK' => $user_link,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   508
            'DATE' => $date,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   509
            'NUM_COMMENTS' => $num_comments,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   510
            'COMMENT_S' => $comment_s,
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   511
            'COMMENT_LINK' => $comment_link
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   512
          ));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   513
        echo $parser->run();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   514
      }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   515
      else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   516
      {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   517
        echo '<p><a href="'.makeUrlNS('NewsBoy', 'Archive').'">Older news...</a></p>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   518
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   519
      }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   520
      $i++;
19
93c01ea4366b Main portal query is now buffered (but limits selection size) to fix some 1.1.6 issues
Dan
parents: 18
diff changeset
   521
    } while ( $row = $db->fetchrow($q) );
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   522
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   523
  else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   524
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   525
    echo '<p>No news items yet.</p>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   526
  }
9
162b0f10e3d0 Fixed a few issues with timestamp and Article/* matching
Dan
parents: 8
diff changeset
   527
  $db->free_result();
5
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   528
  if ( file_exists( ENANO_ROOT . "/themes/{$template->theme}/newsboy-portal-post.tpl" ) )
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   529
  {
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   530
    $parser_post = $template->makeParser("newsboy-portal-post.tpl");
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   531
    echo $parser_post->run();
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   532
  }
fed61fc8895b Added support for a custom template (newsboy-post.tpl) and templates to be shown before and after news content
Dan
parents: 4
diff changeset
   533
  
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   534
  if ( $session->user_level >= USER_LEVEL_ADMIN )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   535
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   536
    echo '<div class="tblholder" style="margin: 10px auto 0 auto; display: table;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   537
            <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   538
              <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   539
                <th>Administrative tools:</th>
3
8ae9acb2e919 Re-implement announcement link fix, blame it on my bad Hg repo management
Dan
parents: 2
diff changeset
   540
                <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
   541
                <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
   542
              </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   543
            </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   544
          </div><br />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   545
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   546
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   547
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   548
/**
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   549
 * Formats row data in the archive.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   550
 * @package Enano
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   551
 * @subpackage Newsboy
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   552
 * @license GNU General Public License
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   553
 */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   554
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   555
class NewsBoyFormatter
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   556
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   557
  function article_link($name, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   558
  {
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
   559
    $article_link = '<a href="' . nb_make_article_url($row['urlname'], $row['name']) . '">' . $row['name'] . '</a>';
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   560
    return $article_link;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   561
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   562
  function format_date($date, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   563
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   564
    $date = date('Y-m-j g:m', intval ( $date ));
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   565
    return $date;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   566
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   567
  function format_username($x, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   568
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   569
    $ul = intval($row['user_level']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   570
    $author = nb_make_username_link($row['author'], $ul);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   571
    return $author;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   572
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   573
  function format_commentlink($x, $row)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   574
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   575
    $comments = '<a href="' . makeUrlNS('NewsBoy', $row['urlname']) . '#do:comments">' . $row['num_comments'] . '</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   576
    return $comments;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   577
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   578
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   579
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   580
function NewsBoy_archive()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   581
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   582
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   583
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   584
  $lower_limit = ( isset($_GET['start']) ) ? intval($_GET['start']) : ( ( $xx = $paths->getParam(0) ) ? intval($xx) : 0 );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   585
  $entries_per_page = 50;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   586
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   587
  $row_count = $entries_per_page + 1;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   588
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   589
  // Determine number of total news entries
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   590
  $q = $db->sql_query('SELECT urlname FROM '.table_prefix.'pages WHERE namespace=\'NewsBoy\' AND urlname '.(ENANO_DBLAYER == 'MYSQL'?'REGEXP':'~').' \'^([0-9]+)$\' AND visible=1;');
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   591
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   592
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   593
  $r = $db->fetchrow();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   594
  $num_total = intval($db->numrows());
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   595
  $db->free_result();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   596
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   597
  if ( $lower_limit >= $num_total )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   598
    $lower_limit = 0;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   599
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   600
  $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
   601
         LEFT JOIN '.table_prefix.'comments AS c
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   602
           ON ( c.page_id=p.urlname AND c.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   603
         LEFT JOIN '.table_prefix.'logs AS l
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   604
           ON ( l.page_id=p.urlname AND l.namespace=p.namespace )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   605
         LEFT JOIN '.table_prefix.'users AS u
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   606
           ON ( u.username=l.author )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   607
         WHERE p.namespace=\'NewsBoy\'
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   608
           AND l.action=\'create\'
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   609
           AND p.urlname '.(ENANO_DBLAYER == 'MYSQL'?'REGEXP':'~').' \'^([0-9]+)$\'
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   610
           AND p.visible=1
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   611
         GROUP BY p.urlname, p.page_order, p.name, p.namespace, p.special, p.visible, p.comments_on, p.page_format, p.protected,
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
   612
           p.wiki_mode, p.delvotes, p.password, p.delvote_ips, l.time_id, l.author, u.user_level
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   613
         ORDER BY urlname DESC;';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   614
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   615
  $q = $db->sql_unbuffered_query($sql);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   616
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   617
  if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   618
    $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   619
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   620
  $formatter = new NewsBoyFormatter();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   621
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   622
  $callers = Array(
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   623
      'name' => Array($formatter, 'article_link'),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   624
      'urlname' => Array($formatter, 'format_date'),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   625
      'author' => Array($formatter, 'format_username'),
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   626
      'num_comments' => Array($formatter, 'format_commentlink')
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   627
    );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   628
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   629
  $head = '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   630
          <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   631
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   632
              <th>Article</th><th>Date</th><th>Author</th><th>Comments</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   633
            </tr>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   634
  $foot = "</table></div>";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   635
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   636
  $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
   637
                      $num_total, makeUrlNS('NewsBoy', 'Archive/%s'), $lower_limit, 20, $callers, $head, $foot);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   638
  echo $content;  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   639
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   640
  $code = $plugins->setHook('send_page_footers');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   641
  foreach ( $code as $cmd )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   642
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   643
    eval($cmd);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   644
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   645
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   646
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   647
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   648
function nb_make_username_link($username, $user_level)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   649
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   650
  $color = '#0000AA';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   651
  $user_level = intval($user_level);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   652
  if ( $user_level < USER_LEVEL_MEMBER ) return $username;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   653
  if ( $user_level >= USER_LEVEL_MOD ) $color = '#00AA00';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   654
  if ( $user_level >= USER_LEVEL_ADMIN ) $color = '#AA0000';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   655
  $link = '<a style="color: ' . $color . '" href="' . makeUrlNS('User', str_replace(' ', '_', $username) ) . '">' . $username . '</a>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   656
  return $link;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   657
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   658
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   659
function NewsBoy_PortalLink()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   660
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   661
  global $db, $session, $paths, $template, $plugins; // Common objects
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   662
  if ( $paths->namespace == 'NewsBoy' )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   663
    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
   664
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   665
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   666
// Administration panel
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   667
function page_Admin_NewsboyItemManager()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   668
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   669
  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
   670
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   671
  $done = false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   672
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   673
  if ( isset( $_GET['act'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   674
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   675
    switch ( $_GET['act'] )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   676
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   677
      case 'edit':
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   678
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   679
        // Error list
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   680
        $errors = Array();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   681
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   682
        if ( isset ( $_POST['submitting'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   683
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   684
          // Generate timestamp
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   685
          $year = intval($_POST['pub_year']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   686
          $month = intval($_POST['pub_month']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   687
          $day = intval($_POST['pub_day']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   688
          $hour = intval($_POST['pub_hour']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   689
          $minute = intval($_POST['pub_minute']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   690
          $second = intval($_POST['pub_second']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   691
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   692
          // Validation
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   693
          if ( $year < 1500 || $year > 10000 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   694
            $errors[] = 'Invalid year.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   695
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   696
          if ( $month < 1 || $month > 12 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   697
            $errors[] = 'Invalid month.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   698
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   699
          if ( $day < 1 || $day > 31 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   700
            $errors[] = 'Invalid day.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   701
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   702
          if ( $hour < 0 || $hour > 23 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   703
            $errors[] = 'Invalid hour.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   704
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   705
          if ( $minute < 0 || $minute > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   706
            $errors[] = 'Invalid minute.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   707
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   708
          if ( $second < 0 || $second > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   709
            $errors[] = 'Invalid second.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   710
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   711
          $name = $_POST['article_name'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   712
          $name = $db->escape($name);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   713
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   714
          $author = $_POST['author'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   715
          $author = $db->escape($author);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   716
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   717
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   718
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   719
            $time = mktime($hour, $minute, $second, $month, $day, $year);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   720
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   721
          
20
1cbefc789a46 Improved 1.1.6/1.1.7 compatibility
Dan
parents: 19
diff changeset
   722
          $time_changed = $time !== intval($_POST['page_id']);
1cbefc789a46 Improved 1.1.6/1.1.7 compatibility
Dan
parents: 19
diff changeset
   723
          if ( isPage($paths->nslist['NewsBoy'] . $time) && $time_changed ) // $paths->pages[ $paths->nslist['NewsBoy'] . $time ] != $paths->pages[ $paths->nslist['NewsBoy'] . $_POST['page_id'] ] )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   724
            $errors[] = 'You cannot have two news articles with the same publish time.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   725
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   726
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   727
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   728
            $publ = ( isset($_POST['published']) ) ? '1' : '0';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   729
            $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
   730
            $q = $db->sql_query($sql);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   731
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   732
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   733
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   734
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   735
            // Update author
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   736
            $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
   737
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   738
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   739
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   740
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   741
            // Update other tables with urlname info
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   742
            $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
   743
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   744
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   745
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   746
            $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
   747
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   748
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   749
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   750
            $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
   751
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   752
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   753
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   754
            $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
   755
            if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   756
              $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   757
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   758
            echo '<div class="info-box">Your changes have been saved.</div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   759
            
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   760
            break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   761
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   762
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   763
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   764
        if ( count($errors) > 0 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   765
          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
   766
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   767
        // Obtain page information
20
1cbefc789a46 Improved 1.1.6/1.1.7 compatibility
Dan
parents: 19
diff changeset
   768
        if ( !isPage($paths->nslist['NewsBoy'] . $_GET['id']) )
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   769
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   770
          echo 'Invalid ID';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   771
          return false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   772
        }
20
1cbefc789a46 Improved 1.1.6/1.1.7 compatibility
Dan
parents: 19
diff changeset
   773
        $page = namespace_factory($_GET['id'], 'NewsBoy');
1cbefc789a46 Improved 1.1.6/1.1.7 compatibility
Dan
parents: 19
diff changeset
   774
        $page_info = $page->get_cdata();
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   775
        $time = intval($page_info['urlname_nons']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   776
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   777
        // Get author
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   778
        $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
   779
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   780
        if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   781
          $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   782
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   783
        $row = $db->fetchrow();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   784
        $author = ( isset($row['author']) ) ? $row['author'] : '';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   785
        if ( empty($author) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   786
          $author = 'Anonymous';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   787
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   788
        // Set date & time
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   789
        $month  = date('n', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   790
        $year   = date('Y', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   791
        $day    = date('j', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   792
        $hour   = date('G', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   793
        $minute = date('m', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   794
        $second = date('s', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   795
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   796
        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
   797
        echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   798
                <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   799
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   800
                    <th colspan="2">Editing news article</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   801
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   802
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   803
                    <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
   804
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   805
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   806
                    <td class="row1">Published date:</td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   807
                    <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   808
                      <input name="pub_year" type="text" size="5" value="'.$year.'" />-<select name="pub_month">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   809
       for ( $i = 1; $i <= 12; $i++ )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   810
       {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   811
         $m = "[$i] ";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   812
         switch ( $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   813
         {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   814
           case 1:  $m .= 'January'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   815
           case 2:  $m .= 'February'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   816
           case 3:  $m .= 'March'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   817
           case 4:  $m .= 'April'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   818
           case 5:  $m .= 'May'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   819
           case 6:  $m .= 'June'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   820
           case 7:  $m .= 'July'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   821
           case 8:  $m .= 'August'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   822
           case 9:  $m .= 'September'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   823
           case 10: $m .= 'October'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   824
           case 11: $m .= 'November'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   825
           case 12: $m .= 'December'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   826
           default: $m .= 'Fuhrober'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   827
         }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   828
         if ( $month == $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   829
           echo '         <option selected="selected" value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   830
         else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   831
           echo '         <option value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   832
       }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   833
       echo '         </select>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   834
                      <input name="pub_day" type="text" size="3" value="' . $day . '" />, time:
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   835
                      <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
   836
                      <small>Note: Hours are in 24-hour format.</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   837
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   838
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   839
                  <!-- Inline developer blog, episode 1:
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   840
                       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
   841
                       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
   842
                       (b) I wouldn\'t want to offend you hackers. (j/k)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   843
                       
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   844
                       Oh crap. And no, I don\'t give towels with my showers.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   845
                       
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   846
                       -Dan
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   847
                       -->
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   848
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   849
                    <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
   850
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   851
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   852
                    <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
   853
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   854
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   855
                    <td class="row3" style="text-align: center;" colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   856
                      <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
   857
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   858
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   859
                </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   860
              </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   861
              <input type="hidden" name="submitting" value="yes" />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   862
              <input type="hidden" name="page_id" value="' . $_GET['id'] . '" />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   863
        echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   864
        $done = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   865
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   866
      case 'del':
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   867
        if ( isset( $_POST['confirmed'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   868
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   869
          $page_id = $_POST['page_id'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   870
          $namespace = 'NewsBoy';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   871
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   872
          $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
   873
          if(!$e) $db->_die('The page log entry could not be inserted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   874
          $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
   875
          if(!$e) $db->_die('The page categorization entries could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   876
          $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
   877
          if(!$e) $db->_die('The page comments could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   878
          $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
   879
          if(!$e) $db->_die('The page text entry could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   880
          $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
   881
          if(!$e) $db->_die('The page entry could not be deleted.');
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   882
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   883
          $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
   884
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   885
          echo $result . '<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   886
               <br />
15
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   887
               <a href="#" onclick="ajaxPage(\'' . $paths->cpage['module'] . '\'); return false;">Return to Newsboy</a>';
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   888
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   889
        else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   890
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   891
          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
   892
          echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   893
                  <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   894
                    <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   895
                      <th>Confirm deletion</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   896
                     </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   897
                     <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   898
                       <td class="row1" style="text-align: center;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   899
                         <p>Are you sure you want to delete this news article?</p>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   900
                       </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   901
                     </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   902
                     <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   903
                       <td class="row3" style="text-align: center;">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   904
                         <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
   905
                       </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   906
                     </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   907
                  </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   908
                </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   909
                <input type="hidden" name="confirmed" value="yes" />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   910
                <input type="hidden" name="page_id" value="' . intval ( $_GET['id'] ) . '" />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   911
          echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   912
        }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   913
        $done = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   914
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   915
      case 'create':
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   916
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   917
        // Error list
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   918
        $errors = Array();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   919
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   920
        if ( isset ( $_POST['submitting'] ) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   921
        {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   922
          // Generate timestamp
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   923
          $year = intval($_POST['pub_year']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   924
          $month = intval($_POST['pub_month']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   925
          $day = intval($_POST['pub_day']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   926
          $hour = intval($_POST['pub_hour']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   927
          $minute = intval($_POST['pub_minute']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   928
          $second = intval($_POST['pub_second']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   929
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   930
          // Validation
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   931
          if ( $year < 1500 || $year > 10000 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   932
            $errors[] = 'Invalid year.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   933
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   934
          if ( $month < 1 || $month > 12 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   935
            $errors[] = 'Invalid month.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   936
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   937
          if ( $day < 1 || $day > 31 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   938
            $errors[] = 'Invalid day.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   939
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   940
          if ( $hour < 0 || $hour > 23 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   941
            $errors[] = 'Invalid hour.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   942
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   943
          if ( $minute < 0 || $minute > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   944
            $errors[] = 'Invalid minute.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   945
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   946
          if ( $second < 0 || $second > 60 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   947
            $errors[] = 'Invalid second.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   948
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   949
          $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
   950
          // This is db-escaped by PageUtils
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   951
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   952
          $author = $_POST['author'];
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   953
          $author = $db->escape($author);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   954
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   955
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   956
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   957
            $time = mktime($hour, $minute, $second, $month, $day, $year);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   958
          }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   959
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   960
          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
   961
            $errors[] = 'You cannot have two news articles with the same publish time.';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   962
          
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   963
          if ( count($errors) < 1 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   964
          {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   965
            $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
   966
            
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   967
            $page = new PageProcessor((string)$time, 'NewsBoy');
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   968
            $page->create_page($name, $publ);
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   969
            
15
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   970
            if ( $page->update_page($_POST['content'], 'Initial revision', false, 'wikitext') )
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   971
            {
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   972
              echo '<div class="info-box">Your changes have been saved.</div>';
15
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   973
              break;
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   974
            }
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   975
            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
   976
            {
10
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   977
              while ( $err = $page->pop_error() )
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   978
              {
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   979
                $errors[] = $err;
0d52ee49c11c Whoops, did article creation really still use PageUtils? Deprecated in favor of PageProcessor. Should work but not fully with 1.1.5. (Published checkbox will always be treated as if checked)
Dan
parents: 9
diff changeset
   980
              }
15
f0cf0b512fbb Fixed more 1.1.6 bugs
Dan
parents: 14
diff changeset
   981
              $done = false;
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   982
            }
0
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
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   986
        if ( count($errors) > 0 )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   987
          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
   988
        
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
   989
        $time = time();
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   990
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   991
        // Get author
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   992
        $author = $session->username;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   993
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   994
        if ( empty($author) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   995
          $author = 'Anonymous';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   996
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   997
        // Set date & time
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   998
        $month  = date('n', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
   999
        $year   = date('Y', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1000
        $day    = date('j', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1001
        $hour   = date('G', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1002
        $minute = date('m', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1003
        $second = date('s', $time);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1004
        
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
  1005
        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
  1006
        echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1007
                <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1008
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1009
                    <th colspan="2">Creating news article</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1010
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1011
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1012
                    <td class="row1">Article name:</td><td class="row2"><input name="article_name" value="" /></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="row1">Published datestamp:</td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1016
                    <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1017
                      <input name="pub_year" type="text" size="5" value="'.$year.'" />-<select name="pub_month">';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1018
       for ( $i = 1; $i <= 12; $i++ )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1019
       {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1020
         $m = "[$i] ";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1021
         switch ( $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1022
         {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1023
           case 1:  $m .= 'January'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1024
           case 2:  $m .= 'February'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1025
           case 3:  $m .= 'March'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1026
           case 4:  $m .= 'April'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1027
           case 5:  $m .= 'May'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1028
           case 6:  $m .= 'June'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1029
           case 7:  $m .= 'July'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1030
           case 8:  $m .= 'August'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1031
           case 9:  $m .= 'September'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1032
           case 10: $m .= 'October'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1033
           case 11: $m .= 'November'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1034
           case 12: $m .= 'December'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1035
           default: $m .= 'Fuhrober'; break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1036
         }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1037
         if ( $month == $i )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1038
           echo '         <option selected="selected" value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1039
         else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1040
           echo '         <option value="' . $i . '">'.$m.'</option>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1041
       }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1042
       echo '         </select>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1043
                      <input name="pub_day" type="text" size="3" value="' . $day . '" />, time:
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1044
                      <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
  1045
                      <small>Note: Hours are in 24-hour format.</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1046
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1047
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1048
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1049
                    <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
  1050
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1051
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1052
                    <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
  1053
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1054
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1055
                    <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
  1056
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1057
                  <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1058
                    <td class="row3" style="text-align: center;" colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1059
                      <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
  1060
                    </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1061
                  </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1062
                </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1063
              </div>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1064
              <input type="hidden" name="submitting" value="yes" />';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1065
        echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1066
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1067
        $done = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1068
        break;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1069
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1070
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1071
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1072
  if ( !$done )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1073
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1074
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1075
    // Start output
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1076
    echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1077
      <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1078
        <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1079
          <th>Name</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1080
          <th>Date published</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1081
          <th colspan="3">Actions</th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1082
        </tr>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1083
        
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1084
    $row_class = 'row2';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1085
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1086
    // List existing news entries
21
af40ef1982dd Improved PostgreSQL compatibility
phirox
parents: 19
diff changeset
  1087
    $q = $db->sql_query('SELECT name,urlname FROM '.table_prefix.'pages WHERE namespace=\'NewsBoy\' AND urlname!=\'Announce\' ORDER BY name ASC;');
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1088
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1089
    if ( !$q )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1090
      $db->_die();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1091
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1092
    if ( $row = $db->fetchrow($q) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1093
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1094
      do {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1095
        $row_class = ( $row_class == 'row1' ) ? 'row2' : 'row1';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1096
        $ts = intval($row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1097
        $date = date('F d, Y h:i a', $ts);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1098
        $edit_url = makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=edit&id={$row['urlname']}", true);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1099
        $dele_url = makeUrlNS('Special', 'Administration', "module={$paths->cpage['module']}&act=del&id={$row['urlname']}", true);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1100
        $page_url = makeUrlNS('NewsBoy', $row['urlname']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1101
        echo "<tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1102
                <td class='$row_class' style='width: 50%;'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1103
                  {$row['name']}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1104
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1105
                <td class='$row_class' style='width: 40%;'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1106
                  $date
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1107
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1108
                <td class='$row_class'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1109
                  <a href='$edit_url'>Settings</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1110
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1111
                <td class='$row_class'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1112
                  <a href='$page_url' onclick='window.open(this.href); return false;'>Page</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1113
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1114
                <td class='$row_class'>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1115
                  <a href='$dele_url'>Delete</a>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1116
                </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1117
              </tr>";
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1118
      } while ( $row = $db->fetchrow($q) );
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1119
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1120
    else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1121
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1122
      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
  1123
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1124
    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
  1125
          </table></div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1126
    $db->free_result();
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1127
    
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1128
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1129
  
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1130
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1131
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1132
function page_Admin_NewsboyConfiguration()
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1133
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1134
  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
  1135
  if ( isset($_POST['submit']) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1136
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1137
    setConfig('nb_portal_title', $_POST['portal_name']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1138
    if ( isPage($_POST['announce_page']) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1139
      setConfig('nb_announce_page', $_POST['announce_page']);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1140
    else
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1141
      setConfig('nb_announce_page', '');
16
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1142
    
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1143
    $num_articles = intval($_POST['num_articles']);
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1144
    if ( $num_articles > 0 )
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1145
      setConfig('nb_portal_num_articles', $num_articles);
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1146
    
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1147
    // Submit
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1148
    echo '<div class="info-box">Your changes have been saved.</div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1149
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1150
  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
  1151
  echo '<div class="tblholder">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1152
          <table border="0" cellspacing="1" cellpadding="4">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1153
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1154
              <th colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1155
                Newsboy portal: General configuration
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1156
              </th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1157
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1158
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1159
              <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1160
                Portal title:<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1161
                <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
  1162
                portal. If you don\'t enter anything here, a default will be used.</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1163
              </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1164
              <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
  1165
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1166
            <tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1167
              <td class="row2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1168
                Page to embed as announcement:<br />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1169
                <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
  1170
                portal. The default is "' . $paths->nslist['NewsBoy'] . 'Announce".</small>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1171
              </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1172
              <td class="row1">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1173
                ' . $template->pagename_field('announce_page', htmlspecialchars(getConfig('nb_announce_page'))) . '
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1174
              </td>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1175
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1176
            <tr>
16
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1177
              <td class="row2">
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1178
                Number of articles to show on portal:
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1179
              </td>
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1180
              <td class="row1">
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1181
                <input type="text" name="num_articles" value="' . getConfig('nb_portal_num_articles', '5') . '" size="7" />
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1182
              </td>
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1183
            </tr>
3d96dbb770b5 Added ability to change number of articles shown on portal.
Dan
parents: 15
diff changeset
  1184
            <tr>
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1185
              <th class="subhead" colspan="2">
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1186
                <input type="submit" name="submit" value="Save changes" />
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1187
              </th>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1188
            </tr>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1189
          </table>
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1190
        </div>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1191
  echo '</form>';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1192
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1193
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1194
/**
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1195
 * Trims a wad of text to the specified length.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1196
 * @todo make HTML friendly (don't break tags)
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1197
 * @param string The text to trim
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1198
 * @param int The maximum length to trim the text to.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1199
 * @param bool Reference. Set to true if the text was trimmed, otherwise set to false.
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1200
 */
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1201
2
66b299fdb9ca Fixed Wicked Flea's bug (apostrophes in page title) and fixed error checking on PageUtils::createpage return
Dan
parents: 1
diff changeset
  1202
function nb_trim_paragraph($text, $len = 500, &$trimmed)
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1203
{
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1204
  $trimmed = false;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1205
  if ( strlen($text) <= $len )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1206
    return $text;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1207
  $trimmed = true;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1208
  $text = substr($text, 0, $len);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1209
  for ( $i = $len; $i > 0; $i-- )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1210
  {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1211
    $chr = $text{$i-1};
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1212
    if ( preg_match('/[\s]/', $chr) )
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1213
    {
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1214
      $text = substr($text, 0, $i - 1);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1215
      $text .= '...';
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1216
      return $text;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1217
    }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1218
    $text = substr($text, 0, $i);
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1219
  }
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1220
  return $text;
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1221
}
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1222
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1223
/**
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1224
 * Generates a link to the given Newsboy article given the article name and timestamp
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1225
 * @param int Article timestamp
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1226
 * @param string Article title
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1227
 * @return string
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1228
 */
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1229
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1230
function nb_make_article_url($timestamp, $title = false)
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1231
{
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1232
  if ( !$title )
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1233
    return makeUrlNS('NewsBoy', $timestamp);
9
162b0f10e3d0 Fixed a few issues with timestamp and Article/* matching
Dan
parents: 8
diff changeset
  1234
  $day = gmdate('d', $timestamp);
162b0f10e3d0 Fixed a few issues with timestamp and Article/* matching
Dan
parents: 8
diff changeset
  1235
  $year = gmdate('Y', $timestamp);
162b0f10e3d0 Fixed a few issues with timestamp and Article/* matching
Dan
parents: 8
diff changeset
  1236
  $month = gmdate('m', $timestamp);
7
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1237
  return makeUrlNS('NewsBoy', "Article/$year/$month/$day/" . sanitize_page_id($title));
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1238
}
c3710cbed6d0 Modified article links and stuff to be more SEO-friendly. Here ends 1.0.x compatibility!
Dan
parents: 6
diff changeset
  1239
0
9f29b32e5224 Initial repository population
dan@fuhry
parents:
diff changeset
  1240
?>