2 function mb_get_extension ($filename) // {{{
4 return strtolower(substr(strrchr($filename,'.'),1));
6 function mb_chomp ($string) // {{{
8 return substr($string, 0, -1);
10 function mb_datetext ($timestamp) // {{{
13 return date($config['datestring'],$timestamp);
15 function mb_sizetext ($sizeinbytes) // {{{
19 $t_b = 1024; // use bytes when size < 1024
20 $t_kb = 1048576; // use kb when size < 1 MB
21 if (!$config['human_readable_size']) {
22 return "$sizeinbytes";
24 if ($sizeinbytes < $t_b) {
25 return "$sizeinbytes B";
26 } elseif ($sizeinbytes < $t_kb) {
27 $kb = floor($sizeinbytes / 1024);
30 $mb = floor($sizeinbytes / 1048576);
34 function mb_lengthtext ($seconds) // {{{
36 $minutes = floor($seconds/60);
37 $seconds = $seconds %
60;
38 if (strlen($seconds) == 1) { $seconds = '0'.$seconds; }
39 return "$minutes:$seconds";
41 function mb_typetext ($type) // {{{
44 case MB_T_AUDIO
: return 'Audio CD';
45 case MB_T_DATA
: return 'Data CD';
46 case MB_T_EMPTY
: return 'CD';
47 default: return 'Unknown';
50 function mb_icon ($extension) // {{{
53 $icon = $config['icon_prefix'];
54 // I'm planning to add icon-by-extension sometime :-)
56 case '__folder': $icon .= 'folder.png'; break;
57 case '__unknown': $icon .= 'unknown.png'; break;
58 case '__category': $icon .= 'category.png'; break;
59 case '__media_cd': $icon .= 'cd.png'; break;
60 case '__media_acd': $icon .= 'acd.png'; break;
62 return "<img alt=\"icon\" src=\"$icon\"> ";
64 function mb_iconbytype ($type) // {{{
67 case MB_T_DATA
: return mb_icon('__media_cd');
68 case MB_T_AUDIO
: return mb_icon('__media_acd');
69 case MB_T_EMPTY
: return mb_icon('__media_cd');
70 default: return mb_icon('__unknown');
73 function mb_getparentdir ($dir) // {{{
75 // I'm sure there's a better way to do this,
76 // I was just lazy. Sorry about that :)
77 if ($dir == '/') { return false; }
78 $parts = explode('/',$dir);
81 $dir = implode('/',$parts) . '/';
84 function mb_table_start () // {{{
86 global $TABLE_COLUMNS;
87 if (!(isset($TABLE_COLUMNS) && is_array($TABLE_COLUMNS))) {
88 $TABLE_COLUMNS = array();
91 array_unshift($TABLE_COLUMNS,$c);
94 for ($x=0;$x<$c;$x++
) {
95 echo " <th>".func_get_arg($x)."</th>\n";
99 function mb_table_widecol ($content) // {{{
101 global $TABLE_COLUMNS;
103 global $TABLE_CSSCLASS;
105 $cols = $TABLE_COLUMNS[0];
107 if (!isset($TABLE_ROW))
112 if (($TABLE_ROW %
2) != 0)
114 $TABLE_CSSCLASS="OddTableRow";
118 $TABLE_CSSCLASS="EvenTableRow";
124 echo " <td colspan=\"$cols\" class=\"".$TABLE_CSSCLASS."\">$content</td>\n";
127 function mb_table_row () // {{{
130 $c = func_num_args();
132 for ($x=0;$x<$c;$x++
) {
133 echo " <td>".func_get_arg($x)."</td>\n";
137 function mb_table_col ($content)
139 global $TABLE_COLUMNS;
140 global $TABLE_COLUMN;
142 global $TABLE_CSSCLASS;
143 $cols = $TABLE_COLUMNS[0];
145 if (!isset($TABLE_COLUMN))
150 if (!isset($TABLE_ROW))
155 $curcol = $TABLE_COLUMN++
;
159 if (($TABLE_ROW %
2) != 0)
161 $TABLE_CSSCLASS="OddTableRow";
165 $TABLE_CSSCLASS="EvenTableRow";
172 echo " <td class=\"".$TABLE_CSSCLASS."\"><nobr>$content</nobr></td>\n";
173 if ($curcol == $cols) { echo "\t</tr>\n"; $TABLE_COLUMN = 1; }
176 function mb_table_end () // {{{
178 global $TABLE_COLUMNS;
179 array_shift($TABLE_COLUMNS);
182 function mb_fetch_select_categories ($indent=0) // {{{
185 $indent = str_repeat("\t",$indent);
186 if (!$res = mysql_query("SELECT * FROM ".$config['tbl_categories']." ORDER BY name")) {
189 if (!mysql_num_rows($res)) {
192 while ($row = mysql_fetch_assoc($res)) {
193 echo $indent.'<option value="'.$row['catid'].'">'.$row['name']."</option>\n";
198 function truncate_ellipsis ($string, $max)
200 if (strlen($string) > $max +
3)
201 return substr_replace($string, "...", $max - 3);