/** * @brief login 用户登录 * * @return void */ public function login() { $username = Request::P('username', 'string'); $password = Request::P('password', 'string'); $remember = Request::P('remember'); if ($username == NULL || $password == NULL) { $r = array('success' => FALSE, 'message' => _t('Username or password missed.')); Response::ajaxReturn($r); return; } $user = new UserLibrary(); $user->setName($username); if (!($u = $user->getUser())) { $r = array('success' => FALSE, 'message' => _t('Username not exists.')); Response::ajaxReturn($r); } else { if ($u['password'] != strtolower(md5($password))) { $r = array('success' => FALSE, 'message' => _t('Password wrong.')); Response::ajaxReturn($r); return; } $this->user['uid'] = $u['uid']; $this->user['username'] = $u['username']; $this->user['group'] = $u['group']; $this->user['email'] = $u['email']; $this->user['website'] = $u['website']; $expire = $remember ? time() + $remember : 0; if ($remember) { $u['auth'] = LogX::randomString(8); $user->updateSalt($u['auth']); } Response::setCookie('userid', $u['uid'], $expire); Response::setCookie('password', md5($u['auth'] . $u['password']), $expire); $r = array('success' => TRUE, 'message' => _t('Login success.')); Response::ajaxReturn($r); } }
/** * @brief censorComment 审核一条评论 * * @return void */ public function censorComment() { $cid = Request::P('cid'); // 删除评论 $comment = new CommentLibrary(); $comment->censorComment($cid); $r = array('success' => TRUE); Response::ajaxReturn($r); }
/** * @brief disable 卸载插件 * * @param $plugin 插件名称 * * @return void */ public static function disable($plugin) { // 检查是否已经安装 if (!self::isInstall($plugin)) { Response::ajaxReturn(array('success' => FALSE, 'message' => _t('Already removed.'))); return; } // 调用插件自身的 remove 方法 require_once LOGX_PLUGIN . $plugin . '/' . $plugin . '.php'; $pluginName = $plugin . 'Plugin'; if (!class_exists($pluginName)) { Response::ajaxReturn(array('success' => FALSE, 'message' => _t('Plugin broken.'))); return; } $po = new $pluginName(); if (!$po->remove()) { Response::ajaxReturn(array('success' => FALSE, 'message' => _t('Remove failed.'))); return; } // 标记插件为已卸载 $pluginInstall = Cache::get('PluginInstall'); unset($pluginInstall[$plugin]); Cache::set('PluginInstall', $pluginInstall, 0); Response::ajaxReturn(array('success' => TRUE, 'message' => _t('Remove complete.'))); }
/** * @brief delMeta 删除 Meta * * @return void */ public function delMeta() { $mid = Request::P('mid'); $meta = new MetaLibrary(); if ($meta->delMeta($mid)) { $r = array('success' => TRUE, 'message' => _t('Delete Meta complete.')); } else { $r = array('success' => FALSE, 'message' => _t('Delete Meta failed.')); } Response::ajaxReturn($r); }
/** * @brief deletePost 删除一篇文章 * * @return void */ public function deletePost() { $pid = Request::P('pid'); // 删除文章 $post = new PostLibrary(); $post->deletePost($pid); // 删除 Meta 关系 $meta = new MetaLibrary(); $meta->setPID($pid); $metas = $meta->getMeta(); foreach ($metas as $m) { if ($m['type'] == 1 || $m['type'] == 2) { $meta->delRelation($m['mid'], $pid); } elseif ($m['type'] == 3) { $meta->movRelation($m['mid'], $pid, 1000000000); } } // 删除评论 $comment = new CommentLibrary(); $comment->deleteComments($pid); $r = array('success' => TRUE); Response::ajaxReturn($r); }
/** * @brief advancedSettingsDo 保存高级设置 * * @return void */ private function advancedSettingsDo() { // 验证用户权限 if (!Widget::getWidget('User')->isAdmin()) { Response::ajaxReturn(array('success' => FALSE, 'message' => _t('Permission denied.'))); return; } $rewrite = Request::P('rewrite', 'string'); $timezone = Request::P('timezone', 'string'); $register = Request::P('register', 'string'); if (!$rewrite || !$timezone || !$register) { $r = array('success' => FALSE, 'message' => _t('Option can not be null.')); Response::ajaxReturn($r); } else { if ($rewrite == 'close') { if (file_exists(LOGX_ROOT . '.htaccess') && !@unlink(LOGX_ROOT . '.htaccess')) { $r = array('success' => FALSE, 'message' => _t('Can not delete .htaccess file.')); Response::ajaxReturn($r); return; } } else { $content = "# BEGIN LogX\n\n<IfModule mod_rewrite.c>\nRewriteEngine On\nRewriteBase " . LOGX_PATH . "\nRewriteCond \$1 ^(index\\.php)?\$ [OR]\nRewriteCond \$1 \\.(gif|jpg|png|css|js|ico)\$ [NC,OR]\nRewriteCond %{REQUEST_FILENAME} -f [OR]\nRewriteCond %{REQUEST_FILENAME} -d\nRewriteRule ^(.*)\$ - [S=1]\nRewriteRule . " . LOGX_PATH . "index.php [L]\n</IfModule>\n\n# END LogX"; if (!file_exists(LOGX_ROOT . '.htaccess') && !@file_put_contents(LOGX_ROOT . '.htaccess', $content)) { $r = array('success' => FALSE, 'message' => _t('Can not create .htaccess file.')); Response::ajaxReturn($r); return; } } OptionLibrary::set('rewrite', $rewrite); OptionLibrary::set('timezone', $timezone); OptionLibrary::set('register', $register); $r = array('success' => TRUE, 'message' => _t('Settings Saved.')); Response::ajaxReturn($r); } }