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

View File

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

View File

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

View File

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

View File

@ -3,13 +3,13 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-02-02 20:56:42 * @Date: 2016-02-02 20:56:42
* @Last Modified by: printempw * @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. * All textures requests of legacy link will be handle here.
*/ */
$dir = dirname(__FILE__); $dir = dirname(__FILE__);
require "$dir/includes/autoload.inc.php"; require "$dir/includes/autoloader.php";
if (isset($_GET['type']) && isset($_GET['uname'])) { if (isset($_GET['type']) && isset($_GET['uname'])) {
$user = new User($_GET['uname']); $user = new User($_GET['uname']);

View File

@ -3,13 +3,15 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-02-02 21:17:59 * @Date: 2016-02-02 21:17:59
* @Last Modified by: printempw * @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) { function __autoload($classname) {
global $dir; global $dir;
$filename = "$dir/includes/".$classname.".class.php"; // echo $classname.'<br />';
include_once($filename); $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')) if (!file_exists($dir.'/config.php'))
Utils::showErrorPage(-1, '未找到 `config.php`,请确认配置文件是否存在。'); Utils::showErrorPage(-1, '未找到 `config.php`,请确认配置文件是否存在。');

View File

@ -3,12 +3,13 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-18 14:02:12 * @Date: 2016-03-18 14:02:12
* @Last Modified by: printempw * @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 class Config
{ {
public static function get($key) { public static function get($key) {
$conn = Database::checkConfig(); $conn = Database::checkConfig();
$sql = "SELECT * FROM ".DB_PREFIX."options WHERE `option_name` = '$key'"; $sql = "SELECT * FROM ".DB_PREFIX."options WHERE `option_name` = '$key'";

View File

@ -3,9 +3,16 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-18 16:53:55 * @Date: 2016-03-18 16:53:55
* @Last Modified by: printempw * @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 class AdaptedDatabase extends Database implements EncryptInterface, SyncInterface
{ {
protected $table_name; protected $table_name;

View File

@ -3,9 +3,13 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-13 11:59:32 * @Date: 2016-03-13 11:59:32
* @Last Modified by: printempw * @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 class AuthmeDatabase extends AdaptedDatabase
{ {
/** /**

View File

@ -3,9 +3,13 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-13 12:15:08 * @Date: 2016-03-13 12:15:08
* @Last Modified by: printempw * @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 class CrazyDatabase extends AdaptedDatabase
{ {
/** /**

View File

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

View File

@ -3,9 +3,13 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-13 14:59:32 * @Date: 2016-03-13 14:59:32
* @Last Modified by: printempw * @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 class DiscuzDatabase extends AdaptedDatabase
{ {
/** /**

View File

@ -3,9 +3,11 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-13 11:53:47 * @Date: 2016-03-13 11:53:47
* @Last Modified by: printempw * @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 interface EncryptInterface
{ {
/** /**

View File

@ -3,9 +3,11 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-03-13 13:31:28 * @Date: 2016-03-13 13:31:28
* @Last Modified by: printempw * @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 interface SyncInterface
{ {
/** /**

View File

@ -3,9 +3,11 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-01-16 23:01:33 * @Date: 2016-01-16 23:01:33
* @Last Modified by: printempw * @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 class User
{ {
public $uname = ""; public $uname = "";
@ -18,7 +20,7 @@ class User
function __construct($uname) { function __construct($uname) {
$this->uname = Utils::convertString($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(); $this->db = new $class_name();
if ($this->db->sync($this->uname)) { if ($this->db->sync($this->uname)) {

View File

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

View File

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

View File

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

View File

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

View File

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