diff --git a/app/Controllers/CLI/Crawler.php b/app/Controllers/CLI/Crawler.php
index 539cd74..7fc6759 100644
--- a/app/Controllers/CLI/Crawler.php
+++ b/app/Controllers/CLI/Crawler.php
@@ -2,13 +2,12 @@
namespace App\Controllers\CLI;
-use App\Models\Mangboard\BoardModel;
-
-use App\Libraries\MyWebLibrary;
+use App\Controllers\BaseController;
use App\Libraries\MyCrawler\YamapLibrary;
use App\Libraries\Mangboard\BoardLibrary;
+use App\Models\Mangboard\UserModel;
+use App\Models\Mangboard\BoardModel;
use App\Entities\Mangboard\BoardEntity;
-use App\Controllers\BaseController;
class Crawler extends BaseController
{
@@ -16,13 +15,9 @@ class Crawler extends BaseController
{
try {
$isDebug = in_array("debug", $params);
- //1.Yamap사이트에서 자유게시판에서 최근 게시물 데이터 가져오기
- $yamap = new YamapLibrary();
- $yamap->setDebug($isDebug);
- if (!in_array("skip_build", $params)) {
- list($item, $fileInfos, $mediaTags) = $yamap->execute();
- }
- // //2. 사이트 로그인 처리
+ //1. 사이트 로그인 처리
+ $userModel = new UserModel();
+ $user = $userModel->getEntityByID("idcjp");
// if (!in_array("skip_login", $params)) {
// $daemonidc = new MyWebLibrary(getenv('daemonidc.host.url'));
// $daemonidc->setDebug($isDebug);
@@ -32,7 +27,12 @@ class Crawler extends BaseController
// getenv('daemonidc.login.user_password')
// );
// }
- //3. 망보드 일반게시판에 게시물 등록 처리
+ //2.Yamap사이트에서 자유게시판에서 최근 게시물 데이터 가져오기
+ $yamap = new YamapLibrary();
+ $yamap->setDebug($isDebug);
+ list($item, $fileInfos) = $yamap->execute();
+
+ //3.망보드 일반게시판에 게시물 등록 처리
if (!in_array("skip_create", $params)) {
$board = new BoardLibrary(new BoardModel(getenv("crawler.yamap.registration.table")));
$board->setDebug($isDebug);
@@ -45,11 +45,14 @@ class Crawler extends BaseController
$entity->hit = $item['hit'];
$entity->data_type = "html";
$entity->editor_type = "S";
- $entity->content = is_array($mediaTags) ? implode("\n", $mediaTags) : $mediaTags;
+ foreach ($fileInfos as $fileInfo) {
+ $entity->content .= $fileInfo["mediatag"];
+ }
//망보드에 넣기
$board->create($entity);
}
+
log_message("notice", "Crawler->" . __FUNCTION__ . " 작업이 완료되었습니다.");
return true;
} catch (\Exception $e) {
diff --git a/app/Controllers/CLI/Mangboard.php b/app/Controllers/CLI/Mangboard.php
index c56337f..7f67838 100644
--- a/app/Controllers/CLI/Mangboard.php
+++ b/app/Controllers/CLI/Mangboard.php
@@ -2,7 +2,6 @@
namespace App\Controllers\CLI;
-use App\Models\Mangboard\UserModel;
use App\Libraries\Mangboard\UserLibrary;
use App\Controllers\BaseController;
@@ -12,7 +11,7 @@ class Mangboard extends BaseController
{
try {
$isDebug = in_array("debug", $params);
- $user = new UserLibrary(new UserModel);
+ $user = new UserLibrary();
$user->setDebug($isDebug);
$user->setLevel();
log_message("notice", "Mangboard->level 작업이 완료되었습니다.");
diff --git a/app/Controllers/Mangboard/Admin/UserController.php b/app/Controllers/Mangboard/Admin/UserController.php
index a185f81..e9f20a2 100644
--- a/app/Controllers/Mangboard/Admin/UserController.php
+++ b/app/Controllers/Mangboard/Admin/UserController.php
@@ -2,7 +2,6 @@
namespace App\Controllers\Mangboard\Admin;
-use App\Models\Mangboard\UserModel;
use App\Libraries\Mangboard\UserLibrary;
use App\Controllers\Admin\AdminController;
@@ -25,7 +24,7 @@ class UserController extends AdminController
$point = intval($this->request->getVar("point"));
$sign = $this->request->getVar("point") ?? "+";
- $user = new UserLibrary(new UserModel());
+ $user = new UserLibrary();
$user->setPoint($id, $point, $sign);
return "완료되었습니다.";
} catch (\Exception $e) {
diff --git a/app/Entities/CommonEntity.php b/app/Entities/CommonEntity.php
index bb3c454..6dda71e 100644
--- a/app/Entities/CommonEntity.php
+++ b/app/Entities/CommonEntity.php
@@ -13,4 +13,5 @@ abstract class CommonEntity extends Entity
abstract public function __toString();
abstract public function getPK();
abstract public function getTitle();
+ abstract public function setTitle(string $tile): void;
}
diff --git a/app/Entities/Mangboard/BoardEntity.php b/app/Entities/Mangboard/BoardEntity.php
index 3ee21a3..9bfc2f9 100644
--- a/app/Entities/Mangboard/BoardEntity.php
+++ b/app/Entities/Mangboard/BoardEntity.php
@@ -18,5 +18,9 @@ class BoardEntity extends CommonEntity
{
return $this->attributes['title'];
}
+ public function setTitle(string $title): void
+ {
+ $this->attributes['title'] = $title;
+ }
//Common Function
}
diff --git a/app/Entities/Mangboard/FileEntity.php b/app/Entities/Mangboard/FileEntity.php
index 2c4f87c..ef8ddd2 100644
--- a/app/Entities/Mangboard/FileEntity.php
+++ b/app/Entities/Mangboard/FileEntity.php
@@ -18,5 +18,9 @@ class FileEntity extends CommonEntity
{
return $this->attributes['file_name'];
}
+ public function setTitle(string $title): void
+ {
+ $this->attributes['file_name'] = $title;
+ }
//Common Function
}
diff --git a/app/Entities/Mangboard/UserEntity.php b/app/Entities/Mangboard/UserEntity.php
index 280e18e..40f3103 100644
--- a/app/Entities/Mangboard/UserEntity.php
+++ b/app/Entities/Mangboard/UserEntity.php
@@ -18,6 +18,10 @@ class UserEntity extends CommonEntity
{
return $this->attributes['user_name'];
}
+ public function setTitle(string $title): void
+ {
+ $this->attributes['user_name'] = $title;
+ }
//Common Function
public function getID(): string
diff --git a/app/Libraries/CommonLibrary.php b/app/Libraries/CommonLibrary.php
index 2f187ff..509b427 100644
--- a/app/Libraries/CommonLibrary.php
+++ b/app/Libraries/CommonLibrary.php
@@ -15,9 +15,4 @@ abstract class CommonLibrary
{
$this->_debug = $debug;
}
-
- final public function getFileMimeType($file): string
- {
- return image_type_to_mime_type(exif_imagetype($file));
- }
}
diff --git a/app/Libraries/Mangboard/FileLibrary.php b/app/Libraries/Mangboard/FileLibrary.php
index 6a8de5d..a03896b 100644
--- a/app/Libraries/Mangboard/FileLibrary.php
+++ b/app/Libraries/Mangboard/FileLibrary.php
@@ -3,16 +3,42 @@
namespace App\Libraries\Mangboard;
-use App\Models\Mangboard\FileModel;
use App\Libraries\MyStorage\FileLibrary as MyStorageLibrary;
+use App\Models\Mangboard\FileModel;
+use App\Entities\Mangboard\UserEntity;
+use App\Entities\Mangboard\FileEntity;
class FileLibrary extends MyStorageLibrary
{
+ private $_user = null;
+ private $_boardName = null;
private $_model = null;
public function __construct(string $path)
{
parent::__construct($path);
}
+ public function getUser(): UserEntity
+ {
+ if ($this->_user === null) {
+ throw new \Exception("사용자정보가 없습니다.");
+ }
+ return $this->_user;
+ }
+ public function setUser(UserEntity $user): void
+ {
+ $this->_user = $user;
+ }
+ public function getBoardName(): string
+ {
+ if ($this->_boardName === null) {
+ throw new \Exception("BoardModel이 지정되지 않았습니다.");
+ }
+ return $this->_boardName;
+ }
+ public function setBoardName(string $boardName): void
+ {
+ $this->_boardName = $boardName;
+ }
public function getModel(): FileModel
{
@@ -21,13 +47,23 @@ class FileLibrary extends MyStorageLibrary
}
return $this->_model;
}
- public function save($content): bool
+
+ //망보드 파일관리 table에 등록
+ public function createFile($content): bool
{
if (!parent::save($content)) {
return false;
}
//mb_files 모델작업
-
+ $entity = new FileEntity();
+ $entity->setTitle($this->getFileName());
+ $entity->user_pid = $this->getUser()->getPK();
+ $entity->user_name = $this->getUser()->getTitle();
+ $entity->board_name = $this->getBoardName();
+ $entity->table_name = "mb_" . $this->getBoardName();
+ $entity->file_path = $this->getPath();
+ $entity->file_type = $this->getMimeType();
+ $entity->reg_date = date("Y-m-d H:i:s");
return true;
}
}
diff --git a/app/Libraries/MyCrawler/MyCrawlerLibrary.php b/app/Libraries/MyCrawler/MyCrawlerLibrary.php
index 68b9a88..afa4b79 100644
--- a/app/Libraries/MyCrawler/MyCrawlerLibrary.php
+++ b/app/Libraries/MyCrawler/MyCrawlerLibrary.php
@@ -11,13 +11,13 @@ abstract class MyCrawlerLibrary extends CommonLibrary
{
parent::__construct();
}
- abstract public function getMySocket();
- abstract public function getMyStorage();
+ abstract protected function getMySocket();
+ abstract protected function getMyStorage();
abstract public function execute(): array;
final protected function getContent(string $url, string $tag): Crawler
{
- $response = $this->getMySocket()->getContent($url);
+ $response = $this->getMySocket()->getContent($url);
if (!$response) {
throw new \Exception("getCrawler 실패:{$url}");
}
@@ -35,18 +35,47 @@ abstract class MyCrawlerLibrary extends CommonLibrary
);
return $nodes;
}
+ protected function getMediaTag(string $mediaType): string
+ {
+ $mediaTag = "";
+ switch ($mediaType) {
+ case "image":
+ $mediaTag = sprintf(
+ "
",
+ $this->getMyStorage()->getUploadPath(),
+ $this->getMyStorage()->getPath(),
+ $this->getMyStorage()->getFieName(),
+ $this->getMyStorage()->getFieName()
+ );
+ break;
+ case "video":
+ $mediaTag = sprintf(
+ "",
+ $this->getMyStorage()->getFieName(),
+ $this->getMyStorage()->getUploadPath(),
+ $this->getMyStorage()->getPath(),
+ $this->getMyStorage()->getFieName(),
+ $this->getMyStorage()->getFieMimeType(),
+ );
+ break;
+ }
+ return $mediaTag;
+ }
final protected function download(Crawler $crawler, array $options): array
{
$downloadInfos = [];
$nodes = $this->getNodes($crawler, $options);
foreach ($nodes as $node) {
- $downloadInfos[] = $this->getMySocket()->download($node->attr($options["attr"]));
+ $url = $node->attr($options["attr"]);
+ $downloadInfos[] = $this->getMySocket()->download($url);
}
return $downloadInfos;
}
-
- final protected function save(array $downloadInfos, $fileInfos = []): array
+ final protected function save(string $mediaType, array $downloadInfos, $fileInfos = []): array
{
foreach ($downloadInfos as $downloadInfo) {
$this->getMyStorage()->setFileName($downloadInfo['fileName']);
@@ -54,47 +83,12 @@ abstract class MyCrawlerLibrary extends CommonLibrary
continue;
}
$fileInfos[] = [
- "url" => $downloadInfo['url'],
+ "mediatag" => $this->getMediaTag($mediaType),
"path" => $this->getMyStorage()->getPath(),
- "fileType" => $this->getMyStorage()->getFieType(),
+ "mimeType" => $this->getMyStorage()->getMimeType(),
"fileName" => $this->getMyStorage()->getFieName(),
];
}
return $fileInfos;
}
- final protected function getMediaTags(array $fileInfos, array $mediaTags = []): array
- {
- switch ($fileInfos['fileType']) {
- case "jpeg":
- if ($this->getMySocket()->isContainsHttpOrHttps($fileInfos['orignal'])) {
- $mediaTags[] = $fileInfos['orignal'];
- } else {
- $mediaTags[] = sprintf(
- "
",
- $this->getMyStorage()->getUploadPath(),
- $fileInfos["path"],
- $fileInfos["fileName"],
- $fileInfos["fileName"]
- );
- }
- break;
- case "mp4":
- if ($this->getMySocket()->isContainsHttpOrHttps($fileInfos['orignal'])) {
- $mediaTags[] = $fileInfos['orignal'];
- } else {
- $mediaTags[] = sprintf(
- "