use namespace to organize classes

This commit is contained in:
printempw 2016-03-18 17:49:52 +08:00
parent e18dec19a1
commit 5f401a5ba3
22 changed files with 77 additions and 45 deletions

View File

@ -3,7 +3,7 @@
* @Author: prpr
* @Date: 2016-02-03 14:39:50
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:44:17
* @Last Modified time: 2016-03-18 17:45:01
*/
require "../includes/session.inc.php";
if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是管理员');
@ -34,7 +34,7 @@ if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是
<a class="pure-menu-link" href="manage.php">用户管理</a>
<a class="pure-menu-link" href="../user/profile.php">个人设置</a>
</li>
<?php include "../includes/welcome.inc.php"; ?>
<?php include "../includes/templates/welcome.tpl.php"; ?>
</ul>
<div class="home-menu-blur">
<div class="home-menu-wrp">
@ -50,7 +50,7 @@ if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是
<div class="panel-body">
<?php
$page_now = isset($_GET['page']) ? $_GET['page'] : 1;
$db = new Database();
$db = new Database\Database();
?>
<p>注册用户:<?php echo $db->getRecordNum();?></p>
<p>上传材质总数:<?php echo count(scandir("../textures/"))-2;?></p>

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 16:34:32
* @Last Modified time: 2016-03-18 17:46:50
*
* Blessing Skin Server Installer
*/
@ -29,7 +29,7 @@ if (false): ?>
<?php endif;
$dir = dirname(dirname(__FILE__));
require "$dir/includes/autoload.inc.php";
require "$dir/includes/autoloader.php";
$step = isset($_GET['step']) ? $_GET['step'] : 1;
?>
<!DOCTYPE html>

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-03-06 14:19:20
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:44:23
* @Last Modified time: 2016-03-18 17:45:06
*/
require "../includes/session.inc.php";
if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是管理员');
@ -34,7 +34,7 @@ if (!$user->is_admin) header('Location: ../index.php?msg=看起来你并不是
<a class="pure-menu-link" href="index.php">仪表盘</a>
<a class="pure-menu-link" href="../user/profile.php">个人设置</a>
</li>
<?php include "../includes/welcome.inc.php"; ?>
<?php include "../includes/templates/welcome.tpl.php"; ?>
</ul>
<div class="home-menu-blur">
<div class="home-menu-wrp">

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:50:43
* @Last Modified time: 2016-03-18 17:47:22
*
* - login, register, logout
* - upload, change, delete
@ -16,8 +16,8 @@ header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
$dir = dirname(__FILE__);
require "$dir/includes/autoload.inc.php";
Database::checkConfig();
require "$dir/includes/autoloader.php";
Database\Database::checkConfig();
if (isset($_POST['uname'])) {
$uname = $_POST['uname'];

View File

@ -3,13 +3,13 @@
* @Author: prpr
* @Date: 2016-02-02 20:56:42
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:38:46
* @Last Modified time: 2016-03-18 17:47:37
*
* All textures requests of legacy link will be handle here.
*/
$dir = dirname(__FILE__);
require "$dir/includes/autoload.inc.php";
require "$dir/includes/autoloader.php";
if (isset($_GET['type']) && isset($_GET['uname'])) {
$user = new User($_GET['uname']);

View File

@ -3,13 +3,15 @@
* @Author: prpr
* @Date: 2016-02-02 21:17:59
* @Last Modified by: printempw
* @Last Modified time: 2016-03-12 18:44:26
* @Last Modified time: 2016-03-18 17:34:35
*/
function __autoload($classname) {
global $dir;
$filename = "$dir/includes/".$classname.".class.php";
include_once($filename);
// echo $classname.'<br />';
$include_dir = $dir.DIRECTORY_SEPARATOR."includes".DIRECTORY_SEPARATOR."classes".DIRECTORY_SEPARATOR;
$filename = $include_dir.str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.class.php';
require_once($filename);
}
if (!file_exists($dir.'/config.php'))
Utils::showErrorPage(-1, '未找到 `config.php`,请确认配置文件是否存在。');

View File

@ -3,12 +3,13 @@
* @Author: printempw
* @Date: 2016-03-18 14:02:12
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:37:04
* @Last Modified time: 2016-03-18 17:24:13
*/
use Database\Database;
class Config
{
public static function get($key) {
$conn = Database::checkConfig();
$sql = "SELECT * FROM ".DB_PREFIX."options WHERE `option_name` = '$key'";

View File

@ -3,9 +3,16 @@
* @Author: printempw
* @Date: 2016-03-18 16:53:55
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 16:55:30
* @Last Modified time: 2016-03-18 17:33:58
*/
namespace Database;
use Database\Database;
use Database\EncryptInterface;
use Database\SyncInterface;
use Config;
class AdaptedDatabase extends Database implements EncryptInterface, SyncInterface
{
protected $table_name;

View File

@ -3,9 +3,13 @@
* @Author: printempw
* @Date: 2016-03-13 11:59:32
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 16:55:57
* @Last Modified time: 2016-03-18 17:33:27
*/
namespace Database;
use Database\AdaptedDatabase;
class AuthmeDatabase extends AdaptedDatabase
{
/**

View File

@ -3,9 +3,13 @@
* @Author: printempw
* @Date: 2016-03-13 12:15:08
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 16:56:29
* @Last Modified time: 2016-03-18 17:23:25
*/
namespace Database;
use Database\AdaptedDatabase;
class CrazyDatabase extends AdaptedDatabase
{
/**

View File

@ -3,9 +3,16 @@
* @Author: printempw
* @Date: 2016-02-02 21:59:06
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:34:09
* @Last Modified time: 2016-03-18 17:37:01
*/
namespace Database;
use Database\EncryptInterface;
use Database\SyncInterface;
use Utils;
use Mysqli;
class Database implements EncryptInterface, SyncInterface
{
private $connection = null;
@ -24,8 +31,7 @@ class Database implements EncryptInterface, SyncInterface
if (!self::checkTableExist($conn)) {
}
$dir = dirname(dirname(__FILE__));
if (!is_dir("$dir/textures/")) {
if (!is_dir(BASE_DIR."/textures/")) {
Utils::showErrorPage(-1, "textures 文件夹不存在。请先运行 /admin/install.php 进行安装,或者手动放置一个。");
}
return $conn;

View File

@ -3,9 +3,13 @@
* @Author: printempw
* @Date: 2016-03-13 14:59:32
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 16:56:46
* @Last Modified time: 2016-03-18 17:23:38
*/
namespace Database;
use Database\AdaptedDatabase;
class DiscuzDatabase extends AdaptedDatabase
{
/**

View File

@ -3,9 +3,11 @@
* @Author: printempw
* @Date: 2016-03-13 11:53:47
* @Last Modified by: printempw
* @Last Modified time: 2016-03-13 14:31:29
* @Last Modified time: 2016-03-18 17:23:08
*/
namespace Database;
interface EncryptInterface
{
/**

View File

@ -3,9 +3,11 @@
* @Author: printempw
* @Date: 2016-03-13 13:31:28
* @Last Modified by: printempw
* @Last Modified time: 2016-03-13 14:35:37
* @Last Modified time: 2016-03-18 17:23:33
*/
namespace Database;
interface SyncInterface
{
/**

View File

@ -3,9 +3,11 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 16:45:00
* @Last Modified time: 2016-03-18 17:31:41
*/
use Database\Database;
class User
{
public $uname = "";
@ -18,7 +20,7 @@ class User
function __construct($uname) {
$this->uname = Utils::convertString($uname);
$class_name = Config::get('data_adapter')."Database";
$class_name = "Database\\".Config::get('data_adapter')."Database";
$this->db = new $class_name();
if ($this->db->sync($this->uname)) {

View File

@ -3,7 +3,7 @@
* @Author: printempw
* @Date: 2016-01-16 23:01:33
* @Last Modified by: printempw
* @Last Modified time: 2016-03-12 18:00:02
* @Last Modified time: 2016-03-18 17:40:51
*/
class Utils
@ -23,8 +23,7 @@ class Utils
}
public static function showErrorPage($errno = -1, $msg = "Error occured.") {
$dir = dirname(dirname(__FILE__));
require "$dir/includes/error.tpl.php";
require BASE_DIR."/includes/templates/error.tpl.php";
die();
}
@ -35,10 +34,9 @@ class Utils
* @return string $hash, sha256 hash of file
*/
public static function upload($file) {
$dir = dirname(dirname(__FILE__));
move_uploaded_file($file["tmp_name"], "$dir/textures/tmp.png");
$hash = hash_file('sha256', "$dir/textures/tmp.png");
rename("$dir/textures/tmp.png", "$dir/textures/".$hash);
move_uploaded_file($file["tmp_name"], BASE_DIR."/textures/tmp.png");
$hash = hash_file('sha256', BASE_DIR."/textures/tmp.png");
rename(BASE_DIR."/textures/tmp.png", BASE_DIR."/textures/".$hash);
return $hash;
}

View File

@ -2,12 +2,12 @@
/**
* @Author: prpr
* @Date: 2016-02-06 23:18:49
* @Last Modified by: prpr
* @Last Modified time: 2016-02-06 23:27:48
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 17:46:22
*/
session_start();
$dir = dirname(dirname(__FILE__));
require "$dir/includes/autoload.inc.php";
require "$dir/includes/autoloader.php";
if(isset($_COOKIE['uname']) && isset($_COOKIE['token'])) {
$_SESSION['uname'] = $_COOKIE['uname'];

View File

@ -3,12 +3,12 @@
* @Author: printempw
* @Date: 2016-01-17 13:55:20
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 15:02:24
* @Last Modified time: 2016-03-18 17:47:57
*/
session_start();
$dir = dirname(__FILE__);
require "$dir/includes/autoload.inc.php";
Database::checkConfig();
require "$dir/includes/autoloader.php";
Database\Database::checkConfig();
// Auto load cookie value to session
if (isset($_COOKIE['uname']) && isset($_COOKIE['token'])) {

View File

@ -3,7 +3,7 @@
* @Author: prpr
* @Date: 2016-01-21 13:56:40
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:44:02
* @Last Modified time: 2016-03-18 17:44:39
*/
require "../includes/session.inc.php";
?>
@ -31,7 +31,7 @@ require "../includes/session.inc.php";
<li class="pure-menu-item">
<a class="pure-menu-link" href="profile.php">个人设置</a>
</li>
<?php include "../includes/welcome.inc.php"; ?>
<?php include "../includes/templates/welcome.tpl.php"; ?>
</ul>
<div class="home-menu-blur">
<div class="home-menu-wrp">

View File

@ -3,7 +3,7 @@
* @Author: prpr
* @Date: 2016-02-03 16:12:45
* @Last Modified by: printempw
* @Last Modified time: 2016-03-18 14:44:12
* @Last Modified time: 2016-03-18 17:44:50
*/
require "../includes/session.inc.php";
?>
@ -33,7 +33,7 @@ require "../includes/session.inc.php";
<li class="pure-menu-item">
<a class="pure-menu-link" href="index.php">皮肤上传</a>
</li>
<?php include "../includes/welcome.inc.php"; ?>
<?php include "../includes/templates/welcome.tpl.php"; ?>
</ul>
<div class="home-menu-blur">
<div class="home-menu-wrp">