includes/namespaces/file.php
author Dan
Thu, 17 Dec 2009 04:27:50 -0500
changeset 1168 277a9cdead3e
parent 1114 4f4d63a281cd
child 1227 bdac73ed481e
permissions -rw-r--r--
Namespace_Default: added a workaround for an inconsistency in SQL. Basically, if you join the same table multiple times under multiple aliases, COUNT() always uses the first instance. Was affecting the comment counter in the "discussion" button.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     1
<?php
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     2
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     3
/*
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 953
diff changeset
     5
 * Copyright (C) 2006-2009 Dan Fuhry
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     6
 *
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     7
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     8
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
     9
 *
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    12
 */
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    13
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    14
class Namespace_File extends Namespace_Default
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    15
{
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    16
  function send()
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    17
  {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    18
    global $output;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    19
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    20
    $output->add_before_footer($this->show_info());
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    21
    $output->add_before_footer($this->display_categories());
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    22
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    23
    if ( $this->exists )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    24
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    25
      $this->send_from_db();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    26
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    27
    else
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    28
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    29
      $output->header();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    30
      $this->error_404();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    31
      $output->footer();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    32
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    33
  }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    34
  
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    35
  function show_info()
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    36
  {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    37
    global $db, $session, $paths, $template, $plugins; // Common objects
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    38
    global $lang;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    39
    
912
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
    40
    require_once(ENANO_ROOT . '/includes/log.php');
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
    41
    
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    42
    $local_page_id = $this->page_id;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    43
    $local_namespace = $this->namespace;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    44
    $html = '';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    45
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    46
    // Prevent unnecessary work
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    47
    if ( $local_namespace != 'File' )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    48
      return null;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    49
    
953
323c4cd1aa37 Made some more changes to the way namespaces are handled, for optimization purposes. This is a bit of a structural reorganization: $paths->pages is obsoleted in its entirety; calculating page existence and metadata is now the job of the Namespace_* backend class. There are many things in PageProcessor that should be reorganized, and page actions in general should really be rethought. This is probably the beginning of a long process that will be taking place over the course of the betas.
Dan
parents: 912
diff changeset
    50
    $selfn = $db->escape($this->page_id);
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    51
    $q = $db->sql_query('SELECT f.mimetype,f.time_id,f.size,l.log_id FROM ' . table_prefix . "files AS f\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    52
                      . "  LEFT JOIN " . table_prefix . "logs AS l\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    53
                      . "    ON ( l.time_id = f.time_id AND ( l.action = 'reupload' OR l.action IS NULL ) )\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    54
                      . "  WHERE f.page_id = '$selfn'\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    55
                      . "    ORDER BY f.time_id DESC;");
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    56
    if ( !$q )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    57
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    58
      $db->_die('The file type could not be fetched.');
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    59
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    60
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    61
    if ( $db->numrows() < 1 )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    62
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    63
      $html .= '<div class="mdg-comment" style="margin-left: 0;">
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    64
              <h3>' . $lang->get('onpage_filebox_heading') . '</h3>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    65
              <p>' . $lang->get('onpage_filebox_msg_not_found', array('upload_link' => makeUrlNS('Special', 'UploadFile/'.$local_page_id))) . '</p>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    66
            </div>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    67
            <br />';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    68
      return $html;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    69
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    70
    $r = $db->fetchrow();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    71
    $mimetype = $r['mimetype'];
1081
745200a9cc2a Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
parents: 953
diff changeset
    72
    $datestring = enano_date(ED_DATE | ED_TIME, (int)$r['time_id']);
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    73
    $html .= '<div class="mdg-comment" style="margin-left: 0;">
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    74
            <h3>' . $lang->get('onpage_filebox_heading') . '</h3>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    75
            <p>' . $lang->get('onpage_filebox_lbl_type') . ' '.$r['mimetype'].'<br />';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    76
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    77
    $size = $r['size'] . ' ' . $lang->get('etc_unit_bytes');
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    78
    if ( $r['size'] >= 1048576 )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    79
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    80
      $size .= ' (' . ( round($r['size'] / 1048576, 1) ) . ' ' . $lang->get('etc_unit_megabytes_short') . ')';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    81
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    82
    else if ( $r['size'] >= 1024 )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    83
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    84
      $size .= ' (' . ( round($r['size'] / 1024, 1) ) . ' ' . $lang->get('etc_unit_kilobytes_short') . ')';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    85
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    86
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    87
    $html .= $lang->get('onpage_filebox_lbl_size', array('size' => $size));
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    88
    
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    89
    $html .= '<br />' . $lang->get('onpage_filebox_lbl_uploaded') . ' ' . $datestring . '</p>';
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
    90
    // are we dealing with an image?
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
    91
    $is_image = substr($mimetype, 0, 6) == 'image/';
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
    92
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
    93
    // for anything other than plain text and 
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
    94
    if ( !$is_image && ( substr($mimetype, 0, 5) != 'text/' || $mimetype == 'text/html' || $mimetype == 'text/javascript' ) )
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    95
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    96
      $html .= '<div class="warning-box">
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    97
              ' . $lang->get('onpage_filebox_msg_virus_warning') . '
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    98
            </div>';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
    99
    }
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   100
    if ( $is_image )
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   101
    {
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   102
      // show a thumbnail of the image
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   103
      $html .= '<p>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   104
              <a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn).'">
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   105
                <img style="border: 0;" alt="' . htmlspecialchars($paths->page) . '" src="' . makeUrlNS('Special', "DownloadFile/$selfn/{$r['time_id']}", 'preview', true) . '" />
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   106
              </a>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   107
            </p>';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   108
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   109
    $html .= '<p>
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   110
            <a href="'.makeUrlNS('Special', 'DownloadFile'.'/'.$selfn.'/'.$r['time_id'].htmlspecialchars(urlSeparator).'download').'">
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   111
              ' . $lang->get('onpage_filebox_btn_download') . '
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   112
            </a>';
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   113
    // allow reupload if:
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   114
    //   * we are allowed to upload new versions, and
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   115
    //      - the file is unprotected, or
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   116
    //      - we have permission to override protection
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   117
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   118
    if ( !$this->perms )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   119
      $this->perms = $session->fetch_page_acl($this->page_id, $this->namespace);
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   120
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   121
    if ( $this->perms->get_permissions('upload_new_version') && ( !$this->page_protected || $this->perms->get_permissions('even_when_protected') ) )
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   122
    {
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   123
      // upload new version link
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   124
      $html .= '  |  <a href="'.makeUrlNS('Special', "UploadFile/$selfn", false, true).'">
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   125
              ' . $lang->get('onpage_filebox_btn_upload_new') . '
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   126
            </a>';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   127
    }
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   128
    // close off paragraph
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   129
    $html .= '</p>';
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   130
    // only show this if there's more than one revision
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   131
    if ( $db->numrows() > 1 )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   132
    {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   133
      // requery, sql_result_seek() doesn't work on postgres
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   134
      $db->free_result();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   135
      $q = $db->sql_query('SELECT f.mimetype,f.time_id,f.size,l.log_id FROM ' . table_prefix . "files AS f\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   136
                      . "  LEFT JOIN " . table_prefix . "logs AS l\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   137
                      . "    ON ( l.time_id = f.time_id AND ( l.action = 'reupload' OR l.action IS NULL ) )\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   138
                      . "  WHERE f.page_id = '$selfn'\n"
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   139
                      . "    ORDER BY f.time_id DESC;");
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   140
      if ( !$q )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   141
        $db->_die();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   142
      
912
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   143
      $log = new LogDisplay();
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   144
      $log->add_criterion('page', $paths->nslist['File'] . $this->page_id);
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   145
      $log->add_criterion('action', 'reupload');
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   146
      $data = $log->get_data();
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   147
      $i = -1;
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   148
      
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   149
      $html .= '<h3>' . $lang->get('onpage_filebox_heading_history') . '</h3><p>';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   150
      $last_rollback_id = false;
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   151
      $download_flag = $is_image ? false : 'download';
912
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   152
      while ( $r = $db->fetchrow($q) )
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   153
      {
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   154
        $html .= '(<a href="'.makeUrlNS('Special', "DownloadFile/$selfn/{$r['time_id']}", $download_flag, true).'">' . $lang->get('onpage_filebox_btn_this_version') . '</a>) ';
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   155
        if ( $session->get_permissions('history_rollback') && $last_rollback_id )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   156
          $html .= ' (<a href="#rollback:' . $last_rollback_id . '" onclick="ajaxRollback(\''.$last_rollback_id.'\'); return false;">' . $lang->get('onpage_filebox_btn_revert') . '</a>) ';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   157
        else if ( $session->get_permissions('history_rollback') && !$last_rollback_id )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   158
          $html .= ' (' . $lang->get('onpage_filebox_btn_current') . ') ';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   159
        $last_rollback_id = $r['log_id'];
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   160
        
912
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   161
        $html .= $r['mimetype'].', ';
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   162
        
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   163
        $fs = $r['size'];
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   164
        $fs = (int)$fs;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   165
        
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   166
        if($fs >= 1048576)
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   167
        {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   168
          $fs = round($fs / 1048576, 1);
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   169
          $size = $fs . ' ' . $lang->get('etc_unit_megabytes_short');
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   170
        }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   171
        else
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   172
        if ( $fs >= 1024 )
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   173
        {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   174
          $fs = round($fs / 1024, 1);
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   175
          $size = $fs . ' ' . $lang->get('etc_unit_kilobytes_short');
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   176
        }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   177
        else
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   178
        {
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   179
          $size = $fs . ' ' . $lang->get('etc_unit_bytes');
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   180
        }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   181
        
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   182
        $html .= $size;
912
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   183
        if ( isset($data[++$i]) )
95d0d8596c87 File rollbacks should be all up to date now.
Dan
parents: 801
diff changeset
   184
          $html .= ': ' . LogDisplay::render_row($data[$i], false, false);
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   185
        
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   186
        $html .= '<br />';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   187
      }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   188
      $html .= '</p>';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   189
    }
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   190
    $db->free_result();
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   191
    $html .= '</div><br />';
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   192
    return $html;
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   193
  }
1114
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   194
  
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   195
  /**
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   196
   * Delete a file from the database and filesystem based on file ID.
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   197
   * @param int File ID
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   198
   * @return null
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   199
   */
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   200
  
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   201
  public static function delete_file($file_id)
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   202
  {
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   203
    global $db, $session, $paths, $template, $plugins; // Common objects
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   204
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   205
    if ( !is_int($file_id) )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   206
      // seriously?
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   207
      return null;
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   208
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   209
    // pull file info
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   210
    $q = $db->sql_query('SELECT filename, page_id, time_id, file_extension, file_key FROM ' . table_prefix . "files WHERE file_id = $file_id;");
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   211
    if ( !$q )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   212
      $db->_die();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   213
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   214
    if ( $db->numrows() < 1 )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   215
    {
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   216
      $db->free_result();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   217
      return null;
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   218
    }
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   219
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   220
    $row = $db->fetchrow();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   221
    $db->free_result();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   222
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   223
    // make sure the image isn't used by multiple revisions
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   224
    $q = $db->sql_query('SELECT 1 FROM ' . table_prefix . "files WHERE file_key = '{$row['file_key']}';");
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   225
    if ( !$q )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   226
      $db->_die();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   227
    if ( $db->numrows() < 1 )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   228
    {
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   229
      // remove from filesystem
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   230
      $file_path = ENANO_ROOT . "/files/{$row['file_key']}{$row['file_extension']}";
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   231
      @unlink($file_path);
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   232
      // old filename standard
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   233
      $file_path = ENANO_ROOT . "/files/{$row['file_key']}-{$row['time_id']}{$row['file_extension']}";
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   234
      @unlink($file_path);
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   235
    }
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   236
    $db->free_result();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   237
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   238
    // remove from cache
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   239
    if ( $dp = @opendir(ENANO_ROOT . '/cache/') )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   240
    {
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   241
      $regexp = '#' . preg_quote($row['filename']) . '-' . $row['time_id'] . '-[0-9]+x[0-9]+' . preg_quote($row['file_extension']) . '#';
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   242
      while ( $dh = @readdir($dp) )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   243
      {
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   244
        if ( preg_match($regexp, $dh) )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   245
        {
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   246
          // it's a match, delete the cached thumbnail
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   247
          @unlink(ENANO_ROOT . "/cache/$dh");
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   248
        }
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   249
      }
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   250
      closedir($dp);
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   251
    }
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   252
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   253
    // remove from database
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   254
    $q = $db->sql_query('DELETE FROM ' . table_prefix . "files WHERE file_id = $file_id;");
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   255
    if ( !$q )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   256
      $db->_die();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   257
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   258
    // remove from logs
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   259
    $page_id_db = $db->escape($row['page_id']);
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   260
    $q = $db->sql_query('DELETE FROM ' . table_prefix . "logs WHERE page_id = '{$page_id_db}' AND namespace = 'File' AND action = 'reupload' AND time_id = {$row['time_id']};");
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   261
    if ( !$q )
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   262
      $db->_die();
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   263
    
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   264
    return true;
4f4d63a281cd Fixed (well, implemented) log clearing functionality on uploaded files.
Dan
parents: 1081
diff changeset
   265
  }
800
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   266
}
9cdfe82c56cd Major underlying changes to namespace handling. Each namespace is handled by its own class which extends Namespace_Default. Much greater customization/pluggability potential, at the possible expense of some code reusing (though code reusing has been avoided thus far). Also a bit better handling of page passwords [SECURITY].
Dan
parents:
diff changeset
   267