<?php
// Charray's CMS (CCMS) Version 0.9.1.1
//
// Copyright (c) 2007, Kinson Chan
// charray[at]gmail.com / kchan[at]cs.hku.hk
// All rights reserved.
//
// Please refer to LICENSE.txt coming with this package for
// terms and conditions for redistribution and reuse.
if (!defined("CCMS_IN")) {
die();
}
function ccms_module_download($file) {
global $ccms_controller_url;
global $ccms_decoders;
global $ccms_mime;
$result['title'] = 'Download';
$result['content'] = '';
$dir = substr($file, 0, strrpos($file, '/'));
$filenames = ccms_list_directory($dir);
natsort($filenames);
foreach ($filenames as $filename) {
$extension = ccms_identify_extension($filename);
// Skip files that no not have mime defined
// or having default decoder to decode. Also,
// skip unreadable files and images.
if (!isset($ccms_mime[$extension]) ||
in_array($extension, $ccms_decoders) ||
preg_match('/\/\.[^\/]*$/', $filename) ||
preg_match('/\.ccms_[a-zA-Z_]+\.[a-zA-Z]+$/', $filename) ||
!is_readable($filename) ||
preg_match('/^image/', $ccms_mime[$extension])) {
continue;
}
// Add the hyperlink.
$pathname = ccms_obtain_path($filename, true);
$display_name = substr($pathname, strrpos($pathname, '/') + 1);
$filesize = number_format(filesize($filename));
$result['content'] .= "<p style=\"text-align: center;\">";
$result['content'] .= "<a href=\"$ccms_controller_url$pathname\">";
$result['content'] .= "$display_name\n</a><br />\n";
$result['content'] .= "($filesize bytes)";
$result['content'] .= "</p>\n";
}
if ($result['content']) {
return $result;
} else {
return false;
}
}
?>