/[drupal]/contributions/modules/auditfiles/notonserver.admin.inc
ViewVC logotype

Contents of /contributions/modules/auditfiles/notonserver.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Dec 5 22:33:19 2007 UTC (23 months, 2 weeks ago) by stuartgreenfield
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3
File MIME type: text/x-php
Commit of Audit Files for Drupal 6 (code is still under development).
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Callback to generate files not on server report
7 */
8
9
10 /**
11 * Menu callback: audit files not on the server.
12 */
13 function auditfiles_notonserver() {
14
15 // Get all the files from the files table using defined sort order
16 if (db_table_exists('upload')) {
17 // Using a left join means all rows in {files} are selected even if there is no entry in {upload}
18 $sql = 'SELECT u.nid, f.filepath FROM {files} AS f LEFT JOIN {upload} AS u ON f.fid = u.fid';
19
20 // Initialise table header to allow sorting
21 $header = array(
22 array('data' => t('Node'), 'field' => 'u.nid', 'sort' => 'asc'),
23 array('data' => t('File'), 'field' => 'f.filepath'),
24 array('data' => t('Operations')),
25 );
26 }
27 else {
28 // If {upload} doesn't exist do a simpler query
29 $sql = 'SELECT f.filepath FROM {files} AS f';
30
31 // Initialise table header to allow sorting
32 $header = array(
33 array('data' => t('Node')),
34 array('data' => t('File'), 'field' => 'f.filepath', 'sort' => 'asc'),
35 array('data' => t('Operations')),
36 );
37 }
38
39 $table_sort = tablesort_sql($header);
40 $result = db_query($sql . $table_sort);
41
42 // Initialise array to hold rows of table
43 $rows = array();
44
45 // Iterate through the results
46 while ($file = db_fetch_object($result)) {
47
48 // Construct a valid drupal path for the named file
49 $target = file_create_path($file->filepath);
50
51 // Check to see if the file exists
52 if (!file_exists($target)) {
53
54 // If it doesn't strip out the directory path and store the result
55 $file->filepath = preg_replace('@^'.preg_quote(file_directory_path()).'/@', '', $file->filepath);
56
57 // Construct table rows, but only make hyperlinks if $file->nid is defined
58 if ($file->nid) {
59 $rows[] = array(
60 array('data' => l($file->nid, 'node/'.$file->nid)),
61 array('data' => $file->filepath),
62 array('data' => l(t('edit'), 'node/'.$file->nid.'/edit'))
63 );
64 }
65 else {
66 $rows[] = array(
67 array('data' => ''),
68 array('data' => $file->filepath),
69 array('data' => '')
70 );
71 }
72 }
73
74 }
75
76 // Create output string
77 if ($rows) {
78 $output .= format_plural(count($rows), '1 file found.', '@count files found.');
79 $output .= theme('table', $header, $rows);
80 }
81 else {
82 $output .= t('No files found.');
83 }
84
85 // Return the results
86 return $output;
87 }
88

  ViewVC Help
Powered by ViewVC 1.1.2