make diogenes depends compatible with sarge
[diogenes.git] / include / diogenes.icons.inc.php
... / ...
CommitLineData
1<?php
2/*
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21
22/** This class describes Diogenes' icons.
23 */
24class DiogenesIcons
25{
26 /** Construct an object to manipulate Diogenes's icons.
27 */
28 function DiogenesIcons($theme = 'gartoon')
29 {
30 $this->theme = $theme;
31 }
32
33
34 /** Return the available icon themes.
35 */
36 function get_icon_themes()
37 {
38 $themes = array(
39 'gartoon' => array(
40 'action' => array(
41 'add' => 'action-add.png',
42 'delete' => 'action-delete.png',
43 'edit' => 'action-edit.png',
44 'properties' => 'action-properties.png',
45 'plugins' => 'action-plugins.png',
46 'revisions' => 'action-revisions.png',
47 'rename' => 'action-rename.png',
48 'remove' => 'action-remove.png',
49 'update' => 'action-update.png',
50 'view' => 'action-view.png',
51 ),
52 'barrel' => array(
53 'home' => 'barrel-home.png',
54 'directory' => 'barrel-directory.png'
55 ),
56 'mime' => array(
57 'audio' => 'mime-audio.png',
58 'deb' => 'mime-deb.png',
59 'drm' => 'mime-drm.png',
60 'excel' => 'mime-excel.png',
61 'html' => 'mime-html.png',
62 'lyx' => 'mime-lyx.png',
63 'msword' => 'mime-msword.png',
64 'postscript' => 'mime-postscript.png',
65 'powerpoint' => 'mime-powerpoint.png',
66 'pdf' => 'mime-pdf.png',
67 'image' => 'mime-image.png',
68 'text' => 'mime-text.png',
69 'video' => 'mime-video.png',
70 'compressed' => 'mime-compressed.png',
71 'unknown' => 'mime-unknown.png',
72 'xml' => 'mime-xml.png',
73 ),
74 'perm' => array(
75 'public' => 'perm-public.png',
76 'auth' => 'perm-auth.png',
77 'user' => 'perm-user.png',
78 'admin' => 'perm-admin.png',
79 'forbidden' => 'perm-forbidden.png',
80 )
81 )
82 );
83
84 return $themes;
85 }
86
87
88 /** Return the icon associated with an action.
89 *
90 * @param $category the icon category
91 * @param $name the icon name
92 */
93 function get_icon($category, $name)
94 {
95 global $globals;
96 $maps = $this->get_icon_themes();
97
98 if (isset($maps[$this->theme][$category][$name])) {
99 return $globals->rooturl . "images/".$maps[$this->theme][$category][$name];
100 } else {
101 trigger_error("could not find icon for '$name' in category '$category'", E_USER_WARNING);
102 return false;
103 }
104 }
105
106
107 /** Return the icon associated with an action.
108 *
109 * @param $action the action we are describing
110 */
111 function get_action_icon($action)
112 {
113 return $this->get_icon('action', $action);
114 }
115
116
117 /** Return the icons associated with an array of actions
118 *
119 * @param $actions the actions we are describing
120 */
121 function get_action_icons($actions)
122 {
123 $oactions = array();
124 foreach ($actions as $action)
125 {
126 $oaction = $action;
127 if (isset($action[2]))
128 {
129 $oaction[2] = $this->get_action_icon($action[2]);
130 }
131 array_push($oactions, $oaction);
132 }
133 return $oactions;
134 }
135
136
137 /** Return the icon associated with a file's MIME content-type
138 *
139 * @param $filename the file we are describing
140 */
141 function get_mime_icon($filename)
142 {
143 global $globals;
144
145 $type = get_mime_type($filename);
146
147 if (preg_match('/^application\/msword$/', $type)) {
148 $itype = 'msword';
149 } elseif (preg_match('/^application\/vnd\.ms-powerpoint$/', $type)) {
150 $itype = 'powerpoint';
151 } elseif (preg_match('/^application\/vnd\.oma\.drm\.(content|message)$/', $type)) {
152 $itype = 'drm';
153 } elseif (preg_match('/^application\/(arj|x-bzip|x-bzip2|x-gzip|x-compressed|zip)$/', $type)) {
154 $itype = 'compressed';
155 } elseif (preg_match('/^application\/pdf$/', $type)) {
156 $itype = 'pdf';
157 } elseif (preg_match('/^application\/postscript$/', $type)) {
158 $itype = 'postscript';
159 } elseif (preg_match('/^application\/x-deb$/', $type)) {
160 $itype = 'deb';
161 } elseif (preg_match('/^audio\//', $type)) {
162 $itype = 'audio';
163 } elseif (preg_match('/^application\/vnd\.ms-excel$/', $type)) {
164 $itype = 'excel';
165 } elseif (preg_match('/^image\//', $type)) {
166 $itype = 'image';
167 } elseif (preg_match('/^text\/html$/', $type)) {
168 $itype = 'html';
169 } elseif (preg_match('/^text\/xml$/', $type)) {
170 $itype = 'xml';
171 } elseif (preg_match('/^text\/x-lyx$/', $type)) {
172 $itype = 'lyx';
173 } elseif (preg_match('/^text\//', $type)) {
174 $itype = 'text';
175 } elseif (preg_match('/^video\//', $type)) {
176 $itype = 'video';
177 } else {
178 $itype = 'unknown';
179 }
180
181 return $this->get_icon('mime', $itype);
182 }
183}
184
185?>