[php]代码库
=========================================================
安装:
=========================================================
1. 解压缩文件包
将文件包中的所有文件解压缩到你电脑上的某个目录中。保证解压缩后的文件目录结构保持不变。解压缩完成后,你将得到如下的目录结构(* 代表该目录下包含文件):
/* (系统主文件目录)
/nucleus/* (管理主文件目录)
/nucleus/javascript/* (javascript帮助代码目录)
/nucleus/libs/* (Nucleus核心库文件目录)
/nucleus/language/* (语言包文件目录)
/nucleus/plugins/* (插件目录)
/nucleus/xmlrpc/* (XML-RPC接口目录)
/nucleus/documentation/* (文档 + 管理帮助目录)
/nucleus/styles/* (文档 + 管理帮助风格目录)
/nucleus/forms/* (表单式样目录)
/extra/* (其他, e.g. needed files to enable fancy URLs)
/skins/* (皮肤目录[导入的皮肤也存放于此])
/media/* (媒体文件目录[空的])
2. 上传文件到服务器
上传所有的文件到服务器,保证所有的php文件都是在ASCII模式下进行传输。如果用其他模式传输,程序运行将会出错。
可选项:
为了使你的安装更简单,你最好将 config.php 的文件属性改为 666 。这样的话,安装脚本就能够自动将系统的配置保存在其中。否则,你只能手动配置。(如何更改文件属性)
如果你想使用文件上传功能,你必须将 /media/ 目录设置为可写(777)属性(777)。(如何更改文件属性)
如果你想使用 SkinFiles 插件编辑皮肤文件,你需要将 /skins/ 目录下的所有文件设置成 666 属性。如果你想创建新的皮肤文件,就必须设置目录为 777 属性。
3. 运行install.php
用你的浏览器打开下面的地址,将 yoursite和yourpath 的内容改成你的服务器对应的内容。
http://www.yoursite.com/yourpath/install.php
该安装脚本将会提示你输入一些信息并完成大部分的安装工作。当安装成功以后,install.php 将会给你进一步的提示(你仍需要手工删除一些文件)。
注意: 当你在浏览器打开 install.php 后,出现 "If you see this text in your browser..." 这样的文字,或者提示你下载 install.php,说明你的服务器不支持PHP,安装将无法进行。
4. 完成
安装完成后你就可以访问你的网站并进行管理了。更多安装问题请到HEXU查询。
<?php
class ACTION
{
function ACTION()
{
}
function doAction($action)
{
switch($action) {
case 'addcomment':
return $this->addComment();
break;
case 'sendmessage':
return $this->sendMessage();
break;
case 'createaccount':
return $this->createAccount();
break;
case 'forgotpassword':
return $this->forgotPassword();
break;
case 'votepositive':
return $this->doKarma('pos');
break;
case 'votenegative':
return $this->doKarma('neg');
break;
case 'plugin':
return $this->callPlugin();
break;
default:
doError(_ERROR_BADACTION);
}
}
function addComment() {
global $CONF, $errormessage, $manager;
$post['itemid'] = intPostVar('itemid');
$post['user'] = postVar('user');
$post['userid'] = postVar('userid');
$post['body'] = postVar('body');
// set cookies when required
$remember = intPostVar('remember');
if ($remember == 1) {
$lifetime = time()+2592000;
setcookie($CONF['CookiePrefix'] . 'comment_user',$post['user'],$lifetime,'/','',0);
setcookie($CONF['CookiePrefix'] . 'comment_userid', $post['userid'],$lifetime,'/','',0);
}
$comments = new COMMENTS($post['itemid']);
$blogid = getBlogIDFromItemID($post['itemid']);
$this->checkban($blogid);
$blog =& $manager->getBlog($blogid);
// note: PreAddComment and PostAddComment gets called somewhere inside addComment
$errormessage = $comments->addComment($blog->getCorrectTime(),$post);
if ($errormessage == '1') {
// redirect when adding comments succeeded
if (postVar('url')) {
redirect(postVar('url'));
} else {
$url = $CONF['IndexURL'] . createItemLink($post['itemid']);
redirect($url);
}
} else {
// else, show error message using default skin for blog
return array(
'message' => $errormessage,
'skinid' => $blog->getDefaultSkin()
);
}
exit;
}
// Sends a message from the current member to the member given as argument
function sendMessage() {
global $CONF, $member;
$error = $this->validateMessage();
if ($error != '')
return array('message' => $error);
if (!$member->isLoggedIn()) {
$fromMail = postVar('frommail');
$fromName = _MMAIL_FROMANON;
} else {
$fromMail = $member->getEmail();
$fromName = $member->getDisplayName();
}
$tomem = new MEMBER();
$tomem->readFromId(postVar('memberid'));
$message = _MMAIL_MSG . ' ' . $fromName . "\n"
. '(' . _MMAIL_FROMNUC. ' ' . $CONF['IndexURL'] .") \n\n"
. _MMAIL_MAIL . " \n\n"
. postVar('message');
$message .= getMailFooter();
$title = _MMAIL_TITLE . ' ' . $fromName;
mail($tomem->getEmail(), $title, $message, 'From: '. $fromMail);
if (postVar('url')) {
redirect(postVar('url'));
} else {
$CONF['MemberURL'] = $CONF['IndexURL'];
if ($CONF['URLMode'] == 'pathinfo')
{
$url = createLink('member', array('memberid' => $tomem->getID(), 'name' => $tomem->getDisplayName()));
}
else
{
$url = $CONF['IndexURL'] . createMemberLink($tomem->getID());
}
redirect($url);
}
exit;
}
function validateMessage() {
global $CONF, $member, $manager;
if (!$CONF['AllowMemberMail'])
return _ERROR_MEMBERMAILDISABLED;
if (!$member->isLoggedIn() && !$CONF['NonmemberMail'])
return _ERROR_DISALLOWED;
if (!$member->isLoggedIn() && (!isValidMailAddress(postVar('frommail'))))
return _ERROR_BADMAILADDRESS;
// let plugins do verification (any plugin which thinks the comment is invalid
// can change 'error' to something other than '')
$result = '';
$manager->notify('ValidateForm', array('type' => 'membermail', 'error' => &$result));
return $result;
}
// creates a new user account
function createAccount() {
global $CONF, $manager;
if (!$CONF['AllowMemberCreate'])
doError(_ERROR_MEMBERCREATEDISABLED);
// even though the member can not log in, set some random initial password. One never knows.
srand((double)microtime()*1000000);
$initialPwd = md5(uniqid(rand(), true));
// create member (non admin/can not login/no notes/random string as password)
$r = MEMBER::create(postVar('name'), postVar('realname'), $initialPwd, postVar('email'), postVar('url'), 0, 0, '');
if ($r != 1)
doError($r);
// send message containing password.
$newmem = new MEMBER();
$newmem->readFromName(postVar('name'));
$newmem->sendActivationLink('register');
$manager->notify('PostRegister',array('member' => &$newmem));
if (postVar('desturl')) {
redirect(postVar('desturl'));
} else {
echo _MSG_ACTIVATION_SENT;
}
exit;
}
// sends a new password
function forgotPassword() {
$membername = trim(postVar('name'));
if (!MEMBER::exists($membername))
doError(_ERROR_NOSUCHMEMBER);
$mem = MEMBER::createFromName($membername);
if (!$mem->canLogin())
doError(_ERROR_NOLOGON_NOACTIVATE);
// check if e-mail address is correct
if (!($mem->getEmail() == postVar('email')))
doError(_ERROR_INCORRECTEMAIL);
// send activation link
$mem->sendActivationLink('forgot');
if (postVar('url')) {
redirect(postVar('url'));
} else {
echo _MSG_ACTIVATION_SENT;
}
exit;
}
// handle karma votes
function doKarma($type) {
global $itemid, $member, $CONF, $manager;
// check if itemid exists
if (!$manager->existsItem($itemid,0,0))
doError(_ERROR_NOSUCHITEM);
$blogid = getBlogIDFromItemID($itemid);
$this->checkban($blogid);
$karma =& $manager->getKarma($itemid);
// check if not already voted
if (!$karma->isVoteAllowed(serverVar('REMOTE_ADDR')))
doError(_ERROR_VOTEDBEFORE);
// check if item does allow voting
$item =& $manager->getItem($itemid,0,0);
if ($item['closed'])
doError(_ERROR_ITEMCLOSED);
switch($type) {
case 'pos':
$karma->votePositive();
break;
case 'neg':
$karma->voteNegative();
break;
}
$blogid = getBlogIDFromItemID($itemid);
$blog =& $manager->getBlog($blogid);
// send email to notification address, if any
if ($blog->getNotifyAddress() && $blog->notifyOnVote()) {
$mailto_msg = _NOTIFY_KV_MSG . ' ' . $itemid . "\n";
$mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
if ($member->isLoggedIn()) {
$mailto_msg .= _NOTIFY_MEMBER . ' ' . $member->getDisplayName() . ' (ID=' . $member->getID() . ")\n";
}
$mailto_msg .= _NOTIFY_IP . ' ' . serverVar('REMOTE_ADDR') . "\n";
$mailto_msg .= _NOTIFY_HOST . ' ' . gethostbyaddr(serverVar('REMOTE_ADDR')) . "\n";
$mailto_msg .= _NOTIFY_VOTE . "\n " . $type . "\n";
$mailto_msg .= getMailFooter();
$mailto_title = _NOTIFY_KV_TITLE . ' ' . strip_tags($item['title']) . ' (' . $itemid . ')';
$frommail = $member->getNotifyFromMailAddress();
$notify = new NOTIFICATION($blog->getNotifyAddress());
$notify->notify($mailto_title, $mailto_msg , $frommail);
}
$refererUrl = serverVar('HTTP_REFERER');
if ($refererUrl)
$url = $refererUrl;
else
$url = $CONF['IndexURL'] . 'index.php?itemid=' . $itemid;
redirect($url);
exit;
}
/**
* Calls a plugin action
*/
function callPlugin() {
global $manager;
$pluginName = 'NP_' . requestVar('name');
$actionType = requestVar('type');
// 1: check if plugin is installed
if (!$manager->pluginInstalled($pluginName))
doError(_ERROR_NOSUCHPLUGIN);
// 2: call plugin
$pluginObject =& $manager->getPlugin($pluginName);
if ($pluginObject)
$error = $pluginObject->doAction($actionType);
else
$error = 'Could not load plugin (see actionlog)';
// doAction returns error when:
// - an error occurred (duh)
// - no actions are allowed (doAction is not implemented)
if ($error)
doError($error);
exit;
}
function checkban($blogid) {
// check if banned
$ban = BAN::isBanned($blogid, serverVar('REMOTE_ADDR'));
if ($ban != 0) {
doError(_ERROR_BANNED1 . $ban->iprange . _ERROR_BANNED2 . $ban->message . _ERROR_BANNED3);
}
}
}
?>
[源代码打包下载]