Skip to content

Commit

Permalink
php full refactor. php add description feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlvtech committed Oct 25, 2018
1 parent c187c31 commit 87e3d94
Show file tree
Hide file tree
Showing 25 changed files with 961 additions and 301 deletions.
4 changes: 2 additions & 2 deletions build_github_pages.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
export BUILD_GITHUB_PAGES=true

php php/github_pages_crawl.php

npm install
npm run build

sed -i "s/new Down52PojieCn({/& jsonUrl: '\/down_52pojie_cn\/list.json' /g" dist/index.html

php php/github_pages_crawl.php
2 changes: 1 addition & 1 deletion build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ npm run build

rm dist/index.html
cp LICENSE dist/
cp php/scan.php dist/
cp php/ dist/ -R
cp README.md dist/
zip dist.zip -r dist
rm -rf dist/
Expand Down
2 changes: 2 additions & 0 deletions php/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config/config.php
vendor
95 changes: 95 additions & 0 deletions php/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# php 文件扫描程序

## 目录结构

```plain
* config/ 配置文件目录(需要自行修改)
* config.php 扫描本地文件使用的设置
* data/ 数据文件目录(程序会储存一些数据,有些需要手动修改)
* description.yml 文件夹/文件的描述信息,会混合到生成的 list.json 中
* src/ 主要代码目录(4 种获取文件列表的扫描器、3 输出格式的编解码器)
* vendor/
* .gitignore
* composer.json
* composer.lock
* github_pages_crawl.php 用于构建 GitHub Pages
* README.md
* scan.php 用于扫描本地文件
```

## 使用方法

首先,复制一份配置文件

```bash
cp config/config.php.example config/config.php
```

然后,修改 `config/config.php` 中的配置参数

最后,执行扫描指令

```bash
php scan.php
```

如果 `data/description.yml` 不存在的话,首次执行 `php scan.php` 会自动生成一个 `data/description.yml` 的模板,这里面没有 `description` 字段,如果想给文件添加备注的话,需要手动在对应文件的文件名下添加一个 `description` 字段,并填写备注信息。

然后,再次执行 `php scan.php` 则会将描述信息合并到 `list.json` 中。

## 备注文件格式

`php scan.php` 自动生成的格式如下。

```yaml
name: /
children:
-
name: Challenge
children:
-
name: 2012CM
-
name: 2016_Security_Challenge
```
你需要手动添加几个 `description` 字段,然后填入相关描述。

```yaml
name: /
children:
-
name: Challenge
description: 收录论坛往年比赛题目
children:
-
name: 2012CM
description: 2012 年论坛举行 CrackMe 大赛的作品和对应的分析文章,难度有易、中、难,大家任选学习
-
name: 2016_Security_Challenge
description: 2016 年论坛举行安全挑战赛,容纳了更多与实际应用息息相关的 Windows、移动安全相关考题,欢迎大家学习
```

## 配置文件内容

```php
<?php
return [
// 扫描的根目录(绝对路径)
'BASE_PATH' => '/home/ganlv/Downloads',
// 排除的文件(相对于 BASE_PATH)
'EXCLUDE_FILES' => [
'/list.json',
'/list.js',
],
// 描述文件(绝对路径)
'DESCRIPTION_FILE' => dirname(__DIR__) . '/data/description.yml',
// 输出的文件类型(json 或者 jsonp)
'OUTPUT_TYPE' => 'jsonp',
// 输出的文件路径(绝对路径)
'OUTPUT_FILE' => '/home/ganlv/Downloads/public/.list.js',
// jsonp 回调函数名(需要与 index.html 中的设置相同)
'JSONP_CALLBACK' => '__jsonpCallbackDown52PojieCn',
];
```
23 changes: 23 additions & 0 deletions php/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "ganlv/down_52pojie_cn",
"description": "down.52pojie.cn file scan script",
"type": "project",
"require": {
"php": ">=7.0",
"ext-json": "*",
"ext-curl": "*",
"symfony/yaml": "^4.1"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Ganlv\\Down52PojieCn\\": "src"
}
},
"authors": [
{
"name": "Ganlv",
"email": "[email protected]"
}
]
}
139 changes: 139 additions & 0 deletions php/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions php/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

return [
// 扫描的根目录(绝对路径)
'BASE_PATH' => "C:\Users\Ganlv\Downloads",
// 'BASE_PATH' => '/home/ganlv/Downloads',
// 排除的文件(相对于 BASE_PATH)
'EXCLUDE_FILES' => [
'/list.json',
'/list.js',
],
// 描述文件(绝对路径)
'DESCRIPTION_FILE' => dirname(__DIR__) . '/data/description.yml',
// 输出的文件类型(json 或者 jsonp)
// 'OUTPUT_TYPE' => 'jsonp',
'OUTPUT_TYPE' => 'json',
// 输出的文件路径(绝对路径)
'OUTPUT_FILE' => 'D:\www\PhpstormProjects\down_52pojie_cn\dist\list.json',
// 'OUTPUT_FILE' => 'C:\Users\Ganlv\Downloads\.list.js',
// jsonp 回调函数名(需要与 index.html 中的设置相同)
'JSONP_CALLBACK' => '__jsonpCallbackDown52PojieCn',
];
19 changes: 19 additions & 0 deletions php/config/config.php.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

return [
// 扫描的根目录(绝对路径)
'BASE_PATH' => '/home/ganlv/Downloads',
// 排除的文件(相对于 BASE_PATH)
'EXCLUDE_FILES' => [
'/list.json',
'/list.js',
],
// 描述文件(绝对路径)
'DESCRIPTION_FILE' => dirname(__DIR__) . '/data/description.yml',
// 输出的文件类型(json 或者 jsonp)
'OUTPUT_TYPE' => 'jsonp',
// 输出的文件路径(绝对路径)
'OUTPUT_FILE' => '/home/ganlv/Downloads/public/.list.js',
// jsonp 回调函数名(需要与 index.html 中的设置相同)
'JSONP_CALLBACK' => '__jsonpCallbackDown52PojieCn',
];
67 changes: 0 additions & 67 deletions php/crawl.php

This file was deleted.

Loading

0 comments on commit 87e3d94

Please sign in to comment.