/[drupal]/contributions/modules/dav/dav.theme.inc
ViewVC logotype

Contents of /contributions/modules/dav/dav.theme.inc

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


Revision 1.5 - (show annotations) (download) (as text)
Mon Nov 17 16:22:31 2008 UTC (12 months, 1 week ago) by arto
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-ALPHA4, HEAD
Changes since 1.4: +27 -1 lines
File MIME type: text/x-php
Merged latest changes from http://github.com/incanus/drupal-dav (3859c2a) by Justin Miller.

Changelog (DAV API):
- Fix issue with DAV root module patch (improper variable cast).
- Added custom setting for character encoding:
  * default PEAR library encodes <space>, &, <, >
  * we now give an admin option and add | as well.
- Added MIME type icons to web listing (i.e., HTTP GET) of DAV resources.
- Fix fatal bug by replacing db_next_id(), which doesn't exist on Drupal 6.x, with db_last_insert_id().
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * PHPTemplate theme for displaying the index for a DAV collection.
7 */
8
9 //////////////////////////////////////////////////////////////////////////////
10 // Theme constants
11
12 define('DAV_LS_FORMAT', '%12s %-19s %-s');
13
14 //////////////////////////////////////////////////////////////////////////////
15 // Theme implementation
16
17 /**
18 * Renders a themed DAV collection index.
19 *
20 * @param $path
21 * @param $resources
22 *
23 * @ingroup themeable
24 */
25 function theme_dav_page($path, $resources = array()) {
26 global $locale;
27 $cwd = is_array($path) ? _dav_implode_path($path) : $path;
28 $title = t('Index of @path', array('@path' => $cwd));
29
30 ob_start();
31
32 print '<?xml version="1.0" encoding="utf-8"?>'. "\n";
33 print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'. "\n" .
34 ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'. "\n";
35 print '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'. $locale .'" lang="'. $locale .'">'. "\n";
36 print " <head>\n";
37 print " <title>$title</title>\n";
38 print " </head>\n";
39 print " <body>\n";
40 print " <h1>$title</h1>\n";
41 print " <pre>\n";
42 print sprintf(DAV_LS_FORMAT, t('Size'), t('Last modified'), t('Name')) . "<hr />\n";
43
44 foreach ($resources as $name => $resource) {
45 print _dav_theme_resource($path, $name, $resource);
46 }
47
48 print " </pre>\n";
49 print " <hr />\n";
50 print ' '. theme('dav_footer') . "\n";
51 print " </body>\n";
52 print "</html>\n";
53
54 return ob_get_clean();
55 }
56
57 /**
58 * Renders a themed DAV resource for display in a collection index.
59 *
60 * @param $path
61 * @param $name
62 * @param $resource
63 *
64 * @ingroup themeable
65 */
66 function theme_dav_resource($path, $name, $resource) {
67 list($type, ) = $resource;
68 $props = dav_propfind($resource);
69
70 $size = !empty($props['getcontentlength']) ? format_size($props['getcontentlength']) : '-';
71 $mtime = !empty($props['getlastmodified']) ? $props['getlastmodified'] : time();
72 $mtime = format_date($mtime, 'small');
73 $slash = ($props['resourcetype'] == 'collection') ? '/' : '';
74 $name = check_plain($name);
75 if (DAV_ICONS) {
76 if ($props['getcontenttype'] == 'httpd/unix-directory') {
77 $icon .= drupal_get_path('module', 'file_browser');
78 $icon .= '/icons/folder.png"';
79 }
80 else {
81 $type = $props['getcontenttype'];
82 /**
83 * Borrowed from FileFramework's file_mime_icon_for().
84 */
85 $handlers = file_get_mime_types();
86 $default_mime_types = file_default_mime_types();
87 $icon = is_array($handlers[$type]['icon']) ? reset($handlers[$type]['icon']) : $handlers[$type]['icon'];
88 $icon = isset($icon) ? $icon : (in_array(preg_replace('/([^\/]+).*/', '$1/*', $type), array_keys($default_mime_types)) ? $default_mime_types[preg_replace('/([^\/]+).*/', '$1/*', $type)]['icon'] : '');
89 /**
90 * End borrowed code.
91 */
92 $icon = drupal_get_path('module', 'file') .'/icons/'. $icon;
93 }
94 $image = '<img src="' . base_path() . $icon . '" ';
95 $image .= 'valign="middle" ';
96 $image .= 'alt="' . $type . '" ';
97 $image .= 'title="' . $type . '" ';
98 $image .= '/> ';
99 }
100
101 $link = $image . '<a href="./'. $name . $slash .'" class="dav '. $type .'">'. $name .'</a>'. $slash;
102
103 return sprintf(DAV_LS_FORMAT . "\n", $size, $mtime, $link);
104 }
105
106 /**
107 * Renders a themed footer used for displaying a DAV collection index.
108 *
109 * @ingroup themeable
110 */
111 function theme_dav_footer() {
112 return '<address>'. t('Powered by <a href="!url">Drupal</a>.', array('!url' => 'http://drupal.org/project/dav')) .'</address>';
113 }
114
115 //////////////////////////////////////////////////////////////////////////////
116 // Theme helpers
117
118 function _dav_theme_resource($path, $name, $resource) {
119 list($type, $item) = $resource;
120
121 $theme_registry = theme_get_registry();
122 $theme_func = 'dav_'. $type;
123 $theme_func = isset($theme_registry[$theme_func]) ? $theme_func : 'dav_resource';
124 return theme($theme_func, $path, $name, $resource);
125 }

  ViewVC Help
Powered by ViewVC 1.1.2