Permalink
Browse files

Big change from Qchan to Qchan-lite

You can feel it!
  • Loading branch information...
1 parent 14ce5f9 commit 8b0c3f382615bc80428e00415aed13c0422a6e56 qakcn committed Sep 11, 2014
Showing with 5,316 additions and 1 deletion.
  1. +11 −0 .gitattributes
  2. +5 −0 .gitignore
  3. +16 −1 README.md
  4. +24 −0 api.php
  5. +27 −0 config.php
  6. +111 −0 engine.php
  7. +166 −0 includes/HttpRequest.class.php
  8. +27 −0 includes/Service.class.php
  9. +55 −0 includes/functions.common.php
  10. +60 −0 includes/functions.language.php
  11. +27 −0 includes/functions.theme.php
  12. +139 −0 includes/functions.upload.php
  13. +30 −0 includes/service/MyTieTuKu.class.php
  14. +33 −0 includes/service/ServiceInterface.php
  15. +139 −0 includes/service/TTKService.class.php
  16. +540 −0 includes/service/TieTuKu.class.php
  17. +27 −0 index.php
  18. 0 lang/en.json
  19. +202 −0 lang/ja.json
  20. +199 −0 lang/lang.list
  21. +202 −0 lang/zh-CN.json
  22. +21 −0 manage/api.php
  23. +116 −0 manage/functions.php
  24. +306 −0 manage/images/WorldMap.svg
  25. +15 −0 manage/images/add.svg
  26. +10 −0 manage/images/error.svg
  27. +7 −0 manage/images/mask.svg
  28. +6 −0 manage/images/none.svg
  29. +9 −0 manage/images/transparent.svg
  30. +205 −0 manage/index.php
  31. +377 −0 manage/style.css
  32. +259 −0 manage/ui.js
  33. BIN site-img/404.jpg
  34. BIN site-img/favicon.png
  35. BIN site-img/logo.png
  36. BIN site-img/logo_m.png
  37. +18 −0 themes/default/footer.php
  38. +44 −0 themes/default/functions.php
  39. +110 −0 themes/default/header.php
  40. +306 −0 themes/default/images/WorldMap.svg
  41. +15 −0 themes/default/images/add.svg
  42. +10 −0 themes/default/images/error.svg
  43. +7 −0 themes/default/images/mask.svg
  44. +9 −0 themes/default/images/transparent.svg
  45. +76 −0 themes/default/main.php
  46. +35 −0 themes/default/page-agreement.php
  47. +32 −0 themes/default/page-privacy.php
  48. +453 −0 themes/default/style.css
  49. +584 −0 themes/default/ui.js
  50. +246 −0 themes/default/upload.js
View
@@ -0,0 +1,11 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+*.php text=auto
+*.js text=auto
+*.css text=auto
+
+*.png binary
+*.gif binary
+*.jpg binary
+*.svg text=auto
View
@@ -0,0 +1,5 @@
+uploads/*
+thumbs/*
+*~
+apikey/*
+config.timestamp
View
@@ -1,4 +1,19 @@
qchan-lite
==========
-A light-weight image upload program for other image host service.
+A light-weight image upload and manage program for other image host service.
+
+
+## Supported Service
+
+[TieTuKu](http://tietuku.com)
+
+----------
+qchan-lite
+==========
+
+由于其他图床服务的轻量级图片上传和管理程序。
+
+## 支持的服务
+
+[贴图库](http://tietuku.com)
View
@@ -0,0 +1,24 @@
+<?php
+define('API_RUN',true);
+
+require 'engine.php';
+
+if(!isset($_SERVER['HTTP_REFERER']) && !isset($_GET['apikey'])) {
+ header('HTTP/1.1 403 Forbidden');
+ exit('API cannot be direct accessed!');
+}
+if(check_apikey()) {
+ if(isset($_GET['type']) && $_GET['type']=='url') {
+ $result = url_handler();
+ }else if(isset($_GET['type']) && $_GET['type']=='file') {
+ $result = array_pop(file_handler());
+ }else {
+ header('HTTP/1.1 400 Bad Request');
+ exit('You must set "type" in the query string.');
+ }
+ header('Content-Type: application/json');
+ echo json_encode($result);
+}else {
+ header('HTTP/1.1 403 Forbidden');
+ exit('API KEY ERROR');
+}
View
@@ -0,0 +1,27 @@
+<?php
+
+// 界面设置
+define('UI_LANG', 'zh-cn'); //设置界面默认语言
+define('UI_THEME', 'default'); //设置界面默认主题
+
+// 站点信息
+define('SITE_TITLE', 'Qchan图床'); // 网站标题
+define('SITE_DESCRIPTION', '上传与分享'); // 网站描述
+define('SITE_KEYWORDS', 'images, photos, image hosting, photo hosting, free image hosting'); //网站关键字
+define('ADMIN_EMAIL', 'admin@example.com'); // 管理员Email
+
+// 版权声明
+define('COPYRIGHT', '所有未声明版权图片均在<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">知识共享 署名-非商业使用-相同方式共享 4.0 协议</a>下发布。');
+
+// 管理设置
+define('MANAGE_NAME','admin'); // 管理员用户名
+define('MANAGE_PASSWORD','admin'); // 管理员密码
+
+// 服务设置
+define('SERVICE', 'tietuku'); // 服务提供商:目前仅支持'tietuku'(贴图库)
+define('ALBUM_PREFIX', 'qchan'); // 相册前缀
+
+// 贴图库API设置
+// 下面两个Key请到[贴图库]->[开放平台]->[管理中心]->[密钥]获取
+define('TIETUKU_ACCESSKEY', ''); // 贴图库API的AccessKey
+define('TIETUKU_SECRETKEY', ''); // 贴图库API的SecretKey
View
@@ -0,0 +1,111 @@
+<?php
+
+/* Deny direct visit */
+if (!defined('INDEX_RUN') && !defined('API_RUN') && !defined('MANAGE_RUN')) {
+ header('HTTP/1.1 403 Forbidden');
+ exit('This file must be loaded in flow.');
+}
+
+// Check if config.php is correct
+function check_config() {
+ if (!(
+ defined('UI_LANG') &&
+ is_string(UI_LANG) &&
+ preg_match('/[a-z]{2,3}(-[A-Z]{2})?|zh-Han[ts]/', UI_LANG)
+ )) {
+ exit('UI_LANG set incorrectly.');
+ }
+ if (!(
+ defined('UI_THEME') &&
+ is_string(UI_THEME) &&
+ file_exists(ABSPATH . '/themes/' . UI_THEME)
+ )) {
+ exit('UI_THEME set incorrectly.');
+ }
+ if(!(
+ defined('SITE_TITLE') &&
+ is_string(SITE_TITLE)
+ )) {
+ exit('SITE_TITLE set incorrectly.');
+ }
+ if(!(
+ defined('SITE_DESCRIPTION') &&
+ is_string(SITE_DESCRIPTION)
+ )) {
+ exit('SITE_DESCRIPTION set incorrectly.');
+ }
+ if(!(
+ defined('SITE_KEYWORDS') &&
+ is_string(SITE_KEYWORDS)
+ )) {
+ exit('SITE_KEYWORDS set incorrectly.');
+ }
+ if(!(
+ defined('ADMIN_EMAIL') &&
+ is_string(ADMIN_EMAIL) &&
+ preg_match('/(\w+\.)*\w+@(\w+\.)+[A-Za-z]+/', ADMIN_EMAIL)
+ )) {
+ exit('ADMIN_EMAIL set incorrectly.');
+ }
+ if(!(
+ defined('MANAGE_NAME') &&
+ is_string(MANAGE_NAME)
+ )) {
+ exit('MANAGE_NAME set incorrectly.');
+ }
+ if(!(
+ defined('MANAGE_PASSWORD') &&
+ is_string(MANAGE_PASSWORD)
+ )) {
+ exit('MANAGE_PASSWORD set incorrectly.');
+ }
+ if(!(
+ defined('COPYRIGHT') &&
+ is_string(COPYRIGHT)
+ )) {
+ exit('COPYRIGHT set incorrectly.');
+ }
+}
+
+define('QCHAN_VER', 'lite-1.0pre build 20140905');
+date_default_timezone_set('UTC');
+define('ABSPATH', __DIR__);
+
+if(!is_writable(ABSPATH . '/')) {
+ exit(ABSPATH.' is not writable.');
+}
+
+/* Load Configurations or start installation */
+if(file_exists( ABSPATH.'/config.php')) {
+ require_once ABSPATH.'/config.php';
+}else {
+ header("Location: install.php");
+ exit();
+}
+
+$config_timestamp = 0;
+$config_timestamp_now = filemtime(ABSPATH.'/config.php');
+if(file_exists(ABSPATH.'/config.timestamp')) {
+ $config_timestamp = file_get_contents(ABSPATH.'/config.timestamp');
+}
+if($config_timestamp != $config_timestamp_now) {
+ check_config();
+ file_put_contents(ABSPATH.'/config.timestamp', $config_timestamp_now);
+}
+
+define('SUPPORT_TYPE', 'jpg|jpeg|jpe|jfif|jfi|jif|gif|png|svg');
+header("\x58\x2D\x51\x63\x68\x61\x6E\x2D\x49\x6E\x66\x6F\x3A\x20\x51\x63\x68\x61\x6E\x20\x69\x73\x20\x61\x6E\x20\x69\x6D\x61\x67\x65\x20\x68\x6F\x73\x74\x69\x6E\x67\x20\x66\x72\x65\x65\x77\x61\x72\x65\x2C\x20\x69\x73\x20\x64\x65\x76\x65\x6C\x6F\x70\x65\x64\x20\x62\x79\x20\x51\x75\x61\x64\x72\x61\x20\x53\x74\x75\x64\x69\x6F\x2C\x20\x61\x6E\x64\x20\x70\x75\x62\x6C\x69\x73\x68\x65\x64\x20\x75\x6E\x64\x65\x72\x20\x47\x50\x4C\x76\x33\x2E");
+
+/* Load functions */
+require_once ABSPATH.'/includes/functions.common.php';
+require_once ABSPATH.'/includes/functions.language.php';
+require_once ABSPATH.'/includes/functions.theme.php';
+require_once ABSPATH.'/includes/functions.upload.php';
+
+/* load classes */
+require_once ABSPATH.'/includes/Service.class.php';
+require_once ABSPATH.'/includes/HttpRequest.class.php';
+Service::init();
+
+$lang = load_lang();
+
@@ -0,0 +1,166 @@
+<?php
+class HTTPRequest {
+
+ private $method;
+ private $host;
+ private $port;
+ private $path;
+ private $query='';
+ private $header=array();
+ private $posts=array();
+ private $files=array();
+ private $multipart = false;
+
+ private $postdata='';
+ private $headerdata='';
+
+ const HTTP_EOL = "\r\n";
+
+ public function __construct() {
+ $this->setHeader(array(
+ array('name'=>'User-Agent', 'value'=>'HTTPRequest/1.0 (PHP; author/qakcn)'),
+ array('name'=>'Accept', 'value'=>'*/*'),
+ array('name'=>'Connection', 'value'=>'Close'),
+ array('name'=>'Cache-Control', 'value'=>'no-cache'),
+ ));
+ $this->setMethod('get');
+ $this->setURL('http://localhost/');
+ }
+
+ public function setURL($url) {
+ $url = parse_url($url);
+ if(isset($url['scheme']) && $url['scheme'] == 'http') {
+ $this->host = $url['host'];
+ $this->port = isset($url['port']) ? $url['port'] : 80;
+ $this->path = isset($url['path']) ? $url['path'] : '/';
+ $this->query = isset($url['query']) ? '?'.$url['query'] : '';
+ }else {
+ return false;
+ }
+ }
+
+ public function setMethod($method) {
+ if(strcasecmp($method, "post") == 0 || strcasecmp($method, "get") == 0) {
+ $this->method = strtoupper($method);
+ }else if(strcasecmp($method, "multipart") == 0) {
+ $this->method = 'POST';
+ $this->multipart = true;
+ }else {
+ return false;
+ }
+ }
+
+ public function send() {
+ $fp = fsockopen($this->host, $this->port);
+ if(!$fp) return false;
+ $this->genPostdata();
+ $this->genHeader();
+ fwrite($fp, $this->headerdata.$this->postdata);
+ $result = '';
+ while(!feof($fp)) {
+ $result .= fgets($fp, 1024);
+ }
+ fclose($fp);
+ $pos = strpos($result, "\r\n\r\n");
+ $result = substr($result, $pos+4);
+
+ return $result;
+ }
+
+ public function addQuery(array $query) {
+ if(isset($query['key']) && isset($query['value'])) {
+ array_push($this->posts, $query);
+ }else {
+ foreach($query as $q) {
+ if(isset($q['key']) && isset($q['value'])) {
+ array_push($this->posts, $q);
+ }
+ }
+ }
+ }
+
+ public function setHeader(array $header) {
+ if(isset($header['name']) && isset($header['value'])) {
+ array_push($this->header, $header);
+ }else {
+ foreach($header as $h) {
+ if(isset($h['name']) && isset($h['value'])) {
+ array_push($this->header, $h);
+ }
+ }
+ }
+ }
+
+ public function addFile(array $file) {
+ if(isset($file['name']) && isset($file['path']) && isset($file['filename'])) {
+ array_push($this->files, $file);
+ }else {
+ foreach($file as $f) {
+ if(isset($f['name']) && isset($f['path']) && isset($file['filename'])) {
+ array_push($this->files, $f);
+ }
+ }
+ }
+ }
+
+ private function genPostdata() {
+ if(count($this->files)==0 && !$this->multipart) {
+ if(count($this->posts)!=0) {
+ $query = '';
+ foreach($this->posts as $post) {
+ $query .= rawurlencode($post['key']).'='.rawurlencode($post['value']).'&';
+ }
+ $query = substr($query,0,-1);
+ if($this->method=='POST') {
+ $this->setHeader(array('name'=>'Content-Type','value'=>'application/x-www-form-urlencoded'));
+ $this->postdata = $query;
+ }else {
+ if($this->query=='') {
+ $this->query = '?'.$query;
+ }else {
+ $this->query .= '&'.$query;
+ }
+ }
+ }
+ }else {
+ // 设置分割标识
+ srand((double)microtime()*1000000);
+ $boundary = '---------------------------'.substr(md5(rand(0,32000)),0,10);
+
+ $this->setHeader(array('name'=>'Content-Type','value'=>'multipart/form-data; boundary='.$boundary));
+ $this->postdata = '--'.$boundary.HTTPRequest::HTTP_EOL;
+
+ if(count($this->posts)!=0) {
+ foreach($this->posts as $post) {
+ $this->postdata .= 'Content-Disposition: form-data; name="'.$post['key'].'"'.HTTPRequest::HTTP_EOL.HTTPRequest::HTTP_EOL;
+ $this->postdata .= $post['value'].HTTPRequest::HTTP_EOL;
+ $this->postdata .= '--'.$boundary.HTTPRequest::HTTP_EOL;
+ }
+ }
+ foreach($this->files as $file) {
+ if(file_exists($file['path'])) {
+ $this->postdata .= 'Content-Disposition: form-data; name="'.$file['name'].'"; filename="'.$file['filename'].'"'.HTTPRequest::HTTP_EOL;
+ $mime = file_mime_type($file['path']);
+ if($mime) {
+ $this->postdata .= 'Content-Type: '.$mime.HTTPRequest::HTTP_EOL;
+ }
+ $this->postdata .= HTTPRequest::HTTP_EOL;
+ $contents = file_get_contents($file['path']);
+ $this->postdata .= $contents.HTTPRequest::HTTP_EOL;
+ $this->postdata .= '--'.$boundary.HTTPRequest::HTTP_EOL;
+ }
+ }
+ $this->postdata = substr($this->postdata, 0, -2).'--'.HTTPRequest::HTTP_EOL;
+ $this->setHeader(array('name'=>'Content-Length', 'value'=>strlen($this->postdata)));
+ }
+ }
+
+ private function genHeader() {
+ $this->headerdata = $this->method.' '.$this->path.$this->query.' HTTP/1.1'.HTTPRequest::HTTP_EOL;
+ $this->headerdata .= 'Host: '.$this->host.HTTPRequest::HTTP_EOL;
+ foreach($this->header as $h) {
+ $this->headerdata.= $h['name'].': '.$h['value'].HTTPRequest::HTTP_EOL;
+ }
+ $this->headerdata .= HTTPRequest::HTTP_EOL;
+ }
+}
Oops, something went wrong.

0 comments on commit 8b0c3f3

Please sign in to comment.