diff --git a/app/Controllers/CLI/Crawler.php b/app/Controllers/CLI/Crawler.php index 107e310..539cd74 100644 --- a/app/Controllers/CLI/Crawler.php +++ b/app/Controllers/CLI/Crawler.php @@ -17,10 +17,10 @@ class Crawler extends BaseController try { $isDebug = in_array("debug", $params); //1.Yamap사이트에서 자유게시판에서 최근 게시물 데이터 가져오기 + $yamap = new YamapLibrary(); + $yamap->setDebug($isDebug); if (!in_array("skip_build", $params)) { - $yamap = new YamapLibrary(); - $yamap->setDebug($isDebug); - list($title, $nickname, $mediaInfos, $mediaTags) = $yamap->execute(); + list($item, $fileInfos, $mediaTags) = $yamap->execute(); } // //2. 사이트 로그인 처리 // if (!in_array("skip_login", $params)) { @@ -39,8 +39,10 @@ class Crawler extends BaseController //미디어관련정보 entity에 넣기 $entity = new BoardEntity(); - $entity->title = $title; - $entity->user_name = $nickname; + $entity->title = $item["title"]; + $entity->user_name = $item["nickname"]; + $entity->reg_date = $item['time']; + $entity->hit = $item['hit']; $entity->data_type = "html"; $entity->editor_type = "S"; $entity->content = is_array($mediaTags) ? implode("\n", $mediaTags) : $mediaTags; diff --git a/app/Controllers/CLI/Mangboard.php b/app/Controllers/CLI/Mangboard.php index 535bf17..c56337f 100644 --- a/app/Controllers/CLI/Mangboard.php +++ b/app/Controllers/CLI/Mangboard.php @@ -2,9 +2,9 @@ namespace App\Controllers\CLI; -use App\Controllers\BaseController; - +use App\Models\Mangboard\UserModel; use App\Libraries\Mangboard\UserLibrary; +use App\Controllers\BaseController; class Mangboard extends BaseController { @@ -12,7 +12,7 @@ class Mangboard extends BaseController { try { $isDebug = in_array("debug", $params); - $user = new UserLibrary(); + $user = new UserLibrary(new UserModel); $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 31549fb..a185f81 100644 --- a/app/Controllers/Mangboard/Admin/UserController.php +++ b/app/Controllers/Mangboard/Admin/UserController.php @@ -2,8 +2,9 @@ namespace App\Controllers\Mangboard\Admin; -use App\Controllers\Admin\AdminController; +use App\Models\Mangboard\UserModel; use App\Libraries\Mangboard\UserLibrary; +use App\Controllers\Admin\AdminController; class UserController extends AdminController { @@ -24,7 +25,7 @@ class UserController extends AdminController $point = intval($this->request->getVar("point")); $sign = $this->request->getVar("point") ?? "+"; - $user = new UserLibrary(); + $user = new UserLibrary(new UserModel()); $user->setPoint($id, $point, $sign); return "완료되었습니다."; } catch (\Exception $e) { diff --git a/app/Entities/Mangboard/FileEntity.php b/app/Entities/Mangboard/FileEntity.php new file mode 100644 index 0000000..2c4f87c --- /dev/null +++ b/app/Entities/Mangboard/FileEntity.php @@ -0,0 +1,22 @@ +getPK()}:{$this->getTitle()}"; + } + public function getPK(): int + { + return $this->attributes['pid']; + } + public function getTitle(): string + { + return $this->attributes['file_name']; + } + //Common Function +} diff --git a/app/Libraries/CommonLibrary.php b/app/Libraries/CommonLibrary.php index 509b427..2f187ff 100644 --- a/app/Libraries/CommonLibrary.php +++ b/app/Libraries/CommonLibrary.php @@ -15,4 +15,9 @@ 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/BoardLibrary.php b/app/Libraries/Mangboard/BoardLibrary.php index 3494442..9607404 100644 --- a/app/Libraries/Mangboard/BoardLibrary.php +++ b/app/Libraries/Mangboard/BoardLibrary.php @@ -13,7 +13,7 @@ class BoardLibrary extends CommonLibrary parent::__construct(); $this->_model = $model; } - protected function getModel(): mixed + public function getModel(): mixed { return $this->_model; } diff --git a/app/Libraries/Mangboard/FileLibrary.php b/app/Libraries/Mangboard/FileLibrary.php new file mode 100644 index 0000000..6a8de5d --- /dev/null +++ b/app/Libraries/Mangboard/FileLibrary.php @@ -0,0 +1,33 @@ +_model === null) { + return $this->_model = new FileModel(); + } + return $this->_model; + } + public function save($content): bool + { + if (!parent::save($content)) { + return false; + } + //mb_files 모델작업 + + return true; + } +} diff --git a/app/Libraries/Mangboard/UserLibrary.php b/app/Libraries/Mangboard/UserLibrary.php index ed443b1..5cb953f 100644 --- a/app/Libraries/Mangboard/UserLibrary.php +++ b/app/Libraries/Mangboard/UserLibrary.php @@ -3,8 +3,8 @@ namespace App\Libraries\Mangboard; use App\Models\Mangboard\UserModel; -use App\Libraries\CommonLibrary; use App\Entities\Mangboard\UserEntity; +use App\Libraries\CommonLibrary; class UserLibrary extends CommonLibrary { @@ -13,10 +13,11 @@ class UserLibrary extends CommonLibrary { parent::__construct(); } - private function getModel(): UserModel + + public function getModel(): UserModel { if ($this->_model === null) { - $this->_model = new UserModel(); + return $this->_model = new UserModel(); } return $this->_model; } diff --git a/app/Libraries/MyCrawler/MyCrawlerLibrary.php b/app/Libraries/MyCrawler/MyCrawlerLibrary.php index c87d340..68b9a88 100644 --- a/app/Libraries/MyCrawler/MyCrawlerLibrary.php +++ b/app/Libraries/MyCrawler/MyCrawlerLibrary.php @@ -41,18 +41,60 @@ abstract class MyCrawlerLibrary extends CommonLibrary $downloadInfos = []; $nodes = $this->getNodes($crawler, $options); foreach ($nodes as $node) { - $original = $node->attr($options["attr"]); - list($fileName, $content) = $this->getMySocket()->download($original); - $this->getMyStorage()->setFileName($fileName); - if (!$this->getMyStorage()->save($content)) { - continue; - } - $downloadInfos[] = [ - "orignal" => $node->html(), - "path" => $this->getMyStorage()->getPath(), - "fileName" => $fileName, - ]; + $downloadInfos[] = $this->getMySocket()->download($node->attr($options["attr"])); } return $downloadInfos; } + + final protected function save(array $downloadInfos, $fileInfos = []): array + { + foreach ($downloadInfos as $downloadInfo) { + $this->getMyStorage()->setFileName($downloadInfo['fileName']); + if (!$this->getMyStorage()->save($downloadInfo['content'])) { + continue; + } + $fileInfos[] = [ + "url" => $downloadInfo['url'], + "path" => $this->getMyStorage()->getPath(), + "fileType" => $this->getMyStorage()->getFieType(), + "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( + "\"%s\"", + $this->getMyStorage()->getUploadPath(), + $fileInfos["path"], + $fileInfos["fileName"], + $fileInfos["fileName"] + ); + } + break; + case "mp4": + if ($this->getMySocket()->isContainsHttpOrHttps($fileInfos['orignal'])) { + $mediaTags[] = $fileInfos['orignal']; + } else { + $mediaTags[] = sprintf( + "