|
发表于 2006-4-7 08:36:47
|
显示全部楼层
还有很多细节没有完成,多镜像下载的管理、软件截图、还有相关编辑
[code:1]
<?php
function download_help ($section)
{
switch ($section) {
case "admin/modules#description":
return t("将linuxfans.org(%linuxfans_url)使用的phpnuke(%phpnuke_url)下载模块嵌入Drupal,保持phpnuke的相关数据表结构。",
array(
"%linuxfans_url" => "http://www.linuxfans.org",
"%phpnuke_url" => "http://phpnuke.org"
)
);
break;
case 'admin/settings/download':
// what should be setted for download module?
break;
}
}
function download_perm ()
{
return array("view", "download", "comment", "upload", "edit", "edit own upload", "delete", "delete own upload", "admin");
}
function download_menu ($may_cache)
{
$view_access = user_access("view");
$download_access = user_access("download");
$comment_access = user_access("comment");
$upload_access = user_access("upload");
$edit_access = user_access("edit");
$delete_access = user_access("delete");
$admin_access = user_access("admin");
$items = array();
if ($may_cache) {
// for normal user
$items[] = array(
"path" => "download",
"title" => t("下载"),
"callback" => "download_main_page",
"access" => $view_access
);
$items[] = array(
"path" => "download/list",
"title" => t("下载"),
"callback" => "download_main_page",
"type" => MENU_DEFAULT_LOCAL_TASK,
"access" => $view_access,
"weight" => -10
);
$items[] = array(
"path" => "download/upload",
"title" => t("上传"),
"callback" => "download_upload",
"type" => MENU_LOCAL_TASK,
"access" => $upload_access
);
$items[] = array(
"path" => "download/view",
"title" => t("浏览"),
"callback" => "download_view",
"type" => MENU_CALLBACK,
"access" => $view_access
);
$items[] = array(
"path" => "download/mirror",
"title" => t("镜像"),
"callback" => "download_mirror",
"type" => MENU_CALLBACK,
"access" => $download_access
);
$items[] = array(
"path" => "download/comment/add",
"title" => t("添加评论"),
"callback" => "download_comment_add",
"type" => MENU_CALLBACK,
"access" => $comment_access
);
// for administrator
$items[] = array(
"path" => "admin/download",
"title" => t("下载"),
"callback" => "download_admin",
"access" => $admin_access
);
$items[] = array(
"path" => "admin/download/category",
"title" => t("下载分类"),
"callback" => "download_category_admin",
"access" => $admin_access
);
$items[] = array(
"path" => "admin/download/category/list",
"title" => t("下载分类列表"),
"callback" => "download_category_admin",
"type" => MENU_DEFAULT_LOCAL_TASK,
"weight" => -10
);
$items[] = array(
"path" => "admin/download/category/configure",
"title" => t("配置下载分类"),
"access" => $admin_access,
"callback" => "download_category_configure",
"type" => MENU_CALLBACK
);
$items[] = array(
"path" => "admin/download/category/delete",
"title" => t("删除下载分类"),
"access" => $admin_access,
"callback" => "download_category_delete",
"type" => MENU_CALLBACK
);
$items[] = array(
"path" => "admin/download/category/add",
"title" => t("添加下载分类"),
"access" => $admin_access,
"callback" => "download_category_add",
"type" => MENU_LOCAL_TASK
);
$items[] = array(
"path" => "admin/download/mirror",
"title" => t("下载镜像"),
"callback" => "download_mirror_admin",
"access" => $admin_access
);
$items[] = array(
"path" => "admin/download/mirror/list",
"title" => t("下载镜像列表"),
"callback" => "download_mirror_admin",
"type" => MENU_DEFAULT_LOCAL_TASK,
"weight" => -10
);
$items[] = array(
"path" => "admin/download/mirror/configure",
"title" => t("配置下载镜像"),
"access" => $admin_access,
"callback" => "download_mirror_configure",
"type" => MENU_CALLBACK
);
$items[] = array(
"path" => "admin/download/mirror/delete",
"title" => t("删除下载镜像"),
"access" => $admin_access,
"callback" => "download_mirror_delete",
"type" => MENU_CALLBACK
);
$items[] = array(
"path" => "admin/download/mirror/add",
"title" => t("添加下载镜像"),
"access" => $admin_access,
"callback" => "download_mirror_add",
"type" => MENU_LOCAL_TASK
);
}
return $items;
}
function download_admin ()
{
$op = $_POST['op'];
$edit = $_POST['edit'];
unset($output);
$admin_access = user_access("admin");
if (user_access($admin_access)) {
switch ($op) {
default:
// what should be shown as default of navigation admin?
$output = "这里是Linuxfans下载栏配置页面";
break;
}
print theme('page', $output);
} else {
print theme('page', message_access());
}
}
function download_category_admin ()
{
$op = $_POST['op'];
$edit = $_POST['edit'];
if (isset($op)) {
drupal_set_message(download_category_admin_save($edit));
cache_clear_all();
drupal_goto($_GET['q']);
}
print theme('page', download_category_admin_display());
}
function download_category_admin_display ()
{
$categories = _download_categories();
if (count($categories) != 0) {
$header = array(t('ID'), t('下载分类名称'));
$header[] = array('data' => t('操作'), 'colspan' => 2);
$rows = array();
foreach ($categories as $category) {
$delete = l(t('删除'), 'admin/download/category/delete/'. $category["id"]);
$row = array(
array(
"data" => $category["id"],
"class" => "block"
),
array(
"data" => $category["title"],
"class" => "block"
)
);
$row[] = l(t('配置'), 'admin/download/category/configure/' . $category["id"]);
$row[] = $delete;
$rows[] = $row;
$output = theme('table', $header, $rows, array('id' => 'categories'));
}
} else {
$output = "您还没有创建任何Linux项目,请点击<a href=\"admin/navigation/linuxfans_project/add\">添加Linux项目</a>先";
}
return form($output, 'post', url('admin/download/category'));
}
function download_category_add ()
{
$edit = $_POST['edit'];
$op = $_POST['op'];
switch ($op) {
case t('Save Download Category'):
download_category_save($edit);
drupal_set_message(t('新建的下载分类添加完毕。'));
drupal_goto('admin/download/category');
default:
$form = download_category_form();
$form .= form_submit(t('Save Download Category'));
$output .= form($form);
}
print theme('page', $output);
}
function download_category_configure ($cid = 0)
{
$edit = $_POST['edit'];
$op = $_POST['op'];
switch ($op) {
case t('Save Download Category'):
drupal_set_message(download_category_save($edit, $cid));
cache_clear_all();
drupal_goto('admin/download/category');
break;
default:
if (!$edit) {
$sql = "SELECT title
FROM {downloads_categories}
WHERE cid = $cid";
$edit = db_fetch_array(db_query($sql));
}
drupal_set_title(t("配置下载分类'%name' ", array('%name' => $edit["title"])));
$form = download_category_form($edit);
$form .= form_submit(t('Save Download Category'));
$output .= form($form);
print theme('page', $output);
break;
}
}
function download_category_delete ($cid = 0)
{
$op = $_POST['op'];
$category = download_category_get($cid);
$info = $category["title"];
if ($_POST['edit']['confirm']) {
$sql = "DELETE
FROM {downloads_categories}
WHERE cid = $cid";
db_query($sql);
drupal_set_message(t('下载分类 %name 已经被删除。', array('%name' => theme('placeholder', $info))));
cache_clear_all();
drupal_goto('admin/download/category');
} else {
$output = theme('confirm',
t('您确认要删除下载分类 %name么?', array('%name' => theme('placeholder', $info))),
'admin/download/category',
NULL,
t('删除'));
}
print theme('page', $output);
}
function download_category_get ($cid)
{
$sql = "SELECT title
FROM {downloads_categories}
WHERE cid = $cid";
return db_fetch_array(db_query($sql));
}
function download_category_form ($edit = NULL)
{
$output = form_textfield(t('下载分类名称'), 'title', $edit['title'], 30, 150, t('下载分类的名称。比如“驱动程序”。'));
return $output;
}
function download_category_save ($edit, $cid = NULL)
{
if (isset($cid)) {
db_query("UPDATE {downloads_categories} SET title = '%s' WHERE id = %d", $edit['title'], $cid);
} else {
$sql = "INSERT INTO {downloads_categories} (title)
VALUES ('" . $edit["title"] . "') ";
db_query($sql);
}
return t("下载分类已经更新。");
}
function download_main_page ()
{
$view_access = user_access("view");
$op = $_POST['op'];
$edit = $_POST['edit'];
unset($output);
if ($view_access) {
switch ($op) {
case 'add':
$output = download_form();
break;
default:
$output = download_overview();
break;
}
print theme('page', $output);
} else {
print theme('page', message_access());
}
}
function download_upload ()
{
$edit = $_POST['edit'];
$op = $_POST['op'];
switch ($op) {
case t('Upload'):
download_upload_save($edit);
drupal_set_message(t('上传完毕。'));
drupal_goto('download');
default:
$output .= download_upload_form();
}
print theme('page', $output);
}
function download_upload_form ()
{
unset($group);
$group = form_textfield(t('文件名称'), 'title', $edit['title'], 30, 150, t('显示在下载列表的文件名称。比如“MagicLinux”。'));
$group .= form_file(t('上传文件'), 'file', 40, t(''));
$group .= form_textfield(t('提供链接'), 'url', "http://" . $edit['url'], 30, 150,
t('如果其他网站有稳定的下载源,请您提供链接。比如“http://sourceforge/”。'));
/* without screenshot function at present ...
$group .= form_file(t('截图1'), 'screenshot1', 40, t('可以选择是否上传截图1'));
$group .= form_file(t('截图2'), 'screenshot2', 40, t('可以选择是否上传截图2'));
$group .= form_file(t('截图3'), 'screenshot3', 40, t('可以选择是否上传截图3'));
*/
$group .= form_textfield(t('版本'), 'version', $edit['version'], 30, 150, t('您提供的版本将会帮助下载者知道更多的信息。比如“2.0.1”。'));
$group .= form_textfield(t('文件大小'), 'filesize', $edit['filesize'], 30, 150, t('显示下载的文件的物理大小。比如“13MB”。'));
$group .= form_textfield(t('相关网址'), 'homepage', "http://" . $edit['homepage'], 30, 150,
t('您提供的相关网址将会帮助下载者知道更多的信息。比如“http://sourceforge/”。'));
$group .= form_select(t('所属分类'), 'cid', $edit['cid'], download_categories(),
t('您提供的文件所属分类将会帮助下载者知道更多的信息。比如“驱动程序”'));
$group .= form_textarea(t('相关描述'), 'description', $edit['description'], 70, 15, t('您可以在相关描述中讲解文件的简短描述、安装步骤和测试环境。'));
$group .= form_submit(t('Upload'));
$form = $group;
return form($form, 'post', 0, array('enctype' => 'multipart/form-data'));
}
/**
* upload save
*
* @param array $edit
* @param int $lid
* @return char
*/
function download_upload_save ($edit, $lid = NULL)
{
global $user;
if (isset($lid)) {
} else {
// do not use auto_intrement, but use drupal's next_id API
$insert_id = db_next_id("downloads");
/* upload file from remote machine to server's "./files/software" */
if ($edit["url"] == "http://" && $edit["url"] == "") {
$file = file_save_upload('file', 'software');
}
/* insert upload file info into download table */
$sql = "INSERT INTO {downloads} (lid, cid, title, url, description, date, name, submitter, filesize, version, homepage)
VALUES ('$insert_id', '" . $edit["cid"] . "', '" . $edit["title"] . "', '" . $edit["url"] . "', '" . $edit["description"] . "',
'" . time() . "',";
if ($edit["title"] != "" && $edit["file"] == "") {
$sql .= "'" . $edit["title"] . "',";
} else {
$sql .= "'$file->filename',";
}
$sql .= "'$user->name', ";
if ($edit["filesize"] != "" && $edit["file"] == "") {
// if user provide other link point to the file ...
$sql .= "'" . $edit["filesize"] . "',";
} else {
// if user upload the file from remote machine ...
$sql .= "'$file->filesize',";
}
$sql .= " '" . $edit["version"] . "', '" . $edit["homepage"] . "')";
db_query($sql);
/* without screenshot function at present ... */
}
return t("文件上传更新。");
}
function download_categories ()
{
$categories = array();
$sql = "SELECT cid, title
FROM {downloads_categories}";
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
$categories[] = array(
$row->cid => t($row->title)
);
}
return $categories;
}
function _download_categories ()
{
$sql = "SELECT cid, title
FROM {downloads_categories}";
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
$categories[] = array(
"id" => $row->cid,
"title" => $row->title
);
}
return $categories;
}
function download_overview ()
{
global $user;
if (empty($_SESSION['download_overview_filter'])) {
$_SESSION['download_overview_filter'] = 'all';
}
$op = $_POST['op'];
if ($op == t('Filter') && isset($_POST['edit']['filter'])) {
$_SESSION['download_overview_filter'] = $_POST['edit']['filter'];
}
$form = form_select(t('根据类别过滤'), 'filter', $_SESSION['download_overview_filter'], download_categories());
$form .= form_submit(t('Filter'));
$headers = array(
t("截屏"),
array(
"data" => t("日期"),
"field" => "date",
"sort" => "asc"
),
array(
"data" => t("名字"),
"field" => "name"
),
array(
"data" => t("类别"),
"field" => "ctitle"
),
array(
"data" => t("下载次数"),
"field" => "hits"
),
array(
"data" => t("得分"),
"field" => "totalvotes"
)
);
if ($_SESSION['download_overview_filter'] != all) {
$sql = "SELECT d.lid, d.title, d.date, d.name, d.hits, d.totalvotes, d.downloadratingsummary, d.totalcomments, c.title AS ctitle, s.pname
FROM {downloads} d LEFT JOIN {downloads_categories} c ON d.cid = c.cid = " . $_SESSION['download_overview_filter'] . "
LEFT JOIN {downloads_screenshots} s ON d.lid = s.lid
GROUP BY d.lid";
} else {
$sql = "SELECT d.lid, d.title, d.date, d.name, d.hits, d.totalvotes, d.downloadratingsummary, d.totalcomments, c.title AS ctitle, s.pname
FROM {downloads} d LEFT JOIN {downloads_categories} c ON d.cid = c.cid LEFT JOIN {downloads_screenshots} s ON d.lid = s.lid
GROUP BY d.lid";
}
$sql .= tablesort_sql($headers);
$result = pager_query($sql, 18);
while ($download = db_fetch_object($result)) {
$row = array();
$row[] = file_exists("files/software/smallshot/" . $download->pname) ? theme('image', "files/software/smallshot/" . $download->pname,
t('Screenshot for %theme theme', array('%theme' => $download->pname)), '', 'class="screenshot"', false) : t('no screenshot');
$row[] = date_format($download->date);
$row[] = array("data" => l($download->title, "download/view/$download->lid"));
$row[] = $download->ctitle;
$row[] = $download->hits;
$row[] = $download->totalvotes;
$rows[] = $row;
}
if ($pager = theme('pager', NULL, 18, 0, tablesort_pager())) {
$rows[] = array(array(
"data" => $pager,
"colspan" => 8
)
);
}
$out = '<div class="container-inline">'. form($form) .'</div>';
$out .= theme('table', $headers, $rows);
return $out;
}
function download_view ($lid = 0)
{
$sql = "SELECT d.title, d.url, d.description, d.date, d.name, d.hits, d.submitter, d.downloadratingsummary, d.totalvotes, d.filesize,
d.version, c.title AS ctitle, s.pname
FROM {downloads} d LEFT JOIN {downloads_categories} c ON d.cid = c.cid LEFT JOIN {downloads_screenshots} s ON d.lid = s.lid
WHERE d.lid = $lid";
$download = db_fetch_object(db_query($sql));
drupal_set_title(t("浏览'%name' ", array('%name' => $download->title)));
$output .= '<table border="1" cellpadding="2" cellspacing="2">';
$output .= ' <tr><th>'. t("名字") .'</th><td>' . l(t($download->title), "download/mirror/" . $download->name) . '</td></tr>';
$output .= ' <tr><th>'. t("类别") .'</th><td>' . t($download->ctitle) . '</td></tr>';
$output .= ' <tr><th>'. t("大小") .'</th><td>' . t($download->filesize) . '</td></tr>';
$output .= ' <tr><th>'. t("提交者") .'</th><td>' . t($download->submitter) . '</td></tr>';
$output .= ' <tr><th>'. t("下载次数") .'</th><td>' . t($download->hits) . '</td></tr>';
$output .= ' <tr><th>'. t("上传时间") .'</th><td>' . t(date_format($download->date)) . '</td></tr>';
$output .= ' <tr><th>'. t("版本") .'</th><td>' . t($download->version) . '</td></tr>';
$output .= ' <tr><th>'. t("相关网址") .'</th><td>' . l(t($download->url), t($download->url)) . '</td></tr>';
$output .= ' <tr><th>'. t("得分") .'</th><td>' . t($download->downloadratingsummary) . '</td></tr>';
$output .= ' <tr><th>'. t("投票") .'</th><td>' . l(t("好"), "temp") . "|" . l(t("差"), "temp") . '</td></tr>';
$output .= ' <tr><th>'. t("相关描述") .'</th><td>' . t($download->description) . '</td></tr>';
$output .= '</table>';
$output .= "<br >";
$output .= download_comment_rendor($lid);
$output .= l(t("我要评论"), "download/comment/add/" . $lid);
print theme('page', $output);
}
function download_mirror ($name = NULL)
{
$headers = array(
array(
"data" => t("镜像名称")
),
array(
"data" => t("下载地址")
)
);
$sql = "SELECT name, url
FROM {downloads_mirrors}";
$result = db_query($sql);
drupal_set_title(t("镜像下载'%name' ", array('%name' => $name)));
while ($mirror = db_fetch_object($result)) {
$row = array();
$row[] = $mirror->name;
$row[] = l(t($mirror->url . $name), $mirror->url . $name);
$rows[] = $row;
}
$output .= theme('table', $headers, $rows);
print theme('page', $output);
}
function download_comment_rendor ($lid = 0, $comments_per_page = 8)
{
$sql = "SELECT c.subject, c.comment, c.date, u.name
FROM {downloads_comments} c LEFT JOIN {users} u ON c.userid = u.uid
WHERE c.lid = $lid
ORDER BY c.date";
$result = db_query($sql);
while ($comment = db_fetch_object($result)) {
$comment = drupal_unpack($comment);
$output .= theme('comment_view', $comment, theme('links', module_invoke_all('link', 'comment', $comment, 0)));
}
if ($pager = theme('pager', NULL, $comments_per_page, 0, array('comments_per_page' => $comments_per_page))) {
$output .= $pager;
}
return $output;
}
function download_comment_add ($lid)
{
$edit = $_POST['edit'];
$op = $_POST['op'];
switch ($op) {
case t("Add Comment"):
download_comment_save($edit, $lid);
drupal_set_message(t('新的评论添加完毕。'));
drupal_goto('download/view/' . $lid);
break;
default:
$form = download_comment_form();
$form .= form_submit(t('Add Comment'));
$output .= form($form);
break;
}
print theme('page', $output);
}
function download_comment_save ($edit, $lid, $cid = NULL)
{
global $user;
if (isset($cid)) {
// but download module in phpnuke is not able to edit...
} else {
$sql = "INSERT INTO {downloads_comments} (lid, subject, comment, date, userid)
VALUES ('$lid', '" . $edit["subject"] . "', '" . $edit["comment"] . "', '" . time() . "', '$user->uid') ";
db_query($sql);
}
return t("评论已经添加。");
}
function download_comment_form ()
{
$output = form_textfield(t('评论标题'), 'subject', $edit['subject'], 30, 150, t('评论的标题。比如“MagicLinux真不错”。'));
$output .= form_textarea(t('评论内容'), 'comment', $edit['comment'], 70, 15, t('评论的内容。比如“MagicLinux的用户体验很好”。'));
return $output;
}
function date_format ($date, $style = 'default')
{
switch ($style) {
default:
$output = date("Y-m-d", $date);
break;
}
return $output;
}
?>
[/code:1]
[code:1]
--
-- 表的结构 `default_downloads`
--
CREATE TABLE `default_downloads` (
`lid` int(11) NOT NULL default '0',
`cid` int(11) NOT NULL default '0',
`sid` int(11) NOT NULL default '0',
`title` varchar(100) NOT NULL default '',
`url` varchar(100) NOT NULL default '',
`description` text NOT NULL,
`date` int(11) default NULL,
`name` varchar(100) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`hits` int(11) NOT NULL default '0',
`submitter` varchar(60) NOT NULL default '',
`downloadratingsummary` double(6,4) NOT NULL default '0.0000',
`totalvotes` int(11) NOT NULL default '0',
`totalcomments` int(11) NOT NULL default '0',
`filesize` varchar(11) NOT NULL default '0',
`version` varchar(10) NOT NULL default '',
`homepage` varchar(200) NOT NULL default '',
PRIMARY KEY (`lid`),
KEY `lid` (`lid`),
KEY `cid` (`cid`),
KEY `sid` (`sid`),
KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
[/code:1]
[code:1]
CREATE TABLE `default_downloads_categories` (
`cid` int(11) NOT NULL auto_increment,
`title` varchar(50) NOT NULL default '',
`cdescription` text,
`parentid` int(11) NOT NULL default '0',
PRIMARY KEY (`cid`),
KEY `cid` (`cid`),
KEY `title` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
[/code:1]
[code:1]
--
-- 表的结构 `default_downloads_comments`
--
CREATE TABLE `default_downloads_comments` (
`cid` int(11) NOT NULL auto_increment,
`lid` int(11) NOT NULL default '0',
`subject` varchar(150) NOT NULL default '',
`comment` text NOT NULL,
`date` int(11) NOT NULL default '0',
`userid` int(11) NOT NULL default '0',
PRIMARY KEY (`cid`),
KEY `lid` (`lid`,`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
[/code:1]
[code:1]
--
-- 表的结构 `default_downloads_mirrors`
--
CREATE TABLE `default_downloads_mirrors` (
`mid` int(11) NOT NULL auto_increment,
`name` varchar(150) NOT NULL default '',
`url` varchar(150) NOT NULL default '',
PRIMARY KEY (`mid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
[/code:1]
[code:1]
--
-- 表的结构 `default_downloads_screenshots`
--
CREATE TABLE `default_downloads_screenshots` (
`pid` int(11) NOT NULL auto_increment,
`lid` int(11) NOT NULL default '0',
`userid` int(11) NOT NULL default '0',
`pname` varchar(150) NOT NULL default '',
PRIMARY KEY (`pid`),
KEY `lid` (`lid`,`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
[/code:1] |
|